Panda3D
|
00001 // Filename: gtkStatsLabelStack.cxx 00002 // Created by: drose (16Jan06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "gtkStatsLabelStack.h" 00016 #include "gtkStatsLabel.h" 00017 #include "pnotify.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: GtkStatsLabelStack::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 GtkStatsLabelStack:: 00025 GtkStatsLabelStack() { 00026 _widget = gtk_vbox_new(FALSE, 0); 00027 _highlight_label = -1; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: GtkStatsLabelStack::Destructor 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 GtkStatsLabelStack:: 00036 ~GtkStatsLabelStack() { 00037 clear_labels(); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: GtkStatsLabelStack::get_widget 00042 // Access: Public 00043 // Description: Returns the widget for this stack. 00044 //////////////////////////////////////////////////////////////////// 00045 GtkWidget *GtkStatsLabelStack:: 00046 get_widget() const { 00047 return _widget; 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: GtkStatsLabelStack::get_label_y 00052 // Access: Public 00053 // Description: Returns the y position of the indicated label's bottom 00054 // edge, relative to the indicated target widget. 00055 //////////////////////////////////////////////////////////////////// 00056 int GtkStatsLabelStack:: 00057 get_label_y(int label_index, GtkWidget *target_widget) const { 00058 nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0); 00059 00060 // Assume all labels have the same height. 00061 int height = _labels[0]->get_height(); 00062 int start_y = _widget->allocation.height - height * label_index; 00063 00064 int x, y; 00065 gtk_widget_translate_coordinates(_widget, target_widget, 00066 0, start_y, &x, &y); 00067 return y; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: GtkStatsLabelStack::get_label_height 00072 // Access: Public 00073 // Description: Returns the height of the indicated label. 00074 //////////////////////////////////////////////////////////////////// 00075 int GtkStatsLabelStack:: 00076 get_label_height(int label_index) const { 00077 nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0); 00078 return _labels[label_index]->get_height(); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: GtkStatsLabelStack::get_label_collector_index 00083 // Access: Public 00084 // Description: Returns the collector index associated with the 00085 // indicated label. 00086 //////////////////////////////////////////////////////////////////// 00087 int GtkStatsLabelStack:: 00088 get_label_collector_index(int label_index) const { 00089 nassertr(label_index >= 0 && label_index < (int)_labels.size(), -1); 00090 return _labels[label_index]->get_collector_index(); 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: GtkStatsLabelStack::clear_labels 00095 // Access: Public 00096 // Description: Removes the set of labels and starts a new set. 00097 //////////////////////////////////////////////////////////////////// 00098 void GtkStatsLabelStack:: 00099 clear_labels(bool delete_widgets) { 00100 Labels::iterator li; 00101 for (li = _labels.begin(); li != _labels.end(); ++li) { 00102 GtkStatsLabel *label = (*li); 00103 if (delete_widgets) { 00104 gtk_container_remove(GTK_CONTAINER(_widget), label->get_widget()); 00105 } 00106 delete label; 00107 } 00108 _labels.clear(); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: GtkStatsLabelStack::add_label 00113 // Access: Public 00114 // Description: Adds a new label to the top of the stack; returns the 00115 // new label index. 00116 //////////////////////////////////////////////////////////////////// 00117 int GtkStatsLabelStack:: 00118 add_label(GtkStatsMonitor *monitor, GtkStatsGraph *graph, 00119 int thread_index, int collector_index, bool use_fullname) { 00120 GtkStatsLabel *label = 00121 new GtkStatsLabel(monitor, graph, thread_index, collector_index, use_fullname); 00122 00123 gtk_box_pack_end(GTK_BOX(_widget), label->get_widget(), 00124 FALSE, FALSE, 0); 00125 00126 int label_index = (int)_labels.size(); 00127 _labels.push_back(label); 00128 00129 return label_index; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: GtkStatsLabelStack::get_num_labels 00134 // Access: Public 00135 // Description: Returns the number of labels in the stack. 00136 //////////////////////////////////////////////////////////////////// 00137 int GtkStatsLabelStack:: 00138 get_num_labels() const { 00139 return _labels.size(); 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: GtkStatsLabelStack::highlight_label 00144 // Access: Public 00145 // Description: Draws a highlight around the label representing the 00146 // indicated collector, and removes the highlight from 00147 // any other label. Specify -1 to remove the highlight 00148 // from all labels. 00149 //////////////////////////////////////////////////////////////////// 00150 void GtkStatsLabelStack:: 00151 highlight_label(int collector_index) { 00152 if (_highlight_label != collector_index) { 00153 _highlight_label = collector_index; 00154 Labels::iterator li; 00155 for (li = _labels.begin(); li != _labels.end(); ++li) { 00156 GtkStatsLabel *label = (*li); 00157 label->set_highlight(label->get_collector_index() == _highlight_label); 00158 } 00159 } 00160 }