dro

package
v0.0.0-...-b822ddd Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	S_Line = iota
	S_Rectangle
	S_RectangleLines
	S_Ellipse
	S_EllipseLines
	ShapeNumber
)
View Source
const (
	M_Brush     = 1 << iota // Brush enabled
	M_Dialog                // Display a dialog
	M_Selection             // Select a region on canvas
	M_Handles               // Manipulate a region on canvas

	// Selection is (or is going to be, in case of M_Selection) stored separately from main canvas.
	// Used for things like clipboard and moving fragments of canvas. Not set e.g. when the region is used to draw a shape.
	M_ExternalSelection
	M_Shape
)

ModeMask

View Source
const (
	D_Shapes = iota
	D_Color
	D_Prompt
)

Dialog

Variables

View Source
var (
	C_Timeout = 0.1 // Don't draw when rl.GetTime() < State.TimeoutT + C_Timeout

	// Show alert for ... seconds
	C_AlertTime         = 4
	C_DefaultThickness  = 6
	C_DefaultCanvasSize = rl.NewVector2(1920, 1080)
	C_StatusBarHeight   = 20

	C_ChangeSnapshotT = 1 // How often to take state snapshots for history [s]
	C_MaxSnapshots    = 16

	C_Filter = true // If true, texture filtering with mipmaps will be used.

	C_HandleSize = 8 // Half of handle size (~radius)

	C_PromptMargin   = 30
	C_PromptMinWidth = 200
	C_PromptMaxWidth = 800
)
View Source
var (
	DragStart     rl.Vector2
	DragStartDisp rl.Vector2 // Displacement of mouse cursor in relation to handle center
	StartRec      dRectangle
	IsDragging    bool = false
	Handle        rl.Vector2
)
View Source
var MenuBarButtons = []MenuBarButton{
	{Name: "New", Function: NewFile},
	{Name: "Open", Function: OpenFile},
	{Name: "Save", Function: SaveFile},
	{Name: "Quit", Function: Quit},
	{Name: "Color", Function: OpenColorDialog},
	{Name: "Shape", Function: OpenShapeSelector},
}
View Source
var UiBtnFlag = ""

Functions

func AssignSelector

func AssignSelector(n int) rl.Rectangle

func DoHandle

func DoHandle(h rl.Vector2, recscr dRectangle, interactive bool) bool

func DoPromptText

func DoPromptText(S *State, position rl.Vector2)

func DrawStatusBar

func DrawStatusBar(S *State)

func HandleResize

func HandleResize(S *State, r *dRectangle, h rl.Vector2)

func LoadFont

func LoadFont()

func NewdRectangle

func NewdRectangle(start rl.Vector2, end rl.Vector2) dRectangle

func Vector2Divide

func Vector2Divide(v rl.Vector2, i float32) rl.Vector2

Types

type Brush

type Brush struct {
	ForegroundColor rl.Color
	BackgroundColor rl.Color
	Thickness       float32
}

func (*Brush) CanDraw

func (B *Brush) CanDraw(S *State) bool

Returns true if mouse moved enough distance to draw new stroke

func (*Brush) DoDrawing

func (B *Brush) DoDrawing(S *State) *State

func (*Brush) DoThickness

func (B *Brush) DoThickness()

type Canvas

type Canvas struct {
	Tex           *rl.RenderTexture2D
	Position      rl.Vector2
	Scale         float32
	DisplayedSize rl.Vector2
	Size          rl.Vector2
}

func (*Canvas) CanvasToScreen

func (C *Canvas) CanvasToScreen(v rl.Vector2) rl.Vector2

func (*Canvas) DoScale

func (C *Canvas) DoScale()

func (*Canvas) Draw

func (C *Canvas) Draw()

func (*Canvas) Load

func (C *Canvas) Load(t *rl.Texture2D)

func (*Canvas) Pan

func (C *Canvas) Pan(s *State)

func (*Canvas) ScreenToCanvas

func (C *Canvas) ScreenToCanvas(v rl.Vector2) rl.Vector2

type File

type File struct {
	Path      string
	Saved     bool
	IsUnnamed bool
}
type MenuBarButton struct {
	Name     string
	Function func(S *State) *State
}

type Picker

type Picker struct {
	H float32 // Hue [0..360]
	S float32 // Saturation [0..1]
	V float32 // Value [0..1]
	A float32 // Alpha [0..1]
}

func ColorToPicker

func ColorToPicker(C rl.Color) Picker

func (Picker) ToColor

func (p Picker) ToColor() rl.Color

func (*Picker) Update

func (p *Picker) Update(h float32, s float32, v float32, a float32)

Update skips fields less than zero

type Prompt

type Prompt struct {
	Action      string // short action identifier
	Prompt      string // prompt displayed to user
	Input       string
	InputCursor int // cursor position
	Accepted    bool
}

type State

type State struct {
	// Brush
	Brush Brush

	Mode     int
	LastMode int

	Dialog int

	// D_Prompt
	Prompt *Prompt

	BaseSize  rl.Vector2 // Used for aspect ratio calculations
	Selection dRectangle // Canvas space

	// M_ExternalSelection
	SelectionTex rl.RenderTexture2D

	// M_Shape
	Shape int

	// Canvas
	Canvas Canvas

	MouseOld rl.Vector2 // Don't draw when MouseOld==(Vector2){-1,-1}
	TimeoutT float32    // Don't draw when GetTime() < TimeoutT + C_Timeout

	Time      float32  // When was this state created
	OldCanvas rl.Image // Only for history
	Next      *State
	Previous  *State

	// File
	File *File

	AlertTime    float32
	AlertMessage string
}

func CloseColorDialog

func CloseColorDialog(S *State) *State

func CloseShapeSelector

func CloseShapeSelector(S *State, shape int) *State

If shape == -1 then no shape was selected

func CommitSelection

func CommitSelection(S *State) *State

func CommitShape

func CommitShape(S *State) *State

func DoColorDialog

func DoColorDialog(S *State) *State

func DoHandles

func DoHandles(S *State) *State

func DoSelectFragment

func DoSelectFragment(S *State) *State

func DoShapeSelector

func DoShapeSelector(S *State) *State

func DrawMenuBar

func DrawMenuBar(S *State) (ret *State)

func FragmentSelected

func FragmentSelected(S *State) *State
func MenuPlaceholder(S *State) *State

func NewFile

func NewFile(S *State) *State

func OpenColorDialog

func OpenColorDialog(S *State) *State

func OpenFile

func OpenFile(S *State) *State

func OpenShapeSelector

func OpenShapeSelector(S *State) *State

func Quit

func Quit(S *State) *State

func SaveFile

func SaveFile(S *State) *State

func (*State) Alert

func (S *State) Alert(a string)

func (*State) CanGetMouseMovement

func (S *State) CanGetMouseMovement() bool

func (*State) Change

func (S *State) Change(snapshot bool) *State

func (*State) Cleanup

func (S *State) Cleanup(all bool)

Remove unneded States from memory

func (*State) DebugMemory

func (S *State) DebugMemory()

func (*State) DebugSnapshots

func (S *State) DebugSnapshots() (int, int)

func (*State) DoPrompt

func (S *State) DoPrompt()

func (*State) Redo

func (S *State) Redo() *State

func (*State) Reset

func (S *State) Reset()

func (*State) ShowPrompt

func (S *State) ShowPrompt(action string, prompt string, input string)

func (*State) Undo

func (S *State) Undo() *State

func (*State) Unload

func (S *State) Unload()

Unload won't check if S.Previous or S.Next should be unloaded.

Jump to

Keyboard shortcuts

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