From 8397d76a8208a09ba3722754c04a2fddaf04713a Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sat, 10 Oct 2009 14:11:45 -0700 Subject: [PATCH] first take on reszing the windows --- callback.c | 50 ++++++++++++- callback.h | 1 + gtk-interface.xml | 215 +++++++++++++++++++++++++++-------------------------- interface.h | 3 +- xboard.c | 51 +++++-------- 5 files changed, 179 insertions(+), 141 deletions(-) diff --git a/callback.c b/callback.c index e878dfc..d2e42f3 100644 --- a/callback.c +++ b/callback.c @@ -12,9 +12,12 @@ # 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) diff --git a/callback.h b/callback.h index c6e7714..b61f26f 100644 --- a/callback.h +++ b/callback.h @@ -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)); diff --git a/gtk-interface.xml b/gtk-interface.xml index 42fc846..4a67cf6 100644 --- a/gtk-interface.xml +++ b/gtk-interface.xml @@ -2,9 +2,116 @@ + + + + + + + + + + + + 5 + normal + False + + + True + vertical + 2 + + + True + True + automatic + automatic + + + True + True + MoveHistoryStore + False + False + 0 + + + Move + + + + 0 + + + + + + + White + + + + 1 + + + + + + + Black + + + + 2 + + + + + + + + + 1 + + + + + True + end + + + gtk-close + True + True + True + True + + + + False + False + 0 + + + + + False + end + 0 + + + + + + CloseButton + + + GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK XBoard + True @@ -14,7 +121,7 @@ 0 False - + True vertical @@ -847,6 +954,7 @@ + False 1 @@ -961,109 +1069,4 @@ 0.40000000596046448 gtk-open - - - - - - - - - - - - 5 - normal - False - - - True - vertical - 2 - - - True - True - automatic - automatic - - - True - True - MoveHistoryStore - False - False - 0 - - - Move - - - - 0 - - - - - - - White - - - - 1 - - - - - - - Black - - - - 2 - - - - - - - - - 1 - - - - - True - end - - - gtk-close - True - True - True - True - - - - False - False - 0 - - - - - False - end - 0 - - - - - - CloseButton - - diff --git a/interface.h b/interface.h index 4ce00b5..b3a457a 100644 --- a/interface.h +++ b/interface.h @@ -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; diff --git a/xboard.c b/xboard.c index 99f5566..4793a1d 100644 --- 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