Skip to content

Commit

Permalink
Merge remote-tracking branch 'daikon-games/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
FaultyFunctions committed Jan 12, 2021
2 parents 38f3d9c + 29fe5c9 commit edc8c56
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
15 changes: 10 additions & 5 deletions rt-shell/objects/obj_shell/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ insertMode = true;
historyPos = 0;
history = [];
output = [];
outputHeight = 0;

filteredSuggestions = [];
inputArray = [];
Expand Down Expand Up @@ -220,9 +221,17 @@ function shell_properties_hash() {
function recalculate_shell_properties() {
var screenCenterX = display_get_gui_width() / 2;
var screenCenterY = display_get_gui_height() / 2;
draw_set_font(consoleFont);
var lineHeight = string_height("M");

// Clamp size of shell to available screen dimensions
var maxWidth = display_get_gui_width() - (anchorMargin * 2);
var maxHeight = display_get_gui_height() - (anchorMargin * 2);
width = clamp(width, 50, maxWidth);
height = clamp(height, lineHeight + (2 * consolePadding), maxHeight);

var halfWidth = width / 2;
var halfHeight = height / 2;

switch (screenAnchorPointH) {
case "left":
shellOriginX = anchorMargin - 1;
Expand All @@ -247,10 +256,6 @@ function recalculate_shell_properties() {
break;
}

// Resize width if larger than gui
if (width > display_get_gui_width()) { width = display_get_gui_width() - anchorMargin * 2; }
if (height > display_get_gui_height()) { height = display_get_gui_height() - anchorMargin * 2; }

// Calculate the width of the visible text area, taking into account all margins
visibleWidth = width - (2 * anchorMargin) - scrollbarWidth - (2 * consolePadding);
visibleHeight = height - anchorMargin - consolePadding;
Expand Down
37 changes: 20 additions & 17 deletions rt-shell/objects/obj_shell/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@ if (isOpen) {

var promptXOffset = consolePadding + string_width(prompt) + anchorMargin;

var outputHeight = 0;
outputHeight = 0;
for (var i = 0; i < array_length(output); i++) {
outputHeight += string_height_ext(output[i], -1, visibleWidth - promptXOffset);
}
var scrollSurfaceHeight = max(outputHeight + emHeight, visibleHeight);
if (!surface_exists(scrollSurface)) {
scrollSurface = surface_create(display_get_gui_width(), scrollSurfaceHeight);
} else {
surface_resize(scrollSurface, display_get_gui_width(), scrollSurfaceHeight);
// Updating this here removes jitter as the scroll bar draws one frame in the old position
// and then jumps to the bottom. This fixes that
if (commandSubmitted) {
maxScrollPosition = max(0, surface_get_height(scrollSurface) - visibleHeight);
scrollPosition = maxScrollPosition;
commandSubmitted = false;
}
scrollSurface = surface_create(display_get_gui_width(), visibleHeight);
} else if (surface_get_width(scrollSurface) != display_get_gui_width() ||
surface_get_height(scrollSurface) != visibleHeight) {
surface_resize(scrollSurface, display_get_gui_width(), visibleHeight);
}

// Updating this here removes jitter as the scroll bar draws one frame in the old position
// and then jumps to the bottom. This fixes that
if (commandSubmitted) {
maxScrollPosition = max(0, outputHeight - visibleHeight);
scrollPosition = maxScrollPosition;
commandSubmitted = false;
}

surface_set_target(scrollSurface);
draw_clear_alpha(c_black, 0.0);
var yOffset = 0;
var yOffset = -scrollPosition;

// Add some blank space if our output is too short so things appear to come from
// the bottom of the panel
if (outputHeight < visibleHeight - emHeight) {
yOffset += visibleHeight - outputHeight - emHeight;
} else {
yOffset -= emHeight;
}

// Draw output history
Expand Down Expand Up @@ -119,10 +122,10 @@ if (isOpen) {
draw_roundrect_ext(shellOriginX, shellOriginY, shellOriginX + width, shellOriginY + height, cornerRadius, cornerRadius, false);

// Draw the scroll surface
draw_surface_part(scrollSurface, 0, scrollPosition, display_get_gui_width(), visibleHeight, 0, shellOriginY + consolePadding);
draw_surface(scrollSurface, 0, shellOriginY + consolePadding);

// Draw scrollbar
if (surface_get_height(scrollSurface) > height - (2 * consolePadding) && surface_get_height(scrollSurface) > visibleHeight) {
if (outputHeight > visibleHeight) {
var x1 = shellOriginX + width - anchorMargin - scrollbarWidth;
var y1 = shellOriginY + anchorMargin;
var x2 = x1 + scrollbarWidth;
Expand All @@ -131,8 +134,8 @@ if (isOpen) {
draw_set_color(fontColorSecondary);
draw_rectangle(x1, y1, x2, y2, false);

var scrollbarHeight = (visibleHeight / surface_get_height(scrollSurface)) * visibleHeight;
var scrollbarProgress = scrollPosition / (surface_get_height(scrollSurface) - visibleHeight);
var scrollbarHeight = (visibleHeight / outputHeight) * visibleHeight;
var scrollbarProgress = scrollPosition / (outputHeight - visibleHeight);
var scrollbarPosition = (visibleHeight - scrollbarHeight) * scrollbarProgress;

y1 = y1 + scrollbarPosition;
Expand Down
2 changes: 1 addition & 1 deletion rt-shell/objects/obj_shell/Step_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if (!isOpen) {
}
} else {
var prevConsoleString = consoleString;
maxScrollPosition = max(0, surface_get_height(scrollSurface) - visibleHeight);
maxScrollPosition = max(0, outputHeight - visibleHeight);

// Recalculate shell properties if certain variables have changed
if (shell_properties_hash() != shellPropertiesHash) {
Expand Down

0 comments on commit edc8c56

Please sign in to comment.