15 #include "gtkStatsLabel.h" 16 #include "gtkStatsMonitor.h" 17 #include "gtkStatsGraph.h" 19 int GtkStatsLabel::_left_margin = 2;
20 int GtkStatsLabel::_right_margin = 2;
21 int GtkStatsLabel::_top_margin = 2;
22 int GtkStatsLabel::_bottom_margin = 2;
31 int thread_index,
int collector_index,
bool use_fullname) :
34 _thread_index(thread_index),
35 _collector_index(collector_index)
44 _widget = gtk_drawing_area_new();
45 gtk_widget_add_events(_widget,
46 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
47 GDK_BUTTON_PRESS_MASK);
48 g_signal_connect(G_OBJECT(_widget),
"expose_event",
49 G_CALLBACK(expose_event_callback),
this);
50 g_signal_connect(G_OBJECT(_widget),
"enter_notify_event",
51 G_CALLBACK(enter_notify_event_callback),
this);
52 g_signal_connect(G_OBJECT(_widget),
"leave_notify_event",
53 G_CALLBACK(leave_notify_event_callback),
this);
54 g_signal_connect(G_OBJECT(_widget),
"button_press_event",
55 G_CALLBACK(button_press_event_callback),
this);
57 gtk_widget_show(_widget);
60 _layout = gtk_widget_create_pango_layout(_widget, _text.c_str());
64 _bg_color.red = (int)(rgb[0] * 65535.0f);
65 _bg_color.green = (int)(rgb[1] * 65535.0f);
66 _bg_color.blue = (int)(rgb[2] * 65535.0f);
75 _fg_color.red = _fg_color.green = _fg_color.blue = 0;
77 _fg_color.red = _fg_color.green = _fg_color.blue = 0xffff;
83 pango_layout_get_pixel_size(_layout, &width, &height);
84 gtk_widget_set_size_request(_widget, width + 8, height);
87 _mouse_within =
false;
128 return _collector_index;
139 if (_highlight != highlight) {
140 _highlight = highlight;
141 gtk_widget_queue_draw(_widget);
163 set_mouse_within(
bool mouse_within) {
164 if (_mouse_within != mouse_within) {
165 _mouse_within = mouse_within;
166 gtk_widget_queue_draw(_widget);
175 gboolean GtkStatsLabel::
176 expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
179 GdkGC *gc = gdk_gc_new(widget->window);
180 gdk_gc_set_rgb_fg_color(gc, &self->_bg_color);
182 gdk_draw_rectangle(widget->window, gc, TRUE, 0, 0,
183 widget->allocation.width, widget->allocation.height);
187 pango_layout_get_pixel_size(self->_layout, &width, &height);
189 gdk_gc_set_rgb_fg_color(gc, &self->_fg_color);
190 gdk_draw_layout(widget->window, gc,
191 (widget->allocation.width - width) / 2, 0,
195 if (self->_highlight || self->_mouse_within) {
196 gdk_draw_rectangle(widget->window, gc, FALSE, 0, 0,
197 widget->allocation.width - 1, widget->allocation.height - 1);
209 gboolean GtkStatsLabel::
210 enter_notify_event_callback(GtkWidget *widget, GdkEventCrossing *event,
213 self->set_mouse_within(
true);
222 gboolean GtkStatsLabel::
223 leave_notify_event_callback(GtkWidget *widget, GdkEventCrossing *event,
226 self->set_mouse_within(
false);
236 gboolean GtkStatsLabel::
237 button_press_event_callback(GtkWidget *widget, GdkEventButton *event,
240 bool double_click = (
event->type == GDK_2BUTTON_PRESS);
This is the base class for all three-component vectors and points.
int get_height() const
Returns the height of the label as we requested it.
bool get_highlight() const
Returns true if the visual highlight for this label is enabled.
const LRGBColor & get_collector_color(int collector_index)
Returns the color associated with the indicated collector.
string get_collector_fullname(int index) const
Returns the "full name" of the indicated collector.
virtual void clicked_label(int collector_index)
Called when the user single-clicks on a label.
string get_collector_name(int index) const
Returns the name of the indicated collector.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
void set_highlight(bool highlight)
Enables or disables the visual highlight for this label.
This class represents a connection to a PStatsClient and manages the data exchange with the client...
int get_collector_index() const
Returns the collector this label represents.
GtkWidget * get_widget() const
Returns the widget for this label.
A text label that will draw in color appropriate for a particular collector.
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.