Re: system colors

"corvid" <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <20110917011825.GA23909@local>
Here's one with preferences as well as some code to ensure that
FL_SELECTION_COLOR has contrast:

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
colors.diff (text/plain, 8.5 KB)
diff -r c241d93e7673 dillorc
--- a/dillorc	Sat Sep 17 00:53:05 2011 +0000
+++ b/dillorc	Sat Sep 17 01:08:27 2011 +0000
@@ -173,7 +173,14 @@
 #                            COLORS SECTION
 #-------------------------------------------------------------------------
 
-# Set the background color
+# Override the user interface colors. By default, these colors may be drawn
+# from your system or environment.
+#
+# ui_fg_color=black
+# ui_main_bg_color=silver
+# ui_text_bg_color=white
+
+# Set the page background color
 # bg_color=gray
 # bg_color=0xd6d6c0
 #bg_color=0xdcd1ba
diff -r c241d93e7673 src/dialog.cc
--- a/src/dialog.cc	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/dialog.cc	Sat Sep 17 01:08:27 2011 +0000
@@ -171,7 +171,6 @@
     ch->tooltip("Select search engine");
     ch->menu(pm);
     ch->value(prefs.search_url_idx);
-    ch->textcolor(FL_DARK_BLUE);
 
     int xpos = ww-2*(gap+bw), ypos = ih+3*gap;
     Fl_Return_Button *rb = new Fl_Return_Button(xpos, ypos, bw, bh, "OK");
diff -r c241d93e7673 src/dillo.cc
--- a/src/dillo.cc	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/dillo.cc	Sat Sep 17 01:08:27 2011 +0000
@@ -233,6 +233,12 @@
    checkFont(prefs.font_fantasy, "fantasy");
 }
 
+static void setColor(int32_t color, void (*fn) (uchar, uchar, uchar))
+{
+   if (color != -1)
+      fn(color >> 16, (color >> 8) & 0xff, color & 0xff);
+}
+
 /*
  * Given a command line argument, build a DilloUrl for it.
  */
@@ -395,6 +401,18 @@
     */
    ((Fl_Widget *)bw->ui)->window()->make_current();
 
+   /* If the preference was set, we set that value. Otherwise,
+    * Fl::get_system_colors() will fill it in.
+    */
+   setColor(prefs.ui_fg_color, Fl::foreground);
+   setColor(prefs.ui_main_bg_color, Fl::background);
+   setColor(prefs.ui_text_bg_color, Fl::background2);
+   Fl::get_system_colors();
+
+   unsigned rgb = Fl::get_color(fl_contrast(FL_SELECTION_COLOR,
+                                            FL_BACKGROUND2_COLOR));
+   Fl::set_color(FL_SELECTION_COLOR, rgb);
+
    /* Proxy authentication */
    if (prefs.http_proxyuser && !a_Http_proxy_auth()) {
       const char *passwd = a_UIcmd_get_passwd(prefs.http_proxyuser);
diff -r c241d93e7673 src/findbar.cc
--- a/src/findbar.cc	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/findbar.cc	Sat Sep 17 01:08:27 2011 +0000
@@ -131,7 +131,6 @@
     i = new MyInput(x, border, input_width, height);
     x += input_width + gap;
     resizable(i);
-    i->color(206);
     i->when(FL_WHEN_NEVER);
    add(i);
 
diff -r c241d93e7673 src/prefs.c
--- a/src/prefs.c	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/prefs.c	Sat Sep 17 01:08:27 2011 +0000
@@ -100,6 +100,9 @@
    prefs.small_icons = FALSE;
    prefs.start_page = a_Url_new(PREFS_START_PAGE, NULL);
    prefs.theme = dStrdup(PREFS_THEME);
+   prefs.ui_fg_color = -1;
+   prefs.ui_main_bg_color = -1;
+   prefs.ui_text_bg_color = -1;
    prefs.w3c_plus_heuristics = TRUE;
 }
 
diff -r c241d93e7673 src/prefs.h
--- a/src/prefs.h	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/prefs.h	Sat Sep 17 01:08:27 2011 +0000
@@ -47,6 +47,9 @@
    DilloUrl *home;
    bool_t allow_white_bg;
    int32_t bg_color;
+   int32_t ui_fg_color;
+   int32_t ui_main_bg_color;
+   int32_t ui_text_bg_color;
    bool_t contrast_visited_color;
    bool_t show_tooltip;
    char *theme;
diff -r c241d93e7673 src/prefsparser.cc
--- a/src/prefsparser.cc	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/prefsparser.cc	Sat Sep 17 01:08:27 2011 +0000
@@ -108,6 +108,9 @@
       { "small_icons", &prefs.small_icons, PREFS_BOOL },
       { "start_page", &prefs.start_page, PREFS_URL },
       { "theme", &prefs.theme, PREFS_STRING },
+      { "ui_fg_color", &prefs.ui_fg_color, PREFS_COLOR },
+      { "ui_main_bg_color", &prefs.ui_main_bg_color, PREFS_COLOR },
+      { "ui_text_bg_color", &prefs.ui_text_bg_color, PREFS_COLOR },
       { "w3c_plus_heuristics", &prefs.w3c_plus_heuristics, PREFS_BOOL }
    };
 
diff -r c241d93e7673 src/ui.cc
--- a/src/ui.cc	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/ui.cc	Sat Sep 17 01:08:27 2011 +0000
@@ -219,10 +219,6 @@
 
    if (b == FL_LEFT_MOUSE) {
       a_UIcmd_search_dialog(a_UIcmd_get_bw_by_widget(wid));
-   } else if (b == FL_MIDDLE_MOUSE) {
-      ((UI*)data)->color_change_cb_i();
-   } else if (b == FL_RIGHT_MOUSE) {
-      // nothing ATM
    }
 }
 
@@ -437,7 +433,6 @@
     p_xpos += b->w();
 
     Fl_Input *i = Location = new CustInput(p_xpos,0,ww-p_xpos-32,lh,0);
-    i->color(CuteColor);
     i->when(FL_WHEN_ENTER_KEY);
     i->callback(location_cb, this);
     i->tooltip("Location");
@@ -470,14 +465,12 @@
     IProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
     IProg->labelsize(12);
     IProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
-    IProg->labelcolor(FL_GRAY_RAMP + 2);
     IProg->update_label(wide ? "Images\n0 of 0" : "0 of 0");
     p_xpos += pw;
     // Page
     PProg = new CustProgressBox(p_xpos,p_ypos,pw,bh);
     PProg->labelsize(12);
     PProg->box(thin_up ? FL_THIN_UP_BOX : FL_EMBOSSED_BOX);
-    PProg->labelcolor(FL_GRAY_RAMP + 2);
     PProg->update_label(wide ? "Page\n0.0KB" : "0.0KB");
 }
 
@@ -638,14 +631,12 @@
    PanelTemporary = false;
    if (cur_ui) {
       PanelSize = cur_ui->PanelSize;
-      CuteColor = cur_ui->CuteColor;
       Small_Icons = cur_ui->Small_Icons;
       Panelmode = cur_ui->Panelmode;
    } else {
      // Set some default values
      PanelSize = prefs.panel_size;
      Small_Icons = prefs.small_icons;
-     CuteColor = 206;
      Panelmode = (prefs.fullwindow_start) ? UI_HIDDEN : UI_NORMAL;
    }
 
@@ -657,11 +648,9 @@
     Main = new Fl_Group(0,0,0,0,"Welcome..."); // size is set by rearrange()
     Main->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
     Main->box(FL_FLAT_BOX);
-    Main->color(FL_GRAY_RAMP + 3);
     Main->labelfont(FL_HELVETICA_BOLD_ITALIC);
     Main->labelsize(36);
     Main->labeltype(FL_SHADOW_LABEL);
-    Main->labelcolor(FL_WHITE);
     TopGroup->add(Main);
     TopGroup->resizable(Main);
     MainIdx = TopGroup->find(Main);
@@ -975,21 +964,6 @@
 }
 
 /*
- * On-the-fly color style change
- */
-void UI::color_change_cb_i()
-{
-   const int cols[] = {7,17,26,51,140,156,205,206,215,-1};
-   static int ncolor = 0;
-
-   ncolor = (cols[ncolor+1] < 0) ? 0 : ncolor + 1;
-   CuteColor = cols[ncolor];
-   MSG("Location color %d\n", CuteColor);
-   Location->color(CuteColor);
-   Location->redraw();
-}
-
-/*
  * Set 'nw' as the main render area widget
  */
 void UI::set_render_layout(Fl_Group *nw)
diff -r c241d93e7673 src/ui.hh
--- a/src/ui.hh	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/ui.hh	Sat Sep 17 01:08:27 2011 +0000
@@ -161,7 +161,7 @@
 
    int MainIdx;
    // Panel customization variables
-   int PanelSize, CuteColor, Small_Icons;
+   int PanelSize, Small_Icons;
    int p_xpos, p_ypos, bw, bh, mh, lh, nh, fh, sh, pw, lbl;
    bool PanelTemporary;
 
diff -r c241d93e7673 src/uicmd.cc
--- a/src/uicmd.cc	Sat Sep 17 00:53:05 2011 +0000
+++ b/src/uicmd.cc	Sat Sep 17 01:08:27 2011 +0000
@@ -107,7 +107,8 @@
       Fl_Group(0,0,ww,th,lbl) {
       Pack = NULL;
       tab_w = 50, tab_h = th, ctab_h = 1, btn_w = 20, ctl_w = 1*btn_w+2;
-      tabcolor_active = 0x87aca700; tabcolor_inactive = 0xb7beb700;
+      tabcolor_active = FL_SELECTION_COLOR;
+      tabcolor_inactive = FL_BACKGROUND_COLOR;
       resize(0,0,ww,ctab_h);
       /* tab buttons go inside a pack within a scroll */
       Scroll = new Fl_Scroll(0,0,ww-ctl_w,ctab_h);
@@ -124,8 +125,6 @@
       Control = new Fl_Group(ww-ctl_w,0,ctl_w,ctab_h);
        CloseBtn = new CustLightButton(ww-ctl_w+2,0,btn_w,ctab_h, "X");
        CloseBtn->box(FL_THIN_UP_BOX);
-       CloseBtn->labelcolor(0x00641000);
-       CloseBtn->hl_color(FL_WHITE);
        CloseBtn->clear_visible_focus();
        CloseBtn->tooltip(prefs.right_click_closes_tab ?
           "Close current tab.\nor Right-click tab label to close." :
@@ -254,6 +253,8 @@
    btn->clear_visible_focus();
    btn->box(FL_GTK_THIN_UP_BOX);
    btn->color(focus ? tabcolor_active : tabcolor_inactive);
+   btn->labelcolor(fl_contrast(FL_FOREGROUND_COLOR,
+                   focus ? tabcolor_active : tabcolor_inactive));
    btn->ui(new_ui);
    btn->callback(tab_btn_cb, this);
    Pack->add(btn); // append
@@ -366,10 +367,12 @@
       if ((idx = get_btn_idx(old_ui)) != -1) {
          btn = (CustTabButton*)Pack->child(idx);
          btn->color(tabcolor_inactive);
+         btn->labelcolor(fl_contrast(FL_FOREGROUND_COLOR, tabcolor_inactive));
          btn->redraw();
       }
       Wizard->value(cbtn->ui());
       cbtn->color(tabcolor_active);
+      cbtn->labelcolor(fl_contrast(FL_FOREGROUND_COLOR, tabcolor_active));
       cbtn->redraw();
       update_pack_offset();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.