SOL9 2.0 Sample: Animator

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * Animator.cpp 
 * Copyright (c) 2009 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.

#include <sol\ApplicationView.h>
#include <sol\FileDialog.h>
#include <sol\PushButton.h>
#include <sol\Animator.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)
    {
        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, sizeof(dir))) {
            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, SizeOf(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)
{
    const TCHAR* appClass = _T("Animator");
    try {
        Application applet(appClass, argc, argv);

        Args args;
        AppView appView(applet, appClass, args);
        appView.realize();
        applet.run();

    } catch (...) {

    }
}



Last modified: 11 Nov 2009

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