From 812013590c48fc0587e51f2e7ce49f8f62d3e7b5 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Mon, 25 May 2015 20:46:55 +0200 Subject: [PATCH 1/6] Reexport everything you need * Reexports `shader_version::OpenGL` * Reexports `graphics::*` * Reexports `piston::window::*` * Reexports `piston::event::*` * Reexports `piston::input::*` * Adds `PistonGlyphCache` type alias * Adds `PistonGraphics` type alias * Adds `window` for creating a window --- Cargo.toml | 6 +++++- examples/hello_piston.rs | 19 ++++--------------- src/lib.rs | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc7a40f..87e8b05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,10 @@ git = "https://github.com/pistondevelopers/gfx_graphics" [dependencies.piston2d-graphics] git = "https://github.com/pistondevelopers/graphics" -[dev-dependencies.pistoncore-glutin_window] +[dependencies.pistoncore-glutin_window] #git = "https://github.com/pistondevelopers/glutin_window" version = "0.0.8" + +[dependencies.shader_version] +#git = "https://github.com/PistonDevelopers/shader_version" +version = "0.0.6" diff --git a/examples/hello_piston.rs b/examples/hello_piston.rs index ba85095..8b38512 100644 --- a/examples/hello_piston.rs +++ b/examples/hello_piston.rs @@ -1,24 +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]) + let window = window( + OpenGL::_3_2, + WindowSettings::new("Hello Piston!", [640, 480]) .exit_on_esc(true) - ))); + ); println!("Press any button to enter inner loop"); for e in PistonWindow::new(window, empty_app()) { e.draw_2d(|_c, g| { diff --git a/src/lib.rs b/src/lib.rs index 64d3a79..c59cbf9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,15 @@ 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; @@ -15,10 +24,18 @@ 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 PistonGlyphCache = gfx_graphics::GlyphCache; +/// 2D graphics. +type PistonGraphics<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; + +/// Creates a window using default window back-end. +pub fn window(opengl: OpenGL, settings: WindowSettings) -> Rc> { + Rc::new(RefCell::new(GlutinWindow::new(opengl, settings))) +} /// Contains everything required for controlling window, graphics, event loop. pub struct PistonWindow { From 376960eaacd773ced745680c3fddb217ba1260b8 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Mon, 25 May 2015 20:55:31 +0200 Subject: [PATCH 2/6] Use `GlutinWindow` by default --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c59cbf9..fb6cdd5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ pub fn window(opengl: OpenGL, settings: WindowSettings) -> Rc { +pub struct PistonWindow { /// The window. pub window: Rc>, /// GFX stream. From 657a3a8284b184c4feb3879058afa63987e43027 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Tue, 26 May 2015 16:56:03 +0200 Subject: [PATCH 3/6] Renamed to `G2d` and `Glyphs` --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fb6cdd5..b391210 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,9 +28,9 @@ use gfx_graphics::{ Gfx2d, GfxGraphics }; /// Actual gfx::Stream implementation carried by the window. pub type GfxStream = gfx::OwnedStream; /// Glyph cache. -type PistonGlyphCache = gfx_graphics::GlyphCache; +type Glyphs = gfx_graphics::GlyphCache; /// 2D graphics. -type PistonGraphics<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; +type G2d<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; /// Creates a window using default window back-end. pub fn window(opengl: OpenGL, settings: WindowSettings) -> Rc> { From e5cc9df038830025e77d32899043a3184b10c7e8 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Mon, 25 May 2015 20:46:55 +0200 Subject: [PATCH 4/6] Reexport everything you need * Reexports `shader_version::OpenGL` * Reexports `graphics::*` * Reexports `piston::window::*` * Reexports `piston::event::*` * Reexports `piston::input::*` * Adds `PistonGlyphCache` type alias * Adds `PistonGraphics` type alias * Adds `window` for creating a window --- Cargo.toml | 8 +++----- examples/hello_piston.rs | 21 ++++----------------- src/lib.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c9ee56..05537dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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..c2045f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,15 @@ 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; @@ -15,13 +24,21 @@ 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 PistonGlyphCache = gfx_graphics::GlyphCache; +/// 2D graphics. +type PistonGraphics<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; + +/// Creates a window using default window back-end. +pub fn window(settings: WindowSettings) -> Rc> { + Rc::new(RefCell::new(GlutinWindow::new(settings))) +} /// Contains everything required for controlling window, graphics, event loop. -pub struct PistonWindow { +pub struct PistonWindow { /// The window. pub window: Rc>, /// GFX stream. @@ -40,6 +57,12 @@ pub struct PistonWindow { pub factory: Rc>, } +impl From for PistonWindow { + fn from(settings: WindowSettings) -> PistonWindow { + PistonWindow::new(window(settings), empty_app()) + } +} + impl Clone for PistonWindow where W: window::Window, W::Event: Clone { From 804b84881dabae7acbd6ce1dac0651a8055d264b Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Tue, 26 May 2015 16:56:03 +0200 Subject: [PATCH 5/6] Renamed to `G2d` and `Glyphs` --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c2045f9..fd5bcfe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,9 +28,9 @@ use gfx_graphics::{ Gfx2d, GfxGraphics }; /// Actual gfx::Stream implementation carried by the window. pub type GfxStream = gfx::OwnedStream; /// Glyph cache. -type PistonGlyphCache = gfx_graphics::GlyphCache; +type Glyphs = gfx_graphics::GlyphCache; /// 2D graphics. -type PistonGraphics<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; +type G2d<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>; /// Creates a window using default window back-end. pub fn window(settings: WindowSettings) -> Rc> { From 937419cbaf55a1577a0cf8bc462abd320f5f32f0 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Thu, 4 Jun 2015 22:57:35 +0200 Subject: [PATCH 6/6] Some cleanup --- src/lib.rs | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index daee459..b43b277 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ use std::cell::RefCell; use std::rc::Rc; use std::any::Any; -use piston::{ event, window }; use gfx::traits::*; use gfx_graphics::{ Gfx2d, GfxGraphics }; @@ -33,7 +32,7 @@ type Glyphs = gfx_graphics::GlyphCache = 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. @@ -43,9 +42,9 @@ 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. @@ -62,7 +61,7 @@ impl From for PistonWindow } impl Clone for PistonWindow - where W: window::Window, W::Event: Clone + where W: Window, W::Event: Clone { fn clone(&self) -> Self { PistonWindow { @@ -79,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 }; @@ -161,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; @@ -195,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("") } } @@ -211,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(), @@ -232,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) {