use crate::drawables::{RaylibDrawContext, RaylibDrawable};
use crate::renderer::RaylibRender;
use cotis::renders::{CotisRenderer, CotisRendererAsync};
use cotis_defaults::render_commands::render_t_list::{IsRenderList, RenderTList};
use raylib::prelude::RaylibDraw;
impl<'b> CotisRenderer<Box<dyn RaylibDrawable + 'b>> for RaylibRender {
fn draw_frame(&mut self, render_commands: impl Iterator<Item = Box<dyn RaylibDrawable + 'b>>) {
self.load_new_font_sizes();
let mut rl = self.lock_handle();
let mut d = rl.begin_drawing(self.thread());
d.clear_background(self.background_color);
let mut clip_stack = Vec::new();
let mut ctx = RaylibDrawContext {
d: &mut d,
fonts: self.fonts(),
clip_stack: &mut clip_stack,
image_cache: None,
};
for cmd in render_commands {
cmd.draw(&mut ctx);
}
}
}
impl<'b> CotisRendererAsync<Box<dyn RaylibDrawable + 'b>> for RaylibRender {
async fn draw_frame(
&mut self,
render_commands: impl Iterator<Item = Box<dyn RaylibDrawable + 'b>>,
) {
self.load_new_font_sizes();
let mut rl = self.lock_handle();
let mut d = rl.begin_drawing(self.thread());
d.clear_background(self.background_color);
let mut clip_stack = Vec::new();
let mut ctx = RaylibDrawContext {
d: &mut d,
fonts: self.fonts(),
clip_stack: &mut clip_stack,
image_cache: None,
};
for cmd in render_commands {
cmd.draw(&mut ctx);
}
}
}
impl<T: RaylibDrawable, L: RaylibDrawable + IsRenderList> CotisRenderer<RenderTList<T, L>>
for RaylibRender
{
fn draw_frame(&mut self, render_commands: impl Iterator<Item = RenderTList<T, L>>) {
self.load_new_font_sizes();
let commands: Vec<_> = render_commands.collect();
for cmd in &commands {
cmd.preload_generic_images(self);
}
let mut rl = self.lock_handle();
let mut d = rl.begin_drawing(self.thread());
d.clear_background(self.background_color);
let mut clip_stack = Vec::new();
let mut ctx = RaylibDrawContext {
d: &mut d,
fonts: self.fonts(),
clip_stack: &mut clip_stack,
image_cache: Some(self.image_cache()),
};
for cmd in commands {
Box::new(cmd).draw(&mut ctx);
}
}
}
impl<T: RaylibDrawable, L: RaylibDrawable + IsRenderList> CotisRendererAsync<RenderTList<T, L>>
for RaylibRender
{
async fn draw_frame(&mut self, render_commands: impl Iterator<Item = RenderTList<T, L>>) {
CotisRenderer::draw_frame(self, render_commands);
}
}
impl<T: RaylibDrawable> CotisRenderer<RenderTList<T, ()>> for RaylibRender {
fn draw_frame(&mut self, render_commands: impl Iterator<Item = RenderTList<T, ()>>) {
self.load_new_font_sizes();
let commands: Vec<_> = render_commands.collect();
for cmd in &commands {
cmd.preload_generic_images(self);
}
let mut rl = self.lock_handle();
let mut d = rl.begin_drawing(self.thread());
d.clear_background(self.background_color);
let mut clip_stack = Vec::new();
let mut ctx = RaylibDrawContext {
d: &mut d,
fonts: self.fonts(),
clip_stack: &mut clip_stack,
image_cache: Some(self.image_cache()),
};
for cmd in commands {
Box::new(cmd).draw(&mut ctx);
}
}
}
impl<T: RaylibDrawable> CotisRendererAsync<RenderTList<T, ()>> for RaylibRender {
async fn draw_frame(&mut self, render_commands: impl Iterator<Item = RenderTList<T, ()>>) {
CotisRenderer::draw_frame(self, render_commands);
}
}