windows

package
v0.0.0-...-48f6ed3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2017 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateUninited   = iota
	StateInited     = iota
	StateRunning    = iota
	StatePaused     = iota
	StateTerminated = iota
)

states

Variables

View Source
var MainWindow = newWindow(800, 600)

MainWindow is _the_ window

Functions

func AddOverlay

func AddOverlay(id string, scene Scene)

AddOverlay adds an overlay

func AddScene

func AddScene(id string, scene Scene)

AddScene adds a scene

func Exit

func Exit()

Exit the mainloop

func GetSize

func GetSize() (int, int)

GetSize returns the window size

func Init

func Init()

Init Creates the window and initializes the graphics thread

func MainLoop

func MainLoop()

MainLoop initializes its scenes and then enters the loop that runs the game. It directs input events to the current scene and any overlays and renders them. When the loop ends, the scenes are terminated

func SetCurrentScene

func SetCurrentScene(id string)

SetCurrentScene sets the current scene

Types

type BasicSceneImpl

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

BasicSceneImpl is a partial Scene implementation that implements shared basic fields and functionality You still need to implement the following functions yourself: Init() HandleInput(key_events []KeyboardInputEvent, mouse_events []MouseInputEvent) WindowAction Tick(timedelta float64, key_states []bool)

func (*BasicSceneImpl) IsFocused

func (s *BasicSceneImpl) IsFocused() bool

IsFocused ...

func (*BasicSceneImpl) IsInited

func (s *BasicSceneImpl) IsInited() bool

IsInited ...

func (*BasicSceneImpl) IsPaused

func (s *BasicSceneImpl) IsPaused() bool

IsPaused ...

func (*BasicSceneImpl) IsRunning

func (s *BasicSceneImpl) IsRunning() bool

IsRunning ...

func (*BasicSceneImpl) IsTerminated

func (s *BasicSceneImpl) IsTerminated() bool

IsTerminated ...

func (*BasicSceneImpl) SetFocused

func (s *BasicSceneImpl) SetFocused(focused bool)

SetFocused ...

func (*BasicSceneImpl) SetState

func (s *BasicSceneImpl) SetState(state int)

SetState sets state

type KeyboardInputEvent

type KeyboardInputEvent struct {
	Key      glfw.Key
	Scancode int
	Action   glfw.Action
	Mod      glfw.ModifierKey
}

KeyboardInputEvent represents a glfw keyboard event

type MouseInputEvent

type MouseInputEvent struct {
	Button glfw.MouseButton
	Action glfw.Action
	Mod    glfw.ModifierKey
	X, Y   float32
}

MouseInputEvent represents a glfw mouse event

type Scene

type Scene interface {

	// Returns true if the Scene cares about input
	AcceptsInput() bool

	// Processes input events
	HandleInput(keyEvents []KeyboardInputEvent, mouseEvents []MouseInputEvent) WindowAction

	// Update the game frame and process time-dependant input
	Tick(timedelta float64, keyStates []bool)

	// Some scenes might want to ignore input or pause if they aren't focused
	SetFocused(isFocused bool)
	IsFocused() bool

	// Init the scene
	Init()
	// Returns true unless the scene is in state STATE_UNINITED or STATE_TERMINATED
	IsInited() bool

	// Set the scene in running mode
	Run()
	// Returns true if the scene is in state STATE_RUNNING
	IsRunning() bool

	// Pause the scene
	Pause()
	// Returns true if the scene is in state STATE_PAUSED
	IsPaused() bool

	Exit()
	// returns true if this scene is in STATE_TERMINATED.
	IsTerminated() bool
}

Scene are responsible for handling input and rendering their content. They can be in the following states: 1. Uninited - only bare minimum setup at this point 2. Inited - resources should be allocated 3. Running - Running normally 4. Paused - Paused, can be resumed to return to the Running state 5. Terminated - all resources should be released

type SimpleSceneImpl

type SimpleSceneImpl struct {
	BasicSceneImpl
}

SimpleSceneImpl is a simple scene implementation to use when you want default state transitions and input

func (*SimpleSceneImpl) AcceptsInput

func (s *SimpleSceneImpl) AcceptsInput() bool

AcceptsInput true

func (*SimpleSceneImpl) Exit

func (s *SimpleSceneImpl) Exit()

Exit terminates the scene

func (*SimpleSceneImpl) Pause

func (s *SimpleSceneImpl) Pause()

Pause pauses the scene

func (*SimpleSceneImpl) Run

func (s *SimpleSceneImpl) Run()

Run checks that the scene is inited and sets the state to running

type Window

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

Window is an actual window in the OS.

type WindowAction

type WindowAction int

WindowAction is something the window should do

const (
	WindowActionNone WindowAction = iota
	WindowActionExit              = iota
)

Window actions

Jump to

Keyboard shortcuts

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