first take on reszing the windows
[xboard.git] / callback.c
index 4bc9210..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)
@@ -345,11 +393,30 @@ void RetractMoveProc(object, user_data)
 }
 
 /* Option Menu */
+void ShowThinkingProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
+{
+    appData.showThinking = !appData.showThinking; 
+    ShowThinkingEvent();
+
+    return;
+}
+
+void HideThinkingProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
+{
+    appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman;
+    ShowThinkingEvent();
+
+    return;
+}
+
 void FlipViewProc(object, user_data)
      GtkObject *object;
      gpointer user_data;
 {
-  printf("DEBUG: in flip view\n");
     flipView = !flipView;
     DrawPosition(True, NULL);
     return;
@@ -441,16 +508,22 @@ void LoadGameProc(object, user_data)
 
       //see loadgamepopup
       f = fopen(filename, "rb");
-      if (f == NULL) {
-       DisplayError(_("Failed to open file"), errno);
-      } else {
-       /* TODO add indec */
-       (void) LoadGamePopUp(f, 0, filename);
-      }
+      if (f == NULL) 
+       {
+         DisplayError(_("Failed to open file"), errno);
+       }
+      else 
+       {
+         /* TODO add indec */
+         (void) LoadGamePopUp(f, 0, filename);
+       }
       g_free (filename);
-    }
+    };
+  
   gtk_widget_destroy (dialog);
   ModeHighlight();
+  
+  return;
 }
 
 
@@ -662,3 +735,19 @@ void UserMoveProc(window, event, data)
     return;
 }
 
+void GetMoveListProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
+{
+  appData.getMoveList = !appData.getMoveList;
+  
+  if (appData.getMoveList) 
+    {
+      GetMoveListEvent();
+    } 
+
+  // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1
+  //  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList );
+  
+  return;
+}