Version: v0.0.0-...-40b9e5c Latest Latest

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 7 Imported by: 10




View Source
const (


View Source
var ActivePageWaitGroup sync.WaitGroup
View Source
var Scaling float32 = 1.0


func DrawParentAndChildren

func DrawParentAndChildren(r *sdl.Renderer, c Component) error

func PassKeyEventToChildren

func PassKeyEventToChildren(event *sdl.KeyboardEvent, children []Component) bool

func PassMouseButtonEventToChildren

func PassMouseButtonEventToChildren(event *sdl.MouseButtonEvent, children []Component) bool

func RegisterPage

func RegisterPage(p Page)

func SetupSDL

func SetupSDL() error

func SwitchPage

func SwitchPage(newPage string)

func SwitchPageWithData

func SwitchPageWithData(newPage string, data interface{})


type BaseComponent

type BaseComponent struct {
	X        int32
	Y        int32
	Width    int32
	Height   int32
	Children []Component
	Visible  bool

func (*BaseComponent) AddChild

func (c *BaseComponent) AddChild(comp Component)

func (*BaseComponent) BaseMouseButtonEvent

func (c *BaseComponent) BaseMouseButtonEvent(event *sdl.MouseButtonEvent) bool

func (*BaseComponent) Draw

func (c *BaseComponent) Draw(r *sdl.Renderer) error

func (*BaseComponent) DrawComponent

func (c *BaseComponent) DrawComponent(r *sdl.Renderer) error

func (BaseComponent) GetChildren

func (c BaseComponent) GetChildren() []Component

func (*BaseComponent) Initialize

func (c *BaseComponent) Initialize()

func (BaseComponent) IsPointInComponent

func (c BaseComponent) IsPointInComponent(x, y int32) bool

func (BaseComponent) IsVisible

func (c BaseComponent) IsVisible() bool

func (*BaseComponent) KeyEvent

func (c *BaseComponent) KeyEvent(event *sdl.KeyboardEvent) bool

func (*BaseComponent) MouseButtonEvent

func (c *BaseComponent) MouseButtonEvent(event *sdl.MouseButtonEvent) bool

func (BaseComponent) Position

func (c BaseComponent) Position() (int32, int32)

func (*BaseComponent) RemoveChild

func (c *BaseComponent) RemoveChild(index int)

func (*BaseComponent) SetPosition

func (c *BaseComponent) SetPosition(x, y int32)

func (*BaseComponent) SetSize

func (c *BaseComponent) SetSize(width, height int32)

func (*BaseComponent) SetVisible

func (c *BaseComponent) SetVisible(visible bool)

func (BaseComponent) Size

func (c BaseComponent) Size() (int32, int32)

type BaseGame

type BaseGame struct {
	GameWidth  int32
	GameHeight int32

func (*BaseGame) Initialize

func (g *BaseGame) Initialize(gameWidth int32, gameHeight int32)

Initialize should be called by any descending structs

func (*BaseGame) LoadPages

func (g *BaseGame) LoadPages() []Page

func (*BaseGame) RegisterPages

func (g *BaseGame) RegisterPages(pages []Page) error

type BasePage

type BasePage struct {

	Data interface{}
	Name string

func (*BasePage) GetData

func (p *BasePage) GetData() interface{}

func (BasePage) GetName

func (p BasePage) GetName() string

func (*BasePage) PageLoad

func (p *BasePage) PageLoad() error

func (*BasePage) PageUnload

func (p *BasePage) PageUnload() error

func (*BasePage) Quit

func (p *BasePage) Quit() bool

func (*BasePage) SetData

func (p *BasePage) SetData(data interface{})

type ButtonComponent

type ButtonComponent struct {

	Text     string
	OnAction OnActionFunc
	// contains filtered or unexported fields

func NewButtonComponent

func NewButtonComponent(x, y, w, h int32, text string, backgroundColor sdl.Color, buttonColor sdl.Color, textColor sdl.Color, onAction OnActionFunc) *ButtonComponent

func (*ButtonComponent) Draw

func (c *ButtonComponent) Draw(r *sdl.Renderer) error

func (*ButtonComponent) DrawComponent

func (c *ButtonComponent) DrawComponent(r *sdl.Renderer) error

func (*ButtonComponent) KeyEvent

func (c *ButtonComponent) KeyEvent(event *sdl.KeyboardEvent) bool

func (*ButtonComponent) MouseButtonEvent

func (c *ButtonComponent) MouseButtonEvent(event *sdl.MouseButtonEvent) bool

type Component

type Component interface {

	Position() (int32, int32)
	Size() (int32, int32)

	GetChildren() []Component

	Draw(r *sdl.Renderer) error
	DrawComponent(r *sdl.Renderer) error

	KeyEvent(event *sdl.KeyboardEvent) bool
	MouseButtonEvent(event *sdl.MouseButtonEvent) bool
	BaseMouseButtonEvent(event *sdl.MouseButtonEvent) bool

	IsPointInComponent(x, y int32) bool

	IsVisible() bool
	SetVisible(visible bool)

Component is the base interface for all components in this system

type LabelComponent

type LabelComponent struct {
	// contains filtered or unexported fields

func NewLabelComponent

func NewLabelComponent(x, y, width, height int32, fontSize int, labelTextFunc LabelTextFunc) *LabelComponent

func NewLabelComponentWithConfig

func NewLabelComponentWithConfig(x, y, width, height int32, labelTextFunc LabelTextFunc, labelConfig LabelConfig) *LabelComponent

func (*LabelComponent) Draw

func (c *LabelComponent) Draw(r *sdl.Renderer) error

func (*LabelComponent) DrawComponent

func (c *LabelComponent) DrawComponent(r *sdl.Renderer) error

type LabelConfig

type LabelConfig struct {
	FontName string    `default:"TruenoLight"`
	FontFile string    `default:"built-in-fonts/TruenoLight.otf"`
	FontSize int       `default:"24"`
	Justify  int       `default:"0" `
	Color    sdl.Color `default:"{\"R\": 50, \"G\": 255, \"B\": 50, \"A\": 255}"`

func NewLabelConfig

func NewLabelConfig() LabelConfig

type LabelTextFunc

type LabelTextFunc func() string

type OnActionFunc

type OnActionFunc func()

type Page

type Page interface {

	GetName() string
	PageLoad() error
	PageUnload() error
	SetData(data interface{})
	GetData() interface{}

	Quit() bool
var ActivePage Page

func GetPage

func GetPage(name string) Page

type RectangleComponent

type RectangleComponent struct {

	Background sdl.Color

func NewRectangleComponent

func NewRectangleComponent(x, y, width, height int32, background sdl.Color) *RectangleComponent

func (*RectangleComponent) Draw

func (c *RectangleComponent) Draw(r *sdl.Renderer) error

func (*RectangleComponent) DrawComponent

func (c *RectangleComponent) DrawComponent(r *sdl.Renderer) error

type Window

type Window struct {
	Width   int32
	Height  int32
	Title   string
	Scaling float32

	Background sdl.Color
	// contains filtered or unexported fields

Window represents the main object to display text output

var MainWindow Window

func NewWindow

func NewWindow(width, height int32, title string, background sdl.Color) *Window

NewWindow creates a new Window object

func (*Window) CleanUp

func (s *Window) CleanUp()

CleanUp cleans up all the resources creates by the Window object

func (*Window) DrawScreen

func (s *Window) DrawScreen() error

DrawScreen draws the active page

func (*Window) Show

func (s *Window) Show() error

Show initializes the main Window and shows it

Jump to

Keyboard shortcuts

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