Skip to content

Commit b48ea71

Browse files
committed
Merge pull request #36 from chrisws/0_11_20
0 12 3
2 parents 62cc14d + 344d433 commit b48ea71

File tree

10 files changed

+120
-42
lines changed

10 files changed

+120
-42
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
77
dnl Download the GNU Public License (GPL) from www.gnu.org
88
dnl
99

10-
AC_INIT([smallbasic], [0.12.2])
10+
AC_INIT([smallbasic], [0.12.3])
1111
AC_CONFIG_SRCDIR([configure.ac])
1212

1313
AC_CANONICAL_TARGET

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
smallbasic (0.12.3) unstable; urgency=low
2+
* Various - see web site
3+
4+
-- Chris Warren-Smith <cwarrensmith@gmail.com> Tue, 26 Jan 2016 09:45:25 +1000
5+
16
smallbasic (0.12.2) unstable; urgency=low
27
* Various - see web site
38

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="16"
6-
android:versionName="0.12.1">
5+
android:versionCode="17"
6+
android:versionName="0.12.3">
77
<!-- This is the platform API where NativeActivity was introduced. -->
88
<uses-sdk android:minSdkVersion="9"/>
99

ide/android/assets/main.bas

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sub do_about()
5555
print "(_ ._ _ _.|||_) /\ (_ |/ "
5656
print "__)| | |(_||||_)/--\__)|\_"
5757
print
58-
print "Version 0.12.2"
58+
print "Version 0.12.3"
5959
print
6060
print "Copyright (c) 2002-2015 Chris Warren-Smith"
6161
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)
@@ -155,6 +155,12 @@ sub serverInfo()
155155
fi
156156
end
157157

158+
func fileCmpFunc(l, r)
159+
local f1 = lower(l)
160+
local f2 = lower(r)
161+
fileCmpFunc = IFF(f1 == f2, 0, IFF(f1 > f2, 1, -1))
162+
end
163+
158164
sub listFiles(byref frm, path, byref basList, byref dirList)
159165
local fileList, ent, name, lastItem, bn, bn_back
160166

@@ -181,15 +187,15 @@ sub listFiles(byref frm, path, byref basList, byref dirList)
181187

182188
for ent in fileList
183189
name = ent
184-
if (isdir(path + name)) then
190+
if (isdir(path + name) && left(name, 1) != ".") then
185191
dirList << name
186192
else if (lower(right(ent, 4)) == ".bas") then
187193
basList << name
188194
endif
189195
next ent
190196

191-
sort dirList
192-
sort basList
197+
sort dirList use fileCmpFunc(x,y)
198+
sort basList use filecmpfunc(x,y)
193199

194200
lastItem = len(dirList) - 1
195201

src/platform/android/jni/runtime.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ void handleCommand(android_app *app, int32_t cmd) {
8181
trace("handleCommand = %d", cmd);
8282
switch (cmd) {
8383
case APP_CMD_INIT_WINDOW:
84-
// thread is ready to start
85-
runtime->construct();
86-
break;
87-
case APP_CMD_TERM_WINDOW:
88-
if (runtime) {
89-
// thread is ending
90-
runtime->setExit(true);
84+
// thread is ready to start or resume
85+
if (runtime->isInitial()) {
86+
runtime->construct();
9187
}
9288
break;
89+
case APP_CMD_GAINED_FOCUS:
90+
trace("gainedFocus");
91+
runtime->setFocus(true);
92+
break;
9393
case APP_CMD_LOST_FOCUS:
94-
// display menu or exit
94+
trace("lostFocus");
95+
runtime->setFocus(false);
9596
break;
9697
}
9798
}
@@ -150,6 +151,7 @@ void onContentRectChanged(ANativeActivity *activity, const ARect *rect) {
150151
Runtime::Runtime(android_app *app) :
151152
System(),
152153
_keypadActive(false),
154+
_hasFocus(false),
153155
_graphics(NULL),
154156
_app(app),
155157
_eventQueue(NULL) {
@@ -603,7 +605,7 @@ void Runtime::pause(int timeout) {
603605
void Runtime::pollEvents(bool blocking) {
604606
int events;
605607
android_poll_source *source;
606-
ALooper_pollAll(blocking ? -1 : 0, NULL, &events, (void **)&source);
608+
ALooper_pollAll(blocking || !_hasFocus ? -1 : 0, NULL, &events, (void **)&source);
607609
if (source != NULL) {
608610
source->process(_app, source);
609611
}

src/platform/android/jni/runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ struct Runtime : public System {
5757
void runPath(const char *path);
5858
void setClipboardText(const char *text);
5959
char *getClipboardText();
60+
void setFocus(bool focus) { _hasFocus = focus; }
6061

6162
private:
6263
bool _keypadActive;
64+
bool _hasFocus;
6365
Graphics *_graphics;
6466
android_app *_app;
6567
Stack<MAEvent *> *_eventQueue;

src/platform/sdl/display.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,26 @@ bool Graphics::construct(const char *font, const char *boldFont) {
111111
logEntered();
112112

113113
int w, h;
114-
bool result = false;
114+
bool result = true;
115115
SDL_GetWindowSize(_window, &w, &h);
116116

117117
SDL_Surface *surface = SDL_GetWindowSurface(_window);
118-
if (surface->format->format != PIXELFORMAT) {
118+
if (surface == NULL) {
119+
fprintf(stderr, "SDL surface is null\n");
120+
result = false;
121+
} else if (surface->format == NULL) {
122+
fprintf(stderr, "SDL surface format is null\n");
123+
result = false;
124+
} else if (surface->format->format != PIXELFORMAT) {
119125
deviceLog("Unexpected window surface format %d", surface->format->format);
120126
_surface = surface;
121127
}
122128

123-
if (loadFonts(font, boldFont)) {
129+
if (result && loadFonts(font, boldFont)) {
124130
_screen = new Canvas();
125131
if (_screen != NULL) {
126132
if (_surface == NULL) {
127133
_screen->setSurface(SDL_GetWindowSurface(_window), w, h);
128-
result = true;
129134
} else {
130135
result = _screen->create(w, h);
131136
}

src/ui/form.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ void set_focus(FormInput *focus) {
3434
}
3535
}
3636

37+
struct FormTextInput : public TextEditInput {
38+
FormTextInput(const char *text, int chW, int chH, int x, int y, int w, int h):
39+
TextEditInput(text, chW, chH, x, y, w, h) {
40+
}
41+
42+
void clicked(int x, int y, bool pressed) {
43+
TextEditInput::clicked(x, y, pressed);
44+
if (pressed && g_system->isRunning()) {
45+
set_focus(this);
46+
updateForm(form);
47+
mode = m_selected;
48+
g_system->getOutput()->setDirty();
49+
}
50+
}
51+
};
52+
3753
// returns setBG when the program colours are default
3854
int FormInput::getBackground(int buttonColor) const {
3955
int result = _bg;
@@ -241,7 +257,7 @@ FormInput *create_input(var_p_t v_field) {
241257
text = value->v.p.ptr;
242258
}
243259
if (h * 2 >= charHeight) {
244-
widget = new TextEditInput(text, charWidth, charHeight, x, y, w, h);
260+
widget = new FormTextInput(text, charWidth, charHeight, x, y, w, h);
245261
} else {
246262
widget = new FormLineInput(text, maxSize, false, x, y, w, h);
247263
}

src/ui/system.cpp

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define MENU_COMPETION_2 (MENU_SIZE + 3)
4848
#define MENU_COMPETION_3 (MENU_SIZE + 4)
4949
#define MAX_COMPLETIONS 4
50+
#define MAX_CACHE 8
5051

5152
#define FONT_SCALE_INTERVAL 10
5253
#define FONT_MIN 20
@@ -56,9 +57,23 @@
5657

5758
System *g_system;
5859

60+
void Cache::add(const char *key, const char *value) {
61+
if (_size == _count) {
62+
// overwrite at next index position
63+
_head[_index]->empty();
64+
_head[_index]->append(key);
65+
_head[_index + 1]->empty();
66+
_head[_index + 1]->append(value);
67+
_index = (_index + 2) % _size;
68+
} else {
69+
Properties::put(key, value);
70+
}
71+
}
72+
5973
System::System() :
6074
_output(NULL),
6175
_state(kInitState),
76+
_cache(MAX_CACHE),
6277
_lastEventTime(0),
6378
_eventTicks(0),
6479
_touchX(-1),
@@ -406,27 +421,35 @@ void System::handleEvent(MAEvent &event) {
406421
char *System::loadResource(const char *fileName) {
407422
char *buffer = NULL;
408423
if (strstr(fileName, "://") != NULL) {
409-
int handle = 1;
410-
var_t *var_p = v_new();
411-
dev_file_t *f = dev_getfileptr(handle);
412-
_output->setStatus("Loading...");
413-
_output->redraw();
414-
if (dev_fopen(handle, fileName, 0)) {
415-
if (http_read(f, var_p) == 0) {
416-
systemPrint("\nfailed to read %s\n", fileName);
424+
String *cached = _cache.get(fileName);
425+
if (cached != NULL) {
426+
int len = cached->length();
427+
buffer = (char *)malloc(len + 1);
428+
memcpy(buffer, cached->c_str(), len);
429+
} else {
430+
int handle = 1;
431+
var_t *var_p = v_new();
432+
dev_file_t *f = dev_getfileptr(handle);
433+
_output->setStatus("Loading...");
434+
_output->redraw();
435+
if (dev_fopen(handle, fileName, 0)) {
436+
if (http_read(f, var_p) == 0) {
437+
systemPrint("\nfailed to read %s\n", fileName);
438+
} else {
439+
int len = var_p->v.p.size;
440+
buffer = (char *)malloc(len + 1);
441+
memcpy(buffer, var_p->v.p.ptr, len);
442+
buffer[len] = '\0';
443+
_cache.add(fileName, buffer);
444+
}
417445
} else {
418-
int len = var_p->v.p.size;
419-
buffer = (char *)malloc(len + 1);
420-
memcpy(buffer, var_p->v.p.ptr, len);
421-
buffer[len] = '\0';
446+
systemPrint("\nfailed to open %s\n", fileName);
422447
}
423-
} else {
424-
systemPrint("\nfailed to open %s\n", fileName);
448+
_output->setStatus(NULL);
449+
dev_fclose(handle);
450+
v_free(var_p);
451+
free(var_p);
425452
}
426-
_output->setStatus(NULL);
427-
dev_fclose(handle);
428-
v_free(var_p);
429-
free(var_p);
430453
}
431454
return buffer;
432455
}
@@ -612,14 +635,25 @@ void System::setBack() {
612635
_output->selectBackScreen(_userScreenId);
613636
_output->selectFrontScreen(_userScreenId);
614637
_userScreenId = -1;
615-
} else {
616-
// quit app when shell is active
617-
setExit(_mainBas);
638+
}
639+
640+
// quit app when shell is active
641+
setExit(_mainBas);
642+
643+
// follow history when available and not exiting
644+
if (!_mainBas) {
645+
// remove the current item
646+
_history.pop();
647+
if (_history.peek() != NULL) {
648+
_loadPath.empty();
649+
_loadPath.append(_history.peek());
650+
}
618651
}
619652
}
620653

621654
void System::setLoadBreak(const char *path) {
622655
_loadPath = path;
656+
_history.push(new strlib::String(path));
623657
_state = kBreakState;
624658
brun_break();
625659
}

src/ui/system.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
#include "platform/fltk/system.h"
1919
#else
2020

21+
struct Cache : public strlib::Properties {
22+
Cache(int size) : Properties(size * 2), _index(0) {}
23+
void add(const char *key, const char *value);
24+
int _index;
25+
};
26+
2127
struct System {
2228
System();
2329
virtual ~System();
@@ -107,8 +113,10 @@ struct System {
107113
kDoneState // thread has terminated
108114
} _state;
109115

116+
strlib::Stack<String *> _history;
110117
strlib::String _loadPath;
111118
strlib::String _activeFile;
119+
Cache _cache;
112120
int _lastEventTime;
113121
int _eventTicks;
114122
int _touchX;

0 commit comments

Comments
 (0)