aboutsummaryrefslogtreecommitdiff
path: root/stockton-passes/src
diff options
context:
space:
mode:
Diffstat (limited to 'stockton-passes/src')
-rw-r--r--stockton-passes/src/ui.rs22
-rw-r--r--stockton-passes/src/window.rs46
2 files changed, 41 insertions, 27 deletions
diff --git a/stockton-passes/src/ui.rs b/stockton-passes/src/ui.rs
index 4b4e1c2..bc1ba69 100644
--- a/stockton-passes/src/ui.rs
+++ b/stockton-passes/src/ui.rs
@@ -117,7 +117,9 @@ impl<'a> DrawPass for UiDrawPass<'a> {
}
let (_out, shapes) = ui.end_frame();
- let screen = ui.dimensions().ok_or(anyhow!("UI not set up properly."))?;
+ let screen = ui
+ .dimensions()
+ .ok_or_else(|| anyhow!("UI not set up properly."))?;
let shapes = ui.ctx().tessellate(shapes);
for ClippedMesh(rect, tris) in shapes.iter() {
@@ -376,23 +378,15 @@ impl LoadableImage for UiTexture {
fn height(&self) -> u32 {
self.0.height as u32
}
- fn copy_row(&self, y: u32, ptr: *mut u8) {
+ unsafe fn copy_row(&self, y: u32, ptr: *mut u8) {
let row_size = self.0.width as u32;
let pixels = &self.0.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize];
for (i, x) in pixels.iter().enumerate() {
- unsafe {
- *ptr.offset(i as isize * 4) = 255;
- *ptr.offset((i as isize * 4) + 1) = 255;
- *ptr.offset((i as isize * 4) + 2) = 255;
- *ptr.offset((i as isize * 4) + 3) = *x;
- }
- }
- }
-
- unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize) {
- for y in 0..self.height() {
- self.copy_row(y, ptr.offset((row_size * y as usize).try_into().unwrap()));
+ *ptr.offset(i as isize * 4) = 255;
+ *ptr.offset((i as isize * 4) + 1) = 255;
+ *ptr.offset((i as isize * 4) + 2) = 255;
+ *ptr.offset((i as isize * 4) + 3) = *x;
}
}
}
diff --git a/stockton-passes/src/window.rs b/stockton-passes/src/window.rs
index c806fa0..46ba1a1 100644
--- a/stockton-passes/src/window.rs
+++ b/stockton-passes/src/window.rs
@@ -84,17 +84,7 @@ pub struct UiState {
}
impl UiState {
- pub fn new() -> Self {
- UiState {
- ctx: CtxRef::default(),
- raw_input: RawInput::default(),
- frame_active: false,
- modifiers: Default::default(),
- pointer_pos: Pos2::new(0.0, 0.0),
- }
- }
-
- pub fn populate_initial_state<'a, T: DrawPass>(&mut self, renderer: &Renderer<T>) {
+ pub fn populate_initial_state<T: DrawPass>(&mut self, renderer: &Renderer<T>) {
let props = &renderer.context().target_chain().properties();
self.set_dimensions(props.extent.width, props.extent.height);
self.set_pixels_per_point(Some(renderer.context().pixels_per_point()));
@@ -163,19 +153,49 @@ impl UiState {
fn handle_action(&mut self, action: KBAction) {
// TODO
match action {
- KBAction::MousePress(stockton_input::MouseButton::Left) => {
+ KBAction::MousePress(btn) => {
self.raw_input.events.push(Event::PointerButton {
pos: self.pointer_pos,
- button: egui::PointerButton::Primary,
+ button: match btn {
+ stockton_input::MouseButton::Left => egui::PointerButton::Primary,
+ stockton_input::MouseButton::Right => egui::PointerButton::Secondary,
+ stockton_input::MouseButton::Middle => egui::PointerButton::Middle,
+ stockton_input::MouseButton::Other(_) => todo!(),
+ },
pressed: true,
modifiers: self.modifiers,
});
}
+ KBAction::MouseRelease(btn) => {
+ self.raw_input.events.push(Event::PointerButton {
+ pos: self.pointer_pos,
+ button: match btn {
+ stockton_input::MouseButton::Left => egui::PointerButton::Primary,
+ stockton_input::MouseButton::Right => egui::PointerButton::Secondary,
+ stockton_input::MouseButton::Middle => egui::PointerButton::Middle,
+ stockton_input::MouseButton::Other(_) => todo!(),
+ },
+ pressed: false,
+ modifiers: self.modifiers,
+ });
+ }
_ => (),
}
}
}
+impl Default for UiState {
+ fn default() -> Self {
+ UiState {
+ ctx: CtxRef::default(),
+ raw_input: RawInput::default(),
+ frame_active: false,
+ modifiers: Default::default(),
+ pointer_pos: Pos2::new(0.0, 0.0),
+ }
+ }
+}
+
pub struct WindowFlow {
window_events: Receiver<WindowEvent>,
update_control_flow: Arc<RwLock<ControlFlow>>,