[hackers] [swk] fix cursor in swk_entry with some ugly hacks || pancake

From: <hg_AT_suckless.org>
Date: Tue, 24 Aug 2010 20:09:38 +0000 (UTC)

changeset: 64:39801049cfcd
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Tue Aug 24 22:06:11 2010 +0200
files: Makefile gi_sdl.c gi_x11.c swk.c t/test.c
description:
fix cursor in swk_entry with some ugly hacks
use USE_X11 and USE_SDL defines
fix error message when cannot open images
add 'close' button in scrollwin screen of test.c

diff -r cda24b52df4a -r 39801049cfcd Makefile
--- a/Makefile Tue Aug 24 19:04:00 2010 +0200
+++ b/Makefile Tue Aug 24 22:06:11 2010 +0200
@@ -7,9 +7,11 @@
 GI?=sdl
 ifeq (${GI},sdl)
 GI_LIBS=-lSDL -lSDL_ttf -lSDL_image
+CFLAGS+=-DUSE_SDL
 else
 ifeq (${GI},x11)
 GI_LIBS=-lX11 -ldraw
+CFLAGS+=-DUSE_X11
 endif
 endif
 
diff -r cda24b52df4a -r 39801049cfcd gi_sdl.c
--- a/gi_sdl.c Tue Aug 24 19:04:00 2010 +0200
+++ b/gi_sdl.c Tue Aug 24 22:06:11 2010 +0200
@@ -13,7 +13,7 @@
 #define SDLFLAGS SDL_DOUBLEBUF|SDL_RESIZABLE
 
 static int first = 1;
-static int fs = FONTSIZE; // TODO: we need fsW and fsH
+static int fs = FONTSIZE;
 static Uint32 pal[ColorLast];
 static SDL_Color fontcolor = { TFCOLOR };
 static SDL_Color bgcolor = { BGCOLOR };
@@ -245,12 +245,17 @@
 void
 swk_gi_fill(Rect r, int color, int lil) {
         SDL_Rect area = { r.x*fs, r.y*fs, r.w*fs, r.h*fs };
- if(lil) {
+ if(lil==1) {
                 const int s = fs/4;
                 area.x += s;
                 area.y += s;
                 area.w -= (s*2);
                 area.h -= (s*2);
+ } else if (lil==2) {
+ area.x/=4;
+ area.y+=4;
+ area.w/=4;
+ area.h-=4;
         }
         if(!area.w) area.w = 1;
         if(!area.h) area.h = 1;
diff -r cda24b52df4a -r 39801049cfcd gi_x11.c
--- a/gi_x11.c Tue Aug 24 19:04:00 2010 +0200
+++ b/gi_x11.c Tue Aug 24 22:06:11 2010 +0200
@@ -211,12 +211,18 @@
 void
 swk_gi_fill(Rect r, int color, int lil) {
         XRectangle area = { r.x*fs, r.y*fs, r.w*fs, r.h*fs };
- if(lil) {
+ if(lil==1) {
                 int s = fs/4;
                 area.x += s;
                 area.y += s;
                 area.width -= (s*2);
                 area.height -= (s*2);
+ } else
+ if(lil==2) {
+ area.x/=3;
+ area.width/=4;
+ area.y+=4;
+ area.height-=4;
         }
         if(area.width<1) area.width = 1;
         if(area.height<1) area.height = 1;
diff -r cda24b52df4a -r 39801049cfcd swk.c
--- a/swk.c Tue Aug 24 19:04:00 2010 +0200
+++ b/swk.c Tue Aug 24 22:06:11 2010 +0200
@@ -394,10 +394,18 @@
                 break;
         case EExpose:
                 // XXX: add support for cursor (handle arrow keys)
- len = strlen(e->box->text);
- len += e->box->r.x;
+ #ifdef USE_SDL
+ len = 4*e->box->r.x;
+ len += 2*strlen(e->box->text)+1;
+ #else
+ len = 3*e->box->r.x;
+ len += strlen(e->box->text)+1;
+ #endif
                 swk_label(e);
- swk_gi_line(len, e->box->r.y, 0, 1, ColorFG);
+ {
+ Rect r = {len, e->box->r.y, 1, 1 };
+ swk_gi_fill(r, ColorFG, 2);
+ }
                 break;
         }
 }
@@ -522,12 +530,12 @@
 swk_image(SwkEvent *e) {
         if(e->box->data == NULL) {
                 e->box->data = swk_gi_img_load(e->box->text);
- if(e->box->data)
+ if(!e->box->data)
                         fprintf(stderr, "Cannot find image %s\n", e->box->text);
         }
         switch(e->type) {
         case EExpose:
- swk_gi_rect(e->box->r, BORDERCOLOR);
+ swk_gi_rect(e->box->r, ColorFG);
                 if(e->win->box == e->box) {
                         Rect r = e->box->r;
                         swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI);
diff -r cda24b52df4a -r 39801049cfcd t/test.c
--- a/t/test.c Tue Aug 24 19:04:00 2010 +0200
+++ b/t/test.c Tue Aug 24 22:06:11 2010 +0200
@@ -79,10 +79,19 @@
         swk_button(e);
 }
 
+static void mybutton_close(SwkEvent *e) {
+ if(e->type == EClick) {
+ e->win->boxes[e->win->col] = helloworld;
+ swk_update(e->win);
+ }
+ swk_button(e);
+}
+
 static SwkBox scrollwin[] = {
         SWK_BOX_NEWLINE(0),
         { .cb=swk_label, .text="Scroll to change value", },
         SWK_BOX_NEWLINE(1),
+ { .cb=mybutton_close, .text="Close" },
         { .cb=swk_separator },
         SWK_BOX_NEWLINE(1),
         { .cb=swk_label, .text=" /etc" },
Received on Tue Aug 24 2010 - 22:09:38 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 24 2010 - 22:12:04 CEST