[hackers] [swk] initial working drawing for swk_sketch() || pancake

From: <hg_AT_suckless.org>
Date: Fri, 7 May 2010 00:22:45 +0000 (UTC)

changeset: 37:6b7c7ff59643
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Fri May 07 02:16:32 2010 +0200
files: gi_sdl.c swk.c test.c
description:
initial working drawing for swk_sketch()
fix sketch inner surface boundaries

diff -r 040fd95e2e0e -r 6b7c7ff59643 gi_sdl.c
--- a/gi_sdl.c Fri May 07 01:29:55 2010 +0200
+++ b/gi_sdl.c Fri May 07 02:16:32 2010 +0200
@@ -283,13 +283,15 @@
 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 @@
 
 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 -r 040fd95e2e0e -r 6b7c7ff59643 swk.c
--- a/swk.c Fri May 07 01:29:55 2010 +0200
+++ b/swk.c Fri May 07 02:16:32 2010 +0200
@@ -479,18 +479,21 @@
 
 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 -r 040fd95e2e0e -r 6b7c7ff59643 test.c
--- a/test.c Fri May 07 01:29:55 2010 +0200
+++ b/test.c Fri May 07 02:16:32 2010 +0200
@@ -90,9 +90,9 @@
         { .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" },
Received on Fri May 07 2010 - 00:22:45 UTC

This archive was generated by hypermail 2.2.0 : Fri May 07 2010 - 00:24:03 UTC