Skip to content

Commit 771267c

Browse files
committed
SDL: update context menu
1 parent c3064c0 commit 771267c

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- F1 key for keywords surrounded by punctuation
66
- page scrolling with up/down arrow keys
77
- pressing tab at the bottom no longer jumps to the top
8+
- display additional editor context menu items
9+
Added a basic debugger
810

911
2015-08-02
1012
Fix display output before DELAY

src/common/inet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ void net_disconnect(socket_t s);
124124
/**
125125
* @ingroup net
126126
*
127-
* returns true if something is waitting in input-buffer
127+
* returns true if something is waiting in input-buffer
128128
*
129129
* @param s the socket
130-
* @return non-zero if something is waitting in input-buffer; otherwise returns 0
130+
* @return non-zero if something is waiting in input-buffer; otherwise returns 0
131131
*/
132132
int net_peek(socket_t s);
133133

src/platform/sdl/runtime.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void Runtime::debugStart(TextEditInput *editWidget, const char *file) {
162162

163163
if (g_debugee != -1) {
164164
net_print(g_debugee, "l\n");
165-
open = net_input(g_debugee, buf, sizeof(buf), "\r\n") > 0;
165+
open = net_input(g_debugee, buf, sizeof(buf), "\n") > 0;
166166
} else {
167167
open = false;
168168
}
@@ -175,7 +175,7 @@ void Runtime::debugStart(TextEditInput *editWidget, const char *file) {
175175
g_debugee = net_connect("localhost", g_debugPort);
176176
if (g_debugee != -1) {
177177
net_print(g_debugee, "l\n");
178-
size = net_input(g_debugee, buf, sizeof(buf), "\r\n");
178+
size = net_input(g_debugee, buf, sizeof(buf), "\n");
179179
if (size > 0) {
180180
editWidget->gotoLine(buf);
181181
appLog("Debug session ready");
@@ -194,14 +194,21 @@ void Runtime::debugStep(TextEditInput *edit, TextEditHelpWidget *help, bool cont
194194
int size;
195195
net_print(g_debugee, cont ? "c\n" : "n\n");
196196
net_print(g_debugee, "l\n");
197-
size = net_input(g_debugee, buf, sizeof(buf), "\r\n");
197+
size = net_input(g_debugee, buf, sizeof(buf), "\n");
198198
if (size > 0) {
199199
edit->gotoLine(buf);
200200
net_print(g_debugee, "v\n");
201-
size = net_input(g_debugee, buf, sizeof(buf), "\1");
202-
if (size > 0) {
203-
help->reload(buf);
204-
}
201+
help->reload(NULL);
202+
do {
203+
size = net_input(g_debugee, buf, sizeof(buf), "\1\n");
204+
if (buf[0] == '\1') {
205+
break;
206+
}
207+
if (size > 0) {
208+
help->append(buf, size);
209+
help->append("\n", 1);
210+
}
211+
} while (size > 0);
205212
}
206213
}
207214
}
@@ -630,7 +637,7 @@ void Runtime::optionsBox(StringList *items) {
630637
}
631638

632639
_output->redraw();
633-
while (selectedIndex == -1) {
640+
while (selectedIndex == -1 && !isClosing()) {
634641
MAEvent ev = processEvents(true);
635642
if (ev.type == EVENT_TYPE_KEY_PRESSED &&
636643
ev.key == 27) {

src/ui/inputs.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,16 @@ void MenuButton::draw(int x, int y, int w, int h, int chw) {
10791079
if (len * chw >= _width) {
10801080
len = _width / chw;
10811081
}
1082+
int charHeight = g_system->getOutput()->getCharHeight();
1083+
int textY = y + (_height - charHeight) / 2;
1084+
10821085
maSetColor(_pressed ? _fg : _bg);
1083-
maDrawText(x + 4, y + 4, _label.c_str(), len);
1086+
maDrawText(x + 4, textY, _label.c_str(), len);
1087+
if (!_pressed && _index > 0 && _index % 2 == 0) {
1088+
maSetColor(0x3b3a36);
1089+
maLine(x + 2, y, x + _width - 2, y);
1090+
maSetColor(0x46453f);
1091+
maLine(x + 2, y - 1, x + _width - 2, y - 1);
1092+
}
10841093
}
10851094
}

src/ui/system.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
#define MENU_SAVE 17
4141
#define MENU_RUN 18
4242
#define MENU_DEBUG 19
43-
#define MENU_SIZE 20
43+
#define MENU_OUTPUT 20
44+
#define MENU_SIZE 21
4445

4546
#define FONT_SCALE_INTERVAL 10
4647
#define FONT_MIN 20
@@ -314,6 +315,10 @@ void System::handleMenu(MAEvent &event) {
314315
event.type = EVENT_TYPE_KEY_PRESSED;
315316
event.key = SB_KEY_F(5);
316317
break;
318+
case MENU_OUTPUT:
319+
event.type = EVENT_TYPE_KEY_PRESSED;
320+
event.key = SB_KEY_CTRL('o');
321+
break;
317322
}
318323

319324
if (fontSize != _output->getFontSize()) {
@@ -720,11 +725,13 @@ void System::showMenu() {
720725
items->add(new String("Save"));
721726
items->add(new String("Run"));
722727
items->add(new String("Debug"));
728+
items->add(new String("Output"));
723729
_systemMenu[index++] = MENU_UNDO;
724730
_systemMenu[index++] = MENU_REDO;
725731
_systemMenu[index++] = MENU_SAVE;
726732
_systemMenu[index++] = MENU_RUN;
727733
_systemMenu[index++] = MENU_DEBUG;
734+
_systemMenu[index++] = MENU_OUTPUT;
728735
}
729736

730737
#if defined(_SDL)

src/ui/textedit.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,9 @@ void TextEditInput::reload(const char *text) {
611611
_scroll = 0;
612612
_cursorRow = 0;
613613
_buf.clear();
614-
_buf.insertChars(0, text, strlen(text));
614+
if (text != NULL) {
615+
_buf.insertChars(0, text, strlen(text));
616+
}
615617
stb_textedit_initialize_state(&_state, false);
616618
}
617619

src/ui/textedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct TextEditInput : public FormEditInput {
6969
TextEditInput(const char *text, int chW, int chH, int x, int y, int w, int h);
7070
virtual ~TextEditInput();
7171

72+
void append(const char *text, int len) { _buf.append(text, len); }
7273
void completeWord(const char *word);
7374
void draw(int x, int y, int w, int h, int chw);
7475
bool edit(int key, int screenWidth, int charWidth);

0 commit comments

Comments
 (0)