mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 08:00:53 +00:00
libsysprof-ui: fix drawing of selections
This commit is contained in:
@ -66,7 +66,8 @@ typedef struct
|
|||||||
GtkListBox *list;
|
GtkListBox *list;
|
||||||
GtkStyleContext *style_context;
|
GtkStyleContext *style_context;
|
||||||
GtkSnapshot *snapshot;
|
GtkSnapshot *snapshot;
|
||||||
GtkAllocation alloc;
|
int width;
|
||||||
|
int height;
|
||||||
gint64 begin_time;
|
gint64 begin_time;
|
||||||
gint64 duration;
|
gint64 duration;
|
||||||
} SelectionDraw;
|
} SelectionDraw;
|
||||||
@ -121,10 +122,10 @@ draw_selection_cb (SysprofSelection *selection,
|
|||||||
x = (range_begin - draw->begin_time) / (gdouble)draw->duration;
|
x = (range_begin - draw->begin_time) / (gdouble)draw->duration;
|
||||||
x2 = (range_end - draw->begin_time) / (gdouble)draw->duration;
|
x2 = (range_end - draw->begin_time) / (gdouble)draw->duration;
|
||||||
|
|
||||||
area.x = x * draw->alloc.width;
|
area.x = x * draw->width;
|
||||||
area.width = (x2 * draw->alloc.width) - area.x;
|
area.width = (x2 * draw->width) - area.x;
|
||||||
area.y = 0;
|
area.y = 0;
|
||||||
area.height = draw->alloc.height;
|
area.height = draw->height;
|
||||||
|
|
||||||
if (area.width < 0)
|
if (area.width < 0)
|
||||||
{
|
{
|
||||||
@ -141,30 +142,43 @@ sysprof_visualizers_frame_snapshot (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
SysprofVisualizersFrame *self = (SysprofVisualizersFrame *)widget;
|
SysprofVisualizersFrame *self = (SysprofVisualizersFrame *)widget;
|
||||||
SelectionDraw draw;
|
SelectionDraw draw;
|
||||||
|
GtkAllocation alloc;
|
||||||
|
|
||||||
g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
|
g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
|
||||||
g_assert (GTK_IS_SNAPSHOT (snapshot));
|
g_assert (GTK_IS_SNAPSHOT (snapshot));
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (sysprof_visualizers_frame_parent_class)->snapshot (widget, snapshot);
|
GTK_WIDGET_CLASS (sysprof_visualizers_frame_parent_class)->snapshot (widget, snapshot);
|
||||||
|
|
||||||
|
draw.duration = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self->ticks));
|
||||||
|
if (draw.duration == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
draw.style_context = gtk_widget_get_style_context (GTK_WIDGET (self->visualizers));
|
draw.style_context = gtk_widget_get_style_context (GTK_WIDGET (self->visualizers));
|
||||||
draw.list = self->visualizers;
|
draw.list = self->visualizers;
|
||||||
draw.snapshot = snapshot;
|
draw.snapshot = snapshot;
|
||||||
draw.begin_time = self->begin_time;
|
draw.begin_time = self->begin_time;
|
||||||
draw.duration = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self->ticks));
|
|
||||||
|
|
||||||
if (draw.duration == 0)
|
gtk_widget_get_allocation (GTK_WIDGET (self->visualizers), &alloc);
|
||||||
return;
|
draw.width = alloc.width;
|
||||||
|
draw.height = alloc.height;
|
||||||
gtk_widget_get_allocation (GTK_WIDGET (self->visualizers), &draw.alloc);
|
|
||||||
|
|
||||||
if (sysprof_selection_get_has_selection (self->selection) || self->button_pressed)
|
if (sysprof_selection_get_has_selection (self->selection) || self->button_pressed)
|
||||||
{
|
{
|
||||||
|
double x, y;
|
||||||
|
|
||||||
|
gtk_snapshot_save (snapshot);
|
||||||
|
gtk_widget_translate_coordinates (GTK_WIDGET (self->visualizers),
|
||||||
|
GTK_WIDGET (self),
|
||||||
|
0, 0, &x, &y);
|
||||||
|
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
|
||||||
|
|
||||||
gtk_style_context_add_class (draw.style_context, "selection");
|
gtk_style_context_add_class (draw.style_context, "selection");
|
||||||
sysprof_selection_foreach (self->selection, draw_selection_cb, &draw);
|
sysprof_selection_foreach (self->selection, draw_selection_cb, &draw);
|
||||||
if (self->button_pressed)
|
if (self->button_pressed)
|
||||||
draw_selection_cb (self->selection, self->drag_begin_at, self->drag_selection_at, &draw);
|
draw_selection_cb (self->selection, self->drag_begin_at, self->drag_selection_at, &draw);
|
||||||
gtk_style_context_remove_class (draw.style_context, "selection");
|
gtk_style_context_remove_class (draw.style_context, "selection");
|
||||||
|
|
||||||
|
gtk_snapshot_restore (snapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user