drawtool

package
v0.0.0-...-79996cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type History

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

History manages a history of Strokes added to a drawing.

func NewHistory

func NewHistory(limit int) *History

NewHistory initializes a History list.

func (*History) AddStroke

func (h *History) AddStroke(s *Stroke)

AddStroke adds a stroke to the history, becoming the new tail at the end of the history data.

func (*History) Latest

func (h *History) Latest() *Stroke

Latest returns the tail of the history (the most recent stroke). If you had recently called Undo, the latest stroke may still have a 'next' stroke. Returns nil if there was no stroke in history.

func (*History) Oldest

func (h *History) Oldest() *Stroke

Oldest returns the head of the history (the earliest stroke added). If the history size limit had been reached, the oldest stroke will creep along forward and not necessarily be the FIRST EVER stroke added.

func (*History) Redo

func (h *History) Redo() bool

Redo advances forwards after a recent Undo. Note that if you added new strokes after an Undo, the new tail has no next node to move to and Redo returns false.

func (*History) Reset

func (h *History) Reset()

Reset clears the history.

func (*History) Size

func (h *History) Size() int

Size returns the current size of the history list.

func (*History) Undo

func (h *History) Undo() bool

Undo steps back a step in the history. This sets the current tail to point to the "tail - 1" element, but doesn't change the link of that element to its future value yet; so that you can Redo it. But if you add a new stroke from this state, it will overwrite the tail.next and invalidate the old history that came after, starting a new branch of history from that point on.

Returns false if the undo failed (no earlier node to move to).

type HistoryElement

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

HistoryElement is a doubly linked list of stroke history.

type Shape

type Shape int

Shape of a stroke line.

const (
	Freehand Shape = iota
	Line
	Rectangle
	Ellipse
	Eraser // not really a shape but communicates the intention
)

Shape values.

type Stroke

type Stroke struct {
	ID        int // Unique ID per each stroke
	Shape     Shape
	Color     render.Color
	Pattern   string
	Thickness int         // 0 = 1px; thickness creates a box N pixels away from each point
	ExtraData interface{} // arbitrary storage for extra data to attach

	// Start and end points for Lines, Rectangles, etc.
	PointA render.Point
	PointB render.Point

	// Array of points for Freehand shapes.
	Points []render.Point

	// Storage space to recall the previous values of points that were replaced,
	// especially for the Undo/Redo History tool. When the uix.Canvas commits a
	// Stroke to the level data, any pixel that has replaced an existing color
	// will cache its color here, so we can easily page forwards and backwards
	// in history and not lose data.
	//
	// The data is implementation defined and controlled by the caller. This
	// package does not modify OriginalPoints or do anything with it.
	OriginalPoints map[render.Point]interface{}
	// contains filtered or unexported fields
}

Stroke holds temporary pixel data with a shape and color.

It is used for myriad purposes:

  • As a staging area for drawing new pixels to the drawing without committing them until completed.
  • As a unit of work for the Undo/Redo History when editing a drawing.
  • As imaginary visual lines superimposed on top of a drawing, for example to visualize the link between two doodads or to draw collision hitboxes and other debug lines to the drawing.

func NewStroke

func NewStroke(shape Shape, color render.Color) *Stroke

NewStroke initializes a new Stroke with a shape and a color.

func (*Stroke) AddPoint

func (s *Stroke) AddPoint(p render.Point)

AddPoint adds a point to the stroke, for freehand shapes.

func (*Stroke) Copy

func (s *Stroke) Copy() *Stroke

Copy returns a duplicate of the Stroke reference.

func (*Stroke) IterPoints

func (s *Stroke) IterPoints() chan render.Point

IterPoints returns an iterator of points represented by the stroke.

For a Line, returns all of the points between PointA and PointB. For freehand, returns every point added to the stroke.

func (*Stroke) IterThickPoints

func (s *Stroke) IterThickPoints() chan render.Rect

IterThickPoints iterates over the points and yield Rects of each one.

type TextSettings

type TextSettings struct {
	Font    string // like 'DejaVuSans.ttf'
	Size    int
	Message string
	Label   *ui.Label // cached label texture
}

TextSettings holds currently selected Text Tool settings.

var TT TextSettings

Currently active settings (global variable)

func (TextSettings) IsZero

func (tt TextSettings) IsZero() bool

IsZero checks if the TextSettings are populated.

func (TextSettings) ToStroke

func (tt TextSettings) ToStroke(e render.Engine, color render.Color, at render.Point) (*Stroke, error)

ToStroke converts a TextSettings configuration into a Freehand Stroke, coloring in all of the pixels.

type Tool

type Tool int

Tool is a draw mode for an editable Canvas.

const (
	PencilTool Tool = iota // draw pixels where the mouse clicks
	LineTool
	RectTool
	EllipseTool
	ActorTool // drag and move actors
	LinkTool
	EraserTool
	PanTool
	TextTool
	FloodTool
)

Draw modes for editable Canvas.

func (Tool) String

func (t Tool) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL