swk

static widget kit
git clone git://git.suckless.org/swk
Log | Files | Refs | README | LICENSE

commit 8b8592e0ddfbb6cf903fecd4de0bcb068c555a7d
parent cac13702568e9a19cc3ac3dd3c5141ba6e9f53d4
Author: pancake <pancake@nopcode.org>
Date:   Fri,  7 May 2010 02:16:32 +0200

initial working drawing for swk_sketch()
fix sketch inner surface boundaries
Diffstat:
gi_sdl.c | 6++++--
swk.c | 11+++++++----
test.c | 4++--
3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/gi_sdl.c b/gi_sdl.c @@ -283,13 +283,15 @@ void swk_gi_img(Rect r, void *img) { SDL_Surface *s = (SDL_Surface*)img; SDL_Rect area = { r.x*fs, r.y*fs, r.w*fs, r.h*fs }; + area.x++; + area.y++; if(s) SDL_BlitSurface(s, NULL, screen, &area); } /* image api */ void* swk_gi_img_new(int w, int h, int color) { - return SDL_CreateRGBSurface(NULL, w, h, BPP, 0, 0, 0, 0); + return SDL_CreateRGBSurface(NULL, (w*fs)-2, (h*fs)-2, BPP, 0, 0, 0, 0); } void* @@ -304,7 +306,7 @@ swk_gi_img_free(void *s) { void swk_gi_img_set(void *img, int x, int y, int color) { - if(img) putpixel((SDL_Surface*)img, x, y, color); + if(img) putpixel((SDL_Surface*)img, x, y, pal[color]); } int diff --git a/swk.c b/swk.c @@ -479,18 +479,21 @@ swk_image(SwkEvent *e) { void swk_sketch(SwkEvent *e) { + int x, y; if(e->box->data == NULL) e->box->data = swk_gi_img_new(e->box->r.w, e->box->r.h, ColorHI); switch(e->type) { case EClick: - swk_gi_img_set(e->box->data, - e->data.click.point.x, e->data.click.point.y, - ColorFG); + // TODO: implement low-level primitives for pixel-level rendering + for(x=y=5;x<10;x=++y) + swk_gi_img_set(e->box->data, x, y, ColorFG); + for(x=y=5;x<10;x++,y--) + swk_gi_img_set(e->box->data, x, y, ColorFG); printf("CLICKED %p %d %d\n", e->box->data, e->data.click.point.x, e->data.click.point.y); break; case EExpose: + swk_gi_rect(e->box->r, ColorHI); // border swk_gi_img(e->box->r, e->box->data); - swk_gi_rect(e->box->r, ColorFG); break; default: break; diff --git a/test.c b/test.c @@ -90,9 +90,9 @@ static SwkBox helloworld[] = { { .cb=swk_label, .text="Password:", }, { .cb=swk_password, .text="1234", }, SWK_BOX_NEWLINE(-1), - { .cb=swk_filler, }, + { .cb=swk_label, .text="Click here ->" }, { .cb=swk_sketch }, - SWK_BOX_NEWLINE(1), + SWK_BOX_NEWLINE(2), { .cb=swk_image, .text="image.png" }, { .cb=swk_image, .text="image.png" }, { .cb=swk_image, .text="image.png" },