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_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);
}
static void
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,
						  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_fixed_t    fx, fy;
    int		    s;
    
    twin_window_set_name (window, "Jelly");
    
    twin_fill (pixmap, 0xffffffff, TWIN_SOURCE, 
	       0, 0, wid, hei);
    
    fx = D(3);
    fy = D(8);
    for (s = 6; s < 36; s += 2)
    {
	twin_path_set_font_size (path, D(s));
	fy += D(s + 2);
	twin_path_move (path, fx, fy);
#define TEXT	"jelly text"
/*	twin_path_set_font_style (path, TWIN_TEXT_UNHINTED); */
	twin_path_utf8 (path, TEXT);
	twin_paint_path (pixmap, 0xff000000, path);
	twin_path_empty (path);
	{
	    twin_text_metrics_t	m;
	    twin_path_t	*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 (pixmap, 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 (pixmap, 0xff00ff00, stroke, D(1));
	    twin_path_destroy (stroke);
	}
    }
    twin_window_show (window);
}
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)
{
    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;

    twin_path_translate (path, x, y);
    twin_path_scale (path, x_radius, y_radius);

    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++;

    sides = (1 << n);

    step = TWIN_ANGLE_360 >> n;
    inc = step;
    epsilon = 1;
    if (extent < 0)
    {
	inc = -inc;
	epsilon = -1;
    }
    
    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_composite_stroke (twin_pixmap_t	*dst,
		       twin_operand_t	*src,
		       twin_coord_t	src_x,
		       twin_coord_t	src_y,
		       twin_path_t	*stroke,
		       twin_fixed_t	pen_width,
		       twin_operator_t	operator)
{
    twin_path_t	    *pen = twin_path_create ();
    twin_path_t	    *path = twin_path_create ();
    twin_matrix_t   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_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);
    twin_path_destroy (pen);
}
Beispiel #5
0
static void
twin_clock_hand (twin_clock_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, 0, 0, fill_width);
    twin_path_convolve (path, stroke, pen);

    twin_paint_path (_twin_clock_pixmap(clock), fill_pixel, path);

    twin_paint_stroke (_twin_clock_pixmap(clock), out_pixel, path, out_width);
    
    twin_path_destroy (path);
    twin_path_destroy (pen);
    twin_path_destroy (stroke);
}