15 #include "gtkStatsPianoRoll.h" 16 #include "gtkStatsMonitor.h" 17 #include "numeric_types.h" 18 #include "gtkStatsLabelStack.h" 20 static const int default_piano_roll_width = 400;
21 static const int default_piano_roll_height = 200;
31 default_piano_roll_width,
32 default_piano_roll_height),
40 _scale_area = gtk_drawing_area_new();
41 g_signal_connect(G_OBJECT(_scale_area),
"expose_event",
42 G_CALLBACK(expose_event_callback),
this);
43 gtk_box_pack_start(GTK_BOX(_graph_vbox), _scale_area,
45 gtk_widget_set_size_request(_scale_area, 0, 20);
48 gtk_widget_set_size_request(_graph_window, default_piano_roll_width,
49 default_piano_roll_height);
54 string window_title = thread_name +
" thread piano roll";
55 gtk_window_set_title(GTK_WINDOW(_window), window_title.c_str());
57 gtk_widget_show_all(_window);
58 gtk_widget_show(_window);
63 gtk_widget_set_size_request(_window, 0, 0);
74 ~GtkStatsPianoRoll() {
100 PStatPianoRoll::force_redraw();
111 PStatPianoRoll::changed_size(graph_xsize, graph_ysize);
125 if ((old_unit_mask & (GBU_hz | GBU_ms)) != 0) {
126 unit_mask = unit_mask & (GBU_hz | GBU_ms);
127 unit_mask |= (old_unit_mask & GBU_show_units);
130 gtk_widget_queue_draw(_scale_area);
141 if (collector_index >= 0) {
142 GtkStatsGraph::_monitor->
open_strip_chart(_thread_index, collector_index,
false);
156 gtk_widget_queue_draw(_graph_window);
157 gtk_widget_queue_draw(_scale_area);
165 void GtkStatsPianoRoll::
167 gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_white);
168 gdk_draw_rectangle(_pixmap, _pixmap_gc, TRUE, 0, 0,
178 void GtkStatsPianoRoll::
184 for (
int i = 0; i < num_guide_bars; i++) {
194 void GtkStatsPianoRoll::
195 draw_bar(
int row,
int from_x,
int to_x) {
196 if (row >= 0 && row < _label_stack.get_num_labels()) {
197 int y = _label_stack.get_label_y(row, _graph_window);
198 int height = _label_stack.get_label_height(row);
201 GdkGC *gc = get_collector_gc(collector_index);
203 gdk_draw_rectangle(_pixmap, gc, TRUE,
204 from_x, y - height + 2,
205 to_x - from_x, height - 4);
215 void GtkStatsPianoRoll::
217 gtk_widget_queue_draw(_graph_window);
225 void GtkStatsPianoRoll::
227 if (_labels_changed) {
239 void GtkStatsPianoRoll::
240 additional_graph_window_paint() {
242 for (
int i = 0; i < num_user_guide_bars; i++) {
255 GtkStatsGraph::DragMode GtkStatsPianoRoll::
256 consider_drag_start(
int graph_x,
int graph_y) {
257 if (graph_y >= 0 && graph_y <
get_ysize()) {
258 if (graph_x >= 0 && graph_x <
get_xsize()) {
264 if (_drag_guide_bar >= 0) {
271 return DM_new_guide_bar;
275 return GtkStatsGraph::consider_drag_start(graph_x, graph_y);
284 gboolean GtkStatsPianoRoll::
285 handle_button_press(GtkWidget *widget,
int graph_x,
int graph_y,
294 if (_potential_drag_mode == DM_none) {
295 set_drag_mode(DM_scale);
300 }
else if (_potential_drag_mode == DM_guide_bar && _drag_guide_bar >= 0) {
301 set_drag_mode(DM_guide_bar);
302 _drag_start_x = graph_x;
307 return GtkStatsGraph::handle_button_press(widget, graph_x, graph_y,
317 gboolean GtkStatsPianoRoll::
318 handle_button_release(GtkWidget *widget,
int graph_x,
int graph_y) {
319 if (_drag_mode == DM_scale) {
320 set_drag_mode(DM_none);
322 return handle_motion(widget, graph_x, graph_y);
324 }
else if (_drag_mode == DM_guide_bar) {
325 if (graph_x < 0 || graph_x >=
get_xsize()) {
330 set_drag_mode(DM_none);
332 return handle_motion(widget, graph_x, graph_y);
335 return GtkStatsGraph::handle_button_release(widget, graph_x, graph_y);
344 gboolean GtkStatsPianoRoll::
345 handle_motion(GtkWidget *widget,
int graph_x,
int graph_y) {
346 if (_drag_mode == DM_none && _potential_drag_mode == DM_none) {
348 _label_stack.highlight_label(get_collector_under_pixel(graph_x, graph_y));
364 _label_stack.highlight_label(-1);
367 if (_drag_mode == DM_scale) {
368 double ratio = (double)graph_x / (
double)
get_xsize();
374 }
else if (_drag_mode == DM_new_guide_bar) {
377 if (graph_x >= 0 && graph_x <
get_xsize()) {
378 set_drag_mode(DM_guide_bar);
383 }
else if (_drag_mode == DM_guide_bar) {
388 return GtkStatsGraph::handle_motion(widget, graph_x, graph_y);
397 int GtkStatsPianoRoll::
398 get_collector_under_pixel(
int xpoint,
int ypoint) {
399 if (_label_stack.get_num_labels() == 0) {
404 int height = _label_stack.get_label_height(0);
405 int row = (
get_ysize() - ypoint) / height;
406 if (row >= 0 && row < _label_stack.get_num_labels()) {
407 return _label_stack.get_label_collector_index(row);
418 void GtkStatsPianoRoll::
420 _label_stack.clear_labels();
422 _label_stack.add_label(GtkStatsGraph::_monitor,
this,
426 _labels_changed =
false;
435 void GtkStatsPianoRoll::
441 switch (bar._style) {
443 gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_light_gray);
447 gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_user_guide_bar);
451 gdk_gc_set_rgb_fg_color(_pixmap_gc, &rgb_dark_gray);
454 gdk_draw_line(surface, _pixmap_gc, x, 0, x,
get_ysize());
463 void GtkStatsPianoRoll::
464 draw_guide_labels() {
467 for (i = 0; i < num_guide_bars; i++) {
472 for (i = 0; i < num_user_guide_bars; i++) {
483 void GtkStatsPianoRoll::
485 GdkGC *gc = gdk_gc_new(_scale_area->window);
487 switch (bar._style) {
489 gdk_gc_set_rgb_fg_color(gc, &rgb_light_gray);
493 gdk_gc_set_rgb_fg_color(gc, &rgb_user_guide_bar);
497 gdk_gc_set_rgb_fg_color(gc, &rgb_dark_gray);
502 const string &label = bar._label;
504 PangoLayout *layout = gtk_widget_create_pango_layout(_window, label.c_str());
506 pango_layout_get_pixel_size(layout, &width, &height);
508 if (bar._style != GBS_user) {
513 g_object_unref(layout);
524 gtk_widget_translate_coordinates(_graph_window, _scale_area,
528 int this_x = x - width / 2;
529 gdk_draw_layout(_scale_area->window, gc, this_x,
530 _scale_area->allocation.height - height, layout);
533 g_object_unref(layout);
542 gboolean GtkStatsPianoRoll::
543 expose_event_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data) {
545 self->draw_guide_labels();
int get_xsize() const
Returns the width of the chart in pixels.
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 ...
int get_guide_bar_units() const
Returns the units that are displayed for the guide bar labels.
void set_guide_bar_units(int unit_mask)
Sets the units that are displayed for the guide bar labels.
int get_ysize() const
Returns the height of the chart in pixels.
int get_num_labels() const
Returns the number of labels to be drawn for this chart.
This is an abstract class that presents the interface for drawing a piano-roll type chart: it shows t...
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
The data associated with a particular client, but not with any one particular frame or thread: the li...
int find_user_guide_bar(double from_height, double to_height) const
Returns the index number of the first user guide bar found whose height is within the indicated range...
void update()
Updates the chart with the latest data.
A window that draws a piano-roll style chart, which shows the collectors explicitly stopping and star...
const GuideBar & get_guide_bar(int n) const
Returns the nth horizontal guide bar.
void set_horizontal_scale(double time_width)
Changes the amount of time the width of the horizontal axis represents.
int height_to_pixel(double value) const
Converts a value (i.e.
virtual void new_data(int thread_index, int frame_number)
Called as each frame's data is made available.
virtual void force_redraw()
Called when it is necessary to redraw the entire graph.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
int get_label_collector(int n) const
Returns the collector index associated with the nth label.
int get_num_guide_bars() const
Returns the number of horizontal guide bars that should be drawn, based on the indicated target frame...
This class represents a connection to a PStatsClient and manages the data exchange with the client...
void open_strip_chart(int thread_index, int collector_index, bool show_level)
Opens a new strip chart showing the indicated data.
void set_horizontal_scale(double time_width)
Changes the amount of time the width of the horizontal axis represents.
double pixel_to_height(int y) const
Converts a horizontal pixel offset to a value (a "height" in the strip chart).
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
int add_user_guide_bar(double height)
Creates a new user guide bar and returns its index number.
GuideBar get_user_guide_bar(int n) const
Returns the nth user-defined guide bar.
virtual void clicked_label(int collector_index)
Called when the user single-clicks on a label.
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.
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
string get_thread_name(int index) const
Returns the name of the indicated thread.
void remove_user_guide_bar(int n)
Removes the user guide bar with the indicated index number.