94 asc_gl_context_add_cleanup_func(asc_active_glctx, textures_destroy); |
94 asc_gl_context_add_cleanup_func(asc_active_glctx, textures_destroy); |
95 } |
95 } |
96 |
96 |
97 static void backdrop_scale(AscBehavior *behavior) { |
97 static void backdrop_scale(AscBehavior *behavior) { |
98 // scale the backdrop to the size of the window |
98 // scale the backdrop to the size of the window |
99 if (asc_active_window->resized) { |
99 if (!asc_active_window->resized) return; |
100 asc_ptr_cast(AscSprite, sprite, behavior->node); |
100 asc_ptr_cast(AscSprite, sprite, behavior->node); |
101 asc_vec2u window_size = asc_active_window->dimensions; |
101 asc_vec2u window_size = asc_active_window->dimensions; |
102 asc_sprite_set_size(sprite, window_size); |
102 asc_sprite_set_size(sprite, window_size); |
103 } |
103 } |
|
104 |
|
105 static void main_scene_frame_scale(AscBehavior *behavior) { |
|
106 // TODO: we cannot skip this behavior when window is resized, |
|
107 // because the viewport is updated after executing all behaviors |
|
108 // and then the resized flag is cleared already. |
|
109 // A possible solution is to add something like a post-rendering behavior. |
|
110 // Another solution would be a viewport-changed-event (once we implement events) |
|
111 asc_ptr_cast(AscRectangle, frame, behavior->node); |
|
112 asc_rectangle_set_bounds(frame, MAIN_SCENE->camera.viewport); |
104 } |
113 } |
105 |
114 |
106 static void backdrop_create(void) { |
115 static void backdrop_create(void) { |
107 const float scale = asc_active_window->ui_scale; |
116 const float scale = asc_active_window->ui_scale; |
108 AscSceneNode *node = asc_sprite( |
117 AscSceneNode *node = asc_sprite( |
110 .texture_scale_mode = ASC_TEXTURE_SCALE_REPEAT, |
119 .texture_scale_mode = ASC_TEXTURE_SCALE_REPEAT, |
111 .texture_scale_x = scale, .texture_scale_y = scale, |
120 .texture_scale_x = scale, .texture_scale_y = scale, |
112 ); |
121 ); |
113 asc_behavior_add(node, .func = backdrop_scale); |
122 asc_behavior_add(node, .func = backdrop_scale); |
114 asc_scene_add_node(BACKDROP_SCENE, node); |
123 asc_scene_add_node(BACKDROP_SCENE, node); |
|
124 |
|
125 // also add a frame for the main scene |
|
126 // add this to the UI layer so that the border size does not scale |
|
127 AscSceneNode *frame = asc_rectangle(.thickness = 2, .color = ASC_RGB(66, 142, 161)); |
|
128 asc_behavior_add(frame, .func = main_scene_frame_scale); |
|
129 asc_ui_add_node(frame); |
115 } |
130 } |
116 |
131 |
117 static void fps_counter_update(AscBehavior *behavior) { |
132 static void fps_counter_update(AscBehavior *behavior) { |
118 asc_ptr_cast(AscText, node, behavior->node); |
133 asc_ptr_cast(AscText, node, behavior->node); |
119 static float last_fps = 0.f; |
134 static float last_fps = 0.f; |