changeset: 5:fcdc9b71b256
tag: tip
user: Anselm R Garbe <anselm_AT_garbe.us>
date: Tue Apr 20 00:29:19 2010 +0100
files: app1.c app2.c gi_sdl.c swk.c swk.h test.c
description:
added pancakes stuff
diff -r 04b91f1e957e -r fcdc9b71b256 app1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app1.c Tue Apr 20 00:29:19 2010 +0100
@@ -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 -r 04b91f1e957e -r fcdc9b71b256 app2.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app2.c Tue Apr 20 00:29:19 2010 +0100
@@ -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 -r 04b91f1e957e -r fcdc9b71b256 gi_sdl.c
--- a/gi_sdl.c Tue Apr 20 01:20:37 2010 +0200
+++ b/gi_sdl.c Tue Apr 20 00:29:19 2010 +0100
@@ -21,15 +21,12 @@
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 @@
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 -r 04b91f1e957e -r fcdc9b71b256 swk.c
--- a/swk.c Tue Apr 20 01:20:37 2010 +0200
+++ b/swk.c Tue Apr 20 00:29:19 2010 +0100
@@ -22,16 +22,6 @@
}
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 -r 04b91f1e957e -r fcdc9b71b256 swk.h
--- a/swk.h Tue Apr 20 01:20:37 2010 +0200
+++ b/swk.h Tue Apr 20 00:29:19 2010 +0100
@@ -63,7 +63,7 @@
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 -r 04b91f1e957e -r fcdc9b71b256 test.c
--- a/test.c Tue Apr 20 01:20:37 2010 +0200
+++ b/test.c Tue Apr 20 00:29:19 2010 +0100
@@ -11,6 +11,7 @@
int
main() {
+ SwkEvent *e;
SwkWindow w = {
.title="Hello World",
.boxes=helloworld
@@ -18,6 +19,10 @@
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;
}
Received on Mon Apr 19 2010 - 23:29:22 UTC
This archive was generated by hypermail 2.2.0 : Mon Apr 19 2010 - 23:36:04 UTC