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.27 by root, Wed Jan 25 21:09:21 2006 UTC vs.
Revision 1.28 by root, Sun Jan 29 20:51:28 2006 UTC

191 visual = DefaultVisualOfScreen (screen); 191 visual = DefaultVisualOfScreen (screen);
192 cmap = DefaultColormapOfScreen (screen); 192 cmap = DefaultColormapOfScreen (screen);
193} 193}
194 194
195void 195void
196rxvt_screen::set (rxvt_display *disp, int depth) 196rxvt_screen::set (rxvt_display *disp, int bitdepth)
197{ 197{
198 set (disp); 198 set (disp);
199 199
200 XVisualInfo vinfo; 200 XVisualInfo vinfo;
201 201
202 if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) 202 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
203 { 203 {
204 this->depth = depth; 204 depth = bitdepth;
205 this->visual = vinfo.visual; 205 visual = vinfo.visual;
206 this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); 206 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
207 } 207 }
208} 208}
209 209
210void 210void
211rxvt_screen::clear () 211rxvt_screen::clear ()
534refcache<rxvt_display> displays; 534refcache<rxvt_display> displays;
535 535
536///////////////////////////////////////////////////////////////////////////// 536/////////////////////////////////////////////////////////////////////////////
537 537
538bool 538bool
539rxvt_color::set (rxvt_screen *screen, Pixel p) 539rxvt_color::set (rxvt_screen *screen, const char *name)
540{ 540{
541#if XFT 541#if XFT
542 XColor xc; 542 int l = strlen (name);
543 rxvt_rgba r;
544 char eos;
545 int mult;
543 546
544 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))
545 if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) 548 mult = 0x1111;
546 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))
547 550 mult = 0x0101;
548 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))
549 552 mult = 0x0001;
550 d.red = xc.red; 553 else
551 d.green = xc.green;
552 d.blue = xc.blue;
553 d.alpha = 0xffff;
554
555 return
556 XftColorAllocValue (screen->xdisp,
557 screen->visual,
558 screen->cmap,
559 &d, &c);
560#else
561 this->p = p;
562#endif
563
564 return true;
565}
566
567bool
568rxvt_color::set (rxvt_screen *screen, const char *name)
569{
570#if XFT
571 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); 554 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
555
556 r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult;
557 return set (screen, r);
572#else 558#else
573 XColor xc; 559 XColor xc;
574 560
575 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 561 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
576 return set (screen, xc.red, xc.green, xc.blue); 562 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
577 563
578 return false; 564 return false;
579#endif 565#endif
580} 566}
581 567
582bool 568bool
583rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) 569rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
584{ 570{
571#if XFT
572 XRenderColor d;
573
574 d.red = rgba.r;
575 d.green = rgba.g;
576 d.blue = rgba.b;
577 d.alpha = rgba.a;
578
579 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
580#else
585 XColor xc; 581 XColor xc;
586 582
587 xc.red = cr; 583 xc.red = rgba.r;
588 xc.green = cg; 584 xc.green = rgba.g;
589 xc.blue = cb; 585 xc.blue = rgba.b;
590 xc.flags = DoRed | DoGreen | DoBlue; 586 xc.flags = DoRed | DoGreen | DoBlue;
591 587
592 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 588 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
593 return set (screen, xc.pixel); 589 {
590 p = xc.pixel;
591 return true;
592 }
594 593
595 return false; 594 return false;
595#endif
596} 596}
597 597
598void 598void
599rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) 599rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
600{ 600{
601#if XFT 601#if XFT
602 cr = c.color.red; 602 rgba.r = c.color.red;
603 cg = c.color.green; 603 rgba.g = c.color.green;
604 cb = c.color.blue; 604 rgba.b = c.color.blue;
605 rgba.a = c.color.alpha;
605#else 606#else
606 XColor c; 607 XColor c;
607 608
608 c.pixel = p; 609 c.pixel = p;
609 XQueryColor (screen->xdisp, screen->cmap, &c); 610 XQueryColor (screen->xdisp, screen->cmap, &c);
610 611
611 cr = c.red; 612 rgba.r = c.red;
612 cg = c.green; 613 rgba.g = c.green;
613 cb = c.blue; 614 rgba.b = c.blue;
615 rgba.a = rxvt_rgba::MAX_CC;
614#endif 616#endif
615} 617}
616 618
617void 619void
618rxvt_color::free (rxvt_screen *screen) 620rxvt_color::free (rxvt_screen *screen)
625} 627}
626 628
627rxvt_color 629rxvt_color
628rxvt_color::fade (rxvt_screen *screen, int percent) 630rxvt_color::fade (rxvt_screen *screen, int percent)
629{ 631{
630 percent = 100 - percent;
631
632 unsigned short cr, cg, cb;
633 rxvt_color faded; 632 rxvt_color faded;
634 633
634 rxvt_rgba c;
635 get (screen, cr, cg, cb); 635 get (screen, c);
636
637 c.r = lerp (0, c.r, percent);
638 c.g = lerp (0, c.g, percent);
639 c.b = lerp (0, c.b, percent);
640
641 faded.set (screen, c);
642
643 return faded;
644}
645
646rxvt_color
647rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
648{
649 rxvt_rgba c, fc;
650 rxvt_color faded;
651
652 get (screen, c);
653 fadeto.get (screen, fc);
636 654
637 faded.set ( 655 faded.set (
638 screen, 656 screen,
639 cr * percent / 100, 657 rxvt_rgba (
640 cg * percent / 100, 658 lerp (fc.r, c.r, percent),
641 cb * percent / 100 659 lerp (fc.g, c.g, percent),
660 lerp (fc.b, c.b, percent),
661 lerp (fc.a, c.a, percent)
662 )
642 ); 663 );
643 664
644 return faded; 665 return faded;
645} 666}
646 667
647#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
648
649rxvt_color
650rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
651{
652 percent = 100 - percent;
653
654 unsigned short cr, cg, cb;
655 unsigned short fcr, fcg, fcb;
656 rxvt_color faded;
657
658 get (screen, cr, cg, cb);
659 fadeto.get (screen, fcr, fcg, fcb);
660
661 faded.set (
662 screen,
663 LERP (cr, fcr, percent),
664 LERP (cg, fcg, percent),
665 LERP (cb, fcb, percent)
666 );
667
668 return faded;
669}
670

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines