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.
This commit is contained in:
Christian Hergert
2019-05-14 13:07:09 -07:00
parent b19ce4b741
commit 0f0bdee4ac
2 changed files with 30 additions and 15 deletions

View File

@ -27,6 +27,9 @@
#include "sysprof-zoom-manager.h" #include "sysprof-zoom-manager.h"
#define DEFAULT_PIXELS_PER_SEC (20.0)
#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
struct _SysprofZoomManager struct _SysprofZoomManager
{ {
GObject parent_instance; GObject parent_instance;
@ -56,21 +59,9 @@ G_DEFINE_TYPE_EXTENDED (SysprofZoomManager, sysprof_zoom_manager, G_TYPE_OBJECT,
static GParamSpec *properties [N_PROPS]; static GParamSpec *properties [N_PROPS];
static gdouble zoom_levels[] = { static gdouble zoom_levels[] = {
0.3, 0.3, 0.5, 0.67, 0.80, 0.90,
0.5, 1.0, 1.5, 2.0, 2.5, 3.0,
0.67, 5.0, 10.0, 20.0, 30.0, 50.0,
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 static void
@ -506,3 +497,21 @@ sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self)
else else
return g_strdup_printf ("%d%%", (gint)percent); 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;
}

View File

@ -64,5 +64,11 @@ void sysprof_zoom_manager_set_zoom (SysprofZoomManager *s
gdouble zoom); gdouble zoom);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gchar *sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self); 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 G_END_DECLS