Commit a3704415 authored by Florian Blasius's avatar Florian Blasius 🤘

[#157] initial window event handling

parent 1474ea1c
......@@ -130,7 +130,7 @@ dependencies = [
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
"scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -302,7 +302,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.2.0"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
......@@ -468,13 +468,21 @@ version = "0.3.0"
dependencies = [
"cssparser 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dces 0.1.6 (git+https://gitlab.redox-os.org/redox-os/dces-rust.git)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
"orbfont 0.1.9 (git+https://gitlab.redox-os.org/redox-os/orbfont.git)",
"orbgl 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
"orbgl_api 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
"orbgl_shapes 0.1.0 (git+https://gitlab.redox-os.org/redox-os/orbgl.git)",
"orbimage 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"orbtk-windows 0.1.0",
]
[[package]]
name = "orbtk-windows"
version = "0.1.0"
dependencies = [
"orbclient 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -694,7 +702,7 @@ version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
......@@ -1033,7 +1041,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
"checksum jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c8b7d43206b34b3f94ea9445174bda196e772049b9bddbc620c9d29b2d20110d"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047"
"checksum linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70fb39025bc7cdd76305867c4eccf2f2dcf6e9a57f5b21a93e1c2d86cd03ec9e"
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
......
......@@ -23,15 +23,19 @@ path = "src/lib.rs"
[dependencies]
cssparser = "0.17.0"
lazy_static = "1.2.0"
lazy_static = "1.3.0"
# dces = { path = "../dces-rust"}
dces = { git = "https://gitlab.redox-os.org/redox-os/dces-rust.git" }
orbclient = "0.3.20"
orbclient = "0.3.9"
orbfont = { git = "https://gitlab.redox-os.org/redox-os/orbfont.git" }
orbimage = "0.1.16"
orbimage = "0.1.9"
# orbgl_api = { path = "../orbgl/orbgl_api" }
orbgl_api = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
# orbgl = { path = "../orbgl/orbgl" }
orbgl = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
# orbgl_shapes = { path = "../orbgl/orbgl_shapes" }
orbgl_shapes = { git = "https://gitlab.redox-os.org/redox-os/orbgl.git" }
orbtk-windows = { version = "0.1.0", path = "crates/windows" }
[workspace]
\ No newline at end of file
CMakeLists.txt not found in /Users/florian.blasius/Projects/Focus-Time/orbtk Select CMakeLists.txt file...
[package]
name = "orbtk-windows"
version = "0.1.0"
authors = ["Florian Blasius <flovanpt@posteo.de>"]
description = "OrbTk Window Abstraction Layer."
repository = "https://gitlab.redox-os.org/redox-os/orbtk"
license = "MIT"
keywords = ["windowing"]
edition = "2018"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
orbclient = "0.3.9"
[features]
default = []
/// Used to identify a specific key by code.
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
pub enum KeyCode {
// Numeric keys
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
Key0,
// Letter keys
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
// Function keys.
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
// Actions.
Escape,
Snapshot,
Scroll,
Pause,
Insert,
Home,
Delete,
End,
PageDown,
PageUp,
Back,
Return,
Space,
Compose,
Caret,
// Arrow keys.
Left,
Up,
Right,
Down,
// NumPad keys.
Numlock,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
// Additional keys.
AbntC1,
AbntC2,
Add,
Apostrophe,
Apps,
At,
Ax,
Backslash,
Calculator,
Capital,
Colon,
Comma,
Convert,
Decimal,
Divide,
Equals,
Grave,
Kana,
Kanji,
LAlt,
LBracket,
LControl,
LShift,
LWin,
Mail,
MediaSelect,
MediaStop,
Minus,
Multiply,
Mute,
MyComputer,
NavigateForward,
NavigateBackward,
NextTrack,
NoConvert,
NumpadComma,
NumpadEnter,
NumpadEquals,
OEM102,
Period,
PlayPause,
Power,
PrevTrack,
RAlt,
RBracket,
RControl,
RShift,
RWin,
Semicolon,
Slash,
Sleep,
Stop,
Subtract,
Sysrq,
Tab,
Underline,
Unlabeled,
VolumeDown,
VolumeUp,
Wake,
WebBack,
WebFavorites,
WebForward,
WebHome,
WebRefresh,
WebSearch,
WebStop,
Yen,
Copy,
Paste,
Cut,
}
/// Represents keyboard modifier keys.
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
pub struct Modifier {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub command: bool
}
/// Represents the current state of a key.
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum KeyState {
Pressed,
Released
}
/// Keyboard key scan code. Depends on hardware.
pub type ScanCode = u32;
/// Describes a keyboard input event.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct KeyEvent {
/// Identifies the physical key pressed.
pub scan_code: ScanCode,
pub state: KeyState,
/// Represents the current code of the key.
pub key_code: Option<KeyCode>,
/// Represents the active keyboard modifier state.
pub modifiers: Modifier
}
\ No newline at end of file
//! This module contains all resources to handles events.
//!
pub use self::key::*;
pub use self::mouse::*;
pub use self::window::*;
mod key;
mod mouse;
mod window;
/// Describes a event form a window.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Event {
KeyEvent,
MouseEvent,
WindowEvent
}
\ No newline at end of file
/// Represents the current state of a mouse button.
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum ButtonState {
Pressed,
Released
}
/// Represents a mouse button.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MouseButton {
Left,
Middle,
Right,
Other
}
/// Represents a mouse button event.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MouseEvent {
pub button: MouseButton,
pub state: ButtonState
}
\ No newline at end of file
/// Represents a mouse button event.
pub enum WindowEvent {
Resized((f64, f64)),
Closed,
}
\ No newline at end of file
pub mod window;
pub mod events;
\ No newline at end of file
use orbclient::{Window as OrbWindow, EventOption, Renderer, WindowFlag};
use crate::events::*;
/// Window implementation for OrbClient.
pub struct Window {
inner: OrbWindow,
}
impl super::Window for Window {
fn set_title(&mut self, title: impl Into<String>) {
self.inner.set_title(&title.into());
}
fn title(&self) -> String {
self.inner.title()
}
fn set_position(&mut self, x: f64, y: f64) {
self.inner.set_pos(x as i32, y as i32);
}
fn position(&self) -> (f64, f64) {
(self.inner.x() as f64, self.inner.y() as f64)
}
fn set_size(&mut self, width: f64, height: f64) {
self.inner.set_size(width as u32, height as u32);
}
fn size(&self) -> (f64, f64) {
(self.inner.width() as f64, self.inner.height() as f64)
}
fn sync(&mut self) {
self.inner.sync();
}
fn events(&mut self) -> Vec<Event> {
let mut events: Vec<Event> = vec![];
for event in self.inner.events() {
match event.to_option() {
// EventOption::Quit(_) => events.push(Event::WindowEvent::Close),
_ => {}
}
}
events
}
}
impl Drop for Window {
fn drop(&mut self) {
self.inner.sync();
}
}
impl From<super::WindowBuilder> for Window {
fn from(builder: super::WindowBuilder) -> Self {
let mut flags = vec![];
if builder.resizable {
flags.push(WindowFlag::Resizable);
}
Window {
inner: OrbWindow::new_flags(
builder.position.0 as i32,
builder.position.1 as i32,
builder.size.0 as u32,
builder.size.1 as u32,
&builder.title,
&flags,
).unwrap()
}
}
}
//! This module contains all resources to create and use a window.
use super::events::*;
#[cfg(not(target_arch = "wasm32"))]
#[path = "impl_orbclient.rs"]
mod implementation;
/// Used to define a window.
pub trait Window {
/// Creates a new `WindowBuilder` with default values.
fn create() -> WindowBuilder {
WindowBuilder::new()
}
/// Sets the title.
fn set_title(&mut self, title: impl Into<String>);
/// Gets the title.
fn title(&self) -> String;
/// Sets the position.
fn set_position(&mut self, x: f64, y: f64);
/// Gets the position.
fn position(&self) -> (f64, f64);
/// Sets the size.
fn set_size(&mut self, width: f64, height: f64);
/// Gets the size.
fn size(&self) -> (f64, f64);
/// Swaps the buffers.
fn sync(&mut self);
/// Request current window events.
fn events(&mut self) -> Vec<Event>;
}
/// Used to build a window, specifying additional details.
#[derive(Default, Debug, PartialEq)]
pub struct WindowBuilder {
title: String,
size: (f64, f64),
position: (f64, f64),
resizable: bool,
}
impl WindowBuilder {
/// Creates a new border builder with default values.
pub fn new() -> WindowBuilder {
WindowBuilder::default()
}
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = title.into();
self
}
/// Inserts the window bounds.
pub fn bounds(mut self, bounds: impl Into<(f64, f64, f64, f64)>) -> Self {
let bounds = bounds.into();
self.position = (bounds.0, bounds.1);
self.size = (bounds.2, bounds.3);
self
}
/// Inserts a position.
pub fn position(mut self, position: impl Into<(f64, f64)>) -> Self {
self.position = position.into();
self
}
/// Inserts a size.
pub fn size(mut self, size: impl Into<(f64, f64)>) -> Self {
self.size = size.into();
self
}
/// Inserts a value that indicates wether the window is resizable.
pub fn resizable(mut self, resizable: impl Into<bool>) -> Self {
self.resizable = resizable.into();
self
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment