[sysprof/wip/chergert/sysprof-3] libsysprof-ui: add some helpers to zoom manager
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/sysprof-3] libsysprof-ui: add some helpers to zoom manager
- Date: Tue, 14 May 2019 20:07:38 +0000 (UTC)
commit ff7d5cb9d3fa566a681b6a2ca843a264d181adf6
Author: Christian Hergert <chergert redhat com>
Date: Tue May 14 13:07:09 2019 -0700
libsysprof-ui: add some helpers to zoom manager
This should be able to help us cleanup some duplicated code in various
places so that we keep our timings associated amongst different visualizing
widgets.
src/libsysprof-ui/sysprof-zoom-manager.c | 39 ++++++++++++++++++++------------
src/libsysprof-ui/sysprof-zoom-manager.h | 6 +++++
2 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.c b/src/libsysprof-ui/sysprof-zoom-manager.c
index ed7b045..cdb0665 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.c
+++ b/src/libsysprof-ui/sysprof-zoom-manager.c
@@ -27,6 +27,9 @@
#include "sysprof-zoom-manager.h"
+#define DEFAULT_PIXELS_PER_SEC (20.0)
+#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
+
struct _SysprofZoomManager
{
GObject parent_instance;
@@ -56,21 +59,9 @@ G_DEFINE_TYPE_EXTENDED (SysprofZoomManager, sysprof_zoom_manager, G_TYPE_OBJECT,
static GParamSpec *properties [N_PROPS];
static gdouble zoom_levels[] = {
- 0.3,
- 0.5,
- 0.67,
- 0.80,
- 0.90,
- 1.0,
- 1.5,
- 2.0,
- 2.5,
- 3.0,
- 5.0,
- 10.0,
- 20.0,
- 30.0,
- 50.0,
+ 0.3, 0.5, 0.67, 0.80, 0.90,
+ 1.0, 1.5, 2.0, 2.5, 3.0,
+ 5.0, 10.0, 20.0, 30.0, 50.0,
};
static void
@@ -506,3 +497,21 @@ sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self)
else
return g_strdup_printf ("%d%%", (gint)percent);
}
+
+gint64
+sysprof_zoom_manager_get_duration_for_width (SysprofZoomManager *self,
+ gint width)
+{
+ g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0);
+
+ return NSEC_PER_SEC * ((gdouble)width / (DEFAULT_PIXELS_PER_SEC * self->zoom));
+}
+
+gint
+sysprof_zoom_manager_get_width_for_duration (SysprofZoomManager *self,
+ gint64 duration)
+{
+ g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0);
+
+ return (gdouble)duration / (gdouble)NSEC_PER_SEC * DEFAULT_PIXELS_PER_SEC * self->zoom;
+}
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.h b/src/libsysprof-ui/sysprof-zoom-manager.h
index 62aa45e..4c7859b 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.h
+++ b/src/libsysprof-ui/sysprof-zoom-manager.h
@@ -64,5 +64,11 @@ void sysprof_zoom_manager_set_zoom (SysprofZoomManager *s
gdouble zoom);
SYSPROF_AVAILABLE_IN_ALL
gchar *sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self);
+SYSPROF_AVAILABLE_IN_ALL
+gint sysprof_zoom_manager_get_width_for_duration (SysprofZoomManager *self,
+ gint64 duration);
+SYSPROF_AVAILABLE_IN_ALL
+gint64 sysprof_zoom_manager_get_duration_for_width (SysprofZoomManager *self,
+ gint width);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]