ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.C
(Generate patch)

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.40 by root, Tue Jan 31 16:19:16 2006 UTC vs.
Revision 1.45 by root, Wed Feb 1 01:58:47 2006 UTC

560refcache<rxvt_display> displays; 560refcache<rxvt_display> displays;
561 561
562///////////////////////////////////////////////////////////////////////////// 562/////////////////////////////////////////////////////////////////////////////
563 563
564bool 564bool
565rxvt_color::alloc (rxvt_screen *screen, const rxvt_rgba &color) 565rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
566{ 566{
567#if XFT 567#if XFT
568 XRenderPictFormat *format; 568 XRenderPictFormat *format;
569 569
570 // FUCKING Xft gets it wrong, of course, so work around it 570 // FUCKING Xft gets it wrong, of course, so work around it
577 c.color.red = color.r; 577 c.color.red = color.r;
578 c.color.green = color.g; 578 c.color.green = color.g;
579 c.color.blue = color.b; 579 c.color.blue = color.b;
580 c.color.alpha = color.a; 580 c.color.alpha = color.a;
581 581
582 c.pixel = ((color.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red ) 582 c.pixel = ((color.r * format->direct.redMask / rgba::MAX_CC) << format->direct.red )
583 | ((color.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green) 583 | ((color.g * format->direct.greenMask / rgba::MAX_CC) << format->direct.green)
584 | ((color.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue ) 584 | ((color.b * format->direct.blueMask / rgba::MAX_CC) << format->direct.blue )
585 | ((color.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha); 585 | ((color.a * format->direct.alphaMask / rgba::MAX_CC) << format->direct.alpha);
586 586
587 return true; 587 return true;
588 } 588 }
589 else 589 else
590 { 590 {
598 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); 598 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
599 } 599 }
600#else 600#else
601 if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor) 601 if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor)
602 { 602 {
603 c.red = color.g;
604 c.green = color.g;
605 c.blue = color.g;
603 p = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) 606 c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask ))
604 / rxvt_rgba::MAX_CC) << ctz (screen->visual->red_mask ) 607 / rgba::MAX_CC) << ctz (screen->visual->red_mask )
605 | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) 608 | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask))
606 / rxvt_rgba::MAX_CC) << ctz (screen->visual->green_mask) 609 / rgba::MAX_CC) << ctz (screen->visual->green_mask)
607 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) 610 | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
608 / rxvt_rgba::MAX_CC) << ctz (screen->visual->blue_mask ); 611 / rgba::MAX_CC) << ctz (screen->visual->blue_mask );
609 612
610 return true; 613 return true;
611 } 614 }
612 else 615 else
613 { 616 {
614 XColor xc;
615
616 xc.red = color.r; 617 c.red = color.r;
617 xc.green = color.g; 618 c.green = color.g;
618 xc.blue = color.b; 619 c.blue = color.b;
619 620
620 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 621 if (XAllocColor (screen->xdisp, screen->cmap, &c))
621 {
622 p = xc.pixel;
623 return true; 622 return true;
624 }
625 else 623 else
626 p = (color.r + color.g + color.b) > 128*3 624 c.pixel = (color.r + color.g + color.b) > 128*3
627 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) 625 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp))
628 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); 626 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp));
629 } 627 }
630#endif 628#endif
631 629
632 return false; 630 return false;
633} 631}
634 632
635bool 633bool
636rxvt_color::set (rxvt_screen *screen, const char *name) 634rxvt_color::set (rxvt_screen *screen, const char *name)
637{ 635{
638 rxvt_rgba c; 636 rgba c;
639 char eos; 637 char eos;
640 int skip; 638 int skip;
641 639
642 if (1 <= sscanf (name, "[%hx]%n", &c.a, &skip)) 640 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
643 { 641 {
644 switch (skip) 642 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a);
645 {
646 case 2 + 1: c.a *= rxvt_rgba::MAX_CC / 0x000f; break;
647 case 2 + 2: c.a *= rxvt_rgba::MAX_CC / 0x00ff; break;
648 case 2 + 3: c.a *= rxvt_rgba::MAX_CC / 0x0fff; break;
649 case 2 + 4: c.a *= rxvt_rgba::MAX_CC / 0xffff; break;
650 }
651
652 name += skip; 643 name += skip;
653 } 644 }
654 else 645 else
655 c.a = rxvt_rgba::MAX_CC; 646 c.a = rgba::MAX_CC;
656 647
657 // parse the non-standard rgba format 648 // parse the non-standard rgba format
658 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) 649 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos))
659 { 650 {
660 XColor xc, xc_exact; 651 XColor xc, xc_exact;
677 668
678 return set (screen, c); 669 return set (screen, c);
679} 670}
680 671
681bool 672bool
682rxvt_color::set (rxvt_screen *screen, const rxvt_rgba &color) 673rxvt_color::set (rxvt_screen *screen, const rgba &color)
683{ 674{
684 bool got = alloc (screen, color); 675 bool got = alloc (screen, color);
685 676
686#if !ENABLE_MINIMAL 677#if !ENABLE_MINIMAL
687 int cmap_size = screen->visual->map_entries; 678 int cmap_size = screen->visual->map_entries;
693 XColor *colors = new XColor [screen->visual->map_entries]; 684 XColor *colors = new XColor [screen->visual->map_entries];
694 685
695 for (int i = 0; i < cmap_size; i++) 686 for (int i = 0; i < cmap_size; i++)
696 colors [i].pixel = i; 687 colors [i].pixel = i;
697 688
689 // many kilobytes transfer per colour, but pseudocolor isn't worth
690 // many extra optimisations.
698 XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size); 691 XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size);
699 692
700 int diff = 0x7fffffffUL; 693 int diff = 0x7fffffffUL;
701 XColor *best = colors; 694 XColor *best = colors;
702 695
714 } 707 }
715 708
716 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", 709 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n",
717 // color.r, color.g, color.b, best->red, best->green, best->blue, diff); 710 // color.r, color.g, color.b, best->red, best->green, best->blue, diff);
718 711
719 got = alloc (screen, rxvt_rgba (best->red, best->green, best->blue)); 712 got = alloc (screen, rgba (best->red, best->green, best->blue));
720 713
721 delete colors; 714 delete colors;
722 } 715 }
723#endif 716#endif
724 717
725 return got; 718 return got;
726} 719}
727 720
728void 721void
729rxvt_color::get (rxvt_screen *screen, rxvt_rgba &color) 722rxvt_color::get (rgba &color)
730{ 723{
731#if XFT 724#if XFT
732 color.r = c.color.red; 725 color.r = c.color.red;
733 color.g = c.color.green; 726 color.g = c.color.green;
734 color.b = c.color.blue; 727 color.b = c.color.blue;
735 color.a = c.color.alpha; 728 color.a = c.color.alpha;
736#else 729#else
737 XColor c;
738
739 c.pixel = p;
740 XQueryColor (screen->xdisp, screen->cmap, &c);
741
742 color.r = c.red; 730 color.r = c.red;
743 color.g = c.green; 731 color.g = c.green;
744 color.b = c.blue; 732 color.b = c.blue;
745 color.a = rxvt_rgba::MAX_CC; 733 color.a = rgba::MAX_CC;
746#endif 734#endif
747} 735}
748 736
749void 737void
750rxvt_color::free (rxvt_screen *screen) 738rxvt_color::free (rxvt_screen *screen)
751{ 739{
752#if XFT 740#if XFT
753 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); 741 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
754#else 742#else
755 XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); 743 XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes);
756#endif 744#endif
757} 745}
758 746
759rxvt_color 747void
760rxvt_color::fade (rxvt_screen *screen, int percent, const rxvt_rgba &to) 748rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to)
761{ 749{
762 rxvt_rgba c; 750 rgba c;
763 get (screen, c); 751 get (c);
764 752
765 rxvt_color faded; 753 result.set (
766 faded.set (
767 screen, 754 screen,
768 rxvt_rgba ( 755 rgba (
769 lerp (to.r, c.r, percent), 756 lerp (c.r, to.r, percent),
770 lerp (to.g, c.g, percent), 757 lerp (c.g, to.g, percent),
771 lerp (to.b, c.b, percent), 758 lerp (c.b, to.b, percent),
772 lerp (to.a, c.a, percent) 759 lerp (c.a, to.a, percent)
773 ) 760 )
774 ); 761 );
775
776 return faded;
777} 762}
778 763

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines