Mercurial > emacs
comparison src/xterm.c @ 33449:41fcaa0b864b
(x_alloc_lighter_color): Include an additive component too for dark
colors, because FACTOR isn't enough.
(HIGHLIGHT_COLOR_DARK_BOOST, HIGHLIGHT_COLOR_DARK_BOOST_LIMIT):
New macros.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 13 Nov 2000 15:47:32 +0000 |
parents | 1dc1953987a7 |
children | d8d4ecfa24fd |
comparison
equal
deleted
inserted
replaced
33448:21903c0f782c | 33449:41fcaa0b864b |
---|---|
3487 #endif | 3487 #endif |
3488 return color.pixel; | 3488 return color.pixel; |
3489 } | 3489 } |
3490 | 3490 |
3491 | 3491 |
3492 | |
3493 /* Constants used by x_alloc_lighter_color. */ | |
3494 | |
3495 /* How much to boost the brightness of 3d highlights for dark colors. | |
3496 Nominally, highlight colors for `3d' faces are calculated by | |
3497 brightening an object's color by a constant factor. If | |
3498 `highlight-color-dark-boost' is a floating point number between 0 and | |
3499 1, colors darker than `highlight-color-dark-boost-limit' have their | |
3500 highlight factor increased: a value of 0 means no increase at all, | |
3501 and greater values yield correspondingly greater increases. */ | |
3502 #define HIGHLIGHT_COLOR_DARK_BOOST 0.7 | |
3503 | |
3504 /* Brightness beyond which a color won't have its highlight brightness | |
3505 boosted. See HIGHLIGHT_COLOR_DARK_BOOST. | |
3506 | |
3507 The `brightness' of a color, for this purpose, is defined to be the | |
3508 maximum of the color's red, green, or blue components, as returned by | |
3509 `color-values'. | |
3510 | |
3511 The value here is set so that the default menu-bar/mode-line color | |
3512 (grey75) will not have its highlights changed at all. */ | |
3513 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000 | |
3514 | |
3515 | |
3492 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR | 3516 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR |
3493 or DELTA. Try a color with RGB values multiplied by FACTOR first. | 3517 or DELTA. Try a color with RGB values multiplied by FACTOR first. |
3494 If this produces the same color as PIXEL, try a color where all RGB | 3518 If this produces the same color as PIXEL, try a color where all RGB |
3495 values have DELTA added. Return the allocated color in *PIXEL. | 3519 values have DELTA added. Return the allocated color in *PIXEL. |
3496 DISPLAY is the X display, CMAP is the colormap to operate on. | 3520 DISPLAY is the X display, CMAP is the colormap to operate on. |
3504 unsigned long *pixel; | 3528 unsigned long *pixel; |
3505 double factor; | 3529 double factor; |
3506 int delta; | 3530 int delta; |
3507 { | 3531 { |
3508 XColor color, new; | 3532 XColor color, new; |
3533 long bright; | |
3509 int success_p; | 3534 int success_p; |
3510 | 3535 |
3511 /* Get RGB color values. */ | 3536 /* Get RGB color values. */ |
3512 color.pixel = *pixel; | 3537 color.pixel = *pixel; |
3513 x_query_color (f, &color); | 3538 x_query_color (f, &color); |
3515 /* Change RGB values by specified FACTOR. Avoid overflow! */ | 3540 /* Change RGB values by specified FACTOR. Avoid overflow! */ |
3516 xassert (factor >= 0); | 3541 xassert (factor >= 0); |
3517 new.red = min (0xffff, factor * color.red); | 3542 new.red = min (0xffff, factor * color.red); |
3518 new.green = min (0xffff, factor * color.green); | 3543 new.green = min (0xffff, factor * color.green); |
3519 new.blue = min (0xffff, factor * color.blue); | 3544 new.blue = min (0xffff, factor * color.blue); |
3545 | |
3546 /* Use the maximum component brightness as the overall brightness | |
3547 (this works quite well in practice). */ | |
3548 bright = color.red; | |
3549 if (color.green > bright) | |
3550 bright = color.green; | |
3551 if (color.blue > bright) | |
3552 bright = color.blue; | |
3553 | |
3554 /* We only boost colors that are darker than | |
3555 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */ | |
3556 if (bright < HIGHLIGHT_COLOR_DARK_BOOST_LIMIT) | |
3557 /* Make an additive adjustment to NEW, because it's dark enough so | |
3558 that scaling by FACTOR alone isn't enough. */ | |
3559 { | |
3560 /* How far below the limit this color is (0 - 1, 1 being darker). */ | |
3561 double dimness = 1 - (double)bright / HIGHLIGHT_COLOR_DARK_BOOST_LIMIT; | |
3562 /* The additive adjustment. */ | |
3563 int min_delta = delta * dimness * HIGHLIGHT_COLOR_DARK_BOOST; | |
3564 | |
3565 if (factor < 1) | |
3566 { | |
3567 min_delta /= 2; | |
3568 new.red = max (0, new.red - min_delta); | |
3569 new.green = max (0, new.green - min_delta); | |
3570 new.blue = max (0, new.blue - min_delta); | |
3571 } | |
3572 else | |
3573 { | |
3574 new.red = min (0xffff, min_delta + new.red); | |
3575 new.green = min (0xffff, min_delta + new.green); | |
3576 new.blue = min (0xffff, min_delta + new.blue); | |
3577 } | |
3578 } | |
3520 | 3579 |
3521 /* Try to allocate the color. */ | 3580 /* Try to allocate the color. */ |
3522 success_p = x_alloc_nearest_color (f, cmap, &new); | 3581 success_p = x_alloc_nearest_color (f, cmap, &new); |
3523 if (success_p) | 3582 if (success_p) |
3524 { | 3583 { |
13889 staticpro (&last_mouse_motion_frame); | 13948 staticpro (&last_mouse_motion_frame); |
13890 last_mouse_motion_frame = Qnil; | 13949 last_mouse_motion_frame = Qnil; |
13891 } | 13950 } |
13892 | 13951 |
13893 #endif /* not HAVE_X_WINDOWS */ | 13952 #endif /* not HAVE_X_WINDOWS */ |
13894 |