Skip to content

Commit 7328da4

Browse files
committed
UI: experimental keypad to replace android keypad
- added const declarations
1 parent 85aa416 commit 7328da4

File tree

15 files changed

+152
-141
lines changed

15 files changed

+152
-141
lines changed

src/platform/emcc/runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void Runtime::showCursor(CursorType cursorType) {
383383
}
384384
}
385385

386-
void System::editSource(strlib::String loadPath, bool restoreOnExit) {
386+
void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
387387
logEntered();
388388

389389
strlib::String fileName;

src/platform/emcc/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Runtime : public System {
2121
void browseFile(const char *url);
2222
char *getClipboardText();
2323
int getFontSize() { return _output->getFontSize(); }
24+
void editSource(String loadPath, bool restoreOnExit) override;
2425
void enableCursor(bool enabled) {}
2526
int handle(int event);
2627
char *loadResource(const char *fileName);

src/platform/fltk/runtime.cxx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ void Runtime::showCursor(CursorType cursorType) {
269269
//
270270
// System platform methods
271271
//
272-
void System::editSource(strlib::String loadPath, bool restoreOnExit) {
273-
// empty
274-
}
275-
276272
bool System::getPen3() {
277273
Fl::check();
278274
bool result = Fl::event_state(FL_BUTTON1);

src/platform/fltk/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct Runtime : public System {
2020
void alert(const char *title, const char *message);
2121
int ask(const char *title, const char *prompt, bool cancel=true);
2222
void browseFile(const char *url);
23+
void editSource(String loadPath, bool restoreOnExit) override {}
2324
char *getClipboardText();
2425
int getFontSize() { return _output->getFontSize(); }
2526
void enableCursor(bool enabled);

src/platform/sdl/editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
232232
if (_keypad != nullptr) {
233233
_output->addInput(_keypad);
234234
} else {
235-
_keypad = new KeypadInput(false, false, charWidth, charHeight);
235+
_keypad = new KeypadInput(false, true, charWidth, charHeight);
236236
_output->addInput(_keypad);
237237
}
238238

@@ -329,7 +329,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
329329
helpWidget->hide();
330330
helpWidget->cancelMode();
331331
statusMessage.setDirty(editWidget);
332-
((Runtime *)this)->debugStop();
332+
Runtime::debugStop();
333333
break;
334334
case SB_KEY_CTRL('s'):
335335
saveFile(editWidget, loadPath);

src/platform/sdl/runtime.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
#include <SDL3/SDL_messagebox.h>
2929
#include <SDL3/SDL_mutex.h>
3030
#include <SDL3/SDL_thread.h>
31-
#include <SDL3/SDL_timer.h>
32-
#include <math.h>
33-
#include <wchar.h>
31+
#include <cmath>
3432

3533
#define WAIT_INTERVAL 5
3634
#define COND_WAIT_TIME 250
@@ -52,16 +50,16 @@ extern int g_debugPort;
5250

5351
int debugThread(void *data);
5452

55-
MAEvent *getMotionEvent(int type, SDL_Event *event) {
56-
MAEvent *result = new MAEvent();
53+
MAEvent *getMotionEvent(int type, const SDL_Event *event) {
54+
auto *result = new MAEvent();
5755
result->type = type;
5856
result->point.x = event->motion.x;
5957
result->point.y = event->motion.y;
6058
return result;
6159
}
6260

6361
MAEvent *getKeyPressedEvent(int keycode, int nativeKey) {
64-
MAEvent *result = new MAEvent();
62+
auto *result = new MAEvent();
6563
result->type = EVENT_TYPE_KEY_PRESSED;
6664
result->key = keycode;
6765
result->nativeKey = nativeKey;
@@ -76,7 +74,8 @@ Runtime::Runtime(SDL_Window *window) :
7674
_window(window),
7775
_cursorHand(nullptr),
7876
_cursorArrow(nullptr),
79-
_cursorIBeam(nullptr) {
77+
_cursorIBeam(nullptr),
78+
_keypad(nullptr) {
8079
runtime = this;
8180
}
8281

@@ -119,8 +118,7 @@ int Runtime::ask(const char *title, const char *prompt, bool cancel) {
119118
buttons[2].buttonID = 2;
120119
}
121120

122-
SDL_MessageBoxData data;
123-
memset(&data, 0, sizeof(SDL_MessageBoxData));
121+
SDL_MessageBoxData data = {};
124122
data.window = _window;
125123
data.title = title;
126124
data.message = prompt;
@@ -194,9 +192,9 @@ void Runtime::debugStart(TextEditInput *editWidget, const char *file) {
194192
if (g_debugee != -1) {
195193
net_print(g_debugee, "l\n");
196194
char buf[OS_PATHNAME_SIZE + 1];
197-
int size = net_input(g_debugee, buf, sizeof(buf), "\n");
195+
const int size = net_input(g_debugee, buf, sizeof(buf), "\n");
198196
if (size > 0) {
199-
int *marker = editWidget->getMarkers();
197+
int *marker = TextEditInput::getMarkers();
200198
for (int i = 0; i < MAX_MARKERS; i++) {
201199
if (marker[i] != -1) {
202200
net_printf(g_debugee, "b %d\n", marker[i]);
@@ -258,7 +256,7 @@ void Runtime::enableCursor(bool enabled) {
258256
}
259257
}
260258

261-
void Runtime::exportRun(const char *file) {
259+
void Runtime::exportRun(const char *file) const {
262260
launchExec(file);
263261
SDL_RaiseWindow(_window);
264262
}
@@ -347,7 +345,7 @@ char *Runtime::loadResource(const char *fileName) {
347345
return buffer;
348346
}
349347

350-
void Runtime::handleKeyEvent(MAEvent &event) {
348+
void Runtime::handleKeyEvent(MAEvent &event) const {
351349
// handle keypad keys
352350
if (event.key != -1) {
353351
if (event.key == SDLK_NUMLOCKCLEAR) {
@@ -415,7 +413,7 @@ void Runtime::pause(int timeout) {
415413
}
416414
} else {
417415
int slept = 0;
418-
while (1) {
416+
while (true) {
419417
pollEvents(false);
420418
if (isBreak()) {
421419
break;
@@ -632,7 +630,7 @@ void Runtime::setWindowTitle(const char *title) {
632630
} else {
633631
slash++;
634632
}
635-
int len = strlen(slash) + 16;
633+
const int len = strlen(slash) + 16;
636634
char *buffer = new char[len];
637635
if (buffer) {
638636
sprintf(buffer, "%s - SmallBASIC", slash);
@@ -669,7 +667,7 @@ void Runtime::onResize(int width, int height) {
669667
}
670668
}
671669

672-
SDL_Rect Runtime::getWindowRect() {
670+
SDL_Rect Runtime::getWindowRect() const {
673671
SDL_Rect result;
674672
if (_fullscreen) {
675673
result = _windowRect;
@@ -685,7 +683,7 @@ SDL_Rect Runtime::getWindowRect() {
685683
return result;
686684
}
687685

688-
void Runtime::setWindowRect(SDL_Rect &rc) {
686+
void Runtime::setWindowRect(SDL_Rect &rc) const {
689687
SDL_GetWindowPosition(_window, &rc.x, &rc.y);
690688
SDL_GetWindowSize(_window, &rc.w, &rc.h);
691689
}
@@ -847,15 +845,15 @@ void restart() {
847845
g_debugTrace = false;
848846
g_breakPoints.removeAll();
849847

850-
MAEvent *event = new MAEvent();
848+
auto *event = new MAEvent();
851849
event->type = EVENT_TYPE_RESTART;
852850
runtime->pushEvent(event);
853851
if (runtime->isThreadActive()) {
854852
// break out of waitForBack()
855-
SDL_Event event;
856-
event.type = SDL_EVENT_KEY_DOWN;
857-
event.key.key = SDLK_BACKSPACE;
858-
SDL_PushEvent(&event);
853+
SDL_Event sdlEvent;
854+
sdlEvent.type = SDL_EVENT_KEY_DOWN;
855+
sdlEvent.key.key = SDLK_BACKSPACE;
856+
SDL_PushEvent(&sdlEvent);
859857
}
860858

861859
SDL_SignalCondition(g_cond);
@@ -958,7 +956,7 @@ extern "C" void dev_trace_line(int lineNo) {
958956
break;
959957
}
960958
}
961-
} else if (!g_breakPoints.size() && g_debugTrace) {
959+
} else if (g_breakPoints.empty() && g_debugTrace) {
962960
runtime->systemPrint("Trace line: %d", lineNo);
963961
}
964962
SDL_UnlockMutex(g_lock);

src/platform/sdl/runtime.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ struct Runtime final : System {
2929
int ask(const char *title, const char *prompt, bool cancel) override;
3030
void browseFile(const char *url) override;
3131
void construct(const char *font, const char *boldFont);
32-
bool debugActive();
32+
static bool debugActive();
3333
bool debugOpen(const char *file);
3434
void debugStart(TextEditInput *edit, const char *file);
3535
void debugStep(TextEditInput *edit, TextEditHelpWidget *help, bool cont);
36-
void debugStop();
36+
static void debugStop();
3737
void enableCursor(bool enabled) override;
38-
void exportRun(const char *path);
38+
void exportRun(const char *path) const;
3939
void redraw() const { _graphics->redraw(); }
4040
bool toggleFullscreen();
41-
void handleKeyEvent(MAEvent &event);
41+
void handleKeyEvent(MAEvent &event) const;
4242
bool hasEvent() const { return _eventQueue && !_eventQueue->empty(); }
4343
void pause(int timeout);
4444
void pollEvents(bool blocking);
@@ -53,13 +53,12 @@ struct Runtime final : System {
5353
void showCursor(CursorType cursorType) override;
5454
int runShell(const char *startupBas, bool once, int fontScale, int debugPort);
5555
char *loadResource(const char *fileName) override;
56-
void logStack(int line, bool subOrFunc);
5756
void onResize(int w, int h);
5857
void onRunCompleted() override;
5958
void setClipboardText(const char *text) override;
6059
char *getClipboardText() override;
61-
void setWindowRect(SDL_Rect &rect);
62-
SDL_Rect getWindowRect();
60+
void setWindowRect(SDL_Rect &rect) const;
61+
SDL_Rect getWindowRect() const;
6362

6463
private:
6564
void editSource(String loadPath, bool restoreOnExit) override;
@@ -73,7 +72,7 @@ struct Runtime final : System {
7372
SDL_Cursor *_cursorHand;
7473
SDL_Cursor *_cursorArrow;
7574
SDL_Cursor *_cursorIBeam;
76-
KeypadInput *_keypad{};
75+
KeypadInput *_keypad;
7776
};
7877

7978
#endif

src/ui/graphics.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Graphics::~Graphics() {
9696
_screen = nullptr;
9797
}
9898

99-
Font *Graphics::createFont(int style, int size) {
99+
Font *Graphics::createFont(int style, int size) const {
100100
Font *result;
101101
bool italic = (style & FONT_STYLE_ITALIC);
102102
if (style & FONT_STYLE_BOLD) {
@@ -107,7 +107,7 @@ Font *Graphics::createFont(int style, int size) {
107107
return result;
108108
}
109109

110-
void Graphics::deleteFont(Font *font) {
110+
void Graphics::deleteFont(const Font *font) {
111111
if (font == _font) {
112112
_font = nullptr;
113113
}
@@ -208,7 +208,7 @@ void Graphics::drawAaEllipse(int xc, int yc, int rx, int ry, bool fill) {
208208
}
209209
}
210210

211-
void Graphics::drawLine(int startX, int startY, int endX, int endY) {
211+
void Graphics::drawLine(int startX, int startY, int endX, int endY) const {
212212
if (_drawTarget) {
213213
if (startY == endY) {
214214
// horizontal
@@ -271,13 +271,13 @@ void Graphics::drawLine(int startX, int startY, int endX, int endY) {
271271
}
272272
}
273273

274-
void Graphics::drawPixel(int posX, int posY) {
274+
void Graphics::drawPixel(int posX, int posY) const {
275275
pixel_t *line = _drawTarget->getLine(posY);
276276
line[posX] = _drawColor;
277277
}
278278

279279
void Graphics::drawRGB(const MAPoint2d *dstPoint, const void *src,
280-
const MARect *srcRect, int opacity, int stride) {
280+
const MARect *srcRect, int opacity, int stride) const {
281281
auto *image = (uint8_t *)src;
282282
float op = opacity / 100.0f;
283283
int top = srcRect->top;
@@ -316,7 +316,7 @@ void Graphics::drawRGB(const MAPoint2d *dstPoint, const void *src,
316316
}
317317
}
318318

319-
void Graphics::drawChar(FT_Bitmap *bitmap, FT_Int x, FT_Int y) {
319+
void Graphics::drawChar(FT_Bitmap *bitmap, FT_Int x, FT_Int y) const {
320320
FT_Int xMax = x + bitmap->width;
321321
FT_Int yMax = y + bitmap->rows;
322322

@@ -351,7 +351,7 @@ void Graphics::drawChar(FT_Bitmap *bitmap, FT_Int x, FT_Int y) {
351351
}
352352
}
353353

354-
void Graphics::drawText(int left, int top, const char *str, int len) {
354+
void Graphics::drawText(int left, int top, const char *str, int len) const {
355355
if (_drawTarget && _font) {
356356
FT_Vector pen;
357357
pen.x = left;
@@ -367,7 +367,7 @@ void Graphics::drawText(int left, int top, const char *str, int len) {
367367
}
368368
}
369369

370-
void Graphics::getImageData(Canvas *canvas, uint8_t *image, const MARect *srcRect, int stride) {
370+
void Graphics::getImageData(Canvas *canvas, uint8_t *image, const MARect *srcRect, int stride) const {
371371
size_t scale = 1;
372372
int x_end = srcRect->left + srcRect->width;
373373
int y_end = srcRect->top + srcRect->height;
@@ -389,7 +389,7 @@ void Graphics::getImageData(Canvas *canvas, uint8_t *image, const MARect *srcRec
389389
}
390390
}
391391

392-
int Graphics::getPixel(Canvas *canvas, int posX, int posY) {
392+
int Graphics::getPixel(Canvas *canvas, int posX, int posY) const {
393393
int result = 0;
394394
if (canvas == HANDLE_SCREEN) {
395395
canvas = _screen;
@@ -411,7 +411,7 @@ int Graphics::getPixel(Canvas *canvas, int posX, int posY) {
411411
return result;
412412
}
413413

414-
MAExtent Graphics::getTextSize(const char *str, int len) {
414+
MAExtent Graphics::getTextSize(const char *str, int len) const {
415415
int width = 0;
416416
int height = 0;
417417
if (_font) {
@@ -424,7 +424,7 @@ MAExtent Graphics::getTextSize(const char *str, int len) {
424424
return (MAExtent)((width << 16) + height);
425425
}
426426

427-
void Graphics::setClip(int x, int y, int w, int h) {
427+
void Graphics::setClip(int x, int y, int w, int h) const {
428428
if (_drawTarget) {
429429
_drawTarget->setClip(x, y, w, h);
430430
}
@@ -444,7 +444,7 @@ MAHandle Graphics::setDrawTarget(MAHandle maHandle) {
444444
}
445445

446446
// see: http://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm
447-
void Graphics::aaLine(int x0, int y0, int x1, int y1) {
447+
void Graphics::aaLine(int x0, int y0, int x1, int y1) const {
448448
int steep = abs(y1 - y0) > abs(x1 - x0);
449449

450450
if (steep) {
@@ -507,7 +507,7 @@ void Graphics::aaLine(int x0, int y0, int x1, int y1) {
507507
}
508508
}
509509

510-
void Graphics::aaPlot(int posX, int posY, double c) {
510+
void Graphics::aaPlot(int posX, int posY, double c) const {
511511
if (_drawTarget
512512
&& posX >= _drawTarget->x()
513513
&& posY >= _drawTarget->y()
@@ -527,7 +527,7 @@ void Graphics::aaPlot(int posX, int posY, double c) {
527527
}
528528
}
529529

530-
void Graphics::aaPlotX8(int xc, int yc, int x, int y, double c, bool fill) {
530+
void Graphics::aaPlotX8(int xc, int yc, int x, int y, double c, bool fill) const {
531531
if (fill) {
532532
int x1 = xc + x;
533533
int x2 = xc - x;
@@ -548,7 +548,7 @@ void Graphics::aaPlotX8(int xc, int yc, int x, int y, double c, bool fill) {
548548

549549
}
550550

551-
void Graphics::aaPlotY8(int xc, int yc, int x, int y, double c, bool fill) {
551+
void Graphics::aaPlotY8(int xc, int yc, int x, int y, double c, bool fill) const {
552552
if (fill) {
553553
int x1 = xc + x;
554554
int x2 = xc - x;
@@ -575,7 +575,7 @@ void Graphics::plot4(int xc, int yc, int x, int y) {
575575
drawPixel(xc - x, yc - y);
576576
}
577577

578-
void Graphics::line2(int xc, int yc, int x, int y) {
578+
void Graphics::line2(int xc, int yc, int x, int y) const {
579579
drawLine(xc - x, yc + y, xc + x, yc + y);
580580
drawLine(xc - x, yc - y, xc + x, yc - y);
581581
}

0 commit comments

Comments
 (0)