Skip to content

Commit e5cc9df

Browse files
committed
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
1 parent a46969d commit e5cc9df

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ name = "piston_window"
1919
[dependencies]
2020
gfx = "0.6.1"
2121
gfx_device_gl = "0.4.0"
22-
piston = "0.1.4"
22+
piston = "0.1.5"
2323
piston2d-gfx_graphics = "0.1.22"
2424
piston2d-graphics = "0.1.3"
25-
26-
[dev-dependencies]
27-
pistoncore-glutin_window = "0.1.0"
28-
25+
shader_version = "0.1.0"
26+
pistoncore-glutin_window = "0.2.0"

examples/hello_piston.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
extern crate piston_window;
2-
extern crate glutin_window;
3-
extern crate piston;
4-
extern crate graphics;
52

6-
use std::cell::RefCell;
7-
use std::rc::Rc;
8-
use glutin_window::{ OpenGL, GlutinWindow };
93
use piston_window::*;
10-
use piston::window::WindowSettings;
11-
12-
use piston::event::*;
13-
use graphics::*;
14-
use piston::input::*;
154

165
fn main() {
17-
let window = Rc::new(RefCell::new(GlutinWindow::new(
18-
OpenGL::_3_2,
19-
WindowSettings::new("Hello Piston!", [640, 480])
20-
.exit_on_esc(true)
21-
)));
6+
let window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480])
7+
.exit_on_esc(true)
8+
.into();
229
println!("Press any button to enter inner loop");
23-
for e in PistonWindow::new(window, empty_app()) {
10+
for e in window {
2411
e.draw_2d(|_c, g| {
2512
clear([0.5, 1.0, 0.5, 1.0], g);
2613
});

src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ extern crate gfx;
77
extern crate gfx_device_gl;
88
extern crate gfx_graphics;
99
extern 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

1120
use std::cell::RefCell;
1221
use std::rc::Rc;
@@ -15,13 +24,21 @@ use std::any::Any;
1524
use piston::{ event, window };
1625
use gfx::traits::*;
1726
use gfx_graphics::{ Gfx2d, GfxGraphics };
18-
use graphics::Context;
1927

2028
/// Actual gfx::Stream implementation carried by the window.
2129
pub type GfxStream = gfx::OwnedStream<gfx_device_gl::Device, gfx_device_gl::Output>;
30+
/// Glyph cache.
31+
type PistonGlyphCache = gfx_graphics::GlyphCache<gfx_device_gl::Resources, gfx_device_gl::Factory>;
32+
/// 2D graphics.
33+
type PistonGraphics<'a> = GfxGraphics<'a, gfx_device_gl::Resources, gfx_device_gl::CommandBuffer, gfx_device_gl::Output>;
34+
35+
/// Creates a window using default window back-end.
36+
pub fn window(settings: WindowSettings) -> Rc<RefCell<GlutinWindow>> {
37+
Rc::new(RefCell::new(GlutinWindow::new(settings)))
38+
}
2239

2340
/// Contains everything required for controlling window, graphics, event loop.
24-
pub struct PistonWindow<W: window::Window, T = ()> {
41+
pub struct PistonWindow<W: window::Window = GlutinWindow, T = ()> {
2542
/// The window.
2643
pub window: Rc<RefCell<W>>,
2744
/// GFX stream.
@@ -40,6 +57,12 @@ pub struct PistonWindow<W: window::Window, T = ()> {
4057
pub factory: Rc<RefCell<gfx_device_gl::Factory>>,
4158
}
4259

60+
impl From<WindowSettings> for PistonWindow {
61+
fn from(settings: WindowSettings) -> PistonWindow {
62+
PistonWindow::new(window(settings), empty_app())
63+
}
64+
}
65+
4366
impl<W, T> Clone for PistonWindow<W, T>
4467
where W: window::Window, W::Event: Clone
4568
{

0 commit comments

Comments
 (0)