Ejemplo n.º 1
0
static void
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,
						  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_pixmap_t   *alpha = twin_pixmap_create (TWIN_A8, wid, hei);
    int		    s;
    twin_operand_t  source, mask;
    
    twin_fill (pixmap, 0xffffffff, TWIN_SOURCE, 
	       0, 0, wid, hei);
    twin_window_set_name (window, "circletext");
    
    twin_path_set_font_style (path, TWIN_TEXT_UNHINTED);
    twin_path_circle (pen, 0, 0, D (1));
    
    twin_path_translate (path, D(200), D(200));
    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_fill_path (alpha, path, 0, 0);
    twin_path_destroy (path);
    twin_path_destroy (pen);
    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);
}
Ejemplo n.º 2
0
static void
_twin_clock_face (twin_clock_t *clock)
{
    twin_path_t	    *path = twin_path_create ();
    int		    m;

    twin_clock_set_transform (clock, path);

    twin_path_circle (path, 0, 0, TWIN_FIXED_ONE);
    
    twin_paint_path (_twin_clock_pixmap(clock), TWIN_CLOCK_BACKGROUND, path);

    twin_paint_stroke (_twin_clock_pixmap(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, 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 (_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 (_twin_clock_pixmap(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);
	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 (_twin_clock_pixmap(clock), 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 (_twin_clock_pixmap(clock), TWIN_CLOCK_NUMBERS, path);
	}
        twin_path_restore (path, &state);
    }
    
    twin_path_destroy (path);
}