On Thu, 21 Dec 2000, Vlad Harchev wrote:
I've attached a patch and a screenshot of dia running SatinBlack gtk theme,
with the following in .gtkrc
style "magic-icon-style"
{
text[NORMAL] = { 1.0, 1.0, 0 }
}
widget "magic-icon-foreground-color" style "magic-icon-style"
I.e. it was requested to replace 'black' in icons with 'yellow' in ~/.gtkrc
If these 5 lines were absent in ~/.gtkrc, the 'black' would be substituted
with white since that's the color of text of GtkLabel dictated by this gtk
theme.
It would be nice if these 2 functions (that do color replacement) were used
for loading icons in all gtk-based software.
Would you include this patch into Dia tree?
> On Thu, 21 Dec 2000, James Henstridge wrote:
>
> > On Thu, 21 Dec 2000, Vlad Harchev wrote:
> >
> > > On 21 Dec 2000, Lars Clausen wrote:
> > >
> > > > On Thu, 21 Dec 2000, Vlad Harchev wrote:
> > > >
> > > > >
> > > > > Hi,
> > > > >
> > > > > I use very dark Gtk theme (SatinBlack). All icons that use black are
> > > > > almost invisible on the very dark "buttons" they are placed on. I'm
> > > > > going to modify dia so that it will use default text forgeground color
> > > > > or color of text foreground of some special named widget defined in
> > > > > .gtkrc (e.g. "icon-foreground-color") instead of black for icons. Would
> > > > > you accept the patch that adds this functionality? If yes, could you
> > > > > please tell me the approximate name of the file and function that
> > > > > creates "palette" icons so that I won't need to grep around all dia
> > > > > tree?
> > > >
> > > > The icons are stored as pixmaps (.xpm) files in pixmaps directories,
> > > > e.g. for the standard tools, they are in objects/standard/pixmaps.
> > > > However, most of them are not generated, so it'll require some picture
> > > > trickery to make them another color. The generated icons are from
> > > > app/color_area.c, linewidth_area.c and lineprops_area.c. If you can get
> > > > all this to work well, I'm sure a patch will be appreciated.
> > >
> > > Thank you for the explanation.
> > > Where do the icons get loaded (where gdk_pixmap_colormap_create_from_xpm_d is
> > > called that is relevant to icons) ?
> >
> > Most of the pixmaps are compiled into the binary. There are no special
> > colour transformations done on them (except for handling the shape mask).
>
> No, most of the pixmaps are loaded from ${prefix}/dia/{Shapes}{Sheets}
>
> > Probably the easiest way to fix this would be to go through the images and
> > put a light grey (or other light colour) border around the images.
>
> I've already written and tested a replacement for
> gdk_pixmap_colormap_create_from_xpm_d, I have to write analog of
> gdk_pixmap_colormap_create_from_xpm().
>
> It seems I will post a patch later today.
>
> > James.
> >
>
> Best regards,
> -Vlad
>
Best regards,
-Vlad
dia.png
diff -ru was/dia-0.86/app/interface.c fixed/dia-0.86/app/interface.c
--- was/dia-0.86/app/interface.c Mon Jul 31 11:12:47 2000
+++ fixed/dia-0.86/app/interface.c Fri Dec 22 02:02:07 2000
@@ -29,6 +29,10 @@
#include "dia_dirs.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
ToolButton tool_data[] =
{
{ (char **) arrow_xpm,
@@ -349,6 +353,148 @@
}
}
+/*
+ The two functions below are by Vlad Harchev <[EMAIL PROTECTED]>
+ Their task is to substitute the black colors on the icons with the
+ color of current theme's text foreground of the widget with name
+ "magic-icon-foreground-color", or if no such widget style is defined, with
+ current theme's text foreground of GtkLabel. This is very important if
+ the gtk theme is the dark one - without these 2 functions black color in icons
+ would be indistinguishable from the dark button the icon is painted on.
+
+ So, to substitute black with say, yellow, add the following to your
+ theme or ~/.gtkrc
+
+style "magic-icon-style"
+{
+ text[NORMAL] = { 1.0, 1.0, 0 } #this is the spec of the color
+}
+widget "magic-icon-foreground-color" style "magic-icon-style"
+
+ The spread of the use of these 2 functions for loading icons is appreciated.
+*/
+static GdkPixmap* themed_pixmap_colormap_create_from_xpm_d
+ (GdkWindow *window,
+ GdkColormap *colormap,
+ GdkBitmap **mask,
+ GdkColor *transparent_color,
+ gchar **data)
+{
+ int w,h,nc;
+ static GtkWidget* aux_label = NULL;
+ static char magic_color_spec[50];
+ char** dynamic_buffer = NULL;
+ char** buffer = data;
+ GdkPixmap* retval;
+
+ if (!aux_label) {
+ GdkColor* c;
+
+ aux_label = gtk_label_new("");
+ gtk_widget_set_name(aux_label, "magic-icon-foreground-color");
+ gtk_widget_ensure_style(aux_label);
+ c = aux_label->style->text + GTK_STATE_NORMAL;
+ sprintf(magic_color_spec,"%02x%02x%02x",(unsigned
+ int)c->red>>8,(unsigned int) c->green>>8,(unsigned int) c->blue>>8);
+ };
+
+ if (sscanf(data[0],"%d %d %d",&h,&w,&nc)==3) {
+ int magic_color_index = -1;
+ if (nc==2) {
+ int line;
+ for (line = 1; line<=2;++line) {
+ if (!strcmp(data[line]+2,"c #000000") || !strcmp(data[line]+2,"c black")) {
+ magic_color_index = line - 1;
+ break;
+ };
+ };
+ } else if (data[1][0]=='?') {
+ int idx=-1;
+ if (sscanf(data[1]+strlen(".\tc #"),"%x",&idx)==1 && idx>0 && idx < nc) {
+ magic_color_index = idx;
+ };
+ }
+ if (magic_color_index!=-1) {
+ static char replacement_line[100];
+ static char* static_buffer[100];
+
+ if (h+1+nc > sizeof(static_buffer)/sizeof(static_buffer[0])) {
+ buffer = dynamic_buffer = g_new(char*,h+1+nc);
+ } else
+ buffer = static_buffer;
+ memcpy(buffer,data,sizeof(char*)*(h+1+nc));
+ sprintf(replacement_line,"%c\tc #%s",data[1+magic_color_index][0],
+ magic_color_spec);
+ buffer[1+magic_color_index] = replacement_line;
+ };
+ };
+ retval = gdk_pixmap_colormap_create_from_xpm_d (window,
+ colormap, mask, transparent_color, (gchar**)buffer);
+ if (dynamic_buffer)
+ g_free(dynamic_buffer);
+ return retval;
+};
+
+static GdkPixmap* themed_pixmap_colormap_create_from_xpm
+ (GdkWindow *window,
+ GdkColormap *colormap,
+ GdkBitmap **mask,
+ GdkColor *transparent_color,
+ const gchar *filename)
+{
+ char buf[2048];
+ int cnt;
+ {
+ FILE* f = fopen(filename,"rt");
+ if (!f)
+ return NULL;
+ cnt = fread(buf,1,sizeof(buf),f);
+ if (!cnt || cnt == sizeof(buf))
+ return NULL;/*too big or small*/
+ fclose(f);
+ buf[cnt] = '\0';
+ }
+ {
+ char** strings = g_strsplit(buf,"\n",0);
+ char** p;
+ int nlines;
+ void* retval = NULL;
+ char** data;
+ int i;
+
+ for(p=strings;*p;++p);
+ --p;
+ for(;p>strings;--p)
+ if (strchr(*p,'"'))
+ break;
+ ++p;
+ nlines = p - strings - 2;
+ data = g_new(char*,nlines+1);
+ data[nlines] = NULL;
+
+ for(i=0;i<nlines;++i) {
+ char* pos = strchr(strings[i+2],'"');
+ if (!pos)
+ goto failed;
+ data[i] = pos+1;
+
+ pos = strrchr(data[i],'"');
+ if (!pos)
+ goto failed;
+ *pos = '\0';
+ };
+ /*process data*/
+ retval = themed_pixmap_colormap_create_from_xpm_d (window, colormap,
+ mask, transparent_color, (gchar**)data);
+failed:
+ g_strfreev(strings);
+ g_free(data);
+
+ return retval;
+ }
+};
+
+
static void
create_tools(GtkWidget *parent)
{
@@ -387,7 +533,7 @@
}
style = gtk_widget_get_style(button);
- pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL,
+ pixmap = themed_pixmap_colormap_create_from_xpm_d(NULL,
gtk_widget_get_colormap(button), &mask,
&style->bg[GTK_STATE_NORMAL], pixmap_data);
@@ -546,17 +692,17 @@
ToolButtonData *data;
if (sheet_obj->pixmap != NULL) {
- pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL,
+ pixmap = themed_pixmap_colormap_create_from_xpm_d(NULL,
gtk_widget_get_colormap(sheet_wbox), &mask,
&style->bg[GTK_STATE_NORMAL], sheet_obj->pixmap);
} else if (sheet_obj->pixmap_file != NULL) {
- pixmap = gdk_pixmap_colormap_create_from_xpm(NULL,
+ pixmap = themed_pixmap_colormap_create_from_xpm(NULL,
gtk_widget_get_colormap(sheet_wbox), &mask,
&style->bg[GTK_STATE_NORMAL], sheet_obj->pixmap_file);
} else {
ObjectType *type;
type = object_get_type(sheet_obj->object_type);
- pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL,
+ pixmap = themed_pixmap_colormap_create_from_xpm_d(NULL,
gtk_widget_get_colormap(sheet_wbox), &mask,
&style->bg[GTK_STATE_NORMAL], type->pixmap);
}
@@ -691,7 +837,7 @@
gtk_widget_get_colormap(parent), &mask,
&style->bg[GTK_STATE_NORMAL], default_xpm);
swap_pixmap =
- gdk_pixmap_colormap_create_from_xpm_d(NULL,
+ themed_pixmap_colormap_create_from_xpm_d(NULL,
gtk_widget_get_colormap(parent), &mask,
&style->bg[GTK_STATE_NORMAL], swap_xpm);
Only in fixed/dia-0.86/app: interface.c-was
diff -ru was/dia-0.86/app/pixmaps/swap.xpm fixed/dia-0.86/app/pixmaps/swap.xpm
--- was/dia-0.86/app/pixmaps/swap.xpm Thu Jun 3 15:09:49 1999
+++ fixed/dia-0.86/app/pixmaps/swap.xpm Thu Dec 21 18:21:02 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * swap_xpm[] = {
-"13 13 3 1",
+"13 13 4 1",
+"? c #000003",
" c None",
". c #919191",
"+ c #000000",
diff -ru was/dia-0.86/objects/FS/pixmaps/flow.xpm
fixed/dia-0.86/objects/FS/pixmaps/flow.xpm
--- was/dia-0.86/objects/FS/pixmaps/flow.xpm Sun Jul 25 12:30:15 1999
+++ fixed/dia-0.86/objects/FS/pixmaps/flow.xpm Fri Dec 22 01:10:53 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * flow_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000003",
" c None",
". c white",
"X c black",
diff -ru was/dia-0.86/objects/FS/pixmaps/orthflow.xpm
fixed/dia-0.86/objects/FS/pixmaps/orthflow.xpm
--- was/dia-0.86/objects/FS/pixmaps/orthflow.xpm Sun Jul 25 12:30:15 1999
+++ fixed/dia-0.86/objects/FS/pixmaps/orthflow.xpm Fri Dec 22 01:17:15 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * orthflow_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000003",
" c None",
". c white",
"X c black",
diff -ru was/dia-0.86/objects/GRAFCET/pixmaps/condition.xpm
fixed/dia-0.86/objects/GRAFCET/pixmaps/condition.xpm
--- was/dia-0.86/objects/GRAFCET/pixmaps/condition.xpm Wed Feb 2 20:25:28 2000
+++ fixed/dia-0.86/objects/GRAFCET/pixmaps/condition.xpm Fri Dec 22 01:18:28
+2000
@@ -1,6 +1,7 @@
/* XPM */
static char * condition_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c None",
". c #000000",
"+ c #5F5F5F",
diff -ru was/dia-0.86/objects/SADT/pixmaps/arrow.xpm
fixed/dia-0.86/objects/SADT/pixmaps/arrow.xpm
--- was/dia-0.86/objects/SADT/pixmaps/arrow.xpm Thu Jan 27 00:58:12 2000
+++ fixed/dia-0.86/objects/SADT/pixmaps/arrow.xpm Fri Dec 22 01:19:34 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * arrow_xpm[] = {
-"22 22 4 1",
+"22 22 5 1",
+"? c #000003",
" c None",
". c #00FC00",
"+ c #000000",
diff -ru was/dia-0.86/objects/SADT/pixmaps/sadtbox.xpm
fixed/dia-0.86/objects/SADT/pixmaps/sadtbox.xpm
--- was/dia-0.86/objects/SADT/pixmaps/sadtbox.xpm Thu Jan 27 00:58:12 2000
+++ fixed/dia-0.86/objects/SADT/pixmaps/sadtbox.xpm Fri Dec 22 01:19:56 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * sadtbox_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c None",
". c #000000",
"+ c #FFFFFF",
diff -ru was/dia-0.86/objects/UML/pixmaps/classicon.xpm
fixed/dia-0.86/objects/UML/pixmaps/classicon.xpm
--- was/dia-0.86/objects/UML/pixmaps/classicon.xpm Thu Jun 3 15:12:08 1999
+++ fixed/dia-0.86/objects/UML/pixmaps/classicon.xpm Fri Dec 22 01:21:36 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * classicon_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c none",
". c black",
"X c white",
diff -ru was/dia-0.86/objects/UML/pixmaps/generalization.xpm
fixed/dia-0.86/objects/UML/pixmaps/generalization.xpm
--- was/dia-0.86/objects/UML/pixmaps/generalization.xpm Thu Jun 3 15:12:08 1999
+++ fixed/dia-0.86/objects/UML/pixmaps/generalization.xpm Fri Dec 22 01:22:16
+2000
@@ -1,6 +1,7 @@
/* XPM */
static char * generalization_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c None",
". c #000000",
"+ c #FFFFFF",
diff -ru was/dia-0.86/objects/UML/pixmaps/implements.xpm
fixed/dia-0.86/objects/UML/pixmaps/implements.xpm
--- was/dia-0.86/objects/UML/pixmaps/implements.xpm Thu Jun 3 15:12:08 1999
+++ fixed/dia-0.86/objects/UML/pixmaps/implements.xpm Fri Dec 22 01:22:34 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * implements_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c None",
". c #000000",
"+ c #FFFFFF",
diff -ru was/dia-0.86/objects/UML/pixmaps/lifeline.xpm
fixed/dia-0.86/objects/UML/pixmaps/lifeline.xpm
--- was/dia-0.86/objects/UML/pixmaps/lifeline.xpm Thu Jun 3 15:12:08 1999
+++ fixed/dia-0.86/objects/UML/pixmaps/lifeline.xpm Fri Dec 22 01:22:58 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * lifeline_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c None",
". c black",
"X c white",
diff -ru was/dia-0.86/objects/UML/pixmaps/message.xpm
fixed/dia-0.86/objects/UML/pixmaps/message.xpm
--- was/dia-0.86/objects/UML/pixmaps/message.xpm Thu Jun 3 15:12:08 1999
+++ fixed/dia-0.86/objects/UML/pixmaps/message.xpm Fri Dec 22 01:33:36 2000
@@ -1,8 +1,7 @@
/* XPM */
static char * message_xpm[] = {
-"22 22 3 1",
+"22 22 2 1",
" c None",
-". c white",
"X c black",
" ",
" ",
diff -ru was/dia-0.86/objects/UML/pixmaps/realizes.xpm
fixed/dia-0.86/objects/UML/pixmaps/realizes.xpm
--- was/dia-0.86/objects/UML/pixmaps/realizes.xpm Thu Jun 3 15:12:09 1999
+++ fixed/dia-0.86/objects/UML/pixmaps/realizes.xpm Fri Dec 22 01:24:13 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * realizes_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000002",
" c None",
". c #000000",
"+ c #FFFFFF",
diff -ru was/dia-0.86/objects/chronogram/pixmaps/chronoline.xpm
fixed/dia-0.86/objects/chronogram/pixmaps/chronoline.xpm
--- was/dia-0.86/objects/chronogram/pixmaps/chronoline.xpm Wed Jan 26 03:54:38
2000
+++ fixed/dia-0.86/objects/chronogram/pixmaps/chronoline.xpm Fri Dec 22 01:40:26
+2000
@@ -1,6 +1,7 @@
/* XPM */
static char * chronoline_xpm[] = {
-"22 22 4 1",
+"22 22 5 1",
+"#? c #000004",
" c None",
". c #FF0000",
"+ c #FF8080",
diff -ru was/dia-0.86/objects/standard/pixmaps/arc.xpm
fixed/dia-0.86/objects/standard/pixmaps/arc.xpm
--- was/dia-0.86/objects/standard/pixmaps/arc.xpm Thu Jun 3 15:12:26 1999
+++ fixed/dia-0.86/objects/standard/pixmaps/arc.xpm Fri Dec 22 01:26:12 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * arc_xpm[] = {
-"22 22 4 1",
+"22 22 5 1",
+"? c #000003",
" c None",
". c #00FC00",
"+ c #000000",
diff -ru was/dia-0.86/objects/standard/pixmaps/bezier.xpm
fixed/dia-0.86/objects/standard/pixmaps/bezier.xpm
--- was/dia-0.86/objects/standard/pixmaps/bezier.xpm Sun Dec 5 11:25:06 1999
+++ fixed/dia-0.86/objects/standard/pixmaps/bezier.xpm Fri Dec 22 01:26:34 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * bezier_xpm[] = {
-"22 22 4 1",
+"22 22 5 1",
+"? c #000004",
" c None",
". c #F88010",
"+ c #00FC00",
diff -ru was/dia-0.86/objects/standard/pixmaps/line.xpm
fixed/dia-0.86/objects/standard/pixmaps/line.xpm
--- was/dia-0.86/objects/standard/pixmaps/line.xpm Thu Jun 3 15:12:26 1999
+++ fixed/dia-0.86/objects/standard/pixmaps/line.xpm Fri Dec 22 01:27:14 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * line_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+"? c #000003",
" c None",
". c #00FF00",
"+ c #000000",
diff -ru was/dia-0.86/objects/standard/pixmaps/polyline.xpm
fixed/dia-0.86/objects/standard/pixmaps/polyline.xpm
--- was/dia-0.86/objects/standard/pixmaps/polyline.xpm Thu Jun 3 15:12:26 1999
+++ fixed/dia-0.86/objects/standard/pixmaps/polyline.xpm Fri Dec 22 01:27:55
+2000
@@ -1,6 +1,7 @@
/* XPM */
static char * polyline_xpm[] = {
-"22 22 4 1",
+"22 22 5 1",
+"? c #000003",
" c None",
". c #00FC00",
"+ c #000000",
diff -ru was/dia-0.86/objects/standard/pixmaps/zigzag.xpm
fixed/dia-0.86/objects/standard/pixmaps/zigzag.xpm
--- was/dia-0.86/objects/standard/pixmaps/zigzag.xpm Thu Jun 3 15:12:26 1999
+++ fixed/dia-0.86/objects/standard/pixmaps/zigzag.xpm Fri Dec 22 01:28:03 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * zigzag_xpm[] = {
-"22 22 4 1",
+"22 22 5 1",
+"? c #000003",
" c None",
". c #00FC00",
"+ c #000000",
diff -ru was/dia-0.86/sheets/UML/aggregation.xpm
fixed/dia-0.86/sheets/UML/aggregation.xpm
--- was/dia-0.86/sheets/UML/aggregation.xpm Fri Nov 12 03:32:15 1999
+++ fixed/dia-0.86/sheets/UML/aggregation.xpm Fri Dec 22 01:36:19 2000
@@ -1,6 +1,7 @@
/* XPM */
static char * aggregation_xpm[] = {
-"22 22 3 1",
+"22 22 4 1",
+#? c #000002",
" c None",
". c #000000",
"+ c #FFFFFF",