File SMGraph.mys
Graph utility functions
- Sylvain Machefert
Summary
Constant | Type | Summary |
---|---|---|
ORIENTATION_EAST | string | Orientation of arrows and some drawings: east (to the right) |
ORIENTATION_NORTH | string | Orientation of arrows and some drawings: north (to the top) |
ORIENTATION_NORTH_EAST | string | Orientation of arrows and some drawings: north east (to right top) |
ORIENTATION_NORTH_WEST | string | Orientation of arrows and some drawings: north west (to left top) |
ORIENTATION_SOUTH | string | Orientation of arrows and some drawings: south (to the bottom) |
ORIENTATION_SOUTH_EAST | string | Orientation of arrows and some drawings: south east (to right bottom) |
ORIENTATION_SOUTH_WEST | string | Orientation of arrows and some drawings: south west (to left bottom) |
ORIENTATION_WEST | string | Orientation of arrows and some drawings: west (to the left) |
PICTURE_SCALE_ALWAYS | int | Picture scaling: shrink large picture, and enlarge small pictures. |
PICTURE_SCALE_ENLARGE | int | Picture scaling: enlarge small picture, never shrink large pictures. |
PICTURE_SCALE_NEVER | int | Picture scaling: never. |
PICTURE_SCALE_SHRINK | int | Picture scaling: shrink large picture, never enlarge small pictures. |
VERTICAL_ALIGN_BOTTOM | int | Text and picture vertical alignment: bottom |
VERTICAL_ALIGN_MIDDLE | int | Text and picture vertical alignment: middle |
VERTICAL_ALIGN_TOP | int | Text and picture vertical alignment: top |
Return type | Function and summary |
---|---|
int | BuildPolygon(Graph graphContext, table points, bool autoClose) Open a polygon, draw lines between each point and close the polygon. |
DrawArrow90DegreesHead(Graph graphContext, number left, number top, number right, number bottom, int orientation, int headSize, string headType, bool drawBody) Draws a 90°-headed (2 lines) arrow in the given boundaries, pointing to the given orientation. | |
number, number, number, number | DrawPicture(Graph graphContext, string file, number left, number top, number right, number bottom, int verticalAlign, int horizontal, int scaling, bool keepAspectRatio) Draw a picture file, using Graph.DrawPicture(...) with advanced and easy-to-use resizing and alignments. |
number, number | DrawText(Graph graphContext, string text, string fontFamily, int fontSize, int fontFace, number left, number top, number right, number bottom, int verticalAlign, int horizontalAlign, bool allowOverflow, int originX, int originY, bool autoLineBreak, Score score) Draw a text, using given font family, size and face, aligned within boundaries. |
FrameTriangle(Graph graphContext, number xA, number yA, number xB, number yB, number xC, number yC) Draws an outline just inside of the borders of an ABC triangle. | |
PaintTriangle(Graph graphContext, number xA, number yA, number xB, number yB, number xC, number yC) Fills an ABC triangle with the current pen pattern, using the current pen transfer mode. | |
number, number | StringSize(Graph graphContext, string s, string fontFamily, int fontSize, int fontFace) Get the string size using given font family, size and face. |
Constants
int PICTURE_SCALE_SHRINK
Picture scaling: shrink large picture, never enlarge small pictures.
- See
- DrawPicture
int PICTURE_SCALE_ENLARGE
Picture scaling: enlarge small picture, never shrink large pictures.
- See
- DrawPicture
int PICTURE_SCALE_ALWAYS
Picture scaling: shrink large picture, and enlarge small pictures.
- See
- DrawPicture
string ORIENTATION_NORTH
Orientation of arrows and some drawings: north (to the top)
string ORIENTATION_NORTH_EAST
Orientation of arrows and some drawings: north east (to right top)
string ORIENTATION_EAST
Orientation of arrows and some drawings: east (to the right)
string ORIENTATION_SOUTH_EAST
Orientation of arrows and some drawings: south east (to right bottom)
string ORIENTATION_SOUTH
Orientation of arrows and some drawings: south (to the bottom)
string ORIENTATION_SOUTH_WEST
Orientation of arrows and some drawings: south west (to left bottom)
string ORIENTATION_WEST
Orientation of arrows and some drawings: west (to the left)
string ORIENTATION_NORTH_WEST
Orientation of arrows and some drawings: north west (to left top)
Functions
StringSize(Graph graphContext, string s, string fontFamily, int fontSize, int fontFace)
Get the string size using given font family, size and face.
Multi-line is not handled.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
s | string | The string, rich string is handled, tokens are transformed (e.g. Moderato $(4) = 80) | |
fontFamily | string | "geneva" | |
fontSize | int | 11 | |
fontFace | int | FACE_NONE | Sum of FACE_* constants in MSDefine |
- Returns
- number: Width of the string.
- number: Height of the string.
DrawText(Graph graphContext, string text, string fontFamily, int fontSize, int fontFace, number left, number top, number right, number bottom, int verticalAlign, int horizontalAlign, bool allowOverflow, int originX, int originY, bool autoLineBreak, Score score)
Draw a text, using given font family, size and face, aligned within boundaries.
This may be useful if you create your own component that need to display text.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
text | string | The text to draw, rich strings are handled, tokens are transformed (e.g. $(4) = 80) | |
fontFamily | string | "geneva" | |
fontSize | int | 11 | |
fontFace | int | FACE_NONE | Sum of FACE_* constants in MSDefine |
left | number | Left boundary | |
top | number | Top boundary | |
right | number | Right boundary | |
bottom | number | Bottom boundary | |
verticalAlign | int | VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE or VERTICAL_ALIGN_BOTTOM | |
horizontalAlign | int | ALIGN_LEFT, ALIGN_CENTER or ALIGN_RIGHT | |
allowOverflow | bool | true | Accepts that text can be displayed outside of the boundaries? If not allowed, alignment may be changed to minimize the risk of truncation. |
originX | int | nil | Horizontal origin of alignment, e.g. right aligned from the center (left+bottom)/2 |
originY | int | nil | Vertical origin of alignment, e.g. top aligned from 1/3 of the height. |
autoLineBreak | bool | false | Split text into lines to try to avoid horizontal overflow? |
score | Score | nil | In case of text with tokens like $T (title), $N (number of pages), if score is provided, tokens are transformed. See Text commands in manual. |
- Returns
- number: Width needed to draw the full text, even if it overflows and as been truncated.
- number: Height needed to draw the full text, even if it overflows and as been truncated.
DrawPicture(Graph graphContext, string file, number left, number top, number right, number bottom, int verticalAlign, int horizontal, int scaling, bool keepAspectRatio)
Draw a picture file, using Graph.DrawPicture(...)
with advanced and easy-to-use resizing and alignments.
Download the demo script SMGraph DrawPicture. It installs in Scripts>Miscellaneous>Dev tools menu. It shows all behaviours, and you can copy/paste the code.
Although Graph.DrawPicture
can a "broken icon" if file doesn't exist, this function will draw nothing, because size of the broken icon is unknown. A debugging message will appear in console and nil is returned.
left, top, right and bottom represent a rectangle, but if the rectangle have a width or height of 0, the picture can be scaled always keep its original aspect ratio.
If they represent a single point (width and height are zero), image can't be scaled.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
file | string | A PICT (.pct), BMP, JPG, PNG file | |
left | number | ||
top | number | ||
right | number | left | |
bottom | number | top | |
verticalAlign | int | nil | One of VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE or VERTICAL_ALIGN_BOTTOM. If nil and not a rectangle, default is VERTICAL_ALIGN_TOP. If nil and all rectangle boundaries are provided, default is VERTICAL_ALIGN_MIDDLE. |
horizontal | int | nil | One of ALIGN_LEFT, ALIGN_RIGHT or ALIGN_CENTER. If nil and not a rectangle, default is ALIGN_LEFT. If nil and all rectangle boundaries are provided, default is ALIGN_CENTER. |
scaling | int | PICTURE_SCALE_SHRINK | One of PICTURE_SCALE_NEVER, PICTURE_SCALE_SHRINK, PICTURE_SCALE_ENLARGE or PICTURE_SCALE_ALWAYS. |
keepAspectRatio | bool | true | If resized, keep aspect ratio? |
- Returns
- number: Left boundary of the drawn picture
- number: Top boundary of the drawn picture
- number: Right boundary of the drawn picture
- number: Bottom boundary of the drawn picture
BuildPolygon(Graph graphContext, table points, bool autoClose)
Open a polygon, draw lines between each point and close the polygon.
Having the polygon, you can paint, erase, invert... and must kill it.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
points | table | Table of {x,y} | |
autoClose | bool | true | Close the polygon? If true, 3 points draw a triangle, else it draw 2 lines. |
- Return
- int: the id of the polygon.
- Errors
- if points is not a table or have less than 3 values
- if each point is not a table with x and y not nil.
- Example
local tri = BuildPolygon(item.GraphContext, {{xA,yA}, {xB,yB}, {xC,yC}}) item.GraphContext.FramePolygon(tri) item.GraphContext.KillPolygon(tri)
FrameTriangle(Graph graphContext, number xA, number yA, number xB, number yB, number xC, number yC)
Draws an outline just inside of the borders of an ABC triangle.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
xA | number | ||
yA | number | ||
xB | number | ||
yB | number | ||
xC | number | ||
yC | number |
- Error
- if one coordinate is nil
PaintTriangle(Graph graphContext, number xA, number yA, number xB, number yB, number xC, number yC)
Fills an ABC triangle with the current pen pattern, using the current pen transfer mode.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
xA | number | ||
yA | number | ||
xB | number | ||
yB | number | ||
xC | number | ||
yC | number |
- Error
- if one coordinate is nil
DrawArrow90DegreesHead(Graph graphContext, number left, number top, number right, number bottom, int orientation, int headSize, string headType, bool drawBody)
Draws a 90°-headed (2 lines) arrow in the given boundaries, pointing to the given orientation.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
left | number | ||
top | number | ||
right | number | ||
bottom | number | ||
orientation | int | One of ORIENTATION_* constants | |
headSize | int | max in boundaries | Limit head size? |
headType | string | "angle" | "angle", "black triangle", "white triangle" |
drawBody | bool | true | Draw the arrow body (line) |