229 asc_scene_add_node(MAIN_SCENE, gamefield); |
229 asc_scene_add_node(MAIN_SCENE, gamefield); |
230 } |
230 } |
231 |
231 |
232 static asc_rect update_viewport_for_window_resize(asc_vec2u window_size) { |
232 static asc_rect update_viewport_for_window_resize(asc_vec2u window_size) { |
233 |
233 |
234 // TODO: special case: window is SO small that nothing would be rendered |
234 // margins |
235 |
|
236 // remove margins |
|
237 const unsigned margin = 10; |
235 const unsigned margin = 10; |
238 window_size.width -= 2*margin; |
236 |
239 window_size.height -= 2*margin; |
237 // space for score, power-ups, etc. |
240 |
|
241 // remove space for score, power-ups, etc. |
|
242 const unsigned left_area = (unsigned) (asc_active_window->ui_scale*200); |
238 const unsigned left_area = (unsigned) (asc_active_window->ui_scale*200); |
243 window_size.width -= left_area; |
239 |
|
240 // calculate how many pixels need to be removed from width and height |
|
241 const unsigned rw = 2*margin + left_area; |
|
242 const unsigned rh = 2*margin; |
|
243 |
|
244 // check if there is still a viewport left and chicken out when not |
|
245 if (window_size.width < rw || window_size.height < rh) { |
|
246 return ASC_RECT(0, 0, 0, 0); |
|
247 } |
|
248 window_size.width -= rw; |
|
249 window_size.height -= rh; |
244 |
250 |
245 // Compute scaling and offsets |
251 // Compute scaling and offsets |
246 unsigned viewport_size, offset_x = 0, offset_y = 0; |
252 unsigned viewport_size, offset_x = 0, offset_y = 0; |
247 if (window_size.width > window_size.height) { |
253 if (window_size.width > window_size.height) { |
248 // Wider window: letterbox (black bars on top/bottom) |
254 // Wider window: letterbox (black bars on top/bottom) |