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
PracticeDx
Commits
20ca62d0
Commit
20ca62d0
authored
Apr 17, 2023
by
Administrator
Browse files
added mouse scroll operation
parent
9f392617
Changes
5
Hide whitespace changes
Inline
Side-by-side
PracticeDx/CoreHandler.cpp
View file @
20ca62d0
...
@@ -44,12 +44,12 @@ void CoreHandler::CoreProcess(Window& window, Graphics& gfx, HWND& hWnd, Logger&
...
@@ -44,12 +44,12 @@ void CoreHandler::CoreProcess(Window& window, Graphics& gfx, HWND& hWnd, Logger&
break
;
break
;
}
}
case
(
Mouse
::
MouseEvent
::
Type
::
LRelease
):
case
(
Mouse
::
MouseEvent
::
Type
::
LRelease
):
{
{
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
oss
<<
"("
<<
mouseEvent
.
GetX
()
<<
","
<<
mouseEvent
.
GetY
()
<<
"): Mouse Left Released"
;
oss
<<
"("
<<
mouseEvent
.
GetX
()
<<
","
<<
mouseEvent
.
GetY
()
<<
"): Mouse Left Released"
;
window
.
SetTitle
(
hWnd
,
oss
.
str
());
window
.
SetTitle
(
hWnd
,
oss
.
str
());
break
;
break
;
}
}
case
(
Mouse
::
MouseEvent
::
Type
::
RClick
):
case
(
Mouse
::
MouseEvent
::
Type
::
RClick
):
{
{
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
...
@@ -58,19 +58,31 @@ void CoreHandler::CoreProcess(Window& window, Graphics& gfx, HWND& hWnd, Logger&
...
@@ -58,19 +58,31 @@ void CoreHandler::CoreProcess(Window& window, Graphics& gfx, HWND& hWnd, Logger&
break
;
break
;
}
}
case
(
Mouse
::
MouseEvent
::
Type
::
RRelease
):
case
(
Mouse
::
MouseEvent
::
Type
::
RRelease
):
{
{
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
cameraX
+=
cameraDeltaX
;
cameraX
+=
cameraDeltaX
;
cameraY
+=
cameraDeltaY
;
cameraY
+=
cameraDeltaY
;
cameraDeltaX
=
0
;
cameraDeltaX
=
0
;
cameraDeltaY
=
0
;
cameraDeltaY
=
0
;
oss
<<
"("
<<
mouseEvent
.
GetX
()
<<
","
<<
mouseEvent
.
GetY
()
<<
"): Mouse Right Released"
;
oss
<<
"("
<<
mouseEvent
.
GetX
()
<<
","
<<
mouseEvent
.
GetY
()
<<
"): Mouse Right Released"
;
window
.
SetTitle
(
hWnd
,
oss
.
str
());
window
.
SetTitle
(
hWnd
,
oss
.
str
());
break
;
break
;
}
}
case
(
Mouse
::
MouseEvent
::
Type
::
Wheel
):
{
std
::
ostringstream
oss
;
cameraDeltaZ
=
Window
::
mouse
.
GetWheelDelta
();
oss
<<
"("
<<
mouseEvent
.
GetX
()
<<
","
<<
mouseEvent
.
GetY
()
<<
"): Mouse WheelUp"
;
oss
<<
" | cameraDeltaZ("
<<
cameraDeltaZ
<<
")"
;
window
.
SetTitle
(
hWnd
,
oss
.
str
());
break
;
}
}
}
}
}
...
@@ -103,7 +115,7 @@ void CoreHandler::SetCamera(Window& window, Logger& logger)
...
@@ -103,7 +115,7 @@ void CoreHandler::SetCamera(Window& window, Logger& logger)
DirectX::XMVECTOR focusPosition = DirectX::XMVectorZero();
DirectX::XMVECTOR focusPosition = DirectX::XMVectorZero();
DirectX::XMVECTOR upDirection = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);*/
DirectX::XMVECTOR upDirection = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);*/
float
radius
=
5
.0
f
;
float
radius
=
cameraZ
-
cameraDeltaZ
/
120
.0
f
;
auto
vSinValue
=
sin
((
cameraY
+
cameraDeltaY
)
/
100.0
f
);
auto
vSinValue
=
sin
((
cameraY
+
cameraDeltaY
)
/
100.0
f
);
auto
vCosValue
=
cos
((
cameraY
+
cameraDeltaY
)
/
100.0
f
);
auto
vCosValue
=
cos
((
cameraY
+
cameraDeltaY
)
/
100.0
f
);
...
...
PracticeDx/CoreHandler.h
View file @
20ca62d0
...
@@ -13,10 +13,10 @@ public:
...
@@ -13,10 +13,10 @@ public:
void
SetCamera
(
Window
&
window
,
Logger
&
logger
);
void
SetCamera
(
Window
&
window
,
Logger
&
logger
);
private:
private:
double
seed
;
double
seed
;
in
t
cameraX
=
80
;
floa
t
cameraX
=
80
.0
f
;
in
t
cameraY
=
60
;
floa
t
cameraY
=
60
.0
f
;
in
t
cameraZ
=
0
;
floa
t
cameraZ
=
5.0
f
;
in
t
cameraDeltaX
=
0
;
floa
t
cameraDeltaX
=
0
;
in
t
cameraDeltaY
=
0
;
floa
t
cameraDeltaY
=
0
;
in
t
cameraDeltaZ
=
0
;
floa
t
cameraDeltaZ
=
0
;
};
};
\ No newline at end of file
PracticeDx/Mouse.cpp
View file @
20ca62d0
#include "Mouse.h"
#include "Mouse.h"
#include "Window.h"
Mouse
::
Mouse
()
Mouse
::
Mouse
()
{
{
...
@@ -54,6 +55,11 @@ int Mouse::GetRightDragDeltaY()
...
@@ -54,6 +55,11 @@ int Mouse::GetRightDragDeltaY()
return
rightDragDeltaY
;
return
rightDragDeltaY
;
}
}
int
Mouse
::
GetWheelDelta
()
{
return
wheelDelta
;
}
void
Mouse
::
OnMouseMove
(
int
newX
,
int
newY
)
void
Mouse
::
OnMouseMove
(
int
newX
,
int
newY
)
{
{
x
=
newX
;
x
=
newX
;
...
@@ -103,6 +109,47 @@ void Mouse::OnRightRelease(int newX, int newY)
...
@@ -103,6 +109,47 @@ void Mouse::OnRightRelease(int newX, int newY)
TrimEvents
();
TrimEvents
();
}
}
void
Mouse
::
OnWheelDelta
(
int
x
,
int
y
,
int
delta
)
{
wheelDelta
+=
delta
;
if
(
wheelDelta
>=
2.0
f
*
WHEEL_DELTA
)
{
wheelDelta
=
2.0
f
*
WHEEL_DELTA
;
}
if
(
wheelDelta
<=
-
120.0
f
*
WHEEL_DELTA
)
{
wheelDelta
=
-
120.0
f
*
WHEEL_DELTA
;
}
mouseEvents
.
push
(
Mouse
::
MouseEvent
(
Mouse
::
MouseEvent
::
Type
::
Wheel
,
*
this
));
TrimEvents
();
// generate events for every 120
// 默认每次达到120,执行一次滚轮事件。如果数字够大,可以执行复数次
//if (wheelDelta >= 0.0f)
//{
// //wheelDelta -= WHEEL_DELTA;
// OnWheelUp(x, y);
//}
//else
//{
// //wheelDelta += WHEEL_DELTA;
// OnWheelDown(x, y);
//}
}
//void Mouse::OnWheelUp(int x, int y)
//{
// mouseEvents.push(Mouse::MouseEvent(Mouse::MouseEvent::Type::WheelUp, *this));
// TrimEvents();
//}
//
//void Mouse::OnWheelDown(int x, int y)
//{
// mouseEvents.push(Mouse::MouseEvent(Mouse::MouseEvent::Type::WheelDown, *this));
// TrimEvents();
//}
Mouse
::
MouseEvent
Mouse
::
ReadEvent
()
Mouse
::
MouseEvent
Mouse
::
ReadEvent
()
{
{
if
(
mouseEvents
.
size
()
>
0
)
if
(
mouseEvents
.
size
()
>
0
)
...
...
PracticeDx/Mouse.h
View file @
20ca62d0
...
@@ -13,8 +13,9 @@ public:
...
@@ -13,8 +13,9 @@ public:
LRelease
,
LRelease
,
RClick
,
RClick
,
RRelease
,
RRelease
,
WheelUp
,
//WheelUp,
WheelDown
,
//WheelDown,
Wheel
,
Move
,
Move
,
Enter
,
Enter
,
Leave
,
Leave
,
...
@@ -89,12 +90,16 @@ public:
...
@@ -89,12 +90,16 @@ public:
int
GetRightClickAtY
();
int
GetRightClickAtY
();
int
GetRightDragDeltaX
();
int
GetRightDragDeltaX
();
int
GetRightDragDeltaY
();
int
GetRightDragDeltaY
();
int
GetWheelDelta
();
void
OnMouseMove
(
int
newX
,
int
newY
);
void
OnMouseMove
(
int
newX
,
int
newY
);
void
OnLeftClick
(
int
newX
,
int
newY
);
void
OnLeftClick
(
int
newX
,
int
newY
);
void
OnleftRelease
(
int
newX
,
int
newY
);
void
OnleftRelease
(
int
newX
,
int
newY
);
void
OnRightClick
(
int
newX
,
int
newY
);
void
OnRightClick
(
int
newX
,
int
newY
);
void
OnRightRelease
(
int
newX
,
int
newY
);
void
OnRightRelease
(
int
newX
,
int
newY
);
void
OnWheelDelta
(
int
x
,
int
y
,
int
delta
);
//void OnWheelUp(int x, int y);
//void OnWheelDown(int x, int y);
Mouse
::
MouseEvent
ReadEvent
();
Mouse
::
MouseEvent
ReadEvent
();
void
TrimEvents
();
void
TrimEvents
();
...
@@ -110,9 +115,9 @@ private:
...
@@ -110,9 +115,9 @@ private:
int
leftClickAtY
;
int
leftClickAtY
;
int
rightClickAtX
;
int
rightClickAtX
;
int
rightClickAtY
;
int
rightClickAtY
;
int
rightDragDeltaX
;
int
rightDragDeltaX
;
int
rightDragDeltaY
;
int
rightDragDeltaY
;
int
wheelDelta
;
static
constexpr
unsigned
int
bufferSize
=
16u
;
static
constexpr
unsigned
int
bufferSize
=
16u
;
...
...
PracticeDx/Window.cpp
View file @
20ca62d0
...
@@ -116,6 +116,11 @@ LRESULT Window::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noe
...
@@ -116,6 +116,11 @@ LRESULT Window::HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noe
pt
=
MAKEPOINTS
(
lParam
);
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnRightRelease
(
pt
.
x
,
pt
.
y
);
mouse
.
OnRightRelease
(
pt
.
x
,
pt
.
y
);
break
;
break
;
case
WM_MOUSEWHEEL
:
pt
=
MAKEPOINTS
(
lParam
);
int
mouseDelta
=
GET_WHEEL_DELTA_WPARAM
(
wParam
);
mouse
.
OnWheelDelta
(
pt
.
x
,
pt
.
y
,
mouseDelta
);
break
;
}
}
return
DefWindowProc
(
hWnd
,
msg
,
wParam
,
lParam
);
return
DefWindowProc
(
hWnd
,
msg
,
wParam
,
lParam
);
...
...
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