From: H.G. Muller Date: Sat, 20 Oct 2012 17:57:58 +0000 (+0200) Subject: Add displaying of icons X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=cf79064032c57731c50c694ee83c22312976940d Add displaying of icons A new Option type, 'Icon', was added for this as in GTK Icons and Labels need different types of widget. The icons are now svg, so we could remove the icon pixmaps. --- diff --git a/nengineoutput.c b/nengineoutput.c index 774d63a..cf304a0 100644 --- a/nengineoutput.c +++ b/nengineoutput.c @@ -74,16 +74,16 @@ static int currentPV, highTextStart[2], highTextEnd[2]; int MemoProc P((Option *opt, int n, int x, int y, char *text, int index)); Option engoutOptions[] = { -{ 0, LL|T2T, 17, NULL, NULL, NULL, NULL, Label, " " }, +{ 0, LL|T2T, 17, NULL, NULL, NULL, NULL, Icon, " " }, { 0, L2L|T2T|SAME_ROW, 163, NULL, NULL, NULL, NULL, Label, N_("engine name") }, -{ 0, T2T|SAME_ROW, 30, NULL, NULL, NULL, NULL, Label, " " }, +{ 0, T2T|SAME_ROW, 30, NULL, NULL, NULL, NULL, Icon, " " }, { 0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") }, { 0, RR|T2T|SAME_ROW, 80, NULL, NULL, NULL, NULL, Label, N_("NPS") }, {200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem1, "", (char**) MemoProc, TextBox, "" }, { 0, 0, 0, NULL, NULL, "", NULL, Break , "" }, -{ 0, LL|T2T, 17, NULL, NULL, NULL, NULL, Label, " " }, +{ 0, LL|T2T, 17, NULL, NULL, NULL, NULL, Icon, " " }, { 0, L2L|T2T|SAME_ROW, 163, NULL, NULL, NULL, NULL, Label, N_("engine name") }, -{ 0, T2T|SAME_ROW, 30, NULL, NULL, NULL, NULL, Label, " " }, +{ 0, T2T|SAME_ROW, 30, NULL, NULL, NULL, NULL, Icon, " " }, { 0, R2R|T2T|SAME_ROW, 188, NULL, NULL, NULL, NULL, Label, N_("move") }, { 0, RR|T2T|SAME_ROW, 80, NULL, NULL, NULL, NULL, Label, N_("NPS") }, {200, T_VSCRL | T_TOP, 500, NULL, (void*) &mem2, "", (char**) MemoProc, TextBox, "" }, diff --git a/xengineoutput.c b/xengineoutput.c index b19b77e..576d58b 100644 --- a/xengineoutput.c +++ b/xengineoutput.c @@ -66,40 +66,24 @@ extern char *getenv(); # define N_(s) s #endif -// [HGM] pixmaps of some ICONS used in the engine-outut window -#include "pixmaps/WHITE_14.xpm" -#include "pixmaps/BLACK_14.xpm" -#include "pixmaps/CLEAR_14.xpm" -#include "pixmaps/UNKNOWN_14.xpm" -#include "pixmaps/THINKING_14.xpm" -#include "pixmaps/PONDER_14.xpm" -#include "pixmaps/ANALYZING_14.xpm" - extern Option engoutOptions[]; // must go in header, but which? /* Module variables */ static int currentPV, highTextStart[2], highTextEnd[2]; #ifdef TODO_GTK -static Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle static Widget memoWidget; #endif -static void *memoWidget; +static GdkPixbuf *iconsGTK[8]; +static GtkWidget *outputFieldGTK[2][7]; // [HGM] front-end array to translate output field to window handlestatic void *memoWidget; -#ifdef TODO_GTK static void -ReadIcon (char *pixData[], int iconNr, Widget w) +ReadIcon (gchar *svgFilename, int iconNr) { - int r; - - if ((r=XpmCreatePixmapFromData(xDisplay, XtWindow(w), - pixData, - &(icons[iconNr]), - NULL, NULL /*&attr*/)) != 0) { - fprintf(stderr, _("Error %d loading icon image\n"), r); - exit(1); - } + char buf[MSG_SIZ]; + + snprintf(buf, MSG_SIZ, "%s/%s", SVGDIR, svgFilename); + iconsGTK[iconNr] = gdk_pixbuf_new_from_file(buf, NULL); } -#endif void InitEngineOutput (Option *opt, Option *memo2) @@ -107,28 +91,21 @@ InitEngineOutput (Option *opt, Option *memo2) #ifdef TODO_GTK Widget w = opt->handle; memoWidget = memo2->handle; - - ReadIcon(WHITE_14, nColorWhite, w); - ReadIcon(BLACK_14, nColorBlack, w); - ReadIcon(UNKNOWN_14, nColorUnknown, w); - - ReadIcon(CLEAR_14, nClear, w); - ReadIcon(PONDER_14, nPondering, w); - ReadIcon(THINK_14, nThinking, w); - ReadIcon(ANALYZE_14, nAnalyzing, w); #endif + ReadIcon("eo_White.svg", nColorWhite); + ReadIcon("eo_Black.svg", nColorBlack); + ReadIcon("eo_Unknown.svg", nColorUnknown); + + ReadIcon("eo_Clear.svg", nClear); + ReadIcon("eo_Ponder.svg", nPondering); + ReadIcon("eo_Thinking.svg", nThinking); + ReadIcon("eo_Analyzing.svg", nAnalyzing); } void DrawWidgetIcon (Option *opt, int nIcon) -{ // as we are already in X front-end, so do X-stuff here -#ifdef TODO_GTK - gchar widgetname[50]; - - if( nIcon != 0 ) { - gtk_image_set_from_pixbuf(GTK_IMAGE(opt->handle), GDK_PIXBUF(iconsGTK[nIcon])); - } -#endif +{ // as we are already in GTK front-end, so do GTK-stuff here + if( nIcon != 0 ) gtk_image_set_from_pixbuf(GTK_IMAGE(opt->handle), GDK_PIXBUF(iconsGTK[nIcon])); } void diff --git a/xoptions.c b/xoptions.c index 4717ec8..e081bd7 100644 --- a/xoptions.c +++ b/xoptions.c @@ -1075,7 +1075,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 == ListBox || opt->type == BoxBegin || opt->type == Icon)); } static void @@ -1299,6 +1299,11 @@ printf("n=%d, h=%d, w=%d\n",n,height,width); gtk_table_attach(GTK_TABLE(table), checkbutton, left, left+r, top, top+1, GTK_FILL | GTK_EXPAND, GTK_FILL, 2, 0); option[i].handle = (void *)checkbutton; break; + case Icon: + option[i].handle = (void *) (label = gtk_image_new_from_pixbuf(NULL)); + gtk_widget_set_size_request(label, option[i].max ? option[i].max : -1, -1); + Pack(hbox, table, label, left, left+2, top, 0); + break; case Label: option[i].handle = (void *) (label = gtk_label_new(option[i].name)); /* Left Justify */