2007-05-11 17:07:00 +08:00
|
|
|
#ifndef _WXSIMPLEVIEWERWX_H_
|
|
|
|
#define _WXSIMPLEVIEWERWX_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/cursor.h"
|
|
|
|
#include "wx/glcanvas.h"
|
2007-06-02 23:31:21 +08:00
|
|
|
#include <osgViewer/Viewer>
|
2007-05-11 17:07:00 +08:00
|
|
|
#include <string>
|
|
|
|
|
2008-06-19 21:49:36 +08:00
|
|
|
class GraphicsWindowWX;
|
|
|
|
|
|
|
|
class OSGCanvas : public wxGLCanvas
|
2007-05-11 17:07:00 +08:00
|
|
|
{
|
|
|
|
public:
|
2008-06-19 21:49:36 +08:00
|
|
|
OSGCanvas(wxWindow *parent, wxWindowID id = wxID_ANY,
|
2007-05-21 20:28:25 +08:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize, long style = 0,
|
2007-08-27 21:33:58 +08:00
|
|
|
const wxString& name = wxT("TestGLCanvas"),
|
|
|
|
int *attributes = 0);
|
2007-05-11 17:07:00 +08:00
|
|
|
|
2008-06-19 21:49:36 +08:00
|
|
|
virtual ~OSGCanvas();
|
2008-05-27 05:09:54 +08:00
|
|
|
|
2008-06-19 21:49:36 +08:00
|
|
|
void SetGraphicsWindow(osgViewer::GraphicsWindow *gw) { _graphics_window = gw; }
|
2007-05-11 17:07:00 +08:00
|
|
|
|
2007-05-21 20:28:25 +08:00
|
|
|
void OnPaint(wxPaintEvent& event);
|
|
|
|
void OnSize(wxSizeEvent& event);
|
|
|
|
void OnEraseBackground(wxEraseEvent& event);
|
2008-05-27 05:09:54 +08:00
|
|
|
|
|
|
|
void OnChar(wxKeyEvent &event);
|
2007-05-21 20:28:25 +08:00
|
|
|
void OnKeyUp(wxKeyEvent &event);
|
2008-05-27 05:09:54 +08:00
|
|
|
|
|
|
|
void OnMouseEnter(wxMouseEvent &event);
|
|
|
|
void OnMouseDown(wxMouseEvent &event);
|
|
|
|
void OnMouseUp(wxMouseEvent &event);
|
|
|
|
void OnMouseMotion(wxMouseEvent &event);
|
2009-11-19 19:21:05 +08:00
|
|
|
void OnMouseWheel(wxMouseEvent &event);
|
2008-05-27 05:09:54 +08:00
|
|
|
|
2008-06-19 21:49:36 +08:00
|
|
|
void UseCursor(bool value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
|
|
|
osg::ref_ptr<osgViewer::GraphicsWindow> _graphics_window;
|
|
|
|
|
|
|
|
wxCursor _oldCursor;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GraphicsWindowWX : public osgViewer::GraphicsWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GraphicsWindowWX(OSGCanvas *canvas);
|
|
|
|
~GraphicsWindowWX();
|
|
|
|
|
|
|
|
void init();
|
2007-05-11 17:07:00 +08:00
|
|
|
|
2007-05-21 20:28:25 +08:00
|
|
|
//
|
|
|
|
// GraphicsWindow interface
|
|
|
|
//
|
|
|
|
void grabFocus();
|
2007-05-11 17:07:00 +08:00
|
|
|
void grabFocusIfPointerInWindow();
|
|
|
|
void useCursor(bool cursorOn);
|
|
|
|
|
2007-05-21 20:28:25 +08:00
|
|
|
bool makeCurrentImplementation();
|
|
|
|
void swapBuffersImplementation();
|
2007-05-11 17:07:00 +08:00
|
|
|
|
2008-05-27 05:09:54 +08:00
|
|
|
// not implemented yet...just use dummy implementation to get working.
|
2007-06-02 23:31:21 +08:00
|
|
|
virtual bool valid() const { return true; }
|
|
|
|
virtual bool realizeImplementation() { return true; }
|
|
|
|
virtual bool isRealizedImplementation() const { return true; }
|
|
|
|
virtual void closeImplementation() {}
|
|
|
|
virtual bool releaseContextImplementation() { return true; }
|
|
|
|
|
2007-05-11 17:07:00 +08:00
|
|
|
private:
|
2008-06-19 21:49:36 +08:00
|
|
|
// XXX need to set _canvas to NULL when the canvas is deleted by
|
|
|
|
// its parent. for this, need to add event handler in OSGCanvas
|
|
|
|
OSGCanvas* _canvas;
|
2007-05-11 17:07:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class MainFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2008-05-27 05:09:54 +08:00
|
|
|
MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
2007-05-21 20:28:25 +08:00
|
|
|
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
2007-05-11 17:07:00 +08:00
|
|
|
|
2007-06-02 23:31:21 +08:00
|
|
|
void SetViewer(osgViewer::Viewer *viewer);
|
2007-05-21 20:28:25 +08:00
|
|
|
void OnIdle(wxIdleEvent& event);
|
2007-05-11 17:07:00 +08:00
|
|
|
|
|
|
|
private:
|
2007-06-02 23:31:21 +08:00
|
|
|
osg::ref_ptr<osgViewer::Viewer> _viewer;
|
2007-05-11 17:07:00 +08:00
|
|
|
|
2007-05-21 20:28:25 +08:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-05-11 17:07:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Define a new application type */
|
|
|
|
class wxOsgApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
2007-05-21 20:28:25 +08:00
|
|
|
bool OnInit();
|
2007-05-11 17:07:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WXSIMPLEVIEWERWX_H_
|