From: James Turner Date: Wed, 6 Mar 2013 18:22:37 +0000 (+0000) Subject: Windows cursor implementation. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=23a1d4338d2f96670caade629ea3d12b48f407bf;p=flightgear.git Windows cursor implementation. This does not (yet) support custom cursor images, but can be easily extended to do so. --- diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index 469117e4f..6f36a1da2 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -42,7 +42,14 @@ set(HEADERS PUIFileDialog.hxx MouseCursor.hxx ) - + +if(WIN32) + message(STATUS "on Windows") + + list(APPEND HEADERS WindowsMouseCursor.hxx) + list(APPEND SOURCES WindowsMouseCursor.cxx) +endif() + if (APPLE) list(APPEND HEADERS FGCocoaMenuBar.hxx CocoaFileDialog.hxx CocoaMouseCursor.hxx) list(APPEND SOURCES FGCocoaMenuBar.mm CocoaFileDialog.mm CocoaMouseCursor.mm) diff --git a/src/GUI/MouseCursor.cxx b/src/GUI/MouseCursor.cxx index 541a725a0..aad589d64 100644 --- a/src/GUI/MouseCursor.cxx +++ b/src/GUI/MouseCursor.cxx @@ -37,6 +37,10 @@ #include "CocoaMouseCursor.hxx" #endif +#ifdef SG_WINDOWS +#include "WindowsMouseCursor.hxx" +#endif + #include
#include
#include @@ -99,12 +103,14 @@ private: osgViewer::GraphicsWindow::MouseCursor translateCursor(Cursor aCursor) { switch (aCursor) { + case CURSOR_ARROW: return osgViewer::GraphicsWindow::RightArrowCursor; case CURSOR_HAND: return osgViewer::GraphicsWindow::HandCursor; case CURSOR_CROSSHAIR: return osgViewer::GraphicsWindow::CrosshairCursor; case CURSOR_IBEAM: return osgViewer::GraphicsWindow::TextCursor; case CURSOR_LEFT_RIGHT: return osgViewer::GraphicsWindow::LeftRightCursor; - default: return osgViewer::GraphicsWindow::InheritCursor; + default: + return osgViewer::GraphicsWindow::RightArrowCursor; } } @@ -151,8 +157,17 @@ FGMouseCursor* FGMouseCursor::instance() static_instance = new CocoaMouseCursor; } #endif - - // windows + #ifdef SG_WINDOWS + // set osgViewer cursor inherit, otherwise it will interefere + std::vector gws; + globals->get_renderer()->getViewer()->getWindows(gws); + BOOST_FOREACH(osgViewer::GraphicsWindow* gw, gws) { + gw->setCursor(osgViewer::GraphicsWindow::InheritCursor); + } + + // and create our real implementation + static_instance = new WindowsMouseCursor; + #endif // X11 diff --git a/src/GUI/WindowsMouseCursor.cxx b/src/GUI/WindowsMouseCursor.cxx index a2417f17e..9e2e29c8a 100644 --- a/src/GUI/WindowsMouseCursor.cxx +++ b/src/GUI/WindowsMouseCursor.cxx @@ -1,4 +1,4 @@ -// WindowsMouseCursor.cxx - mouse cursor using Cocoa APIs +// WindowsMouseCursor.cxx - mouse cursor using Windows APIs // Copyright (C) 2013 James Turner // @@ -33,28 +33,21 @@ class WindowsMouseCursor::WindowsMouseCursorPrivate { public: Cursor activeCursorKey; - + bool hideUntilMove; + typedef std::map CursorMap; CursorMap cursors; }; HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey) { - #if 0 - NSImage* img = nil; - - NSString* path = [NSString stringWithCString:globals->get_fg_root().c_str() - encoding:NSUTF8StringEncoding]; - path = [path stringByAppendingPathComponent:@"gui"]; - switch (aKey) { - case FGMouseCursor::CURSOR_HAND: return [NSCursor pointingHandCursor]; - case FGMouseCursor::CURSOR_CROSSHAIR: return [NSCursor crosshairCursor]; - case FGMouseCursor::CURSOR_IBEAM: return [NSCursor IBeamCursor]; + case FGMouseCursor::CURSOR_HAND: return LoadCursor(NULL, IDC_HAND); + case FGMouseCursor::CURSOR_CROSSHAIR: return LoadCursor(NULL, IDC_CROSS); + case FGMouseCursor::CURSOR_IBEAM: return LoadCursor(NULL, IDC_IBEAM); + case FGMouseCursor::CURSOR_LEFT_RIGHT: return LoadCursor( NULL, IDC_SIZEWE ); - // FIXME - use a proper left-right cursor here. - case FGMouseCursor::CURSOR_LEFT_RIGHT: return [NSCursor resizeLeftRightCursor]; - +#if 0 case FGMouseCursor::CURSOR_SPIN_CW: path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"]; img = [[NSImage alloc] initWithContentsOfFile:path]; @@ -64,17 +57,17 @@ HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey) path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"]; img = [[NSImage alloc] initWithContentsOfFile:path]; return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)]; - - default: return [NSCursor arrowCursor]; +#endif + default: return LoadCursor(NULL, IDC_ARROW); } -#endif } WindowsMouseCursor::WindowsMouseCursor() : d(new WindowsMouseCursorPrivate) { - + d->hideUntilMove = false; + d->activeCursorKey = CURSOR_ARROW; } WindowsMouseCursor::~WindowsMouseCursor() @@ -92,23 +85,16 @@ void WindowsMouseCursor::setCursor(Cursor aCursor) d->activeCursorKey = aCursor; if (d->cursors.find(aCursor) == d->cursors.end()) { - d->cursors[key] = windowsCursorForKey(aCursor); + d->cursors[aCursor] = windowsCursorForKey(aCursor); } - - SetCursor(windowsCursorForKey(d->cursors[key])); + SetCursor(d->cursors[aCursor]); } void WindowsMouseCursor::setCursorVisible(bool aVis) { d->hideUntilMove = false; // cancel this - - if (aVis) { - ShowCursor(); - } else { - - HideCursor(); - } + ShowCursor(aVis); } void WindowsMouseCursor::hideCursorUntilMouseMove() @@ -118,13 +104,13 @@ void WindowsMouseCursor::hideCursorUntilMouseMove() } d->hideUntilMove = true; - HideCursor(); + ShowCursor(false); } void WindowsMouseCursor::mouseMoved() { if (d->hideUntilMove) { d->hideUntilMove = false; - ShowCursor(); + ShowCursor(true); } }