|
@@ -29,6 +29,7 @@ Console::Console() {
|
29
|
29
|
mPartialInput = NULL;
|
30
|
30
|
mHistoryPointer = 0;
|
31
|
31
|
mUnfinishedInput = NULL;
|
|
32
|
+ mLineOffset = 0;
|
32
|
33
|
}
|
33
|
34
|
|
34
|
35
|
Console::~Console() {
|
|
@@ -77,6 +78,16 @@ void Console::print(const char *s, ...) {
|
77
|
78
|
}
|
78
|
79
|
}
|
79
|
80
|
|
|
81
|
+#define LINE_GEOMETRY(window) unsigned int firstLine = 35; \
|
|
82
|
+ unsigned int lastLine = (window->mHeight / 2) - 55; \
|
|
83
|
+ unsigned int inputLine = (window->mHeight / 2) - 30; \
|
|
84
|
+ unsigned int lineSteps = 20; \
|
|
85
|
+ unsigned int lineCount = (lastLine - firstLine + lineSteps) / lineSteps; \
|
|
86
|
+ while (((lineCount * lineSteps) + firstLine) < inputLine) { \
|
|
87
|
+ lineSteps++; \
|
|
88
|
+ lineCount = (lastLine - firstLine + lineSteps) / lineSteps; \
|
|
89
|
+ }
|
|
90
|
+
|
80
|
91
|
void Console::display() {
|
81
|
92
|
Window *window = gOpenRaider->mWindow;
|
82
|
93
|
unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
|
|
@@ -84,15 +95,7 @@ void Console::display() {
|
84
|
95
|
if (mVisible) {
|
85
|
96
|
// Calculate line drawing geometry
|
86
|
97
|
// Depends on window height, so recalculate every time
|
87
|
|
- unsigned int firstLine = 35;
|
88
|
|
- unsigned int lastLine = (window->mHeight / 2) - 55;
|
89
|
|
- unsigned int inputLine = (window->mHeight / 2) - 30;
|
90
|
|
- unsigned int lineSteps = 20;
|
91
|
|
- unsigned int lineCount = (lastLine - firstLine + lineSteps) / lineSteps;
|
92
|
|
- while (((lineCount * lineSteps) + firstLine) < inputLine) {
|
93
|
|
- lineSteps++;
|
94
|
|
- lineCount = (lastLine - firstLine + lineSteps) / lineSteps;
|
95
|
|
- }
|
|
98
|
+ LINE_GEOMETRY(window);
|
96
|
99
|
|
97
|
100
|
// Draw half-transparent *overlay*
|
98
|
101
|
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
|
|
@@ -100,7 +103,15 @@ void Console::display() {
|
100
|
103
|
glRecti(0, 0, window->mWidth, window->mHeight / 2);
|
101
|
104
|
glEnable(GL_TEXTURE_2D);
|
102
|
105
|
|
103
|
|
- gOpenRaider->mWindow->drawText(10, 10, 0.70f, color, "%s uptime %lus", VERSION, systemTimerGet() / 1000);
|
|
106
|
+ int scrollIndicator;
|
|
107
|
+ if (mHistory.size() > lineCount) {
|
|
108
|
+ scrollIndicator = (mHistory.size() - lineCount - mLineOffset) * 100 / (mHistory.size() - lineCount);
|
|
109
|
+ } else {
|
|
110
|
+ scrollIndicator = 100;
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ gOpenRaider->mWindow->drawText(10, 10, 0.70f, color,
|
|
114
|
+ "%s uptime %lus scroll %d%%", VERSION, systemTimerGet() / 1000, scrollIndicator);
|
104
|
115
|
|
105
|
116
|
// Draw output log
|
106
|
117
|
int end = lineCount;
|
|
@@ -114,7 +125,7 @@ void Console::display() {
|
114
|
125
|
}
|
115
|
126
|
for (int i = 0; i < end; i++) {
|
116
|
127
|
gOpenRaider->mWindow->drawText(10, ((i + drawOffset) * lineSteps) + firstLine,
|
117
|
|
- 0.75f, color, "%s", mHistory[i + historyOffset]);
|
|
128
|
+ 0.75f, color, "%s", mHistory[i + historyOffset - mLineOffset]);
|
118
|
129
|
}
|
119
|
130
|
|
120
|
131
|
// Draw current input
|
|
@@ -135,6 +146,8 @@ void Console::handleKeyboard(KeyboardButton key, bool pressed) {
|
135
|
146
|
mHistory.push_back(bufferString("> %s", mInputBuffer));
|
136
|
147
|
mCommandHistory.push_back(bufferString("%s", mInputBuffer));
|
137
|
148
|
gOpenRaider->command(mInputBuffer);
|
|
149
|
+ } else {
|
|
150
|
+ mHistory.push_back(bufferString("> "));
|
138
|
151
|
}
|
139
|
152
|
|
140
|
153
|
// Clear partial and input buffer
|
|
@@ -200,6 +213,9 @@ void Console::moveInHistory(bool up) {
|
200
|
213
|
void Console::handleText(char *text, bool notFinished) {
|
201
|
214
|
//printf("Text: %s (%s)\n", text, (notFinished ? "not finished" : "finished"));
|
202
|
215
|
|
|
216
|
+ // Always scroll to bottom when text input is received
|
|
217
|
+ mLineOffset = 0;
|
|
218
|
+
|
203
|
219
|
if (!notFinished) {
|
204
|
220
|
// Finished entering character
|
205
|
221
|
// delete previous partial character, if present
|
|
@@ -228,3 +244,19 @@ void Console::handleText(char *text, bool notFinished) {
|
228
|
244
|
}
|
229
|
245
|
}
|
230
|
246
|
|
|
247
|
+void Console::handleMouseScroll(int xrel, int yrel) {
|
|
248
|
+ LINE_GEOMETRY(gOpenRaider->mWindow);
|
|
249
|
+
|
|
250
|
+ if (mHistory.size() > lineCount) {
|
|
251
|
+ if (yrel > 0) {
|
|
252
|
+ if (mLineOffset < (mHistory.size() - lineCount)) {
|
|
253
|
+ mLineOffset++;
|
|
254
|
+ }
|
|
255
|
+ } else if (yrel < 0) {
|
|
256
|
+ if (mLineOffset > 0) {
|
|
257
|
+ mLineOffset--;
|
|
258
|
+ }
|
|
259
|
+ }
|
|
260
|
+ }
|
|
261
|
+}
|
|
262
|
+
|