| 1 | #include <iostream> |
|---|
| 2 | |
|---|
| 3 | #include "FOX_OSG.h" |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | FXDEFMAP(GraphicsWindowFOX) GraphicsWindowFOX_Map[] = { |
|---|
| 7 | |
|---|
| 8 | FXMAPFUNC(SEL_CONFIGURE, 0, GraphicsWindowFOX::onConfigure), |
|---|
| 9 | FXMAPFUNC(SEL_KEYPRESS, 0, GraphicsWindowFOX::onKeyPress), |
|---|
| 10 | FXMAPFUNC(SEL_KEYRELEASE, 0, GraphicsWindowFOX::onKeyRelease), |
|---|
| 11 | FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, GraphicsWindowFOX::onLeftBtnPress), |
|---|
| 12 | FXMAPFUNC(SEL_LEFTBUTTONRELEASE, 0, GraphicsWindowFOX::onLeftBtnRelease), |
|---|
| 13 | FXMAPFUNC(SEL_MIDDLEBUTTONPRESS, 0, GraphicsWindowFOX::onMiddleBtnPress), |
|---|
| 14 | FXMAPFUNC(SEL_MIDDLEBUTTONRELEASE, 0, GraphicsWindowFOX::onMiddleBtnRelease), |
|---|
| 15 | FXMAPFUNC(SEL_RIGHTBUTTONPRESS, 0, GraphicsWindowFOX::onRightBtnPress), |
|---|
| 16 | FXMAPFUNC(SEL_RIGHTBUTTONRELEASE, 0, GraphicsWindowFOX::onRightBtnRelease), |
|---|
| 17 | FXMAPFUNC(SEL_MOTION, 0, GraphicsWindowFOX::onMotion) |
|---|
| 18 | }; |
|---|
| 19 | |
|---|
| 20 | FXIMPLEMENT(GraphicsWindowFOX, FXGLCanvas, GraphicsWindowFOX_Map, ARRAYNUMBER(GraphicsWindowFOX_Map)) |
|---|
| 21 | |
|---|
| 22 | GraphicsWindowFOX::GraphicsWindowFOX(FXComposite *parent, FXGLVisual *vis, |
|---|
| 23 | FXObject *tgt, FXSelector sel, |
|---|
| 24 | FXuint opts, FXint x, FXint y, |
|---|
| 25 | FXint w, FXint h) |
|---|
| 26 | : FXGLCanvas(parent, vis, tgt, sel, opts, x, y, w, h) |
|---|
| 27 | { |
|---|
| 28 | |
|---|
| 29 | _oldCursor = new FXCursor(parent->getApp(),CURSOR_CROSS); |
|---|
| 30 | |
|---|
| 31 | _traits = new GraphicsContext::Traits; |
|---|
| 32 | _traits->x = x; |
|---|
| 33 | _traits->y = y; |
|---|
| 34 | _traits->width = w; |
|---|
| 35 | _traits->height = h; |
|---|
| 36 | _traits->windowDecoration = false; |
|---|
| 37 | _traits->doubleBuffer = true; |
|---|
| 38 | _traits->sharedContext = 0; |
|---|
| 39 | |
|---|
| 40 | init(); |
|---|
| 41 | |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void GraphicsWindowFOX::init() |
|---|
| 45 | { |
|---|
| 46 | if (valid()) |
|---|
| 47 | { |
|---|
| 48 | setState( new osg::State ); |
|---|
| 49 | getState()->setGraphicsContext(this); |
|---|
| 50 | |
|---|
| 51 | if (_traits.valid() && _traits->sharedContext.valid()) |
|---|
| 52 | { |
|---|
| 53 | getState()->setContextID( _traits->sharedContext->getState()->getContextID() ); |
|---|
| 54 | incrementContextIDUsageCount( getState()->getContextID() ); |
|---|
| 55 | } |
|---|
| 56 | else |
|---|
| 57 | { |
|---|
| 58 | getState()->setContextID( osg::GraphicsContext::createNewContextID() ); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | GraphicsWindowFOX::~GraphicsWindowFOX() |
|---|
| 64 | { |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void GraphicsWindowFOX::grabFocus() |
|---|
| 68 | { |
|---|
| 69 | |
|---|
| 70 | setFocus(); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void GraphicsWindowFOX::grabFocusIfPointerInWindow() |
|---|
| 74 | { |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void GraphicsWindowFOX::useCursor(bool cursorOn) |
|---|
| 79 | { |
|---|
| 80 | if (cursorOn) { |
|---|
| 81 | |
|---|
| 82 | setDefaultCursor(_oldCursor); |
|---|
| 83 | } |
|---|
| 84 | else { |
|---|
| 85 | setDefaultCursor(NULL); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | bool GraphicsWindowFOX::makeCurrentImplementation() |
|---|
| 90 | { |
|---|
| 91 | FXGLCanvas::makeCurrent(); |
|---|
| 92 | return true; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | bool GraphicsWindowFOX::releaseContext() |
|---|
| 96 | { |
|---|
| 97 | FXGLCanvas::makeNonCurrent(); |
|---|
| 98 | return true; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | void GraphicsWindowFOX::swapBuffersImplementation() |
|---|
| 102 | { |
|---|
| 103 | FXGLCanvas::swapBuffers(); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | long GraphicsWindowFOX::onConfigure(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 108 | { |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | getEventQueue()->windowResize(0, 0, getWidth(), getHeight()); |
|---|
| 112 | resized(0, 0, getWidth(), getHeight()); |
|---|
| 113 | |
|---|
| 114 | return FXGLCanvas::onConfigure(sender, sel, ptr); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | long GraphicsWindowFOX::onKeyPress(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 118 | { |
|---|
| 119 | int key = ((FXEvent*)ptr)->code; |
|---|
| 120 | getEventQueue()->keyPress(key); |
|---|
| 121 | |
|---|
| 122 | return FXGLCanvas::onKeyPress(sender, sel, ptr); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | long GraphicsWindowFOX::onKeyRelease(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 126 | { |
|---|
| 127 | int key = ((FXEvent*)ptr)->code; |
|---|
| 128 | getEventQueue()->keyRelease(key); |
|---|
| 129 | |
|---|
| 130 | return FXGLCanvas::onKeyRelease(sender, sel, ptr); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | long GraphicsWindowFOX::onLeftBtnPress(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 134 | { |
|---|
| 135 | handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr); |
|---|
| 136 | |
|---|
| 137 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 138 | getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 1); |
|---|
| 139 | |
|---|
| 140 | return FXGLCanvas::onLeftBtnPress(sender, sel, ptr); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | long GraphicsWindowFOX::onLeftBtnRelease(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 144 | { |
|---|
| 145 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 146 | getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 1); |
|---|
| 147 | |
|---|
| 148 | return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | long GraphicsWindowFOX::onMiddleBtnPress(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 152 | { |
|---|
| 153 | handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr); |
|---|
| 154 | |
|---|
| 155 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 156 | getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 2); |
|---|
| 157 | |
|---|
| 158 | return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | long GraphicsWindowFOX::onMiddleBtnRelease(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 162 | { |
|---|
| 163 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 164 | getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 2); |
|---|
| 165 | |
|---|
| 166 | return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | long GraphicsWindowFOX::onRightBtnPress(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 170 | { |
|---|
| 171 | handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr); |
|---|
| 172 | |
|---|
| 173 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 174 | getEventQueue()->mouseButtonPress(event->click_x, event->click_y, 3); |
|---|
| 175 | |
|---|
| 176 | return FXGLCanvas::onRightBtnPress(sender, sel, ptr); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | long GraphicsWindowFOX::onRightBtnRelease(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 180 | { |
|---|
| 181 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 182 | getEventQueue()->mouseButtonRelease(event->click_x, event->click_y, 3); |
|---|
| 183 | |
|---|
| 184 | return FXGLCanvas::onRightBtnRelease(sender, sel, ptr); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | long GraphicsWindowFOX::onMotion(FXObject *sender, FXSelector sel, void* ptr) |
|---|
| 188 | { |
|---|
| 189 | FXEvent* event=(FXEvent*)ptr; |
|---|
| 190 | getEventQueue()->mouseMotion(event->win_x, event->win_y); |
|---|
| 191 | |
|---|
| 192 | return FXGLCanvas::onMotion(sender, sel, ptr); |
|---|
| 193 | } |
|---|