pub(crate) mod canvas;
pub(crate) mod context;
pub(crate) mod draw;
pub(crate) mod gpu;
pub(crate) mod image;
pub(crate) mod instance;
pub(crate) mod internal_canvas;
pub(crate) mod mesh;
pub(crate) mod sampler;
pub(crate) mod shader;
pub(crate) mod text;
mod types;
pub use lyon::tessellation::{FillOptions, FillRule, LineCap, LineJoin, StrokeOptions};
pub use {
self::image::*, canvas::*, context::*, draw::*, instance::*, mesh::*, sampler::*, shader::*,
text::*, types::*,
};
#[must_use]
pub fn transform_rect(rect: Rect, param: DrawParam) -> Rect {
match param.transform {
Transform::Values {
scale,
offset,
dest,
rotation,
} => {
let mut r = Rect {
w: rect.w,
h: rect.h,
x: rect.x - offset.x * rect.w,
y: rect.y - offset.y * rect.h,
};
let real_scale = (param.src.w * scale.x, param.src.h * scale.y);
r.w = real_scale.0 * rect.w;
r.h = real_scale.1 * rect.h;
r.x *= real_scale.0;
r.y *= real_scale.1;
r.rotate(rotation);
r.x += dest.x;
r.y += dest.y;
r
}
Transform::Matrix(_m) => todo!("Fix me"),
}
}
use crate::{context::Has, GameResult};
use mint::Point2;
use std::path::Path;
#[deprecated(
since = "0.8.0",
note = "Use `drawable.draw` or `canvas.draw` instead."
)]
pub fn draw(canvas: &mut Canvas, drawable: &impl Drawable, param: impl Into<DrawParam>) {
drawable.draw(canvas, param);
}
#[deprecated(since = "0.8.0", note = "Use `ctx.gfx.set_window_icon` instead.")]
pub fn set_window_icon<P: AsRef<Path>>(
ctx: &impl Has<GraphicsContext>,
path: impl Into<Option<P>>,
) -> GameResult {
let gfx: &GraphicsContext = ctx.retrieve();
gfx.set_window_icon(&gfx.fs, path)
}
#[deprecated(since = "0.8.0", note = "Use `ctx.gfx.set_window_position` instead.")]
pub fn set_window_position(
ctx: &impl Has<GraphicsContext>,
position: impl Into<winit::dpi::Position>,
) -> GameResult {
let gfx: &GraphicsContext = ctx.retrieve();
gfx.set_window_position(position)
}
#[deprecated(since = "0.8.0", note = "Use `ctx.gfx.window` instead.")]
pub fn window(ctx: &impl Has<GraphicsContext>) -> &winit::window::Window {
let gfx: &GraphicsContext = ctx.retrieve();
gfx.window()
}
#[deprecated(since = "0.8.0", note = "Use `ctx.gfx.set_window_title` instead.")]
pub fn set_window_title(ctx: &impl Has<GraphicsContext>, title: &str) {
let gfx: &GraphicsContext = ctx.retrieve();
gfx.set_window_title(title);
}
#[deprecated(
since = "0.8.0",
note = "Don't use the `queue_text` and `draw_queued_text` system. Instead draw the texts directly."
)]
pub fn queue_text(
canvas: &mut Canvas,
text: &Text,
relative_dest: impl Into<Point2<f32>>,
color: Option<Color>,
) {
canvas
.queued_texts
.push((text.clone(), relative_dest.into(), color));
}
#[deprecated(
since = "0.8.0",
note = "Don't use the `queue_text` and `draw_queued_text` system. Instead draw the texts directly."
)]
pub fn draw_queued_text(
canvas: &mut Canvas,
param: impl Into<DrawParam>,
blend: Option<BlendMode>,
filter: FilterMode,
) -> GameResult {
let mut param = param.into();
let param_dest = *param.get_dest_mut();
canvas.set_sampler(filter);
if let Some(blend) = blend {
canvas.set_blend_mode(blend);
}
for queued_text in std::mem::take(&mut canvas.queued_texts) {
queued_text.0.draw(
canvas,
param.dest(mint::Point2 {
x: param_dest.x + queued_text.1.x,
y: param_dest.y + queued_text.1.y,
}),
);
}
Ok(())
}