viewdrag

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: Apache-2.0 Imports: 3 Imported by: 2

README

viewdrag

viewdrag will drag and drop the image in the viewport.

accepts ebiten.image only as sprite or; accepts ebiten.image with vertices and indeces as mesh

running the app

This is basic dragging the view implementation.

This is ebiten's dragging example (with only one "ebiten"): go run ./cmd/1_basic/main.go

This creates a mesh if you want to set the mesh upon initializing the app: go run ./cmd/1_basic_with_mesher/main.go

This sets the mesh every loop: go run ./cmd/1_basic_with_mesh/main.go

license

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Size

func Size(vertices []ebiten.Vertex) (w, h float32)

Size returns the width and height of the mesh

Types

type Mesh

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

Mesh represents set of triangles.

func NewMesh

func NewMesh(ebitenImage *ebiten.Image, vertices []ebiten.Vertex, indeces []uint16, x, y, screenWidth, screenHeight int) *Mesh

NewMesh generates new mesh with farthest vector

func (*Mesh) Draw

func (m *Mesh) Draw(screen *ebiten.Image, dx, dy int, alpha float64)

Draw draws the mesh.

func (*Mesh) GetPosition

func (m *Mesh) GetPosition() (int, int)

GetPosition gives the displacement position of the of the whole mesh

func (*Mesh) MoveBy

func (m *Mesh) MoveBy(x, y int)

MoveBy asks for increments of the movements

type MouseStrokeSource

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

MouseStrokeSource is a StrokeSource implementation of mouse.

func (*MouseStrokeSource) IsJustReleased

func (m *MouseStrokeSource) IsJustReleased() bool

IsJustReleased asks if the mouse button is up

func (*MouseStrokeSource) Position

func (m *MouseStrokeSource) Position() (int, int)

Position gives the current position by a mouse

type Sprite

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

Sprite represents an image.

func NewSprite

func NewSprite(ebitenImage *ebiten.Image, x, y, screenWidth, screenHeight int) *Sprite

NewSprite generates new Sprite

func (*Sprite) Draw

func (s *Sprite) Draw(screen *ebiten.Image, dx, dy int, alpha float64)

Draw draws the sprite.

func (*Sprite) GetPosition

func (s *Sprite) GetPosition() (int, int)

GetPosition gives the current position of the sprite

func (*Sprite) MoveBy

func (s *Sprite) MoveBy(x, y int)

MoveBy asks for increments of the movements

type Spriter

type Spriter interface {
	MoveBy(x, y int)
	GetPosition() (int, int)
	Draw(screen *ebiten.Image, dx, dy int, alpha float64)
}

Spriter will match mesh and sprite structs. only difference is that mesh will contain triangle vertices nad indeces

type Stroke

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

Stroke manages the current drag state by mouse.

func NewStroke

func NewStroke(source StrokeSource) *Stroke

NewStroke asks for devices' custom controls and provides custom default values

func (*Stroke) DraggingSprite

func (s *Stroke) DraggingSprite() Spriter

DraggingSprite gives the Spriter being dragged

func (*Stroke) IsReleased

func (s *Stroke) IsReleased() bool

IsReleased asks if the mouse button is up

func (*Stroke) Position

func (s *Stroke) Position() (int, int)

Position gives the current stroke position

func (*Stroke) PositionDiff

func (s *Stroke) PositionDiff() (int, int)

PositionDiff gives the position after the change from initial to current

func (*Stroke) SetDraggingSpriter

func (s *Stroke) SetDraggingSpriter(sprite Spriter)

SetDraggingSpriter sets the Spriter to be dragged

func (*Stroke) Update

func (s *Stroke) Update()

Update sets the current stroke's position

type StrokeSource

type StrokeSource interface {
	Position() (int, int)
	IsJustReleased() bool
}

StrokeSource represents a input device to provide strokes.

type View

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

View controls the state of the game

func NewView

func NewView(ebitenImage *ebiten.Image, x, y, screenWidth, screenHeight int, trigger ebiten.MouseButton) *View

NewView gives custom default values

func NewViewWithMesh

func NewViewWithMesh(ebitenImage *ebiten.Image, vertices []ebiten.Vertex, indeces []uint16, x, y, screenWidth, screenHeight int, trigger ebiten.MouseButton) *View

NewViewWithMesh gives custom default values

func (*View) Compute

func (v *View) Compute(scr *ebiten.Image) error

Compute implements ebiten Update func before draw skipping for main loop

func (*View) Render

func (v *View) Render(scr *ebiten.Image) error

Render implements ebiten Update func after draw skipping for main loop

func (*View) SetMesh

func (v *View) SetMesh(vertices []ebiten.Vertex, indices []uint16) error

SetMesh sets the sprite as a mesh from triangles.

This must be called before compute is called.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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