Add experimental option to use native mouse cursors (and some renames of cursor names)

This commit is contained in:
David Capello 2014-08-10 19:51:14 -03:00
parent f48440fe71
commit 1c324c9b14
26 changed files with 488 additions and 168 deletions

View File

@ -89,22 +89,24 @@
<cursor id="hand" x="80" y="48" w="16" h="16" focusx="5" focusy="3" />
<cursor id="scroll" x="80" y="64" w="16" h="16" focusx="8" focusy="8" />
<cursor id="move" x="80" y="80" w="16" h="16" focusx="0" focusy="0" />
<cursor id="size_tl" x="80" y="96" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_t" x="80" y="112" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_tr" x="80" y="128" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_l" x="80" y="144" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_r" x="80" y="160" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_bl" x="80" y="176" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_b" x="80" y="192" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_br" x="80" y="208" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_tl" x="240" y="160" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_tr" x="256" y="160" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_l" x="240" y="176" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_r" x="256" y="176" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_t" x="240" y="192" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_b" x="256" y="192" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_bl" x="240" y="208" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_br" x="256" y="208" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_ns" x="80" y="112" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_we" x="80" y="144" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_n" x="80" y="112" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_ne" x="80" y="128" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_e" x="80" y="160" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_se" x="80" y="208" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_s" x="80" y="192" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_sw" x="80" y="176" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_w" x="80" y="144" w="16" h="16" focusx="8" focusy="8" />
<cursor id="size_nw" x="80" y="96" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_n" x="240" y="192" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_ne" x="256" y="160" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_e" x="256" y="176" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_se" x="256" y="208" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_s" x="256" y="192" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_sw" x="240" y="208" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_w" x="240" y="176" w="16" h="16" focusx="8" focusy="8" />
<cursor id="rotate_nw" x="240" y="160" w="16" h="16" focusx="8" focusy="8" />
<cursor id="eyedropper" x="80" y="224" w="16" h="16" focusx="0" focusy="15" />
<cursor id="magnifier" x="80" y="240" w="16" h="16" focusx="5" focusy="5" />
</cursors>

View File

@ -10,6 +10,7 @@
<listitem text="Editor" value="section_editor" />
<listitem text="Grid &amp;&amp; Background" value="section_grid" />
<listitem text="Undo" value="section_undo" />
<listitem text="Experimental" value="section_experimental" />
</listbox>
</view>
@ -74,6 +75,13 @@
<check id="undo_goto_modified" text="Go to modified frame/layer" tooltip="When it's enabled each time you undo/redo&#10;the current frame &amp; layer will be modified&#10;to focus the undid/redid change." />
</box>
</vbox>
<!-- Experimental -->
<vbox id="section_experimental">
<separator text="User Interface" horizontal="true" />
<check id="native_cursor" text="Use native mouse cursor" />
</vbox>
</panel>
</hbox>
<separator horizontal="true" />

View File

@ -154,10 +154,12 @@ if(USE_SHARED_ALLEGRO4)
include_directories(${LIBALLEGRO4_INCLUDE_DIR})
else()
add_definitions(-DALLEGRO4_WITH_RESIZE_PATCH)
add_definitions(-DALLEGRO4_WITH_EXTRA_CURSORS)
# Use patched version of Allegro 4 (with window resize support).
add_subdirectory(allegro)
set(libs3rdparty ${libs3rdparty} allegro)
add_definitions(-DALLEGRO4_WITH_RESIZE_PATCH)
endif()
######################################################################

View File

@ -63,13 +63,31 @@ AL_FUNC(void, enable_hardware_cursor, (void));
AL_FUNC(void, disable_hardware_cursor, (void));
/* Mouse cursors */
#define MOUSE_CURSOR_NONE 0
#define MOUSE_CURSOR_ALLEGRO 1
#define MOUSE_CURSOR_ARROW 2
#define MOUSE_CURSOR_BUSY 3
#define MOUSE_CURSOR_QUESTION 4
#define MOUSE_CURSOR_EDIT 5
#define AL_NUM_MOUSE_CURSORS 6
enum {
MOUSE_CURSOR_NONE,
MOUSE_CURSOR_ALLEGRO,
MOUSE_CURSOR_ARROW,
MOUSE_CURSOR_BUSY,
MOUSE_CURSOR_QUESTION,
MOUSE_CURSOR_EDIT,
#ifdef ALLEGRO4_WITH_EXTRA_CURSORS
MOUSE_CURSOR_CROSS,
MOUSE_CURSOR_MOVE,
MOUSE_CURSOR_LINK,
MOUSE_CURSOR_FORBIDDEN,
MOUSE_CURSOR_SIZE_N,
MOUSE_CURSOR_SIZE_NE,
MOUSE_CURSOR_SIZE_E,
MOUSE_CURSOR_SIZE_SE,
MOUSE_CURSOR_SIZE_S,
MOUSE_CURSOR_SIZE_SW,
MOUSE_CURSOR_SIZE_W,
MOUSE_CURSOR_SIZE_NW,
MOUSE_CURSOR_SIZE_NS,
MOUSE_CURSOR_SIZE_WE,
#endif
AL_NUM_MOUSE_CURSORS
};
AL_VAR(struct BITMAP *, mouse_sprite);
AL_VAR(int, mouse_x_focus);

View File

@ -0,0 +1,2 @@
void osx_hide_native_mouse();
void osx_show_native_mouse();

View File

@ -12,6 +12,8 @@
*
* By Angelo Mottola.
*
* Some changes by to show/hide the native cursor by David Capello.
*
* See readme.txt for copyright information.
*/
@ -20,6 +22,8 @@
#include "allegro/internal/aintern.h"
#include "allegro/platform/aintosx.h"
#include "qzmouse.h"
#ifndef ALLEGRO_MACOSX
#error Something is wrong with the makefile
#endif
@ -58,6 +62,8 @@ int osx_mouse_warped = FALSE;
int osx_skip_mouse_move = FALSE;
NSTrackingRectTag osx_mouse_tracking_rect = -1;
static int osx_using_native_cursor = FALSE;
static int osx_native_mouse_visiblity = TRUE; // By default the OS cursor is visible
static NSCursor *cursor = NULL, *current_cursor = NULL;
static NSCursor *requested_cursor = NULL;
@ -179,7 +185,7 @@ static int osx_mouse_init(void)
_unix_unlock_mutex(osx_event_mutex);
_mouse_on = TRUE;
[NSCursor performSelectorOnMainThread: @selector(hide) withObject: nil waitUntilDone: NO];
osx_hide_native_mouse();
return max_buttons;
}
@ -358,6 +364,9 @@ int osx_mouse_show(BITMAP *bmp, int x, int y)
void osx_mouse_hide(void)
{
osx_change_cursor(osx_blank_cursor);
osx_using_native_cursor = FALSE;
osx_hide_native_mouse();
}
@ -388,21 +397,85 @@ void osx_enable_hardware_cursor(AL_CONST int mode)
static int osx_select_system_cursor(AL_CONST int cursor)
{
switch (cursor) {
case MOUSE_CURSOR_ARROW:
requested_cursor = [NSCursor arrowCursor];
break;
case MOUSE_CURSOR_EDIT:
requested_cursor = [NSCursor IBeamCursor];
break;
default:
return 0;
case MOUSE_CURSOR_ARROW:
case MOUSE_CURSOR_BUSY:
requested_cursor = [NSCursor arrowCursor];
break;
case MOUSE_CURSOR_EDIT:
requested_cursor = [NSCursor IBeamCursor];
break;
#ifdef ALLEGRO4_WITH_EXTRA_CURSORS
// case MOUSE_CURSOR_CROSS:
// requested_cursor = [NSCursor crossCursor];
// break;
case MOUSE_CURSOR_MOVE:
requested_cursor = [NSCursor openHandCursor];
break;
case MOUSE_CURSOR_LINK:
requested_cursor = [NSCursor pointingHandCursor];
break;
case MOUSE_CURSOR_FORBIDDEN:
requested_cursor = [NSCursor operationNotAllowedCursor];
break;
case MOUSE_CURSOR_SIZE_N:
requested_cursor = [NSCursor resizeUpCursor]; break;
break;
case MOUSE_CURSOR_SIZE_S:
requested_cursor = [NSCursor resizeDownCursor]; break;
break;
case MOUSE_CURSOR_SIZE_NS:
requested_cursor = [NSCursor resizeUpDownCursor]; break;
break;
case MOUSE_CURSOR_SIZE_W:
requested_cursor = [NSCursor resizeLeftCursor];
break;
case MOUSE_CURSOR_SIZE_E:
requested_cursor = [NSCursor resizeRightCursor];
break;
case MOUSE_CURSOR_SIZE_WE:
requested_cursor = [NSCursor resizeLeftRightCursor];
break;
case MOUSE_CURSOR_SIZE_NW:
case MOUSE_CURSOR_SIZE_SE:
requested_cursor = [NSCursor arrowCursor];
break;
case MOUSE_CURSOR_SIZE_NE:
case MOUSE_CURSOR_SIZE_SW:
requested_cursor = [NSCursor arrowCursor];
break;
#endif
default:
osx_using_native_cursor = FALSE;
osx_hide_native_mouse();
return 0;
}
osx_change_cursor(requested_cursor);
osx_using_native_cursor = TRUE;
osx_show_native_mouse();
return cursor;
}
void osx_hide_native_mouse()
{
if (osx_native_mouse_visiblity) {
osx_native_mouse_visiblity = FALSE;
[NSCursor performSelectorOnMainThread: @selector(hide) withObject: nil waitUntilDone: NO];
}
}
void osx_show_native_mouse()
{
if (!osx_native_mouse_visiblity) {
osx_native_mouse_visiblity = TRUE;
[NSCursor performSelectorOnMainThread: @selector(unhide) withObject: nil waitUntilDone: NO];
}
}
/* Local variables: */
/* c-basic-offset: 3 */
/* indent-tabs-mode: nil */

View File

@ -19,6 +19,7 @@
#include "allegro.h"
#include "allegro/internal/aintern.h"
#include "allegro/platform/aintosx.h"
#include "qzmouse.h"
#ifndef ALLEGRO_MACOSX
#error something is wrong with the makefile
@ -225,7 +226,7 @@ void osx_event_handler()
buttons = 0;
if (!_mouse_on) {
_mouse_on = TRUE;
[NSCursor performSelectorOnMainThread: @selector(hide) withObject: nil waitUntilDone: NO];
osx_hide_native_mouse();
}
}
}
@ -298,7 +299,7 @@ void osx_event_handler()
gotmouseevent = YES;
if (!_mouse_on) {
_mouse_on = TRUE;
[NSCursor performSelectorOnMainThread: @selector(hide) withObject: nil waitUntilDone: NO];
osx_hide_native_mouse();
}
}
}
@ -311,7 +312,7 @@ void osx_event_handler()
gotmouseevent = YES;
if (_mouse_on) {
_mouse_on = FALSE;
[NSCursor performSelectorOnMainThread: @selector(unhide) withObject: nil waitUntilDone: NO];
osx_show_native_mouse();
}
}
}

View File

@ -225,20 +225,52 @@ static int mouse_winapi_select_system_cursor(int cursor)
wc = NULL;
switch(cursor) {
case MOUSE_CURSOR_ARROW:
wc = LoadCursor(NULL, IDC_ARROW);
break;
case MOUSE_CURSOR_BUSY:
wc = LoadCursor(NULL, IDC_WAIT);
break;
case MOUSE_CURSOR_QUESTION:
wc = LoadCursor(NULL, IDC_HELP);
break;
case MOUSE_CURSOR_EDIT:
wc = LoadCursor(NULL, IDC_IBEAM);
break;
default:
return 0;
case MOUSE_CURSOR_ARROW:
wc = LoadCursor(NULL, IDC_ARROW);
break;
case MOUSE_CURSOR_BUSY:
wc = LoadCursor(NULL, IDC_WAIT);
break;
case MOUSE_CURSOR_QUESTION:
wc = LoadCursor(NULL, IDC_HELP);
break;
case MOUSE_CURSOR_EDIT:
wc = LoadCursor(NULL, IDC_IBEAM);
break;
#ifdef ALLEGRO4_WITH_EXTRA_CURSORS
case MOUSE_CURSOR_CROSS:
wc = LoadCursor(NULL, IDC_CROSS);
break;
case MOUSE_CURSOR_MOVE:
wc = LoadCursor(NULL, IDC_SIZEALL);
break;
case MOUSE_CURSOR_LINK:
wc = LoadCursor(NULL, IDC_HAND);
break;
case MOUSE_CURSOR_FORBIDDEN:
wc = LoadCursor(NULL, IDC_NO);
break;
case MOUSE_CURSOR_SIZE_N:
case MOUSE_CURSOR_SIZE_S:
case MOUSE_CURSOR_SIZE_NS:
wc = LoadCursor(NULL, IDC_SIZENS);
break;
case MOUSE_CURSOR_SIZE_E:
case MOUSE_CURSOR_SIZE_W:
case MOUSE_CURSOR_SIZE_WE:
wc = LoadCursor(NULL, IDC_SIZEWE);
break;
case MOUSE_CURSOR_SIZE_NW:
case MOUSE_CURSOR_SIZE_SE:
wc = LoadCursor(NULL, IDC_SIZENWSE);
break;
case MOUSE_CURSOR_SIZE_NE:
case MOUSE_CURSOR_SIZE_SW:
wc = LoadCursor(NULL, IDC_SIZENESW);
break;
#endif
default:
return 0;
}
_win_hcursor = wc;

View File

@ -45,6 +45,7 @@
#include "app/modules/palettes.h"
#include "app/recent_files.h"
#include "app/resource_finder.h"
#include "app/settings/settings.h"
#include "app/shell.h"
#include "app/tools/tool_box.h"
#include "app/ui/color_bar.h"
@ -179,8 +180,13 @@ int App::run()
if (isGui()) {
PRINTF("GUI mode\n");
// Setup the GUI screen
// Setup the GUI cursor and redraw screen
ui::set_use_native_cursors(
UIContext::instance()->settings()->experimental()->useNativeCursor());
jmouse_set_cursor(kArrowCursor);
ui::Manager::getDefault()->invalidate();
// Create the main window and show it.

View File

@ -36,6 +36,7 @@
#include "app/util/render.h"
#include "base/bind.h"
#include "raster/image.h"
#include "she/system.h"
#include "ui/ui.h"
#include "generated_options.h"
@ -73,6 +74,9 @@ public:
if (get_config_bool("Options", "AutoShowTimeline", true))
autotimeline()->setSelected(true);
if (m_settings->experimental()->useNativeCursor())
nativeCursor()->setSelected(true);
if (m_settings->getShowSpriteEditorScrollbars())
showScrollbars()->setSelected(true);
@ -144,6 +148,9 @@ public:
m_settings->setUndoSizeLimit(undo_size_limit_value);
m_settings->setUndoGotoModified(undoGotoModified()->isSelected());
// Native cursor
m_settings->experimental()->setUseNativeCursor(nativeCursor()->isSelected());
int new_screen_scaling = screenScale()->getSelectedItemIndex()+1;
if (new_screen_scaling != get_screen_scaling()) {
set_screen_scaling(new_screen_scaling);

View File

@ -41,6 +41,7 @@ namespace app {
class IToolSettings;
class ToolSettingsObserver;
class ISelectionSettings;
class IExperimentalSettings;
class SelectionSettingsObserver;
class GlobalSettingsObserver;
@ -85,6 +86,8 @@ namespace app {
// Specific configuration for the current selection
virtual ISelectionSettings* selection() = 0;
virtual IExperimentalSettings* experimental() = 0;
virtual IColorSwatchesStore* getColorSwatchesStore() = 0;
@ -164,6 +167,13 @@ namespace app {
virtual void removeColorSwatches(app::ColorSwatches* colorSwatches) = 0;
};
class IExperimentalSettings {
public:
virtual ~IExperimentalSettings() { }
virtual bool useNativeCursor() const = 0;
virtual void setUseNativeCursor(bool state) = 0;
};
} // namespace app
#endif

View File

@ -34,6 +34,7 @@
#include "app/ui/color_bar.h"
#include "base/observable.h"
#include "ui/manager.h"
#include "ui/system.h"
#include <algorithm>
#include <allegro/color.h>
@ -396,6 +397,22 @@ ISelectionSettings* UISettingsImpl::selection()
return m_selectionSettings;
}
IExperimentalSettings* UISettingsImpl::experimental()
{
return this;
}
bool UISettingsImpl::useNativeCursor() const
{
return get_config_bool("Options", "NativeCursor", false);
}
void UISettingsImpl::setUseNativeCursor(bool state)
{
set_config_bool("Options", "NativeCursor", state);
ui::set_use_native_cursors(state);
}
//////////////////////////////////////////////////////////////////////
// IDocumentSettings implementation

View File

@ -34,6 +34,7 @@ namespace app {
class UISettingsImpl
: public ISettings
, public IExperimentalSettings
, public IColorSwatchesStore
, base::Observable<GlobalSettingsObserver> {
public:
@ -68,6 +69,12 @@ namespace app {
IColorSwatchesStore* getColorSwatchesStore() OVERRIDE;
ISelectionSettings* selection() OVERRIDE;
IExperimentalSettings* experimental() OVERRIDE;
// IExperimentalSettings implementation
bool useNativeCursor() const OVERRIDE;
void setUseNativeCursor(bool state) OVERRIDE;
// IColorSwatchesStore implementation

View File

@ -127,8 +127,8 @@ bool SelectBoxState::onSetCursor(Editor* editor)
{
if (m_movingRuler >= 0) {
switch (m_rulers[m_movingRuler].getOrientation()) {
case Ruler::Horizontal: jmouse_set_cursor(kSizeTCursor); return true;
case Ruler::Vertical: jmouse_set_cursor(kSizeLCursor); return true;
case Ruler::Horizontal: jmouse_set_cursor(kSizeNSCursor); return true;
case Ruler::Vertical: jmouse_set_cursor(kSizeWECursor); return true;
}
}
@ -139,10 +139,10 @@ bool SelectBoxState::onSetCursor(Editor* editor)
if (touchRuler(editor, *it, x, y)) {
switch (it->getOrientation()) {
case Ruler::Horizontal:
jmouse_set_cursor(kSizeTCursor);
jmouse_set_cursor(kSizeNSCursor);
return true;
case Ruler::Vertical:
jmouse_set_cursor(kSizeLCursor);
jmouse_set_cursor(kSizeWECursor);
return true;
}
}

View File

@ -71,25 +71,25 @@ enum WHEEL_ACTION { WHEEL_NONE,
WHEEL_FRAME };
static CursorType rotated_size_cursors[] = {
kSizeRCursor,
kSizeTRCursor,
kSizeTCursor,
kSizeTLCursor,
kSizeLCursor,
kSizeBLCursor,
kSizeBCursor,
kSizeBRCursor
kSizeECursor,
kSizeNECursor,
kSizeNCursor,
kSizeNWCursor,
kSizeWCursor,
kSizeSWCursor,
kSizeSCursor,
kSizeSECursor
};
static CursorType rotated_rotate_cursors[] = {
kRotateRCursor,
kRotateTRCursor,
kRotateTCursor,
kRotateTLCursor,
kRotateLCursor,
kRotateBLCursor,
kRotateBCursor,
kRotateBRCursor
kRotateECursor,
kRotateNECursor,
kRotateNCursor,
kRotateNWCursor,
kRotateWCursor,
kRotateSWCursor,
kRotateSCursor,
kRotateSECursor
};
#pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
@ -597,22 +597,22 @@ bool StandbyState::Decorator::onSetCursor(Editor* editor)
CursorType newCursor = kArrowCursor;
switch (handle) {
case ScaleNWHandle: newCursor = kSizeTLCursor; break;
case ScaleNHandle: newCursor = kSizeTCursor; break;
case ScaleNEHandle: newCursor = kSizeTRCursor; break;
case ScaleWHandle: newCursor = kSizeLCursor; break;
case ScaleEHandle: newCursor = kSizeRCursor; break;
case ScaleSWHandle: newCursor = kSizeBLCursor; break;
case ScaleSHandle: newCursor = kSizeBCursor; break;
case ScaleSEHandle: newCursor = kSizeBRCursor; break;
case RotateNWHandle: newCursor = kRotateTLCursor; break;
case RotateNHandle: newCursor = kRotateTCursor; break;
case RotateNEHandle: newCursor = kRotateTRCursor; break;
case RotateWHandle: newCursor = kRotateLCursor; break;
case RotateEHandle: newCursor = kRotateRCursor; break;
case RotateSWHandle: newCursor = kRotateBLCursor; break;
case RotateSHandle: newCursor = kRotateBCursor; break;
case RotateSEHandle: newCursor = kRotateBRCursor; break;
case ScaleNWHandle: newCursor = kSizeNWCursor; break;
case ScaleNHandle: newCursor = kSizeNCursor; break;
case ScaleNEHandle: newCursor = kSizeNECursor; break;
case ScaleWHandle: newCursor = kSizeWCursor; break;
case ScaleEHandle: newCursor = kSizeECursor; break;
case ScaleSWHandle: newCursor = kSizeSWCursor; break;
case ScaleSHandle: newCursor = kSizeSCursor; break;
case ScaleSEHandle: newCursor = kSizeSECursor; break;
case RotateNWHandle: newCursor = kRotateNWCursor; break;
case RotateNHandle: newCursor = kRotateNCursor; break;
case RotateNEHandle: newCursor = kRotateNECursor; break;
case RotateWHandle: newCursor = kRotateWCursor; break;
case RotateEHandle: newCursor = kRotateECursor; break;
case RotateSWHandle: newCursor = kRotateSWCursor; break;
case RotateSHandle: newCursor = kRotateSCursor; break;
case RotateSEHandle: newCursor = kRotateSECursor; break;
case PivotHandle: newCursor = kHandCursor; break;
default:
return false;
@ -625,7 +625,7 @@ bool StandbyState::Decorator::onSetCursor(Editor* editor)
angle >>= 16;
angle /= 32;
if (newCursor >= kSizeTLCursor && newCursor <= kSizeBRCursor) {
if (newCursor >= kSizeNCursor && newCursor <= kSizeNWCursor) {
size_t num = sizeof(rotated_size_cursors) / sizeof(rotated_size_cursors[0]);
size_t c;
for (c=num-1; c>0; --c)
@ -634,7 +634,7 @@ bool StandbyState::Decorator::onSetCursor(Editor* editor)
newCursor = rotated_size_cursors[(c+angle) % num];
}
else if (newCursor >= kRotateTLCursor && newCursor <= kRotateBRCursor) {
else if (newCursor >= kRotateNCursor && newCursor <= kRotateNWCursor) {
size_t num = sizeof(rotated_rotate_cursors) / sizeof(rotated_rotate_cursors[0]);
size_t c;
for (c=num-1; c>0; --c)

View File

@ -121,22 +121,28 @@ static const char* cursor_names[kCursorTypes] = {
"hand", // kHandCursor
"scroll", // kScrollCursor
"move", // kMoveCursor
"size_tl", // kSizeTLCursor
"size_t", // kSizeTCursor
"size_tr", // kSizeTRCursor
"size_l", // kSizeLCursor
"size_r", // kSizeRCursor
"size_bl", // kSizeBLCursor
"size_b", // kSizeBCursor
"size_br", // kSizeBRCursor
"rotate_tl", // kRotateTLCursor
"rotate_t", // kRotateTCursor
"rotate_tr", // kRotateTRCursor
"rotate_l", // kRotateLCursor
"rotate_r", // kRotateRCursor
"rotate_bl", // kRotateBLCursor
"rotate_b", // kRotateBCursor
"rotate_br", // kRotateBRCursor
"size_ns", // kSizeNSCursor
"size_we", // kSizeWECursor
"size_n", // kSizeNCursor
"size_ne", // kSizeNECursor
"size_e", // kSizeECursor
"size_se", // kSizeSECursor
"size_s", // kSizeSCursor
"size_sw", // kSizeSWCursor
"size_w", // kSizeWCursor
"size_nw", // kSizeNWCursor
"rotate_n", // kRotateNCursor
"rotate_ne", // kRotateNECursor
"rotate_e", // kRotateECursor
"rotate_se", // kRotateSECursor
"rotate_s", // kRotateSCursor
"rotate_sw", // kRotateSWCursor
"rotate_w", // kRotateWCursor
"rotate_nw", // kRotateNWCursor
"eyedropper", // kEyedropperCursor
"magnifier" // kMagnifierCursor
};

View File

@ -1082,18 +1082,18 @@ void Timeline::setCursor(int x, int y)
// Normal state.
else if (m_hot_part == A_PART_HEADER_ONIONSKIN_RANGE_LEFT
|| m_state == STATE_MOVING_ONIONSKIN_RANGE_LEFT) {
jmouse_set_cursor(kSizeLCursor);
jmouse_set_cursor(kSizeWCursor);
}
else if (m_hot_part == A_PART_HEADER_ONIONSKIN_RANGE_RIGHT
|| m_state == STATE_MOVING_ONIONSKIN_RANGE_RIGHT) {
jmouse_set_cursor(kSizeRCursor);
jmouse_set_cursor(kSizeECursor);
}
else if (m_hot_part == A_PART_RANGE_OUTLINE) {
jmouse_set_cursor(kMoveCursor);
}
else if (mx > m_separator_x-2 && mx < m_separator_x+2) {
// Is the mouse in the separator.
jmouse_set_cursor(kSizeLCursor);
jmouse_set_cursor(kSizeWECursor);
}
else {
jmouse_set_cursor(kArrowCursor);

View File

@ -551,6 +551,47 @@ public:
return m_queue;
}
bool setNativeMouseCursor(NativeCursor cursor) OVERRIDE {
int newCursor = MOUSE_CURSOR_NONE;
switch (cursor) {
case kNoCursor:
newCursor = MOUSE_CURSOR_NONE;
break;
case kArrowCursor:
newCursor = MOUSE_CURSOR_ARROW;
break;
case kIBeamCursor:
newCursor = MOUSE_CURSOR_EDIT;
break;
case kWaitCursor:
newCursor = MOUSE_CURSOR_BUSY;
break;
case kHelpCursor:
newCursor = MOUSE_CURSOR_QUESTION;
break;
#ifdef ALLEGRO4_WITH_EXTRA_CURSORS
case kForbiddenCursor: newCursor = MOUSE_CURSOR_FORBIDDEN; break;
case kMoveCursor: newCursor = MOUSE_CURSOR_MOVE; break;
case kLinkCursor: newCursor = MOUSE_CURSOR_LINK; break;
case kSizeNSCursor: newCursor = MOUSE_CURSOR_SIZE_NS; break;
case kSizeWECursor: newCursor = MOUSE_CURSOR_SIZE_WE; break;
case kSizeNCursor: newCursor = MOUSE_CURSOR_SIZE_N; break;
case kSizeNECursor: newCursor = MOUSE_CURSOR_SIZE_NE; break;
case kSizeECursor: newCursor = MOUSE_CURSOR_SIZE_E; break;
case kSizeSECursor: newCursor = MOUSE_CURSOR_SIZE_SE; break;
case kSizeSCursor: newCursor = MOUSE_CURSOR_SIZE_S; break;
case kSizeSWCursor: newCursor = MOUSE_CURSOR_SIZE_SW; break;
case kSizeWCursor: newCursor = MOUSE_CURSOR_SIZE_W; break;
case kSizeNWCursor: newCursor = MOUSE_CURSOR_SIZE_NW; break;
#endif
default:
return false;
}
return (show_os_cursor(newCursor) == 0);
}
void setMousePosition(const gfx::Point& position) OVERRIDE {
position_mouse(
m_scale * position.x,

View File

@ -9,6 +9,7 @@
#pragma once
#include "gfx/point.h"
#include "she/native_cursor.h"
namespace she {
@ -51,6 +52,7 @@ namespace she {
virtual EventQueue* getEventQueue() = 0;
virtual bool setNativeMouseCursor(NativeCursor cursor) = 0;
virtual void setMousePosition(const gfx::Point& position) = 0;
virtual void captureMouse() = 0;
virtual void releaseMouse() = 0;

38
src/she/native_cursor.h Normal file
View File

@ -0,0 +1,38 @@
// SHE library
// Copyright (C) 2012-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_NATIVE_CURSOR_H_INCLUDED
#define SHE_NATIVE_CURSOR_H_INCLUDED
#pragma once
#include "gfx/fwd.h"
namespace she {
enum NativeCursor {
kNoCursor,
kArrowCursor,
kIBeamCursor,
kWaitCursor,
kLinkCursor,
kHelpCursor,
kForbiddenCursor,
kMoveCursor,
kSizeNSCursor,
kSizeWECursor,
kSizeNCursor,
kSizeNECursor,
kSizeECursor,
kSizeSECursor,
kSizeSCursor,
kSizeSWCursor,
kSizeWCursor,
kSizeNWCursor,
};
} // namespace she
#endif

View File

@ -19,26 +19,33 @@ namespace ui {
kHandCursor,
kScrollCursor,
kMoveCursor,
kSizeTLCursor,
kSizeTCursor,
kSizeTRCursor,
kSizeLCursor,
kSizeRCursor,
kSizeBLCursor,
kSizeBCursor,
kSizeBRCursor,
kRotateTLCursor,
kRotateTCursor,
kRotateTRCursor,
kRotateLCursor,
kRotateRCursor,
kRotateBLCursor,
kRotateBCursor,
kRotateBRCursor,
kSizeNSCursor,
kSizeWECursor,
kSizeNCursor,
kSizeNECursor,
kSizeECursor,
kSizeSECursor,
kSizeSCursor,
kSizeSWCursor,
kSizeWCursor,
kSizeNWCursor,
kRotateNCursor,
kRotateNECursor,
kRotateECursor,
kRotateSECursor,
kRotateSCursor,
kRotateSWCursor,
kRotateWCursor,
kRotateNWCursor,
kEyedropperCursor,
kMagnifierCursor,
kLastCursorType = kMagnifierCursor,
kCursorTypes
kCursorTypes,
};
} // namespace ui

View File

@ -254,7 +254,7 @@ void Slider::setupSliderCursor()
if (slider_press_left)
jmouse_set_cursor(kArrowCursor);
else
jmouse_set_cursor(kSizeLCursor);
jmouse_set_cursor(kSizeWECursor);
}
else
jmouse_set_cursor(kArrowCursor);

View File

@ -166,9 +166,9 @@ bool Splitter::onProcessMessage(Message* msg)
if (change_cursor) {
if (getAlign() & JI_HORIZONTAL)
jmouse_set_cursor(kSizeLCursor);
jmouse_set_cursor(kSizeWECursor);
else
jmouse_set_cursor(kSizeTCursor);
jmouse_set_cursor(kSizeNSCursor);
return true;
}
}

View File

@ -46,6 +46,8 @@ static CursorType mouse_cursor_type = kNoCursor;
static Cursor* mouse_cursor = NULL;
static she::Display* mouse_display = NULL;
static Overlay* mouse_cursor_overlay = NULL;
static bool use_native_mouse_cursor = false;
static bool native_cursor_set = false; // If we displayed a native cursor
/* Mouse information (button and position). */
@ -99,10 +101,71 @@ static void update_mouse_cursor()
{
show_mouse(NULL);
if (mouse_cursor_type == kNoCursor)
// Use native cursor when it's possible/available/configured to do so.
bool native_cursor_available = false;
if (use_native_mouse_cursor) {
she::NativeCursor nativeCursor = she::kNoCursor;
native_cursor_available = true;
switch (mouse_cursor_type) {
case ui::kNoCursor: break;
case ui::kArrowCursor:
case ui::kArrowPlusCursor:
nativeCursor = she::kArrowCursor;
break;
case ui::kForbiddenCursor:
nativeCursor = she::kForbiddenCursor;
break;
case ui::kHandCursor:
nativeCursor = she::kLinkCursor;
break;
case ui::kScrollCursor:
case ui::kMoveCursor:
nativeCursor = she::kMoveCursor;
break;
case ui::kSizeNSCursor: nativeCursor = she::kSizeNSCursor; break;
case ui::kSizeWECursor: nativeCursor = she::kSizeWECursor; break;
case ui::kSizeNCursor: nativeCursor = she::kSizeNCursor; break;
case ui::kSizeNECursor: nativeCursor = she::kSizeNECursor; break;
case ui::kSizeECursor: nativeCursor = she::kSizeECursor; break;
case ui::kSizeSECursor: nativeCursor = she::kSizeSECursor; break;
case ui::kSizeSCursor: nativeCursor = she::kSizeSCursor; break;
case ui::kSizeSWCursor: nativeCursor = she::kSizeSWCursor; break;
case ui::kSizeWCursor: nativeCursor = she::kSizeWCursor; break;
case ui::kSizeNWCursor: nativeCursor = she::kSizeNWCursor; break;
default:
native_cursor_available = false;
break;
}
if (native_cursor_available) {
native_cursor_available =
mouse_display->setNativeMouseCursor(nativeCursor);
native_cursor_set = (nativeCursor != she::kNoCursor);
}
}
// Hide native cursor if it is visible but the current cursor type
// is not supported natively.
if (!native_cursor_available && native_cursor_set) {
mouse_display->setNativeMouseCursor(she::kNoCursor);
native_cursor_set = false;
}
// Use a software cursor with the overlay.
if (!native_cursor_set) {
if (mouse_cursor_type == ui::kNoCursor)
update_mouse_overlay(NULL);
else
update_mouse_overlay(CurrentTheme::get()->getCursor(mouse_cursor_type));
}
else {
// Hide the overlay if we are using a native cursor.
update_mouse_overlay(NULL);
else
update_mouse_overlay(CurrentTheme::get()->getCursor(mouse_cursor_type));
}
dirty_display_flag = true;
}
@ -173,6 +236,11 @@ void UpdateCursorOverlay()
}
}
void set_use_native_cursors(bool state)
{
use_native_mouse_cursor = state;
}
CursorType jmouse_get_cursor()
{
return mouse_cursor_type;

View File

@ -46,6 +46,7 @@ namespace ui {
// current mouse position.
void UpdateCursorOverlay();
void set_use_native_cursors(bool state);
CursorType jmouse_get_cursor();
void jmouse_set_cursor(CursorType type);

View File

@ -380,43 +380,15 @@ bool Window::onProcessMessage(Message* msg)
CursorType cursor = kArrowCursor;
switch (ht) {
case HitTestCaption:
cursor = kArrowCursor;
break;
case HitTestBorderNW:
cursor = kSizeTLCursor;
break;
case HitTestBorderW:
cursor = kSizeLCursor;
break;
case HitTestBorderSW:
cursor = kSizeBLCursor;
break;
case HitTestBorderNE:
cursor = kSizeTRCursor;
break;
case HitTestBorderE:
cursor = kSizeRCursor;
break;
case HitTestBorderSE:
cursor = kSizeBRCursor;
break;
case HitTestBorderN:
cursor = kSizeTCursor;
break;
case HitTestBorderS:
cursor = kSizeBCursor;
break;
case HitTestCaption: cursor = kArrowCursor; break;
case HitTestBorderNW: cursor = kSizeNWCursor; break;
case HitTestBorderW: cursor = kSizeWCursor; break;
case HitTestBorderSW: cursor = kSizeSWCursor; break;
case HitTestBorderNE: cursor = kSizeNECursor; break;
case HitTestBorderE: cursor = kSizeECursor; break;
case HitTestBorderSE: cursor = kSizeSECursor; break;
case HitTestBorderN: cursor = kSizeNCursor; break;
case HitTestBorderS: cursor = kSizeSCursor; break;
}
jmouse_set_cursor(cursor);