Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
rzerres
orbclient
Commits
a6e24a3d
Verified
Commit
a6e24a3d
authored
Aug 11, 2019
by
Jeremy Soller
Browse files
0.3.26 - add MouseRelative event
parent
70415b0a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Cargo.toml
View file @
a6e24a3d
[package]
name
=
"orbclient"
version
=
"0.3.2
5
"
version
=
"0.3.2
6
"
authors
=
[
"Jeremy Soller <jackpot51@gmail.com>"
]
description
=
"The Orbital Client Library"
documentation
=
"https://docs.rs/orbclient"
...
...
src/event.rs
View file @
a6e24a3d
...
...
@@ -12,14 +12,17 @@ pub const EVENT_MOVE: i64 = 7;
pub
const
EVENT_RESIZE
:
i64
=
8
;
pub
const
EVENT_SCREEN
:
i64
=
9
;
pub
const
EVENT_CLIPBOARD
:
i64
=
10
;
pub
const
EVENT_MOUSE_RELATIVE
:
i64
=
11
;
/// An optional event
#[derive(Copy,
Clone,
Debug)]
pub
enum
EventOption
{
/// A key event
Key
(
KeyEvent
),
/// A mouse event
/// A mouse event
(absolute)
Mouse
(
MouseEvent
),
/// A mouse event (relative)
MouseRelative
(
MouseRelativeEvent
),
/// A mouse button event
Button
(
ButtonEvent
),
/// A mouse scroll event
...
...
@@ -253,7 +256,7 @@ impl KeyEvent {
}
}
/// A event related to the mouse
/// A event related to the mouse
(absolute position)
#[derive(Copy,
Clone,
Debug)]
pub
struct
MouseEvent
{
/// The x coordinate of the mouse
...
...
@@ -281,6 +284,34 @@ impl MouseEvent {
}
}
/// A event related to the mouse (relative position)
#[derive(Copy,
Clone,
Debug)]
pub
struct
MouseRelativeEvent
{
/// The x coordinate of the mouse
pub
dx
:
i32
,
/// The y coordinate of the mouse
pub
dy
:
i32
,
}
impl
MouseRelativeEvent
{
/// Convert to an `Event`
pub
fn
to_event
(
&
self
)
->
Event
{
Event
{
code
:
EVENT_MOUSE_RELATIVE
,
a
:
self
.dx
as
i64
,
b
:
self
.dy
as
i64
,
}
}
/// Convert an `Event` to a `MouseRelativeEvent`
pub
fn
from_event
(
event
:
Event
)
->
MouseRelativeEvent
{
MouseRelativeEvent
{
dx
:
event
.a
as
i32
,
dy
:
event
.b
as
i32
,
}
}
}
/// A event for clicking the mouse
#[derive(Copy,
Clone,
Debug)]
pub
struct
ButtonEvent
{
...
...
src/sys/sdl2.rs
View file @
a6e24a3d
...
...
@@ -55,6 +55,8 @@ pub struct Window {
mode
:
Cell
<
Mode
>
,
/// The inner renderer
inner
:
sdl2
::
render
::
WindowCanvas
,
/// Mouse in relative mode
mouse_relative
:
bool
,
}
impl
Renderer
for
Window
{
...
...
@@ -170,6 +172,7 @@ impl Window {
async
:
async
,
mode
:
Cell
::
new
(
Mode
::
Blend
),
inner
:
window
.into_canvas
()
.software
()
.build
()
.unwrap
(),
mouse_relative
:
false
,
}),
Err
(
_
)
=>
None
,
}
...
...
@@ -225,6 +228,7 @@ impl Window {
/// Set mouse relative mode
pub
fn
set_mouse_relative
(
&
mut
self
,
relative
:
bool
)
{
unsafe
{
&
mut
*
SDL_CTX
}
.mouse
()
.set_relative_mouse_mode
(
relative
);
self
.mouse_relative
=
relative
;
}
/// Set position
...
...
@@ -394,8 +398,12 @@ impl Window {
}
_
=>
(),
},
sdl2
::
event
::
Event
::
MouseMotion
{
x
,
y
,
..
}
=>
{
events
.push
(
MouseEvent
{
x
:
x
,
y
:
y
}
.to_event
())
sdl2
::
event
::
Event
::
MouseMotion
{
x
,
y
,
xrel
,
yrel
,
..
}
=>
{
if
self
.mouse_relative
{
events
.push
(
MouseRelativeEvent
{
dx
:
xrel
,
dy
:
yrel
}
.to_event
())
}
else
{
events
.push
(
MouseEvent
{
x
:
x
,
y
:
y
}
.to_event
())
}
}
sdl2
::
event
::
Event
::
MouseButtonDown
{
..
}
=>
events
.push
(
button_event
()),
sdl2
::
event
::
Event
::
MouseButtonUp
{
..
}
=>
events
.push
(
button_event
()),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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