Written by Nick Gammon - July 2008. Updated September 2010.
On this page:
See also:
Examples on this page
Most of the examples on this page are drawn in a 100 x 100 pixel window, with a grid drawn every 20 pixels to make it clearer the effect of the example code. The code for producing the grid is described in Creating miniwindows.
Many functions below use a "pen". This is something used to draw lines. To save explaining the pen parameters for every function they are listed here:
Value | Purpose | Lua symbol |
---|---|---|
0 | Solid (an unbroken pen) | |
1 | Dash: ------- | |
2 | Dot: ....... | |
3 | Dashdot: _._._._ | |
4 | Dashdotdot: _.._.._ | |
5 | 5 - Null (no pen) | |
6 | Insideframe - a solid pen, drawn inside the shape |
You can also add in one of the following to control how the ends of line are drawn (version 4.59 onwards):
Value | Purpose | Lua symbol |
---|---|---|
0 | Round ends (the default) | |
0x100 (256) | Square ends | |
0x200 (512) | Flat ends |
You can also add in one of the following to control how lines join (version 4.59 onwards):
Value | Purpose | Lua symbol |
---|---|---|
0 | Round joins (the default) | |
0x1000 (4096) | Bevel joins | |
0x2000 (8192) | Miter joins |
Lua note: Instead of numbers you can use the above "symbolic constants" in Lua (version 4.52 onwards).
For a particular shape, specify style 5 (miniwin.pen_null) if you only want to fill the shape, and not stroke it as well.
Many functions below use a "brush". This is something used to fill the interior of a shape. To save explaining the brush parameters for every function they are listed here:
Value | Purpose | Lua symbol |
---|---|---|
0 | Solid (filled with a solid colour) | |
1 | Null (not filled) | |
2 | Hatch: horizontal | |
3 | Hatch: vertical | |
4 | Hatch: forwards diagonal | |
5 | Hatch: backwards diagonal | |
6 | Hatch: cross | |
7 | Hatch: diagonal cross | |
8 | Fine pattern | |
9 | Medium pattern | |
10 | Coarse pattern | |
11 | Waves - horizontal | |
12 | Waves - vertical |
Lua note: Instead of numbers you can use the above "symbolic constants" in Lua (version 4.52 onwards).
These screenshots illustrate the effects of the various brush styles (style 1 - no brush - is not shown).
For the various patterns, the PenColour is used as the "foreground" colour of the pattern, and the BrushColour is used as the "background" colour of the pattern.
In many functions described below you specify the rectangle in which the shapes is to appear (including ellipses, circles, etc.). As a shorthand you can specify a negative number, or zero, for the bottom or right side. This is taken to be offset from the bottom or right edge of the containing miniwindow. For example:
WindowLine function prototype:
long WindowLine(BSTR Name, long x1, long y1, long x2, long y2, long PenColour, long PenStyle, long PenWidth);
This draws a line from x1,y1 to x2,y2 with the designated pen.
WindowLine (win, 20, 20, 80, 80, ColourNameToRGB ("blue"), miniwin.pen_solid, 2)
WindowArc function prototype:
long WindowArc(BSTR Name, long Left, long Top, long Right, long Bottom, long x1, long y1, long x2, long y2, long PenColour, long PenStyle, long PenWidth);
This draws an arc from x1,y1 to x2,y2 inside the box (Left,Top,Right,Bottom) with the designated pen.
WindowArc (win, 20, 20, 80, 80, 30, 30, 120, 50, ColourNameToRGB ("green"), miniwin.pen_solid, 4)
The example above shows the enclosing rectangle, in blue, and the starting and ending points, in red, to illustrate how the arc works. They are not drawn as part of the arc, but shown to illustrate the idea.
WindowPolygon function prototype:
long WindowPolygon(BSTR Name, BSTR Points, long PenColour, long PenStyle, long PenWidth, long BrushColour, long BrushStyle, BOOL Close, BOOL Winding);
This draws a polygon (series of straight lines) connecting the specified points, with the designated pen and filled with the designated brush.
For example: "20,50,180,50" would specify two points, one at 20,50 and one at 180,50.
You must have at least 2 points (the start and end), which is 4 numbers. The number of numbers in the string must be even (divisible by two), as it takes a pair of numbers to specify one point.
WindowPolygon (win, "20,50,180,50,180,20,230,70,180,120,180,90,20,90",
ColourNameToRGB("cyan"), miniwin.pen_solid, 3, -- pen (solid, width 3)
ColourNameToRGB("yellow"), miniwin.brush_solid, -- brush (solid)
true, -- fill
false) -- alternate fill
WindowRectOp function prototype:
long WindowRectOp(BSTR Name, short Action, long Left, long Top, long Right, long Bottom, long Colour1, long Colour2);
This draws a rectangle in various styles, controlled by the Action parameter. You can also use WindowCircleOp with an action of 2 (miniwin.circle_rectangle) to draw rectangles with a pen and brush.
Value | Purpose | Lua symbol |
---|---|---|
1 | Frame by a single pixel wide line in Colour1 | |
2 | Fill the entire rectangle by Colour1 | |
3 | InvertRect - the colour on the miniwindow inside that rectangle is inverted | |
4 | Draw a "3D-style" rectangle in two colours, a single pixel wide (Colour1 is top and left edge colour, Colour2 is bottom and right edge colour) | |
5 | Draw Edge (draws a 3d-style edge with optional fill) | |
6 | Flood Fill Border (fills to border specified by Colour1) - the filling commences at the pixel designated by Left, Top and continues until it runs out of pixels that colour. | |
7 | Flood Fill Surface (fills while on surface specified by Colour1) - the filling commences at the pixel designated by Left, Top and continues until it is on pixels that colour. |
Value | Purpose | Lua symbol |
---|---|---|
5 | Raised | |
6 | Etched | |
9 | Bump | |
10 | Sunken |
Value | Purpose | Lua symbol |
---|---|---|
3 | Top left | |
6 | Top right | |
9 | Bottom left | |
12 | Bottom right | |
15 | Rect |
Diagonal lines:
Value | Purpose | Lua symbol |
---|---|---|
19 | Diagonal - end top left | |
22 | Diagonal - end top right | |
25 | Diagonal - end bottom left | |
28 | Diagonal - end bottom right |
For Action 5 (miniwin.rect_draw_edge) you can also add in the following values to modify the behaviour of the drawn rectangle:
Value | Purpose | Lua symbol |
---|---|---|
0x0800 (2048) | Fill in the middle | |
0x1000 (4096) | For softer buttons | |
0x4000 (16384) | For flat rather than 3D borders | |
0x8000 (32768) | For monochrome borders |
Resulting image is to the left of the corresponding code.
![]() |
|
There are more things you can try with rectangles, such as "bump" and "sunken" styles. Ellipses, Filled Rectangles, Round Rectangles, Chords, PiesWindowCircleOp function prototype:
long WindowCircleOp(BSTR Name, short Action, long Left, long Top, long Right, long Bottom, long PenColour, long PenStyle, long PenWidth, long BrushColour, long BrushStyle, long Extra1, long Extra2, long Extra3, long Extra4);
This draws an ellipse, rectangle, round rectangle, chord or pie, controlled by the Action parameter. Unlike WindowRectOp, described above, the rectangles drawn here can be filled with a brush, thus allowing you to have patterned interiors if desired. If you just want to draw a plain rectangle, however, WindowRectOp may be easier to use.
Examples of drawing ellipses and other shapesResulting image is to the left of the corresponding code.
The example above shows the enclosing rectangle, in blue, and the starting and ending points, in red, to illustrate how the chord works. They are not drawn as part of the chord, but shown to illustrate the idea.
The example above shows the enclosing rectangle, in blue, and the starting and ending points, in red, to illustrate how the pie works. They are not drawn as part of the pie, but shown to illustrate the idea. Bézier curvesWindowBezier function prototype:
long WindowBezier(BSTR Name, BSTR Points, long PenColour, long PenStyle, long PenWidth);
Draws one or more Bézier splines. This function draws cubic Bézier splines by using the endpoints and control points specified by the Points parameter. The first spline is drawn from the first point to the fourth point by using the second and third points as control points. Each subsequent spline in the sequence needs exactly three more points: the end point of the previous spline is used as the starting point, the next two points in the sequence are control points, and the third is the end point.
Example of drawing a Bézier curve
The example above shows the control points, in red, to illustrate how the Bézier curve works. They are not drawn as part of the curve, but shown to illustrate the idea. GradientsWindowGradient function prototype:
long WindowGradient(BSTR Name, long Left, long Top, long Right, long Bottom, long StartColour, long EndColour, short Mode);
Draws a gradient - that is a rectangle that gradually changes from the start colour to the end colour.
Examples of drawing a gradient
Setting pixelsWindowSetPixel function prototype:
long WindowSetPixel(BSTR Name, long x, long y, long Colour);
Sets a single pixel in the miniwindow.
Warning - although setting individual pixels is reasonably fast, if you need to set a lot (for example, to draw a line or a box), it would be much faster to use the appropriate dedicated function (such as WindowLine). This is because to draw boxes and lines, especially large ones, or filled ones, would take many, many calls to WindowSetPixel to achieve the same result. Example of setting pixels
You can also use WindowGetPixel to get the RGB colour code at a particular pixel location. Other pages about miniwindows
![]()
Comments to:
Gammon Software support
|