Skip to content

Commit 5137115

Browse files
committed
UI: experimental keypad to replace android keypad
1 parent 3695a0c commit 5137115

File tree

15 files changed

+85
-165
lines changed

15 files changed

+85
-165
lines changed

src/lib/maapi.h

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,29 @@
1616
02111-1307, USA.
1717
*/
1818

19-
#if !defined(MAAPI_H)
20-
#define MAAPI_H
21-
22-
#include <stdint.h>
19+
#pragma once
20+
#include <cstdint>
2321

2422
#define EXTENT_Y(e) ((short)(e))
2523
#define EXTENT_X(e) ((short)((e) >> 16))
2624
#define TRANS_NONE 0
2725
#define FONT_TYPE_SERIF 0
2826
#define FONT_TYPE_SANS_SERIF 1
2927
#define FONT_TYPE_MONOSPACE 2
30-
// same values as tizen enum FontStyle
3128
#define FONT_STYLE_NORMAL 0x0001
3229
#define FONT_STYLE_BOLD 0x0002
3330
#define FONT_STYLE_ITALIC 0x0004
34-
#define HANDLE_LOCAL 0
35-
#define RES_OUT_OF_MEMORY -1
36-
#define RES_BAD_INPUT -2
3731
#define RES_OK 1
3832
#define HANDLE_SCREEN 0
3933
#define RES_FONT_OK 1
40-
#define MAK_MENU 293
4134
#define EVENT_TYPE_POINTER_PRESSED 8
4235
#define EVENT_TYPE_POINTER_RELEASED 9
4336
#define EVENT_TYPE_POINTER_DRAGGED 10
4437
#define EVENT_TYPE_KEY_PRESSED 11
4538
#define EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED 41
4639
#define EVENT_TYPE_SCREEN_CHANGED 21
4740

48-
#ifndef _WCHAR_DEFINED
49-
#define _WCHAR_DEFINED
50-
typedef wchar_t wchar;
51-
#endif //_WCHAR_DEFINED
52-
53-
#ifndef _SYSV_TYPES_DEFINED
54-
#define _SYSV_TYPES_DEFINED
55-
typedef unsigned short ushort;
56-
typedef unsigned int uint;
57-
#endif //_SYSV_TYPES_DEFINED
58-
5941
typedef int MAExtent;
60-
typedef void* MAAddress;
6142
typedef intptr_t MAHandle;
6243

6344
typedef struct MARect {
@@ -170,7 +151,7 @@ void maDrawText(int left, int top, const char *str, int length);
170151
/**
171152
* Copies the back buffer to the physical screen.
172153
*/
173-
void maUpdateScreen(void);
154+
void maUpdateScreen();
174155

175156
/**
176157
* Returns the size in pixels of Latin-1 text as it would appear on-screen.
@@ -181,7 +162,7 @@ MAExtent maGetTextSize(const char *str);
181162
* Returns the screen size.
182163
* Returns the screen size.
183164
*/
184-
MAExtent maGetScrSize(void);
165+
MAExtent maGetScrSize();
185166

186167
/**
187168
* Returns a handle to one of the default fonts of the device, in the style and size you specify.
@@ -231,14 +212,14 @@ void maDrawImageRegion(MAHandle image, const MARect *srcRect, const MAPoint2d *d
231212
* \param width Width, in pixels, of the new image. Must be \> 0.
232213
* \param height Height, in pixels, of the new image. Must be \> 0.
233214
* \see maSetDrawTarget()
234-
* \returns #RES_OK if succeded and #RES_OUT_OF_MEMORY if failed.
215+
* \returns #RES_OK if succeeded and #RES_OUT_OF_MEMORY if failed.
235216
*/
236217
int maCreateDrawableImage(MAHandle placeholder, int width, int height);
237218

238219
/**
239220
* Creates a new placeholder and returns the handle to it.
240221
*/
241-
MAHandle maCreatePlaceholder(void);
222+
MAHandle maCreatePlaceholder();
242223

243224
/**
244225
* Releases a handle returned by maCreatePlaceholder().
@@ -264,13 +245,13 @@ void maDestroyPlaceholder(MAHandle handle);
264245
* The destination rectangle is defined as { 0,0, \a srcRect.width, \a srcRect.height }.
265246
* Parts of the destination array that are outside the destination rectangle are not modified.
266247
* If \a srcRect is outside the bounds of the source image,
267-
* or if \a srcRect.width is greater than \a scanlength, a MoSync Panic is thrown.
248+
* or if \a srcRect.width is greater than \a scanLength, a MoSync Panic is thrown.
268249
* \param image The handle to the source image.
269250
* \param dst The address of the destination array.
270-
* \param scanlength The width of the image, in pixels, represented by the destination array.
251+
* \param scanLength The width of the image, in pixels, represented by the destination array.
271252
* \param srcRect The portion of the source image to be copied.
272253
*/
273-
void maGetImageData(MAHandle image, void *dst, const MARect *srcRect, int scanlength);
254+
void maGetImageData(MAHandle image, void *dst, const MARect *srcRect, int scanLength);
274255

275256
/**
276257
* Sets the current draw target.
@@ -287,17 +268,17 @@ MAHandle maSetDrawTarget(MAHandle image);
287268
* Returns the number of milliseconds that has passed since some unknown point in time.
288269
* Accuracy is platform-specific, but should be better than 20 ms.
289270
*/
290-
int maGetMilliSecondCount(void);
271+
int maGetMilliSecondCount();
291272

292273
/**
293274
* Shows the virtual keyboard.
294275
*/
295-
void maShowVirtualKeyboard(void);
276+
void maShowVirtualKeyboard();
296277

297278
/**
298279
* Hides the virtual keyboard.
299280
*/
300-
void maHideVirtualKeyboard(void);
281+
void maHideVirtualKeyboard();
301282

302283
/**
303284
* There is a FIFO buffer that contains up to #EVENT_BUFFER_SIZE events.
@@ -339,4 +320,3 @@ void maPushEvent(MAEvent *event);
339320
*/
340321
void maWait(int timeout);
341322

342-
#endif

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/EditorBar.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ public void run() {
326326
return result;
327327
}
328328

329+
public int getDensity() {
330+
DisplayMetrics metrics = new DisplayMetrics();
331+
getWindowManager().getDefaultDisplay().getMetrics(metrics);
332+
return metrics.densityDpi;
333+
}
334+
329335
public String getIpAddress() {
330336
String result = "";
331337
try {

src/platform/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:8.11.0'
8+
classpath 'com.android.tools.build:gradle:8.11.1'
99
}
1010
}
1111

src/platform/android/jni/editor.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include "config.h"
1010

11-
#include "ui/textedit.h"
1211
#include "platform/android/jni/runtime.h"
1312
#include "common/device.h"
13+
#include "ui/textedit.h"
1414
#include "ui/keypad.h"
1515

1616
// whether to hide the status message
@@ -126,11 +126,12 @@ void showHelp(TextEditHelpWidget *helpWidget) {
126126
void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
127127
logEntered();
128128

129+
showKeypad(false);
129130
int w = _output->getWidth();
130131
int h = _output->getHeight();
131132
int charWidth = _output->getCharWidth();
132133
int charHeight = _output->getCharHeight();
133-
int prevScreenId = _output->selectScreen(SOURCE_SCREEN);
134+
int prevScreenId = _output->selectScreen(FORM_SCREEN);
134135
TextEditInput *editWidget;
135136
if (_editor != nullptr) {
136137
editWidget = _editor;
@@ -155,7 +156,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
155156
if (_keypad != nullptr) {
156157
_output->addInput(_keypad);
157158
} else {
158-
_keypad = new KeypadInput(false, false, charWidth, charHeight);
159+
_keypad = new KeypadInput(false, false, charWidth, charHeight, _density);
159160
_output->addInput(_keypad);
160161
}
161162

@@ -183,7 +184,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
183184
switch (event.type) {
184185
case EVENT_TYPE_POINTER_RELEASED:
185186
case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
186-
if (statusMessage.update(editWidget, _output)) {
187+
if (widget == editWidget && statusMessage.update(editWidget, _output)) {
187188
_output->redraw();
188189
}
189190
break;
@@ -248,12 +249,11 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
248249
_output->redraw();
249250
_state = kActiveState;
250251
waitForBack();
251-
_output->selectScreen(SOURCE_SCREEN);
252+
_output->selectScreen(FORM_SCREEN);
252253
_state = kEditState;
253254
break;
254255
case SB_KEY_CTRL('t'):
255256
statusMessage.toggleEnabled(editWidget);
256-
redraw = true;
257257
break;
258258
default:
259259
redraw = widget->edit(event.key, _output->getScreenWidth(), charWidth);
@@ -271,6 +271,7 @@ void Runtime::editSource(strlib::String loadPath, bool restoreOnExit) {
271271
helpWidget->hide();
272272
editWidget->setFocus(true);
273273
statusMessage.setFind(false, editWidget);
274+
statusMessage.update(editWidget, _output);
274275
_state = kEditState;
275276
_output->redraw();
276277
}

src/platform/android/jni/runtime.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ Runtime::Runtime(android_app *app) :
234234
_looper = ALooper_forThread();
235235
_sensorManager = ASensorManager_getInstance();
236236
memset(&_sensors, 0, sizeof(_sensors));
237+
_density = getInteger("getDensity");
237238
}
238239

239240
Runtime::~Runtime() {
@@ -855,8 +856,12 @@ MAEvent Runtime::processEvents(int waitFlag) {
855856
switch (waitFlag) {
856857
case 1:
857858
// wait for an event
858-
_output->flush(true);
859-
if (!hasEvent()) {
859+
if (!hasEvent() || _eventQueue->peek()->type == EVENT_TYPE_POINTER_DRAGGED) {
860+
// drain any motion events so we only return the latest
861+
while (hasEvent()) {
862+
delete popEvent();
863+
}
864+
_output->flush(true);
860865
pollEvents(true);
861866
}
862867
break;

src/platform/android/jni/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct Runtime : public System {
8686
private:
8787
void editSource(String loadPath, bool restoreOnExit) override;
8888

89+
int _density;
8990
bool _keypadActive;
9091
bool _hasFocus;
9192
Graphics *_graphics;

src/platform/sdl/editor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
202202
int h = _output->getHeight();
203203
int charWidth = _output->getCharWidth();
204204
int charHeight = _output->getCharHeight();
205-
int prevScreenId = _output->selectScreen(SOURCE_SCREEN);
205+
int prevScreenId = _output->selectScreen(FORM_SCREEN);
206206
TextEditInput *editWidget;
207207
if (_editor != nullptr) {
208208
editWidget = _editor;
@@ -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, true, charWidth, charHeight);
235+
_keypad = new KeypadInput(false, true, charWidth, charHeight, 0);
236236
_output->addInput(_keypad);
237237
}
238238

@@ -457,7 +457,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
457457
_output->redraw();
458458
_state = kActiveState;
459459
waitForBack();
460-
_output->selectScreen(SOURCE_SCREEN);
460+
_output->selectScreen(FORM_SCREEN);
461461
_state = kEditState;
462462
break;
463463
case SB_KEY_ALT('0'):

src/ui/ansiwidget.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Screen *AnsiWidget::createScreen(int screenId) {
109109
if (result == nullptr) {
110110
if (screenId == TEXT_SCREEN || screenId == MENU_SCREEN) {
111111
result = new TextScreen(_width, _height, _fontSize);
112-
} else if (screenId == SOURCE_SCREEN) {
112+
} else if (screenId == FORM_SCREEN) {
113113
result = new FormInputScreen(_width, _height, _fontSize);
114114
} else {
115115
result = new GraphicScreen(_width, _height, _fontSize);
@@ -494,6 +494,11 @@ void AnsiWidget::pointerReleaseEvent(const MAEvent &event) {
494494
} else if (_swipeExit) {
495495
_swipeExit = false;
496496
} else {
497+
if (_activeButton && (_activeButton->floatTop() || _activeButton->floatBottom())) {
498+
// release keypad/toolbar button
499+
_activeButton->clicked(event.point.x, event.point.y, false);
500+
drawActiveButton();
501+
}
497502
int maxScroll = (_front->_curY - _front->_height) + (2 * _fontSize);
498503
if (_yMove != -1 && maxScroll > 0) {
499504
_front->drawInto();

src/ui/ansiwidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#define SOURCE_SCREEN 3
2626
#define CONSOLE_SCREEN 4
2727
#define MENU_SCREEN 5
28-
#define MAX_SCREENS 6
28+
#define FORM_SCREEN 6
29+
#define MAX_SCREENS 7
2930

3031
using namespace strlib;
3132

0 commit comments

Comments
 (0)