Browse Source

smooth box, frame total

David Rose 20 years ago
parent
commit
59bdb24719

+ 16 - 17
pandatool/src/gtk-stats/gtkStatsChartMenu.cxx

@@ -124,11 +124,9 @@ 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.fType = MFT_SEPARATOR; 
-        InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii);
-	*/
+	GtkWidget *sep = gtk_separator_menu_item_new();
+	gtk_widget_show(sep);
+	gtk_menu_shell_append(GTK_MENU_SHELL(_menu), sep);
 
 
         needs_separator = false;
         needs_separator = false;
       }
       }
@@ -140,18 +138,19 @@ 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.fType = MFT_SEPARATOR; 
-  InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii);
-
-  GtkStatsMonitor::MenuDef menu_def(_thread_index, -1, false);
-  int menu_id = _monitor->get_menu_id(menu_def);
-
-  mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID; 
-  mii.fType = MFT_STRING; 
-  mii.wID = menu_id;
-  mii.dwTypeData = "Piano Roll";
-  InsertMenuItem(_menu, GetMenuItemCount(_menu), TRUE, &mii);
+  GtkWidget *sep = gtk_separator_menu_item_new();
+  gtk_widget_show(sep);
+  gtk_menu_shell_append(GTK_MENU_SHELL(_menu), sep);
+  
+  GtkStatsMonitor::MenuDef smd(_thread_index, -1, false);
+  const GtkStatsMonitor::MenuDef *menu_def = _monitor->add_menu(smd);
+
+  GtkWidget *menu_item = gtk_menu_item_new_with_label("Piano Roll");
+  gtk_widget_show(menu_item);
+  gtk_menu_shell_append(GTK_MENU_SHELL(_menu), menu_item);
+
+  g_signal_connect_swapped(G_OBJECT(menu_item), "activate", 
+			   G_CALLBACK(handle_menu), (void *)(const void *)menu_def);
   */
   */
 }
 }
 
 

+ 7 - 1
pandatool/src/gtk-stats/gtkStatsGraph.cxx

@@ -100,10 +100,16 @@ GtkStatsGraph(GtkStatsMonitor *monitor, int thread_index) :
   gtk_frame_set_shadow_type(GTK_FRAME(graph_frame), GTK_SHADOW_IN);
   gtk_frame_set_shadow_type(GTK_FRAME(graph_frame), GTK_SHADOW_IN);
   gtk_container_add(GTK_CONTAINER(graph_frame), _graph_window);
   gtk_container_add(GTK_CONTAINER(graph_frame), _graph_window);
 
 
+  // A VBox to hold the graph's frame, and any numbers (scale legend?
+  // total?) above it.
+  _graph_vbox = gtk_vbox_new(FALSE, 0);
+  gtk_box_pack_end(GTK_BOX(_graph_vbox), graph_frame,
+		   TRUE, TRUE, 0);
+
   // An HBox to hold the graph's frame, and the scale legend to the
   // An HBox to hold the graph's frame, and the scale legend to the
   // right of it.
   // right of it.
   _graph_hbox = gtk_hbox_new(FALSE, 0);
   _graph_hbox = gtk_hbox_new(FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(_graph_hbox), graph_frame,
+  gtk_box_pack_start(GTK_BOX(_graph_hbox), _graph_vbox,
 		     TRUE, TRUE, 0);
 		     TRUE, TRUE, 0);
 
 
   // An HPaned to hold the label stack and the graph hbox.
   // An HPaned to hold the label stack and the graph hbox.

+ 1 - 0
pandatool/src/gtk-stats/gtkStatsGraph.h

@@ -86,6 +86,7 @@ protected:
   GtkWidget *_window;
   GtkWidget *_window;
   GtkWidget *_graph_window;
   GtkWidget *_graph_window;
   GtkWidget *_graph_hbox;
   GtkWidget *_graph_hbox;
+  GtkWidget *_graph_vbox;
   GtkWidget *_hpaned;
   GtkWidget *_hpaned;
   GtkWidget *_scale_area;
   GtkWidget *_scale_area;
   GtkStatsLabelStack _label_stack;
   GtkStatsLabelStack _label_stack;

+ 48 - 26
pandatool/src/gtk-stats/gtkStatsStripChart.cxx

@@ -54,9 +54,23 @@ GtkStatsStripChart(GtkStatsMonitor *monitor, int thread_index,
     set_guide_bar_units(get_guide_bar_units() | GBU_show_units);
     set_guide_bar_units(get_guide_bar_units() | GBU_show_units);
   }
   }
 
 
-  _smooth_check_box = 0;
+  // Put some stuff on top of the graph.
+  _top_hbox = gtk_hbox_new(FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(_graph_vbox), _top_hbox,
+		     FALSE, FALSE, 0);
+
+  _smooth_check_box = gtk_check_button_new_with_label("Smooth");
+  g_signal_connect(G_OBJECT(_smooth_check_box), "toggled",  
+		   G_CALLBACK(toggled_callback), this);
+
+  _total_label = gtk_label_new("");
+  gtk_box_pack_start(GTK_BOX(_top_hbox), _smooth_check_box,
+		     FALSE, FALSE, 0);
+  gtk_box_pack_end(GTK_BOX(_top_hbox), _total_label,
+		   FALSE, FALSE, 0);
 
 
-  // Add a DrawingArea widget to display all of the scale units.
+  // Add a DrawingArea widget to the right of the graph, to display
+  // all of the scale units.
   _scale_area = gtk_drawing_area_new();
   _scale_area = gtk_drawing_area_new();
   g_signal_connect(G_OBJECT(_scale_area), "expose_event",  
   g_signal_connect(G_OBJECT(_scale_area), "expose_event",  
 		   G_CALLBACK(expose_event_callback), this);
 		   G_CALLBACK(expose_event_callback), this);
@@ -119,16 +133,11 @@ new_data(int thread_index, int frame_number) {
   if (!_pause) {
   if (!_pause) {
     update();
     update();
 
 
-    /*
     string text = format_number(get_average_net_value(), get_guide_bar_units(), get_guide_bar_unit_name());
     string text = format_number(get_average_net_value(), get_guide_bar_units(), get_guide_bar_unit_name());
     if (_net_value_text != text) {
     if (_net_value_text != text) {
       _net_value_text = text;
       _net_value_text = text;
-      RECT rect;
-      GetClientRect(_window, &rect);
-      rect.bottom = _top_margin;
-      InvalidateRect(_window, &rect, TRUE);
+      gtk_label_set_text(GTK_LABEL(_total_label), _net_value_text.c_str());
     }
     }
-    */
   }
   }
 }
 }
 
 
@@ -437,10 +446,9 @@ set_drag_mode(GtkStatsGraph::DragMode drag_mode) {
   default:
   default:
     // Restore smoothing according to the current setting of the check
     // Restore smoothing according to the current setting of the check
     // box.
     // box.
-    /*
-    int result = SendMessage(_smooth_check_box, BM_GETCHECK, 0, 0);
-    set_average_mode(result == BST_CHECKED);
-    */
+    bool active = 
+      gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(_smooth_check_box));
+    set_average_mode(active);
     break;
     break;
   }
   }
 }
 }
@@ -658,26 +666,40 @@ draw_guide_label(const PStatGraph::GuideBar &bar, int last_y) {
     }
     }
   }
   }
 
 
-  // Now convert our y to a coordinate within our drawing area.
-  int junk_x;
-
-  // The y coordinate comes from the graph_window.
-  gtk_widget_translate_coordinates(_graph_window, _scale_area,
-				   0, y,
-				   &junk_x, &y);
-
-  int this_y = y - height / 2;
-  if (y >= 0 && y <= _scale_area->allocation.height &&
-      (last_y < this_y || last_y > this_y + height)) {
-    gdk_draw_layout(_scale_area->window, gc, 0, this_y, layout);
-    last_y = this_y;
+  if (y >= 0 && y < get_ysize()) {
+    // Now convert our y to a coordinate within our drawing area.
+    int junk_x;
+    
+    // The y coordinate comes from the graph_window.
+    gtk_widget_translate_coordinates(_graph_window, _scale_area,
+				     0, y,
+				     &junk_x, &y);
+    
+    int this_y = y - height / 2;
+    if (last_y < this_y || last_y > this_y + height) {
+      gdk_draw_layout(_scale_area->window, gc, 0, this_y, layout);
+      last_y = this_y;
+    }
   }
   }
-
+    
   g_object_unref(layout);
   g_object_unref(layout);
   g_object_unref(gc);
   g_object_unref(gc);
   return last_y;
   return last_y;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: GtkStatsStripChart::toggled_callback
+//       Access: Private, Static
+//  Description: Called when the smooth check box is toggled.
+////////////////////////////////////////////////////////////////////
+void GtkStatsStripChart::
+toggled_callback(GtkToggleButton *button, gpointer data) {
+  GtkStatsStripChart *self = (GtkStatsStripChart *)data;
+
+  bool active = gtk_toggle_button_get_active(button);
+  self->set_average_mode(active);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GtkStatsStripChart::expose_event_callback
 //     Function: GtkStatsStripChart::expose_event_callback
 //       Access: Private, Static
 //       Access: Private, Static

+ 4 - 1
pandatool/src/gtk-stats/gtkStatsStripChart.h

@@ -74,7 +74,8 @@ private:
 		      const PStatGraph::GuideBar &bar);
 		      const PStatGraph::GuideBar &bar);
   void draw_guide_labels();
   void draw_guide_labels();
   int draw_guide_label(const PStatGraph::GuideBar &bar, int last_y);
   int draw_guide_label(const PStatGraph::GuideBar &bar, int last_y);
-  
+
+  static void toggled_callback(GtkToggleButton *button, gpointer data);  
   static gboolean expose_event_callback(GtkWidget *widget, 
   static gboolean expose_event_callback(GtkWidget *widget, 
 					GdkEventExpose *event, gpointer data);
 					GdkEventExpose *event, gpointer data);
 
 
@@ -83,7 +84,9 @@ private:
   int _brush_origin;
   int _brush_origin;
   string _net_value_text;
   string _net_value_text;
 
 
+  GtkWidget *_top_hbox;
   GtkWidget *_smooth_check_box;
   GtkWidget *_smooth_check_box;
+  GtkWidget *_total_label;
 
 
   static bool _window_class_registered;
   static bool _window_class_registered;
   static const char * const _window_class_name;
   static const char * const _window_class_name;