|
2 | 2 |
|
3 | 3 | #![no_std]
|
4 | 4 | #![warn(missing_docs)]
|
| 5 | +#![feature(const_fn)] |
5 | 6 |
|
6 | 7 | use bitflags::bitflags;
|
7 | 8 | use x86_64::instructions::port::Port;
|
@@ -73,6 +74,15 @@ pub struct MouseState {
|
73 | 74 | }
|
74 | 75 |
|
75 | 76 | impl MouseState {
|
| 77 | + /// Returns a new `MouseState`. |
| 78 | + pub const fn new() -> MouseState { |
| 79 | + MouseState { |
| 80 | + flags: MouseFlags::empty(), |
| 81 | + x: 0, |
| 82 | + y: 0, |
| 83 | + } |
| 84 | + } |
| 85 | + |
76 | 86 | /// Returns true if the left mouse button is currently down.
|
77 | 87 | pub fn left_button_down(&self) -> bool {
|
78 | 88 | self.flags.contains(MouseFlags::LEFT_BUTTON)
|
@@ -107,17 +117,27 @@ impl MouseState {
|
107 | 117 | pub fn moved(&self) -> bool {
|
108 | 118 | self.x_moved() || self.y_moved()
|
109 | 119 | }
|
| 120 | + |
| 121 | + /// Returns the x delta of the mouse state. |
| 122 | + pub fn get_x(&self) -> i16 { |
| 123 | + self.x |
| 124 | + } |
| 125 | + |
| 126 | + /// Returns the y delta of the mouse state. |
| 127 | + pub fn get_y(&self) -> i16 { |
| 128 | + self.y |
| 129 | + } |
110 | 130 | }
|
111 | 131 |
|
112 | 132 | impl Mouse {
|
113 | 133 | /// Creates a new `Mouse`.
|
114 |
| - pub fn new() -> Mouse { |
| 134 | + pub const fn new() -> Mouse { |
115 | 135 | Mouse {
|
116 | 136 | command_port: Port::new(ADDRESS_PORT_ADDRESS),
|
117 | 137 | data_port: Port::new(DATA_PORT_ADDRESS),
|
118 | 138 | current_packet: 0,
|
119 |
| - current_state: MouseState::default(), |
120 |
| - completed_state: MouseState::default(), |
| 139 | + current_state: MouseState::new(), |
| 140 | + completed_state: MouseState::new(), |
121 | 141 | on_complete: None,
|
122 | 142 | }
|
123 | 143 | }
|
|
0 commit comments