Enhanced Features API New

Complete API reference for AdvanceGG's latest enhanced features including layer compositing, DOM-style object model, hit testing, and animation support.

Layer Compositing System

Professional multi-layer compositing with 13 blend modes for advanced graphics composition.

LayerManager

EnableLayers()
void

Enables the layer system for the current context.

GetLayerManager()
*LayerManager

Returns the layer manager for the current context.

AddLayer(name string)
*Layer

Creates and adds a new layer with the specified name.

Blend Modes

Available blend modes for layer compositing:

  • BlendModeNormal
  • BlendModeMultiply
  • BlendModeScreen
  • BlendModeOverlay
  • BlendModeSoftLight
  • BlendModeHardLight
  • BlendModeColorDodge
  • BlendModeColorBurn
  • BlendModeDarken
  • BlendModeLighten
  • BlendModeDifference
  • BlendModeExclusion
// Enable layers and create layer manager
dc.EnableLayers()
lm := dc.GetLayerManager()

// Create layers with different blend modes
bgLayer := lm.GetActiveLayer()
bgLayer.Name = "Background"

overlayLayer := lm.AddLayer("Overlay")
overlayLayer.SetBlendMode(advancegg.BlendModeMultiply)
overlayLayer.SetOpacity(0.8)

// Draw on specific layers
lm.SetActiveLayer(1)
dc.SetRGB(1, 0, 0)
dc.DrawCircle(100, 100, 50)
dc.Fill()

// Composite all layers
result := lm.Composite()

DOM-Style Object Model

Modern web-like API with tree structure for shapes, IDs, CSS-like classes, and style inheritance.

Document

NewDocument()
*Document

Creates a new document for managing graphics elements.

AddElement(element *Element)
void

Adds an element to the document.

GetElementByID(id string)
*Element

Retrieves an element by its ID.

Element

AddClass(class string)
void

Adds a CSS-like class to the element.

SetStyle(property string, value interface{})
void

Sets a style property on the element.

Shape Creation Functions

CreateRect(id string, x, y, width, height float64)
*Element
CreateCircle(id string, x, y, radius float64)
*Element
// Create document and elements
doc := advancegg.NewDocument()

// Create shapes with IDs and classes
circle := advancegg.CreateCircle("circle1", 100, 100, 40)
circle.AddClass("shape")
circle.AddClass("primary")
circle.SetStyle("fill", color.RGBA{255, 100, 100, 255})

// Add CSS-like styles
doc.AddStyle(".primary", advancegg.Style{
    Fill: color.RGBA{255, 100, 100, 255},
    Stroke: color.RGBA{200, 50, 50, 255},
})

doc.AddElement(circle)
doc.Render(ctx)

Hit Testing System

Point-in-path detection for interactive graphics with spatial indexing for optimal performance.

HitTestManager

NewHitTestManager()
*HitTestManager

Creates a new hit test manager.

AddObject(obj HitTestable)
void

Adds an object for hit testing.

HitTest(x, y float64)
[]HitTestable

Returns all objects that contain the specified point.

HitTestable Shapes

CreateHitTestRect(id string, x, y, width, height float64)
*HitTestRect
CreateHitTestCircle(id string, x, y, radius float64)
*HitTestCircle
// Create hit test manager
htm := advancegg.NewHitTestManager()

// Add hit testable shapes
rect := advancegg.CreateHitTestRect("rect1", 50, 50, 100, 80)
circle := advancegg.CreateHitTestCircle("circle1", 200, 100, 40)

htm.AddObject(rect)
htm.AddObject(circle)

// Test for hits at mouse position
hits := htm.HitTest(mouseX, mouseY)
if len(hits) > 0 {
    fmt.Printf("Hit: %s\n", hits[0].GetID())
}

Animation Framework

Frame-based animation system with easing functions and GIF export capabilities.

Animator

NewAnimator(width, height int, fps float64, duration time.Duration)
*Animator

Creates a new animator with specified dimensions, frame rate, and duration.

AddFrame(frame *image.RGBA)
void

Adds a frame to the animation.

SaveGIF(filename string)
error

Exports the animation as a GIF file.

Easing Functions

  • EaseLinear
  • EaseIn
  • EaseOut
  • EaseInOut
  • EaseInCubic
  • EaseOutCubic
  • EaseInOutCubic
  • EaseBounce
  • EaseElastic
// Create animator
animator := advancegg.NewAnimator(400, 300, 30.0, 3*time.Second)

// Generate frames with easing
frameCount := int(30.0 * 3.0) // 30 fps * 3 seconds
for i := 0; i < frameCount; i++ {
    t := float64(i) / float64(frameCount-1)
    
    // Animate with bounce easing
    x := advancegg.AnimateProperty(50, 350, t, advancegg.EaseLinear)
    y := 150 + 80*advancegg.EaseBounce(t)
    
    // Create frame
    ctx := advancegg.NewContext(400, 300)
    ctx.SetRGB(1, 0.3, 0.3)
    ctx.DrawCircle(x, y, 15)
    ctx.Fill()
    
    animator.AddFrame(ctx.Image().(*image.RGBA))
}

// Export as GIF
err := animator.SaveGIF("bouncing-ball.gif")