11#include < span>
22
3+ #include " txt/utils.hpp"
34#include " txt/window.hpp"
45#include " txt/renderer.hpp"
56#include " txt/text/fonts.hpp"
67
78using namespace txt ::types;
89
9- static auto entry ([[maybe_unused]]std::span<char const *> const & args) -> void {
10- fmt::print (" hello\n " );
11- auto win = txt::make_window ({" Hello, Text!" });
12- auto ren = txt::make_renderer (win);
10+ auto entry ([[maybe_unused]]std::span<char const *> const & args) -> void {
11+ static auto win = txt::make_window ({" Hello, Text!" });
12+ static auto ren = txt::make_renderer (win);
13+ // ren->load_font({
14+ // "./res/fonts/Cozette/CozetteVector.ttf",
15+ // 128,
16+ // txt::text_render_mode::raster,
17+ // });
1318 ren->load_font ({
14- " ./res/fonts/Cozette/CozetteVector .ttf" ,
15- 13 ,
19+ " ./res/fonts/RobotoMono/RobotoMonoNerdFontMono-Medium .ttf" ,
20+ 16 ,
1621 txt::text_render_mode::raster,
22+ {0 , 0xFFFF }
1723 });
1824
19- auto mouse_x = 0 .0f ;
20- auto mouse_y = 0 .0f ;
25+ static auto mouse_x = 0 .0f ;
26+ static auto mouse_y = 0 .0f ;
27+ static auto rot = 0 .0f ;
2128
29+ win->add_event_listener ([&](txt::touch_start_event const & e) {
30+ if (e.points ().empty ()) return ;
31+ mouse_x = f32 (e.points ()[0 ].x ());
32+ mouse_y = f32 (win->height () - e.points ()[0 ].y ());
33+ fmt::print (" {}\n " , e.str ());
34+ });
35+ win->add_event_listener ([&](txt::touch_move_event const & e) {
36+ if (e.points ().empty ()) return ;
37+ mouse_x = f32 (e.points ()[0 ].x ());
38+ mouse_y = f32 (win->height () - e.points ()[0 ].y ());
39+ fmt::print (" {} {}: {}={}\n " , e.str (), mouse_y, win->height (), win->buffer_width ());
40+ });
2241 win->add_event_listener ([&](txt::mouse_move_event const & e) {
2342 fmt::print (" {}\n " , e.str ());
24- mouse_x = f32 (e.x ());
25- mouse_y = f32 (win->buffer_height () - e.y ());
2643 });
2744 win->add_event_listener ([&](txt::key_down_event const & e) {
2845 fmt::print (" {}\n " , e.str ());
@@ -33,13 +50,23 @@ static auto entry([[maybe_unused]]std::span<char const*> const& args) -> void {
3350 });
3451
3552 txt::loop (win, [&] {
53+ rot += txt::pi_f32 / 180 .0f * 3 .0f ;
54+
3655 ren->begin ();
3756 ren->viewport (0 , 0 , win->buffer_width (), win->buffer_height ());
3857 ren->clear_color (0x000000 );
3958 ren->clear ();
4059
4160 ren->text (" Hello, World!" , {0 .0f , 0 .0f });
4261
62+ ren->rect (glm::vec2{mouse_x, mouse_y}, glm::vec2{1 .0f , 100 .0f },
63+ rot, glm::vec4{1 .0f , 1 .0f , 1 .0f , 1 .0f }, {});
64+ ren->rect (glm::vec2{mouse_x, mouse_y}, glm::vec2{1 .0f , 100 .0f },
65+ rot+txt::pi_f32/2 .0f , glm::vec4{1 .0f , 1 .0f , 1 .0f , 1 .0f }, {});
66+
67+ ren->rect (glm::vec2{mouse_x, mouse_y}, glm::vec2{32 .0f , 32 .0f },
68+ rot, glm::vec4{1 .0f , 0 .0f , 0 .0f , 1 .0f }, {});
69+
4370 ren->end ();
4471
4572 win->swap ();
0 commit comments