Class DispEngine
HiAPI display engine.
public class DispEngine : IDisposable, IGetDispEngine
- Inheritance
-
DispEngine
- Implements
- Inherited Members
- Extension Methods
Remarks
The DispEngine
is the core rendering and interaction engine for HiAPI applications.
Related Documentation
The DispEngine provides a unified API for handling rendering, user interaction, and touch gestures across different UI frameworks.
Constructors
DispEngine(IDisplayee)
Ctor. The SetViewToHomeView() is called in this function.
public DispEngine(IDisplayee displayee)
Parameters
displayee
IDisplayeeThe displayee to render.
DispEngine(params IDisplayee[])
Ctor.
public DispEngine(params IDisplayee[] displayees)
Parameters
displayees
IDisplayee[]displayees to render.
Fields
CoreDll
Core dll path.
public const string CoreDll = "core.dll"
Field Value
defaultFontFile
The default font file path used by the display engine.
public const string defaultFontFile = "Font/WCL06.ttf"
Field Value
Properties
BackgroundColor
Background color
public Vec3d BackgroundColor { get; set; }
Property Value
BackgroundOpacity
Background opacity. Range is from 0 to 1.
public double BackgroundOpacity { get; set; }
Property Value
ContextProjDepth
Gets the projection depth of the current context.
public static double ContextProjDepth { get; }
Property Value
CursorOffsetX
Internal Use.
public int CursorOffsetX { get; }
Property Value
CursorOffsetY
Internal Use.
public int CursorOffsetY { get; }
Property Value
CursorX
Internal Use.
public int CursorX { get; set; }
Property Value
CursorY
Internal Use.
public int CursorY { get; set; }
Property Value
Displayee
Displayee to be rendered in the rendering loop. The SetViewToHomeView() is called in this function.
public IDisplayee Displayee { get; set; }
Property Value
EnableSuppressDefaultLogo
Get or Set to Enable Suppress Default Logo. The set take no effect if the license SuppressDefaultLogo is not login.
public static bool EnableSuppressDefaultLogo { get; set; }
Property Value
FontFile
Font file.
public static string FontFile { get; set; }
Property Value
IsOnDispThread
Gets a value indicating whether the current thread is the display thread.
public static bool IsOnDispThread { get; }
Property Value
IsVisible
The anime stop running if the value is false; otherwise, the anime starts or keeps running.
public bool IsVisible { get; set; }
Property Value
Model
public Mat4d Model { get; set; }
Property Value
- Mat4d
Model matrix in MVP convention. This Model matrix is the first matrix in Hi.Disp.Bind.modelMatStack.
PixelProj
public Mat4d PixelProj { get; set; }
Property Value
PreCursorX
Internal Use.
public int PreCursorX { get; set; }
Property Value
PreCursorY
Internal Use.
public int PreCursorY { get; set; }
Property Value
PrincipleView
public Mat4d PrincipleView { get; set; }
Property Value
- Mat4d
view = PrincipleView * SketchView. Where view matrix is in MVP convention.
Remarks
The default value is new Mat4d(new Vec3d(1, 0, 0), -Math.PI / 2). This make the 2D plane from xy plane to xz plane. The xz plane is much suit for 3D engineering display.
RefreshingPeriod
Image refreshing period.
public TimeSpan RefreshingPeriod { get; set; }
Property Value
ScaleProj
public Mat4d ScaleProj { get; set; }
Property Value
SketchView
view = PrincipleView * SketchView. Where view matrix is in MVP convention.
public Mat4d SketchView { get; set; }
Property Value
Methods
DeleteDispContext()
Deletes the current display context.
public static void DeleteDispContext()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
EnqueueDispose(IDisposable)
Enqueues a disposable object to be disposed on the display thread.
public static Task EnqueueDispose(IDisposable disposable)
Parameters
disposable
IDisposableThe disposable object to be disposed
Returns
- Task
A task representing the disposal operation
EnqueueTask(Task)
Enqueues a task to be executed on the display thread.
public static Task EnqueueTask(Task task)
Parameters
task
TaskThe task to be executed
Returns
- Task
The enqueued task
EnqueueTask<T>(Task<T>)
Enqueues a task to be executed on the display thread.
public static Task<T> EnqueueTask<T>(Task<T> task)
Parameters
task
Task<T>The task to be executed
Returns
- Task<T>
The enqueued task
Type Parameters
T
The type of the task result
~DispEngine()
protected ~DispEngine()
FinishDisp()
Elegantly end the rendering core. Probably not essential.
public static void FinishDisp()
GetDispEngine()
Get DispEngine.
public DispEngine GetDispEngine()
Returns
Init(string)
Initializes the display engine system.
public static void Init(string fontFile = null)
Parameters
fontFile
stringThe font file to use. If null, the default font file will be used.
IsMouseButtonPressed(long)
Checks if a specific mouse button is currently pressed.
public bool IsMouseButtonPressed(long mouseButton)
Parameters
mouseButton
longThe mouse button to check, typically a value from the HiMouseButton enumeration.
Returns
- bool
True if the specified mouse button is pressed; otherwise, false.
Remarks
This method is useful for implementing conditional UI behaviors based on mouse button state:
// Check if left mouse button is pressed
if (dispEngine.IsMouseButtonPressed((long)HiMouseButton.Left))
{
// Perform special action while left button is held down
}
KeyDown(long)
Key down. This function is typically called in the GUI implementation for keyboard interaction.
public void KeyDown(long key)
Parameters
key
longkey
KeyDownTransform(long, key_table__transform_view_by_key_pressing_t)
Transform SketchView by key. Home, F1, F2, F3, F4 call SetViewToHomeView(), SetViewToFrontView(), SetViewToSideView(), SetViewToTopView(), SetViewToIsometricView() respectively. PageDown and PageUp scale the SketchView. Left, Right, Down, Up translate the SketchView; Press Shift make these keys to rotate the SketchView.
public void KeyDownTransform(long key, key_table__transform_view_by_key_pressing_t table)
Parameters
key
longThe key that was pressed, typically a value from the HiKey enumeration.
table
key_table__transform_view_by_key_pressing_tA table defining which keys trigger different transformation operations.
Remarks
This method is typically called from key down event handlers in the GUI implementation.
KeyUp(long)
Key up. This function is typically called in the GUI implementation for keyboard interaction.
public void KeyUp(long key)
Parameters
key
longkey
LockGlContext()
Lock a opengl context. The function is only used for native OpenGL rendering. After lock the gl context, It should be unlock by UnlockGlContext(nint).
public static nint LockGlContext()
Returns
Remarks
If any other lock requires LockGlContext, the lock should better set inside LockGlContext. or it is easy to occur race condition. see design pattern of “Solid” class for reference.
MouseButtonDown(long)
Mouse button down. This function is typically called in the GUI implementation for mouse interaction.
public void MouseButtonDown(long button)
Parameters
button
longbutton
MouseButtonUp(long)
Mouse button up. This function is typically called in the GUI implementation for mouse interaction.
public void MouseButtonUp(long button)
Parameters
button
longbutton
MouseDragTransform(int, int, mouse_button_table__transform_view_by_mouse_drag_t)
Transform the view by mouse drag. If drag by left mouse button, Translate(double, double) is performed; If drag by right mouse button, Rotate(double, double) is performed.
public void MouseDragTransform(int x, int y, mouse_button_table__transform_view_by_mouse_drag_t mouse_button_table)
Parameters
x
intThe current x-coordinate of the mouse cursor.
y
intThe current y-coordinate of the mouse cursor.
mouse_button_table
mouse_button_table__transform_view_by_mouse_drag_tA table defining which mouse buttons trigger different transformation operations.
Remarks
The mouse_button_table__transform_view_by_mouse_drag_t structure allows you to configure which mouse buttons perform which transformations:
var buttonTable = new mouse_button_table__transform_view_by_mouse_drag_t
{
LEFT_BUTTON = (long)HiMouseButton.Left, // For translation
RIGHT_BUTTON = (long)HiMouseButton.Right // For rotation
};
This method is typically called from mouse move event handlers when buttons are pressed.
MouseMove(int, int)
Mouse move. This function is typically called in the GUI implementation for mouse interaction.
public void MouseMove(int x, int y)
Parameters
MouseWheel(int, int)
Mouse wheel move. This function is typically called in the GUI implementation for mouse interaction.
public void MouseWheel(int deltaX, int deltaY)
Parameters
MouseWheelTransform(int, int, double)
Scale SketchView by mouse wheel.
public void MouseWheelTransform(int deltaX, int deltaY, double zooming_ratio = 0.2)
Parameters
deltaX
intmouse wheel delta X
deltaY
intmouse wheel delta Y. The traditional mouse wheel.
zooming_ratio
doubleThe ratio used for zooming. Default is 0.2.
Resize(int, int)
Resize the opengl context.
public void Resize(int w, int h)
Parameters
Rotate(double, double)
Rotate the SketchView. Usually used by mouse drag on window. The rotation axis is along (delta_y, 0, delta_x). The rotation rad is 5 * Math.Sqrt(delta_y * delta_y + delta_x * delta_x) / window_height.
public void Rotate(double delta_x, double delta_y)
Parameters
RotateAndScaleByTouchPad(Vec2d, Vec2d, Vec2d, Vec2d)
Rotate and scale the SketchView based on touch pad gestures.
public void RotateAndScaleByTouchPad(Vec2d prePosA, Vec2d curPosA, Vec2d prePosB, Vec2d curPosB)
Parameters
prePosA
Vec2dThe previous position of the first touch point.
curPosA
Vec2dThe current position of the first touch point.
prePosB
Vec2dThe previous position of the second touch point.
curPosB
Vec2dThe current position of the second touch point.
Remarks
The method detects two types of gestures:
- Pinch gesture: When the distance between touch points changes, it triggers zooming via MouseWheelTransform(int, int, double)
- Rotation/Pan gesture: When touch points move together, it triggers rotation via Rotate(double, double)
This method is typically used to implement touchpad or multi-touch gestures in custom UI implementations.
RotateWithoutHeightAdjustment(double, double)
Rotate the SketchView. Usually used by keyboard command. The rotation axis is along (delta_y, 0, delta_x). The rotation rad is Math.ToRad(Math.Sqrt(delta_y * delta_y + delta_x * delta_x)).
public void RotateWithoutHeightAdjustment(double delta_x, double delta_y)
Parameters
SetViewToFrontView()
Set the SketchView to front view.
public void SetViewToFrontView()
SetViewToHomeView()
Set the SketchView to home view(front view). This is the same as SetViewToFrontView().
public void SetViewToHomeView()
SetViewToIsometricView()
Set the SketchView to isometric view.
public void SetViewToIsometricView()
SetViewToSideView()
Set the SketchView to side view.
public void SetViewToSideView()
SetViewToTopView()
Set the SketchView to top view.
public void SetViewToTopView()
Snapshot(string)
Snapshot to BMP file with current canvas size.
public void Snapshot(string filePath)
Parameters
filePath
string
Snapshot(string, int, int)
Snapshot to BMP file.
public void Snapshot(string filePath, int panelWidth, int panelHeight)
Parameters
Start(int, int)
Start a thread of keeping Swapping buffers of OpenGL context. If the thread has running, this function does nothing.
public void Start(int panelWidth, int panelHeight)
Parameters
Terminate()
Terminate the opengl context swapping buffers thread from Start(int, int). If the thread has not running, this function does nothing.
public void Terminate()
TouchDown(int, int, int)
Tracks a new touch point in the DispEngine's touch gesture system.
public void TouchDown(int touchId, int x, int y)
Parameters
touchId
intA unique identifier for the touch point.
x
intThe x-coordinate of the touch point in screen coordinates.
y
intThe y-coordinate of the touch point in screen coordinates.
Remarks
When a touch point is added, the method:
- Stores the touch point in the internal tracking dictionary
- If this is the first touch point, simulates a mouse move and left button press
TouchMove(int, int, int)
Updates the position of an existing touch point.
public void TouchMove(int touchId, int x, int y)
Parameters
touchId
intThe unique identifier of the touch point to update.
x
intThe new x-coordinate of the touch point in screen coordinates.
y
intThe new y-coordinate of the touch point in screen coordinates.
Remarks
The method handles different gestures based on the number of active touch points:
- Single touch: Performs panning (translation) like mouse dragging
- Two touches: Performs pinch-to-zoom and rotation gestures
TouchUp(int)
Removes a touch point from tracking when the touch is released.
public void TouchUp(int touchId)
Parameters
touchId
intThe unique identifier of the touch point to remove.
Remarks
When a touch point is released, the method:
- Removes the touch point from internal tracking dictionaries
- If all touch points are released, simulates a mouse button release
- If transitioning from multi-touch to single-touch, updates the mouse position to prevent “teleportation”
Translate(double, double)
Translate the SketchView. Usually used by mouse drag on window. The translation is (delta_x * 2.0 / h, 0, -delta_y* 2.0 / h). Where h is window height.
public void Translate(double delta_x, double delta_y)
Parameters
UnlockGlContext(nint)
Unlock opengl context. The function is only used for native OpenGL rendering. The function unlock the opengl context for LockGlContext().
public static void UnlockGlContext(nint disp_torch_p)
Parameters
disp_torch_p
nint
Events
FinishingDisp
Event at the begining of FinishDisp()
public static event Action FinishingDisp
Event Type
ImageRequestAfterBufferSwapped
Triggered after swap buffer of gl context.
public event DispEngine.ImageRequestedDelegate ImageRequestAfterBufferSwapped