Section Graphics
Utility functions for images, drawing on Graph
- See
- SMGraph.mys
Summary
Return type | Function and summary |
---|---|
int | BuildPolygon(Graph graphContext, table points, boolean autoClose) Open a polygon, draw lines between each point and close the polygon. |
boolean | CropSurface(Surface surface, int red, int green, int blue, int opacity) Crop a Surface for a given color. |
DrawArrow90DegreesHead(Graph graphContext, number left, number top, number right, number bottom, int orientation, int headSize, string headType, boolean drawBody) Draws a 90°-headed (2 lines) arrow in the given boundaries, pointing to the given orientation. | |
DrawCheckbox(Graph graphContext, int left, int top, int right, int bottom, boolean checked, boolean disabled, string foreColor, string backColor, string disableColor) Draw a checkbox. | |
DrawHorizontalSwitch(Graph graphContext, int left, int top, int right, int bottom, boolean turnedOn, boolean disabled, string onColor, string offColor, string unknownColor, string backColor, string disableColor) Draw ah horizontal switch. | |
number, number, number, number | DrawPicture(Graph graphContext, string file, number left, number top, number right, number bottom, int verticalAlign, int horizontal, int scaling, boolean keepAspectRatio) Draw a picture file, using Graph.DrawPicture(...) with advanced and easy-to-use resizing and alignments. |
DrawRadio(Graph graphContext, int left, int top, int right, int bottom, boolean checked, boolean disabled, string foreColor, string backColor, string disableColor) Draw a radio button. | |
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, boolean allowOverflow, int originX, int originY, boolean 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 the outline inside 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. |
Functions
DrawText(Graph graphContext, string text, string fontFamily, int fontSize, int fontFace, number left, number top, number right, number bottom, int verticalAlign, int horizontalAlign, boolean allowOverflow, int originX, int originY, boolean 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 | boolean | 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 | boolean | 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, boolean keepAspectRatio)
Draw a picture file, using Graph.DrawPicture(...)
with advanced and easy-to-use resizing and alignments.
Run demo script > Misceleanneous > Dev tools > SMGraph DrawPicture, 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 | left | |
top | number | top | |
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 | boolean | 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, boolean 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 | boolean | 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 the outline inside the borders of an ABC triangle.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | The GraphContext: dialog.GraphContext , surface.GraphContext ... | |
xA | number | xA | |
yA | number | yA | |
xB | number | xB | |
yB | number | yB | |
xC | number | xC | |
yC | number | yC |
- 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 | xA | |
yA | number | yA | |
xB | number | xB | |
yB | number | yB | |
xC | number | xC | |
yC | number | yC |
- Error
- if one coordinate is nil
DrawArrow90DegreesHead(Graph graphContext, number left, number top, number right, number bottom, int orientation, int headSize, string headType, boolean 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 | left | |
top | number | top | |
right | number | right | |
bottom | number | bottom | |
orientation | int | One of ORIENTATION_* constants | |
headSize | int | max in boundaries | Limit head size? |
headType | string | "angle" | "angle", "black triangle", "white triangle" |
drawBody | boolean | true | Draw the arrow body (line) |
CropSurface(Surface surface, int red, int green, int blue, int opacity)
Crop a Surface for a given color.
For example, CropSurface(mySurface, 255, 255, 255, 255)
crops surface to remove white areas on 4 sides of a drawn image/text/staff.
Parameter | Type | Default | Description |
---|---|---|---|
surface | Surface | The surface to crop | |
red | int | Red value from 0 to 255 | |
green | int | Green value from 0 to 255 | |
blue | int | Blue value from 0 to 255 | |
opacity | int | 255 | Opacity value from 0 to 255 |
- Return
- boolean: true if crop succeed, return by
Surface.Crop(...)
MyrScript function.
DrawCheckbox(Graph graphContext, int left, int top, int right, int bottom, boolean checked, boolean disabled, string foreColor, string backColor, string disableColor)
Draw a checkbox.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | graphContext | |
left | int | left | |
top | int | top | |
right | int | right | |
bottom | int | bottom | |
checked | boolean | nil | true to check, false to uncheck, nil for unknown state |
disabled | boolean | false | true =disabled, the checkbox is gray,. false =enabled, the checkbox is colored. |
foreColor | string | "0000FF" | Foreground color in RGB format |
backColor | string | "FFFFFF" | Background color in RGB format |
disableColor | string | "808080" | Background color in RGB format |
DrawRadio(Graph graphContext, int left, int top, int right, int bottom, boolean checked, boolean disabled, string foreColor, string backColor, string disableColor)
Draw a radio button.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | graphContext | |
left | int | left | |
top | int | top | |
right | int | right | |
bottom | int | bottom | |
checked | boolean | nil | true to check, false to uncheck, nil for unknown state |
disabled | boolean | false | true =disabled, the radio is gray,. false =enabled, the radio is colored. |
foreColor | string | "0000FF" | Foreground color in RGB format |
backColor | string | "FFFFFF" | Background color in RGB format |
disableColor | string | "808080" | Background color in RGB format |
DrawHorizontalSwitch(Graph graphContext, int left, int top, int right, int bottom, boolean turnedOn, boolean disabled, string onColor, string offColor, string unknownColor, string backColor, string disableColor)
Draw ah horizontal switch.
Parameter | Type | Default | Description |
---|---|---|---|
graphContext | Graph | graphContext | |
left | int | left | |
top | int | top | |
right | int | right | |
bottom | int | bottom | |
turnedOn | boolean | nil | true if turned on, false if turned off, nil for unknown state |
disabled | boolean | false | true =disabled, the switch is gray,. false =enabled, the switch is colored. |
onColor | string | 007700"" | Color when switch is turned on |
offColor | string | "FF0000" | Color when switch is turned off |
unknownColor | string | "FF8C00" | Color when switch is in unknown state |
backColor | string | "FFFFFF" | Background color |
disableColor | string | "808080" | Color when switch is disabled. |