Skip to content

Commit 2709c3f

Browse files
committed
UI: experimental keypad to replace android keypad
1 parent 1c22dfa commit 2709c3f

File tree

8 files changed

+142
-83
lines changed

8 files changed

+142
-83
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
set(VERSION "12.29")
99
cmake_minimum_required(VERSION 3.10)
10-
project(SmallBASIC_SDL VERSION ${VERSION} LANGUAGES C CXX)
10+
project(SmallBASIC VERSION ${VERSION} LANGUAGES C CXX)
1111

1212
set(CMAKE_CXX_STANDARD 14)
1313
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1414

15-
find_package(SDL3 REQUIRED)
15+
# cmake -DWITH_DEBUG=ON
16+
option(WITH_DEBUG "Enable debug build" OFF)
1617

1718
function(writeConfig)
1819
execute_process(
@@ -35,13 +36,23 @@ function(writeConfig)
3536
)
3637
endfunction()
3738

39+
function(checkDebugMode)
40+
if(WITH_DEBUG)
41+
set(SANITIZER_FLAGS "-fstack-protector-all -fno-omit-frame-pointer -fsanitize=address,undefined")
42+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
44+
message(STATUS "Debug mode enabled via --with-debug")
45+
endif()
46+
endfunction()
47+
3848
function(buildSDL)
3949
# Initialize variables
4050
set(TARGET "Building SDL version.")
4151
set(PACKAGE_CFLAGS "")
4252
set(PACKAGE_LIBS "")
4353

4454
# check dependencies using pkg-config
55+
find_package(SDL3 REQUIRED)
4556
find_package(PkgConfig REQUIRED)
4657

4758
pkg_check_modules(SDL3 REQUIRED sdl3)
@@ -105,6 +116,12 @@ function(buildSDL)
105116
writeConfig()
106117
endfunction()
107118

119+
message("generating kwp.h")
120+
execute_process(
121+
COMMAND bash -c "(cd ../documentation && g++ -o build_kwp build_kwp.cpp && ./build_kwp > ../src/ui/kwp.h)"
122+
)
123+
124+
checkDebugMode()
108125
buildSDL()
109126

110127
set(COMMON_DIR ${CMAKE_SOURCE_DIR}/src/common)

documentation/build_kwp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ int main(int argc, char *argv[]) {
245245
}
246246

247247
fprintf(stdout, "/* automagicaly generated file */\n");
248+
fprintf(stdout, "#pragma once\n");
248249
fprintf(stdout, "static struct KEYWORD_HELP {\n");
249250
fprintf(stdout, " const char *package;\n");
250251
fprintf(stdout, " const char *keyword;\n");

ide/config.h.in

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ extern "C" {
1818
#cmakedefine01 _UnixOS
1919
#cmakedefine01 IMPL_DEV_READ
2020
#cmakedefine01 IMPL_LOG_WRITE
21-
22-
#cmakedefine _SDL_VERSION "@_SDL_VERSION@"
23-
#cmakedefine VERSION "@VERSION@"
24-
#cmakedefine BUILD_DATE @BUILD_DATE@
25-
#cmakedefine SB_DWORD_VER @SB_DWORD_VER@
21+
#cmakedefine _SDL_VERSION "@_SDL_VERSION@"
22+
#cmakedefine VERSION "@VERSION@"
23+
#cmakedefine BUILD_DATE @BUILD_DATE@
24+
#cmakedefine SB_DWORD_VER @SB_DWORD_VER@
2625

2726
#ifdef __cplusplus
2827
}

src/platform/sdl/runtime.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@
2020
#include "platform/sdl/display.h"
2121

2222
struct Runtime : public System {
23-
Runtime(SDL_Window *window);
24-
virtual ~Runtime();
23+
explicit Runtime(SDL_Window *window);
24+
~Runtime() override;
2525

26-
void addShortcut(const char *) {}
27-
void alert(const char *title, const char *message);
28-
int ask(const char *title, const char *prompt, bool cancel);
29-
void browseFile(const char *url);
26+
void addShortcut(const char *) override {}
27+
void alert(const char *title, const char *message) override;
28+
int ask(const char *title, const char *prompt, bool cancel) override;
29+
void browseFile(const char *url) override;
3030
void construct(const char *font, const char *boldFont);
3131
bool debugActive();
3232
bool debugOpen(const char *file);
3333
void debugStart(TextEditInput *edit, const char *file);
3434
void debugStep(TextEditInput *edit, TextEditHelpWidget *help, bool cont);
3535
void debugStop();
36-
void enableCursor(bool enabled);
36+
void enableCursor(bool enabled) override;
3737
void exportRun(const char *path);
3838
void redraw() { _graphics->redraw(); }
3939
bool toggleFullscreen();
@@ -42,21 +42,21 @@ struct Runtime : public System {
4242
void pause(int timeout);
4343
void pollEvents(bool blocking);
4444
MAEvent *popEvent() { return _eventQueue->pop(); }
45-
MAEvent processEvents(int waitFlag);
45+
MAEvent processEvents(int waitFlag) override;
4646
void processEvent(MAEvent &event);
4747
void pushEvent(MAEvent *event) { _eventQueue->push(event); }
48-
void saveWindowRect();
49-
void setWindowRect(int x, int y, int width, int height);
50-
void setWindowTitle(const char *title);
51-
void share(const char *path) {}
52-
void showCursor(CursorType cursorType);
48+
void saveWindowRect() override;
49+
void setWindowRect(int x, int y, int width, int height) override;
50+
void setWindowTitle(const char *title) override;
51+
void share(const char *path) override {}
52+
void showCursor(CursorType cursorType) override;
5353
int runShell(const char *startupBas, bool once, int fontScale, int debugPort);
54-
char *loadResource(const char *fileName);
54+
char *loadResource(const char *fileName) override;
5555
void logStack(int line, bool subOrFunc);
5656
void onResize(int w, int h);
57-
void onRunCompleted();
58-
void setClipboardText(const char *text);
59-
char *getClipboardText();
57+
void onRunCompleted() override;
58+
void setClipboardText(const char *text) override;
59+
char *getClipboardText() override;
6060
void setWindowRect(SDL_Rect &rect);
6161
SDL_Rect getWindowRect();
6262

src/ui/ansiwidget.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ void AnsiWidget::drawRect(int x1, int y1, int x2, int y2) {
158158
}
159159

160160
// draw a filled rectangle onto the offscreen buffer
161-
void AnsiWidget::drawRectFilled(int x1, int y1, int x2, int y2) {
161+
void AnsiWidget::drawRectFilled(int x1, int y1, int x2, int y2) const {
162162
_back->drawRectFilled(x1, y1, x2, y2);
163163
flush(false, false, MAX_PENDING_GRAPHICS);
164164
}
165165

166166
// display any pending images changed
167-
void AnsiWidget::flush(bool force, bool vscroll, int maxPending) {
167+
void AnsiWidget::flush(bool force, bool vscroll, int maxPending) const {
168168
if (_front != nullptr && _autoflush) {
169169
bool update = false;
170170
if (force) {
@@ -178,7 +178,7 @@ void AnsiWidget::flush(bool force, bool vscroll, int maxPending) {
178178
}
179179
}
180180

181-
int AnsiWidget::getScreenId(bool back) {
181+
int AnsiWidget::getScreenId(bool back) const {
182182
int result = 0;
183183
for (int i = 0; i < MAX_SCREENS; i++) {
184184
if (_screens[i] == (back ? _back : _front)) {
@@ -347,18 +347,18 @@ void AnsiWidget::setFontSize(int fontSize) {
347347
}
348348

349349
// sets the pixel to the given color at the given xy location
350-
void AnsiWidget::setPixel(int x, int y, int c) {
350+
void AnsiWidget::setPixel(int x, int y, int c) const {
351351
_back->setPixel(x, y, c);
352352
flush(false, false, MAX_PENDING_GRAPHICS);
353353
}
354354

355-
void AnsiWidget::setStatus(const char *label) {
355+
void AnsiWidget::setStatus(const char *label) const {
356356
_back->_label = label;
357357
_back->setDirty();
358358
}
359359

360360
// sets the current text drawing color
361-
void AnsiWidget::setTextColor(long fg, long bg) {
361+
void AnsiWidget::setTextColor(long fg, long bg) const {
362362
_back->setTextColor(fg, bg);
363363
}
364364

@@ -484,7 +484,7 @@ bool AnsiWidget::pointerMoveEvent(MAEvent &event) {
484484
}
485485

486486
// handler for pointer release events
487-
void AnsiWidget::pointerReleaseEvent(MAEvent &event) {
487+
void AnsiWidget::pointerReleaseEvent(const MAEvent &event) {
488488
if (_activeButton != nullptr && _front == _screens[MENU_SCREEN]) {
489489
_activeButton->clicked(event.point.x, event.point.y, false);
490490
} else if (_activeButton != nullptr && _activeButton->_pressed) {
@@ -531,7 +531,7 @@ void AnsiWidget::pointerReleaseEvent(MAEvent &event) {
531531

532532
// handles the characters following the \e[ sequence. Returns whether a further call
533533
// is required to complete the process.
534-
bool AnsiWidget::doEscape(const char *&p, int textHeight) {
534+
bool AnsiWidget::doEscape(const char *&p, int textHeight) const {
535535
int escValue = 0;
536536

537537
while (isdigit(*p)) {
@@ -594,7 +594,7 @@ void AnsiWidget::doSwipe(int start, bool moveDown, int distance, int maxScroll)
594594
}
595595

596596
// draws the focus screen's active button
597-
void AnsiWidget::drawActiveButton() {
597+
void AnsiWidget::drawActiveButton() const {
598598
#if defined(_SDL) || defined(_FLTK)
599599
if (_focus != nullptr && !_activeButton->hasHover()) {
600600
MAHandle currentHandle = maSetDrawTarget(HANDLE_SCREEN);
@@ -624,7 +624,7 @@ void AnsiWidget::drawActiveButton() {
624624
#endif
625625
}
626626

627-
bool AnsiWidget::drawHoverLink(MAEvent &event) {
627+
bool AnsiWidget::drawHoverLink(const MAEvent &event) {
628628
#if defined(_SDL) || defined(_FLTK)
629629
if (_front != _screens[MENU_SCREEN]) {
630630
int dx = _front->_x;
@@ -704,7 +704,7 @@ void AnsiWidget::handleEscape(const char *&p, int lineHeight) {
704704
}
705705

706706
// returns whether the event is over the given screen
707-
bool AnsiWidget::setActiveButton(MAEvent &event, Screen *screen) {
707+
bool AnsiWidget::setActiveButton(const MAEvent &event, Screen *screen) {
708708
bool result = false;
709709
if (_front != _screens[MENU_SCREEN] &&
710710
screen->overlaps(event.point.x, event.point.y)) {

src/ui/ansiwidget.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,80 +34,80 @@ struct AnsiWidget {
3434
~AnsiWidget();
3535

3636
void addImage(ImageDisplay &image);
37-
void addInput(FormInput *input) { _back->_inputs.add(input); }
37+
void addInput(FormInput *input) const { _back->_inputs.add(input); }
3838
void clearScreen();
3939
bool construct();
4040
void drawArc(int xc, int yc, double r, double start, double end, double aspect);
4141
void drawEllipse(int xc, int yc, int rx, int ry, int fill);
4242
void drawImage(ImageDisplay &image);
43-
void drawOverlay(bool vscroll) { _back->drawOverlay(vscroll); }
43+
void drawOverlay(bool vscroll) const { _back->drawOverlay(vscroll); }
4444
void drawLine(int x1, int y1, int x2, int y2);
4545
void drawRect(int x1, int y1, int x2, int y2);
46-
void drawRectFilled(int x1, int y1, int x2, int y2);
47-
void flush(bool force, bool vscroll=false, int maxPending = MAX_PENDING);
48-
void flushNow() { if (_front) _front->drawBase(false); }
49-
int getBackgroundColor() { return _back->_bg; }
50-
int getCharHeight() { return _back->_charHeight; }
51-
int getCharWidth() { return _back->_charWidth; }
52-
int getColor() { return _back->_fg; }
46+
void drawRectFilled(int x1, int y1, int x2, int y2) const;
47+
void flush(bool force, bool vscroll=false, int maxPending = MAX_PENDING) const;
48+
void flushNow() const { if (_front) _front->drawBase(false); }
49+
int getBackgroundColor() const { return _back->_bg; }
50+
int getCharHeight() const { return _back->_charHeight; }
51+
int getCharWidth() const { return _back->_charWidth; }
52+
int getColor() const { return _back->_fg; }
5353
int getFontSize() const { return _fontSize; }
54-
FormInput *getNextField(FormInput *field) { return _back->getNextField(field); }
55-
int getPixel(int x, int y) { return _back->getPixel(x, y); }
56-
int getStatusHeight() { return _back->_height - _back->_statusOffset; }
57-
int getScreenId(bool back);
58-
int getScreenWidth() { return _back->_width; }
59-
void getScroll(int &x, int &y) { _back->getScroll(x, y); }
54+
FormInput *getNextField(FormInput *field) const { return _back->getNextField(field); }
55+
int getPixel(int x, int y) const { return _back->getPixel(x, y); }
56+
int getStatusHeight() const { return _back->_height - _back->_statusOffset; }
57+
int getScreenId(bool back) const;
58+
int getScreenWidth() const { return _back->_width; }
59+
void getScroll(int &x, int &y) const { _back->getScroll(x, y); }
6060
int getHeight() const { return _height; }
6161
int getWidth() const { return _width; }
62-
int getX() { return _back->_curX; }
63-
int getY() { return _back->_curY; }
62+
int getX() const { return _back->_curX; }
63+
int getY() const { return _back->_curY; }
6464
int getMenuIndex() const { return _back->getIndex(_activeButton); }
6565
bool hasActiveButton() const { return _activeButton != nullptr; }
6666
bool hasHover() const { return _hoverInput != nullptr; }
6767
bool hasMenu() const { return _back == _screens[MENU_SCREEN]; }
6868
void handleMenu(bool up);
6969
void insetMenuScreen(int x, int y, int w, int h);
7070
void insetTextScreen(int x, int y, int w, int h);
71-
bool overLabel(int x, int y) { return _back->overLabel(x, y); };
72-
bool overMenu(int x, int y) { return _back->overMenu(x, y); };
71+
bool overLabel(int x, int y) const { return _back->overLabel(x, y); };
72+
bool overMenu(int x, int y) const { return _back->overMenu(x, y); };
7373
bool pointerTouchEvent(MAEvent &event);
7474
bool pointerMoveEvent(MAEvent &event);
75-
void pointerReleaseEvent(MAEvent &event);
75+
void pointerReleaseEvent(const MAEvent &event);
7676
void print(const char *str);
7777
void redraw();
7878
void removeHover();
79-
void removeImage(int imageId) { _back->removeImage(imageId); }
80-
bool removeInput(FormInput *input) { return _back->removeInput(input); }
79+
void removeImage(int imageId) const { _back->removeImage(imageId); }
80+
bool removeInput(FormInput *input) const { return _back->removeInput(input); }
8181
void removeInputs();
82-
void resetScroll() { _back->resetScroll(); }
82+
void resetScroll() const { _back->resetScroll(); }
8383
void reset();
84-
void resetFont() { _back->reset(_fontSize); _back->updateFont(); }
84+
void resetFont() const { _back->reset(_fontSize); _back->updateFont(); }
8585
void resize(int width, int height);
8686
bool scroll(bool up, bool page);
8787
void selectBackScreen(int screenId);
8888
void selectFrontScreen(int screenId);
8989
int selectScreen(int screenId, bool forceFlush=true);
9090
void setColor(long color);
91-
void setDirty() { _back->setDirty(); }
91+
void setDirty() const { _back->setDirty(); }
9292
void setAutoflush(bool autoflush) { _autoflush = autoflush; }
9393
void setFont(int size, bool bold, bool italic);
9494
void setFontSize(int fontSize);
95-
void setPixel(int x, int y, int c);
96-
void setScroll(int x, int y) { _back->setScroll(x, y); }
97-
void setStatus(const char *label);
98-
void setTextColor(long fg, long bg);
95+
void setPixel(int x, int y, int c) const;
96+
void setScroll(int x, int y) const { _back->setScroll(x, y); }
97+
void setStatus(const char *label) const;
98+
void setTextColor(long fg, long bg) const;
9999
void setXY(int x, int y);
100-
int textHeight() { return _back->_charHeight; }
101-
void updateInputs(var_p_t form, bool setv) { _back->updateInputs(form, setv); }
100+
int textHeight() const { return _back->_charHeight; }
101+
void updateInputs(var_p_t form, bool setv) const { _back->updateInputs(form, setv); }
102102

103103
private:
104104
Screen *createScreen(int screenId);
105-
bool doEscape(const char *&p, int textHeight);
105+
bool doEscape(const char *&p, int textHeight) const;
106106
void doSwipe(int start, bool moveDown, int distance, int maxScroll);
107-
void drawActiveButton();
108-
bool drawHoverLink(MAEvent &event);
107+
void drawActiveButton() const;
108+
bool drawHoverLink(const MAEvent &event);
109109
void handleEscape(const char *&p, int textHeight);
110-
bool setActiveButton(MAEvent &event, Screen *screen);
110+
bool setActiveButton(const MAEvent &event, Screen *screen);
111111

112112
Screen *_screens[MAX_SCREENS]{};
113113
Screen *_back; // screen being painted/written

0 commit comments

Comments
 (0)