changeset: 19:058d02bdbdb5
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Mon Apr 26 22:36:47 2010 +0200
files: config.def.h gi_sdl.c swk.c swk.h test.c
description:
define default window width/height in config.h
implemented vertical filler widget
option widget supports sharing widget root
visual fixes in option widget
diff -r e36d61a59af9 -r 058d02bdbdb5 config.def.h
--- a/config.def.h Mon Apr 26 00:31:30 2010 +0200
+++ b/config.def.h Mon Apr 26 22:36:47 2010 +0200
@@ -2,6 +2,8 @@
/* appearance */
#define FONTSIZE 14
+#define WINWIDTH 640
+#define WINHEIGHT 480
// SDL
#define SWK_COLOR(r,g,b) 0x##r,0x##g,0x##b
// X11
diff -r e36d61a59af9 -r 058d02bdbdb5 gi_sdl.c
--- a/gi_sdl.c Mon Apr 26 00:31:30 2010 +0200
+++ b/gi_sdl.c Mon Apr 26 22:36:47 2010 +0200
@@ -4,16 +4,6 @@
#include "swk.h"
#include "config.h"
-//#define SWK_COLOR(r,g,b) 0x##r,0x##g,0x##b
-
-#if 0
-#define HICOLOR 0x00,0x66,0xff
-#define FGCOLOR 0xff,0xff,0xff
-#define BGCOLOR 0x00,0x00,0x00
-#define TFCOLOR 0xcc,0xcc,0xcc
-#endif
-
-/* --- */
#define FONTNAME "Inconsolata.otf"
#define FS FONTSIZE
#define BPP 32
@@ -23,6 +13,9 @@
static SDL_Color fontcolor = { TFCOLOR };
static SDL_Surface *screen = NULL;
static TTF_Font *font = NULL;
+/* FIXME: put ugly statics into void *aux of SwkWindow */
+static int has_event = 0;
+static SDL_Event lastev = { .type=-1 };
static void putpixel(int x, int y, Uint32 pixel) {
int bpp = screen->format->BytesPerPixel;
@@ -33,15 +26,15 @@
#elif BPP == 16
*(Uint16 *)p = pixel;
#elif BPP == 24
- #if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[0] = (pixel >> 16) & 0xff;
- p[1] = (pixel >> 8) & 0xff;
- p[2] = pixel & 0xff;
- #else
- p[0] = pixel & 0xff;
- p[1] = (pixel >> 8) & 0xff;
- p[2] = (pixel >> 16) & 0xff;
- #endif
+# if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ p[0] = (pixel >> 16) & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = pixel & 0xff;
+# else
+ p[0] = pixel & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = (pixel >> 16) & 0xff;
+# endif
#elif BPP == 32
*(Uint32 *)p = pixel;
#endif
@@ -86,10 +79,6 @@
SDL_Quit();
}
-/* FIXME: put ugly statics into void *aux of SwkWindow */
-static int has_event = 0;
-static SDL_Event lastev = {.type=-1};
-
int
swk_gi_has_event(SwkWindow *w) {
if(!has_event)
@@ -108,6 +97,7 @@
if(has_event);
switch(event.type) {
default: ret = NULL; break;
+ case SDL_ACTIVEEVENT:
case SDL_VIDEORESIZE:
fprintf(stderr, "resize %d %d\n", event.resize.w, event.resize.h);
SDL_SetVideoMode(event.resize.w, event.resize.h, BPP, SDLFLAGS);
diff -r e36d61a59af9 -r 058d02bdbdb5 swk.c
--- a/swk.c Mon Apr 26 00:31:30 2010 +0200
+++ b/swk.c Mon Apr 26 22:36:47 2010 +0200
@@ -14,8 +14,8 @@
if (w->box == NULL)
swk_focus_first(w);
if(w->r.w == 0 || w->r.h == 0) {
- w->r.w = 640;
- w->r.h = 480;
+ w->r.w = WINWIDTH;
+ w->r.h = WINHEIGHT;
}
if(swk_gi_init(w)) {
running = 1;
@@ -66,20 +66,42 @@
btmp->r.y = y;
btmp->r.w = winc;
btmp->r.h = 1;
- x+=winc;
+ x += winc;
}
}
}
+static int
+countrows(SwkBox *b) {
+ int row = 0;
+ for(; b->cb; b++) {
+ if(b->r.w==-1&&b->r.h==-1)
+ row += (int)(size_t)b->data;
+ else row += b->r.h;
+ }
+ return row;
+}
+
void
swk_fit(SwkWindow *w) {
- int y = 0;
+ int x, y = 0;
SwkBox *b, *b2;
for(b=b2=w->boxes; b->cb; b++) {
if(b->r.w==-1 && b->r.h==-1) {
- swk_fit_row(w, b2, b, y);
- y += (int)(size_t)b->data;
- b2 = b+1;
+ x = (int)(size_t)b->data;
+ if (x>0) {
+ swk_fit_row(w, b2, b, y);
+ y += (int)(size_t)b->data;
+ b2 = b+1;
+ } else {
+ swk_fit_row(w, b2, b, y);
+ b2 = b+1;
+ y += (w->r.h-countrows(b2));
+ if (y<0) {
+ fprintf(stderr, "overflow: must scroll\n");
+ y=0;
+ }
+ }
}
}
swk_fit_row(w, b2, b, y);
@@ -298,22 +320,20 @@
void
swk_option(SwkEvent *e) {
+ SwkBox **b = (SwkBox**)e->box->data;
Rect r;
switch(e->type) {
case EClick:
- if(e->box==e->box->data)
- e->box->data = NULL;
- else e->box->data = e->box;
+ *b = (e->box==*b)?NULL:e->box;
break;
case EExpose:
r = e->box->r;
- r.w = r.h = 1;
- if(e->box==e->box->data)
- swk_gi_fill(r, ColorFG);
- else swk_gi_rect(r, ColorFG);
if(e->win->box == e->box)
swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI);
- r.x+=2;
+ r.w = r.h = 1;
+ if(e->box==*b) swk_gi_fill(r, ColorFG);
+ else swk_gi_rect(r, ColorFG);
+ r.x += 2;
swk_gi_text(r, e->box->text);
break;
default:
diff -r e36d61a59af9 -r 058d02bdbdb5 swk.h
--- a/swk.h Mon Apr 26 00:31:30 2010 +0200
+++ b/swk.h Mon Apr 26 22:36:47 2010 +0200
@@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */
#define SWK_BOX_NEWLINE(x) { .data=(void*)(size_t)x, .r.w=-1, .r.h=-1, .cb = swk_filler }
+#define SWK_BOX_VFILL(x) { .data=(void*)(size_t)x, .r.w=-1, .r.h=-2, .cb = swk_filler }
#define SWK_HIT(r,p) (p.x>=r.x && p.x<(r.x+r.w) && p.y>=r.y && p.y<(r.y+r.h))
typedef enum { EVoid, EClick, EMotion, EKey, EExpose, EQuit, ELast } SwkEventType;
diff -r e36d61a59af9 -r 058d02bdbdb5 test.c
--- a/test.c Mon Apr 26 00:31:30 2010 +0200
+++ b/test.c Mon Apr 26 22:36:47 2010 +0200
@@ -4,11 +4,15 @@
static int count = 3;
static char text[64];
static SwkBox helloworld[];
+static SwkBox *opt = NULL;
static void mybutton(SwkEvent *e) {
if (e->type == EClick) {
sprintf(text, "Do it again %d times\n", count);
helloworld[0].text = text;
+ if (opt == NULL)
+ printf("Option: none\n");
+ else printf("Option: %s\n", opt->text);
if(count-- == 0)
swk_exit();
}
@@ -25,13 +29,14 @@
{ .cb=swk_label, .text="Password:", },
{ .cb=swk_password, .text="1234", },
{ .cb=swk_filler, },
- SWK_BOX_NEWLINE(2),
+ SWK_BOX_NEWLINE(-1),
{ .cb=mybutton, .text="yes" },
{ .cb=mybutton, .text="no" },
{ .cb=swk_filler, },
+ SWK_BOX_NEWLINE(2),
+ { .cb=swk_option, .text="remember values", .data=&opt },
SWK_BOX_NEWLINE(1),
- { .cb=swk_option, .text="remember values", },
- { .cb=swk_option, .text="pasta barata", },
+ { .cb=swk_option, .text="pasta barata", .data=&opt },
SWK_BOX_NEWLINE(5),
{ .cb=swk_label, .text="--swktest", },
{ .cb=NULL }
@@ -42,7 +47,8 @@
SwkWindow w = {
.title="Hello World",
.boxes=helloworld,
- .box=helloworld+10
+ .box=helloworld+10,
+ //.r = { 0, 0, 320, 240 },
/*
// TODO: application workflow
.ok=cb
Received on Mon Apr 26 2010 - 20:43:36 UTC
This archive was generated by hypermail 2.2.0 : Mon Apr 26 2010 - 20:48:04 UTC