Documentation
¶
Overview ¶
animations - Animations timers
Index ¶
- Constants
- func CheckCollisionRecLine(rec rl.Rectangle, p1, p2 rl.Vector2) bool
- func Close()
- func CopyIdxs[T any](dst, src []T, idxs []int) []T
- func GetKeyName(key int32) string
- func Init(assets embed.FS, opts *AppOptions) error
- func LoadAssets(assets embed.FS) error
- func LoadFonts(assets embed.FS) error
- func LoadIcon(assets embed.FS) (*rl.Image, error)
- func NormalizePath(p string) string
- func ParseFloat32(s string) (float32, error)
- func Range(i, j int) []int
- func RemoveQuotes(s string) string
- func Repeat[T any](dst []T, v T, n int) []T
- func ShouldExit() bool
- func SortedIntsIndex(a []int, x int) int
- func Step()
- func SwapDelete[T any](s []T, i int) []T
- func SwapDeleteMany[T any](s []T, idxs []int) []T
- func SwapInsert[T any](s []T, i int, v T) []T
- func SwapInsertMany[T any](s []T, idxs []int, vs []T) []T
- type Action
- type ActionHandler
- type ActionTarget
- type Animations
- type App
- type AppActionNew
- type AppActionOpen
- type AppActionSave
- type AppActionSaveAs
- type AppActionSwitchMode
- type AppMode
- type AppOptions
- type Building
- type BuildingDef
- type BuildingDefs
- type Camera
- type CameraActionPan
- type CameraActionReset
- type CameraActionZoom
- type DecodeTextError
- type Dims
- type DrawCounts
- type DrawState
- type GetActionFunc
- type Grid
- type Gui
- type KeyBinding
- type Keyboard
- type MaskIterator
- type Mouse
- type NewBuilding
- type NewBuildingActionInit
- type NewBuildingActionMoveTo
- type NewBuildingActionPlace
- type NewBuildingActionRotate
- type NewPath
- type NewPathActionInit
- type NewPathActionMoveTo
- type NewPathActionPlace
- type NewPathActionPlaceStart
- type NewPathActionReverse
- type NewTextBox
- type NewTextBoxActionInit
- type NewTextBoxActionMoveTo
- type NewTextBoxActionPlace
- type NewTextBoxActionPlaceStart
- type NewTextBoxActionReverse
- type Object
- type ObjectCollection
- type ObjectSelection
- func (os ObjectSelection) AnyPathIdxs() []int
- func (os ObjectSelection) BuildingsIterator() MaskIterator
- func (os ObjectSelection) Contains(obj Object) bool
- func (os ObjectSelection) EndIdxs() []int
- func (os ObjectSelection) FullPathIdxs() []int
- func (os ObjectSelection) IsEmpty() bool
- func (os ObjectSelection) PathsIterator() PathSelMaskIterator
- func (os ObjectSelection) StartIdxs() []int
- func (os ObjectSelection) TextBoxesIterator() MaskIterator
- type ObjectType
- type Path
- func (p Path) CheckCollisionPoint(pos rl.Vector2) bool
- func (p Path) CheckEndCollisionPoint(pos rl.Vector2) bool
- func (p Path) CheckStartCollisionPoint(pos rl.Vector2) bool
- func (p Path) Def() PathDef
- func (p Path) Draw(state DrawState)
- func (p Path) DrawBody(state DrawState)
- func (p Path) DrawEnd(state DrawState)
- func (p Path) DrawStart(state DrawState)
- func (p Path) IsValid() bool
- func (p Path) String() string
- type PathDef
- type PathDefs
- type PathSel
- type PathSelMaskIterator
- type Resets
- func (r Resets) String() string
- func (r Resets) WithCamera(v bool) Resets
- func (r Resets) WithGui(v bool) Resets
- func (r Resets) WithNewBuilding(v bool) Resets
- func (r Resets) WithNewPath(v bool) Resets
- func (r Resets) WithNewTextBox(v bool) Resets
- func (r Resets) WithSelection(v bool) Resets
- func (r Resets) WithSelector(v bool) Resets
- type Scene
- func (s *Scene) AddBuilding(building Building)
- func (s *Scene) AddObjects(col ObjectCollection)
- func (s *Scene) AddPath(path Path)
- func (s *Scene) AddTextBox(tb TextBox)
- func (s *Scene) DeleteObjects(sel ObjectSelection)
- func (s Scene) Draw()
- func (s Scene) GetObjectAt(pos rl.Vector2) Object
- func (s *Scene) HasRedo() bool
- func (s *Scene) HasUndo() bool
- func (s Scene) IsBuildingValid(building Building, ignore int) bool
- func (s *Scene) IsModified() bool
- func (s Scene) IsPathValid(path Path) bool
- func (s *Scene) LoadFromText(r io.Reader) error
- func (s *Scene) ModifyObjects(sel ObjectSelection, new ObjectCollection)
- func (s *Scene) Redo() (bool, Action)
- func (s *Scene) ResetModified()
- func (s *Scene) SaveToText(w io.Writer) error
- func (s *Scene) Undo() (bool, Action)
- func (s *Scene) Update() (action Action)
- type Selection
- type SelectionActionBeginTransformation
- type SelectionActionDelete
- type SelectionActionEndTransformation
- type SelectionActionInitSelection
- type SelectionActionInitSingleDrag
- type SelectionActionMoveBy
- type SelectionActionMoveTo
- type SelectionActionRotate
- type SelectionMode
- type Selector
- type SelectorActionInit
- type SelectorActionMoveTo
- type SelectorActionSelect
- type TextBox
Constants ¶
const ( // Top bar height in px TopbarHeight = 50.0 // Side bar width in px SidebarWidth = 300.0 // Details bar width in px DetailsBarWidth = 300.0 // Status bar height in px StatusBarHeight = 30.0 )
const ( Any optBool = iota No // false Yes // true )
const ( SceneOpAdd sceneOpType = "add" SceneOpDelete sceneOpType = "delete" SceneOpModify sceneOpType = "modify" )
const (
DefaultTargetFPS = 30
)
const MAX_INOUT = 4
Variables ¶
This section is empty.
Functions ¶
func CopyIdxs ¶
CopyIdxs clears dst and copies the elements at idxs from src into dst
It reallocates of cap(dst) < len(idxs)
func GetKeyName ¶
func Init ¶
func Init(assets embed.FS, opts *AppOptions) error
Init initializes the application.
It loads assets, initializes the window, and sets up the default state.
It must only be called once at startup.
func LoadAssets ¶
func NormalizePath ¶
NormalizePath normalizes a path to use the OS path separator.
It preserves the trailing separator if any.
func RemoveQuotes ¶
Replaces single and double quotes with asterisks.
func Repeat ¶
Repeat clears dst and fills it with n copies of the given value
It reallocates of cap(dst) < n
func SortedIntsIndex ¶
SortedIntsIndex returns the index of x in a ascending sorted int slice (-1 if not found)
Binary search is used.
func SwapDelete ¶
SwapDelete efficiently deletes the element at index i by swapping it with the last element and then truncating the slice.
Calling SwapDelete with i == len(s) - 1 simply removes the last element.
The complexity is O(1) but the slice order is not preserved.
func SwapDeleteMany ¶
SwapDeleteMany efficiently deletes the elements at given indices idxs by swapping them with the last elements and then truncating the slice.
idxs must be sorted in ascending order.
The complexity is O(len(indices)) but the slice order is not preserved.
func SwapInsert ¶
SwapInsert efficiently inserts the given element at index i by pushing the current i-th element to the back.
Calling SwapInsert with i == len(s) simply appends the element.
This is the reverse of SwapDelete.
The complexity is O(1) but the slice order is not preserved.
func SwapInsertMany ¶
SwapInsertMany efficiently inserts the given elements at given indices idxs by pushing the current$ elements at idxs to the back.
Idxs values must all be between 0 and len(s)+len(idxs)-1.
This is the reverse of SwapDeleteMany.
The complexity is O(len(indices)) but the slice order is not preserved.
Types ¶
type Action ¶
type Action interface { // Returns which app mode the action is for Target() ActionTarget }
Action is an abstraction layer between inputs and state updates in [Update] step.
It allows to decouple inputs and state updates, cleanly defining atomic state updates and each function / method perimeter.
See: - ActionHandler - GetActionFunc - [getAction] - [DispatchAction]
type ActionHandler ¶
ActionHandler are responsible for performing and an Action, and may return a follow up Action.
Each AppMode has a corresponding struct implementing a Do ActionHandler method.
In most cases, the ActionHandler only calls appropriate handler for the specific action they recieve. Those handler,in turn, often do not return an Action directly, but rather calls other handler directly and returns their result.
This prevents runtime reflection (switch action.(type) statements) at the expense of a deeper call stack.
type ActionTarget ¶
type ActionTarget int
ActionTarget - action target
const ( // TargetApp - app level actions TargetApp ActionTarget = iota // TargetGui - gui level actions TargetGui // TargetCamera - camera level actions TargetCamera // TargetSelector - selector level actions TargetSelector // TargetNewPath - new path level actions TargetNewPath // TargetNewBuilding - new building level actions TargetNewBuilding // TargetNewTextBox - new text box level actions TargetNewTextBox // TargetSelection - selection level actions TargetSelection )
type Animations ¶
type Animations struct { // Elapsed time since window initialization (seconds) Timer float32 // Brightness factor for DrawSelected SelectedLerp float32 // Belt arrows offset BeltOffset float32 }
func (*Animations) Update ¶
func (a *Animations) Update()
Update animations state
Do not depends on any other state
type App ¶
type App struct { // Application view mode Mode AppMode // contains filtered or unexported fields }
App contains application global state
type AppActionOpen ¶
type AppActionOpen struct{}
AppActionOpen - open and load a project from a file
func (AppActionOpen) Target ¶
func (a AppActionOpen) Target() ActionTarget
type AppActionSave ¶
type AppActionSave struct{ Filepath string }
AppActionSave - save the current project to a file
func (AppActionSave) Target ¶
func (a AppActionSave) Target() ActionTarget
type AppActionSaveAs ¶
type AppActionSaveAs struct{}
AppActionSaveAs - save the current project to a new file
func (AppActionSaveAs) Target ¶
func (a AppActionSaveAs) Target() ActionTarget
type AppActionSwitchMode ¶
AppActionSwitchMode - switch app mode
This action terminates the action chain in the current frame.
func (AppActionSwitchMode) Target ¶
func (a AppActionSwitchMode) Target() ActionTarget
type AppMode ¶
type AppMode int
const ( // ModeNormal is the default mode ModeNormal AppMode = iota // ModeNewPath is used when creating a new path ModeNewPath // ModeNewBuilding is used when creating a new building ModeNewBuilding // ModeNewTextBox is used when creating a new text box ModeNewTextBox // ModeSelection is used when one or many object are selected ModeSelection )
type AppOptions ¶
type BuildingDef ¶
type BuildingDef struct { Class string Category string Dims rl.Vector2 BeltIn inputOutputs BeltOut inputOutputs PipeIn inputOutputs PipeOut inputOutputs }
func (BuildingDef) String ¶
func (b BuildingDef) String() string
type BuildingDefs ¶
type BuildingDefs []BuildingDef
func (BuildingDefs) Categories ¶
func (defs BuildingDefs) Categories() []string
func (BuildingDefs) Classes ¶
func (defs BuildingDefs) Classes() []string
func (BuildingDefs) Index ¶
func (defs BuildingDefs) Index(class string) int
type Camera ¶
type Camera struct { // true if camera is currently zooming (middle mouse button down) Zooming bool // zoom at position ZoomAt rl.Vector2 // contains filtered or unexported fields }
Holds camera state
func (*Camera) Dispatch ¶
Dispatch performs a Camera action, updating its state, and returns an new action to be performed
Note: All camera actions returns nil (no follow up)
See: ActionHandler
func (*Camera) Update ¶
func (c *Camera) Update()
Update processes inputs, and directly execute the TargetCamera action to be performed.
TargetCamera actions does not have follow up actions.
type CameraActionPan ¶
CameraActionPan - pan the camera by the given vector
func (CameraActionPan) Target ¶
func (a CameraActionPan) Target() ActionTarget
type CameraActionReset ¶
type CameraActionReset struct{}
CameraActionReset - reset the camera to its default position and zoom
func (CameraActionReset) Target ¶
func (a CameraActionReset) Target() ActionTarget
type CameraActionZoom ¶
CameraActionZoom - zoom the camera
func (CameraActionZoom) Target ¶
func (a CameraActionZoom) Target() ActionTarget
type DecodeTextError ¶
func (DecodeTextError) Error ¶
func (e DecodeTextError) Error() string
type Dims ¶
type Dims struct { // Screen size Screen rl.Vector2 // Scene area dimensions Scene rl.Rectangle // Scene area dimensions (world coordinates) World rl.Rectangle // Scene area dimensions (world coordinates) expanded by 1 world unit on each side ExWorld rl.Rectangle // contains filtered or unexported fields }
type DrawCounts ¶
type GetActionFunc ¶
type GetActionFunc func() Action
GetActionFunc are responsible for converting inputs (mouse and keyboard) into an Action.
Each AppMode has a corresponding struct implementing a GetActionFunc method. They do not modify the state directly.
In most cases, the GetActionFunc methods do not returns an Action directly, but rather calls appropriate ActionHandler directly and returns their result.
This prevents runtime reflection (switch action.(type) statements) at the expense of a deeper call stack.
type Grid ¶
type Grid struct { // SnapStep is the snap step in world units, 0 to disable SnapStep float32 }
type Gui ¶
type Gui struct { Topbar guiTopbar Sidebar guiSidebar Detailsbar guiDetailsbar Statusbar guiStatusbar }
Gui is a container struct for all the GUI elements
func (*Gui) CapturesKeyPress ¶
Whether the gui should captures key presses
func (*Gui) Dispatch ¶
Dispatch performs an Gui action, updating its state, and returns an new action to be performed
See: ActionHandler
func (*Gui) UpdateAndDraw ¶
UpdateAndDraw combines drawing the GUI, handling GUI inputs and returns an Action to be performed.
Note: Raygui being an immediate mode GUI, we cannot seperate the update and draw steps.
type KeyBinding ¶
type KeyBinding int
KeyBinding represents a keyboard key binding
const ( BindingNull KeyBinding = iota BindingEscape BindingSave BindingSaveAs BindingUndo BindingRedo BindingDelete BindingDuplicate BindingRotate BindingDrag BindingUp BindingDown BindingLeft BindingRight BindingZoomIn BindingZoomOut BindingZoomReset )
type Keyboard ¶
type Keyboard struct { // Pressed key (handles repeated key presses) // // It is not 0 (KeyNull) on the first frame the key is down and if a key is maintained down // and no other key is pressed, it will periodically repeat that key. Pressed int32 // True if left or right shift key is down Shift bool // True if left or right control key is down Ctrl bool // True if alt key is down Alt bool // contains filtered or unexported fields }
func (Keyboard) Binding ¶
func (kb Keyboard) Binding() KeyBinding
Binding returns the key binding that matches the pressed key and modifiers
If gui is capturing key presses, always returns BindingNull
type MaskIterator ¶
type MaskIterator struct { // index for which to return true TrueIdxs []int // current index counter Idx int // contains filtered or unexported fields }
Iterate over a would-be mask from the true values indices.
func NewMaskIterator ¶
func NewMaskIterator(trueIdx []int) MaskIterator
NewMaskIterator returns a new MaskIterator from the given true values indices.
trueIdxs must be sorted in ascending order.
func (*MaskIterator) Next ¶
func (it *MaskIterator) Next() bool
Next returns the next value from the mask.
It always returns false when all the true values have been iterated over, but keep incrementing [MaskIterator.Idx] counter.
type Mouse ¶
type Mouse struct { // Mouse position (in world coordinates) Pos rl.Vector2 // Mouse position (in screen coordinates) ScreenPos rl.Vector2 // Snapped mouse position (in world coordinates) SnappedPos rl.Vector2 // Mouse movement delta since last frame (in screen coordinates) ScreenDelta rl.Vector2 // True when mouse is inside the scene area InScene bool // Wheel movement Wheel float32 // Left mouse button Left mouseButton // Middle mouse button Middle mouseButton // Right mouse button Right mouseButton }
type NewBuilding ¶
type NewBuilding struct {
// contains filtered or unexported fields
}
NewBuilding represents a new building creation state (corresponding to ModeNewBuilding)
func (*NewBuilding) Dispatch ¶
func (np *NewBuilding) Dispatch(action Action) Action
Dispatch performs an NewBuilding action, updating its state, and returns an new action to be performed
See: ActionHandler
func (NewBuilding) Draw ¶
func (np NewBuilding) Draw()
func (*NewBuilding) GetAction ¶
func (nb *NewBuilding) GetAction() (action Action)
GetAction processes inputs in ModeNewBuilding, and returns an action to be performed.
See: GetActionFunc
type NewBuildingActionInit ¶
type NewBuildingActionInit struct{ DefIdx int }
NewBuildingActionInit - initialize placing a new path
func (NewBuildingActionInit) Target ¶
func (a NewBuildingActionInit) Target() ActionTarget
type NewBuildingActionMoveTo ¶
NewBuildingActionMoveTo - update the new building position
func (NewBuildingActionMoveTo) Target ¶
func (a NewBuildingActionMoveTo) Target() ActionTarget
type NewBuildingActionPlace ¶
type NewBuildingActionPlace struct{}
NewBuildingActionPlace - place a new building
func (NewBuildingActionPlace) Target ¶
func (a NewBuildingActionPlace) Target() ActionTarget
type NewBuildingActionRotate ¶
type NewBuildingActionRotate struct{}
NewBuildingActionRotate - rotate the new building direction
func (NewBuildingActionRotate) Target ¶
func (a NewBuildingActionRotate) Target() ActionTarget
type NewPath ¶
type NewPath struct {
// contains filtered or unexported fields
}
NewPath represents a new path creation state (corresponding to ModeNewPath)
func (*NewPath) Dispatch ¶
Dispatch performs an NewPath action, updating its state, and returns an new action to be performed
See: ActionHandler
func (*NewPath) GetAction ¶
GetAction processes inputs in ModeNewPath, and returns an action to be performed
See: GetActionFunc
type NewPathActionInit ¶
type NewPathActionInit struct{ DefIdx int }
NewPathActionInit - initialize placing a new path
func (NewPathActionInit) Target ¶
func (a NewPathActionInit) Target() ActionTarget
type NewPathActionMoveTo ¶
NewPathActionMoveTo - update the new path position (either start or end, depending on internal state)
func (NewPathActionMoveTo) Target ¶
func (a NewPathActionMoveTo) Target() ActionTarget
type NewPathActionPlace ¶
type NewPathActionPlace struct{}
NewPathActionPlace - add a new path to the scene
func (NewPathActionPlace) Target ¶
func (a NewPathActionPlace) Target() ActionTarget
type NewPathActionPlaceStart ¶
type NewPathActionPlaceStart struct{}
NewPathActionPlaceStart - place a new path start
func (NewPathActionPlaceStart) Target ¶
func (a NewPathActionPlaceStart) Target() ActionTarget
type NewPathActionReverse ¶
type NewPathActionReverse struct{}
NewPathActionReverse - reverse the new path direction
func (NewPathActionReverse) Target ¶
func (a NewPathActionReverse) Target() ActionTarget
type NewTextBox ¶
type NewTextBox struct { TextBox TextBox // contains filtered or unexported fields }
func (*NewTextBox) Dispatch ¶
func (np *NewTextBox) Dispatch(action Action) Action
Dispatch performs an NewTextBox action, updating its state, and returns an new action to be performed
See: ActionHandler
func (NewTextBox) Draw ¶
func (np NewTextBox) Draw()
func (*NewTextBox) GetAction ¶
func (ntb *NewTextBox) GetAction() (action Action)
GetAction processes inputs in ModeNewTextBox, and returns an action to be performed.
See: GetActionFunc
type NewTextBoxActionInit ¶
type NewTextBoxActionInit struct{ DefIdx int }
NewTextBoxActionInit - initialize placing a new text box
func (NewTextBoxActionInit) Target ¶
func (a NewTextBoxActionInit) Target() ActionTarget
type NewTextBoxActionMoveTo ¶
NewTextBoxActionMoveTo - update the new text box position (either start or end, depending on internal state)
func (NewTextBoxActionMoveTo) Target ¶
func (a NewTextBoxActionMoveTo) Target() ActionTarget
type NewTextBoxActionPlace ¶
type NewTextBoxActionPlace struct{}
NewTextBoxActionPlace - add a new text box to the scene
func (NewTextBoxActionPlace) Target ¶
func (a NewTextBoxActionPlace) Target() ActionTarget
type NewTextBoxActionPlaceStart ¶
type NewTextBoxActionPlaceStart struct{}
NewTextBoxActionPlaceStart - place a new text box start
func (NewTextBoxActionPlaceStart) Target ¶
func (a NewTextBoxActionPlaceStart) Target() ActionTarget
type NewTextBoxActionReverse ¶
type NewTextBoxActionReverse struct{}
NewTextBoxActionReverse - reverse the new text box direction
func (NewTextBoxActionReverse) Target ¶
func (a NewTextBoxActionReverse) Target() ActionTarget
type Object ¶
type Object struct { // Type of the object Type ObjectType // Index in either [Scene.Buildings], [Scene.Paths] or [Scene.TextBoxes] Idx int }
Object represents a building, a whole path, a path start or a path end in the scene
type ObjectCollection ¶
ObjectCollection represents a collection of objects (buildings, & paths)
func (ObjectCollection) IsEmpty ¶
func (oc ObjectCollection) IsEmpty() bool
IsEmpty returns true if the collection is empty
func (ObjectCollection) SelectFromRect ¶
func (oc ObjectCollection) SelectFromRect(sel *ObjectSelection, rect rl.Rectangle)
SelectFromRect fills sel with the objects in the given rectangle and recomputes its bounding box
sel must be empty, it is passed to avoid reallocating it
type ObjectSelection ¶
type ObjectSelection struct { // BuildingIdxs is the slice of selected buildings indices of a [ObjectCollection.Buildings] // // It must be sorted in ascending order. BuildingIdxs []int // PathIdxs is the slice of selected paths indices of a [ObjectCollection.Paths] and whether // the path start and/or end is selected // // It must be sorted in ascending order. PathIdxs []PathSel // TextBoxIdxs is the slice of selected text boxes indices of a [ObjectCollection.TextBoxes] // // It must be sorted in ascending order. TextBoxIdxs []int // Bounds is the bounding box of the selection Bounds rl.Rectangle }
ObjectSelection represents a selection of objects in a ObjectCollection
func (ObjectSelection) AnyPathIdxs ¶
func (os ObjectSelection) AnyPathIdxs() []int
AnyPathIdxs returns the indices of the path with either start or end selected
func (ObjectSelection) BuildingsIterator ¶
func (os ObjectSelection) BuildingsIterator() MaskIterator
BuildingsIterator returns a mask iterator of the selected buildings
func (ObjectSelection) Contains ¶
func (os ObjectSelection) Contains(obj Object) bool
Contains returns true if the given object is in the selection (false for TypeInvalid)
func (ObjectSelection) EndIdxs ¶
func (os ObjectSelection) EndIdxs() []int
EndIdxs returns the indices of the path with end selected
func (ObjectSelection) FullPathIdxs ¶
func (os ObjectSelection) FullPathIdxs() []int
FullPathIdxs returns the indices of the path with both start and end selected
func (ObjectSelection) IsEmpty ¶
func (os ObjectSelection) IsEmpty() bool
IsEmpty returns true if the selection is empty
func (ObjectSelection) PathsIterator ¶
func (os ObjectSelection) PathsIterator() PathSelMaskIterator
PathsIterator returns a mask iterator of the selected paths
func (ObjectSelection) StartIdxs ¶
func (os ObjectSelection) StartIdxs() []int
StartIdxs returns the indices of the path with start selected
func (ObjectSelection) TextBoxesIterator ¶
func (os ObjectSelection) TextBoxesIterator() MaskIterator
TextBoxesIterator returns a mask iterator of the selected text boxes
type ObjectType ¶
type ObjectType int
ObjectType enumerates the different types of objects
const ( TypeInvalid ObjectType = iota TypeBuilding TypePath TypePathStart TypePathEnd TypeTextBox )
func (ObjectType) String ¶
func (ot ObjectType) String() string
type Path ¶
func (Path) CheckCollisionPoint ¶
Returns true if the given position is inside the path body.
func (Path) CheckEndCollisionPoint ¶
Returns true if the given position is inside the path end.
func (Path) CheckStartCollisionPoint ¶
Returns true if the given position is inside the path start.
type PathDef ¶
func (*PathDef) UnmarshalJSON ¶
type PathSel ¶
type PathSel struct { // Idx is the index of the path in [ObjectCollection.Paths] Idx int // Start is true if the path start is selected Start bool // End is true if the path end is selected End bool }
PathSel represents a selected path in a ObjectSelection
One of [Start] or [End] must be true.
type PathSelMaskIterator ¶
type PathSelMaskIterator struct { // index for which to return true TrueIdxs []PathSel // current index counter Idx int // contains filtered or unexported fields }
Iterate over a would-be mask from the true values.
func NewPathSelMaskIterator ¶
func NewPathSelMaskIterator(trueIdx []PathSel) PathSelMaskIterator
NewPathSelMaskIterator returns a new PathSelMaskIterator from the given true values.
trueIdxs must be sorted in ascending order.
func (*PathSelMaskIterator) Next ¶
func (it *PathSelMaskIterator) Next() (bool, bool)
Next returns the next pair of (start, end) from the mask.
It always returns (false, flase) when all the true values have been iterated over [PathSelMaskIterator.Idx] counter.
type Resets ¶
type Resets struct { Selector bool NewPath bool NewBuilding bool NewTextBox bool Selection bool Gui bool Camera bool }
TODO: Make it a flag set
func (Resets) WithCamera ¶
func (Resets) WithNewBuilding ¶
func (Resets) WithNewPath ¶
func (Resets) WithNewTextBox ¶
func (Resets) WithSelection ¶
func (Resets) WithSelector ¶
type Scene ¶
type Scene struct { ObjectCollection // The scene object currently hovered by the mouse Hovered Object // contains filtered or unexported fields }
Scene holds the scene objects (buildings and paths)
func (*Scene) AddBuilding ¶
AddBuilding adds the given building to the scene.
No validity check is performed.
func (*Scene) AddObjects ¶
func (s *Scene) AddObjects(col ObjectCollection)
AddObjects adds the given paths and buildings to the scene.
No validity checks is performed.
func (*Scene) AddTextBox ¶
AddTextBox adds the given text box to the scene.
func (*Scene) DeleteObjects ¶
func (s *Scene) DeleteObjects(sel ObjectSelection)
DeleteObjects deletes the given paths and buildings from the scene.
func (Scene) GetObjectAt ¶
GetObjectAt returns the object at the given position (world coordinates)
If multiple objects are at the position returns first one on this list:
- selected path with highest index: start / end over body
- selected building with highest index
- selected text box with highest index
- normal path with highest index: start / end over body
- normal building with highest index
- normal text box with highest index
This is (mostly) the reverse of Scene.Draw order to make viewing/selecting masked objects easier.
If no object is found, returns an zero-valued Object
func (*Scene) IsModified ¶
IsModified returns true if the scene has been modified since last save
func (Scene) IsPathValid ¶
func (*Scene) ModifyObjects ¶
func (s *Scene) ModifyObjects(sel ObjectSelection, new ObjectCollection)
ModifyObjects updates the given paths and buildings in the scene.
No validity checks is performed.
func (*Scene) Redo ¶
Redo tries to redo the last undone operation, and returns whether it has, and the action to be performed.
func (*Scene) ResetModified ¶
func (s *Scene) ResetModified()
ResetModified resets the scene modified flag
func (*Scene) SaveToText ¶
SaveToText saves the scene into text format.
All errors originate from the underlying io.Writer.
type Selection ¶
type Selection struct { ObjectSelection // contains filtered or unexported fields }
func (*Selection) Dispatch ¶
Dispatch performs a Selection action, updating its state, and returns an new action to be performed
See: ActionHandler
func (Selection) Draw ¶
func (s Selection) Draw()
Draws the selection (and the transformed selection if any)
func (*Selection) GetAction ¶
GetAction processes inputs in ModeSelection and returns an action to be performed.
See: GetActionFunc
type SelectionActionBeginTransformation ¶
type SelectionActionBeginTransformation struct { // Selection mode Mode SelectionMode // Start position for transformation Pos rl.Vector2 // If true, the transformation will track the mouse even on mouse down MoveOnMouseDown bool }
SelectionActionBeginTransformation - switch selection to either SelectionDrag or SelectionDuplicate
func (SelectionActionBeginTransformation) Target ¶
func (a SelectionActionBeginTransformation) Target() ActionTarget
type SelectionActionDelete ¶
type SelectionActionDelete struct{}
SelectionActionDelete - delete the current selection (SelectionNormal)
func (SelectionActionDelete) Target ¶
func (a SelectionActionDelete) Target() ActionTarget
type SelectionActionEndTransformation ¶
type SelectionActionEndTransformation struct { // If true, discard the transformation regardless of its validity Discard bool }
SelectionActionEndTransformation - commit the selection transformation to the scene
func (SelectionActionEndTransformation) Target ¶
func (a SelectionActionEndTransformation) Target() ActionTarget
type SelectionActionInitSelection ¶
type SelectionActionInitSelection struct{ Selection ObjectSelection }
SelectionActionInitSelection - initialize a new selection from a subset of the scene
func (SelectionActionInitSelection) Target ¶
func (a SelectionActionInitSelection) Target() ActionTarget
type SelectionActionInitSingleDrag ¶
type SelectionActionInitSingleDrag struct { // Object to select Object Object // Start position [SelectionDrag] Pos rl.Vector2 }
SelectionActionInitSingleDrag - initialize a new selection with a single object in SelectionDrag mode
func (SelectionActionInitSingleDrag) Target ¶
func (a SelectionActionInitSingleDrag) Target() ActionTarget
type SelectionActionMoveBy ¶
SelectionActionMoveBy - translate the selection by a given delta
func (SelectionActionMoveBy) Target ¶
func (a SelectionActionMoveBy) Target() ActionTarget
type SelectionActionMoveTo ¶
SelectionActionMoveTo - update the selection transformation position
func (SelectionActionMoveTo) Target ¶
func (a SelectionActionMoveTo) Target() ActionTarget
type SelectionActionRotate ¶
type SelectionActionRotate struct{}
SelectionActionRotate - rotate the selection transformation
func (SelectionActionRotate) Target ¶
func (a SelectionActionRotate) Target() ActionTarget
type SelectionMode ¶
type SelectionMode int
Represents a selection sub mode
const ( // Normal selection SelectionNormal SelectionMode = iota // A single text box is selected, allow text editing in details panel & text box resizing SelectionSingleTextBox // Selection is dragged SelectionDrag // Selection is being duplicated SelectionDuplicate // A single text box is being resized SelectionTextBoxResize )
func (SelectionMode) String ¶
func (m SelectionMode) String() string
type Selector ¶
type Selector struct { // objects in selector rectangle ObjectSelection // contains filtered or unexported fields }
func (*Selector) Dispatch ¶
Dispatch performs Selector action, updating its state, and returns an new action to be performed
See: ActionHandler
func (*Selector) GetAction ¶
GetAction processes inputs in ModeNormal and returns an action to be performed.
See: GetActionFunc
type SelectorActionInit ¶
SelectorActionInit - initialize the rectangle selector
func (SelectorActionInit) Target ¶
func (a SelectorActionInit) Target() ActionTarget
type SelectorActionMoveTo ¶
SelectorActionMoveTo - update the rectangle selector end corner position
func (SelectorActionMoveTo) Target ¶
func (a SelectorActionMoveTo) Target() ActionTarget
type SelectorActionSelect ¶
type SelectorActionSelect struct{}
SelectorActionSelect - apply the rectangle selector
func (SelectorActionSelect) Target ¶
func (a SelectorActionSelect) Target() ActionTarget