Ejemplo n.º 1
0
static gboolean
gtk_clock_update (gpointer data)
{
	GtkClock *clock = GTK_CLOCK (data);
	GtkClockPrivate *priv = GTK_CLOCK_GET_PRIVATE (clock);
	time_t timet;

	time (&timet);
	localtime_r (&timet, &priv->time);

	gtk_clock_redraw_canvas (clock);

	return TRUE;
}
Ejemplo n.º 2
0
static void gtk_clock_init (GtkClock *clock)
{
	clock->priv = GTK_CLOCK_GET_PRIVATE (clock);
    clock->priv->secflash = TRUE;
    clock->priv->time = NULL;
    clock->priv->date = NULL;
    gtk_widget_set_has_window (GTK_WIDGET(clock), FALSE);

    weekday[0] = _("Sunday");
    weekday[1] = _("Monday");
    weekday[2] = _("Tuesday");
    weekday[3] = _("Wednesday");
    weekday[4] = _("Thursday");
    weekday[5] = _("Friday");
    weekday[6] = _("Saturday");

    month[0] = _("Jan");
    month[1] = _("Feb");
    month[2] = _("Mar");
    month[3] = _("Apr");
    month[4] = _("May");
    month[5] = _("Jun");
    month[6] = _("Jul");
    month[7] = _("Aug");
    month[8] = _("Sep");
    month[9] = _("Oct");
    month[10] = _("Nov");
    month[11] = _("Dec");

    day[1] = _("1");
    day[2] = _("2");
    day[3] = _("3");
    day[4] = _("4");
    day[5] = _("5");
    day[6] = _("6");
    day[7] = _("7");
    day[8] = _("8");
    day[9] = _("9");
    day[10] = _("10");
    day[11] = _("11");
    day[12] = _("12");
    day[13] = _("13");
    day[14] = _("14");
    day[15] = _("15");
    day[16] = _("16");
    day[17] = _("17");
    day[18] = _("18");
    day[19] = _("19");
    day[20] = _("20");
    day[21] = _("21");
    day[22] = _("22");
    day[23] = _("23");
    day[24] = _("24");
    day[25] = _("25");
    day[26] = _("26");
    day[27] = _("27");
    day[28] = _("28");
    day[29] = _("29");
    day[30] = _("30");
    day[31] = _("31");
}
Ejemplo n.º 3
0
static gboolean
gtk_clock_draw (GtkWidget *clock, cairo_t *cr)
{
	gint width = gtk_widget_get_allocated_width (clock);
	gint height = gtk_widget_get_allocated_height (clock);
	gdouble cx = width / 2.0;
	gdouble cy = height / 2.0;
	gdouble radius = MIN (width/2, height/2) - 5;
	gint inset;
	gint i;
	GtkClockPrivate *priv = GTK_CLOCK_GET_PRIVATE (clock);
	struct tm *time = &priv->time;
	cairo_pattern_t *pat;

	cairo_arc (cr, cx, cy, radius, 0, 2 * M_PI);
	cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
	cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_stroke (cr);

	for (i = 0; i < 12; i++)
	{
		cairo_save (cr);

		if (i % 3 == 0)
			inset = 0.2 * radius;
		else {
			inset = 0.1 * radius;
			cairo_set_line_width (cr,
				0.5 * cairo_get_line_width (cr));
		}

		cairo_move_to (cr,
				cx + (radius - inset) * cos (i * M_PI / 6),
				cy + (radius - inset) * sin (i * M_PI / 6));
		cairo_line_to (cr,
				cx + radius * cos (i * M_PI / 6),
				cy + radius * sin (i * M_PI / 6));
		cairo_stroke (cr);

		cairo_restore (cr);
	}

	cairo_set_line_width (cr, 2.0 * cairo_get_line_width (cr));
	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);

	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius / 2 * sin (M_PI / 6 * time->tm_hour +
						M_PI / 360 * time->tm_min),
			cy + radius / 2 * -cos (M_PI / 6 * time->tm_hour +
						M_PI / 360 * time->tm_min));
	cairo_stroke (cr);

	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_min),
			cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_min));
	cairo_stroke (cr);

	cairo_set_line_width (cr, 0.2 * cairo_get_line_width (cr));
	cairo_set_source_rgb (cr, 1, 0, 0);
	cairo_move_to (cr, cx, cy);
	cairo_line_to (cr, cx + radius * 0.75 * sin (M_PI / 30 * time->tm_sec),
			cy + radius * 0.75 * -cos (M_PI / 30 * time->tm_sec));
	cairo_stroke (cr);

	cairo_arc (cr, cx, cy, radius, 0.0, 2.0 * M_PI);

	pat = cairo_pattern_create_radial (cx, cy, radius,
                                   cx,  0, radius);
	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 0.4);
	cairo_pattern_add_color_stop_rgba (pat, 1, 1, 1, 1, 0.0);
	cairo_set_source (cr, pat);
	cairo_fill (cr);
	cairo_pattern_destroy (pat); 

	return TRUE;
}