summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--cairo-bclock.c4
-rwxr-xr-xcairo-testbin23170 -> 0 bytes
-rw-r--r--cairo-test.c170
-rwxr-xr-xvon-waitbin20737 -> 0 bytes
-rw-r--r--von-wait.c80
6 files changed, 189 insertions, 71 deletions
diff --git a/Makefile b/Makefile
index a3576aa..dd9d7d5 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,8 @@
APPS = \
cairo-test \
- von-wait
+ von-wait \
+ cairo-bclock \
+ cairo-rule
CFLAGS = -ggdb -Wall
@@ -10,4 +12,4 @@ LDFLAGS += `pkg-config gtk+-2.0 librsvg-2.0 --libs`
all: $(APPS)
clean:
- $(RM): $(APPS)
+ $(RM) $(APPS)
diff --git a/cairo-bclock.c b/cairo-bclock.c
index 36fe62c..946735b 100644
--- a/cairo-bclock.c
+++ b/cairo-bclock.c
@@ -187,8 +187,8 @@ static void paint (GtkWidget *widget, GdkEventExpose *eev, selection_t *sel) {
cr = gdk_cairo_create (widget->window);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-
- cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.4f);
+
+ cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.0f);
cairo_paint (cr);
diff --git a/cairo-test b/cairo-test
deleted file mode 100755
index 3e7da3f..0000000
--- a/cairo-test
+++ /dev/null
Binary files differ
diff --git a/cairo-test.c b/cairo-test.c
index b82b39d..7b0d507 100644
--- a/cairo-test.c
+++ b/cairo-test.c
@@ -2,8 +2,9 @@
#include <gtk/gtk.h>
#include <cairo.h>
#include <math.h>
-#include <librsvg/rsvg.h>
-#include <librsvg/rsvg-cairo.h>
+
+#include <unistd.h>
+#include <time.h>
#define SECOND_INTERVAL 1000
@@ -13,11 +14,31 @@
typedef struct
{
- gboolean active; /* whether the selection is active or not */
- gdouble x, y;
+ gboolean active; /* whether the selection is active or not */
+ gdouble x, y;
} selection_t;
+typedef struct
+{
+ float r;
+ float g;
+ float b;
+ float a;
+} color_t;
+
+static gboolean time_handler (GtkWidget* w)
+{
+ if (GTK_IS_WIDGET(w)) {
+ gdk_window_scroll (w->window, -20, 0);
+ printf("Moving.\n");
+ gtk_widget_queue_draw (w);
+ return TRUE;
+ } else {
+ _exit(-1);
+ return FALSE;
+ }
+}
gboolean on_key_press (GtkWidget *widget,
GdkEventKey *key,
@@ -88,72 +109,115 @@ static void paint_dot (cairo_t *cr, selection_t *sel) {
}
+void paint_rounded_box (cairo_t *cr, float x, float y,
+ float w, float h,
+ color_t *o, color_t *f,
+ float c)
+{
+ gint t, i;
+
+ cairo_save (cr);
+ cairo_translate (cr, x, y);
+ if (f) cairo_set_source_rgba (cr, f->r, f->g, f->b, f->a);
+ cairo_move_to (cr, - w/2, - h/2 + c);
+
+ for ( i = 0; i < 4; i++ ) {
+ cairo_translate (cr, -w/2.0, -h/2.0);
+
+ cairo_curve_to (cr, 0.0, c, 0.0, 0.0, c, 0.0);
+ cairo_line_to (cr, w - c, 0.0);
+
+ cairo_translate (cr, w/2.0, h/2.0);
+ cairo_rotate (cr, M_PI/2.0);
+ t = w; w = h; h = t;
+ }
+
+ if (f) cairo_fill_preserve (cr);
+ cairo_set_source_rgba (cr, o->r, o->g, o->b, o->a);
+ cairo_stroke (cr);
+ cairo_restore (cr);
+}
+
+void paint_rect (cairo_t *cr, float x, float y,
+ float w, float h,
+ color_t *o, color_t *f)
+{
+ cairo_save (cr);
+ cairo_translate (cr, x, y);
+ if (f) cairo_set_source_rgba (cr, f->r, f->g, f->b, f->a);
+ cairo_rectangle (cr, -w/2, -h/2, w, h);
+ if (f) cairo_fill_preserve (cr);
+ cairo_set_source_rgba (cr, o->r, o->g, o->b, o->a);
+ cairo_stroke (cr);
+ cairo_restore (cr);
+}
+
+
+void paint_clock_dot (cairo_t *cr, float x, float y,
+ float w, float h,
+ color_t *c)
+{
+ color_t back_o = { 0.0f, 0.0f, 0.0f, 1.0f };
+
+ /* paint_rounded_box (cr, x, y, w, h, &back_o, c, 5);*/
+ paint_rect (cr, x, y, w, h, &back_o, c);
+}
+
static void paint (GtkWidget *widget, GdkEventExpose *eev, selection_t *sel) {
- gint width, height, cache;
+ gint width, height;
cairo_t *cr;
- gint i;
- gchar d[2] = {'0','\0'};
- gfloat colors[6][3] = {{0.0f, 0.0f, 1.0f},
- {0.0f, 1.0f, 0.0f},
- {1.0f, 0.0f, 0.0f},
- {1.0f, 1.0f, 0.0f},
- {1.0f, 0.0f, 1.0f},
- {0.0f, 1.0f, 1.1f}};
-
+ cairo_surface_t *surface;
+ gint i, j;
+
+ time_t now;
+ struct tm *tm;
+
+ int timet[3];
+
+ color_t color[] = {{ 1.0f, 0.0f, 0.0f, 0.6f },
+ { 0.0f, 1.0f, 0.0f, 0.6f },
+ { 0.0f, 0.0f, 1.0f, 0.6f }};
+
+ now = time(NULL);
+ tm = localtime(&now);
+
+ timet[0] = tm->tm_hour;
+ timet[1] = tm->tm_min;
+ timet[2] = tm->tm_sec;
+
width = widget->allocation.width;
height = widget->allocation.height;
cr = gdk_cairo_create (widget->window);
+
+ surface = cairo_get_target (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.4f);
cairo_paint (cr);
- cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
- CAIRO_FONT_WEIGHT_BOLD);
-
- for (i = 0; i < 6; i++) {
- cairo_save (cr);
- cairo_set_font_size (cr, 10);
- cairo_set_source_rgba (cr, colors[i][0],
- colors[i][1],
- colors[i][2],
- 1.0f);
- cairo_move_to (cr, 10*i, 10);
- d[0] = '0' + i;
- cairo_show_text (cr, d);
- cairo_restore (cr);
- }
-
-
- cairo_save (cr);
- cairo_set_source_rgba (cr, 1.0f, 1.0f, 0.0f, 1.0f);
- cairo_move_to (cr, 10, 20);
- cairo_translate (cr, width/2, height/2);
-
-
- for ( i = 0; i < 4; i++ ) {
- cairo_translate (cr, -width/2, -height/2);
-
- cairo_curve_to (cr, 10, 20, 10, 10, 20, 10);
- cairo_line_to (cr, width - 20, 10);
-
- cairo_translate (cr, width/2, height/2);
- cairo_rotate (cr, M_PI/2.0);
- cache = width; width = height; height = cache;
+ for (i = 0; i < 3; i++) {
+ for (j = 0; j < 6; j++) {
+ paint_clock_dot (cr, (width/7)*(6-j) , (height/4)*(i+1),
+ (width/8), (height/5),
+ (((timet[i])>>j)&0x1)?&color[i]:NULL);
+ }
}
- cairo_fill_preserve (cr);
- cairo_set_source_rgba (cr, 0.0f, 1.0f, 0.0f, 0.4f);
- cairo_stroke (cr);
- cairo_restore (cr);
-
+ /*
+ cairo_set_source_surface (cr, surface, 0, -5);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_rectangle (cr, 0, 0, width, height -5);
+ cairo_fill (cr);
+ */
+
paint_dot (cr, sel);
- cairo_destroy (cr);
+ /* cairo_destroy (cr); */
}
+
static void install_colormap (GtkWidget *w) {
GdkScreen* screen = gtk_widget_get_screen (w);
GdkColormap* colormap = gdk_screen_get_rgba_colormap (screen);
@@ -217,6 +281,8 @@ gint main (gint argc, gchar **argv) {
G_CALLBACK (on_mouse_motion),
&sel);
+ g_timeout_add (SECOND_INTERVAL/4, (GtkFunction) time_handler, window);
+
gtk_widget_show_all (window);
gtk_main ();
diff --git a/von-wait b/von-wait
deleted file mode 100755
index 5314222..0000000
--- a/von-wait
+++ /dev/null
Binary files differ
diff --git a/von-wait.c b/von-wait.c
index 23cf802..60a263c 100644
--- a/von-wait.c
+++ b/von-wait.c
@@ -1,10 +1,13 @@
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-#include <cairo.h>
+#define _XOPEN_SOURCE /* glibc2 needs this */
#include <time.h>
#include <sys/time.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <getopt.h>
#include <glib/gprintf.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+#include <cairo.h>
#define SECOND_INTERVAL 1000
@@ -15,6 +18,8 @@ struct private {
time_t time;
time_t von_arrives;
struct timeval tv_now;
+ gchar *ts;
+ gchar *msg;
};
static gboolean time_handler (GtkWidget* w)
@@ -40,8 +45,6 @@ gboolean on_key_press (GtkWidget *widget, GdkEventKey *key, gpointer p) {
static void paint (GtkWidget *widget, GdkEventExpose *eev, struct private *p) {
gint width, height;
cairo_t *cr;
- gchar *gc_time;
-
gint sec, min, hour, day;
@@ -61,9 +64,10 @@ static void paint (GtkWidget *widget, GdkEventExpose *eev, struct private *p) {
sec = p->time;
- gc_time = g_strdup_printf("Von arrives in %02dd %02d:%02d:%02d:%02d",
- day, hour, min, sec,
- (int) ((p->tv_now.tv_usec)/10e3));
+ g_sprintf(p->ts,
+ "Von arrives in %02dd %02d:%02d:%02d:%02d",
+ day, hour, min, sec,
+ (int) (99 - ((p->tv_now.tv_usec)/10e3)));
width = widget->allocation.width;
height = widget->allocation.height;
@@ -82,7 +86,7 @@ static void paint (GtkWidget *widget, GdkEventExpose *eev, struct private *p) {
cairo_set_font_size (cr, 10);
cairo_move_to (cr, 10, 10);
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 1.0f);
- cairo_show_text (cr, gc_time);
+ cairo_show_text (cr, p->ts);
cairo_restore (cr);
cairo_destroy (cr);
@@ -97,21 +101,66 @@ static void install_colormap (GtkWidget *w) {
gtk_widget_set_colormap (w, colormap);
}
-
+
+
+gint usage (char *name) {
+ return printf ("usage: %s [TIME[+FMT]].\n", name);
+}
+
gint main (gint argc, gchar **argv) {
+ int c;
+
+ char *s_time = NULL;
+ char *s_res = NULL;
+ char *fmt = "%Y-%m-%d";
+
GtkWidget *window;
struct private *p = malloc(sizeof(struct private));
+
struct tm von_time = {
.tm_min = 40,
.tm_hour = 9,
.tm_mday = 14,
.tm_mon = 1,
.tm_year = 107,
- };
+ };
- p->von_arrives = mktime(&von_time);
+ for (c = 1; c < argc; c++) {
+ switch (*argv[c]) {
+ case '+':
+ fmt = argv[c] + 1;
+ break;
+ case '-':
+ switch (*(argv[c] + 1)) {
+ case 'h':
+ return usage(argv[0]);
+ case '-':
+ break;
+ }
+ break;
+ default:
+ if (s_time != NULL)
+ printf ("WARNING: overriding previously given time \n"
+ "'%s'\n"
+ "with '%s'.\n", s_time, argv[c]);
+ s_time = argv[c];
+ }
+ }
+
+ if (s_time) {
+ s_res = strptime(s_time, fmt, &von_time);
+ if (*s_res != '\0')
+ printf("WARNING: processing stoped at '%s'\n", s_res);
+ }
+ if (time(NULL) > mktime(&von_time))
+ printf("WARNING: given a date in the past !\n");
+
+ p->ts = g_strdup_printf("Von arrives in 00d 00:00:00:00");
+
+ p->von_arrives = mktime(&von_time);
+
gtk_init(&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -146,11 +195,12 @@ gint main (gint argc, gchar **argv) {
gtk_widget_show_all (window);
- gtk_timeout_add (SECOND_INTERVAL/100, (GtkFunction) time_handler, window);
+ gtk_timeout_add (SECOND_INTERVAL/9, (GtkFunction) time_handler, window);
gtk_main ();
+
+ g_free(p->ts);
+ free(p);
return 0;
}
-
-