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.26 by root, Wed Jan 25 21:03:04 2006 UTC vs.
Revision 1.30 by root, Sun Jan 29 21:54:33 2006 UTC

181 181
182void 182void
183rxvt_screen::set (rxvt_display *disp) 183rxvt_screen::set (rxvt_display *disp)
184{ 184{
185 display = disp; 185 display = disp;
186
187 xdisp = disp->display; 186 xdisp = disp->display;
188 187
189 Screen *screen = ScreenOfDisplay (xdisp, disp->screen); 188 Screen *screen = ScreenOfDisplay (xdisp, disp->screen);
190 189
191 depth = DefaultDepthOfScreen (screen); 190 depth = DefaultDepthOfScreen (screen);
192 visual = DefaultVisualOfScreen (screen); 191 visual = DefaultVisualOfScreen (screen);
193 cmap = DefaultColormapOfScreen (screen); 192 cmap = DefaultColormapOfScreen (screen);
194} 193}
195 194
196void 195void
197rxvt_screen::set (rxvt_display *disp, int depth) 196rxvt_screen::set (rxvt_display *disp, int bitdepth)
198{ 197{
199 set (disp); 198 set (disp);
200 199
201 XVisualInfo vinfo; 200 XVisualInfo vinfo;
202 201
203 if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) 202 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
204 { 203 {
205 this->depth = depth; 204 depth = bitdepth;
206 this->visual = vinfo.visual; 205 visual = vinfo.visual;
207 this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 206 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
208 } 207 }
209} 208}
210 209
211void 210void
212rxvt_screen::clear () 211rxvt_screen::clear ()
535refcache<rxvt_display> displays; 534refcache<rxvt_display> displays;
536 535
537///////////////////////////////////////////////////////////////////////////// 536/////////////////////////////////////////////////////////////////////////////
538 537
539bool 538bool
540rxvt_color::set (rxvt_screen *screen, Pixel p) 539rxvt_color::set (rxvt_screen *screen, const char *name)
541{ 540{
542#if XFT 541#if XFT
543 XColor xc; 542 int l = strlen (name);
543 rxvt_rgba r;
544 char eos;
545 int mult;
544 546
545 xc.pixel = p; 547 if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
546 if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) 548 mult = rxvt_rgba::MAX_CC / 0x000f;
547 return false; 549 else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
548 550 mult = rxvt_rgba::MAX_CC / 0x00ff;
549 XRenderColor d; 551 else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
550 552 mult = rxvt_rgba::MAX_CC / 0xffff;
551 d.red = xc.red; 553 else if (l == 4+5*4 && 4 == sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos))
552 d.green = xc.green; 554 mult = rxvt_rgba::MAX_CC / 0xffff;
553 d.blue = xc.blue; 555 else
554 d.alpha = 0xffff;
555
556 return
557 XftColorAllocValue (screen->xdisp,
558 screen->visual,
559 screen->cmap,
560 &d, &c);
561#else
562 this->p = p;
563#endif
564
565 return true;
566}
567
568bool
569rxvt_color::set (rxvt_screen *screen, const char *name)
570{
571#if XFT
572 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); 556 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
557
558 r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult;
559 return set (screen, r);
573#else 560#else
574 XColor xc; 561 XColor xc;
575 562
576 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 563 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
577 return set (screen, xc.red, xc.green, xc.blue); 564 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
578 565
579 return false; 566 return false;
580#endif 567#endif
581} 568}
582 569
583bool 570bool
584rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) 571rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
585{ 572{
573#if XFT
574 XRenderColor d;
575
576 d.red = rgba.r;
577 d.green = rgba.g;
578 d.blue = rgba.b;
579 d.alpha = rgba.a;
580
581 if (XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c))
582 {
583 // FUCKING Xft gets it wrong, of course, fix it for the common case
584 // transparency users should eat shit and die, and then
585 // XRenderQueryPictIndexValues themselves plenty.
586 if (screen->depth == 32 && screen->visual->c_class == TrueColor)
587 if ((screen->visual->red_mask | screen->visual->green_mask | screen->visual->blue_mask) == 0x00ffffffUL)
588 c.pixel = c.pixel & 0x00ffffffUL | ((rgba.a >> 8) << 24);
589 else if ((screen->visual->red_mask | screen->visual->green_mask | screen->visual->blue_mask) == 0xffffff00UL)
590 c.pixel = c.pixel & 0xffffff00UL | (rgba.a >> 8);
591
592 return true;
593 }
594
595 return false;
596#else
586 XColor xc; 597 XColor xc;
587 598
588 xc.red = cr; 599 xc.red = rgba.r;
589 xc.green = cg; 600 xc.green = rgba.g;
590 xc.blue = cb; 601 xc.blue = rgba.b;
591 xc.flags = DoRed | DoGreen | DoBlue; 602 xc.flags = DoRed | DoGreen | DoBlue;
592 603
593 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 604 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
594 return set (screen, xc.pixel); 605 {
606 p = xc.pixel;
607 return true;
608 }
595 609
596 return false; 610 return false;
611#endif
597} 612}
598 613
599void 614void
600rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) 615rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
601{ 616{
602#if XFT 617#if XFT
603 cr = c.color.red; 618 rgba.r = c.color.red;
604 cg = c.color.green; 619 rgba.g = c.color.green;
605 cb = c.color.blue; 620 rgba.b = c.color.blue;
621 rgba.a = c.color.alpha;
606#else 622#else
607 XColor c; 623 XColor c;
608 624
609 c.pixel = p; 625 c.pixel = p;
610 XQueryColor (screen->xdisp, screen->cmap, &c); 626 XQueryColor (screen->xdisp, screen->cmap, &c);
611 627
612 cr = c.red; 628 rgba.r = c.red;
613 cg = c.green; 629 rgba.g = c.green;
614 cb = c.blue; 630 rgba.b = c.blue;
631 rgba.a = rxvt_rgba::MAX_CC;
615#endif 632#endif
616} 633}
617 634
618void 635void
619rxvt_color::free (rxvt_screen *screen) 636rxvt_color::free (rxvt_screen *screen)
626} 643}
627 644
628rxvt_color 645rxvt_color
629rxvt_color::fade (rxvt_screen *screen, int percent) 646rxvt_color::fade (rxvt_screen *screen, int percent)
630{ 647{
631 percent = 100 - percent;
632
633 unsigned short cr, cg, cb;
634 rxvt_color faded; 648 rxvt_color faded;
635 649
650 rxvt_rgba c;
636 get (screen, cr, cg, cb); 651 get (screen, c);
652
653 c.r = lerp (0, c.r, percent);
654 c.g = lerp (0, c.g, percent);
655 c.b = lerp (0, c.b, percent);
656
657 faded.set (screen, c);
658
659 return faded;
660}
661
662rxvt_color
663rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
664{
665 rxvt_rgba c, fc;
666 rxvt_color faded;
667
668 get (screen, c);
669 fadeto.get (screen, fc);
637 670
638 faded.set ( 671 faded.set (
639 screen, 672 screen,
640 cr * percent / 100, 673 rxvt_rgba (
641 cg * percent / 100, 674 lerp (fc.r, c.r, percent),
642 cb * percent / 100 675 lerp (fc.g, c.g, percent),
676 lerp (fc.b, c.b, percent),
677 lerp (fc.a, c.a, percent)
678 )
643 ); 679 );
644 680
645 return faded; 681 return faded;
646} 682}
647 683
648#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
649
650rxvt_color
651rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
652{
653 percent = 100 - percent;
654
655 unsigned short cr, cg, cb;
656 unsigned short fcr, fcg, fcb;
657 rxvt_color faded;
658
659 get (screen, cr, cg, cb);
660 fadeto.get (screen, fcr, fcg, fcb);
661
662 faded.set (
663 screen,
664 LERP (cr, fcr, percent),
665 LERP (cg, fcg, percent),
666 LERP (cb, fcb, percent)
667 );
668
669 return faded;
670}
671

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines