Overview
TheVectorDisplayFunctions class extends RefCounted and provides a collection of static utility functions used internally by the VectorDisplay2D node. These functions handle validation, transformations, color calculations, and position computations.
Class Definition
Static Methods
check_targets_and_settings()
_ready() initialization.
Parameters:
self_node: The VectorDisplay2D node instancetarget_node: The node to validate (can be null for auto-assignment)target_property: Name of the Vector2 property to validatesettings: The settings resource to validate
- If
target_nodeis null, auto-assigns toself_node’s parent and warns - Pushes error if target node is invalid after assignment
- Pushes error if
target_propertyis not a Vector2 or doesn’t exist - Pushes error if
settingsis null
apply_lenght_mode()
vector: The vector to transform (Vector2 or Vector3)settings: Settings resource containing the length mode configuration
- Transformed vector based on length mode
nullif length mode is invalid
"Normal": Returns vector unchanged"Clamp": Returnsvector.limit_length(settings.max_length)"Normalize": Returnsvector.normalized() * settings.max_length
_process() to transform the display vector without modifying the original value.
Example:
calculate_draw_colors()
vector: The current display vector (Vector2 or Vector3)current_raw_length: The original vector length before transformationssettings: Settings resource with color configuration
- Rainbow Mode: If enabled, calculates
maincolor from vector angle using HSV (hue from 0 to 1 based on angle) - Dimming Mode: If enabled, lerps all colors toward
fallback_colorbased on vector length
_draw() before rendering to determine final colors for all vector components.
get_main_vector_position()
vector: The display vector (Vector2 or Vector3)settings: Settings resource containing pivot mode
"Normal": Begin at origin, end at vector position"Centered": Centered around origin
_draw() to determine where to render the main vector line.
get_axes_positions()
vector: The display vector (Vector2 or Vector3)settings: Settings resource containing pivot modes
-
Normal axes, Normal main or axes_pivot_mode = “Normal”:
-
Centered axes, Centered main or axes_pivot_mode = “Centered”:
-
Normal axes, Centered main (special case):
_draw() when show_axes is true to render component breakdown.
check_shortcut()
event: The input event to checksettings: Settings resource containing the shortcut configuration
trueif the shortcut was matched and handledfalseif the event doesn’t match the shortcut
- Checks if event is pressed (not released)
- Checks if event is not an echo (prevents key repeat)
- Checks if event matches
settings.SHORTCUT - If matched, toggles
settings.show_vectorsand returns true
_unhandled_key_input() to handle keyboard shortcuts for toggling visibility.
Example:
_is_vector_type() (Internal)
vector: Value to check
trueif vector is Vector2 or Vector3falseotherwise (also pushes error)
Usage Notes
- All functions are static and can be called without instantiating the class
- Functions are designed to work with both Vector2 and Vector3 (future 3D support)
- Error messages use the
[VectorDisplay]prefix for easy identification - These functions are primarily for internal use by VectorDisplay2D
- The functions handle edge cases like zero-length vectors and invalid inputs gracefully
