ae303e38e9
* I split the mouse handling from a monolithic method to separate ones, slightly cleaner than a whole bunch of if()'s, especially with another case of the mouse entering the canvas. * I changed the EVT_KEY_DOWN handler to an EVT_CHAR handler, although that now makes the up and down handler assymetric. The new down-handler returns translated key codes, so when you press the S key (without anything else), it actually returns 's' and not 'S' as the EVT_KEY_DOWN did. This means that statistics can be called up in the viewer window, while the example previously only printed a "Stats output:" line to the console. I'm not truly happy that the up handler returns _untranslated_ key codes. But solving this completely would probably mean adding some table that translated from wxWidgets' untranslated key codes to OSG's internal ones. This might be interesting to add, as anyone using OSG + wxWidgets in any serious manner would also have to add this. * I commented out the evt.Skip()'s in the keyboard handlers as these would only be necessary if there were some key events that are not handled. But currently all key events are simply forwarded. * I changed the handling of a mouse drag to a more general mouse move"
83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
#ifndef _WXSIMPLEVIEWERWX_H_
|
|
#define _WXSIMPLEVIEWERWX_H_
|
|
|
|
#include "wx/defs.h"
|
|
#include "wx/app.h"
|
|
#include "wx/cursor.h"
|
|
#include "wx/glcanvas.h"
|
|
#include <osgViewer/Viewer>
|
|
#include <string>
|
|
|
|
class GraphicsWindowWX : public wxGLCanvas, public osgViewer::GraphicsWindow
|
|
{
|
|
public:
|
|
GraphicsWindowWX(wxWindow *parent, wxWindowID id = wxID_ANY,
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
const wxSize& size = wxDefaultSize, long style = 0,
|
|
const wxString& name = wxT("TestGLCanvas"),
|
|
int *attributes = 0);
|
|
|
|
~GraphicsWindowWX();
|
|
|
|
void init();
|
|
|
|
void OnPaint(wxPaintEvent& event);
|
|
void OnSize(wxSizeEvent& event);
|
|
void OnEraseBackground(wxEraseEvent& event);
|
|
|
|
void OnChar(wxKeyEvent &event);
|
|
void OnKeyUp(wxKeyEvent &event);
|
|
|
|
void OnMouseEnter(wxMouseEvent &event);
|
|
void OnMouseDown(wxMouseEvent &event);
|
|
void OnMouseUp(wxMouseEvent &event);
|
|
void OnMouseMotion(wxMouseEvent &event);
|
|
|
|
|
|
//
|
|
// GraphicsWindow interface
|
|
//
|
|
void grabFocus();
|
|
void grabFocusIfPointerInWindow();
|
|
void useCursor(bool cursorOn);
|
|
|
|
bool makeCurrentImplementation();
|
|
void swapBuffersImplementation();
|
|
|
|
// not implemented yet...just use dummy implementation to get working.
|
|
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; }
|
|
|
|
private:
|
|
wxCursor _oldCursor;
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
};
|
|
|
|
class MainFrame : public wxFrame
|
|
{
|
|
public:
|
|
MainFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
|
const wxSize& size, long style = wxDEFAULT_FRAME_STYLE);
|
|
|
|
void SetViewer(osgViewer::Viewer *viewer);
|
|
void OnIdle(wxIdleEvent& event);
|
|
|
|
private:
|
|
osg::ref_ptr<osgViewer::Viewer> _viewer;
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
};
|
|
|
|
/* Define a new application type */
|
|
class wxOsgApp : public wxApp
|
|
{
|
|
public:
|
|
bool OnInit();
|
|
};
|
|
|
|
#endif // _WXSIMPLEVIEWERWX_H_
|