gtkStatsLabelStack.cxx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Filename: gtkStatsLabelStack.cxx
  2. // Created by: drose (16Jan06)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #include "gtkStatsLabelStack.h"
  19. #include "gtkStatsLabel.h"
  20. #include "pnotify.h"
  21. ////////////////////////////////////////////////////////////////////
  22. // Function: GtkStatsLabelStack::Constructor
  23. // Access: Public
  24. // Description:
  25. ////////////////////////////////////////////////////////////////////
  26. GtkStatsLabelStack::
  27. GtkStatsLabelStack() {
  28. _widget = gtk_vbox_new(FALSE, 0);
  29. _highlight_label = -1;
  30. }
  31. ////////////////////////////////////////////////////////////////////
  32. // Function: GtkStatsLabelStack::Destructor
  33. // Access: Public
  34. // Description:
  35. ////////////////////////////////////////////////////////////////////
  36. GtkStatsLabelStack::
  37. ~GtkStatsLabelStack() {
  38. clear_labels();
  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. // Function: GtkStatsLabelStack::get_label_y
  51. // Access: Public
  52. // Description: Returns the y position of the indicated label's bottom
  53. // edge, relative to the indicated target widget.
  54. ////////////////////////////////////////////////////////////////////
  55. int GtkStatsLabelStack::
  56. get_label_y(int label_index, GtkWidget *target_widget) const {
  57. nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0);
  58. // Assume all labels have the same height.
  59. int height = _labels[0]->get_height();
  60. int start_y = _widget->allocation.height - height * label_index;
  61. int x, y;
  62. gtk_widget_translate_coordinates(_widget, target_widget,
  63. 0, start_y, &x, &y);
  64. return y;
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: GtkStatsLabelStack::get_label_height
  68. // Access: Public
  69. // Description: Returns the height of the indicated label.
  70. ////////////////////////////////////////////////////////////////////
  71. int GtkStatsLabelStack::
  72. get_label_height(int label_index) const {
  73. nassertr(label_index >= 0 && label_index < (int)_labels.size(), 0);
  74. return _labels[label_index]->get_height();
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Function: GtkStatsLabelStack::get_label_collector_index
  78. // Access: Public
  79. // Description: Returns the collector index associated with the
  80. // indicated label.
  81. ////////////////////////////////////////////////////////////////////
  82. int GtkStatsLabelStack::
  83. get_label_collector_index(int label_index) const {
  84. nassertr(label_index >= 0 && label_index < (int)_labels.size(), -1);
  85. return _labels[label_index]->get_collector_index();
  86. }
  87. ////////////////////////////////////////////////////////////////////
  88. // Function: GtkStatsLabelStack::clear_labels
  89. // Access: Public
  90. // Description: Removes the set of labels and starts a new set.
  91. ////////////////////////////////////////////////////////////////////
  92. void GtkStatsLabelStack::
  93. clear_labels() {
  94. Labels::iterator li;
  95. for (li = _labels.begin(); li != _labels.end(); ++li) {
  96. GtkStatsLabel *label = (*li);
  97. gtk_container_remove(GTK_CONTAINER(_widget), label->get_widget());
  98. delete (*li);
  99. }
  100. _labels.clear();
  101. }
  102. ////////////////////////////////////////////////////////////////////
  103. // Function: GtkStatsLabelStack::add_label
  104. // Access: Public
  105. // Description: Adds a new label to the top of the stack; returns the
  106. // new label index.
  107. ////////////////////////////////////////////////////////////////////
  108. int GtkStatsLabelStack::
  109. add_label(GtkStatsMonitor *monitor, GtkStatsGraph *graph,
  110. int thread_index, int collector_index, bool use_fullname) {
  111. GtkStatsLabel *label =
  112. new GtkStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
  113. gtk_box_pack_end(GTK_BOX(_widget), label->get_widget(),
  114. FALSE, FALSE, 0);
  115. int label_index = (int)_labels.size();
  116. _labels.push_back(label);
  117. return label_index;
  118. }
  119. ////////////////////////////////////////////////////////////////////
  120. // Function: GtkStatsLabelStack::get_num_labels
  121. // Access: Public
  122. // Description: Returns the number of labels in the stack.
  123. ////////////////////////////////////////////////////////////////////
  124. int GtkStatsLabelStack::
  125. get_num_labels() const {
  126. return _labels.size();
  127. }
  128. ////////////////////////////////////////////////////////////////////
  129. // Function: GtkStatsLabelStack::highlight_label
  130. // Access: Public
  131. // Description: Draws a highlight around the label representing the
  132. // indicated collector, and removes the highlight from
  133. // any other label. Specify -1 to remove the highlight
  134. // from all labels.
  135. ////////////////////////////////////////////////////////////////////
  136. void GtkStatsLabelStack::
  137. highlight_label(int collector_index) {
  138. if (_highlight_label != collector_index) {
  139. _highlight_label = collector_index;
  140. Labels::iterator li;
  141. for (li = _labels.begin(); li != _labels.end(); ++li) {
  142. GtkStatsLabel *label = (*li);
  143. label->set_highlight(label->get_collector_index() == _highlight_label);
  144. }
  145. }
  146. }