SOL9 Sample: Animator

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * Animator.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// SOL++2000
// 1999.09.25

// 2000.02.16
// 2008/09/16 Modified to use restoreFileFolder/saveFileFolder in open method.
#define COMMONCONTROLS_V6

#include <sol\ApplicationView.h>
#include <sol\FileDialog.h>
#include <sol\PushButton.h>
#include <sol\Animator.h>
#include <sol\PaintDC.h>

#include "resource.h"

namespace SOL {

class AppView :public ApplicationView {
private:
  Animator  animator;
  PushButton playb;
  PushButton stopb;

  FileDialog filedlg;


public:
  /**
   * Constructor
   */
  AppView(Application& applet, const TCHAR* label, Args& args)
    :ApplicationView(applet, label, args.set(XmNstyle, WS_CLIPCHILDREN))
  {
    Args ar;
    ar.set(XmNx, 10);
    ar.set(XmNy, 10);
    playb.create(this, _T("Play"), ar);
    playb.addCallback(XmNactivateCallback, this, 
      (Callback)&AppView::play, NULL);
    playb.disable();

    ar.reset();
    ar.set(XmNx, 120);
    ar.set(XmNy, 10);
    stopb.create(this, _T("Stop"), ar);
    stopb.addCallback(XmNactivateCallback, this, 
      (Callback)&AppView::stop, NULL);
    stopb.disable();
    
    ar.reset();
    ar.set(XmNx,     10);
    ar.set(XmNy,      50);
    ar.set(XmNwidth,  200);
    ar.set(XmNheight, 200);
    ar.set(XmNexStyle, (ulong)WS_EX_WINDOWEDGE);
    animator.create(this, _T("animator"), ar);
  
    ar.reset();
    // 1999.09.25
    ar.set(XmNfilter, (ulong)_T("(AVI *.avi)\0 *.avi\0"));
    filedlg.create(this, _T("Open"), ar);

    addCallback(XmNmenuCallback, IDM_OPEN, this, 
      (Callback)&AppView::open, NULL);
    addCallback(XmNmenuCallback, IDM_EXIT, this, 
      (Callback)&AppView::exit, NULL);

    restorePlacement();
  }

public:
  ~AppView() 
  { 
    animator.close();
  }

//
private:
  void open(Action& action)
  {
    TCHAR dir[_MAX_PATH];
    if (restoreFileFolder(dir, CountOf(dir))) { //2012/06/26
      Args ar;
      ar.set(XmNdirectory, dir);
      filedlg.setValues(ar);
    }
    if(filedlg.open() == IDOK) {
      TCHAR* name = filedlg.getFileName();
      if(name) {
        saveFileFolder(name);

        animator.close();
        animator.open(name);
        playb.enable();
        TCHAR title[MAX_PATH*2];
        _stprintf_s(title, CountOf(title), _T("%s - Animator"), name);
        setText(title);
      }
    }
  }

private:
  void play(Action& action)
  {
    animator.play(0, -1, -1);
    playb.disable();
    stopb.enable();
  }

private:
  void stop(Action& action)
  {
    animator.stop();
    stopb.disable();
    playb.enable();
  }

};

}

////////////////////////////////////
// Program Main
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);

    Args args;

    AppView appView(applet, name, args);
    appView.realize();
    applet.run();
  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  } 
}



Last modified: 1 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.