ui

package
v0.0.0-...-8b39f33 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unknown Button = iota
	Left           = 1 << iota
	Right
	Up
	Down
	Action
	Menu
	Hands
)
View Source
const FrameMsec = 16 * time.Millisecond

Variables

View Source
var (
	// CurrentKeymap is the current keymap used to translate
	// key code into Buttons.
	CurrentKeymap = DefaultKeymap

	DefaultKeymap = map[KeyCode]Button{
		KeyCode(C.SDLK_s): Left,
		KeyCode(C.SDLK_f): Right,
		KeyCode(C.SDLK_e): Up,
		KeyCode(C.SDLK_d): Down,
		KeyCode(C.SDLK_j): Action,
		KeyCode(C.SDLK_k): Menu,
		KeyCode(C.SDLK_h): Hands,
	}

	DvorakKeymap = map[KeyCode]Button{
		KeyCode(C.SDLK_o):      Left,
		KeyCode(C.SDLK_u):      Right,
		KeyCode(C.SDLK_PERIOD): Up,
		KeyCode(C.SDLK_e):      Down,
		KeyCode(C.SDLK_h):      Action,
		KeyCode(C.SDLK_t):      Menu,
		KeyCode(C.SDLK_d):      Hands,
	}
)
View Source
var ButtonNames = map[Button]string{
	Unknown: "Unknown",
	Left:    "Left",
	Right:   "Right",
	Up:      "Up",
	Down:    "Down",
	Action:  "Action",
	Menu:    "Menu",
	Hands:   "Hands",
}

Functions

This section is empty.

Types

type Button

type Button int

func (Button) String

func (b Button) String() string

type Camera

type Camera struct {
	Torus geom.Torus
	Pt    geom.Point
	Dims  geom.Point
}

func (*Camera) Center

func (c *Camera) Center(v geom.Point)

func (*Camera) Draw

func (c *Camera) Draw(d Drawer, s Sprite, p geom.Point) geom.Point

func (*Camera) Move

func (c *Camera) Move(v geom.Point)

type Drawer

type Drawer interface {
	Draw(interface{}, geom.Point) geom.Point
	SetFont(name string, szPts float64)
	SetColor(color.Color)
	TextSize(string) geom.Point
}

A Drawer can draw things and change colors.

type Event

type Event interface{}

type Finder

type Finder interface {
	Find(string) string
}

The Finder's Find method takes a filename of a resource and returns the full path to it.

type Key

type Key struct {
	Down   bool
	Button Button
	Code   KeyCode
}

type KeyCode

type KeyCode C.SDL_Keycode

func (KeyCode) String

func (k KeyCode) String() string

type Quit

type Quit struct{}

type Screen

type Screen interface {
	// Draw should send draw commands via the given Writer.
	Draw(Drawer)

	// Handle is called for each event coming from the
	// Ui, with the exception of the Close event which is
	// intercepted by the ScreenStack to exit the program.
	Handle(*ScreenStack, Event) error

	// Update is called after all of the events are handled and after
	// the next frame is drawn in order to allow the screen to update
	// its state based on the events.
	Update(*ScreenStack) error

	// Transparent returns true iff the screen doesn't fill the window.
	Transparent() bool
}

A Screen represents some game screen. E.g. the title, the main gameplay, etc.

type ScreenStack

type ScreenStack struct {
	NFrames   uint
	MeanFrame float64 // milliseconds

	// Buttons is a bit set of the currently pressed buttons.
	Buttons Button
	// contains filtered or unexported fields
}

A ScreenStack holds the stack of game screens.

func NewScreenStack

func NewScreenStack(win *Ui, first Screen) *ScreenStack

NewScreenStack returns a new screen stack with the given initial screen.

func (*ScreenStack) Pop

func (s *ScreenStack) Pop()

Pop pops the current screen off of the top of the stack.

func (*ScreenStack) Push

func (s *ScreenStack) Push(screen Screen)

Push pushes a new screen onto the top of the stack.

func (*ScreenStack) Run

func (s *ScreenStack) Run()

Run runs the main loop of the program, calling the Draw(), Handle(), then Update() methods on the top screen on the stack.

type Sprite

type Sprite struct {
	Name   string
	Bounds geom.Rectangle
	Shade  float32
}

Sprite represents an image, the portion of the image to be rendered, and its shading.

type Ui

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

func New

func New(title string, w, h int, f Finder, vsync bool) (*Ui, error)

func (*Ui) Clear

func (ui *Ui) Clear()

func (*Ui) Close

func (ui *Ui) Close()

func (*Ui) Draw

func (ui *Ui) Draw(i interface{}, p geom.Point) geom.Point

Draw queues a rendering of x and returns the dimensions of what will be rendered, or an error. Draw supports the following types:

string
	The given string is drawn at p in the current font, in the
	current color.

geom.Rectangle
	The given rectangle is filled at offset p, in the current color.

Sprite
	The given image is drawn at offset p.

image.Image
	The given image is drawn at offset p.

func (*Ui) PollEvent

func (ui *Ui) PollEvent() Event

func (*Ui) SetColor

func (ui *Ui) SetColor(col color.Color)

SetColor sets the current drawing color.

func (*Ui) SetFont

func (ui *Ui) SetFont(name string, sz float64)

SetFont sets the current font face and size.

func (*Ui) Sync

func (ui *Ui) Sync() error

func (*Ui) TextSize

func (ui *Ui) TextSize(txt string) geom.Point

TextSize returns the size of the text when rendered in the current font.

Notes

Bugs

  • asRgba assumes the image bounds starts at (0,0).

  • barf

Jump to

Keyboard shortcuts

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