From commit at keithp.com Fri Oct 1 12:58:56 2004 From: commit at keithp.com (Bart Massey) Date: Fri Oct 1 12:59:02 2004 Subject: [Commit] nickle compile.c,1.158,1.159 Message-ID: Committed by: bart Update of /local/src/CVS/nickle In directory home.keithp.com:/tmp/cvs-serv23538 Modified Files: compile.c Log Message: Compiler dumped core when trying to create a variable of incomplete structure type. Index: compile.c =================================================================== RCS file: /local/src/CVS/nickle/compile.c,v retrieving revision 1.158 retrieving revision 1.159 diff -u -d -r1.158 -r1.159 --- compile.c 7 Jul 2004 07:32:47 -0000 1.158 +++ compile.c 1 Oct 2004 19:58:54 -0000 1.159 @@ -419,9 +419,13 @@ } static TypePtr -CompileRefType (TypePtr t) +CompileRefType (ObjPtr obj, ExprPtr expr, TypePtr t) { t = TypeCanon (t); + if (!t) { + CompileError(obj, expr, "reference to incomplete type"); + return 0; + } if (t->base.tag == type_ref && !t->ref.pointer) return t->ref.ref; @@ -622,7 +626,7 @@ } if (flipTypes) { - t = CompileRefType (expr->base.type); + t = CompileRefType (obj, expr, expr->base.type); if (amper) { if (t) @@ -2237,7 +2241,7 @@ if (!inst) break; expr->base.type = s->symbol.type; - t = CompileRefType (expr->base.type); + t = CompileRefType (obj, expr, expr->base.type); if (t) { BuildInst (obj, OpUnFunc, inst, stat); @@ -2412,7 +2416,7 @@ } BuildInst (obj, OpDot, inst, stat); inst->atom.atom = expr->tree.right->atom.atom; - t = CompileRefType (expr->base.type); + t = CompileRefType (obj, expr, expr->base.type); if (t) { BuildInst (obj, OpUnFunc, inst, stat); @@ -2435,7 +2439,7 @@ } BuildInst (obj, OpArrow, inst, stat); inst->atom.atom = expr->tree.right->atom.atom; - t = CompileRefType (expr->base.type); + t = CompileRefType (obj, expr, expr->base.type); if (t) { BuildInst (obj, OpUnFunc, inst, stat); @@ -2452,7 +2456,7 @@ case AMPER: obj = CompileLvalue (obj, expr->tree.left, stat, code, False, False, False, False, True); - t = CompileRefType (expr->tree.left->base.type); + t = CompileRefType (obj, expr->tree.left, expr->tree.left->base.type); if (!t) t = expr->tree.left->base.type; expr->base.type = NewTypeRef (t, True); @@ -4064,7 +4068,7 @@ lvalue = NewExprAtom (decl->name, decl->symbol, False); *initObj = CompileLvalue (*initObj, lvalue, decls, code, False, True, True, - CompileRefType (s->symbol.type) != 0, + CompileRefType (obj, lvalue, s->symbol.type) != 0, False); SetPush (*initObj); *initObj = CompileInit (*initObj, init, s->symbol.type, stat, code); From commit at keithp.com Fri Oct 1 20:07:29 2004 From: commit at keithp.com (Keith Packard) Date: Fri Oct 1 20:07:36 2004 Subject: [Commit] twin ChangeLog, 1.13, 1.14 twin.h, 1.10, 1.11 twin_fixed.c, 1.2, 1.3 twin_font.c, 1.9, 1.10 twin_path.c, 1.7, 1.8 twin_poly.c, 1.6, 1.7 twin_screen.c, 1.3, 1.4 twin_x11.c, 1.2, 1.3 twin_x11.h, 1.1, 1.2 twinint.h, 1.8, 1.9 xtwin.c, 1.12, 1.13 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv4064 Modified Files: ChangeLog twin.h twin_fixed.c twin_font.c twin_path.c twin_poly.c twin_screen.c twin_x11.c twin_x11.h twinint.h xtwin.c Log Message: 2004-10-01 Keith Packard * twin.h: * twin_fixed.c: * twin_font.c: (twin_text_metrics_ucs4), (twin_path_ucs4), (twin_text_metrics_utf8): * twin_screen.c: (twin_screen_create), (twin_screen_update): * twin_x11.c: (_twin_x11_put_begin), (_twin_x11_put_span), * twin_x11.h: (twin_x11_create): Add put_begin to screen structure so that the backend can batch updates. Add twin_int_to_fixed. Inline twin_fixed_mul and twin_fixed_div using int64_t. Add twin_text_metrics_utf8. Hard-code the max number of vertices in a glyph. Set various ICCCM properties to make X wms happy. * twin_path.c: (_twin_matrix_max_radius), (twin_path_circle): Use better approximation of ellipse major axis radius when drawing circles. * twin_poly.c: (_twin_edge_fill): Compiler warning. * twinint.h: Delete duplicate twin_over definition * xtwin.c: (twin_clock_hand), (twin_clock_face), (twin_clock), (twin_app_thread), (twin_start_app), (twin_start_clock), (main): Allow for multiple clocks, and add watermark. Note that text metrics are quite broken currently. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- ChangeLog 30 Sep 2004 17:23:07 -0000 1.13 +++ ChangeLog 2 Oct 2004 03:07:26 -0000 1.14 @@ -1,3 +1,36 @@ +2004-10-01 Keith Packard + + * twin.h: + * twin_fixed.c: + * twin_font.c: (twin_text_metrics_ucs4), (twin_path_ucs4), + (twin_text_metrics_utf8): + * twin_screen.c: (twin_screen_create), (twin_screen_update): + * twin_x11.c: (_twin_x11_put_begin), (_twin_x11_put_span), + * twin_x11.h: + (twin_x11_create): + Add put_begin to screen structure so that the backend can batch + updates. + Add twin_int_to_fixed. + Inline twin_fixed_mul and twin_fixed_div using int64_t. + Add twin_text_metrics_utf8. + Hard-code the max number of vertices in a glyph. + Set various ICCCM properties to make X wms happy. + + * twin_path.c: (_twin_matrix_max_radius), (twin_path_circle): + Use better approximation of ellipse major axis radius when + drawing circles. + + * twin_poly.c: (_twin_edge_fill): + Compiler warning. + + * twinint.h: + Delete duplicate twin_over definition + + * xtwin.c: (twin_clock_hand), (twin_clock_face), (twin_clock), + (twin_app_thread), (twin_start_app), (twin_start_clock), (main): + Allow for multiple clocks, and add watermark. Note that + text metrics are quite broken currently. + 2004-09-30 Keith Packard * Makefile.am: Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- twin.h 30 Sep 2004 17:23:07 -0000 1.10 +++ twin.h 2 Oct 2004 03:07:26 -0000 1.11 @@ -106,8 +106,14 @@ } twin_pixmap_t; /* - * A function that paints pixels to the screen + * twin_put_begin_t: called before data are drawn to the screen + * twin_put_span_t: called for each scanline drawn */ +typedef void (*twin_put_begin_t) (int x, + int y, + int width, + int height, + void *closure); typedef void (*twin_put_span_t) (int x, int y, int width, @@ -139,6 +145,7 @@ /* * Repaint function */ + twin_put_begin_t put_begin; twin_put_span_t put_span; void *closure; } twin_screen_t; @@ -173,6 +180,8 @@ #define twin_double_to_fixed(d) ((twin_fixed_t) ((d) * 65536)) #define twin_fixed_to_double(f) ((double) (f) / 65536.0) +#define twin_int_to_fixed(i) ((twin_fixed_t) (i) << 16) + /* * Place matrices in structures so they can be easily copied */ @@ -241,14 +250,22 @@ * twin_fixed.c */ +#if 0 twin_fixed_t twin_fixed_mul (twin_fixed_t af, twin_fixed_t bf); +#else +#define twin_fixed_mul(a,b) ((twin_fixed_t) (((int64_t) (a) * (b)) >> 16)) +#endif twin_fixed_t twin_fixed_sqrt (twin_fixed_t a); +#if 0 twin_fixed_t twin_fixed_div (twin_fixed_t a, twin_fixed_t b); +#else +#define twin_fixed_div(a,b) ((twin_fixed_t) ((((int64_t) (a)) << 16) / b)) +#endif /* * twin_font.c @@ -282,6 +299,10 @@ twin_ucs4_t ucs4, twin_text_metrics_t *m); +void +twin_text_metrics_utf8 (twin_path_t *path, + const char *string, + twin_text_metrics_t *m); /* * twin_hull.c */ @@ -450,10 +471,11 @@ */ twin_screen_t * -twin_screen_create (int width, - int height, - twin_put_span_t put_span, - void *closure); +twin_screen_create (int width, + int height, + twin_put_begin_t put_begin, + twin_put_span_t put_span, + void *closure); void twin_screen_destroy (twin_screen_t *screen); Index: twin_fixed.c =================================================================== RCS file: /local/src/CVS/twin/twin_fixed.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_fixed.c 28 Sep 2004 05:42:36 -0000 1.2 +++ twin_fixed.c 2 Oct 2004 03:07:26 -0000 1.3 @@ -36,6 +36,7 @@ #define uint32_hi(i) ((i) >> 16) #define uint32_carry16 ((1) << 16) +#if 0 twin_fixed_t twin_fixed_mul (twin_fixed_t af, twin_fixed_t bf) { @@ -88,7 +89,9 @@ twin_fixed_to_double (r))); return r; } +#endif +#if 0 twin_fixed_t twin_fixed_div (twin_fixed_t a, twin_fixed_t b) { @@ -96,6 +99,7 @@ q = (twin_fixed_t) ((((int64_t) a) << 16) / b); return q; } +#endif twin_fixed_t twin_fixed_sqrt (twin_fixed_t a) Index: twin_font.c =================================================================== RCS file: /local/src/CVS/twin/twin_font.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- twin_font.c 30 Sep 2004 17:23:07 -0000 1.9 +++ twin_font.c 2 Oct 2004 03:07:26 -0000 1.10 @@ -209,7 +209,6 @@ top = bottom = baseline; right = Scale(p[0].y); } - m->left_side_bearing = SNAPI(path, -left); m->right_side_bearing = SNAPI(path,right); m->width = m->left_side_bearing + m->right_side_bearing; @@ -234,10 +233,10 @@ twin_fixed_t pen_size; twin_matrix_t pen_matrix; twin_fixed_t pen_adjust; - twin_gfixed_t *snap_x = 0, *snap_y = 0; + twin_gfixed_t snap_x[TWIN_GLYPH_MAX_POINTS]; + twin_gfixed_t snap_y[TWIN_GLYPH_MAX_POINTS]; twin_text_metrics_t metrics; int nsnap_x = 0, nsnap_y = 0; - int npoints; twin_text_metrics_ucs4 (path, ucs4, &metrics); @@ -245,14 +244,6 @@ if (Hint (path)) { - for (i = 1; p[i].y != -64; i++) - ; - - npoints = i - 1 + 3; - - snap_x = malloc ((npoints * 2) * sizeof (twin_gfixed_t)); - snap_y = snap_x + npoints; - nsnap_x = 0; nsnap_y = 0; @@ -336,9 +327,6 @@ twin_path_destroy (stroke); twin_path_destroy (pen); - if (snap_x) - free (snap_x); - w = metrics.width; _twin_path_smove (path, @@ -451,3 +439,40 @@ return w; } +void +twin_text_metrics_utf8 (twin_path_t *path, + const char *string, + twin_text_metrics_t *m) +{ + int len; + twin_ucs4_t ucs4; + twin_fixed_t w = 0; + twin_text_metrics_t c; + twin_bool_t first = TWIN_TRUE; + + while ((len = _twin_utf8_to_ucs4(string, &ucs4)) > 0) + { + twin_text_metrics_ucs4 (path, ucs4, &c); + if (first) + *m = c; + else + { + c.left_side_bearing += w; + c.right_side_bearing += w; + c.width += w; + + if (c.left_side_bearing > m->left_side_bearing) + m->left_side_bearing = c.left_side_bearing; + if (c.right_side_bearing > m->right_side_bearing) + m->right_side_bearing = c.right_side_bearing; + if (c.width > m->width) + m->width = c.width; + if (c.ascent < m->ascent) + m->ascent = c.ascent; + if (c.descent > m->descent) + m->descent = c.descent; + } + w = c.width; + string += len; + } +} Index: twin_path.c =================================================================== RCS file: /local/src/CVS/twin/twin_path.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_path.c 30 Sep 2004 17:23:07 -0000 1.7 +++ twin_path.c 2 Oct 2004 03:07:26 -0000 1.8 @@ -154,6 +154,16 @@ path->nsublen++; } +#define twin_fixed_abs(f) ((f) < 0 ? -(f) : (f)) + +static twin_fixed_t +_twin_matrix_max_radius (twin_matrix_t *m) +{ + return (twin_fixed_abs (m->m[0][0]) + twin_fixed_abs (m->m[0][1]) + + twin_fixed_abs (m->m[1][0]) + twin_fixed_abs (m->m[1][1])); +} + + void twin_path_circle (twin_path_t *path, twin_fixed_t radius) { @@ -162,7 +172,7 @@ twin_spoint_t center; int i; twin_matrix_t save; - twin_fixed_t det; + twin_fixed_t max_radius; save = twin_path_current_matrix (path); @@ -172,14 +182,12 @@ twin_path_close (path); - /* The determinant represents the area expansion factor of the - transform. In the worst case, this is entirely in one - dimension, which is what we assume here. */ - - det = _twin_matrix_determinant (&path->state.matrix); + max_radius = _twin_matrix_max_radius (&path->state.matrix); - sides = (4 * det) / twin_sfixed_to_fixed (TWIN_SFIXED_TOLERANCE); + sides = max_radius / twin_sfixed_to_fixed (TWIN_SFIXED_TOLERANCE); + if (sides > 1024) sides = 1024; + n = 2; while ((1 << n) < sides) n++; Index: twin_poly.c =================================================================== RCS file: /local/src/CVS/twin/twin_poly.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- twin_poly.c 30 Sep 2004 17:23:07 -0000 1.6 +++ twin_poly.c 2 Oct 2004 03:07:26 -0000 1.7 @@ -272,7 +272,7 @@ twin_edge_t *active, *a, *n, **prev; int e; twin_sfixed_t y; - twin_sfixed_t x0; + twin_sfixed_t x0 = 0; int w; qsort (edges, nedges, sizeof (twin_edge_t), _edge_compare_y); Index: twin_screen.c =================================================================== RCS file: /local/src/CVS/twin/twin_screen.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_screen.c 30 Sep 2004 17:23:07 -0000 1.3 +++ twin_screen.c 2 Oct 2004 03:07:26 -0000 1.4 @@ -25,10 +25,11 @@ #include "twinint.h" twin_screen_t * -twin_screen_create (int width, - int height, - twin_put_span_t put_span, - void *closure) +twin_screen_create (int width, + int height, + twin_put_begin_t put_begin, + twin_put_span_t put_span, + void *closure) { twin_screen_t *screen = malloc (sizeof (twin_screen_t)); if (!screen) @@ -44,6 +45,7 @@ #if HAVE_PTHREAD_H pthread_mutex_init (&screen->screen_mutex, NULL); #endif + screen->put_begin = put_begin; screen->put_span = put_span; screen->closure = closure; return screen; @@ -162,6 +164,8 @@ if (!span) return; + if (screen->put_begin) + (*screen->put_begin) (x, y, width, height, screen->closure); while (height--) { memset (span, 0xff, width * sizeof (twin_argb32_t)); Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_x11.c 30 Sep 2004 17:23:07 -0000 1.2 +++ twin_x11.c 2 Oct 2004 03:07:26 -0000 1.3 @@ -26,6 +26,29 @@ #include "twinint.h" static void +_twin_x11_put_begin (int x, + int y, + int width, + int height, + void *closure) +{ + twin_x11_t *tx = closure; + + tx->iy = 0; + tx->image = XCreateImage (tx->dpy, tx->visual, tx->depth, ZPixmap, + 0, 0, width, height, 32, 0); + if (tx->image) + { + tx->image->data = malloc (4 * width * height); + if (!tx->image->data) + { + XDestroyImage (tx->image); + tx->image = 0; + } + } +} + +static void _twin_x11_put_span (int x, int y, int width, @@ -33,14 +56,11 @@ void *closure) { twin_x11_t *tx = closure; - XImage *image; int ix = 0; int iw = width; - image = XCreateImage (tx->dpy, tx->visual, tx->depth, ZPixmap, - 0, 0, width, 1, 32, 0); - - image->data = malloc (4 * width); + if (!tx->image) + return; while (iw--) { @@ -48,11 +68,17 @@ if (tx->depth == 16) pixel = twin_argb32_to_rgb16 (pixel); - XPutPixel (image, ix, 0, pixel); + XPutPixel (tx->image, ix, tx->iy, pixel); ix++; } - XPutImage (tx->dpy, tx->win, tx->gc, image, 0, 0, x, y, width, 1); - XDestroyImage (image); + tx->iy++; + if (tx->iy == tx->image->height) + { + XPutImage (tx->dpy, tx->win, tx->gc, tx->image, 0, 0, + x, y - tx->iy, width, tx->image->height); + XDestroyImage (tx->image); + tx->image = 0; + } } static void * @@ -111,6 +137,13 @@ twin_x11_t *tx; int scr = DefaultScreen (dpy); XSetWindowAttributes wa; + XTextProperty wm_name, icon_name; + XSizeHints sizeHints; + XWMHints wmHints; + XClassHint classHints; + Atom wm_delete_window; + static char *argv[] = { "xtwin", 0 }; + static int argc = 1; tx = malloc (sizeof (twin_x11_t)); if (!tx) @@ -128,12 +161,29 @@ ExposureMask| StructureNotifyMask); + wm_name.value = (unsigned char *) argv[0]; + wm_name.encoding = XA_STRING; + wm_name.format = 8; + wm_name.nitems = strlen (wm_name.value) + 1; + icon_name = wm_name; + tx->win = XCreateWindow (dpy, RootWindow (dpy, scr), 0, 0, width, height, 0, tx->depth, InputOutput, tx->visual, CWBackPixmap|CWEventMask, &wa); + sizeHints.flags = 0; + wmHints.flags = InputHint; + wmHints.input = True; + classHints.res_name = argv[0]; + classHints.res_class = argv[0]; + XSetWMProperties (dpy, tx->win, + &wm_name, &icon_name, + argv, argc, + &sizeHints, &wmHints, 0); + XSetWMProtocols (dpy, tx->win, &wm_delete_window, 1); + tx->gc = XCreateGC (dpy, tx->win, 0, 0); - tx->screen = twin_screen_create (width, height, + tx->screen = twin_screen_create (width, height, _twin_x11_put_begin, _twin_x11_put_span, tx); twin_screen_register_damaged (tx->screen, twin_x11_screen_damaged, tx); Index: twin_x11.h =================================================================== RCS file: /local/src/CVS/twin/twin_x11.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_x11.h 30 Sep 2004 17:23:38 -0000 1.1 +++ twin_x11.h 2 Oct 2004 03:07:26 -0000 1.2 @@ -28,6 +28,7 @@ #include #include +#include #include typedef struct _twin_x11 { @@ -40,6 +41,8 @@ pthread_t damage_thread; pthread_cond_t damage_cond; pthread_t event_thread; + XImage *image; + int iy; } twin_x11_t; /* Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- twinint.h 30 Sep 2004 17:23:07 -0000 1.8 +++ twinint.h 2 Oct 2004 03:07:26 -0000 1.9 @@ -79,11 +79,7 @@ ((twin_argb32_t) twin_int_mult (twin_get_8(s,i),(m),(t)) << (i)) #define twin_over(s,d,i,m,t) \ - ((t) = twin_int_mult(twin_get_8(d,i),(m),(t)) + twin_get_8(s,i),\ - (twin_argb32_t) twin_sat (t) << (i)) - -#define twin_over(s,d,i,m,t) \ - ((t) = twin_int_mult(twin_get_8(d,i),(m),(t)) + twin_get_8(s,i),\ + (((t) = twin_int_mult(twin_get_8(d,i),(m),(t)) + twin_get_8(s,i)),\ (twin_argb32_t) twin_sat (t) << (i)) #define twin_argb32_to_rgb16(s) ((((s) >> 3) & 0x001f) | \ @@ -344,4 +340,6 @@ extern const twin_gpoint_t _twin_glyphs[]; extern const uint16_t _twin_glyph_offsets[]; +#define TWIN_GLYPH_MAX_POINTS 56 + #endif /* _TWININT_H_ */ Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- xtwin.c 30 Sep 2004 17:23:07 -0000 1.12 +++ xtwin.c 2 Oct 2004 03:07:26 -0000 1.13 @@ -32,26 +32,81 @@ #define D(x) twin_double_to_fixed(x) -#define CLOCK_SIZE 256 - #define TWIN_CLOCK_BACKGROUND 0xff3b80ae -#define TWIN_CLOCK_HOUR 0xffdedede -#define TWIN_CLOCK_MINUTE 0xffdedede +#define TWIN_CLOCK_HOUR 0x80808080 +#define TWIN_CLOCK_HOUR_OUT 0xffdedede +#define TWIN_CLOCK_MINUTE 0x80808080 +#define TWIN_CLOCK_MINUTE_OUT 0xffdedede #define TWIN_CLOCK_SECOND 0x80808080 #define TWIN_CLOCK_TIC 0xffbababa #define TWIN_CLOCK_NUMBERS 0xffdedede +#define TWIN_CLOCK_WATER 0x40404040 +#define TWIN_CLOCK_BORDER 0xffbababa +#define TWIN_CLOCK_BORDER_WIDTH D(0.01) + +static void +twin_clock_set_transform (twin_pixmap_t *clock, + twin_path_t *path) +{ + twin_fixed_t scale; + + scale = D(1) / 2; + scale = twin_fixed_mul (scale, TWIN_FIXED_ONE - TWIN_CLOCK_BORDER_WIDTH * 3); + twin_path_scale (path, + clock->width * scale, + clock->height * scale); + + twin_path_translate (path, D(1) + TWIN_CLOCK_BORDER_WIDTH * 3, + D(1) + TWIN_CLOCK_BORDER_WIDTH * 3); +} static void twin_clock_hand (twin_pixmap_t *clock, twin_angle_t angle, twin_fixed_t len, + twin_fixed_t fill_width, + twin_fixed_t out_width, + twin_argb32_t fill_pixel, + twin_argb32_t out_pixel) +{ + twin_path_t *stroke = twin_path_create (); + twin_path_t *pen = twin_path_create (); + twin_path_t *path = twin_path_create (); + twin_matrix_t m; + + twin_clock_set_transform (clock, stroke); + + twin_path_rotate (stroke, angle); + twin_path_move (stroke, D(0), D(0)); + twin_path_draw (stroke, len, D(0)); + + m = twin_path_current_matrix (stroke); + m.m[2][0] = 0; + m.m[2][1] = 0; + twin_path_set_matrix (pen, m); + twin_path_set_matrix (path, m); + twin_path_circle (pen, fill_width); + twin_path_convolve (path, stroke, pen); + + twin_paint_path (clock, fill_pixel, path); + + twin_paint_stroke (clock, out_pixel, path, out_width); + + twin_path_destroy (path); + twin_path_destroy (pen); + twin_path_destroy (stroke); +} + +static void +twin_clock_sec (twin_pixmap_t *clock, + twin_angle_t angle, + twin_fixed_t len, twin_fixed_t width, twin_argb32_t pixel) { twin_path_t *stroke = twin_path_create (); - twin_path_translate (stroke, D(CLOCK_SIZE) / 2, D(CLOCK_SIZE) / 2); - twin_path_scale (stroke, D(CLOCK_SIZE) / 2, D(CLOCK_SIZE) / 2); + twin_clock_set_transform (clock, stroke); twin_path_rotate (stroke, angle); twin_path_move (stroke, D(0), D(0)); @@ -74,16 +129,37 @@ twin_path_t *path = twin_path_create (); int m; - twin_path_translate (path, D(CLOCK_SIZE) / 2, D(CLOCK_SIZE) / 2); - twin_path_scale (path, D(CLOCK_SIZE) / 2, D(CLOCK_SIZE) / 2); - twin_path_set_font_size (path, D(0.2)); - twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); + twin_clock_set_transform (clock, path); twin_path_move (path, 0, 0); twin_path_circle (path, TWIN_FIXED_ONE); twin_paint_path (clock, TWIN_CLOCK_BACKGROUND, path); + twin_paint_stroke (clock, TWIN_CLOCK_BORDER, path, TWIN_CLOCK_BORDER_WIDTH); + + { + twin_state_t state = twin_path_save (path); + twin_text_metrics_t metrics; + twin_fixed_t height; + static char *label = "twin"; + + twin_path_empty (path); + twin_path_rotate (path, twin_degrees_to_angle (-11)); + twin_path_set_font_size (path, D(0.5)); + twin_path_set_font_style (path, TWIN_TEXT_UNHINTED|TWIN_TEXT_OBLIQUE); + twin_text_metrics_utf8 (path, label, &metrics); + height = metrics.ascent + metrics.descent; +/* twin_path_move (path, -metrics.width / 2, height / 2 - metrics.ascent);*/ + twin_path_move (path, -D(.4), -D(.16)); + twin_path_utf8 (path, label); + twin_paint_path (clock, TWIN_CLOCK_WATER, path); + twin_path_restore (path, &state); + } + + twin_path_set_font_size (path, D(0.2)); + twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); + for (m = 1; m <= 60; m++) { twin_state_t state = twin_path_save (path); @@ -112,22 +188,32 @@ twin_path_destroy (path); } +int nclock; + static void -twin_clock (twin_screen_t *screen) +twin_clock (twin_screen_t *screen, int x, int y, int w, int h) { - twin_pixmap_t *clock = twin_pixmap_create (TWIN_ARGB32, CLOCK_SIZE, CLOCK_SIZE); + twin_pixmap_t *clock = twin_pixmap_create (TWIN_ARGB32, w, h); struct timeval tv; struct tm t; twin_angle_t hour_angle, minute_angle, second_angle; +#if 0 + int i; +#endif printf ("twin clock\n"); - twin_pixmap_move (clock, 0, 0); + twin_pixmap_move (clock, x, y); twin_pixmap_show (clock, screen, 0); + +#if 0 + for (i = 0; i < 5; i++) +#else for (;;) +#endif { twin_pixmap_disable_update (clock); twin_fill (clock, 0x00000000, TWIN_SOURCE, 0, 0, - CLOCK_SIZE, CLOCK_SIZE); + clock->width, clock->height); gettimeofday (&tv, NULL); @@ -139,13 +225,63 @@ hour_angle = t.tm_hour * TWIN_ANGLE_360 / 12 - TWIN_ANGLE_90 + minute_angle / 12; twin_clock_face (clock); - twin_clock_hand (clock, hour_angle, D(0.4), D(0.05), 0xffdedede); - twin_clock_hand (clock, minute_angle, D(0.8), D(0.03), 0xffdedede); - twin_clock_hand (clock, second_angle, D(0.6), D(0.01), 0x80808080); + twin_clock_hand (clock, hour_angle, D(0.4), D(0.07), D(0.01), + TWIN_CLOCK_HOUR, TWIN_CLOCK_HOUR_OUT); + twin_clock_hand (clock, minute_angle, D(0.8), D(0.05), D(0.01), + TWIN_CLOCK_MINUTE, TWIN_CLOCK_MINUTE_OUT); + twin_clock_sec (clock, second_angle, D(0.9), D(0.02), + TWIN_CLOCK_SECOND); twin_pixmap_enable_update (clock); + + gettimeofday (&tv, NULL); + usleep (1000000 - tv.tv_usec); } + nclock--; +} + +typedef void (*twin_app_func_t) (twin_screen_t *screen, + int x, int y, int w, int h); + +typedef struct _twin_app_args { + twin_app_func_t func; + twin_screen_t *screen; + int x, y, w, h; +} twin_app_args_t; + +static void * +twin_app_thread (void *closure) +{ + twin_app_args_t *a = closure; + + (*a->func) (a->screen, a->x, a->y, a->w, a->h); + free (a); + return 0; +} + +static void +twin_start_app (twin_app_func_t func, + twin_screen_t *screen, + int x, int y, int w, int h) +{ + twin_app_args_t *a = malloc (sizeof (twin_app_args_t)); + pthread_t thread; + + a->func = func; + a->screen = screen; + a->x = x; + a->y = y; + a->w = w; + a->h = h; + pthread_create (&thread, NULL, twin_app_thread, a); +} + +static void +twin_start_clock (twin_screen_t *screen, int x, int y, int w, int h) +{ + ++nclock; + twin_start_app (twin_clock, screen, x, y, w, h); } int styles[] = { @@ -475,8 +611,12 @@ twin_pixmap_show (red, x11->screen, 0); twin_pixmap_show (blue, x11->screen, 0); #endif - twin_clock (x11->screen); - sleep (10000); + twin_start_clock (x11->screen, 0, 0, 512, 512); +/* twin_start_clock (x11->screen, 256, 0, 256, 256); + twin_start_clock (x11->screen, 0, 256, 256, 256); + twin_start_clock (x11->screen, 256, 256, 256, 256); */ + while (nclock) + sleep (1); #if 0 had_motion = TWIN_FALSE; for (;;) From commit at keithp.com Mon Oct 4 00:49:52 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 4 00:50:09 2004 Subject: [Commit] twin ChangeLog, 1.14, 1.15 twin.h, 1.11, 1.12 twin_draw.c, 1.3, 1.4 twin_font.c, 1.10, 1.11 twin_glyphs.c, 1.3, 1.4 twin_matrix.c, 1.2, 1.3 twin_path.c, 1.8, 1.9 twin_spline.c, 1.3, 1.4 twin_trig.c, 1.1, 1.2 twin_x11.c, 1.3, 1.4 twinint.h, 1.9, 1.10 xtwin.c, 1.13, 1.14 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv8272 Modified Files: ChangeLog twin.h twin_draw.c twin_font.c twin_glyphs.c twin_matrix.c twin_path.c twin_spline.c twin_trig.c twin_x11.c twinint.h xtwin.c Log Message: 2004-10-04 Keith Packard * twin.h: * twin_draw.c: (twin_composite): Fix a clipping bug * twinint.h: * twin_font.c: (_snap), (_twin_g_base), (_twin_pen_size), (twin_text_metrics_ucs4), (twin_add_snap), (twin_n_in_spline), (twin_spline_fit), (_ucs4_string), (px), (py), (twin_dump_glyphs), (twin_path_ucs4), (twin_text_metrics_utf8): * twin_glyphs.c: Change glyph representation to allow splines and include metrics. * twin_matrix.c: (_twin_matrix_expand): * twin_path.c: (twin_path_rmove), (twin_path_rdraw): Add some new helper functions. * twin_spline.c: Expose _twin_path_scurve for glyphs * twin_trig.c: Increase sin table precision. * twin_x11.c: (_twin_x11_put_span), (twin_x11_screen_damaged), (twin_x11_damage): Fix off-by-one error in y position. Lock screen while adding expose damage * xtwin.c: (twin_clock_face), (twin_clock), (main): Change clock appearance. Use corrected glyph metrics Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- ChangeLog 2 Oct 2004 03:07:26 -0000 1.14 +++ ChangeLog 4 Oct 2004 07:49:49 -0000 1.15 @@ -1,3 +1,35 @@ +2004-10-04 Keith Packard + + * twin.h: + * twin_draw.c: (twin_composite): + Fix a clipping bug + + * twinint.h: + * twin_font.c: (_snap), (_twin_g_base), (_twin_pen_size), + (twin_text_metrics_ucs4), (twin_add_snap), (twin_n_in_spline), + (twin_spline_fit), (_ucs4_string), (px), (py), (twin_dump_glyphs), + (twin_path_ucs4), (twin_text_metrics_utf8): + * twin_glyphs.c: + Change glyph representation to allow splines and include metrics. + + * twin_matrix.c: (_twin_matrix_expand): + * twin_path.c: (twin_path_rmove), (twin_path_rdraw): + Add some new helper functions. + + * twin_spline.c: + Expose _twin_path_scurve for glyphs + + * twin_trig.c: + Increase sin table precision. + + * twin_x11.c: (_twin_x11_put_span), (twin_x11_screen_damaged), + (twin_x11_damage): + Fix off-by-one error in y position. + Lock screen while adding expose damage + + * xtwin.c: (twin_clock_face), (twin_clock), (main): + Change clock appearance. Use corrected glyph metrics + 2004-10-01 Keith Packard * twin.h: Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- twin.h 2 Oct 2004 03:07:26 -0000 1.11 +++ twin.h 4 Oct 2004 07:49:49 -0000 1.12 @@ -49,16 +49,16 @@ /* * Angles */ -typedef int16_t twin_angle_t; /* -512 .. 512 for -180 .. 180 */ +typedef int16_t twin_angle_t; /* -2048 .. 2048 for -180 .. 180 */ -#define TWIN_ANGLE_360 1024 -#define TWIN_ANGLE_180 512 -#define TWIN_ANGLE_90 256 -#define TWIN_ANGLE_45 128 -#define TWIN_ANGLE_22_5 64 -#define TWIN_ANGLE_11_25 32 +#define TWIN_ANGLE_360 4096 +#define TWIN_ANGLE_180 (TWIN_ANGLE_360 >> 1) +#define TWIN_ANGLE_90 (TWIN_ANGLE_360 >> 2) +#define TWIN_ANGLE_45 (TWIN_ANGLE_360 >> 3) +#define TWIN_ANGLE_22_5 (TWIN_ANGLE_360 >> 4) +#define TWIN_ANGLE_11_25 (TWIN_ANGLE_360 >> 5) -#define twin_degrees_to_angle(d) ((d) * 512 / 180) +#define twin_degrees_to_angle(d) ((twin_angle_t) ((((int32_t) (d)) * TWIN_ANGLE_360 / 360))) /* * A rectangle @@ -182,6 +182,10 @@ #define twin_int_to_fixed(i) ((twin_fixed_t) (i) << 16) +typedef struct _twin_point { + twin_fixed_t x, y; +} twin_point_t; + /* * Place matrices in structures so they can be easily copied */ @@ -333,10 +337,16 @@ void twin_path_move (twin_path_t *path, twin_fixed_t x, twin_fixed_t y); +void +twin_path_rmove (twin_path_t *path, twin_fixed_t x, twin_fixed_t y); + void twin_path_draw (twin_path_t *path, twin_fixed_t x, twin_fixed_t y); void +twin_path_rdraw (twin_path_t *path, twin_fixed_t x, twin_fixed_t y); + +void twin_path_circle(twin_path_t *path, twin_fixed_t radius); void Index: twin_draw.c =================================================================== RCS file: /local/src/CVS/twin/twin_draw.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_draw.c 30 Sep 2004 17:23:07 -0000 1.3 +++ twin_draw.c 4 Oct 2004 07:49:49 -0000 1.4 @@ -298,8 +298,8 @@ right = dst->width; if (top < 0) top = 0; - if (top > dst->height) - top = dst->height; + if (bottom > dst->height) + bottom = dst->height; op = comp3[operator][operand_index(src)][operand_index(msk)][dst->format]; if (op) Index: twin_font.c =================================================================== RCS file: /local/src/CVS/twin/twin_font.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- twin_font.c 2 Oct 2004 03:07:26 -0000 1.10 +++ twin_font.c 4 Oct 2004 07:49:49 -0000 1.11 @@ -34,9 +34,7 @@ #define DBGMSG(x) #endif -#define Scale(f) (((twin_fixed_t) (f) * path->state.font_size) >> 5) -#define ScaleX(x) Scale(x) -#define ScaleY(y) Scale(y) +#define Scale(f) (((twin_fixed_t) (f) * path->state.font_size) >> 6) #define Hint(p) (((p)->state.font_style & TWIN_TEXT_UNHINTED) == 0) @@ -46,18 +44,10 @@ return ucs4 <= TWIN_FONT_MAX && _twin_glyph_offsets[ucs4] != 0; } -static int -compare_snap (const void *av, const void *bv) -{ - const twin_gfixed_t *a = av; - const twin_gfixed_t *b = bv; - - return (int) (*a - *b); -} - -#define SNAPI(path,p) (Hint(path) ? (((p) + 0x7fff) & ~0xffff) : (p)) -#define SNAPH(path,p) (Hint(path) ? (((p) + 0x3fff) & ~0x7fff) : (p)) +#define SNAPI(p) (((p) + 0x7fff) & ~0xffff) +#define SNAPH(p) (((p) + 0x3fff) & ~0x7fff) +#if 0 static twin_fixed_t _snap (twin_path_t *path, twin_gfixed_t g, twin_gfixed_t *snap, int nsnap) { @@ -72,8 +62,8 @@ twin_fixed_t before = Scale(snap[s]); twin_fixed_t after = Scale(snap[s+1]); twin_fixed_t dist = after - before; - twin_fixed_t snap_before = SNAPI(path, before); - twin_fixed_t snap_after = SNAPI(path, after); + twin_fixed_t snap_before = SNAPI(before); + twin_fixed_t snap_after = SNAPI(after); twin_fixed_t move_before = snap_before - before; twin_fixed_t move_after = snap_after - after; twin_fixed_t dist_before = v - before; @@ -92,22 +82,11 @@ DBGMSG (("_snap: %d => %9.4f\n", g, F(v))); return v; } +#endif #define SNAPX(p) _snap (path, p, snap_x, nsnap_x) #define SNAPY(p) _snap (path, p, snap_y, nsnap_y) -static int -_add_snap (twin_gfixed_t *snaps, int nsnap, twin_fixed_t snap) -{ - int s; - - for (s = 0; s < nsnap; s++) - if (snaps[s] == snap) - return nsnap; - snaps[nsnap++] = snap; - return nsnap; -} - static const twin_gpoint_t * _twin_ucs4_base(twin_ucs4_t ucs4) { @@ -116,183 +95,409 @@ return _twin_glyphs + _twin_glyph_offsets[ucs4]; } -#define TWIN_FONT_BASELINE 9 +static const signed char * +_twin_g_base (twin_ucs4_t ucs4) +{ + if (ucs4 > TWIN_FONT_MAX) ucs4 = 0; + + return _twin_gtable + _twin_g_offsets[ucs4]; +} static twin_fixed_t _twin_pen_size (twin_path_t *path) { twin_fixed_t pen_size; - pen_size = SNAPH(path, path->state.font_size / 24); - if (Hint (path) && pen_size < TWIN_FIXED_HALF) + pen_size = path->state.font_size / 24; + + if (Hint (path)) + { + pen_size = SNAPH(pen_size); + if( pen_size < TWIN_FIXED_HALF) pen_size = TWIN_FIXED_HALF; + } if (path->state.font_style & TWIN_TEXT_BOLD) { - twin_fixed_t pen_add = SNAPH(path, pen_size >> 1); - if (Hint (path) && pen_add == 0) - pen_add = TWIN_FIXED_HALF; + twin_fixed_t pen_add = pen_size >> 1; + + if (Hint (path)) + { + pen_add = SNAPH (pen_add); + if (pen_add == 0) + pen_add = TWIN_FIXED_HALF; + } pen_size += pen_add; } return pen_size; } +#define Margin(pen_size) ((pen_size) * 2) + void twin_text_metrics_ucs4 (twin_path_t *path, twin_ucs4_t ucs4, twin_text_metrics_t *m) { - const twin_gpoint_t *p = _twin_ucs4_base (ucs4); - twin_fixed_t x, y; - twin_fixed_t left, right; - twin_fixed_t top, bottom; + const signed char *g = _twin_g_base (ucs4); twin_fixed_t pen_size = _twin_pen_size (path); - twin_fixed_t baseline = SNAPI(path, Scale(TWIN_FONT_BASELINE)); - int i; - int skip_xi; - int skip_yi; - int next_xi; - int next_yi; + twin_fixed_t left = Scale(twin_glyph_left(g)); + twin_fixed_t right = Scale (twin_glyph_right(g)) + pen_size * 2; + twin_fixed_t ascent = Scale (twin_glyph_ascent(g)) + pen_size * 2; + twin_fixed_t descent = Scale (twin_glyph_descent(g)); + twin_fixed_t font_spacing = path->state.font_size; + twin_fixed_t font_descent = font_spacing / 3; + twin_fixed_t font_ascent = font_spacing - font_descent; + + if (Hint(path)) + { + left = SNAPI(left); + right = SNAPI(right); + ascent = SNAPI(ascent); + descent = SNAPI(descent); + font_descent = SNAPI(font_descent); + font_ascent = SNAPI(font_ascent); + } + m->left_side_bearing = left + Margin(pen_size); + m->right_side_bearing = right + Margin(pen_size); + m->ascent = ascent; + m->descent = descent; + m->width = m->right_side_bearing + Margin(pen_size); + m->font_ascent = font_ascent + Margin(pen_size); + m->font_descent = font_ascent + Margin(pen_size); +} + +#include + +#define TWIN_MAX_POINTS 50 +#define TWIN_MAX_STROKE 50 + +typedef enum { twin_gmove, twin_gline, twin_gcurve } twin_gcmd_t; + +typedef struct _twin_gop { + twin_gcmd_t cmd; + twin_gpoint_t p[3]; +} twin_gop_t; - left = TWIN_FIXED_MAX; - top = TWIN_FIXED_MAX; - right = TWIN_FIXED_MIN; - bottom = TWIN_FIXED_MIN; - /* - * Locate horizontal and vertical segments - */ - skip_xi = 0; - skip_yi = 0; - for (i = 1; p[i].y != -64; i++) +typedef struct _twin_stroke { + int n; + twin_gpoint_t p[TWIN_MAX_STROKE]; +} twin_stroke_t; + +typedef struct _twin_snap { + int n; + twin_gfixed_t s[TWIN_MAX_POINTS]; +} twin_snap_t; + +typedef struct _twin_glyph { + twin_ucs4_t ucs4; + int offset; + twin_bool_t exists; + twin_gfixed_t left, right, top, bottom; + int n; + twin_stroke_t s[TWIN_MAX_STROKE]; + int nop; + twin_gop_t op[TWIN_MAX_STROKE]; + twin_snap_t snap_x; + twin_snap_t snap_y; +} twin_glyph_t; + +static twin_glyph_t glyphs[0x80]; + +static void +twin_add_snap (twin_snap_t *snap, twin_gfixed_t v) +{ + int n; + + for (n = 0; n < snap->n; n++) { - if (p[i].x == -64) - continue; - x = Scale (p[i].x); - y = Scale (p[i].y); - next_xi = skip_xi; - next_yi = skip_yi; - if (Hint (path) && p[i+1].y != -64 && p[i+1].x != -64) + if (snap->s[n] == v) + return; + if (snap->s[n] > v) + break; + } + memmove (&snap->s[n+1], &snap->s[n], snap->n - n); + snap->s[n] = v; + snap->n++; +} + +static int +twin_n_in_spline (twin_gpoint_t *p, int n) +{ + return 0; +} + +static void +twin_spline_fit (twin_gpoint_t *p, int n, twin_gpoint_t *c1, twin_gpoint_t *c2) +{ +} + +static char * +_ucs4_string (twin_ucs4_t ucs4) +{ + static char buf[10]; + if (ucs4 < ' ' || ucs4 > '~') + { + if (!ucs4) + return "\\0"; + sprintf (buf, "\\0%o", ucs4); + return buf; + } + sprintf (buf, "%c", ucs4); + return buf; +} + +static twin_gfixed_t +px (const twin_gpoint_t *p, int i) +{ + return p[i].x << 1; +} + +static twin_gfixed_t +py (const twin_gpoint_t *p, int i) +{ + return p[i].y << 1; +} + +static void +twin_dump_glyphs (void) +{ + twin_ucs4_t ucs4; + int offset = 0; + int i, j; + twin_gop_t *gop; + + for (ucs4 = 0; ucs4 < 0x80; ucs4++) + { + const twin_gpoint_t *p = _twin_ucs4_base (ucs4); + twin_glyph_t *g = &glyphs[ucs4]; + twin_stroke_t *s; + twin_gfixed_t origin; + twin_gfixed_t left, right, top, bottom; + twin_gfixed_t baseline; + twin_gfixed_t x, y; + twin_bool_t move; + + g->ucs4 = ucs4; + g->n = 0; + + if (ucs4 && p == _twin_glyphs) continue; + + if (p[1].y == -64) { - if (p[i].x == p[i+1].x) + origin = 0; + left = 0; + right = 4; + top = 18; + bottom = 18; + baseline = 18; + } + else + { + origin = 64; + left = 64; + right = -64; + top = 64; + bottom = -64; + baseline = 18; + for (i = 1, move = TWIN_TRUE; p[i].y != -64; i++) { - x = SNAPI(path, x); - skip_xi = i + 2; + if (p[i].x == -64) { move = TWIN_TRUE; continue; } + if (py(p,i) <= baseline && px(p,i) < origin) origin = px(p,i); + if (px(p,i) < left) left = px(p,i); + if (px(p,i) > right) right = px(p,i); + if (py(p,i) < top) top = py(p,i); + if (py(p,i) > bottom) bottom = py(p,i); + move = TWIN_FALSE; } - if (p[i].y == p[i+1].y) + } + left -= origin; + right -= origin;; + bottom -= baseline; + top -= baseline; + + /* + * Convert from hershey format to internal format + */ + for (i = 1, move = TWIN_TRUE; p[i].y != -64; i++) + { + if (p[i].x == -64) { move = TWIN_TRUE; continue; } + + x = px(p,i) - origin; + y = py(p,i) - baseline; + if (move) + if (g->s[g->n].n) + ++g->n; + s = &g->s[g->n]; + s->p[s->n].x = x; + s->p[s->n].y = y; + s->n++; + + move = TWIN_FALSE; + } + if (g->s[g->n].n) + ++g->n; + + g->left = left; + g->right = right; + g->top = top; + g->bottom = bottom; + + /* + * Find snap points + */ + twin_add_snap (&g->snap_x, 0); /* origin */ + twin_add_snap (&g->snap_x, right); /* right */ + + twin_add_snap (&g->snap_y, 0); /* baseline */ + twin_add_snap (&g->snap_y, -15); /* x height */ + twin_add_snap (&g->snap_y, -21); /* cap height */ + + for (i = 0; i < g->n; i++) + { + s = &g->s[i]; + for (j = 0; j < s->n - 1; j++) { - y = SNAPI(path, y); - skip_yi = i + 2; + if (s->p[j].x == s->p[j+1].x) + twin_add_snap (&g->snap_x, s->p[j].x); + if (s->p[j].y == s->p[j+1].y) + twin_add_snap (&g->snap_y, s->p[j].y); } } - if (i >= next_xi) + + /* + * Now convert to gops and try to locate splines + */ + + gop = &g->op[0]; + for (i = 0; i < g->n; i++) { - if (x < left) - left = x; - if (x > right) - right = x; + s = &g->s[i]; + gop->cmd = twin_gmove; + gop->p[0] = s->p[0]; + gop++; + for (j = 0; j < s->n - 1;) + { + int ns = twin_n_in_spline (s->p + j, s->n - j); + + if (ns) + { + twin_spline_fit (s->p + j, ns, + &gop->p[0], &gop->p[1]); + gop->cmd = twin_gcurve; + gop->p[2] = s->p[j + ns - 1]; + gop++; + j += ns; + } + else + { + gop->cmd = twin_gline; + gop->p[0] = s->p[j+1]; + gop++; + j++; + } + } } - if (i >= next_yi) + g->nop = gop - &g->op[0]; + g->exists = TWIN_TRUE; + } + + printf ("const signed char _twin_gtable[] = {\n"); + for (ucs4 = 0; ucs4 < 0x80; ucs4++) + { + twin_glyph_t *g = &glyphs[ucs4]; + + if (!g->exists) continue; + + g->offset = offset; + + printf ("/* 0x%x '%s' */\n", g->ucs4, _ucs4_string (g->ucs4)); + printf (" %d, %d, %d, %d, %d, %d,\n", + g->left, g->right, -g->top, g->bottom, g->snap_x.n, g->snap_y.n); + + offset += 6; + + printf (" "); + for (i = 0; i < g->snap_x.n; i++) + printf (" %d,", g->snap_x.s[i]); + printf (" /* snap_x */\n"); + + offset += g->snap_x.n; + + printf (" "); + for (i = 0; i < g->snap_y.n; i++) + printf (" %d,", g->snap_y.s[i]); + printf (" /* snap_y */\n"); + + offset += g->snap_y.n; + +#define CO(n) gop->p[n].x, gop->p[n].y + for (i = 0; i < g->nop; i++) { - if (y < top) - top = y; - if (y > bottom) - bottom = y; + gop = &g->op[i]; + switch (gop->cmd) { + case twin_gmove: + printf (" 'm', %d, %d,\n", CO(0)); + offset += 3; + break; + case twin_gline: + printf (" 'l', %d, %d,\n", CO(0)); + offset += 3; + break; + case twin_gcurve: + printf (" 'c', %d, %d, %d, %d, %d, %d,\n", + CO(0), CO(1), CO(2)); + offset += 7; + break; + } } + printf (" 'e',\n"); + offset++; } - - left -= pen_size * 2; - right += pen_size * 2; - - if (i == 1) + printf ("};\n\n"); + printf ("const uint16_t _twin_g_offsets[] = {"); + for (ucs4 = 0; ucs4 < 0x80; ucs4++) { - left = Scale(p[0].x); - top = bottom = baseline; - right = Scale(p[0].y); + twin_glyph_t *g = &glyphs[ucs4]; + + if ((ucs4 & 7) == 0) + printf ("\n "); + else + printf (" "); + printf ("%4d,", g->offset); } - m->left_side_bearing = SNAPI(path, -left); - m->right_side_bearing = SNAPI(path,right); - m->width = m->left_side_bearing + m->right_side_bearing; - m->ascent = baseline - SNAPI(path, top); - m->descent = SNAPI(path, bottom) - baseline; - m->font_descent = SNAPI(path, path->state.font_size / 3); - m->font_ascent = SNAPI(path,path->state.font_size) - m->font_descent; + printf ("\n};\n"); + fflush (stdout); + exit (0); } void twin_path_ucs4 (twin_path_t *path, twin_ucs4_t ucs4) { - const twin_gpoint_t *p = _twin_ucs4_base (ucs4); - int i; + const signed char *b = _twin_g_base (ucs4); + const signed char *g = twin_glyph_draw(b); twin_spoint_t origin; - twin_fixed_t xc, yc; - twin_sfixed_t sx, sy; + twin_fixed_t x1, y1, x2, y2, x3, y3; + twin_fixed_t xo, yo; twin_path_t *stroke; twin_path_t *pen; - twin_fixed_t w; - twin_fixed_t x, y; - twin_fixed_t pen_size; + twin_fixed_t pen_size = _twin_pen_size (path); twin_matrix_t pen_matrix; - twin_fixed_t pen_adjust; - twin_gfixed_t snap_x[TWIN_GLYPH_MAX_POINTS]; - twin_gfixed_t snap_y[TWIN_GLYPH_MAX_POINTS]; twin_text_metrics_t metrics; - int nsnap_x = 0, nsnap_y = 0; + if (0) + { + static int been_here = 0; + if (!been_here) { been_here = 1; twin_dump_glyphs (); } + } + twin_text_metrics_ucs4 (path, ucs4, &metrics); origin = _twin_path_current_spoint (path); - if (Hint (path)) - { - nsnap_x = 0; - nsnap_y = 0; - - /* snap left and right boundaries */ - - nsnap_x = _add_snap (snap_x, nsnap_x, p[0].x); - nsnap_x = _add_snap (snap_x, nsnap_x, p[0].y); - - /* snap baseline, x height and cap height */ - nsnap_y = _add_snap (snap_y, nsnap_y, 9); - nsnap_y = _add_snap (snap_y, nsnap_y, -5); - nsnap_y = _add_snap (snap_y, nsnap_y, -12); - - /* - * Locate horizontal and vertical segments - */ - for (i = 1; p[i].y != -64 && p[i+1].y != -64; i++) - { - if (p[i].x == -64 || p[i+1].x == -64) - continue; - if (p[i].x == p[i+1].x) - nsnap_x = _add_snap (snap_x, nsnap_x, p[i].x); - if (p[i].y == p[i+1].y) - nsnap_y = _add_snap (snap_y, nsnap_y, p[i].y); - } - - qsort (snap_x, nsnap_x, sizeof (twin_gfixed_t), compare_snap); - qsort (snap_y, nsnap_y, sizeof (twin_gfixed_t), compare_snap); - - DBGMSG (("snap_x:")); - for (i = 0; i < nsnap_x; i++) - DBGMSG ((" %d", snap_x[i])); - DBGMSG (("\n")); - - DBGMSG (("snap_y:")); - for (i = 0; i < nsnap_y; i++) - DBGMSG ((" %d", snap_y[i])); - DBGMSG (("\n")); - } - stroke = twin_path_create (); - twin_path_set_matrix (stroke, twin_path_current_matrix (path)); - pen_size = _twin_pen_size (path); - - if (Hint (path)) - pen_adjust = pen_size & TWIN_FIXED_HALF; - else - pen_adjust = 0; + twin_path_set_matrix (stroke, twin_path_current_matrix (path)); pen = twin_path_create (); pen_matrix = twin_path_current_matrix (path); @@ -303,35 +508,55 @@ twin_path_circle (pen, pen_size); - xc = metrics.left_side_bearing + pen_adjust; - yc = SNAPY(TWIN_FONT_BASELINE) + pen_adjust; +#define PX(_x,_y) (origin.x + _twin_matrix_dx (&path->state.matrix, _x, _y)) +#define PY(_x,_y) (origin.y + _twin_matrix_dy (&path->state.matrix, _x, _y)) - for (i = 1; p[i].y != -64; i++) - if (p[i].x == -64) - twin_path_close (stroke); - else - { - x = xc + SNAPX(p[i].x); - y = yc + SNAPY(p[i].y); - + xo = pen_size * 3; + yo = -pen_size; + + for (;;) { + switch (*g++) { + case 'm': + x1 = Scale (*g++) + xo; + y1 = Scale (*g++) + yo; if (path->state.font_style & TWIN_TEXT_OBLIQUE) - x -= y / 4; - sx = origin.x + _twin_matrix_dx (&path->state.matrix, x, y); - sy = origin.y + _twin_matrix_dy (&path->state.matrix, x, y); - DBGMSG(("x: %9.4f, y: %9.4f -> sx: %9.4f, sy: %9.4f\n", - F(x), F(y), S(sx), S(sy))); - _twin_path_sdraw (stroke, sx, sy); + x1 -= y1 >> 2; + _twin_path_smove (stroke, PX(x1,y1), PY(x1,y1)); + continue; + case 'l': + x1 = Scale (*g++) + xo; + y1 = Scale (*g++) + yo; + if (path->state.font_style & TWIN_TEXT_OBLIQUE) + x1 -= y1 >> 2; + _twin_path_sdraw (stroke, PX(x1,y1), PY(x1,y1)); + continue; + case 'c': + x1 = Scale (*g++) + xo; + y1 = Scale (*g++) + yo; + x2 = Scale (*g++) + xo; + y2 = Scale (*g++) + yo; + x3 = Scale (*g++) + xo; + y3 = Scale (*g++) + yo; + if (path->state.font_style & TWIN_TEXT_OBLIQUE) + { + x1 -= y1 >> 2; + x2 -= y2 >> 2; + x3 -= y3 >> 2; + } + _twin_path_scurve (stroke, PX(x1,y1), PY(x1,y1), + PX(x2,y2), PY(x2,y2), PX(x3,y3), PY(x3,y3)); + continue; + case 'e': + break; } + break; + } twin_path_convolve (path, stroke, pen); twin_path_destroy (stroke); twin_path_destroy (pen); - w = metrics.width; - - _twin_path_smove (path, - origin.x + _twin_matrix_dx (&path->state.matrix, w, 0), - origin.y + _twin_matrix_dy (&path->state.matrix, w, 0)); + _twin_path_smove (path, PX(metrics.width, 0), PY(metrics.width,0)); } twin_fixed_t @@ -454,20 +679,23 @@ { twin_text_metrics_ucs4 (path, ucs4, &c); if (first) + { *m = c; + first = TWIN_FALSE; + } else { c.left_side_bearing += w; c.right_side_bearing += w; c.width += w; - if (c.left_side_bearing > m->left_side_bearing) + if (c.left_side_bearing < m->left_side_bearing) m->left_side_bearing = c.left_side_bearing; if (c.right_side_bearing > m->right_side_bearing) m->right_side_bearing = c.right_side_bearing; if (c.width > m->width) m->width = c.width; - if (c.ascent < m->ascent) + if (c.ascent > m->ascent) m->ascent = c.ascent; if (c.descent > m->descent) m->descent = c.descent; Index: twin_glyphs.c =================================================================== RCS file: /local/src/CVS/twin/twin_glyphs.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_glyphs.c 25 Sep 2004 06:41:19 -0000 1.3 +++ twin_glyphs.c 4 Oct 2004 07:49:49 -0000 1.4 @@ -446,3 +446,1567 @@ /* 0x78 */ 1233, 1240, 1251, 1261, 1274, 1278, 1291, 0, }; + +const signed char _twin_gtable[] = { +/* 0x0 '\0' */ + 0, 24, 42, 0, 2, 4, + 0, 24, /* snap_x */ + -42, -21, -15, 0, /* snap_y */ + 'm', 0, -2, + 'l', 0, -42, [...1536 lines suppressed...] +}; + +const uint16_t _twin_g_offsets[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 28, 40, 74, 98, 136, 223, 328, 445, + 478, 520, 562, 593, 619, 655, 674, 701, + 718, 782, 806, 863, 922, 951, 1016, 1099, + 1124, 1226, 1309, 1351, 1402, 1423, 1449, 1470, + 1541, 1711, 1742, 1819, 1886, 1941, 1979, 2011, + 2088, 2119, 2136, 2178, 2208, 2232, 2268, 2298, + 2374, 2424, 2506, 2562, 2635, 2661, 2703, 2727, + 2763, 2787, 2815, 2846, 2871, 2889, 2914, 2938, + 2956, 2989, 3050, 3111, 3166, 3227, 3292, 3328, + 3405, 3445, 3479, 3523, 3553, 3570, 3632, 3672, + 3736, 3797, 3858, 3892, 3956, 3991, 4030, 4054, + 4090, 4114, 4151, 4182, 4230, 4247, 4295, 0, +}; Index: twin_matrix.c =================================================================== RCS file: /local/src/CVS/twin/twin_matrix.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_matrix.c 28 Sep 2004 05:42:36 -0000 1.2 +++ twin_matrix.c 4 Oct 2004 07:49:49 -0000 1.3 @@ -119,6 +119,21 @@ return det; } +twin_point_t +_twin_matrix_expand (twin_matrix_t *matrix) +{ + twin_fixed_t a = matrix->m[0][0]; + twin_fixed_t d = matrix->m[1][1]; + twin_fixed_t aa = twin_fixed_mul (a,a); + twin_fixed_t dd = twin_fixed_mul (d,d); + twin_point_t expand; + + expand.x = twin_fixed_sqrt (aa + dd); + expand.y = twin_fixed_div (_twin_matrix_determinant (matrix), + expand.x); + return expand; +} + void twin_matrix_rotate (twin_matrix_t *m, twin_angle_t a) { Index: twin_path.c =================================================================== RCS file: /local/src/CVS/twin/twin_path.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- twin_path.c 2 Oct 2004 03:07:26 -0000 1.8 +++ twin_path.c 4 Oct 2004 07:49:49 -0000 1.9 @@ -115,6 +115,17 @@ } void +twin_path_rmove (twin_path_t *path, twin_fixed_t dx, twin_fixed_t dy) +{ + twin_spoint_t here = _twin_path_current_spoint (path); + _twin_path_smove (path, + here.x + + _twin_matrix_dx (&path->state.matrix, dx, dy), + here.y + + _twin_matrix_dy (&path->state.matrix, dx, dy)); +} + +void twin_path_draw (twin_path_t *path, twin_fixed_t x, twin_fixed_t y) { _twin_path_sdraw (path, @@ -123,6 +134,17 @@ } void +twin_path_rdraw (twin_path_t *path, twin_fixed_t dx, twin_fixed_t dy) +{ + twin_spoint_t here = _twin_path_current_spoint (path); + _twin_path_sdraw (path, + here.x + + _twin_matrix_dx (&path->state.matrix, dx, dy), + here.y + + _twin_matrix_dy (&path->state.matrix, dx, dy)); +} + +void twin_path_close (twin_path_t *path) { switch (_twin_current_subpath_len(path)) { Index: twin_spline.c =================================================================== RCS file: /local/src/CVS/twin/twin_spline.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_spline.c 27 Sep 2004 21:28:31 -0000 1.3 +++ twin_spline.c 4 Oct 2004 07:49:49 -0000 1.4 @@ -102,7 +102,7 @@ } } -static void +void _twin_path_scurve (twin_path_t *path, twin_sfixed_t x1, twin_sfixed_t y1, twin_sfixed_t x2, twin_sfixed_t y2, Index: twin_trig.c =================================================================== RCS file: /local/src/CVS/twin/twin_trig.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_trig.c 27 Sep 2004 21:28:31 -0000 1.1 +++ twin_trig.c 4 Oct 2004 07:49:49 -0000 1.2 @@ -24,45 +24,149 @@ #include "twinint.h" -#define TWIN_LOG2_SIN 8 +#define TWIN_LOG2_SIN 10 + +/* + * construction: + int s = 10; for (int i = 0; i < (1 << s); i++) { + if (i % 8 == 0) printf ("\n "); + printf (" 0x%04x,", floor (sin(pi/2 * i / (1 << s)) * 2**16 + 0.5)); + } + */ static const uint16_t _twin_sin_table[1 << TWIN_LOG2_SIN] = { - 0x0000, 0x0192, 0x0324, 0x04b6, 0x0648, 0x07da, 0x096c, 0x0afe, - 0x0c90, 0x0e21, 0x0fb3, 0x1144, 0x12d5, 0x1466, 0x15f7, 0x1787, - 0x1918, 0x1aa8, 0x1c38, 0x1dc7, 0x1f56, 0x20e5, 0x2274, 0x2402, - 0x2590, 0x271e, 0x28ab, 0x2a38, 0x2bc4, 0x2d50, 0x2edc, 0x3067, - 0x31f1, 0x337c, 0x3505, 0x368e, 0x3817, 0x399f, 0x3b27, 0x3cae, - 0x3e34, 0x3fba, 0x413f, 0x42c3, 0x4447, 0x45cb, 0x474d, 0x48cf, - 0x4a50, 0x4bd1, 0x4d50, 0x4ecf, 0x504d, 0x51cb, 0x5348, 0x54c3, - 0x563e, 0x57b9, 0x5932, 0x5aaa, 0x5c22, 0x5d99, 0x5f0f, 0x6084, - 0x61f8, 0x636b, 0x64dd, 0x664e, 0x67be, 0x692d, 0x6a9b, 0x6c08, - 0x6d74, 0x6edf, 0x7049, 0x71b2, 0x731a, 0x7480, 0x75e6, 0x774a, - 0x78ad, 0x7a10, 0x7b70, 0x7cd0, 0x7e2f, 0x7f8c, 0x80e8, 0x8243, - 0x839c, 0x84f5, 0x864c, 0x87a1, 0x88f6, 0x8a49, 0x8b9a, 0x8ceb, - 0x8e3a, 0x8f88, 0x90d4, 0x921f, 0x9368, 0x94b0, 0x95f7, 0x973c, - 0x9880, 0x99c2, 0x9b03, 0x9c42, 0x9d80, 0x9ebc, 0x9ff7, 0xa130, - 0xa268, 0xa39e, 0xa4d2, 0xa605, 0xa736, 0xa866, 0xa994, 0xaac1, - 0xabeb, 0xad14, 0xae3c, 0xaf62, 0xb086, 0xb1a8, 0xb2c9, 0xb3e8, - 0xb505, 0xb620, 0xb73a, 0xb852, 0xb968, 0xba7d, 0xbb8f, 0xbca0, - 0xbdaf, 0xbebc, 0xbfc7, 0xc0d1, 0xc1d8, 0xc2de, 0xc3e2, 0xc4e4, - 0xc5e4, 0xc6e2, 0xc7de, 0xc8d9, 0xc9d1, 0xcac7, 0xcbbc, 0xccae, - 0xcd9f, 0xce8e, 0xcf7a, 0xd065, 0xd14d, 0xd234, 0xd318, 0xd3fb, - 0xd4db, 0xd5ba, 0xd696, 0xd770, 0xd848, 0xd91e, 0xd9f2, 0xdac4, - 0xdb94, 0xdc62, 0xdd2d, 0xddf7, 0xdebe, 0xdf83, 0xe046, 0xe107, - 0xe1c6, 0xe282, 0xe33c, 0xe3f4, 0xe4aa, 0xe55e, 0xe610, 0xe6bf, - 0xe76c, 0xe817, 0xe8bf, 0xe966, 0xea0a, 0xeaab, 0xeb4b, 0xebe8, - 0xec83, 0xed1c, 0xedb3, 0xee47, 0xeed9, 0xef68, 0xeff5, 0xf080, - 0xf109, 0xf18f, 0xf213, 0xf295, 0xf314, 0xf391, 0xf40c, 0xf484, - 0xf4fa, 0xf56e, 0xf5df, 0xf64e, 0xf6ba, 0xf724, 0xf78c, 0xf7f1, - 0xf854, 0xf8b4, 0xf913, 0xf96e, 0xf9c8, 0xfa1f, 0xfa73, 0xfac5, - 0xfb15, 0xfb62, 0xfbad, 0xfbf5, 0xfc3b, 0xfc7f, 0xfcc0, 0xfcfe, - 0xfd3b, 0xfd74, 0xfdac, 0xfde1, 0xfe13, 0xfe43, 0xfe71, 0xfe9c, - 0xfec4, 0xfeeb, 0xff0e, 0xff30, 0xff4e, 0xff6b, 0xff85, 0xff9c, - 0xffb1, 0xffc4, 0xffd4, 0xffe1, 0xffec, 0xfff5, 0xfffb, 0xffff, + 0x0000, 0x0065, 0x00c9, 0x012e, 0x0192, 0x01f7, 0x025b, 0x02c0, + 0x0324, 0x0389, 0x03ed, 0x0452, 0x04b6, 0x051b, 0x057f, 0x05e4, + 0x0648, 0x06ad, 0x0711, 0x0776, 0x07da, 0x083f, 0x08a3, 0x0908, + 0x096c, 0x09d1, 0x0a35, 0x0a9a, 0x0afe, 0x0b62, 0x0bc7, 0x0c2b, + 0x0c90, 0x0cf4, 0x0d59, 0x0dbd, 0x0e21, 0x0e86, 0x0eea, 0x0f4e, + 0x0fb3, 0x1017, 0x107b, 0x10e0, 0x1144, 0x11a8, 0x120d, 0x1271, + 0x12d5, 0x1339, 0x139e, 0x1402, 0x1466, 0x14ca, 0x152e, 0x1593, + 0x15f7, 0x165b, 0x16bf, 0x1723, 0x1787, 0x17eb, 0x1850, 0x18b4, + 0x1918, 0x197c, 0x19e0, 0x1a44, 0x1aa8, 0x1b0c, 0x1b70, 0x1bd4, + 0x1c38, 0x1c9b, 0x1cff, 0x1d63, 0x1dc7, 0x1e2b, 0x1e8f, 0x1ef3, + 0x1f56, 0x1fba, 0x201e, 0x2082, 0x20e5, 0x2149, 0x21ad, 0x2210, + 0x2274, 0x22d7, 0x233b, 0x239f, 0x2402, 0x2466, 0x24c9, 0x252d, + 0x2590, 0x25f4, 0x2657, 0x26ba, 0x271e, 0x2781, 0x27e4, 0x2848, + 0x28ab, 0x290e, 0x2971, 0x29d5, 0x2a38, 0x2a9b, 0x2afe, 0x2b61, + 0x2bc4, 0x2c27, 0x2c8a, 0x2ced, 0x2d50, 0x2db3, 0x2e16, 0x2e79, + 0x2edc, 0x2f3f, 0x2fa1, 0x3004, 0x3067, 0x30ca, 0x312c, 0x318f, + 0x31f1, 0x3254, 0x32b7, 0x3319, 0x337c, 0x33de, 0x3440, 0x34a3, + 0x3505, 0x3568, 0x35ca, 0x362c, 0x368e, 0x36f1, 0x3753, 0x37b5, + 0x3817, 0x3879, 0x38db, 0x393d, 0x399f, 0x3a01, 0x3a63, 0x3ac5, + 0x3b27, 0x3b88, 0x3bea, 0x3c4c, 0x3cae, 0x3d0f, 0x3d71, 0x3dd2, + 0x3e34, 0x3e95, 0x3ef7, 0x3f58, 0x3fba, 0x401b, 0x407c, 0x40de, + 0x413f, 0x41a0, 0x4201, 0x4262, 0x42c3, 0x4324, 0x4385, 0x43e6, + 0x4447, 0x44a8, 0x4509, 0x456a, 0x45cb, 0x462b, 0x468c, 0x46ec, + 0x474d, 0x47ae, 0x480e, 0x486f, 0x48cf, 0x492f, 0x4990, 0x49f0, + 0x4a50, 0x4ab0, 0x4b10, 0x4b71, 0x4bd1, 0x4c31, 0x4c90, 0x4cf0, + 0x4d50, 0x4db0, 0x4e10, 0x4e70, 0x4ecf, 0x4f2f, 0x4f8e, 0x4fee, + 0x504d, 0x50ad, 0x510c, 0x516c, 0x51cb, 0x522a, 0x5289, 0x52e8, + 0x5348, 0x53a7, 0x5406, 0x5464, 0x54c3, 0x5522, 0x5581, 0x55e0, + 0x563e, 0x569d, 0x56fc, 0x575a, 0x57b9, 0x5817, 0x5875, 0x58d4, + 0x5932, 0x5990, 0x59ee, 0x5a4c, 0x5aaa, 0x5b08, 0x5b66, 0x5bc4, + 0x5c22, 0x5c80, 0x5cde, 0x5d3b, 0x5d99, 0x5df6, 0x5e54, 0x5eb1, + 0x5f0f, 0x5f6c, 0x5fc9, 0x6026, 0x6084, 0x60e1, 0x613e, 0x619b, + 0x61f8, 0x6254, 0x62b1, 0x630e, 0x636b, 0x63c7, 0x6424, 0x6480, + 0x64dd, 0x6539, 0x6595, 0x65f2, 0x664e, 0x66aa, 0x6706, 0x6762, + 0x67be, 0x681a, 0x6876, 0x68d1, 0x692d, 0x6989, 0x69e4, 0x6a40, + 0x6a9b, 0x6af6, 0x6b52, 0x6bad, 0x6c08, 0x6c63, 0x6cbe, 0x6d19, + 0x6d74, 0x6dcf, 0x6e2a, 0x6e85, 0x6edf, 0x6f3a, 0x6f94, 0x6fef, + 0x7049, 0x70a3, 0x70fe, 0x7158, 0x71b2, 0x720c, 0x7266, 0x72c0, + 0x731a, 0x7373, 0x73cd, 0x7427, 0x7480, 0x74da, 0x7533, 0x758d, + 0x75e6, 0x763f, 0x7698, 0x76f1, 0x774a, 0x77a3, 0x77fc, 0x7855, + 0x78ad, 0x7906, 0x795f, 0x79b7, 0x7a10, 0x7a68, 0x7ac0, 0x7b18, + 0x7b70, 0x7bc8, 0x7c20, 0x7c78, 0x7cd0, 0x7d28, 0x7d7f, 0x7dd7, + 0x7e2f, 0x7e86, 0x7edd, 0x7f35, 0x7f8c, 0x7fe3, 0x803a, 0x8091, + 0x80e8, 0x813f, 0x8195, 0x81ec, 0x8243, 0x8299, 0x82f0, 0x8346, + 0x839c, 0x83f2, 0x8449, 0x849f, 0x84f5, 0x854a, 0x85a0, 0x85f6, + 0x864c, 0x86a1, 0x86f7, 0x874c, 0x87a1, 0x87f6, 0x884c, 0x88a1, + 0x88f6, 0x894a, 0x899f, 0x89f4, 0x8a49, 0x8a9d, 0x8af2, 0x8b46, + 0x8b9a, 0x8bef, 0x8c43, 0x8c97, 0x8ceb, 0x8d3f, 0x8d93, 0x8de6, + 0x8e3a, 0x8e8d, 0x8ee1, 0x8f34, 0x8f88, 0x8fdb, 0x902e, 0x9081, + 0x90d4, 0x9127, 0x9179, 0x91cc, 0x921f, 0x9271, 0x92c4, 0x9316, + 0x9368, 0x93ba, 0x940c, 0x945e, 0x94b0, 0x9502, 0x9554, 0x95a5, + 0x95f7, 0x9648, 0x969a, 0x96eb, 0x973c, 0x978d, 0x97de, 0x982f, + 0x9880, 0x98d0, 0x9921, 0x9972, 0x99c2, 0x9a12, 0x9a63, 0x9ab3, + 0x9b03, 0x9b53, 0x9ba3, 0x9bf2, 0x9c42, 0x9c92, 0x9ce1, 0x9d31, + 0x9d80, 0x9dcf, 0x9e1e, 0x9e6d, 0x9ebc, 0x9f0b, 0x9f5a, 0x9fa8, + 0x9ff7, 0xa045, 0xa094, 0xa0e2, 0xa130, 0xa17e, 0xa1cc, 0xa21a, + 0xa268, 0xa2b5, 0xa303, 0xa350, 0xa39e, 0xa3eb, 0xa438, 0xa485, + 0xa4d2, 0xa51f, 0xa56c, 0xa5b8, 0xa605, 0xa652, 0xa69e, 0xa6ea, + 0xa736, 0xa782, 0xa7ce, 0xa81a, 0xa866, 0xa8b2, 0xa8fd, 0xa949, + 0xa994, 0xa9df, 0xaa2a, 0xaa76, 0xaac1, 0xab0b, 0xab56, 0xaba1, + 0xabeb, 0xac36, 0xac80, 0xacca, 0xad14, 0xad5e, 0xada8, 0xadf2, + 0xae3c, 0xae85, 0xaecf, 0xaf18, 0xaf62, 0xafab, 0xaff4, 0xb03d, + 0xb086, 0xb0ce, 0xb117, 0xb160, 0xb1a8, 0xb1f0, 0xb239, 0xb281, + 0xb2c9, 0xb311, 0xb358, 0xb3a0, 0xb3e8, 0xb42f, 0xb477, 0xb4be, + 0xb505, 0xb54c, 0xb593, 0xb5da, 0xb620, 0xb667, 0xb6ad, 0xb6f4, + 0xb73a, 0xb780, 0xb7c6, 0xb80c, 0xb852, 0xb898, 0xb8dd, 0xb923, + 0xb968, 0xb9ae, 0xb9f3, 0xba38, 0xba7d, 0xbac1, 0xbb06, 0xbb4b, + 0xbb8f, 0xbbd4, 0xbc18, 0xbc5c, 0xbca0, 0xbce4, 0xbd28, 0xbd6b, + 0xbdaf, 0xbdf2, 0xbe36, 0xbe79, 0xbebc, 0xbeff, 0xbf42, 0xbf85, + 0xbfc7, 0xc00a, 0xc04c, 0xc08f, 0xc0d1, 0xc113, 0xc155, 0xc197, + 0xc1d8, 0xc21a, 0xc25c, 0xc29d, 0xc2de, 0xc31f, 0xc360, 0xc3a1, + 0xc3e2, 0xc423, 0xc463, 0xc4a4, 0xc4e4, 0xc524, 0xc564, 0xc5a4, + 0xc5e4, 0xc624, 0xc663, 0xc6a3, 0xc6e2, 0xc721, 0xc761, 0xc7a0, + 0xc7de, 0xc81d, 0xc85c, 0xc89a, 0xc8d9, 0xc917, 0xc955, 0xc993, + 0xc9d1, 0xca0f, 0xca4d, 0xca8a, 0xcac7, 0xcb05, 0xcb42, 0xcb7f, + 0xcbbc, 0xcbf9, 0xcc35, 0xcc72, 0xccae, 0xcceb, 0xcd27, 0xcd63, + 0xcd9f, 0xcddb, 0xce17, 0xce52, 0xce8e, 0xcec9, 0xcf04, 0xcf3f, + 0xcf7a, 0xcfb5, 0xcff0, 0xd02a, 0xd065, 0xd09f, 0xd0d9, 0xd113, + 0xd14d, 0xd187, 0xd1c1, 0xd1fa, 0xd234, 0xd26d, 0xd2a6, 0xd2df, + 0xd318, 0xd351, 0xd38a, 0xd3c2, 0xd3fb, 0xd433, 0xd46b, 0xd4a3, + 0xd4db, 0xd513, 0xd54b, 0xd582, 0xd5ba, 0xd5f1, 0xd628, 0xd65f, + 0xd696, 0xd6cd, 0xd703, 0xd73a, 0xd770, 0xd7a6, 0xd7dc, 0xd812, + 0xd848, 0xd87e, 0xd8b4, 0xd8e9, 0xd91e, 0xd954, 0xd989, 0xd9be, + 0xd9f2, 0xda27, 0xda5c, 0xda90, 0xdac4, 0xdaf8, 0xdb2c, 0xdb60, + 0xdb94, 0xdbc8, 0xdbfb, 0xdc2f, 0xdc62, 0xdc95, 0xdcc8, 0xdcfb, + 0xdd2d, 0xdd60, 0xdd92, 0xddc5, 0xddf7, 0xde29, 0xde5b, 0xde8c, + 0xdebe, 0xdef0, 0xdf21, 0xdf52, 0xdf83, 0xdfb4, 0xdfe5, 0xe016, + 0xe046, 0xe077, 0xe0a7, 0xe0d7, 0xe107, 0xe137, 0xe167, 0xe196, + 0xe1c6, 0xe1f5, 0xe224, 0xe253, 0xe282, 0xe2b1, 0xe2df, 0xe30e, + 0xe33c, 0xe36b, 0xe399, 0xe3c7, 0xe3f4, 0xe422, 0xe450, 0xe47d, + 0xe4aa, 0xe4d7, 0xe504, 0xe531, 0xe55e, 0xe58b, 0xe5b7, 0xe5e3, + 0xe610, 0xe63c, 0xe667, 0xe693, 0xe6bf, 0xe6ea, 0xe716, 0xe741, + 0xe76c, 0xe797, 0xe7c2, 0xe7ec, 0xe817, 0xe841, 0xe86b, 0xe895, + 0xe8bf, 0xe8e9, 0xe913, 0xe93c, 0xe966, 0xe98f, 0xe9b8, 0xe9e1, + 0xea0a, 0xea32, 0xea5b, 0xea83, 0xeaab, 0xead4, 0xeafc, 0xeb23, + 0xeb4b, 0xeb73, 0xeb9a, 0xebc1, 0xebe8, 0xec0f, 0xec36, 0xec5d, + 0xec83, 0xecaa, 0xecd0, 0xecf6, 0xed1c, 0xed42, 0xed68, 0xed8d, + 0xedb3, 0xedd8, 0xedfd, 0xee22, 0xee47, 0xee6b, 0xee90, 0xeeb4, + 0xeed9, 0xeefd, 0xef21, 0xef45, 0xef68, 0xef8c, 0xefaf, 0xefd2, + 0xeff5, 0xf018, 0xf03b, 0xf05e, 0xf080, 0xf0a3, 0xf0c5, 0xf0e7, + 0xf109, 0xf12b, 0xf14c, 0xf16e, 0xf18f, 0xf1b1, 0xf1d2, 0xf1f3, + 0xf213, 0xf234, 0xf254, 0xf275, 0xf295, 0xf2b5, 0xf2d5, 0xf2f5, + 0xf314, 0xf334, 0xf353, 0xf372, 0xf391, 0xf3b0, 0xf3cf, 0xf3ed, + 0xf40c, 0xf42a, 0xf448, 0xf466, 0xf484, 0xf4a2, 0xf4bf, 0xf4dd, + 0xf4fa, 0xf517, 0xf534, 0xf551, 0xf56e, 0xf58a, 0xf5a6, 0xf5c3, + 0xf5df, 0xf5fb, 0xf616, 0xf632, 0xf64e, 0xf669, 0xf684, 0xf69f, + 0xf6ba, 0xf6d5, 0xf6ef, 0xf70a, 0xf724, 0xf73e, 0xf758, 0xf772, + 0xf78c, 0xf7a5, 0xf7bf, 0xf7d8, 0xf7f1, 0xf80a, 0xf823, 0xf83b, + 0xf854, 0xf86c, 0xf885, 0xf89d, 0xf8b4, 0xf8cc, 0xf8e4, 0xf8fb, + 0xf913, 0xf92a, 0xf941, 0xf958, 0xf96e, 0xf985, 0xf99b, 0xf9b2, + 0xf9c8, 0xf9de, 0xf9f3, 0xfa09, 0xfa1f, 0xfa34, 0xfa49, 0xfa5e, + 0xfa73, 0xfa88, 0xfa9c, 0xfab1, 0xfac5, 0xfad9, 0xfaed, 0xfb01, + 0xfb15, 0xfb28, 0xfb3c, 0xfb4f, 0xfb62, 0xfb75, 0xfb88, 0xfb9a, + 0xfbad, 0xfbbf, 0xfbd1, 0xfbe3, 0xfbf5, 0xfc07, 0xfc18, 0xfc2a, + 0xfc3b, 0xfc4c, 0xfc5d, 0xfc6e, 0xfc7f, 0xfc8f, 0xfca0, 0xfcb0, + 0xfcc0, 0xfcd0, 0xfcdf, 0xfcef, 0xfcfe, 0xfd0e, 0xfd1d, 0xfd2c, + 0xfd3b, 0xfd49, 0xfd58, 0xfd66, 0xfd74, 0xfd83, 0xfd90, 0xfd9e, + 0xfdac, 0xfdb9, 0xfdc7, 0xfdd4, 0xfde1, 0xfdee, 0xfdfa, 0xfe07, + 0xfe13, 0xfe1f, 0xfe2b, 0xfe37, 0xfe43, 0xfe4f, 0xfe5a, 0xfe66, + 0xfe71, 0xfe7c, 0xfe87, 0xfe91, 0xfe9c, 0xfea6, 0xfeb0, 0xfeba, + 0xfec4, 0xfece, 0xfed8, 0xfee1, 0xfeeb, 0xfef4, 0xfefd, 0xff06, + 0xff0e, 0xff17, 0xff1f, 0xff28, 0xff30, 0xff38, 0xff3f, 0xff47, + 0xff4e, 0xff56, 0xff5d, 0xff64, 0xff6b, 0xff71, 0xff78, 0xff7e, + 0xff85, 0xff8b, 0xff91, 0xff96, 0xff9c, 0xffa2, 0xffa7, 0xffac, + 0xffb1, 0xffb6, 0xffbb, 0xffbf, 0xffc4, 0xffc8, 0xffcc, 0xffd0, + 0xffd4, 0xffd7, 0xffdb, 0xffde, 0xffe1, 0xffe4, 0xffe7, 0xffea, + 0xffec, 0xffef, 0xfff1, 0xfff3, 0xfff5, 0xfff7, 0xfff8, 0xfffa, + 0xfffb, 0xfffc, 0xfffd, 0xfffe, 0xffff, 0xffff, 0xffff, 0xffff, }; /* - * angles are measured from -512 .. 512 + * angles are measured from -2048 .. 2048 */ #if 0 Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_x11.c 2 Oct 2004 03:07:26 -0000 1.3 +++ twin_x11.c 4 Oct 2004 07:49:49 -0000 1.4 @@ -75,7 +75,7 @@ if (tx->iy == tx->image->height) { XPutImage (tx->dpy, tx->win, tx->gc, tx->image, 0, 0, - x, y - tx->iy, width, tx->image->height); + x, (y + 1) - tx->iy, width, tx->image->height); XDestroyImage (tx->image); tx->image = 0; } @@ -126,9 +126,7 @@ { twin_x11_t *tx = closure; - pthread_mutex_unlock (&tx->screen->screen_mutex); pthread_cond_broadcast (&tx->damage_cond); - pthread_mutex_unlock (&tx->screen->screen_mutex); } twin_x11_t * @@ -210,8 +208,10 @@ void twin_x11_damage (twin_x11_t *tx, XExposeEvent *ev) { + twin_screen_lock (tx->screen); twin_screen_damage (tx->screen, ev->x, ev->y, ev->x + ev->width, ev->y + ev->height); + twin_screen_unlock (tx->screen); } void Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- twinint.h 2 Oct 2004 03:07:26 -0000 1.9 +++ twinint.h 4 Oct 2004 07:49:49 -0000 1.10 @@ -118,7 +118,7 @@ /* Geometrical objects */ -typedef struct _twin_point { +typedef struct _twin_spoint { twin_sfixed_t x, y; } twin_spoint_t; @@ -311,6 +311,8 @@ twin_sfixed_t _twin_matrix_len (twin_matrix_t *m, twin_fixed_t dx, twin_fixed_t dy); +twin_point_t +_twin_matrix_expand (twin_matrix_t *matrix); /* * Path stuff */ @@ -331,6 +333,12 @@ void _twin_path_sdraw (twin_path_t *path, twin_sfixed_t x, twin_sfixed_t y); +void +_twin_path_scurve (twin_path_t *path, + twin_sfixed_t x1, twin_sfixed_t y1, + twin_sfixed_t x2, twin_sfixed_t y2, + twin_sfixed_t x3, twin_sfixed_t y3); + /* * Glyph stuff. Coordinates are stored in 2.6 fixed point format */ @@ -342,4 +350,17 @@ #define TWIN_GLYPH_MAX_POINTS 56 +extern const signed char _twin_gtable[]; +extern const uint16_t _twin_g_offsets[]; + +#define twin_glyph_left(g) ((g)[0]) +#define twin_glyph_right(g) ((g)[1]) +#define twin_glyph_ascent(g) ((g)[2]) +#define twin_glyph_descent(g) ((g)[3]) +#define twin_glyph_n_snap_x(g) ((g)[4]) +#define twin_glyph_n_snap_y(g) ((g)[5]) +#define twin_glyph_snap_x(g) (&g[6]) +#define twin_glyph_snap_y(g) (twin_glyph_snap_x(g) + twin_glyph_n_snap_x(g)) +#define twin_glyph_draw(g) (twin_glyph_snap_y(g) + twin_glyph_n_snap_y(g)) + #endif /* _TWININT_H_ */ Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- xtwin.c 2 Oct 2004 03:07:26 -0000 1.13 +++ xtwin.c 4 Oct 2004 07:49:49 -0000 1.14 @@ -34,13 +34,16 @@ #define TWIN_CLOCK_BACKGROUND 0xff3b80ae #define TWIN_CLOCK_HOUR 0x80808080 -#define TWIN_CLOCK_HOUR_OUT 0xffdedede +#define TWIN_CLOCK_HOUR_OUT 0x30000000 #define TWIN_CLOCK_MINUTE 0x80808080 -#define TWIN_CLOCK_MINUTE_OUT 0xffdedede +#define TWIN_CLOCK_MINUTE_OUT 0x30000000 #define TWIN_CLOCK_SECOND 0x80808080 +#define TWIN_CLOCK_SECOND_OUT 0x30000000 #define TWIN_CLOCK_TIC 0xffbababa #define TWIN_CLOCK_NUMBERS 0xffdedede -#define TWIN_CLOCK_WATER 0x40404040 +#define TWIN_CLOCK_WATER 0x40000000 +#define TWIN_CLOCK_WATER_OUT 0x40404040 +#define TWIN_CLOCK_WATER_UNDER 0xcccc0000 #define TWIN_CLOCK_BORDER 0xffbababa #define TWIN_CLOCK_BORDER_WIDTH D(0.01) @@ -97,26 +100,6 @@ twin_path_destroy (stroke); } -static void -twin_clock_sec (twin_pixmap_t *clock, - twin_angle_t angle, - twin_fixed_t len, - twin_fixed_t width, - twin_argb32_t pixel) -{ - twin_path_t *stroke = twin_path_create (); - - twin_clock_set_transform (clock, stroke); - - twin_path_rotate (stroke, angle); - twin_path_move (stroke, D(0), D(0)); - twin_path_draw (stroke, len, D(0)); - - twin_paint_stroke (clock, pixel, stroke, width); - - twin_path_destroy (stroke); -} - static twin_angle_t twin_clock_minute_angle (int min) { @@ -141,7 +124,7 @@ { twin_state_t state = twin_path_save (path); twin_text_metrics_t metrics; - twin_fixed_t height; + twin_fixed_t height, width; static char *label = "twin"; twin_path_empty (path); @@ -150,8 +133,14 @@ twin_path_set_font_style (path, TWIN_TEXT_UNHINTED|TWIN_TEXT_OBLIQUE); twin_text_metrics_utf8 (path, label, &metrics); height = metrics.ascent + metrics.descent; -/* twin_path_move (path, -metrics.width / 2, height / 2 - metrics.ascent);*/ - twin_path_move (path, -D(.4), -D(.16)); + width = metrics.right_side_bearing - metrics.left_side_bearing; + + twin_path_move (path, -width / 2, metrics.ascent - height/2); + twin_path_draw (path, width / 2, metrics.ascent - height/2); + twin_paint_stroke (clock, TWIN_CLOCK_WATER_UNDER, path, D(0.02)); + twin_path_empty (path); + + twin_path_move (path, -width / 2 - metrics.left_side_bearing, metrics.ascent - height/2); twin_path_utf8 (path, label); twin_paint_path (clock, TWIN_CLOCK_WATER, path); twin_path_restore (path, &state); @@ -173,12 +162,16 @@ } else { - char hour[3]; + char hour[3]; + twin_text_metrics_t metrics; + twin_fixed_t width; + twin_fixed_t left; - twin_fixed_t w; sprintf (hour, "%d", m / 5); - w = twin_width_utf8 (path, hour); - twin_path_move (path, -(w/2), -D(0.95)); + twin_text_metrics_utf8 (path, hour, &metrics); + width = metrics.right_side_bearing - metrics.left_side_bearing; + left = -width / 2 - metrics.left_side_bearing; + twin_path_move (path, left, -D(0.98) + metrics.ascent); twin_path_utf8 (path, hour); twin_paint_path (clock, TWIN_CLOCK_NUMBERS, path); } @@ -197,19 +190,11 @@ struct timeval tv; struct tm t; twin_angle_t hour_angle, minute_angle, second_angle; -#if 0 - int i; -#endif - printf ("twin clock\n"); twin_pixmap_move (clock, x, y); twin_pixmap_show (clock, screen, 0); -#if 0 - for (i = 0; i < 5; i++) -#else for (;;) -#endif { twin_pixmap_disable_update (clock); twin_fill (clock, 0x00000000, TWIN_SOURCE, 0, 0, @@ -222,15 +207,16 @@ second_angle = ((t.tm_sec * 100 + tv.tv_usec / 10000) * TWIN_ANGLE_360) / 6000 - TWIN_ANGLE_90; minute_angle = twin_clock_minute_angle (t.tm_min) + second_angle / 60; - hour_angle = t.tm_hour * TWIN_ANGLE_360 / 12 - TWIN_ANGLE_90 + minute_angle / 12; - + hour_angle = (t.tm_hour * TWIN_ANGLE_360 / 12 + + (minute_angle + TWIN_ANGLE_90) / 12 - + TWIN_ANGLE_90); twin_clock_face (clock); twin_clock_hand (clock, hour_angle, D(0.4), D(0.07), D(0.01), TWIN_CLOCK_HOUR, TWIN_CLOCK_HOUR_OUT); twin_clock_hand (clock, minute_angle, D(0.8), D(0.05), D(0.01), TWIN_CLOCK_MINUTE, TWIN_CLOCK_MINUTE_OUT); - twin_clock_sec (clock, second_angle, D(0.9), D(0.02), - TWIN_CLOCK_SECOND); + twin_clock_hand (clock, second_angle, D(0.9), D(0.01), D(0.01), + TWIN_CLOCK_SECOND, TWIN_CLOCK_SECOND_OUT); twin_pixmap_enable_update (clock); @@ -392,7 +378,7 @@ twin_path_convolve (path, extra, pen); #endif -#if 1 +#if 0 { twin_state_t state = twin_path_save (path); twin_path_translate (path, D(300), D(300)); @@ -409,12 +395,12 @@ } #endif #if 1 - fx = D(3); + fx = D(10); fy = 0; - for (g = 8; g < 30; g += 4) + for (g = 90; g < 91; g += 4) { twin_path_set_font_size (path, D(g)); -#if 1 +#if 0 fy += D(g+2); twin_path_move (path, fx, fy); twin_path_utf8 (path, @@ -443,7 +429,30 @@ #if 0 fy += D(g); twin_path_move (path, fx, fy); - twin_path_utf8 (path, "t"); +#define TEXT "jelly world" + twin_path_utf8 (path, TEXT); + { + twin_text_metrics_t m; + + stroke = twin_path_create (); + twin_path_set_matrix (stroke, twin_path_current_matrix (path)); + twin_text_metrics_utf8 (path, TEXT, &m); + twin_path_move (stroke, fx, fy); + twin_path_draw (stroke, fx + m.width, fy); + twin_paint_stroke (red, 0xffff0000, stroke, D(1)); + twin_path_empty (stroke); + twin_path_move (stroke, + fx + m.left_side_bearing, fy - m.ascent); + twin_path_draw (stroke, + fx + m.right_side_bearing, fy - m.ascent); + twin_path_draw (stroke, + fx + m.right_side_bearing, fy + m.descent); + twin_path_draw (stroke, + fx + m.left_side_bearing, fy + m.descent); + twin_path_draw (stroke, + fx + m.left_side_bearing, fy - m.ascent); + twin_paint_stroke (red, 0xff00ff00, stroke, D(1)); + } #endif } #endif @@ -461,7 +470,7 @@ fy += D(g); } #endif - twin_fill_path (alpha, path); + twin_fill_path (alpha, path, 0, 0); twin_path_destroy (path); @@ -610,53 +619,20 @@ twin_pixmap_move (blue, 100, 100); twin_pixmap_show (red, x11->screen, 0); twin_pixmap_show (blue, x11->screen, 0); + ++nclock; #endif - twin_start_clock (x11->screen, 0, 0, 512, 512); -/* twin_start_clock (x11->screen, 256, 0, 256, 256); + +#if 1 + twin_start_clock (x11->screen, 0, 0, 256, 256); +#endif +#if 0 + twin_start_clock (x11->screen, 0, 0, 256, 256); + twin_start_clock (x11->screen, 256, 0, 256, 256); twin_start_clock (x11->screen, 0, 256, 256, 256); - twin_start_clock (x11->screen, 256, 256, 256, 256); */ + twin_start_clock (x11->screen, 256, 256, 256, 256); +#endif while (nclock) sleep (1); -#if 0 - had_motion = TWIN_FALSE; - for (;;) - { - if (had_motion) - { - x = motion.xmotion.x - 50; - y = motion.xmotion.y - 50; - if (motion.xmotion.state & Button1Mask) - twin_pixmap_move (red, x, y); - if (motion.xmotion.state & Button3Mask) - twin_pixmap_move (blue, x, y); - had_motion = TWIN_FALSE; - } - if (twin_screen_damaged (x11->screen)) - twin_x11_update (x11); - XSync (dpy, False); - do { - XNextEvent (dpy, &ev); - switch (ev.type) { - case Expose: - twin_x11_damage (x11, &ev.xexpose); - break; - case ButtonPress: - if (ev.xbutton.button == 2) - { - if (red->higher == 0) - twin_pixmap_show (red, x11->screen, 0); - else - twin_pixmap_show (blue, x11->screen, 0); - } - break; - case MotionNotify: - had_motion = TWIN_TRUE; - motion = ev; - break; - } - } while (QLength (dpy)); - } -#endif return 0; } From commit at keithp.com Mon Oct 4 01:30:38 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 4 01:30:44 2004 Subject: [Commit] twin ChangeLog, 1.15, 1.16 twin_font.c, 1.11, 1.12 twin_geom.c, 1.2, 1.3 twin_glyphs.c, 1.4, 1.5 xtwin.c, 1.14, 1.15 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv9007 Modified Files: ChangeLog twin_font.c twin_geom.c twin_glyphs.c xtwin.c Log Message: 2004-10-04 Keith Packard * twin_font.c: (twin_has_ucs4), (twin_path_ucs4): Delete old glyph representation support code. * twin_geom.c: (_twin_distance_to_line_squared): Oops -- overflow not handled correctly in distance functions. * twin_glyphs.c: Replace new glyphs with versions using splines. * xtwin.c: (main): Whack around the default presentation a bit more Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- ChangeLog 4 Oct 2004 07:49:49 -0000 1.15 +++ ChangeLog 4 Oct 2004 08:30:35 -0000 1.16 @@ -1,5 +1,19 @@ 2004-10-04 Keith Packard + * twin_font.c: (twin_has_ucs4), (twin_path_ucs4): + Delete old glyph representation support code. + + * twin_geom.c: (_twin_distance_to_line_squared): + Oops -- overflow not handled correctly in distance functions. + + * twin_glyphs.c: + Replace new glyphs with versions using splines. + + * xtwin.c: (main): + Whack around the default presentation a bit more + +2004-10-04 Keith Packard + * twin.h: * twin_draw.c: (twin_composite): Fix a clipping bug Index: twin_font.c =================================================================== RCS file: /local/src/CVS/twin/twin_font.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- twin_font.c 4 Oct 2004 07:49:49 -0000 1.11 +++ twin_font.c 4 Oct 2004 08:30:35 -0000 1.12 @@ -41,7 +41,7 @@ twin_bool_t twin_has_ucs4 (twin_ucs4_t ucs4) { - return ucs4 <= TWIN_FONT_MAX && _twin_glyph_offsets[ucs4] != 0; + return ucs4 <= TWIN_FONT_MAX && _twin_g_offsets[ucs4] != 0; } #define SNAPI(p) (((p) + 0x7fff) & ~0xffff) @@ -87,14 +87,6 @@ #define SNAPX(p) _snap (path, p, snap_x, nsnap_x) #define SNAPY(p) _snap (path, p, snap_y, nsnap_y) -static const twin_gpoint_t * -_twin_ucs4_base(twin_ucs4_t ucs4) -{ - if (ucs4 > TWIN_FONT_MAX) ucs4 = 0; - - return _twin_glyphs + _twin_glyph_offsets[ucs4]; -} - static const signed char * _twin_g_base (twin_ucs4_t ucs4) { @@ -167,310 +159,6 @@ m->font_descent = font_ascent + Margin(pen_size); } -#include - -#define TWIN_MAX_POINTS 50 -#define TWIN_MAX_STROKE 50 - -typedef enum { twin_gmove, twin_gline, twin_gcurve } twin_gcmd_t; - -typedef struct _twin_gop { - twin_gcmd_t cmd; - twin_gpoint_t p[3]; -} twin_gop_t; - -typedef struct _twin_stroke { - int n; - twin_gpoint_t p[TWIN_MAX_STROKE]; -} twin_stroke_t; - -typedef struct _twin_snap { - int n; - twin_gfixed_t s[TWIN_MAX_POINTS]; -} twin_snap_t; - -typedef struct _twin_glyph { - twin_ucs4_t ucs4; - int offset; - twin_bool_t exists; - twin_gfixed_t left, right, top, bottom; - int n; - twin_stroke_t s[TWIN_MAX_STROKE]; - int nop; - twin_gop_t op[TWIN_MAX_STROKE]; - twin_snap_t snap_x; - twin_snap_t snap_y; -} twin_glyph_t; - -static twin_glyph_t glyphs[0x80]; - -static void -twin_add_snap (twin_snap_t *snap, twin_gfixed_t v) -{ - int n; - - for (n = 0; n < snap->n; n++) - { - if (snap->s[n] == v) - return; - if (snap->s[n] > v) - break; - } - memmove (&snap->s[n+1], &snap->s[n], snap->n - n); - snap->s[n] = v; - snap->n++; -} - -static int -twin_n_in_spline (twin_gpoint_t *p, int n) -{ - return 0; -} - -static void -twin_spline_fit (twin_gpoint_t *p, int n, twin_gpoint_t *c1, twin_gpoint_t *c2) -{ -} - -static char * -_ucs4_string (twin_ucs4_t ucs4) -{ - static char buf[10]; - if (ucs4 < ' ' || ucs4 > '~') - { - if (!ucs4) - return "\\0"; - sprintf (buf, "\\0%o", ucs4); - return buf; - } - sprintf (buf, "%c", ucs4); - return buf; -} - -static twin_gfixed_t -px (const twin_gpoint_t *p, int i) -{ - return p[i].x << 1; -} - -static twin_gfixed_t -py (const twin_gpoint_t *p, int i) -{ - return p[i].y << 1; -} - -static void -twin_dump_glyphs (void) -{ - twin_ucs4_t ucs4; - int offset = 0; - int i, j; - twin_gop_t *gop; - - for (ucs4 = 0; ucs4 < 0x80; ucs4++) - { - const twin_gpoint_t *p = _twin_ucs4_base (ucs4); - twin_glyph_t *g = &glyphs[ucs4]; - twin_stroke_t *s; - twin_gfixed_t origin; - twin_gfixed_t left, right, top, bottom; - twin_gfixed_t baseline; - twin_gfixed_t x, y; - twin_bool_t move; - - g->ucs4 = ucs4; - g->n = 0; - - if (ucs4 && p == _twin_glyphs) continue; - - if (p[1].y == -64) - { - origin = 0; - left = 0; - right = 4; - top = 18; - bottom = 18; - baseline = 18; - } - else - { - origin = 64; - left = 64; - right = -64; - top = 64; - bottom = -64; - baseline = 18; - for (i = 1, move = TWIN_TRUE; p[i].y != -64; i++) - { - if (p[i].x == -64) { move = TWIN_TRUE; continue; } - if (py(p,i) <= baseline && px(p,i) < origin) origin = px(p,i); - if (px(p,i) < left) left = px(p,i); - if (px(p,i) > right) right = px(p,i); - if (py(p,i) < top) top = py(p,i); - if (py(p,i) > bottom) bottom = py(p,i); - move = TWIN_FALSE; - } - } - left -= origin; - right -= origin;; - bottom -= baseline; - top -= baseline; - - /* - * Convert from hershey format to internal format - */ - for (i = 1, move = TWIN_TRUE; p[i].y != -64; i++) - { - if (p[i].x == -64) { move = TWIN_TRUE; continue; } - - x = px(p,i) - origin; - y = py(p,i) - baseline; - if (move) - if (g->s[g->n].n) - ++g->n; - s = &g->s[g->n]; - s->p[s->n].x = x; - s->p[s->n].y = y; - s->n++; - - move = TWIN_FALSE; - } - if (g->s[g->n].n) - ++g->n; - - g->left = left; - g->right = right; - g->top = top; - g->bottom = bottom; - - /* - * Find snap points - */ - twin_add_snap (&g->snap_x, 0); /* origin */ - twin_add_snap (&g->snap_x, right); /* right */ - - twin_add_snap (&g->snap_y, 0); /* baseline */ - twin_add_snap (&g->snap_y, -15); /* x height */ - twin_add_snap (&g->snap_y, -21); /* cap height */ - - for (i = 0; i < g->n; i++) - { - s = &g->s[i]; - for (j = 0; j < s->n - 1; j++) - { - if (s->p[j].x == s->p[j+1].x) - twin_add_snap (&g->snap_x, s->p[j].x); - if (s->p[j].y == s->p[j+1].y) - twin_add_snap (&g->snap_y, s->p[j].y); - } - } - - /* - * Now convert to gops and try to locate splines - */ - - gop = &g->op[0]; - for (i = 0; i < g->n; i++) - { - s = &g->s[i]; - gop->cmd = twin_gmove; - gop->p[0] = s->p[0]; - gop++; - for (j = 0; j < s->n - 1;) - { - int ns = twin_n_in_spline (s->p + j, s->n - j); - - if (ns) - { - twin_spline_fit (s->p + j, ns, - &gop->p[0], &gop->p[1]); - gop->cmd = twin_gcurve; - gop->p[2] = s->p[j + ns - 1]; - gop++; - j += ns; - } - else - { - gop->cmd = twin_gline; - gop->p[0] = s->p[j+1]; - gop++; - j++; - } - } - } - g->nop = gop - &g->op[0]; - g->exists = TWIN_TRUE; - } - - printf ("const signed char _twin_gtable[] = {\n"); - for (ucs4 = 0; ucs4 < 0x80; ucs4++) - { - twin_glyph_t *g = &glyphs[ucs4]; - - if (!g->exists) continue; - - g->offset = offset; - - printf ("/* 0x%x '%s' */\n", g->ucs4, _ucs4_string (g->ucs4)); - printf (" %d, %d, %d, %d, %d, %d,\n", - g->left, g->right, -g->top, g->bottom, g->snap_x.n, g->snap_y.n); - - offset += 6; - - printf (" "); - for (i = 0; i < g->snap_x.n; i++) - printf (" %d,", g->snap_x.s[i]); - printf (" /* snap_x */\n"); - - offset += g->snap_x.n; - - printf (" "); - for (i = 0; i < g->snap_y.n; i++) - printf (" %d,", g->snap_y.s[i]); - printf (" /* snap_y */\n"); - - offset += g->snap_y.n; - -#define CO(n) gop->p[n].x, gop->p[n].y - for (i = 0; i < g->nop; i++) - { - gop = &g->op[i]; - switch (gop->cmd) { - case twin_gmove: - printf (" 'm', %d, %d,\n", CO(0)); - offset += 3; - break; - case twin_gline: - printf (" 'l', %d, %d,\n", CO(0)); - offset += 3; - break; - case twin_gcurve: - printf (" 'c', %d, %d, %d, %d, %d, %d,\n", - CO(0), CO(1), CO(2)); - offset += 7; - break; - } - } - printf (" 'e',\n"); - offset++; - } - printf ("};\n\n"); - printf ("const uint16_t _twin_g_offsets[] = {"); - for (ucs4 = 0; ucs4 < 0x80; ucs4++) - { - twin_glyph_t *g = &glyphs[ucs4]; - - if ((ucs4 & 7) == 0) - printf ("\n "); - else - printf (" "); - printf ("%4d,", g->offset); - } - printf ("\n};\n"); - fflush (stdout); - exit (0); -} - void twin_path_ucs4 (twin_path_t *path, twin_ucs4_t ucs4) { @@ -485,12 +173,6 @@ twin_matrix_t pen_matrix; twin_text_metrics_t metrics; - if (0) - { - static int been_here = 0; - if (!been_here) { been_here = 1; twin_dump_glyphs (); } - } - twin_text_metrics_ucs4 (path, ucs4, &metrics); origin = _twin_path_current_spoint (path); Index: twin_geom.c =================================================================== RCS file: /local/src/CVS/twin/twin_geom.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_geom.c 27 Sep 2004 21:28:31 -0000 1.2 +++ twin_geom.c 4 Oct 2004 08:30:35 -0000 1.3 @@ -56,8 +56,10 @@ twin_dfixed_t den, num; num = A * p->x + B * p->y + C; + if (num < 0) + num = -num; den = A * A + B * B; - if (den == 0 || num >= 0x10000) + if (den == 0 || num >= 0x8000) return _twin_distance_to_point_squared (p, p1); else return (num * num) / den; Index: twin_glyphs.c =================================================================== RCS file: /local/src/CVS/twin/twin_glyphs.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_glyphs.c 4 Oct 2004 07:49:49 -0000 1.4 +++ twin_glyphs.c 4 Oct 2004 08:30:35 -0000 1.5 @@ -24,458 +24,36 @@ #include "twinint.h" -const twin_gpoint_t _twin_glyphs[] = { -/* box for missing chars */ - { -9, 9 }, { -6, 8 }, { -6, -12 }, { 6, -12 }, { 6, 9 }, { -6, 9 }, - { -64, -64 }, -/* space */ - { -4, 4 }, { -64, -64 }, -/* ! */ - { -5, 5 }, { 0, -12 }, { 0, 2 }, { -64, 0 }, [...2192 lines suppressed...] - 2088, 2119, 2136, 2178, 2208, 2232, 2268, 2298, - 2374, 2424, 2506, 2562, 2635, 2661, 2703, 2727, - 2763, 2787, 2815, 2846, 2871, 2889, 2914, 2938, - 2956, 2989, 3050, 3111, 3166, 3227, 3292, 3328, - 3405, 3445, 3479, 3523, 3553, 3570, 3632, 3672, - 3736, 3797, 3858, 3892, 3956, 3991, 4030, 4054, - 4090, 4114, 4151, 4182, 4230, 4247, 4295, 0, + 28, 40, 90, 114, 152, 224, 323, 390, + 419, 441, 463, 494, 520, 556, 575, 604, + 622, 666, 691, 736, 780, 809, 860, 919, + 944, 1004, 1063, 1109, 1162, 1183, 1209, 1230, + 1288, 1375, 1406, 1455, 1499, 1534, 1572, 1604, + 1655, 1686, 1703, 1731, 1761, 1785, 1821, 1851, + 1895, 1931, 1981, 2023, 2074, 2100, 2128, 2152, + 2188, 2212, 2240, 2271, 2296, 2314, 2339, 2363, + 2381, 2417, 2467, 2517, 2561, 2611, 2659, 2693, + 2758, 2790, 2826, 2870, 2900, 2917, 2963, 2995, + 3039, 3089, 3139, 3168, 3219, 3252, 3283, 3307, + 3343, 3367, 3399, 3430, 3474, 3491, 3535, 0, }; Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- xtwin.c 4 Oct 2004 07:49:49 -0000 1.14 +++ xtwin.c 4 Oct 2004 08:30:35 -0000 1.15 @@ -277,8 +277,8 @@ TWIN_TEXT_BOLD|TWIN_TEXT_OBLIQUE }; -#define WIDTH 512 -#define HEIGHT 512 +#define WIDTH 256 +#define HEIGHT 256 int main (int argc, char **argv) @@ -347,7 +347,8 @@ #if 0 stroke = twin_path_create (); twin_path_move (stroke, D(30), D(400)); - twin_path_string (stroke, D(200), D(200), TWIN_TEXT_ROMAN, "jelly world."); + twin_path_set_font_size (stroke, D(100)); + twin_path_utf8 (stroke, "jelly world."); twin_path_convolve (path, stroke, pen); /* twin_path_append (path, stroke); */ twin_path_destroy (stroke); @@ -397,10 +398,10 @@ #if 1 fx = D(10); fy = 0; - for (g = 90; g < 91; g += 4) + for (g = 10; g <= 38; g += 4) { twin_path_set_font_size (path, D(g)); -#if 0 +#if 1 fy += D(g+2); twin_path_move (path, fx, fy); twin_path_utf8 (path, @@ -623,7 +624,7 @@ #endif #if 1 - twin_start_clock (x11->screen, 0, 0, 256, 256); + twin_start_clock (x11->screen, 0, 0, WIDTH, HEIGHT); #endif #if 0 twin_start_clock (x11->screen, 0, 0, 256, 256); From commit at keithp.com Mon Oct 4 13:44:31 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 4 13:44:45 2004 Subject: [Commit] twin ChangeLog, 1.16, 1.17 twin_primitive.c, 1.2, 1.3 twinint.h, 1.10, 1.11 xtwin.c, 1.15, 1.16 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv23690 Modified Files: ChangeLog twin_primitive.c twinint.h xtwin.c Log Message: 2004-10-04 Keith Packard * twin_primitive.c: (in_over), (over): * twinint.h: Recognize a few special cases to speed up operations * xtwin.c: (twin_clock_set_transform), (twin_clock_minute_angle), (twin_clock_face), (twin_clock): Fix angular problems in hand position by rotating everything 90 degrees. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ChangeLog 4 Oct 2004 08:30:35 -0000 1.16 +++ ChangeLog 4 Oct 2004 20:44:28 -0000 1.17 @@ -1,5 +1,16 @@ 2004-10-04 Keith Packard + * twin_primitive.c: (in_over), (over): + * twinint.h: + Recognize a few special cases to speed up operations + + * xtwin.c: (twin_clock_set_transform), (twin_clock_minute_angle), + (twin_clock_face), (twin_clock): + Fix angular problems in hand position by rotating everything 90 + degrees. + +2004-10-04 Keith Packard + * twin_font.c: (twin_has_ucs4), (twin_path_ucs4): Delete old glyph representation support code. Index: twin_primitive.c =================================================================== RCS file: /local/src/CVS/twin/twin_primitive.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_primitive.c 25 Sep 2004 01:10:01 -0000 1.2 +++ twin_primitive.c 4 Oct 2004 20:44:28 -0000 1.3 @@ -34,15 +34,38 @@ uint16_t t1, t2, t3, t4; twin_a8_t a; - src = (twin_in(src,0,msk,t1) | - twin_in(src,8,msk,t2) | - twin_in(src,16,msk,t3) | - twin_in(src,24,msk,t4)); + switch (msk) { + case 0: + return dst; + case 0xff: + break; + default: + src = (twin_in(src,0,msk,t1) | + twin_in(src,8,msk,t2) | + twin_in(src,16,msk,t3) | + twin_in(src,24,msk,t4)); + break; + } + if (!src) + return dst; a = ~(src >> 24); - return (twin_over (src, dst, 0, a, t1) | - twin_over (src, dst, 8, a, t2) | - twin_over (src, dst, 16, a, t3) | - twin_over (src, dst, 24, a, t4)); + switch (a) { + case 0: + return src; + case 0xff: + dst = (twin_add (src, dst, 0, t1) | + twin_add (src, dst, 8, t2) | + twin_add (src, dst, 16, t3) | + twin_add (src, dst, 24, t4)); + break; + default: + dst = (twin_over (src, dst, 0, a, t1) | + twin_over (src, dst, 8, a, t2) | + twin_over (src, dst, 16, a, t3) | + twin_over (src, dst, 24, a, t4)); + break; + } + return dst; } static twin_argb32_t __inline @@ -64,11 +87,26 @@ uint16_t t1, t2, t3, t4; twin_a8_t a; + if (!src) + return dst; a = ~(src >> 24); - return (twin_over (src, dst, 0, a, t1) | - twin_over (src, dst, 8, a, t2) | - twin_over (src, dst, 16, a, t3) | - twin_over (src, dst, 24, a, t4)); + switch (a) { + case 0: + return src; + case 0xff: + dst = (twin_add (src, dst, 0, t1) | + twin_add (src, dst, 8, t2) | + twin_add (src, dst, 16, t3) | + twin_add (src, dst, 24, t4)); + break; + default: + dst = (twin_over (src, dst, 0, a, t1) | + twin_over (src, dst, 8, a, t2) | + twin_over (src, dst, 16, a, t3) | + twin_over (src, dst, 24, a, t4)); + break; + } + return dst; } static twin_argb32_t __inline Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- twinint.h 4 Oct 2004 07:49:49 -0000 1.10 +++ twinint.h 4 Oct 2004 20:44:28 -0000 1.11 @@ -82,6 +82,10 @@ (((t) = twin_int_mult(twin_get_8(d,i),(m),(t)) + twin_get_8(s,i)),\ (twin_argb32_t) twin_sat (t) << (i)) +#define twin_add(s,d,i,t) \ + (((t) = twin_get_8(d,i) + twin_get_8(s,i)),\ + (twin_argb32_t) twin_sat (t) << (i)) + #define twin_argb32_to_rgb16(s) ((((s) >> 3) & 0x001f) | \ (((s) >> 5) & 0x07e0) | \ (((s) >> 8) & 0xf800)) Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- xtwin.c 4 Oct 2004 08:30:35 -0000 1.15 +++ xtwin.c 4 Oct 2004 20:44:28 -0000 1.16 @@ -61,6 +61,7 @@ twin_path_translate (path, D(1) + TWIN_CLOCK_BORDER_WIDTH * 3, D(1) + TWIN_CLOCK_BORDER_WIDTH * 3); + twin_path_rotate (path, -TWIN_ANGLE_90); } static void @@ -103,7 +104,7 @@ static twin_angle_t twin_clock_minute_angle (int min) { - return min * TWIN_ANGLE_360 / 60 - TWIN_ANGLE_90; + return min * TWIN_ANGLE_360 / 60; } static void @@ -128,15 +129,15 @@ static char *label = "twin"; twin_path_empty (path); - twin_path_rotate (path, twin_degrees_to_angle (-11)); + twin_path_rotate (path, twin_degrees_to_angle (-11) + TWIN_ANGLE_90); twin_path_set_font_size (path, D(0.5)); twin_path_set_font_style (path, TWIN_TEXT_UNHINTED|TWIN_TEXT_OBLIQUE); twin_text_metrics_utf8 (path, label, &metrics); height = metrics.ascent + metrics.descent; width = metrics.right_side_bearing - metrics.left_side_bearing; - twin_path_move (path, -width / 2, metrics.ascent - height/2); - twin_path_draw (path, width / 2, metrics.ascent - height/2); + twin_path_move (path, -width / 2, metrics.ascent - height/2 + D(0.01)); + twin_path_draw (path, width / 2, metrics.ascent - height/2 + D(0.01)); twin_paint_stroke (clock, TWIN_CLOCK_WATER_UNDER, path, D(0.02)); twin_path_empty (path); @@ -205,11 +206,9 @@ localtime_r(&tv.tv_sec, &t); second_angle = ((t.tm_sec * 100 + tv.tv_usec / 10000) * - TWIN_ANGLE_360) / 6000 - TWIN_ANGLE_90; + TWIN_ANGLE_360) / 6000; minute_angle = twin_clock_minute_angle (t.tm_min) + second_angle / 60; - hour_angle = (t.tm_hour * TWIN_ANGLE_360 / 12 + - (minute_angle + TWIN_ANGLE_90) / 12 - - TWIN_ANGLE_90); + hour_angle = (t.tm_hour * TWIN_ANGLE_360 + minute_angle) / 12; twin_clock_face (clock); twin_clock_hand (clock, hour_angle, D(0.4), D(0.07), D(0.01), TWIN_CLOCK_HOUR, TWIN_CLOCK_HOUR_OUT); @@ -222,7 +221,9 @@ gettimeofday (&tv, NULL); - usleep (1000000 - tv.tv_usec); +#define INTERVAL 1000000 + + usleep (INTERVAL - (tv.tv_usec % INTERVAL)); } nclock--; } From commit at keithp.com Tue Oct 5 11:42:56 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 5 11:43:11 2004 Subject: [Commit] twin ChangeLog, 1.17, 1.18 twin.h, 1.12, 1.13 twin_draw.c, 1.4, 1.5 twin_font.c, 1.12, 1.13 twin_matrix.c, 1.3, 1.4 twin_path.c, 1.9, 1.10 twin_pixmap.c, 1.2, 1.3 twin_poly.c, 1.7, 1.8 twin_screen.c, 1.4, 1.5 twin_x11.c, 1.4, 1.5 twinint.h, 1.11, 1.12 xtwin.c, 1.16, 1.17 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv17484 Modified Files: ChangeLog twin.h twin_draw.c twin_font.c twin_matrix.c twin_path.c twin_pixmap.c twin_poly.c twin_screen.c twin_x11.c twinint.h xtwin.c Log Message: 2004-10-05 Keith Packard * twin.h: * twin_draw.c: (twin_composite), (twin_fill): * twin_matrix.c: (twin_matrix_multiply), (twin_matrix_translate), (twin_matrix_scale), (twin_matrix_rotate): * twin_path.c: (twin_path_ellipse), (twin_path_set_font_style), (twin_composite_path), (twin_composite_stroke): * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_pointer), (twin_pixmap_damage), (twin_pixmap_move): * twin_poly.c: (twin_fill_path): * twin_screen.c: (twin_screen_create), (twin_screen_damage), (twin_screen_resize), (twin_screen_update): * twin_x11.c: (_twin_x11_put_begin), (_twin_x11_put_span): * twinint.h: Update API to use twin_ types for most everything. * twin_font.c: (_twin_text_compute_info), (_twin_text_compute_snap), (_twin_text_compute_pen), (_twin_snap), (twin_has_ucs4), (_twin_glyph_width), (twin_text_metrics_ucs4), (twin_path_ucs4): Rework snapping to correctly snap vertical and horizontal text on pixel boundaries. * xtwin.c: (main): Change clock watermark Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- ChangeLog 4 Oct 2004 20:44:28 -0000 1.17 +++ ChangeLog 5 Oct 2004 18:42:53 -0000 1.18 @@ -1,3 +1,30 @@ +2004-10-05 Keith Packard + + * twin.h: + * twin_draw.c: (twin_composite), (twin_fill): + * twin_matrix.c: (twin_matrix_multiply), (twin_matrix_translate), + (twin_matrix_scale), (twin_matrix_rotate): + * twin_path.c: (twin_path_ellipse), (twin_path_set_font_style), + (twin_composite_path), (twin_composite_stroke): + * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_pointer), + (twin_pixmap_damage), (twin_pixmap_move): + * twin_poly.c: (twin_fill_path): + * twin_screen.c: (twin_screen_create), (twin_screen_damage), + (twin_screen_resize), (twin_screen_update): + * twin_x11.c: (_twin_x11_put_begin), (_twin_x11_put_span): + * twinint.h: + Update API to use twin_ types for most everything. + + * twin_font.c: (_twin_text_compute_info), + (_twin_text_compute_snap), (_twin_text_compute_pen), (_twin_snap), + (twin_has_ucs4), (_twin_glyph_width), (twin_text_metrics_ucs4), + (twin_path_ucs4): + Rework snapping to correctly snap vertical and horizontal text + on pixel boundaries. + + * xtwin.c: (main): + Change clock watermark + 2004-10-04 Keith Packard * twin_primitive.c: (in_over), (over): Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- twin.h 4 Oct 2004 07:49:49 -0000 1.12 +++ twin.h 5 Oct 2004 18:42:53 -0000 1.13 @@ -38,13 +38,18 @@ typedef uint32_t twin_argb32_t; typedef uint32_t twin_ucs4_t; typedef int twin_bool_t; +typedef int16_t twin_coord_t; +typedef int16_t twin_style_t; +typedef int16_t twin_count_t; +typedef int16_t twin_keysym_t; +typedef int32_t twin_area_t; #define TWIN_FALSE 0 #define TWIN_TRUE 1 typedef enum { TWIN_A8, TWIN_RGB16, TWIN_ARGB32 } twin_format_t; -#define twin_bytes_per_pixel(format) (1 << (int) (format)) +#define twin_bytes_per_pixel(format) (1 << (twin_coord_t) (format)) /* * Angles @@ -64,7 +69,7 @@ * A rectangle */ typedef struct _twin_rect { - int left, right, top, bottom; + twin_coord_t left, right, top, bottom; } twin_rect_t; typedef union _twin_pointer { @@ -83,7 +88,7 @@ * Screen showing these pixels */ struct _twin_screen *screen; - int disable; + twin_count_t disable; /* * List of displayed pixmaps */ @@ -91,32 +96,32 @@ /* * Screen position */ - int x, y; + twin_coord_t x, y; /* * Pixmap layout */ - twin_format_t format; - int width; /* pixels */ - int height; /* pixels */ - int stride; /* bytes */ + twin_format_t format; + twin_coord_t width; /* pixels */ + twin_coord_t height; /* pixels */ + twin_coord_t stride; /* bytes */ /* * Pixels */ - twin_pointer_t p; + twin_pointer_t p; } twin_pixmap_t; /* * twin_put_begin_t: called before data are drawn to the screen * twin_put_span_t: called for each scanline drawn */ -typedef void (*twin_put_begin_t) (int x, - int y, - int width, - int height, +typedef void (*twin_put_begin_t) (twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height, void *closure); -typedef void (*twin_put_span_t) (int x, - int y, - int width, +typedef void (*twin_put_span_t) (twin_coord_t x, + twin_coord_t y, + twin_coord_t width, twin_argb32_t *pixels, void *closure); @@ -131,14 +136,14 @@ /* * Output size */ - int width, height; + twin_coord_t width, height; /* * Damage */ twin_rect_t damage; void (*damaged) (void *); void *damaged_closure; - int disable; + twin_count_t disable; #if HAVE_PTHREAD_H pthread_mutex_t screen_mutex; #endif @@ -190,15 +195,15 @@ * Place matrices in structures so they can be easily copied */ typedef struct _twin_matrix { - twin_fixed_t m[3][2]; + twin_fixed_t m[3][2]; } twin_matrix_t; typedef struct _twin_path twin_path_t; typedef struct _twin_state { - twin_matrix_t matrix; - twin_fixed_t font_size; - int font_style; + twin_matrix_t matrix; + twin_fixed_t font_size; + twin_style_t font_style; } twin_state_t; /* @@ -216,6 +221,34 @@ } twin_text_metrics_t; /* + * Events + */ + +typedef enum _twin_event_kind { + EventButtonDown, EventButtonUp, EventMotion, + EventKeyDown, EventKeyUp, EventUcs4 +} twin_event_kind_t; + +typedef struct _twin_event { + twin_event_kind_t kind; + union { + struct { + twin_coord_t x, y; + twin_count_t button; + } button; + struct { + twin_coord_t x, y; + } motion; + struct { + twin_keysym_t key; + } key; + struct { + twin_ucs4_t ucs4; + } ucs4; + } u; +} twin_event_t; + +/* * twin_convolve.c */ void @@ -229,26 +262,26 @@ void twin_composite (twin_pixmap_t *dst, - int dst_x, - int dst_y, + twin_coord_t dst_x, + twin_coord_t dst_y, twin_operand_t *src, - int src_x, - int src_y, + twin_coord_t src_x, + twin_coord_t src_y, twin_operand_t *msk, - int msk_x, - int msk_y, + twin_coord_t msk_x, + twin_coord_t msk_y, twin_operator_t operator, - int width, - int height); + twin_coord_t width, + twin_coord_t height); void twin_fill (twin_pixmap_t *dst, twin_argb32_t pixel, twin_operator_t operator, - int x, - int y, - int width, - int height); + twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height); /* * twin_fixed.c @@ -330,6 +363,11 @@ void twin_matrix_rotate (twin_matrix_t *m, twin_angle_t a); +void +twin_matrix_multiply (twin_matrix_t *result, + const twin_matrix_t *a, + const twin_matrix_t *b); + /* * twin_path.c */ @@ -350,6 +388,10 @@ twin_path_circle(twin_path_t *path, twin_fixed_t radius); void +twin_path_ellipse (twin_path_t *path, + twin_fixed_t x_radius, + twin_fixed_t y_radius); +void twin_path_close (twin_path_t *path); void @@ -391,11 +433,11 @@ void twin_path_set_font_size (twin_path_t *path, twin_fixed_t font_size); -int +twin_style_t twin_path_current_font_style (twin_path_t *path); void -twin_path_set_font_style (twin_path_t *path, int font_style); +twin_path_set_font_style (twin_path_t *path, twin_style_t font_style); twin_state_t twin_path_save (twin_path_t *path); @@ -406,8 +448,8 @@ void twin_composite_path (twin_pixmap_t *dst, twin_operand_t *src, - int src_x, - int src_y, + twin_coord_t src_x, + twin_coord_t src_y, twin_path_t *path, twin_operator_t operator); void @@ -418,8 +460,8 @@ void twin_composite_stroke (twin_pixmap_t *dst, twin_operand_t *src, - int src_x, - int src_y, + twin_coord_t src_x, + twin_coord_t src_y, twin_path_t *stroke, twin_fixed_t pen_width, twin_operator_t operator); @@ -435,7 +477,9 @@ */ twin_pixmap_t * -twin_pixmap_create (twin_format_t format, int width, int height); +twin_pixmap_create (twin_format_t format, + twin_coord_t width, + twin_coord_t height); void twin_pixmap_destroy (twin_pixmap_t *pixmap); @@ -456,7 +500,8 @@ void twin_pixmap_damage (twin_pixmap_t *pixmap, - int x1, int y1, int x2, int y2); + twin_coord_t x1, twin_coord_t y1, + twin_coord_t x2, twin_coord_t y2); void twin_pixmap_lock (twin_pixmap_t *pixmap); @@ -465,24 +510,25 @@ twin_pixmap_unlock (twin_pixmap_t *pixmap); void -twin_pixmap_move (twin_pixmap_t *pixmap, int x, int y); +twin_pixmap_move (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y); twin_pointer_t -twin_pixmap_pointer (twin_pixmap_t *pixmap, int x, int y); +twin_pixmap_pointer (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y); /* * twin_poly.c */ void -twin_fill_path (twin_pixmap_t *pixmap, twin_path_t *path, int dx, int dy); +twin_fill_path (twin_pixmap_t *pixmap, twin_path_t *path, + twin_coord_t dx, twin_coord_t dy); /* * twin_screen.c */ twin_screen_t * -twin_screen_create (int width, - int height, +twin_screen_create (twin_coord_t width, + twin_coord_t height, twin_put_begin_t put_begin, twin_put_span_t put_span, void *closure); @@ -498,7 +544,8 @@ void twin_screen_damage (twin_screen_t *screen, - int x1, int y1, int x2, int y2); + twin_coord_t left, twin_coord_t top, + twin_coord_t right, twin_coord_t bottom); void twin_screen_register_damaged (twin_screen_t *screen, @@ -506,7 +553,8 @@ void *closure); void -twin_screen_resize (twin_screen_t *screen, int width, int height); +twin_screen_resize (twin_screen_t *screen, + twin_coord_t width, twin_coord_t height); twin_bool_t twin_screen_damaged (twin_screen_t *screen); Index: twin_draw.c =================================================================== RCS file: /local/src/CVS/twin/twin_draw.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_draw.c 4 Oct 2004 07:49:49 -0000 1.4 +++ twin_draw.c 5 Oct 2004 18:42:53 -0000 1.5 @@ -261,45 +261,48 @@ void twin_composite (twin_pixmap_t *dst, - int dst_x, - int dst_y, + twin_coord_t dst_x, + twin_coord_t dst_y, twin_operand_t *src, - int src_x, - int src_y, + twin_coord_t src_x, + twin_coord_t src_y, twin_operand_t *msk, - int msk_x, - int msk_y, + twin_coord_t msk_x, + twin_coord_t msk_y, twin_operator_t operator, - int width, - int height) + twin_coord_t width, + twin_coord_t height) { - int iy; - int left, right, top, bottom; + twin_coord_t iy; + twin_coord_t left, right, top, bottom; + + left = dst_x; + right = dst_x + width; + top = dst_y; + bottom = dst_y + height; + if (left < 0) + left = 0; + if (right > dst->width) + right = dst->width; + if (top < 0) + top = 0; + if (bottom > dst->height) + bottom = dst->height; + if (left >= right || top >= bottom) + return; twin_pixmap_lock (dst); if (msk) { twin_src_msk_op op; twin_source_u s, m; - int sdx, sdy, mdx, mdy; + twin_coord_t sdx, sdy, mdx, mdy; sdx = src_x - dst_x; sdy = src_y - dst_y; mdx = msk_x - dst_x; mdy = msk_y - dst_y; - left = dst_x; - right = dst_x + width; - top = dst_y; - bottom = dst_y + height; - if (left < 0) - left = 0; - if (right > dst->width) - right = dst->width; - if (top < 0) - top = 0; - if (bottom > dst->height) - bottom = dst->height; op = comp3[operator][operand_index(src)][operand_index(msk)][dst->format]; if (op) @@ -326,24 +329,11 @@ { twin_src_op op; twin_source_u s; - int sdx, sdy; + twin_coord_t sdx, sdy; sdx = src_x - dst_x; sdy = src_y - dst_y; - left = dst_x; - right = dst_x + width; - top = dst_y; - bottom = dst_y + height; - if (left < 0) - left = 0; - if (right > dst->width) - right = dst->width; - if (top < 0) - top = 0; - if (top > dst->height) - top = dst->height; - op = comp2[operator][operand_index(src)][dst->format]; if (src->source_kind == TWIN_SOLID) s.c = src->u.argb; @@ -380,15 +370,15 @@ twin_fill (twin_pixmap_t *dst, twin_argb32_t pixel, twin_operator_t operator, - int x, - int y, - int width, - int height) + twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height) { twin_src_op op; twin_source_u src; - int iy; - int left, right, top, bottom; + twin_coord_t iy; + twin_coord_t left, right, top, bottom; twin_pixmap_lock (dst); src.c = pixel; Index: twin_font.c =================================================================== RCS file: /local/src/CVS/twin/twin_font.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- twin_font.c 4 Oct 2004 08:30:35 -0000 1.12 +++ twin_font.c 5 Oct 2004 18:42:53 -0000 1.13 @@ -34,33 +34,185 @@ #define DBGMSG(x) #endif -#define Scale(f) (((twin_fixed_t) (f) * path->state.font_size) >> 6) +#define SNAPI(p) (((p) + 0x8000) & ~0xffff) +#define SNAPH(p) (((p) + 0x4000) & ~0x7fff) +#define FX(g,i) (((g) * (i)->scale.x) >> 6) +#define FY(g,i) (((g) * (i)->scale.y) >> 6) -#define Hint(p) (((p)->state.font_style & TWIN_TEXT_UNHINTED) == 0) +typedef struct _twin_text_info { + twin_point_t scale; + twin_point_t pen; + twin_point_t margin; + twin_point_t reverse_scale; + twin_bool_t snap; + twin_matrix_t matrix; + twin_matrix_t pen_matrix; + int n_snap_x; + twin_fixed_t snap_x[TWIN_GLYPH_MAX_SNAP_X]; + int n_snap_y; + twin_fixed_t snap_y[TWIN_GLYPH_MAX_SNAP_Y]; +} twin_text_info_t; -twin_bool_t -twin_has_ucs4 (twin_ucs4_t ucs4) +static void +_twin_text_compute_info (twin_path_t *path, twin_text_info_t *info) { - return ucs4 <= TWIN_FONT_MAX && _twin_g_offsets[ucs4] != 0; + twin_spoint_t origin = _twin_path_current_spoint (path); + + /* + * Only hint axis aligned text + */ + if ((path->state.font_style & TWIN_TEXT_UNHINTED) == 0 && + ((path->state.matrix.m[0][1] == 0 && + path->state.matrix.m[1][0] == 0) || + (path->state.matrix.m[0][0] == 0 && + path->state.matrix.m[1][1] == 0))) + { + int xi, yi; + + if (path->state.matrix.m[0][0] != 0) + xi = 0; + else + xi = 1; + yi = 1-xi; + info->snap = TWIN_TRUE; + info->matrix.m[xi][0] = TWIN_FIXED_ONE; + info->matrix.m[xi][1] = 0; + info->matrix.m[yi][0] = 0; + info->matrix.m[yi][1] = TWIN_FIXED_ONE; + info->matrix.m[2][0] = twin_sfixed_to_fixed (origin.x); + info->matrix.m[2][1] = twin_sfixed_to_fixed (origin.y); + info->scale.x = twin_fixed_mul (path->state.font_size, + path->state.matrix.m[0][xi]); + info->reverse_scale.x = twin_fixed_div (TWIN_FIXED_ONE, + path->state.matrix.m[0][xi]); + if (info->scale.x < 0) + { + info->scale.x = -info->scale.x; + info->reverse_scale.x = -info->reverse_scale.x; + info->matrix.m[0][xi] = -info->matrix.m[0][xi]; + info->matrix.m[1][xi] = -info->matrix.m[1][xi]; + } + info->scale.y = twin_fixed_mul (path->state.font_size, + path->state.matrix.m[1][yi]); + info->reverse_scale.y = twin_fixed_div (TWIN_FIXED_ONE, + path->state.matrix.m[1][yi]); + if (info->scale.y < 0) + { + info->scale.y = -info->scale.y; + info->reverse_scale.y = -info->reverse_scale.y; + info->matrix.m[0][yi] = -info->matrix.m[0][yi]; + info->matrix.m[1][yi] = -info->matrix.m[1][yi]; + } + + info->pen.x = SNAPH(info->scale.x / 24); + info->pen.y = SNAPH(info->scale.y / 24); + if (info->pen.x < TWIN_FIXED_HALF) + info->pen.x = TWIN_FIXED_HALF; + if (info->pen.y < TWIN_FIXED_HALF) + info->pen.y = TWIN_FIXED_HALF; + info->margin.x = info->pen.x; + info->margin.y = info->pen.y; + if (path->state.font_style & TWIN_TEXT_BOLD) + { + twin_fixed_t pen_x_add = SNAPH(info->pen.x >> 1); + twin_fixed_t pen_y_add = SNAPH(info->pen.y >> 1); + + if (pen_x_add < TWIN_FIXED_HALF) + pen_x_add = TWIN_FIXED_HALF; + if (pen_y_add < TWIN_FIXED_HALF) + pen_y_add = TWIN_FIXED_HALF; + info->pen.x += pen_x_add; + info->pen.y += pen_y_add; + } + DBGMSG (("pen: %9.4f %9.4f\n", F(info->pen.x), F(info->pen.y))); + + twin_matrix_translate (&info->matrix, + SNAPI(info->margin.x) + info->pen.x, + -info->pen.y); + info->pen_matrix = info->matrix; + } + else + { + info->snap = TWIN_FALSE; + info->matrix = path->state.matrix; + info->matrix.m[2][0] = twin_sfixed_to_fixed (origin.x); + info->matrix.m[2][1] = twin_sfixed_to_fixed (origin.y); + info->scale.x = path->state.font_size; + info->scale.y = path->state.font_size; + + if (path->state.font_style & TWIN_TEXT_BOLD) + info->pen.x = path->state.font_size / 16; + else + info->pen.x = path->state.font_size / 24; + info->pen.y = info->pen.x; + + info->margin.x = path->state.font_size / 24; + info->margin.y = info->margin.x; + + info->pen_matrix = path->state.matrix; + twin_matrix_translate (&info->matrix, + info->margin.x + info->pen.x, -info->pen.y); + } + info->pen_matrix.m[2][0] = 0; info->pen_matrix.m[2][1] = 0; + twin_matrix_scale (&info->pen_matrix, info->pen.x, info->pen.y); + + if (path->state.font_style & TWIN_TEXT_OBLIQUE) + { + twin_matrix_t m; + + m.m[0][0] = TWIN_FIXED_ONE; m.m[0][1] = 0; + m.m[1][0] = -TWIN_FIXED_ONE / 4; m.m[1][1] = TWIN_FIXED_ONE; + m.m[2][0] = 0; m.m[2][1] = 0; + twin_matrix_multiply (&info->matrix, &m, &info->matrix); + } + DBGMSG (("%9.4f %9.4f\n", F(info->matrix.m[0][0]), F(info->matrix.m[0][1]))); + DBGMSG (("%9.4f %9.4f\n", F(info->matrix.m[1][0]), F(info->matrix.m[1][1]))); + DBGMSG (("%9.4f %9.4f\n", F(info->matrix.m[2][0]), F(info->matrix.m[2][1]))); } -#define SNAPI(p) (((p) + 0x7fff) & ~0xffff) -#define SNAPH(p) (((p) + 0x3fff) & ~0x7fff) +static void +_twin_text_compute_snap (twin_text_info_t *info, + const signed char *b) +{ + int s, n; + const signed char *snap; + + snap = twin_glyph_snap_x (b); + n = twin_glyph_n_snap_x (b); + info->n_snap_x = n; + for (s = 0; s < n; s++) + info->snap_x[s] = FX(snap[s], info); + + snap = twin_glyph_snap_y (b); + n = twin_glyph_n_snap_y (b); + info->n_snap_y = n; + for (s = 0; s < n; s++) + info->snap_y[s] = FY(snap[s], info); +} + +static twin_path_t * +_twin_text_compute_pen (twin_text_info_t *info) +{ + twin_path_t *pen = twin_path_create (); + + twin_path_set_matrix (pen, info->pen_matrix); + twin_path_circle (pen, TWIN_FIXED_ONE); + return pen; +} -#if 0 static twin_fixed_t -_snap (twin_path_t *path, twin_gfixed_t g, twin_gfixed_t *snap, int nsnap) +_twin_snap (twin_fixed_t v, + twin_fixed_t *snap, + int n) { - int s; - twin_fixed_t v; + int s; - v = Scale(g); - for (s = 0; s < nsnap - 1; s++) + for (s = 0; s < n - 1; s++) { - if (snap[s] <= g && g <= snap[s+1]) + if (snap[s] <= v && v <= snap[s+1]) { - twin_fixed_t before = Scale(snap[s]); - twin_fixed_t after = Scale(snap[s+1]); + twin_fixed_t before = snap[s]; + twin_fixed_t after = snap[s+1]; twin_fixed_t dist = after - before; twin_fixed_t snap_before = SNAPI(before); twin_fixed_t snap_after = SNAPI(after); @@ -70,7 +222,6 @@ twin_fixed_t dist_after = after - v; twin_fixed_t move = ((int64_t) dist_before * move_after + (int64_t) dist_after * move_before) / dist; - DBGMSG (("%d <= %d <= %d\n", snap[s], g, snap[s+1])); DBGMSG (("%9.4f <= %9.4f <= %9.4f\n", F(before), F(v), F(after))); DBGMSG (("before: %9.4f -> %9.4f\n", F(before), F(snap_before))); DBGMSG (("after: %9.4f -> %9.4f\n", F(after), F(snap_after))); @@ -79,10 +230,14 @@ break; } } - DBGMSG (("_snap: %d => %9.4f\n", g, F(v))); return v; } -#endif + +twin_bool_t +twin_has_ucs4 (twin_ucs4_t ucs4) +{ + return ucs4 <= TWIN_FONT_MAX && _twin_g_offsets[ucs4] != 0; +} #define SNAPX(p) _snap (path, p, snap_x, nsnap_x) #define SNAPY(p) _snap (path, p, snap_y, nsnap_y) @@ -96,67 +251,73 @@ } static twin_fixed_t -_twin_pen_size (twin_path_t *path) +_twin_glyph_width (twin_text_info_t *info, + const signed char *b) { - twin_fixed_t pen_size; - - pen_size = path->state.font_size / 24; - - if (Hint (path)) - { - pen_size = SNAPH(pen_size); - if( pen_size < TWIN_FIXED_HALF) - pen_size = TWIN_FIXED_HALF; - } - - if (path->state.font_style & TWIN_TEXT_BOLD) - { - twin_fixed_t pen_add = pen_size >> 1; + twin_fixed_t right = FX(twin_glyph_right(b), info) + info->pen.x * 2; + twin_fixed_t right_side_bearing; + twin_fixed_t width; - if (Hint (path)) - { - pen_add = SNAPH (pen_add); - if (pen_add == 0) - pen_add = TWIN_FIXED_HALF; - } - pen_size += pen_add; - } - return pen_size; + if (info->snap) + right = SNAPI(_twin_snap (right, info->snap_x, info->n_snap_x)); + + right_side_bearing = right + info->margin.x; + width = right_side_bearing + info->margin.x; + return width; } -#define Margin(pen_size) ((pen_size) * 2) - void twin_text_metrics_ucs4 (twin_path_t *path, twin_ucs4_t ucs4, twin_text_metrics_t *m) { - const signed char *g = _twin_g_base (ucs4); - twin_fixed_t pen_size = _twin_pen_size (path); - twin_fixed_t left = Scale(twin_glyph_left(g)); - twin_fixed_t right = Scale (twin_glyph_right(g)) + pen_size * 2; - twin_fixed_t ascent = Scale (twin_glyph_ascent(g)) + pen_size * 2; - twin_fixed_t descent = Scale (twin_glyph_descent(g)); - twin_fixed_t font_spacing = path->state.font_size; - twin_fixed_t font_descent = font_spacing / 3; - twin_fixed_t font_ascent = font_spacing - font_descent; + const signed char *b = _twin_g_base (ucs4); + twin_text_info_t info; + twin_fixed_t left, right, ascent, descent; + twin_fixed_t font_spacing; + twin_fixed_t font_descent; + twin_fixed_t font_ascent; + twin_fixed_t margin_x, margin_y; - if (Hint(path)) + _twin_text_compute_info (path, &info); + if (info.snap) + _twin_text_compute_snap (&info, b); + + left = FX(twin_glyph_left(b), &info); + right = FX(twin_glyph_right(b), &info) + info.pen.x * 2; + ascent = FY(twin_glyph_ascent(b), &info) + info.pen.y * 2; + descent = FY(twin_glyph_descent(b), &info); + margin_x = info.margin.x; + margin_y = info.margin.y; + + font_spacing = FY(TWIN_GFIXED_ONE, &info); + font_descent = font_spacing / 3; + font_ascent = font_spacing - font_descent; + if (info.snap) { - left = SNAPI(left); - right = SNAPI(right); - ascent = SNAPI(ascent); - descent = SNAPI(descent); + left = SNAPI(_twin_snap (left, info.snap_x, info.n_snap_x)); + right = SNAPI(_twin_snap (right, info.snap_x, info.n_snap_x)); + ascent = SNAPI(_twin_snap (ascent, info.snap_y, info.n_snap_y)); + descent = SNAPI(_twin_snap (descent, info.snap_y, info.n_snap_y)); font_descent = SNAPI(font_descent); font_ascent = SNAPI(font_ascent); + + left = twin_fixed_mul (left, info.reverse_scale.x); + right = twin_fixed_mul (right, info.reverse_scale.x); + ascent = twin_fixed_mul (ascent, info.reverse_scale.y); + descent = twin_fixed_mul (descent, info.reverse_scale.y); + font_descent = twin_fixed_mul (font_descent, info.reverse_scale.y); + font_ascent = twin_fixed_mul (font_ascent, info.reverse_scale.y); + margin_x = twin_fixed_mul (margin_x, info.reverse_scale.x); + margin_y = twin_fixed_mul (margin_y, info.reverse_scale.y); } - m->left_side_bearing = left + Margin(pen_size); - m->right_side_bearing = right + Margin(pen_size); + m->left_side_bearing = left + margin_x; + m->right_side_bearing = right + margin_x; m->ascent = ascent; m->descent = descent; - m->width = m->right_side_bearing + Margin(pen_size); - m->font_ascent = font_ascent + Margin(pen_size); - m->font_descent = font_ascent + Margin(pen_size); + m->width = m->right_side_bearing + margin_x; + m->font_ascent = font_ascent + margin_y; + m->font_descent = font_descent + margin_y; } void @@ -166,67 +327,66 @@ const signed char *g = twin_glyph_draw(b); twin_spoint_t origin; twin_fixed_t x1, y1, x2, y2, x3, y3; - twin_fixed_t xo, yo; twin_path_t *stroke; twin_path_t *pen; - twin_fixed_t pen_size = _twin_pen_size (path); - twin_matrix_t pen_matrix; - twin_text_metrics_t metrics; - - twin_text_metrics_ucs4 (path, ucs4, &metrics); + twin_fixed_t width; + twin_text_info_t info; + _twin_text_compute_info (path, &info); + if (info.snap) + _twin_text_compute_snap (&info, b); + origin = _twin_path_current_spoint (path); stroke = twin_path_create (); - - twin_path_set_matrix (stroke, twin_path_current_matrix (path)); - - pen = twin_path_create (); - pen_matrix = twin_path_current_matrix (path); - /* eliminate translation part */ - pen_matrix.m[2][0] = 0; - pen_matrix.m[2][1] = 0; - twin_path_set_matrix (pen, pen_matrix); - - twin_path_circle (pen, pen_size); - -#define PX(_x,_y) (origin.x + _twin_matrix_dx (&path->state.matrix, _x, _y)) -#define PY(_x,_y) (origin.y + _twin_matrix_dy (&path->state.matrix, _x, _y)) - - xo = pen_size * 3; - yo = -pen_size; + twin_path_set_matrix (stroke, info.matrix); + pen = _twin_text_compute_pen (&info); for (;;) { switch (*g++) { case 'm': - x1 = Scale (*g++) + xo; - y1 = Scale (*g++) + yo; - if (path->state.font_style & TWIN_TEXT_OBLIQUE) - x1 -= y1 >> 2; - _twin_path_smove (stroke, PX(x1,y1), PY(x1,y1)); + x1 = FX(*g++, &info); + y1 = FY(*g++, &info); + if (info.snap) + { + x1 = _twin_snap (x1, info.snap_x, info.n_snap_x); + y1 = _twin_snap (y1, info.snap_y, info.n_snap_y); + } + DBGMSG (("m %9.4f %9.4f\n", + S(_twin_matrix_x (&stroke->state.matrix, x1, y1)), + S(_twin_matrix_y (&stroke->state.matrix, x1, y1)))); + twin_path_move (stroke, x1, y1); continue; case 'l': - x1 = Scale (*g++) + xo; - y1 = Scale (*g++) + yo; - if (path->state.font_style & TWIN_TEXT_OBLIQUE) - x1 -= y1 >> 2; - _twin_path_sdraw (stroke, PX(x1,y1), PY(x1,y1)); + x1 = FX(*g++, &info); + y1 = FY(*g++, &info); + if (info.snap) + { + x1 = _twin_snap (x1, info.snap_x, info.n_snap_x); + y1 = _twin_snap (y1, info.snap_y, info.n_snap_y); + } + DBGMSG (("l %9.4f %9.4f\n", + S(_twin_matrix_x (&stroke->state.matrix, x1, y1)), + S(_twin_matrix_y (&stroke->state.matrix, x1, y1)))); + twin_path_draw (stroke, x1, y1); continue; case 'c': - x1 = Scale (*g++) + xo; - y1 = Scale (*g++) + yo; - x2 = Scale (*g++) + xo; - y2 = Scale (*g++) + yo; - x3 = Scale (*g++) + xo; - y3 = Scale (*g++) + yo; - if (path->state.font_style & TWIN_TEXT_OBLIQUE) + x1 = FX(*g++, &info); + y1 = FY(*g++, &info); + x2 = FX(*g++, &info); + y2 = FY(*g++, &info); + x3 = FX(*g++, &info); + y3 = FY(*g++, &info); + if (info.snap) { - x1 -= y1 >> 2; - x2 -= y2 >> 2; - x3 -= y3 >> 2; + x1 = _twin_snap (x1, info.snap_x, info.n_snap_x); + y1 = _twin_snap (y1, info.snap_y, info.n_snap_y); + x2 = _twin_snap (x2, info.snap_x, info.n_snap_x); + y2 = _twin_snap (y2, info.snap_y, info.n_snap_y); + x3 = _twin_snap (x3, info.snap_x, info.n_snap_x); + y3 = _twin_snap (y3, info.snap_y, info.n_snap_y); } - _twin_path_scurve (stroke, PX(x1,y1), PY(x1,y1), - PX(x2,y2), PY(x2,y2), PX(x3,y3), PY(x3,y3)); + twin_path_curve (stroke, x1, y1, x2, y2, x3, y3); continue; case 'e': break; @@ -235,10 +395,14 @@ } twin_path_convolve (path, stroke, pen); - twin_path_destroy (stroke); twin_path_destroy (pen); + twin_path_destroy (stroke); - _twin_path_smove (path, PX(metrics.width, 0), PY(metrics.width,0)); + width = _twin_glyph_width (&info, b); + + _twin_path_smove (path, + origin.x + _twin_matrix_dx (&info.matrix, width, 0), + origin.y + _twin_matrix_dy (&info.matrix, width, 0)); } twin_fixed_t Index: twin_matrix.c =================================================================== RCS file: /local/src/CVS/twin/twin_matrix.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_matrix.c 4 Oct 2004 07:49:49 -0000 1.3 +++ twin_matrix.c 5 Oct 2004 18:42:53 -0000 1.4 @@ -49,10 +49,10 @@ #define _twin_dump_matrix(n,m) #endif -static void -_twin_matrix_multiply (twin_matrix_t *result, - const twin_matrix_t *a, - const twin_matrix_t *b) +void +twin_matrix_multiply (twin_matrix_t *result, + const twin_matrix_t *a, + const twin_matrix_t *b) { twin_matrix_t r; int row, col, n; @@ -91,7 +91,7 @@ t.m[0][0] = TWIN_FIXED_ONE; t.m[0][1] = 0; t.m[1][0] = 0; t.m[1][1] = TWIN_FIXED_ONE; t.m[2][0] = tx; t.m[2][1] = ty; - _twin_matrix_multiply (m, &t, m); + twin_matrix_multiply (m, &t, m); } void @@ -102,7 +102,7 @@ t.m[0][0] = sx; t.m[0][1] = 0; t.m[1][0] = 0; t.m[1][1] = sy; t.m[2][0] = 0; t.m[2][1] = 0; - _twin_matrix_multiply (m, &t, m); + twin_matrix_multiply (m, &t, m); } twin_fixed_t @@ -144,7 +144,7 @@ t.m[0][0] = c; t.m[0][1] = s; t.m[1][0] = -s; t.m[1][1] = c; t.m[2][0] = 0; t.m[2][1] = 0; - _twin_matrix_multiply (m, &t, m); + twin_matrix_multiply (m, &t, m); } twin_sfixed_t Index: twin_path.c =================================================================== RCS file: /local/src/CVS/twin/twin_path.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- twin_path.c 4 Oct 2004 07:49:49 -0000 1.9 +++ twin_path.c 5 Oct 2004 18:42:53 -0000 1.10 @@ -185,7 +185,6 @@ twin_fixed_abs (m->m[1][0]) + twin_fixed_abs (m->m[1][1])); } - void twin_path_circle (twin_path_t *path, twin_fixed_t radius) { @@ -230,6 +229,51 @@ } void +twin_path_ellipse (twin_path_t *path, + twin_fixed_t x_radius, + twin_fixed_t y_radius) +{ + int sides; + int n; + twin_spoint_t center; + int i; + twin_matrix_t save; + twin_fixed_t max_radius; + + save = twin_path_current_matrix (path); + + twin_path_scale (path, x_radius, y_radius); + + center = _twin_path_current_spoint (path); + + twin_path_close (path); + + max_radius = _twin_matrix_max_radius (&path->state.matrix); + + sides = max_radius / twin_sfixed_to_fixed (TWIN_SFIXED_TOLERANCE); + + if (sides > 1024) sides = 1024; + + n = 2; + while ((1 << n) < sides) + n++; + + for (i = 0; i <= (1 << n); i++) + { + twin_angle_t a = (i * TWIN_ANGLE_360) >> n; + twin_fixed_t x = twin_cos (a); + twin_fixed_t y = twin_sin (a); + + _twin_path_sdraw (path, + center.x + _twin_matrix_dx (&path->state.matrix, x, y), + center.y + _twin_matrix_dy (&path->state.matrix, x, y)); + } + + twin_path_close (path); + twin_path_set_matrix (path, save); +} + +void twin_path_set_matrix (twin_path_t *path, twin_matrix_t matrix) { path->state.matrix = matrix; @@ -278,12 +322,12 @@ } void -twin_path_set_font_style (twin_path_t *path, int font_style) +twin_path_set_font_style (twin_path_t *path, twin_style_t font_style) { path->state.font_style = font_style; } -int +twin_style_t twin_path_current_font_style (twin_path_t *path) { return path->state.font_style; @@ -380,15 +424,15 @@ void twin_composite_path (twin_pixmap_t *dst, twin_operand_t *src, - int src_x, - int src_y, + twin_coord_t src_x, + twin_coord_t src_y, twin_path_t *path, twin_operator_t operator) { twin_rect_t bounds; twin_pixmap_t *mask; twin_operand_t msk; - int width, height; + twin_coord_t width, height; twin_path_bounds (path, &bounds); if (bounds.left == bounds.right) @@ -424,8 +468,8 @@ void twin_composite_stroke (twin_pixmap_t *dst, twin_operand_t *src, - int src_x, - int src_y, + twin_coord_t src_x, + twin_coord_t src_y, twin_path_t *stroke, twin_fixed_t pen_width, twin_operator_t operator) Index: twin_pixmap.c =================================================================== RCS file: /local/src/CVS/twin/twin_pixmap.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_pixmap.c 30 Sep 2004 17:23:07 -0000 1.2 +++ twin_pixmap.c 5 Oct 2004 18:42:53 -0000 1.3 @@ -25,10 +25,12 @@ #include "twinint.h" twin_pixmap_t * -twin_pixmap_create (twin_format_t format, int width, int height) +twin_pixmap_create (twin_format_t format, + twin_coord_t width, + twin_coord_t height) { - int stride = twin_bytes_per_pixel (format) * width; - int size = sizeof (twin_pixmap_t) + stride * height; + twin_coord_t stride = twin_bytes_per_pixel (format) * width; + twin_area_t size = sizeof (twin_pixmap_t) + (twin_area_t) stride * height; twin_pixmap_t *pixmap = malloc (size); if (!pixmap) return 0; @@ -99,7 +101,7 @@ } twin_pointer_t -twin_pixmap_pointer (twin_pixmap_t *pixmap, int x, int y) +twin_pixmap_pointer (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y) { twin_pointer_t p; @@ -131,7 +133,8 @@ void twin_pixmap_damage (twin_pixmap_t *pixmap, - int x1, int y1, int x2, int y2) + twin_coord_t x1, twin_coord_t y1, + twin_coord_t x2, twin_coord_t y2) { if (pixmap->screen) twin_screen_damage (pixmap->screen, @@ -156,7 +159,7 @@ } void -twin_pixmap_move (twin_pixmap_t *pixmap, int x, int y) +twin_pixmap_move (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y) { twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); pixmap->x = x; Index: twin_poly.c =================================================================== RCS file: /local/src/CVS/twin/twin_poly.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_poly.c 2 Oct 2004 03:07:26 -0000 1.7 +++ twin_poly.c 5 Oct 2004 18:42:53 -0000 1.8 @@ -348,7 +348,8 @@ } void -twin_fill_path (twin_pixmap_t *pixmap, twin_path_t *path, int dx, int dy) +twin_fill_path (twin_pixmap_t *pixmap, twin_path_t *path, + twin_coord_t dx, twin_coord_t dy) { twin_edge_t *edges; int nedges, n; Index: twin_screen.c =================================================================== RCS file: /local/src/CVS/twin/twin_screen.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_screen.c 2 Oct 2004 03:07:26 -0000 1.4 +++ twin_screen.c 5 Oct 2004 18:42:53 -0000 1.5 @@ -25,8 +25,8 @@ #include "twinint.h" twin_screen_t * -twin_screen_create (int width, - int height, +twin_screen_create (twin_coord_t width, + twin_coord_t height, twin_put_begin_t put_begin, twin_put_span_t put_span, void *closure) @@ -106,7 +106,8 @@ void twin_screen_damage (twin_screen_t *screen, - int left, int top, int right, int bottom) + twin_coord_t left, twin_coord_t top, + twin_coord_t right, twin_coord_t bottom) { if (screen->damage.left == screen->damage.right) { @@ -131,7 +132,8 @@ } void -twin_screen_resize (twin_screen_t *screen, int width, int height) +twin_screen_resize (twin_screen_t *screen, + twin_coord_t width, twin_coord_t height) { screen->width = width; screen->height = height; @@ -152,10 +154,10 @@ screen->damage.left < screen->damage.right && screen->damage.top < screen->damage.bottom) { - int x = screen->damage.left; - int y = screen->damage.top; - int width = screen->damage.right - screen->damage.left; - int height = screen->damage.bottom - screen->damage.top; + twin_coord_t x = screen->damage.left; + twin_coord_t y = screen->damage.top; + twin_coord_t width = screen->damage.right - screen->damage.left; + twin_coord_t height = screen->damage.bottom - screen->damage.top; twin_argb32_t *span; twin_pixmap_t *p; Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_x11.c 4 Oct 2004 07:49:49 -0000 1.4 +++ twin_x11.c 5 Oct 2004 18:42:53 -0000 1.5 @@ -26,11 +26,11 @@ #include "twinint.h" static void -_twin_x11_put_begin (int x, - int y, - int width, - int height, - void *closure) +_twin_x11_put_begin (twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height, + void *closure) { twin_x11_t *tx = closure; @@ -49,15 +49,15 @@ } static void -_twin_x11_put_span (int x, - int y, - int width, +_twin_x11_put_span (twin_coord_t x, + twin_coord_t y, + twin_coord_t width, twin_argb32_t *pixels, void *closure) { twin_x11_t *tx = closure; - int ix = 0; - int iw = width; + twin_coord_t ix = 0; + twin_coord_t iw = width; if (!tx->image) return; Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- twinint.h 4 Oct 2004 20:44:28 -0000 1.11 +++ twinint.h 5 Oct 2004 18:42:53 -0000 1.12 @@ -66,6 +66,8 @@ typedef signed char twin_gfixed_t; +#define TWIN_GFIXED_ONE (0x40) + /* * Compositing stuff */ @@ -357,6 +359,12 @@ extern const signed char _twin_gtable[]; extern const uint16_t _twin_g_offsets[]; +/* + * Check these whenever glyphs are changed + */ +#define TWIN_GLYPH_MAX_SNAP_X 4 +#define TWIN_GLYPH_MAX_SNAP_Y 7 + #define twin_glyph_left(g) ((g)[0]) #define twin_glyph_right(g) ((g)[1]) #define twin_glyph_ascent(g) ((g)[2]) Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- xtwin.c 4 Oct 2004 20:44:28 -0000 1.16 +++ xtwin.c 5 Oct 2004 18:42:53 -0000 1.17 @@ -41,9 +41,9 @@ #define TWIN_CLOCK_SECOND_OUT 0x30000000 #define TWIN_CLOCK_TIC 0xffbababa #define TWIN_CLOCK_NUMBERS 0xffdedede -#define TWIN_CLOCK_WATER 0x40000000 +#define TWIN_CLOCK_WATER 0x60200000 #define TWIN_CLOCK_WATER_OUT 0x40404040 -#define TWIN_CLOCK_WATER_UNDER 0xcccc0000 +#define TWIN_CLOCK_WATER_UNDER 0x60400000 #define TWIN_CLOCK_BORDER 0xffbababa #define TWIN_CLOCK_BORDER_WIDTH D(0.01) @@ -278,8 +278,8 @@ TWIN_TEXT_BOLD|TWIN_TEXT_OBLIQUE }; -#define WIDTH 256 -#define HEIGHT 256 +#define WIDTH 512 +#define HEIGHT 512 int main (int argc, char **argv) @@ -349,7 +349,7 @@ stroke = twin_path_create (); twin_path_move (stroke, D(30), D(400)); twin_path_set_font_size (stroke, D(100)); - twin_path_utf8 (stroke, "jelly world."); + twin_path_utf8 (stroke, "jelly HEzt/[]."); twin_path_convolve (path, stroke, pen); /* twin_path_append (path, stroke); */ twin_path_destroy (stroke); @@ -397,12 +397,21 @@ } #endif #if 1 - fx = D(10); + fx = D(15); fy = 0; - for (g = 10; g <= 38; g += 4) + twin_path_translate (path, 0, D(HEIGHT)); + twin_path_rotate (path, -twin_degrees_to_angle (90)); + twin_path_scale (path, D(1), D(0.5)); + twin_path_set_font_style (path, TWIN_TEXT_OBLIQUE); + for (g = 40; g <= 60; g += 4) { twin_path_set_font_size (path, D(g)); -#if 1 +#if 0 + fy += D(g+2); + twin_path_move (path, fx, fy); + twin_path_utf8 (path, "H"); +#endif +#if 0 fy += D(g+2); twin_path_move (path, fx, fy); twin_path_utf8 (path, @@ -428,10 +437,11 @@ "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."); } #endif -#if 0 - fy += D(g); +#if 1 + fy += D(g + 2); twin_path_move (path, fx, fy); -#define TEXT "jelly world" +#define TEXT "jelly HEzt/[]." +/* twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); */ twin_path_utf8 (path, TEXT); { twin_text_metrics_t m; @@ -439,6 +449,7 @@ stroke = twin_path_create (); twin_path_set_matrix (stroke, twin_path_current_matrix (path)); twin_text_metrics_utf8 (path, TEXT, &m); + twin_path_translate (stroke, TWIN_FIXED_HALF, TWIN_FIXED_HALF); twin_path_move (stroke, fx, fy); twin_path_draw (stroke, fx + m.width, fy); twin_paint_stroke (red, 0xffff0000, stroke, D(1)); @@ -624,9 +635,8 @@ ++nclock; #endif -#if 1 - twin_start_clock (x11->screen, 0, 0, WIDTH, HEIGHT); -#endif + if (!nclock) + twin_start_clock (x11->screen, 0, 0, WIDTH, HEIGHT); #if 0 twin_start_clock (x11->screen, 0, 0, 256, 256); twin_start_clock (x11->screen, 256, 0, 256, 256); @@ -637,4 +647,3 @@ sleep (1); return 0; } - From commit at keithp.com Tue Oct 5 17:11:30 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 5 17:11:40 2004 Subject: [Commit] twin ChangeLog, 1.18, 1.19 Makefile.am, 1.7, 1.8 twin.h, 1.13, 1.14 twin_draw.c, 1.5, 1.6 twin_path.c, 1.10, 1.11 twin_pixmap.c, 1.3, 1.4 twin_screen.c, 1.5, 1.6 twin_thread.c, NONE, 1.1 twin_window.c, NONE, 1.1 twin_x11.c, 1.5, 1.6 twin_x11.h, 1.2, 1.3 xtwin.c, 1.17, 1.18 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv24081 Modified Files: ChangeLog Makefile.am twin.h twin_draw.c twin_path.c twin_pixmap.c twin_screen.c twin_x11.c twin_x11.h xtwin.c Added Files: twin_thread.c twin_window.c Log Message: 2004-10-05 Keith Packard * Makefile.am: * twin.h: * twin_draw.c: (twin_fill): * twin_path.c: (twin_composite_path): * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_show), (twin_pixmap_hide), (_twin_pixmap_fetch), (twin_pixmap_transparent), (twin_pixmap_move), (twin_pixmap_dispatch): * twin_screen.c: (twin_screen_create), (twin_screen_lock), (twin_screen_unlock), (twin_screen_update), (twin_screen_set_active), (twin_screen_get_active), (twin_screen_dispatch): * twin_thread.c: (twin_mutex_init), (twin_mutex_lock), (twin_mutex_unlock), (twin_cond_init), (twin_cond_broadcast), (twin_cond_wait), (twin_thread_create): * twin_window.c: (twin_window_create), (twin_window_destroy), (twin_window_show), (twin_window_hide), (twin_window_configure), (twin_window_style_size), (twin_window_set_name), (twin_window_frame), (twin_window_draw), (twin_window_dispatch): * twin_x11.c: (_twin_x11_put_begin), (_twin_x11_put_span), (twin_x11_damage_thread), (twin_x11_event_thread), (twin_x11_screen_damaged), (twin_x11_create), (twin_x11_destroy): * twin_x11.h: * xtwin.c: (twin_clock_set_transform), (twin_clock_hand), (twin_clock_face), (twin_clock), (twin_app_thread), (twin_start_app), (twin_start_clock), (main): Add the beginings of event dispatch and a bit of window management including titles. Default event dispatcher does restacking and motion. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- ChangeLog 5 Oct 2004 18:42:53 -0000 1.18 +++ ChangeLog 6 Oct 2004 00:11:27 -0000 1.19 @@ -1,5 +1,37 @@ 2004-10-05 Keith Packard + * Makefile.am: + * twin.h: + * twin_draw.c: (twin_fill): + * twin_path.c: (twin_composite_path): + * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_show), + (twin_pixmap_hide), (_twin_pixmap_fetch), + (twin_pixmap_transparent), (twin_pixmap_move), + (twin_pixmap_dispatch): + * twin_screen.c: (twin_screen_create), (twin_screen_lock), + (twin_screen_unlock), (twin_screen_update), + (twin_screen_set_active), (twin_screen_get_active), + (twin_screen_dispatch): + * twin_thread.c: (twin_mutex_init), (twin_mutex_lock), + (twin_mutex_unlock), (twin_cond_init), (twin_cond_broadcast), + (twin_cond_wait), (twin_thread_create): + * twin_window.c: (twin_window_create), (twin_window_destroy), + (twin_window_show), (twin_window_hide), (twin_window_configure), + (twin_window_style_size), (twin_window_set_name), + (twin_window_frame), (twin_window_draw), (twin_window_dispatch): + * twin_x11.c: (_twin_x11_put_begin), (_twin_x11_put_span), + (twin_x11_damage_thread), (twin_x11_event_thread), + (twin_x11_screen_damaged), (twin_x11_create), (twin_x11_destroy): + * twin_x11.h: + * xtwin.c: (twin_clock_set_transform), (twin_clock_hand), + (twin_clock_face), (twin_clock), (twin_app_thread), + (twin_start_app), (twin_start_clock), (main): + Add the beginings of event dispatch and a bit of + window management including titles. Default event dispatcher + does restacking and motion. + +2004-10-05 Keith Packard + * twin.h: * twin_draw.c: (twin_composite), (twin_fill): * twin_matrix.c: (twin_matrix_multiply), (twin_matrix_translate), Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Makefile.am 30 Sep 2004 17:23:07 -0000 1.7 +++ Makefile.am 6 Oct 2004 00:11:27 -0000 1.8 @@ -30,7 +30,9 @@ twin_primitive.c \ twin_screen.c \ twin_spline.c \ + twin_thread.c \ twin_trig.c \ + twin_window.c \ twin_x11.c \ twinint.h \ xtwin.c Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- twin.h 5 Oct 2004 18:42:53 -0000 1.13 +++ twin.h 6 Oct 2004 00:11:27 -0000 1.14 @@ -44,6 +44,19 @@ typedef int16_t twin_keysym_t; typedef int32_t twin_area_t; +/* + * Mutexes + */ +#if HAVE_PTHREAD_H +typedef pthread_mutex_t twin_mutex_t; +typedef pthread_cond_t twin_cond_t; +typedef pthread_t twin_thread_t; +#else +typedef int twin_mutext_t; +typedef int twin_cond_t; +typedef int twin_thread_t; +#endif + #define TWIN_FALSE 0 #define TWIN_TRUE 1 @@ -80,6 +93,8 @@ twin_argb32_t *argb32; } twin_pointer_t; +typedef struct _twin_window twin_window_t; + /* * A rectangular array of pixels */ @@ -92,7 +107,7 @@ /* * List of displayed pixmaps */ - struct _twin_pixmap *higher; + struct _twin_pixmap *down, *up; /* * Screen position */ @@ -108,20 +123,25 @@ * Pixels */ twin_pointer_t p; + /* + * When representing a window, this point + * refers to the window object + */ + twin_window_t *window; } twin_pixmap_t; /* * twin_put_begin_t: called before data are drawn to the screen * twin_put_span_t: called for each scanline drawn */ -typedef void (*twin_put_begin_t) (twin_coord_t x, - twin_coord_t y, - twin_coord_t width, - twin_coord_t height, +typedef void (*twin_put_begin_t) (twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom, void *closure); -typedef void (*twin_put_span_t) (twin_coord_t x, - twin_coord_t y, - twin_coord_t width, +typedef void (*twin_put_span_t) (twin_coord_t left, + twin_coord_t top, + twin_coord_t right, twin_argb32_t *pixels, void *closure); @@ -132,7 +152,15 @@ /* * List of displayed pixmaps */ - twin_pixmap_t *bottom; + twin_pixmap_t *top, *bottom; + /* + * One of them receives all key events + */ + twin_pixmap_t *active; + /* + * pointer down for this window + */ + twin_pixmap_t *pointer; /* * Output size */ @@ -144,15 +172,17 @@ void (*damaged) (void *); void *damaged_closure; twin_count_t disable; -#if HAVE_PTHREAD_H - pthread_mutex_t screen_mutex; -#endif + twin_mutex_t screen_mutex; /* * Repaint function */ twin_put_begin_t put_begin; twin_put_span_t put_span; void *closure; + /* + * Window manager stuff + */ + twin_coord_t button_x, button_y; } twin_screen_t; /* @@ -226,7 +256,8 @@ typedef enum _twin_event_kind { EventButtonDown, EventButtonUp, EventMotion, - EventKeyDown, EventKeyUp, EventUcs4 + EventKeyDown, EventKeyUp, EventUcs4, + EventActivate, EventDeactivate, } twin_event_kind_t; typedef struct _twin_event { @@ -234,11 +265,9 @@ union { struct { twin_coord_t x, y; + twin_coord_t screen_x, screen_y; twin_count_t button; - } button; - struct { - twin_coord_t x, y; - } motion; + } pointer; struct { twin_keysym_t key; } key; @@ -248,6 +277,53 @@ } u; } twin_event_t; +typedef struct _twin_event_queue { + struct _twin_event_queue *next; + twin_event_t event; +} twin_event_queue_t; + +/* + * Windows + */ + +typedef enum _twin_window_style { + WindowPlain, + WindowApplication, +} twin_window_style_t; + +typedef void (*twin_draw_func_t) (twin_window_t *window); + +typedef twin_bool_t (*twin_event_func_t) (twin_window_t *window, + twin_event_t *event); + +typedef void (*twin_destroy_func_t) (twin_window_t *window); + +struct _twin_window { + twin_screen_t *screen; + twin_pixmap_t *pixmap; + twin_window_style_t style; + twin_rect_t client; + twin_rect_t damage; + void *client_data; + char *name; + + twin_draw_func_t draw; + twin_event_func_t event; + twin_destroy_func_t destroy; +}; + +/* + * Widgets + */ + +typedef struct { + twin_rect_t geometry; +} twin_widget_t; + +typedef struct { + twin_widget_t core; +} twin_button_t; + /* * twin_convolve.c */ @@ -278,10 +354,17 @@ twin_fill (twin_pixmap_t *dst, twin_argb32_t pixel, twin_operator_t operator, - twin_coord_t x, - twin_coord_t y, - twin_coord_t width, - twin_coord_t height); + twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom); + +/* + * twin_event.c + */ + +void +twin_event_enqueue (const twin_event_t *event); /* * twin_fixed.c @@ -515,6 +598,12 @@ twin_pointer_t twin_pixmap_pointer (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y); +twin_bool_t +twin_pixmap_transparent (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y); + +twin_bool_t +twin_pixmap_dispatch (twin_pixmap_t *pixmap, twin_event_t *event); + /* * twin_poly.c */ @@ -563,6 +652,16 @@ twin_screen_update (twin_screen_t *screen); void +twin_screen_set_active (twin_screen_t *screen, twin_pixmap_t *pixmap); + +twin_pixmap_t * +twin_screen_get_active (twin_screen_t *screen); + +twin_bool_t +twin_screen_dispatch (twin_screen_t *screen, + twin_event_t *event); + +void twin_screen_lock (twin_screen_t *screen); void @@ -580,6 +679,33 @@ twin_fixed_t x3, twin_fixed_t y3); /* + * twin_thread.c + */ + +void +twin_mutex_init (twin_mutex_t *mutex); + +void +twin_mutex_lock (twin_mutex_t *mutex); + +void +twin_mutex_unlock (twin_mutex_t *mutex); + +void +twin_cond_init (twin_cond_t *cond); + +void +twin_cond_broadcast (twin_cond_t *cond); + +void +twin_cond_wait (twin_cond_t *cond, twin_mutex_t *mutex); + +typedef void * (*twin_thread_func_t) (void *arg); + +int +twin_thread_create (twin_thread_t *thread, twin_thread_func_t func, void *arg); + +/* * twin_trig.c */ @@ -592,4 +718,49 @@ twin_fixed_t twin_tan (twin_angle_t a); +/* + * twin_window.c + */ + +twin_window_t * +twin_window_create (twin_screen_t *screen, + twin_format_t format, + twin_window_style_t style, + twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height); + +void +twin_window_destroy (twin_window_t *window); + +void +twin_window_show (twin_window_t *window); + +void +twin_window_hide (twin_window_t *window); + +void +twin_window_configure (twin_window_t *window, + twin_window_style_t style, + twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height); + +void +twin_window_set_name (twin_window_t *window, + const char *name); + +void +twin_window_style_size (twin_window_style_t style, + twin_rect_t *size); + +void +twin_window_draw (twin_window_t *window); + +twin_bool_t +twin_window_dispatch (twin_window_t *window, twin_event_t *event); + + #endif /* _TWIN_H_ */ Index: twin_draw.c =================================================================== RCS file: /local/src/CVS/twin/twin_draw.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_draw.c 5 Oct 2004 18:42:53 -0000 1.5 +++ twin_draw.c 6 Oct 2004 00:11:27 -0000 1.6 @@ -370,32 +370,28 @@ twin_fill (twin_pixmap_t *dst, twin_argb32_t pixel, twin_operator_t operator, - twin_coord_t x, - twin_coord_t y, - twin_coord_t width, - twin_coord_t height) + twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom) { twin_src_op op; twin_source_u src; twin_coord_t iy; - twin_coord_t left, right, top, bottom; twin_pixmap_lock (dst); src.c = pixel; - left = x; - right = x + width; - top = y; - bottom = y + height; if (left < 0) left = 0; if (right > dst->width) right = dst->width; if (top < 0) top = 0; - if (top > dst->height) - top = dst->height; + if (bottom > dst->height) + bottom = dst->height; op = fill[operator][dst->format]; for (iy = top; iy < bottom; iy++) (*op) (twin_pixmap_pointer (dst, left, iy), src, right - left); + twin_pixmap_damage (dst, left, right, top, bottom); twin_pixmap_unlock (dst); } Index: twin_path.c =================================================================== RCS file: /local/src/CVS/twin/twin_path.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- twin_path.c 5 Oct 2004 18:42:53 -0000 1.10 +++ twin_path.c 6 Oct 2004 00:11:27 -0000 1.11 @@ -443,7 +443,6 @@ if (!mask) return; - twin_fill (mask, 0x00000000, TWIN_SOURCE, 0, 0, width, height); twin_fill_path (mask, path, -bounds.left, -bounds.top); msk.source_kind = TWIN_PIXMAP; msk.u.pixmap = mask; Index: twin_pixmap.c =================================================================== RCS file: /local/src/CVS/twin/twin_pixmap.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_pixmap.c 5 Oct 2004 18:42:53 -0000 1.3 +++ twin_pixmap.c 6 Oct 2004 00:11:27 -0000 1.4 @@ -30,12 +30,14 @@ twin_coord_t height) { twin_coord_t stride = twin_bytes_per_pixel (format) * width; - twin_area_t size = sizeof (twin_pixmap_t) + (twin_area_t) stride * height; + twin_area_t space = (twin_area_t) stride * height; + twin_area_t size = sizeof (twin_pixmap_t) + space; twin_pixmap_t *pixmap = malloc (size); if (!pixmap) return 0; pixmap->screen = 0; - pixmap->higher = 0; + pixmap->up = 0; + pixmap->down = 0; pixmap->x = pixmap->y = 0; pixmap->format = format; pixmap->width = width; @@ -43,6 +45,7 @@ pixmap->stride = stride; pixmap->disable = 0; pixmap->p.v = pixmap + 1; + memset (pixmap->p.v, '\0', space); return pixmap; } @@ -59,23 +62,36 @@ twin_screen_t *screen, twin_pixmap_t *lower) { - twin_pixmap_t **higherp; - - twin_screen_lock (screen); - if (pixmap->disable) twin_screen_disable_update (screen); + if (lower == pixmap) + lower = pixmap->down; + if (pixmap->screen) twin_pixmap_hide (pixmap); + twin_screen_lock (screen); + pixmap->screen = screen; + if (lower) - higherp = &lower->higher; + { + pixmap->down = lower; + pixmap->up = lower->up; + lower->up = pixmap; + if (!pixmap->up) + screen->top = pixmap; + } else - higherp = &screen->bottom; - pixmap->higher = *higherp; - *higherp = pixmap; + { + pixmap->down = NULL; + pixmap->up = screen->bottom; + screen->bottom = pixmap; + if (!pixmap->up) + screen->top = pixmap; + } + twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); twin_screen_unlock (screen); } @@ -84,17 +100,29 @@ twin_pixmap_hide (twin_pixmap_t *pixmap) { twin_screen_t *screen = pixmap->screen; - twin_pixmap_t **higherp; + twin_pixmap_t **up, **down; if (!screen) return; twin_screen_lock (screen); twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); - for (higherp = &screen->bottom; *higherp != pixmap; higherp = &(*higherp)->higher) - ; - *higherp = pixmap->higher; + + if (pixmap->up) + down = &pixmap->up->down; + else + down = &screen->top; + + if (pixmap->down) + up = &pixmap->down->up; + else + up = &screen->bottom; + + *down = pixmap->down; + *up = pixmap->up; + pixmap->screen = 0; - pixmap->higher = 0; + pixmap->up = 0; + pixmap->down = 0; if (pixmap->disable) twin_screen_enable_update (screen); twin_screen_unlock (screen); @@ -158,11 +186,48 @@ twin_screen_unlock (pixmap->screen); } +static twin_argb32_t +_twin_pixmap_fetch (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y) +{ + twin_pointer_t p = twin_pixmap_pointer (pixmap, x - pixmap->x, y - pixmap->y); + + if (pixmap->x <= x && x < pixmap->x + pixmap->width && + pixmap->y <= y && y < pixmap->y + pixmap->height) + { + switch (pixmap->format) { + case TWIN_A8: + return *p.a8 << 24; + case TWIN_RGB16: + return twin_rgb16_to_argb32 (*p.rgb16); + case TWIN_ARGB32: + return *p.argb32; + } + } + return 0; +} + +twin_bool_t +twin_pixmap_transparent (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y) +{ + return (_twin_pixmap_fetch (pixmap, x, y) >> 24) == 0; +} + void twin_pixmap_move (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y) { + twin_pixmap_lock (pixmap); twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); pixmap->x = x; pixmap->y = y; twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); + twin_pixmap_unlock (pixmap); } + +twin_bool_t +twin_pixmap_dispatch (twin_pixmap_t *pixmap, twin_event_t *event) +{ + if (pixmap->window) + return twin_window_dispatch (pixmap->window, event); + return TWIN_FALSE; +} + Index: twin_screen.c =================================================================== RCS file: /local/src/CVS/twin/twin_screen.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_screen.c 5 Oct 2004 18:42:53 -0000 1.5 +++ twin_screen.c 6 Oct 2004 00:11:27 -0000 1.6 @@ -34,6 +34,7 @@ twin_screen_t *screen = malloc (sizeof (twin_screen_t)); if (!screen) return 0; + screen->top = 0; screen->bottom = 0; screen->width = width; screen->height = height; @@ -42,29 +43,25 @@ screen->damaged = NULL; screen->damaged_closure = NULL; screen->disable = 0; -#if HAVE_PTHREAD_H - pthread_mutex_init (&screen->screen_mutex, NULL); -#endif + twin_mutex_init (&screen->screen_mutex); screen->put_begin = put_begin; screen->put_span = put_span; screen->closure = closure; + + screen->button_x = screen->button_y = -1; return screen; } void twin_screen_lock (twin_screen_t *screen) { -#if HAVE_PTHREAD_H - pthread_mutex_lock (&screen->screen_mutex); -#endif + twin_mutex_lock (&screen->screen_mutex); } void twin_screen_unlock (twin_screen_t *screen) { -#if HAVE_PTHREAD_H - pthread_mutex_unlock (&screen->screen_mutex); -#endif + twin_mutex_unlock (&screen->screen_mutex); } void @@ -104,6 +101,8 @@ screen->disable++; } +#include + void twin_screen_damage (twin_screen_t *screen, twin_coord_t left, twin_coord_t top, @@ -150,59 +149,128 @@ void twin_screen_update (twin_screen_t *screen) { - if (!screen->disable && - screen->damage.left < screen->damage.right && - screen->damage.top < screen->damage.bottom) + twin_coord_t left = screen->damage.left; + twin_coord_t top = screen->damage.top; + twin_coord_t right = screen->damage.right; + twin_coord_t bottom = screen->damage.bottom; + + if (!screen->disable && left < right && top < bottom) { - twin_coord_t x = screen->damage.left; - twin_coord_t y = screen->damage.top; - twin_coord_t width = screen->damage.right - screen->damage.left; - twin_coord_t height = screen->damage.bottom - screen->damage.top; twin_argb32_t *span; twin_pixmap_t *p; + twin_coord_t y; + twin_coord_t width = right - left; + screen->damage.left = screen->damage.right = 0; + screen->damage.top = screen->damage.bottom = 0; /* XXX what is the maximum number of lines? */ span = malloc (width * sizeof (twin_argb32_t)); if (!span) return; if (screen->put_begin) - (*screen->put_begin) (x, y, width, height, screen->closure); - while (height--) + (*screen->put_begin) (left, top, right, bottom, screen->closure); + for (y = top; y < bottom; y++) { memset (span, 0xff, width * sizeof (twin_argb32_t)); - for (p = screen->bottom; p; p = p->higher) + for (p = screen->bottom; p; p = p->up) { twin_pointer_t dst; twin_source_u src; - - int left, right; + twin_coord_t p_left, p_right; + /* bounds check in y */ if (y < p->y) continue; if (p->y + p->height <= y) continue; /* bounds check in x*/ - left = x; - if (left < p->x) - left = p->x; - right = x + width; - if (right > p->x + p->width) - right = p->x + p->width; - if (left >= right) + p_left = left; + if (p_left < p->x) + p_left = p->x; + p_right = right; + if (p_right > p->x + p->width) + p_right = p->x + p->width; + if (p_left >= p_right) continue; - dst.argb32 = span + (left - x); - src.p = twin_pixmap_pointer (p, left - p->x, y - p->y); + dst.argb32 = span + (p_left - left); + src.p = twin_pixmap_pointer (p, p_left - p->x, y - p->y); if (p->format == TWIN_RGB16) - _twin_rgb16_source_argb32 (dst, src, right - left); + _twin_rgb16_source_argb32 (dst, src, p_right - p_left); else - _twin_argb32_over_argb32 (dst, src, right - left); + _twin_argb32_over_argb32 (dst, src, p_right - p_left); } - (*screen->put_span) (x, y, width, span, screen->closure); - y++; + (*screen->put_span) (left, y, right, span, screen->closure); } free (span); - screen->damage.left = screen->damage.right = 0; - screen->damage.top = screen->damage.bottom = 0; } } + +void +twin_screen_set_active (twin_screen_t *screen, twin_pixmap_t *pixmap) +{ + twin_event_t ev; + twin_pixmap_t *old = screen->active; + screen->active = pixmap; + if (old) + { + ev.kind = EventDeactivate; + twin_pixmap_dispatch (old, &ev); + } + if (pixmap) + { + ev.kind = EventActivate; + twin_pixmap_dispatch (pixmap, &ev); + } +} + +twin_pixmap_t * +twin_screen_get_active (twin_screen_t *screen) +{ + return screen->active; +} + +twin_bool_t +twin_screen_dispatch (twin_screen_t *screen, + twin_event_t *event) +{ + twin_pixmap_t *pixmap; + + switch (event->kind) { + case EventMotion: + case EventButtonDown: + case EventButtonUp: + pixmap = screen->pointer; + if (!pixmap) + { + for (pixmap = screen->top; pixmap; pixmap = pixmap->down) + if (!twin_pixmap_transparent (pixmap, + event->u.pointer.screen_x, + event->u.pointer.screen_y)) + { + break; + } + if (event->kind == EventButtonDown) + screen->pointer = pixmap; + } + if (event->kind == EventButtonUp) + screen->pointer = NULL; + if (pixmap) + { + event->u.pointer.x = event->u.pointer.screen_x - pixmap->x; + event->u.pointer.y = event->u.pointer.screen_y - pixmap->y; + } + break; + case EventKeyDown: + case EventKeyUp: + case EventUcs4: + pixmap = screen->active; + break; + default: + pixmap = NULL; + break; + } + if (pixmap) + return twin_pixmap_dispatch (pixmap, event); + return TWIN_FALSE; +} --- NEW FILE: twin_thread.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_window.c --- (This appears to be a binary file; contents omitted.) Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_x11.c 5 Oct 2004 18:42:53 -0000 1.5 +++ twin_x11.c 6 Oct 2004 00:11:27 -0000 1.6 @@ -26,15 +26,17 @@ #include "twinint.h" static void -_twin_x11_put_begin (twin_coord_t x, - twin_coord_t y, - twin_coord_t width, - twin_coord_t height, +_twin_x11_put_begin (twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom, void *closure) { - twin_x11_t *tx = closure; + twin_x11_t *tx = closure; + twin_coord_t width = right - left; + twin_coord_t height = bottom - top; - tx->iy = 0; + tx->image_y = top; tx->image = XCreateImage (tx->dpy, tx->visual, tx->depth, ZPixmap, 0, 0, width, height, 32, 0); if (tx->image) @@ -49,33 +51,32 @@ } static void -_twin_x11_put_span (twin_coord_t x, - twin_coord_t y, - twin_coord_t width, +_twin_x11_put_span (twin_coord_t left, + twin_coord_t top, + twin_coord_t right, twin_argb32_t *pixels, void *closure) { - twin_x11_t *tx = closure; - twin_coord_t ix = 0; - twin_coord_t iw = width; + twin_x11_t *tx = closure; + twin_coord_t width = right - left; + twin_coord_t ix; + twin_coord_t iy = top - tx->image_y; if (!tx->image) return; - while (iw--) + for (ix = 0; ix < width; ix++) { twin_argb32_t pixel = *pixels++; if (tx->depth == 16) pixel = twin_argb32_to_rgb16 (pixel); - XPutPixel (tx->image, ix, tx->iy, pixel); - ix++; + XPutPixel (tx->image, ix, iy, pixel); } - tx->iy++; - if (tx->iy == tx->image->height) + if ((top + 1 - tx->image_y) == tx->image->height) { XPutImage (tx->dpy, tx->win, tx->gc, tx->image, 0, 0, - x, (y + 1) - tx->iy, width, tx->image->height); + left, tx->image_y, tx->image->width, tx->image->height); XDestroyImage (tx->image); tx->image = 0; } @@ -86,10 +87,10 @@ { twin_x11_t *tx = arg; - pthread_mutex_lock (&tx->screen->screen_mutex); + twin_mutex_lock (&tx->screen->screen_mutex); for (;;) { - pthread_cond_wait (&tx->damage_cond, &tx->screen->screen_mutex); + twin_cond_wait (&tx->damage_cond, &tx->screen->screen_mutex); if (!tx->win) break; if (twin_screen_damaged (tx->screen)) @@ -98,15 +99,16 @@ XFlush (tx->dpy); } } - pthread_mutex_unlock (&tx->screen->screen_mutex); + twin_mutex_unlock (&tx->screen->screen_mutex); return 0; } static void * twin_x11_event_thread (void *arg) { - twin_x11_t *tx = arg; - XEvent ev; + twin_x11_t *tx = arg; + XEvent ev; + twin_event_t tev; for (;;) { @@ -117,6 +119,21 @@ break; case DestroyNotify: return 0; + case ButtonPress: + case ButtonRelease: + tev.u.pointer.screen_x = ev.xbutton.x; + tev.u.pointer.screen_y = ev.xbutton.y; + tev.kind = ((ev.type == ButtonPress) ? + EventButtonDown : EventButtonUp); + twin_screen_dispatch (tx->screen, &tev); + break; + case MotionNotify: + tev.u.pointer.screen_x = ev.xmotion.x; + tev.u.pointer.screen_y = ev.xmotion.y; + tev.kind = EventMotion; + tev.u.pointer.button = ev.xmotion.state; + twin_screen_dispatch (tx->screen, &tev); + break; } } } @@ -126,7 +143,7 @@ { twin_x11_t *tx = closure; - pthread_cond_broadcast (&tx->damage_cond); + twin_cond_broadcast (&tx->damage_cond); } twin_x11_t * @@ -187,11 +204,11 @@ XMapWindow (dpy, tx->win); - pthread_cond_init (&tx->damage_cond, NULL); + twin_cond_init (&tx->damage_cond); - pthread_create (&tx->damage_thread, NULL, twin_x11_damage_thread, tx); + twin_thread_create (&tx->damage_thread, twin_x11_damage_thread, tx); - pthread_create (&tx->event_thread, NULL, twin_x11_event_thread, tx); + twin_thread_create (&tx->event_thread, twin_x11_event_thread, tx); return tx; } @@ -201,7 +218,7 @@ { XDestroyWindow (tx->dpy, tx->win); tx->win = 0; - pthread_cond_broadcast (&tx->damage_cond); + twin_cond_broadcast (&tx->damage_cond); twin_screen_destroy (tx->screen); } Index: twin_x11.h =================================================================== RCS file: /local/src/CVS/twin/twin_x11.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_x11.h 2 Oct 2004 03:07:26 -0000 1.2 +++ twin_x11.h 6 Oct 2004 00:11:27 -0000 1.3 @@ -29,7 +29,6 @@ #include #include #include -#include typedef struct _twin_x11 { twin_screen_t *screen; @@ -38,11 +37,11 @@ GC gc; Visual *visual; int depth; - pthread_t damage_thread; - pthread_cond_t damage_cond; - pthread_t event_thread; + twin_thread_t damage_thread; + twin_cond_t damage_cond; + twin_thread_t event_thread; XImage *image; - int iy; + int image_y; } twin_x11_t; /* Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- xtwin.c 5 Oct 2004 18:42:53 -0000 1.17 +++ xtwin.c 6 Oct 2004 00:11:27 -0000 1.18 @@ -48,24 +48,28 @@ #define TWIN_CLOCK_BORDER_WIDTH D(0.01) static void -twin_clock_set_transform (twin_pixmap_t *clock, +twin_clock_set_transform (twin_window_t *clock, twin_path_t *path) { twin_fixed_t scale; - scale = D(1) / 2; - scale = twin_fixed_mul (scale, TWIN_FIXED_ONE - TWIN_CLOCK_BORDER_WIDTH * 3); + scale = (TWIN_FIXED_ONE - TWIN_CLOCK_BORDER_WIDTH * 3) / 2; + twin_path_translate (path, + twin_int_to_fixed (clock->client.left), + twin_int_to_fixed (clock->client.top)); twin_path_scale (path, - clock->width * scale, - clock->height * scale); + (clock->client.right - clock->client.left) * scale, + (clock->client.bottom - clock->client.top) * scale); - twin_path_translate (path, D(1) + TWIN_CLOCK_BORDER_WIDTH * 3, - D(1) + TWIN_CLOCK_BORDER_WIDTH * 3); + twin_path_translate (path, + TWIN_FIXED_ONE + TWIN_CLOCK_BORDER_WIDTH * 3, + TWIN_FIXED_ONE + TWIN_CLOCK_BORDER_WIDTH * 3); + twin_path_rotate (path, -TWIN_ANGLE_90); } static void -twin_clock_hand (twin_pixmap_t *clock, +twin_clock_hand (twin_window_t *clock, twin_angle_t angle, twin_fixed_t len, twin_fixed_t fill_width, @@ -92,9 +96,9 @@ twin_path_circle (pen, fill_width); twin_path_convolve (path, stroke, pen); - twin_paint_path (clock, fill_pixel, path); + twin_paint_path (clock->pixmap, fill_pixel, path); - twin_paint_stroke (clock, out_pixel, path, out_width); + twin_paint_stroke (clock->pixmap, out_pixel, path, out_width); twin_path_destroy (path); twin_path_destroy (pen); @@ -108,7 +112,7 @@ } static void -twin_clock_face (twin_pixmap_t *clock) +twin_clock_face (twin_window_t *clock) { twin_path_t *path = twin_path_create (); int m; @@ -118,9 +122,9 @@ twin_path_move (path, 0, 0); twin_path_circle (path, TWIN_FIXED_ONE); - twin_paint_path (clock, TWIN_CLOCK_BACKGROUND, path); + twin_paint_path (clock->pixmap, TWIN_CLOCK_BACKGROUND, path); - twin_paint_stroke (clock, TWIN_CLOCK_BORDER, path, TWIN_CLOCK_BORDER_WIDTH); + twin_paint_stroke (clock->pixmap, TWIN_CLOCK_BORDER, path, TWIN_CLOCK_BORDER_WIDTH); { twin_state_t state = twin_path_save (path); @@ -138,12 +142,12 @@ twin_path_move (path, -width / 2, metrics.ascent - height/2 + D(0.01)); twin_path_draw (path, width / 2, metrics.ascent - height/2 + D(0.01)); - twin_paint_stroke (clock, TWIN_CLOCK_WATER_UNDER, path, D(0.02)); + twin_paint_stroke (clock->pixmap, TWIN_CLOCK_WATER_UNDER, path, D(0.02)); twin_path_empty (path); twin_path_move (path, -width / 2 - metrics.left_side_bearing, metrics.ascent - height/2); twin_path_utf8 (path, label); - twin_paint_path (clock, TWIN_CLOCK_WATER, path); + twin_paint_path (clock->pixmap, TWIN_CLOCK_WATER, path); twin_path_restore (path, &state); } @@ -159,7 +163,7 @@ { twin_path_move (path, 0, -TWIN_FIXED_ONE); twin_path_draw (path, 0, -D(0.9)); - twin_paint_stroke (clock, TWIN_CLOCK_TIC, path, D(0.01)); + twin_paint_stroke (clock->pixmap, TWIN_CLOCK_TIC, path, D(0.01)); } else { @@ -174,7 +178,7 @@ left = -width / 2 - metrics.left_side_bearing; twin_path_move (path, left, -D(0.98) + metrics.ascent); twin_path_utf8 (path, hour); - twin_paint_path (clock, TWIN_CLOCK_NUMBERS, path); + twin_paint_path (clock->pixmap, TWIN_CLOCK_NUMBERS, path); } twin_path_restore (path, &state); } @@ -185,21 +189,27 @@ int nclock; static void -twin_clock (twin_screen_t *screen, int x, int y, int w, int h) +twin_clock (twin_screen_t *screen, const char *name, int x, int y, int w, int h) { - twin_pixmap_t *clock = twin_pixmap_create (TWIN_ARGB32, w, h); + twin_window_t *clock = twin_window_create (screen, TWIN_ARGB32, + WindowApplication, + x, y, w, h); struct timeval tv; struct tm t; twin_angle_t hour_angle, minute_angle, second_angle; - twin_pixmap_move (clock, x, y); - twin_pixmap_show (clock, screen, 0); + twin_window_set_name (clock, name); + twin_window_show (clock); for (;;) { - twin_pixmap_disable_update (clock); - twin_fill (clock, 0x00000000, TWIN_SOURCE, 0, 0, - clock->width, clock->height); + twin_pixmap_disable_update (clock->pixmap); + twin_window_draw (clock); + twin_fill (clock->pixmap, 0x00000000, TWIN_SOURCE, + clock->client.left, clock->client.top, + clock->client.right, clock->client.bottom); + + twin_clock_face (clock); gettimeofday (&tv, NULL); @@ -209,7 +219,6 @@ TWIN_ANGLE_360) / 6000; minute_angle = twin_clock_minute_angle (t.tm_min) + second_angle / 60; hour_angle = (t.tm_hour * TWIN_ANGLE_360 + minute_angle) / 12; - twin_clock_face (clock); twin_clock_hand (clock, hour_angle, D(0.4), D(0.07), D(0.01), TWIN_CLOCK_HOUR, TWIN_CLOCK_HOUR_OUT); twin_clock_hand (clock, minute_angle, D(0.8), D(0.05), D(0.01), @@ -217,7 +226,7 @@ twin_clock_hand (clock, second_angle, D(0.9), D(0.01), D(0.01), TWIN_CLOCK_SECOND, TWIN_CLOCK_SECOND_OUT); - twin_pixmap_enable_update (clock); + twin_pixmap_enable_update (clock->pixmap); gettimeofday (&tv, NULL); @@ -228,12 +237,13 @@ nclock--; } -typedef void (*twin_app_func_t) (twin_screen_t *screen, +typedef void (*twin_app_func_t) (twin_screen_t *screen, const char *name, int x, int y, int w, int h); typedef struct _twin_app_args { twin_app_func_t func; twin_screen_t *screen; + char *name; int x, y, w, h; } twin_app_args_t; @@ -242,7 +252,7 @@ { twin_app_args_t *a = closure; - (*a->func) (a->screen, a->x, a->y, a->w, a->h); + (*a->func) (a->screen, a->name, a->x, a->y, a->w, a->h); free (a); return 0; } @@ -250,25 +260,28 @@ static void twin_start_app (twin_app_func_t func, twin_screen_t *screen, + const char *name, int x, int y, int w, int h) { - twin_app_args_t *a = malloc (sizeof (twin_app_args_t)); + twin_app_args_t *a = malloc (sizeof (twin_app_args_t) + strlen (name) + 1); pthread_t thread; a->func = func; a->screen = screen; + a->name = (char *) (a + 1); a->x = x; a->y = y; a->w = w; a->h = h; + strcpy (a->name, name); pthread_create (&thread, NULL, twin_app_thread, a); } static void -twin_start_clock (twin_screen_t *screen, int x, int y, int w, int h) +twin_start_clock (twin_screen_t *screen, const char *name, int x, int y, int w, int h) { ++nclock; - twin_start_app (twin_clock, screen, x, y, w, h); + twin_start_app (twin_clock, screen, name, x, y, w, h); } int styles[] = { @@ -328,9 +341,6 @@ pen = twin_path_create (); twin_path_circle (pen, D (1)); - twin_fill (red, 0x00000000, TWIN_SOURCE, 0, 0, WIDTH, HEIGHT); - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, WIDTH, HEIGHT); - path = twin_path_create (); #if 0 twin_path_move (path, D(3), D(0)); @@ -494,8 +504,6 @@ twin_composite (red, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, WIDTH, HEIGHT); - twin_fill (blue, 0x00000000, TWIN_SOURCE, 0, 0, 100, 100); - #if 0 path = twin_path_create (); @@ -636,12 +644,14 @@ #endif if (!nclock) - twin_start_clock (x11->screen, 0, 0, WIDTH, HEIGHT); + twin_start_clock (x11->screen, "small clock", 10, 10, 200, 200); +#if 1 + twin_start_clock (x11->screen, "ul clock", 0, 0, 256, 256); +#endif #if 0 - twin_start_clock (x11->screen, 0, 0, 256, 256); - twin_start_clock (x11->screen, 256, 0, 256, 256); - twin_start_clock (x11->screen, 0, 256, 256, 256); - twin_start_clock (x11->screen, 256, 256, 256, 256); + twin_start_clock (x11->screen, "ur clock", 256, 0, 256, 256); + twin_start_clock (x11->screen, "ll clock", 0, 256, 256, 256); + twin_start_clock (x11->screen, "lr clock", 256, 256, 256, 256); #endif while (nclock) sleep (1); From commit at keithp.com Tue Oct 5 23:41:00 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 5 23:41:08 2004 Subject: [Commit] twin ChangeLog, 1.19, 1.20 Makefile.am, 1.8, 1.9 twin.h, 1.14, 1.15 twin_pattern.c, NONE, 1.1 twin_pixmap.c, 1.4, 1.5 twin_screen.c, 1.6, 1.7 twin_window.c, 1.1, 1.2 xtwin.c, 1.18, 1.19 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv31952 Modified Files: ChangeLog Makefile.am twin.h twin_pixmap.c twin_screen.c twin_window.c xtwin.c Added Files: twin_pattern.c Log Message: 2004-10-05 Keith Packard * Makefile.am: * twin.h: * twin_pattern.c: (twin_make_pattern): * twin_pixmap.c: (twin_pixmap_create_const): Add patterns. * twin_screen.c: (twin_screen_create), (twin_screen_update), (twin_screen_set_background), (twin_screen_get_background): Add screen backgrounds * twin_window.c: (twin_window_create), (twin_window_style_size), (twin_window_frame), (twin_window_draw): Eliminate spurious border bits * xtwin.c: (twin_clock), (twin_text_app), (twin_start_clock), (main): Add text display applet Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- ChangeLog 6 Oct 2004 00:11:27 -0000 1.19 +++ ChangeLog 6 Oct 2004 06:40:57 -0000 1.20 @@ -2,6 +2,26 @@ * Makefile.am: * twin.h: + * twin_pattern.c: (twin_make_pattern): + * twin_pixmap.c: (twin_pixmap_create_const): + Add patterns. + + * twin_screen.c: (twin_screen_create), (twin_screen_update), + (twin_screen_set_background), (twin_screen_get_background): + Add screen backgrounds + + * twin_window.c: (twin_window_create), (twin_window_style_size), + (twin_window_frame), (twin_window_draw): + Eliminate spurious border bits + + * xtwin.c: (twin_clock), (twin_text_app), (twin_start_clock), + (main): + Add text display applet + +2004-10-05 Keith Packard + + * Makefile.am: + * twin.h: * twin_draw.c: (twin_fill): * twin_path.c: (twin_composite_path): * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_show), Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Makefile.am 6 Oct 2004 00:11:27 -0000 1.8 +++ Makefile.am 6 Oct 2004 06:40:57 -0000 1.9 @@ -25,6 +25,7 @@ twin_geom.c \ twin_matrix.c \ twin_path.c \ + twin_pattern.c \ twin_pixmap.c \ twin_poly.c \ twin_primitive.c \ Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- twin.h 6 Oct 2004 00:11:27 -0000 1.14 +++ twin.h 6 Oct 2004 06:40:57 -0000 1.15 @@ -166,6 +166,10 @@ */ twin_coord_t width, height; /* + * Background pattern + */ + twin_pixmap_t *background; + /* * Damage */ twin_rect_t damage; @@ -289,6 +293,9 @@ typedef enum _twin_window_style { WindowPlain, WindowApplication, + WindowFullScreen, + WindowDialog, + WindowAlert, } twin_window_style_t; typedef void (*twin_draw_func_t) (twin_window_t *window); @@ -313,6 +320,17 @@ }; /* + * Icons + */ + +typedef enum _twin_icon { + TwinIconMenu, + TwinIconMinimize, + TwinIconMaximize, + TwinIconClose, +} twin_icon_t; + +/* * Widgets */ @@ -431,6 +449,13 @@ twin_path_convex_hull (twin_path_t *path); /* + * twin_icon.c + */ + +void +twin_icon_draw (twin_pixmap_t *pixmap, twin_icon_t icon, twin_matrix_t matrix); + +/* * twin_matrix.c */ @@ -556,6 +581,12 @@ twin_fixed_t pen_width); /* + * twin_pattern.c + */ +twin_pixmap_t * +twin_make_pattern (void); + +/* * twin_pixmap.c */ @@ -564,6 +595,13 @@ twin_coord_t width, twin_coord_t height); +twin_pixmap_t * +twin_pixmap_create_const (twin_format_t format, + twin_coord_t width, + twin_coord_t height, + twin_coord_t stride, + twin_pointer_t pixels); + void twin_pixmap_destroy (twin_pixmap_t *pixmap); @@ -657,6 +695,12 @@ twin_pixmap_t * twin_screen_get_active (twin_screen_t *screen); +void +twin_screen_set_background (twin_screen_t *screen, twin_pixmap_t *pixmap); + +twin_pixmap_t * +twin_screen_get_background (twin_screen_t *screen); + twin_bool_t twin_screen_dispatch (twin_screen_t *screen, twin_event_t *event); --- NEW FILE: twin_pattern.c --- /* GIMP RGBA C-Source image dump (cork.c) */ #include "twinint.h" static const struct { unsigned int width; unsigned int height; unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ char *comment; unsigned char pixel_data[8 * 8 * 4]; } cork_image = { 8, 8, 4, "cork", "{\265\357\377\214\275\357\377{\265\357\377{\265\357\377\214\275\357\377{\265" "\336\377{\265\357\377\234\316\377\377{\265\357\377Z\214\316\377{\265\357\377" "k\234\336\377Z\214\326\377Z\224\336\377{\265\357\377{\265\336\377\214\275" "\357\377Z\214\326\377{\265\357\377\214\275\357\377{\255\336\377{\265\357\377" "{\265\336\377{\255\357\377{\265\336\377{\265\357\377Z\214\316\377{\263\353" "\377{\265\357\377\234\316\377\377{\265\357\377{\265\336\377\214\275\357\377{" "\255\336\377{\265\357\377{\265\336\377{\265\357\377k\245\357\377\234\316\377" "\377{\265\357\377{\265\336\377\214\306\377\377{\255\336\377k\245\357\377{" "\265\336\377{\265\357\377\234\316\377\377Z\214\316\377Z\214\326\377{\265\357" "\377k\245\357\377{\265\336\377\214\275\357\377{\255\357\377\214\275\357\377a" "\223\321\377\207\270\354\377[\215\326\377{\265\357\377Z\214\316\377\214\306" "\377\377{\255\336\377{\255\357\377Z\224" "\336\377" }; twin_pixmap_t * twin_make_pattern (void) { twin_pointer_t pixels; pixels.v = (void *) cork_image.pixel_data; return twin_pixmap_create_const (TWIN_ARGB32, cork_image.width, cork_image.height, cork_image.width * cork_image.bytes_per_pixel, pixels); } Index: twin_pixmap.c =================================================================== RCS file: /local/src/CVS/twin/twin_pixmap.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_pixmap.c 6 Oct 2004 00:11:27 -0000 1.4 +++ twin_pixmap.c 6 Oct 2004 06:40:57 -0000 1.5 @@ -49,6 +49,29 @@ return pixmap; } +twin_pixmap_t * +twin_pixmap_create_const (twin_format_t format, + twin_coord_t width, + twin_coord_t height, + twin_coord_t stride, + twin_pointer_t pixels) +{ + twin_pixmap_t *pixmap = malloc (sizeof (twin_pixmap_t)); + if (!pixmap) + return 0; + pixmap->screen = 0; + pixmap->up = 0; + pixmap->down = 0; + pixmap->x = pixmap->y = 0; + pixmap->format = format; + pixmap->width = width; + pixmap->height = height; + pixmap->stride = stride; + pixmap->disable = 0; + pixmap->p = pixels; + return pixmap; +} + void twin_pixmap_destroy (twin_pixmap_t *pixmap) { Index: twin_screen.c =================================================================== RCS file: /local/src/CVS/twin/twin_screen.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- twin_screen.c 6 Oct 2004 00:11:27 -0000 1.6 +++ twin_screen.c 6 Oct 2004 06:40:57 -0000 1.7 @@ -43,6 +43,7 @@ screen->damaged = NULL; screen->damaged_closure = NULL; screen->disable = 0; + screen->background = 0; twin_mutex_init (&screen->screen_mutex); screen->put_begin = put_begin; screen->put_span = put_span; @@ -172,7 +173,30 @@ (*screen->put_begin) (left, top, right, bottom, screen->closure); for (y = top; y < bottom; y++) { - memset (span, 0xff, width * sizeof (twin_argb32_t)); + if (screen->background) + { + twin_pointer_t dst; + twin_source_u src; + twin_coord_t p_left; + twin_coord_t m_left; + twin_coord_t p_this; + twin_coord_t p_width = screen->background->width; + twin_coord_t p_y = y % screen->background->height; + + for (p_left = left; p_left < right; p_left += p_this) + { + dst.argb32 = span + (p_left - left); + m_left = p_left % p_width; + p_this = p_width - m_left; + if (p_left + p_this > right) + p_this = right - p_left; + src.p = twin_pixmap_pointer (screen->background, + m_left, p_y); + _twin_argb32_source_argb32 (dst, src, p_this); + } + } + else + memset (span, 0xff, width * sizeof (twin_argb32_t)); for (p = screen->bottom; p; p = p->up) { twin_pointer_t dst; @@ -230,6 +254,21 @@ return screen->active; } +void +twin_screen_set_background (twin_screen_t *screen, twin_pixmap_t *pixmap) +{ + if (screen->background) + twin_pixmap_destroy (screen->background); + screen->background = pixmap; + twin_screen_damage (screen, 0, 0, screen->width, screen->height); +} + +twin_pixmap_t * +twin_screen_get_background (twin_screen_t *screen) +{ + return screen->background; +} + twin_bool_t twin_screen_dispatch (twin_screen_t *screen, twin_event_t *event) Index: twin_window.c =================================================================== RCS file: /local/src/CVS/twin/twin_window.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_window.c 6 Oct 2004 00:11:27 -0000 1.1 +++ twin_window.c 6 Oct 2004 06:40:57 -0000 1.2 @@ -24,12 +24,12 @@ #include "twinint.h" -#define TWIN_ACTIVE_BG 0xff3b80ae +#define TWIN_ACTIVE_BG 0xd03b80ae #define TWIN_INACTIVE_BG 0xff808080 #define TWIN_FRAME_TEXT 0xffffffff -#define TWIN_ACTIVE_BORDER 0xff000000 -#define TWIN_BW 3 -#define TWIN_TITLE_HEIGHT 18 +#define TWIN_ACTIVE_BORDER 0xff606060 +#define TWIN_BW 0 +#define TWIN_TITLE_HEIGHT 22 twin_window_t * twin_window_create (twin_screen_t *screen, @@ -41,17 +41,35 @@ twin_coord_t height) { twin_window_t *window = malloc (sizeof (twin_window_t)); + twin_coord_t left, right, top, bottom; if (!window) return NULL; window->screen = screen; + window->style = style; + switch (window->style) { + case WindowApplication: + left = TWIN_BW; + top = TWIN_BW + TWIN_TITLE_HEIGHT + TWIN_BW; + right = TWIN_BW; + bottom = TWIN_BW; + break; + case WindowPlain: + default: + left = 0; + top = 0; + right = 0; + bottom = 0; + break; + } + width += left + right; + height += top + bottom; + window->client.left = left; + window->client.right = width - right; + window->client.top = top; + window->client.bottom = height - bottom; window->pixmap = twin_pixmap_create (format, width, height); window->pixmap->window = window; twin_pixmap_move (window->pixmap, x, y); - window->style = style; - window->client.left = TWIN_BW; - window->client.top = TWIN_BW + TWIN_TITLE_HEIGHT + TWIN_BW; - window->client.right = width - TWIN_BW; - window->client.bottom = height - TWIN_BW; window->damage.left = window->damage.right = 0; window->damage.top = window->damage.bottom = 0; window->client_data = 0; @@ -128,6 +146,7 @@ { switch (style) { case WindowPlain: + default: size->left = size->right = size->top = size->bottom = 0; break; case WindowApplication: @@ -152,54 +171,62 @@ static void twin_window_frame (twin_window_t *window) { - twin_coord_t bw = window->client.left; + twin_coord_t bw = 2; twin_path_t *path; twin_coord_t name_height; twin_text_metrics_t m; twin_pixmap_t *pixmap = window->pixmap; + twin_fixed_t bw_2 = twin_int_to_fixed (bw) / 2; + twin_fixed_t w_top = bw_2; + twin_fixed_t c_left = bw_2; + twin_fixed_t t_h = twin_int_to_fixed (window->client.top - bw); + twin_fixed_t t_arc_1 = t_h / 3; + twin_fixed_t c_right = twin_int_to_fixed (pixmap->width) - bw_2; + twin_fixed_t c_top = twin_int_to_fixed (window->client.top) - bw_2; + + twin_fill (pixmap, 0x00000000, TWIN_SOURCE, + 0, 0, pixmap->width, window->client.top); /* border */ - twin_fill (pixmap, TWIN_ACTIVE_BORDER, - TWIN_SOURCE, - 0, 0, pixmap->width, bw); - twin_fill (pixmap, TWIN_ACTIVE_BORDER, - TWIN_SOURCE, - 0, bw, bw, pixmap->height - bw); - twin_fill (pixmap, TWIN_ACTIVE_BORDER, - TWIN_SOURCE, - window->client.right, bw, pixmap->width, pixmap->height - bw); - twin_fill (pixmap, TWIN_ACTIVE_BORDER, - TWIN_SOURCE, - window->client.left, window->client.top - bw, - window->client.right, window->client.top); - twin_fill (pixmap, TWIN_ACTIVE_BORDER, - TWIN_SOURCE, - 0, window->client.bottom, - pixmap->width, pixmap->height); + path = twin_path_create (); + twin_path_move (path, c_left, c_top); + twin_path_draw (path, c_right, c_top); + twin_path_curve (path, + c_right, w_top + t_arc_1, + c_right - t_arc_1, w_top, + c_right - t_h, w_top); + twin_path_draw (path, c_left + t_h, w_top); + twin_path_curve (path, + c_left + t_arc_1, w_top, + c_left, w_top + t_arc_1, + c_left, c_top); + twin_path_close (path); + + twin_paint_path (pixmap, TWIN_ACTIVE_BG, path); + + twin_paint_stroke (pixmap, TWIN_ACTIVE_BORDER, path, bw_2 * 2); + + twin_path_empty (path); - /* name background */ - twin_fill (pixmap, TWIN_ACTIVE_BG, - TWIN_SOURCE, - bw, bw, pixmap->width - bw, window->client.top - bw); - /* name */ if (window->name) { - path = twin_path_create (); - name_height = window->client.top - bw * 4; + twin_point_t t; + name_height = window->client.top - bw * 2; if (name_height < 1) name_height = 1; - twin_path_translate (path, twin_int_to_fixed (bw*2), - twin_int_to_fixed (bw*2)); twin_path_set_font_size (path, twin_int_to_fixed (name_height)); twin_path_set_font_style (path, TWIN_TEXT_OBLIQUE); twin_text_metrics_utf8 (path, window->name, &m); - twin_path_move (path, 0, m.font_ascent); + t.x = ((c_right - c_left) - + (m.right_side_bearing - m.left_side_bearing)) / 2; + t.y = c_top - bw_2 * 4; + twin_path_move (path, t.x, t.y); twin_path_utf8 (path, window->name); twin_paint_path (pixmap, TWIN_FRAME_TEXT, path); - twin_path_destroy (path); } + twin_path_destroy (path); } void @@ -207,6 +234,7 @@ { switch (window->style) { case WindowPlain: + default: break; case WindowApplication: twin_window_frame (window); Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- xtwin.c 6 Oct 2004 00:11:27 -0000 1.18 +++ xtwin.c 6 Oct 2004 06:40:57 -0000 1.19 @@ -186,7 +186,7 @@ twin_path_destroy (path); } -int nclock; +int napp; static void twin_clock (twin_screen_t *screen, const char *name, int x, int y, int w, int h) @@ -234,7 +234,67 @@ usleep (INTERVAL - (tv.tv_usec % INTERVAL)); } - nclock--; + napp--; +} + +static void +twin_text_app (twin_screen_t *screen, const char *name, int x, int y, int w, int h) +{ + twin_window_t *text = twin_window_create (screen, TWIN_ARGB32, + WindowApplication, + x,y,w,h); + twin_fixed_t fx, fy; + static const char *lines[] = { + "Fourscore and seven years ago our fathers brought forth on", + "this continent a new nation, conceived in liberty and", + "dedicated to the proposition that all men are created equal.", + "", + "Now we are engaged in a great civil war, testing whether that", + "nation or any nation so conceived and so dedicated can long", + "endure. We are met on a great battlefield of that war. We", + "have come to dedicate a portion of it as a final resting", + "place for those who died here that the nation might live.", + "This we may, in all propriety do. But in a larger sense, we", + "cannot dedicate, we cannot consecrate, we cannot hallow this", + "ground. The brave men, living and dead who struggled here", + "have hallowed it far above our poor power to add or detract.", + "The world will little note nor long remember what we say here,", + "but it can never forget what they did here.", + "", + "It is rather for us the living, we here be dedicated to the", + "great task remaining before us--that from these honored", + "dead we take increased devotion to that cause for which they", + "here gave the last full measure of devotion--that we here", + "highly resolve that these dead shall not have died in vain, that", + "this nation shall have a new birth of freedom, and that", + "government of the people, by the people, for the people shall", + "not perish from the earth.", + 0 + }; + const char **l; + twin_path_t *path; + + twin_window_set_name(text, name); + path = twin_path_create (); + twin_path_translate (path, + twin_int_to_fixed (text->client.left), + twin_int_to_fixed (text->client.top)); +#define TEXT_SIZE 10 + twin_path_set_font_size (path, D(TEXT_SIZE)); + fx = D(3); + fy = D(10); + twin_fill (text->pixmap, 0xc0c0c0c0, TWIN_SOURCE, + text->client.left, text->client.top, + text->client.right, text->client.bottom); + for (l = lines; *l; l++) + { + twin_path_move (path, fx, fy); + twin_path_utf8 (path, *l); + twin_paint_path (text->pixmap, 0xff000000, path); + twin_path_empty (path); + fy += D(TEXT_SIZE); + } + twin_window_show (text); } typedef void (*twin_app_func_t) (twin_screen_t *screen, const char *name, @@ -280,7 +340,7 @@ static void twin_start_clock (twin_screen_t *screen, const char *name, int x, int y, int w, int h) { - ++nclock; + ++napp; twin_start_app (twin_clock, screen, name, x, y, w, h); } @@ -315,6 +375,7 @@ twin_fixed_t fx, fy; int g; + twin_screen_set_background (x11->screen, twin_make_pattern ()); (void) ev; (void) motion; (void) had_motion; @@ -640,20 +701,24 @@ twin_pixmap_move (blue, 100, 100); twin_pixmap_show (red, x11->screen, 0); twin_pixmap_show (blue, x11->screen, 0); - ++nclock; + ++napp; #endif - if (!nclock) - twin_start_clock (x11->screen, "small clock", 10, 10, 200, 200); + if (!napp) + twin_start_clock (x11->screen, "Clock", 10, 10, 200, 200); +#if 0 + twin_start_clock (x11->screen, "Large clock", 0, 100, 256, 256); +#endif #if 1 - twin_start_clock (x11->screen, "ul clock", 0, 0, 256, 256); + twin_start_app (twin_text_app, x11->screen, "Gettysburg Address", + 100, 100, 318, 250); #endif #if 0 twin_start_clock (x11->screen, "ur clock", 256, 0, 256, 256); twin_start_clock (x11->screen, "ll clock", 0, 256, 256, 256); twin_start_clock (x11->screen, "lr clock", 256, 256, 256, 256); #endif - while (nclock) + while (napp) sleep (1); return 0; } From commit at keithp.com Sat Oct 9 15:38:31 2004 From: commit at keithp.com (Keith Packard) Date: Sat Oct 9 15:38:35 2004 Subject: [Commit] nickle ChangeLog,1.87,1.88 value.c,1.47,1.48 Message-ID: Committed by: keithp Update of /local/src/CVS/nickle In directory home.keithp.com:/tmp/cvs-serv14417 Modified Files: ChangeLog value.c Log Message: 2004-10-09 Keith Packard * value.c: (ShiftL), (ShiftR): Optimize shifts of small ints by small ints Index: ChangeLog =================================================================== RCS file: /local/src/CVS/nickle/ChangeLog,v retrieving revision 1.87 retrieving revision 1.88 diff -u -d -r1.87 -r1.88 --- ChangeLog 22 Sep 2004 16:51:30 -0000 1.87 +++ ChangeLog 9 Oct 2004 22:38:28 -0000 1.88 @@ -1,3 +1,8 @@ +2004-10-09 Keith Packard + + * value.c: (ShiftL), (ShiftR): + Optimize shifts of small ints by small ints + 2004-09-22 Bart Massey * gram.y: Index: value.c =================================================================== RCS file: /local/src/CVS/nickle/value.c,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- value.c 28 May 2004 01:26:38 -0000 1.47 +++ value.c 9 Oct 2004 22:38:28 -0000 1.48 @@ -429,11 +429,25 @@ if (ValueIsInt(bv)) { Sign sign = Positive; - if (Negativep (av)) - sign = Negative; - av = Reduce (NewInteger (sign, - NaturalLsl (IntegerMag(IntegerRep.promote (av,0)), - ValueInt(bv)))); + int b = ValueInt(bv); + + if (ValueIsInt (av) && b < NICKLE_INT_BITS) + { + signed_digit rd = (signed_digit) ValueInt (av) << b; + + if (rd > (signed_digit) MAX_NICKLE_INT || rd < (signed_digit) MIN_NICKLE_INT) + av = NewSignedDigitInteger (rd); + else + av = NewInt ((int) rd); + } + else + { + if (Negativep (av)) + sign = Negative; + av = Reduce (NewInteger (sign, + NaturalLsl (IntegerMag(IntegerRep.promote (av,0)), + ValueInt(bv)))); + } } else { @@ -460,14 +474,23 @@ if (ValueIsInt(bv)) { Sign sign = Positive; - if (Negativep (av)) + int b = ValueInt(bv); + + if (ValueIsInt (av) && b < NICKLE_INT_BITS) { - av = Minus (av, Minus (ShiftL (One, bv), One)); - sign = Negative; + av = NewInt (ValueInt (av) >> b); + } + else + { + if (Negativep (av)) + { + av = Minus (av, Minus (ShiftL (One, bv), One)); + sign = Negative; + } + av = Reduce (NewInteger (sign, + NaturalRsl (IntegerMag(IntegerRep.promote (av,0)), + b))); } - av = Reduce (NewInteger (sign, - NaturalRsl (IntegerMag(IntegerRep.promote (av,0)), - ValueInt(bv)))); } else { From commit at keithp.com Sat Oct 9 15:49:10 2004 From: commit at keithp.com (Keith Packard) Date: Sat Oct 9 15:49:14 2004 Subject: [Commit] nickle ChangeLog,1.88,1.89 gram.y,1.141,1.142 Message-ID: Committed by: keithp Update of /local/src/CVS/nickle In directory home.keithp.com:/tmp/cvs-serv14710 Modified Files: ChangeLog gram.y Log Message: 2004-10-09 Keith Packard * gram.y: Permit multiple namespaces in import statements Index: ChangeLog =================================================================== RCS file: /local/src/CVS/nickle/ChangeLog,v retrieving revision 1.88 retrieving revision 1.89 diff -u -d -r1.88 -r1.89 --- ChangeLog 9 Oct 2004 22:38:28 -0000 1.88 +++ ChangeLog 9 Oct 2004 22:49:07 -0000 1.89 @@ -1,5 +1,10 @@ 2004-10-09 Keith Packard + * gram.y: + Permit multiple namespaces in import statements + +2004-10-09 Keith Packard + * value.c: (ShiftL), (ShiftR): Optimize shifts of small ints by small ints Index: gram.y =================================================================== RCS file: /local/src/CVS/nickle/gram.y,v retrieving revision 1.141 retrieving revision 1.142 diff -u -d -r1.141 -r1.142 --- gram.y 22 Sep 2004 16:51:31 -0000 1.141 +++ gram.y 9 Oct 2004 22:49:07 -0000 1.142 @@ -90,7 +90,7 @@ FuncDecl funcDecl; } -%type fullname +%type fullname fullnames %type opt_rawnames rawname rawnames rawnamespace %type rawatom %type block opt_func_body func_body func_right catches catch @@ -382,6 +382,15 @@ LexNamespace = 0; } ; +fullnames : fullname + { + $$ = $1; + } + | fullname COMMA fullnames + { + $$ = NewExprTree (COMMA, $1, $3); + } + ; namespace : namespace NAMESPACENAME COLONCOLON { ExprPtr e; @@ -604,27 +613,40 @@ CurrentNamespace = $2; $$ = NewExprTree (NAMESPACE, NewExprAtom ($4, 0, False), $7); } - | opt_publish IMPORT ignorenl fullname SEMI attendnl + | opt_publish IMPORT ignorenl fullnames SEMI attendnl { SymbolPtr symbol; - ExprPtr e; + ExprPtr p, e, n; - e = $4; - if ($4->base.tag == COLONCOLON) - e = e->tree.right; - symbol = e->atom.symbol; - if (!symbol) - { - ParseError ("non-existant namespace %A", e->atom.atom); - YYERROR; - } - else if (symbol->symbol.class != class_namespace) + p = $4; + for (p = $4; p; p = n) { - ParseError ("%A is not a namespace", e->atom.atom); - YYERROR; + if (p->base.tag == COMMA) + { + e = p->tree.left; + n = p->tree.right; + } + else + { + e = p; + n = 0; + } + if (e->base.tag == COLONCOLON) + e = e->tree.right; + symbol = e->atom.symbol; + if (!symbol) + { + ParseError ("non-existant namespace %A", e->atom.atom); + YYERROR; + } + else if (symbol->symbol.class != class_namespace) + { + ParseError ("%A is not a namespace", e->atom.atom); + YYERROR; + } + NamespaceImport (CurrentNamespace, + symbol->namespace.namespace, $1); } - NamespaceImport (CurrentNamespace, - symbol->namespace.namespace, $1); $$ = NewExprTree (IMPORT, $4, NewExprDecl (IMPORT, 0, class_undef, From commit at keithp.com Sun Oct 10 00:36:04 2004 From: commit at keithp.com (Keith Packard) Date: Sun Oct 10 00:36:08 2004 Subject: [Commit] jove ChangeLog,1.1,1.2 fp.c,1.6,1.7 insert.c,1.5,1.6 Message-ID: Committed by: keithp Update of /local/src/CVS/jove In directory home.keithp.com:/tmp/cvs-serv25729 Modified Files: ChangeLog fp.c insert.c Log Message: 2004-10-10 Keith Packard * fp.c: Assume UTF-8 output * insert.c: Rearrange compose sequences to include everything in vera sans mono Index: ChangeLog =================================================================== RCS file: /local/src/CVS/jove/ChangeLog,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ChangeLog 6 Dec 2003 20:15:29 -0000 1.1 +++ ChangeLog 10 Oct 2004 07:36:02 -0000 1.2 @@ -1,3 +1,10 @@ +2004-10-10 Keith Packard + + * fp.c: + Assume UTF-8 output + * insert.c: + Rearrange compose sequences to include everything in vera sans mono + 2003-12-06 Keith Packard * recover.c: Index: fp.c =================================================================== RCS file: /local/src/CVS/jove/fp.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- fp.c 6 Sep 2004 00:39:48 -0000 1.6 +++ fp.c 10 Oct 2004 07:36:02 -0000 1.7 @@ -31,7 +31,7 @@ termflush(EOF); } -int Utf8Out = 0; +int Utf8Out = 1; void termoutchar (ucs4 c) Index: insert.c =================================================================== RCS file: /local/src/CVS/jove/insert.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- insert.c 19 May 2003 20:13:46 -0000 1.5 +++ insert.c 10 Oct 2004 07:36:02 -0000 1.6 @@ -464,18 +464,28 @@ char ComposeSequences[V_STRING_LEN] = /* Latin 1 Supplement */ -"!:¡|c:¢#:£$:¤y:¥| :¦ss:§\" :¨cr:©_a:ª<<:«~:¬-:­rc:®__:¯" -". :°+-:±2:²3:³' :´,u:µpp:¶. :·, :¸1:¹m:º>>:»14:¼12:½34:¾?:¿" -"`A:À'A:Á^A:Â~A:Ã\"A:Ä.A:ÅAE:ÆC,:Ç`E:È'E:É^E:Ê\"E:Ë`I:Ì'I:Í^I:Î\"I:Ï" -"-D:Ð~N:Ñ`O:Ò'O:Ó^O:Ô~O:Õ\"O:Ö *:×/O:Ø`U:Ù'u:Ú^U:Û\"U:Ü'Y:ÝTH:ÞSS:ß" +"!:¡|c:¢#:£$:¤y:¥| :¦ss:§\" :¨cr:©_a:ª<<:«~ :¬- :­rc:®__:¯" +". :°+-:±1 :¹2 :²3 :³' :´,u:µpp:¶ .:·, :¸m:º>>:»14:¼12:½34:¾?:¿" +"`A:À'A:Á^A:Â~A:Ã\"A:Ä.A:ÅAE:Æ,C:Ç`E:È'E:É^E:Ê\"E:Ë`I:Ì'I:Í^I:Î\"I:Ï" +"-D:Ð~N:Ñ`O:Ò'O:Ó^O:Ô~O:Õ\"O:Ö* :×/O:Ø`U:Ù'U:Ú^U:Û\"U:Ü'Y:ÝTH:ÞSS:ß" "`a:à'a:á^a:â~a:ã\"a:ä.a:åae:æ,c:ç`e:è'e:é^e:ê\"e:ë`i:ì'i:í^i:î\"i:ï" -"et:ð~n:ñ`o:ò'o:ó^o:ô~o:õ\"o:ö /:÷/o:ø`u:ù'u:ú^u:û\"u:ü'y:ýth:þ\"y:ÿ" +"et:ð~n:ñ`o:ò'o:ó^o:ô~o:õ\"o:ö/ :÷/o:ø`u:ù'u:ú^u:û\"u:ü'y:ýth:þ\"y:ÿ" +/* extended latin */ +"'C:Ć'c:ćvC:Čvc:č-d:đvG:Ğvg:ğ.I:İ.i:ı/L:Ł/l:łOE:Œoe:œ,S:Ş,s:şvS:Švs:š\"Y:ŸvZ:Žvz:ž,f:ƒ" +/* Greek */ +"OM:Ωpi:π" /* Currency Symbols */ -"CE:₠/C:₡CR:₢=F:₣=L:₤/m:₥=N:₦PT:₧RS:₨=W:₩NS:₪=d:₫=C:€-K:₭=T:₮DP:₯" -/* General punctuation */ -"||:‖__:‗ `:‘ ':’ ,:‚``:“'':”,,:„ +:†++:‡ o:•" +"/C:₡CR:₢=F:₣=L:₤/m:₥=N:₦=P:₧=R:₨=W:₩=S:₪=d:₫=C:€=K:₭=T:₮=D:₯=f:₰" +/* General punctuation, preceded by a space in some cases */ +"||:‖__:‗ `:‘ ':’ ,:‚``:“'':”,,:„+ :†++:‡o :•..:…%:‰ <:‹ >:›" +/* Letterlike Sybols */ +"tm:™" /* Mathematical operators */ -" -:− ~:∼ |:∣/|:∤||:∥=~:≂~=:≃" +"de:∂DE:∆PI:∏SI:∑ /:∕sq:√oo:∞in:∫~~:≈/=:≠<=:≤>=:≥ -:− ~:∼ |:∣/|:∤||:∥=~:≂~=:≃" +/* Geometric Shapes */ +"<>:◊" +/* Alphabetic Presentation Forms */ +"fi:fifl:fl" ; char * From commit at keithp.com Sun Oct 17 16:34:39 2004 From: commit at keithp.com (Keith Packard) Date: Sun Oct 17 16:34:53 2004 Subject: [Commit] nickle ChangeLog, 1.89, 1.90 gram.y, 1.142, 1.143 lex.l, 1.77, 1.78 mem.h, 1.15, 1.16 Message-ID: Committed by: keithp Update of /local/src/CVS/nickle In directory home.keithp.com:/tmp/cvs-serv20675 Modified Files: ChangeLog gram.y lex.l mem.h Log Message: 2004-10-17 Keith Packard * gram.y: Add POW2 and POW3 operators * lex.l: Add several non-ascii character equivalents. Make \r be white space (and ignored) * mem.h: Remove spurious semi-colon from ALLOCATE definition. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/nickle/ChangeLog,v retrieving revision 1.89 retrieving revision 1.90 diff -u -d -r1.89 -r1.90 --- ChangeLog 9 Oct 2004 22:49:07 -0000 1.89 +++ ChangeLog 17 Oct 2004 23:34:34 -0000 1.90 @@ -1,3 +1,15 @@ +2004-10-17 Keith Packard + + * gram.y: + Add POW2 and POW3 operators + + * lex.l: + Add several non-ascii character equivalents. + Make \r be white space (and ignored) + + * mem.h: + Remove spurious semi-colon from ALLOCATE definition. + 2004-10-09 Keith Packard * gram.y: Index: gram.y =================================================================== RCS file: /local/src/CVS/nickle/gram.y,v retrieving revision 1.142 retrieving revision 1.143 diff -u -d -r1.142 -r1.143 --- gram.y 9 Oct 2004 22:49:07 -0000 1.142 +++ gram.y 17 Oct 2004 23:34:34 -0000 1.143 @@ -175,7 +175,7 @@ %left SHIFTL SHIFTR %left PLUS MINUS %left TIMES DIVIDE DIV MOD -%right POW STARSTAR +%right POW STARSTAR POW2 POW3 %left UNIONCAST %right UMINUS BANG FACT LNOT INC DEC STAR AMPER THREADID %left OS CS DOT ARROW STAROS CALL OP CP @@ -1325,6 +1325,22 @@ BuildName ("Math", "pow"), NewExprTree (POW, $1, $3)); } + | simpleexpr POW2 + { + $$ = NewExprTree (POW, + BuildName("Math", "pow"), + NewExprTree (POW, $1, + NewExprConst (TEN_NUM, + NewInt(2)))); + } + | simpleexpr POW3 + { + $$ = NewExprTree (POW, + BuildName("Math", "pow"), + NewExprTree (POW, $1, + NewExprConst (TEN_NUM, + NewInt(3)))); + } | simpleexpr SHIFTL simpleexpr { $$ = NewExprTree(SHIFTL, $1, $3); } | simpleexpr SHIFTR simpleexpr Index: lex.l =================================================================== RCS file: /local/src/CVS/nickle/lex.l,v retrieving revision 1.77 retrieving revision 1.78 diff -u -d -r1.77 -r1.78 --- lex.l 29 Jul 2004 00:23:32 -0000 1.77 +++ lex.l 17 Oct 2004 23:34:34 -0000 1.78 @@ -354,10 +354,14 @@ "," { yylval.ints = COMMA; return COMMA; } "$" { yylval.ints = DOLLAR; return DOLLAR; } "..." { yylval.ints = DOTDOTDOT; return DOTDOTDOT; } +"…" { yylval.ints = DOTDOTDOT; return DOTDOTDOT; } "." { yylval.ints = DOT; return DOT; } "->" { yylval.ints = ARROW; return ARROW; } +"→" { yylval.ints = ARROW; return ARROW; } "=>" { yylval.ints = DARROW; return DARROW; } +"⇒" { yylval.ints = DARROW; return DARROW; } "<>" { yylval.value = Void; return VOIDVAL; } +"◊" { yylval.value = Void; return VOIDVAL; } \n { if (lexInput->at_eof) { strcpy (yytext, "EOF"); yylval.ints = ENDFILE; return ENDFILE; } if (!ignorenl) { yylval.ints = NL; return NL; } @@ -372,12 +376,17 @@ "+=" { yylval.ints = ASSIGNPLUS; return ASSIGNPLUS; } "-=" { yylval.ints = ASSIGNMINUS; return ASSIGNMINUS; } "*=" { yylval.ints = ASSIGNTIMES; return ASSIGNTIMES; } +"×=" { yylval.ints = ASSIGNTIMES; return ASSIGNTIMES; } "/=" { yylval.ints = ASSIGNDIVIDE; return ASSIGNDIVIDE; } +"÷=" { yylval.ints = ASSIGNDIVIDE; return ASSIGNDIVIDE; } "//=" { yylval.ints = ASSIGNDIV; return ASSIGNDIV; } +"⫽=" { yylval.ints = ASSIGNDIV; return ASSIGNDIV; } "%=" { yylval.ints = ASSIGNMOD; return ASSIGNMOD; } -"**=" { yylval.ints = ASSIGNPOW; return ASSIGNPOW; } +"↑=" { yylval.ints = ASSIGNPOW; return ASSIGNPOW; } "<<=" { yylval.ints = ASSIGNSHIFTL; return ASSIGNSHIFTL; } +"⪡=" { yylval.ints = ASSIGNSHIFTL; return ASSIGNSHIFTL; } ">>=" { yylval.ints = ASSIGNSHIFTR; return ASSIGNSHIFTR; } +"⪢=" { yylval.ints = ASSIGNSHIFTR; return ASSIGNSHIFTR; } "^=" { yylval.ints = ASSIGNLXOR; return ASSIGNLXOR; } "&=" { yylval.ints = ASSIGNLAND; return ASSIGNLAND; } "|=" { yylval.ints = ASSIGNLOR; return ASSIGNLOR; } @@ -386,9 +395,13 @@ "+" { yylval.ints = PLUS; return PLUS; } "-" { yylval.ints = MINUS; return MINUS; } "*" { yylval.ints = TIMES; return TIMES; } +"×" { yylval.ints = TIMES; return TIMES; } "/" { yylval.ints = DIVIDE; return DIVIDE; } +"÷" { yylval.ints = DIVIDE; return DIVIDE; } "//" { yylval.ints = DIV; return DIV; } +"⫽" { yylval.ints = DIV; return DIV; } "**" { yylval.ints = STARSTAR; return STARSTAR; } +"↑" { yylval.ints = STARSTAR; return STARSTAR; } "%" { yylval.ints = MOD; return MOD; } "!" { yylval.ints = BANG; return BANG; } "#" { yylval.ints = POUND; return POUND; } @@ -396,23 +409,35 @@ "|" { yylval.ints = LOR; return LOR; } "^" { yylval.ints = LXOR; return LXOR; } "~" { yylval.ints = LNOT; return LNOT; } +"¬" { yylval.ints = LNOT; return LNOT; } "++" { yylval.ints = INC; return INC; } +"⧺" { yylval.ints = INC; return INC; } "--" { yylval.ints = DEC; return DEC; } "==" { yylval.ints = EQ; return EQ; } "!=" { yylval.ints = NE; return NE; } +"≠" { yylval.ints = NE; return NE; } "<" { yylval.ints = LT; return LT; } ">" { yylval.ints = GT; return GT; } "<=" { yylval.ints = LE; return LE; } +"≤" { yylval.ints = LE; return LE; } ">=" { yylval.ints = GE; return GE; } +"≥" { yylval.ints = GE; return GE; } "&&" { yylval.ints = AND; return AND; } +"∧" { yylval.ints = AND; return AND; } "||" { yylval.ints = OR; return OR; } +"∨" { yylval.ints = OR; return OR; } "<<" { yylval.ints = SHIFTL; return SHIFTL; } +"⪡" { yylval.ints = SHIFTL; return SHIFTL; } ">>" { yylval.ints = SHIFTR; return SHIFTR; } +"⪢" { yylval.ints = SHIFTR; return SHIFTR; } "?" { yylval.ints = QUEST; return QUEST; } "::" { yylval.ints = COLONCOLON; return COLONCOLON; } ":" { yylval.ints = COLON; return COLON; } +"²" { yylval.ints = POW2; return POW2; } +"³" { yylval.ints = POW3; return POW3; } " " ; "\t" ; +"\r" ; \'([^\n\']|\\\')*\' { ENTER (); char *s; Index: mem.h =================================================================== RCS file: /local/src/CVS/nickle/mem.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- mem.h 10 Aug 2004 17:45:40 -0000 1.15 +++ mem.h 17 Oct 2004 23:34:34 -0000 1.16 @@ -122,7 +122,7 @@ #define REFERENCE(o) STACK_PUSH(MemStack, (o)) #define ENTER() StackPointer __stackPointer = STACK_TOP(MemStack) -#define ALLOCATE(type,size) MemAllocateRef(type,size); +#define ALLOCATE(type,size) MemAllocateRef(type,size) #define EXIT() STACK_RESET(MemStack, __stackPointer) #define RETURN(r) return (STACK_RETURN (MemStack, __stackPointer, (r))) #define NOREFRETURN(r) return (EXIT(), (r)) From commit at keithp.com Sun Oct 17 21:31:19 2004 From: commit at keithp.com (Keith Packard) Date: Sun Oct 17 21:31:23 2004 Subject: [Commit] jove ChangeLog, 1.2, 1.3 jove.c, 1.6, 1.7 macros.c, 1.3, 1.4 re.c, 1.4, 1.5 screen.c, 1.5, 1.6 Message-ID: Committed by: keithp Update of /local/src/CVS/jove In directory home.keithp.com:/tmp/cvs-serv29059 Modified Files: ChangeLog jove.c macros.c re.c screen.c Log Message: 2004-10-17 Keith Packard * jove.c: (dispatch): * macros.c: (PrefChar), (IsInsertChar): maps are only 0x80 long, bounds check correctly * re.c: Let ANYC match any UTF-8 sequence * screen.c: (set_scroll): Force cursor to HOME when setting scrolling region to work around buggy emulators. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/jove/ChangeLog,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ChangeLog 10 Oct 2004 07:36:02 -0000 1.2 +++ ChangeLog 18 Oct 2004 04:31:16 -0000 1.3 @@ -1,3 +1,16 @@ +2004-10-17 Keith Packard + + * jove.c: (dispatch): + * macros.c: (PrefChar), (IsInsertChar): + maps are only 0x80 long, bounds check correctly + + * re.c: + Let ANYC match any UTF-8 sequence + + * screen.c: (set_scroll): + Force cursor to HOME when setting scrolling region to work around + buggy emulators. + 2004-10-10 Keith Packard * fp.c: Index: jove.c =================================================================== RCS file: /local/src/CVS/jove/jove.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- jove.c 10 Jun 2003 17:32:07 -0000 1.6 +++ jove.c 18 Oct 2004 04:31:16 -0000 1.7 @@ -708,8 +708,8 @@ c = 033; } this_cmd = 0; - if (c < 0x100) - cp = mainmap[c & 0177]; + if (c < 0x80) + cp = mainmap[c]; else cp = mainmap['a']; Index: macros.c =================================================================== RCS file: /local/src/CVS/jove/macros.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- macros.c 15 May 2003 06:00:14 -0000 1.3 +++ macros.c 18 Oct 2004 04:31:16 -0000 1.4 @@ -321,12 +321,12 @@ static PrefChar(c) { - return c <= 0x100 && IsPrefix(mainmap[c]) != 0; + return c < 0x80 && IsPrefix(mainmap[c]) != 0; } IsInsertChar(c) { - return (int) (c <= 0x100 && (mainmap[c]->Type & FUNCINS) == FUNCINS); + return (int) (c > 0x80 || (mainmap[c]->Type & FUNCINS) == FUNCINS); } Forget() Index: re.c =================================================================== RCS file: /local/src/CVS/jove/re.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- re.c 15 May 2003 06:00:14 -0000 1.4 +++ re.c 18 Oct 2004 04:31:16 -0000 1.5 @@ -374,9 +374,15 @@ return 0; case ANYC: - if (*linep++ != 0) - continue; - return 0; + n = *linep++; + if (!n) + return 0; + if ((n & 0xc0) == 0xc0) + { + while (*linep++ & 0x80); + --linep; + } + continue; case AT_BOW: if (ismword(*linep) && (linep == REbolp || !ismword(linep[-1]))) Index: screen.c =================================================================== RCS file: /local/src/CVS/jove/screen.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- screen.c 12 Aug 2004 04:29:56 -0000 1.5 +++ screen.c 18 Oct 2004 04:31:16 -0000 1.6 @@ -487,6 +487,13 @@ } else { putpad (tgoto (CS, bottom, top), 1); } + /* + * Correct VT100 behaviour is to move to the top of the screen + * when the scrolling region is set, but many emulators leave + * the cursor position alone. Force the cursor to a known + * position to work around this bug + */ + putpad (HO, 1); } } From commit at keithp.com Tue Oct 19 22:26:43 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 19 22:26:49 2004 Subject: [Commit] jove/doc .joverc,1.2,1.3 Message-ID: Committed by: keithp Update of /local/src/CVS/jove/doc In directory home.keithp.com:/tmp/cvs-serv32161/doc Modified Files: .joverc Log Message: 2004-10-19 Keith Packard * abbrev.c: * ask.c: * buf.c: (strchr_ucs4), (strrchr_ucs4): * c.c: (FindMatch): * doc/.joverc: * extend.c: (addgetc): * funcdefs.c: * insert.c: (DescribeCompose): * io.c: (WriteFile): * iproc-ptys.c: * iproc.c: (ProcCDToRealBufferDir): * jove.h: * man.c: (scanapropos): * paragraph.c: (do_space): * re.c: (do_comp): * re1.c: * screen.c: (Placur): * tune.h: * util.c: Replace usage of index/rindex with strchr_ucs4/strrchr_ucs4 which handle UTF-8 encoded strings and single UCS4 encoded chars. Don't use tabs for positioning when in utf-8 output mode because double-width characters make this hard. Index: .joverc =================================================================== RCS file: /local/src/CVS/jove/doc/.joverc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- .joverc 15 May 2003 06:00:14 -0000 1.2 +++ .joverc 20 Oct 2004 05:26:40 -0000 1.3 @@ -42,6 +42,7 @@ bind-to-key x-track-mouse-long ^[[T set mode-line %a-%(%a %)%[%m"%f" (%M%P) %b %]%s%(%C%s%d %)%e set meta-key on +set use-i/d-char off endif erase-tag-file-list push-tag-file /usr/lib/tags From commit at keithp.com Tue Oct 19 22:26:43 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 19 22:26:54 2004 Subject: [Commit] jove ChangeLog, 1.3, 1.4 abbrev.c, 1.3, 1.4 ask.c, 1.5, 1.6 buf.c, 1.4, 1.5 c.c, 1.6, 1.7 extend.c, 1.3, 1.4 funcdefs.c, 1.2, 1.3 insert.c, 1.6, 1.7 io.c, 1.4, 1.5 iproc-ptys.c, 1.5, 1.6 iproc.c, 1.5, 1.6 jove.h, 1.9, 1.10 man.c, 1.4, 1.5 paragraph.c, 1.4, 1.5 re.c, 1.5, 1.6 re1.c, 1.4, 1.5 screen.c, 1.6, 1.7 tune.h, 1.4, 1.5 util.c, 1.4, 1.5 Message-ID: Committed by: keithp Update of /local/src/CVS/jove In directory home.keithp.com:/tmp/cvs-serv32161 Modified Files: ChangeLog abbrev.c ask.c buf.c c.c extend.c funcdefs.c insert.c io.c iproc-ptys.c iproc.c jove.h man.c paragraph.c re.c re1.c screen.c tune.h util.c Log Message: 2004-10-19 Keith Packard * abbrev.c: * ask.c: * buf.c: (strchr_ucs4), (strrchr_ucs4): * c.c: (FindMatch): * doc/.joverc: * extend.c: (addgetc): * funcdefs.c: * insert.c: (DescribeCompose): * io.c: (WriteFile): * iproc-ptys.c: * iproc.c: (ProcCDToRealBufferDir): * jove.h: * man.c: (scanapropos): * paragraph.c: (do_space): * re.c: (do_comp): * re1.c: * screen.c: (Placur): * tune.h: * util.c: Replace usage of index/rindex with strchr_ucs4/strrchr_ucs4 which handle UTF-8 encoded strings and single UCS4 encoded chars. Don't use tabs for positioning when in utf-8 output mode because double-width characters make this hard. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/jove/ChangeLog,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ChangeLog 18 Oct 2004 04:31:16 -0000 1.3 +++ ChangeLog 20 Oct 2004 05:26:40 -0000 1.4 @@ -1,3 +1,29 @@ +2004-10-19 Keith Packard + + * abbrev.c: + * ask.c: + * buf.c: (strchr_ucs4), (strrchr_ucs4): + * c.c: (FindMatch): + * doc/.joverc: + * extend.c: (addgetc): + * funcdefs.c: + * insert.c: (DescribeCompose): + * io.c: (WriteFile): + * iproc-ptys.c: + * iproc.c: (ProcCDToRealBufferDir): + * jove.h: + * man.c: (scanapropos): + * paragraph.c: (do_space): + * re.c: (do_comp): + * re1.c: + * screen.c: (Placur): + * tune.h: + * util.c: + Replace usage of index/rindex with strchr_ucs4/strrchr_ucs4 + which handle UTF-8 encoded strings and single UCS4 encoded chars. + Don't use tabs for positioning when in utf-8 output mode because + double-width characters make this hard. + 2004-10-17 Keith Packard * jove.c: (dispatch): Index: abbrev.c =================================================================== RCS file: /local/src/CVS/jove/abbrev.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- abbrev.c 15 May 2003 00:01:06 -0000 1.3 +++ abbrev.c 20 Oct 2004 05:26:40 -0000 1.4 @@ -199,7 +199,7 @@ } if (mode == -1) fmterr: complain("Abbrev. format error, line %d.", file, lnum); - phrase_p = index(genbuf, ':'); + phrase_p = strchr_ucs4(genbuf, ':'); if (phrase_p == 0) goto fmterr; *phrase_p++ = '\0'; /* Null terminate the abbrev. */ Index: ask.c =================================================================== RCS file: /local/src/CVS/jove/ask.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ask.c 10 Jun 2003 17:32:07 -0000 1.5 +++ ask.c 20 Oct 2004 05:26:40 -0000 1.6 @@ -158,7 +158,7 @@ cont: s_mess("%s%s", prompt, linebuf); Asking = curchar + prompt_len; c = terminch(); - if ((c == EOF) || index(delim, c)) { + if ((c == EOF) || strchr_ucs4(delim, c)) { if (DoEVexpand) EVexpand(); if (d_proc == 0 || (*d_proc)(c, linebuf) == 0) @@ -310,7 +310,7 @@ stop = 0; do { - if (ip = index(bads, ' ')) + if (ip = strchr_ucs4 (bads, ' ')) *ip = 0; else { ip = bads + strlen(bads); @@ -417,7 +417,7 @@ if (c == CR || c == LF) return 0; /* tells ask to return now */ - if ((fc_filebase = rindex(buf, '/')) != 0) { + if ((fc_filebase = strrchr_ucs4 (buf, '/')) != 0) { char tmp[FILESIZE]; null_ncpy(tmp, buf, (++fc_filebase - buf)); Index: buf.c =================================================================== RCS file: /local/src/CVS/jove/buf.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- buf.c 19 May 2003 20:13:46 -0000 1.4 +++ buf.c 20 Oct 2004 05:26:40 -0000 1.5 @@ -120,7 +120,7 @@ char *s; for (s = globchars; *s; s++) - if (index (pattern, *s)) + if (strchr_ucs4 (pattern, *s)) return 1; return 0; } @@ -201,7 +201,7 @@ int nentries, i; int first; - if ((filebase = rindex(pattern, '/')) != 0) { + if ((filebase = strrchr_ucs4(pattern, '/')) != 0) { null_ncpy(dir, pattern, ++filebase - pattern); if (dir[0] == '\0') strcpy(dir, "/"); @@ -816,6 +816,45 @@ return result; } +char * +strchr_ucs4 (const char *buf, ucs4 c) +{ + char utf8[10]; + char *f; + int l; + + if (c < 0x100) return strchr (buf, (char) c); + unparse_ucs4 (c, utf8); + l = strlen (utf8); + while (f = strchr (buf, utf8[0])) + { + if (!strncmp (f, utf8, l)) + return f; + buf = f + l; + } + return 0; +} + +char * +strrchr_ucs4 (const char *buf, ucs4 c) +{ + char utf8[10]; + char *f; + char *last = 0; + int l; + + if (c < 0x100) return strrchr (buf, (char) c); + unparse_ucs4 (c, utf8); + l = strlen (utf8); + while (f = strchr (buf, utf8[0])) + { + if (!strncmp (f, utf8, l)) + last = f; + buf = f + l; + } + return last; +} + char *buf_next (char *buf) { if ((*buf++ & 0xc0) == 0xc0) Index: c.c =================================================================== RCS file: /local/src/CVS/jove/c.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- c.c 12 Aug 2004 04:29:56 -0000 1.6 +++ c.c 20 Oct 2004 05:26:40 -0000 1.7 @@ -104,7 +104,7 @@ REcompile(re_str, 1, re_buf, re_alts); if (!p_type) p_match = '\0'; - else if (cp = index(p_types, p_type)) + else if (cp = strchr_ucs4 (p_types, p_type)) p_match = cp[dir]; else complain("[Cannot match %c's]", p_type); @@ -349,7 +349,7 @@ register Bufpos *bp; register ucs4 c = cur_char (); - if ((index(p_types, c) == 0) || + if ((strchr_ucs4 (p_types, c) == 0) || (backslashed(linebuf, curchar))) complain((char *) 0); if (dir == FORWARD) Index: extend.c =================================================================== RCS file: /local/src/CVS/jove/extend.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- extend.c 10 Jun 2003 17:32:07 -0000 1.3 +++ extend.c 20 Oct 2004 05:26:40 -0000 1.4 @@ -166,7 +166,7 @@ } else if (c == '^') { if ((c = terminch()) == '?') c = RUBOUT; - else if (isalpha(c) || index("@[\\]^_", c)) + else if (isalpha(c) || strchr_ucs4("@[\\]^_", c)) c = c - '@'; else complain("[Unknown control character]"); Index: funcdefs.c =================================================================== RCS file: /local/src/CVS/jove/funcdefs.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- funcdefs.c 15 May 2003 00:01:06 -0000 1.2 +++ funcdefs.c 20 Oct 2004 05:26:40 -0000 1.3 @@ -666,7 +666,7 @@ } /* gather the cmd name */ - while (((c = terminch()) != EOF) && !index(" \t\r\n", c)) { + while (((c = terminch()) != EOF) && !strchr_ucs4(" \t\r\n", c)) { *cp++ = c; } if (c == EOF) Index: insert.c =================================================================== RCS file: /local/src/CVS/jove/insert.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- insert.c 10 Oct 2004 07:36:02 -0000 1.6 +++ insert.c 20 Oct 2004 05:26:40 -0000 1.7 @@ -531,7 +531,7 @@ compose; compose = NextComposeSequence (compose)) { - equal = index (compose, ':'); + equal = strchr_ucs4 (compose, ':'); if (!equal) break; ncompose++; @@ -551,7 +551,7 @@ compose = getCompose (which); if (!compose) break; - equal = index (compose, ':'); + equal = strchr_ucs4 (compose, ':'); if (!equal) break; semi = buf_next (equal+1); Index: io.c =================================================================== RCS file: /local/src/CVS/jove/io.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- io.c 15 May 2003 00:01:06 -0000 1.4 +++ io.c 20 Oct 2004 05:26:40 -0000 1.5 @@ -425,7 +425,7 @@ /* Machine name */ if (*file == '/' && file[1] == '/' && file[2] != '/') { - dp = index (file+2, '/'); + dp = strchr_ucs4 (file+2, '/'); if (!dp) dp = file + strlen(file); strncpy(into, file, dp-file); @@ -442,7 +442,7 @@ dp = into + strlen(into); aftermachine = into; if (into[0] == '/' && into[1] == '/' && into[2] != '/') { - aftermachine = index (into+2, '/'); + aftermachine = strchr_ucs4 (into+2, '/'); if (!aftermachine) aftermachine = into + strlen (into); } @@ -451,7 +451,7 @@ do { if (*file == 0) break; - if (sp = index(file, '/')) + if (sp = strchr_ucs4(file, '/')) *sp = 0; if (strcmp(file, ".") == 0) ; /* So it will get to the end of the loop */ @@ -503,7 +503,7 @@ strcpy(localbuf, HomeDir); name++; } else { - char *uendp = index(name, '/'), + char *uendp = strchr_ucs4(name, '/'), unamebuf[30]; if (uendp == 0) @@ -600,7 +600,7 @@ register int c; while (c = *cp++) - if ((0 <= c && c < ' ') || c == '\177' || index(badchars, c)) + if ((0 <= c && c < ' ') || c == '\177' || strchr_ucs4(badchars, c)) complain("'%p': bad character in filename.", c); } @@ -1324,7 +1324,7 @@ strcpy(tmp1, fname); - if ((s = rindex(tmp1, '/')) == NULL) + if ((s = strrchr_ucs4(tmp1, '/')) == NULL) sprintf(tmp2, "#%s", fname); else { *s++ = '\0'; Index: iproc-ptys.c =================================================================== RCS file: /local/src/CVS/jove/iproc-ptys.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- iproc-ptys.c 10 Jun 2003 17:32:07 -0000 1.5 +++ iproc-ptys.c 20 Oct 2004 05:26:40 -0000 1.6 @@ -287,7 +287,7 @@ int slot; int got; - line = rindex (p->p_tty, '/'); + line = strrchr_ucs4 (p->p_tty, '/'); if (line) line++; else Index: iproc.c =================================================================== RCS file: /local/src/CVS/jove/iproc.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- iproc.c 6 Sep 2004 00:39:48 -0000 1.5 +++ iproc.c 20 Oct 2004 05:26:40 -0000 1.6 @@ -799,7 +799,7 @@ if (!b->b_fname) complain("[Buffer has no file name]"); real_file (b->b_fname, realname); - slash = rindex (realname, '/'); + slash = strrchr_ucs4 (realname, '/'); if (slash) { if (slash == realname) Index: jove.h =================================================================== RCS file: /local/src/CVS/jove/jove.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- jove.h 6 Sep 2004 00:39:48 -0000 1.9 +++ jove.h 20 Oct 2004 05:26:40 -0000 1.10 @@ -141,6 +141,8 @@ char *unparse_ucs4 (ucs4 c, char *buf); char *buf_next (char *buf); char *buf_prev (char *buf, char *first); +char *strchr_ucs4 (const char *buf, ucs4 c); +char *strrchr_ucs4 (const char *buf, ucs4 c); #define char_at(i) parse_ucs4(linebuf + (i)) #define cur_char() char_at(curchar) #define prev_char() parse_ucs4(buf_prev (linebuf + curchar, linebuf)) Index: man.c =================================================================== RCS file: /local/src/CVS/jove/man.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- man.c 6 Sep 2004 00:39:48 -0000 1.4 +++ man.c 20 Oct 2004 05:26:40 -0000 1.5 @@ -144,13 +144,13 @@ char name_part[256]; char section_part[256]; - op = rindex (name, '('); + op = strrchr_ucs4 (name, '('); if (!op) op = name + strlen (name); strncpy (name_part, name, op - name); name_part[op-name] = '\0'; op++; - cp = rindex (op, ')'); + cp = strrchr_ucs4 (op, ')'); if (!cp) cp = op + strlen (op); strncpy (section_part, op, cp - op); @@ -233,7 +233,7 @@ char page[128]; char *op; - op = rindex (name, '('); + op = strrchr_ucs4 (name, '('); if (op) { strncpy (page, name, op - name); @@ -282,7 +282,7 @@ char page[128]; char *op; - op = rindex (name, '('); + op = strrchr_ucs4 (name, '('); if (op) { strncpy (page, name, op - name); @@ -392,7 +392,7 @@ return 0; len = strlen (curNamePtr); if (strncmp (entry, curNamePtr, len) == 0) { - if (entry[len] == '.' || index (curNamePtr, '(')) + if (entry[len] == '.' || strchr_ucs4 (curNamePtr, '(')) return 1; } return 0; @@ -436,7 +436,7 @@ char *name; char *buf; { - name = rindex (name, '('); + name = strrchr_ucs4 (name, '('); if (name && name[1] != '\0') { buf[0] = name[1]; buf[1] = '\0'; @@ -487,11 +487,11 @@ char *nname; /* Strip any trailing .gz extension */ - dot = rindex (names[i], '.'); + dot = strrchr_ucs4 (names[i], '.'); if (dot && !strcmp (dot, ".gz")) *dot = '\0'; /* Replace .section with (section) */ - dot = rindex (names[i], '.'); + dot = strrchr_ucs4 (names[i], '.'); if (dot) { nname = malloc (strlen (names[i]) + 3); @@ -542,12 +542,12 @@ if (*entry == '.') return 0; /* check for a section number */ - curOp = rindex (curNamePtr, '('); - entryDot = rindex (entry, '.'); + curOp = strrchr_ucs4 (curNamePtr, '('); + entryDot = strrchr_ucs4 (entry, '.'); if (entryDot && !strcmp (entryDot, ".gz")) { *entryDot = '\0'; - entryDot = rindex (entry, '.'); + entryDot = strrchr_ucs4 (entry, '.'); } if (curOp) { @@ -557,7 +557,7 @@ return 0; /* extract section part from current name */ curOp++; - curCp = rindex (curOp, ')'); + curCp = strrchr_ucs4 (curOp, ')'); if (!curCp) curCp = curOp + strlen (curOp); seclen = curCp - curOp; @@ -739,12 +739,12 @@ len = strlen (entry); while (jove_gets(fp, line, sizeof line) != EOF) { hit = line; - if (!commands || !(paren = index (line, '('))) + if (!commands || !(paren = strchr_ucs4 (line, '('))) paren = line + sizeof line; do { if (strncmp (entry, hit, len) == 0) break; - if (hit = index (hit, ' ')) { + if (hit = strchr_ucs4 (hit, ' ')) { ++hit; if (hit >= paren) hit = 0; Index: paragraph.c =================================================================== RCS file: /local/src/CVS/jove/paragraph.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- paragraph.c 15 May 2003 00:01:06 -0000 1.4 +++ paragraph.c 20 Oct 2004 05:26:40 -0000 1.5 @@ -408,12 +408,12 @@ nspace = 1; if (diff >= 2) { - while (index("\")]", parse_ucs4 (pp))) { + while (strchr_ucs4("\")]", parse_ucs4 (pp))) { if (pp == linebuf) break; pp = buf_prev (pp, linebuf); } - if (index("?!.:", parse_ucs4 (pp))) + if (strchr_ucs4("?!.:", parse_ucs4 (pp))) nspace = 2; } } else Index: re.c =================================================================== RCS file: /local/src/CVS/jove/re.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- re.c 18 Oct 2004 04:31:16 -0000 1.5 +++ re.c 20 Oct 2004 05:26:40 -0000 1.6 @@ -114,7 +114,7 @@ if (c != '*') last_p = comp_p; - if (kind == NORM && index(".[*", c) != 0) + if (kind == NORM && strchr_ucs4 (".[*", c) != 0) goto defchar; switch (c) { case '\\': Index: re1.c =================================================================== RCS file: /local/src/CVS/jove/re1.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- re1.c 15 May 2003 06:00:14 -0000 1.4 +++ re1.c 20 Oct 2004 05:26:40 -0000 1.5 @@ -348,7 +348,7 @@ goto gottag; complain("[No such tag \"%s\"]", tag); gottag: ; - if (filebuf[0] != '/' && (ssp = rindex(tagfiles[tagI].tagfile, '/'))) + if (filebuf[0] != '/' && (ssp = strrchr_ucs4(tagfiles[tagI].tagfile, '/'))) { strncpy (wholefilebuf, tagfiles[tagI].tagfile, @@ -502,10 +502,10 @@ char *tagdir; int tagdirlen = 0; - dir = rindex (tag, '/'); + dir = strrchr_ucs4 (tag, '/'); if (dir) { - tagdir = rindex (tagfile->tagfile, '/'); + tagdir = strrchr_ucs4 (tagfile->tagfile, '/'); if (!tagdir) { tagdir = "./" + 1; @@ -590,7 +590,7 @@ break; if (searchbuf && whichway == 0 && !isspace(linePtr[taglen])) break; - nextLine = index (linePtr, '\n'); + nextLine = strchr_ucs4 (linePtr, '\n'); if (!nextLine) break; if (whichway < 0) Index: screen.c =================================================================== RCS file: /local/src/CVS/jove/screen.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- screen.c 18 Oct 2004 04:31:16 -0000 1.6 +++ screen.c 20 Oct 2004 05:26:40 -0000 1.7 @@ -619,7 +619,7 @@ ntabs, tabstp = phystab; - if (TABS && (tabstp > 0)) { + if ((TABS && !Utf8Out) && (tabstp > 0)) { tabgoal = destcol + (tabstp / 2); tabgoal -= (tabgoal % tabstp); @@ -746,9 +746,9 @@ } else { WarpHor[FORWARD].cm_numchars = dcol >= 0 ? dcol + xtracost : 1000; WarpHor[BACKWARD].cm_numchars = dcol < 0 ? -(dcol + xtracost) : 1000; - WarpHor[FORTAB].cm_numchars = dcol >= 0 && TABS ? + WarpHor[FORTAB].cm_numchars = dcol >= 0 && (TABS && !Utf8Out) ? ForNum(CapCol, col) + xtracost : 1000; - WarpHor[RETFORWARD].cm_numchars = (xtracost + 1 + (TABS ? ForNum(0, col) : col)); + WarpHor[RETFORWARD].cm_numchars = (xtracost + 1 + ((TABS && Utf8Out) ? ForNum(0, col) : col)); /* Which is the shortest of the bunch */ @@ -821,7 +821,7 @@ if (from >= to) return from - to; - if (TABS && (tabstp > 0)) { + if ((TABS && Utf8Out) && (tabstp > 0)) { tabgoal = to + (tabstp / 2); tabgoal -= (tabgoal % tabstp); if (tabgoal >= CO) Index: tune.h =================================================================== RCS file: /local/src/CVS/jove/tune.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- tune.h 15 May 2003 00:01:07 -0000 1.4 +++ tune.h 20 Oct 2004 05:26:40 -0000 1.5 @@ -146,11 +146,6 @@ # endif #endif -#ifdef SYSV -# define index strchr -# define rindex strrchr -#endif - /* These are here since they define things in tune.c. If you add things to tune.c, add them here too, if necessary. */ Index: util.c =================================================================== RCS file: /local/src/CVS/jove/util.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- util.c 10 Jun 2003 17:32:07 -0000 1.4 +++ util.c 20 Oct 2004 05:26:40 -0000 1.5 @@ -657,7 +657,7 @@ { register char *cp; - if (cp = rindex(f, '/')) + if (cp = strrchr_ucs4(f, '/')) return cp + 1; else return f; @@ -671,7 +671,7 @@ register char *t, *d; d = dir; - if (t = rindex(f, '/')) { + if (t = strrchr_ucs4(f, '/')) { while (f != t) *d++ = *f++; } else From commit at keithp.com Tue Oct 19 23:17:58 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 19 23:18:02 2004 Subject: [Commit] nickle ChangeLog,1.90,1.91 lex.l,1.78,1.79 Message-ID: Committed by: keithp Update of /local/src/CVS/nickle In directory home.keithp.com:/tmp/cvs-serv1329 Modified Files: ChangeLog lex.l Log Message: 2004-10-19 Keith Packard * lex.l: Permit any non-ASCII character in an identifier. Better discrimination requires a better lexer generator as flex can't deal with UTF-8. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/nickle/ChangeLog,v retrieving revision 1.90 retrieving revision 1.91 diff -u -d -r1.90 -r1.91 --- ChangeLog 17 Oct 2004 23:34:34 -0000 1.90 +++ ChangeLog 20 Oct 2004 06:17:55 -0000 1.91 @@ -1,3 +1,10 @@ +2004-10-19 Keith Packard + + * lex.l: + Permit any non-ASCII character in an identifier. Better + discrimination requires a better lexer generator as flex + can't deal with UTF-8. + 2004-10-17 Keith Packard * gram.y: Index: lex.l =================================================================== RCS file: /local/src/CVS/nickle/lex.l,v retrieving revision 1.78 retrieving revision 1.79 diff -u -d -r1.78 -r1.79 --- lex.l 17 Oct 2004 23:34:34 -0000 1.78 +++ lex.l 20 Oct 2004 06:17:55 -0000 1.79 @@ -583,7 +583,7 @@ yylval.value = aetov (yytext, 10); return TEN_FLOAT; } -[a-zA-Z_][0-9a-zA-Z_]* { +[a-zA-Z\200-\377_][0-9a-zA-Z\200-\377_]* { CommandPtr c; SymbolPtr symbol; yylval.atom = AtomId (yytext); From commit at keithp.com Mon Oct 25 12:02:05 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 25 12:02:09 2004 Subject: [Commit] twin/twin_fedit - New directory,NONE,NONE Message-ID: Committed by: keithp Update of /local/src/CVS/twin/twin_fedit In directory home.keithp.com:/tmp/cvs-serv4420/twin_fedit Log Message: Directory /local/src/CVS/twin/twin_fedit added to the repository --- NEW FILE: - New directory --- From commit at keithp.com Mon Oct 25 12:09:39 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 25 12:09:47 2004 Subject: [Commit] twin/twin_fedit Makefile, NONE, 1.1 nchars, NONE, 1.1 twin-fedit.c, NONE, 1.1 twin-fedit.h, NONE, 1.1 twin-sfit.c, NONE, 1.1 Message-ID: Committed by: keithp Update of /local/src/CVS/twin/twin_fedit In directory home.keithp.com:/tmp/cvs-serv4796/twin_fedit Added Files: Makefile nchars twin-fedit.c twin-fedit.h twin-sfit.c Log Message: 2004-10-25 Keith Packard * Makefile.am: * configure.ac: * twin_dispatch.c: (twin_dispatch): * twin_file.c: (_twin_file_order), (_twin_run_file), (twin_set_file), (twin_clear_file): * twin_queue.c: (_twin_queue_insert), (_twin_queue_remove), (_twin_queue_delete), (_twin_queue_set_order), (_twin_queue_review_order): * twin_timeout.c: (_twin_timeout_order), (_twin_queue_timeout), (_twin_run_timeout), (twin_set_timeout), (twin_clear_timeout), (_twin_timeout_delay), (twin_now): * twin_work.c: (_twin_work_order), (_twin_queue_work), (_twin_run_work), (twin_set_work), (twin_clear_work): * twinint.h: Add dispatch stuff to manage timeouts, workprocs and files. Remove thread stuff * twin.h: * twin_clock.c: (twin_clock_set_transform), (twin_clock_hand), (twin_clock_minute_angle), (twin_clock_face), (twin_clock_timeout), (twin_clock_start): * twin_clock.h: * twin_demo.c: (twin_example_start), (twin_line_start), (twin_circletext_start), (twin_quickbrown_start), (twin_ascii_start), (twin_jelly_start), (twin_extents_start), (twin_demo_start): * twin_demo.h: * twin_text.c: (twin_text_start): * twin_text.h: * xtwin.c: (main): Split demos into separate files * twin_draw.c: (twin_composite), (twin_fill): Make drawing origin match clip rectangle. * twin_fedit Add glyph editor to CVS to preserve it * twin_icon.c: (twin_icon_draw): Add scalable icons * twin_path.c: (_twin_path_sfinish), (_twin_path_smove), (twin_path_close), (twin_path_circle), (twin_path_ellipse), (twin_path_append), (twin_composite_path): Separate 'closing' a subpath from 'finishing' a subpath; the former adds a point back to the start while the latter just leaves the path unclosed and prepares for a new subpath. * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_show), (twin_pixmap_hide), (twin_pixmap_clip), (twin_pixmap_current_clip), (twin_pixmap_restore_clip), (twin_pixmap_reset_clip), (twin_pixmap_damage), (twin_pixmap_move): * twin_poly.c: (_twin_edge_build), (_span_fill), (_twin_edge_fill), (twin_fill_path): * twin_screen.c: (twin_screen_create): Eliminate locking, add clipping. * twin_window.c: (twin_window_create), (twin_window_configure), (twin_window_frame): Clean up title drawing, use clipping * twin_x11.c: (twin_x11_read_events), (twin_x11_work), (twin_x11_create), (twin_x11_destroy), (twin_x11_damage): * twin_x11.h: Eliminate locking, use dispatch stuff --- NEW FILE: Makefile --- CFLAGS=$(shell pkg-config --cflags cairo) -g LIBS=$(shell pkg-config --libs cairo) OBJS=twin-fedit.o twin-sfit.o twin-fedit: $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(OBJS): twin-fedit.h --- NEW FILE: nchars --- /* 0x0 '\0' offset 0 */ 0, 24, 42, 0, 2, 4, 0, 24, /* snap_x */ -42, -21, -15, 0, /* snap_y */ 'm', 0, 0, 'l', 0, -42, 'l', 24, -42, 'l', 24, 0, 'l', 0, 0, 'e', /* 0x20 ' ' offset 28 */ 0, 4, 0, 0, 2, 3, -128, 0, /* snap_x */ -21, -15, 0, /* snap_y */ 'e', /* 0x21 '!' offset 40 */ 0, 4, 42, 0, 3, 3, 0, 2, 4, /* snap_x */ -21, -15, 0, /* snap_y */ [...982 lines suppressed...] 'c', 18, -24, 18, -12, 28, -12, 'c', 32, -12, 35, -15, 36, -22, 'e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 40, 90, 114, 152, 224, 323, 390, 419, 441, 463, 494, 520, 556, 575, 604, 622, 666, 691, 736, 780, 809, 860, 919, 944, 1004, 1063, 1109, 1162, 1183, 1209, 1230, 1288, 1375, 1406, 1455, 1499, 1534, 1572, 1604, 1655, 1686, 1703, 1731, 1761, 1785, 1821, 1851, 1895, 1931, 1981, 2023, 2074, 2100, 2128, 2152, 2188, 2212, 2240, 2271, 2296, 2314, 2339, 2363, 2381, 2417, 2467, 2517, 2561, 2611, 2659, 2693, 2758, 2790, 2826, 2870, 2900, 2917, 2963, 2995, 3039, 3089, 3139, 3168, 3219, 3252, 3283, 3307, 3343, 3367, 3399, 3430, 3474, 3491, 3535, 0, --- NEW FILE: twin-fedit.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin-fedit.h --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin-sfit.c --- (This appears to be a binary file; contents omitted.) From commit at keithp.com Mon Oct 25 12:09:41 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 25 12:10:00 2004 Subject: [Commit] twin ChangeLog, 1.20, 1.21 Makefile.am, 1.9, 1.10 configure.ac, 1.3, 1.4 twin.h, 1.15, 1.16 twin_clock.c, NONE, 1.1 twin_clock.h, NONE, 1.1 twin_demo.c, NONE, 1.1 twin_demo.h, NONE, 1.1 twin_dispatch.c, NONE, 1.1 twin_draw.c, 1.6, 1.7 twin_file.c, NONE, 1.1 twin_icon.c, NONE, 1.1 twin_path.c, 1.11, 1.12 twin_pixmap.c, 1.5, 1.6 twin_poly.c, 1.8, 1.9 twin_queue.c, NONE, 1.1 twin_screen.c, 1.7, 1.8 twin_text.c, NONE, 1.1 twin_text.h, NONE, 1.1 twin_timeout.c, NONE, 1.1 twin_window.c, 1.2, 1.3 twin_work.c, NONE, 1.1 twin_x11.c, 1.6, 1.7 twin_x11.h, 1.3, 1.4 twinint.h, 1.12, 1.13 xtwin.c, 1.19, 1.20 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv4796 Modified Files: ChangeLog Makefile.am configure.ac twin.h twin_draw.c twin_path.c twin_pixmap.c twin_poly.c twin_screen.c twin_window.c twin_x11.c twin_x11.h twinint.h xtwin.c Added Files: twin_clock.c twin_clock.h twin_demo.c twin_demo.h twin_dispatch.c twin_file.c twin_icon.c twin_queue.c twin_text.c twin_text.h twin_timeout.c twin_work.c Log Message: 2004-10-25 Keith Packard * Makefile.am: * configure.ac: * twin_dispatch.c: (twin_dispatch): * twin_file.c: (_twin_file_order), (_twin_run_file), (twin_set_file), (twin_clear_file): * twin_queue.c: (_twin_queue_insert), (_twin_queue_remove), (_twin_queue_delete), (_twin_queue_set_order), (_twin_queue_review_order): * twin_timeout.c: (_twin_timeout_order), (_twin_queue_timeout), (_twin_run_timeout), (twin_set_timeout), (twin_clear_timeout), (_twin_timeout_delay), (twin_now): * twin_work.c: (_twin_work_order), (_twin_queue_work), (_twin_run_work), (twin_set_work), (twin_clear_work): * twinint.h: Add dispatch stuff to manage timeouts, workprocs and files. Remove thread stuff * twin.h: * twin_clock.c: (twin_clock_set_transform), (twin_clock_hand), (twin_clock_minute_angle), (twin_clock_face), (twin_clock_timeout), (twin_clock_start): * twin_clock.h: * twin_demo.c: (twin_example_start), (twin_line_start), (twin_circletext_start), (twin_quickbrown_start), (twin_ascii_start), (twin_jelly_start), (twin_extents_start), (twin_demo_start): * twin_demo.h: * twin_text.c: (twin_text_start): * twin_text.h: * xtwin.c: (main): Split demos into separate files * twin_draw.c: (twin_composite), (twin_fill): Make drawing origin match clip rectangle. * twin_fedit Add glyph editor to CVS to preserve it * twin_icon.c: (twin_icon_draw): Add scalable icons * twin_path.c: (_twin_path_sfinish), (_twin_path_smove), (twin_path_close), (twin_path_circle), (twin_path_ellipse), (twin_path_append), (twin_composite_path): Separate 'closing' a subpath from 'finishing' a subpath; the former adds a point back to the start while the latter just leaves the path unclosed and prepares for a new subpath. * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_show), (twin_pixmap_hide), (twin_pixmap_clip), (twin_pixmap_current_clip), (twin_pixmap_restore_clip), (twin_pixmap_reset_clip), (twin_pixmap_damage), (twin_pixmap_move): * twin_poly.c: (_twin_edge_build), (_span_fill), (_twin_edge_fill), (twin_fill_path): * twin_screen.c: (twin_screen_create): Eliminate locking, add clipping. * twin_window.c: (twin_window_create), (twin_window_configure), (twin_window_frame): Clean up title drawing, use clipping * twin_x11.c: (twin_x11_read_events), (twin_x11_work), (twin_x11_create), (twin_x11_destroy), (twin_x11_damage): * twin_x11.h: Eliminate locking, use dispatch stuff Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- ChangeLog 6 Oct 2004 06:40:57 -0000 1.20 +++ ChangeLog 25 Oct 2004 19:09:35 -0000 1.21 @@ -1,3 +1,71 @@ +2004-10-25 Keith Packard + + * Makefile.am: + * configure.ac: + * twin_dispatch.c: (twin_dispatch): + * twin_file.c: (_twin_file_order), (_twin_run_file), + (twin_set_file), (twin_clear_file): + * twin_queue.c: (_twin_queue_insert), (_twin_queue_remove), + (_twin_queue_delete), (_twin_queue_set_order), + (_twin_queue_review_order): + * twin_timeout.c: (_twin_timeout_order), (_twin_queue_timeout), + (_twin_run_timeout), (twin_set_timeout), (twin_clear_timeout), + (_twin_timeout_delay), (twin_now): + * twin_work.c: (_twin_work_order), (_twin_queue_work), + (_twin_run_work), (twin_set_work), (twin_clear_work): + * twinint.h: + Add dispatch stuff to manage timeouts, workprocs and files. + Remove thread stuff + + * twin.h: + * twin_clock.c: (twin_clock_set_transform), (twin_clock_hand), + (twin_clock_minute_angle), (twin_clock_face), (twin_clock_timeout), + (twin_clock_start): + * twin_clock.h: + * twin_demo.c: (twin_example_start), (twin_line_start), + (twin_circletext_start), (twin_quickbrown_start), + (twin_ascii_start), (twin_jelly_start), (twin_extents_start), + (twin_demo_start): + * twin_demo.h: + * twin_text.c: (twin_text_start): + * twin_text.h: + * xtwin.c: (main): + Split demos into separate files + + * twin_draw.c: (twin_composite), (twin_fill): + Make drawing origin match clip rectangle. + + * twin_fedit + Add glyph editor to CVS to preserve it + + * twin_icon.c: (twin_icon_draw): + Add scalable icons + + * twin_path.c: (_twin_path_sfinish), (_twin_path_smove), + (twin_path_close), (twin_path_circle), (twin_path_ellipse), + (twin_path_append), (twin_composite_path): + Separate 'closing' a subpath from 'finishing' a subpath; the + former adds a point back to the start while the latter just + leaves the path unclosed and prepares for a new subpath. + + * twin_pixmap.c: (twin_pixmap_create), (twin_pixmap_show), + (twin_pixmap_hide), (twin_pixmap_clip), (twin_pixmap_current_clip), + (twin_pixmap_restore_clip), (twin_pixmap_reset_clip), + (twin_pixmap_damage), (twin_pixmap_move): + * twin_poly.c: (_twin_edge_build), (_span_fill), (_twin_edge_fill), + (twin_fill_path): + * twin_screen.c: (twin_screen_create): + Eliminate locking, add clipping. + + * twin_window.c: (twin_window_create), (twin_window_configure), + (twin_window_frame): + Clean up title drawing, use clipping + + * twin_x11.c: (twin_x11_read_events), (twin_x11_work), + (twin_x11_create), (twin_x11_destroy), (twin_x11_damage): + * twin_x11.h: + Eliminate locking, use dispatch stuff + 2004-10-05 Keith Packard * Makefile.am: Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 6 Oct 2004 06:40:57 -0000 1.9 +++ Makefile.am 25 Oct 2004 19:09:35 -0000 1.10 @@ -1,4 +1,4 @@ -CFLAGS=-g +AM_CFLAGS=-O0 -g INCLUDES= @X_CFLAGS@ @WARN_CFLAGS@ #libtwin_la_SOURCES = \ @@ -17,9 +17,12 @@ xtwin_SOURCES = \ twin.h \ twin_convolve.c \ + twin_dispatch.c \ twin_draw.c \ twin_glyphs.c \ twin_hull.c \ + twin_icon.c \ + twin_file.c \ twin_fixed.c \ twin_font.c \ twin_geom.c \ @@ -31,11 +34,17 @@ twin_primitive.c \ twin_screen.c \ twin_spline.c \ - twin_thread.c \ twin_trig.c \ twin_window.c \ twin_x11.c \ twinint.h \ + twin_queue.c \ + twin_timeout.c \ + twin_work.c \ + twinint.h \ + twin_clock.c \ + twin_text.c \ + twin_demo.c \ xtwin.c xtwin_LDADD = @X_LIBS@ -lm Index: configure.ac =================================================================== RCS file: /local/src/CVS/twin/configure.ac,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- configure.ac 30 Sep 2004 17:23:07 -0000 1.3 +++ configure.ac 25 Oct 2004 19:09:35 -0000 1.4 @@ -52,10 +52,6 @@ AC_SUBST(X_CFLAGS) AC_SUBST(X_LIBS) -AC_CHECK_LIB([pthread], [pthread_create]) - -AC_CHECK_HEADERS([pthread.h]) - # #AC_ARG_WITH(freetype-config, [ --with-freetype-config=PROG Use FreeType configuration program PROG], freetype_config=$withval, freetype_config=yes) # Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- twin.h 6 Oct 2004 06:40:57 -0000 1.15 +++ twin.h 25 Oct 2004 19:09:35 -0000 1.16 @@ -28,9 +28,6 @@ #include #include #include -#if HAVE_PTHREAD_H -#include -#endif typedef uint8_t twin_a8_t; typedef uint16_t twin_a16_t; @@ -43,19 +40,7 @@ typedef int16_t twin_count_t; typedef int16_t twin_keysym_t; typedef int32_t twin_area_t; - -/* - * Mutexes - */ -#if HAVE_PTHREAD_H -typedef pthread_mutex_t twin_mutex_t; -typedef pthread_cond_t twin_cond_t; -typedef pthread_t twin_thread_t; -#else -typedef int twin_mutext_t; -typedef int twin_cond_t; -typedef int twin_thread_t; -#endif +typedef int32_t twin_time_t; #define TWIN_FALSE 0 #define TWIN_TRUE 1 @@ -120,6 +105,11 @@ twin_coord_t height; /* pixels */ twin_coord_t stride; /* bytes */ /* + * Clipping - a single rectangle in pixmap coordinates. + * Drawing is done relative to this rectangle + */ + twin_rect_t clip; + /* * Pixels */ twin_pointer_t p; @@ -176,7 +166,6 @@ void (*damaged) (void *); void *damaged_closure; twin_count_t disable; - twin_mutex_t screen_mutex; /* * Repaint function */ @@ -220,6 +209,9 @@ #define twin_fixed_to_double(f) ((double) (f) / 65536.0) #define twin_int_to_fixed(i) ((twin_fixed_t) (i) << 16) +#define twin_fixed_ceil(f) (((f) + 0xffff) & ~0xffff) +#define twin_fixed_floor(f) ((f) & ~0xffff) +#define twin_fixed_to_int(f) ((int) ((f) >> 16)) typedef struct _twin_point { twin_fixed_t x, y; @@ -328,12 +320,23 @@ TwinIconMinimize, TwinIconMaximize, TwinIconClose, + TwinIconResize, } twin_icon_t; /* * Widgets */ +typedef enum _twin_box_layout { + TwinLayoutHorz, TwinLayoutVert +} twin_box_layout_t; + +typedef struct _twin_box { + twin_box_layout_t layout; + twin_rect_t geometry; + +} twin_box_t; + typedef struct { twin_rect_t geometry; } twin_widget_t; @@ -343,6 +346,36 @@ } twin_button_t; /* + * Timeout and work procs return TWIN_TRUE to remain in the queue, + * timeout procs are called every 'delay' ms + */ + +typedef twin_time_t (*twin_timeout_proc_t) (twin_time_t now, + void *closure); + +typedef twin_bool_t (*twin_work_proc_t) (void *closure); + +typedef enum _twin_file_op { + TWIN_READ = 1, + TWIN_WRITE = 2 +} twin_file_op_t; + +typedef twin_bool_t (*twin_file_proc_t) (int file, + twin_file_op_t ops, + void *closure); + +typedef void (*twin_block_proc_t) (void *closure); +typedef void (*twin_wakeup_proc_t) (void *closure); + +#define twin_time_compare(a,op,b) (((a) - (b)) op 0) + +typedef struct _twin_timeout twin_timeout_t; +typedef struct _twin_work twin_work_t; +typedef struct _twin_file twin_file_t; +typedef struct _twin_block twin_block_t; +typedef struct _twin_wakeup twin_wakeup_t; + +/* * twin_convolve.c */ void @@ -351,6 +384,12 @@ twin_path_t *pen); /* + * twin_dispatch.c + */ +void +twin_dispatch (void); + +/* * twin_draw.c */ @@ -385,6 +424,19 @@ twin_event_enqueue (const twin_event_t *event); /* + * twin_file.c + */ + +twin_file_t * +twin_set_file (twin_file_proc_t file_proc, + int file, + twin_file_op_t ops, + void *closure); + +void +twin_clear_file (twin_file_t *file); + +/* * twin_fixed.c */ @@ -620,9 +672,23 @@ twin_pixmap_disable_update (twin_pixmap_t *pixmap); void -twin_pixmap_damage (twin_pixmap_t *pixmap, - twin_coord_t x1, twin_coord_t y1, - twin_coord_t x2, twin_coord_t y2); +twin_pixmap_clip (twin_pixmap_t *pixmap, + twin_coord_t left, twin_coord_t top, + twin_coord_t right, twin_coord_t bottom); + +twin_rect_t +twin_pixmap_current_clip (twin_pixmap_t *pixmap); + +void +twin_pixmap_restore_clip (twin_pixmap_t *pixmap, twin_rect_t rect); + +void +twin_pixmap_reset_clip (twin_pixmap_t *pixmap); + +void +twin_pixmap_damage (twin_pixmap_t *pixmap, + twin_coord_t left, twin_coord_t top, + twin_coord_t right, twin_coord_t bottom); void twin_pixmap_lock (twin_pixmap_t *pixmap); @@ -723,31 +789,21 @@ twin_fixed_t x3, twin_fixed_t y3); /* - * twin_thread.c + * twin_timeout.c */ -void -twin_mutex_init (twin_mutex_t *mutex); - -void -twin_mutex_lock (twin_mutex_t *mutex); - -void -twin_mutex_unlock (twin_mutex_t *mutex); - -void -twin_cond_init (twin_cond_t *cond); +#define twin_time_compare(a,op,b) (((a) - (b)) op 0) -void -twin_cond_broadcast (twin_cond_t *cond); +twin_timeout_t * +twin_set_timeout (twin_timeout_proc_t timeout_proc, + twin_time_t delay, + void *closure); void -twin_cond_wait (twin_cond_t *cond, twin_mutex_t *mutex); - -typedef void * (*twin_thread_func_t) (void *arg); +twin_clear_timeout (twin_timeout_t *timeout); -int -twin_thread_create (twin_thread_t *thread, twin_thread_func_t func, void *arg); +twin_time_t +twin_now (void); /* * twin_trig.c @@ -806,5 +862,18 @@ twin_bool_t twin_window_dispatch (twin_window_t *window, twin_event_t *event); - +/* + * twin_work.c + */ + +#define TWIN_WORK_REDISPLAY 0 + +twin_work_t * +twin_set_work (twin_work_proc_t work_proc, + int priority, + void *closure); + +void +twin_clear_work (twin_work_t *work); + #endif /* _TWIN_H_ */ --- NEW FILE: twin_clock.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_clock.h --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_demo.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_demo.h --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_dispatch.c --- (This appears to be a binary file; contents omitted.) Index: twin_draw.c =================================================================== RCS file: /local/src/CVS/twin/twin_draw.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- twin_draw.c 6 Oct 2004 00:11:27 -0000 1.6 +++ twin_draw.c 25 Oct 2004 19:09:36 -0000 1.7 @@ -275,68 +275,73 @@ { twin_coord_t iy; twin_coord_t left, right, top, bottom; + twin_coord_t sdx, sdy; + twin_source_u s; + dst_x += dst->clip.left; + dst_y += dst->clip.top; left = dst_x; right = dst_x + width; top = dst_y; bottom = dst_y + height; - if (left < 0) - left = 0; - if (right > dst->width) - right = dst->width; - if (top < 0) - top = 0; - if (bottom > dst->height) - bottom = dst->height; + /* clip */ + if (left < dst->clip.left) + left = dst->clip.left; + if (right > dst->clip.right) + right = dst->clip.right; + if (top < dst->clip.top) + top = dst->clip.top; + if (bottom > dst->clip.bottom) + bottom = dst->clip.bottom; + if (left >= right || top >= bottom) return; - twin_pixmap_lock (dst); + if (src->source_kind == TWIN_PIXMAP) + { + src_x += src->u.pixmap->clip.left; + src_y += src->u.pixmap->clip.top; + } + else + s.c = src->u.argb; + + sdx = src_x - dst_x; + sdy = src_y - dst_y; + if (msk) { twin_src_msk_op op; - twin_source_u s, m; - twin_coord_t sdx, sdy, mdx, mdy; + twin_source_u m; + twin_coord_t mdx, mdy; + + if (msk->source_kind == TWIN_PIXMAP) + { + msk_x += msk->u.pixmap->clip.left; + msk_y += msk->u.pixmap->clip.top; + } + else + s.c = msk->u.argb; - sdx = src_x - dst_x; - sdy = src_y - dst_y; mdx = msk_x - dst_x; mdy = msk_y - dst_y; - op = comp3[operator][operand_index(src)][operand_index(msk)][dst->format]; - if (op) - { - if (src->source_kind == TWIN_SOLID) - s.c = src->u.argb; - if (msk->source_kind == TWIN_SOLID) - s.c = msk->u.argb; - for (iy = top; iy < bottom; iy++) - { - if (src->source_kind == TWIN_PIXMAP) - s.p = twin_pixmap_pointer (src->u.pixmap, left+sdx, iy+sdy); - if (msk->source_kind == TWIN_PIXMAP) - m.p = twin_pixmap_pointer (msk->u.pixmap, left+mdx, iy+mdy); - (*op) (twin_pixmap_pointer (dst, left, iy), - s, m, right - left); - } - } - else + for (iy = top; iy < bottom; iy++) { + if (src->source_kind == TWIN_PIXMAP) + s.p = twin_pixmap_pointer (src->u.pixmap, left+sdx, iy+sdy); + if (msk->source_kind == TWIN_PIXMAP) + m.p = twin_pixmap_pointer (msk->u.pixmap, left+mdx, iy+mdy); + (*op) (twin_pixmap_pointer (dst, left, iy), + s, m, right - left); } } else { twin_src_op op; - twin_source_u s; - twin_coord_t sdx, sdy; - - sdx = src_x - dst_x; - sdy = src_y - dst_y; op = comp2[operator][operand_index(src)][dst->format]; - if (src->source_kind == TWIN_SOLID) - s.c = src->u.argb; + for (iy = top; iy < bottom; iy++) { if (src->source_kind == TWIN_PIXMAP) @@ -346,7 +351,6 @@ } } twin_pixmap_damage (dst, left, top, right, bottom); - twin_pixmap_unlock (dst); } /* @@ -379,19 +383,24 @@ twin_source_u src; twin_coord_t iy; - twin_pixmap_lock (dst); + left += dst->clip.left; + right += dst->clip.left; + top += dst->clip.top; + bottom += dst->clip.top; + /* clip */ + if (left < dst->clip.left) + left = dst->clip.left; + if (right > dst->clip.right) + right = dst->clip.right; + if (top < dst->clip.top) + top = dst->clip.top; + if (bottom > dst->clip.bottom) + bottom = dst->clip.bottom; + if (left >= right || top >= bottom) + return; src.c = pixel; - if (left < 0) - left = 0; - if (right > dst->width) - right = dst->width; - if (top < 0) - top = 0; - if (bottom > dst->height) - bottom = dst->height; op = fill[operator][dst->format]; for (iy = top; iy < bottom; iy++) (*op) (twin_pixmap_pointer (dst, left, iy), src, right - left); twin_pixmap_damage (dst, left, right, top, bottom); - twin_pixmap_unlock (dst); } --- NEW FILE: twin_file.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_icon.c --- (This appears to be a binary file; contents omitted.) Index: twin_path.c =================================================================== RCS file: /local/src/CVS/twin/twin_path.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- twin_path.c 6 Oct 2004 00:11:27 -0000 1.11 +++ twin_path.c 25 Oct 2004 19:09:36 -0000 1.12 @@ -60,12 +60,44 @@ return path->points[start]; } +void +_twin_path_sfinish (twin_path_t *path) +{ + switch (_twin_current_subpath_len(path)) { + case 1: + path->npoints--; + case 0: + return; + } + + if (path->nsublen == path->size_sublen) + { + int size_sublen; + int *sublen; + + if (path->size_sublen > 0) + size_sublen = path->size_sublen * 2; + else + size_sublen = 1; + if (path->sublen) + sublen = realloc (path->sublen, size_sublen * sizeof (int)); + else + sublen = malloc (size_sublen * sizeof (int)); + if (!sublen) + return; + path->sublen = sublen; + path->size_sublen = size_sublen; + } + path->sublen[path->nsublen] = path->npoints; + path->nsublen++; +} + void _twin_path_smove (twin_path_t *path, twin_sfixed_t x, twin_sfixed_t y) { switch (_twin_current_subpath_len (path)) { default: - twin_path_close (path); + _twin_path_sfinish (path); case 0: _twin_path_sdraw (path, x, y); break; @@ -147,33 +179,17 @@ void twin_path_close (twin_path_t *path) { + twin_spoint_t f; + switch (_twin_current_subpath_len(path)) { - case 1: - path->npoints--; case 0: - return; - } - - if (path->nsublen == path->size_sublen) - { - int size_sublen; - int *sublen; - - if (path->size_sublen > 0) - size_sublen = path->size_sublen * 2; - else - size_sublen = 1; - if (path->sublen) - sublen = realloc (path->sublen, size_sublen * sizeof (int)); - else - sublen = malloc (size_sublen * sizeof (int)); - if (!sublen) - return; - path->sublen = sublen; - path->size_sublen = size_sublen; + case 1: + break; + default: + f = _twin_path_subpath_first_spoint (path); + _twin_path_sdraw (path, f.x, f.y); + break; } - path->sublen[path->nsublen] = path->npoints; - path->nsublen++; } #define twin_fixed_abs(f) ((f) < 0 ? -(f) : (f)) @@ -201,7 +217,7 @@ center = _twin_path_current_spoint (path); - twin_path_close (path); + _twin_path_sfinish (path); max_radius = _twin_matrix_max_radius (&path->state.matrix); @@ -224,7 +240,7 @@ center.y + _twin_matrix_dy (&path->state.matrix, x, y)); } - twin_path_close (path); + _twin_path_sfinish (path); twin_path_set_matrix (path, save); } @@ -246,7 +262,7 @@ center = _twin_path_current_spoint (path); - twin_path_close (path); + _twin_path_sfinish (path); max_radius = _twin_matrix_max_radius (&path->state.matrix); @@ -269,7 +285,7 @@ center.y + _twin_matrix_dy (&path->state.matrix, x, y)); } - twin_path_close (path); + _twin_path_sfinish (path); twin_path_set_matrix (path, save); } @@ -376,7 +392,7 @@ { if (s < src->nsublen && p == src->sublen[s]) { - twin_path_close (dst); + _twin_path_sfinish (dst); s++; } _twin_path_sdraw (dst, src->points[p].x, src->points[p].y); @@ -435,7 +451,7 @@ twin_coord_t width, height; twin_path_bounds (path, &bounds); - if (bounds.left == bounds.right) + if (bounds.left >= bounds.right || bounds.top >= bounds.bottom) return; width = bounds.right - bounds.left; height = bounds.bottom - bounds.top; Index: twin_pixmap.c =================================================================== RCS file: /local/src/CVS/twin/twin_pixmap.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_pixmap.c 6 Oct 2004 06:40:57 -0000 1.5 +++ twin_pixmap.c 25 Oct 2004 19:09:36 -0000 1.6 @@ -42,6 +42,9 @@ pixmap->format = format; pixmap->width = width; pixmap->height = height; + pixmap->clip.left = pixmap->clip.top = 0; + pixmap->clip.right = pixmap->width; + pixmap->clip.bottom = pixmap->height; pixmap->stride = stride; pixmap->disable = 0; pixmap->p.v = pixmap + 1; @@ -94,8 +97,6 @@ if (pixmap->screen) twin_pixmap_hide (pixmap); - twin_screen_lock (screen); - pixmap->screen = screen; if (lower) @@ -116,7 +117,6 @@ } twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); - twin_screen_unlock (screen); } void @@ -127,7 +127,7 @@ if (!screen) return; - twin_screen_lock (screen); + twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); if (pixmap->up) @@ -148,7 +148,6 @@ pixmap->down = 0; if (pixmap->disable) twin_screen_enable_update (screen); - twin_screen_unlock (screen); } twin_pointer_t @@ -183,30 +182,50 @@ } void -twin_pixmap_damage (twin_pixmap_t *pixmap, - twin_coord_t x1, twin_coord_t y1, - twin_coord_t x2, twin_coord_t y2) +twin_pixmap_clip (twin_pixmap_t *pixmap, + twin_coord_t left, twin_coord_t top, + twin_coord_t right, twin_coord_t bottom) { - if (pixmap->screen) - twin_screen_damage (pixmap->screen, - x1 + pixmap->x, - y1 + pixmap->y, - x2 + pixmap->x, - y2 + pixmap->y); + if (left > pixmap->clip.left) pixmap->clip.left = left; + if (top > pixmap->clip.top) pixmap->clip.top = top; + if (right < pixmap->clip.right) pixmap->clip.right = right; + if (bottom < pixmap->clip.bottom) pixmap->clip.bottom = bottom; + if (pixmap->clip.left >= pixmap->clip.right) + pixmap->clip.right = pixmap->clip.left = 0; + if (pixmap->clip.top >= pixmap->clip.bottom) + pixmap->clip.bottom = pixmap->clip.top = 0; +} + +twin_rect_t +twin_pixmap_current_clip (twin_pixmap_t *pixmap) +{ + return pixmap->clip; } void -twin_pixmap_lock (twin_pixmap_t *pixmap) +twin_pixmap_restore_clip (twin_pixmap_t *pixmap, twin_rect_t rect) { - if (pixmap->screen) - twin_screen_lock (pixmap->screen); + pixmap->clip = rect; } void -twin_pixmap_unlock (twin_pixmap_t *pixmap) +twin_pixmap_reset_clip (twin_pixmap_t *pixmap) +{ + pixmap->clip.left = 0; pixmap->clip.top = 0; + pixmap->clip.right = pixmap->width; pixmap->clip.bottom = pixmap->height; +} + +void +twin_pixmap_damage (twin_pixmap_t *pixmap, + twin_coord_t x1, twin_coord_t y1, + twin_coord_t x2, twin_coord_t y2) { if (pixmap->screen) - twin_screen_unlock (pixmap->screen); + twin_screen_damage (pixmap->screen, + x1 + pixmap->x, + y1 + pixmap->y, + x2 + pixmap->x, + y2 + pixmap->y); } static twin_argb32_t @@ -238,12 +257,10 @@ void twin_pixmap_move (twin_pixmap_t *pixmap, twin_coord_t x, twin_coord_t y) { - twin_pixmap_lock (pixmap); twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); pixmap->x = x; pixmap->y = y; twin_pixmap_damage (pixmap, 0, 0, pixmap->width, pixmap->height); - twin_pixmap_unlock (pixmap); } twin_bool_t Index: twin_poly.c =================================================================== RCS file: /local/src/CVS/twin/twin_poly.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- twin_poly.c 5 Oct 2004 18:42:53 -0000 1.8 +++ twin_poly.c 25 Oct 2004 19:09:36 -0000 1.9 @@ -85,7 +85,7 @@ static int _twin_edge_build (twin_spoint_t *vertices, int nvertices, twin_edge_t *edges, - twin_sfixed_t dx, twin_sfixed_t dy) + twin_sfixed_t dx, twin_sfixed_t dy, twin_sfixed_t top_y) { int v, nv; int tv, bv; @@ -120,8 +120,8 @@ /* snap top to first grid point in pixmap */ y = _twin_sfixed_grid_ceil (vertices[tv].y + dy); - if (y < TWIN_POLY_START) - y = TWIN_POLY_START; + if (y < TWIN_POLY_START + top_y) + y = TWIN_POLY_START + top_y; /* skip vertices which don't span a sample row */ if (y >= vertices[bv].y + dy) @@ -206,8 +206,8 @@ int col; /* clip to pixmap */ - if (left < 0) - left = 0; + if (left < twin_int_to_sfixed (pixmap->clip.left)) + left = twin_int_to_sfixed (pixmap->clip.left); if (right > twin_int_to_sfixed (pixmap->width)) right = twin_int_to_sfixed (pixmap->width); @@ -311,7 +311,7 @@ /* step down, clipping to pixmap */ y += TWIN_POLY_STEP; - if (twin_sfixed_trunc (y) >= pixmap->height) + if (twin_sfixed_trunc (y) >= pixmap->clip.bottom) break; /* strip out dead edges */ @@ -363,6 +363,8 @@ edges = malloc (sizeof (twin_edge_t) * nalloc); p = 0; nedges = 0; + dx += twin_int_to_sfixed (pixmap->clip.left); + dy += twin_int_to_sfixed (pixmap->clip.top); for (s = 0; s <= path->nsublen; s++) { int sublen; @@ -376,7 +378,7 @@ if (npoints > 1) { n = _twin_edge_build (path->points + p, npoints, edges + nedges, - sdx, sdy); + sdx, sdy, twin_int_to_sfixed (pixmap->clip.top)); p = sublen; nedges += n; } --- NEW FILE: twin_queue.c --- (This appears to be a binary file; contents omitted.) Index: twin_screen.c =================================================================== RCS file: /local/src/CVS/twin/twin_screen.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_screen.c 6 Oct 2004 06:40:57 -0000 1.7 +++ twin_screen.c 25 Oct 2004 19:09:36 -0000 1.8 @@ -44,7 +44,6 @@ screen->damaged_closure = NULL; screen->disable = 0; screen->background = 0; - twin_mutex_init (&screen->screen_mutex); screen->put_begin = put_begin; screen->put_span = put_span; screen->closure = closure; @@ -54,18 +53,6 @@ } void -twin_screen_lock (twin_screen_t *screen) -{ - twin_mutex_lock (&screen->screen_mutex); -} - -void -twin_screen_unlock (twin_screen_t *screen) -{ - twin_mutex_unlock (&screen->screen_mutex); -} - -void twin_screen_destroy (twin_screen_t *screen) { while (screen->bottom) --- NEW FILE: twin_text.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_text.h --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_timeout.c --- (This appears to be a binary file; contents omitted.) Index: twin_window.c =================================================================== RCS file: /local/src/CVS/twin/twin_window.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_window.c 6 Oct 2004 06:40:57 -0000 1.2 +++ twin_window.c 25 Oct 2004 19:09:36 -0000 1.3 @@ -29,7 +29,9 @@ #define TWIN_FRAME_TEXT 0xffffffff #define TWIN_ACTIVE_BORDER 0xff606060 #define TWIN_BW 0 -#define TWIN_TITLE_HEIGHT 22 +#define TWIN_TITLE_HEIGHT 20 +#define TWIN_RESIZE_SIZE ((TWIN_TITLE_HEIGHT + 4) / 5) +#define TWIN_TITLE_BW ((TWIN_TITLE_HEIGHT + 11) / 12) twin_window_t * twin_window_create (twin_screen_t *screen, @@ -50,8 +52,8 @@ case WindowApplication: left = TWIN_BW; top = TWIN_BW + TWIN_TITLE_HEIGHT + TWIN_BW; - right = TWIN_BW; - bottom = TWIN_BW; + right = TWIN_BW + TWIN_RESIZE_SIZE; + bottom = TWIN_BW + TWIN_RESIZE_SIZE; break; case WindowPlain: default: @@ -68,6 +70,9 @@ window->client.top = top; window->client.bottom = height - bottom; window->pixmap = twin_pixmap_create (format, width, height); + twin_pixmap_clip (window->pixmap, + window->client.left, window->client.top, + window->client.right, window->client.bottom); window->pixmap->window = window; twin_pixmap_move (window->pixmap, x, y); window->damage.left = window->damage.right = 0; @@ -132,6 +137,9 @@ for (i = 0; i < old->disable; i++) twin_pixmap_disable_update (window->pixmap); twin_pixmap_destroy (old); + twin_pixmap_clip (window->pixmap, + window->client.left, window->client.top, + window->client.right, window->client.bottom); } if (x != window->pixmap->x || y != window->pixmap->y) twin_pixmap_move (window->pixmap, x, y); @@ -171,25 +179,68 @@ static void twin_window_frame (twin_window_t *window) { - twin_coord_t bw = 2; + twin_fixed_t bw = twin_int_to_fixed (TWIN_TITLE_BW); twin_path_t *path; - twin_coord_t name_height; - twin_text_metrics_t m; + twin_fixed_t bw_2 = bw / 2; twin_pixmap_t *pixmap = window->pixmap; - twin_fixed_t bw_2 = twin_int_to_fixed (bw) / 2; twin_fixed_t w_top = bw_2; twin_fixed_t c_left = bw_2; - twin_fixed_t t_h = twin_int_to_fixed (window->client.top - bw); + twin_fixed_t t_h = twin_int_to_fixed (window->client.top) - bw; twin_fixed_t t_arc_1 = t_h / 3; - twin_fixed_t c_right = twin_int_to_fixed (pixmap->width) - bw_2; + twin_fixed_t t_arc_2 = t_h * 2 / 3; + twin_fixed_t c_right = twin_int_to_fixed (window->client.right) - bw_2; twin_fixed_t c_top = twin_int_to_fixed (window->client.top) - bw_2; - + + twin_fixed_t name_height = t_h - bw - bw_2; + twin_fixed_t icon_size = name_height * 8 / 10; + twin_fixed_t icon_y = (twin_int_to_fixed (window->client.top) - + icon_size) / 2; + twin_fixed_t menu_x = t_arc_2; + twin_fixed_t text_x = menu_x + icon_size + bw; + twin_fixed_t text_y = icon_y + icon_size; + twin_fixed_t text_width; + twin_fixed_t title_right; + twin_fixed_t close_x; + twin_fixed_t max_x; + twin_fixed_t min_x; + twin_fixed_t resize_x; + twin_fixed_t resize_y; + const char *name; + + twin_pixmap_reset_clip (pixmap); + twin_fill (pixmap, 0x00000000, TWIN_SOURCE, 0, 0, pixmap->width, window->client.top); + path = twin_path_create (); + + + /* name */ + name = window->name; + if (!name) + name = "Sans un nom!"; + twin_path_set_font_size (path, name_height); + twin_path_set_font_style (path, TWIN_TEXT_OBLIQUE | TWIN_TEXT_UNHINTED); + text_width = twin_width_utf8 (path, name); + + title_right = (text_x + text_width + + bw + icon_size + + bw + icon_size + + bw + icon_size + + t_arc_2); + + if (title_right < c_right) + c_right = title_right; + + + close_x = c_right - t_arc_2 - icon_size; + max_x = close_x - bw - icon_size; + min_x = max_x - bw - icon_size; + resize_x = twin_int_to_fixed (window->client.right); + resize_y = twin_int_to_fixed (window->client.bottom); + /* border */ - path = twin_path_create (); twin_path_move (path, c_left, c_top); twin_path_draw (path, c_right, c_top); twin_path_curve (path, @@ -209,23 +260,54 @@ twin_path_empty (path); - /* name */ - if (window->name) + twin_pixmap_clip (pixmap, + twin_fixed_to_int (twin_fixed_floor (menu_x)), + 0, + twin_fixed_to_int (twin_fixed_ceil (c_right - t_arc_2)), + window->client.top); + + twin_path_move (path, text_x - twin_fixed_floor (menu_x), text_y); + twin_path_utf8 (path, window->name); + twin_paint_path (pixmap, TWIN_FRAME_TEXT, path); + + twin_pixmap_reset_clip (pixmap); + + /* widgets */ + { - twin_point_t t; - name_height = window->client.top - bw * 2; - if (name_height < 1) - name_height = 1; - twin_path_set_font_size (path, twin_int_to_fixed (name_height)); - twin_path_set_font_style (path, TWIN_TEXT_OBLIQUE); - twin_text_metrics_utf8 (path, window->name, &m); - t.x = ((c_right - c_left) - - (m.right_side_bearing - m.left_side_bearing)) / 2; - t.y = c_top - bw_2 * 4; - twin_path_move (path, t.x, t.y); - twin_path_utf8 (path, window->name); - twin_paint_path (pixmap, TWIN_FRAME_TEXT, path); + twin_matrix_t m; + + twin_matrix_identity (&m); + twin_matrix_translate (&m, menu_x, icon_y); + twin_matrix_scale (&m, icon_size, icon_size); + twin_icon_draw (pixmap, TwinIconMenu, m); + + twin_matrix_identity (&m); + twin_matrix_translate (&m, min_x, icon_y); + twin_matrix_scale (&m, icon_size, icon_size); + twin_icon_draw (pixmap, TwinIconMinimize, m); + + twin_matrix_identity (&m); + twin_matrix_translate (&m, max_x, icon_y); + twin_matrix_scale (&m, icon_size, icon_size); + twin_icon_draw (pixmap, TwinIconMaximize, m); + + twin_matrix_identity (&m); + twin_matrix_translate (&m, close_x, icon_y); + twin_matrix_scale (&m, icon_size, icon_size); + twin_icon_draw (pixmap, TwinIconClose, m); + + twin_matrix_identity (&m); + twin_matrix_translate (&m, resize_x, resize_y); + twin_matrix_scale (&m, + twin_int_to_fixed (TWIN_TITLE_HEIGHT), + twin_int_to_fixed (TWIN_TITLE_HEIGHT)); + twin_icon_draw (pixmap, TwinIconResize, m); } + + twin_pixmap_clip (pixmap, + window->client.left, window->client.top, + window->client.right, window->client.bottom); twin_path_destroy (path); } --- NEW FILE: twin_work.c --- (This appears to be a binary file; contents omitted.) Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- twin_x11.c 6 Oct 2004 00:11:27 -0000 1.6 +++ twin_x11.c 25 Oct 2004 19:09:36 -0000 1.7 @@ -82,36 +82,18 @@ } } -static void * -twin_x11_damage_thread (void *arg) +static twin_bool_t +twin_x11_read_events (int file, + twin_file_op_t ops, + void *closure) { - twin_x11_t *tx = arg; + twin_x11_t *tx = closure; - twin_mutex_lock (&tx->screen->screen_mutex); - for (;;) + while (XEventsQueued (tx->dpy, QueuedAfterReading)) { - twin_cond_wait (&tx->damage_cond, &tx->screen->screen_mutex); - if (!tx->win) - break; - if (twin_screen_damaged (tx->screen)) - { - twin_x11_update (tx); - XFlush (tx->dpy); - } - } - twin_mutex_unlock (&tx->screen->screen_mutex); - return 0; -} - -static void * -twin_x11_event_thread (void *arg) -{ - twin_x11_t *tx = arg; - XEvent ev; - twin_event_t tev; + XEvent ev; + twin_event_t tev; - for (;;) - { XNextEvent (tx->dpy, &ev); switch (ev.type) { case Expose: @@ -136,14 +118,20 @@ break; } } + return TWIN_TRUE; } -static void -twin_x11_screen_damaged (void *closure) +static twin_bool_t +twin_x11_work (void *closure) { - twin_x11_t *tx = closure; - - twin_cond_broadcast (&tx->damage_cond); + twin_x11_t *tx = closure; + + if (twin_screen_damaged (tx->screen)) + { + twin_x11_update (tx); + XFlush (tx->dpy); + } + return TWIN_TRUE; } twin_x11_t * @@ -167,6 +155,13 @@ tx->visual = DefaultVisual (dpy, scr); tx->depth = DefaultDepth (dpy, scr); + twin_set_file (twin_x11_read_events, + ConnectionNumber (dpy), + TWIN_READ, + tx); + + twin_set_work (twin_x11_work, TWIN_WORK_REDISPLAY, tx); + wa.background_pixmap = None; wa.event_mask = (KeyPressMask| KeyReleaseMask| @@ -200,16 +195,9 @@ tx->gc = XCreateGC (dpy, tx->win, 0, 0); tx->screen = twin_screen_create (width, height, _twin_x11_put_begin, _twin_x11_put_span, tx); - twin_screen_register_damaged (tx->screen, twin_x11_screen_damaged, tx); XMapWindow (dpy, tx->win); - twin_cond_init (&tx->damage_cond); - - twin_thread_create (&tx->damage_thread, twin_x11_damage_thread, tx); - - twin_thread_create (&tx->event_thread, twin_x11_event_thread, tx); - return tx; } @@ -218,17 +206,14 @@ { XDestroyWindow (tx->dpy, tx->win); tx->win = 0; - twin_cond_broadcast (&tx->damage_cond); twin_screen_destroy (tx->screen); } void twin_x11_damage (twin_x11_t *tx, XExposeEvent *ev) { - twin_screen_lock (tx->screen); twin_screen_damage (tx->screen, ev->x, ev->y, ev->x + ev->width, ev->y + ev->height); - twin_screen_unlock (tx->screen); } void Index: twin_x11.h =================================================================== RCS file: /local/src/CVS/twin/twin_x11.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_x11.h 6 Oct 2004 00:11:27 -0000 1.3 +++ twin_x11.h 25 Oct 2004 19:09:36 -0000 1.4 @@ -37,9 +37,6 @@ GC gc; Visual *visual; int depth; - twin_thread_t damage_thread; - twin_cond_t damage_cond; - twin_thread_t event_thread; XImage *image; int image_y; } twin_x11_t; Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- twinint.h 5 Oct 2004 18:42:53 -0000 1.12 +++ twinint.h 25 Oct 2004 19:09:36 -0000 1.13 @@ -345,6 +345,9 @@ twin_sfixed_t x2, twin_sfixed_t y2, twin_sfixed_t x3, twin_sfixed_t y3); +void +_twin_path_sfinish (twin_path_t *path); + /* * Glyph stuff. Coordinates are stored in 2.6 fixed point format */ @@ -375,4 +378,89 @@ #define twin_glyph_snap_y(g) (twin_glyph_snap_x(g) + twin_glyph_n_snap_x(g)) #define twin_glyph_draw(g) (twin_glyph_snap_y(g) + twin_glyph_n_snap_y(g)) +/* + * dispatch stuff + */ + +typedef struct _twin_queue { + struct _twin_queue *next; + struct _twin_queue *order; + twin_bool_t walking; + twin_bool_t deleted; +} twin_queue_t; + +struct _twin_timeout { + twin_queue_t queue; + twin_time_t time; + twin_time_t delay; + twin_timeout_proc_t proc; + void *closure; +}; + +struct _twin_work { + twin_queue_t queue; + int priority; + twin_work_proc_t proc; + void *closure; +}; + +struct _twin_file { + twin_queue_t queue; + int file; + twin_file_op_t ops; + twin_file_proc_t proc; + void *closure; +}; + +struct _twin_block { + twin_queue_t queue; + twin_block_proc_t proc; + void *closure; +}; + +struct _twin_wakeup { + twin_queue_t queue; + twin_wakeup_proc_t proc; + void *closure; +}; + +typedef enum _twin_order { + TWIN_BEFORE = -1, + TWIN_AT = 0, + TWIN_AFTER = 1 +} twin_order_t; + +typedef twin_order_t (*twin_queue_proc_t) (twin_queue_t *a, twin_queue_t *b); + +void +_twin_queue_insert (twin_queue_t **head, + twin_queue_proc_t proc, + twin_queue_t *new); + +void +_twin_queue_remove (twin_queue_t **head, + twin_queue_t *old); + +void +_twin_queue_delete (twin_queue_t **head, + twin_queue_t *old); + +twin_queue_t * +_twin_queue_set_order (twin_queue_t **head); + +void +_twin_queue_review_order (twin_queue_t *first); + +void +_twin_run_file (twin_time_t delay); + +void +_twin_run_timeout (void); + +twin_time_t +_twin_timeout_delay (void); + +void +_twin_run_work (void); + #endif /* _TWININT_H_ */ Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- xtwin.c 6 Oct 2004 06:40:57 -0000 1.19 +++ xtwin.c 25 Oct 2004 19:09:36 -0000 1.20 @@ -29,327 +29,9 @@ #include #include #include - -#define D(x) twin_double_to_fixed(x) - -#define TWIN_CLOCK_BACKGROUND 0xff3b80ae -#define TWIN_CLOCK_HOUR 0x80808080 -#define TWIN_CLOCK_HOUR_OUT 0x30000000 -#define TWIN_CLOCK_MINUTE 0x80808080 -#define TWIN_CLOCK_MINUTE_OUT 0x30000000 -#define TWIN_CLOCK_SECOND 0x80808080 -#define TWIN_CLOCK_SECOND_OUT 0x30000000 -#define TWIN_CLOCK_TIC 0xffbababa -#define TWIN_CLOCK_NUMBERS 0xffdedede -#define TWIN_CLOCK_WATER 0x60200000 -#define TWIN_CLOCK_WATER_OUT 0x40404040 -#define TWIN_CLOCK_WATER_UNDER 0x60400000 -#define TWIN_CLOCK_BORDER 0xffbababa -#define TWIN_CLOCK_BORDER_WIDTH D(0.01) - -static void -twin_clock_set_transform (twin_window_t *clock, - twin_path_t *path) -{ - twin_fixed_t scale; - - scale = (TWIN_FIXED_ONE - TWIN_CLOCK_BORDER_WIDTH * 3) / 2; - twin_path_translate (path, - twin_int_to_fixed (clock->client.left), - twin_int_to_fixed (clock->client.top)); - twin_path_scale (path, - (clock->client.right - clock->client.left) * scale, - (clock->client.bottom - clock->client.top) * scale); - - twin_path_translate (path, - TWIN_FIXED_ONE + TWIN_CLOCK_BORDER_WIDTH * 3, - TWIN_FIXED_ONE + TWIN_CLOCK_BORDER_WIDTH * 3); - - twin_path_rotate (path, -TWIN_ANGLE_90); -} - -static void -twin_clock_hand (twin_window_t *clock, - twin_angle_t angle, - twin_fixed_t len, - twin_fixed_t fill_width, - twin_fixed_t out_width, - twin_argb32_t fill_pixel, - twin_argb32_t out_pixel) -{ - twin_path_t *stroke = twin_path_create (); - twin_path_t *pen = twin_path_create (); - twin_path_t *path = twin_path_create (); - twin_matrix_t m; - - twin_clock_set_transform (clock, stroke); - - twin_path_rotate (stroke, angle); - twin_path_move (stroke, D(0), D(0)); - twin_path_draw (stroke, len, D(0)); - - m = twin_path_current_matrix (stroke); - m.m[2][0] = 0; - m.m[2][1] = 0; - twin_path_set_matrix (pen, m); - twin_path_set_matrix (path, m); - twin_path_circle (pen, fill_width); - twin_path_convolve (path, stroke, pen); - - twin_paint_path (clock->pixmap, fill_pixel, path); - - twin_paint_stroke (clock->pixmap, out_pixel, path, out_width); - - twin_path_destroy (path); - twin_path_destroy (pen); - twin_path_destroy (stroke); -} - -static twin_angle_t -twin_clock_minute_angle (int min) -{ - return min * TWIN_ANGLE_360 / 60; -} - -static void -twin_clock_face (twin_window_t *clock) -{ - twin_path_t *path = twin_path_create (); - int m; - - twin_clock_set_transform (clock, path); - - twin_path_move (path, 0, 0); - twin_path_circle (path, TWIN_FIXED_ONE); - - twin_paint_path (clock->pixmap, TWIN_CLOCK_BACKGROUND, path); - - twin_paint_stroke (clock->pixmap, TWIN_CLOCK_BORDER, path, TWIN_CLOCK_BORDER_WIDTH); - - { - twin_state_t state = twin_path_save (path); - twin_text_metrics_t metrics; - twin_fixed_t height, width; - static char *label = "twin"; - - twin_path_empty (path); - twin_path_rotate (path, twin_degrees_to_angle (-11) + TWIN_ANGLE_90); - twin_path_set_font_size (path, D(0.5)); - twin_path_set_font_style (path, TWIN_TEXT_UNHINTED|TWIN_TEXT_OBLIQUE); - twin_text_metrics_utf8 (path, label, &metrics); - height = metrics.ascent + metrics.descent; - width = metrics.right_side_bearing - metrics.left_side_bearing; - - twin_path_move (path, -width / 2, metrics.ascent - height/2 + D(0.01)); - twin_path_draw (path, width / 2, metrics.ascent - height/2 + D(0.01)); - twin_paint_stroke (clock->pixmap, TWIN_CLOCK_WATER_UNDER, path, D(0.02)); - twin_path_empty (path); - - twin_path_move (path, -width / 2 - metrics.left_side_bearing, metrics.ascent - height/2); - twin_path_utf8 (path, label); - twin_paint_path (clock->pixmap, TWIN_CLOCK_WATER, path); - twin_path_restore (path, &state); - } - - twin_path_set_font_size (path, D(0.2)); - twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); - - for (m = 1; m <= 60; m++) - { - twin_state_t state = twin_path_save (path); - twin_path_rotate (path, twin_clock_minute_angle (m) + TWIN_ANGLE_90); - twin_path_empty (path); - if (m % 5 != 0) - { - twin_path_move (path, 0, -TWIN_FIXED_ONE); - twin_path_draw (path, 0, -D(0.9)); - twin_paint_stroke (clock->pixmap, TWIN_CLOCK_TIC, path, D(0.01)); - } - else - { - char hour[3]; - twin_text_metrics_t metrics; - twin_fixed_t width; - twin_fixed_t left; - - sprintf (hour, "%d", m / 5); - twin_text_metrics_utf8 (path, hour, &metrics); - width = metrics.right_side_bearing - metrics.left_side_bearing; - left = -width / 2 - metrics.left_side_bearing; - twin_path_move (path, left, -D(0.98) + metrics.ascent); - twin_path_utf8 (path, hour); - twin_paint_path (clock->pixmap, TWIN_CLOCK_NUMBERS, path); - } - twin_path_restore (path, &state); - } - - twin_path_destroy (path); -} - -int napp; - -static void -twin_clock (twin_screen_t *screen, const char *name, int x, int y, int w, int h) -{ - twin_window_t *clock = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, - x, y, w, h); - struct timeval tv; - struct tm t; - twin_angle_t hour_angle, minute_angle, second_angle; - - twin_window_set_name (clock, name); - twin_window_show (clock); - - for (;;) - { - twin_pixmap_disable_update (clock->pixmap); - twin_window_draw (clock); - twin_fill (clock->pixmap, 0x00000000, TWIN_SOURCE, - clock->client.left, clock->client.top, - clock->client.right, clock->client.bottom); - - twin_clock_face (clock); - - gettimeofday (&tv, NULL); - - localtime_r(&tv.tv_sec, &t); - - second_angle = ((t.tm_sec * 100 + tv.tv_usec / 10000) * - TWIN_ANGLE_360) / 6000; - minute_angle = twin_clock_minute_angle (t.tm_min) + second_angle / 60; - hour_angle = (t.tm_hour * TWIN_ANGLE_360 + minute_angle) / 12; - twin_clock_hand (clock, hour_angle, D(0.4), D(0.07), D(0.01), - TWIN_CLOCK_HOUR, TWIN_CLOCK_HOUR_OUT); - twin_clock_hand (clock, minute_angle, D(0.8), D(0.05), D(0.01), - TWIN_CLOCK_MINUTE, TWIN_CLOCK_MINUTE_OUT); - twin_clock_hand (clock, second_angle, D(0.9), D(0.01), D(0.01), - TWIN_CLOCK_SECOND, TWIN_CLOCK_SECOND_OUT); - - twin_pixmap_enable_update (clock->pixmap); - - gettimeofday (&tv, NULL); - -#define INTERVAL 1000000 - - usleep (INTERVAL - (tv.tv_usec % INTERVAL)); - } - napp--; -} - -static void -twin_text_app (twin_screen_t *screen, const char *name, int x, int y, int w, int h) -{ - twin_window_t *text = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, - x,y,w,h); - twin_fixed_t fx, fy; - static const char *lines[] = { - "Fourscore and seven years ago our fathers brought forth on", - "this continent a new nation, conceived in liberty and", - "dedicated to the proposition that all men are created equal.", - "", - "Now we are engaged in a great civil war, testing whether that", - "nation or any nation so conceived and so dedicated can long", - "endure. We are met on a great battlefield of that war. We", - "have come to dedicate a portion of it as a final resting", - "place for those who died here that the nation might live.", - "This we may, in all propriety do. But in a larger sense, we", - "cannot dedicate, we cannot consecrate, we cannot hallow this", - "ground. The brave men, living and dead who struggled here", - "have hallowed it far above our poor power to add or detract.", - "The world will little note nor long remember what we say here,", - "but it can never forget what they did here.", - "", - "It is rather for us the living, we here be dedicated to the", - "great task remaining before us--that from these honored", - "dead we take increased devotion to that cause for which they", - "here gave the last full measure of devotion--that we here", - "highly resolve that these dead shall not have died in vain, that", - "this nation shall have a new birth of freedom, and that", - "government of the people, by the people, for the people shall", - "not perish from the earth.", - 0 - }; - const char **l; - twin_path_t *path; - - twin_window_set_name(text, name); - path = twin_path_create (); - twin_path_translate (path, - twin_int_to_fixed (text->client.left), - twin_int_to_fixed (text->client.top)); -#define TEXT_SIZE 10 - twin_path_set_font_size (path, D(TEXT_SIZE)); - fx = D(3); - fy = D(10); - twin_fill (text->pixmap, 0xc0c0c0c0, TWIN_SOURCE, - text->client.left, text->client.top, - text->client.right, text->client.bottom); - for (l = lines; *l; l++) - { - twin_path_move (path, fx, fy); - twin_path_utf8 (path, *l); - twin_paint_path (text->pixmap, 0xff000000, path); - twin_path_empty (path); - fy += D(TEXT_SIZE); - } - twin_window_show (text); -} - -typedef void (*twin_app_func_t) (twin_screen_t *screen, const char *name, - int x, int y, int w, int h); - -typedef struct _twin_app_args { - twin_app_func_t func; - twin_screen_t *screen; - char *name; - int x, y, w, h; -} twin_app_args_t; - -static void * -twin_app_thread (void *closure) -{ - twin_app_args_t *a = closure; - - (*a->func) (a->screen, a->name, a->x, a->y, a->w, a->h); - free (a); - return 0; -} - -static void -twin_start_app (twin_app_func_t func, - twin_screen_t *screen, - const char *name, - int x, int y, int w, int h) -{ - twin_app_args_t *a = malloc (sizeof (twin_app_args_t) + strlen (name) + 1); - pthread_t thread; - - a->func = func; - a->screen = screen; - a->name = (char *) (a + 1); - a->x = x; - a->y = y; - a->w = w; - a->h = h; - strcpy (a->name, name); - pthread_create (&thread, NULL, twin_app_thread, a); -} - -static void -twin_start_clock (twin_screen_t *screen, const char *name, int x, int y, int w, int h) -{ - ++napp; - twin_start_app (twin_clock, screen, name, x, y, w, h); -} - -int styles[] = { - TWIN_TEXT_ROMAN, - TWIN_TEXT_OBLIQUE, - TWIN_TEXT_BOLD, - TWIN_TEXT_BOLD|TWIN_TEXT_OBLIQUE -}; +#include +#include +#include #define WIDTH 512 #define HEIGHT 512 @@ -357,368 +39,14 @@ int main (int argc, char **argv) { - Status status = XInitThreads (); Display *dpy = XOpenDisplay (0); twin_x11_t *x11 = twin_x11_create (dpy, WIDTH, HEIGHT); - twin_pixmap_t *red = twin_pixmap_create (TWIN_ARGB32, WIDTH, HEIGHT); - twin_pixmap_t *blue = twin_pixmap_create (TWIN_ARGB32, 100, 100); - twin_pixmap_t *alpha = twin_pixmap_create (TWIN_A8, WIDTH, HEIGHT); - twin_operand_t source, mask; - twin_path_t *path; - XEvent ev, motion; - twin_bool_t had_motion; - int x, y; - twin_path_t *pen; - twin_path_t *stroke; - twin_path_t *extra; - int s; - twin_fixed_t fx, fy; - int g; twin_screen_set_background (x11->screen, twin_make_pattern ()); - (void) ev; - (void) motion; - (void) had_motion; - (void) x; - (void) y; - (void) red; - (void) blue; - (void) status; - (void) alpha; - (void) source; - (void) mask; - (void) source; - (void) path; - - extra = 0; - stroke = 0; - pen = 0; - s = 0; - fx = 0; - fy = 0; - g = 0 ; - -#if 0 - pen = twin_path_create (); - twin_path_circle (pen, D (1)); - - path = twin_path_create (); -#if 0 - twin_path_move (path, D(3), D(0)); - for (g = 0; g < 4326; g++) - { - int glyph = g; - if (!twin_has_glyph (glyph)) glyph = 0; - twin_path_cur_point (path, &fx, &fy); - if (fx + twin_glyph_width (glyph, D(10)) >= D(WIDTH) || g % 50 == 0) - twin_path_move (path, D(3), fy + D(10)); - twin_path_glyph (path, D(10), D(10), TWIN_TEXT_ROMAN, - glyph); - } -#endif -#if 0 - stroke = twin_path_create (); - twin_path_move (stroke, D(30), D(400)); - twin_path_set_font_size (stroke, D(100)); - twin_path_utf8 (stroke, "jelly HEzt/[]."); - twin_path_convolve (path, stroke, pen); -/* twin_path_append (path, stroke); */ - twin_path_destroy (stroke); - stroke = twin_path_create (); - twin_path_move (stroke, D(30), D(400)); - twin_path_draw (stroke, D(1000), D(400)); - twin_path_convolve (path, stroke, pen); -#endif - -#if 0 - stroke = twin_path_create (); - pen = twin_path_create (); - twin_path_translate (stroke, D(100), D(100)); -/* twin_path_rotate (stroke, twin_degrees_to_angle (270)); */ - twin_path_rotate (stroke, twin_degrees_to_angle (270)); - twin_path_move (stroke, D(0), D(0)); - twin_path_draw (stroke, D(100), D(0)); - twin_path_set_matrix (pen, twin_path_current_matrix (stroke)); - twin_path_circle (pen, D(20)); - twin_path_convolve (path, stroke, pen); -#endif - -#if 0 - stroke = twin_path_create (); - twin_path_translate (stroke, D(250), D(250)); - twin_path_circle (stroke, 0x42aaa); - extra = twin_path_convex_hull (stroke); - twin_path_convolve (path, extra, pen); -#endif - -#if 0 - { - twin_state_t state = twin_path_save (path); - twin_path_translate (path, D(300), D(300)); - twin_path_set_font_size (path, D(15)); - for (s = 0; s < 41; s++) - { - twin_state_t state = twin_path_save (path); - twin_path_rotate (path, twin_degrees_to_angle (9 * s)); - twin_path_move (path, D(100), D(0)); - twin_path_utf8 (path, "Hello, world!"); - twin_path_restore (path, &state); - } - twin_path_restore (path, &state); - } -#endif -#if 1 - fx = D(15); - fy = 0; - twin_path_translate (path, 0, D(HEIGHT)); - twin_path_rotate (path, -twin_degrees_to_angle (90)); - twin_path_scale (path, D(1), D(0.5)); - twin_path_set_font_style (path, TWIN_TEXT_OBLIQUE); - for (g = 40; g <= 60; g += 4) - { - twin_path_set_font_size (path, D(g)); -#if 0 - fy += D(g+2); - twin_path_move (path, fx, fy); - twin_path_utf8 (path, "H"); -#endif -#if 0 - fy += D(g+2); - twin_path_move (path, fx, fy); - twin_path_utf8 (path, - " !\"#$%&'()*+,-./0123456789:;<=>?"); - fy += D(g+2); - twin_path_move (path, fx, fy); - twin_path_utf8 (path, - "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"); - fy += D(g+2); - twin_path_move (path, fx, fy); - twin_path_utf8 (path, - "`abcdefghijklmnopqrstuvwxyz{|}~"); -#endif -#if 0 - for (s = 0; s < 4; s++) - { - fy += D(g+2); - twin_path_move (path, fx, fy); - twin_path_set_font_style (path, styles[s]); - twin_path_utf8 (path, - "the quick brown fox jumps over the lazy dog."); - twin_path_utf8 (path, - "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."); - } -#endif -#if 1 - fy += D(g + 2); - twin_path_move (path, fx, fy); -#define TEXT "jelly HEzt/[]." -/* twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); */ - twin_path_utf8 (path, TEXT); - { - twin_text_metrics_t m; - - stroke = twin_path_create (); - twin_path_set_matrix (stroke, twin_path_current_matrix (path)); - twin_text_metrics_utf8 (path, TEXT, &m); - twin_path_translate (stroke, TWIN_FIXED_HALF, TWIN_FIXED_HALF); - twin_path_move (stroke, fx, fy); - twin_path_draw (stroke, fx + m.width, fy); - twin_paint_stroke (red, 0xffff0000, stroke, D(1)); - twin_path_empty (stroke); - twin_path_move (stroke, - fx + m.left_side_bearing, fy - m.ascent); - twin_path_draw (stroke, - fx + m.right_side_bearing, fy - m.ascent); - twin_path_draw (stroke, - fx + m.right_side_bearing, fy + m.descent); - twin_path_draw (stroke, - fx + m.left_side_bearing, fy + m.descent); - twin_path_draw (stroke, - fx + m.left_side_bearing, fy - m.ascent); - twin_paint_stroke (red, 0xff00ff00, stroke, D(1)); - } -#endif - } -#endif -#if 0 - fx = D(3); - fy = D(8); - for (g = 6; g < 36; g++) - { - twin_path_move (path, fx, fy); - twin_path_set_font_size (path, D(g)); - twin_path_utf8 (path, - "the quick brown fox jumps over the lazy dog."); - twin_path_utf8 (path, - "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."); - fy += D(g); - } -#endif - twin_fill_path (alpha, path, 0, 0); - - twin_path_destroy (path); - - source.source_kind = TWIN_SOLID; - source.u.argb = 0xff000000; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (red, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - WIDTH, HEIGHT); - -#if 0 - path = twin_path_create (); - - twin_path_rotate (path, -TWIN_ANGLE_45); - twin_path_translate (path, D(10), D(2)); - for (s = 0; s < 40; s++) - { - twin_path_rotate (path, TWIN_ANGLE_11_25 / 16); - twin_path_scale (path, D(1.125), D(1.125)); - twin_path_move (path, D(0), D(0)); - twin_path_draw (path, D(1), D(0)); - twin_path_draw (path, D(1), D(1)); - twin_path_draw (path, D(0), D(1)); - } - - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, WIDTH, HEIGHT); - twin_fill_path (alpha, path); - - source.source_kind = TWIN_SOLID; - source.u.argb = 0xffff0000; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (red, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - WIDTH, HEIGHT); -#endif - -#if 0 - path = twin_path_create (); - stroke = twin_path_create (); - - twin_path_translate (stroke, D(62), D(62)); - twin_path_scale (stroke,D(60),D(60)); - for (s = 0; s < 60; s++) - { - twin_state_t save = twin_path_save (stroke); - twin_angle_t a = s * TWIN_ANGLE_90 / 15; - - twin_path_rotate (stroke, a); - twin_path_move (stroke, D(1), 0); - if (s % 5 == 0) - twin_path_draw (stroke, D(0.85), 0); - else - twin_path_draw (stroke, D(.98), 0); - twin_path_restore (stroke, &save); - } - twin_path_convolve (path, stroke, pen); - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, WIDTH, HEIGHT); - twin_fill_path (alpha, path); - - source.source_kind = TWIN_SOLID; - source.u.argb = 0xffff0000; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (red, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - WIDTH, HEIGHT); -#endif - -#if 0 - path = twin_path_create (); - stroke = twin_path_create (); - - twin_path_translate (stroke, D(100), D(100)); - twin_path_scale (stroke, D(10), D(10)); - twin_path_move (stroke, D(0), D(0)); - twin_path_draw (stroke, D(10), D(0)); - twin_path_convolve (path, stroke, pen); - - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, WIDTH, HEIGHT); - twin_fill_path (alpha, path); - - source.source_kind = TWIN_SOLID; - source.u.argb = 0xffff0000; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (red, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - WIDTH, HEIGHT); -#endif - -#if 0 - path = twin_path_create (); - - stroke = twin_path_create (); - - twin_path_move (stroke, D (10), D (40)); - twin_path_draw (stroke, D (40), D (40)); - twin_path_draw (stroke, D (10), D (10)); - twin_path_move (stroke, D (10), D (50)); - twin_path_draw (stroke, D (40), D (50)); - - twin_path_convolve (path, stroke, pen); - twin_path_destroy (stroke); - - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, 100, 100); - twin_fill_path (alpha, path); - source.source_kind = TWIN_SOLID; - source.u.argb = 0xff00ff00; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (blue, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - 100, 100); - - twin_path_destroy (path); - - path = twin_path_create (); - stroke = twin_path_create (); - - twin_path_move (stroke, D (50), D (50)); - twin_path_curve (stroke, D (70), D (70), D (80), D (70), D (100), D (50)); - - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, 100, 100); - twin_fill_path (alpha, stroke); - - source.source_kind = TWIN_SOLID; - source.u.argb = 0xffff0000; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (blue, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - 100, 100); - - twin_path_convolve (path, stroke, pen); - - twin_fill (alpha, 0x00000000, TWIN_SOURCE, 0, 0, 100, 100); - twin_fill_path (alpha, path); - - source.source_kind = TWIN_SOLID; - source.u.argb = 0xff0000ff; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (blue, 0, 0, &source, 0, 0, &mask, 0, 0, TWIN_OVER, - 100, 100); -#endif - - twin_pixmap_move (red, 0, 0); - twin_pixmap_move (blue, 100, 100); - twin_pixmap_show (red, x11->screen, 0); - twin_pixmap_show (blue, x11->screen, 0); - ++napp; -#endif - - if (!napp) - twin_start_clock (x11->screen, "Clock", 10, 10, 200, 200); -#if 0 - twin_start_clock (x11->screen, "Large clock", 0, 100, 256, 256); -#endif -#if 1 - twin_start_app (twin_text_app, x11->screen, "Gettysburg Address", - 100, 100, 318, 250); -#endif -#if 0 - twin_start_clock (x11->screen, "ur clock", 256, 0, 256, 256); - twin_start_clock (x11->screen, "ll clock", 0, 256, 256, 256); - twin_start_clock (x11->screen, "lr clock", 256, 256, 256, 256); -#endif - while (napp) - sleep (1); + twin_demo_start (x11->screen, "Demo", 100, 100, 400, 400); + twin_clock_start (x11->screen, "Clock", 10, 10, 200, 200); + twin_text_start (x11->screen, "Gettysburg Address", + 0, 0, 300, 300); + twin_dispatch (); return 0; } From commit at keithp.com Mon Oct 25 23:15:46 2004 From: commit at keithp.com (Keith Packard) Date: Mon Oct 25 23:15:54 2004 Subject: [Commit] twin ChangeLog, 1.21, 1.22 Makefile.am, 1.10, 1.11 twin.h, 1.16, 1.17 twin_box.c, NONE, 1.1 twin_clock.c, 1.1, 1.2 twin_demo.c, 1.1, 1.2 twin_glyphs.c, 1.5, 1.6 twin_hello.c, NONE, 1.1 twin_label.c, NONE, 1.1 twin_pixmap.c, 1.6, 1.7 twin_screen.c, 1.8, 1.9 twin_text.c, 1.1, 1.2 twin_toplevel.c, NONE, 1.1 twin_widget.c, NONE, 1.1 twin_window.c, 1.3, 1.4 twin_x11.c, 1.7, 1.8 twinint.h, 1.13, 1.14 xtwin.c, 1.20, 1.21 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv21003 Modified Files: ChangeLog Makefile.am twin.h twin_clock.c twin_demo.c twin_glyphs.c twin_pixmap.c twin_screen.c twin_text.c twin_window.c twin_x11.c twinint.h xtwin.c Added Files: twin_box.c twin_hello.c twin_label.c twin_toplevel.c twin_widget.c Log Message: 2004-10-25 Keith Packard * Makefile.am: * twin.h: * twin_box.c: (_twin_box_init), (_twin_box_query_geometry), (_twin_box_configure), (_twin_box_xy_to_widget), (_twin_box_dispatch), (twin_box_create): * twin_label.c: (_twin_label_query_geometry), (_twin_label_paint), (_twin_label_dispatch), (twin_label_set), (_twin_label_init), (twin_label_create): * twin_toplevel.c: (_twin_toplevel_dispatch), (_twin_toplevel_event), (_twin_toplevel_draw), (_twin_toplevel_destroy), (_twin_toplevel_init), (twin_toplevel_create), (_twin_toplevel_paint), (_twin_toplevel_queue_paint), (_twin_toplevel_layout), (_twin_toplevel_queue_layout), (twin_toplevel_show): * twin_widget.c: (_twin_widget_paint), (_twin_widget_dispatch), (_twin_widget_init), (_twin_widget_queue_paint), (_twin_widget_queue_layout), (twin_widget_create), (twin_widget_set): * twinint.h: Add initial widget implementation. * twin_glyphs.c: Fix numbers to have the same width. * twin_pixmap.c: (twin_pixmap_set_clip): Add new relative-origin clip setting function * twin_screen.c: (twin_screen_set_active), (twin_screen_dispatch): * twin_window.c: (twin_window_create), (twin_window_style_size), (twin_window_draw), (twin_window_dispatch): * twin_x11.c: (twin_x11_read_events): * twin_clock.c: (twin_clock_start): * twin_demo.c: (twin_example_start), (twin_line_start), (twin_circletext_start), (twin_quickbrown_start), (twin_ascii_start), (twin_jelly_start): * twin_text.c: (twin_text_start): Change enumerated constants to include Twin prefix * twin_hello.c: (_twin_hello_timeout), (twin_hello_start): Add new widget-based demo * xtwin.c: (main): Start widget based demo Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- ChangeLog 25 Oct 2004 19:09:35 -0000 1.21 +++ ChangeLog 26 Oct 2004 06:15:42 -0000 1.22 @@ -1,6 +1,52 @@ 2004-10-25 Keith Packard * Makefile.am: + * twin.h: + * twin_box.c: (_twin_box_init), (_twin_box_query_geometry), + (_twin_box_configure), (_twin_box_xy_to_widget), + (_twin_box_dispatch), (twin_box_create): + * twin_label.c: (_twin_label_query_geometry), (_twin_label_paint), + (_twin_label_dispatch), (twin_label_set), (_twin_label_init), + (twin_label_create): + * twin_toplevel.c: (_twin_toplevel_dispatch), + (_twin_toplevel_event), (_twin_toplevel_draw), + (_twin_toplevel_destroy), (_twin_toplevel_init), + (twin_toplevel_create), (_twin_toplevel_paint), + (_twin_toplevel_queue_paint), (_twin_toplevel_layout), + (_twin_toplevel_queue_layout), (twin_toplevel_show): + * twin_widget.c: (_twin_widget_paint), (_twin_widget_dispatch), + (_twin_widget_init), (_twin_widget_queue_paint), + (_twin_widget_queue_layout), (twin_widget_create), + (twin_widget_set): + * twinint.h: + Add initial widget implementation. + + * twin_glyphs.c: + Fix numbers to have the same width. + + * twin_pixmap.c: (twin_pixmap_set_clip): + Add new relative-origin clip setting function + + * twin_screen.c: (twin_screen_set_active), (twin_screen_dispatch): + * twin_window.c: (twin_window_create), (twin_window_style_size), + (twin_window_draw), (twin_window_dispatch): + * twin_x11.c: (twin_x11_read_events): + * twin_clock.c: (twin_clock_start): + * twin_demo.c: (twin_example_start), (twin_line_start), + (twin_circletext_start), (twin_quickbrown_start), + (twin_ascii_start), (twin_jelly_start): + * twin_text.c: (twin_text_start): + Change enumerated constants to include Twin prefix + + * twin_hello.c: (_twin_hello_timeout), (twin_hello_start): + Add new widget-based demo + + * xtwin.c: (main): + Start widget based demo + +2004-10-25 Keith Packard + + * Makefile.am: * configure.ac: * twin_dispatch.c: (twin_dispatch): * twin_file.c: (_twin_file_order), (_twin_run_file), Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 25 Oct 2004 19:09:35 -0000 1.10 +++ Makefile.am 26 Oct 2004 06:15:42 -0000 1.11 @@ -1,4 +1,3 @@ -AM_CFLAGS=-O0 -g INCLUDES= @X_CFLAGS@ @WARN_CFLAGS@ #libtwin_la_SOURCES = \ @@ -16,6 +15,7 @@ xtwin_SOURCES = \ twin.h \ + twin_box.c \ twin_convolve.c \ twin_dispatch.c \ twin_draw.c \ @@ -26,25 +26,28 @@ twin_fixed.c \ twin_font.c \ twin_geom.c \ + twin_label.c \ twin_matrix.c \ twin_path.c \ twin_pattern.c \ twin_pixmap.c \ twin_poly.c \ twin_primitive.c \ + twin_queue.c \ twin_screen.c \ twin_spline.c \ + twin_timeout.c \ + twin_toplevel.c \ twin_trig.c \ + twin_widget.c \ twin_window.c \ - twin_x11.c \ - twinint.h \ - twin_queue.c \ - twin_timeout.c \ twin_work.c \ + twin_x11.c \ twinint.h \ twin_clock.c \ twin_text.c \ twin_demo.c \ + twin_hello.c \ xtwin.c xtwin_LDADD = @X_LIBS@ -lm Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- twin.h 25 Oct 2004 19:09:35 -0000 1.16 +++ twin.h 26 Oct 2004 06:15:42 -0000 1.17 @@ -41,6 +41,7 @@ typedef int16_t twin_keysym_t; typedef int32_t twin_area_t; typedef int32_t twin_time_t; +typedef int16_t twin_stretch_t; #define TWIN_FALSE 0 #define TWIN_TRUE 1 @@ -251,9 +252,14 @@ */ typedef enum _twin_event_kind { - EventButtonDown, EventButtonUp, EventMotion, - EventKeyDown, EventKeyUp, EventUcs4, - EventActivate, EventDeactivate, + TwinEventButtonDown, TwinEventButtonUp, TwinEventMotion, + TwinEventKeyDown, TwinEventKeyUp, TwinEventUcs4, + TwinEventActivate, TwinEventDeactivate, + TwinEventPaint, + TwinEventShow, + TwinEventQueryGeometry, + TwinEventConfigure, + TwinEventDestroy, } twin_event_kind_t; typedef struct _twin_event { @@ -270,6 +276,9 @@ struct { twin_ucs4_t ucs4; } ucs4; + struct { + twin_rect_t extents; + } configure; } u; } twin_event_t; @@ -283,11 +292,11 @@ */ typedef enum _twin_window_style { - WindowPlain, - WindowApplication, - WindowFullScreen, - WindowDialog, - WindowAlert, + TwinWindowPlain, + TwinWindowApplication, + TwinWindowFullScreen, + TwinWindowDialog, + TwinWindowAlert, } twin_window_style_t; typedef void (*twin_draw_func_t) (twin_window_t *window); @@ -324,28 +333,6 @@ } twin_icon_t; /* - * Widgets - */ - -typedef enum _twin_box_layout { - TwinLayoutHorz, TwinLayoutVert -} twin_box_layout_t; - -typedef struct _twin_box { - twin_box_layout_t layout; - twin_rect_t geometry; - -} twin_box_t; - -typedef struct { - twin_rect_t geometry; -} twin_widget_t; - -typedef struct { - twin_widget_t core; -} twin_button_t; - -/* * Timeout and work procs return TWIN_TRUE to remain in the queue, * timeout procs are called every 'delay' ms */ @@ -364,16 +351,85 @@ twin_file_op_t ops, void *closure); -typedef void (*twin_block_proc_t) (void *closure); -typedef void (*twin_wakeup_proc_t) (void *closure); - #define twin_time_compare(a,op,b) (((a) - (b)) op 0) typedef struct _twin_timeout twin_timeout_t; typedef struct _twin_work twin_work_t; typedef struct _twin_file twin_file_t; -typedef struct _twin_block twin_block_t; -typedef struct _twin_wakeup twin_wakeup_t; + +/* + * Widgets + */ + +typedef struct _twin_widget twin_widget_t; +typedef struct _twin_box twin_box_t; + +typedef enum _twin_widget_kind_t { + TwinWidgetToplevel, + TwinWidgetBox, + TwinWidgetLabel, + TwinWidgetGlue, +} twin_widget_kind_t; + +typedef enum _twin_dispatch_result { + TwinDispatchNone, + TwinDispatchPaint, + TwinDispatchConfigure, +} twin_dispatch_result_t; + +typedef enum _twin_layout { + TwinLayoutHorz, TwinLayoutVert +} twin_layout_t; + +typedef twin_dispatch_result_t (*twin_dispatch_proc_t) (twin_widget_t *widget, + twin_event_t *event); + +struct _twin_widget { + twin_window_t *window; + twin_widget_t *next; + twin_box_t *parent; + twin_bool_t paint; + twin_bool_t layout; + twin_bool_t want_focus; + twin_argb32_t background; + twin_rect_t extents; /* current geometry */ + twin_rect_t preferred; /* desired geometry */ + twin_stretch_t hstretch; /* stretch ratio in horizontal dir */ + twin_stretch_t vstretch; /* stretch ratio in vertical dir */ + twin_dispatch_proc_t dispatch; +}; + +struct _twin_box { + twin_widget_t widget; + twin_layout_t layout; + twin_widget_t *children; + twin_widget_t *button_down; + twin_widget_t *focus; +}; + +typedef struct _twin_toplevel { + twin_box_t box; +} twin_toplevel_t; + +typedef struct _twin_label { + twin_widget_t widget; + char *label; + twin_argb32_t foreground; + twin_fixed_t font_size; + twin_style_t font_style; +} twin_label_t; + +typedef struct _twin_glue { + twin_widget_t widget; +} twin_glue_t; + +/* + * twin_box.c + */ + +twin_box_t * +twin_box_create (twin_box_t *parent, + twin_layout_t layout); /* * twin_convolve.c @@ -508,6 +564,24 @@ twin_icon_draw (twin_pixmap_t *pixmap, twin_icon_t icon, twin_matrix_t matrix); /* + * twin_label.c + */ + +twin_label_t * +twin_label_create (twin_box_t *parent, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style); + +void +twin_label_set (twin_label_t *label, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style); + +/* * twin_matrix.c */ @@ -676,6 +750,9 @@ twin_coord_t left, twin_coord_t top, twin_coord_t right, twin_coord_t bottom); +void +twin_pixmap_set_clip (twin_pixmap_t *pixmap, twin_rect_t clip); + twin_rect_t twin_pixmap_current_clip (twin_pixmap_t *pixmap); @@ -795,9 +872,9 @@ #define twin_time_compare(a,op,b) (((a) - (b)) op 0) twin_timeout_t * -twin_set_timeout (twin_timeout_proc_t timeout_proc, - twin_time_t delay, - void *closure); +twin_set_timeout (twin_timeout_proc_t timeout_proc, + twin_time_t delay, + void *closure); void twin_clear_timeout (twin_timeout_t *timeout); @@ -806,6 +883,22 @@ twin_now (void); /* + * twin_toplevel.c + */ +twin_toplevel_t * +twin_toplevel_create (twin_screen_t *screen, + twin_format_t format, + twin_window_style_t style, + twin_coord_t x, + twin_coord_t y, + twin_coord_t width, + twin_coord_t height, + const char *name); + +void +twin_toplevel_show (twin_toplevel_t *toplevel); + +/* * twin_trig.c */ @@ -819,6 +912,21 @@ twin_tan (twin_angle_t a); /* + * twin_widget.c + */ + +twin_widget_t * +twin_widget_create (twin_box_t *parent, + twin_argb32_t background, + twin_coord_t width, + twin_coord_t height, + twin_stretch_t hstretch, + twin_stretch_t vstretch); + +void +twin_widget_set (twin_widget_t *widget, twin_argb32_t background); + +/* * twin_window.c */ @@ -866,12 +974,14 @@ * twin_work.c */ -#define TWIN_WORK_REDISPLAY 0 +#define TWIN_WORK_REDISPLAY 0 +#define TWIN_WORK_PAINT 1 +#define TWIN_WORK_LAYOUT 2 twin_work_t * -twin_set_work (twin_work_proc_t work_proc, - int priority, - void *closure); +twin_set_work (twin_work_proc_t work_proc, + int priority, + void *closure); void twin_clear_work (twin_work_t *work); --- NEW FILE: twin_box.c --- (This appears to be a binary file; contents omitted.) Index: twin_clock.c =================================================================== RCS file: /local/src/CVS/twin/twin_clock.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_clock.c 25 Oct 2004 19:09:35 -0000 1.1 +++ twin_clock.c 26 Oct 2004 06:15:42 -0000 1.2 @@ -223,7 +223,7 @@ struct timeval tv; twin_time_t to; twin_window_t *clock = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); twin_window_set_name (clock, name); twin_clock_timeout (0, clock); Index: twin_demo.c =================================================================== RCS file: /local/src/CVS/twin/twin_demo.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_demo.c 25 Oct 2004 19:09:35 -0000 1.1 +++ twin_demo.c 26 Oct 2004 06:15:42 -0000 1.2 @@ -26,18 +26,21 @@ #define D(x) twin_double_to_fixed(x) +#if 0 static int styles[] = { TWIN_TEXT_ROMAN, TWIN_TEXT_OBLIQUE, TWIN_TEXT_BOLD, TWIN_TEXT_BOLD|TWIN_TEXT_OBLIQUE }; +#endif +#if 0 static void twin_example_start (twin_screen_t *screen, int x, int y, int w, int h) { twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); int wid = window->client.right - window->client.left; int hei = window->client.bottom - window->client.top; @@ -67,12 +70,13 @@ twin_pixmap_destroy (alpha); twin_window_show (window); } +#endif static void twin_line_start (twin_screen_t *screen, int x, int y, int w, int h) { twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); int wid = window->client.right - window->client.left; int hei = window->client.bottom - window->client.top; @@ -120,7 +124,7 @@ twin_circletext_start (twin_screen_t *screen, int x, int y, int w, int h) { twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); int wid = window->client.right - window->client.left; int hei = window->client.bottom - window->client.top; @@ -165,7 +169,7 @@ twin_quickbrown_start (twin_screen_t *screen, int x, int y, int w, int h) { twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); int wid = window->client.right - window->client.left; int hei = window->client.bottom - window->client.top; @@ -214,7 +218,7 @@ twin_ascii_start (twin_screen_t *screen, int x, int y, int w, int h) { twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); int wid = window->client.right - window->client.left; int hei = window->client.bottom - window->client.top; @@ -268,7 +272,7 @@ twin_jelly_start (twin_screen_t *screen, int x, int y, int w, int h) { twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x, y, w, h); int wid = window->client.right - window->client.left; int hei = window->client.bottom - window->client.top; @@ -321,11 +325,6 @@ twin_window_show (window); } -static void -twin_extents_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h) -{ -} - void twin_demo_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h) { Index: twin_glyphs.c =================================================================== RCS file: /local/src/CVS/twin/twin_glyphs.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_glyphs.c 4 Oct 2004 08:30:35 -0000 1.5 +++ twin_glyphs.c 26 Oct 2004 06:15:42 -0000 1.6 @@ -208,12 +208,12 @@ 'c', 28, -42, 19, -42, 14, -42, 'e', /* 0x31 '1' offset 666 */ - 0, 10, 42, 0, 2, 3, - 0, 10, /* snap_x */ + 0, 28, 42, 0, 2, 3, + 0, 14, 28 /* snap_x */ -21, -15, 0, /* snap_y */ - 'm', 0, -34, - 'c', 4, -35, 8, -38, 10, -42, - 'l', 10, 0, + 'm', 4, -34, + 'c', 8, -35, 12, -38, 14, -42, + 'l', 14, 0, 'e', /* 0x32 '2' offset 691 */ 0, 28, 42, 0, 4, 4, @@ -238,7 +238,7 @@ 'c', 8, 0, 3, -1, 0, -8, 'e', /* 0x34 '4' offset 780 */ - 0, 30, 42, 0, 3, 4, + 0, 28, 42, 0, 3, 4, 0, 20, 30, /* snap_x */ -21, -15, -14, 0, /* snap_y */ 'm', 20, -42, @@ -260,7 +260,7 @@ 'c', 10, 0, 3, 0, 0, -8, 'e', /* 0x36 '6' offset 860 */ - 0, 26, 42, 0, 2, 5, + 0, 28, 42, 0, 2, 5, 0, 26, /* snap_x */ -42, -26, -21, -15, 0, /* snap_y */ 'm', 24, -36, @@ -293,7 +293,7 @@ 'c', 26, -40, 23, -42, 14, -42, 'e', /* 0x39 '9' offset 1004 */ - 0, 26, 42, 0, 2, 5, + 0, 28, 42, 0, 2, 5, 0, 26, /* snap_x */ -42, -21, -16, -15, 0, /* snap_y */ 'm', 26, -28, --- NEW FILE: twin_hello.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_label.c --- (This appears to be a binary file; contents omitted.) Index: twin_pixmap.c =================================================================== RCS file: /local/src/CVS/twin/twin_pixmap.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- twin_pixmap.c 25 Oct 2004 19:09:36 -0000 1.6 +++ twin_pixmap.c 26 Oct 2004 06:15:42 -0000 1.7 @@ -196,6 +196,16 @@ pixmap->clip.bottom = pixmap->clip.top = 0; } +void +twin_pixmap_set_clip (twin_pixmap_t *pixmap, twin_rect_t clip) +{ + twin_pixmap_clip (pixmap, + clip.left + pixmap->clip.left, + clip.top + pixmap->clip.top, + clip.right + pixmap->clip.left, + clip.bottom+ pixmap->clip.top); +} + twin_rect_t twin_pixmap_current_clip (twin_pixmap_t *pixmap) { Index: twin_screen.c =================================================================== RCS file: /local/src/CVS/twin/twin_screen.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- twin_screen.c 25 Oct 2004 19:09:36 -0000 1.8 +++ twin_screen.c 26 Oct 2004 06:15:42 -0000 1.9 @@ -225,12 +225,12 @@ screen->active = pixmap; if (old) { - ev.kind = EventDeactivate; + ev.kind = TwinEventDeactivate; twin_pixmap_dispatch (old, &ev); } if (pixmap) { - ev.kind = EventActivate; + ev.kind = TwinEventActivate; twin_pixmap_dispatch (pixmap, &ev); } } @@ -263,9 +263,9 @@ twin_pixmap_t *pixmap; switch (event->kind) { - case EventMotion: - case EventButtonDown: - case EventButtonUp: + case TwinEventMotion: + case TwinEventButtonDown: + case TwinEventButtonUp: pixmap = screen->pointer; if (!pixmap) { @@ -276,10 +276,10 @@ { break; } - if (event->kind == EventButtonDown) + if (event->kind == TwinEventButtonDown) screen->pointer = pixmap; } - if (event->kind == EventButtonUp) + if (event->kind == TwinEventButtonUp) screen->pointer = NULL; if (pixmap) { @@ -287,9 +287,9 @@ event->u.pointer.y = event->u.pointer.screen_y - pixmap->y; } break; - case EventKeyDown: - case EventKeyUp: - case EventUcs4: + case TwinEventKeyDown: + case TwinEventKeyUp: + case TwinEventUcs4: pixmap = screen->active; break; default: Index: twin_text.c =================================================================== RCS file: /local/src/CVS/twin/twin_text.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_text.c 25 Oct 2004 19:09:36 -0000 1.1 +++ twin_text.c 26 Oct 2004 06:15:42 -0000 1.2 @@ -30,7 +30,7 @@ twin_text_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h) { twin_window_t *text = twin_window_create (screen, TWIN_ARGB32, - WindowApplication, + TwinWindowApplication, x,y,w,h); twin_fixed_t fx, fy; static const char *lines[] = { --- NEW FILE: twin_toplevel.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_widget.c --- (This appears to be a binary file; contents omitted.) Index: twin_window.c =================================================================== RCS file: /local/src/CVS/twin/twin_window.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_window.c 25 Oct 2004 19:09:36 -0000 1.3 +++ twin_window.c 26 Oct 2004 06:15:42 -0000 1.4 @@ -49,13 +49,13 @@ window->screen = screen; window->style = style; switch (window->style) { - case WindowApplication: + case TwinWindowApplication: left = TWIN_BW; top = TWIN_BW + TWIN_TITLE_HEIGHT + TWIN_BW; right = TWIN_BW + TWIN_RESIZE_SIZE; bottom = TWIN_BW + TWIN_RESIZE_SIZE; break; - case WindowPlain: + case TwinWindowPlain: default: left = 0; top = 0; @@ -153,11 +153,11 @@ twin_rect_t *size) { switch (style) { - case WindowPlain: + case TwinWindowPlain: default: size->left = size->right = size->top = size->bottom = 0; break; - case WindowApplication: + case TwinWindowApplication: size->left = TWIN_BW; size->right = TWIN_BW; size->top = TWIN_BW + TWIN_TITLE_HEIGHT + TWIN_BW; @@ -315,10 +315,10 @@ twin_window_draw (twin_window_t *window) { switch (window->style) { - case WindowPlain: + case TwinWindowPlain: default: break; - case WindowApplication: + case TwinWindowApplication: twin_window_frame (window); break; } @@ -329,18 +329,47 @@ twin_bool_t twin_window_dispatch (twin_window_t *window, twin_event_t *event) { - if (window->event && (*window->event) (window, event)) + twin_event_t ev = *event; + twin_bool_t delegate = TWIN_TRUE; + + if (!window->event) + delegate = TWIN_FALSE; + + switch (ev.kind) { + case TwinEventButtonDown: + if (ev.u.pointer.x < window->client.left || + window->client.right <= ev.u.pointer.x || + ev.u.pointer.y < window->client.top || + window->client.bottom <= ev.u.pointer.y) + { + delegate = TWIN_FALSE; + break; + } + /* fall through... */ + case TwinEventButtonUp: + case TwinEventMotion: + ev.u.pointer.x -= window->client.left; + ev.u.pointer.y -= window->client.top; + break; + default: + break; + } + if (delegate && (*window->event) (window, &ev)) return TWIN_TRUE; + + /* + * simple window management + */ switch (event->kind) { - case EventButtonDown: + case TwinEventButtonDown: twin_window_show (window); window->screen->button_x = event->u.pointer.x; window->screen->button_y = event->u.pointer.y; return TWIN_TRUE; - case EventButtonUp: + case TwinEventButtonUp: window->screen->button_x = -1; window->screen->button_y = -1; - case EventMotion: + case TwinEventMotion: if (window->screen->button_x >= 0) { twin_coord_t x, y; Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_x11.c 25 Oct 2004 19:09:36 -0000 1.7 +++ twin_x11.c 26 Oct 2004 06:15:42 -0000 1.8 @@ -106,13 +106,13 @@ tev.u.pointer.screen_x = ev.xbutton.x; tev.u.pointer.screen_y = ev.xbutton.y; tev.kind = ((ev.type == ButtonPress) ? - EventButtonDown : EventButtonUp); + TwinEventButtonDown : TwinEventButtonUp); twin_screen_dispatch (tx->screen, &tev); break; case MotionNotify: tev.u.pointer.screen_x = ev.xmotion.x; tev.u.pointer.screen_y = ev.xmotion.y; - tev.kind = EventMotion; + tev.kind = TwinEventMotion; tev.u.pointer.button = ev.xmotion.state; twin_screen_dispatch (tx->screen, &tev); break; Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- twinint.h 25 Oct 2004 19:09:36 -0000 1.13 +++ twinint.h 26 Oct 2004 06:15:42 -0000 1.14 @@ -412,18 +412,6 @@ void *closure; }; -struct _twin_block { - twin_queue_t queue; - twin_block_proc_t proc; - void *closure; -}; - -struct _twin_wakeup { - twin_queue_t queue; - twin_wakeup_proc_t proc; - void *closure; -}; - typedef enum _twin_order { TWIN_BEFORE = -1, TWIN_AT = 0, @@ -463,4 +451,58 @@ void _twin_run_work (void); +void +_twin_box_init (twin_box_t *box, + twin_box_t *parent, + twin_window_t *window, + twin_layout_t layout, + twin_dispatch_proc_t dispatch); + +twin_dispatch_result_t +_twin_box_dispatch (twin_widget_t *widget, twin_event_t *event); + +void +_twin_widget_init (twin_widget_t *widget, + twin_box_t *parent, + twin_window_t *window, + twin_rect_t preferred, + twin_stretch_t hstretch, + twin_stretch_t vstretch, + twin_dispatch_proc_t dispatch); + +twin_dispatch_result_t +_twin_widget_dispatch (twin_widget_t *widget, twin_event_t *event); + +void +_twin_widget_queue_paint (twin_widget_t *widget); + +void +_twin_widget_queue_layout (twin_widget_t *widget); + +void +_twin_label_init (twin_label_t *label, + twin_box_t *parent, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style); + +twin_dispatch_result_t +_twin_label_dispatch (twin_widget_t *widget, twin_event_t *event); + +twin_dispatch_result_t +_twin_toplevel_dispatch (twin_widget_t *widget, twin_event_t *event); + +void +_twin_toplevel_init (twin_toplevel_t *toplevel, + twin_dispatch_proc_t dispatch, + twin_window_t *window, + const char *name); + +void +_twin_toplevel_queue_paint (twin_widget_t *widget); + +void +_twin_toplevel_queue_layout (twin_widget_t *widget); + #endif /* _TWININT_H_ */ Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- xtwin.c 25 Oct 2004 19:09:36 -0000 1.20 +++ xtwin.c 26 Oct 2004 06:15:42 -0000 1.21 @@ -43,10 +43,14 @@ twin_x11_t *x11 = twin_x11_create (dpy, WIDTH, HEIGHT); twin_screen_set_background (x11->screen, twin_make_pattern ()); +#if 0 twin_demo_start (x11->screen, "Demo", 100, 100, 400, 400); twin_clock_start (x11->screen, "Clock", 10, 10, 200, 200); twin_text_start (x11->screen, "Gettysburg Address", 0, 0, 300, 300); +#endif + twin_hello_start (x11->screen, "Hello, World", + 0, 0, 100, 100); twin_dispatch (); return 0; } From commit at keithp.com Tue Oct 26 12:56:22 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 26 12:56:29 2004 Subject: [Commit] twin ChangeLog, 1.22, 1.23 Makefile.am, 1.11, 1.12 twin.h, 1.17, 1.18 twin_button.c, NONE, 1.1 twin_hello.c, 1.1, 1.2 twin_hello.h, NONE, 1.1 twin_label.c, 1.1, 1.2 twin_widget.c, 1.1, 1.2 twin_window.c, 1.4, 1.5 twinint.h, 1.14, 1.15 xtwin.c, 1.21, 1.22 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv9281 Modified Files: ChangeLog Makefile.am twin.h twin_hello.c twin_label.c twin_widget.c twin_window.c twinint.h xtwin.c Added Files: twin_button.c twin_hello.h Log Message: 2004-10-26 Keith Packard * Makefile.am: * twin_button.c: (_twin_button_paint), (_twin_button_set_label_offset), (_twin_button_dispatch), (_twin_button_init), (twin_button_create): Add button widget * twin.h: * twinint.h: Grab button down inside client area. Add button widget * twin_hello.c: (twin_hello_start): * twin_hello.h: Test button widget * twin_label.c: (_twin_label_paint), (_twin_label_init), (twin_label_create): Permit subclassing; add offset to make text shift in button * twin_widget.c: (_twin_widget_contains): Add _twin_widget_contains to test inclusion * twin_window.c: (twin_window_create), (twin_window_dispatch): Grab button down inside client area * xtwin.c: (main): Make hello window larger Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- ChangeLog 26 Oct 2004 06:15:42 -0000 1.22 +++ ChangeLog 26 Oct 2004 19:56:18 -0000 1.23 @@ -1,3 +1,33 @@ +2004-10-26 Keith Packard + + * Makefile.am: + * twin_button.c: (_twin_button_paint), + (_twin_button_set_label_offset), (_twin_button_dispatch), + (_twin_button_init), (twin_button_create): + Add button widget + + * twin.h: + * twinint.h: + Grab button down inside client area. + Add button widget + + * twin_hello.c: (twin_hello_start): + * twin_hello.h: + Test button widget + + * twin_label.c: (_twin_label_paint), (_twin_label_init), + (twin_label_create): + Permit subclassing; add offset to make text shift in button + + * twin_widget.c: (_twin_widget_contains): + Add _twin_widget_contains to test inclusion + + * twin_window.c: (twin_window_create), (twin_window_dispatch): + Grab button down inside client area + + * xtwin.c: (main): + Make hello window larger + 2004-10-25 Keith Packard * Makefile.am: Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Makefile.am 26 Oct 2004 06:15:42 -0000 1.11 +++ Makefile.am 26 Oct 2004 19:56:18 -0000 1.12 @@ -16,6 +16,7 @@ xtwin_SOURCES = \ twin.h \ twin_box.c \ + twin_button.c \ twin_convolve.c \ twin_dispatch.c \ twin_draw.c \ Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- twin.h 26 Oct 2004 06:15:42 -0000 1.17 +++ twin.h 26 Oct 2004 19:56:18 -0000 1.18 @@ -312,6 +312,8 @@ twin_window_style_t style; twin_rect_t client; twin_rect_t damage; + twin_bool_t client_grab; + twin_bool_t want_focus; void *client_data; char *name; @@ -364,12 +366,11 @@ typedef struct _twin_widget twin_widget_t; typedef struct _twin_box twin_box_t; -typedef enum _twin_widget_kind_t { - TwinWidgetToplevel, - TwinWidgetBox, - TwinWidgetLabel, - TwinWidgetGlue, -} twin_widget_kind_t; +#define _twin_widget_width(w) (((twin_widget_t *)(w))->extents.right - \ + ((twin_widget_t *)(w))->extents.left) + +#define _twin_widget_height(w) (((twin_widget_t *)(w))->extents.bottom - \ + ((twin_widget_t *)(w))->extents.top) typedef enum _twin_dispatch_result { TwinDispatchNone, @@ -417,11 +418,18 @@ twin_argb32_t foreground; twin_fixed_t font_size; twin_style_t font_style; + twin_point_t offset; } twin_label_t; -typedef struct _twin_glue { - twin_widget_t widget; -} twin_glue_t; +typedef void (*twin_callback_t) (twin_widget_t *widget, void *closure); + +typedef struct _twin_button { + twin_label_t label; + twin_bool_t pressed; + twin_bool_t active; + twin_callback_t callback; + void *closure; +} twin_button_t; /* * twin_box.c @@ -432,6 +440,17 @@ twin_layout_t layout); /* + * twin_button.c + */ + +twin_button_t * +twin_button_create (twin_box_t *parent, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style); + +/* * twin_convolve.c */ void --- NEW FILE: twin_button.c --- (This appears to be a binary file; contents omitted.) Index: twin_hello.c =================================================================== RCS file: /local/src/CVS/twin/twin_hello.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_hello.c 26 Oct 2004 06:15:42 -0000 1.1 +++ twin_hello.c 26 Oct 2004 19:56:19 -0000 1.2 @@ -22,7 +22,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -#include +#include "twin_hello.h" #include static twin_time_t @@ -58,8 +58,15 @@ 0xff008000, twin_int_to_fixed (12), TWIN_TEXT_OBLIQUE); + twin_button_t *button = twin_button_create (&top->box, + "Button", + 0xff800000, + twin_int_to_fixed (18), + TWIN_TEXT_BOLD); twin_widget_set (&labela->widget, 0xc0c0c0c0); + (void) widget; twin_widget_set (&labelb->widget, 0xc0c0c0c0); + twin_widget_set (&button->label.widget, 0xc0808080); twin_toplevel_show (top); twin_set_timeout (_twin_hello_timeout, 1000, labelb); } --- NEW FILE: twin_hello.h --- (This appears to be a binary file; contents omitted.) Index: twin_label.c =================================================================== RCS file: /local/src/CVS/twin/twin_label.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_label.c 26 Oct 2004 06:15:42 -0000 1.1 +++ twin_label.c 26 Oct 2004 19:56:19 -0000 1.2 @@ -49,8 +49,8 @@ { twin_path_t *path = twin_path_create (); twin_text_metrics_t m; - twin_coord_t w = label->widget.extents.right - label->widget.extents.left; - twin_coord_t h = label->widget.extents.bottom - label->widget.extents.top; + twin_coord_t w = _twin_widget_width(label); + twin_coord_t h = _twin_widget_height(label); if (path) { @@ -60,8 +60,8 @@ twin_path_set_font_size (path, label->font_size); twin_path_set_font_style (path, label->font_style); twin_text_metrics_utf8 (path, label->label, &m); - twin_path_move (path, (wf - m.width) / 2, - (hf - (m.font_ascent + m.font_descent)) / 2 + m.font_ascent); + twin_path_move (path, (wf - m.width) / 2 + label->offset.x, + (hf - (m.ascent + m.descent)) / 2 + m.ascent + label->offset.y); twin_path_utf8 (path, label->label); twin_paint_path (label->widget.window->pixmap, label->foreground, path); @@ -114,17 +114,20 @@ } void -_twin_label_init (twin_label_t *label, - twin_box_t *parent, - const char *value, - twin_argb32_t foreground, - twin_fixed_t font_size, - twin_style_t font_style) +_twin_label_init (twin_label_t *label, + twin_box_t *parent, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style, + twin_dispatch_proc_t dispatch) { static const twin_rect_t empty = { 0, 0, 0, 0 }; _twin_widget_init (&label->widget, parent, 0, - empty, 1, 1, _twin_label_dispatch); + empty, 1, 1, dispatch); label->label = NULL; + label->offset.x = 0; + label->offset.y = 0; twin_label_set (label, value, foreground, font_size, font_style); } @@ -140,7 +143,8 @@ if (!label) return 0; - _twin_label_init (label, parent, value, foreground, font_size, font_style); + _twin_label_init (label, parent, value, foreground, + font_size, font_style, _twin_label_dispatch); return label; } Index: twin_widget.c =================================================================== RCS file: /local/src/CVS/twin/twin_widget.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_widget.c 26 Oct 2004 06:15:42 -0000 1.1 +++ twin_widget.c 26 Oct 2004 19:56:19 -0000 1.2 @@ -113,6 +113,15 @@ _twin_toplevel_queue_layout (widget); } +twin_bool_t +_twin_widget_contains (twin_widget_t *widget, + twin_coord_t x, + twin_coord_t y) +{ + return (0 <= x && x < _twin_widget_width(widget) && + 0 <= y && y < _twin_widget_height(widget)); +} + twin_widget_t * twin_widget_create (twin_box_t *parent, twin_argb32_t background, Index: twin_window.c =================================================================== RCS file: /local/src/CVS/twin/twin_window.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_window.c 26 Oct 2004 06:15:42 -0000 1.4 +++ twin_window.c 26 Oct 2004 19:56:19 -0000 1.5 @@ -77,6 +77,8 @@ twin_pixmap_move (window->pixmap, x, y); window->damage.left = window->damage.right = 0; window->damage.top = window->damage.bottom = 0; + window->client_grab = TWIN_FALSE; + window->want_focus = TWIN_FALSE; window->client_data = 0; window->name = 0; @@ -337,19 +339,43 @@ switch (ev.kind) { case TwinEventButtonDown: - if (ev.u.pointer.x < window->client.left || - window->client.right <= ev.u.pointer.x || - ev.u.pointer.y < window->client.top || - window->client.bottom <= ev.u.pointer.y) + if (window->client.left <= ev.u.pointer.x && + ev.u.pointer.x < window->client.right && + window->client.top <= ev.u.pointer.y && + ev.u.pointer.y < window->client.bottom) { - delegate = TWIN_FALSE; - break; + delegate = TWIN_TRUE; + window->client_grab = TWIN_TRUE; + ev.u.pointer.x -= window->client.left; + ev.u.pointer.y -= window->client.top; } - /* fall through... */ + else + delegate = TWIN_FALSE; + break; case TwinEventButtonUp: + if (window->client_grab) + { + delegate = TWIN_TRUE; + window->client_grab = TWIN_FALSE; + ev.u.pointer.x -= window->client.left; + ev.u.pointer.y -= window->client.top; + } + else + delegate = TWIN_FALSE; + break; case TwinEventMotion: - ev.u.pointer.x -= window->client.left; - ev.u.pointer.y -= window->client.top; + if (window->client_grab || + (window->client.left <= ev.u.pointer.x && + ev.u.pointer.x < window->client.right && + window->client.top <= ev.u.pointer.y && + ev.u.pointer.y < window->client.bottom)) + { + delegate = TWIN_TRUE; + ev.u.pointer.x -= window->client.left; + ev.u.pointer.y -= window->client.top; + } + else + delegate = TWIN_FALSE; break; default: break; Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- twinint.h 26 Oct 2004 06:15:42 -0000 1.14 +++ twinint.h 26 Oct 2004 19:56:19 -0000 1.15 @@ -479,13 +479,19 @@ void _twin_widget_queue_layout (twin_widget_t *widget); +twin_bool_t +_twin_widget_contains (twin_widget_t *widget, + twin_coord_t x, + twin_coord_t y); + void -_twin_label_init (twin_label_t *label, - twin_box_t *parent, - const char *value, - twin_argb32_t foreground, - twin_fixed_t font_size, - twin_style_t font_style); +_twin_label_init (twin_label_t *label, + twin_box_t *parent, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style, + twin_dispatch_proc_t dispatch); twin_dispatch_result_t _twin_label_dispatch (twin_widget_t *widget, twin_event_t *event); @@ -505,4 +511,16 @@ void _twin_toplevel_queue_layout (twin_widget_t *widget); +twin_dispatch_result_t +_twin_button_dispatch (twin_widget_t *widget, twin_event_t *event); + +void +_twin_button_init (twin_button_t *button, + twin_box_t *parent, + const char *value, + twin_argb32_t foreground, + twin_fixed_t font_size, + twin_style_t font_style, + twin_dispatch_proc_t dispatch); + #endif /* _TWININT_H_ */ Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- xtwin.c 26 Oct 2004 06:15:42 -0000 1.21 +++ xtwin.c 26 Oct 2004 19:56:19 -0000 1.22 @@ -32,6 +32,7 @@ #include #include #include +#include #define WIDTH 512 #define HEIGHT 512 @@ -50,7 +51,7 @@ 0, 0, 300, 300); #endif twin_hello_start (x11->screen, "Hello, World", - 0, 0, 100, 100); + 0, 0, 200, 200); twin_dispatch (); return 0; } From commit at keithp.com Tue Oct 26 19:46:42 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 26 19:46:47 2004 Subject: [Commit] twin ChangeLog, 1.23, 1.24 twin_button.c, 1.1, 1.2 twin_font.c, 1.13, 1.14 twin_hello.c, 1.2, 1.3 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv19289 Modified Files: ChangeLog twin_button.c twin_font.c twin_hello.c Log Message: 2004-10-26 Keith Packard * twin_button.c: (_twin_button_paint): Paint polygons instead of stroked lines for button edges * twin_font.c: (_twin_text_compute_info): Snap origin to pixel grid * twin_hello.c: (_twin_hello_timeout): Strip newline from ctime output Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- ChangeLog 26 Oct 2004 19:56:18 -0000 1.23 +++ ChangeLog 27 Oct 2004 02:46:39 -0000 1.24 @@ -1,5 +1,16 @@ 2004-10-26 Keith Packard + * twin_button.c: (_twin_button_paint): + Paint polygons instead of stroked lines for button edges + + * twin_font.c: (_twin_text_compute_info): + Snap origin to pixel grid + + * twin_hello.c: (_twin_hello_timeout): + Strip newline from ctime output + +2004-10-26 Keith Packard + * Makefile.am: * twin_button.c: (_twin_button_paint), (_twin_button_set_label_offset), (_twin_button_dispatch), Index: twin_button.c =================================================================== RCS file: /local/src/CVS/twin/twin_button.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_button.c 26 Oct 2004 19:56:19 -0000 1.1 +++ twin_button.c 27 Oct 2004 02:46:40 -0000 1.2 @@ -35,7 +35,6 @@ twin_fixed_t wf = twin_int_to_fixed (w); twin_fixed_t hf = twin_int_to_fixed (h); twin_fixed_t bf = _twin_button_bw (button); - twin_fixed_t bh = bf / 2; twin_argb32_t top_color, bot_color; twin_pixmap_t *pixmap = button->label.widget.window->pixmap; @@ -51,15 +50,23 @@ top_color = 0x80808080; bot_color = 0x80000000; } - twin_path_move (path, bh, hf-bh); - twin_path_draw (path, bh, bh); - twin_path_draw (path, wf-bh, bh); - twin_paint_stroke (pixmap, top_color, path, bf); + twin_path_move (path, 0, 0); + twin_path_draw (path, wf, 0); + twin_path_draw (path, wf-bf, bf); + twin_path_draw (path, bf, bf); + twin_path_draw (path, bf, hf-bf); + twin_path_draw (path, 0, hf); + twin_path_close (path); + twin_paint_path (pixmap, top_color, path); twin_path_empty (path); - twin_path_move (path, bh, hf-bh); - twin_path_draw (path, wf-bh, hf-bh); - twin_path_draw (path, wf-bh, bh); - twin_paint_stroke (pixmap, bot_color, path, bf); + twin_path_move (path, bf, hf-bf); + twin_path_draw (path, wf-bf, hf-bf); + twin_path_draw (path, wf-bf, bf); + twin_path_draw (path, wf, 0); + twin_path_draw (path, wf, hf); + twin_path_draw (path, 0, hf); + twin_path_close (path); + twin_paint_path (pixmap, bot_color, path); twin_path_destroy (path); } } Index: twin_font.c =================================================================== RCS file: /local/src/CVS/twin/twin_font.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- twin_font.c 5 Oct 2004 18:42:53 -0000 1.13 +++ twin_font.c 27 Oct 2004 02:46:40 -0000 1.14 @@ -79,8 +79,8 @@ info->matrix.m[xi][1] = 0; info->matrix.m[yi][0] = 0; info->matrix.m[yi][1] = TWIN_FIXED_ONE; - info->matrix.m[2][0] = twin_sfixed_to_fixed (origin.x); - info->matrix.m[2][1] = twin_sfixed_to_fixed (origin.y); + info->matrix.m[2][0] = SNAPI(twin_sfixed_to_fixed (origin.x)); + info->matrix.m[2][1] = SNAPI(twin_sfixed_to_fixed (origin.y)); info->scale.x = twin_fixed_mul (path->state.font_size, path->state.matrix.m[0][xi]); info->reverse_scale.x = twin_fixed_div (TWIN_FIXED_ONE, Index: twin_hello.c =================================================================== RCS file: /local/src/CVS/twin/twin_hello.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_hello.c 26 Oct 2004 19:56:19 -0000 1.2 +++ twin_hello.c 27 Oct 2004 02:46:40 -0000 1.3 @@ -24,14 +24,17 @@ #include "twin_hello.h" #include +#include static twin_time_t _twin_hello_timeout (twin_time_t now, void *closure) { twin_label_t *labelb = closure; time_t secs = time (0); + char *t = ctime(&secs); - twin_label_set (labelb, ctime (&secs), + *strchr(t, '\n') = '\0'; + twin_label_set (labelb, t, 0xff008000, twin_int_to_fixed (12), TWIN_TEXT_OBLIQUE); From commit at keithp.com Tue Oct 26 23:07:38 2004 From: commit at keithp.com (Keith Packard) Date: Tue Oct 26 23:07:44 2004 Subject: [Commit] twin ChangeLog, 1.24, 1.25 twin_button.c, 1.2, 1.3 twin_dispatch.c, 1.1, 1.2 twin_draw.c, 1.7, 1.8 twin_hello.c, 1.3, 1.4 twin_pixmap.c, 1.7, 1.8 twin_widget.c, 1.2, 1.3 twinint.h, 1.15, 1.16 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv7048 Modified Files: ChangeLog twin_button.c twin_dispatch.c twin_draw.c twin_hello.c twin_pixmap.c twin_widget.c twinint.h Log Message: 2004-10-26 Keith Packard * twin_button.c: (_twin_button_paint): * twin_widget.c: (_twin_widget_bevel): * twinint.h: Move bevel routine to twin_widget for sharing * twin_dispatch.c: (twin_dispatch): Change order of timeout vs work, making work come last as that's where redisplay occurs. * twin_draw.c: (twin_fill): Oops. Argument order wrong in twin_pixmap_damage call * twin_hello.c: (twin_hello_start): Make button italic to test * twin_pixmap.c: (twin_pixmap_damage): Change names of formals to match prototype Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- ChangeLog 27 Oct 2004 02:46:39 -0000 1.24 +++ ChangeLog 27 Oct 2004 06:07:35 -0000 1.25 @@ -1,6 +1,26 @@ 2004-10-26 Keith Packard * twin_button.c: (_twin_button_paint): + * twin_widget.c: (_twin_widget_bevel): + * twinint.h: + Move bevel routine to twin_widget for sharing + + * twin_dispatch.c: (twin_dispatch): + Change order of timeout vs work, making work come last as + that's where redisplay occurs. + + * twin_draw.c: (twin_fill): + Oops. Argument order wrong in twin_pixmap_damage call + + * twin_hello.c: (twin_hello_start): + Make button italic to test + + * twin_pixmap.c: (twin_pixmap_damage): + Change names of formals to match prototype + +2004-10-26 Keith Packard + + * twin_button.c: (_twin_button_paint): Paint polygons instead of stroked lines for button edges * twin_font.c: (_twin_text_compute_info): Index: twin_button.c =================================================================== RCS file: /local/src/CVS/twin/twin_button.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_button.c 27 Oct 2004 02:46:40 -0000 1.2 +++ twin_button.c 27 Oct 2004 06:07:35 -0000 1.3 @@ -29,46 +29,9 @@ static void _twin_button_paint (twin_button_t *button) { - twin_path_t *path = twin_path_create (); - twin_coord_t w = button->label.widget.extents.right - button->label.widget.extents.left; - twin_coord_t h = button->label.widget.extents.bottom - button->label.widget.extents.top; - twin_fixed_t wf = twin_int_to_fixed (w); - twin_fixed_t hf = twin_int_to_fixed (h); - twin_fixed_t bf = _twin_button_bw (button); - twin_argb32_t top_color, bot_color; - twin_pixmap_t *pixmap = button->label.widget.window->pixmap; - - if (path) - { - if (button->active) - { - top_color = 0x80000000; - bot_color = 0x80808080; - } - else - { - top_color = 0x80808080; - bot_color = 0x80000000; - } - twin_path_move (path, 0, 0); - twin_path_draw (path, wf, 0); - twin_path_draw (path, wf-bf, bf); - twin_path_draw (path, bf, bf); - twin_path_draw (path, bf, hf-bf); - twin_path_draw (path, 0, hf); - twin_path_close (path); - twin_paint_path (pixmap, top_color, path); - twin_path_empty (path); - twin_path_move (path, bf, hf-bf); - twin_path_draw (path, wf-bf, hf-bf); - twin_path_draw (path, wf-bf, bf); - twin_path_draw (path, wf, 0); - twin_path_draw (path, wf, hf); - twin_path_draw (path, 0, hf); - twin_path_close (path); - twin_paint_path (pixmap, bot_color, path); - twin_path_destroy (path); - } + _twin_widget_bevel (&button->label.widget, + _twin_button_bw(button), + button->active); } static void Index: twin_dispatch.c =================================================================== RCS file: /local/src/CVS/twin/twin_dispatch.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_dispatch.c 25 Oct 2004 19:09:36 -0000 1.1 +++ twin_dispatch.c 27 Oct 2004 06:07:35 -0000 1.2 @@ -29,8 +29,8 @@ { for (;;) { - _twin_run_work (); _twin_run_timeout (); + _twin_run_work (); _twin_run_file (_twin_timeout_delay ()); } } Index: twin_draw.c =================================================================== RCS file: /local/src/CVS/twin/twin_draw.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_draw.c 25 Oct 2004 19:09:36 -0000 1.7 +++ twin_draw.c 27 Oct 2004 06:07:35 -0000 1.8 @@ -402,5 +402,5 @@ op = fill[operator][dst->format]; for (iy = top; iy < bottom; iy++) (*op) (twin_pixmap_pointer (dst, left, iy), src, right - left); - twin_pixmap_damage (dst, left, right, top, bottom); + twin_pixmap_damage (dst, left, top, right, bottom); } Index: twin_hello.c =================================================================== RCS file: /local/src/CVS/twin/twin_hello.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_hello.c 27 Oct 2004 02:46:40 -0000 1.3 +++ twin_hello.c 27 Oct 2004 06:07:35 -0000 1.4 @@ -65,7 +65,7 @@ "Button", 0xff800000, twin_int_to_fixed (18), - TWIN_TEXT_BOLD); + TWIN_TEXT_BOLD|TWIN_TEXT_OBLIQUE); twin_widget_set (&labela->widget, 0xc0c0c0c0); (void) widget; twin_widget_set (&labelb->widget, 0xc0c0c0c0); Index: twin_pixmap.c =================================================================== RCS file: /local/src/CVS/twin/twin_pixmap.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_pixmap.c 26 Oct 2004 06:15:42 -0000 1.7 +++ twin_pixmap.c 27 Oct 2004 06:07:35 -0000 1.8 @@ -226,16 +226,16 @@ } void -twin_pixmap_damage (twin_pixmap_t *pixmap, - twin_coord_t x1, twin_coord_t y1, - twin_coord_t x2, twin_coord_t y2) +twin_pixmap_damage (twin_pixmap_t *pixmap, + twin_coord_t left, twin_coord_t top, + twin_coord_t right, twin_coord_t bottom) { if (pixmap->screen) twin_screen_damage (pixmap->screen, - x1 + pixmap->x, - y1 + pixmap->y, - x2 + pixmap->x, - y2 + pixmap->y); + left + pixmap->x, + top + pixmap->y, + right + pixmap->x, + bottom + pixmap->y); } static twin_argb32_t Index: twin_widget.c =================================================================== RCS file: /local/src/CVS/twin/twin_widget.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_widget.c 26 Oct 2004 19:56:19 -0000 1.2 +++ twin_widget.c 27 Oct 2004 06:07:35 -0000 1.3 @@ -122,6 +122,50 @@ 0 <= y && y < _twin_widget_height(widget)); } +void +_twin_widget_bevel (twin_widget_t *widget, + twin_fixed_t b, + twin_bool_t down) +{ + twin_path_t *path = twin_path_create (); + twin_fixed_t w = twin_int_to_fixed (_twin_widget_width (widget)); + twin_fixed_t h = twin_int_to_fixed (_twin_widget_height (widget)); + twin_argb32_t top_color, bot_color; + twin_pixmap_t *pixmap = widget->window->pixmap; + + if (path) + { + if (down) + { + top_color = 0x80000000; + bot_color = 0x80808080; + } + else + { + top_color = 0x80808080; + bot_color = 0x80000000; + } + twin_path_move (path, 0, 0); + twin_path_draw (path, w, 0); + twin_path_draw (path, w-b, b); + twin_path_draw (path, b, b); + twin_path_draw (path, b, h-b); + twin_path_draw (path, 0, h); + twin_path_close (path); + twin_paint_path (pixmap, top_color, path); + twin_path_empty (path); + twin_path_move (path, b, h-b); + twin_path_draw (path, w-b, h-b); + twin_path_draw (path, w-b, b); + twin_path_draw (path, w, 0); + twin_path_draw (path, w, h); + twin_path_draw (path, 0, h); + twin_path_close (path); + twin_paint_path (pixmap, bot_color, path); + twin_path_destroy (path); + } +} + twin_widget_t * twin_widget_create (twin_box_t *parent, twin_argb32_t background, Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- twinint.h 26 Oct 2004 19:56:19 -0000 1.15 +++ twinint.h 27 Oct 2004 06:07:35 -0000 1.16 @@ -485,6 +485,11 @@ twin_coord_t y); void +_twin_widget_bevel (twin_widget_t *widget, + twin_fixed_t bevel_width, + twin_bool_t down); + +void _twin_label_init (twin_label_t *label, twin_box_t *parent, const char *value, From commit at keithp.com Wed Oct 27 10:58:24 2004 From: commit at keithp.com (Keith Packard) Date: Wed Oct 27 10:58:30 2004 Subject: [Commit] jove ChangeLog,1.4,1.5 insert.c,1.7,1.8 util.c,1.5,1.6 Message-ID: Committed by: keithp Update of /local/src/CVS/jove In directory home.keithp.com:/tmp/cvs-serv6567 Modified Files: ChangeLog insert.c util.c Log Message: 2004-10-27 Keith Packard * insert.c: Add a bunch more compose sequences * util.c: Warn when displaying buffer of externally modified file Index: ChangeLog =================================================================== RCS file: /local/src/CVS/jove/ChangeLog,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ChangeLog 20 Oct 2004 05:26:40 -0000 1.4 +++ ChangeLog 27 Oct 2004 17:58:21 -0000 1.5 @@ -1,3 +1,11 @@ +2004-10-27 Keith Packard + + * insert.c: + Add a bunch more compose sequences + + * util.c: + Warn when displaying buffer of externally modified file + 2004-10-19 Keith Packard * abbrev.c: Index: insert.c =================================================================== RCS file: /local/src/CVS/jove/insert.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- insert.c 20 Oct 2004 05:26:40 -0000 1.7 +++ insert.c 27 Oct 2004 17:58:21 -0000 1.8 @@ -467,21 +467,24 @@ "!:¡|c:¢#:£$:¤y:¥| :¦ss:§\" :¨cr:©_a:ª<<:«~ :¬- :­rc:®__:¯" ". :°+-:±1 :¹2 :²3 :³' :´,u:µpp:¶ .:·, :¸m:º>>:»14:¼12:½34:¾?:¿" "`A:À'A:Á^A:Â~A:Ã\"A:Ä.A:ÅAE:Æ,C:Ç`E:È'E:É^E:Ê\"E:Ë`I:Ì'I:Í^I:Î\"I:Ï" -"-D:Ð~N:Ñ`O:Ò'O:Ó^O:Ô~O:Õ\"O:Ö* :×/O:Ø`U:Ù'U:Ú^U:Û\"U:Ü'Y:ÝTH:ÞSS:ß" +"-D:Ð~N:Ñ`O:Ò'O:Ó^O:Ô~O:Õ\"O:Ö* :×/O:Ø`U:Ù'U:Ú^U:Û\"U:Ü'Y:ÝTR:ÞSS:ß" "`a:à'a:á^a:â~a:ã\"a:ä.a:åae:æ,c:ç`e:è'e:é^e:ê\"e:ë`i:ì'i:í^i:î\"i:ï" -"et:ð~n:ñ`o:ò'o:ó^o:ô~o:õ\"o:ö/ :÷/o:ø`u:ù'u:ú^u:û\"u:ü'y:ýth:þ\"y:ÿ" +"et:ð~n:ñ`o:ò'o:ó^o:ô~o:õ\"o:ö/ :÷/o:ø`u:ù'u:ú^u:û\"u:ü'y:ýtr:þ\"y:ÿ" /* extended latin */ "'C:Ć'c:ćvC:Čvc:č-d:đvG:Ğvg:ğ.I:İ.i:ı/L:Ł/l:łOE:Œoe:œ,S:Ş,s:şvS:Švs:š\"Y:ŸvZ:Žvz:ž,f:ƒ" /* Greek */ -"OM:Ωpi:π" +"AL:ΑBE:ΒGA:ΓDE:ΔEP:ΕZE:ΖET:ΗTH:ΘIO:ΙKA:ΚLA:ΛMU:ΜNU:ΝXI:ΞON:ΟPI:ΠRH:ΡSI:ΣTA:ΤUP:ΥPH:ΦCH:ΧPS:ΨOM:Ω" +"al:αbe:βga:γde:δep:εze:ζet:ηth:θio:ιka:κla:λmu:μnu:νxi:ξon:οpi:πrh:ρsi:σta:τup:υph:φch:χps:ψom:ω" /* Currency Symbols */ "/C:₡CR:₢=F:₣=L:₤/m:₥=N:₦=P:₧=R:₨=W:₩=S:₪=d:₫=C:€=K:₭=T:₮=D:₯=f:₰" /* General punctuation, preceded by a space in some cases */ "||:‖__:‗ `:‘ ':’ ,:‚``:“'':”,,:„+ :†++:‡o :•..:…%:‰ <:‹ >:›" /* Letterlike Sybols */ "tm:™" +/* Arrows */ +"->:→<-:←|^:↑|v:↓<=:⇐=>:⇒=^:⇑=v:⇓<~:⇜~>:⇝" /* Mathematical operators */ -"de:∂DE:∆PI:∏SI:∑ /:∕sq:√oo:∞in:∫~~:≈/=:≠<=:≤>=:≥ -:− ~:∼ |:∣/|:∤||:∥=~:≂~=:≃" +"V-:∀di:∂ E:∃/E:∄ /:∕sq:√oo:∞in:∫~~:≈/=:≠<=:≤>=:≥ -:− ~:∼ |:∣/|:∤||:∥=~:≂~=:≃" /* Geometric Shapes */ "<>:◊" /* Alphabetic Presentation Forms */ Index: util.c =================================================================== RCS file: /local/src/CVS/jove/util.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- util.c 20 Oct 2004 05:26:40 -0000 1.5 +++ util.c 27 Oct 2004 17:58:21 -0000 1.6 @@ -426,6 +426,8 @@ CalcWind(w); /* ah, this has been missing since the beginning of time! */ w->w_offset = 0; + if (bp->b_fname) + chk_mtime (bp, bp->b_fname, 0); } } From commit at keithp.com Wed Oct 27 13:09:39 2004 From: commit at keithp.com (Keith Packard) Date: Wed Oct 27 13:09:47 2004 Subject: [Commit] twin ChangeLog, 1.25, 1.26 Makefile.am, 1.12, 1.13 twin.h, 1.18, 1.19 twin_box.c, 1.1, 1.2 twin_button.c, 1.3, 1.4 twin_calc.c, NONE, 1.1 twin_calc.h, NONE, 1.1 twin_label.c, 1.2, 1.3 twin_toplevel.c, 1.1, 1.2 twin_widget.c, 1.3, 1.4 twinint.h, 1.16, 1.17 xtwin.c, 1.22, 1.23 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv9801 Modified Files: ChangeLog Makefile.am twin.h twin_box.c twin_button.c twin_label.c twin_toplevel.c twin_widget.c twinint.h xtwin.c Added Files: twin_calc.c twin_calc.h Log Message: 2004-10-27 Keith Packard * Makefile.am: Add calculator and missing header files * twin.h: * twin_box.c: (_twin_box_init), (_twin_box_query_geometry), (_twin_box_configure), (_twin_box_dispatch), (twin_box_create): * twin_button.c: (_twin_button_dispatch), (_twin_button_init): * twin_toplevel.c: (_twin_toplevel_init): * twin_widget.c: (_twin_widget_dispatch), (_twin_widget_init), * twin_label.c: (_twin_label_query_geometry), (_twin_label_dispatch), (_twin_label_init): * twinint.h: (twin_widget_create): Change type name from twin_layout_t to twin_box_dir_t Create new twin_widget_layout_t holding layout preferences. Add copy_geom field to widget to make widgets look the same Add button signals and signal proc. Fix box layout to sum stretch along axis and minimize normal * twin_calc.c: (_twin_calc_button_to_id), (_twin_calc_update_value), (_twin_calc_push), (_twin_calc_pop), (_twin_calc_digit), (_twin_calc_button_signal), (twin_calc_start): * twin_calc.h: * xtwin.c: (main): Add calculator demo Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- ChangeLog 27 Oct 2004 06:07:35 -0000 1.25 +++ ChangeLog 27 Oct 2004 20:09:36 -0000 1.26 @@ -1,3 +1,31 @@ +2004-10-27 Keith Packard + + * Makefile.am: + Add calculator and missing header files + + * twin.h: + * twin_box.c: (_twin_box_init), (_twin_box_query_geometry), + (_twin_box_configure), (_twin_box_dispatch), (twin_box_create): + * twin_button.c: (_twin_button_dispatch), (_twin_button_init): + * twin_toplevel.c: (_twin_toplevel_init): + * twin_widget.c: (_twin_widget_dispatch), (_twin_widget_init), + * twin_label.c: (_twin_label_query_geometry), + (_twin_label_dispatch), (_twin_label_init): + * twinint.h: + (twin_widget_create): + Change type name from twin_layout_t to twin_box_dir_t + Create new twin_widget_layout_t holding layout preferences. + Add copy_geom field to widget to make widgets look the same + Add button signals and signal proc. + Fix box layout to sum stretch along axis and minimize normal + + * twin_calc.c: (_twin_calc_button_to_id), + (_twin_calc_update_value), (_twin_calc_push), (_twin_calc_pop), + (_twin_calc_digit), (_twin_calc_button_signal), (twin_calc_start): + * twin_calc.h: + * xtwin.c: (main): + Add calculator demo + 2004-10-26 Keith Packard * twin_button.c: (_twin_button_paint): Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Makefile.am 26 Oct 2004 19:56:18 -0000 1.12 +++ Makefile.am 27 Oct 2004 20:09:36 -0000 1.13 @@ -44,11 +44,18 @@ twin_window.c \ twin_work.c \ twin_x11.c \ + twin_x11.h \ twinint.h \ twin_clock.c \ + twin_clock.h \ + twin_calc.c \ + twin_calc.h \ twin_text.c \ + twin_text.h \ twin_demo.c \ + twin_demo.h \ twin_hello.c \ + twin_hello.h \ xtwin.c xtwin_LDADD = @X_LIBS@ -lm Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- twin.h 26 Oct 2004 19:56:18 -0000 1.18 +++ twin.h 27 Oct 2004 20:09:36 -0000 1.19 @@ -372,37 +372,42 @@ #define _twin_widget_height(w) (((twin_widget_t *)(w))->extents.bottom - \ ((twin_widget_t *)(w))->extents.top) +typedef enum _twin_box_dir { + TwinBoxHorz, TwinBoxVert +} twin_box_dir_t; + typedef enum _twin_dispatch_result { - TwinDispatchNone, - TwinDispatchPaint, - TwinDispatchConfigure, + TwinDispatchDone, + TwinDispatchContinue } twin_dispatch_result_t; -typedef enum _twin_layout { - TwinLayoutHorz, TwinLayoutVert -} twin_layout_t; - typedef twin_dispatch_result_t (*twin_dispatch_proc_t) (twin_widget_t *widget, twin_event_t *event); +typedef struct _twin_widget_layout { + twin_coord_t width; + twin_coord_t height; + twin_stretch_t stretch_width; + twin_stretch_t stretch_height; +} twin_widget_layout_t; + struct _twin_widget { twin_window_t *window; twin_widget_t *next; twin_box_t *parent; + twin_widget_t *copy_geom; twin_bool_t paint; twin_bool_t layout; twin_bool_t want_focus; twin_argb32_t background; twin_rect_t extents; /* current geometry */ - twin_rect_t preferred; /* desired geometry */ - twin_stretch_t hstretch; /* stretch ratio in horizontal dir */ - twin_stretch_t vstretch; /* stretch ratio in vertical dir */ + twin_widget_layout_t preferred; twin_dispatch_proc_t dispatch; }; struct _twin_box { twin_widget_t widget; - twin_layout_t layout; + twin_box_dir_t dir; twin_widget_t *children; twin_widget_t *button_down; twin_widget_t *focus; @@ -421,15 +426,42 @@ twin_point_t offset; } twin_label_t; -typedef void (*twin_callback_t) (twin_widget_t *widget, void *closure); +typedef enum _twin_button_signal { + TwinButtonSignalDown, /* sent when button pressed */ + TwinButtonSignalUp, /* send when button released inside widget */ +} twin_button_signal_t; -typedef struct _twin_button { - twin_label_t label; - twin_bool_t pressed; - twin_bool_t active; - twin_callback_t callback; - void *closure; -} twin_button_t; +typedef struct _twin_button twin_button_t; + +typedef void (*twin_button_signal_proc_t) (twin_button_t *button, + twin_button_signal_t signal, + void *closure); + +struct _twin_button { + twin_label_t label; + twin_bool_t pressed; + twin_bool_t active; + twin_button_signal_proc_t signal; + void *closure; +}; + +typedef enum _twin_scroll_signal { + TwinScrollSignalUpArrow, + TwinScrollSignalDownArrow, + TwinScrollSignalThumb, + TwinScrollSignalAboveThumb, + TwinScrollSignalBelowThumb, +} twin_scroll_signal_t; + +typedef struct _twin_scroll twin_scroll_t; + +typedef void (*twin_scroll_signal_proc_t) (twin_scroll_t *scroll, + twin_scroll_signal_t signal, + void *closure); + +struct _twin_scroll { + twin_widget_t widget; +}; /* * twin_box.c @@ -437,7 +469,7 @@ twin_box_t * twin_box_create (twin_box_t *parent, - twin_layout_t layout); + twin_box_dir_t dir); /* * twin_button.c Index: twin_box.c =================================================================== RCS file: /local/src/CVS/twin/twin_box.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_box.c 26 Oct 2004 06:15:42 -0000 1.1 +++ twin_box.c 27 Oct 2004 20:09:36 -0000 1.2 @@ -28,58 +28,74 @@ _twin_box_init (twin_box_t *box, twin_box_t *parent, twin_window_t *window, - twin_layout_t layout, + twin_box_dir_t dir, twin_dispatch_proc_t dispatch) { - static twin_rect_t preferred = { 0, 0, 0, 0 }; - _twin_widget_init (&box->widget, parent, window, preferred, 0, 0, dispatch); - box->layout = layout; - box->children = 0; + static twin_widget_layout_t preferred = { 0, 0, 0, 0 }; + _twin_widget_init (&box->widget, parent, window, preferred, dispatch); + box->dir = dir; + box->children = NULL; + box->button_down = NULL; + box->focus = NULL; } static twin_dispatch_result_t _twin_box_query_geometry (twin_box_t *box) { - twin_widget_t *widget; - twin_event_t ev; - twin_coord_t w, h; - twin_coord_t c_w, c_h; + twin_widget_t *child; + twin_event_t ev; + twin_widget_layout_t preferred; - w = 0; h = 0; + preferred.width = 0; + preferred.height = 0; + if (box->dir == TwinBoxHorz) + { + preferred.stretch_width = 0; + preferred.stretch_height = 10000; + } + else + { + preferred.stretch_width = 10000; + preferred.stretch_height = 0; + } /* * Find preferred geometry */ - for (widget = box->children; widget; widget = widget->next) + for (child = box->children; child; child = child->next) { - ev.kind = TwinEventQueryGeometry; - (*widget->dispatch) (widget, &ev); - c_w = widget->preferred.right - widget->preferred.left; - c_h = widget->preferred.bottom - widget->preferred.top; - if (box->layout == TwinLayoutHorz) + if (child->layout) { - w += c_w; - if (c_h > h) - h = c_h; + ev.kind = TwinEventQueryGeometry; + (*child->dispatch) (child, &ev); + } + if (box->dir == TwinBoxHorz) + { + preferred.width += child->preferred.width; + preferred.stretch_width += child->preferred.stretch_width; + if (child->preferred.height > preferred.height) + preferred.height = child->preferred.height; + if (child->preferred.stretch_height < preferred.stretch_height) + preferred.stretch_height = child->preferred.stretch_height; } else { - h += c_h; - if (c_w > w) - w = c_w; + preferred.height += child->preferred.height; + preferred.stretch_height += child->preferred.stretch_height; + if (child->preferred.width > preferred.width) + preferred.width = child->preferred.width; + if (child->preferred.stretch_width < preferred.stretch_width) + preferred.stretch_width = child->preferred.stretch_width; } } - box->widget.preferred.left = 0; - box->widget.preferred.top = 0; - box->widget.preferred.right = w; - box->widget.preferred.bottom = h; - return TwinDispatchNone; + box->widget.preferred = preferred; + return TwinDispatchContinue; } static twin_dispatch_result_t _twin_box_configure (twin_box_t *box) { - twin_coord_t w = box->widget.extents.right - box->widget.extents.left; - twin_coord_t h = box->widget.extents.bottom - box->widget.extents.top; + twin_coord_t width = _twin_widget_width (box); + twin_coord_t height = _twin_widget_height (box); twin_coord_t actual; twin_coord_t pref; twin_coord_t delta; @@ -87,21 +103,18 @@ twin_coord_t stretch = 0; twin_coord_t pos = 0; twin_widget_t *child; - twin_dispatch_result_t result = TwinDispatchNone; - if (box->layout == TwinLayoutHorz) + if (box->dir == TwinBoxHorz) { - for (child = box->children; child; child = child->next) - stretch += child->hstretch; - actual = w; - pref = box->widget.preferred.right - box->widget.preferred.left; + stretch = box->widget.preferred.stretch_width; + actual = width; + pref = box->widget.preferred.width; } else { - for (child = box->children; child; child = child->next) - stretch += child->vstretch; - actual = h; - pref = box->widget.preferred.bottom - box->widget.preferred.top; + stretch = box->widget.preferred.stretch_height; + actual = height; + pref = box->widget.preferred.height; } if (!stretch) stretch = 1; delta = delta_remain = actual - pref; @@ -116,10 +129,10 @@ delta_this = delta_remain; else { - if (box->layout == TwinLayoutHorz) - stretch_this = child->hstretch; + if (box->dir == TwinBoxHorz) + stretch_this = child->preferred.stretch_width; else - stretch_this = child->vstretch; + stretch_this = child->preferred.stretch_height; delta_this = delta * stretch_this / stretch; } if (delta_remain < 0) @@ -133,30 +146,33 @@ delta_this = delta_remain; } delta_remain -= delta_this; - if (box->layout == TwinLayoutHorz) + if (box->dir == TwinBoxHorz) { - twin_coord_t child_w = (child->preferred.right - - child->preferred.left); + twin_coord_t child_w = child->preferred.width; extents.top = 0; - extents.bottom = h; + extents.bottom = height; extents.left = pos; pos = extents.right = pos + child_w + delta_this; } else { - twin_coord_t child_h = (child->preferred.bottom - - child->preferred.top); + twin_coord_t child_h = child->preferred.height; extents.left = 0; - extents.right = w; + extents.right = width; extents.top = pos; pos = extents.bottom = pos + child_h + delta_this; } - ev.kind = TwinEventConfigure; - ev.u.configure.extents = extents; - (*child->dispatch) (child, &ev); - result = TwinDispatchPaint; + if (extents.left != ev.u.configure.extents.left || + extents.top != ev.u.configure.extents.top || + extents.right != ev.u.configure.extents.right || + extents.bottom != ev.u.configure.extents.bottom) + { + ev.kind = TwinEventConfigure; + ev.u.configure.extents = extents; + (*child->dispatch) (child, &ev); + } } - return result; + return TwinDispatchContinue; } static twin_widget_t * @@ -180,11 +196,12 @@ twin_event_t ev; twin_widget_t *child; + if (_twin_widget_dispatch (widget, event) == TwinDispatchDone) + return TwinDispatchDone; switch (event->kind) { case TwinEventQueryGeometry: return _twin_box_query_geometry (box); case TwinEventConfigure: - _twin_widget_dispatch (widget, event); return _twin_box_configure (box); case TwinEventButtonDown: box->button_down = _twin_box_xy_to_widget (box, @@ -227,17 +244,17 @@ default: break; } - return TwinDispatchNone; + return TwinDispatchContinue; } twin_box_t * twin_box_create (twin_box_t *parent, - twin_layout_t layout) + twin_box_dir_t dir) { twin_box_t *box = malloc (sizeof (twin_box_t)); if (!box) return 0; - _twin_box_init (box, parent, 0, layout, _twin_box_dispatch); + _twin_box_init (box, parent, 0, dir, _twin_box_dispatch); return box; } Index: twin_button.c =================================================================== RCS file: /local/src/CVS/twin/twin_button.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_button.c 27 Oct 2004 06:07:35 -0000 1.3 +++ twin_button.c 27 Oct 2004 20:09:36 -0000 1.4 @@ -52,16 +52,19 @@ { twin_button_t *button = (twin_button_t *) widget; - _twin_label_dispatch (widget, event); + if (_twin_label_dispatch (widget, event) == TwinDispatchDone) + return TwinDispatchDone; switch (event->kind) { case TwinEventPaint: _twin_button_paint (button); - return TWIN_TRUE; + break; case TwinEventButtonDown: button->pressed = TWIN_TRUE; button->active = TWIN_TRUE; _twin_button_set_label_offset (button); - return TWIN_TRUE; + if (button->signal) + (*button->signal) (button, TwinButtonSignalDown, button->closure); + break; case TwinEventMotion: if (button->pressed) { @@ -74,21 +77,21 @@ _twin_button_set_label_offset (button); } } - return TWIN_TRUE; + break; case TwinEventButtonUp: button->pressed = TWIN_FALSE; if (button->active) { - if (button->callback) - (*button->callback) (&button->label.widget, button->closure); button->active = TWIN_FALSE; _twin_button_set_label_offset (button); + if (button->signal) + (*button->signal) (button, TwinButtonSignalUp, button->closure); } - return TWIN_TRUE; + break; default: break; } - return TwinDispatchNone; + return TwinDispatchContinue; } void @@ -103,6 +106,9 @@ _twin_label_init (&button->label, parent, value, foreground, font_size, font_style, dispatch); button->pressed = TWIN_FALSE; + button->active = TWIN_FALSE; + button->signal = NULL; + button->closure = NULL; _twin_button_set_label_offset (button); } --- NEW FILE: twin_calc.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_calc.h --- (This appears to be a binary file; contents omitted.) Index: twin_label.c =================================================================== RCS file: /local/src/CVS/twin/twin_label.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_label.c 26 Oct 2004 19:56:19 -0000 1.2 +++ twin_label.c 27 Oct 2004 20:09:36 -0000 1.3 @@ -30,16 +30,14 @@ twin_path_t *path = twin_path_create (); twin_text_metrics_t m; - label->widget.preferred.left = 0; - label->widget.preferred.top = 0; - label->widget.preferred.right = twin_fixed_to_int (label->font_size); - label->widget.preferred.bottom = twin_fixed_to_int (label->font_size) * 2; + label->widget.preferred.width = twin_fixed_to_int (label->font_size) * 2; + label->widget.preferred.height = twin_fixed_to_int (label->font_size) * 2; if (path) { twin_path_set_font_size (path, label->font_size); twin_path_set_font_style (path, label->font_style); twin_text_metrics_utf8 (path, label->label, &m); - label->widget.preferred.right += twin_fixed_to_int (m.width); + label->widget.preferred.width += twin_fixed_to_int (m.width); twin_path_destroy (path); } } @@ -74,18 +72,19 @@ { twin_label_t *label = (twin_label_t *) widget; - _twin_widget_dispatch (widget, event); + if (_twin_widget_dispatch (widget, event) == TwinDispatchDone) + return TwinDispatchDone; switch (event->kind) { case TwinEventPaint: _twin_label_paint (label); - return TwinDispatchNone; + break; case TwinEventQueryGeometry: _twin_label_query_geometry (label); break; default: break; } - return TwinDispatchNone; + return TwinDispatchContinue; } void @@ -122,9 +121,8 @@ twin_style_t font_style, twin_dispatch_proc_t dispatch) { - static const twin_rect_t empty = { 0, 0, 0, 0 }; - _twin_widget_init (&label->widget, parent, 0, - empty, 1, 1, dispatch); + static const twin_widget_layout_t preferred = { 0, 0, 1, 1 }; + _twin_widget_init (&label->widget, parent, 0, preferred, dispatch); label->label = NULL; label->offset.x = 0; label->offset.y = 0; Index: twin_toplevel.c =================================================================== RCS file: /local/src/CVS/twin/twin_toplevel.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_toplevel.c 26 Oct 2004 06:15:42 -0000 1.1 +++ twin_toplevel.c 27 Oct 2004 20:09:36 -0000 1.2 @@ -91,7 +91,7 @@ window->destroy = _twin_toplevel_destroy; window->event = _twin_toplevel_event; window->client_data = toplevel; - _twin_box_init (&toplevel->box, 0, window, TwinLayoutVert, dispatch); + _twin_box_init (&toplevel->box, 0, window, TwinBoxVert, dispatch); } twin_toplevel_t * Index: twin_widget.c =================================================================== RCS file: /local/src/CVS/twin/twin_widget.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_widget.c 27 Oct 2004 06:07:35 -0000 1.3 +++ twin_widget.c 27 Oct 2004 20:09:36 -0000 1.4 @@ -41,9 +41,19 @@ _twin_widget_dispatch (twin_widget_t *widget, twin_event_t *event) { switch (event->kind) { + case TwinEventQueryGeometry: + widget->layout = TWIN_FALSE; + if (widget->copy_geom) + { + twin_widget_t *copy = widget->copy_geom; + if (copy->layout) + (*copy->dispatch) (copy, event); + widget->preferred = copy->preferred; + return TwinDispatchDone; + } + break; case TwinEventConfigure: widget->extents = event->u.configure.extents; - widget->layout = TWIN_FALSE; break; case TwinEventPaint: _twin_widget_paint (widget); @@ -52,16 +62,14 @@ default: break; } - return TwinDispatchNone; + return TwinDispatchContinue; } void _twin_widget_init (twin_widget_t *widget, twin_box_t *parent, twin_window_t *window, - twin_rect_t preferred, - twin_stretch_t hstretch, - twin_stretch_t vstretch, + twin_widget_layout_t preferred, twin_dispatch_proc_t dispatch) { if (parent) @@ -77,13 +85,15 @@ widget->next = NULL; widget->window = window; widget->parent = parent; + widget->copy_geom = NULL; widget->paint = TWIN_TRUE; + widget->layout = TWIN_TRUE; + widget->want_focus = TWIN_FALSE; + widget->background = 0x00000000; + widget->extents.left = widget->extents.top = 0; + widget->extents.right = widget->extents.bottom = 0; widget->preferred = preferred; - widget->extents = preferred; - widget->hstretch = hstretch; - widget->vstretch = vstretch; widget->dispatch = dispatch; - widget->background = 0x00000000; } void @@ -171,20 +181,19 @@ twin_argb32_t background, twin_coord_t width, twin_coord_t height, - twin_stretch_t hstretch, - twin_stretch_t vstretch) + twin_stretch_t stretch_width, + twin_stretch_t stretch_height) { - twin_widget_t *widget = malloc (sizeof (twin_widget_t)); - twin_rect_t extents; + twin_widget_t *widget = malloc (sizeof (twin_widget_t)); + twin_widget_layout_t preferred; if (!widget) return NULL; - extents.left = 0; - extents.top = 0; - extents.right = width; - extents.bottom = height; - _twin_widget_init (widget, parent, 0, extents, hstretch, vstretch, - _twin_widget_dispatch); + preferred.width = width; + preferred.height = height; + preferred.stretch_width = stretch_width; + preferred.stretch_height = stretch_height; + _twin_widget_init (widget, parent, 0, preferred, _twin_widget_dispatch); widget->background = background; return widget; } Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- twinint.h 27 Oct 2004 06:07:35 -0000 1.16 +++ twinint.h 27 Oct 2004 20:09:36 -0000 1.17 @@ -455,7 +455,7 @@ _twin_box_init (twin_box_t *box, twin_box_t *parent, twin_window_t *window, - twin_layout_t layout, + twin_box_dir_t dir, twin_dispatch_proc_t dispatch); twin_dispatch_result_t @@ -465,9 +465,7 @@ _twin_widget_init (twin_widget_t *widget, twin_box_t *parent, twin_window_t *window, - twin_rect_t preferred, - twin_stretch_t hstretch, - twin_stretch_t vstretch, + twin_widget_layout_t preferred, twin_dispatch_proc_t dispatch); twin_dispatch_result_t Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- xtwin.c 26 Oct 2004 19:56:19 -0000 1.22 +++ xtwin.c 27 Oct 2004 20:09:36 -0000 1.23 @@ -33,6 +33,7 @@ #include #include #include +#include #define WIDTH 512 #define HEIGHT 512 @@ -49,9 +50,11 @@ twin_clock_start (x11->screen, "Clock", 10, 10, 200, 200); twin_text_start (x11->screen, "Gettysburg Address", 0, 0, 300, 300); -#endif twin_hello_start (x11->screen, "Hello, World", 0, 0, 200, 200); +#endif + twin_calc_start (x11->screen, "Calculator", + 100, 100, 200, 200); twin_dispatch (); return 0; } From commit at keithp.com Wed Oct 27 13:34:58 2004 From: commit at keithp.com (Keith Packard) Date: Wed Oct 27 13:35:04 2004 Subject: [Commit] twin ChangeLog, 1.26, 1.27 twin_box.c, 1.2, 1.3 twin_clock.c, 1.2, 1.3 twin_clock.h, 1.1, 1.2 twin_widget.c, 1.4, 1.5 xtwin.c, 1.23, 1.24 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv10432 Modified Files: ChangeLog twin_box.c twin_clock.c twin_clock.h twin_widget.c xtwin.c Log Message: 2004-10-27 Keith Packard * twin_box.c: (_twin_box_dispatch): Boxes have no paint * twin_clock.c: (twin_clock_set_transform), (twin_clock_hand), (_twin_clock_face), (_twin_clock_interval), (_twin_clock_paint), (_twin_clock_timeout), (_twin_clock_dispatch), (_twin_clock_init), (twin_clock_create), (twin_clock_start): * twin_clock.h: Convert to a widget * twin_widget.c: (_twin_widget_paint): Always paint background, even if transparent * xtwin.c: (main): show clock widget Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- ChangeLog 27 Oct 2004 20:09:36 -0000 1.26 +++ ChangeLog 27 Oct 2004 20:34:55 -0000 1.27 @@ -1,5 +1,23 @@ 2004-10-27 Keith Packard + * twin_box.c: (_twin_box_dispatch): + Boxes have no paint + + * twin_clock.c: (twin_clock_set_transform), (twin_clock_hand), + (_twin_clock_face), (_twin_clock_interval), (_twin_clock_paint), + (_twin_clock_timeout), (_twin_clock_dispatch), (_twin_clock_init), + (twin_clock_create), (twin_clock_start): + * twin_clock.h: + Convert to a widget + + * twin_widget.c: (_twin_widget_paint): + Always paint background, even if transparent + + * xtwin.c: (main): + show clock widget + +2004-10-27 Keith Packard + * Makefile.am: Add calculator and missing header files Index: twin_box.c =================================================================== RCS file: /local/src/CVS/twin/twin_box.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_box.c 27 Oct 2004 20:09:36 -0000 1.2 +++ twin_box.c 27 Oct 2004 20:34:55 -0000 1.3 @@ -196,7 +196,8 @@ twin_event_t ev; twin_widget_t *child; - if (_twin_widget_dispatch (widget, event) == TwinDispatchDone) + if (event->kind != TwinEventPaint && + _twin_widget_dispatch (widget, event) == TwinDispatchDone) return TwinDispatchDone; switch (event->kind) { case TwinEventQueryGeometry: Index: twin_clock.c =================================================================== RCS file: /local/src/CVS/twin/twin_clock.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_clock.c 26 Oct 2004 06:15:42 -0000 1.2 +++ twin_clock.c 27 Oct 2004 20:34:55 -0000 1.3 @@ -23,6 +23,7 @@ */ #include +#include #include #include #include @@ -44,16 +45,17 @@ #define TWIN_CLOCK_BORDER 0xffbababa #define TWIN_CLOCK_BORDER_WIDTH D(0.01) +#define _twin_clock_pixmap(clock) ((clock)->widget.window->pixmap) + static void -twin_clock_set_transform (twin_window_t *clock, +twin_clock_set_transform (twin_clock_t *clock, twin_path_t *path) { twin_fixed_t scale; scale = (TWIN_FIXED_ONE - TWIN_CLOCK_BORDER_WIDTH * 3) / 2; - twin_path_scale (path, - (clock->client.right - clock->client.left) * scale, - (clock->client.bottom - clock->client.top) * scale); + twin_path_scale (path, _twin_widget_width (clock) * scale, + _twin_widget_height (clock) * scale); twin_path_translate (path, TWIN_FIXED_ONE + TWIN_CLOCK_BORDER_WIDTH * 3, @@ -63,7 +65,7 @@ } static void -twin_clock_hand (twin_window_t *clock, +twin_clock_hand (twin_clock_t *clock, twin_angle_t angle, twin_fixed_t len, twin_fixed_t fill_width, @@ -90,9 +92,9 @@ twin_path_circle (pen, fill_width); twin_path_convolve (path, stroke, pen); - twin_paint_path (clock->pixmap, fill_pixel, path); + twin_paint_path (_twin_clock_pixmap(clock), fill_pixel, path); - twin_paint_stroke (clock->pixmap, out_pixel, path, out_width); + twin_paint_stroke (_twin_clock_pixmap(clock), out_pixel, path, out_width); twin_path_destroy (path); twin_path_destroy (pen); @@ -106,7 +108,7 @@ } static void -twin_clock_face (twin_window_t *clock) +_twin_clock_face (twin_clock_t *clock) { twin_path_t *path = twin_path_create (); int m; @@ -116,9 +118,9 @@ twin_path_move (path, 0, 0); twin_path_circle (path, TWIN_FIXED_ONE); - twin_paint_path (clock->pixmap, TWIN_CLOCK_BACKGROUND, path); + twin_paint_path (_twin_clock_pixmap(clock), TWIN_CLOCK_BACKGROUND, path); - twin_paint_stroke (clock->pixmap, TWIN_CLOCK_BORDER, path, TWIN_CLOCK_BORDER_WIDTH); + twin_paint_stroke (_twin_clock_pixmap(clock), TWIN_CLOCK_BORDER, path, TWIN_CLOCK_BORDER_WIDTH); { twin_state_t state = twin_path_save (path); @@ -136,12 +138,12 @@ twin_path_move (path, -width / 2, metrics.ascent - height/2 + D(0.01)); twin_path_draw (path, width / 2, metrics.ascent - height/2 + D(0.01)); - twin_paint_stroke (clock->pixmap, TWIN_CLOCK_WATER_UNDER, path, D(0.02)); + twin_paint_stroke (_twin_clock_pixmap(clock), TWIN_CLOCK_WATER_UNDER, path, D(0.02)); twin_path_empty (path); twin_path_move (path, -width / 2 - metrics.left_side_bearing, metrics.ascent - height/2); twin_path_utf8 (path, label); - twin_paint_path (clock->pixmap, TWIN_CLOCK_WATER, path); + twin_paint_path (_twin_clock_pixmap(clock), TWIN_CLOCK_WATER, path); twin_path_restore (path, &state); } @@ -157,7 +159,7 @@ { twin_path_move (path, 0, -TWIN_FIXED_ONE); twin_path_draw (path, 0, -D(0.9)); - twin_paint_stroke (clock->pixmap, TWIN_CLOCK_TIC, path, D(0.01)); + twin_paint_stroke (_twin_clock_pixmap(clock), TWIN_CLOCK_TIC, path, D(0.01)); } else { @@ -172,7 +174,7 @@ left = -width / 2 - metrics.left_side_bearing; twin_path_move (path, left, -D(0.98) + metrics.ascent); twin_path_utf8 (path, hour); - twin_paint_path (clock->pixmap, TWIN_CLOCK_NUMBERS, path); + twin_paint_path (_twin_clock_pixmap(clock), TWIN_CLOCK_NUMBERS, path); } twin_path_restore (path, &state); } @@ -181,9 +183,17 @@ } static twin_time_t -twin_clock_timeout (twin_time_t now, void *closure) +_twin_clock_interval (void) +{ + struct timeval tv; + gettimeofday (&tv, NULL); + + return 1000 - (tv.tv_usec / 1000); +} + +void +_twin_clock_paint (twin_clock_t *clock) { - twin_window_t *clock = closure; struct timeval tv; twin_angle_t second_angle, minute_angle, hour_angle; struct tm t; @@ -192,12 +202,7 @@ localtime_r(&tv.tv_sec, &t); - twin_pixmap_disable_update (clock->pixmap); - twin_fill (clock->pixmap, 0x00000000, TWIN_SOURCE, - clock->client.left, clock->client.top, - clock->client.right, clock->client.bottom); - - twin_clock_face (clock); + _twin_clock_face (clock); second_angle = ((t.tm_sec * 100 + tv.tv_usec / 10000) * TWIN_ANGLE_360) / 6000; @@ -209,30 +214,61 @@ TWIN_CLOCK_MINUTE, TWIN_CLOCK_MINUTE_OUT); twin_clock_hand (clock, second_angle, D(0.9), D(0.01), D(0.01), TWIN_CLOCK_SECOND, TWIN_CLOCK_SECOND_OUT); +} - twin_pixmap_enable_update (clock->pixmap); - - gettimeofday (&tv, NULL); +static twin_time_t +_twin_clock_timeout (twin_time_t now, void *closure) +{ + twin_clock_t *clock = closure; + _twin_widget_queue_paint (&clock->widget); + return _twin_clock_interval (); +} - return 1000 - (tv.tv_usec / 1000); +twin_dispatch_result_t +_twin_clock_dispatch (twin_widget_t *widget, twin_event_t *event) +{ + twin_clock_t *clock = (twin_clock_t *) widget; + + if (_twin_widget_dispatch (widget, event) == TwinDispatchDone) + return TwinDispatchDone; + switch (event->kind) { + case TwinEventPaint: + _twin_clock_paint (clock); + break; + default: + break; + } + return TwinDispatchContinue; } void -twin_clock_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h) +_twin_clock_init (twin_clock_t *clock, + twin_box_t *parent, + twin_dispatch_proc_t dispatch) { - struct timeval tv; - twin_time_t to; - twin_window_t *clock = twin_window_create (screen, TWIN_ARGB32, - TwinWindowApplication, - x, y, w, h); - twin_window_set_name (clock, name); - twin_clock_timeout (0, clock); - twin_window_show (clock); + static const twin_widget_layout_t preferred = { 0, 0, 1, 1 }; + _twin_widget_init (&clock->widget, parent, 0, preferred, dispatch); + clock->timeout = twin_set_timeout (_twin_clock_timeout, + _twin_clock_interval(), + clock); +} - gettimeofday (&tv, NULL); +twin_clock_t * +twin_clock_create (twin_box_t *parent) +{ + twin_clock_t *clock = malloc (sizeof (twin_clock_t)); + + _twin_clock_init(clock, parent, _twin_clock_dispatch); + return clock; +} - to = 1000 - (tv.tv_usec / 1000); - (void) twin_set_timeout (twin_clock_timeout, - to, - clock); +void +twin_clock_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h) +{ + twin_toplevel_t *toplevel = twin_toplevel_create (screen, TWIN_ARGB32, + TwinWindowApplication, + x, y, w, h, name); + twin_clock_t *clock = twin_clock_create (&toplevel->box); + (void) clock; + twin_toplevel_show (toplevel); } Index: twin_clock.h =================================================================== RCS file: /local/src/CVS/twin/twin_clock.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_clock.h 25 Oct 2004 19:09:35 -0000 1.1 +++ twin_clock.h 27 Oct 2004 20:34:55 -0000 1.2 @@ -27,6 +27,25 @@ #include +typedef struct _twin_clock { + twin_widget_t widget; + twin_timeout_t *timeout; +} twin_clock_t; + +void +_twin_clock_paint (twin_clock_t *clock); + +twin_dispatch_result_t +_twin_clock_dispatch (twin_widget_t *widget, twin_event_t *event); + +void +_twin_clock_init (twin_clock_t *clock, + twin_box_t *parent, + twin_dispatch_proc_t dispatch); + +twin_clock_t * +twin_clock_create (twin_box_t *parent); + void twin_clock_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h); Index: twin_widget.c =================================================================== RCS file: /local/src/CVS/twin/twin_widget.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_widget.c 27 Oct 2004 20:09:36 -0000 1.4 +++ twin_widget.c 27 Oct 2004 20:34:55 -0000 1.5 @@ -27,14 +27,11 @@ static void _twin_widget_paint (twin_widget_t *widget) { - if (widget->background) - { - twin_pixmap_t *pixmap = widget->window->pixmap; - twin_coord_t w = widget->extents.right - widget->extents.left; - twin_coord_t h = widget->extents.bottom - widget->extents.top; - - twin_fill (pixmap, widget->background, TWIN_SOURCE, 0, 0, w, h); - } + twin_pixmap_t *pixmap = widget->window->pixmap; + twin_coord_t w = widget->extents.right - widget->extents.left; + twin_coord_t h = widget->extents.bottom - widget->extents.top; + + twin_fill (pixmap, widget->background, TWIN_SOURCE, 0, 0, w, h); } twin_dispatch_result_t Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- xtwin.c 27 Oct 2004 20:09:36 -0000 1.23 +++ xtwin.c 27 Oct 2004 20:34:55 -0000 1.24 @@ -47,12 +47,12 @@ twin_screen_set_background (x11->screen, twin_make_pattern ()); #if 0 twin_demo_start (x11->screen, "Demo", 100, 100, 400, 400); - twin_clock_start (x11->screen, "Clock", 10, 10, 200, 200); twin_text_start (x11->screen, "Gettysburg Address", 0, 0, 300, 300); twin_hello_start (x11->screen, "Hello, World", 0, 0, 200, 200); #endif + twin_clock_start (x11->screen, "Clock", 10, 10, 200, 200); twin_calc_start (x11->screen, "Calculator", 100, 100, 200, 200); twin_dispatch (); From commit at keithp.com Thu Oct 28 08:17:27 2004 From: commit at keithp.com (Keith Packard) Date: Thu Oct 28 08:17:40 2004 Subject: [Commit] jove ChangeLog,1.5,1.6 man.c,1.5,1.6 Message-ID: Committed by: keithp Update of /local/src/CVS/jove In directory home.keithp.com:/tmp/cvs-serv4769 Modified Files: ChangeLog man.c Log Message: 2004-10-28 Keith Packard * man.c: set LC_CTYPE to C before running man to avoid non-ascii punctuation Index: ChangeLog =================================================================== RCS file: /local/src/CVS/jove/ChangeLog,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ChangeLog 27 Oct 2004 17:58:21 -0000 1.5 +++ ChangeLog 28 Oct 2004 15:17:24 -0000 1.6 @@ -1,3 +1,8 @@ +2004-10-28 Keith Packard + + * man.c: + set LC_CTYPE to C before running man to avoid non-ascii punctuation + 2004-10-27 Keith Packard * insert.c: Index: man.c =================================================================== RCS file: /local/src/CVS/jove/man.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- man.c 20 Oct 2004 05:26:40 -0000 1.5 +++ man.c 28 Oct 2004 15:17:24 -0000 1.6 @@ -320,6 +320,7 @@ (void) dup (fd[1]); (void) dup (0); close_pipe (fd); + setenv ("LC_CTYPE", "C", 1); execvp(argv[0], &argv[1]); (void) write (1, "man not found\n", 14); _exit (1); From commit at keithp.com Fri Oct 29 10:33:08 2004 From: commit at keithp.com (Keith Packard) Date: Fri Oct 29 10:33:19 2004 Subject: [Commit] twin ChangeLog, 1.27, 1.28 Makefile.am, 1.13, 1.14 twin.h, 1.19, 1.20 twin_box.c, 1.3, 1.4 twin_button.c, 1.4, 1.5 twin_calc.c, 1.1, 1.2 twin_clock.c, 1.3, 1.4 twin_convolve.c, 1.7, 1.8 twin_demo.c, 1.2, 1.3 twin_demoline.c, NONE, 1.1 twin_demoline.h, NONE, 1.1 twin_demospline.c, NONE, 1.1 twin_demospline.h, NONE, 1.1 twin_draw.c, 1.8, 1.9 twin_font.c, 1.14, 1.15 twin_glyphs.c, 1.6, 1.7 twin_label.c, 1.3, 1.4 twin_path.c, 1.12, 1.13 twin_toplevel.c, 1.2, 1.3 twin_widget.c, 1.5, 1.6 twin_window.c, 1.5, 1.6 twin_x11.c, 1.8, 1.9 twinint.h, 1.17, 1.18 xtwin.c, 1.24, 1.25 Message-ID: Committed by: keithp Update of /local/src/CVS/twin In directory home.keithp.com:/tmp/cvs-serv9445 Modified Files: ChangeLog Makefile.am twin.h twin_box.c twin_button.c twin_calc.c twin_clock.c twin_convolve.c twin_demo.c twin_draw.c twin_font.c twin_glyphs.c twin_label.c twin_path.c twin_toplevel.c twin_widget.c twin_window.c twin_x11.c twinint.h xtwin.c Added Files: twin_demoline.c twin_demoline.h twin_demospline.c twin_demospline.h Log Message: 2004-10-29 Keith Packard * Makefile.am: add demoline + demospline * twin.h: * twin_box.c: (_twin_box_dispatch): * twin_clock.c: (twin_clock_hand), (_twin_clock_face): * twin_convolve.c: (_twin_subpath_convolve): * twin_demo.c: (twin_line_start), (twin_circletext_start), * twin_draw.c: (twin_composite): * twin_font.c: (_twin_text_compute_pen): * twin_label.c: (_twin_label_paint), (_twin_label_init): * twin_path.c: (twin_path_circle), (twin_path_ellipse), (twin_path_arc), (twin_path_rectangle), (twin_path_rounded_rectangle), (twin_path_lozenge), (twin_path_tab), (twin_path_set_cap_style), (twin_path_current_cap_style), (twin_path_create), (twin_composite_stroke): (twin_quickbrown_start), (twin_ascii_start), (twin_demo_start): * twin_widget.c: (_twin_path_shape), (_twin_widget_paint_shape), (_twin_widget_paint), (_twin_widget_init), (_twin_path_bevel_shape): * twinint.h: Add cap styles, widget shapes, text alignment and arcs Change circle/ellipse API. * twin_button.c: (_twin_button_dispatch): Capture button events. * twin_calc.c: (twin_calc_start): Use Lozenge shape for output * twin_demoline.c: (_twin_demoline_paint), (_twin_demoline_update_pos), (_twin_demoline_hit), (_twin_demoline_dispatch), (_twin_demoline_init), (twin_demoline_create), (twin_demoline_start): * twin_demoline.h: Drag lines with the mouse * twin_demospline.c: (_twin_demospline_paint), (_twin_demospline_update_pos), (_twin_demospline_hit), (_twin_demospline_dispatch), (_twin_demospline_init), (twin_demospline_create), (twin_demospline_start): * twin_demospline.h: drag splines with the mouse * twin_glyphs.c: move '1' right a bit * twin_toplevel.c: (_twin_toplevel_event): Convert dispatch result to boool * twin_window.c: (twin_window_create), (twin_window_dispatch): was mis-computing delegate and crashing when window->event was NULL * twin_x11.c: (twin_x11_read_events): Map X button info to twin mask * xtwin.c: (main): draw different stuff. Index: ChangeLog =================================================================== RCS file: /local/src/CVS/twin/ChangeLog,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- ChangeLog 27 Oct 2004 20:34:55 -0000 1.27 +++ ChangeLog 29 Oct 2004 17:33:03 -0000 1.28 @@ -1,3 +1,65 @@ +2004-10-29 Keith Packard + + * Makefile.am: + add demoline + demospline + + * twin.h: + * twin_box.c: (_twin_box_dispatch): + * twin_clock.c: (twin_clock_hand), (_twin_clock_face): + * twin_convolve.c: (_twin_subpath_convolve): + * twin_demo.c: (twin_line_start), (twin_circletext_start), + * twin_draw.c: (twin_composite): + * twin_font.c: (_twin_text_compute_pen): + * twin_label.c: (_twin_label_paint), (_twin_label_init): + * twin_path.c: (twin_path_circle), (twin_path_ellipse), + (twin_path_arc), (twin_path_rectangle), + (twin_path_rounded_rectangle), (twin_path_lozenge), + (twin_path_tab), (twin_path_set_cap_style), + (twin_path_current_cap_style), (twin_path_create), + (twin_composite_stroke): + (twin_quickbrown_start), (twin_ascii_start), (twin_demo_start): + * twin_widget.c: (_twin_path_shape), (_twin_widget_paint_shape), + (_twin_widget_paint), (_twin_widget_init), + (_twin_path_bevel_shape): + * twinint.h: + Add cap styles, widget shapes, text alignment and arcs + Change circle/ellipse API. + + * twin_button.c: (_twin_button_dispatch): + Capture button events. + + * twin_calc.c: (twin_calc_start): + Use Lozenge shape for output + + * twin_demoline.c: (_twin_demoline_paint), + (_twin_demoline_update_pos), (_twin_demoline_hit), + (_twin_demoline_dispatch), (_twin_demoline_init), + (twin_demoline_create), (twin_demoline_start): + * twin_demoline.h: + Drag lines with the mouse + + * twin_demospline.c: (_twin_demospline_paint), + (_twin_demospline_update_pos), (_twin_demospline_hit), + (_twin_demospline_dispatch), (_twin_demospline_init), + (twin_demospline_create), (twin_demospline_start): + * twin_demospline.h: + drag splines with the mouse + + * twin_glyphs.c: + move '1' right a bit + + * twin_toplevel.c: (_twin_toplevel_event): + Convert dispatch result to boool + + * twin_window.c: (twin_window_create), (twin_window_dispatch): + was mis-computing delegate and crashing when window->event was NULL + + * twin_x11.c: (twin_x11_read_events): + Map X button info to twin mask + + * xtwin.c: (main): + draw different stuff. + 2004-10-27 Keith Packard * twin_box.c: (_twin_box_dispatch): Index: Makefile.am =================================================================== RCS file: /local/src/CVS/twin/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- Makefile.am 27 Oct 2004 20:09:36 -0000 1.13 +++ Makefile.am 29 Oct 2004 17:33:03 -0000 1.14 @@ -56,6 +56,10 @@ twin_demo.h \ twin_hello.c \ twin_hello.h \ + twin_demoline.c \ + twin_demoline.h \ + twin_demospline.c \ + twin_demospline.h \ xtwin.c xtwin_LDADD = @X_LIBS@ -lm Index: twin.h =================================================================== RCS file: /local/src/CVS/twin/twin.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- twin.h 27 Oct 2004 20:09:36 -0000 1.19 +++ twin.h 29 Oct 2004 17:33:03 -0000 1.20 @@ -62,6 +62,9 @@ #define TWIN_ANGLE_22_5 (TWIN_ANGLE_360 >> 4) #define TWIN_ANGLE_11_25 (TWIN_ANGLE_360 >> 5) +#define TWIN_ANGLE_270 (TWIN_ANGLE_180 + TWIN_ANGLE_90) +#define TWIN_ANGLE_0 (0) + #define twin_degrees_to_angle(d) ((twin_angle_t) ((((int32_t) (d)) * TWIN_ANGLE_360 / 360))) /* @@ -227,10 +230,17 @@ typedef struct _twin_path twin_path_t; +typedef enum _twin_cap { + TwinCapRound, + TwinCapButt, + TwinCapProjecting, +} twin_cap_t; + typedef struct _twin_state { twin_matrix_t matrix; twin_fixed_t font_size; twin_style_t font_style; + twin_cap_t cap_style; } twin_state_t; /* @@ -391,18 +401,28 @@ twin_stretch_t stretch_height; } twin_widget_layout_t; +typedef enum _twin_shape { + TwinShapeRectangle, + TwinShapeRoundedRectangle, + TwinShapeLozenge, + TwinShapeTab, + TwinShapeEllipse, +} twin_shape_t; + struct _twin_widget { twin_window_t *window; twin_widget_t *next; twin_box_t *parent; + twin_dispatch_proc_t dispatch; + twin_rect_t extents; /* current geometry */ twin_widget_t *copy_geom; twin_bool_t paint; twin_bool_t layout; twin_bool_t want_focus; twin_argb32_t background; - twin_rect_t extents; /* current geometry */ twin_widget_layout_t preferred; - twin_dispatch_proc_t dispatch; + twin_shape_t shape; + twin_fixed_t radius; }; struct _twin_box { @@ -417,6 +437,10 @@ twin_box_t box; } twin_toplevel_t; +typedef enum _twin_align { + TwinAlignLeft, TwinAlignCenter, TwinAlignRight +} twin_align_t; + typedef struct _twin_label { twin_widget_t widget; char *label; @@ -424,6 +448,7 @@ twin_fixed_t font_size; twin_style_t font_style; twin_point_t offset; + twin_align_t align; } twin_label_t; typedef enum _twin_button_signal { @@ -670,13 +695,60 @@ twin_path_rdraw (twin_path_t *path, twin_fixed_t x, twin_fixed_t y); void -twin_path_circle(twin_path_t *path, twin_fixed_t radius); +twin_path_circle(twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t radius); void -twin_path_ellipse (twin_path_t *path, +twin_path_ellipse (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, twin_fixed_t x_radius, twin_fixed_t y_radius); void +twin_path_arc (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t x_radius, + twin_fixed_t y_radius, + twin_angle_t start, + twin_angle_t extent); + +void +twin_path_rectangle (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h); + +void +twin_path_rounded_rectangle (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h, + twin_fixed_t x_radius, + twin_fixed_t y_radius); + +void +twin_path_lozenge (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h); + +void +twin_path_tab (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h, + twin_fixed_t x_radius, + twin_fixed_t y_radius); + + +void twin_path_close (twin_path_t *path); void @@ -724,6 +796,12 @@ void twin_path_set_font_style (twin_path_t *path, twin_style_t font_style); +void +twin_path_set_cap_style (twin_path_t *path, twin_cap_t cap_style); + +twin_cap_t +twin_path_current_cap_style (twin_path_t *path); + twin_state_t twin_path_save (twin_path_t *path); Index: twin_box.c =================================================================== RCS file: /local/src/CVS/twin/twin_box.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_box.c 27 Oct 2004 20:34:55 -0000 1.3 +++ twin_box.c 29 Oct 2004 17:33:03 -0000 1.4 @@ -236,6 +236,11 @@ twin_pixmap_t *pixmap = box->widget.window->pixmap; twin_rect_t clip = twin_pixmap_current_clip (pixmap); + if (child->shape != TwinShapeRectangle) + twin_fill (child->window->pixmap, + widget->background, TWIN_SOURCE, + child->extents.left, child->extents.top, + child->extents.right, child->extents.bottom); twin_pixmap_set_clip (pixmap, child->extents); child->paint = TWIN_FALSE; (*child->dispatch) (child, event); Index: twin_button.c =================================================================== RCS file: /local/src/CVS/twin/twin_button.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- twin_button.c 27 Oct 2004 20:09:36 -0000 1.4 +++ twin_button.c 29 Oct 2004 17:33:03 -0000 1.5 @@ -64,6 +64,7 @@ _twin_button_set_label_offset (button); if (button->signal) (*button->signal) (button, TwinButtonSignalDown, button->closure); + return TwinDispatchDone; break; case TwinEventMotion: if (button->pressed) @@ -77,6 +78,7 @@ _twin_button_set_label_offset (button); } } + return TwinDispatchDone; break; case TwinEventButtonUp: button->pressed = TWIN_FALSE; @@ -87,6 +89,7 @@ if (button->signal) (*button->signal) (button, TwinButtonSignalUp, button->closure); } + return TwinDispatchDone; break; default: break; Index: twin_calc.c =================================================================== RCS file: /local/src/CVS/twin/twin_calc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- twin_calc.c 27 Oct 2004 20:09:36 -0000 1.1 +++ twin_calc.c 29 Oct 2004 17:33:03 -0000 1.2 @@ -81,10 +81,10 @@ "+", "-", "*", "/", "=", "CLR" }; -#define TWIN_CALC_VALUE_SIZE twin_int_to_fixed(24) -#define TWIN_CALC_VALUE_STYLE TWIN_TEXT_BOLD +#define TWIN_CALC_VALUE_SIZE twin_int_to_fixed(29) +#define TWIN_CALC_VALUE_STYLE TWIN_TEXT_ROMAN #define TWIN_CALC_VALUE_FG 0xff000000 -#define TWIN_CALC_VALUE_BG 0xc0c0c0c0 +#define TWIN_CALC_VALUE_BG 0x80808080 #define TWIN_CALC_BUTTON_SIZE twin_int_to_fixed(15) #define TWIN_CALC_BUTTON_STYLE TWIN_TEXT_BOLD #define TWIN_CALC_BUTTON_FG 0xff000000 @@ -210,6 +210,8 @@ TWIN_CALC_VALUE_SIZE, TWIN_CALC_VALUE_STYLE); twin_widget_set (&calc->display->widget, TWIN_CALC_VALUE_BG); + calc->display->align = TwinAlignRight; + calc->display->widget.shape = TwinShapeLozenge; calc->keys = twin_box_create (&calc->toplevel->box, TwinBoxHorz); for (i = 0; i < TWIN_CALC_COLS; i++) { @@ -226,6 +228,7 @@ TWIN_CALC_BUTTON_BG); calc->buttons[b]->signal = _twin_calc_button_signal; calc->buttons[b]->closure = calc; +/* calc->buttons[b]->label.widget.shape = TwinShapeLozenge; */ if (i || j) calc->buttons[b]->label.widget.copy_geom = &calc->buttons[calc_layout[0][0]]->label.widget; } Index: twin_clock.c =================================================================== RCS file: /local/src/CVS/twin/twin_clock.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_clock.c 27 Oct 2004 20:34:55 -0000 1.3 +++ twin_clock.c 29 Oct 2004 17:33:03 -0000 1.4 @@ -89,7 +89,7 @@ m.m[2][1] = 0; twin_path_set_matrix (pen, m); twin_path_set_matrix (path, m); - twin_path_circle (pen, fill_width); + twin_path_circle (pen, 0, 0, fill_width); twin_path_convolve (path, stroke, pen); twin_paint_path (_twin_clock_pixmap(clock), fill_pixel, path); @@ -115,8 +115,7 @@ twin_clock_set_transform (clock, path); - twin_path_move (path, 0, 0); - twin_path_circle (path, TWIN_FIXED_ONE); + twin_path_circle (path, 0, 0, TWIN_FIXED_ONE); twin_paint_path (_twin_clock_pixmap(clock), TWIN_CLOCK_BACKGROUND, path); Index: twin_convolve.c =================================================================== RCS file: /local/src/CVS/twin/twin_convolve.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- twin_convolve.c 27 Sep 2004 21:28:31 -0000 1.7 +++ twin_convolve.c 29 Oct 2004 17:33:03 -0000 1.8 @@ -75,10 +75,10 @@ return 0; } +#define F(x) twin_sfixed_to_double(x) #if 0 #include #include -#define F(x) twin_sfixed_to_double(x) #define DBGOUT(x...) printf(x) static double @@ -95,6 +95,8 @@ #define DBGOUT(x...) #endif +#define A(a) ((a) < 0 ? -(a) : (a)) + /* * Convolve one subpath with a convex pen. The result is * a closed path. @@ -104,21 +106,22 @@ twin_path_t *stroke, twin_path_t *pen) { - twin_spoint_t *sp = stroke->points; - twin_spoint_t *pp = pen->points; + twin_spoint_t *sp = stroke->points; + twin_spoint_t *pp = pen->points; int ns = stroke->npoints; int np = pen->npoints; - twin_spoint_t *sp0 = &sp[0]; - twin_spoint_t *sp1 = &sp[1]; + twin_spoint_t *sp0 = &sp[0]; + twin_spoint_t *sp1 = &sp[1]; int start = _twin_path_leftpoint (pen, sp0, sp1); - twin_spoint_t *spn1 = &sp[ns-1]; - twin_spoint_t *spn2 = &sp[ns-2]; + twin_spoint_t *spn1 = &sp[ns-1]; + twin_spoint_t *spn2 = &sp[ns-2]; int ret = _twin_path_leftpoint (pen, spn1, spn2); int p; int s; int starget; int ptarget; int inc; + int first; DBGOUT ("convolve stroke:\n"); for (s = 0; s < ns; s++) @@ -135,6 +138,7 @@ p, F(pp[p].x), F(pp[p].y), F(sp[s].x + pp[p].x), F(sp[s].y + pp[p].y)); _twin_path_smove (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y); + first = path->npoints - 1; /* step along the path first */ inc = 1; @@ -186,15 +190,67 @@ */ /* draw a cap */ - while (p != ptarget) - { - if (++p == np) p = 0; - DBGOUT("cap: "); - DBGOUT ("s%02d (%9.4f, %9.4f), p%02d (%9.4f, %9.4f): %9.4f, %9.4f\n", - s, F(sp[s].x), F(sp[s].y), - p, F(pp[p].x), F(pp[p].y), - F(sp[s].x + pp[p].x), F(sp[s].y + pp[p].y)); - _twin_path_sdraw (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y); + switch (path->state.cap_style) { + int pm; + case TwinCapProjecting: + /* + * This draws a rough projecting cap using the + * pen. + * + * First, project the line forward one pen radius + * by finding the pen location halfway between the + * two normals. + * + * Then, just add that to the normals themselves to + * find the corners of the projecting cap. + * + * The result may have significant error, so overwrite + * the existing corners with the new coordinates to + * avoid a kink. + */ + if (p <= ptarget) + pm = (ptarget + p) >> 1; + else + { + pm = (ptarget + np + p) >> 1; + if (pm >= np) pm -= np; + } + + /* replace last point with corner of cap */ + path->npoints--; + _twin_path_sdraw (path, + sp[s].x + pp[pm].x + pp[p].x, + sp[s].y + pp[pm].y + pp[p].y); + p = ptarget; + if (inc == 1) + { + /* start next line at cap corner */ + _twin_path_sdraw (path, + sp[s].x + pp[pm].x + pp[p].x, + sp[s].y + pp[pm].y + pp[p].y); + } + else + { + /* overwrite initial point */ + path->points[first].x = sp[s].x + pp[pm].x + pp[p].x; + path->points[first].y = sp[s].y + pp[pm].y + pp[p].y; + } + break; + case TwinCapButt: + p = ptarget-1; + /* fall through … */ + case TwinCapRound: + while (p != ptarget) + { + if (++p == np) p = 0; + DBGOUT("cap: "); + DBGOUT ("s%02d (%9.4f, %9.4f), p%02d (%9.4f, %9.4f): %9.4f, %9.4f\n", + s, F(sp[s].x), F(sp[s].y), + p, F(pp[p].x), F(pp[p].y), + F(sp[s].x + pp[p].x), F(sp[s].y + pp[p].y)); + _twin_path_sdraw (path, sp[s].x + pp[p].x, sp[s].y + pp[p].y); + } + break; } if (inc == -1) @@ -205,6 +261,7 @@ ptarget = start; starget = 0; } + twin_path_close (path); } void Index: twin_demo.c =================================================================== RCS file: /local/src/CVS/twin/twin_demo.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_demo.c 26 Oct 2004 06:15:42 -0000 1.2 +++ twin_demo.c 29 Oct 2004 17:33:03 -0000 1.3 @@ -78,45 +78,24 @@ twin_window_t *window = twin_window_create (screen, TWIN_ARGB32, TwinWindowApplication, x, y, w, h); - int wid = window->client.right - window->client.left; - int hei = window->client.bottom - window->client.top; twin_pixmap_t *pixmap = window->pixmap; - twin_path_t *path = twin_path_create (); - twin_path_t *pen = twin_path_create (); twin_path_t *stroke = twin_path_create (); - twin_pixmap_t *alpha = twin_pixmap_create (TWIN_A8, w, h); - twin_operand_t source, mask; + twin_fixed_t fy; + twin_path_translate (stroke, D(200), D(200)); twin_fill (pixmap, 0xffffffff, TWIN_SOURCE, - 0, 0, wid, hei); + 0, 0, w, h); twin_window_set_name (window, "line"); - twin_path_circle (pen, D (1)); - - stroke = twin_path_create (); - pen = twin_path_create (); - twin_path_translate (stroke, D(100), D(100)); - -/* twin_path_rotate (stroke, twin_degrees_to_angle (270)); */ - twin_path_rotate (stroke, twin_degrees_to_angle (270)); - twin_path_move (stroke, D(0), D(0)); - twin_path_draw (stroke, D(100), D(0)); - twin_path_set_matrix (pen, twin_path_current_matrix (stroke)); - twin_path_circle (pen, D(20)); - twin_path_convolve (path, stroke, pen); - - twin_fill_path (alpha, path, 0, 0); - twin_path_destroy (path); - twin_path_destroy (pen); + for (fy = 0; fy < 150; fy += 40) + { + twin_path_move (stroke, D(-150), -D(fy)); + twin_path_draw (stroke, D(150), D(fy)); + } + twin_path_set_cap_style (stroke, TwinCapProjecting); + twin_paint_stroke (pixmap, 0xff000000, stroke, D(10)); twin_path_destroy (stroke); - source.source_kind = TWIN_SOLID; - source.u.argb = 0xff000000; - mask.source_kind = TWIN_PIXMAP; - mask.u.pixmap = alpha; - twin_composite (pixmap, 0, 0, - &source, 0, 0, &mask, 0, 0, TWIN_OVER, wid, hei); - twin_pixmap_destroy (alpha); twin_window_show (window); } @@ -140,7 +119,7 @@ twin_window_set_name (window, "circletext"); twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); - twin_path_circle (pen, D (1)); + twin_path_circle (pen, 0, 0, D (1)); twin_path_translate (path, D(200), D(200)); twin_path_set_font_size (path, D(15)); @@ -186,7 +165,7 @@ twin_fill (pixmap, 0xffffffff, TWIN_SOURCE, 0, 0, wid, hei); - twin_path_circle (pen, D (1)); + twin_path_circle (pen, 0, 0, D (1)); fx = D(3); fy = D(8); @@ -233,7 +212,7 @@ twin_window_set_name (window, "ASCII"); twin_fill (pixmap, 0xffffffff, TWIN_SOURCE, 0, 0, wid, hei); - twin_path_circle (pen, D (1)); + twin_path_circle (pen, 0, 0, D (1)); fx = D(3); fy = D(8); @@ -328,11 +307,15 @@ void twin_demo_start (twin_screen_t *screen, const char *name, int x, int y, int w, int h) { +#if 0 twin_circletext_start (screen, x, y, w, h); +#endif twin_line_start (screen, x += 20, y += 20, w, h); +#if 0 twin_quickbrown_start (screen, x += 20, y += 20, w, h); twin_ascii_start (screen, x += 20, y += 20, w, h); twin_jelly_start (screen, x += 20, y += 20, w, h); +#endif #if 0 #if 0 --- NEW FILE: twin_demoline.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_demoline.h --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_demospline.c --- (This appears to be a binary file; contents omitted.) --- NEW FILE: twin_demospline.h --- (This appears to be a binary file; contents omitted.) Index: twin_draw.c =================================================================== RCS file: /local/src/CVS/twin/twin_draw.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- twin_draw.c 27 Oct 2004 06:07:35 -0000 1.8 +++ twin_draw.c 29 Oct 2004 17:33:03 -0000 1.9 @@ -274,23 +274,23 @@ twin_coord_t height) { twin_coord_t iy; - twin_coord_t left, right, top, bottom; + twin_coord_t left, top, right, bottom; twin_coord_t sdx, sdy; twin_source_u s; dst_x += dst->clip.left; dst_y += dst->clip.top; left = dst_x; - right = dst_x + width; top = dst_y; + right = dst_x + width; bottom = dst_y + height; /* clip */ if (left < dst->clip.left) left = dst->clip.left; - if (right > dst->clip.right) - right = dst->clip.right; if (top < dst->clip.top) top = dst->clip.top; + if (right > dst->clip.right) + right = dst->clip.right; if (bottom > dst->clip.bottom) bottom = dst->clip.bottom; Index: twin_font.c =================================================================== RCS file: /local/src/CVS/twin/twin_font.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- twin_font.c 27 Oct 2004 02:46:40 -0000 1.14 +++ twin_font.c 29 Oct 2004 17:33:03 -0000 1.15 @@ -196,7 +196,7 @@ twin_path_t *pen = twin_path_create (); twin_path_set_matrix (pen, info->pen_matrix); - twin_path_circle (pen, TWIN_FIXED_ONE); + twin_path_circle (pen, 0, 0, TWIN_FIXED_ONE); return pen; } Index: twin_glyphs.c =================================================================== RCS file: /local/src/CVS/twin/twin_glyphs.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- twin_glyphs.c 26 Oct 2004 06:15:42 -0000 1.6 +++ twin_glyphs.c 29 Oct 2004 17:33:03 -0000 1.7 @@ -209,11 +209,11 @@ 'e', /* 0x31 '1' offset 666 */ 0, 28, 42, 0, 2, 3, - 0, 14, 28 /* snap_x */ + 0, 17, 28 /* snap_x */ -21, -15, 0, /* snap_y */ - 'm', 4, -34, - 'c', 8, -35, 12, -38, 14, -42, - 'l', 14, 0, + 'm', 7, -34, + 'c', 11, -35, 15, -38, 17, -42, + 'l', 17, 0, 'e', /* 0x32 '2' offset 691 */ 0, 28, 42, 0, 4, 4, Index: twin_label.c =================================================================== RCS file: /local/src/CVS/twin/twin_label.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- twin_label.c 27 Oct 2004 20:09:36 -0000 1.3 +++ twin_label.c 29 Oct 2004 17:33:03 -0000 1.4 @@ -54,13 +54,25 @@ { twin_fixed_t wf = twin_int_to_fixed (w); twin_fixed_t hf = twin_int_to_fixed (h); + twin_fixed_t x, y; twin_path_set_font_size (path, label->font_size); twin_path_set_font_style (path, label->font_style); twin_text_metrics_utf8 (path, label->label, &m); - twin_path_move (path, (wf - m.width) / 2 + label->offset.x, - (hf - (m.ascent + m.descent)) / 2 + m.ascent + label->offset.y); - + y = (hf - (m.ascent + m.descent)) / 2 + m.ascent + label->offset.y; + switch (label->align) { + case TwinAlignLeft: + x = label->font_size / 2; + break; + case TwinAlignCenter: + x = (wf - m.width) / 2; + break; + case TwinAlignRight: + x = wf - label->font_size / 2 - m.width; + break; + } + x += label->offset.x; + twin_path_move (path, x, y); twin_path_utf8 (path, label->label); twin_paint_path (label->widget.window->pixmap, label->foreground, path); twin_path_destroy (path); @@ -126,6 +138,7 @@ label->label = NULL; label->offset.x = 0; label->offset.y = 0; + label->align = TwinAlignCenter; twin_label_set (label, value, foreground, font_size, font_style); } Index: twin_path.c =================================================================== RCS file: /local/src/CVS/twin/twin_path.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- twin_path.c 25 Oct 2004 19:09:36 -0000 1.12 +++ twin_path.c 29 Oct 2004 17:33:03 -0000 1.13 @@ -192,6 +192,27 @@ } } +void +twin_path_circle (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t radius) +{ + twin_path_ellipse (path, x, y, radius, radius); +} + +void +twin_path_ellipse (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t x_radius, + twin_fixed_t y_radius) +{ + twin_path_move (path, x + x_radius, y); + twin_path_arc (path, x, y, x_radius, y_radius, 0, TWIN_ANGLE_360); + twin_path_close (path); +} + #define twin_fixed_abs(f) ((f) < 0 ? -(f) : (f)) static twin_fixed_t @@ -202,90 +223,146 @@ } void -twin_path_circle (twin_path_t *path, twin_fixed_t radius) +twin_path_arc (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t x_radius, + twin_fixed_t y_radius, + twin_angle_t start, + twin_angle_t extent) { - int sides; - int n; - twin_spoint_t center; - int i; - twin_matrix_t save; + twin_matrix_t save = twin_path_current_matrix (path); twin_fixed_t max_radius; + int32_t sides; + int32_t n; + twin_angle_t a; + twin_angle_t first, last, step, inc; + twin_angle_t epsilon; - save = twin_path_current_matrix (path); - - twin_path_scale (path, radius, radius); - - center = _twin_path_current_spoint (path); + twin_path_translate (path, x, y); + twin_path_scale (path, x_radius, y_radius); - _twin_path_sfinish (path); - max_radius = _twin_matrix_max_radius (&path->state.matrix); - sides = max_radius / twin_sfixed_to_fixed (TWIN_SFIXED_TOLERANCE); - if (sides > 1024) sides = 1024; n = 2; while ((1 << n) < sides) n++; - for (i = 0; i <= (1 << n); i++) - { - twin_angle_t a = (i * TWIN_ANGLE_360) >> n; - twin_fixed_t x = twin_cos (a); - twin_fixed_t y = twin_sin (a); + sides = (1 << n); - _twin_path_sdraw (path, - center.x + _twin_matrix_dx (&path->state.matrix, x, y), - center.y + _twin_matrix_dy (&path->state.matrix, x, y)); + step = TWIN_ANGLE_360 >> n; + inc = step; + epsilon = 1; + if (extent < 0) + { + inc = -inc; + epsilon = -1; } - _twin_path_sfinish (path); + first = (start + inc - epsilon) & ~(step - 1); + last = (start + extent - inc + epsilon) & ~(step - 1); + + if (first != start) + twin_path_draw (path, twin_cos(start), twin_sin(start)); + + for (a = first; a != last; a += inc) + twin_path_draw (path, twin_cos (a), twin_sin (a)); + + if (last != start + extent) + twin_path_draw (path, twin_cos (start+extent), twin_sin(start+extent)); + twin_path_set_matrix (path, save); } void -twin_path_ellipse (twin_path_t *path, - twin_fixed_t x_radius, - twin_fixed_t y_radius) +twin_path_rectangle (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h) { - int sides; - int n; - twin_spoint_t center; - int i; - twin_matrix_t save; - twin_fixed_t max_radius; - - save = twin_path_current_matrix (path); - - twin_path_scale (path, x_radius, y_radius); - - center = _twin_path_current_spoint (path); + twin_path_move (path, x, y); + twin_path_draw (path, x+w, y); + twin_path_draw (path, x+w, y+h); + twin_path_draw (path, x, y+h); + twin_path_close (path); +} + +void +twin_path_rounded_rectangle (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h, + twin_fixed_t x_radius, + twin_fixed_t y_radius) +{ + twin_matrix_t save = twin_path_current_matrix (path); - _twin_path_sfinish (path); - - max_radius = _twin_matrix_max_radius (&path->state.matrix); - - sides = max_radius / twin_sfixed_to_fixed (TWIN_SFIXED_TOLERANCE); - - if (sides > 1024) sides = 1024; + twin_path_translate (path, x, y); + twin_path_move (path, + 0, y_radius); + twin_path_arc (path, x_radius, y_radius, x_radius, y_radius, + TWIN_ANGLE_180, TWIN_ANGLE_90); + twin_path_draw (path, + w - x_radius, 0); + twin_path_arc (path, w - x_radius, y_radius, x_radius, y_radius, + TWIN_ANGLE_270, TWIN_ANGLE_90); + twin_path_draw (path, + w, h - y_radius); + twin_path_arc (path, w - x_radius, h - y_radius, x_radius, y_radius, + TWIN_ANGLE_0, TWIN_ANGLE_90); + twin_path_draw (path, + x_radius, h); + twin_path_arc (path, x_radius, h - y_radius, x_radius, y_radius, + TWIN_ANGLE_90, TWIN_ANGLE_90); + twin_path_close (path); + twin_path_set_matrix (path, save); +} + +void +twin_path_lozenge (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h) +{ + twin_fixed_t radius; - n = 2; - while ((1 << n) < sides) - n++; + if (w > h) + radius = h / 2; + else + radius = w / 2; + twin_path_rounded_rectangle (path, x, y, w, h, radius, radius); +} - for (i = 0; i <= (1 << n); i++) - { - twin_angle_t a = (i * TWIN_ANGLE_360) >> n; - twin_fixed_t x = twin_cos (a); - twin_fixed_t y = twin_sin (a); +void +twin_path_tab (twin_path_t *path, + twin_fixed_t x, + twin_fixed_t y, + twin_fixed_t w, + twin_fixed_t h, + twin_fixed_t x_radius, + twin_fixed_t y_radius) +{ + twin_matrix_t save = twin_path_current_matrix (path); - _twin_path_sdraw (path, - center.x + _twin_matrix_dx (&path->state.matrix, x, y), - center.y + _twin_matrix_dy (&path->state.matrix, x, y)); - } - - _twin_path_sfinish (path); + twin_path_translate (path, x, y); + twin_path_move (path, + 0, y_radius); + twin_path_arc (path, x_radius, y_radius, x_radius, y_radius, + TWIN_ANGLE_180, TWIN_ANGLE_90); + twin_path_draw (path, + w - x_radius, 0); + twin_path_arc (path, w - x_radius, y_radius, x_radius, y_radius, + TWIN_ANGLE_270, TWIN_ANGLE_90); + twin_path_draw (path, + w, h); + twin_path_draw (path, + 0, h); + twin_path_close (path); twin_path_set_matrix (path, save); } @@ -350,6 +427,18 @@ } void +twin_path_set_cap_style (twin_path_t *path, twin_cap_t cap_style) +{ + path->state.cap_style = cap_style; +} + +twin_cap_t +twin_path_current_cap_style (twin_path_t *path) +{ + return path->state.cap_style; +} + +void twin_path_empty (twin_path_t *path) { path->npoints = 0; @@ -424,6 +513,7 @@ twin_matrix_identity (&path->state.matrix); path->state.font_size = TWIN_FIXED_ONE * 15; path->state.font_style = TWIN_TEXT_ROMAN; + path->state.cap_style = TwinCapRound; return path; } @@ -496,7 +586,8 @@ m.m[2][0] = 0; m.m[2][1] = 0; twin_path_set_matrix (pen, m); - twin_path_circle (pen, pen_width / 2); + twin_path_set_cap_style (path, twin_path_current_cap_style (stroke)); + twin_path_circle (pen, 0, 0, pen_width / 2); twin_path_convolve (path, stroke, pen); twin_composite_path (dst, src, src_x, src_y, path, operator); twin_path_destroy (path); Index: twin_toplevel.c =================================================================== RCS file: /local/src/CVS/twin/twin_toplevel.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- twin_toplevel.c 27 Oct 2004 20:09:36 -0000 1.2 +++ twin_toplevel.c 29 Oct 2004 17:33:03 -0000 1.3 @@ -51,7 +51,7 @@ { twin_toplevel_t *toplevel = window->client_data; - return (*toplevel->box.widget.dispatch) (&toplevel->box.widget, event); + return (*toplevel->box.widget.dispatch) (&toplevel->box.widget, event) == TwinDispatchDone; } static void Index: twin_widget.c =================================================================== RCS file: /local/src/CVS/twin/twin_widget.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_widget.c 27 Oct 2004 20:34:55 -0000 1.5 +++ twin_widget.c 29 Oct 2004 17:33:03 -0000 1.6 @@ -24,14 +24,74 @@ #include "twinint.h" -static void -_twin_widget_paint (twin_widget_t *widget) +static twin_path_t * +_twin_path_shape (twin_shape_t shape, + twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom, + twin_fixed_t radius) +{ + twin_path_t *path = twin_path_create (); + twin_fixed_t x = twin_int_to_fixed (left); + twin_fixed_t y = twin_int_to_fixed (top); + twin_fixed_t w = twin_int_to_fixed (right - left); + twin_fixed_t h = twin_int_to_fixed (bottom - top); + + if (!path) + return 0; + switch (shape) { + case TwinShapeRectangle: + twin_path_rectangle (path, x, y, w, h); + break; + case TwinShapeRoundedRectangle: + twin_path_rounded_rectangle (path, x, h, w, y, radius, radius); + break; + case TwinShapeLozenge: + twin_path_lozenge (path, x, y, w, h); + break; + case TwinShapeTab: + twin_path_tab (path, x, y, w, h, radius, radius); + break; + case TwinShapeEllipse: + twin_path_ellipse (path, x + w/2, y + h/2, w/2, h/2); + break; + } + return path; +} + +void +_twin_widget_paint_shape (twin_widget_t *widget, + twin_shape_t shape, + twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom, + twin_fixed_t radius) { twin_pixmap_t *pixmap = widget->window->pixmap; - twin_coord_t w = widget->extents.right - widget->extents.left; - twin_coord_t h = widget->extents.bottom - widget->extents.top; - twin_fill (pixmap, widget->background, TWIN_SOURCE, 0, 0, w, h); + if (shape == TwinShapeRectangle) + twin_fill (pixmap, widget->background, TWIN_SOURCE, + left, top, right, bottom); + else + { + twin_path_t *path = _twin_path_shape (shape, left, top, + right, bottom, radius); + if (path) + { + twin_paint_path (pixmap, widget->background, path); + twin_path_destroy (path); + } + } +} + +static void +_twin_widget_paint (twin_widget_t *widget) +{ + _twin_widget_paint_shape (widget, widget->shape, 0, 0, + _twin_widget_width (widget), + _twin_widget_height (widget), widget->radius); } twin_dispatch_result_t @@ -91,6 +151,8 @@ widget->extents.right = widget->extents.bottom = 0; widget->preferred = preferred; widget->dispatch = dispatch; + widget->shape = TwinShapeRectangle; + widget->radius = twin_int_to_fixed (12); } void @@ -129,6 +191,19 @@ 0 <= y && y < _twin_widget_height(widget)); } +static twin_path_t * +_twin_path_bevel_shape (twin_shape_t shape, + twin_bool_t upper, + twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom, + twin_fixed_t radius, + twin_fixed_t bw) +{ + return 0; +} + void _twin_widget_bevel (twin_widget_t *widget, twin_fixed_t b, Index: twin_window.c =================================================================== RCS file: /local/src/CVS/twin/twin_window.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- twin_window.c 26 Oct 2004 19:56:19 -0000 1.5 +++ twin_window.c 29 Oct 2004 17:33:03 -0000 1.6 @@ -43,7 +43,7 @@ twin_coord_t height) { twin_window_t *window = malloc (sizeof (twin_window_t)); - twin_coord_t left, right, top, bottom; + twin_coord_t left, top, right, bottom; if (!window) return NULL; window->screen = screen; @@ -66,8 +66,8 @@ width += left + right; height += top + bottom; window->client.left = left; - window->client.right = width - right; window->client.top = top; + window->client.right = width - right; window->client.bottom = height - bottom; window->pixmap = twin_pixmap_create (format, width, height); twin_pixmap_clip (window->pixmap, @@ -334,9 +334,6 @@ twin_event_t ev = *event; twin_bool_t delegate = TWIN_TRUE; - if (!window->event) - delegate = TWIN_FALSE; - switch (ev.kind) { case TwinEventButtonDown: if (window->client.left <= ev.u.pointer.x && @@ -380,6 +377,9 @@ default: break; } + if (!window->event) + delegate = TWIN_FALSE; + if (delegate && (*window->event) (window, &ev)) return TWIN_TRUE; Index: twin_x11.c =================================================================== RCS file: /local/src/CVS/twin/twin_x11.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- twin_x11.c 26 Oct 2004 06:15:42 -0000 1.8 +++ twin_x11.c 29 Oct 2004 17:33:03 -0000 1.9 @@ -105,6 +105,8 @@ case ButtonRelease: tev.u.pointer.screen_x = ev.xbutton.x; tev.u.pointer.screen_y = ev.xbutton.y; + tev.u.pointer.button = ((ev.xbutton.state >> 8) | + (1 << (ev.xbutton.button-1))); tev.kind = ((ev.type == ButtonPress) ? TwinEventButtonDown : TwinEventButtonUp); twin_screen_dispatch (tx->screen, &tev); @@ -113,7 +115,7 @@ tev.u.pointer.screen_x = ev.xmotion.x; tev.u.pointer.screen_y = ev.xmotion.y; tev.kind = TwinEventMotion; - tev.u.pointer.button = ev.xmotion.state; + tev.u.pointer.button = ev.xbutton.state >> 8; twin_screen_dispatch (tx->screen, &tev); break; } Index: twinint.h =================================================================== RCS file: /local/src/CVS/twin/twinint.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- twinint.h 27 Oct 2004 20:09:36 -0000 1.17 +++ twinint.h 29 Oct 2004 17:33:03 -0000 1.18 @@ -468,6 +468,15 @@ twin_widget_layout_t preferred, twin_dispatch_proc_t dispatch); +void +_twin_widget_paint_shape (twin_widget_t *widget, + twin_shape_t shape, + twin_coord_t left, + twin_coord_t top, + twin_coord_t right, + twin_coord_t bottom, + twin_fixed_t radius); + twin_dispatch_result_t _twin_widget_dispatch (twin_widget_t *widget, twin_event_t *event); Index: xtwin.c =================================================================== RCS file: /local/src/CVS/twin/xtwin.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- xtwin.c 27 Oct 2004 20:34:55 -0000 1.24 +++ xtwin.c 29 Oct 2004 17:33:03 -0000 1.25 @@ -34,6 +34,8 @@ #include #include #include +#include +#include #define WIDTH 512 #define HEIGHT 512 @@ -47,14 +49,25 @@ twin_screen_set_background (x11->screen, twin_make_pattern ()); #if 0 twin_demo_start (x11->screen, "Demo", 100, 100, 400, 400); - twin_text_start (x11->screen, "Gettysburg Address", - 0, 0, 300, 300); - twin_hello_start (x11->screen, "Hello, World", - 0, 0, 200, 200); #endif +#if 0 + twin_text_start (x11->screen, "Gettysburg Address", 0, 0, 300, 300); +#endif +#if 0 + twin_hello_start (x11->screen, "Hello, World", 0, 0, 200, 200); +#endif +#if 1 twin_clock_start (x11->screen, "Clock", 10, 10, 200, 200); - twin_calc_start (x11->screen, "Calculator", - 100, 100, 200, 200); +#endif +#if 1 + twin_calc_start (x11->screen, "Calculator", 100, 100, 200, 200); +#endif +#if 1 + twin_demoline_start (x11->screen, "Demo Line", 0, 0, 400, 400); +#endif +#if 1 + twin_demospline_start (x11->screen, "Demo Spline", 20, 20, 400, 400); +#endif twin_dispatch (); return 0; }