Menu

GFX

Benedict Jäggi

Back to [APK_DOTNET_MAUI]

GFX.cs

All graphics functions are in this file.
It's made with static members and functions instead of using a singleton.
So consider that before each member and function there is the word "static", but not here in the docs.
Use that instead of drawing directly with the MAUI engine, so that one only has to change this file when the rendering engine changes.

class GFX

ICanvas canvas

The MAUI GraphicsView component will be accessed with this canvas variable.
Don't use it outside of the GFX class. This holds all MAUI draw functions.

PointF screenSize

The display (respective GraphicsView) width (X) and height (Y).

PointF adjustScreen

This is used to draw only on the field of the lower screenSize parameter.
(It's used to make the playfield square.)
e.g. if screenSize.X > screenSize.Y then adjustScreen.X will be (screenSize.X - screenSize.Y)/2,
so that you can adjust the X coordinate to the center of the screen. adjustSize.Y is 0 then.

object? parentObject

This will be this from the class instance calling initializeValues.
It's used only for DrawImage and because everything here is static.

Dictionary<string, iimage=""> dictImages</string,>

This dictionary holds all the images which were already loaded once, so that it must not load the images in every draw call. The key is the path to the image.

void initializeValues(object caller, ICanvas c, float graphicsWidth, float graphicsHeight)

This function gets called in the engine before the Draw function of cGame is called. It initializes all the above values.
- caller: set to "this" in the IDrawable.
- c: the MAUI canvas given in the draw function.
- graphicsWidth: Width of the viewport
- graphicsHeight: Height of the viewport

PointF getScreenSize()

Returns screenSize

PointF getAdjustScreen()

Returns adjustScreen

void setStroke(Color col, int strokeSize = 5)

Set the MAUI canvas stroke color and size.
Use this before you draw any lines or something with border.
You must only use it once until color or size changes.

void setFont(IFont font, Color color, int fontsize)

Sets the font used in DrawText(), and its color and size.
You must only set this once until font, color or size changes.

void DrawCenteredText(string text, float x = 0, float y = 0, float w = 200, float h = 50)

Draws the text text with the font, color and size set with setFont() centered in the rectangle from x, y to x+w, y+h.
Only use in IGame.onDraw() - Function

void DrawLine(float x1, float y1, float x2, float y2)

Draws a line from x1, y1 to x2, y2 with the color and line width set with setStroke.
Only use in IGame.onDraw() - Function

void DrawRect(float x, float y, float w, float h)

Draws a NOT FILLED rectangle from x, y to x+w, y+h with a border with the line width and color set with setStroke.
Only use in IGame.onDraw() - Function

void DrawFilledRect(Color fillcolor, float x, float y, float w, float h)

Draws a rectangle from x, y to x+w, y+h, filled with the color fillcolor.
Only use in IGame.onDraw() - Function

void DrawRoundedRect(float x, float y, float w, float h, float cornerRadius)

Draws a NOT FILLED rectangle from x, y to x+w, y+h with the color and line width set with setStroke and round corners with the radius cornerRadius.
Only use in IGame.onDraw() - Function

void DrawFilledRoundedRect(Color fillcolor, float x, float y, float w, float h, float cornerRadius)

Draws a rectangle from x, y to x+w, y+h filled with the color fillcolor and round corners with the radius cornerRadius.
Only use in IGame.onDraw() - Function

void DrawCircle(float x, float y, float radius)

Draws a NOT filled circle with the color and line thickness set with setStroke at x, y with radius radius.

void DrawFilledCircle(Color fillcolor, float x, float y, float radius)

Draws a filled circle with the fillcolor at x, y with radius radius.
Only use in IGame.onDraw() - Function

void DrawCheckeredFields(float startx, float starty, float width, float height, int fieldCountXY, Color color1, Color color2)

Draws a "chess playfield" with fieldCountXY * fieldCountXY fields (X same as Y) from startx, starty to startx+width, starty+height in the colors color1 and color2.
Only use in IGame.onDraw() - Function

void DrawImage(IImage image, float x, float y, float w, float h)

Draws the image at x, y in size w, h. If w or h are < 0 then it will use the size of the image respectively.
Only use in IGame.onDraw() - Function
DO NOT USE THIS FUNCTION. USE THE ONE BELOW.

void DrawImage(string imagepath, float x, float y, float w, float h)

Loads the image at imagepath into the imageDict dictionary if it is not already loaded.

Draws the image from the imageDict dictionary with key imagepath at x, y in the size w, h. If w or h is < 0 then it will use the image size respectively.

Only use in IGame.onDraw() - Function

void ClearAllImages()

Clears all the images in the dictImages-Dictionary.

int GetLoadedImageCount()

Returns how many images are in the dictImages-Dictionary.


Related

Wiki: APK_DOTNET_MAUI
Wiki: IGame