Fossil SCM

Enhance the hash_color() function so that it can provide foreground colors in addition to background colors.

drh 2015-03-28 19:47 UTC trunk
Commit 9cd79bf009db63cd852c4b05e97316790f6ca1b7
+1 -1
--- src/branch.c
+++ src/branch.c
@@ -471,11 +471,11 @@
471471
}
472472
@ <ul>
473473
cnt++;
474474
}
475475
if( colorTest ){
476
- const char *zColor = hash_color(zBr);
476
+ const char *zColor = hash_color(zBr, 0);
477477
@ <li><span style="background-color: %s(zColor)">
478478
@ %h(zBr) &rarr; %s(zColor)</span></li>
479479
}else{
480480
@ <li>%z(href("%R/timeline?r=%T&n=200",zBr))%h(zBr)</a></li>
481481
}
482482
--- src/branch.c
+++ src/branch.c
@@ -471,11 +471,11 @@
471 }
472 @ <ul>
473 cnt++;
474 }
475 if( colorTest ){
476 const char *zColor = hash_color(zBr);
477 @ <li><span style="background-color: %s(zColor)">
478 @ %h(zBr) &rarr; %s(zColor)</span></li>
479 }else{
480 @ <li>%z(href("%R/timeline?r=%T&n=200",zBr))%h(zBr)</a></li>
481 }
482
--- src/branch.c
+++ src/branch.c
@@ -471,11 +471,11 @@
471 }
472 @ <ul>
473 cnt++;
474 }
475 if( colorTest ){
476 const char *zColor = hash_color(zBr, 0);
477 @ <li><span style="background-color: %s(zColor)">
478 @ %h(zBr) &rarr; %s(zColor)</span></li>
479 }else{
480 @ <li>%z(href("%R/timeline?r=%T&n=200",zBr))%h(zBr)</a></li>
481 }
482
+2 -2
--- src/finfo.c
+++ src/finfo.c
@@ -441,13 +441,13 @@
441441
nParent++;
442442
}
443443
db_reset(&qparent);
444444
if( zBr==0 ) zBr = "trunk";
445445
if( uBg ){
446
- zBgClr = hash_color(zUser);
446
+ zBgClr = hash_color(zUser, 0);
447447
}else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
448
- zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr);
448
+ zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr, 0);
449449
}
450450
gidx = graph_add_row(pGraph, frid>0 ? frid : fpid+1000000000,
451451
nParent, aParent, zBr, zBgClr,
452452
zUuid, 0);
453453
if( strncmp(zDate, zPrevDate, 10) ){
454454
--- src/finfo.c
+++ src/finfo.c
@@ -441,13 +441,13 @@
441 nParent++;
442 }
443 db_reset(&qparent);
444 if( zBr==0 ) zBr = "trunk";
445 if( uBg ){
446 zBgClr = hash_color(zUser);
447 }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
448 zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr);
449 }
450 gidx = graph_add_row(pGraph, frid>0 ? frid : fpid+1000000000,
451 nParent, aParent, zBr, zBgClr,
452 zUuid, 0);
453 if( strncmp(zDate, zPrevDate, 10) ){
454
--- src/finfo.c
+++ src/finfo.c
@@ -441,13 +441,13 @@
441 nParent++;
442 }
443 db_reset(&qparent);
444 if( zBr==0 ) zBr = "trunk";
445 if( uBg ){
446 zBgClr = hash_color(zUser, 0);
447 }else if( brBg || zBgClr==0 || zBgClr[0]==0 ){
448 zBgClr = strcmp(zBr,"trunk")==0 ? "" : hash_color(zBr, 0);
449 }
450 gidx = graph_add_row(pGraph, frid>0 ? frid : fpid+1000000000,
451 nParent, aParent, zBr, zBgClr,
452 zUuid, 0);
453 if( strncmp(zDate, zPrevDate, 10) ){
454
+2 -1
--- src/skins.c
+++ src/skins.c
@@ -142,11 +142,12 @@
142142
}
143143
}
144144
return zOut;
145145
}
146146
int skin_white_foreground(void){
147
- int rc;
147
+ static int rc = -1;
148
+ if( rc>=0 ) return rc;
148149
if( pAltSkin ){
149150
rc = pAltSkin->whiteForeground;
150151
}else{
151152
rc = db_get_boolean("white-foreground",0);
152153
}
153154
--- src/skins.c
+++ src/skins.c
@@ -142,11 +142,12 @@
142 }
143 }
144 return zOut;
145 }
146 int skin_white_foreground(void){
147 int rc;
 
148 if( pAltSkin ){
149 rc = pAltSkin->whiteForeground;
150 }else{
151 rc = db_get_boolean("white-foreground",0);
152 }
153
--- src/skins.c
+++ src/skins.c
@@ -142,11 +142,12 @@
142 }
143 }
144 return zOut;
145 }
146 int skin_white_foreground(void){
147 static int rc = -1;
148 if( rc>=0 ) return rc;
149 if( pAltSkin ){
150 rc = pAltSkin->whiteForeground;
151 }else{
152 rc = db_get_boolean("white-foreground",0);
153 }
154
+20 -21
--- src/timeline.c
+++ src/timeline.c
@@ -96,38 +96,34 @@
9696
#define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
9797
#define TIMELINE_SHOWRID 0x0400 /* Show RID values in addition to UUIDs */
9898
#endif
9999
100100
/*
101
-** Hash a string and use the hash to determine a background color.
101
+** Hash a string and use the hash to determine a background color or
102
+** foreground color.
102103
*/
103
-char *hash_color(const char *z){
104
+char *hash_color(const char *z, int bFgnd){
104105
int i; /* Loop counter */
105106
unsigned int h = 0; /* Hash on the branch name */
106107
int r, g, b; /* Values for red, green, and blue */
107108
int h1, h2, h3, h4; /* Elements of the hash value */
108109
int mx, mn; /* Components of HSV */
109110
static char zColor[10]; /* The resulting color */
110
- static int ix[2] = {0,0}; /* Color chooser parameters */
111
-
112
- if( ix[0]==0 ){
113
- if( db_get_boolean("white-foreground", 0) ){
114
- ix[0] = 140;
115
- ix[1] = 40;
116
- }else{
117
- ix[0] = 216;
118
- ix[1] = 16;
119
- }
120
- }
111
+
121112
for(i=0; z[i]; i++ ){
122113
h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
123114
}
124115
h1 = h % 6; h /= 6;
125116
h3 = h % 30; h /= 30;
126117
h4 = h % 40; h /= 40;
127
- mx = ix[0] - h3;
128
- mn = mx - h4 - ix[1];
118
+ if( bFgnd^skin_white_foreground() ){
119
+ mx = 140 - h3;
120
+ mn = mx - h4 - 40;
121
+ }else{
122
+ mx = 216 - h3;
123
+ mn = mx - h4 - 16;
124
+ }
129125
h2 = (h%(mx - mn)) + mn;
130126
switch( h1 ){
131127
case 0: r = mx; g = h2, b = mn; break;
132128
case 1: r = h2; g = mx, b = mn; break;
133129
case 2: r = mn; g = mx, b = h2; break;
@@ -148,11 +144,11 @@
148144
** testing the hash_color() function.
149145
*/
150146
void test_hash_color(void){
151147
int i;
152148
for(i=2; i<g.argc; i++){
153
- fossil_print("%20s: %s\n", g.argv[i], hash_color(g.argv[i]));
149
+ fossil_print("%20s: %s\n", g.argv[i], hash_color(g.argv[i], 0));
154150
}
155151
}
156152
157153
/*
158154
** WEBPAGE: hash-color-test
@@ -170,15 +166,18 @@
170166
style_header("Hash Color Test");
171167
for(i=cnt=0; i<10; i++){
172168
sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
173169
zBr = P(zNm);
174170
if( zBr && zBr[0] ){
175
- @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'>
176
- @ %h(zBr) - %s(hash_color(zBr)) -
171
+ @ <p>
172
+ @ <span style='border:1px solid;background-color:%s(hash_color(zBr,0));'>
173
+ @ %h(zBr) - %s(hash_color(zBr,0)) -
177174
@ Omnes nos quasi oves erravimus unusquisque in viam
178
- @ suam declinavit.</p>
175
+ @ suam declinavit.</span>
179176
cnt++;
177
+ @ <span style='color:%s(hash_color(zBr,1))'>
178
+ @ Corresponding foreground color: %s(hash_color(zBr,1))</span></p>
180179
}
181180
}
182181
if( cnt ){
183182
@ <hr>
184183
}
@@ -353,11 +352,11 @@
353352
}else {
354353
@ <tr>
355354
}
356355
@ <td class="timelineTime">%s(zTime)</td>
357356
@ <td class="timelineGraph">
358
- if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hash_color(zUser) : 0;
357
+ if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hash_color(zUser,0) : 0;
359358
if( zType[0]=='c'
360359
&& (pGraph || zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0)
361360
){
362361
db_reset(&qbranch);
363362
db_bind_int(&qbranch, ":rid", rid);
@@ -368,11 +367,11 @@
368367
}
369368
if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){
370369
if( zBr==0 || strcmp(zBr,"trunk")==0 ){
371370
zBgClr = 0;
372371
}else{
373
- zBgClr = hash_color(zBr);
372
+ zBgClr = hash_color(zBr,0);
374373
}
375374
}
376375
}
377376
if( zType[0]=='c' && (pGraph || (tmFlags & TIMELINE_BRCOLOR)!=0) ){
378377
int nParent = 0;
379378
--- src/timeline.c
+++ src/timeline.c
@@ -96,38 +96,34 @@
96 #define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
97 #define TIMELINE_SHOWRID 0x0400 /* Show RID values in addition to UUIDs */
98 #endif
99
100 /*
101 ** Hash a string and use the hash to determine a background color.
 
102 */
103 char *hash_color(const char *z){
104 int i; /* Loop counter */
105 unsigned int h = 0; /* Hash on the branch name */
106 int r, g, b; /* Values for red, green, and blue */
107 int h1, h2, h3, h4; /* Elements of the hash value */
108 int mx, mn; /* Components of HSV */
109 static char zColor[10]; /* The resulting color */
110 static int ix[2] = {0,0}; /* Color chooser parameters */
111
112 if( ix[0]==0 ){
113 if( db_get_boolean("white-foreground", 0) ){
114 ix[0] = 140;
115 ix[1] = 40;
116 }else{
117 ix[0] = 216;
118 ix[1] = 16;
119 }
120 }
121 for(i=0; z[i]; i++ ){
122 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
123 }
124 h1 = h % 6; h /= 6;
125 h3 = h % 30; h /= 30;
126 h4 = h % 40; h /= 40;
127 mx = ix[0] - h3;
128 mn = mx - h4 - ix[1];
 
 
 
 
 
129 h2 = (h%(mx - mn)) + mn;
130 switch( h1 ){
131 case 0: r = mx; g = h2, b = mn; break;
132 case 1: r = h2; g = mx, b = mn; break;
133 case 2: r = mn; g = mx, b = h2; break;
@@ -148,11 +144,11 @@
148 ** testing the hash_color() function.
149 */
150 void test_hash_color(void){
151 int i;
152 for(i=2; i<g.argc; i++){
153 fossil_print("%20s: %s\n", g.argv[i], hash_color(g.argv[i]));
154 }
155 }
156
157 /*
158 ** WEBPAGE: hash-color-test
@@ -170,15 +166,18 @@
170 style_header("Hash Color Test");
171 for(i=cnt=0; i<10; i++){
172 sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
173 zBr = P(zNm);
174 if( zBr && zBr[0] ){
175 @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'>
176 @ %h(zBr) - %s(hash_color(zBr)) -
 
177 @ Omnes nos quasi oves erravimus unusquisque in viam
178 @ suam declinavit.</p>
179 cnt++;
 
 
180 }
181 }
182 if( cnt ){
183 @ <hr>
184 }
@@ -353,11 +352,11 @@
353 }else {
354 @ <tr>
355 }
356 @ <td class="timelineTime">%s(zTime)</td>
357 @ <td class="timelineGraph">
358 if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hash_color(zUser) : 0;
359 if( zType[0]=='c'
360 && (pGraph || zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0)
361 ){
362 db_reset(&qbranch);
363 db_bind_int(&qbranch, ":rid", rid);
@@ -368,11 +367,11 @@
368 }
369 if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){
370 if( zBr==0 || strcmp(zBr,"trunk")==0 ){
371 zBgClr = 0;
372 }else{
373 zBgClr = hash_color(zBr);
374 }
375 }
376 }
377 if( zType[0]=='c' && (pGraph || (tmFlags & TIMELINE_BRCOLOR)!=0) ){
378 int nParent = 0;
379
--- src/timeline.c
+++ src/timeline.c
@@ -96,38 +96,34 @@
96 #define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
97 #define TIMELINE_SHOWRID 0x0400 /* Show RID values in addition to UUIDs */
98 #endif
99
100 /*
101 ** Hash a string and use the hash to determine a background color or
102 ** foreground color.
103 */
104 char *hash_color(const char *z, int bFgnd){
105 int i; /* Loop counter */
106 unsigned int h = 0; /* Hash on the branch name */
107 int r, g, b; /* Values for red, green, and blue */
108 int h1, h2, h3, h4; /* Elements of the hash value */
109 int mx, mn; /* Components of HSV */
110 static char zColor[10]; /* The resulting color */
111
 
 
 
 
 
 
 
 
 
 
112 for(i=0; z[i]; i++ ){
113 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i];
114 }
115 h1 = h % 6; h /= 6;
116 h3 = h % 30; h /= 30;
117 h4 = h % 40; h /= 40;
118 if( bFgnd^skin_white_foreground() ){
119 mx = 140 - h3;
120 mn = mx - h4 - 40;
121 }else{
122 mx = 216 - h3;
123 mn = mx - h4 - 16;
124 }
125 h2 = (h%(mx - mn)) + mn;
126 switch( h1 ){
127 case 0: r = mx; g = h2, b = mn; break;
128 case 1: r = h2; g = mx, b = mn; break;
129 case 2: r = mn; g = mx, b = h2; break;
@@ -148,11 +144,11 @@
144 ** testing the hash_color() function.
145 */
146 void test_hash_color(void){
147 int i;
148 for(i=2; i<g.argc; i++){
149 fossil_print("%20s: %s\n", g.argv[i], hash_color(g.argv[i], 0));
150 }
151 }
152
153 /*
154 ** WEBPAGE: hash-color-test
@@ -170,15 +166,18 @@
166 style_header("Hash Color Test");
167 for(i=cnt=0; i<10; i++){
168 sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
169 zBr = P(zNm);
170 if( zBr && zBr[0] ){
171 @ <p>
172 @ <span style='border:1px solid;background-color:%s(hash_color(zBr,0));'>
173 @ %h(zBr) - %s(hash_color(zBr,0)) -
174 @ Omnes nos quasi oves erravimus unusquisque in viam
175 @ suam declinavit.</span>
176 cnt++;
177 @ <span style='color:%s(hash_color(zBr,1))'>
178 @ Corresponding foreground color: %s(hash_color(zBr,1))</span></p>
179 }
180 }
181 if( cnt ){
182 @ <hr>
183 }
@@ -353,11 +352,11 @@
352 }else {
353 @ <tr>
354 }
355 @ <td class="timelineTime">%s(zTime)</td>
356 @ <td class="timelineGraph">
357 if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hash_color(zUser,0) : 0;
358 if( zType[0]=='c'
359 && (pGraph || zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0)
360 ){
361 db_reset(&qbranch);
362 db_bind_int(&qbranch, ":rid", rid);
@@ -368,11 +367,11 @@
367 }
368 if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){
369 if( zBr==0 || strcmp(zBr,"trunk")==0 ){
370 zBgClr = 0;
371 }else{
372 zBgClr = hash_color(zBr,0);
373 }
374 }
375 }
376 if( zType[0]=='c' && (pGraph || (tmFlags & TIMELINE_BRCOLOR)!=0) ){
377 int nParent = 0;
378

Keyboard Shortcuts

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