Fossil SCM

Improvements to the automatic background color chooser. Provide a setting which alters the algorithm to work with a light-color foreground.

drh 2011-07-23 22:05 trunk
Commit ce4a44d931dfb3c0194c6d3b704010205f78c4b5
2 files changed +1 +19 -7
+1
--- src/db.c
+++ src/db.c
@@ -1669,10 +1669,11 @@
16691669
{ "proxy", 0, 32, "off" },
16701670
{ "repo-cksum", 0, 0, "on" },
16711671
{ "self-register", 0, 0, "off" },
16721672
{ "ssh-command", 0, 32, "" },
16731673
{ "web-browser", 0, 32, "" },
1674
+ { "white-foreground", 0, 0, "off" },
16741675
{ 0,0,0,0 }
16751676
};
16761677
16771678
/*
16781679
** COMMAND: settings
16791680
--- src/db.c
+++ src/db.c
@@ -1669,10 +1669,11 @@
1669 { "proxy", 0, 32, "off" },
1670 { "repo-cksum", 0, 0, "on" },
1671 { "self-register", 0, 0, "off" },
1672 { "ssh-command", 0, 32, "" },
1673 { "web-browser", 0, 32, "" },
 
1674 { 0,0,0,0 }
1675 };
1676
1677 /*
1678 ** COMMAND: settings
1679
--- src/db.c
+++ src/db.c
@@ -1669,10 +1669,11 @@
1669 { "proxy", 0, 32, "off" },
1670 { "repo-cksum", 0, 0, "on" },
1671 { "self-register", 0, 0, "off" },
1672 { "ssh-command", 0, 32, "" },
1673 { "web-browser", 0, 32, "" },
1674 { "white-foreground", 0, 0, "off" },
1675 { 0,0,0,0 }
1676 };
1677
1678 /*
1679 ** COMMAND: settings
1680
+19 -7
--- src/timeline.c
+++ src/timeline.c
@@ -118,21 +118,33 @@
118118
*/
119119
const char *hashColor(const char *z){
120120
int i; /* Loop counter */
121121
unsigned int h = 0; /* Hash on the branch name */
122122
int r, g, b; /* Values for red, green, and blue */
123
- int mx, mn, h1, h2; /* Components of HSV */
123
+ int h1, h2, h3, h4; /* Elements of the hash value */
124
+ int mx, mn; /* Components of HSV */
124125
static char zColor[10]; /* The resulting color */
126
+ static int ix[2] = {0,0}; /* Color chooser parameters */
125127
128
+ if( ix[0]==0 ){
129
+ if( db_get_boolean("white-foreground", 0) ){
130
+ ix[0] = 140;
131
+ ix[1] = 40;
132
+ }else{
133
+ ix[0] = 216;
134
+ ix[1] = 16;
135
+ }
136
+ }
126137
for(i=0; z[i]; i++ ){
127
- h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[0];
128
- z++;
138
+ h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
129139
}
130
- mx = 0xd1;
131
- mn = 0xa8;
132
- h1 = h%6;
133
- h2 = ((h/6)%(mx - mn)) + mn;
140
+ h1 = h % 6; h /= 6;
141
+ h3 = h % 30; h /= 30;
142
+ h4 = h % 40; h /= 40;
143
+ mx = ix[0] - h3;
144
+ mn = mx - h4 - ix[1];
145
+ h2 = (h%(mx - mn)) + mn;
134146
switch( h1 ){
135147
case 0: r = mx; g = h2, b = mn; break;
136148
case 1: r = h2; g = mx, b = mn; break;
137149
case 2: r = mn; g = mx, b = h2; break;
138150
case 3: r = mn; g = h2, b = mx; break;
139151
--- src/timeline.c
+++ src/timeline.c
@@ -118,21 +118,33 @@
118 */
119 const char *hashColor(const char *z){
120 int i; /* Loop counter */
121 unsigned int h = 0; /* Hash on the branch name */
122 int r, g, b; /* Values for red, green, and blue */
123 int mx, mn, h1, h2; /* Components of HSV */
 
124 static char zColor[10]; /* The resulting color */
 
125
 
 
 
 
 
 
 
 
 
126 for(i=0; z[i]; i++ ){
127 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[0];
128 z++;
129 }
130 mx = 0xd1;
131 mn = 0xa8;
132 h1 = h%6;
133 h2 = ((h/6)%(mx - mn)) + mn;
 
 
134 switch( h1 ){
135 case 0: r = mx; g = h2, b = mn; break;
136 case 1: r = h2; g = mx, b = mn; break;
137 case 2: r = mn; g = mx, b = h2; break;
138 case 3: r = mn; g = h2, b = mx; break;
139
--- src/timeline.c
+++ src/timeline.c
@@ -118,21 +118,33 @@
118 */
119 const char *hashColor(const char *z){
120 int i; /* Loop counter */
121 unsigned int h = 0; /* Hash on the branch name */
122 int r, g, b; /* Values for red, green, and blue */
123 int h1, h2, h3, h4; /* Elements of the hash value */
124 int mx, mn; /* Components of HSV */
125 static char zColor[10]; /* The resulting color */
126 static int ix[2] = {0,0}; /* Color chooser parameters */
127
128 if( ix[0]==0 ){
129 if( db_get_boolean("white-foreground", 0) ){
130 ix[0] = 140;
131 ix[1] = 40;
132 }else{
133 ix[0] = 216;
134 ix[1] = 16;
135 }
136 }
137 for(i=0; z[i]; i++ ){
138 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
 
139 }
140 h1 = h % 6; h /= 6;
141 h3 = h % 30; h /= 30;
142 h4 = h % 40; h /= 40;
143 mx = ix[0] - h3;
144 mn = mx - h4 - ix[1];
145 h2 = (h%(mx - mn)) + mn;
146 switch( h1 ){
147 case 0: r = mx; g = h2, b = mn; break;
148 case 1: r = h2; g = mx, b = mn; break;
149 case 2: r = mn; g = mx, b = h2; break;
150 case 3: r = mn; g = h2, b = mx; break;
151

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button