├── .gitignore ├── .travis.yml ├── Cargo.png ├── Cargo.toml ├── LICENSE ├── README.md ├── examples └── hello_piston.rs ├── scripts ├── id_rsa.enc └── travis-doc-upload.cfg └── src ├── lib.rs └── prelude.rs /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *~ 3 | *# 4 | *.o 5 | *.so 6 | *.swp 7 | *.old 8 | *.bak 9 | *.kate-swp 10 | *.dylib 11 | *.dSYM 12 | *.dll 13 | *.rlib 14 | *.dummy 15 | *.exe 16 | *-test 17 | /bin/main 18 | /bin/test-internal 19 | /bin/test-external 20 | /doc/ 21 | /target/ 22 | /build/ 23 | /.rust/ 24 | rusti.sh 25 | watch.sh 26 | /examples/** 27 | !/examples/*.rs 28 | !/examples/assets/ 29 | !/bin/assets/ 30 | 31 | Cargo.lock 32 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - stable 4 | - beta 5 | - nightly 6 | script: 7 | - cargo test -v 8 | - cargo doc -v 9 | after_success: 10 | - curl http://docs.piston.rs/travis-doc-upload.sh | sh 11 | -------------------------------------------------------------------------------- /Cargo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/piston_window/4b3991dce7ec9050fb2e239dd455c11ef6484d21/Cargo.png -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | 3 | name = "piston_window" 4 | version = "0.132.0" 5 | authors = ["bvssvni "] 6 | keywords = ["window", "piston"] 7 | description = "The official Piston window wrapper for the Piston game engine" 8 | license = "MIT" 9 | readme = "README.md" 10 | repository = "https://github.com/pistondevelopers/piston_window.git" 11 | homepage = "https://github.com/pistondevelopers/piston_window" 12 | documentation = "https://docs.rs/piston_window" 13 | exclude = ["*.png"] 14 | 15 | [lib] 16 | 17 | path = "src/lib.rs" 18 | name = "piston_window" 19 | 20 | 21 | [dependencies] 22 | gfx = "0.18.1" 23 | gfx_device_gl = "0.16.2" 24 | piston = "1.0.0" 25 | piston2d-gfx_graphics = "0.81.0" 26 | piston2d-graphics = "0.44.0" 27 | piston-texture = "0.9.0" 28 | shader_version = "0.7.0" 29 | 30 | 31 | pistoncore-glutin_window = {version = "0.72.0", optional = true} 32 | 33 | [features] 34 | default = ["glutin"] 35 | glutin = ["pistoncore-glutin_window"] 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PistonDevelopers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # piston_window [![Build Status](https://travis-ci.org/PistonDevelopers/piston_window.svg?branch=master)](https://travis-ci.org/PistonDevelopers/piston_window) [![Crates.io](https://img.shields.io/crates/v/piston_window.svg)](https://crates.io/crates/piston_window) [![Crates.io](https://img.shields.io/crates/l/piston_window.svg)](https://github.com/PistonDevelopers/piston_window/blob/master/LICENSE) 2 | The official Piston convenience window wrapper for the Piston game engine 3 | 4 | **Notice! If this is your first time visiting Piston, [start here](https://github.com/PistonDevelopers/piston).** 5 | 6 | Piston-Window is designed for only one purpose: Convenience. 7 | 8 | [Documentation](http://docs.piston.rs/piston_window/piston_window/) 9 | 10 | * Reexports everything you need to write 2D interactive applications 11 | * `.draw_2d` for drawing 2D, and `.draw_3d` for drawing 3D 12 | * Uses Gfx to work with 3D libraries in the Piston ecosystem 13 | 14 | ```Rust 15 | extern crate piston_window; 16 | use piston_window::*; 17 | fn main() { 18 | let mut window: PistonWindow = WindowSettings::new("Hello Piston!", (640, 480)) 19 | .exit_on_esc(true) 20 | .build() 21 | .unwrap_or_else(|e| { panic!("Failed to build PistonWindow: {}", e) }); 22 | while let Some(e) = window.next() { 23 | window.draw_2d(&e, |_c, g, _d| { 24 | clear([0.5, 1.0, 0.5, 1.0], g); 25 | }); 26 | } 27 | } 28 | ``` 29 | 30 | `PistonWindow` uses Glutin as window back-end by default, 31 | but you can change to another back-end, for example SDL2 or GLFW by changing the type parameter: 32 | 33 | ```Rust 34 | let mut window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480]) 35 | .exit_on_esc(true).build().unwrap(); 36 | ``` 37 | 38 | `PistonWindow` implements `AdvancedWindow`, `Window` and `EventLoop`. 39 | Nested game loops are supported, so you can have one inside another. 40 | 41 | ```Rust 42 | while let Some(e) = window.next() { 43 | if let Some(button) = e.press_args() { 44 | // Intro. 45 | while let Some(e) = window.next() { 46 | ... 47 | } 48 | } 49 | } 50 | ``` 51 | 52 | Ideas or feedback? Open up an issue [here](https://github.com/pistondevelopers/piston_window/issues). 53 | 54 | ### Dependency graph 55 | 56 | ![Dependencies](./Cargo.png) 57 | -------------------------------------------------------------------------------- /examples/hello_piston.rs: -------------------------------------------------------------------------------- 1 | extern crate piston_window; 2 | 3 | use piston_window::*; 4 | 5 | fn main() { 6 | let title = "Hello Piston! (press any key to enter inner loop)"; 7 | let mut window: PistonWindow = WindowSettings::new(title, [640, 480]) 8 | .exit_on_esc(true) 9 | .build() 10 | .unwrap_or_else(|e| panic!("Failed to build PistonWindow: {}", e)); 11 | 12 | window.set_lazy(true); 13 | while let Some(e) = window.next() { 14 | window.draw_2d(&e, |c, g, _| { 15 | clear([0.5, 1.0, 0.5, 1.0], g); 16 | rectangle( 17 | [1.0, 0.0, 0.0, 1.0], 18 | [50.0, 50.0, 100.0, 100.0], 19 | c.transform, 20 | g, 21 | ); 22 | }); 23 | 24 | if e.press_args().is_some() { 25 | InnerApp { 26 | title: "Inner loop (press X to exit inner loop)", 27 | exit_button: Button::Keyboard(Key::X), 28 | } 29 | .run(&mut window); 30 | window.set_title(title.into()); 31 | } 32 | } 33 | } 34 | 35 | /// Stores application state of inner event loop. 36 | pub struct InnerApp { 37 | pub title: &'static str, 38 | pub exit_button: Button, 39 | } 40 | 41 | impl InnerApp { 42 | pub fn run(&mut self, window: &mut PistonWindow) { 43 | window.set_title(self.title.into()); 44 | while let Some(e) = window.next() { 45 | window.draw_2d(&e, |c, g, _| { 46 | clear([0.5, 0.5, 1.0, 1.0], g); 47 | ellipse( 48 | [1.0, 0.0, 0.0, 1.0], 49 | [50.0, 50.0, 100.0, 100.0], 50 | c.transform, 51 | g, 52 | ); 53 | }); 54 | if let Some(button) = e.press_args() { 55 | if button == self.exit_button { 56 | break; 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /scripts/id_rsa.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PistonDevelopers/piston_window/4b3991dce7ec9050fb2e239dd455c11ef6484d21/scripts/id_rsa.enc -------------------------------------------------------------------------------- /scripts/travis-doc-upload.cfg: -------------------------------------------------------------------------------- 1 | PROJECT_NAME=piston_window 2 | DOCS_REPO=PistonDevelopers/docs.git 3 | SSH_KEY_TRAVIS_ID=19031282950c 4 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(missing_docs)] 2 | 3 | //! The official Piston window wrapper for the Piston game engine 4 | //! 5 | //! **Notice! If this is your first time visiting Piston, [start here](https://github.com/PistonDevelopers/piston).** 6 | //! 7 | //! The purpose of this library is to provide an easy-to-use, 8 | //! simple-to-get-started and convenient-for-applications API for Piston. 9 | //! 10 | //! Sets up: 11 | //! 12 | //! - [Gfx](https://github.com/gfx-rs/gfx) with an OpenGL back-end. 13 | //! - [gfx_graphics](https://github.com/pistondevelopers/gfx_graphics) 14 | //! for 2D rendering. 15 | //! - [glutin_window](https://github.com/pistondevelopers/glutin_window) 16 | //! as default window back-end, but this can be swapped (see below). 17 | //! 18 | //! ### Example 19 | //! 20 | //! ```no_run 21 | //! extern crate piston_window; 22 | //! 23 | //! use piston_window::*; 24 | //! 25 | //! fn main() { 26 | //! let mut window: PistonWindow = 27 | //! WindowSettings::new("Hello World!", [512; 2]) 28 | //! .build().unwrap(); 29 | //! while let Some(e) = window.next() { 30 | //! window.draw_2d(&e, |c, g, _| { 31 | //! clear([0.5, 0.5, 0.5, 1.0], g); 32 | //! rectangle([1.0, 0.0, 0.0, 1.0], // red 33 | //! [0.0, 0.0, 100.0, 100.0], // rectangle 34 | //! c.transform, g); 35 | //! }); 36 | //! } 37 | //! } 38 | //! ``` 39 | //! 40 | //! The `draw_2d` function calls the closure on render events. 41 | //! There is no need to filter events manually, and there is no overhead. 42 | //! 43 | //! ### Swap to another window back-end 44 | //! 45 | //! Change the generic parameter to the window back-end you want to use. 46 | //! 47 | //! ```ignore 48 | //! extern crate piston_window; 49 | //! extern crate sdl2_window; 50 | //! 51 | //! use piston_window::*; 52 | //! use sdl2_window::Sdl2Window; 53 | //! 54 | //! # fn main() { 55 | //! 56 | //! let window: PistonWindow = 57 | //! WindowSettings::new("title", [512; 2]) 58 | //! .build().unwrap(); 59 | //! 60 | //! # } 61 | //! ``` 62 | //! 63 | //! ### sRGB 64 | //! 65 | //! The impl of `BuildFromWindowSettings` in this library turns on 66 | //! `WindowSettings::srgb`, because it is required by gfx_graphics. 67 | //! 68 | //! Most images such as those found on the internet uses sRGB, 69 | //! that has a non-linear gamma corrected space. 70 | //! When rendering 3D, make sure textures and colors are in linear gamma space. 71 | //! Alternative is to use `Srgb8` and `Srgba8` formats for textures. 72 | //! 73 | //! For more information about sRGB, see 74 | //! https://github.com/PistonDevelopers/piston/issues/1014 75 | //! 76 | //! ### Library dependencies 77 | //! 78 | //! This library is meant to be used in applications only. 79 | //! It is not meant to be depended on by generic libraries. 80 | //! Instead, libraries should depend on the lower abstractions, 81 | //! such as the [Piston core](https://github.com/pistondevelopers/piston). 82 | 83 | extern crate gfx; 84 | extern crate gfx_device_gl; 85 | extern crate gfx_graphics; 86 | extern crate piston; 87 | extern crate shader_version; 88 | 89 | pub extern crate graphics; 90 | pub extern crate texture; 91 | 92 | /// Exports all of the types exposed by this module, *except* for `graphics`. 93 | /// 94 | /// The `graphics` module contains a module and function called `image`, 95 | /// which is very likely to conflict with the `image` crate. 96 | /// 97 | /// Using the name "prelude" also suppresses the wildcard import warning from clippy. 98 | pub mod prelude; 99 | 100 | pub use graphics::*; 101 | pub use prelude::*; 102 | -------------------------------------------------------------------------------- /src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use gfx_graphics::{Filter, Flip, Texture, TextureContext, TextureSettings}; 2 | pub use piston::event_loop::*; 3 | pub use piston::input::*; 4 | pub use piston::window::*; 5 | pub use piston::*; 6 | pub use shader_version::OpenGL; 7 | 8 | use gfx_graphics::{Gfx2d, GfxGraphics}; 9 | use graphics::Context; 10 | use std::error::Error; 11 | use std::time::Duration; 12 | 13 | /// Actual device used by Gfx backend. 14 | pub type GfxDevice = gfx_device_gl::Device; 15 | /// Actual factory used by Gfx backend. 16 | pub type GfxFactory = gfx_device_gl::Factory; 17 | /// Actual gfx::Stream implementation carried by the window. 18 | pub type GfxEncoder = gfx::Encoder; 19 | /// Glyph cache. 20 | pub type Glyphs = gfx_graphics::GlyphCache< 21 | 'static, 22 | gfx_device_gl::Factory, 23 | gfx_device_gl::Resources, 24 | gfx_device_gl::CommandBuffer, 25 | >; 26 | /// 2D graphics. 27 | pub type G2d<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer>; 28 | /// Texture type compatible with `G2d`. 29 | pub type G2dTexture = Texture; 30 | /// Texture context. 31 | pub type G2dTextureContext = 32 | TextureContext; 33 | 34 | /// Contains everything required for controlling window, graphics, event loop. 35 | #[cfg(not(feature = "glutin"))] 36 | pub struct PistonWindow { 37 | /// The window. 38 | pub window: W, 39 | /// GFX encoder. 40 | pub encoder: GfxEncoder, 41 | /// GFX device. 42 | pub device: gfx_device_gl::Device, 43 | /// Output frame buffer. 44 | pub output_color: gfx::handle::RenderTargetView, 45 | /// Output stencil buffer. 46 | pub output_stencil: 47 | gfx::handle::DepthStencilView, 48 | /// Gfx2d. 49 | pub g2d: Gfx2d, 50 | /// Event loop state. 51 | pub events: Events, 52 | /// The factory that was created along with the device. 53 | pub factory: gfx_device_gl::Factory, 54 | } 55 | 56 | #[cfg(feature = "glutin")] 57 | extern crate glutin_window; 58 | #[cfg(feature = "glutin")] 59 | use self::glutin_window::GlutinWindow; 60 | /// Contains everything required for controlling window, graphics, event loop. 61 | #[cfg(feature = "glutin")] 62 | pub struct PistonWindow { 63 | /// The window. 64 | pub window: W, 65 | /// GFX encoder. 66 | pub encoder: GfxEncoder, 67 | /// GFX device. 68 | pub device: gfx_device_gl::Device, 69 | /// Output frame buffer. 70 | pub output_color: gfx::handle::RenderTargetView, 71 | /// Output stencil buffer. 72 | pub output_stencil: 73 | gfx::handle::DepthStencilView, 74 | /// Gfx2d. 75 | pub g2d: Gfx2d, 76 | /// Event loop state. 77 | pub events: Events, 78 | /// The factory that was created along with the device. 79 | pub factory: gfx_device_gl::Factory, 80 | } 81 | 82 | impl BuildFromWindowSettings for PistonWindow 83 | where 84 | W: Window + OpenGLWindow + BuildFromWindowSettings, 85 | { 86 | fn build_from_window_settings( 87 | settings: &WindowSettings, 88 | ) -> Result, Box> { 89 | // Turn on sRGB. 90 | let settings = settings.clone().srgb(true); 91 | 92 | // Use OpenGL 3.2 by default, because this is what window backends 93 | // usually do. 94 | let api = settings 95 | .get_maybe_graphics_api() 96 | .unwrap_or(Api::opengl(3, 2)); 97 | let samples = settings.get_samples(); 98 | 99 | let opengl = 100 | OpenGL::from_api(api).expect("Could not detect OpenGL version from graphics API"); 101 | 102 | Ok(PistonWindow::new(opengl, samples, settings.build()?)) 103 | } 104 | } 105 | 106 | fn create_main_targets( 107 | dim: gfx::texture::Dimensions, 108 | ) -> ( 109 | gfx::handle::RenderTargetView, 110 | gfx::handle::DepthStencilView, 111 | ) { 112 | use gfx::format::{DepthStencil, Format, Formatted, Srgba8}; 113 | use gfx::memory::Typed; 114 | 115 | let color_format: Format = ::get_format(); 116 | let depth_format: Format = ::get_format(); 117 | let (output_color, output_stencil) = 118 | gfx_device_gl::create_main_targets_raw(dim, color_format.0, depth_format.0); 119 | let output_color = Typed::new(output_color); 120 | let output_stencil = Typed::new(output_stencil); 121 | (output_color, output_stencil) 122 | } 123 | 124 | impl PistonWindow 125 | where 126 | W: Window, 127 | { 128 | /// Creates a new piston window. 129 | pub fn new(opengl: OpenGL, samples: u8, mut window: W) -> Self 130 | where 131 | W: OpenGLWindow, 132 | { 133 | let (device, mut factory) = 134 | gfx_device_gl::create(|s| window.get_proc_address(s) as *const _); 135 | 136 | let (output_color, output_stencil) = { 137 | let aa = samples as gfx::texture::NumSamples; 138 | let draw_size = window.draw_size(); 139 | let dim = ( 140 | draw_size.width as u16, 141 | draw_size.height as u16, 142 | 1, 143 | aa.into(), 144 | ); 145 | create_main_targets(dim) 146 | }; 147 | 148 | let g2d = Gfx2d::new(opengl, &mut factory); 149 | let encoder = factory.create_command_buffer().into(); 150 | let events = Events::new(EventSettings::new()); 151 | PistonWindow { 152 | window: window, 153 | encoder: encoder, 154 | device: device, 155 | output_color: output_color, 156 | output_stencil: output_stencil, 157 | g2d: g2d, 158 | events: events, 159 | factory: factory, 160 | } 161 | } 162 | 163 | /// Creates context used to create and update textures. 164 | pub fn create_texture_context(&mut self) -> G2dTextureContext { 165 | TextureContext { 166 | factory: self.factory.clone(), 167 | encoder: self.factory.create_command_buffer().into(), 168 | } 169 | } 170 | 171 | /// Loads font from a path. 172 | pub fn load_font>( 173 | &mut self, 174 | path: P, 175 | ) -> Result { 176 | Glyphs::new( 177 | path, 178 | TextureContext { 179 | factory: self.factory.clone(), 180 | encoder: self.factory.create_command_buffer().into(), 181 | }, 182 | TextureSettings::new(), 183 | ) 184 | } 185 | 186 | /// Renders 2D graphics. 187 | /// 188 | /// Calls the closure on render events. 189 | /// There is no need to filter events manually, and there is no overhead. 190 | pub fn draw_2d(&mut self, e: &E, f: F) -> Option 191 | where 192 | W: OpenGLWindow, 193 | E: GenericEvent, 194 | F: FnOnce(Context, &mut G2d, &mut gfx_device_gl::Device) -> U, 195 | { 196 | if let Some(args) = e.render_args() { 197 | self.window.make_current(); 198 | let device = &mut self.device; 199 | let res = self.g2d.draw( 200 | &mut self.encoder, 201 | &self.output_color, 202 | &self.output_stencil, 203 | args.viewport(), 204 | |c, g| f(c, g, device), 205 | ); 206 | self.encoder.flush(device); 207 | Some(res) 208 | } else { 209 | None 210 | } 211 | } 212 | 213 | /// Renders 3D graphics. 214 | /// 215 | /// Calls the closure on render events. 216 | /// There is no need to filter events manually, and there is no overhead. 217 | pub fn draw_3d(&mut self, e: &E, f: F) -> Option 218 | where 219 | W: OpenGLWindow, 220 | E: GenericEvent, 221 | F: FnOnce(&mut Self) -> U, 222 | { 223 | if let Some(_) = e.render_args() { 224 | self.window.make_current(); 225 | let res = f(self); 226 | self.encoder.flush(&mut self.device); 227 | Some(res) 228 | } else { 229 | None 230 | } 231 | } 232 | 233 | /// Let window handle new event. 234 | /// Cleans up after rendering and resizes frame buffers. 235 | pub fn event(&mut self, event: &E) { 236 | use gfx::memory::Typed; 237 | use gfx::Device; 238 | 239 | if let Some(_) = event.after_render_args() { 240 | // After swapping buffers. 241 | self.device.cleanup(); 242 | } 243 | 244 | // Check whether window has resized and update the output. 245 | let dim = self.output_color.raw().get_dimensions(); 246 | let (w, h) = (dim.0, dim.1); 247 | let draw_size = self.window.draw_size(); 248 | if w != draw_size.width as u16 || h != draw_size.height as u16 { 249 | let dim = ( 250 | draw_size.width as u16, 251 | draw_size.height as u16, 252 | dim.2, 253 | dim.3, 254 | ); 255 | let (output_color, output_stencil) = create_main_targets(dim); 256 | self.output_color = output_color; 257 | self.output_stencil = output_stencil; 258 | } 259 | } 260 | } 261 | 262 | impl Window for PistonWindow 263 | where 264 | W: Window, 265 | { 266 | fn should_close(&self) -> bool { 267 | self.window.should_close() 268 | } 269 | fn set_should_close(&mut self, value: bool) { 270 | self.window.set_should_close(value) 271 | } 272 | fn size(&self) -> Size { 273 | self.window.size() 274 | } 275 | fn draw_size(&self) -> Size { 276 | self.window.draw_size() 277 | } 278 | fn swap_buffers(&mut self) { 279 | self.window.swap_buffers() 280 | } 281 | fn wait_event(&mut self) -> Event { 282 | Window::wait_event(&mut self.window) 283 | } 284 | fn wait_event_timeout(&mut self, timeout: Duration) -> Option { 285 | Window::wait_event_timeout(&mut self.window, timeout) 286 | } 287 | fn poll_event(&mut self) -> Option { 288 | Window::poll_event(&mut self.window) 289 | } 290 | } 291 | 292 | impl AdvancedWindow for PistonWindow 293 | where 294 | W: AdvancedWindow, 295 | { 296 | fn get_title(&self) -> String { 297 | self.window.get_title() 298 | } 299 | fn set_title(&mut self, title: String) { 300 | self.window.set_title(title) 301 | } 302 | fn get_automatic_close(&self) -> bool { 303 | self.window.get_automatic_close() 304 | } 305 | fn set_automatic_close(&mut self, value: bool) { 306 | self.window.set_automatic_close(value); 307 | } 308 | fn get_exit_on_esc(&self) -> bool { 309 | self.window.get_exit_on_esc() 310 | } 311 | fn set_exit_on_esc(&mut self, value: bool) { 312 | self.window.set_exit_on_esc(value) 313 | } 314 | fn set_capture_cursor(&mut self, value: bool) { 315 | self.window.set_capture_cursor(value) 316 | } 317 | fn show(&mut self) { 318 | self.window.show() 319 | } 320 | fn hide(&mut self) { 321 | self.window.hide() 322 | } 323 | fn get_position(&self) -> Option { 324 | self.window.get_position() 325 | } 326 | fn set_position>(&mut self, pos: P) { 327 | self.window.set_position(pos) 328 | } 329 | fn set_size>(&mut self, size: S) { 330 | self.window.set_size(size) 331 | } 332 | } 333 | 334 | impl EventLoop for PistonWindow 335 | where 336 | W: Window, 337 | { 338 | fn get_event_settings(&self) -> EventSettings { 339 | self.events.get_event_settings() 340 | } 341 | 342 | fn set_event_settings(&mut self, settings: EventSettings) { 343 | self.events.set_event_settings(settings); 344 | } 345 | } 346 | 347 | impl Iterator for PistonWindow 348 | where 349 | W: Window, 350 | { 351 | type Item = Event; 352 | 353 | /// Returns next event. 354 | /// Cleans up after rendering and resizes frame buffers. 355 | fn next(&mut self) -> Option { 356 | if let Some(e) = self.events.next(&mut self.window) { 357 | self.event(&e); 358 | Some(e) 359 | } else { 360 | None 361 | } 362 | } 363 | } 364 | --------------------------------------------------------------------------------