changeset: 13:d85874fa79cf
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Wed Apr 21 14:21:54 2010 +0200
files: gi_sdl.c swk.c swk.h
description:
default colors from dwm by default
use bold font in sdl backend
do not render empty text
fix mouse over widget focus
diff -r 477047c05136 -r d85874fa79cf gi_sdl.c
--- a/gi_sdl.c Wed Apr 21 12:22:34 2010 +0200
+++ b/gi_sdl.c Wed Apr 21 14:21:54 2010 +0200
@@ -2,12 +2,11 @@
#include <SDL/SDL_ttf.h>
#include "swk.h"
-#define HICOLOR 0xa0,0x00,0x00
-#define FGCOLOR 0xa0,0xa0,0xa0
+#define HICOLOR 0x00,0x66,0xff
+#define FGCOLOR 0xff,0xff,0xff
#define BGCOLOR 0x00,0x00,0x00
-#define TFCOLOR 0xff,0xff,0xff
+#define TFCOLOR 0xcc,0xcc,0xcc
#define FONTNAME "Inconsolata.otf"
-//#define FONTSIZE 16
#define FONTSIZE 14
#define FS FONTSIZE
#define BPP 32
@@ -63,7 +62,7 @@
if (font == NULL) {
fprintf(stderr, "Cannot open font '%s'\n", FONTNAME);
return 0;
- } //else TTF_SetFontStyle(font, TTF_STYLE_BOLD);
+ } else TTF_SetFontStyle(font, TTF_STYLE_BOLD);
return 1;
}
@@ -98,9 +97,8 @@
static SwkEvent ev;
SwkEvent *ret = NULL;
- if(has_event) {
- event = lastev;
- } else has_event = SDL_WaitEvent(&event);
+ if(has_event) event = lastev;
+ else has_event = SDL_WaitEvent(&event);
if (has_event);
switch(event.type) {
@@ -197,10 +195,12 @@
void
swk_gi_text(int x, int y, const char *text) {
- SDL_Surface *ts = TTF_RenderText_Solid(font, text, fontcolor);
- if (ts) {
- SDL_Rect to = { x*FS, y*FS, ts->w, ts->h };
- SDL_BlitSurface(ts, NULL, screen, &to);
- SDL_FreeSurface(ts);
- } else fprintf(stderr, "Cannot render string (%s)\n", text);
+ if (*text) {
+ SDL_Surface *ts = TTF_RenderText_Solid(font, text, fontcolor);
+ if (ts) {
+ SDL_Rect to = { x*FS, y*FS, ts->w, ts->h };
+ SDL_BlitSurface(ts, NULL, screen, &to);
+ SDL_FreeSurface(ts);
+ } else fprintf(stderr, "Cannot render string (%s)\n", text);
+ }
}
diff -r 477047c05136 -r d85874fa79cf swk.c
--- a/swk.c Wed Apr 21 12:22:34 2010 +0200
+++ b/swk.c Wed Apr 21 14:21:54 2010 +0200
@@ -11,11 +11,11 @@
swk_init(SwkWindow* window) {
w = window;
w->box = w->boxes;
- if (w->r.w == 0 || w->r.h == 0) {
+ if(w->r.w == 0 || w->r.h == 0) {
w->r.w = 640;
w->r.h = 480;
}
- if (swk_gi_init(w)) {
+ if(swk_gi_init(w)) {
running = 1;
swk_update();
}
@@ -25,9 +25,10 @@
void
swk_update() {
SwkEvent ev = { .type = EExpose };
- if (swk_gi_update(w)) {
+ if(swk_gi_update(w)) {
SwkBox *b = w->boxes;
swk_fit();
+ swk_gi_clear();
for(;b->cb; b++) {
ev.box = b;
b->cb(&ev);
@@ -45,7 +46,7 @@
swk_loop() {
SwkEvent *e;
do {
- if ((e = swk_event(1)))
+ if((e = swk_event(1)))
swk_event_handle(e);
} while (!e || e->type != EQuit);
}
@@ -56,7 +57,7 @@
count = 0;
for(btmp=a; btmp<b; btmp++)
count++;
- if (count) {
+ if(count) {
int winc = w->r.w / count;
for(btmp=a; btmp<b; btmp++) {
btmp->r.x = x;
@@ -85,7 +86,7 @@
SwkEvent *
swk_event(int dowait) {
static SwkEvent ev;
- if (running)
+ if(running)
return swk_gi_event();
ev.type = EQuit;
return &ev;
@@ -96,25 +97,26 @@
SwkBox *b;
switch(e->type) {
case EKey:
- if (e->data.key.keycode == 9) { // TAB
- if (e->data.key.modmask)
+ // TODO: handle ^Y and ^P to copypasta box->text
+ if(e->data.key.keycode == 9) { // TAB
+ if(e->data.key.modmask)
swk_focus_prev();
else swk_focus_next();
swk_update();
} else
- if (e->data.key.keycode == 13) { // ENTER
+ if(e->data.key.keycode == 13) { // ENTER
e->box = w->box;
e->type = EClick;
}
// send key to focused box
e->box = w->box;
- if (w->box)
+ if(w->box)
w->box->cb(e);
swk_update();
break;
case EMotion:
for(b=w->boxes; b->cb; b++) {
- if (SWK_HIT(b->r, e->data.click.point)) {
+ if(SWK_HIT(b->r, e->data.motion)) {
w->box = e->box = b;
b->cb(e);
swk_update();
@@ -124,7 +126,7 @@
break;
case EClick:
for(b=w->boxes; b->cb; b++) {
- if (SWK_HIT(b->r, e->data.click.point)) {
+ if(SWK_HIT(b->r, e->data.click.point)) {
e->box = w->box = b;
e->box->cb(e);
swk_update();
@@ -145,7 +147,7 @@
void
swk_focus_next() {
w->box++;
- if (w->box->cb == NULL)
+ if(w->box->cb == NULL)
w->box = w->boxes;
while(w->box->cb == swk_filler)
w->box++;
@@ -155,7 +157,7 @@
void
swk_focus_prev() {
- if (w->box == w->boxes) {
+ if(w->box == w->boxes) {
while(w->box->cb)
w->box++;
w->box--;
@@ -163,7 +165,7 @@
w->box--;
while (w->box->cb == swk_filler) {
w->box--;
- if (w->box < w->boxes) {
+ if(w->box < w->boxes) {
w->box = w->boxes;
swk_focus_prev();
return;
@@ -179,7 +181,7 @@
switch(e->type) {
case EExpose:
r = e->box->r;
- if (w->box == e->box)
+ if(w->box == e->box)
swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI);
swk_gi_text(r.x, r.y, e->box->text);
break;
@@ -195,7 +197,7 @@
switch(e->type) {
case EKey:
key = e->data.key.keycode;
- if (key==8) {
+ if(key == 8) {
ptr = strdup (e->box->text);
if(e->box->data)
free(e->box->text);
@@ -222,7 +224,7 @@
switch(e->type) {
case EExpose:
r = e->box->r;
- if (w->box == e->box)
+ if(w->box == e->box)
swk_gi_rect(r.x, r.y, r.w, r.h, ColorHI);
else swk_gi_rect(r.x, r.y, r.w, r.h, ColorFG);
swk_gi_text(r.x+1, r.y, e->box->text);
diff -r 477047c05136 -r d85874fa79cf swk.h
--- a/swk.h Wed Apr 21 12:22:34 2010 +0200
+++ b/swk.h Wed Apr 21 14:21:54 2010 +0200
@@ -61,14 +61,12 @@
} SwkWindow;
int swk_init(SwkWindow *w);
-int swk_gi_update(SwkWindow *w);
void swk_update();
void swk_exit();
void swk_fit();
void swk_loop();
SwkEvent * swk_event();
void swk_event_handle(SwkEvent *e);
-int swk_gi_has_event();
void swk_focus_next();
void swk_focus_prev();
@@ -83,7 +81,10 @@
int swk_gi_init(SwkWindow *w);
void swk_gi_exit();
SwkEvent * swk_gi_event();
+int swk_gi_update(SwkWindow *w);
+int swk_gi_has_event();
+void swk_gi_clear();
void swk_gi_flip();
void swk_gi_line(int x, int y, int w, int h, int color);
Received on Wed Apr 21 2010 - 12:28:25 UTC
This archive was generated by hypermail 2.2.0 : Wed Apr 21 2010 - 12:36:04 UTC