mirror of https://github.com/buggins/dlangui.git
support standard mouse cursors
This commit is contained in:
parent
455e0ebd52
commit
e16d1cacbc
|
@ -282,7 +282,7 @@ class Window {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool dispatchMouseEvent(Widget root, MouseEvent event) {
|
protected bool dispatchMouseEvent(Widget root, MouseEvent event, ref bool cursorIsSet) {
|
||||||
// only route mouse events to visible widgets
|
// only route mouse events to visible widgets
|
||||||
if (root.visibility != Visibility.Visible)
|
if (root.visibility != Visibility.Visible)
|
||||||
return false;
|
return false;
|
||||||
|
@ -291,9 +291,16 @@ class Window {
|
||||||
// offer event to children first
|
// offer event to children first
|
||||||
for (int i = 0; i < root.childCount; i++) {
|
for (int i = 0; i < root.childCount; i++) {
|
||||||
Widget child = root.child(i);
|
Widget child = root.child(i);
|
||||||
if (dispatchMouseEvent(child, event))
|
if (dispatchMouseEvent(child, event, cursorIsSet))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (event.action == MouseAction.Move && !cursorIsSet) {
|
||||||
|
uint cursorType = root.getCursorType(event.x, event.y);
|
||||||
|
if (cursorType != CursorType.Parent) {
|
||||||
|
setCursorType(cursorType);
|
||||||
|
cursorIsSet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
// if not processed by children, offer event to root
|
// if not processed by children, offer event to root
|
||||||
if (sendAndCheckOverride(root, event)) {
|
if (sendAndCheckOverride(root, event)) {
|
||||||
debug(mouse) Log.d("MouseEvent is processed");
|
debug(mouse) Log.d("MouseEvent is processed");
|
||||||
|
@ -445,6 +452,7 @@ class Window {
|
||||||
if (event.action == MouseAction.Move || event.action == MouseAction.Leave) {
|
if (event.action == MouseAction.Move || event.action == MouseAction.Leave) {
|
||||||
processed = checkRemoveTracking(event);
|
processed = checkRemoveTracking(event);
|
||||||
}
|
}
|
||||||
|
bool cursorIsSet = false;
|
||||||
if (!res) {
|
if (!res) {
|
||||||
bool insideOneOfPopups = false;
|
bool insideOneOfPopups = false;
|
||||||
for (int i = cast(int)_popups.length - 1; i >= 0; i--) {
|
for (int i = cast(int)_popups.length - 1; i >= 0; i--) {
|
||||||
|
@ -458,11 +466,11 @@ class Window {
|
||||||
if (p.onMouseEventOutside(event)) // stop loop when true is returned, but allow other main widget to handle event
|
if (p.onMouseEventOutside(event)) // stop loop when true is returned, but allow other main widget to handle event
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (dispatchMouseEvent(p, event))
|
if (dispatchMouseEvent(p, event, cursorIsSet))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = dispatchMouseEvent(_mainWidget, event);
|
res = dispatchMouseEvent(_mainWidget, event, cursorIsSet);
|
||||||
}
|
}
|
||||||
return res || processed || _mainWidget.needDraw;
|
return res || processed || _mainWidget.needDraw;
|
||||||
}
|
}
|
||||||
|
@ -485,6 +493,10 @@ class Window {
|
||||||
for (int i = 0; i < root.childCount; i++)
|
for (int i = 0; i < root.childCount; i++)
|
||||||
checkUpdateNeeded(root.child(i), needDraw, needLayout, animationActive);
|
checkUpdateNeeded(root.child(i), needDraw, needLayout, animationActive);
|
||||||
}
|
}
|
||||||
|
/// sets cursor type for window
|
||||||
|
protected void setCursorType(uint cursorType) {
|
||||||
|
// override to support different mouse cursors
|
||||||
|
}
|
||||||
/// checks content widgets for necessary redraw and/or layout
|
/// checks content widgets for necessary redraw and/or layout
|
||||||
bool checkUpdateNeeded(ref bool needDraw, ref bool needLayout, ref bool animationActive) {
|
bool checkUpdateNeeded(ref bool needDraw, ref bool needLayout, ref bool animationActive) {
|
||||||
needDraw = needLayout = animationActive = false;
|
needDraw = needLayout = animationActive = false;
|
||||||
|
|
|
@ -144,6 +144,69 @@ version(USE_SDL) {
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected uint _lastCursorType = CursorType.None;
|
||||||
|
protected SDL_Cursor * [uint] _cursorMap;
|
||||||
|
/// sets cursor type for window
|
||||||
|
override protected void setCursorType(uint cursorType) {
|
||||||
|
// override to support different mouse cursors
|
||||||
|
if (_lastCursorType != cursorType) {
|
||||||
|
_lastCursorType = cursorType;
|
||||||
|
if (cursorType in _cursorMap) {
|
||||||
|
Log.d("changing cursor to ", cursorType);
|
||||||
|
SDL_SetCursor(_cursorMap[cursorType]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SDL_Cursor * cursor;
|
||||||
|
switch (cursorType) {
|
||||||
|
case CursorType.Arrow:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||||
|
break;
|
||||||
|
case CursorType.IBeam:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||||
|
break;
|
||||||
|
case CursorType.Wait:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
||||||
|
break;
|
||||||
|
case CursorType.WaitArrow:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAITARROW);
|
||||||
|
break;
|
||||||
|
case CursorType.Crosshair:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR);
|
||||||
|
break;
|
||||||
|
case CursorType.No:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
|
||||||
|
break;
|
||||||
|
case CursorType.Hand:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
|
||||||
|
break;
|
||||||
|
case CursorType.SizeNWSE:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
||||||
|
break;
|
||||||
|
case CursorType.SizeNESW:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
||||||
|
break;
|
||||||
|
case CursorType.SizeWE:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
||||||
|
break;
|
||||||
|
case CursorType.SizeNS:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
||||||
|
break;
|
||||||
|
case CursorType.SizeAll:
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// TODO: support custom cursors
|
||||||
|
cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (cursor) {
|
||||||
|
Log.d("changing cursor to ", cursorType);
|
||||||
|
_cursorMap[cursorType] = cursor;
|
||||||
|
SDL_SetCursor(cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Texture * _texture;
|
SDL_Texture * _texture;
|
||||||
int _txw;
|
int _txw;
|
||||||
int _txh;
|
int _txh;
|
||||||
|
|
|
@ -936,6 +936,7 @@ class EditWidgetBase : WidgetGroup, EditableContentListener, MenuItemActionHandl
|
||||||
return super.isActionEnabled(action);
|
return super.isActionEnabled(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// shows popup at (x,y)
|
/// shows popup at (x,y)
|
||||||
override void showPopupMenu(int x, int y) {
|
override void showPopupMenu(int x, int y) {
|
||||||
/// if preparation signal handler assigned, call it; don't show popup if false is returned from handler
|
/// if preparation signal handler assigned, call it; don't show popup if false is returned from handler
|
||||||
|
@ -960,6 +961,12 @@ class EditWidgetBase : WidgetGroup, EditableContentListener, MenuItemActionHandl
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// returns mouse cursor type for widget
|
||||||
|
override uint getCursorType(int x, int y) {
|
||||||
|
return CursorType.IBeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// when true, Tab / Shift+Tab presses are processed internally in widget (e.g. insert tab character) instead of focus change navigation.
|
/// when true, Tab / Shift+Tab presses are processed internally in widget (e.g. insert tab character) instead of focus change navigation.
|
||||||
@property bool wantTabs() {
|
@property bool wantTabs() {
|
||||||
return _wantTabs;
|
return _wantTabs;
|
||||||
|
|
|
@ -85,6 +85,25 @@ enum FocusMovement {
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// standard mouse cursor types
|
||||||
|
enum CursorType {
|
||||||
|
None,
|
||||||
|
/// use parent's cursor
|
||||||
|
Parent,
|
||||||
|
Arrow,
|
||||||
|
IBeam,
|
||||||
|
Wait,
|
||||||
|
Crosshair,
|
||||||
|
WaitArrow,
|
||||||
|
SizeNWSE,
|
||||||
|
SizeNESW,
|
||||||
|
SizeWE,
|
||||||
|
SizeNS,
|
||||||
|
SizeAll,
|
||||||
|
No,
|
||||||
|
Hand
|
||||||
|
}
|
||||||
|
|
||||||
class Widget {
|
class Widget {
|
||||||
/// widget id
|
/// widget id
|
||||||
protected string _id;
|
protected string _id;
|
||||||
|
@ -121,6 +140,11 @@ class Widget {
|
||||||
/// set new trackHover flag value (when true, widget will change Hover state while mouse is moving)
|
/// set new trackHover flag value (when true, widget will change Hover state while mouse is moving)
|
||||||
@property Widget trackHover(bool v) { _trackHover = v; return this; }
|
@property Widget trackHover(bool v) { _trackHover = v; return this; }
|
||||||
|
|
||||||
|
/// returns mouse cursor type for widget
|
||||||
|
uint getCursorType(int x, int y) {
|
||||||
|
return CursorType.Arrow;
|
||||||
|
}
|
||||||
|
|
||||||
debug(resalloc) {
|
debug(resalloc) {
|
||||||
private static int _instanceCount = 0;
|
private static int _instanceCount = 0;
|
||||||
private static bool _appShuttingDown = false;
|
private static bool _appShuttingDown = false;
|
||||||
|
|
Loading…
Reference in New Issue