Skip to content

Commit

Permalink
Adds maximise argument to .scale_to_box()
Browse files Browse the repository at this point in the history
  • Loading branch information
JujuAdams committed Feb 4, 2023
1 parent 3590252 commit afd29da
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions scripts/__scribble_class_element/__scribble_class_element.gml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ function __scribble_class_element(_string, _unique_id) constructor
__wrap_no_pages = false;
__wrap_max_scale = 1;

__scale_to_box_dirty = true;
__scale_to_box_max_width = 0;
__scale_to_box_max_height = 0;
__scale_to_box_scale = undefined;
__scale_to_box_dirty = true;
__scale_to_box_width = 0;
__scale_to_box_height = 0;
__scale_to_box_maximise = false;
__scale_to_box_scale = undefined;

__line_height_min = -1;
__line_height_max = -1;
Expand Down Expand Up @@ -411,16 +412,18 @@ function __scribble_class_element(_string, _unique_id) constructor

/// @param maxWidth
/// @param maxHeight
static scale_to_box = function(_max_width, _max_height)
/// @param [maximise=false]
static scale_to_box = function(_max_width, _max_height, _maximise = false)
{
_max_width = ((_max_width == undefined) || (_max_width < 0))? 0 : _max_width;
_max_height = ((_max_height == undefined) || (_max_height < 0))? 0 : _max_height;

if ((_max_width != __scale_to_box_max_width) || (_max_height != __scale_to_box_max_height))
if ((_max_width != __scale_to_box_width) || (_max_height != __scale_to_box_height) || (_maximise != __scale_to_box_maximise))
{
__scale_to_box_max_width = _max_width;
__scale_to_box_max_height = _max_height;
__scale_to_box_dirty = true;
__scale_to_box_width = _max_width;
__scale_to_box_height = _max_height;
__scale_to_box_maximise = _maximise;
__scale_to_box_dirty = true;
}

return self;
Expand Down Expand Up @@ -1806,11 +1809,13 @@ function __scribble_class_element(_string, _unique_id) constructor

var _xscale = 1.0;
var _yscale = 1.0;
if (__scale_to_box_max_width > 0) _xscale = __scale_to_box_max_width / (_model.__get_width() + __padding_l + __padding_r);
if (__scale_to_box_max_height > 0) _yscale = __scale_to_box_max_height / (_model.__get_height() + __padding_t + __padding_b);
if (__scale_to_box_width > 0) _xscale = __scale_to_box_width / (_model.__get_width() + __padding_l + __padding_r);
if (__scale_to_box_height > 0) _yscale = __scale_to_box_height / (_model.__get_height() + __padding_t + __padding_b);

var _previous_scale_to_box_scale = __scale_to_box_scale;
__scale_to_box_scale = min(1.0, _xscale, _yscale);
__scale_to_box_scale = min(_xscale, _yscale);
if (!__scale_to_box_maximise) __scale_to_box_scale = min(1, __scale_to_box_scale);

if (__scale_to_box_scale != _previous_scale_to_box_scale)
{
__matrix_dirty = true;
Expand Down

0 comments on commit afd29da

Please sign in to comment.