Skip to content

Commit e34a466

Browse files
committed
UI: Added theme menu
1 parent 2622ffd commit e34a466

File tree

10 files changed

+75
-37
lines changed

10 files changed

+75
-37
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2020-06-14 (12.19)
22
UI: Use theme colours in main display #94
3+
UI: Added theme menu
34

45
2020-06-14 (12.19)
56
FLTK: line numbers colours #93

src/lib/jsmn

src/lib/lodepng

src/lib/miniaudio

src/platform/sdl/runtime.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ void Runtime::setActive(bool active) {
809809
if (active) {
810810
setWindowRect(_saveRect);
811811
} else {
812-
SDL_SetWindowPosition(_window, _saveRect.x, _saveRect.y);
813812
SDL_SetWindowSize(_window, _saveRect.w, _saveRect.h);
814813
setWindowSize(_saveRect.w, _saveRect.h);
815814
}

src/ui/system.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "common/keymap.h"
2121
#include "ui/system.h"
2222
#include "ui/inputs.h"
23+
#include "ui/theme.h"
2324

2425
#define MENU_CONSOLE 0
2526
#define MENU_SOURCE 1
@@ -45,7 +46,8 @@
4546
#define MENU_HELP 21
4647
#define MENU_SHORTCUT 22
4748
#define MENU_SHARE 23
48-
#define MENU_SIZE 24
49+
#define MENU_THEME 24
50+
#define MENU_SIZE 25
4951
#define MENU_COMPLETION_0 (MENU_SIZE + 1)
5052
#define MENU_COMPLETION_1 (MENU_SIZE + 2)
5153
#define MENU_COMPLETION_2 (MENU_SIZE + 3)
@@ -78,6 +80,7 @@
7880
#define MENU_STR_ON "ON"
7981
#define MENU_STR_AUDIO " Audio [%s] "
8082
#define MENU_STR_EDITOR " Editor [%s] "
83+
#define MENU_STR_THEME " Theme [%s] "
8184
#define MENU_STR_CONSOLE " Console "
8285
#define MENU_STR_CONTROL " Control Mode [%s] "
8386
#define MENU_STR_DEBUG " Debug "
@@ -398,6 +401,10 @@ void System::handleMenu(MAEvent &event) {
398401
case MENU_EDITMODE:
399402
opt_ide = (opt_ide == IDE_NONE ? IDE_INTERNAL : IDE_NONE);
400403
break;
404+
case MENU_THEME:
405+
g_themeId = (g_themeId + 1) % NUM_THEMES;
406+
setRestart();
407+
break;
401408
case MENU_AUDIO:
402409
opt_mute_audio = !opt_mute_audio;
403410
break;
@@ -1007,6 +1014,9 @@ void System::showMenu() {
10071014
sprintf(buffer, MENU_STR_EDITOR, opt_ide == IDE_NONE ? MENU_STR_OFF : MENU_STR_ON);
10081015
items->add(new String(buffer));
10091016
_systemMenu[index++] = MENU_EDITMODE;
1017+
sprintf(buffer, MENU_STR_THEME, themeName());
1018+
items->add(new String(buffer));
1019+
_systemMenu[index++] = MENU_THEME;
10101020
}
10111021
sprintf(buffer, MENU_STR_AUDIO, (opt_mute_audio ? MENU_STR_OFF : MENU_STR_ON));
10121022
items->add(new String(buffer));

src/ui/textedit.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ int textedit_move_to_word_next(EditBuffer *str, int c) {
6767
#define LINE_BUFFER_SIZE 200
6868
#define INDENT_LEVEL 2
6969
#define HELP_WIDTH 22
70-
#define NUM_THEMES 6
7170
#define TWISTY1_OPEN "> "
7271
#define TWISTY1_CLOSE "< "
7372
#define TWISTY2_OPEN " > "
@@ -90,6 +89,18 @@ int g_lineMarker[MAX_MARKERS] = {
9089
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
9190
};
9291

92+
const char *themeName() {
93+
switch (g_themeId) {
94+
case 0: return "Dark";
95+
case 1: return "Light";
96+
case 2: return "Shian";
97+
case 3: return "ATOM 1";
98+
case 4: return "ATOM 2";
99+
case 5: return "R157";
100+
default: return "";
101+
}
102+
}
103+
93104
// see: http://ethanschoonover.com/solarized#features
94105
#define sol_base03 0x002b36
95106
#define sol_base02 0x073642

src/ui/textedit.h

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of SmallBASIC
22
//
3-
// Copyright(C) 2001-2019 Chris Warren-Smith.
3+
// Copyright(C) 2001-2020 Chris Warren-Smith.
44
//
55
// This program is distributed under the terms of the GPL v2.0 or later
66
// Download the GNU Public License (GPL) from www.gnu.org
@@ -20,40 +20,12 @@
2020
#include <ctype.h>
2121
#include "lib/stb/stb_textedit.h"
2222
#include "ui/inputs.h"
23+
#include "ui/theme.h"
2324
#include "common/smbas.h"
2425
#include "common/keymap.h"
2526

26-
extern unsigned g_themeId;
27-
extern int g_user_theme[];
28-
#define THEME_COLOURS 17
29-
3027
struct TextEditInput;
3128

32-
struct EditTheme {
33-
EditTheme();
34-
EditTheme(int fg, int bg);
35-
void setId(const unsigned themeId);
36-
void selectTheme(const int theme[]);
37-
38-
int _color;
39-
int _background;
40-
int _selection_color;
41-
int _selection_background;
42-
int _number_color;
43-
int _number_selection_color;
44-
int _number_selection_background;
45-
int _cursor_color;
46-
int _cursor_background;
47-
int _match_background;
48-
int _row_cursor;
49-
int _syntax_comments;
50-
int _syntax_text;
51-
int _syntax_command;
52-
int _syntax_statement;
53-
int _syntax_digit;
54-
int _row_marker;
55-
};
56-
5729
struct StackTraceNode {
5830
StackTraceNode(const char *keyword, int type, int line)
5931
: _keyword(keyword), _type(type), _line(line) {}

src/ui/theme.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This file is part of SmallBASIC
2+
//
3+
// Copyright(C) 2001-2020 Chris Warren-Smith.
4+
//
5+
// This program is distributed under the terms of the GPL v2.0 or later
6+
// Download the GNU Public License (GPL) from www.gnu.org
7+
//
8+
9+
#ifndef THEME_H
10+
#define THEME_H
11+
12+
#define THEME_COLOURS 17
13+
#define NUM_THEMES 6
14+
15+
extern unsigned g_themeId;
16+
extern int g_user_theme[];
17+
18+
const char *themeName();
19+
20+
struct EditTheme {
21+
EditTheme();
22+
EditTheme(int fg, int bg);
23+
void setId(const unsigned themeId);
24+
void selectTheme(const int theme[]);
25+
26+
int _color;
27+
int _background;
28+
int _selection_color;
29+
int _selection_background;
30+
int _number_color;
31+
int _number_selection_color;
32+
int _number_selection_background;
33+
int _cursor_color;
34+
int _cursor_background;
35+
int _match_background;
36+
int _row_cursor;
37+
int _syntax_comments;
38+
int _syntax_text;
39+
int _syntax_command;
40+
int _syntax_statement;
41+
int _syntax_digit;
42+
int _row_marker;
43+
};
44+
45+
#endif

src/ui/window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "common/pproc.h"
1212
#include "lib/maapi.h"
1313
#include "ui/system.h"
14-
#include "ui/textedit.h"
14+
#include "ui/theme.h"
1515

1616
extern System *g_system;
1717

0 commit comments

Comments
 (0)