Skip to content

Commit 46bd333

Browse files
committed
UI: add menu control key indicators
1 parent 1babb1b commit 46bd333

File tree

5 files changed

+97
-34
lines changed

5 files changed

+97
-34
lines changed

ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
2019-11-30 (0.12.17)
1+
2019-12-07 (0.12.17)
22
FLTK: fix memory leaks
33
FLTK: implement audio
4+
UI: add menu control key indicators
45

56
2019-11-30 (0.12.17)
67
ANDROID: fix module access in newer android versions.

src/platform/fltk/HelpWidget.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3045,5 +3045,5 @@ Fl_Image *loadImage(const char *imgSrc) {
30453045
}
30463046

30473047
void browseFile(const char *url) {
3048-
fl_open_uri(url);
3048+
fl_open_uri(url, nullptr, 0);
30493049
}

src/platform/sdl/runtime.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define MAIN_BAS "__main_bas__"
3535
#define AMPLITUDE 22000
3636
#define FREQUENCY 44100
37-
#define OPTIONS_BOX_WIDTH_EXTRA 4
37+
#define OPTIONS_BOX_WIDTH_EXTRA 1
3838
#define OPTIONS_BOX_BG 0xd2d1d0
3939
#define OPTIONS_BOX_FG 0x3e3f3e
4040
#define EVENT_TYPE_RESTART 101
@@ -971,8 +971,9 @@ int osd_devrestore(void) {
971971
}
972972
}
973973

974-
// delete the cached sounds
974+
// delete the sounds
975975
g_soundCache.removeAll();
976+
g_sounds.removeAll();
976977

977978
SDL_UnlockAudio();
978979

src/ui/system.cpp

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@
5858
#define FONT_MIN 20
5959
#define FONT_MAX 200
6060

61+
#define MENU_STR_AUDIO "Audio [%s]"
62+
#define MENU_STR_BACK "Back ^b"
63+
#define MENU_STR_CONSOLE "Console"
64+
#define MENU_STR_CONTROL "Control Mode [%s]"
65+
#define MENU_STR_COPY "Copy ^c"
66+
#define MENU_STR_CUT "Cut ^x"
67+
#define MENU_STR_DEBUG "Debug"
68+
#define MENU_STR_EDITOR "Editor [%s]"
69+
#define MENU_STR_FONT "Font Size %d%%"
70+
#define MENU_STR_HELP "Help"
71+
#define MENU_STR_KEYPAD "Show Keypad"
72+
#define MENU_STR_OFF "OFF"
73+
#define MENU_STR_ON "ON"
74+
#define MENU_STR_OUTPUT "Show Output"
75+
#define MENU_STR_PASTE "Paste ^v"
76+
#define MENU_STR_REDO "Redo ^y"
77+
#define MENU_STR_RESTART "Restart"
78+
#define MENU_STR_RUN "Run ^r"
79+
#define MENU_STR_SAVE "Save ^s"
80+
#define MENU_STR_SCREEN "Screenshot ^p"
81+
#define MENU_STR_SELECT "Select All ^a"
82+
#define MENU_STR_SHARE "Share"
83+
#define MENU_STR_SHORT "Desktop Shortcut"
84+
#define MENU_STR_SOURCE "View Source"
85+
#define MENU_STR_UNDO "Undo ^z"
86+
6187
System *g_system;
6288

6389
void Cache::add(const char *key, const char *value) {
@@ -141,6 +167,38 @@ bool System::execute(const char *bas) {
141167
return result != 0;
142168
}
143169

170+
void System::formatOptions(StringList *items) {
171+
int maxLength = 0;
172+
bool hasControl = false;
173+
List_each(String *, it, *items) {
174+
String *str = * it;
175+
if (str->indexOf('^', 0) != -1) {
176+
hasControl = true;
177+
}
178+
int len = str->length();
179+
if (len > maxLength) {
180+
maxLength = len;
181+
}
182+
}
183+
if (hasControl) {
184+
List_each(String *, it, *items) {
185+
String *str = * it;
186+
if (str->indexOf('^', 0) != -1) {
187+
String command = str->leftOf('^');
188+
String control = str->rightOf('^');
189+
int len = maxLength - str->length();
190+
for (int i = 0; i < len; i++) {
191+
command.append(' ');
192+
}
193+
command.append("C-");
194+
command.append(control);
195+
str->clear();
196+
str->append(command);
197+
}
198+
}
199+
}
200+
}
201+
144202
bool System::fileExists(strlib::String &path) {
145203
bool result = false;
146204
if (path.indexOf("://", 1) != -1) {
@@ -866,19 +924,19 @@ void System::showMenu() {
866924
int index = 0;
867925
if (get_focus_edit() != nullptr) {
868926
if (isEditing()) {
869-
items->add(new String("Undo"));
870-
items->add(new String("Redo"));
871-
items->add(new String("Cut"));
872-
items->add(new String("Copy"));
873-
items->add(new String("Paste"));
874-
items->add(new String("Select All"));
875-
items->add(new String("Save"));
876-
items->add(new String("Run"));
927+
items->add(new String(MENU_STR_UNDO));
928+
items->add(new String(MENU_STR_REDO));
929+
items->add(new String(MENU_STR_CUT));
930+
items->add(new String(MENU_STR_COPY));
931+
items->add(new String(MENU_STR_PASTE));
932+
items->add(new String(MENU_STR_SELECT));
933+
items->add(new String(MENU_STR_SAVE));
934+
items->add(new String(MENU_STR_RUN));
877935
#if defined(_SDL)
878-
items->add(new String("Debug"));
879-
items->add(new String("Show Output"));
936+
items->add(new String(MENU_STR_DEBUG));
937+
items->add(new String(MENU_STR_OUTPUT));
880938
#endif
881-
items->add(new String("Help"));
939+
items->add(new String(MENU_STR_HELP));
882940
for (int i = 0; i < completions; i++) {
883941
_systemMenu[index++] = MENU_COMPLETION_0 + i;
884942
}
@@ -896,70 +954,72 @@ void System::showMenu() {
896954
#endif
897955
_systemMenu[index++] = MENU_HELP;
898956
} else if (isRunning()) {
899-
items->add(new String("Cut"));
900-
items->add(new String("Copy"));
901-
items->add(new String("Paste"));
902-
items->add(new String("Select All"));
957+
items->add(new String(MENU_STR_CUT));
958+
items->add(new String(MENU_STR_COPY));
959+
items->add(new String(MENU_STR_PASTE));
960+
items->add(new String(MENU_STR_SELECT));
903961
_systemMenu[index++] = MENU_CUT;
904962
_systemMenu[index++] = MENU_COPY;
905963
_systemMenu[index++] = MENU_PASTE;
906964
_systemMenu[index++] = MENU_SELECT_ALL;
907965
}
908966
#if defined(_SDL) || defined(_FLTK)
909-
items->add(new String("Back"));
967+
items->add(new String(MENU_STR_BACK));
910968
_systemMenu[index++] = MENU_BACK;
911969
#else
912-
items->add(new String("Show keypad"));
970+
items->add(new String(MENU_STR_KEYPAD));
913971
_systemMenu[index++] = MENU_KEYPAD;
914972
if (!isEditing()) {
915973
bool controlMode = get_focus_edit()->getControlMode();
916-
sprintf(buffer, "Control Mode [%s]", (controlMode ? "ON" : "OFF"));
974+
sprintf(buffer, MENU_STR_CONTROL, (controlMode ? MENU_STR_ON : MENU_STR_OFF));
917975
items->add(new String(buffer));
918976
_systemMenu[index++] = MENU_CTRL_MODE;
919977
}
920978
#endif
921979
} else {
922-
items->add(new String("Console"));
923-
items->add(new String("View source"));
980+
items->add(new String(MENU_STR_CONSOLE));
981+
items->add(new String(MENU_STR_SOURCE));
924982
_systemMenu[index++] = MENU_CONSOLE;
925983
_systemMenu[index++] = MENU_SOURCE;
926984
if (!isEditing()) {
927-
items->add(new String("Restart"));
985+
items->add(new String(MENU_STR_RESTART));
928986
_systemMenu[index++] = MENU_RESTART;
929987
}
930988
#if !defined(_SDL) && !defined(_FLTK)
931-
items->add(new String("Show keypad"));
989+
items->add(new String(MENU_STR_KEYPAD));
932990
_systemMenu[index++] = MENU_KEYPAD;
933991
#endif
934-
items->add(new String("Screenshot"));
992+
items->add(new String(MENU_STR_SCREEN));
935993
_systemMenu[index++] = MENU_SCREENSHOT;
936994
if (_mainBas) {
937-
sprintf(buffer, "Font Size %d%%", _fontScale - FONT_SCALE_INTERVAL);
995+
sprintf(buffer, MENU_STR_FONT, _fontScale - FONT_SCALE_INTERVAL);
938996
items->add(new String(buffer));
939-
sprintf(buffer, "Font Size %d%%", _fontScale + FONT_SCALE_INTERVAL);
997+
sprintf(buffer, MENU_STR_FONT, _fontScale + FONT_SCALE_INTERVAL);
940998
items->add(new String(buffer));
941999
_systemMenu[index++] = MENU_ZOOM_UP;
9421000
_systemMenu[index++] = MENU_ZOOM_DN;
943-
sprintf(buffer, "Editor [%s]", opt_ide == IDE_NONE ? "OFF" : "ON");
1001+
sprintf(buffer, MENU_STR_EDITOR, opt_ide == IDE_NONE ? MENU_STR_OFF : MENU_STR_ON);
9441002
items->add(new String(buffer));
9451003
_systemMenu[index++] = MENU_EDITMODE;
9461004
}
9471005
#if !defined(_SDL) && !defined(_FLTK)
9481006
if (!_mainBas && !_activeFile.empty()) {
949-
items->add(new String("Desktop Shortcut"));
950-
items->add(new String("Share"));
1007+
items->add(new String(MENU_STR_SHORT));
1008+
items->add(new String(MENU_STR_SHARE));
9511009
_systemMenu[index++] = MENU_SHORTCUT;
9521010
_systemMenu[index++] = MENU_SHARE;
9531011
}
9541012
#endif
955-
sprintf(buffer, "Audio [%s]", (opt_mute_audio ? "OFF" : "ON"));
1013+
sprintf(buffer, MENU_STR_AUDIO, (opt_mute_audio ? MENU_STR_OFF : MENU_STR_ON));
9561014
items->add(new String(buffer));
9571015
_systemMenu[index++] = MENU_AUDIO;
9581016
#if defined(_SDL) || defined(_FLTK)
959-
items->add(new String("Back"));
1017+
items->add(new String(MENU_STR_BACK));
9601018
_systemMenu[index++] = MENU_BACK;
9611019
#endif
9621020
}
1021+
1022+
formatOptions(items);
9631023
optionsBox(items);
9641024
delete items;
9651025
_menuActive = false;

src/ui/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct System {
7373
void editSource(strlib::String loadPath, bool restoreOnExit);
7474
bool execute(const char *bas);
7575
bool fileExists(strlib::String &path);
76+
void formatOptions(StringList *items);
7677
MAEvent getNextEvent() { return processEvents(1); }
7778
uint32_t getModifiedTime();
7879
void handleEvent(MAEvent &event);

0 commit comments

Comments
 (0)