Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Improvements to /test-bgcolor to show the requested color and both light-mode and dark-mode background colors all at once. Also prepopulate the entry boxes with a selection of colors. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
a390c6ba5a32d18a40a1d34dbf5fcbba |
| User & Date: | drh 2025-03-26 09:54:52.176 |
Context
|
2025-03-26
| ||
| 10:22 | Add the "raw-bgcolor" setting, defaulting to "off" but if turned "on" disables the background color filter. ... (check-in: f23d9ab878 user: drh tags: trunk) | |
| 09:54 | Improvements to /test-bgcolor to show the requested color and both light-mode and dark-mode background colors all at once. Also prepopulate the entry boxes with a selection of colors. ... (check-in: a390c6ba5a user: drh tags: trunk) | |
|
2025-03-25
| ||
| 23:57 | Add a new routine "reasonable_bg_color()" that tries to transform a user-requested background color for a check-in or branch into a color that is appropriate for the current skin. The /test-bgcolor web page was added for testing the algorithm. With this enhancement, it is ok to add back the the --bgcolor and --branchcolor options to "fossil commit". ... (check-in: f7a18cfcaf user: drh tags: trunk) | |
Changes
Changes to src/branch.c.
| ︙ | ︙ | |||
868 869 870 871 872 873 874 |
const char *zMergeTo = db_column_text(&q, 3);
int nCkin = db_column_int(&q, 4);
const char *zLastCkin = db_column_text(&q, 5);
const char *zBgClr = db_column_text(&q, 6);
char *zAge = human_readable_age(rNow - rMtime);
sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0);
if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0;
| | | 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
const char *zMergeTo = db_column_text(&q, 3);
int nCkin = db_column_int(&q, 4);
const char *zLastCkin = db_column_text(&q, 5);
const char *zBgClr = db_column_text(&q, 6);
char *zAge = human_readable_age(rNow - rMtime);
sqlite3_int64 iMtime = (sqlite3_int64)(rMtime*86400.0);
if( zMergeTo && zMergeTo[0]==0 ) zMergeTo = 0;
if( zBgClr ) zBgClr = reasonable_bg_color(zBgClr, 0);
if( zBgClr==0 ){
if( zBranch==0 || strcmp(zBranch,"trunk")==0 ){
zBgClr = 0;
}else{
zBgClr = hash_color(zBranch);
}
}
|
| ︙ | ︙ |
Changes to src/color.c.
| ︙ | ︙ | |||
182 183 184 185 186 187 188 |
int color_name_to_rgb(const char *zName){
if( zName==0 || zName[0]==0 ) return -1;
if( zName[0]=='#' ){
int i, v = 0;
for(i=1; i<=6 && fossil_isxdigit(zName[i]); i++){
v = v*16 + fossil_hexvalue(zName[i]);
}
| > > | > > | > > | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
int color_name_to_rgb(const char *zName){
if( zName==0 || zName[0]==0 ) return -1;
if( zName[0]=='#' ){
int i, v = 0;
for(i=1; i<=6 && fossil_isxdigit(zName[i]); i++){
v = v*16 + fossil_hexvalue(zName[i]);
}
if( i==4 ){
for(v=0, i=1; i<4; i++) v = v*256 + fossil_hexvalue(zName[i]);
return v;
}
if( i==7 ){
return v;
}
return -1;
}else if( sqlite3_strlike("rgb%)", zName,0)==0 ){
return -1;
}else if( sqlite3_strlike("hsl%)",zName,0)==0 ){
return -1;
}else{
int iMin = 0;
int iMax = count(aCssColors)-1;
|
| ︙ | ︙ | |||
214 215 216 217 218 219 220 221 | ** for use as a background color in the current skin. ** ** The return value is a #HHHHHH color name contained in ** static space that is overwritten on the next call. ** ** If we cannot make sense of the background color recommendation ** that is the input, then return NULL. */ | > > > | | > > > > > > > > > | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
** for use as a background color in the current skin.
**
** The return value is a #HHHHHH color name contained in
** static space that is overwritten on the next call.
**
** If we cannot make sense of the background color recommendation
** that is the input, then return NULL.
**
** The iFgClr parameter is normally 0. But for testing purposes, set
** it to 1 for a black foregrounds and 2 for a white foreground.
*/
char *reasonable_bg_color(const char *zRequested, int iFgClr){
int iRGB = color_name_to_rgb(zRequested);
int cc[3];
int lo, hi;
int r, g, b;
static int systemFg = 0; /* 1==black-foreground 2==white-foreground */
int fg;
static char zColor[10];
int K = 70; /* Tune for background color saturation */
if( iFgClr ){
fg = iFgClr;
}else if( systemFg==0 ){
fg = systemFg = skin_detail_boolean("white-foreground") ? 2 : 1;
}else{
fg = systemFg;
}
if( iRGB<0 ) return 0;
if( fg==0 ) fg = skin_detail_boolean("white-foreground") ? 2 : 1;
cc[0] = (iRGB>>16) & 0xff;
cc[1] = (iRGB>>8) & 0xff;
cc[2] = iRGB & 0xff;
lo = cc[0]<cc[1] ? 0 : 1;
|
| ︙ | ︙ | |||
427 428 429 430 431 432 433 434 |
**
** Show how user-specified background colors will be rendered
** using the reasonable_bg_color() algorithm.
*/
void test_bgcolor_page(void){
const char *zReq; /* Requested color name */
const char *zBG; /* Actual color provided */
char zNm[10];
| > > > > > | > | > > > > > > > > > | > | > > > > > > > > > > > | | | < | | < > > > > > > > | > | 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
**
** Show how user-specified background colors will be rendered
** using the reasonable_bg_color() algorithm.
*/
void test_bgcolor_page(void){
const char *zReq; /* Requested color name */
const char *zBG; /* Actual color provided */
const char *zBg1;
char zNm[10];
static const char *azDflt[] = {
"red", "orange", "yellow", "green", "blue", "indigo", "violet",
"tan", "brown", "gray"
};
int i, cnt, iClr, r, g, b;
char *zFg;
login_check_credentials();
style_set_current_feature("test");
style_header("Background Color Test");
for(i=cnt=0; i<10; i++){
sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
zReq = PD(zNm,azDflt[i]);
if( zReq==0 || zReq[0]==0 ) continue;
if( cnt==0 ){
@ <table border="1" cellspacing="0" cellpadding="10">
@ <tr>
@ <th>Requested Background
@ <th>Light mode
@ <th>Dark mode
@ </tr>
}
cnt++;
zBG = reasonable_bg_color(zReq, 0);
if( zBG==0 ){
@ <tr><td colspan="3" align="center">\
@ "%h(zReq)" is not a recognized color name</td></tr>
continue;
}
iClr = color_name_to_rgb(zReq);
r = (iClr>>16) & 0xff;
g = (iClr>>8) & 0xff;
b = iClr & 0xff;
if( 3*r + 6*g + b > 5*255 ){
zFg = "black";
}else{
zFg = "white";
}
if( zReq[0]!='#' ){
char zReqRGB[12];
sqlite3_snprintf(sizeof(zReqRGB),zReqRGB,"#%06x",color_name_to_rgb(zReq));
@ <tr><td style='color:%h(zFg);background-color:%h(zReq);'>\
@ Requested color "%h(zReq)" (%h(zReqRGB))</td>
}else{
@ <tr><td style='color:%h(zFg);background-color:%s(zReq);'>\
@ Requested color "%h(zReq)"</td>
}
zBg1 = reasonable_bg_color(zReq,1);
@ <td style='color:black;background-color:%h(zBg1);'>\
@ Background color for dark text: %h(zBg1)</td>
zBg1 = reasonable_bg_color(zReq,2);
@ <td style='color:white;background-color:%h(zBg1);'>\
@ Background color for light text: %h(zBg1)</td></tr>
}
if( cnt ){
@ </table>
@ <hr>
}
@ <form method="POST">
@ <p>Enter CSS color names below and see them shifted into corresponding
@ background colors above.</p>
for(i=0; i<10; i++){
sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i);
@ <input type="text" size="30" name='%s(zNm)' \
@ value='%h(PD(zNm,azDflt[i]))'><br>
}
@ <input type="submit" value="Submit">
@ </form>
style_finish_page();
}
|
Changes to src/timeline.c.
| ︙ | ︙ | |||
422 423 424 425 426 427 428 |
}else{
zBgClr = hash_color("f"); /* delta manifest */
}
db_reset(&qdelta);
}
}else{
/* Make sure the user-specified background color is reasonable */
| | | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
}else{
zBgClr = hash_color("f"); /* delta manifest */
}
db_reset(&qdelta);
}
}else{
/* Make sure the user-specified background color is reasonable */
zBgClr = reasonable_bg_color(zBgClr, 0);
}
if( zType[0]=='c'
&& (pGraph || zBgClr==0 || (tmFlags & (TIMELINE_BRCOLOR|TIMELINE_DELTA))!=0)
){
zBr = branch_of_rid(rid);
if( zBgClr==0 || (tmFlags & TIMELINE_BRCOLOR)!=0 ){
/* If no background color is specified, use a color based on the
|
| ︙ | ︙ |