Browse Source

clicking on labels change focus, not create new graph

David Rose 22 years ago
parent
commit
eb951840cc

+ 21 - 4
pandatool/src/pstatserver/pStatStripChart.cxx

@@ -20,10 +20,10 @@
 #include "pStatClientData.h"
 #include "pStatClientData.h"
 #include "pStatMonitor.h"
 #include "pStatMonitor.h"
 
 
-#include <pStatFrameData.h>
-#include <pStatCollectorDef.h>
-#include <string_utils.h>
-#include <config_pstats.h>
+#include "pStatFrameData.h"
+#include "pStatCollectorDef.h"
+#include "string_utils.h"
+#include "config_pstats.h"
 
 
 #include <algorithm>
 #include <algorithm>
 
 
@@ -140,6 +140,23 @@ first_data() const {
   return _first_data;
   return _first_data;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PStatStripChart::set_collector_index
+//       Access: Public
+//  Description: Changes the collector represented by this strip
+//               chart.  This may force a redraw.
+////////////////////////////////////////////////////////////////////
+void PStatStripChart::
+set_collector_index(int collector_index) {
+  if (_collector_index != collector_index) {
+    _collector_index = collector_index;
+    _title_unknown = true;
+    _data.clear();
+    force_redraw();
+    update_labels();
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PStatStripChart::set_default_vertical_scale
 //     Function: PStatStripChart::set_default_vertical_scale
 //       Access: Public
 //       Access: Public

+ 1 - 0
pandatool/src/pstatserver/pStatStripChart.h

@@ -55,6 +55,7 @@ public:
 
 
   INLINE PStatView &get_view() const;
   INLINE PStatView &get_view() const;
   INLINE int get_collector_index() const;
   INLINE int get_collector_index() const;
+  void set_collector_index(int collector_index);
 
 
   INLINE void set_horizontal_scale(float time_width);
   INLINE void set_horizontal_scale(float time_width);
   INLINE float get_horizontal_scale() const;
   INLINE float get_horizontal_scale() const;

+ 10 - 1
pandatool/src/win-stats/winStatsGraph.cxx

@@ -174,6 +174,15 @@ user_guide_bars_changed() {
   InvalidateRect(_graph_window, NULL, TRUE);
   InvalidateRect(_graph_window, NULL, TRUE);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsGraph::clicked_label
+//       Access: Public, Virtual
+//  Description: Called when the user single-clicks on a label.
+////////////////////////////////////////////////////////////////////
+void WinStatsGraph::
+clicked_label(int collector_index) {
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsGraph::close
 //     Function: WinStatsGraph::close
 //       Access: Protected
 //       Access: Protected
@@ -576,7 +585,7 @@ register_graph_window_class(HINSTANCE application) {
   WNDCLASS wc;
   WNDCLASS wc;
 
 
   ZeroMemory(&wc, sizeof(WNDCLASS));
   ZeroMemory(&wc, sizeof(WNDCLASS));
-  wc.style = 0;
+  wc.style = CS_DBLCLKS;
   wc.lpfnWndProc = (WNDPROC)static_graph_window_proc;
   wc.lpfnWndProc = (WNDPROC)static_graph_window_proc;
   wc.hInstance = application;
   wc.hInstance = application;
   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
   wc.hCursor = LoadCursor(NULL, IDC_ARROW);

+ 1 - 0
pandatool/src/win-stats/winStatsGraph.h

@@ -59,6 +59,7 @@ public:
   virtual void set_time_units(int unit_mask);
   virtual void set_time_units(int unit_mask);
   virtual void set_scroll_speed(float scroll_speed);
   virtual void set_scroll_speed(float scroll_speed);
   void user_guide_bars_changed();
   void user_guide_bars_changed();
+  virtual void clicked_label(int collector_index);
 
 
 protected:
 protected:
   void close();
   void close();

+ 8 - 6
pandatool/src/win-stats/winStatsLabel.cxx

@@ -18,6 +18,7 @@
 
 
 #include "winStatsLabel.h"
 #include "winStatsLabel.h"
 #include "winStatsMonitor.h"
 #include "winStatsMonitor.h"
+#include "winStatsGraph.h"
 
 
 int WinStatsLabel::_left_margin = 2;
 int WinStatsLabel::_left_margin = 2;
 int WinStatsLabel::_right_margin = 2;
 int WinStatsLabel::_right_margin = 2;
@@ -33,9 +34,10 @@ const char * const WinStatsLabel::_window_class_name = "label";
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WinStatsLabel::
 WinStatsLabel::
-WinStatsLabel(WinStatsMonitor *monitor, int thread_index, 
-              int collector_index, bool use_fullname) :
+WinStatsLabel(WinStatsMonitor *monitor, WinStatsGraph *graph,
+              int thread_index, int collector_index, bool use_fullname) :
   _monitor(monitor),
   _monitor(monitor),
+  _graph(graph),
   _thread_index(thread_index),
   _thread_index(thread_index),
   _collector_index(collector_index)
   _collector_index(collector_index)
 {
 {
@@ -315,16 +317,16 @@ LONG WinStatsLabel::
 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   switch (msg) {
   switch (msg) {
   case WM_LBUTTONDBLCLK:
   case WM_LBUTTONDBLCLK:
-    _monitor->open_strip_chart(_thread_index, _collector_index);
+    _graph->clicked_label(_collector_index);
     return 0;
     return 0;
-
+    
   case WM_MOUSEMOVE: 
   case WM_MOUSEMOVE: 
     {
     {
       // When the mouse enters the label area, highlight the label.
       // When the mouse enters the label area, highlight the label.
       set_mouse_within(true);
       set_mouse_within(true);
-
+      
       // Now we want to get a WM_MOUSELEAVE when the mouse leaves the
       // Now we want to get a WM_MOUSELEAVE when the mouse leaves the
-      // graph window.
+      // label.
       TRACKMOUSEEVENT tme = {
       TRACKMOUSEEVENT tme = {
         sizeof(TRACKMOUSEEVENT),
         sizeof(TRACKMOUSEEVENT),
         TME_LEAVE,
         TME_LEAVE,

+ 4 - 2
pandatool/src/win-stats/winStatsLabel.h

@@ -24,6 +24,7 @@
 #include <windows.h>
 #include <windows.h>
 
 
 class WinStatsMonitor;
 class WinStatsMonitor;
+class WinStatsGraph;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : WinStatsLabel
 //       Class : WinStatsLabel
@@ -34,8 +35,8 @@ class WinStatsMonitor;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class WinStatsLabel {
 class WinStatsLabel {
 public:
 public:
-  WinStatsLabel(WinStatsMonitor *monitor, int thread_index, 
-                int collector_index, bool use_fullname);
+  WinStatsLabel(WinStatsMonitor *monitor, WinStatsGraph *graph,
+                int thread_index, int collector_index, bool use_fullname);
   ~WinStatsLabel();
   ~WinStatsLabel();
 
 
   void setup(HWND parent_window);
   void setup(HWND parent_window);
@@ -62,6 +63,7 @@ private:
   LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
   LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
 
   WinStatsMonitor *_monitor;
   WinStatsMonitor *_monitor;
+  WinStatsGraph *_graph;
   int _thread_index;
   int _thread_index;
   int _collector_index;
   int _collector_index;
   string _text;
   string _text;

+ 15 - 5
pandatool/src/win-stats/winStatsLabelStack.cxx

@@ -30,8 +30,6 @@ const char * const WinStatsLabelStack::_window_class_name = "stack";
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WinStatsLabelStack::
 WinStatsLabelStack::
 WinStatsLabelStack() {
 WinStatsLabelStack() {
-  _window = 0;
-
   _x = 0;
   _x = 0;
   _y = 0;
   _y = 0;
   _width = 0;
   _width = 0;
@@ -185,6 +183,18 @@ get_label_height(int label_index) const {
   return _labels[label_index]->get_height();
   return _labels[label_index]->get_height();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsLabelStack::get_label_collector_index
+//       Access: Public
+//  Description: Returns the collector index associated with the
+//               indicated label.
+////////////////////////////////////////////////////////////////////
+int WinStatsLabelStack::
+get_label_collector_index(int label_index) const {
+  nassertr(label_index >= 0 && label_index < (int)_labels.size(), -1);
+  return _labels[label_index]->get_collector_index();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsLabelStack::clear_labels
 //     Function: WinStatsLabelStack::clear_labels
 //       Access: Public
 //       Access: Public
@@ -207,15 +217,15 @@ clear_labels() {
 //               new label index.
 //               new label index.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int WinStatsLabelStack::
 int WinStatsLabelStack::
-add_label(WinStatsMonitor *monitor, int thread_index, int collector_index,
-          bool use_fullname) {
+add_label(WinStatsMonitor *monitor, WinStatsGraph *graph,
+          int thread_index, int collector_index, bool use_fullname) {
   int yp = _height;
   int yp = _height;
   if (!_labels.empty()) {
   if (!_labels.empty()) {
     WinStatsLabel *top_label = _labels.back();
     WinStatsLabel *top_label = _labels.back();
     yp = top_label->get_y() - top_label->get_height();
     yp = top_label->get_y() - top_label->get_height();
   }
   }
   WinStatsLabel *label = 
   WinStatsLabel *label = 
-    new WinStatsLabel(monitor, thread_index, collector_index, use_fullname);
+    new WinStatsLabel(monitor, graph, thread_index, collector_index, use_fullname);
   if (_window) {
   if (_window) {
     label->setup(_window);
     label->setup(_window);
     label->set_pos(0, yp, _width);
     label->set_pos(0, yp, _width);

+ 4 - 2
pandatool/src/win-stats/winStatsLabelStack.h

@@ -26,6 +26,7 @@
 
 
 class WinStatsLabel;
 class WinStatsLabel;
 class WinStatsMonitor;
 class WinStatsMonitor;
+class WinStatsGraph;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : WinStatsLabelStack
 //       Class : WinStatsLabelStack
@@ -49,10 +50,11 @@ public:
 
 
   int get_label_y(int label_index) const;
   int get_label_y(int label_index) const;
   int get_label_height(int label_index) const;
   int get_label_height(int label_index) const;
+  int get_label_collector_index(int label_index) const;
 
 
   void clear_labels();
   void clear_labels();
-  int add_label(WinStatsMonitor *monitor, int thread_index,
-                int collector_index, bool use_fullname);
+  int add_label(WinStatsMonitor *monitor, WinStatsGraph *graph,
+                int thread_index, int collector_index, bool use_fullname);
   int get_num_labels() const;
   int get_num_labels() const;
 
 
   void highlight_label(int collector_index);
   void highlight_label(int collector_index);

+ 72 - 1
pandatool/src/win-stats/winStatsPianoRoll.cxx

@@ -117,6 +117,18 @@ set_time_units(int unit_mask) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsPianoRoll::clicked_label
+//       Access: Public, Virtual
+//  Description: Called when the user single-clicks on a label.
+////////////////////////////////////////////////////////////////////
+void WinStatsPianoRoll::
+clicked_label(int collector_index) {
+  if (collector_index >= 0) {
+    WinStatsGraph::_monitor->open_strip_chart(WinStatsGraph::_thread_index, collector_index);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsPianoRoll::set_horizontal_scale
 //     Function: WinStatsPianoRoll::set_horizontal_scale
 //       Access: Public
 //       Access: Public
@@ -254,6 +266,27 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     break;
     break;
 
 
   case WM_MOUSEMOVE: 
   case WM_MOUSEMOVE: 
+    if (_drag_mode == DM_none && _potential_drag_mode == DM_none) {
+      // When the mouse is over a color bar, highlight it.
+      PN_int16 x = LOWORD(lparam);
+      PN_int16 y = HIWORD(lparam);
+      _label_stack.highlight_label(get_collector_under_pixel(x, y));
+
+      // Now we want to get a WM_MOUSELEAVE when the mouse leaves the
+      // graph window.
+      TRACKMOUSEEVENT tme = {
+        sizeof(TRACKMOUSEEVENT),
+        TME_LEAVE,
+        _graph_window,
+        0
+      };
+      TrackMouseEvent(&tme);
+
+    } else {
+      // If the mouse is in some drag mode, stop highlighting.
+      _label_stack.highlight_label(-1);
+    }
+
     if (_drag_mode == DM_scale) {
     if (_drag_mode == DM_scale) {
       PN_int16 x = LOWORD(lparam);
       PN_int16 x = LOWORD(lparam);
       float ratio = (float)x / (float)get_xsize();
       float ratio = (float)x / (float)get_xsize();
@@ -279,6 +312,11 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     }
     }
     break;
     break;
 
 
+  case WM_MOUSELEAVE:
+    // When the mouse leaves the graph, stop highlighting.
+    _label_stack.highlight_label(-1);
+    break;
+
   case WM_LBUTTONUP:
   case WM_LBUTTONUP:
     if (_drag_mode == DM_scale) {
     if (_drag_mode == DM_scale) {
       _drag_mode = DM_none;
       _drag_mode = DM_none;
@@ -298,6 +336,17 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     }
     }
     break;
     break;
 
 
+  case WM_LBUTTONDBLCLK:
+    {
+      // Double-clicking on a color bar in the graph is the same as
+      // double-clicking on the corresponding label.
+      PN_int16 x = LOWORD(lparam);
+      PN_int16 y = HIWORD(lparam);
+      clicked_label(get_collector_under_pixel(x, y));
+      return 0;
+    }
+    break;
+
   default:
   default:
     break;
     break;
   }
   }
@@ -382,6 +431,28 @@ consider_drag_start(int mouse_x, int mouse_y, int width, int height) {
   return WinStatsGraph::consider_drag_start(mouse_x, mouse_y, width, height);
   return WinStatsGraph::consider_drag_start(mouse_x, mouse_y, width, height);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsPianoRoll::get_collector_under_pixel
+//       Access: Private
+//  Description: Returns the collector index associated with the
+//               indicated vertical row, or -1.
+////////////////////////////////////////////////////////////////////
+int WinStatsPianoRoll::
+get_collector_under_pixel(int xpoint, int ypoint) {
+  if (_label_stack.get_num_labels() == 0) {
+    return -1;
+  }
+
+  // Assume all of the labels are the same height.
+  int height = _label_stack.get_label_height(0);
+  int row = (get_ysize() - ypoint) / height;
+  if (row >= 0 && row < _label_stack.get_num_labels()) {
+    return _label_stack.get_label_collector_index(row);
+  } else {
+    return -1;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsPianoRoll::update_labels
 //     Function: WinStatsPianoRoll::update_labels
 //       Access: Private
 //       Access: Private
@@ -392,7 +463,7 @@ update_labels() {
   _label_stack.clear_labels();
   _label_stack.clear_labels();
   for (int i = 0; i < get_num_labels(); i++) {
   for (int i = 0; i < get_num_labels(); i++) {
     int label_index = 
     int label_index = 
-      _label_stack.add_label(WinStatsGraph::_monitor, 
+      _label_stack.add_label(WinStatsGraph::_monitor, this,
                              WinStatsGraph::_thread_index,
                              WinStatsGraph::_thread_index,
                              get_label_collector(i), true);
                              get_label_collector(i), true);
   }
   }

+ 2 - 0
pandatool/src/win-stats/winStatsPianoRoll.h

@@ -45,6 +45,7 @@ public:
   virtual void changed_graph_size(int graph_xsize, int graph_ysize);
   virtual void changed_graph_size(int graph_xsize, int graph_ysize);
 
 
   virtual void set_time_units(int unit_mask);
   virtual void set_time_units(int unit_mask);
+  virtual void clicked_label(int collector_index);
   void set_horizontal_scale(float time_width);
   void set_horizontal_scale(float time_width);
 
 
 protected:
 protected:
@@ -62,6 +63,7 @@ protected:
                                        int width, int height);
                                        int width, int height);
 
 
 private:
 private:
+  int get_collector_under_pixel(int xpoint, int ypoint);
   void update_labels();
   void update_labels();
   void draw_guide_bar(HDC hdc, const GuideBar &bar);
   void draw_guide_bar(HDC hdc, const GuideBar &bar);
   void draw_guide_label(HDC hdc, int y, const PStatGraph::GuideBar &bar);
   void draw_guide_label(HDC hdc, int y, const PStatGraph::GuideBar &bar);

+ 41 - 1
pandatool/src/win-stats/winStatsStripChart.cxx

@@ -153,6 +153,35 @@ set_scroll_speed(float scroll_speed) {
   }
   }
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::clicked_label
+//       Access: Public, Virtual
+//  Description: Called when the user single-clicks on a label.
+////////////////////////////////////////////////////////////////////
+void WinStatsStripChart::
+clicked_label(int collector_index) {
+  if (collector_index < 0) {
+    // Clicking on whitespace in the graph is the same as clicking on
+    // the top label.
+    collector_index = get_collector_index();
+  }
+
+  if (collector_index == get_collector_index() && collector_index != 0) {
+    // Clicking on the top label means to go up to the parent level.
+    const PStatClientData *client_data = 
+      WinStatsGraph::_monitor->get_client_data();
+    if (client_data->has_collector(collector_index)) {
+      const PStatCollectorDef &def =
+        client_data->get_collector_def(collector_index);
+      set_collector_index(def._parent_index);
+    }
+
+  } else {
+    // Clicking on any other label means to focus on that.
+    set_collector_index(collector_index);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsStripChart::set_vertical_scale
 //     Function: WinStatsStripChart::set_vertical_scale
 //       Access: Public
 //       Access: Public
@@ -180,7 +209,7 @@ update_labels() {
 
 
   _label_stack.clear_labels();
   _label_stack.clear_labels();
   for (int i = 0; i < get_num_labels(); i++) {
   for (int i = 0; i < get_num_labels(); i++) {
-    _label_stack.add_label(WinStatsGraph::_monitor, _thread_index,
+    _label_stack.add_label(WinStatsGraph::_monitor, this, _thread_index,
                            get_label_collector(i), false);
                            get_label_collector(i), false);
   }
   }
   _labels_changed = false;
   _labels_changed = false;
@@ -427,6 +456,17 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     }
     }
     break;
     break;
 
 
+  case WM_LBUTTONDBLCLK:
+    {
+      // Double-clicking on a color bar in the graph is the same as
+      // double-clicking on the corresponding label.
+      PN_int16 x = LOWORD(lparam);
+      PN_int16 y = HIWORD(lparam);
+      clicked_label(get_collector_under_pixel(x, y));
+      return 0;
+    }
+    break;
+
   default:
   default:
     break;
     break;
   }
   }

+ 1 - 0
pandatool/src/win-stats/winStatsStripChart.h

@@ -46,6 +46,7 @@ public:
 
 
   virtual void set_time_units(int unit_mask);
   virtual void set_time_units(int unit_mask);
   virtual void set_scroll_speed(float scroll_speed);
   virtual void set_scroll_speed(float scroll_speed);
+  virtual void clicked_label(int collector_index);
   void set_vertical_scale(float value_height);
   void set_vertical_scale(float value_height);
 
 
 protected:
 protected: