mirror of https://github.com/buggins/dlangui.git
mouse events, initial implementation
This commit is contained in:
parent
81a71fab33
commit
7328b2a662
|
@ -299,6 +299,7 @@
|
||||||
<Folder name="src">
|
<Folder name="src">
|
||||||
<Folder name="dlangui">
|
<Folder name="dlangui">
|
||||||
<Folder name="core">
|
<Folder name="core">
|
||||||
|
<File path="src\dlangui\core\events.d" />
|
||||||
<File path="src\dlangui\core\logger.d" />
|
<File path="src\dlangui\core\logger.d" />
|
||||||
<File path="src\dlangui\core\types.d" />
|
<File path="src\dlangui\core\types.d" />
|
||||||
</Folder>
|
</Folder>
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
module dlangui.core.events;
|
||||||
|
|
||||||
|
import std.conv;
|
||||||
|
|
||||||
|
enum MouseAction : ushort {
|
||||||
|
LButtonDown,
|
||||||
|
LButtonUp,
|
||||||
|
MButtonDown,
|
||||||
|
MButtonUp,
|
||||||
|
RButtonDown,
|
||||||
|
RButtonUp,
|
||||||
|
Wheel,
|
||||||
|
Move,
|
||||||
|
Leave,
|
||||||
|
Hover
|
||||||
|
}
|
||||||
|
|
||||||
|
enum MouseFlag : ushort {
|
||||||
|
Control = 0x0008,
|
||||||
|
LButton = 0x0001,
|
||||||
|
MButton = 0x0010,
|
||||||
|
RButton = 0x0002,
|
||||||
|
Shift = 0x0004,
|
||||||
|
XButton1= 0x0020,
|
||||||
|
XButton2= 0x0040
|
||||||
|
}
|
||||||
|
|
||||||
|
class MouseEvent {
|
||||||
|
protected MouseAction _action;
|
||||||
|
protected ushort _flags;
|
||||||
|
protected short _x;
|
||||||
|
protected short _y;
|
||||||
|
@property MouseAction action() { return _action; }
|
||||||
|
@property ushort flags() { return _flags; }
|
||||||
|
@property short x() { return _x; }
|
||||||
|
@property short y() { return _y; }
|
||||||
|
this (MouseAction a, ushort f, short x, short y) {
|
||||||
|
_action = a;
|
||||||
|
_flags = f;
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
module dlangui.platforms.common.platform;
|
module dlangui.platforms.common.platform;
|
||||||
|
|
||||||
|
public import dlangui.core.events;
|
||||||
import dlangui.widgets.widget;
|
import dlangui.widgets.widget;
|
||||||
import dlangui.graphics.drawbuf;
|
import dlangui.graphics.drawbuf;
|
||||||
import std.file;
|
import std.file;
|
||||||
|
@ -37,6 +38,7 @@ class Window {
|
||||||
_mainWidget.onDraw(buf);
|
_mainWidget.onDraw(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
abstract bool onMouseEvent(MouseEvent event);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Platform {
|
class Platform {
|
||||||
|
|
|
@ -305,6 +305,11 @@ class Win32Window : Window {
|
||||||
paintUsingGDI();
|
paintUsingGDI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override bool onMouseEvent(MouseEvent event) {
|
||||||
|
Log.d("MouseEvent ", event.action, " flags=", event.flags, " x=", event.x, " y=", event.y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Win32Platform : Platform {
|
class Win32Platform : Platform {
|
||||||
|
@ -515,16 +520,38 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
return 1;
|
return 1;
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
//GetClientRect(hwnd, &rect);
|
|
||||||
//int dx = rect.right - rect.left;
|
|
||||||
//int dy = rect.bottom - rect.top;
|
|
||||||
//window.onResize(dx, dy);
|
|
||||||
if (window !is null)
|
if (window !is null)
|
||||||
window.onPaint();
|
window.onPaint();
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0; // processed
|
return 0; // processed
|
||||||
|
case WM_MOUSEMOVE:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.Move, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
|
case WM_LBUTTONDOWN:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.LButtonDown, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.MButtonDown, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
|
case WM_RBUTTONDOWN:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.RButtonDown, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
|
case WM_LBUTTONUP:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.LButtonUp, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
|
case WM_MBUTTONUP:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.MButtonUp, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
if (window !is null)
|
||||||
|
window.onMouseEvent(new MouseEvent(MouseAction.RButtonUp, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF)));
|
||||||
|
return 0; // processed
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
window.onDestroy();
|
window.onDestroy();
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
|
|
Loading…
Reference in New Issue