Graphs menu

This commit is contained in:
David Rose 2006-01-18 01:10:44 +00:00
parent f5736f4853
commit 2f0857570c
7 changed files with 111 additions and 114 deletions

View File

@ -14,6 +14,7 @@
#define SOURCES \ #define SOURCES \
gtkStats.cxx \ gtkStats.cxx \
gtkStatsChartMenu.cxx gtkStatsChartMenu.h \
gtkStatsGraph.cxx gtkStatsGraph.h \ gtkStatsGraph.cxx gtkStatsGraph.h \
gtkStatsLabel.cxx gtkStatsLabel.h \ gtkStatsLabel.cxx gtkStatsLabel.h \
gtkStatsLabelStack.cxx gtkStatsLabelStack.h \ gtkStatsLabelStack.cxx gtkStatsLabelStack.h \
@ -22,7 +23,6 @@
gtkStatsServer.cxx gtkStatsServer.h \ gtkStatsServer.cxx gtkStatsServer.h \
gtkStatsStripChart.cxx gtkStatsStripChart.h gtkStatsStripChart.cxx gtkStatsStripChart.h
// gtkStatsChartMenu.cxx gtkStatsChartMenu.h \
// gtkStatsPianoRoll.cxx gtkStatsPianoRoll.h \ // gtkStatsPianoRoll.cxx gtkStatsPianoRoll.h \
#if $[DEVELOP_GTKSTATS] #if $[DEVELOP_GTKSTATS]

View File

@ -39,8 +39,19 @@ destroy(GtkWidget *widget, gpointer data) {
static gboolean static gboolean
timer(gpointer data) { timer(gpointer data) {
static int count = 0;
server->poll(); server->poll();
if (++count == 5) {
count = 0;
// Every once in a while, say once a second, we call this
// function, which should force gdk to make all changes visible.
// We do this in case we are getting starved and falling behind,
// so that the user still gets a chance to see *something* happen
// onscreen, even if it's just increasingly old data.
gdk_window_process_all_updates();
}
return TRUE; return TRUE;
} }

View File

@ -29,7 +29,8 @@ GtkStatsChartMenu(GtkStatsMonitor *monitor, int thread_index) :
_monitor(monitor), _monitor(monitor),
_thread_index(thread_index) _thread_index(thread_index)
{ {
_menu = CreatePopupMenu(); _menu = gtk_menu_new();
gtk_widget_show(_menu);
do_update(); do_update();
} }
@ -43,13 +44,13 @@ GtkStatsChartMenu::
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GtkStatsChartMenu::get_menu_handle // Function: GtkStatsChartMenu::get_menu_widget
// Access: Public // Access: Public
// Description: Returns the Windows menu handle for this particular // Description: Returns the gtk widget for this particular
// menu. // menu.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
HMENU GtkStatsChartMenu:: GtkWidget *GtkStatsChartMenu::
get_menu_handle() { get_menu_widget() {
return _menu; return _menu;
} }
@ -59,7 +60,7 @@ get_menu_handle() {
// Description: Adds the menu to the end of the indicated menu bar. // Description: Adds the menu to the end of the indicated menu bar.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void GtkStatsChartMenu:: void GtkStatsChartMenu::
add_to_menu_bar(HMENU menu_bar, int before_menu_id) { add_to_menu_bar(GtkWidget *menu_bar, int before_menu_id) {
const PStatClientData *client_data = _monitor->get_client_data(); const PStatClientData *client_data = _monitor->get_client_data();
string thread_name; string thread_name;
if (_thread_index == 0) { if (_thread_index == 0) {
@ -69,15 +70,11 @@ add_to_menu_bar(HMENU menu_bar, int before_menu_id) {
thread_name = client_data->get_thread_name(_thread_index); thread_name = client_data->get_thread_name(_thread_index);
} }
MENUITEMINFO mii; GtkWidget *menu_item = gtk_menu_item_new_with_label(thread_name.c_str());
memset(&mii, 0, sizeof(mii)); gtk_widget_show(menu_item);
mii.cbSize = sizeof(mii); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), _menu);
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU; gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), menu_item);
mii.fType = MFT_STRING;
mii.hSubMenu = _menu;
mii.dwTypeData = (char *)thread_name.c_str();
InsertMenuItem(menu_bar, before_menu_id, FALSE, &mii);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -107,10 +104,7 @@ do_update() {
_last_level_index = view.get_level_index(); _last_level_index = view.get_level_index();
// First, remove all of the old entries from the menu. // First, remove all of the old entries from the menu.
int num_items = GetMenuItemCount(_menu); gtk_container_foreach(GTK_CONTAINER(_menu), remove_menu_child, _menu);
for (int i = num_items - 1; i >= 0; i--) {
DeleteMenu(_menu, i, MF_BYPOSITION);
}
// Now rebuild the menu with the new set of entries. // Now rebuild the menu with the new set of entries.
@ -118,9 +112,6 @@ do_update() {
add_view(_menu, view.get_top_level(), false); add_view(_menu, view.get_top_level(), false);
bool needs_separator = true; bool needs_separator = true;
MENUITEMINFO mii;
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii);
// And then the menu item(s) for each of the level values. // And then the menu item(s) for each of the level values.
const PStatClientData *client_data = _monitor->get_client_data(); const PStatClientData *client_data = _monitor->get_client_data();
@ -133,9 +124,11 @@ do_update() {
// We put a separator between the above frame collector and the // We put a separator between the above frame collector and the
// first level collector. // first level collector.
if (needs_separator) { if (needs_separator) {
/*
mii.fMask = MIIM_FTYPE; mii.fMask = MIIM_FTYPE;
mii.fType = MFT_SEPARATOR; mii.fType = MFT_SEPARATOR;
InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii); InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii);
*/
needs_separator = false; needs_separator = false;
} }
@ -145,6 +138,7 @@ do_update() {
} }
} }
/*
// Also a menu item for a piano roll (following a separator). // Also a menu item for a piano roll (following a separator).
mii.fMask = MIIM_FTYPE; mii.fMask = MIIM_FTYPE;
mii.fType = MFT_SEPARATOR; mii.fType = MFT_SEPARATOR;
@ -158,6 +152,7 @@ do_update() {
mii.wID = menu_id; mii.wID = menu_id;
mii.dwTypeData = "Piano Roll"; mii.dwTypeData = "Piano Roll";
InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii); InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii);
*/
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -167,37 +162,36 @@ do_update() {
// indicated view and its children. // indicated view and its children.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void GtkStatsChartMenu:: void GtkStatsChartMenu::
add_view(HMENU parent_menu, const PStatViewLevel *view_level, bool show_level) { add_view(GtkWidget *parent_menu, const PStatViewLevel *view_level,
bool show_level) {
int collector = view_level->get_collector(); int collector = view_level->get_collector();
const PStatClientData *client_data = _monitor->get_client_data(); const PStatClientData *client_data = _monitor->get_client_data();
string collector_name = client_data->get_collector_name(collector); string collector_name = client_data->get_collector_name(collector);
GtkStatsMonitor::MenuDef menu_def(_thread_index, collector, show_level); GtkStatsMonitor::MenuDef smd(_thread_index, collector, show_level);
int menu_id = _monitor->get_menu_id(menu_def); const GtkStatsMonitor::MenuDef *menu_def = _monitor->add_menu(smd);
MENUITEMINFO mii; GtkWidget *menu_item = gtk_menu_item_new_with_label(collector_name.c_str());
memset(&mii, 0, sizeof(mii)); gtk_widget_show(menu_item);
mii.cbSize = sizeof(mii); gtk_menu_shell_append(GTK_MENU_SHELL(parent_menu), menu_item);
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID; g_signal_connect_swapped(G_OBJECT(menu_item), "activate",
mii.fType = MFT_STRING; G_CALLBACK(handle_menu), (void *)(const void *)menu_def);
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(); int num_children = view_level->get_num_children();
if (num_children > 1) { if (num_children > 1) {
// If the collector has more than one child, add a menu entry to go // If the collector has more than one child, add a menu entry to go
// directly to each of its children. // directly to each of its children.
HMENU submenu = CreatePopupMenu();
string submenu_name = collector_name + " components"; string submenu_name = collector_name + " components";
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU; GtkWidget *submenu_item = gtk_menu_item_new_with_label(submenu_name.c_str());
mii.fType = MFT_STRING; gtk_widget_show(submenu_item);
mii.hSubMenu = submenu; gtk_menu_shell_append(GTK_MENU_SHELL(parent_menu), submenu_item);
mii.dwTypeData = (char *)submenu_name.c_str();
InsertMenuItem(parent_menu, GetMenuItemCount(parent_menu), TRUE, &mii); GtkWidget *submenu = gtk_menu_new();
gtk_widget_show(submenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenu_item), submenu);
// Reverse the order since the menus are listed from the top down; // Reverse the order since the menus are listed from the top down;
// we want to be visually consistent with the graphs, which list // we want to be visually consistent with the graphs, which list
@ -207,3 +201,37 @@ add_view(HMENU parent_menu, const PStatViewLevel *view_level, bool show_level) {
} }
} }
} }
////////////////////////////////////////////////////////////////////
// Function: GtkStatsChartMenu::handle_menu
// Access: Private, Static
// Description: Callback when a menu item is selected.
////////////////////////////////////////////////////////////////////
void GtkStatsChartMenu::
handle_menu(gpointer data) {
const GtkStatsMonitor::MenuDef *menu_def = (GtkStatsMonitor::MenuDef *)data;
GtkStatsMonitor *monitor = menu_def->_monitor;
if (monitor == NULL) {
return;
}
if (menu_def->_collector_index < 0) {
monitor->open_piano_roll(menu_def->_thread_index);
} else {
monitor->open_strip_chart(menu_def->_thread_index,
menu_def->_collector_index,
menu_def->_show_level);
}
}
////////////////////////////////////////////////////////////////////
// Function: GtkStatsChartMenu::remove_menu_child
// Access: Private, Static
// Description: Removes a previous menu child from the menu.
////////////////////////////////////////////////////////////////////
void GtkStatsChartMenu::
remove_menu_child(GtkWidget *widget, gpointer data) {
GtkWidget *menu = (GtkWidget *)data;
gtk_container_remove(GTK_CONTAINER(menu), widget);
}

View File

@ -21,7 +21,7 @@
#include "pandatoolbase.h" #include "pandatoolbase.h"
#include <windows.h> #include <gtk/gtk.h>
class GtkStatsMonitor; class GtkStatsMonitor;
class PStatView; class PStatView;
@ -37,21 +37,24 @@ public:
GtkStatsChartMenu(GtkStatsMonitor *monitor, int thread_index); GtkStatsChartMenu(GtkStatsMonitor *monitor, int thread_index);
~GtkStatsChartMenu(); ~GtkStatsChartMenu();
HMENU get_menu_handle(); GtkWidget *get_menu_widget();
void add_to_menu_bar(HMENU menu_bar, int before_menu_id); void add_to_menu_bar(GtkWidget *menu_bar, int before_menu_id);
void check_update(); void check_update();
void do_update(); void do_update();
private: private:
void add_view(HMENU parent_menu, const PStatViewLevel *view_level, void add_view(GtkWidget *parent_menu, const PStatViewLevel *view_level,
bool show_level); bool show_level);
static void handle_menu(gpointer data);
static void remove_menu_child(GtkWidget *widget, gpointer data);
GtkStatsMonitor *_monitor; GtkStatsMonitor *_monitor;
int _thread_index; int _thread_index;
int _last_level_index; int _last_level_index;
HMENU _menu; GtkWidget *_menu;
}; };
#endif #endif

View File

@ -26,7 +26,8 @@ GtkStatsMonitor::MenuDef::
MenuDef(int thread_index, int collector_index, bool show_level) : MenuDef(int thread_index, int collector_index, bool show_level) :
_thread_index(thread_index), _thread_index(thread_index),
_collector_index(collector_index), _collector_index(collector_index),
_show_level(show_level) _show_level(show_level),
_monitor(NULL)
{ {
} }

View File

@ -20,10 +20,8 @@
#include "gtkStats.h" #include "gtkStats.h"
#include "gtkStatsServer.h" #include "gtkStatsServer.h"
#include "gtkStatsStripChart.h" #include "gtkStatsStripChart.h"
/*
#include "gtkStatsPianoRoll.h"
#include "gtkStatsChartMenu.h" #include "gtkStatsChartMenu.h"
*/ //#include "gtkStatsPianoRoll.h"
#include "gtkStatsMenuId.h" #include "gtkStatsMenuId.h"
#include "pStatGraph.h" #include "pStatGraph.h"
#include "pStatCollectorDef.h" #include "pStatCollectorDef.h"
@ -77,13 +75,11 @@ GtkStatsMonitor::
} }
_graphs.clear(); _graphs.clear();
/*
ChartMenus::iterator mi; ChartMenus::iterator mi;
for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) { for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
delete (*mi); delete (*mi);
} }
_chart_menus.clear(); _chart_menus.clear();
*/
if (_window != NULL) { if (_window != NULL) {
gtk_widget_destroy(_window); gtk_widget_destroy(_window);
@ -193,13 +189,11 @@ new_collector(int collector_index) {
graph->new_collector(collector_index); graph->new_collector(collector_index);
} }
/*
// We might need to update our menus. // We might need to update our menus.
ChartMenus::iterator mi; ChartMenus::iterator mi;
for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) { for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
(*mi)->do_update(); (*mi)->do_update();
} }
*/
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -215,12 +209,10 @@ new_collector(int collector_index) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void GtkStatsMonitor:: void GtkStatsMonitor::
new_thread(int thread_index) { new_thread(int thread_index) {
/*
GtkStatsChartMenu *chart_menu = new GtkStatsChartMenu(this, thread_index); GtkStatsChartMenu *chart_menu = new GtkStatsChartMenu(this, thread_index);
chart_menu->add_to_menu_bar(_menu_bar, MI_frame_rate_label); GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
chart_menu->add_to_menu_bar(menu_bar, MI_frame_rate_label);
_chart_menus.push_back(chart_menu); _chart_menus.push_back(chart_menu);
DrawMenuBar(_window);
*/
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -269,13 +261,13 @@ lost_connection() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void GtkStatsMonitor:: void GtkStatsMonitor::
idle() { idle() {
/*
// Check if any of our chart menus need updating. // Check if any of our chart menus need updating.
ChartMenus::iterator mi; ChartMenus::iterator mi;
for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) { for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
(*mi)->check_update(); (*mi)->check_update();
} }
/*
// Update the frame rate label from the main thread (thread 0). // Update the frame rate label from the main thread (thread 0).
const PStatThreadData *thread_data = get_client_data()->get_thread_data(0); const PStatThreadData *thread_data = get_client_data()->get_thread_data(0);
float frame_rate = thread_data->get_frame_rate(); float frame_rate = thread_data->get_frame_rate();
@ -363,43 +355,21 @@ open_piano_roll(int thread_index) {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: GtkStatsMonitor::lookup_menu // Function: GtkStatsMonitor::add_menu
// Access: Public // Access: Public
// Description: Returns the MenuDef properties associated with the // Description: Adds a new MenuDef to the monitor, or returns an
// indicated menu ID. This specifies what we expect to // existing one if there is already one just like it.
// do when the given menu has been selected.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
const GtkStatsMonitor::MenuDef &GtkStatsMonitor:: const GtkStatsMonitor::MenuDef *GtkStatsMonitor::
lookup_menu(int menu_id) const { add_menu(const MenuDef &menu_def) {
static MenuDef invalid(0, 0, false); pair<Menus::iterator, bool> result = _menus.insert(menu_def);
int menu_index = menu_id - MI_new_chart; Menus::iterator mi = result.first;
nassertr(menu_index >= 0 && menu_index < (int)_menu_by_id.size(), invalid); const GtkStatsMonitor::MenuDef &new_menu_def = (*mi);
return _menu_by_id[menu_index]; if (result.second) {
} // A new MenuDef was inserted.
((GtkStatsMonitor::MenuDef &)new_menu_def)._monitor = this;
////////////////////////////////////////////////////////////////////
// Function: GtkStatsMonitor::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 GtkStatsMonitor::
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;
} }
return &new_menu_def;
// Slot a new id.
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;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -514,19 +484,17 @@ create_window() {
gtk_item_factory_create_items(_item_factory, num_menu_entries, menu_entries, gtk_item_factory_create_items(_item_factory, num_menu_entries, menu_entries,
this); this);
gtk_window_add_accel_group(GTK_WINDOW(_window), accel_group); gtk_window_add_accel_group(GTK_WINDOW(_window), accel_group);
GtkWidget *menubar = gtk_item_factory_get_widget(_item_factory, "<PStats>"); GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
/*
ChartMenus::iterator mi; ChartMenus::iterator mi;
for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) { for (mi = _chart_menus.begin(); mi != _chart_menus.end(); ++mi) {
(*mi)->add_to_menu_bar(_menu_bar, MI_frame_rate_label); (*mi)->add_to_menu_bar(menu_bar, MI_frame_rate_label);
} }
*/
// Pack the menu into the window. // Pack the menu into the window.
GtkWidget *main_vbox = gtk_vbox_new(FALSE, 1); GtkWidget *main_vbox = gtk_vbox_new(FALSE, 1);
gtk_container_add(GTK_CONTAINER(_window), main_vbox); gtk_container_add(GTK_CONTAINER(_window), main_vbox);
gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(_item_factory, "/Speed/3")), gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(_item_factory, "/Speed/3")),
TRUE); TRUE);
@ -633,17 +601,5 @@ handle_menu_command(gpointer callback_data, guint menu_id, GtkWidget *widget) {
case MI_pause: case MI_pause:
self->set_pause(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))); self->set_pause(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)));
break; break;
default:
if (menu_id >= MI_new_chart) {
const MenuDef &menu_def = self->lookup_menu(menu_id);
if (menu_def._collector_index < 0) {
self->open_piano_roll(menu_def._thread_index);
} else {
self->open_strip_chart(menu_def._thread_index,
menu_def._collector_index,
menu_def._show_level);
}
}
} }
} }

View File

@ -48,6 +48,7 @@ public:
int _thread_index; int _thread_index;
int _collector_index; int _collector_index;
bool _show_level; bool _show_level;
GtkStatsMonitor *_monitor;
}; };
GtkStatsMonitor(GtkStatsServer *server); GtkStatsMonitor(GtkStatsServer *server);
@ -72,8 +73,7 @@ public:
void open_strip_chart(int thread_index, int collector_index, bool show_level); void open_strip_chart(int thread_index, int collector_index, bool show_level);
void open_piano_roll(int thread_index); void open_piano_roll(int thread_index);
const MenuDef &lookup_menu(int menu_id) const; const MenuDef *add_menu(const MenuDef &menu_def);
int get_menu_id(const MenuDef &menu_def);
void set_time_units(int unit_mask); void set_time_units(int unit_mask);
void set_scroll_speed(float scroll_speed); void set_scroll_speed(float scroll_speed);
@ -97,10 +97,8 @@ private:
typedef pvector<GtkStatsChartMenu *> ChartMenus; typedef pvector<GtkStatsChartMenu *> ChartMenus;
ChartMenus _chart_menus; ChartMenus _chart_menus;
typedef pvector<MenuDef> MenuById; typedef pset<MenuDef> Menus;
typedef pmap<MenuDef, int> MenuByDef; Menus _menus;
MenuById _menu_by_id;
MenuByDef _menu_by_def;
GtkWidget *_window; GtkWidget *_window;
GtkItemFactory *_item_factory; GtkItemFactory *_item_factory;