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
7a461c18
Commit
7a461c18
authored
Jul 01, 2019
by
chili
Browse files
mousetrap
parent
12914fe9
Changes
2
Hide whitespace changes
Inline
Side-by-side
hw3d/Window.cpp
View file @
7a461c18
...
...
@@ -119,18 +119,20 @@ void Window::SetTitle( const std::string& title )
}
}
void
Window
::
EnableCursor
()
void
Window
::
EnableCursor
()
noexcept
{
cursorEnabled
=
true
;
ShowCursor
();
EnableImGuiMouse
();
FreeCursor
();
}
void
Window
::
DisableCursor
()
void
Window
::
DisableCursor
()
noexcept
{
cursorEnabled
=
false
;
HideCursor
();
DisableImGuiMouse
();
ConfineCursor
();
}
std
::
optional
<
int
>
Window
::
ProcessMessages
()
noexcept
...
...
@@ -164,22 +166,35 @@ Graphics& Window::Gfx()
return
*
pGfx
;
}
void
Window
::
HideCursor
()
void
Window
::
ConfineCursor
()
noexcept
{
RECT
rect
;
GetClientRect
(
hWnd
,
&
rect
);
MapWindowPoints
(
hWnd
,
nullptr
,
reinterpret_cast
<
POINT
*>
(
&
rect
),
2
);
ClipCursor
(
&
rect
);
}
void
Window
::
FreeCursor
()
noexcept
{
ClipCursor
(
nullptr
);
}
void
Window
::
HideCursor
()
noexcept
{
while
(
::
ShowCursor
(
FALSE
)
>=
0
);
}
void
Window
::
ShowCursor
()
void
Window
::
ShowCursor
()
noexcept
{
while
(
::
ShowCursor
(
TRUE
)
<
0
);
}
void
Window
::
EnableImGuiMouse
()
void
Window
::
EnableImGuiMouse
()
noexcept
{
ImGui
::
GetIO
().
ConfigFlags
&=
~
ImGuiConfigFlags_NoMouse
;
}
void
Window
::
DisableImGuiMouse
()
void
Window
::
DisableImGuiMouse
()
noexcept
{
ImGui
::
GetIO
().
ConfigFlags
|=
ImGuiConfigFlags_NoMouse
;
}
...
...
@@ -267,6 +282,7 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
/************* MOUSE MESSAGES ****************/
case
WM_MOUSEMOVE
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
// cursorless exclusive gets first dibs
if
(
!
cursorEnabled
)
{
...
...
@@ -283,7 +299,6 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
{
break
;
}
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
)
{
...
...
hw3d/Window.h
View file @
7a461c18
...
...
@@ -75,15 +75,17 @@ public:
Window
(
const
Window
&
)
=
delete
;
Window
&
operator
=
(
const
Window
&
)
=
delete
;
void
SetTitle
(
const
std
::
string
&
title
);
void
EnableCursor
();
void
DisableCursor
();
void
EnableCursor
()
noexcept
;
void
DisableCursor
()
noexcept
;
static
std
::
optional
<
int
>
ProcessMessages
()
noexcept
;
Graphics
&
Gfx
();
private:
void
HideCursor
();
void
ShowCursor
();
void
EnableImGuiMouse
();
void
DisableImGuiMouse
();
void
ConfineCursor
()
noexcept
;
void
FreeCursor
()
noexcept
;
void
ShowCursor
()
noexcept
;
void
HideCursor
()
noexcept
;
void
EnableImGuiMouse
()
noexcept
;
void
DisableImGuiMouse
()
noexcept
;
static
LRESULT
CALLBACK
HandleMsgSetup
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
static
LRESULT
CALLBACK
HandleMsgThunk
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
LRESULT
HandleMsg
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
...
...
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