visual: github.com/NaniteFactory/visual Index | Files | Directories

package visual

import "github.com/NaniteFactory/visual"

Package visual provides a simple visualizer system that's based on faiface/pixel.

Index

Package Files

atlas.go visualizer.go

func AtlasASCII18 Uses

func AtlasASCII18() *text.Atlas

AtlasASCII18 returns an atlas of font size 18 that's to draw only ASCII characters.

func AtlasASCII36 Uses

func AtlasASCII36() *text.Atlas

AtlasASCII36 returns an atlas of font size 36 that's to draw only ASCII characters.

type Actor Uses

type Actor interface {
    Drawer
    Updater
}

Actor is what a Visualizer visualizes. Actor updates and draws itself. It acts as a game (virtual) object.

The mainthread, called Visualizer, will do what's shown below, every single frame.

func (v *Visualizer) _NextFrame(dt float64) {
	// ---------------------------------------------------
	// 1. update - calc state of game (virtual) objects each frame
	v._Update(dt)
	v.fpsw.Poll()

	// ---------------------------------------------------
	// 2. draw on window
	v.window.Clear(v.bg) // clear canvas
	v._Draw()            // then draw

	// ---------------------------------------------------
	// 3. update window - always end with it
	v.window.Update()
	<-v.vsync
}

type Config Uses

type Config struct {
    Bg                  pixel.RGBA
    OnDrawn             func(t pixel.Target)
    OnUpdated           func(dt float64)
    OnResized           func(width float64, height float64)
    OnPaused            func()
    OnResumed           func()
    OnClose             func()
    OnHandlingEvents    func(dt float64, window *pixelgl.Window)
    OnLogging           func(args ...interface{})
    WinCentered         bool
    Undecorated         bool
    Title               string
    Version             string
    Width               float64
    Height              float64
    WinWidth            float64
    WinHeight           float64
    InitialZoomLevel    float64
    InitialRotateDegree float64
}

Config is just an argument of NewVisualizer() that defines a new visualizer.

func (Config) PosCenterGame Uses

func (c Config) PosCenterGame() pixel.Vec

PosCenterGame returns the world center in game position.

type Drawer Uses

type Drawer interface {
    // Draw obligatorily invoked by Visualizer on mainthread.
    Draw(t pixel.Target)
}

Drawer draws itself on a target canvas.

The mainthread will do what's shown below every single frame.

// Canvas a game (virtual) world
t.SetMatrix(v.camera.Transform())

// For all actors, Draw() in an order.
for i := range v.actors {
	v.actors[i].Draw(t)
}

type HUD Uses

type HUD interface {
    Actor
    PosOnScreen(width, height float64) // Callback on screen resize from mainthread.
}

HUD is an Actor positioned in screen-coord.

type Updater Uses

type Updater interface {
    // Update obligatorily invoked by Visualizer on mainthread.
    Update(dt float64)
}

Updater updates itself with the delta time given, every frame on mainthread.

The mainthread will do what's shown below every single frame.

// For all actors, Update() in an order.
for i := range v.actors {
	v.actors[i].Update(dt)
}

type Visualizer Uses

type Visualizer struct {
    // contains filtered or unexported fields
}

Visualizer is a mainthread that visualizes stuff.

Visualizer manages:

1. A window
2. Actors; General Actors or HUDs
3. A game-like visualizer system along with vsync/fps/dt/camera

Inputs handled by Visualizer by default: Esc, Tab, Enter, Space, Arrows, Left click, Wheeling, Ctrl+M and Ctrl+Click

func NewVisualizer Uses

func NewVisualizer(cfg Config, optionalHUDs []HUD, generalActors ...Actor) *Visualizer

NewVisualizer is a constructor.

func (*Visualizer) Close Uses

func (v *Visualizer) Close()

Close this visualizer. This function breaks the run loop of this.

func (*Visualizer) Pause Uses

func (v *Visualizer) Pause()

Pause everything going on.

func (*Visualizer) PopActor Uses

func (v *Visualizer) PopActor() Actor

PopActor of this visualizer.

func (*Visualizer) PopHUD Uses

func (v *Visualizer) PopHUD() HUD

PopHUD of this visualizer. (HUD: Screen-positioned Actor.)

func (*Visualizer) PushActors Uses

func (v *Visualizer) PushActors(actors ...Actor)

PushActors to this visualizer.

func (*Visualizer) PushHUDs Uses

func (v *Visualizer) PushHUDs(actorHUDs ...HUD)

PushHUDs to this visualizer. (HUD: Screen-positioned Actor.)

func (*Visualizer) RemoveActor Uses

func (v *Visualizer) RemoveActor(thisGuyGetsRemoved Actor) (removedIndeed bool)

RemoveActor of this visualizer. Time complexity is O(N); N is the number of actors available in this visualizer.

func (*Visualizer) RemoveHUD Uses

func (v *Visualizer) RemoveHUD(thisGuyGetsRemoved HUD) (removedIndeed bool)

RemoveHUD of this visualizer. (HUD: Screen-positioned Actor.) Time complexity is O(N); N is the number of HUDs available in this visualizer.

func (*Visualizer) Resume Uses

func (v *Visualizer) Resume()

Resume after pause.

func (*Visualizer) Run Uses

func (v *Visualizer) Run()

Run the game window and its event loop on mainthread. This function must be called from the main function of an application so that it can work on the context of OpenGL.

func (*Visualizer) SetTitle Uses

func (v *Visualizer) SetTitle(title, version string)

SetTitle updates the title and the version be displayed in the title bar.

func (*Visualizer) Title Uses

func (v *Visualizer) Title() (fullname, title, version string)

Title gets the title and the version be displayed in the title bar.

Directories

PathSynopsis
actors
atlas
jukebox
super

Package visual imports 20 packages (graph). Updated 2019-06-04. Refresh now. Tools for package owners.