diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-10-11 08:21:10 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-10-11 08:21:10 +1300 |
commit | 8e08d723ff7a853f2b10dc0f1408911d5801cea8 (patch) | |
tree | 50efd2967e93f8bc1009f242a405ec18335f0aa6 /src/lib.rs | |
parent | a6e97019bd53e4478c846f8f636c18ecb53bece2 (diff) | |
download | phosphor-8e08d723ff7a853f2b10dc0f1408911d5801cea8.zip |
Rewrite phosphor
This has been a long-awaited task, the code has been accumulating small
changes for a while now. This commit consolidates all these changes in
order to make the code more readable and maintainable for the future.
Notable changes:
- Remove the concept of a ProgramController
- Remove all of the dead OpenGL stub code
- Update winit to version 28.1, from 27.4
- Use softbuffer for writing pixels to the native display server
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 60 |
1 files changed, 45 insertions, 15 deletions
@@ -1,25 +1,16 @@ -mod keyboard_input; -mod press_state; -mod program_controller; -mod render_hint; -mod render_request; +mod render; mod window; mod window_controller; mod window_manager; -use window::Window; - -pub use keyboard_input::KeyboardInput; -pub use press_state::PressState; -pub use program_controller::{DefaultProgramController, ProgramController}; -pub use render_hint::RenderHint; -pub use render_request::RenderRequest; -pub use window_controller::WindowController; -pub use window_manager::WindowManager; +pub use render::*; +pub use window::*; +pub use window_controller::*; +pub use window_manager::*; pub use buffer::{Buffer, Colour}; pub use winit::{ - event::ModifiersState, + event::{ModifiersState, ElementState}, event::VirtualKeyCode as KeyCode, window::CursorIcon, }; @@ -27,3 +18,42 @@ pub use winit::{ pub type Point = geometry::Point<i32>; pub type Dimensions = geometry::Dimensions<u32>; pub type Rect = geometry::Rect<i32, u32>; + +// ----------------------------------------------------------------------------- + +#[derive(Copy, Clone)] +pub struct KeyboardInput { + pub action: Action, + pub key: KeyCode, +} + +impl TryFrom<winit::event::KeyboardInput> for KeyboardInput { + type Error = (); + + fn try_from(input: winit::event::KeyboardInput) -> Result<Self, ()> { + if let Some(key) = input.virtual_keycode { + Ok( Self { action: input.state.into(), key } ) + } else { + Err(()) + } + } +} + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Copy, PartialEq, Debug)] +pub enum Action { Pressed, Released } + +impl Action { + pub fn is_pressed(&self) -> bool { *self == Self::Pressed } + pub fn is_released(&self) -> bool { *self == Self::Released } +} + +impl From<ElementState> for Action { + fn from(value: ElementState) -> Self { + match value { + ElementState::Pressed => Action::Pressed, + ElementState::Released => Action::Released, + } + } +} |