diff options
author | Nao Pross <naopross@thearcway.org> | 2018-12-22 04:02:31 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-12-22 04:02:31 +0100 |
commit | 13b9a33270a3d5d6df81ef8bd1b056dcca635ef5 (patch) | |
tree | 77a2b9f8a8b9ac578cf8ddfe17d0263ae34a6ad8 | |
parent | Move tilesets inside res/maps, add error messages for map assets loading (diff) | |
download | Subconscious-rs-13b9a33270a3d5d6df81ef8bd1b056dcca635ef5.tar.gz Subconscious-rs-13b9a33270a3d5d6df81ef8bd1b056dcca635ef5.zip |
Add view and MouseWheel / MouseClick events
Diffstat (limited to '')
-rw-r--r-- | src/graphics.rs | 45 |
1 files changed, 44 insertions, 1 deletions
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<u32, Image>, @@ -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 => {}, + _ => {}, + } + }, _ => {}, } } |