Table of Contents

Class GuiElement

Namespace
Vintagestory.API.Client
Assembly
VintagestoryAPI.dll
public abstract class GuiElement : IDisposable
Inheritance
GuiElement
Implements
Derived
Inherited Members

Constructors

GuiElement(ICoreClientAPI, ElementBounds)

Adds a new GUIElement to the GUI.

public GuiElement(ICoreClientAPI capi, ElementBounds bounds)

Parameters

capi ICoreClientAPI

The Client API

bounds ElementBounds

The bounds of the element.

Fields

Bounds

The bounds of the element.

public ElementBounds Bounds

Field Value

ElementBounds

TabIndex

The tab index of the element.

public int TabIndex

Field Value

int

api

The Client API.

protected ICoreClientAPI api

Field Value

ICoreClientAPI

dirtTextureName

public static AssetLocation dirtTextureName

Field Value

AssetLocation

hasFocus

Whether or not the element has focus.

protected bool hasFocus

Field Value

bool

noisyMetalTextureName

public static AssetLocation noisyMetalTextureName

Field Value

AssetLocation

paperTextureName

public static AssetLocation paperTextureName

Field Value

AssetLocation

stoneTextureName

public static AssetLocation stoneTextureName

Field Value

AssetLocation

waterTextureName

public static AssetLocation waterTextureName

Field Value

AssetLocation

woodTextureName

public static AssetLocation woodTextureName

Field Value

AssetLocation

Properties

DrawOrder

0 = draw first, 1 = draw last. Only for interactive elements.

public virtual double DrawOrder { get; }

Property Value

double

Focusable

Whether or not the element can be focused.

public virtual bool Focusable { get; }

Property Value

bool

HasFocus

Whether or not the element has focus or not.

public bool HasFocus { get; }

Property Value

bool

InsideClipBounds

If the element is inside a clip or not.

public virtual ElementBounds InsideClipBounds { get; set; }

Property Value

ElementBounds

MouseOverCursor

public virtual string MouseOverCursor { get; protected set; }

Property Value

string

RenderAsPremultipliedAlpha

public bool RenderAsPremultipliedAlpha { get; set; }

Property Value

bool

Scale

The scale of the element.

public virtual double Scale { get; set; }

Property Value

double

Methods

BeforeCalcBounds()

public virtual void BeforeCalcBounds()

ComposeElements(Context, ImageSurface)

Composes the elements.

public virtual void ComposeElements(Context ctxStatic, ImageSurface surface)

Parameters

ctxStatic Context

The context of the components.

surface ImageSurface

The surface of the GUI.

DialogRoundRectangle(Context, ElementBounds)

Creates a rounded rectangle.

public void DialogRoundRectangle(Context ctx, ElementBounds bounds)

Parameters

ctx Context

The GUI context

bounds ElementBounds

The bounds of the rectangle.

DiscardPattern(AssetLocation)

Discards a pattern based off the the filename.

public static void DiscardPattern(AssetLocation textureLoc)

Parameters

textureLoc AssetLocation

The pattern to discard.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

ElementRoundRectangle(Context, ElementBounds, bool, double)

Creates a rounded rectangle element.

public void ElementRoundRectangle(Context ctx, ElementBounds bounds, bool isBackground = false, double radius = -1)

Parameters

ctx Context

The context for the rectangle.

bounds ElementBounds

The bounds of the rectangle.

isBackground bool

Is the rectangle part of a background GUI object (Default: false)

radius double

The radius of the corner of the rectangle (default: -1)

EmbossRoundRectangle(Context, double, double, double, double, double, int, float, float, bool, float)

Adds an embossed rounded rectangle to the dialog.

protected void EmbossRoundRectangle(Context ctx, double x, double y, double width, double height, double radius, int depth = 3, float intensity = 0.4, float lightDarkBalance = 1, bool inverse = false, float alphaOffset = 0)

Parameters

ctx Context

The context of the rectangle.

x double

The X position of the rectangle

y double

The Y position of the rectangle

width double

The width of the rectangle

height double

The height of the rectangle.

radius double

The radius of the corner of the rectangle.

depth int

The thickness of the emboss. (Default: 3)

intensity float

The intensity of the emboss. (Default: 0.4f)

lightDarkBalance float

How skewed is the light/dark balance (Default: 1)

inverse bool

Whether or not it goes in or out. (Default: false)

alphaOffset float

The offset for the alpha part of the emboss. (Default: 0)

EmbossRoundRectangleDialog(Context, double, double, double, double, bool)

Adds an embossed rounded rectangle to the dialog.

public void EmbossRoundRectangleDialog(Context ctx, double x, double y, double width, double height, bool inverse = false)

Parameters

ctx Context

The context of the rectangle.

x double

The X position of the rectangle

y double

The Y position of the rectangle

width double

The width of the rectangle

height double

The height of the rectangle.

inverse bool

Whether or not it goes in or out.

EmbossRoundRectangleElement(Context, double, double, double, double, bool, int, int)

Adds an embossed rounded rectangle to the dialog.

public void EmbossRoundRectangleElement(Context ctx, double x, double y, double width, double height, bool inverse = false, int depth = 2, int radius = -1)

Parameters

ctx Context

The context of the rectangle.

x double

The X position of the rectangle

y double

The Y position of the rectangle

width double

The width of the rectangle

height double

The height of the rectangle.

inverse bool

Whether or not it goes in or out.

depth int

The depth of the emboss.

radius int

The radius of the corner of the rectangle.

EmbossRoundRectangleElement(Context, ElementBounds, bool, int, int)

Adds an embossed rounded rectangle to the dialog.

public void EmbossRoundRectangleElement(Context ctx, ElementBounds bounds, bool inverse = false, int depth = 2, int radius = -1)

Parameters

ctx Context

The context of the rectangle.

bounds ElementBounds

The position and size of the rectangle.

inverse bool

Whether or not it goes in or out. (Default: false)

depth int

The depth of the emboss. (Default: 2)

radius int

The radius of the corner of the rectangle. (default: -1)

IsPositionInside(int, int)

Whether or not the point on screen is inside the Element's area.

public virtual bool IsPositionInside(int posX, int posY)

Parameters

posX int

The X Position of the point.

posY int

The Y Position of the point.

Returns

bool

Lamp(Context, double, double, float[])

protected void Lamp(Context ctx, double x, double y, float[] color)

Parameters

ctx Context
x double
y double
color float[]

OnFocusGained()

The event fired when the element gains focus.

public virtual void OnFocusGained()

OnFocusLost()

The event fired when the element looses focus.

public virtual void OnFocusLost()

OnKeyDown(ICoreClientAPI, KeyEvent)

The event fired when a key is held down.

public virtual void OnKeyDown(ICoreClientAPI api, KeyEvent args)

Parameters

api ICoreClientAPI

The client API

args KeyEvent

The key event arguments.

OnKeyPress(ICoreClientAPI, KeyEvent)

The event fired the moment a key is pressed.

public virtual void OnKeyPress(ICoreClientAPI api, KeyEvent args)

Parameters

api ICoreClientAPI

The Client API.

args KeyEvent

The keyboard state when the key was pressed.

OnKeyUp(ICoreClientAPI, KeyEvent)

The event fired when a key is held down.

public virtual void OnKeyUp(ICoreClientAPI api, KeyEvent args)

Parameters

api ICoreClientAPI

The client API

args KeyEvent

The key event arguments.

OnMouseDown(ICoreClientAPI, MouseEvent)

The event fired when the mouse is down the element is around. Fires before OnMouseDownOnElement, however OnMouseDownOnElement is called within the base function.

public virtual void OnMouseDown(ICoreClientAPI api, MouseEvent mouse)

Parameters

api ICoreClientAPI

The Client API

mouse MouseEvent

The mouse event args.

OnMouseDownOnElement(ICoreClientAPI, MouseEvent)

The event fired when the mouse is pressed while on the element. Called after OnMouseDown and tells the engine that the event is handled.

public virtual void OnMouseDownOnElement(ICoreClientAPI api, MouseEvent args)

Parameters

api ICoreClientAPI

The Client API

args MouseEvent

The mouse event args.

OnMouseEnterSlot(ICoreClientAPI, ItemSlot)

public virtual bool OnMouseEnterSlot(ICoreClientAPI api, ItemSlot slot)

Parameters

api ICoreClientAPI
slot ItemSlot

Returns

bool

OnMouseLeaveSlot(ICoreClientAPI, ItemSlot)

public virtual bool OnMouseLeaveSlot(ICoreClientAPI api, ItemSlot slot)

Parameters

api ICoreClientAPI
slot ItemSlot

Returns

bool

OnMouseMove(ICoreClientAPI, MouseEvent)

The event fired when the mouse is moved.

public virtual void OnMouseMove(ICoreClientAPI api, MouseEvent args)

Parameters

api ICoreClientAPI

The Client API.

args MouseEvent

The mouse event arguments.

OnMouseUp(ICoreClientAPI, MouseEvent)

The event fired when the mouse is released.

public virtual void OnMouseUp(ICoreClientAPI api, MouseEvent args)

Parameters

api ICoreClientAPI

The Client API.

args MouseEvent

The arguments for the mouse event.

OnMouseUpOnElement(ICoreClientAPI, MouseEvent)

The event fired when the mouse is released on the element. Called after OnMouseUp.

public virtual void OnMouseUpOnElement(ICoreClientAPI api, MouseEvent args)

Parameters

api ICoreClientAPI

The Client API

args MouseEvent

The mouse event args.

OnMouseWheel(ICoreClientAPI, MouseWheelEventArgs)

The event fired when the mouse wheel is scrolled.

public virtual void OnMouseWheel(ICoreClientAPI api, MouseWheelEventArgs args)

Parameters

api ICoreClientAPI

The Client API

args MouseWheelEventArgs

The mouse wheel arguments.

OutlineColor()

The compressed version of the debug outline color as a single int value.

public virtual int OutlineColor()

Returns

int

PostRenderInteractiveElements(float)

The post render of the interactive element.

public virtual void PostRenderInteractiveElements(float deltaTime)

Parameters

deltaTime float

The change in time.

Rectangle(Context, double, double, double, double)

Makes a rectangle with specified parameters.

public static void Rectangle(Context ctx, double x, double y, double width, double height)

Parameters

ctx Context

Context of the rectangle

x double

The X position of the rectangle

y double

The Y position of the rectangle

width double

The width of the rectangle

height double

The height of the rectangle.

Rectangle(Context, ElementBounds)

Makes a rectangle with the provided context and bounds.

public static void Rectangle(Context ctx, ElementBounds bounds)

Parameters

ctx Context

The context for the rectangle.

bounds ElementBounds

The bounds of the rectangle.

Render2DTexture(int, double, double, double, double, float, Vec4f)

protected void Render2DTexture(int textureid, double posX, double posY, double width, double height, float z = 50, Vec4f color = null)

Parameters

textureid int
posX double
posY double
width double
height double
z float
color Vec4f

Render2DTexture(int, float, float, float, float, float, Vec4f)

protected void Render2DTexture(int textureid, float posX, float posY, float width, float height, float z = 50, Vec4f color = null)

Parameters

textureid int
posX float
posY float
width float
height float
z float
color Vec4f

Render2DTexture(int, ElementBounds, float, Vec4f)

protected void Render2DTexture(int textureid, ElementBounds bounds, float z = 50, Vec4f color = null)

Parameters

textureid int
bounds ElementBounds
z float
color Vec4f

RenderBoundsDebug()

public virtual void RenderBoundsDebug()

RenderFocusOverlay(float)

Renders the focus overlay.

public void RenderFocusOverlay(float deltaTime)

Parameters

deltaTime float

The change in time.

RenderInteractiveElements(float)

Renders the element as an interactive element.

public virtual void RenderInteractiveElements(float deltaTime)

Parameters

deltaTime float

The change in time.

RoundRectangle(Context, double, double, double, double, double)

Creates a rounded rectangle

public static void RoundRectangle(Context ctx, double x, double y, double width, double height, double radius)

Parameters

ctx Context

The context for the rectangle.

x double

The X position of the rectangle

y double

The Y position of the rectangle

width double

The width of the rectangle

height double

The height of the rectangle.

radius double

The radius of the corner of the rectangle.

ShadePath(Context, double)

Shades a path with the given context.

public void ShadePath(Context ctx, double thickness = 2)

Parameters

ctx Context

The context of the shading.

thickness double

The thickness of the line to shade.

fillWithPattern(ICoreClientAPI, Context, AssetLocation, bool, bool, int, float)

Fills an area with a pattern.

public static SurfacePattern fillWithPattern(ICoreClientAPI capi, Context ctx, AssetLocation textureLoc, bool nearestScalingFiler = false, bool preserve = false, int mulAlpha = 255, float scale = 1)

Parameters

capi ICoreClientAPI

The Client API

ctx Context

The context of the fill.

textureLoc AssetLocation

The name of the texture file.

nearestScalingFiler bool
preserve bool

Whether or not to preserve the aspect ratio of the texture.

mulAlpha int
scale float

Returns

SurfacePattern

The surface pattern filled with the given texture.

genContext(ImageSurface)

Generates context based off the image surface.

protected Context genContext(ImageSurface surface)

Parameters

surface ImageSurface

The surface where the context is based.

Returns

Context

The context based off the provided surface.

generateTexture(ImageSurface, ref int, bool)

Generates a texture with an ID.

protected void generateTexture(ImageSurface surface, ref int textureId, bool linearMag = true)

Parameters

surface ImageSurface

The image surface supplied.

textureId int

The previous texture id.

linearMag bool

Whether or not the texture will have linear magnification.

generateTexture(ImageSurface, ref LoadedTexture, bool)

Generates a new texture.

protected void generateTexture(ImageSurface surface, ref LoadedTexture intoTexture, bool linearMag = true)

Parameters

surface ImageSurface

The surface provided.

intoTexture LoadedTexture

The texture to be loaded into.

linearMag bool

Whether or not the texture will have linear magnification.

getImageSurfaceFromAsset(SKBitmap)

Gets an image surface based off the bitmap.

[Obsolete("Use getImageSurfaceFromAsset(BitmapExternal bitmap) for easier update to .NET7.0")]
public static ImageSurface getImageSurfaceFromAsset(SKBitmap bitmap)

Parameters

bitmap SKBitmap

The provided bitmap.

Returns

ImageSurface

The image surface built from the bitmap.

getImageSurfaceFromAsset(SKBitmap, int, int)

Gets an image surface based off the bitmap.

[Obsolete("Use getImageSurfaceFromAsset(BitmapExternal bitmap, int width, int height) for easier update to .NET7.0")]
public static ImageSurface getImageSurfaceFromAsset(SKBitmap bitmap, int width, int height)

Parameters

bitmap SKBitmap

The provided bitmap.

width int

The width requested.

height int

The height requested.

Returns

ImageSurface

The image surface built from the bitmap and data.

getImageSurfaceFromAsset(ICoreClientAPI, AssetLocation, int)

Fetches an image surface from a named file.

public static ImageSurface getImageSurfaceFromAsset(ICoreClientAPI capi, AssetLocation textureLoc, int mulAlpha = 255)

Parameters

capi ICoreClientAPI

The Client API

textureLoc AssetLocation

The name of the text file.

mulAlpha int

Returns

ImageSurface

getImageSurfaceFromAsset(BitmapExternal)

Gets an image surface based off the bitmap.

public static ImageSurface getImageSurfaceFromAsset(BitmapExternal bitmap)

Parameters

bitmap BitmapExternal

The provided bitmap.

Returns

ImageSurface

The image surface built from the bitmap.

getImageSurfaceFromAsset(BitmapExternal, int, int)

Gets an image surface based off the bitmap.

public static ImageSurface getImageSurfaceFromAsset(BitmapExternal bitmap, int width, int height)

Parameters

bitmap BitmapExternal

The provided bitmap.

width int

The width requested.

height int

The height requested.

Returns

ImageSurface

The image surface built from the bitmap and data.

getPattern(SKBitmap)

Gets a surface pattern based off the bitmap.

[Obsolete("Use getPattern(BitmapExternal bitmap) for easier update to .NET7.0")]
public static SurfacePattern getPattern(SKBitmap bitmap)

Parameters

bitmap SKBitmap

The provided bitmap.

Returns

SurfacePattern

The resulting surface pattern.

getPattern(ICoreClientAPI, AssetLocation, bool, int, float)

Gets a surface pattern from a named file.

public static SurfacePattern getPattern(ICoreClientAPI capi, AssetLocation textureLoc, bool doCache = true, int mulAlpha = 255, float scale = 1)

Parameters

capi ICoreClientAPI

The Client API

textureLoc AssetLocation

The name of the file.

doCache bool

Do we cache the file?

mulAlpha int
scale float

Returns

SurfacePattern

The resulting surface pattern.

getPattern(BitmapExternal)

Gets a surface pattern based off the bitmap.

[Obsolete("Use getPattern(BitmapExternal bitmap) for easier update to .NET7.0")]
public static SurfacePattern getPattern(BitmapExternal bitmap)

Parameters

bitmap BitmapExternal

The provided bitmap.

Returns

SurfacePattern

The resulting surface pattern.

scaled(double)

Changes the scale of given value by the GUIScale factor.

public static double scaled(double value)

Parameters

value double

Returns

double

The scaled value based

scaledi(double)

Changes the scale of given value by the GUIScale factor

public static int scaledi(double value)

Parameters

value double

Returns

int

Scaled value type cast to int