Windows cursor implementation.
This does not (yet) support custom cursor images, but can be easily extended to do so.
This commit is contained in:
parent
7cad407843
commit
23a1d4338d
3 changed files with 43 additions and 35 deletions
|
@ -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)
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
#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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue