Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
41b57602
Commit
41b57602
authored
Dec 24, 2018
by
chili
Browse files
capture mouse on drag and track mouse entry/exit
parent
569af691
Changes
3
Show whitespace changes
Inline
Side-by-side
hw3d/Mouse.cpp
View file @
41b57602
...
...
@@ -36,6 +36,11 @@ int Mouse::GetPosY() const noexcept
return
y
;
}
bool
Mouse
::
IsInWindow
()
const
noexcept
{
return
isInWindow
;
}
bool
Mouse
::
LeftIsPressed
()
const
noexcept
{
return
leftIsPressed
;
...
...
@@ -74,6 +79,20 @@ void Mouse::OnMouseMove( int newx,int newy ) noexcept
TrimBuffer
();
}
void
Mouse
::
OnMouseLeave
()
noexcept
{
isInWindow
=
false
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
Leave
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnMouseEnter
()
noexcept
{
isInWindow
=
true
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
Enter
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnLeftPressed
(
int
x
,
int
y
)
noexcept
{
leftIsPressed
=
true
;
...
...
hw3d/Mouse.h
View file @
41b57602
...
...
@@ -37,6 +37,8 @@ public:
WheelUp
,
WheelDown
,
Move
,
Enter
,
Leave
,
Invalid
};
private:
...
...
@@ -98,6 +100,7 @@ public:
std
::
pair
<
int
,
int
>
GetPos
()
const
noexcept
;
int
GetPosX
()
const
noexcept
;
int
GetPosY
()
const
noexcept
;
bool
IsInWindow
()
const
noexcept
;
bool
LeftIsPressed
()
const
noexcept
;
bool
RightIsPressed
()
const
noexcept
;
Mouse
::
Event
Read
()
noexcept
;
...
...
@@ -108,6 +111,8 @@ public:
void
Flush
()
noexcept
;
private:
void
OnMouseMove
(
int
x
,
int
y
)
noexcept
;
void
OnMouseLeave
()
noexcept
;
void
OnMouseEnter
()
noexcept
;
void
OnLeftPressed
(
int
x
,
int
y
)
noexcept
;
void
OnLeftReleased
(
int
x
,
int
y
)
noexcept
;
void
OnRightPressed
(
int
x
,
int
y
)
noexcept
;
...
...
@@ -121,5 +126,6 @@ private:
int
y
;
bool
leftIsPressed
=
false
;
bool
rightIsPressed
=
false
;
bool
isInWindow
=
false
;
std
::
queue
<
Event
>
buffer
;
};
\ No newline at end of file
hw3d/Window.cpp
View file @
41b57602
...
...
@@ -175,7 +175,30 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
case
WM_MOUSEMOVE
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
// in client region -> log move, and log enter + capture mouse (if not previously in window)
if
(
pt
.
x
>=
0
&&
pt
.
x
<
width
&&
pt
.
y
>=
0
&&
pt
.
y
<
height
)
{
mouse
.
OnMouseMove
(
pt
.
x
,
pt
.
y
);
if
(
!
mouse
.
IsInWindow
()
)
{
SetCapture
(
hWnd
);
mouse
.
OnMouseEnter
();
}
}
// not in client -> log move / maintain capture if button down
else
{
if
(
wParam
&
(
MK_LBUTTON
|
MK_RBUTTON
)
)
{
mouse
.
OnMouseMove
(
pt
.
x
,
pt
.
y
);
}
// button up -> release capture / log event for leaving
else
{
ReleaseCapture
();
mouse
.
OnMouseLeave
();
}
}
break
;
}
case
WM_LBUTTONDOWN
:
...
...
@@ -194,12 +217,24 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnLeftReleased
(
pt
.
x
,
pt
.
y
);
// release mouse if outside of window
if
(
pt
.
x
<
0
||
pt
.
x
>=
width
||
pt
.
y
<
0
||
pt
.
y
>=
height
)
{
ReleaseCapture
();
mouse
.
OnMouseLeave
();
}
break
;
}
case
WM_RBUTTONUP
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnRightReleased
(
pt
.
x
,
pt
.
y
);
// release mouse if outside of window
if
(
pt
.
x
<
0
||
pt
.
x
>=
width
||
pt
.
y
<
0
||
pt
.
y
>=
height
)
{
ReleaseCapture
();
mouse
.
OnMouseLeave
();
}
break
;
}
case
WM_MOUSEWHEEL
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment