1#![crate_name = "graphics"]
2#![deny(
3 rust_2018_compatibility,
4 rust_2018_idioms,
5 unused,
6 nonstandard_style,
7 future_incompatible,
8 missing_docs,
9 missing_copy_implementations
10)]
11
12pub use character::{Character, CharacterCache};
39pub use circle_arc::CircleArc;
40pub use colored::Colored;
41pub use context::Context;
42pub use draw_state::DrawState;
43pub use ellipse::Ellipse;
44pub use crate::graphics::Graphics;
45pub use image::Image;
46pub use line::Line;
47pub use polygon::Polygon;
48pub use radians::Radians;
49pub use rectangle::Rectangle;
50pub use rectangled::Rectangled;
51pub use source_rectangled::SourceRectangled;
52pub use text::Text;
53pub use texture::ImageSize;
54pub use transformed::Transformed;
55pub use viewport::Viewport;
56
57pub const BACK_END_MAX_VERTEX_COUNT: usize = 1023;
64
65mod colored;
66mod graphics;
67mod rectangled;
68mod source_rectangled;
69mod transformed;
70
71pub mod character;
72pub mod circle_arc;
73pub mod color;
74pub mod context;
75pub mod draw_state;
76pub mod ellipse;
77pub mod glyph_cache;
78pub mod grid;
79pub mod image;
80pub mod line;
81pub mod math;
82pub mod modular_index;
83pub mod polygon;
84pub mod rectangle;
85pub mod text;
86pub mod texture_packer;
87pub mod triangulation;
88pub mod types;
89
90pub mod radians {
91 pub use vecmath::traits::Radians;
94}
95
96pub fn clear<G>(color: types::Color, g: &mut G)
98where
99 G: Graphics,
100{
101 g.clear_color(color);
102 g.clear_stencil(0);
103}
104
105pub fn image<G>(image: &<G as Graphics>::Texture, transform: math::Matrix2d, g: &mut G)
107where
108 G: Graphics,
109{
110 Image::new().draw(image, &Default::default(), transform, g);
111}
112
113pub fn ellipse_from_to<P: Into<types::Vec2d>, G>(
115 color: types::Color,
116 from: P,
117 to: P,
118 transform: math::Matrix2d,
119 g: &mut G,
120) where
121 G: Graphics,
122{
123 Ellipse::new(color).draw_from_to(from, to, &Default::default(), transform, g);
124}
125
126pub fn ellipse<R: Into<types::Rectangle>, G>(
128 color: types::Color,
129 rect: R,
130 transform: math::Matrix2d,
131 g: &mut G,
132) where
133 G: Graphics,
134{
135 Ellipse::new(color).draw(rect, &Default::default(), transform, g);
136}
137
138pub fn circle_arc<R: Into<types::Rectangle>, G>(
140 color: types::Color,
141 radius: types::Radius,
142 start: types::Scalar,
143 end: types::Scalar,
144 rect: R,
145 transform: math::Matrix2d,
146 g: &mut G,
147) where
148 G: Graphics,
149{
150 CircleArc::new(color, radius, start, end).draw(rect, &Default::default(), transform, g);
151}
152
153pub fn rectangle_from_to<P: Into<types::Vec2d>, G>(
155 color: types::Color,
156 from: P,
157 to: P,
158 transform: math::Matrix2d,
159 g: &mut G,
160) where
161 G: Graphics,
162{
163 Rectangle::new(color).draw_from_to(from, to, &Default::default(), transform, g);
164}
165
166pub fn rectangle<R: Into<types::Rectangle>, G>(
168 color: types::Color,
169 rect: R,
170 transform: math::Matrix2d,
171 g: &mut G,
172) where
173 G: Graphics,
174{
175 Rectangle::new(color).draw(rect, &Default::default(), transform, g);
176}
177
178pub fn polygon<G>(
180 color: types::Color,
181 polygon: types::Polygon<'_>,
182 transform: math::Matrix2d,
183 g: &mut G,
184) where
185 G: Graphics,
186{
187 Polygon::new(color).draw(polygon, &Default::default(), transform, g);
188}
189
190pub fn line_from_to<P: Into<types::Vec2d>, G>(
192 color: types::Color,
193 radius: types::Radius,
194 from: P,
195 to: P,
196 transform: math::Matrix2d,
197 g: &mut G,
198) where
199 G: Graphics,
200{
201 Line::new(color, radius).draw_from_to(from, to, &Default::default(), transform, g)
202}
203
204pub fn line<L: Into<types::Line>, G>(
206 color: types::Color,
207 radius: types::Radius,
208 line: L,
209 transform: math::Matrix2d,
210 g: &mut G,
211) where
212 G: Graphics,
213{
214 Line::new(color, radius).draw(line, &Default::default(), transform, g)
215}
216
217pub fn text<C, G>(
219 color: types::Color,
220 font_size: types::FontSize,
221 text: &str,
222 cache: &mut C,
223 transform: math::Matrix2d,
224 g: &mut G,
225) -> Result<(), C::Error>
226where
227 C: character::CharacterCache,
228 G: Graphics<Texture = <C as character::CharacterCache>::Texture>,
229{
230 Text::new_color(color, font_size).draw(text, cache, &Default::default(), transform, g)
231}