Commit 519ce936 authored by Florian Blasius's avatar Florian Blasius 🤘

[#168] remove last orbtk dependencies from

backend / window shell. Start reimplemenation of shell events.
parent c2f5b8a9
......@@ -9,7 +9,7 @@ use std::{
use dces::prelude::{Entity, World};
use crate::prelude::*;
use crate::backend::{WindowBuilder, ShellRunner};
use crate::backend::{WindowBuilder, ShellRunner, Updater};
use crate::systems::*;
pub use self::global::*;
......@@ -65,6 +65,7 @@ impl Application {
world.entity_component_manager().register_component(window, Bounds::from((0.0, 0.0, constraint.width(), constraint.height())));
let window_shell = Rc::new(RefCell::new(WindowBuilder::new(WindowAdapter {
root: window,
render_objects: render_objects.clone(),
layouts: layouts.clone(),
handlers: handlers.clone(),
......@@ -135,7 +136,9 @@ impl Application {
self.runners.push(ShellRunner {
world: Some(world),
updater: Box::new(WorldWrapper {
world
}),
window_shell,
update,
running,
......
......@@ -4,7 +4,7 @@ use std::{
rc::Rc,
};
use dces::prelude::Entity;
use dces::prelude::{Entity, World};
use crate::prelude::*;
......@@ -19,6 +19,7 @@ pub struct WindowAdapter {
pub states: Rc<RefCell<BTreeMap<Entity, Rc<dyn State>>>>,
pub event_queue: EventQueue,
pub messages: BTreeMap<Entity, Vec<MessageBox>>,
pub root: Entity,
}
// todo: remove all render_objects etc. from system, handle all with window adapter
......@@ -29,8 +30,39 @@ pub struct WindowAdapter {
// }
// }
pub struct WorldWrapper {
pub world: World<Tree>,
}
impl backend::Updater for WorldWrapper {
fn update(&mut self) {
self.world.run();
}
}
impl backend::WindowAdapter for WindowAdapter {
fn update(&mut self) {}
fn mouse_event(&mut self, event: backend::MouseEvent) {
match event.state {
backend::ButtonState::Up => {
self.event_queue.register_event(MouseUpEvent {
x: event.x,
y: event.y,
button: event.button,
}, self.root)
},
backend::ButtonState::Down => {
self.event_queue.register_event(MouseDownEvent {
x: event.x,
y: event.y,
button: event.button,
}, self.root)
}
}
// self.event_queue.register_event(event: E, source: Entity)
}
}
impl Into<Box<backend::WindowAdapter>> for WindowAdapter {
......
......@@ -69,9 +69,10 @@ pub trait FontMeasure {
pub trait WindowAdapter {
fn update(&mut self);
fn mouse_event(&mut self, event: MouseEvent);
}
pub use self::platform::{WindowBuilder, ShellRunner, WindowShell};
pub use self::platform::{WindowBuilder, ShellRunner, WindowShell, Updater, MouseButton, MouseEvent, ButtonState };
pub use self::platform::FONT_MEASURE;
#[cfg(not(platform_arch = "wasm32"))]
......
......@@ -8,6 +8,31 @@ use orbgl_api::Canvas;
use crate::backend::*;
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum MouseButton {
Left,
Middle,
Right,
}
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum ButtonState {
Down,
Up
}
#[derive(Debug)]
pub struct MouseEvent {
pub x: f64,
pub y: f64,
pub button: MouseButton,
pub state: ButtonState
}
// todo: generic adapter A where A : ShellAdapber...
/// Implementation of the OrbClient based backend.
......@@ -15,8 +40,6 @@ pub struct WindowShell<A> where A: WindowAdapter {
pub inner: OrbWindow,
mouse_buttons: (bool, bool, bool),
mouse_position: Point,
// event_queue: RefCell<EventQueue>,
// messages: RefCell<BTreeMap<Entity, Vec<MessageBox>>>,
pub canvas: Canvas,
adapter: A,
}
......@@ -39,8 +62,6 @@ impl<A> WindowShell<A> where A: WindowAdapter {
inner,
mouse_buttons: (false, false, false),
mouse_position: Point::default(),
// event_queue: RefCell::new(EventQueue::default()),
// messages: RefCell::new(BTreeMap::new()),
canvas,
adapter,
}
......@@ -76,14 +97,12 @@ impl<A> WindowShell<A> where A: WindowAdapter {
}
};
// todo call adapter method
// self.event_queue.borrow_mut().register_event(
// MouseUpEvent {
// button,
// position: self.mouse_position,
// },
// 0,
// )
self.adapter.mouse_event(MouseEvent {
x: self.mouse_position.x,
y: self.mouse_position.y,
button,
state: ButtonState::Up
});
} else {
let button = {
if button.left {
......@@ -95,14 +114,12 @@ impl<A> WindowShell<A> where A: WindowAdapter {
}
};
// todo: call adapter method
// self.event_queue.borrow_mut().register_event(
// MouseDownEvent {
// button,
// position: self.mouse_position,
// },
// 0,
// );
self.adapter.mouse_event(MouseEvent {
x: self.mouse_position.x,
y: self.mouse_position.y,
button,
state: ButtonState::Down
});
}
self.mouse_buttons = (button.left, button.middle, button.right);
......@@ -168,10 +185,14 @@ impl<A> Drop for WindowShell<A> where A: WindowAdapter {
/// Implementation of the OrbClient based backend runner.
pub struct ShellRunner<A> where A: WindowAdapter {
pub world: Option<World<Tree>>,
pub window_shell: Rc<RefCell<WindowShell<A>>>,
pub update: Rc<Cell<bool>>,
pub running: Rc<Cell<bool>>,
pub updater: Box<Updater>,
}
pub trait Updater {
fn update(&mut self);
}
impl<A> ShellRunner<A> where A: WindowAdapter {
......@@ -181,9 +202,7 @@ impl<A> ShellRunner<A> where A: WindowAdapter {
break;
}
if let Some(world) = &mut self.world {
world.run();
}
self.updater.update();
self.update.set(false);
......
......@@ -4,7 +4,7 @@ use std::sync::Arc;
use orbfont::Font;
pub use self::backend::{WindowBuilder, WindowShell, ShellRunner};
pub use self::backend::{WindowBuilder, WindowShell, ShellRunner, Updater, MouseButton, MouseEvent, ButtonState };
use crate::backend::*;
......
use std::rc::Rc;
use crate::prelude::*;
use crate::{prelude::*, backend::MouseButton};
/// Checks if the given point is inside of a widget.
pub fn check_mouse_condition(mouse_position: Point, widget: &WidgetContainer<'_>) -> bool {
......@@ -15,13 +15,6 @@ pub fn check_mouse_condition(mouse_position: Point, widget: &WidgetContainer<'_>
return rect.contains((mouse_position.x, mouse_position.y));
}
/// Describes a mouse button.
pub enum MouseButton {
Left,
Middle,
Right,
}
pub struct MouseMoveEvent {
pub position: Point,
}
......@@ -30,7 +23,9 @@ impl Event for MouseMoveEvent {}
pub struct MouseUpEvent {
pub button: MouseButton,
pub position: Point,
pub x: f64,
pub y: f64,
}
impl Event for MouseUpEvent {}
......@@ -43,7 +38,9 @@ impl Event for ClickEvent {}
pub struct MouseDownEvent {
pub button: MouseButton,
pub position: Point,
pub x: f64,
pub y: f64,
}
impl Event for MouseDownEvent {}
......
......@@ -40,7 +40,7 @@ impl EventSystem {
// MouseDownEvent handling
if let Ok(event) = event.downcast_ref::<MouseDownEvent>() {
if check_mouse_condition(event.position, &widget) {
if check_mouse_condition(Point::new(event.x, event.y), &widget) {
matching_nodes.push(node);
}
......@@ -121,7 +121,7 @@ impl EventSystem {
let mut pressed = false;
let mut in_mouse_pos = false;
if check_mouse_condition(event.position, &widget) {
if check_mouse_condition(Point::new(event.x, event.y), &widget) {
in_mouse_pos = true;
}
......@@ -142,7 +142,7 @@ impl EventSystem {
if in_mouse_pos {
new_events.push(EventBox::new(
ClickEvent {
position: event.position,
position: Point::new(event.x, event.y),
},
EventStrategy::BottomUp,
*node,
......@@ -186,8 +186,6 @@ impl System<Tree> for EventSystem {
fn run(&self, tree: &Tree, ecm: &mut EntityComponentManager) {
let mut backend = self.backend.borrow_mut();
let adapter = backend.adapter();
// let blub = adapter.context_provider();
let mut new_events = vec![];
......
use std::collections::BTreeMap;
use dces::prelude::{Entity, EntityComponentManager};
use orbgl_api::Canvas;
......
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