[Home] [Downloads] [Search] [Help/forum]

MUSHclient scripting

Description of MUSHclient world function: world.WindowTransformImage


Name WindowTransformImage
Type Method
Summary Draws an image into a miniwindow with optional rotation, scaling, reflection and shearing
Prototype long WindowTransformImage(BSTR WindowName, BSTR ImageId, float Left, float Top, short Mode, float Mxx, float Mxy, float Myx, float Myy);

View list of data type meanings

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)
Lua notes
You can use the following constants for the mode:

miniwin.image_copy = 1
miniwin.image_transparent_copy = 3
Returns eNoSuchWindow - no such miniwindow

eImageNotInstalled - that image was not loaded with WindowLoadImage or WindowLoadImageMemory

eBadParameter - drawing mode not in list above or not available due to being run under Windows 95 or earlier

eOK - completed OK

View list of return code meanings

Introduced in version 4.59

See also ...

Function Description
WindowCreate Creates a miniwindow
WindowCreateImage Creates an image in a miniwindow
WindowDrawImage Draws an image into a miniwindow
WindowDrawImageAlpha Draws an image into a miniwindow respecting the alpha channel
WindowImageInfo Returns information about an image
WindowImageList Lists all images installed into a miniwindow
WindowImageOp Draws an ellipse, rectangle or round rectangle, filled with an image

Search for script function

Enter a word or phrase in the box below to narrow the list down to those that match.

The function name, prototype, summary, and description are searched.

Search for:   

Leave blank to show all functions.


Return codes

Many functions return a "code" which indicates the success or otherwise of the function.

You can view a list of the return codes


Function prototypes

The "prototype" part of each function description lists exactly how the function is called (what arguments, if any, to pass to it).

You can view a list of the data types used in function prototypes


View all functions

[Back]

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]