mirror of
https://github.com/italicsjenga/mini_gl_fb.git
synced 2024-11-22 07:21:30 +11:00
Fix botched mouse handling
This commit is contained in:
parent
f71d48b814
commit
8df4325917
11
CHANGELOG.md
Normal file
11
CHANGELOG.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Change Log
|
||||
|
||||
## [v0.5.1] - 2018-08-25
|
||||
|
||||
Started a change log!
|
||||
|
||||
### Fixed
|
||||
|
||||
- Vertical mouse position was wrong, v0.5.0 changed coordinate systems from a window-like one
|
||||
to a UV-like one (0, 0 is now the lower left) but the glutin basic input feature did not
|
||||
respect this and reported old style mouse positions
|
|
@ -4,6 +4,7 @@ use mini_gl_fb::{Config, BufferFormat};
|
|||
use mini_gl_fb::glutin::{MouseButton, VirtualKeyCode};
|
||||
|
||||
use std::time::SystemTime;
|
||||
use std::cmp;
|
||||
|
||||
const WIDTH: usize = 200;
|
||||
const HEIGHT: usize = 200;
|
||||
|
@ -45,7 +46,9 @@ fn main() {
|
|||
|
||||
if input.mouse_is_down(MouseButton::Left) {
|
||||
// Mouse was pressed
|
||||
let (x, y) = input.mouse_pos;
|
||||
let (mut x, mut y) = input.mouse_pos;
|
||||
x = cmp::min(x, WIDTH - 1);
|
||||
y = cmp::min(y, HEIGHT - 1);
|
||||
cells[y * WIDTH + x] = true;
|
||||
fb.update_buffer(&cells);
|
||||
// Give the user extra time to make something pretty each time they click
|
||||
|
|
|
@ -16,7 +16,9 @@ pub struct GlutinBreakout {
|
|||
}
|
||||
|
||||
pub struct BasicInput {
|
||||
/// The mouse position in buffer coordinates
|
||||
/// The mouse position in buffer coordinates.
|
||||
///
|
||||
/// The bottom left of the window is (0, 0).
|
||||
pub mouse_pos: (usize, usize),
|
||||
/// Stores whether a mouse button was down and is down, in that order.
|
||||
///
|
||||
|
|
|
@ -307,7 +307,11 @@ impl Internal {
|
|||
let (x, y): (f64, f64) = pos.to_physical(dpi_factor).into();
|
||||
let x_scale = self.fb.buffer_width as f64 / (self.fb.vp_width as f64);
|
||||
let y_scale = self.fb.buffer_height as f64 / (self.fb.vp_height as f64);
|
||||
let mouse_pos = ((x * x_scale).floor() as usize, (y * y_scale).floor() as usize);
|
||||
let mut mouse_pos = (
|
||||
(x * x_scale).floor() as usize,
|
||||
// use the OpenGL texture coordinate system instead of window coordinates
|
||||
(self.fb.buffer_height as f64 - y * y_scale).floor() as usize
|
||||
);
|
||||
input.mouse_pos = mouse_pos;
|
||||
}
|
||||
|
||||
|
|
|
@ -307,7 +307,8 @@ impl MiniGlFb {
|
|||
/// Provides an easy interface for rudimentary input handling.
|
||||
///
|
||||
/// Automatically handles close events and partially handles resizes (the caller chooses if
|
||||
/// a redraw is necessary).
|
||||
/// a redraw is necessary; and the window will only actually physically change size if it is
|
||||
/// a resizable window).
|
||||
///
|
||||
/// Polls for window events and summarizes the input events for you each frame. See
|
||||
/// `BasicInput` for the information that is provided to you. You will need to use some
|
||||
|
|
Loading…
Reference in a new issue