1
0
Fork 0

Windows cursor implementation.

This does not (yet) support custom cursor images, but can be easily
extended to do so.
This commit is contained in:
James Turner 2013-03-06 18:22:37 +00:00
parent 7cad407843
commit 23a1d4338d
3 changed files with 43 additions and 35 deletions

View file

@ -42,7 +42,14 @@ set(HEADERS
PUIFileDialog.hxx PUIFileDialog.hxx
MouseCursor.hxx MouseCursor.hxx
) )
if(WIN32)
message(STATUS "on Windows")
list(APPEND HEADERS WindowsMouseCursor.hxx)
list(APPEND SOURCES WindowsMouseCursor.cxx)
endif()
if (APPLE) if (APPLE)
list(APPEND HEADERS FGCocoaMenuBar.hxx CocoaFileDialog.hxx CocoaMouseCursor.hxx) list(APPEND HEADERS FGCocoaMenuBar.hxx CocoaFileDialog.hxx CocoaMouseCursor.hxx)
list(APPEND SOURCES FGCocoaMenuBar.mm CocoaFileDialog.mm CocoaMouseCursor.mm) list(APPEND SOURCES FGCocoaMenuBar.mm CocoaFileDialog.mm CocoaMouseCursor.mm)

View file

@ -37,6 +37,10 @@
#include "CocoaMouseCursor.hxx" #include "CocoaMouseCursor.hxx"
#endif #endif
#ifdef SG_WINDOWS
#include "WindowsMouseCursor.hxx"
#endif
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Viewer/renderer.hxx> #include <Viewer/renderer.hxx>
@ -99,12 +103,14 @@ private:
osgViewer::GraphicsWindow::MouseCursor translateCursor(Cursor aCursor) osgViewer::GraphicsWindow::MouseCursor translateCursor(Cursor aCursor)
{ {
switch (aCursor) { switch (aCursor) {
case CURSOR_ARROW: return osgViewer::GraphicsWindow::RightArrowCursor;
case CURSOR_HAND: return osgViewer::GraphicsWindow::HandCursor; case CURSOR_HAND: return osgViewer::GraphicsWindow::HandCursor;
case CURSOR_CROSSHAIR: return osgViewer::GraphicsWindow::CrosshairCursor; case CURSOR_CROSSHAIR: return osgViewer::GraphicsWindow::CrosshairCursor;
case CURSOR_IBEAM: return osgViewer::GraphicsWindow::TextCursor; case CURSOR_IBEAM: return osgViewer::GraphicsWindow::TextCursor;
case CURSOR_LEFT_RIGHT: return osgViewer::GraphicsWindow::LeftRightCursor; 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; static_instance = new CocoaMouseCursor;
} }
#endif #endif
#ifdef SG_WINDOWS
// 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 // X11

View 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> // Copyright (C) 2013 James Turner <zakalawe@mac.com>
// //
@ -33,28 +33,21 @@ class WindowsMouseCursor::WindowsMouseCursorPrivate
{ {
public: public:
Cursor activeCursorKey; Cursor activeCursorKey;
bool hideUntilMove;
typedef std::map<Cursor, HCURSOR> CursorMap; typedef std::map<Cursor, HCURSOR> CursorMap;
CursorMap cursors; CursorMap cursors;
}; };
HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey) 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) { switch (aKey) {
case FGMouseCursor::CURSOR_HAND: return [NSCursor pointingHandCursor]; case FGMouseCursor::CURSOR_HAND: return LoadCursor(NULL, IDC_HAND);
case FGMouseCursor::CURSOR_CROSSHAIR: return [NSCursor crosshairCursor]; case FGMouseCursor::CURSOR_CROSSHAIR: return LoadCursor(NULL, IDC_CROSS);
case FGMouseCursor::CURSOR_IBEAM: return [NSCursor IBeamCursor]; 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. #if 0
case FGMouseCursor::CURSOR_LEFT_RIGHT: return [NSCursor resizeLeftRightCursor];
case FGMouseCursor::CURSOR_SPIN_CW: case FGMouseCursor::CURSOR_SPIN_CW:
path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"]; path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"];
img = [[NSImage alloc] initWithContentsOfFile:path]; img = [[NSImage alloc] initWithContentsOfFile:path];
@ -64,17 +57,17 @@ HCURSOR windowsCursorForKey(FGMouseCursor::Cursor aKey)
path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"]; path = [path stringByAppendingPathComponent:@"cursor-spin-cw.png"];
img = [[NSImage alloc] initWithContentsOfFile:path]; img = [[NSImage alloc] initWithContentsOfFile:path];
return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)]; return [[NSCursor alloc] initWithImage:img hotSpot:NSMakePoint(16,16)];
#endif
default: return [NSCursor arrowCursor]; default: return LoadCursor(NULL, IDC_ARROW);
} }
#endif
} }
WindowsMouseCursor::WindowsMouseCursor() : WindowsMouseCursor::WindowsMouseCursor() :
d(new WindowsMouseCursorPrivate) d(new WindowsMouseCursorPrivate)
{ {
d->hideUntilMove = false;
d->activeCursorKey = CURSOR_ARROW;
} }
WindowsMouseCursor::~WindowsMouseCursor() WindowsMouseCursor::~WindowsMouseCursor()
@ -92,23 +85,16 @@ void WindowsMouseCursor::setCursor(Cursor aCursor)
d->activeCursorKey = aCursor; d->activeCursorKey = aCursor;
if (d->cursors.find(aCursor) == d->cursors.end()) { 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) void WindowsMouseCursor::setCursorVisible(bool aVis)
{ {
d->hideUntilMove = false; // cancel this d->hideUntilMove = false; // cancel this
ShowCursor(aVis);
if (aVis) {
ShowCursor();
} else {
HideCursor();
}
} }
void WindowsMouseCursor::hideCursorUntilMouseMove() void WindowsMouseCursor::hideCursorUntilMouseMove()
@ -118,13 +104,13 @@ void WindowsMouseCursor::hideCursorUntilMouseMove()
} }
d->hideUntilMove = true; d->hideUntilMove = true;
HideCursor(); ShowCursor(false);
} }
void WindowsMouseCursor::mouseMoved() void WindowsMouseCursor::mouseMoved()
{ {
if (d->hideUntilMove) { if (d->hideUntilMove) {
d->hideUntilMove = false; d->hideUntilMove = false;
ShowCursor(); ShowCursor(true);
} }
} }