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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#include <iostream>
#include "FOX_OSG.h"
// Map
FXDEFMAP(GraphicsWindowFOX) GraphicsWindowFOX_Map[] = {
//________Message_Type_________ ___ID___ ________Message_Handler________
FXMAPFUNC(SEL_CONFIGURE, 0, GraphicsWindowFOX::onConfigure),
FXMAPFUNC(SEL_KEYPRESS, 0, GraphicsWindowFOX::onKeyPress),
FXMAPFUNC(SEL_KEYRELEASE, 0, GraphicsWindowFOX::onKeyRelease),
FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, GraphicsWindowFOX::onLeftBtnPress),
FXMAPFUNC(SEL_LEFTBUTTONRELEASE, 0, GraphicsWindowFOX::onLeftBtnRelease),
FXMAPFUNC(SEL_MIDDLEBUTTONPRESS, 0, GraphicsWindowFOX::onMiddleBtnPress),
FXMAPFUNC(SEL_MIDDLEBUTTONRELEASE, 0, GraphicsWindowFOX::onMiddleBtnRelease),
FXMAPFUNC(SEL_RIGHTBUTTONPRESS, 0, GraphicsWindowFOX::onRightBtnPress),
FXMAPFUNC(SEL_RIGHTBUTTONRELEASE, 0, GraphicsWindowFOX::onRightBtnRelease),
FXMAPFUNC(SEL_MOTION, 0, GraphicsWindowFOX::onMotion)
};
FXIMPLEMENT(GraphicsWindowFOX, FXGLCanvas, GraphicsWindowFOX_Map, ARRAYNUMBER(GraphicsWindowFOX_Map))
GraphicsWindowFOX::GraphicsWindowFOX(FXComposite *parent, FXGLVisual *vis,
FXObject *tgt, FXSelector sel,
FXuint opts, FXint x, FXint y,
FXint w, FXint h)
: FXGLCanvas(parent, vis, tgt, sel, opts, x, y, w, h)
{
// default cursor to standard
_oldCursor = new FXCursor(parent->getApp(),CURSOR_CROSS);
_traits = new GraphicsContext::Traits;
_traits->x = x;
_traits->y = y;
_traits->width = w;
_traits->height = h;
_traits->windowDecoration = false;
_traits->doubleBuffer = true;
_traits->sharedContext = 0;
init();
}
void GraphicsWindowFOX::init()
{
if (valid())
{
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );
}
else
{
getState()->setContextID( osg::GraphicsContext::createNewContextID() );
}
}
}
GraphicsWindowFOX::~GraphicsWindowFOX()
{
}
void GraphicsWindowFOX::grabFocus()
{
// focus this window
setFocus();
}
void GraphicsWindowFOX::grabFocusIfPointerInWindow()
{
// do nothing
}
void GraphicsWindowFOX::useCursor(bool cursorOn)
{
if (cursorOn) {
// show the old cursor
setDefaultCursor(_oldCursor);
}
else {
setDefaultCursor(NULL);
}
}
bool GraphicsWindowFOX::makeCurrentImplementation()
{
FXGLCanvas::makeCurrent();
return true;
}
bool GraphicsWindowFOX::releaseContext()
{
FXGLCanvas::makeNonCurrent();
return true;
}
void GraphicsWindowFOX::swapBuffersImplementation()
{
FXGLCanvas::swapBuffers();
}
long GraphicsWindowFOX::onConfigure(FXObject *sender, FXSelector sel, void* ptr)
{
// set GL viewport (not called by FXGLCanvas::onConfigure on all platforms...)
// update the window dimensions, in case the window has been resized.
getEventQueue()->windowResize(0, 0, getWidth(), getHeight());
resized(0, 0, getWidth(), getHeight());
return FXGLCanvas::onConfigure(sender, sel, ptr);
}
long GraphicsWindowFOX::onKeyPress(FXObject *sender, FXSelector sel, void* ptr)
{
int key = ((FXEvent*)ptr)->code;
getEventQueue()->keyPress(key);
return FXGLCanvas::onKeyPress(sender, sel, ptr);
}
long GraphicsWindowFOX::onKeyRelease(FXObject *sender, FXSelector sel, void* ptr)
{
int key = ((FXEvent*)ptr)->code;
getEventQueue()->keyRelease(key);
return FXGLCanvas::onKeyRelease(sender, sel, ptr);
}
long GraphicsWindowFOX::onLeftBtnPress(FXObject *sender, FXSelector sel, void* ptr)
{
handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 1);
return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
}
long GraphicsWindowFOX::onLeftBtnRelease(FXObject *sender, FXSelector sel, void* ptr)
{
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 1);
return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
}
long GraphicsWindowFOX::onMiddleBtnPress(FXObject *sender, FXSelector sel, void* ptr)
{
handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 2);
return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
}
long GraphicsWindowFOX::onMiddleBtnRelease(FXObject *sender, FXSelector sel, void* ptr)
{
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 2);
return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
}
long GraphicsWindowFOX::onRightBtnPress(FXObject *sender, FXSelector sel, void* ptr)
{
handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 3);
return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
}
long GraphicsWindowFOX::onRightBtnRelease(FXObject *sender, FXSelector sel, void* ptr)
{
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 3);
return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
}
long GraphicsWindowFOX::onMotion(FXObject *sender, FXSelector sel, void* ptr)
{
FXEvent* event=(FXEvent*)ptr;
getEventQueue()->mouseMotion(event->win_x, event->win_y);
return FXGLCanvas::onMotion(sender, sel, ptr);
}
|