summaryrefslogtreecommitdiffstats
path: root/examples/tour/renderer.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-05 07:23:03 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-09-05 07:23:03 +0200
commitced3ffc22570048711fefba638782a31d0e06035 (patch)
treec3c3f29be40ec348f15205a3dd920088edb52ace /examples/tour/renderer.rs
parent3440ba3cb44bfc9a2b67708b683958a97d8c5e23 (diff)
downloadiced-ced3ffc22570048711fefba638782a31d0e06035.tar.gz
iced-ced3ffc22570048711fefba638782a31d0e06035.tar.bz2
iced-ced3ffc22570048711fefba638782a31d0e06035.zip
Move `ggez` example to `tour`
Diffstat (limited to 'examples/tour/renderer.rs')
-rw-r--r--examples/tour/renderer.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/tour/renderer.rs b/examples/tour/renderer.rs
new file mode 100644
index 00000000..8746dd96
--- /dev/null
+++ b/examples/tour/renderer.rs
@@ -0,0 +1,63 @@
+mod button;
+mod checkbox;
+mod debugger;
+mod image;
+mod radio;
+mod slider;
+mod text;
+
+use ggez::graphics::{
+ self, spritebatch::SpriteBatch, Font, Image, MeshBuilder,
+};
+use ggez::Context;
+
+pub struct Renderer<'a> {
+ pub context: &'a mut Context,
+ pub sprites: SpriteBatch,
+ pub spritesheet: Image,
+ pub font: Font,
+ font_size: f32,
+ debug_mesh: Option<MeshBuilder>,
+}
+
+impl Renderer<'_> {
+ pub fn new(
+ context: &mut Context,
+ spritesheet: Image,
+ font: Font,
+ ) -> Renderer {
+ Renderer {
+ context,
+ sprites: SpriteBatch::new(spritesheet.clone()),
+ spritesheet,
+ font,
+ font_size: 20.0,
+ debug_mesh: None,
+ }
+ }
+
+ pub fn flush(&mut self) {
+ graphics::draw(
+ self.context,
+ &self.sprites,
+ graphics::DrawParam::default(),
+ )
+ .expect("Draw sprites");
+
+ graphics::draw_queued_text(
+ self.context,
+ graphics::DrawParam::default(),
+ Default::default(),
+ graphics::FilterMode::Linear,
+ )
+ .expect("Draw text");
+
+ if let Some(debug_mesh) = self.debug_mesh.take() {
+ let mesh =
+ debug_mesh.build(self.context).expect("Build debug mesh");
+
+ graphics::draw(self.context, &mesh, graphics::DrawParam::default())
+ .expect("Draw debug mesh");
+ }
+ }
+}