From 13b9a33270a3d5d6df81ef8bd1b056dcca635ef5 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 22 Dec 2018 04:02:31 +0100 Subject: Add view and MouseWheel / MouseClick events --- src/graphics.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/graphics.rs b/src/graphics.rs index 68dfa65..18ccfec 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use sfml::system::Vector2f; +use sfml::window::mouse::Button; use sfml::window::{ ContextSettings, @@ -11,6 +12,10 @@ use sfml::window::{ use sfml::graphics::{ RenderWindow, RenderTarget, + View, +}; + +use sfml::graphics::{ Texture, Image, Color, @@ -29,7 +34,10 @@ pub struct MapAssets; #[derive(Debug)] pub struct Graphics { + // sfml elements window: RenderWindow, + view: View, + // status running: bool, // loaded resources tilesets: HashMap, @@ -46,6 +54,7 @@ impl Graphics { ..Default::default() }; + // create window let mut window = RenderWindow::new( default_window_size, "Subconscious", @@ -56,12 +65,29 @@ impl Graphics { window.set_framerate_limit(default_framerate); window.set_vertical_sync_enabled(true); - return Graphics { + let mut graphics = Graphics { + // sfml elements window: window, + view: View::new( + Vector2f::new( + default_window_size.0 as f32 / 2.0, + default_window_size.1 as f32 / 2.0 + ), + Vector2f::new( + default_window_size.0 as f32, + default_window_size.1 as f32, + ), + ), + // status running: true, + // resources tilesets: HashMap::new(), textures: HashMap::new(), }; + + graphics.window.set_view(&graphics.view); + + return graphics; } pub fn is_running(self: &mut Self) -> bool { @@ -179,6 +205,23 @@ impl Graphics { self.window.close(); self.running = false; }, + Event::MouseWheelScrolled { wheel: _, delta, x, y } => { + + }, + Event::MouseButtonPressed { button, x: _, y: _ } => { + match button { + Button::Left => {}, + Button::Right => {} + _ => {}, + } + }, + Event::MouseButtonReleased { button, x: _, y: _ } => { + match button { + Button::Left => {} + Button::Right => {}, + _ => {}, + } + }, _ => {}, } } -- cgit v1.2.1