| Description
| This copies an image to the miniwindow. You specify effectively a "matrix" which is applied to each pixel position, so that the image can be rotated, scaled, reflected, sheared and translated.
Note that changes to miniwindows will not become visible until the output window is redrawn. This happens when new (visible) lines arrive from the MUD, or if you call WindowShow, Repaint or Redraw.
Parameters:
WindowName - the name of an existing miniwindow.
ImageId - an image id that you have loaded.
Left, Top - the offset in the destination miniwindow for the image
Mode - the method of drawing the image:
1 - Copy non-transparently to the destination position.
2 - Not used.
3 - Do a transparent copy, where the pixel at the left,top corner (pixel position 0,0) is considered the transparent colour. Any pixels that exactly match that colour are not copied. WARNING - do not choose black or white as the transparent colour as that throws out the calculations. Choose some other colour (eg. purple) - you won't see that colour anyway.
The position of each destination pixel (x' and y') is given by:
x' = (x * Mxx) + (y * Mxy) + Left
y' = (x * Myx) + (y * Myy) + Top
Note that if you draw a monchrome image, such as one set up by WindowCreateImage then the pen colour from the most recent drawing operation is used as the foreground colour, and the brush colour for the background colour. Thus you may want to draw a small rectangle (eg. 1 x 1 pixel) with WindowCircleOp to establish those colours first.
For example images and code, see:
http://www.gammon.com.au/forum/?id=10527
Some examples of rotating, scaling, shearing etc. can be found below in the Lua examples.
Note that in some cases you need to also modify the Left and Top parameters or you may not see the result. For example, reflecting an image is likely to reflect it off the side of the bitmap, so you need to add the size of the image back in, to put it back in its original place. The forum posting mentioned above has a discussion about this, and more detailed examples.
Note: Available in version 4.59 onwards.
|
| Lua example
| -- IDENTITY COPY (ie. copy without changing)
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, 1, 0, 0, 1)
-- TRANSLATE
-- move in X direction
WindowTransformImage (win, imageid, 100, 0, miniwin.image_copy, 1, 0, 0, 1)
-- move in Y direction
WindowTransformImage (win, imageid, 0, 100, miniwin.image_copy, 1, 0, 0, 1)
-- REFLECT ON THE X AXIS
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, -1, 0, 0, 1)
-- REFLECT ON THE Y AXIS
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, 1, 0, 0, -1)
-- REFLECT ON BOTH AXES (ROTATE 180 DEGREES)
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, -1, 0, 0, -1)
-- ROTATE
-- rotation angle in degrees
local angle = 30
-- angle converted to radians
local radians = math.rad (angle)
-- calculate sine and cosine
local sine = math.sin (radians)
local cosine = math.cos (radians)
-- rotate counterclockwise
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, cosine, sine, -sine, cosine)
-- rotate clockwise
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, cosine, -sine, sine, cosine)
-- SHEAR
-- shear vertically right side downwards
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, 1, 0, 1, 1)
-- shear horizontally, bottom to the right
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, 1, 0.5, 0, 1)
-- SCALE
-- make 1.5 times larger
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, 1.5, 0, 0, 1.5)
-- reduce to 50%
WindowTransformImage (win, imageid, 0, 0, miniwin.image_copy, 0.5, 0, 0, 0.5) |