--- rxvt-unicode/src/rxvtperl.xs 2012/06/12 10:45:53 1.192 +++ rxvt-unicode/src/rxvtperl.xs 2012/06/14 18:19:11 1.197 @@ -60,14 +60,48 @@ typedef GdkPixbuf * urxvt__pixbuf; #endif typedef rxvt_img * urxvt__img; +typedef rxvt_img::nv rxvt_img__nv; ///////////////////////////////////////////////////////////////////////////// -static void -parse_color (rxvt_screen *s, rxvt_color &c, SV *sv) +static rgba +parse_rgba (SV *sv, rxvt_screen *s = 0) { - //TODO: support component stuff, 0..1 - c.set (s, SvPVbyte_nolen (sv)); + rgba c; + + if (AV *av = (AV *)SvRV (sv)) + { + if (SvTYPE ((SV *)av) != SVt_PVAV) + croak ("colour must be either a colour string, or an array,"); + + int len = av_len (av) + 1; + + if (len != 1 && len != 3 && len != 4) + croak ("component colour array must have 1, 3 or 4 components,"); + + c.a = rgba::MAX_CC; + + c.r = c.g = c.b = float_to_component (SvIV (*av_fetch (av, 0, 0))); + + if (len >= 3) + { + c.g = float_to_component (SvIV (*av_fetch (av, 1, 0))); + c.b = float_to_component (SvIV (*av_fetch (av, 2, 0))); + + if (len >= 4) + c.a = float_to_component (SvIV (*av_fetch (av, 3, 0))); + } + } + else if (s) + { + rxvt_color rc; + rc.set (s, SvPVbyte_nolen (sv)); + rc.get (c); + } + else + croak ("unable to parse colour,"); + + return c; } ///////////////////////////////////////////////////////////////////////////// @@ -2065,12 +2099,12 @@ #if HAVE_IMG rxvt_img * -rxvt_term::new_img (SV *format, int width = 1, int height = 1) +rxvt_term::new_img (SV *format, int x = 0, int y = 0, int width = 1, int height = 1) CODE: XRenderPictFormat *f = SvOK (format) ? XRenderFindStandardFormat (THIS->dpy, SvIV (format)) : XRenderFindVisualFormat (THIS->dpy, THIS->visual); - RETVAL = new rxvt_img (THIS, f, 0, 0, width, height); + RETVAL = new rxvt_img (THIS, f, x, y, width, height); RETVAL->alloc (); OUTPUT: RETVAL @@ -2181,6 +2215,29 @@ # rxvt_img *new (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) # rxvt_img *rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap); +void +rxvt_img::geometry () + PPCODE: + EXTEND (SP, 4); + PUSHs (sv_2mortal (newSViv (THIS->x))); + PUSHs (sv_2mortal (newSViv (THIS->y))); + PUSHs (sv_2mortal (newSViv (THIS->w))); + PUSHs (sv_2mortal (newSViv (THIS->h))); + +int +rxvt_img::x () + CODE: + RETVAL = THIS->x; + OUTPUT: + RETVAL + +int +rxvt_img::y () + CODE: + RETVAL = THIS->y; + OUTPUT: + RETVAL + int rxvt_img::w () CODE: @@ -2205,9 +2262,8 @@ void rxvt_img::fill (SV *c) INIT: - rxvt_color rc; - parse_color (THIS->s, rc, c); - C_ARGS: rc + rgba cc = parse_rgba (c, THIS->s); + C_ARGS: cc void rxvt_img::DESTROY () @@ -2229,10 +2285,10 @@ rxvt_img::move (int dx, int dy) void -rxvt_img::brightness (NV r, NV g, NV b, NV a = 1.) +rxvt_img::brightness (rxvt_img::nv r, rxvt_img::nv g, rxvt_img::nv b, rxvt_img::nv a = 1.) void -rxvt_img::contrast (NV r, NV g, NV b, NV a = 1.) +rxvt_img::contrast (rxvt_img::nv r, rxvt_img::nv g, rxvt_img::nv b, rxvt_img::nv a = 1.) rxvt_img * rxvt_img::clone () @@ -2247,20 +2303,20 @@ rxvt_img::blur (int rh, int rv) rxvt_img * -rxvt_img::transform (NV p11, NV p12, NV p13, NV p21, NV p22, NV p23, NV p31, NV p32, NV p33, int new_width = 0, int new_height = 0) +rxvt_img::transform (rxvt_img::nv p11, rxvt_img::nv p12, rxvt_img::nv p13, rxvt_img::nv p21, rxvt_img::nv p22, rxvt_img::nv p23, rxvt_img::nv p31, rxvt_img::nv p32, rxvt_img::nv p33) INIT: - double matrix[9] = { - p11, p12, p13, - p21, p22, p23, - p31, p32, p33 + rxvt_img::nv matrix[3][3] = { + { p11, p12, p13 }, + { p21, p22, p23 }, + { p31, p32, p33 } }; - C_ARGS: matrix, new_width, new_height + C_ARGS: matrix rxvt_img * rxvt_img::scale (int new_width, int new_height) rxvt_img * -rxvt_img::rotate (int x, int y, NV phi, int new_width = 0, int new_height = 0) +rxvt_img::rotate (int x, int y, rxvt_img::nv phi) #endif