first take on reszing the windows
authorArun Persaud <arun@nubati.net>
Sat, 10 Oct 2009 21:11:45 +0000 (14:11 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 10 Oct 2009 21:53:17 +0000 (14:53 -0700)
callback.c
callback.h
gtk-interface.xml
interface.h
xboard.c

index e878dfc..d2e42f3 100644 (file)
 # define N_(s)  s
 #endif
 
-
 extern GtkWidget  *about;
 extern GtkWidget  *GUI_Window;
+extern GtkWidget  *GUI_Menubar;
+extern GtkWidget  *GUI_Timer;
+extern GtkWidget  *GUI_Buttonbar;
+extern GtkWidget  *GUI_Board;
 
 extern char *programVersion;
 extern int errorExitStatus;
@@ -23,6 +26,51 @@ extern int fromX;
 extern int fromY;
 extern int toX;
 extern int toY;
+extern int squareSize,lineGap;
+
+gboolean
+ExposeProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
+{
+  /* do resizing to a fixed aspect ratio */
+  GtkRequisition w;
+  int totalh=0,nw,nh;
+  float ratio;
+  int boardWidth,boardHeight,old,new;
+  
+  nw=GTK_WIDGET(object)->allocation.width;
+  nh=GTK_WIDGET(object)->allocation.height;
+    
+  old=squareSize;
+  squareSize  = nw/(BOARD_WIDTH*1.05+0.05);
+
+  if(old!=squareSize)
+    {
+      lineGap = squareSize*0.05;
+      
+      boardWidth  = lineGap + BOARD_WIDTH  * (squareSize + lineGap);
+      boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap);
+      
+      /* get the height of the menus, etc. and calculate the aspect ratio */
+      gtk_widget_size_request(GTK_WIDGET(GUI_Menubar),   &w);
+      totalh += w.height;
+      gtk_widget_size_request(GTK_WIDGET(GUI_Timer),   &w);
+      totalh += w.height;
+      gtk_widget_size_request(GTK_WIDGET(GUI_Buttonbar),   &w);
+      totalh += w.height;
+      
+      ratio  = (totalh+boardHeight)/(boardWidth) ;
+            
+      gtk_widget_set_size_request(GTK_WIDGET(GUI_Board),
+                                 boardWidth,boardHeight);
+      
+      GUI_SetAspectRatio(ratio);
+      /* recreate pieces with new size... TODO: keep svg in memory and just recreate pixmap instead of reloading files */
+      CreatePieces();
+    } 
+  return FALSE; /* return false, so that other expose events are called too */
+}
 
 void
 QuitProc (object, user_data)
index c6e7714..b61f26f 100644 (file)
@@ -19,6 +19,7 @@ void AdjuDrawProc P((GtkObject *object, gpointer user_data));
 void ResetProc P((GtkObject *object, gpointer user_data));
 void WhiteClockProc P((GtkObject *object, gpointer user_data));
 void BlackClockProc P((GtkObject *object, gpointer user_data));
+gboolean ExposeProc P((GtkObject *object, gpointer user_data));
 
 /* Step Menu */
 void BackwardProc P((GtkObject *object, gpointer user_data));
index 42fc846..4a67cf6 100644 (file)
@@ -2,9 +2,116 @@
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkListStore" id="MoveHistoryStore">
+    <columns>
+      <!-- column-name Move -->
+      <column type="gint"/>
+      <!-- column-name White -->
+      <column type="gchararray"/>
+      <!-- column-name Black -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkDialog" id="MoveHistory">
+    <property name="border_width">5</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">automatic</property>
+            <property name="vscrollbar_policy">automatic</property>
+            <child>
+              <object class="GtkTreeView" id="MoveHistoryView">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="model">MoveHistoryStore</property>
+                <property name="headers_clickable">False</property>
+                <property name="enable_search">False</property>
+                <property name="search_column">0</property>
+                <child>
+                  <object class="GtkTreeViewColumn" id="Move">
+                    <property name="title">Move</property>
+                    <child>
+                      <object class="GtkCellRendererText" id="MoveNumberRenderer"/>
+                      <attributes>
+                        <attribute name="text">0</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkTreeViewColumn" id="White">
+                    <property name="title">White</property>
+                    <child>
+                      <object class="GtkCellRendererText" id="MoveWhiteRenderer"/>
+                      <attributes>
+                        <attribute name="text">1</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkTreeViewColumn" id="Black">
+                    <property name="title">Black</property>
+                    <child>
+                      <object class="GtkCellRendererText" id="MoveBlackRenderer"/>
+                      <attributes>
+                        <attribute name="text">2</attribute>
+                      </attributes>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="CloseButton">
+                <property name="label" translatable="yes">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+                <signal name="released" handler="HistoryPopDown"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">CloseButton</action-widget>
+    </action-widgets>
+  </object>
   <object class="GtkWindow" id="MainWindow">
+    <property name="events">GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK</property>
     <property name="title" translatable="yes">XBoard</property>
     <signal name="destroy" handler="QuitProc"/>
+    <signal name="expose_event" handler="ExposeProc"/>
     <child>
       <object class="GtkAspectFrame" id="Aspectframe">
         <property name="visible">True</property>
         <property name="yalign">0</property>
         <property name="obey_child">False</property>
         <child>
-          <object class="GtkVBox" id="VBox">
+          <object class="GtkVBox" id="MenuBox">
             <property name="visible">True</property>
             <property name="orientation">vertical</property>
             <child>
                 </child>
               </object>
               <packing>
+                <property name="expand">False</property>
                 <property name="position">1</property>
               </packing>
             </child>
     <property name="xalign">0.40000000596046448</property>
     <property name="stock">gtk-open</property>
   </object>
-  <object class="GtkListStore" id="MoveHistoryStore">
-    <columns>
-      <!-- column-name Move -->
-      <column type="gint"/>
-      <!-- column-name White -->
-      <column type="gchararray"/>
-      <!-- column-name Black -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
-  <object class="GtkDialog" id="MoveHistory">
-    <property name="border_width">5</property>
-    <property name="type_hint">normal</property>
-    <property name="has_separator">False</property>
-    <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox1">
-        <property name="visible">True</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child>
-          <object class="GtkScrolledWindow" id="scrolledwindow1">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="hscrollbar_policy">automatic</property>
-            <property name="vscrollbar_policy">automatic</property>
-            <child>
-              <object class="GtkTreeView" id="MoveHistoryView">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="model">MoveHistoryStore</property>
-                <property name="headers_clickable">False</property>
-                <property name="enable_search">False</property>
-                <property name="search_column">0</property>
-                <child>
-                  <object class="GtkTreeViewColumn" id="Move">
-                    <property name="title">Move</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="MoveNumberRenderer"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkTreeViewColumn" id="White">
-                    <property name="title">White</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="MoveWhiteRenderer"/>
-                      <attributes>
-                        <attribute name="text">1</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkTreeViewColumn" id="Black">
-                    <property name="title">Black</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="MoveBlackRenderer"/>
-                      <attributes>
-                        <attribute name="text">2</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="CloseButton">
-                <property name="label" translatable="yes">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-                <signal name="released" handler="HistoryPopDown"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="0">CloseButton</action-widget>
-    </action-widgets>
-  </object>
 </interface>
index 4ce00b5..b3a457a 100644 (file)
@@ -20,7 +20,8 @@ gint                     boardHeight;
 GdkPixbuf               *WindowIcon=NULL;
 GdkPixbuf               *WhiteIcon=NULL;
 GdkPixbuf               *BlackIcon=NULL;
-GdkPixbuf               *SVGpieces[100];
+#define MAXPIECES 100
+GdkPixbuf               *SVGpieces[MAXPIECES];
 GdkPixbuf               *SVGLightSquare=NULL;
 GdkPixbuf               *SVGDarkSquare=NULL;
 GdkPixbuf               *SVGNeutralSquare=NULL;
index 99f5566..4793a1d 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -2568,15 +2568,6 @@ main(argc, argv)
       /* TODO hide button bar if requested */
     }
 
-    /*
-     *  gtk set properties of widgets
-     */
-
-    /* set board size */
-    gtk_widget_set_size_request(GTK_WIDGET(GUI_Board),
-                               boardWidth,boardHeight);
-
-    /* end gtk set properties of widgets */
 
     if (appData.titleInWindow)
       {
@@ -2706,25 +2697,7 @@ main(argc, argv)
     /* realize window */
     gtk_widget_show (GUI_Window);
 
-    /* do resizing to a fixed aspect ratio */
-    {
-      GtkRequisition w;
-      int totalh=boardHeight;
-      float ratio;
-
-      gtk_widget_size_request(GTK_WIDGET(GUI_Menubar),   &w);
-      totalh += w.height;
-
-      gtk_widget_size_request(GTK_WIDGET(GUI_Timer),     &w);
-      totalh += w.height;
-
-      gtk_widget_size_request(GTK_WIDGET(GUI_Buttonbar), &w);
-      totalh += w.height;
-
-      ratio  = (totalh)/(boardWidth) ;
-      GUI_SetAspectRatio(ratio);
-    }
-
+    /* recalc boardsize */
     CreateGCs();
     CreatePieces();
     CreatePieceMenus();
@@ -3120,17 +3093,29 @@ void CreateGCs()
 
 void CreatePieces()
 {
-  /* order of pieces
-  WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen, WhiteKing,
-  BlackPawn, BlackKnight, BlackBishop, BlackRook, BlackQueen, BlackKing,
-  */
   int i;
 
+  /* free if used 
+  for(i=0;i<MAXPIECES;i++)
+    {
+      if(SVGpieces[i])
+       {       
+         g_free(SVGpieces[i]);
+         SVGpieces[i]=NULL;
+       }
+    }
+  */
+
+  /* reload these */
+  SVGLightSquare   = load_pixbuf("svg/LightSquare.svg",squareSize);
+  SVGDarkSquare    = load_pixbuf("svg/DarkSquare.svg",squareSize);
+  SVGNeutralSquare = load_pixbuf("svg/NeutralSquare.svg",squareSize);
+
+
   /* get some defaults going */
   for(i=WhitePawn; i<DemotePiece+1; i++)
     SVGpieces[i]   = load_pixbuf("svg/NeutralSquare.svg",squareSize);
     
-
   SVGpieces[WhitePawn]   = load_pixbuf("svg/WhitePawn.svg",squareSize);
   SVGpieces[WhiteKnight] = load_pixbuf("svg/WhiteKnight.svg",squareSize);
   SVGpieces[WhiteBishop] = load_pixbuf("svg/WhiteBishop.svg",squareSize);