diff --git a/pandatool/src/pstatserver/pStatClientData.cxx b/pandatool/src/pstatserver/pStatClientData.cxx index 06c8ff2070..cdc7763ded 100644 --- a/pandatool/src/pstatserver/pStatClientData.cxx +++ b/pandatool/src/pstatserver/pStatClientData.cxx @@ -324,6 +324,12 @@ add_collector(PStatCollectorDef *def) { _collectors[def->_index]._def = def; update_toplevel_collectors(); + + // If we already had the _is_level flag set, it should be + // immediately applied to all ancestors. + if (_collectors[def->_index]._is_level) { + set_collector_has_level(def->_parent_index, true); + } } //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/pstatserver/pStatStripChart.cxx b/pandatool/src/pstatserver/pStatStripChart.cxx index b832a3b886..aee76e490b 100644 --- a/pandatool/src/pstatserver/pStatStripChart.cxx +++ b/pandatool/src/pstatserver/pStatStripChart.cxx @@ -641,7 +641,11 @@ draw_pixels(int first_pixel, int last_pixel) { float time = pixel_to_timestamp(x); frame_number = thread_data->get_frame_number_at_time(time, frame_number); int w = 1; - while (x + w <= last_pixel && + int stop_pixel = last_pixel; + if (!_scroll_mode) { + stop_pixel = min(stop_pixel, _cursor_pixel); + } + while (x + w < stop_pixel && thread_data->get_frame_number_at_time(pixel_to_timestamp(x + w), frame_number) == frame_number) { w++; } @@ -653,5 +657,6 @@ draw_pixels(int first_pixel, int last_pixel) { x += w; } } + end_draw(first_pixel, last_pixel); } diff --git a/pandatool/src/win-stats/Sources.pp b/pandatool/src/win-stats/Sources.pp index 22baa0149f..1262935da8 100644 --- a/pandatool/src/win-stats/Sources.pp +++ b/pandatool/src/win-stats/Sources.pp @@ -17,7 +17,7 @@ winStatsLabel.cxx winStatsLabel.h \ winStatsLabelStack.cxx winStatsLabelStack.h \ winStatsServer.cxx winStatsServer.h \ - winStatsMonitor.cxx winStatsMonitor.h \ + winStatsMonitor.cxx winStatsMonitor.h winStatsMonitor.I \ winStatsStripChart.cxx winStatsStripChart.h #define WIN_SYS_LIBS Imm32.lib winmm.lib kernel32.lib oldnames.lib user32.lib gdi32.lib diff --git a/pandatool/src/win-stats/winStatsChartMenu.cxx b/pandatool/src/win-stats/winStatsChartMenu.cxx index 89abeb2f81..d710ae4103 100755 --- a/pandatool/src/win-stats/winStatsChartMenu.cxx +++ b/pandatool/src/win-stats/winStatsChartMenu.cxx @@ -17,7 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "winStatsChartMenu.h" -#include "pStatMonitor.h" +#include "winStatsMonitor.h" //////////////////////////////////////////////////////////////////// // Function: WinStatsChartMenu::Constructor @@ -25,7 +25,7 @@ // Description: //////////////////////////////////////////////////////////////////// WinStatsChartMenu:: -WinStatsChartMenu(PStatMonitor *monitor, int thread_index) : +WinStatsChartMenu(WinStatsMonitor *monitor, int thread_index) : _monitor(monitor), _thread_index(thread_index) { @@ -153,25 +153,29 @@ add_view(HMENU parent_menu, const PStatViewLevel *view_level) { const PStatClientData *client_data = _monitor->get_client_data(); string collector_name = client_data->get_collector_name(collector); + WinStatsMonitor::MenuDef menu_def(_thread_index, collector); + int menu_id = _monitor->get_menu_id(menu_def); + MENUITEMINFO mii; memset(&mii, 0, sizeof(mii)); mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STRING | MIIM_FTYPE; + mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID; mii.fType = MFT_STRING; + mii.wID = menu_id; mii.dwTypeData = (char *)collector_name.c_str(); InsertMenuItem(parent_menu, GetMenuItemCount(parent_menu), TRUE, &mii); int num_children = view_level->get_num_children(); - if (num_children != 0) { - // If the collector has any children, add a menu entry to go + if (num_children > 1) { + // If the collector has more than one child, add a menu entry to go // directly to each of its children. HMENU submenu = CreatePopupMenu(); string submenu_name = collector_name + " components"; - mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU; + mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU; mii.fType = MFT_STRING; - mii.hSubMenu = submenu; + mii.hSubMenu = submenu; mii.dwTypeData = (char *)submenu_name.c_str(); InsertMenuItem(parent_menu, GetMenuItemCount(parent_menu), TRUE, &mii); diff --git a/pandatool/src/win-stats/winStatsChartMenu.h b/pandatool/src/win-stats/winStatsChartMenu.h index daf8b0741f..aa9253c890 100755 --- a/pandatool/src/win-stats/winStatsChartMenu.h +++ b/pandatool/src/win-stats/winStatsChartMenu.h @@ -23,7 +23,7 @@ #include -class PStatMonitor; +class WinStatsMonitor; class PStatView; class PStatViewLevel; @@ -34,7 +34,7 @@ class PStatViewLevel; //////////////////////////////////////////////////////////////////// class WinStatsChartMenu { public: - WinStatsChartMenu(PStatMonitor *monitor, int thread_index); + WinStatsChartMenu(WinStatsMonitor *monitor, int thread_index); ~WinStatsChartMenu(); HMENU get_menu_handle(); @@ -46,7 +46,7 @@ public: private: void add_view(HMENU parent_menu, const PStatViewLevel *view_level); - PStatMonitor *_monitor; + WinStatsMonitor *_monitor; int _thread_index; int _last_level_index; diff --git a/pandatool/src/win-stats/winStatsGraph.cxx b/pandatool/src/win-stats/winStatsGraph.cxx index 6ea1504531..1f0549853e 100644 --- a/pandatool/src/win-stats/winStatsGraph.cxx +++ b/pandatool/src/win-stats/winStatsGraph.cxx @@ -262,6 +262,10 @@ setup_bitmap(int xsize, int ysize) { _bitmap_dc = CreateCompatibleDC(hdc); _bitmap = CreateCompatibleBitmap(hdc, _bitmap_xsize, _bitmap_ysize); SelectObject(_bitmap_dc, _bitmap); + + RECT rect = { 0, 0, _bitmap_xsize, _bitmap_ysize }; + FillRect(_bitmap_dc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH)); + ReleaseDC(_window, hdc); } @@ -320,7 +324,7 @@ create_graph_window() { register_graph_window_class(application); string window_title = "graph"; - DWORD window_style = WS_CHILD; + DWORD window_style = WS_CHILD | WS_CLIPSIBLINGS; _graph_window = CreateWindow(_graph_window_class_name, window_title.c_str(), window_style, diff --git a/pandatool/src/win-stats/winStatsLabel.cxx b/pandatool/src/win-stats/winStatsLabel.cxx index e42cd7e884..6db09e5e66 100755 --- a/pandatool/src/win-stats/winStatsLabel.cxx +++ b/pandatool/src/win-stats/winStatsLabel.cxx @@ -186,7 +186,7 @@ create_window(HWND parent_window) { register_window_class(application); _window = - CreateWindow(_window_class_name, _text.c_str(), WS_CHILD, + CreateWindow(_window_class_name, _text.c_str(), WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_window, NULL, application, 0); if (!_window) { diff --git a/pandatool/src/win-stats/winStatsLabelStack.cxx b/pandatool/src/win-stats/winStatsLabelStack.cxx index daa057b196..f88720ddad 100755 --- a/pandatool/src/win-stats/winStatsLabelStack.cxx +++ b/pandatool/src/win-stats/winStatsLabelStack.cxx @@ -18,6 +18,7 @@ #include "winStatsLabelStack.h" #include "winStatsLabel.h" +#include "notify.h" bool WinStatsLabelStack::_window_class_registered = false; const char * const WinStatsLabelStack::_window_class_name = "stack"; @@ -211,7 +212,7 @@ create_window(HWND parent_window) { register_window_class(application); _window = - CreateWindow(_window_class_name, "label stack", WS_CHILD | WS_CLIPCHILDREN, + CreateWindow(_window_class_name, "label stack", WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 0, 0, parent_window, NULL, application, 0); if (!_window) { diff --git a/pandatool/src/win-stats/winStatsMonitor.I b/pandatool/src/win-stats/winStatsMonitor.I new file mode 100755 index 0000000000..439918031b --- /dev/null +++ b/pandatool/src/win-stats/winStatsMonitor.I @@ -0,0 +1,43 @@ +// Filename: winStatsMonitor.I +// Created by: drose (09Jan04) +// +//////////////////////////////////////////////////////////////////// +// +// 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 +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: WinStatsMonitor::MenuDef::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +WinStatsMonitor::MenuDef:: +MenuDef(int thread_index, int collector_index) : + _thread_index(thread_index), + _collector_index(collector_index) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: WinStatsMonitor::MenuDef::operator < +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +bool WinStatsMonitor::MenuDef:: +operator < (const MenuDef &other) const { + if (_thread_index != other._thread_index) { + return _thread_index < other._thread_index; + } + return _collector_index < other._collector_index; +} diff --git a/pandatool/src/win-stats/winStatsMonitor.cxx b/pandatool/src/win-stats/winStatsMonitor.cxx index 0d19a6e0d4..4ddef70ee3 100644 --- a/pandatool/src/win-stats/winStatsMonitor.cxx +++ b/pandatool/src/win-stats/winStatsMonitor.cxx @@ -168,6 +168,7 @@ new_thread(int thread_index) { WinStatsChartMenu *chart_menu = new WinStatsChartMenu(this, thread_index); chart_menu->add_to_menu_bar(_menu_bar); _chart_menus.push_back(chart_menu); + DrawMenuBar(_window); } //////////////////////////////////////////////////////////////////// @@ -245,6 +246,45 @@ get_window() const { return _window; } +//////////////////////////////////////////////////////////////////// +// Function: WinStatsMonitor::lookup_menu +// Access: Public +// Description: Returns the MenuDef properties associated with the +// indicated menu ID. This specifies what we expect to +// do when the given menu has been selected. +//////////////////////////////////////////////////////////////////// +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]; +} + +//////////////////////////////////////////////////////////////////// +// Function: WinStatsMonitor::get_menu_id +// Access: Public +// Description: Returns the menu ID that is reserved for the +// indicated MenuDef properties. If this is the first +// time these particular properties have been requested, +// a new menu ID is returned; otherwise, the existing +// menu ID is returned. +//////////////////////////////////////////////////////////////////// +int WinStatsMonitor:: +get_menu_id(const MenuDef &menu_def) { + MenuByDef::iterator mi; + mi = _menu_by_def.find(menu_def); + if (mi != _menu_by_def.end()) { + return (*mi).second; + } + + // Slot a new id. + int menu_id = (int)_menu_by_id.size(); + _menu_by_id.push_back(menu_def); + _menu_by_def[menu_def] = menu_id; + + return menu_id; +} + //////////////////////////////////////////////////////////////////// // Function: WinStatsMonitor::add_graph // Access: Private @@ -306,6 +346,7 @@ create_window() { SetWindowLongPtr(_window, 0, (LONG_PTR)this); ShowWindow(_window, SW_SHOWNORMAL); + ShowWindow(_window, SW_SHOWNORMAL); } //////////////////////////////////////////////////////////////////// @@ -369,6 +410,18 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { close(); break; + case WM_COMMAND: + if (HIWORD(wparam) <= 1) { + int menu_id = LOWORD(wparam); + const MenuDef &menu_def = lookup_menu(menu_id); + WinStatsStripChart *chart = + new WinStatsStripChart(this, get_view(menu_def._thread_index), + menu_def._collector_index); + add_graph(chart); + return 0; + } + break; + default: break; } diff --git a/pandatool/src/win-stats/winStatsMonitor.h b/pandatool/src/win-stats/winStatsMonitor.h index 220ad7de59..8a8c8cb165 100644 --- a/pandatool/src/win-stats/winStatsMonitor.h +++ b/pandatool/src/win-stats/winStatsMonitor.h @@ -25,6 +25,8 @@ #include "pStatMonitor.h" #include "pointerTo.h" #include "pset.h" +#include "pvector.h" +#include "pmap.h" #include @@ -37,6 +39,15 @@ class WinStatsChartMenu; //////////////////////////////////////////////////////////////////// class WinStatsMonitor : public PStatMonitor { public: + class MenuDef { + public: + INLINE MenuDef(int thread_index, int collector_index); + INLINE bool operator < (const MenuDef &other) const; + + int _thread_index; + int _collector_index; + }; + WinStatsMonitor(); virtual ~WinStatsMonitor(); @@ -54,6 +65,9 @@ public: virtual bool has_idle(); HWND get_window() const; + + const MenuDef &lookup_menu(int menu_id) const; + int get_menu_id(const MenuDef &menu_def); private: void add_graph(WinStatsGraph *graph); @@ -71,6 +85,11 @@ private: typedef pvector ChartMenus; ChartMenus _chart_menus; + typedef pvector MenuById; + typedef pmap MenuByDef; + MenuById _menu_by_id; + MenuByDef _menu_by_def; + HWND _window; HMENU _menu_bar; string _window_title; @@ -81,4 +100,6 @@ private: friend class WinStatsGraph; }; +#include "winStatsMonitor.I" + #endif diff --git a/pandatool/src/win-stats/winStatsStripChart.cxx b/pandatool/src/win-stats/winStatsStripChart.cxx index bb32653199..3311c0c2e7 100644 --- a/pandatool/src/win-stats/winStatsStripChart.cxx +++ b/pandatool/src/win-stats/winStatsStripChart.cxx @@ -38,7 +38,6 @@ WinStatsStripChart(WinStatsMonitor *monitor, PStatView &view, default_strip_chart_height), WinStatsGraph(monitor) { - cerr << "Constructing strip chart " << (void *)this << "\n"; _brush_origin = 0; create_window(); @@ -52,7 +51,6 @@ WinStatsStripChart(WinStatsMonitor *monitor, PStatView &view, //////////////////////////////////////////////////////////////////// WinStatsStripChart:: ~WinStatsStripChart() { - cerr << "Destructing strip chart " << (void *)this << "\n"; } //////////////////////////////////////////////////////////////////// @@ -235,7 +233,7 @@ draw_cursor(int x) { void WinStatsStripChart:: end_draw(int from_x, int to_x) { RECT rect = { - from_x, 0, to_x, get_ysize() + from_x, 0, to_x + 1, get_ysize() }; InvalidateRect(_graph_window, &rect, FALSE); } @@ -255,7 +253,7 @@ create_window() { register_window_class(application); string window_title = get_title_text(); - DWORD window_style = WS_CHILD | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW | WS_VISIBLE; + DWORD window_style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW | WS_VISIBLE; RECT win_rect = { 0, 0, @@ -279,6 +277,10 @@ create_window() { SetWindowLongPtr(_window, 0, (LONG_PTR)this); setup_label_stack(); + + // Ensure that the window is on top of the stack. + SetWindowPos(_window, HWND_TOP, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); } ////////////////////////////////////////////////////////////////////