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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![allow(clippy::unnecessary_cast)]
use bitflags::bitflags;
use crate::texture::Texture;
use crate::{
as_raw,
geo::{Point, Rect},
};
use crate::{bind, EnumInt, Sdl};
use super::Renderer;
bitflags! {
pub struct PasteExFlip: u32 {
const HORIZONTAL = bind::SDL_FLIP_HORIZONTAL as u32;
const VERTICAL = bind::SDL_FLIP_VERTICAL as u32;
const BOTH = Self::HORIZONTAL.bits | Self::VERTICAL.bits;
}
}
impl Default for PasteExFlip {
fn default() -> Self {
Self::empty()
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub struct PasteExOption {
pub target_area: Option<Rect>,
pub rotation_degrees: f64,
pub center: Option<Point>,
pub flip: PasteExFlip,
}
pub trait PasteExt {
fn paste(&self, texture: &Texture, target_area: Option<Rect>);
fn paste_ex(&self, texture: &Texture, options: PasteExOption);
}
impl PasteExt for Renderer<'_> {
fn paste(&self, texture: &Texture, target_area: Option<Rect>) {
let src = texture.clip().map(Into::into);
let dst = target_area.map(Into::into);
let ret = unsafe {
bind::SDL_RenderCopy(self.as_ptr(), texture.as_ptr(), as_raw(&src), as_raw(&dst))
};
if ret != 0 {
Sdl::error_then_panic("Pasting texture to renderer");
}
}
fn paste_ex(
&self,
texture: &Texture,
PasteExOption {
target_area,
rotation_degrees,
center,
flip,
}: PasteExOption,
) {
let src = texture.clip().map(Into::into);
let dst = target_area.map(Into::into);
let center = center.map(Into::into);
let ret = unsafe {
bind::SDL_RenderCopyEx(
self.as_ptr(),
texture.as_ptr(),
as_raw(&src),
as_raw(&dst),
rotation_degrees,
as_raw(¢er),
flip.bits as EnumInt,
)
};
if ret != 0 {
Sdl::error_then_panic("Pasting texture to renderer ex");
}
}
}