Re: [GnomeMeeting-devel-list] small bug in stats_drawing_area



Am Mittwoch, 6. April 2005 13:09 schrieb Damien Sandras:
> Hi Stefan,
>
> The stats_drawing_area doesn't apply to the OPAL branch, if you look
> more carefully, the API has changed so that the computation is not done
> in the widget code (which was not very portable if somebody wanted to
> reuse the code).
>
> Can you regenerate a patch with the new API for the OPAL branch?
>
> Thanks,

Ok, recreated the patch. It is not tested, but comparing the 1.2.1 and the 
OPAL patch, they only differ in the patch contexts and line numbers, so the 
patch should be ok and apply cleanly.

The patch for main_window.cpp and endpoint.cpp from my first posting has to be 
applied, too.

Greetings,

Stefan

-- 
Stefan Brüns  /  Kastanienweg 6 - Zimmer 1206  /  52074 Aachen
mailto:lurch gmx li  http://www.kawo1.rwth-aachen.de/~lurchi/
   phone: +49 241 169-4206     mobile: +49 160 3797725
--- stats_drawing_area.c_orig	2005-04-06 17:22:56.884073886 +0200
+++ stats_drawing_area.c	2005-04-06 18:16:05.327512171 +0200
@@ -51,11 +51,13 @@
   GdkGC *gc;
   GdkColormap *colormap;
   GdkColor colors [6];
+  GdkSegment* grid;
+  int numGridLines;
 
-  float transmitted_audio_speeds[100];
-  float received_audio_speeds[100];
-  float transmitted_video_speeds[100];
-  float received_video_speeds[100];
+  float transmitted_audio_speeds[50];
+  float received_audio_speeds[50];
+  float transmitted_video_speeds[50];
+  float received_video_speeds[50];
   int position;
 };
 
@@ -86,6 +88,12 @@
 static gboolean stats_drawing_area_exposed_cb (GtkWidget *,
 					       GdkEventExpose *,
 					       gpointer);
+/* DESCRIPTION  :
+ * PRE          :
+ */
+static void stats_drawing_area_size_allocate (GtkWidget *,
+					      GtkAllocation *);
+
 
 
 /* helper functions' implementation */
@@ -140,6 +148,9 @@
   self->pango_layout = pango_layout_new (self->pango_context);
   self->gc = NULL;
 
+  self->grid = NULL;
+  self->numGridLines = 0;
+
   g_signal_connect (G_OBJECT (self), "expose_event",
 		    G_CALLBACK (stats_drawing_area_exposed_cb), 
 		    NULL);
@@ -151,8 +162,10 @@
 stats_drawing_area_class_init (StatsDrawingAreaClass *klass)
 {
   GObjectClass *gobject_klass = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
 
   gobject_klass->finalize = stats_drawing_area_finalize;
+  widget_class->size_allocate = stats_drawing_area_size_allocate;
 }
 
 static void
@@ -163,7 +176,7 @@
   g_return_if_fail (self != NULL);
 
   self->position = 0;
-  for (i = 0; i < 100; i++) {
+  for (i = 0; i < 50; i++) {
     
     self->transmitted_audio_speeds [i] = (float) 0;
     self->received_audio_speeds [i] = (float) 0;
@@ -180,10 +193,6 @@
 {
   StatsDrawingArea *self = NULL;
   
-  GdkSegment s [50];
-  
-  int x = 0;
-  int y = 0;
   int cpt = 0;
   int pos = 0;
   
@@ -194,12 +203,9 @@
   
   float height_step = 0;
 
-  float max_transmitted_video = 1;
-  float max_transmitted_audio = 1;
-  float max_received_video = 1;
-  float max_received_audio = 1;
+  float max_speed = 1;
 
-  gboolean success [256];
+  gboolean success [6];
 
   g_return_val_if_fail (IS_STATS_DRAWING_AREA (widget), FALSE);
 
@@ -217,10 +223,7 @@
   allocation_height = GTK_WIDGET (widget)->allocation.height;
 
   width_step = (int) GTK_WIDGET (widget)->allocation.width / 40;
-  height_step = allocation_height;
 
-  x = width_step;
-  
   gdk_gc_set_foreground (self->gc, &self->colors [0]);
   gdk_draw_rectangle (widget->window,
 		      self->gc,
@@ -232,57 +235,24 @@
   gdk_gc_set_line_attributes (self->gc, 1, GDK_LINE_SOLID, 
 			      GDK_CAP_ROUND, GDK_JOIN_BEVEL);
   
-  while ( y < allocation_height
-	  && cpt < 50) {
-
-    s [cpt].x1 = 0;
-    s [cpt].x2 = widget->allocation.width;
-    s [cpt].y1 = y;
-    s [cpt].y2 = y;
-      
-    y = y + 21;
-    cpt++;
-  }
- 
-  gdk_draw_segments (GDK_DRAWABLE (widget->window), self->gc, s, cpt);
-
-  cpt = 0;
-  while (x < widget->allocation.width && cpt < 50) {
-
-    s [cpt].x1 = x;
-    s [cpt].x2 = x;
-    s [cpt].y1 = 0;
-    s [cpt].y2 = widget->allocation.height;
-      
-    x = x + 21;
-    cpt++;
-  }
- 
-  gdk_draw_segments (GDK_DRAWABLE (widget->window), self->gc, s, cpt);
+  gdk_draw_segments (GDK_DRAWABLE (widget->window), self->gc, self->grid, self->numGridLines);
   gdk_window_set_background (widget->window, &self->colors [0]);
 
 
   /* Compute the height_step */
   for (cpt = 0 ; cpt < 50 ; cpt++) {
     
-    if (self->transmitted_audio_speeds [cpt] > max_transmitted_audio)
-      max_transmitted_audio = self->transmitted_audio_speeds [cpt];
-    if (self->received_audio_speeds [cpt] > max_received_audio)
-      max_received_audio = self->received_audio_speeds [cpt];
-    if (self->transmitted_video_speeds [cpt] > max_transmitted_video)
-      max_transmitted_video = self->transmitted_video_speeds [cpt];
-    if (self->received_video_speeds [cpt] > max_received_video)
-      max_received_video = self->received_video_speeds [cpt];    
+    if (self->transmitted_audio_speeds [cpt] > max_speed)
+      max_speed = self->transmitted_audio_speeds [cpt];
+    if (self->received_audio_speeds [cpt] > max_speed)
+      max_speed = self->received_audio_speeds [cpt];
+    if (self->transmitted_video_speeds [cpt] > max_speed)
+      max_speed = self->transmitted_video_speeds [cpt];
+    if (self->received_video_speeds [cpt] > max_speed)
+      max_speed = self->received_video_speeds [cpt];    
   }
-  if (max_received_video > allocation_height / height_step)
-    height_step = allocation_height / max_received_video;
-  if (max_received_audio > allocation_height / height_step)
-    height_step = allocation_height / max_received_audio;
-  if (max_transmitted_video > allocation_height / height_step)
-    height_step = allocation_height /  max_transmitted_video;
-  if (max_transmitted_audio > allocation_height / height_step)
-    height_step = allocation_height / max_transmitted_audio;
-
+  height_step = allocation_height / max_speed;
+ 
   gdk_gc_set_line_attributes (self->gc, 2, GDK_LINE_SOLID, 
 			      GDK_CAP_ROUND, GDK_JOIN_BEVEL);
 
@@ -355,6 +325,58 @@
 }
 
 
+static void
+stats_drawing_area_size_allocate (GtkWidget *widget,
+				  GtkAllocation *allocation)
+{
+  StatsDrawingArea *self = NULL;
+  int y = 0;
+  int x = 0;
+  int cpt = 0;
+
+  g_return_if_fail (widget != NULL);
+  g_return_if_fail (IS_STATS_DRAWING_AREA (widget));
+  g_return_if_fail (allocation != NULL);
+
+  self = STATS_DRAWING_AREA (widget);
+
+  widget->allocation = *allocation;
+  if (GTK_WIDGET_REALIZED (widget)) {
+    gdk_window_move_resize (widget->window,
+			    allocation->x, allocation->y,
+			    allocation->width, allocation->height);
+  }
+
+  /* Calculate Grid Segments */
+  self->numGridLines = ((20+allocation->height) / 21) + ((20+allocation->width) / 21);
+  GdkSegment* s = (GdkSegment*) malloc(self->numGridLines * sizeof(GdkSegment));
+  free(self->grid);
+  self->grid = s;
+
+  while ( y < allocation->height) {
+
+    s [cpt].x1 = 0;
+    s [cpt].x2 = allocation->width;
+    s [cpt].y1 = y;
+    s [cpt].y2 = y;
+      
+    y = y + 21;
+    cpt++;
+  }
+ 
+  while (x < allocation->width) {
+
+    s [cpt].x1 = x;
+    s [cpt].x2 = x;
+    s [cpt].y1 = 0;
+    s [cpt].y2 = allocation->height;
+      
+    x = x + 21;
+    cpt++;
+  }
+}
+
+
 /* implementation of the external api */
 
 
@@ -429,5 +451,6 @@
   self->position++;
   if (self->position >= 50) self->position = 0;
 
-  gtk_widget_queue_draw (GTK_WIDGET (self));
+  if (GTK_WIDGET_REALIZED (self))
+	  gtk_widget_queue_draw (GTK_WIDGET (self));
 }

Attachment: pgp7xN8CNWFMj.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]