]> git.mxchange.org Git - flightgear.git/commitdiff
Windows cursor implementation.
authorJames Turner <zakalawe@mac.com>
Wed, 6 Mar 2013 18:22:37 +0000 (18:22 +0000)
committerJames Turner <zakalawe@mac.com>
Wed, 6 Mar 2013 18:22:37 +0000 (18:22 +0000)
This does not (yet) support custom cursor images, but can be easily
extended to do so.

src/GUI/CMakeLists.txt
src/GUI/MouseCursor.cxx
src/GUI/WindowsMouseCursor.cxx

index 469117e4f828fd99cda503a68d8e76f717a6fbe5..6f36a1da21f0f204096049c9903ccecf16166532 100644 (file)
@@ -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)
index 541a725a051ef0a06c617efeae3d26ffe458cd69..aad589d64c0ce4b441cd69f917f9a745a7287888 100644 (file)
 #include "CocoaMouseCursor.hxx"
 #endif
 
+#ifdef SG_WINDOWS
+#include "WindowsMouseCursor.hxx"
+#endif
+
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Viewer/renderer.hxx>
@@ -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<osgViewer::GraphicsWindow*> 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
                 
index a2417f17e820b6fd95fa5a6cdd6d7a943d14e60c..9e2e29c8a2ac11f22c5a489e435548bd96306f08 100644 (file)
@@ -1,4 +1,4 @@
-// WindowsMouseCursor.cxx - mouse cursor using Cocoa APIs
+// WindowsMouseCursor.cxx - mouse cursor using Windows APIs
 
 // Copyright (C) 2013 James Turner <zakalawe@mac.com>
 //
@@ -33,28 +33,21 @@ class WindowsMouseCursor::WindowsMouseCursorPrivate
 {
 public:
     Cursor activeCursorKey;
-    
+    bool hideUntilMove;
+
     typedef std::map<Cursor, HCURSOR> 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);
     }
 }