summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/input.c11
-rw-r--r--gui/render.c3
-rw-r--r--gui/sheet.c6
-rw-r--r--gui/timer.c78
-rw-r--r--gui/timer.h23
5 files changed, 121 insertions, 0 deletions
diff --git a/gui/input.c b/gui/input.c
index f005527..49e310c 100644
--- a/gui/input.c
+++ b/gui/input.c
@@ -19,6 +19,7 @@
#include "misc/util.h"
#include "misc/diag.h"
+#include "gui/timer.h"
#include "gui/input.h"
@@ -183,6 +184,8 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event,
progress(3, "motion %s", state());
+ timer_start();
+
switch (sp->state) {
case input_idle:
hover_consider(event->x, event->y);
@@ -224,6 +227,8 @@ static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
progress(3, "press %s", state());
+ timer_start();
+
buttons |= 1 << event->button;
switch (sp->state) {
@@ -261,6 +266,8 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
progress(3, "release %s", state());
+ timer_start();
+
buttons &= ~(1 << event->button);
if (buttons)
return TRUE;
@@ -307,6 +314,8 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
gpointer data)
{
+ timer_start();
+
if (!sp || !sp->ops->scroll)
return TRUE;
switch (event->direction) {
@@ -329,6 +338,8 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
gpointer data)
{
+ timer_start();
+
if (sp && sp->ops->key)
sp->ops->key(sp->user, curr_x, curr_y, event->keyval);
return TRUE;
diff --git a/gui/render.c b/gui/render.c
index 2411fd6..214b7b2 100644
--- a/gui/render.c
+++ b/gui/render.c
@@ -29,6 +29,7 @@
#include "gfx/diff.h"
#include "gui/aoi.h"
#include "gui/over.h"
+#include "gui/timer.h"
#include "gui/common.h"
@@ -241,6 +242,8 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
if (ctx->mode == showing_index)
index_draw_event(ctx, cr);
+ timer_show(cr);
+
return FALSE;
}
diff --git a/gui/sheet.c b/gui/sheet.c
index 3e65f28..f500078 100644
--- a/gui/sheet.c
+++ b/gui/sheet.c
@@ -26,6 +26,7 @@
#include "gui/input.h"
#include "gui/help.h"
#include "gui/icons.h"
+#include "gui/timer.h"
#include "gui/common.h"
@@ -577,6 +578,11 @@ static void sheet_key(void *user, int x, int y, int keyval)
help();
break;
+ case GDK_KEY_t:
+ timer_toggle();
+ redraw(ctx);
+ break;
+
case GDK_KEY_q:
gtk_main_quit();
}
diff --git a/gui/timer.c b/gui/timer.c
new file mode 100644
index 0000000..6d6cdd6
--- /dev/null
+++ b/gui/timer.c
@@ -0,0 +1,78 @@
+/*
+ * gui/timer.c - Performance timer
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#define _GNU_SOURCE /* for asprintf */
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#include <cairo/cairo.h>
+
+#include "gui/timer.h"
+
+
+static bool timer_enabled = 0;
+static struct timeval then;
+
+
+void timer_start(void)
+{
+ if (timer_enabled)
+ gettimeofday(&then, NULL);
+}
+
+
+static void timer_show_cairo(cairo_t *cr, const char *s)
+{
+ double x1, y1, x2, y2;
+ cairo_text_extents_t ext;
+
+ cairo_reset_clip(cr);
+ cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
+ cairo_select_font_face(cr, "Mono Sans",
+ CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+ cairo_set_font_size(cr, 20);
+ cairo_text_extents(cr, s, &ext);
+ cairo_move_to(cr, x2 - ext.width - 4, y2 - 4);
+ cairo_set_source_rgb(cr, 0, 0, 0.7);
+ cairo_show_text(cr, s);
+}
+
+
+void timer_show(cairo_t *cr)
+{
+ struct timeval now;
+ char *s;
+
+ if (!timer_enabled)
+ return;
+
+ gettimeofday(&now, NULL);
+ now.tv_sec -= then.tv_sec;
+ now.tv_usec -= then.tv_usec;
+ if (now.tv_usec < 0) {
+ now.tv_sec--;
+ now.tv_usec += 1000000;
+ }
+
+
+ if (asprintf(&s , "%u.%03d",
+ (unsigned) now.tv_sec, (int) now.tv_usec / 1000)) {}
+ timer_show_cairo(cr, s);
+}
+
+
+void timer_toggle(void)
+{
+ timer_enabled = !timer_enabled;
+ timer_start();
+}
diff --git a/gui/timer.h b/gui/timer.h
new file mode 100644
index 0000000..cdda945
--- /dev/null
+++ b/gui/timer.h
@@ -0,0 +1,23 @@
+/*
+ * gui/timer.h - Performance timer
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef GUI_TIMER_H
+#define GUI_TIMER_H
+
+#include <cairo/cairo.h>
+
+
+void timer_start(void);
+void timer_show(cairo_t *cr);
+void timer_toggle(void);
+
+#endif /* !GUI_TIMER_H */