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
9bde6218
Commit
9bde6218
authored
Dec 17, 2018
by
chili
Browse files
basic mouse input
parent
7640b5df
Changes
6
Hide whitespace changes
Inline
Side-by-side
hw3d/Mouse.cpp
0 → 100644
View file @
9bde6218
/******************************************************************************************
* Chili DirectX Framework Version 16.07.20 *
* Mouse.cpp *
* Copyright 2016 PlanetChili <http://www.planetchili.net> *
* *
* This file is part of The Chili DirectX Framework. *
* *
* The Chili DirectX Framework is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* The Chili DirectX Framework is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with The Chili DirectX Framework. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/
#include "Mouse.h"
std
::
pair
<
int
,
int
>
Mouse
::
GetPos
()
const
noexcept
{
return
{
x
,
y
};
}
int
Mouse
::
GetPosX
()
const
noexcept
{
return
x
;
}
int
Mouse
::
GetPosY
()
const
noexcept
{
return
y
;
}
bool
Mouse
::
LeftIsPressed
()
const
noexcept
{
return
leftIsPressed
;
}
bool
Mouse
::
RightIsPressed
()
const
noexcept
{
return
rightIsPressed
;
}
Mouse
::
Event
Mouse
::
Read
()
noexcept
{
if
(
buffer
.
size
()
>
0u
)
{
Mouse
::
Event
e
=
buffer
.
front
();
buffer
.
pop
();
return
e
;
}
else
{
return
Mouse
::
Event
();
}
}
void
Mouse
::
Flush
()
noexcept
{
buffer
=
std
::
queue
<
Event
>
();
}
void
Mouse
::
OnMouseMove
(
int
newx
,
int
newy
)
noexcept
{
x
=
newx
;
y
=
newy
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
Move
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnLeftPressed
(
int
x
,
int
y
)
noexcept
{
leftIsPressed
=
true
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
LPress
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnLeftReleased
(
int
x
,
int
y
)
noexcept
{
leftIsPressed
=
false
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
LRelease
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnRightPressed
(
int
x
,
int
y
)
noexcept
{
rightIsPressed
=
true
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
RPress
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnRightReleased
(
int
x
,
int
y
)
noexcept
{
rightIsPressed
=
false
;
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
RRelease
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnWheelUp
(
int
x
,
int
y
)
noexcept
{
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
WheelUp
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
OnWheelDown
(
int
x
,
int
y
)
noexcept
{
buffer
.
push
(
Mouse
::
Event
(
Mouse
::
Event
::
Type
::
WheelDown
,
*
this
)
);
TrimBuffer
();
}
void
Mouse
::
TrimBuffer
()
noexcept
{
while
(
buffer
.
size
()
>
bufferSize
)
{
buffer
.
pop
();
}
}
\ No newline at end of file
hw3d/Mouse.h
0 → 100644
View file @
9bde6218
/******************************************************************************************
* Chili DirectX Framework Version 16.07.20 *
* Mouse.h *
* Copyright 2016 PlanetChili <http://www.planetchili.net> *
* *
* This file is part of The Chili DirectX Framework. *
* *
* The Chili DirectX Framework is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* The Chili DirectX Framework is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with The Chili DirectX Framework. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/
#pragma once
#include <queue>
class
Mouse
{
friend
class
Window
;
public:
class
Event
{
public:
enum
class
Type
{
LPress
,
LRelease
,
RPress
,
RRelease
,
WheelUp
,
WheelDown
,
Move
,
Invalid
};
private:
Type
type
;
bool
leftIsPressed
;
bool
rightIsPressed
;
int
x
;
int
y
;
public:
Event
()
noexcept
:
type
(
Type
::
Invalid
),
leftIsPressed
(
false
),
rightIsPressed
(
false
),
x
(
0
),
y
(
0
)
{}
Event
(
Type
type
,
const
Mouse
&
parent
)
noexcept
:
type
(
type
),
leftIsPressed
(
parent
.
leftIsPressed
),
rightIsPressed
(
parent
.
rightIsPressed
),
x
(
parent
.
x
),
y
(
parent
.
y
)
{}
bool
IsValid
()
const
noexcept
{
return
type
!=
Type
::
Invalid
;
}
Type
GetType
()
const
noexcept
{
return
type
;
}
std
::
pair
<
int
,
int
>
GetPos
()
const
noexcept
{
return
{
x
,
y
};
}
int
GetPosX
()
const
noexcept
{
return
x
;
}
int
GetPosY
()
const
noexcept
{
return
y
;
}
bool
LeftIsPressed
()
const
noexcept
{
return
leftIsPressed
;
}
bool
RightIsPressed
()
const
noexcept
{
return
rightIsPressed
;
}
};
public:
Mouse
()
=
default
;
Mouse
(
const
Mouse
&
)
=
delete
;
Mouse
&
operator
=
(
const
Mouse
&
)
=
delete
;
std
::
pair
<
int
,
int
>
GetPos
()
const
noexcept
;
int
GetPosX
()
const
noexcept
;
int
GetPosY
()
const
noexcept
;
bool
LeftIsPressed
()
const
noexcept
;
bool
RightIsPressed
()
const
noexcept
;
Mouse
::
Event
Read
()
noexcept
;
bool
IsEmpty
()
const
noexcept
{
return
buffer
.
empty
();
}
void
Flush
()
noexcept
;
private:
void
OnMouseMove
(
int
x
,
int
y
)
noexcept
;
void
OnLeftPressed
(
int
x
,
int
y
)
noexcept
;
void
OnLeftReleased
(
int
x
,
int
y
)
noexcept
;
void
OnRightPressed
(
int
x
,
int
y
)
noexcept
;
void
OnRightReleased
(
int
x
,
int
y
)
noexcept
;
void
OnWheelUp
(
int
x
,
int
y
)
noexcept
;
void
OnWheelDown
(
int
x
,
int
y
)
noexcept
;
void
TrimBuffer
()
noexcept
;
private:
static
constexpr
unsigned
int
bufferSize
=
16u
;
int
x
;
int
y
;
bool
leftIsPressed
=
false
;
bool
rightIsPressed
=
false
;
std
::
queue
<
Event
>
buffer
;
};
\ No newline at end of file
hw3d/Window.cpp
View file @
9bde6218
...
...
@@ -159,6 +159,51 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
kbd
.
OnChar
(
static_cast
<
unsigned
char
>
(
wParam
)
);
break
;
/*********** END KEYBOARD MESSAGES ***********/
/************* MOUSE MESSAGES ****************/
case
WM_MOUSEMOVE
:
{
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnMouseMove
(
pt
.
x
,
pt
.
y
);
}
case
WM_LBUTTONDOWN
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnLeftPressed
(
pt
.
x
,
pt
.
y
);
break
;
}
case
WM_RBUTTONDOWN
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnRightPressed
(
pt
.
x
,
pt
.
y
);
break
;
}
case
WM_LBUTTONUP
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnLeftReleased
(
pt
.
x
,
pt
.
y
);
break
;
}
case
WM_RBUTTONUP
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
mouse
.
OnRightReleased
(
pt
.
x
,
pt
.
y
);
break
;
}
case
WM_MOUSEWHEEL
:
{
const
POINTS
pt
=
MAKEPOINTS
(
lParam
);
if
(
GET_WHEEL_DELTA_WPARAM
(
wParam
)
>
0
)
{
mouse
.
OnWheelUp
(
pt
.
x
,
pt
.
y
);
}
else
if
(
GET_WHEEL_DELTA_WPARAM
(
wParam
)
<
0
)
{
mouse
.
OnWheelDown
(
pt
.
x
,
pt
.
y
);
}
break
;
}
/************** END MOUSE MESSAGES **************/
}
return
DefWindowProc
(
hWnd
,
msg
,
wParam
,
lParam
);
...
...
hw3d/Window.h
View file @
9bde6218
...
...
@@ -21,6 +21,7 @@
#include "ChiliWin.h"
#include "ChiliException.h"
#include "Keyboard.h"
#include "Mouse.h"
class
Window
...
...
@@ -65,6 +66,7 @@ private:
LRESULT
HandleMsg
(
HWND
hWnd
,
UINT
msg
,
WPARAM
wParam
,
LPARAM
lParam
)
noexcept
;
public:
Keyboard
kbd
;
Mouse
mouse
;
private:
int
width
;
int
height
;
...
...
hw3d/hw3d.vcxproj
View file @
9bde6218
...
...
@@ -147,6 +147,7 @@
<ItemGroup>
<ClCompile
Include=
"ChiliException.cpp"
/>
<ClCompile
Include=
"Keyboard.cpp"
/>
<ClCompile
Include=
"Mouse.cpp"
/>
<ClCompile
Include=
"Window.cpp"
/>
<ClCompile
Include=
"WindowsMessageMap.cpp"
/>
<ClCompile
Include=
"WinMain.cpp"
/>
...
...
@@ -155,6 +156,7 @@
<ClInclude
Include=
"ChiliException.h"
/>
<ClInclude
Include=
"ChiliWin.h"
/>
<ClInclude
Include=
"Keyboard.h"
/>
<ClInclude
Include=
"Mouse.h"
/>
<ClInclude
Include=
"resource.h"
/>
<ClInclude
Include=
"Window.h"
/>
<ClInclude
Include=
"WindowsMessageMap.h"
/>
...
...
hw3d/hw3d.vcxproj.filters
View file @
9bde6218
...
...
@@ -30,6 +30,9 @@
<ClCompile
Include=
"Keyboard.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"Mouse.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"WindowsMessageMap.h"
>
...
...
@@ -50,6 +53,9 @@
<ClInclude
Include=
"Keyboard.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"Mouse.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile
Include=
"hw3d.rc"
>
...
...
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