Panda3D
 All Classes Functions Variables Enumerations
gtkStatsLabelStack.cxx
1 // Filename: gtkStatsLabelStack.cxx
2 // Created by: drose (16Jan06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "gtkStatsLabelStack.h"
16 #include "gtkStatsLabel.h"
17 #include "pnotify.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: GtkStatsLabelStack::Constructor
21 // Access: Public
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 GtkStatsLabelStack::
25 GtkStatsLabelStack() {
26  _widget = gtk_vbox_new(FALSE, 0);
27  _highlight_label = -1;
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: GtkStatsLabelStack::Destructor
32 // Access: Public
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 GtkStatsLabelStack::
36 ~GtkStatsLabelStack() {
37  clear_labels();
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: GtkStatsLabelStack::get_widget
42 // Access: Public
43 // Description: Returns the widget for this stack.
44 ////////////////////////////////////////////////////////////////////
45 GtkWidget *GtkStatsLabelStack::
46 get_widget() const {
47  return _widget;
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: GtkStatsLabelStack::get_label_y
52 // Access: Public
53 // Description: Returns the y position of the indicated label's bottom
54 // edge, relative to the indicated target widget.
55 ////////////////////////////////////////////////////////////////////
57 get_label_y(int label_index, GtkWidget *target_widget) const {
58  nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0);
59 
60  // Assume all labels have the same height.
61  int height = _labels[0]->get_height();
62  int start_y = _widget->allocation.height - height * label_index;
63 
64  int x, y;
65  gtk_widget_translate_coordinates(_widget, target_widget,
66  0, start_y, &x, &y);
67  return y;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: GtkStatsLabelStack::get_label_height
72 // Access: Public
73 // Description: Returns the height of the indicated label.
74 ////////////////////////////////////////////////////////////////////
76 get_label_height(int label_index) const {
77  nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0);
78  return _labels[label_index]->get_height();
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: GtkStatsLabelStack::get_label_collector_index
83 // Access: Public
84 // Description: Returns the collector index associated with the
85 // indicated label.
86 ////////////////////////////////////////////////////////////////////
88 get_label_collector_index(int label_index) const {
89  nassertr(label_index >= 0 && label_index < (int)_labels.size(), -1);
90  return _labels[label_index]->get_collector_index();
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: GtkStatsLabelStack::clear_labels
95 // Access: Public
96 // Description: Removes the set of labels and starts a new set.
97 ////////////////////////////////////////////////////////////////////
99 clear_labels(bool delete_widgets) {
100  Labels::iterator li;
101  for (li = _labels.begin(); li != _labels.end(); ++li) {
102  GtkStatsLabel *label = (*li);
103  if (delete_widgets) {
104  gtk_container_remove(GTK_CONTAINER(_widget), label->get_widget());
105  }
106  delete label;
107  }
108  _labels.clear();
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: GtkStatsLabelStack::add_label
113 // Access: Public
114 // Description: Adds a new label to the top of the stack; returns the
115 // new label index.
116 ////////////////////////////////////////////////////////////////////
119  int thread_index, int collector_index, bool use_fullname) {
120  GtkStatsLabel *label =
121  new GtkStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
122 
123  gtk_box_pack_end(GTK_BOX(_widget), label->get_widget(),
124  FALSE, FALSE, 0);
125 
126  int label_index = (int)_labels.size();
127  _labels.push_back(label);
128 
129  return label_index;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: GtkStatsLabelStack::get_num_labels
134 // Access: Public
135 // Description: Returns the number of labels in the stack.
136 ////////////////////////////////////////////////////////////////////
138 get_num_labels() const {
139  return _labels.size();
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: GtkStatsLabelStack::highlight_label
144 // Access: Public
145 // Description: Draws a highlight around the label representing the
146 // indicated collector, and removes the highlight from
147 // any other label. Specify -1 to remove the highlight
148 // from all labels.
149 ////////////////////////////////////////////////////////////////////
151 highlight_label(int collector_index) {
152  if (_highlight_label != collector_index) {
153  _highlight_label = collector_index;
154  Labels::iterator li;
155  for (li = _labels.begin(); li != _labels.end(); ++li) {
156  GtkStatsLabel *label = (*li);
157  label->set_highlight(label->get_collector_index() == _highlight_label);
158  }
159  }
160 }
int add_label(GtkStatsMonitor *monitor, GtkStatsGraph *graph, int thread_index, int collector_index, bool use_fullname)
Adds a new label to the top of the stack; returns the new label index.
void clear_labels(bool delete_widgets=true)
Removes the set of labels and starts a new set.
int get_label_height(int label_index) const
Returns the height of the indicated label.
void highlight_label(int collector_index)
Draws a highlight around the label representing the indicated collector, and removes the highlight fr...
int get_num_labels() const
Returns the number of labels in the stack.
int get_label_y(int label_index, GtkWidget *target_widget) const
Returns the y position of the indicated label&#39;s bottom edge, relative to the indicated target widget...
int get_collector_index() const
Returns the collector this label represents.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
Definition: gtkStatsGraph.h:32
GtkWidget * get_widget() const
Returns the widget for this stack.
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_label_collector_index(int label_index) const
Returns the collector index associated with the indicated label.
GtkWidget * get_widget() const
Returns the widget for this label.
A text label that will draw in color appropriate for a particular collector.
Definition: gtkStatsLabel.h:32