1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
use crate::prelude::{MouseButton, MouseCursor};
/// The InputMouse should be implemented by objects wishing to act as virtual mouse controllers.
///
/// Screen bounds are based on Factory::width & Factory::height.
///
pub trait InputMouse {
/// The horizontal component of the mouse position.
fn x(&self) -> i32;
/// The vertical component of the mouse position.
fn y(&self) -> i32;
/// The horizontal position of the mouse relative to screen width. Range 0...1.
fn relative_x(&self) -> f32;
/// The vertical position of the mouse relative to screen height. Range 0...1.
fn relative_y(&self) -> f32;
/// The horizontal position of the mouse relative to screen width and offset to screen centre. Range -1...1.
fn relative_centralised_x(&self) -> f32;
/// The vertical position of the mouse relative to screen height and offset to screen centre. Range -1...1.
fn relative_centralised_y(&self) -> f32;
/// Returns true if the mouse position is within the bounding rectangle (factory width x factory height).
fn is_within_bounds(&self) -> bool;
/// Returns true if the mouse position is different to the previous update's position.
fn is_moving(&self) -> bool;
/// Get the visibility of the mouse cursor.
fn is_visible(&self) -> bool;
/// Specify the visibility of the mouse cursor.
/// If true the cursor will be displayed, if false the cursor is hidden.
fn set_visible(&self, val: bool);
/// The current scroll position. Starts at 0. Range -infinity...infinity.
fn scroll(&self) -> i32;
/// The current cursor type.
fn cursor(&self) -> MouseCursor;
/// Set the cursor type.
fn set_cursor(&self, val: MouseCursor) -> MouseCursor;
/// The horizontal velocity of the mouse position.
///
/// # Arguments
///
/// * `as_time` - If true then returns the velocity as pixels per second (extrapolated from the previous update),
/// else returns velocity as pixels moved in previous update. (optional, default: true)
///
/// Return: The horizontal velocity of the mouse.
///
fn get_delta_x(&self, as_time: Option<bool>) -> i32;
/// The vertical velocity of the mouse position.
///
/// # Arguments
///
/// * `as_time` - If true then returns the velocity as pixels per second (extrapolated from the previous update),
/// else returns velocity as pixels moved in previous update. (optional, default: true)
///
/// Return: The vertical velocity of the mouse.
///
fn get_delta_y(&self, as_time: Option<bool>) -> i32;
/// The velocity of the mouse.
///
/// # Arguments
///
/// * `as_time` - If true then returns the velocity as pixels per second (extrapolated from the previous update),
/// else returns velocity as pixels moved in previous update. (optional, default: true)
///
/// Return: The velocity of the mouse.
///
fn get_speed(&self, as_time: Option<bool>) -> i32;
/// The velocity of scrolling.
///
/// # Arguments
///
/// * `as_time` - If true then returns the velocity as pixels per second (extrapolated from the previous update),
/// else returns velocity as scroll moved in previous update. (optional, default: true)
///
/// Return: The scroll velocity of the mouse.
///
fn get_delta_scroll(&self, as_time: Option<bool>) -> i32;
/// Determine how long the mouse has been still.
///
/// # Arguments
///
/// * `as_time` - If true then returns duration as milliseconds, else returns duration as frame updates. (optional, default: true)
///
/// Return: Returns the duration the mouse has been still.
///
fn get_still_duration(&self, as_time: Option<bool>) -> i32;
/// Determine if a specific mouse button was clicked twice (within the defined time).
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
/// * `delay` - The time within which the mouse button must be clicked twice. (optional, default: 100)
///
/// Return: Returns true if the mouse button was clicked twice (within the defined time).
///
fn is_button_double_click(&self, kind: Option<MouseButton>, delay: Option<i32>) -> bool;
/// Determine if the mouse is being dragged with a specific mouse button down (for at least the defined delay).
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
/// * `delay` - The time which, if exceeded, assumes the mouse is being dragged. (optional, default: 100)
///
/// Return: Returns true if the mouse button was down for a duration exceeding delay.
///
fn is_button_drag(&self, kind: Option<MouseButton>, delay: Option<i32>) -> bool;
/// Determine if a specific mouse button is currently down.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
///
/// Return: Returns true is the mouse button is currently down, false otherwise.
///
fn is_button_down(&self, kind: Option<MouseButton>) -> bool;
/// Determine if a specific mouse button was pressed in the current update frame.
///
/// # Arguments
///
/// A press is defined as a new down - i.e. was up previous frame, and is down this frame.
/// * `kind` - The mouse button. (optional)
///
/// Return: Returns true is the mouse button was pressed in the current update, false otherwise.
///
fn is_button_press(&self, kind: Option<MouseButton>) -> bool;
/// Determine if a specific mouse button was released in the current update.
/// A release is defined as a new up - i.e. was down previous frame, and is up this frame.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
///
/// Return: Returns true is the mouse button was released in the current update, false otherwise.
///
fn is_button_release(&self, kind: Option<MouseButton>) -> bool;
/// Determine the duration a specific mouse button is down.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
/// * `as_time` - If true then returns duration as milliseconds, else returns duration as frame updates. (optional, default: true)
/// * `is_previous If true then returns the previous duration down (the time held prior to the most recent release). (optional, default: false)
///
/// Return: The duration a specific mouse button is down.
///
fn get_button_down_duration(&self, kind: Option<MouseButton>, as_time: Option<bool>, is_previous: Option<bool>)
-> i32;
/// Determine the duration a specific mouse button is up.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
/// * `as_time` - If true then returns duration as milliseconds, else returns duration as frame updates. (optional, default: true)
/// * `is_previous` - If true then returns the previous duration up (the time unused prior to the most recent press). (optional, default: false)
///
/// Return: The duration a specific mouse button is up.
///
fn get_button_up_duration(&self, kind: Option<MouseButton>, as_time: Option<bool>, is_previous: Option<bool>) -> i32;
/// Determine the horizontal movement of the mouse since a specific mouse button was pressed.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
///
/// Return: The horizontal movement of the mouse.
///
fn get_button_drag_width(&self, kind: Option<MouseButton>) -> i32;
/// Determine the vertical movement of the mouse since a specific mouse button was pressed.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
///
/// Return: The vertical movement of the mouse.
///
fn get_button_drag_height(&self, kind: Option<MouseButton>) -> i32;
/// Determine the horizontal position of the mouse when a specific mouse button was last clicked.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
///
/// Return: The horizontal position of the mouse.
///
fn get_button_last_clicked_x(&self, kind: Option<MouseButton>) -> i32;
/// Determine the vertical position of the mouse when a specific mouse button was last clicked.
///
/// # Arguments
///
/// * `kind` - The mouse button. (optional)
///
/// Return: The vertical position of the mouse.
///
fn get_button_last_clicked_y(&self, kind: Option<MouseButton>) -> i32;
}