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.42 by root, Tue Jan 31 16:57:35 2006 UTC vs.
Revision 1.43 by root, Tue Jan 31 18:36:35 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, "[%hd]%n", &c.a, &skip)) 640 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
643 { 641 {
644 printf ("X %d\n", c.a); 642 printf ("X %d\n", c.a);
645 c.a = lerp<int, int, int> (0, rxvt_rgba::MAX_CC, c.a); 643 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a);
646 name += skip; 644 name += skip;
647 printf ("y %04x\n", c.a); 645 printf ("y %04x\n", c.a);
648 } 646 }
649 else 647 else
650 c.a = rxvt_rgba::MAX_CC; 648 c.a = rgba::MAX_CC;
651 649
652 // parse the non-standard rgba format 650 // parse the non-standard rgba format
653 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) 651 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos))
654 { 652 {
655 XColor xc, xc_exact; 653 XColor xc, xc_exact;
672 670
673 return set (screen, c); 671 return set (screen, c);
674} 672}
675 673
676bool 674bool
677rxvt_color::set (rxvt_screen *screen, const rxvt_rgba &color) 675rxvt_color::set (rxvt_screen *screen, const rgba &color)
678{ 676{
679 bool got = alloc (screen, color); 677 bool got = alloc (screen, color);
680 678
681#if !ENABLE_MINIMAL 679#if !ENABLE_MINIMAL
682 int cmap_size = screen->visual->map_entries; 680 int cmap_size = screen->visual->map_entries;
688 XColor *colors = new XColor [screen->visual->map_entries]; 686 XColor *colors = new XColor [screen->visual->map_entries];
689 687
690 for (int i = 0; i < cmap_size; i++) 688 for (int i = 0; i < cmap_size; i++)
691 colors [i].pixel = i; 689 colors [i].pixel = i;
692 690
691 // many kilobytes transfer per colour, but pseudocolor isn't worth
692 // many extra optimisations.
693 XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size); 693 XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size);
694 694
695 int diff = 0x7fffffffUL; 695 int diff = 0x7fffffffUL;
696 XColor *best = colors; 696 XColor *best = colors;
697 697
709 } 709 }
710 710
711 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", 711 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n",
712 // color.r, color.g, color.b, best->red, best->green, best->blue, diff); 712 // color.r, color.g, color.b, best->red, best->green, best->blue, diff);
713 713
714 got = alloc (screen, rxvt_rgba (best->red, best->green, best->blue)); 714 got = alloc (screen, rgba (best->red, best->green, best->blue));
715 715
716 delete colors; 716 delete colors;
717 } 717 }
718#endif 718#endif
719 719
720 return got; 720 return got;
721} 721}
722 722
723void 723void
724rxvt_color::get (rxvt_screen *screen, rxvt_rgba &color) 724rxvt_color::get (rxvt_screen *screen, rgba &color)
725{ 725{
726#if XFT 726#if XFT
727 color.r = c.color.red; 727 color.r = c.color.red;
728 color.g = c.color.green; 728 color.g = c.color.green;
729 color.b = c.color.blue; 729 color.b = c.color.blue;
730 color.a = c.color.alpha; 730 color.a = c.color.alpha;
731#else 731#else
732 XColor c;
733
734 c.pixel = p;
735 XQueryColor (screen->xdisp, screen->cmap, &c);
736
737 color.r = c.red; 732 color.r = c.red;
738 color.g = c.green; 733 color.g = c.green;
739 color.b = c.blue; 734 color.b = c.blue;
740 color.a = rxvt_rgba::MAX_CC; 735 color.a = rgba::MAX_CC;
741#endif 736#endif
742} 737}
743 738
744void 739void
745rxvt_color::free (rxvt_screen *screen) 740rxvt_color::free (rxvt_screen *screen)
746{ 741{
747#if XFT 742#if XFT
748 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); 743 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
749#else 744#else
750 XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); 745 XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes);
751#endif 746#endif
752} 747}
753 748
754void 749void
755rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rxvt_rgba &to) 750rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to)
756{ 751{
757 rxvt_rgba c; 752 rgba c;
758 get (screen, c); 753 get (screen, c);
759 754
760 result.set ( 755 result.set (
761 screen, 756 screen,
762 rxvt_rgba ( 757 rgba (
763 lerp (c.r, to.r, percent), 758 lerp (c.r, to.r, percent),
764 lerp (c.g, to.g, percent), 759 lerp (c.g, to.g, percent),
765 lerp (c.b, to.b, percent), 760 lerp (c.b, to.b, percent),
766 lerp (c.a, to.a, percent) 761 lerp (c.a, to.a, percent)
767 ) 762 )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines