frenyard

package
v0.0.0-...-b5003a3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DrawModeAdd = 2

DrawModeAdd is an "additive" blend mode. `vec4(dst.rgb + src.rgb, dst.a)`

View Source
const DrawModeModulate = 3

DrawModeModulate is a "modulate" blend mode. `vec4(dst.rgb * src.rgb, dst.a)`

View Source
const DrawModeNoBlending = 1

DrawModeNoBlending disables blending. `src`

View Source
const DrawModeNormal = 0

DrawModeNormal is a normal blended draw mode; typically "what you want". `vec4(mix(dst.rgb, src.rgb, src.a), src.a + (dstA * (1 - src.a)))`

View Source
const SizeUnlimited int32 = 0x7FFFFFFF

SizeUnlimited is equal to the maximum value an int32 can have, represents an infinite value. Note that 0x80000000 is reserved; -0x7FFFFFFF is considered the definitive 'negative unlimited' value for simplicity's sake.

Variables

View Source
var ExitFlag bool = false

ExitFlag when set to true, exits the application.

View Source
var TargetFrameTime float64 = 0.05 // 20FPS

TargetFrameTime controls the framerate of the application.

Functions

func AddCU

func AddCU(a int32, b int32) int32

AddCU performs an addition with consideration for unlimited values.

func EasingInOut

func EasingInOut(easeIn func(float64) float64) func(float64) float64

EasingInOut currys a function. Given an ease-in function, returns an ease in-out function.

func EasingQuadraticIn

func EasingQuadraticIn(point float64) float64

EasingQuadraticIn is a quadratic ease-in function, which in practice means it just squares the input value.

func InferScale

func InferScale(dpiSource Window) float64

InferScale infers a 'reasonable scale' for a provided window.

func Max

func Max(a int32, b int32) int32

Max returns the higher of two int32 values.

func Min

func Min(a int32, b int32) int32

Min returns the smaller of two int32 values.

func ModifyScaleBinInt

func ModifyScaleBinInt(scale float64) float64

ModifyScaleBinInt "snaps" the scale to the nearest power-of-two division (if < 1) or the nearest integer (if >= 1)

func Scale

func Scale(scale float64, target int32) int32

Scale returns a scaled value as an integer.

Types

type Alignment1i

type Alignment1i int8

Alignment1i specifies an alignment preference along an axis.

const AlignEnd Alignment1i = 1

AlignEnd aligns the element at the end (right/bottom).

const AlignMiddle Alignment1i = 0

AlignMiddle aligns the element at the centre.

const AlignStart Alignment1i = -1

AlignStart aligns the element at the start (left/top).

type Alignment2i

type Alignment2i struct {
	X Alignment1i
	Y Alignment1i
}

Alignment2i contains two Alignment1is (one for each axis).

type Area1i

type Area1i struct {
	Pos  int32
	Size int32
}

Area1i is a 1-dimensional axis-aligned area, which is a useful primitive for N-dimensional areas. Please note that Area1i, and by extension Area2i, may malfunction if given infinite values.

func Area1iMargin

func Area1iMargin(l int32, r int32) Area1i

Area1iMargin is a quick idiom for a margin of a given size.

func Area1iOfSize

func Area1iOfSize(a int32) Area1i

Area1iOfSize returns an Area1i of the given size (covering range inclusive 0 to exclusive size)

func ScaleMargin1

func ScaleMargin1(scale float64, target Area1i) Area1i

ScaleMargin1 scales a margin.

func UnionArea1i

func UnionArea1i(areas []Area1i) Area1i

UnionArea1i gets an area containing all areas in the given slice

func (Area1i) Align

func (a Area1i) Align(content int32, x Alignment1i) Area1i

Align aligns an area within another.

func (Area1i) Contains

func (a Area1i) Contains(i int32) bool

Contains checks if a point is within the area.

func (Area1i) Contract

func (a Area1i) Contract(n Area1i) Area1i

Contract contracts an area by a margin; the reverse of Expand.

func (Area1i) Empty

func (a Area1i) Empty() bool

Empty returns Size <= 0

func (Area1i) Expand

func (a Area1i) Expand(n Area1i) Area1i

Expand expands an area by a margin, expressed as the area around as if this had zero size.

func (Area1i) Intersect

func (a Area1i) Intersect(b Area1i) Area1i

Intersect intersects two areas. Always returns a normalized area.

func (Area1i) Normalized

func (a Area1i) Normalized() Area1i

Normalized replaces empty areas with zeroed areas.

func (Area1i) Translate

func (a Area1i) Translate(i int32) Area1i

Translate translates an area by an offset.

func (Area1i) Union

func (a Area1i) Union(b Area1i) Area1i

Union unions two areas.

type Area1iGrid3

type Area1iGrid3 struct {
	A Area1i
	B Area1i
	C Area1i
}

Area1iGrid3 is an Area1i split into a left area, the original 'inner' area, and the right area.

func SplitArea1iGrid3

func SplitArea1iGrid3(outer Area1i, inner Area1i) Area1iGrid3

SplitArea1iGrid3 splits an Area1i into 3 sections using the bounds of an inner Area1i.

func (Area1iGrid3) AsMargin

func (a Area1iGrid3) AsMargin() Area1i

AsMargin returns a margin around the centre Area1i for Expand.

type Area2i

type Area2i struct {
	X Area1i
	Y Area1i
}

Area2i is the basic rectangle type. Please note that Area2i may malfunction if given infinite values.

func Area2iFromVecs

func Area2iFromVecs(pos Vec2i, size Vec2i) Area2i

Area2iFromVecs returns an Area2i made from a position/size vector pair.

func Area2iMargin

func Area2iMargin(l int32, u int32, r int32, d int32) Area2i

Area2iMargin is a quick idiom for a margin of a given size.

func Area2iOfSize

func Area2iOfSize(a Vec2i) Area2i

Area2iOfSize returns an Area2i of the given size.

func ScaleMargin2

func ScaleMargin2(scale float64, target Area2i) Area2i

ScaleMargin2 scales a margin.

func UnionArea2i

func UnionArea2i(areas []Area2i) Area2i

UnionArea2i gets an area containing all areas in the given slice

func (Area2i) Align

func (a Area2i) Align(content Vec2i, align Alignment2i) Area2i

Align aligns an area within another.

func (Area2i) Contains

func (a Area2i) Contains(v Vec2i) bool

Contains checks if a point is within the area.

func (Area2i) Contract

func (a Area2i) Contract(b Area2i) Area2i

Contract contracts an area by a margin; the reverse of Expand.

func (Area2i) Empty

func (a Area2i) Empty() bool

Empty returns Size <= 0

func (Area2i) Expand

func (a Area2i) Expand(b Area2i) Area2i

Expand expands an area by a margin, expressed as the area around as if this had zero size.

func (Area2i) Intersect

func (a Area2i) Intersect(b Area2i) Area2i

Intersect intersects two areas. Always returns a normalized area.

func (Area2i) Normalized

func (a Area2i) Normalized() Area2i

Normalized replaces empty areas with zeroed areas.

func (Area2i) Pos

func (a Area2i) Pos() Vec2i

Pos returns a 'position' vector for the area. (see Area2iFromVecs)

func (Area2i) Size

func (a Area2i) Size() Vec2i

Size returns a 'size' vector for the area (see Area2iFromVecs)

func (Area2i) Translate

func (a Area2i) Translate(v Vec2i) Area2i

Translate translates an area by an offset.

func (Area2i) Union

func (a Area2i) Union(b Area2i) Area2i

Union unions two areas.

type Area2iGrid3x3

type Area2iGrid3x3 struct {
	A Area2i
	B Area2i
	C Area2i
	D Area2i
	E Area2i
	F Area2i
	G Area2i
	H Area2i
	I Area2i
}

Area2iGrid3x3 is Area1iGrid3 in two dimensions.

func SplitArea2iGrid3x3

func SplitArea2iGrid3x3(outer Area2i, inner Area2i) Area2iGrid3x3

SplitArea2iGrid3x3 splits an Area2i into 9 sections using the bounds of an inner Area2i.

func (Area2iGrid3x3) AsMargin

func (a Area2iGrid3x3) AsMargin() Area2i

AsMargin returns a margin around the centre Area2i for Expand.

type Backend

type Backend interface {
	// Begins the frame loop. Stops when ExitFlag is set to true.
	Run(ticker func(frameTime float64)) error
	CreateWindow(name string, size Vec2i, vsync bool, receiver WindowReceiver) (Window, error)
	CreateTexture(size Vec2i, pixels []uint32) Texture
}

Backend is the set of "entrypoint" functions to the core API.

var GlobalBackend Backend

GlobalBackend is the global instance of Backend.

type DrawMode

type DrawMode uint8

DrawMode represents some form of drawing mode for the primitive. (Documentation for these should include a GLSLish equal for those versed in graphics, ideally translated from the SDL2 documentation.)

type DrawRectCommand

type DrawRectCommand struct {
	// Where to draw
	Target Area2i
	// Texture
	Tex Texture
	// Area within texture to get pixels from.
	TexSprite Area2i
	// Colour [modulation if Texture is given]
	Colour uint32
	// Blending Mode/etc.
	Mode DrawMode
}

DrawRectCommand represents a rectangle-based drawing command.

type KeyEvent

type KeyEvent struct {
	Pressed   bool
	Scancode  int32
	Keycode   int32
	Modifiers uint16
}

KeyEvent represents a key changing state. It uses the same constants as SDL2 because I never planned for key input to be in here, but then someone said "what about a search box". Nevermind that this opens a massive can of worms...

func (KeyEvent) FyVOffset

func (ke KeyEvent) FyVOffset(amount Vec2i) NormalEvent

FyVOffset implements NormalEvent.FyVOffset

func (KeyEvent) FyVRoute

func (ke KeyEvent) FyVRoute() NormalEventRoute

FyVRoute implements NormalEvent.FyVRoute

type MouseButton

type MouseButton int8

MouseButton describes a mouse button.

const MouseButtonLeft MouseButton = 0

MouseButtonLeft is the left mouse button.

const MouseButtonLength MouseButton = 9

MouseButtonLength is not a real button. You may need to use (int8)(0) in for loops.

const MouseButtonMiddle MouseButton = 1

MouseButtonMiddle is the middle mouse button (Do be warned: Laptop users do not get this in any 'easy to understand' form.)

const MouseButtonNone MouseButton = -1

MouseButtonNone indicates that no button was involved. Only appears for MouseEventMove

const MouseButtonRight MouseButton = 2

MouseButtonRight is the right mouse button

const MouseButtonScrollDown MouseButton = 6

MouseButtonScrollDown is a virtual scroll

const MouseButtonScrollLeft MouseButton = 7

MouseButtonScrollLeft is a virtual scroll

const MouseButtonScrollRight MouseButton = 8

MouseButtonScrollRight is a virtual scroll

const MouseButtonScrollUp MouseButton = 5

MouseButtonScrollUp is a virtual scroll

const MouseButtonX1 MouseButton = 3

MouseButtonX1 is a fancy auxiliary mouse button that not all people have

const MouseButtonX2 MouseButton = 4

MouseButtonX2 is a fancy auxiliary mouse button that not all people have

type MouseEvent

type MouseEvent struct {
	// Where the mouse is *relative to the receiving element.*
	Pos Vec2i
	// Indicates the sub-type of the event.
	ID MouseEventID
	// Meaningless for MOUSEEVENT_MOVE. See MOUSEBUTTON_*
	Button MouseButton
}

MouseEvent is a mouse event.

func (MouseEvent) Offset

func (ev MouseEvent) Offset(offset Vec2i) MouseEvent

Offset offsets the mouse event by a given amount.

type MouseEventID

type MouseEventID uint8

MouseEventID describes a type of MouseEvent.

const MouseEventDown MouseEventID = 1

MouseEventDown indicates that the event is because a mouse button was pressed

const MouseEventMove MouseEventID = 0

MouseEventMove indicates that the event is because the mouse was moved.

const MouseEventUp MouseEventID = 2

MouseEventUp indicates that the event is because a mouse button was released

type NormalEvent

type NormalEvent interface {
	// Indicates how to route the event.
	FyVRoute() NormalEventRoute
	// Offset the event by some amount. Apply the same way as MouseEvent.
	FyVOffset(amount Vec2i) NormalEvent
}

NormalEvent is the base of standard, non-special event types

type NormalEventRoute

type NormalEventRoute uint8

NormalEventRoute represents a target for events.

const (
	// NormalEventRouteStop Do not forward.
	NormalEventRouteStop NormalEventRoute = iota
	// NormalEventRouteFocus Routes to the focused element.
	NormalEventRouteFocus
	// NormalEventRouteBroadcast Broadcast to every element.
	NormalEventRouteBroadcast
	// NormalEventRouteStructuralBroadcast Broadcast to every element, even if an event-blocking firewall is active.
	NormalEventRouteStructuralBroadcast
)

type Renderer

type Renderer interface {

	// Draws a DrawRectCommand.
	DrawRect(DrawRectCommand)

	// Translates the renderer's target. Use with defer to undo later.
	Translate(vec Vec2i)
	// Returns the renderer's translation.
	Translation() Vec2i
	// Sets the clip area, relative to the current translation.
	SetClip(clip Area2i)
	// Gets the clip area, relative to the current translation.
	Clip() Area2i

	// Gets the size of the drawing area.
	Size() Vec2i
	// Clears & resets clip/translate/etc. You should do this at the start of  frame.
	Reset(colour uint32)

	// Calls drawer() while rendering to a texture. All other operations occur within this texture for that duration. Can be stacked; the latest RenderToTexture applies.
	// 'reserved' does nothing but must be left false.
	// The resulting texture from this renderer may only be used on this renderer.
	RenderToTexture(size Vec2i, drawer func(), reserved bool) Texture
}

Renderer is an abstract rendering interface.

type TextInput

type TextInput interface {
	// Called when the text input is made active.
	FyTOpen()
	// Area gets the area of the TextInput.
	FyTArea() Area2i
	// Sets the candidate buffer.
	FyTEditing(text string, start int, length int)
	// Writes into the editing text buffer and clears the candidate buffer.
	FyTInput(text string)
	// Called when the text input is changed to any other input.
	FyTClose()
}

TextInput represents a text input.

type Texture

type Texture interface {
	Size() Vec2i
}

Texture interface. This is automatically deleted on finalization.

type Vec2i

type Vec2i struct {
	X, Y int32
}

Vec2i is the basic 2-dimensional vector type.

func ScaleVec2i

func ScaleVec2i(scale float64, target Vec2i) Vec2i

ScaleVec2i scales a Vec2i.

func Vec2iUnlimited

func Vec2iUnlimited() Vec2i

Vec2iUnlimited returns a Vec2i of unlimited size.

func (Vec2i) Add

func (a Vec2i) Add(b Vec2i) Vec2i

Add adds two Vec2is.

func (Vec2i) ConditionalTranspose

func (a Vec2i) ConditionalTranspose(yes bool) Vec2i

ConditionalTranspose conditionally swaps X/Y, which is useful when the coordinate system is variable.

func (Vec2i) Eq

func (a Vec2i) Eq(b Vec2i) bool

Eq compares two Vec2is and returns true for equal.

func (Vec2i) Ge

func (a Vec2i) Ge(b Vec2i) bool

Ge checks if an area of size A could hold an area of size B (with or without spare room).

func (Vec2i) Gt

func (a Vec2i) Gt(b Vec2i) bool

Gt checks if an area of size A could hold an area of size B with room to spare.

func (Vec2i) Max

func (a Vec2i) Max(b Vec2i) Vec2i

Max is similar to Min, but uses maximum, not minimum.

func (Vec2i) Min

func (a Vec2i) Min(b Vec2i) Vec2i

Min returns a Vec2i with each axis value being the minimum of the two input Vec2i values on that axis.

func (Vec2i) Negate

func (a Vec2i) Negate() Vec2i

Negate returns the vector multiplied by -1.

type Window

type Window interface {
	Renderer
	Name() string
	SetName(name string)
	Present()
	Destroy()
	// Gets the DPI of the window. This can change. Oh well.
	GetLocalDPI() float64
	// Sets the size of the window (if possible)
	SetSize(size Vec2i)
	// Gets the text input, or nil for no input (useful to check when unfocusing)
	TextInput() TextInput
	// Sets the text input, or nil for no input
	SetTextInput(input TextInput)
}

Window type. This type MAY be user-implemented with the understanding that no Core/CoreExt functions accept Window or Renderer (hence there are no potential issues), and that this is still intended as a Core/CoreExt type so doesn't get the name-prefixing.

type WindowReceiver

type WindowReceiver interface {
	FyRStart(w Window)
	FyRTick(time float64)
	FyRNormalEvent(n NormalEvent)
	FyRMouseEvent(m MouseEvent)
	// Note: The window is destroyed after this completes.
	FyRClose()
}

WindowReceiver receives window events.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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