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.28 by root, Sun Jan 29 20:51:28 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 = 0x1111;
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 = 0x0101;
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 = 0x0001;
551 d.red = xc.red; 553 else
552 d.green = xc.green;
553 d.blue = xc.blue;
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); 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);
573#else 558#else
574 XColor xc; 559 XColor xc;
575 560
576 if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) 561 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
577 return set (screen, xc.red, xc.green, xc.blue); 562 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
578 563
579 return false; 564 return false;
580#endif 565#endif
581} 566}
582 567
583bool 568bool
584rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) 569rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
585{ 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
586 XColor xc; 581 XColor xc;
587 582
588 xc.red = cr; 583 xc.red = rgba.r;
589 xc.green = cg; 584 xc.green = rgba.g;
590 xc.blue = cb; 585 xc.blue = rgba.b;
591 xc.flags = DoRed | DoGreen | DoBlue; 586 xc.flags = DoRed | DoGreen | DoBlue;
592 587
593 if (XAllocColor (screen->xdisp, screen->cmap, &xc)) 588 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
594 return set (screen, xc.pixel); 589 {
590 p = xc.pixel;
591 return true;
592 }
595 593
596 return false; 594 return false;
595#endif
597} 596}
598 597
599void 598void
600rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) 599rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
601{ 600{
602#if XFT 601#if XFT
603 cr = c.color.red; 602 rgba.r = c.color.red;
604 cg = c.color.green; 603 rgba.g = c.color.green;
605 cb = c.color.blue; 604 rgba.b = c.color.blue;
605 rgba.a = c.color.alpha;
606#else 606#else
607 XColor c; 607 XColor c;
608 608
609 c.pixel = p; 609 c.pixel = p;
610 XQueryColor (screen->xdisp, screen->cmap, &c); 610 XQueryColor (screen->xdisp, screen->cmap, &c);
611 611
612 cr = c.red; 612 rgba.r = c.red;
613 cg = c.green; 613 rgba.g = c.green;
614 cb = c.blue; 614 rgba.b = c.blue;
615 rgba.a = rxvt_rgba::MAX_CC;
615#endif 616#endif
616} 617}
617 618
618void 619void
619rxvt_color::free (rxvt_screen *screen) 620rxvt_color::free (rxvt_screen *screen)
626} 627}
627 628
628rxvt_color 629rxvt_color
629rxvt_color::fade (rxvt_screen *screen, int percent) 630rxvt_color::fade (rxvt_screen *screen, int percent)
630{ 631{
631 percent = 100 - percent;
632
633 unsigned short cr, cg, cb;
634 rxvt_color faded; 632 rxvt_color faded;
635 633
634 rxvt_rgba c;
636 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);
637 654
638 faded.set ( 655 faded.set (
639 screen, 656 screen,
640 cr * percent / 100, 657 rxvt_rgba (
641 cg * percent / 100, 658 lerp (fc.r, c.r, percent),
642 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 )
643 ); 663 );
644 664
645 return faded; 665 return faded;
646} 666}
647 667
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