Show
Ignore:
Timestamp:
06/04/07 16:46:38 (8 years ago)
Author:
robert
Message:

From Martin Lavery and Robert Osfield, ported fltk example to osgViewer::Viewer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgviewerFLTK/osgviewerFLTK.cpp

    r6813 r6829  
    44// Derived from osgGLUTsimple.cpp and osgkeyboardmouse.cpp 
    55 
    6 #include <osgViewer/SimpleViewer> 
     6#include <osgViewer/Viewer> 
     7#include <osgViewer/StatsHandler> 
    78#include <osgGA/TrackballManipulator> 
    89#include <osgDB/ReadFile> 
     
    1314#include <iostream> 
    1415 
    15 class GraphicsWindowFLTK : public Fl_Gl_Window,  virtual osgViewer::GraphicsWindow 
     16class AdapterWidget : public Fl_Gl_Window 
    1617{ 
    1718public: 
    1819 
    19     GraphicsWindowFLTK(int x, int y, int w, int h, const char *label=0); 
    20     virtual ~GraphicsWindowFLTK() {} 
     20    AdapterWidget(int x, int y, int w, int h, const char *label=0); 
     21    virtual ~AdapterWidget() {} 
     22 
     23    osgViewer::GraphicsWindow* getGraphicsWindow() { return _gw.get(); } 
     24    const osgViewer::GraphicsWindow* getGraphicsWindow() const { return _gw.get(); } 
    2125 
    2226    virtual void resize(int x, int y, int w, int h); 
     
    2529 
    2630    virtual int handle(int event); 
    27  
     31     
     32    osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> _gw; 
    2833}; 
    2934 
    30 GraphicsWindowFLTK::GraphicsWindowFLTK(int x, int y, int w, int h, const char *label): 
     35AdapterWidget::AdapterWidget(int x, int y, int w, int h, const char *label): 
    3136    Fl_Gl_Window(x, y, w, h, label) 
    3237{ 
    33     getEventQueue()->windowResize(x, y, w, h ); 
     38    _gw = new osgViewer::GraphicsWindowEmbedded(x,y,w,h); 
    3439} 
    3540 
    36 void GraphicsWindowFLTK::resize(int x, int y, int w, int h) 
     41void AdapterWidget::resize(int x, int y, int w, int h) 
    3742{ 
    38     getEventQueue()->windowResize(x, y, w, h ); 
     43    _gw->getEventQueue()->windowResize(x, y, w, h ); 
     44    _gw->resized(x,y,w,h); 
     45 
    3946    Fl_Gl_Window::resize(x,y,w,h); 
     47 
    4048} 
    4149 
    42 int GraphicsWindowFLTK::handle(int event) 
     50int AdapterWidget::handle(int event) 
    4351{ 
    4452    switch(event){ 
    4553        case FL_PUSH: 
    46             getEventQueue()->mouseButtonPress(Fl::event_x(), Fl::event_y(), Fl::event_button()); 
     54            _gw->getEventQueue()->mouseButtonPress(Fl::event_x(), Fl::event_y(), Fl::event_button()); 
    4755            return 1; 
    4856        case FL_MOVE: 
    4957        case FL_DRAG: 
    50             getEventQueue()->mouseMotion(Fl::event_x(), Fl::event_y()); 
     58            _gw->getEventQueue()->mouseMotion(Fl::event_x(), Fl::event_y()); 
    5159            return 1; 
    5260        case FL_RELEASE: 
    53             getEventQueue()->mouseButtonRelease(Fl::event_x(), Fl::event_y(), Fl::event_button()); 
     61            _gw->getEventQueue()->mouseButtonRelease(Fl::event_x(), Fl::event_y(), Fl::event_button()); 
    5462            return 1; 
    5563        case FL_KEYDOWN: 
    56             getEventQueue()->keyPress((osgGA::GUIEventAdapter::KeySymbol)Fl::event_key()); 
     64            _gw->getEventQueue()->keyPress((osgGA::GUIEventAdapter::KeySymbol)Fl::event_key()); 
    5765            return 1; 
    5866        case FL_KEYUP: 
    59             getEventQueue()->keyRelease((osgGA::GUIEventAdapter::KeySymbol)Fl::event_key()); 
     67            _gw->getEventQueue()->keyRelease((osgGA::GUIEventAdapter::KeySymbol)Fl::event_key()); 
    6068            return 1; 
    6169        default: 
     
    7179 
    7280 
    73 class SimpleViewerFLTK : public osgViewer::SimpleViewer, public GraphicsWindowFLTK 
     81class ViewerFLTK : public osgViewer::Viewer, public AdapterWidget 
    7482{ 
    75 public: 
    76     SimpleViewerFLTK(int x, int y, int w, int h, const char *label=0): 
    77          GraphicsWindowFLTK(x,y,w,h,label) {} 
     83    public: 
     84        ViewerFLTK(int x, int y, int w, int h, const char *label=0): 
     85            AdapterWidget(x,y,w,h,label) 
     86            { 
     87                getCamera()->setViewport(new osg::Viewport(0,0,w,h)); 
     88                getCamera()->setGraphicsContext(getGraphicsWindow()); 
     89                setThreadingModel(osgViewer::Viewer::SingleThreaded); 
     90            } 
    7891 
    79 protected: 
    80     virtual void draw() { frame(); } 
     92    protected: 
     93        virtual void draw() { frame(); } 
    8194 
    8295}; 
     
    100113 
    101114 
    102     SimpleViewerFLTK viewerWindow(100,100,800,600); 
     115    ViewerFLTK viewerWindow(100,100,800,600); 
    103116    viewerWindow.resizable(&viewerWindow); 
    104117 
    105118    viewerWindow.setSceneData(loadedModel.get()); 
    106119    viewerWindow.setCameraManipulator(new osgGA::TrackballManipulator); 
    107  
     120    viewerWindow.addEventHandler(new osgViewer::StatsHandler); 
     121     
    108122    viewerWindow.show(); 
    109123