Browse Source

add guide bars

David Rose 22 years ago
parent
commit
5a9379a1ac

+ 1 - 1
pandatool/src/win-stats/winStats.cxx

@@ -72,7 +72,7 @@ create_toplevel_window(HINSTANCE application) {
 
   HWND toplevel_window = 
     CreateWindow(toplevel_class_name, "PStats", window_style,
-                 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
+                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                  NULL, NULL, application, 0);
   if (!toplevel_window) {
     nout << "Could not create toplevel window!\n";

+ 63 - 37
pandatool/src/win-stats/winStatsGraph.cxx

@@ -37,12 +37,18 @@ WinStatsGraph(WinStatsMonitor *monitor, int thread_index) :
   _graph_window = 0;
   _bitmap = 0;
   _bitmap_dc = 0;
+
+  _graph_left = 0;
+  _graph_top = 0;
   _bitmap_xsize = 0;
   _bitmap_ysize = 0;
   _left_margin = 96;
   _right_margin = 32;
   _top_margin = 16;
   _bottom_margin = 8;
+
+  _dark_pen = CreatePen(PS_SOLID, 1, RGB(51, 51, 51));
+  _light_pen = CreatePen(PS_SOLID, 1, RGB(154, 154, 154));
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -54,6 +60,9 @@ WinStatsGraph::
 ~WinStatsGraph() {
   _monitor = (WinStatsMonitor *)NULL;
   release_bitmap();
+
+  DeleteObject(_dark_pen);
+  DeleteObject(_light_pen);
   
   Brushes::iterator bi;
   for (bi = _brushes.begin(); bi != _brushes.end(); ++bi) {
@@ -205,7 +214,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
 
   case WM_SIZE:
     move_label_stack();
-    InvalidateRect(hwnd, NULL, FALSE);
+    InvalidateRect(hwnd, NULL, TRUE);
     break;
 
   case WM_PAINT:
@@ -237,6 +246,43 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
         }
       }
 
+      additional_window_paint(hdc);
+
+      EndPaint(hwnd, &ps);
+      return 0;
+    }
+
+  default:
+    break;
+  }
+
+  return DefWindowProc(hwnd, msg, wparam, lparam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsGraph::graph_window_proc
+//       Access: Protected, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+LONG WinStatsGraph::
+graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
+  switch (msg) {
+  case WM_DISPLAYCHANGE:
+    setup_bitmap(_bitmap_xsize, _bitmap_ysize);
+    force_redraw();
+    break;
+
+  case WM_PAINT:
+    {
+      // Repaint the graph by copying the backing pixmap in.
+      PAINTSTRUCT ps;
+      HDC hdc = BeginPaint(hwnd, &ps);
+
+      BitBlt(hdc, 0, 0, 
+             _bitmap_xsize, _bitmap_ysize,
+             _bitmap_dc, 0, 0,
+             SRCCOPY);
+
       EndPaint(hwnd, &ps);
       return 0;
     }
@@ -248,6 +294,18 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   return DefWindowProc(hwnd, msg, wparam, lparam);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsGraph::additional_window_paint
+//       Access: Protected, Virtual
+//  Description: This is called during the servicing of WM_PAINT; it
+//               gives a derived class opportunity to do some further
+//               painting into the window (the outer window, not the
+//               graph window).
+////////////////////////////////////////////////////////////////////
+void WinStatsGraph::
+additional_window_paint(HDC hdc) {
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsGraph::setup_bitmap
 //       Access: Private
@@ -300,8 +358,11 @@ move_graph_window(int graph_left, int graph_top, int graph_xsize, int graph_ysiz
     create_graph_window();
   }
 
+  _graph_left = graph_left;
+  _graph_top = graph_top;
+
   SetWindowPos(_graph_window, 0, 
-               graph_left, graph_top,
+               _graph_left, _graph_top,
                graph_xsize, graph_ysize,
                SWP_NOZORDER | SWP_SHOWWINDOW);
 
@@ -387,38 +448,3 @@ static_graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     return DefWindowProc(hwnd, msg, wparam, lparam);
   }
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: WinStatsGraph::graph_window_proc
-//       Access: Private
-//  Description: 
-////////////////////////////////////////////////////////////////////
-LONG WinStatsGraph::
-graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
-  switch (msg) {
-  case WM_DISPLAYCHANGE:
-    setup_bitmap(_bitmap_xsize, _bitmap_ysize);
-    force_redraw();
-    break;
-
-  case WM_PAINT:
-    {
-      // Repaint the graph by copying the backing pixmap in.
-      PAINTSTRUCT ps;
-      HDC hdc = BeginPaint(hwnd, &ps);
-
-      BitBlt(hdc, 0, 0, 
-             _bitmap_xsize, _bitmap_ysize,
-             _bitmap_dc, 0, 0,
-             SRCCOPY);
-
-      EndPaint(hwnd, &ps);
-      return 0;
-    }
-
-  default:
-    break;
-  }
-
-  return DefWindowProc(hwnd, msg, wparam, lparam);
-}

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

@@ -51,7 +51,11 @@ protected:
 
   HBRUSH get_collector_brush(int collector_index);
 
-  LONG WINAPI window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  virtual LONG graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+
+  virtual void additional_window_paint(HDC hdc);
+
 
 protected:
   // Table of brushes for our various collectors.
@@ -67,10 +71,14 @@ protected:
   HBITMAP _bitmap;
   HDC _bitmap_dc;
 
+  int _graph_left, _graph_top;
   int _bitmap_xsize, _bitmap_ysize;
   int _left_margin, _right_margin;
   int _top_margin, _bottom_margin;
 
+  HPEN _dark_pen;
+  HPEN _light_pen;
+
 private:
   void setup_bitmap(int xsize, int ysize);
   void release_bitmap();
@@ -80,7 +88,6 @@ private:
   static void register_graph_window_class(HINSTANCE application);
 
   static LONG WINAPI static_graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-  LONG WINAPI graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
   static bool _graph_window_class_registered;
   static const char * const _graph_window_class_name;

+ 2 - 2
pandatool/src/win-stats/winStatsLabel.cxx

@@ -96,7 +96,7 @@ setup(HWND parent_window) {
   create_window(parent_window);
 
   HDC hdc = GetDC(_window);
-  HGDIOBJ hfnt = GetStockObject(ANSI_VAR_FONT); 
+  HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT); 
   SelectObject(hdc, hfnt);
 
   SIZE size;
@@ -268,7 +268,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
       RECT rect = { 0, 0, _width, _height };
       FillRect(hdc, &rect, _bg_brush);
 
-      HGDIOBJ hfnt = GetStockObject(ANSI_VAR_FONT); 
+      HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT); 
       SelectObject(hdc, hfnt);
       SetTextAlign(hdc, TA_RIGHT | TA_TOP);
 

+ 1 - 1
pandatool/src/win-stats/winStatsLabel.h

@@ -52,7 +52,7 @@ private:
   static void register_window_class(HINSTANCE application);
 
   static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-  LONG WINAPI window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
   WinStatsMonitor *_monitor;
   int _thread_index;

+ 1 - 1
pandatool/src/win-stats/winStatsLabelStack.h

@@ -56,7 +56,7 @@ private:
   static void register_window_class(HINSTANCE application);
 
   static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-  LONG WINAPI window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
   HWND _window;
   int _x;

+ 3 - 2
pandatool/src/win-stats/winStatsMonitor.cxx

@@ -348,7 +348,7 @@ create_window() {
 
   _window = 
     CreateWindow(_window_class_name, _window_title.c_str(), window_style,
-                 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
+                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                  NULL, _menu_bar, application, 0);
   if (!_window) {
     nout << "Could not create monitor window!\n";
@@ -357,7 +357,8 @@ create_window() {
 
   SetWindowLongPtr(_window, 0, (LONG_PTR)this);
   ShowWindow(_window, SW_SHOWNORMAL);
-  ShowWindow(_window, SW_SHOWNORMAL);
+  SetWindowPos(_window, HWND_TOP, 0, 0, 0, 0, 
+               SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
pandatool/src/win-stats/winStatsMonitor.h

@@ -78,7 +78,7 @@ private:
   static void register_window_class(HINSTANCE application);
 
   static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-  LONG WINAPI window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
   typedef pset<WinStatsGraph *> Graphs;
   Graphs _graphs;

+ 159 - 17
pandatool/src/win-stats/winStatsStripChart.cxx

@@ -18,6 +18,7 @@
 
 #include "winStatsStripChart.h"
 #include "winStatsMonitor.h"
+#include "numeric_types.h"
 
 static const int default_strip_chart_width = 400;
 static const int default_strip_chart_height = 100;
@@ -39,6 +40,8 @@ WinStatsStripChart(WinStatsMonitor *monitor, int thread_index,
   WinStatsGraph(monitor, thread_index)
 {
   _brush_origin = 0;
+  _drag_vscale = false;
+  _drag_vscale_start = 0.0f;
 
   create_window();
   clear_region();
@@ -106,6 +109,22 @@ changed_graph_size(int graph_xsize, int graph_ysize) {
   PStatStripChart::changed_size(graph_xsize, graph_ysize);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::set_vertical_scale
+//       Access: Public
+//  Description: Changes the value the height of the vertical axis
+//               represents.  This may force a redraw.
+////////////////////////////////////////////////////////////////////
+void WinStatsStripChart::
+set_vertical_scale(float value_height) {
+  PStatStripChart::set_vertical_scale(value_height);
+
+  RECT rect;
+  GetClientRect(_window, &rect);
+  rect.left = _right_margin;
+  InvalidateRect(_window, &rect, TRUE);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsStripChart::update_labels
 //       Access: Protected, Virtual
@@ -233,12 +252,152 @@ draw_cursor(int x) {
 ////////////////////////////////////////////////////////////////////
 void WinStatsStripChart::
 end_draw(int from_x, int to_x) {
+  // Draw in the guide bars.
+  int num_guide_bars = get_num_guide_bars();
+  for (int i = 0; i < num_guide_bars; i++) {
+    const GuideBar &bar = get_guide_bar(i);
+    int y = height_to_pixel(bar._height);
+
+    if (y >= 5) {
+      // Only draw it if it's not too close to the top.
+      if (bar._is_target) {
+        SelectObject(_bitmap_dc, _light_pen);
+      } else {
+        SelectObject(_bitmap_dc, _dark_pen);
+      }
+      MoveToEx(_bitmap_dc, from_x, y, NULL);
+      LineTo(_bitmap_dc, to_x + 1, y);
+    }
+  }
+
   RECT rect = { 
     from_x, 0, to_x + 1, get_ysize() 
   };
   InvalidateRect(_graph_window, &rect, FALSE);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::window_proc
+//       Access: Protected
+//  Description: 
+////////////////////////////////////////////////////////////////////
+LONG WinStatsStripChart::
+window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
+  /*
+  switch (msg) {
+  default:
+    break;
+    }
+  */
+
+  return WinStatsGraph::window_proc(hwnd, msg, wparam, lparam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::graph_window_proc
+//       Access: Protected
+//  Description: 
+////////////////////////////////////////////////////////////////////
+LONG WinStatsStripChart::
+graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
+  switch (msg) {
+  case WM_LBUTTONDOWN:
+    {
+      _drag_vscale = true;
+      PN_int16 y = HIWORD(lparam);
+      _drag_vscale_start = pixel_to_height(y);
+      SetCapture(_graph_window);
+    }
+    return 0;
+
+  case WM_MOUSEMOVE: 
+    if (_drag_vscale) {
+      PN_int16 y = HIWORD(lparam);
+      float ratio = 1.0f - ((float)y / (float)get_ysize());
+      if (ratio > 0.0f) {
+        set_vertical_scale(_drag_vscale_start / ratio);
+      }
+      return 0;
+    }
+    break;
+
+  case WM_LBUTTONUP:
+    if (_drag_vscale) {
+      PN_int16 y = HIWORD(lparam);
+      float ratio = 1.0f - ((float)y / (float)get_ysize());
+      if (ratio > 0.0f) {
+        set_vertical_scale(_drag_vscale_start / ratio);
+      }
+      _drag_vscale = false;
+      ReleaseCapture();
+      return 0;
+    }
+    break;
+
+  default:
+    break;
+  }
+
+  return WinStatsGraph::graph_window_proc(hwnd, msg, wparam, lparam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::additional_window_paint
+//       Access: Protected, Virtual
+//  Description: This is called during the servicing of WM_PAINT; it
+//               gives a derived class opportunity to do some further
+//               painting into the window (the outer window, not the
+//               graph window).
+////////////////////////////////////////////////////////////////////
+void WinStatsStripChart::
+additional_window_paint(HDC hdc) {
+  HFONT hfnt = (HFONT)GetStockObject(ANSI_VAR_FONT); 
+  SelectObject(hdc, hfnt);
+  SetTextAlign(hdc, TA_LEFT | TA_TOP);
+  SetBkMode(hdc, TRANSPARENT);
+  SetTextColor(hdc, RGB(0, 0, 0));
+
+  RECT rect;
+  GetClientRect(_window, &rect);
+  int x = rect.right - _right_margin + 2;
+  int last_y = -100;
+
+  int num_guide_bars = get_num_guide_bars();
+  for (int i = 0; i < num_guide_bars; i++) {
+    const GuideBar &bar = get_guide_bar(i);
+    last_y = draw_guide_label(hdc, x, bar._height, last_y);
+  }
+
+  draw_guide_label(hdc, x, get_vertical_scale(), last_y);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::draw_guide_label
+//       Access: Private
+//  Description: Draws the text for the indicated guide bar label to
+//               the right of the graph, unless it would overlap with
+//               the indicated last label, whose top pixel value is
+//               given.  Returns the top pixel value of the new label.
+////////////////////////////////////////////////////////////////////
+int WinStatsStripChart::
+draw_guide_label(HDC hdc, int x, float value, int last_y) {
+  int y = height_to_pixel(value);
+  string label = format_number(value, get_guide_bar_units(),
+                               get_guide_bar_unit_name());
+  SIZE size;
+  GetTextExtentPoint32(hdc, label.data(), label.length(), &size);
+
+  int this_y = _graph_top + y - size.cy / 2;
+  if (last_y < this_y || last_y > this_y + size.cy) {
+    TextOut(hdc, x, this_y,
+            label.data(), label.length()); 
+    last_y = this_y;
+  }
+
+  return last_y;
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsStripChart::create_window
 //       Access: Private
@@ -332,20 +491,3 @@ static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     return DefWindowProc(hwnd, msg, wparam, lparam);
   }
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: WinStatsStripChart::window_proc
-//       Access: Private
-//  Description: 
-////////////////////////////////////////////////////////////////////
-LONG WinStatsStripChart::
-window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
-  /*
-  switch (msg) {
-  default:
-    break;
-  }
-  */
-
-  return WinStatsGraph::window_proc(hwnd, msg, wparam, lparam);
-}

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

@@ -44,6 +44,8 @@ public:
   virtual void force_redraw();
   virtual void changed_graph_size(int graph_xsize, int graph_ysize);
 
+  void set_vertical_scale(float value_height);
+
 protected:
   virtual void update_labels();
 
@@ -54,14 +56,20 @@ protected:
   virtual void draw_cursor(int x);
   virtual void end_draw(int from_x, int to_x);
 
+  LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  virtual LONG graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  virtual void additional_window_paint(HDC hdc);
+
 private:
+  int draw_guide_label(HDC hdc, int x, float value, int last_y);
   void create_window();
   static void register_window_class(HINSTANCE application);
 
   static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-  LONG WINAPI window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
 
   int _brush_origin;
+  bool _drag_vscale;
+  float _drag_vscale_start;
 
   static bool _window_class_registered;
   static const char * const _window_class_name;