@@ -7,21 +7,32 @@ extern crate gfx;
77extern crate gfx_device_gl;
88extern crate gfx_graphics;
99extern crate graphics;
10+ extern crate shader_version;
11+ extern crate glutin_window;
12+
13+ use glutin_window:: GlutinWindow ;
14+ pub use shader_version:: OpenGL ;
15+ pub use graphics:: * ;
16+ pub use piston:: window:: * ;
17+ pub use piston:: event:: * ;
18+ pub use piston:: input:: * ;
1019
1120use std:: cell:: RefCell ;
1221use std:: rc:: Rc ;
1322use std:: any:: Any ;
1423
15- use piston:: { event, window } ;
1624use gfx:: traits:: * ;
1725use gfx_graphics:: { Gfx2d , GfxGraphics } ;
18- use graphics:: Context ;
1926
2027/// Actual gfx::Stream implementation carried by the window.
2128pub type GfxStream = gfx:: OwnedStream < gfx_device_gl:: Device , gfx_device_gl:: Output > ;
29+ /// Glyph cache.
30+ type Glyphs = gfx_graphics:: GlyphCache < gfx_device_gl:: Resources , gfx_device_gl:: Factory > ;
31+ /// 2D graphics.
32+ type G2d < ' a > = GfxGraphics < ' a , gfx_device_gl:: Resources , gfx_device_gl:: CommandBuffer , gfx_device_gl:: Output > ;
2233
2334/// Contains everything required for controlling window, graphics, event loop.
24- pub struct PistonWindow < W : window :: Window , T = ( ) > {
35+ pub struct PistonWindow < W : Window = GlutinWindow , T = ( ) > {
2536 /// The window.
2637 pub window : Rc < RefCell < W > > ,
2738 /// GFX stream.
@@ -31,17 +42,26 @@ pub struct PistonWindow<W: window::Window, T = ()> {
3142 /// Gfx2d.
3243 pub g2d : Rc < RefCell < Gfx2d < gfx_device_gl:: Resources > > > ,
3344 /// The event loop.
34- pub events : Rc < RefCell < event :: WindowEvents < W , event :: Event < W :: Event > > > > ,
45+ pub events : Rc < RefCell < WindowEvents < W , Event < W :: Event > > > > ,
3546 /// The event.
36- pub event : Option < event :: Event < W :: Event > > ,
47+ pub event : Option < Event < W :: Event > > ,
3748 /// Application structure.
3849 pub app : Rc < RefCell < T > > ,
3950 /// The factory that was created along with the device.
4051 pub factory : Rc < RefCell < gfx_device_gl:: Factory > > ,
4152}
4253
54+ impl < T > From < WindowSettings > for PistonWindow < T >
55+ where T : Window + OpenGLWindow + From < WindowSettings > ,
56+ T :: Event : GenericEvent
57+ {
58+ fn from ( settings : WindowSettings ) -> PistonWindow < T > {
59+ PistonWindow :: new ( Rc :: new ( RefCell :: new ( settings. into ( ) ) ) , empty_app ( ) )
60+ }
61+ }
62+
4363impl < W , T > Clone for PistonWindow < W , T >
44- where W : window :: Window , W :: Event : Clone
64+ where W : Window , W :: Event : Clone
4565{
4666 fn clone ( & self ) -> Self {
4767 PistonWindow {
@@ -58,11 +78,11 @@ impl<W, T> Clone for PistonWindow<W, T>
5878}
5979
6080impl < W , T > PistonWindow < W , T >
61- where W : window :: Window , W :: Event : event :: GenericEvent
81+ where W : Window , W :: Event : GenericEvent
6282{
6383 /// Creates a new piston object.
6484 pub fn new ( window : Rc < RefCell < W > > , app : Rc < RefCell < T > > ) -> Self
65- where W : window :: OpenGLWindow
85+ where W : OpenGLWindow
6686 {
6787 use piston:: event:: Events ;
6888 use piston:: window:: { OpenGLWindow , Window } ;
@@ -140,7 +160,7 @@ impl<W, T> PistonWindow<W, T>
140160}
141161
142162impl < W , T > Iterator for PistonWindow < W , T >
143- where W : window :: Window , W :: Event : event :: GenericEvent
163+ where W : Window , W :: Event : GenericEvent
144164{
145165 type Item = PistonWindow < W , T > ;
146166
@@ -174,13 +194,13 @@ impl<W, T> Iterator for PistonWindow<W, T>
174194 }
175195}
176196
177- impl < W , T > event :: GenericEvent for PistonWindow < W , T >
178- where W : window :: Window , W :: Event : event :: GenericEvent
197+ impl < W , T > GenericEvent for PistonWindow < W , T >
198+ where W : Window , W :: Event : GenericEvent
179199{
180- fn event_id ( & self ) -> event :: EventId {
200+ fn event_id ( & self ) -> EventId {
181201 match self . event {
182202 Some ( ref e) => e. event_id ( ) ,
183- None => event :: EventId ( "" )
203+ None => EventId ( "" )
184204 }
185205 }
186206
@@ -190,9 +210,9 @@ impl<W, T> event::GenericEvent for PistonWindow<W, T>
190210 self . event . as_ref ( ) . unwrap ( ) . with_args ( f)
191211 }
192212
193- fn from_args ( event_id : event :: EventId , any : & Any , old_event : & Self ) -> Option < Self > {
213+ fn from_args ( event_id : EventId , any : & Any , old_event : & Self ) -> Option < Self > {
194214 if let Some ( ref e) = old_event. event {
195- match event :: GenericEvent :: from_args ( event_id, any, e) {
215+ match GenericEvent :: from_args ( event_id, any, e) {
196216 Some ( e) => {
197217 Some ( PistonWindow {
198218 window : old_event. window . clone ( ) ,
@@ -211,22 +231,22 @@ impl<W, T> event::GenericEvent for PistonWindow<W, T>
211231 }
212232}
213233
214- impl < W , T > window :: Window for PistonWindow < W , T >
215- where W : window :: Window
234+ impl < W , T > Window for PistonWindow < W , T >
235+ where W : Window
216236{
217- type Event = <W as window :: Window >:: Event ;
237+ type Event = <W as Window >:: Event ;
218238
219239 fn should_close ( & self ) -> bool { self . window . borrow ( ) . should_close ( ) }
220- fn size ( & self ) -> window :: Size { self . window . borrow ( ) . size ( ) }
221- fn draw_size ( & self ) -> window :: Size { self . window . borrow ( ) . draw_size ( ) }
240+ fn size ( & self ) -> Size { self . window . borrow ( ) . size ( ) }
241+ fn draw_size ( & self ) -> Size { self . window . borrow ( ) . draw_size ( ) }
222242 fn swap_buffers ( & mut self ) { self . window . borrow_mut ( ) . swap_buffers ( ) }
223243 fn poll_event ( & mut self ) -> Option < Self :: Event > {
224- window :: Window :: poll_event ( & mut * self . window . borrow_mut ( ) )
244+ Window :: poll_event ( & mut * self . window . borrow_mut ( ) )
225245 }
226246}
227247
228- impl < W , T > window :: AdvancedWindow for PistonWindow < W , T >
229- where W : window :: AdvancedWindow
248+ impl < W , T > AdvancedWindow for PistonWindow < W , T >
249+ where W : AdvancedWindow
230250{
231251 fn get_title ( & self ) -> String { self . window . borrow ( ) . get_title ( ) }
232252 fn set_title ( & mut self , title : String ) {
0 commit comments