1use crate::gfx::Gfx;
2use crate::{
3 to_wgpu_color, FixedAtlas, FontAndMaterial, FrameLookup, MaterialRef, NineSliceAndMaterial,
4 QuadParams, Render, RenderItem, Renderable, SpriteParams, Text, TileMap,
5};
6use int_math::{URect, UVec2, Vec2, Vec3};
7use mireforge_render::{AspectRatio, Color, ViewportStrategy, VirtualScale};
8use monotonic_time_rs::Millis;
9
10impl Gfx for Render {
11 fn sprite_atlas_frame(&mut self, position: Vec3, frame: u16, atlas: &impl FrameLookup) {
12 self.sprite_atlas_frame(position, frame, atlas);
13 }
14
15 fn sprite_atlas(&mut self, position: Vec3, atlas_rect: URect, material_ref: &MaterialRef) {
16 self.sprite_atlas(position, atlas_rect, material_ref);
17 }
18
19 fn draw_sprite(&mut self, position: Vec3, material_ref: &MaterialRef) {
20 self.draw_sprite(position, material_ref);
21 }
22
23 fn draw_sprite_ex(
24 &mut self,
25 position: Vec3,
26 material_ref: &MaterialRef,
27 params: &SpriteParams,
28 ) {
29 self.draw_sprite_ex(position, material_ref, *params);
30 }
31
32 fn quad(&mut self, position: Vec3, size: UVec2, color: Color) {
33 self.draw_quad(position, size, color);
34 }
35
36 fn quad_ex(&mut self, position: Vec3, size: UVec2, color: Color, params: QuadParams) {
37 self.draw_quad_ex(position, size, color, params);
38 }
39
40 fn draw_with_mask(
41 &mut self,
42 position: Vec3,
43 size: UVec2,
44 color: Color,
45 alpha_masked: &MaterialRef,
46 ) {
47 self.push_mask(position, size, color, alpha_masked);
48 }
49
50 fn nine_slice(
51 &mut self,
52 position: Vec3,
53 size: UVec2,
54 color: Color,
55 nine_slice: &NineSliceAndMaterial,
56 ) {
57 self.nine_slice(position, size, color, nine_slice);
58 }
59
60 fn nine_slice_stretch(
61 &mut self,
62 position: Vec3,
63 size: UVec2,
64 color: Color,
65 nine_slice: &NineSliceAndMaterial,
66 ) {
67 self.nine_slice_stretch(position, size, color, nine_slice);
68 }
69
70 fn set_origin(&mut self, position: Vec2) {
71 self.origin = position;
72 }
73
74 fn set_clear_color(&mut self, color: Color) {
75 self.clear_color = to_wgpu_color(color);
76 }
77
78 fn tilemap_params(
79 &mut self,
80 position: Vec3,
81 tiles: &[u16],
82 width: u16,
83 atlas_ref: &FixedAtlas,
84 scale: u8,
85 ) {
86 self.items.push(RenderItem {
87 position,
88 material_ref: atlas_ref.material.clone(),
89 renderable: Renderable::TileMap(TileMap {
90 tiles_data_grid_size: UVec2::new(width, tiles.len() as u16 / width),
91 cell_count_size: atlas_ref.cell_count_size,
92 one_cell_size: atlas_ref.one_cell_size,
93 tiles: Vec::from(tiles),
94 scale,
95 }),
96 });
97 }
98
99 fn text_draw(
100 &mut self,
101 position: Vec3,
102 text: &str,
103 font_and_mat: &FontAndMaterial,
104 color: &Color,
105 ) {
106 self.items.push(RenderItem {
107 position,
108 material_ref: font_and_mat.material_ref.clone(),
109 renderable: Renderable::Text(Text {
110 text: text.to_string(),
111 font_ref: (&font_and_mat.font_ref).into(),
112 color: *color,
113 }),
114 });
115 }
116
117 fn now(&self) -> Millis {
118 self.last_render_at
119 }
120
121 fn physical_aspect_ratio(&self) -> AspectRatio {
122 self.physical_surface_size.into()
123 }
124
125 fn physical_size(&self) -> UVec2 {
126 self.physical_surface_size
127 }
128
129 fn set_virtual_size(&mut self, virtual_size: UVec2) {
130 self.resize_virtual(virtual_size);
131 }
132
133 fn set_viewport(&mut self, viewport_strategy: ViewportStrategy) {
134 self.viewport_strategy = viewport_strategy;
135 }
136
137 fn viewport(&self) -> &ViewportStrategy {
138 &self.viewport_strategy
139 }
140
141 fn set_scale(&mut self, scale_factor: VirtualScale) {
142 match scale_factor {
143 VirtualScale::IntScale(scale) => self.scale = f32::from(scale),
144 VirtualScale::FloatScale(scale) => self.scale = scale,
145 }
146 }
147}