1use bottomless_pit::colour::Colour;
2use bottomless_pit::engine_handle::{Engine, EngineBuilder};
3use bottomless_pit::input::MouseKey;
4use bottomless_pit::render::RenderHandle;
5use bottomless_pit::resource::{LoadingOp, ResourceId};
6use bottomless_pit::text::{Font, TextMaterial};
7use bottomless_pit::vec2;
8use bottomless_pit::vectors::Vec2;
9use bottomless_pit::Game;
10
11fn main() {
12 let mut engine = EngineBuilder::new().build().unwrap();
13
14 let comic = Font::new("examples/Comic.ttf", &mut engine, LoadingOp::Blocking);
15 let text_mat = TextMaterial::new("this is a test", Colour::RED, 0.5, 0.5 * 1.3);
16
17 let text_example = TextExample {
18 text_mat,
19 comic,
20 font_size: 0.5,
21 };
22
23 engine.run(text_example);
24}
25
26struct TextExample {
27 text_mat: TextMaterial,
28 comic: ResourceId<Font>,
29 font_size: f32,
30}
31
32impl Game for TextExample {
33 fn render<'o>(&'o mut self, mut render: RenderHandle<'o>) {
34 let mut render_handle = render.begin_pass(Colour::BLACK);
35
36 self.text_mat
37 .add_instance(vec2! { 0.0 }, Colour::WHITE, &render_handle);
38 self.text_mat.add_instance_with_rotation(
39 Vec2 { x: 100.0, y: 0.0 },
40 Colour::WHITE,
41 45.0,
42 &render_handle,
43 );
44
45 self.text_mat.draw(&mut render_handle);
46 }
47
48 fn update(&mut self, engine_handle: &mut Engine) {
49 self.font_size += 2.0 * engine_handle.get_frame_delta_time();
50
51 self.text_mat.set_font_size(self.font_size, engine_handle);
52 self.text_mat
53 .set_line_height(self.font_size * 1.3, engine_handle);
54
55 if engine_handle.is_mouse_key_pressed(MouseKey::Left) {
56 self.text_mat.set_text_with_font(
57 "hello I am talking to you here???",
58 Colour::GREEN,
59 &self.comic,
60 engine_handle,
61 );
62 }
63
64 self.text_mat.prepare(engine_handle);
65 }
66}