summaryrefslogtreecommitdiffstats
path: root/examples/ggez/renderer.rs
blob: ccf12aba6eb60e415a2bf3443cf20673a6bc4374 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
mod button;
mod checkbox;
mod radio;
mod slider;
mod text;

use ggez::graphics::{self, spritebatch::SpriteBatch, Image};
use ggez::Context;

pub struct Renderer<'a> {
    pub context: &'a mut Context,
    pub sprites: SpriteBatch,
    pub spritesheet: Image,
}

impl Renderer<'_> {
    pub fn new(context: &mut Context, spritesheet: Image) -> Renderer {
        Renderer {
            context,
            sprites: SpriteBatch::new(spritesheet.clone()),
            spritesheet,
        }
    }

    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");
    }
}