gui

package
v0.0.0-...-07d2fe9 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2014 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gui provides a text/graphical rendering system for tile-based games.

Index

Constants

View Source
const (
	ColorBlack   = Color(termbox.ColorBlack)
	ColorBlue    = Color(termbox.ColorBlue)
	ColorCyan    = Color(termbox.ColorCyan)
	ColorGreen   = Color(termbox.ColorGreen)
	ColorMagenta = Color(termbox.ColorMagenta)
	ColorRed     = Color(termbox.ColorRed)
	ColorWhite   = Color(termbox.ColorWhite)
	ColorYellow  = Color(termbox.ColorYellow)

	ColorBrightBlack   = Color(termbox.ColorBlack | termbox.AttrBold)
	ColorBrightBlue    = Color(termbox.ColorBlue | termbox.AttrBold)
	ColorBrightCyan    = Color(termbox.ColorCyan | termbox.AttrBold)
	ColorBrightGreen   = Color(termbox.ColorGreen | termbox.AttrBold)
	ColorBrightMagenta = Color(termbox.ColorMagenta | termbox.AttrBold)
	ColorBrightRed     = Color(termbox.ColorRed | termbox.AttrBold)
	ColorBrightWhite   = Color(termbox.ColorWhite | termbox.AttrBold)
	ColorBrightYellow  = Color(termbox.ColorYellow | termbox.AttrBold)
)

Variables

This section is empty.

Functions

func Exit

func Exit()

Exit tells the program to exit, then returns immediately. Main will return at some point in the future. Calling Exit twice panics.

func Main

func Main(title string, handler Interface) (err error)

Main runs the gui. It must be called from the main function, not from a goroutine. Main will not return until the gui exits with an error or Exit is called.

func Redraw

func Redraw()

Redraw returns immediately. Some time later, the gui will redraw itself. It is not required to call Redraw after an input event (Mouse, Rune, or Key).

Types

type Color

type Color termbox.Attribute

type Interface

type Interface interface {
	// SpriteSize returns the width and height of each tile.
	SpriteSize() (w, h int)

	// PreRender is called with the width and height in tiles of the screen before
	// SpriteAt is called during a frame.
	PreRender(w, h int)

	// SpriteAt returns the Sprite at (x, y) on the screen.
	SpriteAt(x, y, w, h int) *Sprite

	// Mouse is called when the user left clicks on the screen.
	Mouse(x, y, w, h int)

	// Rune is called when a character is entered on the keyboard. Return false if
	// the OS should handle the key event instead.
	Rune(r rune) (handled bool)

	// Key is called when a special key is pressed on the keyboard. Return false if
	// the OS should handle the key event instead. The default action for Escape is
	// to exit the program.
	Key(k Key) (handled bool)

	// Closing is called before the user exits the program. Return false to cancel.
	Closing() (allow bool)
}

Interface is the set of methods that are called by gui.

Methods with x, y, w, h parameters fulful x ∈ [0, w) ∧ y ∈ [0, h).

type Key

type Key uint
const (
	F1 Key
	F2
	F3
	F4
	F5
	F6
	F7
	F8
	F9
	F10
	F11
	F12

	Up
	Down
	Left
	Right

	Escape
	Backspace
	Insert
	Delete
	Home
	End
)

type Sprite

type Sprite struct {
	Images []image.Image
	Rune   rune
	Fg, Bg Color
}

Jump to

Keyboard shortcuts

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