Fix logo placement
[xboard.git] / gtk / xoptions.c
index afc82a6..01775e8 100644 (file)
@@ -634,7 +634,7 @@ GtkWidget *shells[NrOfDialogs];
 DialogClass parents[NrOfDialogs];
 WindowPlacement *wp[NrOfDialogs] = { // Beware! Order must correspond to DialogClass enum
     NULL, &wpComment, &wpTags, NULL, NULL, NULL, NULL, &wpMoveHistory, &wpGameList, &wpEngineOutput, &wpEvalGraph,
-    NULL, NULL, NULL, NULL, /*&wpMain*/ NULL
+    NULL, NULL, NULL, NULL, &wpMain
 };
 
 int
@@ -679,21 +679,9 @@ PopDown (DialogClass n)
     //Arg args[10];    
     
     if (!shellUp[n] || !shells[n]) return 0;    
-#ifdef TODO_GTK
-// Not sure this is still used
     if(n && wp[n]) { // remember position
-       j = 0;
-       XtSetArg(args[j], XtNx, &windowX); j++;
-       XtSetArg(args[j], XtNy, &windowY); j++;
-       XtSetArg(args[j], XtNheight, &windowH); j++;
-       XtSetArg(args[j], XtNwidth, &windowW); j++;
-       XtGetValues(shells[n], args, j);
-       wp[n]->x = windowX;
-       wp[n]->x = windowY;
-       wp[n]->width  = windowW;
-       wp[n]->height = windowH;
+       GetActualPlacement(shells[n], wp[n]);
     }
-#endif
     
     gtk_widget_hide(shells[n]);
     shellUp[n]--; // count rather than clear
@@ -829,16 +817,15 @@ GraphEventProc(GtkWidget *widget, GdkEvent *event, gpointer gdata)
                         // to give drawing routines opportunity to use it before first expose event
                         // (which are only processed when main gets to the event loop, so after all init!)
                         // so only change when size is no longer good
-#ifdef TODO_GTK
                if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice);
                graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
-#endif
                break;
            }
            w = eevent->area.width;
            if(eevent->area.x + w > graph->max) w--; // cut off fudge pixel
            cr = gdk_cairo_create(((GtkWidget *) (graph->handle))->window);
            cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0);
+//cairo_set_source_rgb(cr, 1, 0, 0);
            cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
            cairo_rectangle(cr, eevent->area.x, eevent->area.y, w, eevent->area.height);
            cairo_fill(cr);
@@ -1071,7 +1058,7 @@ static int
 SameRow (Option *opt)
 {
     return (opt->min & SAME_ROW && (opt->type == Button || opt->type == SaveButton || opt->type == Label
-                                || opt->type == ListBox || opt->type == BoxBegin || opt->type == Icon));
+                                || opt->type == ListBox || opt->type == BoxBegin || opt->type == Icon || opt->type == Graph));
 }
 
 static void
@@ -1168,7 +1155,7 @@ printf("n=%d, h=%d, w=%d\n",n,height,width);
     for (i=0;option[i].type != EndMark;i++) {
        if(option[i].type == -1) continue;
         top++;
-printf("option =%2d, top =%2d\n", i, top);
+//printf("option =%2d, top =%2d\n", i, top);
         if (top >= height) {
             gtk_table_resize(GTK_TABLE(table), height, r);
            if(!pane) { // multi-column: put tables in intermediate hbox
@@ -1187,7 +1174,7 @@ printf("option =%2d, top =%2d\n", i, top);
            if(SameRow(&option[i+1])) {
                GtkAttachOptions x = GTK_FILL;
                // make sure hbox is always available when we have more options on same row
-                hbox = gtk_hbox_new (option[i].type == Button && option[i].textValue, 0);
+                hbox = gtk_hbox_new (option[i].type == Button && option[i].textValue || option[i].type == Graph, 0);
                if(!currentCps && option[i].value > 80) x |= GTK_EXPAND; // only vertically extended widgets should size vertically
                 if (strcmp(option[i].name, "") == 0 || option[i].type == Label || option[i].type == Button)
                     // for Label and Button name is contained inside option
@@ -1406,13 +1393,23 @@ printf("option =%2d, top =%2d\n", i, top);
            break;
          case Graph:
            option[i].handle = (void*) (graph = gtk_drawing_area_new());
-            gtk_widget_set_size_request(graph, option[i].max, option[i].value);
-            Pack(hbox, table, graph, left, left+r, top, GTK_EXPAND);
+//            gtk_widget_set_size_request(graph, option[i].max, option[i].value);
+           if(0){ GtkAllocation a;
+               a.x = 0; a.y = 0; a.width = option[i].max, a.height = option[i].value;
+               gtk_widget_set_allocation(graph, &a);
+           }
             g_signal_connect (graph, "expose-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
            gtk_widget_add_events(GTK_WIDGET(graph), GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);
             g_signal_connect (graph, "button-press-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
             g_signal_connect (graph, "button-release-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
             g_signal_connect (graph, "motion-notify-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
+           if(option[i].min & FIX_H) { // logo
+               GtkWidget *frame = gtk_aspect_frame_new(NULL, 0.5, 0.5, option[i].max/(float)option[i].value, FALSE);
+               gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
+                gtk_container_add(GTK_CONTAINER(frame), graph);
+               graph = frame;
+           }
+            Pack(hbox, table, graph, left, left+r, top, GTK_EXPAND);
 
 #ifdef TODO_GTK
            if(option[i].min & SAME_ROW) last = forelast, forelast = lastrow;
@@ -1484,6 +1481,7 @@ printf("option =%2d, top =%2d\n", i, top);
 
     option[i].handle = (void *) table; // remember last table in EndMark handle (for hiding Engine-Output pane).
 
+    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_NONE);
     /* Show dialog */
     gtk_widget_show_all( dialog );    
 
@@ -1501,6 +1499,13 @@ printf("option =%2d, top =%2d\n", i, top);
                       (gpointer)(intptr_t) dlgNr);
     shellUp[dlgNr]++;
 
+    if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
+       gtk_window_move(GTK_WINDOW(dialog), wp[dlgNr]->x, wp[dlgNr]->y);
+//printf("moved %d to (%d,%d)\n", dlgNr, wp[dlgNr]->x, wp[dlgNr]->y);
+       gtk_window_resize(GTK_WINDOW(dialog), wp[dlgNr]->width, wp[dlgNr]->height);
+//printf("resized %d to %dx%d\n", dlgNr, wp[dlgNr]->width, wp[dlgNr]->height);
+    }
+
     return 1; // tells caller he must do initialization (e.g. add specific event handlers)
 }