Advertisement
harpwood

Untitled

Aug 29th, 2020 (edited)
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///@func set_resolution(design_value, is_design_vertical, is_orientation_vertical, resize_all_rooms, scale (optional), overide_other_value (optional))
  2. ///@arg design_value                  real      width or height of ideal resolution
  3. ///@arg is_design_value_vertical      boolean   When true, the design_value is condidered as height; when false, as width
  4. ///@arg is_orientation_vertical       boolean   When true, the screen orientation is considered as portrait; when false, as landscape
  5. ///@arg resize_all_rooms              boolean   When true: Rooms (except room index 0), will be resized to resulting value
  6. ///@arg scale(optional)               real      (Optional) Scale the game window to better fit the monitor. Will ommited on any non windows and non macos builds
  7. ///@arg overide_other_value(optional) real      (Optional) Overides the value other than the design_value arg for a custom aspect ratio. Will ommited like scale arg
  8.  
  9. ///Written by George Kritikos (Harpwood studio) - Based on code written by Pixelpope
  10. ///@License MIT License https://opensource.org/licenses/MIT
  11.  
  12. // arguments evaluation
  13. if argument_count < 4 or argument_count > 6 then show_error("Error set_resolution script: Incorect number of arguments. Expected number of arguments are minimum of 4 to maximum of 6.", true);
  14.  
  15. var _arg = [];
  16.  
  17. for (var i = 0; i < 6; i++;)
  18. {
  19.     if argument_count > i then _arg[i] = argument[i] else _arg[i] = undefined;
  20.     trace(_arg[i]);
  21. }
  22.  
  23.  
  24. // assigning _arg[] values for readability
  25. var _design_value               = _arg[0];
  26. var _is_design_value_vertical   = _arg[1];
  27. var _is_orientation_vertical    = _arg[2];
  28. var _resize_all_rooms           = _arg[3];
  29. var _scale                      = _arg[4] == undefined ? 1 : _arg[4]; // default scale = 1
  30. var _overide_other_value        = _arg[5];
  31.  
  32. //detect os_type only if is GMS2 IDE approprate
  33. _os_type = os_type == os_windows ? os_windows : os_macosx;
  34.  
  35. // The design value is either the design width or height. Every calculation in build with Test -> VM get a temporary scaling
  36. var _desing_width   = os_type == _os_type ? _design_value * _scale : _design_value;
  37. var _desing_height  = os_type == _os_type ? _design_value * _scale : _design_value;
  38.  
  39. var _real_width, _real_height, _aspect_ratio, _ideal_width, _ideal_height;
  40.  
  41. if _is_orientation_vertical
  42. {
  43.     //dirty way to get portait orientation for os_windows/os_macosx
  44.     _real_width     = os_type == _os_type ? display_get_height()  * _scale : display_get_width();
  45.     _real_height    = os_type == _os_type ? display_get_width() * _scale : display_get_height();
  46.     _aspect_ratio   = _real_width >= _real_height ? _real_height / _real_width : _real_width / _real_height;
  47.    
  48.     if _is_design_value_vertical    //The design value is reffering to vertical so we calculate the horizontal
  49.     {
  50.         _ideal_height = _desing_height;
  51.         if os_type == _os_type then _ideal_width = _overide_other_value == undefined ? round(_ideal_height * _aspect_ratio) : _overide_other_value * _scale;
  52.         else _ideal_width = round(_ideal_height * _aspect_ratio);
  53.     }
  54.     else                            //and vice versa
  55.     {
  56.         _ideal_width = _desing_width;
  57.         if os_type == _os_type then _ideal_height = _overide_other_value == undefined ? round(_ideal_width / _aspect_ratio) : _overide_other_value * _scale;
  58.         else _ideal_height = round(_ideal_width / _aspect_ratio);
  59.     }
  60.    
  61. }
  62. else
  63. {
  64.     _real_width     = os_type == _os_type ? display_get_width()  * _scale : display_get_width();
  65.     _real_height    = os_type == _os_type ? display_get_height() * _scale : display_get_height();
  66.     _aspect_ratio   = _real_width >= _real_height ? _real_height / _real_width : _real_width / _real_height;
  67.    
  68.    
  69.     if _is_design_value_vertical    //The design value is reffering to vertical so we calculate the horizontal
  70.     {
  71.         _ideal_height = _desing_height;
  72.         if os_type == _os_type then _ideal_width = _overide_other_value == undefined ?  round(_ideal_height / _aspect_ratio) : _overide_other_value * _scale;
  73.         else _ideal_width =  round(_ideal_height / _aspect_ratio);
  74.     }
  75.     else                            //and vice versa
  76.     {
  77.         _ideal_width = _desing_width;
  78.         if os_type == _os_type then _ideal_height = _overide_other_value == undefined ? round(_ideal_width * _aspect_ratio) : _overide_other_value * _scale;
  79.         else _ideal_height = round(_ideal_width * _aspect_ratio);
  80.     }
  81. }
  82.  
  83. //make the results more pixel perfect friendly
  84. if _ideal_width & 1 then _ideal_width++;
  85. if _ideal_height & 1 then _ideal_height++;
  86.  
  87. if _resize_all_rooms //apply resolution results to all rooms?
  88. {
  89.     for (var i = 1; i < room_last; i++) //all rooms except room with index 0, which usually is the init room
  90.     {
  91.         if room_exists(i)
  92.         {
  93.             room_set_width(i, _ideal_width);
  94.             room_set_height(i, _ideal_height);
  95.         }
  96.     }
  97. }
  98.  
  99. application_surface_enable(false);  // false as default behaviour
  100. window_set_size(_ideal_width, _ideal_height);
  101. surface_resize(application_surface, _real_width, _real_height);
  102.  
  103. //remove the temporary scaling if building with Test -> VM and apply results in global vars for further use
  104. global.ideal_width = os_type == _os_type ? _ideal_width / _scale : _ideal_width;
  105. global.ideal_height = os_type == _os_type ? _ideal_height / _scale : _ideal_height;
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement