engoutil

package module
v0.0.0-...-d518bb8 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 20 Imported by: 0

README

engoutil

A toolkit of EngoEngine/engo. Easy to create components.

Warning: this is experimental. please do not use it in production

glyphterms loading text updater

Canvas

Use Canvas instead of common.RenderSystem

Component
  • LoadingComponent
  • FPSComponent
Shapes
  • Line

  • StippleLine

  • Rect

  • StippleLineRect

  • Circle

  • Polygon

  • Curve

  • Text

  • Shapes and method integration

  • New Text & Shader, unicode support.

See demos for usage.

Documentation

Index

Constants

View Source
const (
	BG_FILL_FULL uint8 = iota
	BG_FILL_WRAP
)
View Source
const Font04b08 = "04b08.ttf"
View Source
const FontDroidSans = "DroidSansFallbackFull.ttf"

Variables

View Source
var (
	TextShader     = &textShader{cameraEnabled: true}
	TextHUDShader  = &textShader{}
	ShapeShader    = &shapeShader{cameraEnabled: true}
	ShapeHUDShader = &shapeShader{}
)

Functions

func ColorEqualUint32

func ColorEqualUint32(c color.Color, u uint32) bool

ColorEqualUint32 判断 color.Color 和 uint32 是否相等

func InitShaders

func InitShaders()

func SetDefaultFont

func SetDefaultFont(urls string)

Types

type Canvas

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

Using Canvas instead of RenderSystem

func NewCanvas

func NewCanvas() *Canvas

func (*Canvas) Draw

func (c *Canvas) Draw()

After that, the contents of push will be rendered in the next frame

func (*Canvas) GroupPush

func (c *Canvas) GroupPush(groups ...Shapes)

func (*Canvas) New

func (c *Canvas) New(w *ecs.World)

func (*Canvas) Push

func (c *Canvas) Push(shapes ...*Shape)

func (*Canvas) Remove

func (c *Canvas) Remove(basic ecs.BasicEntity)

func (*Canvas) Update

func (c *Canvas) Update(dt float32)

type Color

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

Color implementation image.Color Interface

func NewColor

func NewColor(i uint32) *Color

NewColor creating color with uint32

func ParseColor

func ParseColor(clr color.Color) *Color

ParseColor creating color with color.Color

func (Color) Alpha

func (c Color) Alpha() byte

(Color) Alpha 返回透明度

func (*Color) EqualUint32

func (c *Color) EqualUint32(u uint32) bool

func (Color) RGBA

func (c Color) RGBA() (uint32, uint32, uint32, uint32)

implementation image.Color interface

func (*Color) Set

func (c *Color) Set(i uint32)

(*Color) Set set a new color

func (*Color) SetAlpha

func (c *Color) SetAlpha(i byte)

(*Color) SetAlpha 设置透明度

func (Color) String

func (c Color) String() string

func (Color) ToColor

func (c Color) ToColor() color.Color

(Color) ToColor returns a color.Color

func (Color) ToFloat32

func (c Color) ToFloat32() float32

func (Color) Unpack

func (c Color) Unpack() (byte, byte, byte, byte)

func (Color) Vec4

func (c Color) Vec4() [4]float32

type FPSComponent

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

func NewFPSComponent

func NewFPSComponent(x, y, size float32, fgColor, bgColor uint32) (f *FPSComponent)

func (*FPSComponent) Hide

func (f *FPSComponent) Hide()

func (*FPSComponent) Move

func (f *FPSComponent) Move(x, y float32)

func (*FPSComponent) New

func (f *FPSComponent) New(w *ecs.World)

func (*FPSComponent) Remove

func (*FPSComponent) Remove(ecs.BasicEntity)

func (*FPSComponent) SetAnchor

func (f *FPSComponent) SetAnchor(ax, ay float32)

func (*FPSComponent) SetFormat

func (f *FPSComponent) SetFormat(format string)

func (*FPSComponent) Show

func (f *FPSComponent) Show()

func (*FPSComponent) String

func (f *FPSComponent) String() string

func (*FPSComponent) Update

func (f *FPSComponent) Update(dt float32)

type Font

type Font struct {
	URL  string
	Size float64
	TTF  *truetype.Font
	// contains filtered or unexported fields
}

func (*Font) Create

func (f *Font) Create() error

Create is for loading fonts from the disk, given a location

func (*Font) CreatePreloaded

func (f *Font) CreatePreloaded() error

CreatePreloaded is for loading fonts which have already been defined (and loaded) within Preload

type FontAtlas

type FontAtlas struct {
	Image   *image.NRGBA
	Texture *gl.Texture

	// XLocation contains the X-coordinate of the starting position of all characters
	XLocation map[rune]float32
	// YLocation contains the Y-coordinate of the starting position of all characters
	YLocation map[rune]float32
	// Width contains the width in pixels of all the characters, including the spacing between characters
	Width map[rune]float32
	// Height contains the height in pixels of all the characters
	Height map[rune]float32
	// TotalWidth is the total amount of pixels the `FontAtlas` is wide; useful for determining the `Viewport`,
	// which is relative to this value.
	TotalWidth float32
	// TotalHeight is the total amount of pixels the `FontAtlas` is high; useful for determining the `Viewport`,
	// which is relative to this value.
	TotalHeight float32
	// The position of the last character
	CurrentX, CurrentY float32

	// LineHeight is Ascent+Descent
	LineHeight float32
	Ascent     float32
	// left-side and right-side bearings
	LeftSide, RightSide map[rune]float32
	// OffsetY Ascent + bounds.Min.Y
	OffsetY map[rune]float32
}

A FontAtlas is a representation of some of the Font characters, as an image

type LoadingComponent

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

func NewLoadingComponent

func NewLoadingComponent(x, y, size float32, fgColor, bgColor uint32) *LoadingComponent

func (*LoadingComponent) Hide

func (l *LoadingComponent) Hide()

func (*LoadingComponent) Move

func (l *LoadingComponent) Move(x, y float32)

func (*LoadingComponent) New

func (l *LoadingComponent) New(w *ecs.World)

Implement Initializer interface

func (*LoadingComponent) Pause

func (l *LoadingComponent) Pause(state bool)

func (*LoadingComponent) Remove

func (*LoadingComponent) Remove(ecs.BasicEntity)

Implement System interface

func (*LoadingComponent) SetSpeed

func (l *LoadingComponent) SetSpeed(speed float32)

func (*LoadingComponent) Show

func (l *LoadingComponent) Show()

func (*LoadingComponent) Speed

func (l *LoadingComponent) Speed() float32

func (*LoadingComponent) State

func (l *LoadingComponent) State() bool

func (*LoadingComponent) Toggle

func (l *LoadingComponent) Toggle()

func (*LoadingComponent) Update

func (l *LoadingComponent) Update(dt float32)

Implement System interface

type MouseAction

type MouseAction uint8
const (
	MOUSE_NONE MouseAction = iota
	MOUSE_CLICKED
	MOUSE_DRAGGED
)

type Padding

type Padding struct {
	Top, Right, Bottom, Left float32
}

type Point

type Point [2]float32

type Points

type Points []Point

func (Points) Equal

func (p Points) Equal(points []engo.Point) bool

func (Points) Points

func (p Points) Points() (points []engo.Point)

type Shape

type Shape struct {
	Entity *ecs.BasicEntity
	Render *common.RenderComponent
	Space  *common.SpaceComponent

	Mouse *common.MouseComponent
	// contains filtered or unexported fields
}

基础形状

func NewCircle

func NewCircle(cx, cy, radius, arc, strokeWidth float32, strokeColor, fillColor uint32) *Shape

NewCircle cx, cy are the center of the circle

func NewCurve

func NewCurve(x, y, width, height, strokeWidth float32, points Points, clr uint32) *Shape

func NewLine

func NewLine(x1, y1, x2, y2, lineWidth float32, clr uint32) *Shape

func NewPolygon

func NewPolygon(x, y, width, height float32, strokeWidth float32, points Points, strokeColor, fillColor uint32) *Shape

NewPolygon this is ComplexTriangles

func NewRect

func NewRect(x, y, width, height, strokeWidth float32, strokeColor, fillColor uint32) *Shape

NewRect

func NewStippleLine

func NewStippleLine(points Points, factor int32, pattern uint16, lineWidth float32, clr uint32) *Shape

NewStippleLine

func NewStippleRect

func NewStippleRect(x, y, width, height float32, factor int32, pattern uint16, lineWidth float32, clr uint32) *Shape

NewStippleRect

func NewText

func NewText(text string, x, y, ax, ay, size float32, color uint32) *Shape

NewText use default font ax, ay is anchor point, range -1..1, use 0.5 center the text in x, y

func NewTextWithStyle

func NewTextWithStyle(text string, x, y, ax, ay, size float32, color uint32, style *TextStyle) *Shape

func (*Shape) AddArc

func (s *Shape) AddArc(arc float32)

(*Shape) AddArc Loop to increase arc

func (*Shape) AddRotate

func (s *Shape) AddRotate(deg float32)

(*Shape) AddRotate 旋转增加角度

func (*Shape) GetBasicEntity

func (s *Shape) GetBasicEntity() *ecs.BasicEntity

implementation of common.BasicFace

func (*Shape) GetMouseComponent

func (s *Shape) GetMouseComponent() *common.MouseComponent

implementation of common.Mouseable

func (*Shape) GetRenderComponent

func (s *Shape) GetRenderComponent() *common.RenderComponent

implementation of common.RenderFace

func (*Shape) GetSpaceComponent

func (s *Shape) GetSpaceComponent() *common.SpaceComponent

implementation of common.SpaceFace

func (*Shape) Hidden

func (s *Shape) Hidden()

(*Shape) Hidden

func (*Shape) ID

func (s *Shape) ID() uint64

implementation of common.BasicFace

func (*Shape) Move

func (s *Shape) Move(x, y float32)

(*Shape) Move 移动

func (*Shape) MoveStippleLeft

func (s *Shape) MoveStippleLeft()

(*Shape) MoveStippleLeft

func (*Shape) MoveStippleRight

func (s *Shape) MoveStippleRight()

(*Shape) MoveStippleRight

func (*Shape) MoveX

func (s *Shape) MoveX(x float32)

(*Shape) MoveX 移动 X

func (*Shape) MoveY

func (s *Shape) MoveY(y float32)

(*Shape) MoveY 移动 Y

func (*Shape) OnClick

func (s *Shape) OnClick(fn func(*Shape))

(*Shape) OnClick

func (*Shape) OnDrag

func (s *Shape) OnDrag(fn func(*Shape, float32, float32))

(*Shape) OnDrag

func (*Shape) OnHover

func (s *Shape) OnHover(enter, leave func(*Shape))

(*Shape) OnHover

func (*Shape) OnUpdate

func (s *Shape) OnUpdate(fn func(*Shape, float32))

(*Shape) OnUpdate

func (*Shape) Rotate

func (s *Shape) Rotate(deg float32)

(*Shape) Rotate 设置旋转角度

func (*Shape) SetAnchor

func (s *Shape) SetAnchor(ax, ay float32)

(*Shape) SetAnchor 设置锚点, 范围 -1..1

func (*Shape) SetArc

func (s *Shape) SetArc(arc float32)

(*Shape) SetArc 设置形状"圆"的弧度 0..360

func (*Shape) SetBgStyle

func (s *Shape) SetBgStyle(style uint8)

func (*Shape) SetFillColor

func (s *Shape) SetFillColor(clr uint32)

(*Shape) SetFillColor

func (*Shape) SetLetterSpacing

func (s *Shape) SetLetterSpacing(spacing float32)

func (*Shape) SetLineSpacing

func (s *Shape) SetLineSpacing(spacing float32)

func (*Shape) SetPoints

func (s *Shape) SetPoints(points Points)

(*Shape) SetPoints 支持这些形状 SHAPE_KIND_STIPPLE_LINE, SHAPE_KIND_POLYGON, SHAPE_KIND_CURVE

func (*Shape) SetRadius

func (s *Shape) SetRadius(radius float32)

(*Shape) SetRadius

func (*Shape) SetStipple

func (s *Shape) SetStipple(factor int32, pattern uint16)

(*Shape) SetStipple

func (*Shape) SetStrokeColor

func (s *Shape) SetStrokeColor(clr uint32)

(*Shape) SetStrokeColor

func (*Shape) SetStrokeWidth

func (s *Shape) SetStrokeWidth(width float32)

(*Shape) SetStrokeWidth

func (*Shape) SetText

func (s *Shape) SetText(text string)

(*Shape) SetText 改变文本

func (*Shape) Show

func (s *Shape) Show()

(*Shape) Show

func (*Shape) Stipple

func (s *Shape) Stipple() (int32, uint16)

(*Shape) Stipple

func (*Shape) Transform

func (s *Shape) Transform(x, y, width, height float32)

(*Shape) Transform @overload Line.Transform(x1, y1, x2, y2) @overload Circle.Transform(cx, cy, radius) @overload Text.Transform(x, y)

func (*Shape) Visible

func (s *Shape) Visible() bool

(*Shape) Visible

type ShapeKind

type ShapeKind uint16
const (
	SHAPE_KIND_LINE ShapeKind = 1 << iota
	SHAPE_KIND_STIPPLE_LINE
	SHAPE_KIND_RECT
	SHAPE_KIND_STIPPLE_RECT
	SHAPE_KIND_CIRCLE
	SHAPE_KIND_POLYGON
	SHAPE_KIND_CURVE
	SHAPE_KIND_TEXT
	SHAPE_KIND_IMAGE
)

func (ShapeKind) String

func (kind ShapeKind) String() string

type Shapes

type Shapes []*Shape

type Stipple

type Stipple struct {
	Factor  int32
	Pattern uint16
}

type StippleLine

type StippleLine struct {
	BorderWidth float32
	Points      []engo.Point
	Stipple     Stipple
}

StippleLine

func (StippleLine) Close

func (StippleLine) Close()

func (StippleLine) Height

func (StippleLine) Height() float32

func (StippleLine) Texture

func (StippleLine) Texture() *gl.Texture

func (StippleLine) View

func (StippleLine) Width

func (StippleLine) Width() float32

type StippleRect

type StippleRect struct {
	BorderWidth float32
	Stipple     Stipple
}

StippleRect

func (StippleRect) Close

func (StippleRect) Close()

func (StippleRect) Height

func (StippleRect) Height() float32

func (StippleRect) Texture

func (StippleRect) Texture() *gl.Texture

func (StippleRect) View

func (StippleRect) Width

func (StippleRect) Width() float32

type Text

type Text struct {
	// Font is the reference to the font you're using to render this. This includes the font size.
	Font *Font
	// Text is the actual text you want to draw. This may include newlines (\n).
	Text string
	// LineSpacing is the amount of additional spacing there is between the lines (when `Text` consists of multiple lines).
	LineSpacing float32
	// LetterSpacing is the amount of additional spacing there is between the characters.
	LetterSpacing float32

	// The shader uses the position here instead of the SpaceComponent.Position.
	// Because Padding changes size and position of SpaceComponent.
	Position engo.Point
	// font color
	Color *Color
	// BG fill style, BG_FILL_FULL or BG_FILL_WRAP
	BgStyle uint8
	// Only when the BgStyle is BG_TYPE_FULL.
	// This changes the size of the entity (common.SpaceComponent).
	// In order to make common.MouseComponent working.
	Padding Padding
	// contains filtered or unexported fields
}

Text represents a string drawn onto the screen, as used by the `TextShader`.

func (Text) Close

func (t Text) Close()

func (Text) Height

func (t Text) Height() (height float32)

Height returns the height the Text generated from a FontAtlas. This implements the common.Drawable interface.

func (Text) Length

func (t Text) Length() int

func (Text) Texture

func (t Text) Texture() *gl.Texture

Texture returns nil because the Text is generated from a FontAtlas. This implements the common.Drawable interface.

func (Text) View

func (t Text) View() (float32, float32, float32, float32)

func (Text) Width

func (t Text) Width() (width float32)

Width returns the width of the Text generated from a FontAtlas. This implements the common.Drawable interface.

type TextStyle

type TextStyle struct {
	URL           string
	Width         float32
	Height        float32
	BG            uint32
	BgStyle       uint8
	LineSpacing   float32
	LetterSpacing float32
	Padding       Padding
}

Directories

Path Synopsis
demos

Jump to

Keyboard shortcuts

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