rich_sdl2_rust/video/surface/
blend.rs1use crate::color::BlendMode;
4use crate::{bind, Sdl};
5
6use super::{RawSurface, Surface};
7
8#[derive(Debug)]
10pub struct Blended<S> {
11 surface: S,
12 mode: BlendMode,
13}
14
15impl<S> Blended<S> {
16 pub fn blend_mode(&self) -> &BlendMode {
18 &self.mode
19 }
20}
21
22impl<S: Surface> Blended<S> {
23 pub(super) fn new(surface: S, mode: BlendMode) -> Self {
24 let raw_mode = mode.into();
25 unsafe {
26 let ret = bind::SDL_SetSurfaceBlendMode(surface.as_ptr().as_ptr(), raw_mode);
27 if ret != 0 {
28 Sdl::error_then_panic("Setting surface blend mode");
29 }
30 }
31 Self { surface, mode }
32 }
33}
34
35impl<S: Surface> Surface for Blended<S> {
36 fn as_ptr(&self) -> std::ptr::NonNull<RawSurface> {
37 self.surface.as_ptr()
38 }
39}