[wx-dev] mysterious wxImage::Paste() logic
Tim Kosse
tim.kosse at gmx.de
Mon Sep 3 15:43:30 PDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Vadim Zeitlin wrote:
> Does anyone know what does wxImage::Paste() do when its x/y parameters are
> negative? I don't understand this code at all and can't make any sense of
> it nor document it (which I'd like to do).
> int xx = 0;
> int yy = 0;
> int width = image.GetWidth();
> int height = image.GetHeight();
>
> if (x < 0)
> {
> xx = -x;
> width += x;
> }
> if (y < 0)
> {
> yy = -y;
> height += y;
> }
xx and yy are offsets into the source image.
If x and y are >=0, we can start copying from the source image at the
topleft corner, in other words xx and yy are 0.
If x and y are less than zero, we have to clip the source, starting with
the rectangle starting at position xx = -x and yy = -y, extending to the
lower-right.
Note I omit the cases (postive, negative) and (negative, positive here,
they are analogous.
> if ((x+xx)+width > M_IMGDATA->m_width)
> width = M_IMGDATA->m_width - (x+xx);
> if ((y+yy)+height > M_IMGDATA->m_height)
> height = M_IMGDATA->m_height - (y+yy);
case 1: x >= 0:
if (x + width > M_IMGDATA->m_width) // equals width >
M_IMGDATA->m_width - x
width = M_IMGDATA->m_width - x
case 2: x < 0
if (width > M_IMGDATA->m_width)
width = M_IMGDATA->m_width
With that information, the loops later in wxImage::Paste are easy to
understand:
It takes the data starting at coordindates xx and yy and pastes it into
the target image at coordinates (x, y) if >=0 or (0, 0) otherwise.
Tim
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG3I4R8N9+lcqiUkURAifZAJ0U105YVrcdh/ISHc57idKJO0z07ACg9stM
HVfu7hfiJmF8hriPPiilTFk=
=Wtvc
-----END PGP SIGNATURE-----
More information about the wx-dev
mailing list