1 use sdl2::gfx::primitives::DrawRenderer;
2 use sdl2::pixels::Color;
3 use sdl2::rect::{Point, Rect};
4 use sdl2::render::{BlendMode, Canvas, Texture};
5 use sdl2::video::{FullscreenType, Window};
8 canvas: Canvas<Window>,
12 pub fn new(mut canvas: Canvas<Window>) -> Self {
13 canvas.set_blend_mode(BlendMode::Add);
14 canvas.set_draw_color((0, 0, 0));
20 pub fn canvas(&mut self) -> &mut Canvas<Window> {
25 pub fn viewport(&self) -> (u16, u16) {
26 let vp = self.canvas.viewport();
27 (vp.width() as u16, vp.height() as u16)
30 pub fn toggle_fullscreen(&mut self) {
31 match self.canvas.window().fullscreen_state() {
32 FullscreenType::Off => self
35 .set_fullscreen(FullscreenType::Desktop),
36 _ => self.canvas.window_mut().set_fullscreen(FullscreenType::Off),
41 pub fn clear(&mut self) {
42 self.canvas.set_draw_color((0, 0, 0));
46 pub fn present(&mut self) {
47 self.canvas.present();
50 pub fn blit<R1, R2>(&mut self, texture: &Texture, src: R1, dst: R2)
51 where R1: Into<Option<Rect>>,
52 R2: Into<Option<Rect>>
54 self.canvas.copy(texture, src, dst).unwrap();
58 pub fn blit_ex<R1, R2, P>(&mut self,
64 flip_horizontal: bool,
66 where R1: Into<Option<Rect>>,
67 R2: Into<Option<Rect>>,
68 P: Into<Option<Point>>
70 self.canvas.copy_ex(texture, src, dst, angle, center, flip_horizontal, flip_vertical).unwrap();
73 pub fn circle<P, C>(&self, pos: P, rad: i16, col: C)
74 where P: Into<(i16, i16)>,
78 self.canvas.aa_circle(pos.0, pos.1, rad, col.into()).unwrap();
82 pub fn ellipse<P, R, C>(&self, pos: P, rad: R, col: C)
83 where P: Into<(i16, i16)>,
89 self.canvas.aa_ellipse(pos.0, pos.1, rad.0, rad.1, col.into()).unwrap();
92 pub fn draw_line<P1, P2, C>(&mut self, start: P1, end: P2, col: C)
93 where P1: Into<Point>,
97 self.canvas.set_draw_color(col);
98 self.canvas.draw_line(start, end).unwrap();