1 #ifndef _WXSIMPLEVIEWERWX_H_
2 #define _WXSIMPLEVIEWERWX_H_
3 
4 #include "wx/defs.h"
5 #include "wx/app.h"
6 #include "wx/cursor.h"
7 #include "wx/glcanvas.h"
8 #include <osgViewer/Viewer>
9 #include <string>
10 
11 class GraphicsWindowWX;
12 
13 class OSGCanvas : public wxGLCanvas
14 {
15 public:
16     OSGCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
17         const wxPoint& pos = wxDefaultPosition,
18         const wxSize& size = wxDefaultSize, long style = 0,
19         const wxString& name = wxT("TestGLCanvas"),
20         int *attributes = 0);
21 
22     virtual ~OSGCanvas();
23 
SetGraphicsWindow(osgViewer::GraphicsWindow * gw)24     void SetGraphicsWindow(osgViewer::GraphicsWindow *gw)   { _graphics_window = gw; }
25 
26     void OnPaint(wxPaintEvent& event);
27     void OnSize(wxSizeEvent& event);
28     void OnEraseBackground(wxEraseEvent& event);
29 
30     void OnChar(wxKeyEvent &event);
31     void OnKeyUp(wxKeyEvent &event);
32 
33     void OnMouseEnter(wxMouseEvent &event);
34     void OnMouseDown(wxMouseEvent &event);
35     void OnMouseUp(wxMouseEvent &event);
36     void OnMouseMotion(wxMouseEvent &event);
37     void OnMouseWheel(wxMouseEvent &event);
38 
39     void UseCursor(bool value);
40 
41 private:
42     DECLARE_EVENT_TABLE()
43 
44     osg::ref_ptr<osgViewer::GraphicsWindow> _graphics_window;
45 
46     wxCursor _oldCursor;
47 };
48 
49 class GraphicsWindowWX : public osgViewer::GraphicsWindow
50 {
51 public:
52     GraphicsWindowWX(OSGCanvas *canvas);
53     ~GraphicsWindowWX();
54 
55     void init();
56 
57     //
58     // GraphicsWindow interface
59     //
60     void grabFocus();
61     void grabFocusIfPointerInWindow();
62     void useCursor(bool cursorOn);
63 
64     bool makeCurrentImplementation();
65     void swapBuffersImplementation();
66 
67     // not implemented yet...just use dummy implementation to get working.
valid()68     virtual bool valid() const { return true; }
realizeImplementation()69     virtual bool realizeImplementation() { return true; }
isRealizedImplementation()70     virtual bool isRealizedImplementation() const  { return _canvas->IsShownOnScreen(); }
closeImplementation()71     virtual void closeImplementation() {}
releaseContextImplementation()72     virtual bool releaseContextImplementation() { return true; }
73 
74 private:
75     // XXX need to set _canvas to NULL when the canvas is deleted by
76     // its parent. for this, need to add event handler in OSGCanvas
77     OSGCanvas*  _canvas;
78 };
79 
80 class MainFrame : public wxFrame
81 {
82 public:
83     MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
84         const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
85 
86     void SetViewer(osgViewer::Viewer *viewer);
87     void OnIdle(wxIdleEvent& event);
88 
89 private:
90     osg::ref_ptr<osgViewer::Viewer> _viewer;
91 
92     DECLARE_EVENT_TABLE()
93 };
94 
95 /* Define a new application type */
96 class wxOsgApp : public wxApp
97 {
98 public:
99     bool OnInit();
100 };
101 
102 #endif // _WXSIMPLEVIEWERWX_H_
103