File: FOX_OSG_MDIView.cpp

package info (click to toggle)
openscenegraph 3.2.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,820 kB
  • ctags: 34,610
  • sloc: cpp: 370,040; ansic: 9,071; java: 1,020; yacc: 548; objc: 288; makefile: 285; xml: 155; lex: 151
file content (77 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "FOX_OSG_MDIView.h"

#include <osgViewer/ViewerEventHandlers>

#include <osgGA/TrackballManipulator>

#include <osgDB/ReadFile>


// Map
FXDEFMAP(FOX_OSG_MDIView) FOX_OSG_MDIView_Map[] = {
    //________Message_Type_________        ___ID___                        ________Message_Handler________
    FXMAPFUNC(SEL_CHORE,                FOX_OSG_MDIView::ID_CHORE,        FOX_OSG_MDIView::OnIdle)
};

FXIMPLEMENT(FOX_OSG_MDIView, FXMDIChild, FOX_OSG_MDIView_Map, ARRAYNUMBER(FOX_OSG_MDIView_Map))

FOX_OSG_MDIView::FOX_OSG_MDIView(FXMDIClient *p, const FXString &name,
        FXIcon *ic, FXPopup *pup, FXuint opt,
        FXint x, FXint y, FXint w, FXint h)
        :   FXMDIChild(p, name, ic, pup, opt, x, y, w, h)
{
    // A visual to drag OpenGL in double-buffered mode; note the glvisual is
    // shared between all windows which need the same depths and numbers of buffers
    // Thus, while the first visual may take some time to initialize, each subsequent
    // window can be created very quickly; we need to determine grpaphics hardware
    // characteristics only once.
    FXGLVisual* glVisual=new FXGLVisual(getApp(),VISUAL_DOUBLEBUFFER|VISUAL_STEREO);

    m_gwFox = new GraphicsWindowFOX(this, glVisual, NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y, x, y, w, h );

    osgViewer::Viewer *viewer = new osgViewer::Viewer;
    viewer->getCamera()->setGraphicsContext(m_gwFox);
    viewer->getCamera()->setViewport(0,0,w,h);
    viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);

    // FOX example does not catch the close of the graphics window, so
    // don't allow the default escape sets to done to be active.
    viewer->setKeyEventSetsDone(0);

    // load the scene.
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osgt");
    if (!loadedModel)
    {
        return ;
    }

    // add the stats handler
    viewer->addEventHandler(new osgViewer::StatsHandler);

    viewer->setSceneData(loadedModel.get());

    viewer->setCameraManipulator(new osgGA::TrackballManipulator);

    SetViewer(viewer);

    getApp()->addChore(this,ID_CHORE);

}


FOX_OSG_MDIView::~FOX_OSG_MDIView()
{
    getApp()->removeChore(this,ID_CHORE);
}

long FOX_OSG_MDIView::OnIdle(FXObject *sender, FXSelector sel, void* ptr)
{
    m_osgViewer->frame();
    getApp()->addChore(this, ID_CHORE);
    return 1;
}

void FOX_OSG_MDIView::SetViewer(osgViewer::Viewer* viewer)
{
    m_osgViewer = viewer;
}