[hackers] [swk] * Fix click/scroll event handling || pancake

From: <hg_AT_suckless.org>
Date: Wed, 5 May 2010 10:07:00 +0000 (UTC)

changeset: 32:0858a9652eee
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Wed May 05 11:12:02 2010 +0200
files: README config.def.h gi_sdl.c
description:
* Fix click/scroll event handling
* Use constants in putpixel (reduce LOC and complexity)
  - Remove useless space chars
* Minor cleanup for config.def.h
  - remove N900 stuff, drop bold fonts

diff -r 37c83bbb01dc -r 0858a9652eee README
--- a/README Thu Apr 29 00:08:08 2010 +0200
+++ b/README Wed May 05 11:12:02 2010 +0200
@@ -1,7 +1,10 @@
 SWK - simple widget kit
 =======================
+On ArchLinunx:
+ pacman -S sdl sdl_ttf sdl_image
 
- pacman -S sdl sdl_ttf sdl_image
+On Debian/Ubuntu:
+ apt-get install libsdl-dev libsdl-ttf libsdl-image
 
 Usability guideline
 ===================
@@ -12,10 +15,10 @@
 * support for clipboard (implemented in gi_ backend)
 * simple way to define callback for buttons instead of reimplementing widget
 * scroll on focus
-* mouse bindings
-* allow widgets to define their boundaries to force size
-* add support to resize images
-* only focus buttons and entries
+* mouse bindings in config.h
+* allow widgets to define to force size (height, width)
+* add support to resize images (scaling)
+* only focus buttons and entries (input widgets)
 * add function to click button 1, 2, 3, ...
 * allow to load images from memory instead of files
 * default image path
diff -r 37c83bbb01dc -r 0858a9652eee config.def.h
--- a/config.def.h Thu Apr 29 00:08:08 2010 +0200
+++ b/config.def.h Wed May 05 11:12:02 2010 +0200
@@ -1,14 +1,8 @@
 /* See LICENSE file for copyright and license details. */
 
-//#define N900
-#ifdef N900
-#define FONTSIZE 32
-#else
+/* appearance */
 #define FONTSIZE 28
-#endif
-
-/* appearance */
-#define FONTBOLD 1
+#define FONTBOLD 0
 #define WINWIDTH 640
 #define WINHEIGHT 480
 // SDL
@@ -23,22 +17,22 @@
 
 /* key bindings */
 static SwkKeyBind keys[] = {
- { Ctrl, 'j', swk_focus_next },
- { Ctrl, 'k', swk_focus_prev },
- { Ctrl, 8 , swk_focus_first },
- { Ctrl, 9 , swk_focus_prev },
- { 0 , 9 , swk_focus_next },
- { Ctrl, 10 , swk_focus_next },
- { Ctrl, 11 , swk_focus_prev },
- { Ctrl, 12 , swk_focus_activate },
- { 0, 225, swk_focus_activate }, // n900 enter
- { 0 , KUp, swk_focus_prev },
+ { Ctrl, 'j', swk_focus_next },
+ { Ctrl, 'k', swk_focus_prev },
+ { Ctrl, 8 , swk_focus_first },
+ { Ctrl, 9 , swk_focus_prev },
+ { 0 , 9 , swk_focus_next },
+ { Ctrl, 10 , swk_focus_next },
+ { Ctrl, 11 , swk_focus_prev },
+ { Ctrl, 12 , swk_focus_activate },
+ { 0, 225 , swk_focus_activate }, // n900 return
+ { 0 , KUp, swk_focus_prev },
         { 0 , KDown, swk_focus_next },
- { 0 , 13 , swk_focus_activate },
- { Ctrl, 12 , swk_focus_activate },
+ { 0 , 13 , swk_focus_activate },
+ { Ctrl, 12 , swk_focus_activate },
         { Ctrl|Shift, 10, swk_scroll_down },
         { Ctrl|Shift, 11, swk_scroll_up },
- { Ctrl, '+', swk_fontsize_increase },
- { Ctrl, '-', swk_fontsize_decrease },
+ { Ctrl, '+', swk_fontsize_increase },
+ { Ctrl, '-', swk_fontsize_decrease },
         { 0 }
 };
diff -r 37c83bbb01dc -r 0858a9652eee gi_sdl.c
--- a/gi_sdl.c Thu Apr 29 00:08:08 2010 +0200
+++ b/gi_sdl.c Wed May 05 11:12:02 2010 +0200
@@ -16,34 +16,31 @@
 static SDL_Color bgcolor = { BGCOLOR };
 static SDL_Surface *screen = NULL;
 static TTF_Font *font = NULL;
-/* FIXME: put ugly statics into void *aux of SwkWindow */
+/* FIXME: put ugly statics into void *aux of SwkWindow ? */
 static int has_event = 0;
 static SDL_Event lastev = { .type=-1 };
 
 static void putpixel(SDL_Surface *scr, int x, int y, Uint32 pixel) {
- Uint8 *p, *pend;
- int delta, bpp = scr->format->BytesPerPixel;
- delta = y * scr->pitch + x * bpp;
- p = (Uint8 *)scr->pixels + delta;
- pend = (Uint8 *)scr->pixels + (scr->h*scr->w*bpp);
+ Uint8 *p = (Uint8 *)scr->pixels + (y*scr->pitch+x*(BPP/8));
+ Uint8 *pend = (Uint8 *)scr->pixels + (scr->h*scr->w*(BPP/8));
         if((p<((Uint8 *)scr->pixels)) || (p>=pend))
                 return;
 #if BPP == 8
- *p = pixel;
+ *p = pixel;
 #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;
+ 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;
+ p[0] = pixel & 0xff;
+ p[1] = (pixel >> 8) & 0xff;
+ p[2] = (pixel >> 16) & 0xff;
 # endif
 #elif BPP == 32
- *(Uint32 *)p = pixel;
+ *(Uint32 *)p = pixel;
 #endif
 }
 
@@ -108,6 +105,7 @@
 SwkEvent *
 swk_gi_event(SwkWindow *w, int dowait) {
         static int mousedowny, mousedown = 0;
+ static int mousemoved = 0;
         SDL_Event event;
         SwkEvent *ret = &w->_e;
 
@@ -138,6 +136,9 @@
                                 swk_scroll_down(w);
                                 swk_scroll_down(w);
                         }
+ ret->type = EExpose;
+ ret->data.expose.x = ret->data.expose.y = \
+ ret->data.expose.w = ret->data.expose.h = 0;
                 } else {
                         ret->type = EMotion;
                         ret->data.motion.x = event.motion.x / fs;
@@ -146,15 +147,18 @@
                 break;
         case SDL_MOUSEBUTTONUP:
                 mousedown = 0;
+ if(!mousemoved) {
+ fprintf(stderr, "event: click %d\n", event.button.button);
+ ret->type = EClick;
+ ret->data.click.button = event.button.button;
+ ret->data.click.point.x = event.button.x / fs;
+ ret->data.click.point.y = event.button.y / fs;
+ }
                 break;
         case SDL_MOUSEBUTTONDOWN:
+ mousemoved = 0;
                 mousedown = 1;
                 mousedowny = event.button.y;
- fprintf(stderr, "event: click %d\n", event.button.button);
- ret->type = EClick;
- ret->data.click.button = event.button.button;
- ret->data.click.point.x = event.button.x / fs;
- ret->data.click.point.y = event.button.y / fs;
                 break;
         case SDL_KEYDOWN:
                 ret->data.key.modmask = 0;
@@ -173,7 +177,7 @@
                                 ret->data.key.modmask, ret->data.key.keycode);
                 } else {
                         // TODO key aliases defined in config.h
- switch(event.key.keysym.sym) {
+ switch((int)event.key.keysym.sym) {
                         case 1073741906: // n900 up key
                         case 273:
                                 ret->data.key.keycode = KUp;
@@ -189,7 +193,7 @@
                 }
                 break;
         case SDL_QUIT:
- ret->type = ret->type = EQuit;
+ ret->type = EQuit;
                 break;
         }
         has_event = 0;
@@ -210,7 +214,6 @@
 }
 
 /* -- drawing primitives -- */
-
 void
 swk_gi_line(int x1, int y1, int x2, int y2, int color) {
         int i;
@@ -268,7 +271,7 @@
 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 };
- if (s) SDL_BlitSurface(s, NULL, screen, &area);
+ if(s) SDL_BlitSurface(s, NULL, screen, &area);
 }
 
 void*
@@ -284,7 +287,7 @@
 void
 swk_gi_img_set(void *img, int x, int y, int color) {
         SDL_Surface *s = (SDL_Surface*)img;
- if (s) putpixel(s, x, y, color);
+ if(s) putpixel(s, x, y, color);
 }
 
 int
Received on Wed May 05 2010 - 10:07:00 UTC

This archive was generated by hypermail 2.2.0 : Wed May 05 2010 - 10:12:03 UTC