Skip to content

Commit f04354f

Browse files
committed
ANDROID: fix v4.4 startup crash
1 parent a12e704 commit f04354f

File tree

10 files changed

+60
-19
lines changed

10 files changed

+60
-19
lines changed

ide/android/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="net.sourceforge.smallbasic"
44
android:installLocation="preferExternal"
5-
android:versionCode="6"
6-
android:versionName="0.11.6">
5+
android:versionCode="8"
6+
android:versionName="0.11.7">
77
<!-- This is the platform API where NativeActivity was introduced. -->
88
<uses-sdk android:minSdkVersion="9" />
99

ide/android/assets/main.bas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sub about()
3030
print "(_ ._ _ _.|||_) /\ (_ |/ "
3131
print "__)| | |(_||||_)/--\__)|\_"
3232
print
33-
print "Version 0.11.6"
33+
print "Version 0.11.7"
3434
print
3535
print "Copyright (c) 2002-2014 Chris Warren-Smith"
3636
print "Copyright (c) 2000-2006 Nic Christopoulos" + chr(10)
@@ -56,7 +56,7 @@ sub setup()
5656
print boldOn + "Setup web service port number."
5757
print boldOff
5858
print "Enter a port number to allow web browser or desktop IDE access. ";
59-
print "Enter -1 to diable this feature, or press <enter> to leave ";
59+
print "Enter -1 to disable this feature, or press <enter> to leave ";
6060
print "this screen without making any changes."
6161
print "The current setting is: " + env("serverSocket")
6262
print

src/platform/android/jni/runtime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_r
136136

137137
extern "C" JNIEXPORT void JNICALL Java_net_sourceforge_smallbasic_MainActivity_onResize
138138
(JNIEnv *env, jclass jclazz, jint width, jint height) {
139-
runtime->onResize(width, height);
139+
if (runtime != NULL && runtime->isActive()) {
140+
runtime->onResize(width, height);
141+
}
140142
}
141143

142144
void onContentRectChanged(ANativeActivity *activity, const ARect *rect) {

src/platform/common/system.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ System::System() :
4949
_systemMenu(false),
5050
_systemScreen(false),
5151
_mainBas(false),
52+
_buttonPressed(false),
5253
_programSrc(NULL) {
5354
g_system = this;
5455
}
@@ -204,14 +205,15 @@ void System::handleEvent(MAEvent event) {
204205
_touchX = _touchCurX = event.point.x;
205206
_touchY = _touchCurY = event.point.y;
206207
dev_pushkey(SB_KEY_MK_PUSH);
207-
_output->pointerTouchEvent(event);
208+
_buttonPressed = _output->pointerTouchEvent(event);
208209
break;
209210
case EVENT_TYPE_POINTER_DRAGGED:
210211
_touchCurX = event.point.x;
211212
_touchCurY = event.point.y;
212213
_output->pointerMoveEvent(event);
213214
break;
214215
case EVENT_TYPE_POINTER_RELEASED:
216+
_buttonPressed = false;
215217
_touchX = _touchY = _touchCurX = _touchCurY = -1;
216218
_output->pointerReleaseEvent(event);
217219
break;

src/platform/common/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct System : public IButtonListener {
7979
bool _systemMenu;
8080
bool _systemScreen;
8181
bool _mainBas;
82+
bool _buttonPressed;
8283
char *_programSrc;
8384
};
8485

src/platform/common/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef signed long S32;
2222
#define MIN(a,b) ((a>b) ? (b) : (a))
2323
#endif
2424

25-
#if defined(_FLTK)
25+
#if defined(_FLTK) || defined(_SDL)
2626
#define DEFAULT_FOREGROUND 0
2727
#define DEFAULT_BACKGROUND 0xecedef
2828
#define HANDLE_SCREEN_BUFFER HANDLE_SCREEN + 1

src/platform/sdl/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ EXTRA_DIST = \
1515
bin_PROGRAMS = sbasicg
1616

1717
sbasicg_SOURCES = \
18-
../common/graphics.cpp \
18+
../common/graphics.cpp \
1919
../common/ansiwidget.cpp \
2020
../common/screen.cpp \
2121
../common/system.cpp \
2222
../common/form_ui.cpp \
2323
../common/StringLib.cpp \
2424
main.cpp \
2525
display.cpp \
26-
runtime.cpp
26+
runtime.cpp \
27+
settings.cpp
2728

2829
sbasicg_LDADD = -L$(top_srcdir)/src/common -lsb_common @PACKAGE_LIBS@
2930

src/platform/sdl/main.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "platform/common/utils.h"
1515
#include "platform/common/StringLib.h"
1616
#include "platform/sdl/runtime.h"
17+
#include "platform/sdl/settings.h"
1718
#include "common/smbas.h"
1819

1920
using namespace strlib;
@@ -38,6 +39,8 @@ static struct option OPTIONS[] = {
3839
{0, 0, 0, 0}
3940
};
4041

42+
const char *CONFIG_NAME = "SmallBASIC";
43+
4144
void appLog(const char *format, ...) {
4245
char buf[4096], *p = buf;
4346
va_list args;
@@ -192,27 +195,31 @@ int main(int argc, char* argv[]) {
192195
}
193196
}
194197

198+
int fontScale;
199+
SDL_Rect rect;
200+
201+
restoreSettings(CONFIG_NAME, rect, fontScale);
195202
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
196-
SDL_Window *window = SDL_CreateWindow("SmallBASIC",
197-
SDL_WINDOWPOS_UNDEFINED,
198-
SDL_WINDOWPOS_UNDEFINED,
199-
640, 480,
203+
SDL_Window *window = SDL_CreateWindow("SmallBASIC",
204+
rect.x, rect.y, rect.w, rect.h,
200205
SDL_WINDOW_SHOWN |
206+
SDL_WINDOW_RESIZABLE |
201207
SDL_WINDOW_INPUT_FOCUS |
202208
SDL_WINDOW_MOUSE_FOCUS);
203209
if (window != NULL) {
204210
String font, fontBold;
205211
if (getFontFiles(fontFamily, font, fontBold)) {
206212
Runtime *runtime = new Runtime(window);
207213
runtime->construct(font.c_str(), fontBold.c_str());
208-
runtime->runShell(runFile);
214+
fontScale = runtime->runShell(runFile, fontScale);
209215
delete runtime;
210216
} else {
211-
trace("Failed to locate display font\n");
217+
fprintf(stderr, "Failed to locate display font\n");
212218
}
219+
saveSettings(CONFIG_NAME, window, fontScale);
213220
SDL_DestroyWindow(window);
214221
} else {
215-
trace("Could not create window: %s\n", SDL_GetError());
222+
fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
216223
}
217224

218225
SDL_Quit();

src/platform/sdl/runtime.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
#include "platform/sdl/main_bas.h"
2323

2424
#define WAIT_INTERVAL 10
25+
#define DEFAULT_FONT_SIZE 16
2526
#define MAIN_BAS "__main_bas__"
2627

2728
Runtime *runtime;
2829

2930
Runtime::Runtime(SDL_Window *window) :
3031
System(),
31-
_window(window) {
32+
_window(window),
33+
_cursorHand(NULL),
34+
_cursorArrow(NULL) {
3235
runtime = this;
3336
}
3437

@@ -41,12 +44,21 @@ Runtime::~Runtime() {
4144
_output = NULL;
4245
_eventQueue = NULL;
4346
_graphics = NULL;
47+
48+
SDL_FreeCursor(_cursorHand);
49+
SDL_FreeCursor(_cursorArrow);
50+
_cursorHand = NULL;
51+
_cursorArrow = NULL;
4452
}
4553

4654
void Runtime::construct(const char *font, const char *boldFont) {
4755
logEntered();
4856
_state = kClosingState;
4957
_graphics = new Graphics(_window);
58+
59+
_cursorHand = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
60+
_cursorArrow = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
61+
5062
if (_graphics && _graphics->construct(font, boldFont)) {
5163
int w, h;
5264
SDL_GetWindowSize(_window, &w, &h);
@@ -68,7 +80,7 @@ MAEvent *Runtime::popEvent() {
6880
return _eventQueue->pop();
6981
}
7082

71-
void Runtime::runShell(const char *startupBas) {
83+
int Runtime::runShell(const char *startupBas, int fontScale) {
7284
logEntered();
7385

7486
os_graphics = 1;
@@ -80,6 +92,15 @@ void Runtime::runShell(const char *startupBas) {
8092
opt_pref_bpp = 0;
8193
opt_nosave = true;
8294

95+
_output->setTextColor(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
96+
_output->setFontSize(DEFAULT_FONT_SIZE);
97+
_initialFontSize = _output->getFontSize();
98+
if (fontScale != 100) {
99+
_fontScale = fontScale;
100+
int fontSize = (_initialFontSize * _fontScale / 100);
101+
_output->setFontSize(fontSize);
102+
}
103+
83104
if (startupBas != NULL) {
84105
runOnce(startupBas);
85106
} else {
@@ -88,6 +109,7 @@ void Runtime::runShell(const char *startupBas) {
88109

89110
_state = kDoneState;
90111
logLeaving();
112+
return _fontScale;
91113
}
92114

93115
char *Runtime::loadResource(const char *fileName) {
@@ -166,6 +188,7 @@ void Runtime::pollEvents(bool blocking) {
166188
maEvent = getMotionEvent(EVENT_TYPE_POINTER_DRAGGED, &ev);
167189
break;
168190
case SDL_MOUSEBUTTONUP:
191+
SDL_SetCursor(_cursorArrow);
169192
maEvent = getMotionEvent(EVENT_TYPE_POINTER_RELEASED, &ev);
170193
break;
171194
case SDL_WINDOWEVENT_SIZE_CHANGED:
@@ -217,6 +240,9 @@ MAEvent Runtime::processEvents(int waitFlag) {
217240
break;
218241
default:
219242
handleEvent(event);
243+
if (event.type == EVENT_TYPE_POINTER_PRESSED && _buttonPressed) {
244+
SDL_SetCursor(_cursorHand);
245+
}
220246
break;
221247
}
222248
return event;

src/platform/sdl/runtime.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Runtime : public System {
3131
MAEvent *popEvent();
3232
void pushEvent(MAEvent *event);
3333
void setExit(bool quit);
34-
void runShell(const char *startupBas);
34+
int runShell(const char *startupBas, int fontScale);
3535
char *loadResource(const char *fileName);
3636
void showAlert(const char *title, const char *message);
3737
void optionsBox(StringList *items);
@@ -42,6 +42,8 @@ struct Runtime : public System {
4242
Graphics *_graphics;
4343
Stack<MAEvent *> *_eventQueue;
4444
SDL_Window *_window;
45+
SDL_Cursor *_cursorHand;
46+
SDL_Cursor *_cursorArrow;
4547
};
4648

4749
#endif

0 commit comments

Comments
 (0)