commit c21b9fa32913daf46b34b7e72e2ca6567c4a1d14
parent a59801efe90825ed51b87867f6cdb8406b707dd6
Author: Anselm R Garbe <anselm@garbe.us>
Date: Tue, 20 Apr 2010 00:29:19 +0100
added pancakes stuff
Diffstat:
app1.c | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
app2.c | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
gi_sdl.c | | | 12 | ++---------- |
swk.c | | | 10 | ---------- |
swk.h | | | 2 | +- |
test.c | | | 7 | ++++++- |
6 files changed, 89 insertions(+), 22 deletions(-)
diff --git a/app1.c b/app1.c
@@ -0,0 +1,40 @@
+void (*swkhandler)(SwkWidget *, SwkEvent *);
+
+void onclick(SwkWidget *w);
+
+SwkTextField t = {
+ SwkTypeTextField,
+ "enter some text",
+ NULL
+};
+SwkButton b = {
+ SwkTypeButton,
+ "OK",
+ NULL
+};
+SwkWin w = {
+ SwkTypeWin,
+ { &t, &b, NULL }
+};
+
+void onclick(SwkWidget *w) {
+ static int clicks = 0;
+ SwkButton *b = (SwkButton *)w;
+ fprintf(stdout, "onclick: %s\n", t.data);
+ if(++clicks == 10)
+ swk_exit();
+}
+
+static void myhandler(SwkWidget *w, SwkEvent *e) {
+ if(e->type == SWK_CLICK && w->type == SwkTypeButton)
+ onclick(w);
+ else /* fallback */
+ swkhandler(w, e);
+}
+
+int main() {
+ swk_init(&w);
+ swkhandler = swk_set_handler(myhandler);
+ swk_loop(NULL); // loops until swk_exit() is called
+ return 0;
+}
diff --git a/app2.c b/app2.c
@@ -0,0 +1,40 @@
+void (*swkhandler)(SwkWidget *, SwkEvent *);
+
+void onclick(SwkWidget *w);
+
+SwkTextField t = {
+ SwkTypeTextField,
+ "enter some text",
+ NULL
+};
+SwkButton b = {
+ SwkTypeButton,
+ "OK",
+ NULL
+};
+SwkWin w = {
+ SwkTypeWin,
+ { &t, &b, NULL }
+};
+
+void onclick(SwkWidget *w) {
+ static int clicks = 0;
+ SwkButton *b = (SwkButton *)w;
+ fprintf(stdout, "onclick: %s\n", t.data);
+ if(++clicks == 10)
+ swk_exit();
+}
+
+static void myhandler(SwkWidget *w, SwkEvent *e) {
+ if(e->type == SWK_CLICK && w->type == SwkTypeButton)
+ onclick(w);
+ else /* fallback */
+ swkhandler(w, e);
+}
+
+int main() {
+ swk_init(&w);
+ swkhandler = swk_set_handler(myhandler);
+ swk_loop(NULL); // loops until swk_exit() is called
+ return 0;
+}
diff --git a/gi_sdl.c b/gi_sdl.c
@@ -21,15 +21,12 @@ swk_gi_exit() {
static char sdlkeys[256] = { 0 }; // TODO
SwkEvent *
-swk_event(int lock) {
- int evret;
+swk_event() {
SDL_Event event;
static SwkEvent ev;
SwkEvent *ret = NULL;
- if (lock) evret = SDL_WaitEvent(&event);
- else evret = SDL_PollEvent(&event);
- if (evret) {
+ if(SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
ret = &ev;
@@ -46,11 +43,6 @@ swk_event(int lock) {
event.key.keysym.mod & KMOD_RMETA)
ev.data.key.modmask |= Meta;
break;
- case SDL_MOUSEBUTTONDOWN:
- ret = &ev;
- ev.type = EClick;
- //ev.data.click.button =
- break;
case SDL_QUIT:
ev.type = ev.type = EQuit;
ret = &ev;
diff --git a/swk.c b/swk.c
@@ -22,16 +22,6 @@ swk_fit() {
}
void
-swk_loop() {
- SwkEvent *e;
- do {
- if ((e = swk_event(1)))
- swk_event_handle(e);
- } while (!e || e->type != EQuit);
- swk_exit();
-}
-
-void
swk_event_handle(SwkEvent *e) {
switch(e->type) {
case EKey:
diff --git a/swk.h b/swk.h
@@ -63,7 +63,7 @@ typedef struct {
int swk_init(SwkWindow *w);
void swk_exit();
void swk_fit();
-SwkEvent * swk_event(int lock);
+SwkEvent * swk_event();
void swk_event_handle(SwkEvent *e);
void swk_focus_next();
diff --git a/test.c b/test.c
@@ -11,6 +11,7 @@ static SwkBox helloworld[] = {
int
main() {
+ SwkEvent *e;
SwkWindow w = {
.title="Hello World",
.boxes=helloworld
@@ -18,6 +19,10 @@ main() {
if (!swk_init(&w))
return 1;
- swk_loop();
+ do {
+ if ((e = swk_event()))
+ swk_event_handle(e);
+ } while (!e || e->type != EQuit);
+ swk_exit();
return 0;
}