Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joystick support (final) #54

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d189e66
Re-do of Joystick support: dynamic alloc, reset
Mar 17, 2012
d20ede6
Joystick Example.
Mar 17, 2012
adbb468
Fix for Open Pandora --bpp arg selection.
Mar 17, 2012
6253a45
Basic button support.
Mar 17, 2012
b6990e5
Slight tweaks to the joystick demo.
Mar 17, 2012
c6f8656
Unneeded whitespace.
Mar 17, 2012
e564215
Whitepsace
Mar 17, 2012
741a081
Added to support mouse scrolling, page up, page down, home, and end
cobrajs Mar 21, 2012
55b197e
Merge pull request #1 from cobrajs/editorchanges
seclorum Mar 22, 2012
30cedc7
Add support for drawing polygons
cobrajs Mar 23, 2012
1b31c17
Reworked a bit, and added some error trapping
cobrajs Mar 23, 2012
63c6660
Added filled() binding to set the filled state
cobrajs Mar 23, 2012
58ffaa4
Merge branch 'polygon'
cobrajs Mar 24, 2012
c45dfab
Merged, added filled stuff for polygon
cobrajs Mar 24, 2012
f2a8f54
Added functions to the README
cobrajs Mar 24, 2012
eb1178e
Added tiling support to sprites
cobrajs Mar 24, 2012
c99f611
Merge pull request #2 from cobrajs/master
seclorum Mar 24, 2012
58b1161
add joystick support to flames.lua
seclorum Apr 1, 2012
2392e99
consistency check
seclorum Apr 1, 2012
9175910
add joystick support to flames, include new gridify sample
Apr 4, 2012
c566aed
Merge.
Apr 4, 2012
265a1bb
fix for case where no joysticks are available
Apr 4, 2012
6879ff3
Update README.md
seclorum Apr 4, 2012
074639f
slight edit
Apr 4, 2012
fbe0b30
fix for joystick note
Apr 4, 2012
b06cf64
Fixup of gridifuy.lua sample.
Apr 4, 2012
20279c3
timeout demo started
seclorum Apr 11, 2012
8c13a7e
joystick support for timeout.lua
seclorum Apr 11, 2012
c0ef305
color support in timeout.lua
seclorum Apr 11, 2012
c9e3a01
Merge branch 'master' of github.com:seclorum/load81
Apr 12, 2012
081392d
joystick check
Apr 12, 2012
6b2ee93
comments
seclorum Apr 15, 2012
e524e98
Merge branch 'master' of https://github.com/seclorum/load81
seclorum Apr 15, 2012
a6e6074
fix of merge hiccup
seclorum Apr 15, 2012
7a338a6
tweaks
May 2, 2012
5d167aa
Merge branch 'master' of github.com:seclorum/load81
May 2, 2012
a8adc33
pull antirez
seclorum Jul 14, 2016
47a35ef
Adjust Makefile to use sdl-config instead of pkg-config
Sep 12, 2016
8b74739
Add Darwin-specific hooks to compile against SDL_gfx/etc. from homebr…
seclorum Sep 14, 2016
86fbc71
Include LFS in Lua Build
seclorum Sep 14, 2016
7e36ea5
add lfs hook
seclorum Sep 15, 2016
29c5d9b
Add LFS
seclorum Sep 15, 2016
eb3927b
localized headers instead of system headers
seclorum Sep 15, 2016
b5c9459
export LFS for use in LOAD81
seclorum Sep 15, 2016
3976c8e
include lfs in lualibs[]
seclorum Sep 15, 2016
c08025b
global luaopen_lfs export
seclorum Sep 15, 2016
d632917
Put libs back in place properly
seclorum Sep 16, 2016
fae5aa3
Add debian package control dir
seclorum Sep 16, 2016
f5c5716
clean
Oct 7, 2016
b72f00f
gridify example
seclorum Oct 7, 2016
c9227b1
filelist example
seclorum Oct 7, 2016
41ca649
runner to contrib
seclorum Oct 7, 2016
b730212
/usr/include for build
seclorum Oct 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions Makefile
@@ -1,6 +1,13 @@

PKGS=sdl SDL_gfx SDL_image
CFLAGS=-O2 -Wall -W -Ilua/src `pkg-config --cflags $(PKGS)`
LDLIBS=lua/src/liblua.a -lm `pkg-config --libs $(PKGS)`
CFLAGS=-O2 -Wall -W -Ilua/src `sdl-config --cflags`
LDLIBS=lua/src/liblua.a -lm `sdl-config --libs` -lSDL_gfx -lSDL_image

# Customizations per-OS
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
CFLAGS+=-I/usr/local/Cellar//sdl_gfx/2.0.25/include/SDL/ -I/usr/local/Cellar//sdl_image/1.2.12_3/include/SDL/
endif

all: load81

Expand All @@ -20,3 +27,4 @@ distclean: clean

dep:
$(CC) -MM *.c

34 changes: 33 additions & 1 deletion README.md
Expand Up @@ -50,14 +50,30 @@ PROGRAMMING INTERFACE
Drawing functions:

* fill(r,g,b,alpha): select the drawing color.
* filled(filled): set the filled state (true or false)
* background(r,g,b): paint the whole background with the specified color.
* rect(x,y,width,height): draw a rectangle at x,y (left-bottom corner).
* ellipse(x,y,width,height): draw an ellipse centered at x,y.
* line(x1,y1,x2,y2): draw a line from x1,y1 to x2,y2.
* text(x,y,string): print the specified text at x,y using a bitmap font.
* triangle(x1,y1,x2,y2,x3,y3): draw a triangle with the specified vertex.
* getpixel(x,y): return the red,gree,blue value of the specified pixel.
* sprite(file,x,y,[rotation],[antialiasing]): draw sprite at coordinates with the specified rotation (in degrees, default 0) and antialiasing (default false).
* polygon(xv, yv): draw a polygon using a table of X values and a table of Y values.

Sprite functions:

* sprite(file,[x,y,[rotation],[antialiasing]]): draw sprite at coordinates with the specified rotation (in degrees, default 0) and antialiasing (default false).

Returns a sprite userdata object, with the following functions

* getHeight(): returns the height of the sprite.
* getWidth(): returns the height of the sprite.
* getTiles(): returns x,y for the number of tiles horizontally and vertically.
* setTiles(x,y): set the number of tiles horizontally and vertically.
* getTileSize(): return w,h for the size of a tile, calculated from the width and height of the image divided by the number of tiles horizontally and vertically.
* getTileNum(): returns the number of tiles.
* tile(x,y,tileNum,[rotation],[antialiasing]): draw a tile using tileNum at coordinates with the specified rotation (in degrees, default 0) and antialiasing (default: false).
* draw(x,y,[rotation],[antialiasing]): draw sprite at coordinates with the specified rotation (in degrees, default 0) and antialiasing (default: false).

Control functions:

Expand Down Expand Up @@ -106,6 +122,22 @@ if a button is pressed use:

Mouse buttons are called '1', '2', '3', ... and so forth.

JOYSTICK EVENTS
===
Joystick support is available by directly accessing the joystick[] table.
For example:

joystick[1].x / joystick[1].y = X/Y position of Joystick1
joystick[1].button = button state of Joystick1
joystick[1].name = "hardware name of the Joystick1"

joystick.count contains the number of joysticks detected by LOAD81 on
startup, and will be 0 if no joysticks are available. Max # of Joysticks
is currently set at 8.

See examples/joysticks.lua and examples/flames.lua for how to use the
joystick.

LICENSE
===

Expand Down
1 change: 1 addition & 0 deletions contrib/Pandora/PND_Resources/defconf/profile.txt
Expand Up @@ -9,6 +9,7 @@ filepath=./examples/
exepath=./load81 --full
extarg=--width;0;%na%;800
extarg=--height;0;%na%;480
extarg=--bpp;0;%na%;0
extarg=;0;%na%;%filename%

# Custom Entries Settings
13 changes: 13 additions & 0 deletions contrib/PocketCHIP/runner.sh
@@ -0,0 +1,13 @@
# runs load81, resetting it if any file-changes occur in the
# WATCHDIR, for example, the onboard examples/ .. any changes
# to the dir will re-load load81 ..
#!/bin/bash
export DISPLAY=:0
WATCHDIR=./examples/
inotifywait -m -e close_write $WATCHDIR | \
while read -r notifile event filename ; \
do \
echo "notifile: $notifile event: $event filename: $filename"
killall load81 ; \
./load81 --width 480 --height 272 $notifile/$filename & \
done
11 changes: 11 additions & 0 deletions contrib/debian_pocketchip/load81_0.0-2/DEBIAN/control
@@ -0,0 +1,11 @@
Package: load81
Version: 0.1-1
Section: base
Priority: optional
Architecture: armhf
Maintainer: seclorum <seclorum@icloud.com>
Depends: libsdl-gfx1.2-5 (>=1.2), libsdl-image1.2 (>=1.2)
Description: antirez' LOAD81 packaged for PocketCHIP.
antirez (http://github.com/antirez/load81) created the wonderful
load81 development environment, which provides an editor to
create small apps in the Lua programming language.
1 change: 1 addition & 0 deletions contrib/debian_pocketchip/makedeb.sh
@@ -0,0 +1 @@
dpkg-deb --build load81_0.0-2/
178 changes: 149 additions & 29 deletions editor.c
Expand Up @@ -392,7 +392,7 @@ void editorDrawCursor(void) {
y -= E.margin_top;
if (!(E.cblink & 0x80)) drawBox(E.fb,x+charmargin,y,
x+charmargin+FONT_KERNING-1,y+FONT_HEIGHT-1,
165,165,255,128);
165,165,255,128,1);
E.cblink += 4;
}

Expand Down Expand Up @@ -430,25 +430,25 @@ void editorDrawChars(void) {
}

void editorDrawPowerOff(int x, int y) {
drawEllipse(E.fb,x,y,12,12,66,66,231,255);
drawEllipse(E.fb,x,y,7,7,165,165,255,255);
drawBox(E.fb,x-4,y,x+4,y+12,165,165,255,255);
drawBox(E.fb,x-2,y,x+2,y+14,66,66,231,255);
drawEllipse(E.fb,x,y,12,12,66,66,231,255,1);
drawEllipse(E.fb,x,y,7,7,165,165,255,255,1);
drawBox(E.fb,x-4,y,x+4,y+12,165,165,255,255,1);
drawBox(E.fb,x-2,y,x+2,y+14,66,66,231,255,1);
}

void editorDrawSaveIcon(int x, int y) {
drawBox(E.fb,x-12,y-12,x+12,y+12,66,66,231,255);
drawBox(E.fb,x-1,y+7,x+1,y+11,165,165,255,255);
drawEllipse(E.fb,x,y,4,4,165,165,255,255);
drawBox(E.fb,x-12,y-12,x+12,y+12,66,66,231,255,1);
drawBox(E.fb,x-1,y+7,x+1,y+11,165,165,255,255,1);
drawEllipse(E.fb,x,y,4,4,165,165,255,255,1);
}

void editorDraw() {
drawBox(E.fb,0,0,E.fb->width-1,E.fb->height-1,165,165,255,255);
drawBox(E.fb,0,0,E.fb->width-1,E.fb->height-1,165,165,255,255,1);
drawBox(E.fb,
E.margin_left,
E.margin_bottom,
E.fb->width-1-E.margin_right,
E.fb->height-1-E.margin_top,66,66,231,255);
E.fb->height-1-E.margin_top,66,66,231,255,1);
editorDrawChars();
editorDrawCursor();
/* Show buttons */
Expand Down Expand Up @@ -491,24 +491,38 @@ void editorMouseClicked(int x, int y, int button) {
} else if (x >= E.margin_left && x <= E.fb->width-1-E.margin_right &&
y >= E.margin_bottom && y <= E.fb->height-1-E.margin_top)
{
int realheight = E.fb->height - E.margin_top - E.margin_bottom;
int realy = y - E.margin_bottom;
int row = (realheight-realy)/FONT_HEIGHT;
int col = (x-E.margin_left)/FONT_KERNING;
int filerow = E.rowoff+row;
int filecol = E.coloff+col;
erow *r = (filerow >= E.numrows) ? NULL : &E.row[filerow];

E.cblink = 0;
if (filerow == E.numrows) {
E.cx = 0;
E.cy = filerow-E.rowoff;
} else if (r) {
if (filecol >= r->size)
E.cx = r->size-E.coloff;
else
E.cx = filecol-E.coloff;
E.cy = filerow-E.rowoff;
if (button == 4) {
if (E.rowoff) {
E.rowoff--;
if (E.cy < E.screenrows - 1) E.cy++;
}
}
else if (button == 5) {
if (E.rowoff + E.screenrows < E.numrows) {
E.rowoff++;
if (E.cy > 0) E.cy--;
}
}
else {
int realheight = E.fb->height - E.margin_top - E.margin_bottom;
int realy = y - E.margin_bottom;
int row = (realheight-realy)/FONT_HEIGHT;
int col = (x-E.margin_left)/FONT_KERNING;
int filerow = E.rowoff+row;
int filecol = E.coloff+col;
erow *r = (filerow >= E.numrows) ? NULL : &E.row[filerow];

E.cblink = 0;
if (filerow == E.numrows) {
E.cx = 0;
E.cy = filerow-E.rowoff;
} else if (r) {
if (filecol >= r->size)
E.cx = r->size-E.coloff;
else
E.cx = filecol-E.coloff;
E.cy = filerow-E.rowoff;
}
}
}
}
Expand All @@ -518,6 +532,7 @@ void editorMoveCursor(int key) {
int filecol = E.coloff+E.cx;
int rowlen;
erow *row = (filerow >= E.numrows) ? NULL : &E.row[filerow];
int temp;

switch(key) {
case SDLK_LEFT:
Expand Down Expand Up @@ -552,6 +567,61 @@ void editorMoveCursor(int key) {
}
}
break;
case SDLK_PAGEUP:
if (E.rowoff) {
E.rowoff -= E.screenrows - 1;
if (E.rowoff < 0) {
E.rowoff = 0;
E.cy = 0;
}
}
else {
if (E.cy > 0) E.cy = 0;
}
break;
case SDLK_PAGEDOWN:
if (E.rowoff + E.screenrows - 1 < E.numrows) {
E.rowoff += E.screenrows - 1;
if (E.rowoff + E.screenrows - 1 > E.numrows) E.cy = E.numrows - E.rowoff - 1;
}
else {
E.cy = E.numrows - E.rowoff - 1;
}
break;
case SDLK_HOME:
if (E.modifiers & CTRL_MASK) {
E.rowoff = E.coloff = E.cy = E.cx = 0;
}
else {
if (row && filecol != 0) {
temp = getFirstNonSpace(row);
if (temp > -1) {
if (filecol > temp) {
E.cx = temp;
E.coloff = 0;
}
else {
E.cx = E.coloff = 0;
}
}
}
}
break;
case SDLK_END:
if (E.modifiers & CTRL_MASK) {
E.rowoff = E.numrows - E.screenrows;
E.cy = E.screenrows - 1;
E.coloff = E.cx = 0;
}
else {
if (row && filecol < row->size) {
if (row->size - E.screencols + 1 > 0) {
E.coloff = row->size - E.screencols + 1;
}
E.cx = row->size - E.coloff;
}
}
break;
}
/* Fix cx if the current line has not enough chars. */
filerow = E.rowoff+E.cy;
Expand All @@ -567,6 +637,16 @@ void editorMoveCursor(int key) {
}
}

int getFirstNonSpace(erow *row) {
int i;
for (i = 0; i < row->size; i++) {
if (row->chars[i] != ' ' && row->chars[i] != '\t') {
return i;
}
}
return -1;
}

int editorEvents(void) {
SDL_Event event;
int j, ksym;
Expand Down Expand Up @@ -596,6 +676,24 @@ int editorEvents(void) {
E.key[ksym].counter = 1;
E.key[ksym].translation = (event.key.keysym.unicode & 0xff);
}
switch(ksym) {
case SDLK_LSHIFT:
case SDLK_RSHIFT:
E.modifiers |= SHIFT_MASK;
break;
case SDLK_LCTRL:
case SDLK_RCTRL:
E.modifiers |= CTRL_MASK;
break;
case SDLK_LALT:
case SDLK_RALT:
E.modifiers |= ALT_MASK;
break;
case SDLK_LMETA:
case SDLK_RMETA:
E.modifiers |= META_MASK;
break;
}
break;
}
break;
Expand All @@ -604,6 +702,24 @@ int editorEvents(void) {
case SDL_KEYUP:
ksym = event.key.keysym.sym;
if (ksym >= 0 && ksym < KEY_MAX) E.key[ksym].counter = 0;
switch(ksym) {
case SDLK_LSHIFT:
case SDLK_RSHIFT:
E.modifiers &= ~SHIFT_MASK;
break;
case SDLK_LCTRL:
case SDLK_RCTRL:
E.modifiers &= ~CTRL_MASK;
break;
case SDLK_LALT:
case SDLK_RALT:
E.modifiers &= ~ALT_MASK;
break;
case SDLK_LMETA:
case SDLK_RMETA:
E.modifiers &= ~META_MASK;
break;
}
break;
/* Mouse click */
case SDL_MOUSEBUTTONDOWN:
Expand All @@ -628,6 +744,10 @@ int editorEvents(void) {
case SDLK_RIGHT:
case SDLK_UP:
case SDLK_DOWN:
case SDLK_PAGEUP:
case SDLK_PAGEDOWN:
case SDLK_HOME:
case SDLK_END:
editorMoveCursor(j);
break;
case SDLK_BACKSPACE:
Expand All @@ -636,7 +756,6 @@ int editorEvents(void) {
case SDLK_RETURN:
editorInsertNewline();
break;
case SDLK_HOME:
case SDLK_LSHIFT:
case SDLK_RSHIFT:
case SDLK_LCTRL:
Expand Down Expand Up @@ -721,4 +840,5 @@ void initEditor(frameBuffer *fb, int mt, int mb, int ml, int mr) {
E.dirty = 0;
E.filename = NULL;
memset(E.key,0,sizeof(E.key));
E.modifiers = 0;
}