mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
[glium] update to latest glium with EventLoop and vsync
This commit is contained in:
@@ -10,6 +10,6 @@ egui = { path = "../egui", features = ["with_serde"] }
|
||||
|
||||
chrono = { version = "0.4" }
|
||||
clipboard = "0.5"
|
||||
glium = "0.24"
|
||||
glium = "0.27"
|
||||
serde_json = "1"
|
||||
webbrowser = "0.5"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#![deny(warnings)]
|
||||
#![warn(clippy::all)]
|
||||
#![allow(clippy::single_match)]
|
||||
#![allow(deprecated)] // TODO: remove
|
||||
mod painter;
|
||||
|
||||
pub use painter::Painter;
|
||||
@@ -8,7 +9,7 @@ pub use painter::Painter;
|
||||
use {
|
||||
clipboard::{ClipboardContext, ClipboardProvider},
|
||||
egui::*,
|
||||
glium::glutin::{self, VirtualKeyCode},
|
||||
glium::glutin::{self, event::VirtualKeyCode},
|
||||
};
|
||||
|
||||
pub fn init_clipboard() -> Option<ClipboardContext> {
|
||||
@@ -21,88 +22,101 @@ pub fn init_clipboard() -> Option<ClipboardContext> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input_event(
|
||||
event: glutin::Event,
|
||||
pub fn input_to_egui(
|
||||
event: glutin::event::WindowEvent,
|
||||
clipboard: Option<&mut ClipboardContext>,
|
||||
raw_input: &mut RawInput,
|
||||
running: &mut bool,
|
||||
) {
|
||||
use glutin::WindowEvent::*;
|
||||
use glutin::event::WindowEvent::*;
|
||||
match event {
|
||||
glutin::Event::WindowEvent { event, .. } => match event {
|
||||
CloseRequested | Destroyed => *running = false,
|
||||
CloseRequested | Destroyed => *running = false,
|
||||
|
||||
Resized(glutin::dpi::LogicalSize { width, height }) => {
|
||||
raw_input.screen_size = vec2(width as f32, height as f32);
|
||||
}
|
||||
MouseInput { state, .. } => {
|
||||
raw_input.mouse_down = state == glutin::ElementState::Pressed;
|
||||
}
|
||||
CursorMoved { position, .. } => {
|
||||
raw_input.mouse_pos = Some(pos2(position.x as f32, position.y as f32));
|
||||
}
|
||||
CursorLeft { .. } => {
|
||||
raw_input.mouse_pos = None;
|
||||
}
|
||||
ReceivedCharacter(ch) => {
|
||||
if !should_ignore_char(ch) {
|
||||
if ch == '\r' {
|
||||
raw_input.events.push(Event::Text("\n".to_owned()));
|
||||
} else {
|
||||
raw_input.events.push(Event::Text(ch.to_string()));
|
||||
}
|
||||
Resized(physical_size) => {
|
||||
raw_input.screen_size =
|
||||
egui::vec2(physical_size.width as f32, physical_size.height as f32)
|
||||
/ raw_input.pixels_per_point.unwrap();
|
||||
}
|
||||
|
||||
ScaleFactorChanged {
|
||||
scale_factor,
|
||||
new_inner_size,
|
||||
} => {
|
||||
raw_input.pixels_per_point = Some(scale_factor as f32);
|
||||
raw_input.screen_size =
|
||||
egui::vec2(new_inner_size.width as f32, new_inner_size.height as f32)
|
||||
/ (scale_factor as f32);
|
||||
}
|
||||
|
||||
MouseInput { state, .. } => {
|
||||
raw_input.mouse_down = state == glutin::event::ElementState::Pressed;
|
||||
}
|
||||
CursorMoved { position, .. } => {
|
||||
raw_input.mouse_pos = Some(pos2(
|
||||
position.x as f32 / raw_input.pixels_per_point.unwrap(),
|
||||
position.y as f32 / raw_input.pixels_per_point.unwrap(),
|
||||
));
|
||||
}
|
||||
CursorLeft { .. } => {
|
||||
raw_input.mouse_pos = None;
|
||||
}
|
||||
ReceivedCharacter(ch) => {
|
||||
if !should_ignore_char(ch) {
|
||||
if ch == '\r' {
|
||||
raw_input.events.push(Event::Text("\n".to_owned()));
|
||||
} else {
|
||||
raw_input.events.push(Event::Text(ch.to_string()));
|
||||
}
|
||||
}
|
||||
KeyboardInput { input, .. } => {
|
||||
if let Some(virtual_keycode) = input.virtual_keycode {
|
||||
// TODO: If mac
|
||||
if input.modifiers.logo && virtual_keycode == VirtualKeyCode::Q {
|
||||
*running = false;
|
||||
}
|
||||
}
|
||||
KeyboardInput { input, .. } => {
|
||||
if let Some(virtual_keycode) = input.virtual_keycode {
|
||||
// TODO: If mac
|
||||
if input.modifiers.logo() && virtual_keycode == VirtualKeyCode::Q {
|
||||
*running = false;
|
||||
}
|
||||
|
||||
match virtual_keycode {
|
||||
VirtualKeyCode::Paste => {
|
||||
if let Some(clipboard) = clipboard {
|
||||
match clipboard.get_contents() {
|
||||
Ok(contents) => {
|
||||
raw_input.events.push(Event::Text(contents));
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Paste error: {}", err);
|
||||
}
|
||||
match virtual_keycode {
|
||||
VirtualKeyCode::Paste => {
|
||||
if let Some(clipboard) = clipboard {
|
||||
match clipboard.get_contents() {
|
||||
Ok(contents) => {
|
||||
raw_input.events.push(Event::Text(contents));
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Paste error: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
VirtualKeyCode::Copy => raw_input.events.push(Event::Copy),
|
||||
VirtualKeyCode::Cut => raw_input.events.push(Event::Cut),
|
||||
_ => {
|
||||
if let Some(key) = translate_virtual_key_code(virtual_keycode) {
|
||||
raw_input.events.push(Event::Key {
|
||||
key,
|
||||
pressed: input.state == glutin::ElementState::Pressed,
|
||||
});
|
||||
}
|
||||
}
|
||||
VirtualKeyCode::Copy => raw_input.events.push(Event::Copy),
|
||||
VirtualKeyCode::Cut => raw_input.events.push(Event::Cut),
|
||||
_ => {
|
||||
if let Some(key) = translate_virtual_key_code(virtual_keycode) {
|
||||
raw_input.events.push(Event::Key {
|
||||
key,
|
||||
pressed: input.state == glutin::event::ElementState::Pressed,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MouseWheel { delta, .. } => {
|
||||
match delta {
|
||||
glutin::MouseScrollDelta::LineDelta(x, y) => {
|
||||
raw_input.scroll_delta = vec2(x, y) * 24.0;
|
||||
}
|
||||
glutin::MouseScrollDelta::PixelDelta(delta) => {
|
||||
// Actually point delta
|
||||
raw_input.scroll_delta = vec2(delta.x as f32, delta.y as f32);
|
||||
}
|
||||
}
|
||||
MouseWheel { delta, .. } => {
|
||||
match delta {
|
||||
glutin::event::MouseScrollDelta::LineDelta(x, y) => {
|
||||
let line_height = 24.0; // TODO
|
||||
raw_input.scroll_delta = vec2(x, y) * line_height;
|
||||
}
|
||||
glutin::event::MouseScrollDelta::PixelDelta(delta) => {
|
||||
// Actually point delta
|
||||
raw_input.scroll_delta = vec2(delta.x as f32, delta.y as f32);
|
||||
}
|
||||
}
|
||||
// TODO: HiDpiFactorChanged
|
||||
_ => {
|
||||
// dbg!(event);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
_ => {
|
||||
// dbg!(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +140,7 @@ fn should_ignore_char(chr: char) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate_virtual_key_code(key: glutin::VirtualKeyCode) -> Option<egui::Key> {
|
||||
pub fn translate_virtual_key_code(key: VirtualKeyCode) -> Option<egui::Key> {
|
||||
use VirtualKeyCode::*;
|
||||
|
||||
Some(match key {
|
||||
@@ -157,15 +171,15 @@ pub fn translate_virtual_key_code(key: glutin::VirtualKeyCode) -> Option<egui::K
|
||||
})
|
||||
}
|
||||
|
||||
pub fn translate_cursor(cursor_icon: egui::CursorIcon) -> glutin::MouseCursor {
|
||||
pub fn translate_cursor(cursor_icon: egui::CursorIcon) -> glutin::window::CursorIcon {
|
||||
match cursor_icon {
|
||||
CursorIcon::Default => glutin::MouseCursor::Default,
|
||||
CursorIcon::PointingHand => glutin::MouseCursor::Hand,
|
||||
CursorIcon::ResizeHorizontal => glutin::MouseCursor::EwResize,
|
||||
CursorIcon::ResizeNeSw => glutin::MouseCursor::NeswResize,
|
||||
CursorIcon::ResizeNwSe => glutin::MouseCursor::NwseResize,
|
||||
CursorIcon::ResizeVertical => glutin::MouseCursor::NsResize,
|
||||
CursorIcon::Text => glutin::MouseCursor::Text,
|
||||
CursorIcon::Default => glutin::window::CursorIcon::Default,
|
||||
CursorIcon::PointingHand => glutin::window::CursorIcon::Hand,
|
||||
CursorIcon::ResizeHorizontal => glutin::window::CursorIcon::EwResize,
|
||||
CursorIcon::ResizeNeSw => glutin::window::CursorIcon::NeswResize,
|
||||
CursorIcon::ResizeNwSe => glutin::window::CursorIcon::NwseResize,
|
||||
CursorIcon::ResizeVertical => glutin::window::CursorIcon::NsResize,
|
||||
CursorIcon::Text => glutin::window::CursorIcon::Text,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +204,8 @@ pub fn handle_output(
|
||||
|
||||
display
|
||||
.gl_window()
|
||||
.set_cursor(translate_cursor(output.cursor_icon));
|
||||
.window()
|
||||
.set_cursor_icon(translate_cursor(output.cursor_icon));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -233,7 +233,7 @@ impl Painter {
|
||||
let index_buffer =
|
||||
glium::IndexBuffer::new(display, PrimitiveType::TrianglesList, &indices).unwrap();
|
||||
|
||||
let pixels_per_point = display.gl_window().get_hidpi_factor() as f32;
|
||||
let pixels_per_point = display.gl_window().window().scale_factor() as f32;
|
||||
let (width_pixels, height_pixels) = display.get_framebuffer_dimensions();
|
||||
let width_points = width_pixels as f32 / pixels_per_point;
|
||||
let height_points = height_pixels as f32 / pixels_per_point;
|
||||
|
||||
Reference in New Issue
Block a user