15 #include "gtkStatsGraph.h"
16 #include "gtkStatsMonitor.h"
17 #include "gtkStatsLabelStack.h"
19 const GdkColor GtkStatsGraph::rgb_white = {
20 0, 0xffff, 0xffff, 0xffff
22 const GdkColor GtkStatsGraph::rgb_light_gray = {
23 0, 0x9a9a, 0x9a9a, 0x9a9a,
25 const GdkColor GtkStatsGraph::rgb_dark_gray = {
26 0, 0x3333, 0x3333, 0x3333,
28 const GdkColor GtkStatsGraph::rgb_black = {
29 0, 0x0000, 0x0000, 0x0000
31 const GdkColor GtkStatsGraph::rgb_user_guide_bar = {
32 0, 0x8282, 0x9696, 0xffff
44 _parent_window = NULL;
49 GtkWidget *parent_window = monitor->
get_window();
51 GdkDisplay *display = gdk_drawable_get_display(parent_window->window);
52 _hand_cursor = gdk_cursor_new_for_display(display, GDK_HAND2);
60 _window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
67 gtk_widget_add_events(_window,
68 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
69 GDK_POINTER_MOTION_MASK);
70 g_signal_connect(G_OBJECT(_window),
"delete_event",
71 G_CALLBACK(window_delete_event),
this);
72 g_signal_connect(G_OBJECT(_window),
"destroy",
73 G_CALLBACK(window_destroy),
this);
74 g_signal_connect(G_OBJECT(_window),
"button_press_event",
75 G_CALLBACK(button_press_event_callback),
this);
76 g_signal_connect(G_OBJECT(_window),
"button_release_event",
77 G_CALLBACK(button_release_event_callback),
this);
78 g_signal_connect(G_OBJECT(_window),
"motion_notify_event",
79 G_CALLBACK(motion_notify_event_callback),
this);
81 _graph_window = gtk_drawing_area_new();
82 gtk_widget_add_events(_graph_window,
83 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
84 GDK_POINTER_MOTION_MASK);
85 g_signal_connect(G_OBJECT(_graph_window),
"expose_event",
86 G_CALLBACK(graph_expose_callback),
this);
87 g_signal_connect(G_OBJECT(_graph_window),
"configure_event",
88 G_CALLBACK(configure_graph_callback),
this);
89 g_signal_connect(G_OBJECT(_graph_window),
"button_press_event",
90 G_CALLBACK(button_press_event_callback),
this);
91 g_signal_connect(G_OBJECT(_graph_window),
"button_release_event",
92 G_CALLBACK(button_release_event_callback),
this);
93 g_signal_connect(G_OBJECT(_graph_window),
"motion_notify_event",
94 G_CALLBACK(motion_notify_event_callback),
this);
97 GtkWidget *graph_frame = gtk_frame_new(NULL);
98 gtk_frame_set_shadow_type(GTK_FRAME(graph_frame), GTK_SHADOW_IN);
99 gtk_container_add(GTK_CONTAINER(graph_frame), _graph_window);
103 _graph_vbox = gtk_vbox_new(FALSE, 0);
104 gtk_box_pack_end(GTK_BOX(_graph_vbox), graph_frame,
109 _graph_hbox = gtk_hbox_new(FALSE, 0);
110 gtk_box_pack_start(GTK_BOX(_graph_hbox), _graph_vbox,
114 _hpaned = gtk_hpaned_new();
115 gtk_container_add(GTK_CONTAINER(_window), _hpaned);
116 gtk_container_set_border_width(GTK_CONTAINER(_window), 8);
118 gtk_paned_pack1(GTK_PANED(_hpaned), _label_stack.get_widget(), TRUE, TRUE);
119 gtk_paned_pack2(GTK_PANED(_hpaned), _graph_hbox, TRUE, TRUE);
121 _drag_mode = DM_none;
122 _potential_drag_mode = DM_none;
123 _drag_scale_start = 0.0f;
138 Brushes::iterator bi;
139 for (bi = _brushes.begin(); bi != _brushes.end(); ++bi) {
140 GdkGC *gc = (*bi).second;
146 if (_window != (GtkWidget *)NULL) {
147 GtkWidget *window = _window;
149 gtk_widget_destroy(window);
233 if (_scale_area != NULL) {
234 gtk_widget_queue_draw(_scale_area);
236 gtk_widget_queue_draw(_graph_window);
257 if (_window != (GtkWidget *)NULL) {
263 monitor->remove_graph(
this);
274 GdkGC *GtkStatsGraph::
275 get_collector_gc(
int collector_index) {
276 Brushes::iterator bi;
277 bi = _brushes.find(collector_index);
278 if (bi != _brushes.end()) {
286 c.red = (int)(rgb[0] * 65535.0f);
287 c.green = (int)(rgb[1] * 65535.0f);
288 c.blue = (int)(rgb[2] * 65535.0f);
289 GdkGC *gc = gdk_gc_new(_pixmap);
291 gdk_gc_set_rgb_fg_color(gc, &c);
293 _brushes[collector_index] = gc;
305 additional_graph_window_paint() {
316 GtkStatsGraph::DragMode GtkStatsGraph::
317 consider_drag_start(
int graph_x,
int graph_y) {
329 set_drag_mode(GtkStatsGraph::DragMode drag_mode) {
330 _drag_mode = drag_mode;
339 gboolean GtkStatsGraph::
340 handle_button_press(GtkWidget *widget,
int graph_x,
int graph_y,
342 if (_potential_drag_mode != DM_none) {
343 set_drag_mode(_potential_drag_mode);
344 _drag_start_x = graph_x;
345 _drag_start_y = graph_y;
357 gboolean GtkStatsGraph::
358 handle_button_release(GtkWidget *widget,
int graph_x,
int graph_y) {
359 set_drag_mode(DM_none);
362 return handle_motion(widget, graph_x, graph_y);
371 gboolean GtkStatsGraph::
372 handle_motion(GtkWidget *widget,
int graph_x,
int graph_y) {
373 _potential_drag_mode = consider_drag_start(graph_x, graph_y);
375 if (_potential_drag_mode == DM_guide_bar ||
376 _drag_mode == DM_guide_bar) {
377 gdk_window_set_cursor(_window->window, _hand_cursor);
380 gdk_window_set_cursor(_window->window, NULL);
392 setup_pixmap(
int xsize,
int ysize) {
395 _pixmap_xsize = max(xsize, 0);
396 _pixmap_ysize = max(ysize, 0);
398 _pixmap = gdk_pixmap_new(_graph_window->window, _pixmap_xsize, _pixmap_ysize, -1);
400 _pixmap_gc = gdk_gc_new(_pixmap);
403 gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
404 gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, 0, 0,
405 _pixmap_xsize, _pixmap_ysize);
416 if (_pixmap != NULL) {
417 g_object_unref(_pixmap);
418 g_object_unref(_pixmap_gc);
427 gboolean GtkStatsGraph::
428 window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) {
441 window_destroy(GtkWidget *widget, gpointer data) {
451 gboolean GtkStatsGraph::
452 graph_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
455 if (self->_pixmap != NULL) {
456 gdk_draw_drawable(self->_graph_window->window,
457 self->_graph_window->style->fg_gc[0],
458 self->_pixmap, 0, 0, 0, 0,
459 self->_pixmap_xsize, self->_pixmap_ysize);
462 self->additional_graph_window_paint();
472 gboolean GtkStatsGraph::
473 configure_graph_callback(GtkWidget *widget, GdkEventConfigure *event,
478 self->setup_pixmap(event->width, event->height);
479 self->force_redraw();
490 gboolean GtkStatsGraph::
491 button_press_event_callback(GtkWidget *widget, GdkEventButton *event,
494 int graph_x, graph_y;
495 gtk_widget_translate_coordinates(widget, self->_graph_window,
496 (
int)event->x, (
int)event->y,
499 bool double_click = (
event->type == GDK_2BUTTON_PRESS);
501 return self->handle_button_press(widget, graph_x, graph_y, double_click);
510 gboolean GtkStatsGraph::
511 button_release_event_callback(GtkWidget *widget, GdkEventButton *event,
514 int graph_x, graph_y;
515 gtk_widget_translate_coordinates(widget, self->_graph_window,
516 (
int)event->x, (
int)event->y,
519 return self->handle_button_release(widget, graph_x, graph_y);
528 gboolean GtkStatsGraph::
529 motion_notify_event_callback(GtkWidget *widget, GdkEventMotion *event,
532 int graph_x, graph_y;
533 gtk_widget_translate_coordinates(widget, self->_graph_window,
534 (
int)event->x, (
int)event->y,
537 return self->handle_motion(widget, graph_x, graph_y);
This is the base class for all three-component vectors and points.
virtual void new_data(int thread_index, int frame_number)
Called whenever new data arrives.
void user_guide_bars_changed()
Called when the user guide bars have been changed.
void set_pause(bool pause)
Changes the pause flag for the graph.
const LRGBColor & get_collector_color(int collector_index)
Returns the color associated with the indicated collector.
GtkWidget * get_window() const
Returns the window handle to the monitor's window.
void clear_labels(bool delete_widgets=true)
Removes the set of labels and starts a new set.
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
virtual void force_redraw()
Called when it is necessary to redraw the entire graph.
virtual void clicked_label(int collector_index)
Called when the user single-clicks on a label.
virtual void set_scroll_speed(double scroll_speed)
Called when the user selects a new scroll speed from the monitor pulldown menu, this should adjust th...
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
This class represents a connection to a PStatsClient and manages the data exchange with the client...
virtual void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
virtual void changed_graph_size(int graph_xsize, int graph_ysize)
Called when the user has resized the window, forcing a resize of the graph.