Browse Source

guide bar units

David Rose 22 years ago
parent
commit
86985aaa84

+ 2 - 1
pandatool/src/win-stats/Sources.pp

@@ -16,8 +16,9 @@
     winStatsGraph.cxx winStatsGraph.h \
     winStatsLabel.cxx winStatsLabel.h \
     winStatsLabelStack.cxx winStatsLabelStack.h \
-    winStatsServer.cxx winStatsServer.h \
+    winStatsMenuId.h \
     winStatsMonitor.cxx winStatsMonitor.h winStatsMonitor.I \
+    winStatsServer.cxx winStatsServer.h \
     winStatsStripChart.cxx winStatsStripChart.h
 
   #define WIN_SYS_LIBS Imm32.lib winmm.lib kernel32.lib oldnames.lib user32.lib gdi32.lib

+ 7 - 1
pandatool/src/win-stats/winStatsChartMenu.cxx

@@ -61,7 +61,13 @@ get_menu_handle() {
 void WinStatsChartMenu::
 add_to_menu_bar(HMENU menu_bar) {
   const PStatClientData *client_data = _monitor->get_client_data();
-  string thread_name = client_data->get_thread_name(_thread_index);
+  string thread_name;
+  if (_thread_index == 0) {
+    // A special case for the main thread.
+    thread_name = "Graphs";
+  } else {
+    thread_name = client_data->get_thread_name(_thread_index);
+  }
 
   MENUITEMINFO mii;
   memset(&mii, 0, sizeof(mii));

+ 12 - 0
pandatool/src/win-stats/winStatsGraph.cxx

@@ -119,6 +119,18 @@ void WinStatsGraph::
 changed_graph_size(int graph_xsize, int graph_ysize) {
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsGraph::set_time_units
+//       Access: Public, Virtual
+//  Description: Called when the user selects a new time units from
+//               the monitor pulldown menu, this should adjust the
+//               units for the graph to the indicated mask if it is a
+//               time-based graph.
+////////////////////////////////////////////////////////////////////
+void WinStatsGraph::
+set_time_units(int unit_mask) {
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsGraph::close
 //       Access: Protected

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

@@ -43,6 +43,8 @@ public:
   virtual void force_redraw();
   virtual void changed_graph_size(int graph_xsize, int graph_ysize);
 
+  virtual void set_time_units(int unit_mask);
+
 protected:
   void close();
 

+ 40 - 0
pandatool/src/win-stats/winStatsMenuId.h

@@ -0,0 +1,40 @@
+// Filename: winStatsMenuId.h
+// Created by:  drose (11Jan04)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef WINSTATSMENUID_H
+#define WINSTATSMENUID_H
+
+#include "pandatoolbase.h"
+
+////////////////////////////////////////////////////////////////////
+//        Enum : WinStatsMenuId
+// Description : The enumerated values here are used for menu ID's for
+//               the various pulldown menus in the application.
+////////////////////////////////////////////////////////////////////
+enum WinStatsMenuId {
+  MI_none,
+  MI_time_ms,
+  MI_time_hz,
+
+  // This one is last and represents the beginning of the range for
+  // the various "new chart" menu options.
+  MI_new_chart
+};
+
+#endif
+

+ 119 - 12
pandatool/src/win-stats/winStatsMonitor.cxx

@@ -19,7 +19,8 @@
 #include "winStatsMonitor.h"
 #include "winStatsStripChart.h"
 #include "winStatsChartMenu.h"
-
+#include "winStatsMenuId.h"
+#include "pStatGraph.h"
 #include "pStatCollectorDef.h"
 #include "indent.h"
 
@@ -35,6 +36,8 @@ WinStatsMonitor::
 WinStatsMonitor() {
   _window = 0;
   _menu_bar = 0;
+  _options_menu = 0;
+  _time_units = PStatGraph::GBU_ms;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -246,15 +249,17 @@ get_window() const {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: WinStatsMonitor::open_strip_chart_
+//     Function: WinStatsMonitor::open_strip_chart
 //       Access: Public
 //  Description: Opens a new strip chart showing the indicated data.
 ////////////////////////////////////////////////////////////////////
 void WinStatsMonitor::
 open_strip_chart(int thread_index, int collector_index) {
-  WinStatsStripChart *chart = 
+  WinStatsStripChart *graph = 
     new WinStatsStripChart(this, thread_index, collector_index);
-  add_graph(chart);
+  add_graph(graph);
+
+  graph->set_time_units(_time_units);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -267,8 +272,9 @@ open_strip_chart(int thread_index, int collector_index) {
 const WinStatsMonitor::MenuDef &WinStatsMonitor::
 lookup_menu(int menu_id) const {
   static MenuDef invalid(0, 0);
-  nassertr(menu_id >= 0 && menu_id < (int)_menu_by_id.size(), invalid);
-  return _menu_by_id[menu_id];
+  int menu_index = menu_id - MI_new_chart;
+  nassertr(menu_index >= 0 && menu_index < (int)_menu_by_id.size(), invalid);
+  return _menu_by_id[menu_index];
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -289,13 +295,48 @@ get_menu_id(const MenuDef &menu_def) {
   }
 
   // Slot a new id.
-  int menu_id = (int)_menu_by_id.size();
+  int menu_id = (int)_menu_by_id.size() + MI_new_chart;
   _menu_by_id.push_back(menu_def);
   _menu_by_def[menu_def] = menu_id;
 
   return menu_id;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsMonitor::set_time_units
+//       Access: Public
+//  Description: Called when the user selects a new time units from
+//               the monitor pulldown menu, this should adjust the
+//               units for all graphs to the indicated mask if it is a
+//               time-based graph.
+////////////////////////////////////////////////////////////////////
+void WinStatsMonitor::
+set_time_units(int unit_mask) {
+  _time_units = unit_mask;
+
+  // First, change all of the open graphs appropriately.
+  Graphs::iterator gi;
+  for (gi = _graphs.begin(); gi != _graphs.end(); ++gi) {
+    WinStatsGraph *graph = (*gi);
+    graph->set_time_units(_time_units);
+  }
+
+  // Now change the checkmark on the pulldown menu.
+  MENUITEMINFO mii;
+  memset(&mii, 0, sizeof(mii));
+  mii.cbSize = sizeof(mii);
+  mii.fMask = MIIM_STATE;
+  mii.fState = MFS_CHECKED;
+
+  mii.fState = ((_time_units & PStatGraph::GBU_ms) != 0) ? 
+    MFS_CHECKED : MFS_UNCHECKED;
+  SetMenuItemInfo(_options_menu, MI_time_ms, FALSE, &mii);
+
+  mii.fState = ((_time_units & PStatGraph::GBU_hz) != 0) ? 
+    MFS_CHECKED : MFS_UNCHECKED;
+  SetMenuItemInfo(_options_menu, MI_time_hz, FALSE, &mii);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsMonitor::add_graph
 //       Access: Private
@@ -337,6 +378,8 @@ create_window() {
 
   _menu_bar = CreateMenu();
 
+  setup_options_menu();
+
   ChartMenus::iterator mi;
   for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
     (*mi)->add_to_menu_bar(_menu_bar);
@@ -356,9 +399,47 @@ create_window() {
   }
 
   SetWindowLongPtr(_window, 0, (LONG_PTR)this);
-  ShowWindow(_window, SW_SHOWNORMAL);
-  SetWindowPos(_window, HWND_TOP, 0, 0, 0, 0, 
-               SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+
+  // For some reason, SW_SHOWNORMAL doesn't always work, but
+  // SW_RESTORE seems to.
+  ShowWindow(_window, SW_RESTORE);
+  SetForegroundWindow(_window);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsMonitor::setup_options_menu
+//       Access: Private
+//  Description: Creates the "Options" pulldown menu.
+////////////////////////////////////////////////////////////////////
+void WinStatsMonitor::
+setup_options_menu() {
+  _options_menu = CreatePopupMenu();
+
+  MENUITEMINFO mii;
+  memset(&mii, 0, sizeof(mii));
+  mii.cbSize = sizeof(mii);
+
+  mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU;
+  mii.fType = MFT_STRING; 
+  mii.hSubMenu = _options_menu;
+  mii.dwTypeData = "Options"; 
+  InsertMenuItem(_menu_bar, GetMenuItemCount(_menu_bar), TRUE, &mii);
+
+  
+  mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_CHECKMARKS | MIIM_STATE;
+  mii.fType = MFT_STRING | MFT_RADIOCHECK; 
+  mii.hbmpChecked = NULL;
+  mii.hbmpUnchecked = NULL;
+  mii.fState = MFS_CHECKED;
+  mii.wID = MI_time_ms;
+  mii.dwTypeData = "ms";
+  InsertMenuItem(_options_menu, GetMenuItemCount(_options_menu), TRUE, &mii);
+
+  mii.fState = MFS_UNCHECKED;
+  mii.wID = MI_time_hz;
+  mii.dwTypeData = "Hz";
+  InsertMenuItem(_options_menu, GetMenuItemCount(_options_menu), TRUE, &mii);
+
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -425,8 +506,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
   case WM_COMMAND:
     if (HIWORD(wparam) <= 1) {
       int menu_id = LOWORD(wparam);
-      const MenuDef &menu_def = lookup_menu(menu_id);
-      open_strip_chart(menu_def._thread_index, menu_def._collector_index);
+      handle_menu_command(menu_id);
       return 0;
     }
     break;
@@ -437,3 +517,30 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
 
   return DefWindowProc(hwnd, msg, wparam, lparam);
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsMonitor::handle_menu_command
+//       Access: Private
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void WinStatsMonitor::
+handle_menu_command(int menu_id) {
+  switch (menu_id) {
+  case MI_none:
+    break;
+
+  case MI_time_ms:
+    set_time_units(PStatGraph::GBU_ms);
+    break;
+
+  case MI_time_hz:
+    set_time_units(PStatGraph::GBU_hz);
+    break;
+
+  default:
+    if (menu_id >= MI_new_chart) {
+      const MenuDef &menu_def = lookup_menu(menu_id);
+      open_strip_chart(menu_def._thread_index, menu_def._collector_index);
+    }
+  }
+}

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

@@ -69,16 +69,20 @@ public:
 
   const MenuDef &lookup_menu(int menu_id) const;
   int get_menu_id(const MenuDef &menu_def);
+
+  void set_time_units(int unit_mask);
   
 private:
   void add_graph(WinStatsGraph *graph);
   void remove_graph(WinStatsGraph *graph);
 
   void create_window();
+  void setup_options_menu();
   static void register_window_class(HINSTANCE application);
 
   static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
   LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+  void handle_menu_command(int menu_id);
 
   typedef pset<WinStatsGraph *> Graphs;
   Graphs _graphs;
@@ -93,7 +97,9 @@ private:
 
   HWND _window;
   HMENU _menu_bar;
+  HMENU _options_menu;
   string _window_title;
+  int _time_units;
 
   static bool _window_class_registered;
   static const char * const _window_class_name;

+ 38 - 3
pandatool/src/win-stats/winStatsStripChart.cxx

@@ -43,6 +43,9 @@ WinStatsStripChart(WinStatsMonitor *monitor, int thread_index,
   _drag_vscale = false;
   _drag_vscale_start = 0.0f;
 
+  // Let's show the units on the guide bar labels.  There's room.
+  set_guide_bar_units(get_guide_bar_units() | GBU_show_units);
+
   create_window();
   clear_region();
 }
@@ -109,6 +112,29 @@ changed_graph_size(int graph_xsize, int graph_ysize) {
   PStatStripChart::changed_size(graph_xsize, graph_ysize);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: WinStatsStripChart::set_time_units
+//       Access: Public, Virtual
+//  Description: Called when the user selects a new time units from
+//               the monitor pulldown menu, this should adjust the
+//               units for the graph to the indicated mask if it is a
+//               time-based graph.
+////////////////////////////////////////////////////////////////////
+void WinStatsStripChart::
+set_time_units(int unit_mask) {
+  int old_unit_mask = get_guide_bar_units();
+  if ((old_unit_mask & (GBU_hz | GBU_ms)) != 0) {
+    unit_mask = unit_mask & (GBU_hz | GBU_ms);
+    unit_mask |= (old_unit_mask & GBU_show_units);
+    set_guide_bar_units(unit_mask);
+
+    RECT rect;
+    GetClientRect(_window, &rect);
+    rect.left = _right_margin;
+    InvalidateRect(_window, &rect, TRUE);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: WinStatsStripChart::set_vertical_scale
 //       Access: Public
@@ -283,12 +309,20 @@ end_draw(int from_x, int to_x) {
 ////////////////////////////////////////////////////////////////////
 LONG WinStatsStripChart::
 window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
-  /*
   switch (msg) {
+  case WM_RBUTTONDOWN:
+    {
+      set_guide_bar_units(GBU_hz | GBU_show_units);
+      RECT rect;
+      GetClientRect(_window, &rect);
+      rect.left = _right_margin;
+      InvalidateRect(_window, &rect, TRUE);
+    }
+    return 0;
+    
   default:
     break;
-    }
-  */
+  }
 
   return WinStatsGraph::window_proc(hwnd, msg, wparam, lparam);
 }
@@ -334,6 +368,7 @@ graph_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
     }
     break;
 
+
   default:
     break;
   }

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

@@ -44,6 +44,7 @@ public:
   virtual void force_redraw();
   virtual void changed_graph_size(int graph_xsize, int graph_ysize);
 
+  virtual void set_time_units(int unit_mask);
   void set_vertical_scale(float value_height);
 
 protected: