瀏覽代碼

more on average mode

David Rose 21 年之前
父節點
當前提交
88743dab4d

+ 1 - 1
pandatool/src/pstatserver/pStatStripChart.I

@@ -137,7 +137,7 @@ INLINE void PStatStripChart::
 set_average_mode(bool average_mode) {
   if (_average_mode != average_mode) {
     _average_mode = average_mode;
-    force_reset();
+    force_redraw();
   }
 }
 

+ 2 - 0
pandatool/src/pstatserver/pStatStripChart.cxx

@@ -451,6 +451,8 @@ compute_average_pixel_data(PStatStripChart::FrameData &result,
     now_i++;
   }
 
+  then = max(then, thread_data->get_frame(then_i).get_start());
+
   // Sum up a weighted average of all of the individual frames we
   // pass.
 

+ 48 - 28
pandatool/src/win-stats/winStatsGraph.cxx

@@ -289,6 +289,14 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     InvalidateRect(hwnd, NULL, TRUE);
     break;
 
+  case WM_SIZING:
+    set_drag_mode(DM_sizing);
+    break;
+
+  case WM_EXITSIZEMOVE:
+    set_drag_mode(DM_none);
+    break;
+
   case WM_SETCURSOR:
     {
       // Why is it so hard to ask for the cursor position within the
@@ -324,7 +332,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
 
   case WM_LBUTTONDOWN:
     if (_potential_drag_mode != DM_none) {
-      _drag_mode = _potential_drag_mode;
+      set_drag_mode(_potential_drag_mode);
       _drag_start_x = (PN_int16)LOWORD(lparam);
       _drag_start_y = (PN_int16)HIWORD(lparam);
       SetCapture(_window);
@@ -350,7 +358,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     break;
 
   case WM_LBUTTONUP:
-    _drag_mode = DM_none;
+    set_drag_mode(DM_none);
     ReleaseCapture();
     break;
 
@@ -420,7 +428,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     break;
 
   case WM_LBUTTONUP:
-    _drag_mode = DM_none;
+    set_drag_mode(DM_none);
     ReleaseCapture();
     break;
 
@@ -490,6 +498,43 @@ consider_drag_start(int mouse_x, int mouse_y, int width, int height) {
   return DM_none;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsGraph::set_drag_mode
+//       Access: Protected, Virtual
+//  Description: This should be called whenever the drag mode needs to
+//               change state.  It provides hooks for a derived class
+//               to do something special.
+////////////////////////////////////////////////////////////////////
+void WinStatsGraph::
+set_drag_mode(WinStatsGraph::DragMode drag_mode) {
+  _drag_mode = drag_mode;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsGraph::move_graph_window
+//       Access: Protected, Virtual
+//  Description: Repositions the graph child window within the parent
+//               window according to the _margin variables.
+////////////////////////////////////////////////////////////////////
+void WinStatsGraph::
+move_graph_window(int graph_left, int graph_top, int graph_xsize, int graph_ysize) {
+  if (_graph_window == 0) {
+    create_graph_window();
+  }
+
+  _graph_left = graph_left;
+  _graph_top = graph_top;
+
+  SetWindowPos(_graph_window, 0, 
+               _graph_left, _graph_top,
+               graph_xsize, graph_ysize,
+               SWP_NOZORDER | SWP_SHOWWINDOW);
+
+  if (graph_xsize != _bitmap_xsize || graph_ysize != _bitmap_ysize) {
+    setup_bitmap(graph_xsize, graph_ysize);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsGraph::setup_bitmap
 //       Access: Private
@@ -530,31 +575,6 @@ release_bitmap() {
   }
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: WinStatsGraph::move_graph_window
-//       Access: Private
-//  Description: Repositions the graph child window within the parent
-//               window according to the _margin variables.
-////////////////////////////////////////////////////////////////////
-void WinStatsGraph::
-move_graph_window(int graph_left, int graph_top, int graph_xsize, int graph_ysize) {
-  if (_graph_window == 0) {
-    create_graph_window();
-  }
-
-  _graph_left = graph_left;
-  _graph_top = graph_top;
-
-  SetWindowPos(_graph_window, 0, 
-               _graph_left, _graph_top,
-               graph_xsize, graph_ysize,
-               SWP_NOZORDER | SWP_SHOWWINDOW);
-
-  if (graph_xsize != _bitmap_xsize || graph_ysize != _bitmap_ysize) {
-    setup_bitmap(graph_xsize, graph_ysize);
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsGraph::create_graph_window
 //       Access: Private

+ 5 - 2
pandatool/src/win-stats/winStatsGraph.h

@@ -43,6 +43,7 @@ public:
     DM_right_margin,
     DM_guide_bar,
     DM_new_guide_bar,
+    DM_sizing,
   };
 
 public:
@@ -78,6 +79,10 @@ protected:
   virtual void additional_graph_window_paint(HDC hdc);
   virtual DragMode consider_drag_start(int mouse_x, int mouse_y, 
                                        int width, int height);
+  virtual void set_drag_mode(DragMode drag_mode);
+
+  virtual void move_graph_window(int graph_left, int graph_top,
+                                 int graph_xsize, int graph_ysize);
 
 protected:
   // Table of brushes for our various collectors.
@@ -119,8 +124,6 @@ protected:
 private:
   void setup_bitmap(int xsize, int ysize);
   void release_bitmap();
-  void move_graph_window(int graph_left, int graph_top,
-                         int graph_xsize, int graph_ysize);
   void create_graph_window();
   static void register_graph_window_class(HINSTANCE application);
 

+ 6 - 6
pandatool/src/win-stats/winStatsPianoRoll.cxx

@@ -229,7 +229,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   switch (msg) {
   case WM_LBUTTONDOWN:
     if (_potential_drag_mode == DM_new_guide_bar) {
-      _drag_mode = DM_new_guide_bar;
+      set_drag_mode(DM_new_guide_bar);
       SetCapture(_graph_window);
       return 0;
     }
@@ -252,14 +252,14 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   switch (msg) {
   case WM_LBUTTONDOWN:
     if (_potential_drag_mode == DM_none) {
-      _drag_mode = DM_scale;
+      set_drag_mode(DM_scale);
       PN_int16 x = LOWORD(lparam);
       _drag_scale_start = pixel_to_height(x);
       SetCapture(_graph_window);
       return 0;
 
     } else if (_potential_drag_mode == DM_guide_bar && _drag_guide_bar >= 0) {
-      _drag_mode = DM_guide_bar;
+      set_drag_mode(DM_guide_bar);
       PN_int16 x = LOWORD(lparam);
       _drag_start_x = x;
       SetCapture(_graph_window);
@@ -302,7 +302,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
       // mouse comes within the graph's region.
       PN_int16 x = LOWORD(lparam);
       if (x >= 0 && x < get_xsize()) {
-        _drag_mode = DM_guide_bar;
+        set_drag_mode(DM_guide_bar);
         _drag_guide_bar = add_user_guide_bar(pixel_to_height(x));
         return 0;
       }
@@ -321,7 +321,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
 
   case WM_LBUTTONUP:
     if (_drag_mode == DM_scale) {
-      _drag_mode = DM_none;
+      set_drag_mode(DM_none);
       ReleaseCapture();
       return 0;
 
@@ -332,7 +332,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
       } else {
         move_user_guide_bar(_drag_guide_bar, pixel_to_height(x));
       }
-      _drag_mode = DM_none;
+      set_drag_mode(DM_none);
       ReleaseCapture();
       return 0;
     }

+ 84 - 6
pandatool/src/win-stats/winStatsStripChart.cxx

@@ -24,6 +24,12 @@
 static const int default_strip_chart_width = 400;
 static const int default_strip_chart_height = 100;
 
+// Surely we aren't expected to hardcode the size of a normal
+// checkbox.  But Windows seems to require this data to be passed to
+// CreateWindow(), so what else can I do?
+size_t WinStatsStripChart::_check_box_height = 13;
+size_t WinStatsStripChart::_check_box_width = 13;
+
 bool WinStatsStripChart::_window_class_registered = false;
 const char * const WinStatsStripChart::_window_class_name = "strip";
 
@@ -54,6 +60,8 @@ WinStatsStripChart(WinStatsMonitor *monitor, int thread_index,
     set_guide_bar_units(get_guide_bar_units() | GBU_show_units);
   }
 
+  _smooth_check_box = 0;
+
   create_window();
   clear_region();
 }
@@ -369,12 +377,24 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   switch (msg) {
   case WM_LBUTTONDOWN:
     if (_potential_drag_mode == DM_new_guide_bar) {
-      _drag_mode = DM_new_guide_bar;
+      set_drag_mode(DM_new_guide_bar);
       SetCapture(_graph_window);
       return 0;
     }
     break;
 
+  case WM_COMMAND:
+    switch (LOWORD(wparam)) {
+    case BN_CLICKED:
+      if ((HWND)lparam == _smooth_check_box) {
+        int result = SendMessage(_smooth_check_box, BM_GETCHECK, 0, 0);
+        set_average_mode(result == BST_CHECKED);
+        return 0;
+      }
+      break;
+    }
+    break;
+
   default:
     break;
   }
@@ -392,14 +412,14 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   switch (msg) {
   case WM_LBUTTONDOWN:
     if (_potential_drag_mode == DM_none) {
-      _drag_mode = DM_scale;
+      set_drag_mode(DM_scale);
       PN_int16 y = HIWORD(lparam);
       _drag_scale_start = pixel_to_height(y);
       SetCapture(_graph_window);
       return 0;
 
     } else if (_potential_drag_mode == DM_guide_bar && _drag_guide_bar >= 0) {
-      _drag_mode = DM_guide_bar;
+      set_drag_mode(DM_guide_bar);
       PN_int16 y = HIWORD(lparam);
       _drag_start_y = y;
       SetCapture(_graph_window);
@@ -442,7 +462,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
       // mouse comes within the graph's region.
       PN_int16 y = HIWORD(lparam);
       if (y >= 0 && y < get_ysize()) {
-        _drag_mode = DM_guide_bar;
+        set_drag_mode(DM_guide_bar);
         _drag_guide_bar = add_user_guide_bar(pixel_to_height(y));
         return 0;
       }
@@ -461,7 +481,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
 
   case WM_LBUTTONUP:
     if (_drag_mode == DM_scale) {
-      _drag_mode = DM_none;
+      set_drag_mode(DM_none);
       ReleaseCapture();
       return 0;
 
@@ -472,7 +492,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
       } else {
         move_user_guide_bar(_drag_guide_bar, pixel_to_height(y));
       }
-      _drag_mode = DM_none;
+      set_drag_mode(DM_none);
       ReleaseCapture();
       return 0;
     }
@@ -538,6 +558,12 @@ additional_window_paint(HDC hdc) {
   TextOut(hdc, rect.right - _right_margin, _top_margin,
           _net_value_text.data(), _net_value_text.length()); 
 
+  // Also draw the "Smooth" label on the check box.  This isn't part
+  // of the check box itself, because doing that doesn't use the right
+  // font!  Surely this isn't the correct Windows(tm) way to do this
+  // sort of thing, but I don't know any better for now.
+  SetTextAlign(hdc, TA_LEFT | TA_BOTTOM);
+  TextOut(hdc, _left_margin + _check_box_width + 2, _top_margin, "Smooth", 6);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -587,6 +613,52 @@ consider_drag_start(int mouse_x, int mouse_y, int width, int height) {
   return WinStatsGraph::consider_drag_start(mouse_x, mouse_y, width, height);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::set_drag_mode
+//       Access: Protected, Virtual
+//  Description: This should be called whenever the drag mode needs to
+//               change state.  It provides hooks for a derived class
+//               to do something special.
+////////////////////////////////////////////////////////////////////
+void WinStatsStripChart::
+set_drag_mode(WinStatsGraph::DragMode drag_mode) {
+  WinStatsGraph::set_drag_mode(drag_mode);
+
+  switch (_drag_mode) {
+  case DM_scale:
+  case DM_left_margin:
+  case DM_right_margin:
+  case DM_sizing:
+    // Disable smoothing for these expensive operations.
+    set_average_mode(false);
+    break;
+
+  default:
+    // Restore smoothing according to the current setting of the check
+    // box.
+    int result = SendMessage(_smooth_check_box, BM_GETCHECK, 0, 0);
+    set_average_mode(result == BST_CHECKED);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::move_graph_window
+//       Access: Protected, Virtual
+//  Description: Repositions the graph child window within the parent
+//               window according to the _margin variables.
+////////////////////////////////////////////////////////////////////
+void WinStatsStripChart::
+move_graph_window(int graph_left, int graph_top, int graph_xsize, int graph_ysize) {
+  WinStatsGraph::move_graph_window(graph_left, graph_top, graph_xsize, graph_ysize);
+  if (_smooth_check_box != 0) {
+    SetWindowPos(_smooth_check_box, 0, 
+                 _left_margin, _top_margin - _check_box_height - 1,
+                 0, 0,
+                 SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
+    InvalidateRect(_smooth_check_box, NULL, TRUE);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsStripChart::draw_guide_bar
 //       Access: Private
@@ -707,6 +779,12 @@ create_window() {
   SetWindowLongPtr(_window, 0, (LONG_PTR)this);
   setup_label_stack();
 
+  _smooth_check_box = 
+    CreateWindow("BUTTON", "",
+                 WS_CHILD | BS_AUTOCHECKBOX,
+                 0, 0, _check_box_width, _check_box_height,
+                 _window, NULL, application, 0);
+
   // Ensure that the window is on top of the stack.
   SetWindowPos(_window, HWND_TOP, 0, 0, 0, 0, 
                SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

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

@@ -66,6 +66,9 @@ protected:
   virtual void additional_graph_window_paint(HDC hdc);
   virtual DragMode consider_drag_start(int mouse_x, int mouse_y, 
                                        int width, int height);
+  virtual void set_drag_mode(DragMode drag_mode);
+  virtual void move_graph_window(int graph_left, int graph_top,
+                                 int graph_xsize, int graph_ysize);
 
 private:
   void draw_guide_bar(HDC hdc, int from_x, int to_x, const GuideBar &bar);
@@ -78,6 +81,9 @@ private:
   int _brush_origin;
   string _net_value_text;
 
+  HWND _smooth_check_box;
+  static size_t _check_box_height, _check_box_width;
+
   static bool _window_class_registered;
   static const char * const _window_class_name;
 };