Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dnl This program is distributed under the terms of the GPL v2.0
dnl Download the GNU Public License (GPL) from www.gnu.org
dnl

AC_INIT([smallbasic], [0.12.2])
AC_INIT([smallbasic], [0.12.3])
AC_CONFIG_SRCDIR([configure.ac])

AC_CANONICAL_TARGET
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
smallbasic (0.12.3) unstable; urgency=low
* Various - see web site

-- Chris Warren-Smith <cwarrensmith@gmail.com> Tue, 26 Jan 2016 09:45:25 +1000

smallbasic (0.12.2) unstable; urgency=low
* Various - see web site

Expand Down
4 changes: 2 additions & 2 deletions ide/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.sourceforge.smallbasic"
android:installLocation="preferExternal"
android:versionCode="16"
android:versionName="0.12.1">
android:versionCode="17"
android:versionName="0.12.3">
<!-- This is the platform API where NativeActivity was introduced. -->
<uses-sdk android:minSdkVersion="9"/>

Expand Down
14 changes: 10 additions & 4 deletions ide/android/assets/main.bas
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sub do_about()
print "(_ ._ _ _.|||_) /\ (_ |/ "
print "__)| | |(_||||_)/--\__)|\_"
print
print "Version 0.12.2"
print "Version 0.12.3"
print
print "Copyright (c) 2002-2015 Chris Warren-Smith"
print "Copyright (c) 1999-2006 Nic Christopoulos" + chr(10)
Expand Down Expand Up @@ -155,6 +155,12 @@ sub serverInfo()
fi
end

func fileCmpFunc(l, r)
local f1 = lower(l)
local f2 = lower(r)
fileCmpFunc = IFF(f1 == f2, 0, IFF(f1 > f2, 1, -1))
end

sub listFiles(byref frm, path, byref basList, byref dirList)
local fileList, ent, name, lastItem, bn, bn_back

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

for ent in fileList
name = ent
if (isdir(path + name)) then
if (isdir(path + name) && left(name, 1) != ".") then
dirList << name
else if (lower(right(ent, 4)) == ".bas") then
basList << name
endif
next ent

sort dirList
sort basList
sort dirList use fileCmpFunc(x,y)
sort basList use filecmpfunc(x,y)

lastItem = len(dirList) - 1

Expand Down
20 changes: 11 additions & 9 deletions src/platform/android/jni/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ void handleCommand(android_app *app, int32_t cmd) {
trace("handleCommand = %d", cmd);
switch (cmd) {
case APP_CMD_INIT_WINDOW:
// thread is ready to start
runtime->construct();
break;
case APP_CMD_TERM_WINDOW:
if (runtime) {
// thread is ending
runtime->setExit(true);
// thread is ready to start or resume
if (runtime->isInitial()) {
runtime->construct();
}
break;
case APP_CMD_GAINED_FOCUS:
trace("gainedFocus");
runtime->setFocus(true);
break;
case APP_CMD_LOST_FOCUS:
// display menu or exit
trace("lostFocus");
runtime->setFocus(false);
break;
}
}
Expand Down Expand Up @@ -150,6 +151,7 @@ void onContentRectChanged(ANativeActivity *activity, const ARect *rect) {
Runtime::Runtime(android_app *app) :
System(),
_keypadActive(false),
_hasFocus(false),
_graphics(NULL),
_app(app),
_eventQueue(NULL) {
Expand Down Expand Up @@ -603,7 +605,7 @@ void Runtime::pause(int timeout) {
void Runtime::pollEvents(bool blocking) {
int events;
android_poll_source *source;
ALooper_pollAll(blocking ? -1 : 0, NULL, &events, (void **)&source);
ALooper_pollAll(blocking || !_hasFocus ? -1 : 0, NULL, &events, (void **)&source);
if (source != NULL) {
source->process(_app, source);
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform/android/jni/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ struct Runtime : public System {
void runPath(const char *path);
void setClipboardText(const char *text);
char *getClipboardText();
void setFocus(bool focus) { _hasFocus = focus; }

private:
bool _keypadActive;
bool _hasFocus;
Graphics *_graphics;
android_app *_app;
Stack<MAEvent *> *_eventQueue;
Expand Down
13 changes: 9 additions & 4 deletions src/platform/sdl/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,26 @@ bool Graphics::construct(const char *font, const char *boldFont) {
logEntered();

int w, h;
bool result = false;
bool result = true;
SDL_GetWindowSize(_window, &w, &h);

SDL_Surface *surface = SDL_GetWindowSurface(_window);
if (surface->format->format != PIXELFORMAT) {
if (surface == NULL) {
fprintf(stderr, "SDL surface is null\n");
result = false;
} else if (surface->format == NULL) {
fprintf(stderr, "SDL surface format is null\n");
result = false;
} else if (surface->format->format != PIXELFORMAT) {
deviceLog("Unexpected window surface format %d", surface->format->format);
_surface = surface;
}

if (loadFonts(font, boldFont)) {
if (result && loadFonts(font, boldFont)) {
_screen = new Canvas();
if (_screen != NULL) {
if (_surface == NULL) {
_screen->setSurface(SDL_GetWindowSurface(_window), w, h);
result = true;
} else {
result = _screen->create(w, h);
}
Expand Down
18 changes: 17 additions & 1 deletion src/ui/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ void set_focus(FormInput *focus) {
}
}

struct FormTextInput : public TextEditInput {
FormTextInput(const char *text, int chW, int chH, int x, int y, int w, int h):
TextEditInput(text, chW, chH, x, y, w, h) {
}

void clicked(int x, int y, bool pressed) {
TextEditInput::clicked(x, y, pressed);
if (pressed && g_system->isRunning()) {
set_focus(this);
updateForm(form);
mode = m_selected;
g_system->getOutput()->setDirty();
}
}
};

// returns setBG when the program colours are default
int FormInput::getBackground(int buttonColor) const {
int result = _bg;
Expand Down Expand Up @@ -241,7 +257,7 @@ FormInput *create_input(var_p_t v_field) {
text = value->v.p.ptr;
}
if (h * 2 >= charHeight) {
widget = new TextEditInput(text, charWidth, charHeight, x, y, w, h);
widget = new FormTextInput(text, charWidth, charHeight, x, y, w, h);
} else {
widget = new FormLineInput(text, maxSize, false, x, y, w, h);
}
Expand Down
76 changes: 55 additions & 21 deletions src/ui/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define MENU_COMPETION_2 (MENU_SIZE + 3)
#define MENU_COMPETION_3 (MENU_SIZE + 4)
#define MAX_COMPLETIONS 4
#define MAX_CACHE 8

#define FONT_SCALE_INTERVAL 10
#define FONT_MIN 20
Expand All @@ -56,9 +57,23 @@

System *g_system;

void Cache::add(const char *key, const char *value) {
if (_size == _count) {
// overwrite at next index position
_head[_index]->empty();
_head[_index]->append(key);
_head[_index + 1]->empty();
_head[_index + 1]->append(value);
_index = (_index + 2) % _size;
} else {
Properties::put(key, value);
}
}

System::System() :
_output(NULL),
_state(kInitState),
_cache(MAX_CACHE),
_lastEventTime(0),
_eventTicks(0),
_touchX(-1),
Expand Down Expand Up @@ -406,27 +421,35 @@ void System::handleEvent(MAEvent &event) {
char *System::loadResource(const char *fileName) {
char *buffer = NULL;
if (strstr(fileName, "://") != NULL) {
int handle = 1;
var_t *var_p = v_new();
dev_file_t *f = dev_getfileptr(handle);
_output->setStatus("Loading...");
_output->redraw();
if (dev_fopen(handle, fileName, 0)) {
if (http_read(f, var_p) == 0) {
systemPrint("\nfailed to read %s\n", fileName);
String *cached = _cache.get(fileName);
if (cached != NULL) {
int len = cached->length();
buffer = (char *)malloc(len + 1);
memcpy(buffer, cached->c_str(), len);
} else {
int handle = 1;
var_t *var_p = v_new();
dev_file_t *f = dev_getfileptr(handle);
_output->setStatus("Loading...");
_output->redraw();
if (dev_fopen(handle, fileName, 0)) {
if (http_read(f, var_p) == 0) {
systemPrint("\nfailed to read %s\n", fileName);
} else {
int len = var_p->v.p.size;
buffer = (char *)malloc(len + 1);
memcpy(buffer, var_p->v.p.ptr, len);
buffer[len] = '\0';
_cache.add(fileName, buffer);
}
} else {
int len = var_p->v.p.size;
buffer = (char *)malloc(len + 1);
memcpy(buffer, var_p->v.p.ptr, len);
buffer[len] = '\0';
systemPrint("\nfailed to open %s\n", fileName);
}
} else {
systemPrint("\nfailed to open %s\n", fileName);
_output->setStatus(NULL);
dev_fclose(handle);
v_free(var_p);
free(var_p);
}
_output->setStatus(NULL);
dev_fclose(handle);
v_free(var_p);
free(var_p);
}
return buffer;
}
Expand Down Expand Up @@ -612,14 +635,25 @@ void System::setBack() {
_output->selectBackScreen(_userScreenId);
_output->selectFrontScreen(_userScreenId);
_userScreenId = -1;
} else {
// quit app when shell is active
setExit(_mainBas);
}

// quit app when shell is active
setExit(_mainBas);

// follow history when available and not exiting
if (!_mainBas) {
// remove the current item
_history.pop();
if (_history.peek() != NULL) {
_loadPath.empty();
_loadPath.append(_history.peek());
}
}
}

void System::setLoadBreak(const char *path) {
_loadPath = path;
_history.push(new strlib::String(path));
_state = kBreakState;
brun_break();
}
Expand Down
8 changes: 8 additions & 0 deletions src/ui/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "platform/fltk/system.h"
#else

struct Cache : public strlib::Properties {
Cache(int size) : Properties(size * 2), _index(0) {}
void add(const char *key, const char *value);
int _index;
};

struct System {
System();
virtual ~System();
Expand Down Expand Up @@ -107,8 +113,10 @@ struct System {
kDoneState // thread has terminated
} _state;

strlib::Stack<String *> _history;
strlib::String _loadPath;
strlib::String _activeFile;
Cache _cache;
int _lastEventTime;
int _eventTicks;
int _touchX;
Expand Down