This document covers the graphics and UI capabilities provided by OwnLang's visual modules, primarily the canvasfx
module which integrates JavaFX for 2D graphics rendering, canvas operations, and visual effects. This module enables creation of graphical applications with drawing capabilities, event handling, and sophisticated visual effects.
For network-based UI applications, see Server Module. For basic I/O and system interaction, see Standard Library Modules.
The graphics and UI system in OwnLang is built around JavaFX integration through the canvasfx
module, which provides a comprehensive graphics API accessible from OwnLang scripts.
Sources: modules/canvasfx/build.gradle1-24 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java1-48 settings.gradle9-14
The canvasfx
module is configured as a separate Gradle subproject with specific JavaFX dependencies and shadow JAR packaging for distribution.
Configuration | Value | Purpose |
---|---|---|
Module ID | canvasfx | Module identifier in OwnLang |
Version | 1.1.0 | Current module version |
JavaFX Version | 21 | Required JavaFX runtime |
JavaFX Modules | javafx.controls , javafx.swing | Core and Swing bridge components |
Build Plugin | org.openjfx.javafxplugin | JavaFX Gradle plugin |
Distribution | Shadow JAR | Self-contained executable JAR |
The module follows the standard OwnLang module interface pattern, implementing both constants()
and functions()
methods to expose functionality to OwnLang scripts.
Sources: modules/canvasfx/build.gradle1-24 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java88-195
The canvasfx
module provides several key components that work together to enable graphics programming in OwnLang.
Sources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java48-195 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java632-705
The GraphicsFXValue
class provides a comprehensive wrapper around JavaFX's GraphicsContext
, exposing over 60 drawing and rendering methods to OwnLang scripts.
Category | Methods | Description |
---|---|---|
Path Operations | beginPath , closePath , moveTo , lineTo | Path construction and management |
Shape Drawing | fillRect , strokeRect , fillOval , strokeOval | Basic shape rendering |
Complex Shapes | fillPolygon , strokePolygon , fillArc , strokeArc | Advanced geometric shapes |
Text Rendering | fillText , strokeText , setTextAlign , setTextBaseline | Text drawing with alignment |
Image Operations | drawImage , createImage , getPixels | Image rendering and manipulation |
Transformations | translate , rotate , scale , transform | Coordinate system transformations |
Operation | Methods | Purpose |
---|---|---|
Graphics State | save , restore | State stack management |
Fill/Stroke | setFill , setStroke , getFill , getStroke | Color and pattern settings |
Line Properties | setLineWidth , setLineCap , setLineJoin | Stroke appearance |
Blending | setGlobalBlendMode , setGlobalAlpha | Compositing controls |
Effects | setEffect , applyEffect | Visual effect application |
Sources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java632-950
The module provides a comprehensive color system with multiple color space support and predefined color constants.
The color system supports:
#FF0000
, red
, etc.)Sources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java92-105 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java246-298
The module provides access to JavaFX's comprehensive effects engine through wrapper functions that create EffectValue
objects.
Effect Type | Constructor Function | Parameters |
---|---|---|
Blur Effects | BloomEffect , BoxBlurEffect , GaussianBlurEffect , MotionBlurEffect | Threshold, radius, iterations, angle |
Shadow Effects | DropShadowEffect , InnerShadowEffect , ShadowEffect | Blur type, color, radius, offsets |
Color Effects | ColorAdjustEffect , ColorInputEffect , SepiaToneEffect | Hue, saturation, brightness, contrast |
Composite Effects | BlendEffect , ReflectionEffect | Blend mode, opacity, reflection parameters |
Lighting Effects | LightingEffect , GlowEffect | Light sources, surface properties, glow level |
Transform Effects | PerspectiveTransformEffect | Corner point coordinates |
Sources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java175-190 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java346-558
The module provides comprehensive event handling for user interaction through the JavaFX event system.
Event Category | Event Types | Handler Registration |
---|---|---|
Mouse Events | MOUSE_CLICKED , MOUSE_PRESSED , MOUSE_RELEASED , MOUSE_MOVED , MOUSE_DRAGGED | addEventHandler , addEventFilter |
Keyboard Events | KEY_PRESSED , KEY_RELEASED , KEY_TYPED | Event type constants with KeyCode mapping |
Touch Events | SWIPE_UP , SWIPE_DOWN , SWIPE_LEFT , SWIPE_RIGHT | Gesture recognition support |
Drag Events | DRAG_DETECTED , MOUSE_ENTERED_TARGET , MOUSE_EXITED_TARGET | Drag and drop operations |
The module exposes several enumeration constants for event handling:
Events
enum with ordinal valuesPRIMARY
, SECONDARY
, MIDDLE
button constantsSources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java56-86 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java149-166 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java191-194
The ImageFXValue
class provides image creation, loading, and pixel-level manipulation capabilities.
Method | Signature | Purpose |
---|---|---|
Load from URL | createImage(url) | Load image from file or web URL |
Create Blank | createImage(width, height) | Create empty WritableImage |
From Pixel Data | createImage(width, height, pixels) | Create image from ARGB pixel array |
width
, height
, preserveRatio
, smooth
(read-only)getPixels()
method returns ARGB integer arrayWritablePixelFormat.getIntArgbInstance()
for consistent ARGB handlingGraphicsContext.drawImage()
for renderingSources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java601-630 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java561-599
The module integrates with Java Swing through JFXPanel
to provide windowing capabilities that bridge Swing and JavaFX.
Function | Purpose | Implementation |
---|---|---|
window(width, height, title) | Create main application window | Uses JFrame with embedded JFXPanel |
repaint() | Force canvas redraw | Triggers JavaFX Platform update |
The module handles JavaFX threading requirements through Platform.runLater()
calls, ensuring proper thread safety when integrating with Swing applications and the OwnLang runtime.
Sources: modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java53-55 modules/canvasfx/src/main/java/com/annimon/ownlang/modules/canvasfx/canvasfx.java172-173
Refresh this wiki