import std::io; import std::collections; import raylib55::rl; import config; import embed; alias ProjectList = List {Project}; struct Project { int width; int height; } struct Context { rl::RLFont regular_font; rl::RLFont bold_font; rl::RLCamera2D camera; ProjectList projects; } fn void main() { rl::set_config_flags(rl::RLConfigFlag.WINDOW_RESIZABLE | rl::RLConfigFlag.VSYNC_HINT); rl::init_window(config::WINDOW_WIDTH, config::WINDOW_HEIGHT, config::WINDOW_TITLE); defer rl::close_window(); Context ctx = { .regular_font = rl::load_font_from_memory(".ttf", &embed::REGULAR_FONT_DATA[0], (int)embed::REGULAR_FONT_DATA.len, 96, null, 0), .bold_font = rl::load_font_from_memory(".ttf", &embed::BOLD_FONT_DATA[0], (int)embed::BOLD_FONT_DATA.len, 96, null, 0), }; defer rl::unload_font(ctx.regular_font); defer rl::unload_font(ctx.bold_font); rl::RLTexture2D.set_filter(ctx.regular_font.texture, rl::RLTextureFilter.BILINEAR); rl::RLTexture2D.set_filter(ctx.bold_font.texture, rl::RLTextureFilter.BILINEAR); rl::set_target_fps(config::TARGET_FPS); // Camera setup. ctx.camera = { .zoom = 1.0, .target = { 0.0, 0.0 }, }; // Initialize test project. ctx.projects.init(mem); Project p = { .width = 300, .height = 400, }; ctx.projects.push(p); // Load test image rl::RLTexture2D img = rl::load_texture("tests/social_square_1080x1080_235kb.jpg"); defer rl::unload_texture(img); while(!rl::window_should_close()) { // Handle camera movement. if (rl::is_mouse_button_down(rl::RLMouseButton.MIDDLE)) { rl::RLVector2 delta = rl::get_mouse_delta(); ctx.camera.target[0] -= delta[0] / ctx.camera.zoom; ctx.camera.target[1] -= delta[1] / ctx.camera.zoom; } // Handle camera zoom. float wheel = rl::get_mouse_wheel_move(); if (wheel != 0) { rl::RLVector2 mouse_world_pos = rl::get_screen_to_world2d(rl::get_mouse_position(), ctx.camera); ctx.camera.offset = rl::get_mouse_position(); ctx.camera.target = mouse_world_pos; ctx.camera.zoom += (wheel * config::ZOOM_SENSITIVITY); if (ctx.camera.zoom < 0.125) { ctx.camera.zoom = 0.125; }; } rl::begin_drawing(); rl::clear_background(rl::BLACK); rl::draw_text_ex(ctx.regular_font, "Howdy!", { 100, 100 }, 42.0, 2.0, rl::BLUE); rl::begin_mode2d(ctx.camera); rl::draw_text_ex(ctx.regular_font, "Pannable Canvas", { 0, 0 }, 42.0, 2.0, rl::RED); rl::draw_texture(img, 200, 200, rl::WHITE); rl::end_mode2d(); rl::end_drawing(); } }