Files
spore-ledlab/docs/EDITOR_UPDATE.md
2025-10-27 09:37:20 +01:00

7.2 KiB
Raw Permalink Blame History

Editor UI Improvements - Update Summary

Overview

The Preset Editor has been significantly enhanced with live canvas preview, node selection, and real-time rendering capabilities.

New Features

1. Live Canvas Preview

A real-time canvas preview has been added directly to the Editor view:

  • Location: Center panel, above the layer list
  • Display: Shows live animation rendering at the configured FPS
  • Updates: Automatically refreshes when layers are added, modified, or removed
  • FPS Counter: Displays actual rendering frame rate
  • Size Display: Shows current matrix dimensions (e.g., "16×16")

Implementation:

  • canvas-renderer.js - Client-side renderer that executes building blocks
  • Simplified versions of shapes, colors, and animations for browser rendering
  • Efficient pixel-by-pixel drawing with proper serpentine wiring support

2. Node Selector Dropdown

A dropdown has been added to the editor header for target selection:

  • Options:
    • "Canvas Preview Only" (default) - Only renders to canvas
    • List of discovered nodes with IP addresses
  • Auto-Discovery: Automatically populates with available nodes
  • Dynamic Updates: Updates when nodes are discovered or lost
  • Persistent Selection: Maintains selection when nodes list refreshes

3. Dual-Mode Preview

The preview system now supports two modes:

Canvas-Only Mode (No node selected):

  • Renders animation to canvas preview only
  • No network traffic
  • Perfect for designing and testing
  • Uses client-side rendering engine

Canvas + Node Mode (Node selected):

  • Renders to both canvas AND transmits to selected node
  • Canvas preview for visual feedback
  • Node receives frames via server streaming
  • Synchronized rendering

4. Preview Controls

Enhanced preview control panel:

  • Start/Stop Button: Toggles preview on/off
    • "▶️ Start Preview" when stopped
    • "⏸️ Stop Preview" when running
  • Status Indicator: Shows current mode
    • "Stopped" (gray) - Preview is off
    • "Canvas Preview" (green) - Rendering to canvas only
    • "Streaming to [IP]" (blue) - Rendering to canvas + node

5. Auto-Refresh on Changes

The preview automatically restarts when configuration changes:

  • Adding a new layer
  • Deleting a layer
  • Loading a preset
  • Importing JSON
  • Animation states are reset for clean restart

Technical Details

Canvas Renderer (canvas-renderer.js)

A browser-based implementation of the building blocks system:

Features:

  • Renders shapes: circle, rectangle, blob, point
  • Color generators: solid, gradient, rainbow
  • Animations: move, rotate, pulse, oscillate, fade
  • Pattern support: radial, spiral
  • Proper RGB color blending
  • FPS tracking and display

Architecture:

class CanvasRenderer {
  - setSize(width, height)         // Update matrix dimensions
  - renderConfiguration(config)    // Render preset configuration
  - drawFrame(frame)               // Draw frame to canvas
  - clear()                        // Clear canvas
  - reset()                        // Reset animation states
}

Preview System Flow

User clicks "Start Preview"
         ↓
1. Initialize canvas renderer
2. Reset animation states
3. Start render loop (20 FPS default)
         ↓
   Every frame:
   - Execute building blocks
   - Render to canvas
   - Update FPS counter
         ↓
   If node selected:
   - Also send config to server
   - Server streams to node

Node Discovery Integration

The editor subscribes to the main app's event bus:

eventBus.subscribe('nodeDiscovered', () => updateDropdown())
eventBus.subscribe('nodeLost', () => updateDropdown())

This ensures the node list stays synchronized with the Stream view.

UI Layout Changes

Before

[Editor Header]
[Sidebar] [Layers] [Details]

After

[Editor Header with Preview Controls]
[Sidebar] [Canvas Preview + Layers] [Details]

The center panel now features the canvas preview prominently at the top, with the layer list below it.

Usage Examples

Example 1: Design Without Hardware

  1. Create preset in editor
  2. Leave node selector at "Canvas Preview Only"
  3. Click "Start Preview"
  4. Watch animation in canvas
  5. Modify layers and see changes instantly
  6. No SPORE node required!

Example 2: Test on Real Hardware

  1. Create preset in editor
  2. Select target node from dropdown
  3. Click "Start Preview"
  4. Animation appears on both canvas and physical LED matrix
  5. Modify and see changes on both displays

Example 3: Quick Iteration

  1. Import an example preset
  2. Start canvas preview
  3. Modify parameters in layer details
  4. Changes automatically refresh
  5. When satisfied, select node and stream

Performance

  • Canvas Rendering: ~60 FPS capable, default 20 FPS
  • Network Efficiency: Only streams when node is selected
  • CPU Usage: Minimal, uses requestAnimationFrame equivalent (setInterval)
  • Memory: Efficient frame buffer management

Browser Compatibility

  • Modern browsers with Canvas API support
  • Chrome, Firefox, Safari, Edge (latest versions)
  • Mobile browsers supported (responsive design)

Styling Updates

New CSS classes added:

  • .editor-preview-controls - Preview control panel
  • .preview-control-group - Control group container
  • .node-select - Node selector dropdown
  • .preview-status - Status indicator
    • .active - Canvas preview (green)
    • .streaming - Node streaming (blue)
  • .editor-preview-container - Canvas container
  • .editor-canvas - Canvas element
  • .editor-canvas-info - Size and FPS display

Files Modified

  1. public/index.html

    • Added preview controls header
    • Added canvas preview section
    • Removed old preview button
    • Added canvas-renderer.js script
  2. public/styles/main.css

    • Added preview control styles (~80 lines)
    • Added canvas preview styles
    • Enhanced responsive design
    • Added status indicator styles
  3. public/scripts/preset-editor.js

    • Added canvas renderer integration
    • Added node discovery and dropdown
    • Added dual-mode preview system
    • Added auto-refresh on changes
    • Enhanced preview controls
  4. public/scripts/canvas-renderer.js (NEW)

    • Complete client-side renderer
    • Building blocks implementation
    • Animation engine
    • Canvas drawing logic

Benefits

Instant Feedback: See animations immediately without node Faster Iteration: No need to upload to hardware for testing Better UX: Visual confirmation of changes Flexible Testing: Canvas-only or canvas+node modes Resource Efficient: No network traffic in canvas-only mode Educational: Watch animations render in real-time Debugging: FPS counter helps identify performance issues

Future Enhancements

Possible future additions:

  • Adjustable preview FPS slider
  • Canvas zoom controls
  • Grid overlay option
  • Pixel coordinates on hover
  • Recording/GIF export
  • Side-by-side canvas comparison
  • Preview size presets (8×8, 16×16, 32×32)

Conclusion

The enhanced Editor UI provides a professional, feature-rich environment for creating and testing LED animations. The live canvas preview and flexible node targeting make the design process intuitive and efficient, whether working with physical hardware or designing purely in software.