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> {
24 pub fn viewport(&self) -> (u16, u16) {
25 let vp = self.canvas.viewport();
26 (vp.width() as u16, vp.height() as u16)
29 pub fn toggle_fullscreen(&mut self) {
30 match self.canvas.window().fullscreen_state() {
31 FullscreenType::Off => self
34 .set_fullscreen(FullscreenType::Desktop),
35 _ => self.canvas.window_mut().set_fullscreen(FullscreenType::Off),
40 pub fn clear(&mut self) {
41 self.canvas.set_draw_color((0, 0, 0));
45 pub fn present(&mut self) {
46 self.canvas.present();
49 pub fn blit<R1, R2>(&mut self, texture: &Texture, src: R1, dst: R2)
50 where R1: Into<Option<Rect>>,
51 R2: Into<Option<Rect>>
53 self.canvas.copy(texture, src, dst).unwrap();
56 pub fn blit_ex<R1, R2, P>(&mut self,
62 flip_horizontal: bool,
64 where R1: Into<Option<Rect>>,
65 R2: Into<Option<Rect>>,
66 P: Into<Option<Point>>
68 self.canvas.copy_ex(texture, src, dst, angle, center, flip_horizontal, flip_vertical).unwrap();
71 pub fn circle<P, C>(&self, pos: P, rad: i16, col: C)
72 where P: Into<(i16, i16)>,
76 self.canvas.aa_circle(pos.0, pos.1, rad, col.into()).unwrap();
79 pub fn ellipse<P, R, C>(&self, pos: P, rad: R, col: C)
80 where P: Into<(i16, i16)>,
86 self.canvas.aa_ellipse(pos.0, pos.1, rad.0, rad.1, col.into()).unwrap();
89 pub fn draw_line<P1, P2, C>(&mut self, start: P1, end: P2, col: C)
90 where P1: Into<Point>,
94 self.canvas.set_draw_color(col);
95 self.canvas.draw_line(start, end).unwrap();