fonts
LICENSE LiberationMono-Bold.ttf LiberationMono-BoldItalic.ttf LiberationMono-Italic.ttf LiberationMono-Regular.ttf LiberationSans-Bold.ttf LiberationSans-BoldItalic.ttf LiberationSans-Italic.ttf LiberationSans-Regular.ttf LiberationSerif-Bold.ttf LiberationSerif-BoldItalic.ttf LiberationSerif-Italic.ttf LiberationSerif-Regular.ttftests
cmyk_2000x1500_537kb.jpg color_test_800x600_118kb.jpg exif_rich_3000x2000_3.81mb.jpg grayscale_1600x1200_188kb.jpg landscape_hires_4000x2667_6.83mb.jpg large_banner_1920x600_124kb.jpg progressive_1920x1080_319kb.jpg social_square_1080x1080_235kb.jpg thumbnail_150x150_10.5kb.jpg upload_test_5000x3333_11.6mb.jpg web_optimized_1200x800_97kb.jpg
main.c3
raw
1import std::io;
2import std::collections;
3import raylib55::rl;
4
5import config;
6import embed;
7
8alias ProjectList = List {Project};
9
10struct Project {
11 int width;
12 int height;
13}
14
15struct Context {
16 rl::RLFont regular_font;
17 rl::RLFont bold_font;
18 rl::RLCamera2D camera;
19
20 ProjectList projects;
21}
22
23fn void main() {
24 rl::set_config_flags(rl::RLConfigFlag.WINDOW_RESIZABLE | rl::RLConfigFlag.VSYNC_HINT);
25 rl::init_window(config::WINDOW_WIDTH, config::WINDOW_HEIGHT, config::WINDOW_TITLE);
26 defer rl::close_window();
27
28 Context ctx = {
29 .regular_font = rl::load_font_from_memory(".ttf", &embed::REGULAR_FONT_DATA[0], (int)embed::REGULAR_FONT_DATA.len, 96, null, 0),
30 .bold_font = rl::load_font_from_memory(".ttf", &embed::BOLD_FONT_DATA[0], (int)embed::BOLD_FONT_DATA.len, 96, null, 0),
31 };
32
33 defer rl::unload_font(ctx.regular_font);
34 defer rl::unload_font(ctx.bold_font);
35
36 rl::RLTexture2D.set_filter(ctx.regular_font.texture, rl::RLTextureFilter.BILINEAR);
37 rl::RLTexture2D.set_filter(ctx.bold_font.texture, rl::RLTextureFilter.BILINEAR);
38
39 rl::set_target_fps(config::TARGET_FPS);
40
41 // Camera setup.
42 ctx.camera = {
43 .zoom = 1.0,
44 .target = { 0.0, 0.0 },
45 };
46
47 // Initialize test project.
48 ctx.projects.init(mem);
49
50 Project p = {
51 .width = 300,
52 .height = 400,
53 };
54
55 ctx.projects.push(p);
56
57 // Load test image
58 rl::RLTexture2D img = rl::load_texture("tests/social_square_1080x1080_235kb.jpg");
59 defer rl::unload_texture(img);
60
61 while(!rl::window_should_close()) {
62 // Handle camera movement.
63 if (rl::is_mouse_button_down(rl::RLMouseButton.MIDDLE)) {
64 rl::RLVector2 delta = rl::get_mouse_delta();
65 ctx.camera.target[0] -= delta[0] / ctx.camera.zoom;
66 ctx.camera.target[1] -= delta[1] / ctx.camera.zoom;
67 }
68
69 // Handle camera zoom.
70 float wheel = rl::get_mouse_wheel_move();
71 if (wheel != 0) {
72 rl::RLVector2 mouse_world_pos = rl::get_screen_to_world2d(rl::get_mouse_position(), ctx.camera);
73 ctx.camera.offset = rl::get_mouse_position();
74 ctx.camera.target = mouse_world_pos;
75 ctx.camera.zoom += (wheel * config::ZOOM_SENSITIVITY);
76 if (ctx.camera.zoom < 0.125) { ctx.camera.zoom = 0.125; };
77 }
78
79 rl::begin_drawing();
80 rl::clear_background(rl::BLACK);
81 rl::draw_text_ex(ctx.regular_font, "Howdy!", { 100, 100 }, 42.0, 2.0, rl::BLUE);
82
83 rl::begin_mode2d(ctx.camera);
84 rl::draw_text_ex(ctx.regular_font, "Pannable Canvas", { 0, 0 }, 42.0, 2.0, rl::RED);
85 rl::draw_texture(img, 200, 200, rl::WHITE);
86 rl::end_mode2d();
87 rl::end_drawing();
88 }
89}