Skip to content

Commit 611fb27

Browse files
authored
Merge pull request #26 from FaultyFunctions/master
Close #23, Close #25 - Fix clear script, fix scrolling to first line, & smooth scrolling options
2 parents 6ec1567 + a6d1a6f commit 611fb27

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ You can see examples of various ways to customize the shell's appearance on the
146146
| `keyRepeatInitialDelay` | The amount of time in frames to wait after pressing and holding a key before it begins to repeat. | 25 |
147147
| `keyRepeatDelay` | The amount of time in frames to wait between each repeat of a held key. | 4 |
148148
| `scrollSpeed` | The number of pixels at a time to scroll the console when moving the mouse wheel. | 16 |
149+
| `scrollSmoothness` | How smooth you want the scrolling to be when moving the mouse wheel. A number between 0 - 1. | 0.5 |
149150

150151
## Licensing
151152

rt-shell/objects/obj_shell/Create_0.gml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ consoleString = "";
1313
savedConsoleString = "";
1414
scrollPosition = 0;
1515
maxScrollPosition = 0;
16+
targetScrollPosition = 0;
1617
commandSubmitted = false; // Need to update scroll position one frame after a command is submitted
1718
insertMode = true;
1819

@@ -321,4 +322,14 @@ function array_contains(array, element) {
321322
}
322323
}
323324
return false;
325+
}
326+
327+
/// @param value
328+
/// @param min_input
329+
/// @param max_input
330+
/// @param min_output
331+
/// @param max_output
332+
function remap(value, min_input, max_input, min_output, max_output) {
333+
var _t = (value - min_input) / (max_input - min_input);
334+
return lerp(min_output, max_output, _t);
324335
}

rt-shell/objects/obj_shell/Draw_64.gml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ if (isOpen) {
2727
// Updating this here removes jitter as the scroll bar draws one frame in the old position
2828
// and then jumps to the bottom. This fixes that
2929
if (commandSubmitted) {
30-
maxScrollPosition = max(0, outputHeight - visibleHeight);
31-
scrollPosition = maxScrollPosition;
30+
maxScrollPosition = max(0, outputHeight - visibleHeight + emHeight);
31+
if (scrollSmoothness == 0) { scrollPosition = maxScrollPosition; }
32+
targetScrollPosition = maxScrollPosition;
3233
commandSubmitted = false;
3334
}
3435

35-
36-
3736
surface_set_target(scrollSurface);
3837
draw_clear_alpha(c_black, 0.0);
3938
var yOffset = -scrollPosition;
@@ -42,10 +41,9 @@ if (isOpen) {
4241
// the bottom of the panel
4342
if (outputHeight < visibleHeight - emHeight) {
4443
yOffset += visibleHeight - outputHeight - emHeight;
45-
} else {
46-
yOffset -= emHeight;
4744
}
4845

46+
4947
// Draw output history
5048
for (var i = 0; i < array_length(output); i++) {
5149
var outputStr = output[i];
@@ -127,7 +125,7 @@ if (isOpen) {
127125
draw_surface(scrollSurface, 0, shellOriginY + 1 + consolePaddingV);
128126

129127
// Draw scrollbar
130-
if (outputHeight > visibleHeight) {
128+
if (outputHeight > visibleHeight - emHeight) {
131129
var x1 = shellOriginX + width - consolePaddingH - scrollbarWidth;
132130
var y1 = shellOriginY + consolePaddingV + 1;
133131
var x2 = x1 + scrollbarWidth;
@@ -138,8 +136,8 @@ if (isOpen) {
138136

139137
var containerHeight = y2 - y1;
140138

141-
var scrollProgress = scrollPosition / (outputHeight - visibleHeight);
142-
var scrollbarHeight = (visibleHeight / outputHeight) * containerHeight;
139+
var scrollProgress = scrollPosition / (outputHeight - visibleHeight + emHeight);
140+
var scrollbarHeight = (visibleHeight / (outputHeight + emHeight)) * containerHeight;
143141
var scrollbarPosition = (containerHeight - scrollbarHeight) * scrollProgress;
144142

145143
y1 = y1 + scrollbarPosition;

rt-shell/objects/obj_shell/Other_10.gml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ variable_global_set("sh_clear", function(args) {
7474
return "";
7575
} else {
7676
array_push(output, ">" + consoleString);
77-
var _newLinesCount = floor(height / string_height(prompt)) - 1;
77+
draw_set_font(consoleFont);
78+
var _newLinesCount = floor(visibleHeight / string_height(prompt));
7879
repeat(_newLinesCount) {
7980
array_push(output, "\n");
8081
}

rt-shell/objects/obj_shell/Step_0.gml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ if (!isOpen) {
44
}
55
} else {
66
var prevConsoleString = consoleString;
7-
maxScrollPosition = max(0, outputHeight - visibleHeight);
87

98
if (keyboard_check_pressed(vk_escape)) {
109
if (isAutocompleteOpen) {
@@ -15,20 +14,20 @@ if (!isOpen) {
1514
} else if (self.keyboardCheckDelay(vk_backspace)) {
1615
consoleString = string_delete(consoleString, cursorPos - 1, 1);
1716
cursorPos = max(1, cursorPos - 1);
18-
scrollPosition = maxScrollPosition;
17+
targetScrollPosition = maxScrollPosition;
1918
} else if (self.keyboardCheckDelay(vk_delete)) {
2019
consoleString = string_delete(consoleString, cursorPos, 1);
21-
scrollPosition = maxScrollPosition;
20+
targetScrollPosition = maxScrollPosition;
2221
} else if (keyboard_string != "") {
2322
var t = keyboard_string;
2423
if (!insertMode) { consoleString = string_delete(consoleString, cursorPos, string_length(t)); }
2524
consoleString = string_insert(t, consoleString, cursorPos);
2625
cursorPos += string_length(t);
2726
keyboard_string = "";
28-
scrollPosition = maxScrollPosition;
27+
targetScrollPosition = maxScrollPosition;
2928
} else if (self.keyboardCheckDelay(vk_left)) {
3029
cursorPos = max(1, cursorPos - 1);
31-
scrollPosition = maxScrollPosition;
30+
targetScrollPosition = maxScrollPosition;
3231
} else if (self.keyboardCheckDelay(vk_right)) {
3332
if (cursorPos == string_length(consoleString) + 1 &&
3433
array_length(filteredSuggestions) != 0) {
@@ -37,7 +36,7 @@ if (!isOpen) {
3736
} else {
3837
cursorPos = min(string_length(consoleString) + 1, cursorPos + 1);
3938
}
40-
scrollPosition = maxScrollPosition;
39+
targetScrollPosition = maxScrollPosition;
4140
} else if (self.keyComboPressed(historyUpModifiers, historyUpKey)) {
4241
if (historyPos == array_length(history)) {
4342
savedConsoleString = consoleString;
@@ -47,7 +46,7 @@ if (!isOpen) {
4746
consoleString = array_get(history, historyPos);
4847
cursorPos = string_length(consoleString) + 1;
4948
}
50-
scrollPosition = maxScrollPosition;
49+
targetScrollPosition = maxScrollPosition;
5150
} else if (self.keyComboPressed(historyDownModifiers, historyDownKey)) {
5251
if (historyPos < array_length(history)) {
5352
historyPos = min(array_length(history), historyPos + 1);
@@ -58,7 +57,7 @@ if (!isOpen) {
5857
}
5958
cursorPos = string_length(consoleString) + 1;
6059
}
61-
scrollPosition = maxScrollPosition;
60+
targetScrollPosition = maxScrollPosition;
6261
} else if (keyboard_check_pressed(vk_enter)) {
6362
if (isAutocompleteOpen) {
6463
self.confirmCurrentSuggestion();
@@ -146,23 +145,30 @@ if (!isOpen) {
146145
}
147146
} else if (point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), shellOriginX, shellOriginY, shellOriginX + width, shellOriginY + height)) {
148147
if (mouse_wheel_down()) {
149-
scrollPosition += scrollSpeed;
148+
targetScrollPosition = targetScrollPosition + scrollSpeed;
150149
}
151150
if (mouse_wheel_up()) {
152-
scrollPosition -= scrollSpeed;
151+
targetScrollPosition = targetScrollPosition - scrollSpeed;
153152
}
154153
}
155154
} else {
156155
if (point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), shellOriginX, shellOriginY, shellOriginX + width, shellOriginY + height)) {
157156
if (mouse_wheel_down()) {
158-
scrollPosition += scrollSpeed;
157+
targetScrollPosition = targetScrollPosition + scrollSpeed;
159158
}
160159
if (mouse_wheel_up()) {
161-
scrollPosition -= scrollSpeed;
160+
targetScrollPosition = targetScrollPosition - scrollSpeed;
162161
}
163162
}
164163
}
165-
scrollPosition = clamp(scrollPosition, 0, maxScrollPosition);
164+
165+
// Updating scrolling
166+
var lerpValue = (scrollSmoothness == 0) ? 1 : remap(scrollSmoothness, 1, 0, 0.08, 0.4);
167+
scrollPosition = lerp(scrollPosition, targetScrollPosition, lerpValue);
168+
scrollPosition = clamp(scrollPosition, 0, maxScrollPosition)
169+
if (scrollPosition == 0 || scrollPosition == maxScrollPosition) {
170+
targetScrollPosition = clamp(targetScrollPosition, 0, maxScrollPosition);
171+
}
166172

167173
if (consoleString != prevConsoleString) {
168174
// If the text at the prompt has changed, update the list of possible

rt-shell/objects/obj_shell/obj_shell.yy

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)