diff --git a/Cargo.toml b/Cargo.toml index 1c9ee56..dd1ccfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "piston_window" -version = "0.1.0" +version = "0.2.0" authors = ["bvssvni "] keywords = ["window", "piston"] description = "The official Piston window back-end for the Piston game engine" @@ -19,10 +19,8 @@ name = "piston_window" [dependencies] gfx = "0.6.1" gfx_device_gl = "0.4.0" -piston = "0.1.4" +piston = "0.1.5" piston2d-gfx_graphics = "0.1.22" piston2d-graphics = "0.1.3" - -[dev-dependencies] -pistoncore-glutin_window = "0.1.0" - +shader_version = "0.1.0" +pistoncore-glutin_window = "0.2.0" diff --git a/examples/hello_piston.rs b/examples/hello_piston.rs index ba85095..be9c32f 100644 --- a/examples/hello_piston.rs +++ b/examples/hello_piston.rs @@ -1,26 +1,13 @@ extern crate piston_window; -extern crate glutin_window; -extern crate piston; -extern crate graphics; -use std::cell::RefCell; -use std::rc::Rc; -use glutin_window::{ OpenGL, GlutinWindow }; use piston_window::*; -use piston::window::WindowSettings; - -use piston::event::*; -use graphics::*; -use piston::input::*; fn main() { - let window = Rc::new(RefCell::new(GlutinWindow::new( - OpenGL::_3_2, - WindowSettings::new("Hello Piston!", [640, 480]) - .exit_on_esc(true) - ))); + let window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480]) + .exit_on_esc(true) + .into(); println!("Press any button to enter inner loop"); - for e in PistonWindow::new(window, empty_app()) { + for e in window { e.draw_2d(|_c, g| { clear([0.5, 1.0, 0.5, 1.0], g); }); diff --git a/src/lib.rs b/src/lib.rs index 1700fe9..b43b277 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,21 +7,32 @@ extern crate gfx; extern crate gfx_device_gl; extern crate gfx_graphics; extern crate graphics; +extern crate shader_version; +extern crate glutin_window; + +use glutin_window::GlutinWindow; +pub use shader_version::OpenGL; +pub use graphics::*; +pub use piston::window::*; +pub use piston::event::*; +pub use piston::input::*; use std::cell::RefCell; use std::rc::Rc; use std::any::Any; -use piston::{ event, window }; use gfx::traits::*; use gfx_graphics::{ Gfx2d, GfxGraphics }; -use graphics::Context; /// Actual gfx::Stream implementation carried by the window. pub type GfxStream = gfx::OwnedStream; +/// Glyph cache. +type Glyphs = gfx_graphics::GlyphCache; +/// 2D graphics. +type G2d<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; /// Contains everything required for controlling window, graphics, event loop. -pub struct PistonWindow { +pub struct PistonWindow { /// The window. pub window: Rc>, /// GFX stream. @@ -31,17 +42,26 @@ pub struct PistonWindow { /// Gfx2d. pub g2d: Rc>>, /// The event loop. - pub events: Rc>>>, + pub events: Rc>>>, /// The event. - pub event: Option>, + pub event: Option>, /// Application structure. pub app: Rc>, /// The factory that was created along with the device. pub factory: Rc>, } +impl From for PistonWindow + where T: Window + OpenGLWindow + From, + T::Event: GenericEvent +{ + fn from(settings: WindowSettings) -> PistonWindow { + PistonWindow::new(Rc::new(RefCell::new(settings.into())), empty_app()) + } +} + impl Clone for PistonWindow - where W: window::Window, W::Event: Clone + where W: Window, W::Event: Clone { fn clone(&self) -> Self { PistonWindow { @@ -58,11 +78,11 @@ impl Clone for PistonWindow } impl PistonWindow - where W: window::Window, W::Event: event::GenericEvent + where W: Window, W::Event: GenericEvent { /// Creates a new piston object. pub fn new(window: Rc>, app: Rc>) -> Self - where W: window::OpenGLWindow + where W: OpenGLWindow { use piston::event::Events; use piston::window::{ OpenGLWindow, Window }; @@ -140,7 +160,7 @@ impl PistonWindow } impl Iterator for PistonWindow - where W: window::Window, W::Event: event::GenericEvent + where W: Window, W::Event: GenericEvent { type Item = PistonWindow; @@ -174,13 +194,13 @@ impl Iterator for PistonWindow } } -impl event::GenericEvent for PistonWindow - where W: window::Window, W::Event: event::GenericEvent +impl GenericEvent for PistonWindow + where W: Window, W::Event: GenericEvent { - fn event_id(&self) -> event::EventId { + fn event_id(&self) -> EventId { match self.event { Some(ref e) => e.event_id(), - None => event::EventId("") + None => EventId("") } } @@ -190,9 +210,9 @@ impl event::GenericEvent for PistonWindow self.event.as_ref().unwrap().with_args(f) } - fn from_args(event_id: event::EventId, any: &Any, old_event: &Self) -> Option { + fn from_args(event_id: EventId, any: &Any, old_event: &Self) -> Option { if let Some(ref e) = old_event.event { - match event::GenericEvent::from_args(event_id, any, e) { + match GenericEvent::from_args(event_id, any, e) { Some(e) => { Some(PistonWindow { window: old_event.window.clone(), @@ -211,22 +231,22 @@ impl event::GenericEvent for PistonWindow } } -impl window::Window for PistonWindow - where W: window::Window +impl Window for PistonWindow + where W: Window { - type Event = ::Event; + type Event = ::Event; fn should_close(&self) -> bool { self.window.borrow().should_close() } - fn size(&self) -> window::Size { self.window.borrow().size() } - fn draw_size(&self) -> window::Size { self.window.borrow().draw_size() } + fn size(&self) -> Size { self.window.borrow().size() } + fn draw_size(&self) -> Size { self.window.borrow().draw_size() } fn swap_buffers(&mut self) { self.window.borrow_mut().swap_buffers() } fn poll_event(&mut self) -> Option { - window::Window::poll_event(&mut *self.window.borrow_mut()) + Window::poll_event(&mut *self.window.borrow_mut()) } } -impl window::AdvancedWindow for PistonWindow - where W: window::AdvancedWindow +impl AdvancedWindow for PistonWindow + where W: AdvancedWindow { fn get_title(&self) -> String { self.window.borrow().get_title() } fn set_title(&mut self, title: String) {