Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
takeiteasy committed Nov 29, 2023
1 parent a29e158 commit 6992bcc
Show file tree
Hide file tree
Showing 12 changed files with 1,754 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ default:
$(CC) -Isrc src/$(SRC).c examples/basic.c $(CFLAGS) -o build/$(SRC)$(PROGEXT)

library:
$(CC) -shared -fpic -Isrc src/$(SRC).c examples/basic.c $(CFLAGS) -o build/$(SRC).$(LIBEXT)
$(CC) -shared -fpic -Isrc src/$(SRC).c examples/basic.c $(CFLAGS) -o build/lib$(SRC).$(LIBEXT)

web:
emcc -DPP_EMSCRIPTEN -Isrc src/ppEmscripten.c examples/basic.c -o build/pp.html
Expand Down
6 changes: 6 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off
if exist .\build\ppLive.dll move .\build\ppLive.dll .\build\ppLive.%random%.dll
cl .\live\ppUtils.c .\examples\live.c /I.\src /I.\live /MD /link /DLL /SUBSYSTEM:CONSOLE /out:.\build\ppLive.dll
if exist .\build\pp.exe move .\build\pp.exe .\build\pp.%random%.exe
cl .\src\ppWindows.c .\live\*.c /I.\src /I.\live Psapi.lib /link /SUBSYSTEM:CONSOLE /out:.\build\pp.exe
del *.obj
3 changes: 3 additions & 0 deletions docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
headerdoc2html -udpb src/pp.h -o docs/
gatherheaderdoc docs
mv docs/masterTOC.html docs/index.html
75 changes: 75 additions & 0 deletions examples/live.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "ppLive.h"
#include <time.h>
#include <stdlib.h>

struct ppState {
ppColor clearColor;
};

// Called once at the beginning of runtime
static ppState* init(void) {
ppState *state = malloc(sizeof(ppState));
if (!state)
return NULL;
state->clearColor = (ppColor){.r = 255, .g = 0, .b = 0};
return state;
}

// Called once at the end of runtime
static void deinit(ppState *state) {
if (!state)
return;
free(state);
}

// Called whenever the app is modified and reloaded
static void reload(ppState *state) {
}

// Called just before the app is reloaded
static void unload(ppState *state) {
}

static int event(ppState *state, ppEvent *e) {
switch (e->type) {
case ppKeyboardEvent:
printf("Keyboard key %d is now %s\n", e->Keyboard.key, e->Keyboard.isdown ? "pressed" : "released");
break;
case ppMouseButtonEvent:
printf("Mouse button %d is now %s\n", e->Mouse.button, e->Mouse.isdown ? "pressed" : "released");
break;
case ppMouseMoveEvent:
printf("Mouse moved by %fx%f to %dx%d\n", e->Mouse.Position.dx, e->Mouse.Position.dy, e->Mouse.Position.x, e->Mouse.Position.y);
break;
case ppMouseScrollEvent:
printf("Mouse scrolled by %fx%f\n", e->Mouse.Scroll.dx, e->Mouse.Scroll.dy);
break;
case ppResizedEvent:
printf("Window has resized to %dx%d\n", e->Window.Size.width, e->Window.Size.height);
break;
case ppFocusEvent:
printf("Window is now %s\n", e->Window.focused ? "focused" : "blured");
break;
case ppClosedEvent:
printf("Window closed\n");
return 0;
}
return 1;
}

// Called every frame
static int tick(ppState *state, ppSurface *frame, double delta) {
ppClearSurface(frame, state->clearColor);
return 1;
}

// App descriptor to direct callbacks
// Must be called "pp" as that is the symbol that is looked up
EXPORT const ppApp pp = {
.init = init,
.deinit = deinit,
.reload = reload,
.unload = unload,
.event = event,
.tick = tick
};
Loading

0 comments on commit 6992bcc

Please sign in to comment.