diff options
author | Joel Bosveld <Joel.Bosveld@gmail.com> | 2009-07-08 16:03:51 +0800 |
---|---|---|
committer | Joel Bosveld <Joel.Bosveld@gmail.com> | 2009-07-08 16:03:51 +0800 |
commit | b115611081f232aad3a673afd50903a87a78b5bc (patch) | |
tree | 8c6be16607a1d33ea81667642ddee28fce42f6b0 | |
parent | a0662523fc5aed725a9a409a948606f90dba5782 (diff) |
sub: add initial ability to deform subwindow meshes
-rw-r--r-- | sub/sub.c | 64 |
1 files changed, 39 insertions, 25 deletions
@@ -8,12 +8,11 @@ #define N_SUB 5 #define IntToxFixed(x) ((x)<<16); -#define CSIZE 128 +#define CSIZE 256 typedef struct { Window id; - Pixmap p; int width, height; XTriangle *mesh; cairo_matrix_t *m; @@ -23,19 +22,21 @@ typedef struct int x, y; cairo_surface_t *s; cairo_t *cr; + cairo_pattern_t *p; } SubWindow; Display *d; Window w; SubWindow sub[N_SUB]; Visual *v; +int OFFSET = 0; static void meshSquare (XTriangle t[4], int px1, int py1, int px2, int py2, int cx1, int cy1, int cx2, int cy2) { - t[0].p1.x = IntToxFixed (px1); - t[0].p1.y = IntToxFixed (py1); + t[0].p1.x = IntToxFixed (px1+OFFSET); + t[0].p1.y = IntToxFixed (py1+OFFSET); t[0].p2.x = IntToxFixed (px2); t[0].p2.y = IntToxFixed (py1); t[0].p3.x = IntToxFixed (px2); @@ -48,8 +49,8 @@ meshSquare (XTriangle t[4], int px1, int py1, int px2, int py2, t[1].p3.x = IntToxFixed (cx2); t[1].p3.y = IntToxFixed (cy2); - t[2].p1.x = IntToxFixed (px1); - t[2].p1.y = IntToxFixed (py1); + t[2].p1.x = IntToxFixed (px1+OFFSET); + t[2].p1.y = IntToxFixed (py1+OFFSET); t[2].p2.x = IntToxFixed (px2); t[2].p2.y = IntToxFixed (py2); t[2].p3.x = IntToxFixed (px1); @@ -131,14 +132,13 @@ setupMatrix (int xp1, int yp1, int xp2, int yp2, int xp3, int yp3, static void paintTri (cairo_t *cr, SubWindow *s, int i) { - cairo_pattern_t *pattern = cairo_pattern_create_for_surface (s->s); - cairo_pattern_set_matrix (pattern, &s->m[i]); - cairo_set_source (cr, pattern); + + cairo_pattern_set_matrix (s->p, &s->m[i]); + cairo_set_source (cr, s->p); cairo_move_to (cr, s->mesh[2*i].p1.x >> 16, s->mesh[2*i].p1.y >> 16); cairo_line_to (cr, s->mesh[2*i].p2.x >> 16, s->mesh[2*i].p2.y >> 16); cairo_line_to (cr, s->mesh[2*i].p3.x >> 16, s->mesh[2*i].p3.y >> 16); cairo_fill (cr); - cairo_pattern_destroy (pattern); } static void @@ -200,6 +200,22 @@ static Visual return visual; } +static void +setupSubWindow (SubWindow *s, int i) +{ + meshWindow (s->mesh, CSIZE*i, CSIZE*i, CSIZE*(i+1), CSIZE*(i+1), 0, 0, CSIZE, CSIZE); + XCompositeSetTriangularCoordinateMesh (d, s->id, s->mesh, s->nNormTri, s->nTotal - s->nNormTri); + + for (int j = 0; j < s->nNormTri; j+=2) + { + XTriangle p = s->mesh[j]; + XTriangle c = s->mesh[j+1]; + s->m[j/2] = setupMatrix (p.p1.x>>16, p.p1.y>>16, p.p2.x>>16, p.p2.y>>16, p.p3.x>>16, p.p3.y>>16, + c.p1.x>>16, c.p1.y>>16, c.p2.x>>16, c.p2.y>>16, c.p3.x>>16, c.p3.y>>16); + + } +} + int main (int argc, char **argv) { @@ -238,21 +254,11 @@ main (int argc, char **argv) sub[i].nNormTri = 4; sub[i].mesh = malloc (sizeof(XTriangle) * sub[i].nTotal); sub[i].m = malloc (sizeof(cairo_matrix_t) * sub[i].nNormTri / 2); - meshWindow (&sub[i].mesh[0], CSIZE*i, CSIZE*i, CSIZE*(i+1), CSIZE*(i+1), 0, 0, CSIZE, CSIZE); - XCompositeSetTriangularCoordinateMesh (d, sub[i].id, sub[i].mesh, sub[i].nNormTri, sub[i].nTotal - sub[i].nNormTri); - sub[i].p = XCompositeNameWindowPixmap (d, sub[i].id); - - for (int j = 0; j < sub[i].nNormTri; j+=2) - { - XTriangle p = sub[i].mesh[j]; - XTriangle c = sub[i].mesh[j+1]; - sub[i].m[j/2] = setupMatrix (p.p1.x>>16, p.p1.y>>16, p.p2.x>>16, p.p2.y>>16, p.p3.x>>16, p.p3.y>>16, - c.p1.x>>16, c.p1.y>>16, c.p2.x>>16, c.p2.y>>16, c.p3.x>>16, c.p3.y>>16); - - } + setupSubWindow (&sub[i], i); sub[i].s = cairo_xlib_surface_create (d, sub[i].id, v, CSIZE, CSIZE); sub[i].cr = cairo_create (sub[i].s); + sub[i].p = cairo_pattern_create_for_surface (sub[i].s); cairo_set_source_rgba (sub[i].cr, 0.0, 1.0, 0.0, 0.75); cairo_set_operator (sub[i].cr, CAIRO_OPERATOR_SOURCE); @@ -273,9 +279,17 @@ main (int argc, char **argv) { if ( ev.xany.window == w ) continue; SubWindow *s = findSubwindow (ev.xany.window); - s->drawing = true; - s->x = ev.xbutton.x; - s->y = ev.xbutton.y; + if (ev.xbutton.state & ControlMask) + { + OFFSET = - (OFFSET-64); + setupSubWindow (s, s - sub); + } + else + { + s->drawing = true; + s->x = ev.xbutton.x; + s->y = ev.xbutton.y; + } } break; case MotionNotify: |