Ver código fonte

show frame rate in menu

David Rose 20 anos atrás
pai
commit
945251b218

+ 2 - 2
pandatool/src/gtk-stats/gtkStatsChartMenu.cxx

@@ -60,7 +60,7 @@ get_menu_widget() {
 //  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(GtkWidget *menu_bar, int before_menu_id) {
+add_to_menu_bar(GtkWidget *menu_bar, int position) {
   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) {
@@ -74,7 +74,7 @@ add_to_menu_bar(GtkWidget *menu_bar, int before_menu_id) {
   gtk_widget_show(menu_item);
   gtk_widget_show(menu_item);
   gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), _menu);
   gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), _menu);
 
 
-  gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), menu_item);
+  gtk_menu_shell_insert(GTK_MENU_SHELL(menu_bar), menu_item, position);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 1 - 1
pandatool/src/gtk-stats/gtkStatsChartMenu.h

@@ -38,7 +38,7 @@ public:
   ~GtkStatsChartMenu();
   ~GtkStatsChartMenu();
 
 
   GtkWidget *get_menu_widget();
   GtkWidget *get_menu_widget();
-  void add_to_menu_bar(GtkWidget *menu_bar, int before_menu_id);
+  void add_to_menu_bar(GtkWidget *menu_bar, int position);
 
 
   void check_update();
   void check_update();
   void do_update();
   void do_update();

+ 20 - 23
pandatool/src/gtk-stats/gtkStatsMonitor.cxx

@@ -211,7 +211,8 @@ 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);
   GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
   GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
-  chart_menu->add_to_menu_bar(menu_bar, MI_frame_rate_label);
+  chart_menu->add_to_menu_bar(menu_bar, _next_chart_index);
+  ++_next_chart_index;
   _chart_menus.push_back(chart_menu);
   _chart_menus.push_back(chart_menu);
 }
 }
 
 
@@ -267,23 +268,15 @@ idle() {
     (*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();
   if (frame_rate != 0.0f) {
   if (frame_rate != 0.0f) {
     char buffer[128];
     char buffer[128];
     sprintf(buffer, "%0.1f ms / %0.1f Hz", 1000.0f / frame_rate, frame_rate);
     sprintf(buffer, "%0.1f ms / %0.1f Hz", 1000.0f / frame_rate, frame_rate);
-  
-    MENUITEMINFO mii;
-    memset(&mii, 0, sizeof(mii));
-    mii.cbSize = sizeof(mii);
-    mii.fMask = MIIM_STRING;
-    mii.dwTypeData = buffer;
-    SetMenuItemInfo(_menu_bar, MI_frame_rate_label, FALSE, &mii);
-    DrawMenuBar(_window);
+
+    gtk_label_set_text(GTK_LABEL(_frame_rate_label), buffer);
   }
   }
-  */
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -483,10 +476,14 @@ create_window() {
 				this);
 				this);
   gtk_window_add_accel_group(GTK_WINDOW(_window), accel_group);
   gtk_window_add_accel_group(GTK_WINDOW(_window), accel_group);
   GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
   GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
+  _next_chart_index = 2;
+
+  setup_frame_rate_label();
 
 
   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, _next_chart_index);
+    ++_next_chart_index;
   }
   }
 
 
   // Pack the menu into the window.
   // Pack the menu into the window.
@@ -543,17 +540,17 @@ window_destroy(GtkWidget *widget, gpointer data) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void GtkStatsMonitor::
 void GtkStatsMonitor::
 setup_frame_rate_label() {
 setup_frame_rate_label() {
-  /*
-  MENUITEMINFO mii;
-  memset(&mii, 0, sizeof(mii));
-  mii.cbSize = sizeof(mii);
-
-  mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID;
-  mii.fType = MFT_STRING | MFT_RIGHTJUSTIFY; 
-  mii.wID = MI_frame_rate_label;
-  mii.dwTypeData = ""; 
-  InsertMenuItem(_menu_bar, GetMenuItemCount(_menu_bar), TRUE, &mii);
-  */
+  GtkWidget *menu_bar = gtk_item_factory_get_widget(_item_factory, "<PStats>");
+
+  _frame_rate_menu_item = gtk_menu_item_new();
+  _frame_rate_label = gtk_label_new("");
+  gtk_container_add(GTK_CONTAINER(_frame_rate_menu_item), _frame_rate_label);
+
+  gtk_widget_show(_frame_rate_menu_item);
+  gtk_widget_show(_frame_rate_label);
+  gtk_menu_item_right_justify(GTK_MENU_ITEM(_frame_rate_menu_item));
+
+  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), _frame_rate_menu_item);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 3 - 0
pandatool/src/gtk-stats/gtkStatsMonitor.h

@@ -102,6 +102,9 @@ private:
 
 
   GtkWidget *_window;
   GtkWidget *_window;
   GtkItemFactory *_item_factory;
   GtkItemFactory *_item_factory;
+  int _next_chart_index;
+  GtkWidget *_frame_rate_menu_item;
+  GtkWidget *_frame_rate_label;
   string _window_title;
   string _window_title;
   int _time_units;
   int _time_units;
   float _scroll_speed;
   float _scroll_speed;