Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/android tablet aspect ratio - fixes #180 #187

Merged
merged 7 commits into from
Nov 5, 2021
1 change: 0 additions & 1 deletion SonicTimeTwisted.gmx/SonicTimeTwisted.project.gmx
Original file line number Diff line number Diff line change
Expand Up @@ -3840,7 +3840,6 @@
</scripts>
<scripts name="Video">
<script>scripts\apply_video_settings.gml</script>
<script>scripts\get_smartphone_screen_width.gml</script>
</scripts>
<scripts name="I18n">
<script>scripts\tr.gml</script>
Expand Down
32 changes: 27 additions & 5 deletions SonicTimeTwisted.gmx/objects/objSSHud.object.gmx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,33 @@ top_hud_offset = tr_get_real_prop("top_hud_offset");
<kind>1</kind>
<string>metalProgDisplay =128 + objSSMetalSonic.progress * 280;
playerProgDisplay=128 + objSSPlayer.progress * 280;
</string>
</argument>
</arguments>
</action>
</event>
<event eventtype="8" enumb="64">
<action>
<libid>1</libid>
<id>603</id>
<kind>7</kind>
<userelative>0</userelative>
<isquestion>0</isquestion>
<useapplyto>-1</useapplyto>
<exetype>2</exetype>
<functionname></functionname>
<codestring></codestring>
<whoName>self</whoName>
<relative>0</relative>
<isnot>0</isnot>
<arguments>
<argument>
<kind>1</kind>
<string>/// Draw the pause menu and the defeat messages
if(menu.state != 0)
{
with(menu) event_user(4);
}
</string>
</argument>
</arguments>
Expand Down Expand Up @@ -367,11 +394,6 @@ script_execute(hud_draw_script);
draw_rectangle(0,0,426,240,false);
draw_set_color(c_white);
}
// this handles both the pause menu and the defeat messages
if(menu.state != 0)
{
with(menu) event_user(4);
}
</string>
</argument>
</arguments>
Expand Down
77 changes: 68 additions & 9 deletions SonicTimeTwisted.gmx/objects/objScreen.object.gmx
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,78 @@ view_wport[0] = width;
view_hport[0] = height;
if(DEVICE_INFO &amp; DEVICE_TYPE_SMARTPHONE)
{
var calculated_width = get_smartphone_screen_width();
show_debug_message("GUI: "+string(calculated_width)+" x "+string(height));

var maxgui_xscale = display_get_width()/calculated_width;
var maxgui_yscale = display_get_height()/height;
var maxgui_xoffset = maxgui_xscale*(calculated_width - width)/2;

display_set_gui_size(calculated_width, height);
display_set_gui_maximise(maxgui_xscale, maxgui_yscale, maxgui_xoffset, 0);
// calculating what the definition would be if the game used the entire screen
// first, the most common case: if the screen is of an aspect ratio larger than the game's native one
var calculated_width = width;
if(os_type == os_android)
{
if(display_get_orientation() == display_portrait
|| display_get_orientation() == display_portrait_flipped)
{
calculated_width = round(height * (display_get_height()/display_get_width()));
}
else
{
calculated_width = round(height * (display_get_width()/display_get_height()));
}
if(calculated_width mod 2)
{
calculated_width--;
}
}
var maxgui_xscale, maxgui_yscale;
if (calculated_width &gt;= width)
{
// if the device's screen is wide enough, then this works
maxgui_xscale = display_get_width()/calculated_width;
maxgui_yscale = display_get_height()/height;
var maxgui_xoffset = maxgui_xscale*(calculated_width - width)/2;

display_set_gui_size(calculated_width, height);
display_set_gui_maximise(maxgui_xscale, maxgui_yscale, maxgui_xoffset, 0);

gui_width = calculated_width;
gui_height = height;
}
else
{
// if the device's screen is not wide enough, then restart everything:
// the width should be the fixed valuee, the height must be the recalculated instead
var calculated_height = height;
if(os_type == os_android)
{
if(display_get_orientation() == display_portrait
|| display_get_orientation() == display_portrait_flipped)
{
calculated_height = round(426 * (display_get_width()/display_get_height()));
}
else
{
calculated_height = round(426 * (display_get_height()/display_get_width()));
}
if(calculated_height mod 2)
{
calculated_height--;
}
}

maxgui_xscale = display_get_width()/width;
maxgui_yscale = display_get_height()/calculated_height;
var maxgui_yoffset = maxgui_yscale*(calculated_height - height)/2;

display_set_gui_size(width, calculated_height);
display_set_gui_maximise(maxgui_xscale, maxgui_yscale, 0, maxgui_yoffset);

gui_width = width;
gui_height = calculated_height;

}
}
else
{
display_set_gui_size(width, height);
gui_width = width;
gui_height = height;
}


Expand Down
26 changes: 0 additions & 26 deletions SonicTimeTwisted.gmx/scripts/get_smartphone_screen_width.gml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// touchscreen inputs
var screen_width = get_smartphone_screen_width();
var screen_width = objScreen.gui_width;
var default_width = objScreen.width;
var margin = (screen_width - default_width)/2;
if(argument0) // argument0 - from INI, default values if false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
s = -1;
d3d_set_projection_ortho(-1*(internal__menu_slide_offset_x - draw_offset_x), 0, view_wport, view_hport, 0);
d3d_set_projection_ortho(-1*(internal__menu_slide_offset_x), 0, objScreen.gui_width, objScreen.gui_height, 0);
script_execute(draw_script);
49 changes: 45 additions & 4 deletions SonicTimeTwisted.gmx/scripts/menu_fn_draw_with_surface.gml
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
if(!surface_exists(s))
{
if(display_get_gui_width() > 512)
var surface_width, surface_height;

if (objScreen.gui_width > 1024)
{
s = surface_create(1024, 256);
surface_width = 2048;
}
else
{
s = surface_create(512, 256);
if (objScreen.gui_width > 512)
{
surface_width = 1024;
}
else
{
if (objScreen.gui_width > 256)
{
surface_width = 512;
}
else
{
surface_width = 256;
}
}
}


if (objScreen.gui_height > 1024)
{
surface_height = 2048;
}
else
{
if (objScreen.gui_height > 512)
{
surface_height = 1024;
}
else
{
if (objScreen.gui_height > 256)
{
surface_height = 512;
}
else
{
surface_height = 256;
}
}
}
s = surface_create(surface_width, surface_height);
}

surface_set_target(s);
Expand All @@ -16,5 +57,5 @@ draw_clear_alpha(c_black, 0);
script_execute(draw_script);

surface_reset_target();
draw_surface(s, internal__menu_slide_offset_x - draw_offset_x, draw_offset_y);
draw_surface(s, internal__menu_slide_offset_x - draw_offset_x, -1 * draw_offset_y);

1 change: 1 addition & 0 deletions SonicTimeTwisted.gmx/scripts/menu_fn_init.gml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ else
draw_offset_x = 0;
draw_offset_y = 0;
gui_click_offset_x = 0;
gui_click_offset_y = 0;

margin = 8;
button_slot_height = 28;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ else
}


var view_width = view_wview[view_current];
if(DEVICE_INFO & DEVICE_TYPE_SMARTPHONE)
{
view_width = get_smartphone_screen_width();
}
var view_height = view_hview[view_current];
var view_width = objScreen.gui_width;
var view_height = objScreen.gui_height;

draw_set_font(objResources.fontHudMin);
internal__draw_confirmation_height = string_height_ext(confirmation_text, 0, view_width - 4*margin) + 2*margin + 40;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ else
confirmation_no_action = -1;
}

var view_width = view_wview[view_current];
if(DEVICE_INFO & DEVICE_TYPE_SMARTPHONE)
{
view_width = get_smartphone_screen_width();
}
var view_height = view_hview[view_current];
var view_width = objScreen.gui_width;
var view_height = objScreen.gui_height;

draw_set_font(objResources.fontHudMin);
internal__draw_confirmation_height = string_height_ext(confirmation_text, 0, view_width - 4*margin) + 2*margin;
Expand Down
8 changes: 2 additions & 6 deletions SonicTimeTwisted.gmx/scripts/menu_fn_open_mapping_window.gml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ else
confirmation_no_action = -1;
}

var view_width = view_wview[view_current];
if(DEVICE_INFO & DEVICE_TYPE_SMARTPHONE)
{
view_width = get_smartphone_screen_width();
}
var view_height = view_hview[view_current];
var view_width = objScreen.gui_width;
var view_height = objScreen.gui_height;

draw_set_font(objResources.fontHudMin);
internal__draw_confirmation_height = string_height_ext(confirmation_text, 0, view_width - 4*margin) + 2*margin;
Expand Down
26 changes: 7 additions & 19 deletions SonicTimeTwisted.gmx/scripts/menu_fn_open_menu.gml
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,20 @@ if(state == 0)
draw_absolutely = true;
}
}
/*
if(draw_absolutely)
{
draw_offset_x = 0;
draw_offset_y = 0;
}
else
{
draw_offset_x = view_xview[view_current];
draw_offset_y = view_yview[view_current];
}
*/
if(DEVICE_INFO & DEVICE_TYPE_SMARTPHONE)
{
draw_offset_x = (get_smartphone_screen_width()-objScreen.width)/2;
draw_offset_x = (objScreen.gui_width-objScreen.width)/2;
gui_click_offset_x = draw_offset_x;
draw_offset_y = (objScreen.gui_height-objScreen.height)/2;
gui_click_offset_y = draw_offset_y;
}
else
{
draw_offset_x = (display_get_gui_width()-objScreen.width)/2;
gui_click_offset_x = 0;
}

show_debug_message("draw_offset_x: "+string(draw_offset_x));
draw_offset_y = 0;

gui_click_offset_x = 0;
draw_offset_y = 0;
gui_click_offset_y = 0;
}

state = 1;
timer = 0;
Expand Down
8 changes: 2 additions & 6 deletions SonicTimeTwisted.gmx/scripts/menu_fn_open_slider_window.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ confirmation_cursor = argument2;
confirmation_no_action = argument3; // used as minimum instead
confirmation_yes_action = argument4; // used as maximum instead

var view_width = view_wview[view_current];
if(DEVICE_INFO & DEVICE_TYPE_SMARTPHONE)
{
view_width = get_smartphone_screen_width();
}
var view_height = view_hview[view_current];
var view_width = objScreen.gui_width;
var view_height = objScreen.gui_height;

draw_set_font(objResources.fontHudMin);
internal__draw_confirmation_height = string_height_ext(confirmation_text, 0, view_width - 4*margin)*4 + 2*margin;
Expand Down
7 changes: 4 additions & 3 deletions SonicTimeTwisted.gmx/scripts/menu_fn_set_scripts.gml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ script_execute(item_script);
// recalculate coordinates of an open menu
internal__button_count = array_height_2d(items);
var view_width = view_wview[view_current];
var view_height = view_hview[view_current];

if(DEVICE_INFO & DEVICE_TYPE_SMARTPHONE)
{
view_width = get_smartphone_screen_width();
view_width = objScreen.gui_width;
view_height = objScreen.gui_height;
}
var view_height = view_hview[view_current];

internal__draw_menu_buttons_offset_y = (view_height - min(internal__button_count, button_page_count)*button_slot_height)/2;

internal__draw_menu_rect_x_center = view_width/2;
Expand Down
Loading