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