tigo

package module
v0.0.0-...-a82c731 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: MIT Imports: 3 Imported by: 0

README

TIGO

TIGO is a Go binding for TIGR, a tiny graphics library.

TIGO is still working in progress, and has been tested only on macOS. More features and better support for other platforms will be comming soon.

Installation

$ go get github.com/beta/tigo

Example

Below is a basic example of creating window and drawing text with TIGO.

package main

import "github.com/beta/tigo"

func main() {
	win := tigo.NewWindow(320, 240, "Hello TIGO", tigo.WindowAuto)
	for !win.Closed() {
		win.Clear(tigo.RGB(0x80, 0x90, 0xa0))
		win.Print(tigo.DefaultFont(), 120, 110, tigo.RGB(0xff, 0xff, 0xff), "Hello TIGO")
		win.Update()
	}
	win.Free()
}

More examples can be found in the example directory.

License

MIT

Documentation

Overview

Package tigo implements the interface for TIGO.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveImage

func SaveImage(fileName string, bmp *Bitmap) error

SaveImage saves a PNG to a file. fileName is UTF-8.

Types

type Bitmap

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

Bitmap represents a bitmap.

func LoadImage

func LoadImage(fileName string) (*Bitmap, error)

LoadImage loads a PNG, from either a file. fileName is UTF-8.

func NewBitmap

func NewBitmap(width, height int) *Bitmap

NewBitmap creates an empty off-screen bitmap.

func NewWindow

func NewWindow(width, height int, title string, flags WindowFlag) *Bitmap

NewWindow creates a new empty window. title is UTF-8.

func (*Bitmap) Blit

func (bmp *Bitmap) Blit(sx, sy int, dest *Bitmap, dx, dy, w, h int)

Blit copies bitmap data from bmp to dest. sx/sy = source coordinates. dx/dy = dest coordinates. w/h: width/height.

func (*Bitmap) BlitAlpha

func (bmp *Bitmap) BlitAlpha(sx, sy int, dest *Bitmap, dx, dy, w, h int, alpha float32)

BlitAlpha is same as Blit, but blends with the bitmap alpha channel, and uses the 'alpha' variable to fade out.

func (*Bitmap) BlitTint

func (bmp *Bitmap) BlitTint(sx, sy int, dest *Bitmap, dx, dy, w, h int, tint Pixel)

BlitTint is same as Blit, but tints the source bitmap with a color.

func (*Bitmap) Clear

func (bmp *Bitmap) Clear(color Pixel)

Clear clears a bitmap to a color.

func (*Bitmap) Closed

func (bmp *Bitmap) Closed() bool

Closed returns true if the user requested to close a window.

func (*Bitmap) Fill

func (bmp *Bitmap) Fill(x, y, w, h int, color Pixel)

Fill fills in a solid rectangle.

func (*Bitmap) Free

func (bmp *Bitmap) Free()

Free deletes a window/bitmap.

func (*Bitmap) Get

func (bmp *Bitmap) Get(x, y int) Pixel

Get gets a pixel from bitmap.

func (*Bitmap) KeyDown

func (bmp *Bitmap) KeyDown(key Key) bool

KeyDown returns true if a key is pressed for a window. KeyDown only tests for the initial press.

func (*Bitmap) KeyHeld

func (bmp *Bitmap) KeyHeld(key Key) bool

KeyHeld returns true if a key is held for a window. KeyHeld repreats each frame.

func (*Bitmap) Line

func (bmp *Bitmap) Line(x0, y0, x1, y1 int, color Pixel)

Line draws a line.

func (*Bitmap) Mouse

func (bmp *Bitmap) Mouse() (x, y, buttons int)

Mouse returns mouse input for a window.

func (*Bitmap) Plot

func (bmp *Bitmap) Plot(x, y int, p Pixel)

Plot sets a pixel onto bitmap.

func (*Bitmap) Print

func (bmp *Bitmap) Print(font *Font, x, y int, color Pixel, text string)

Print prints UTF-8 text onto a bitmap.

func (*Bitmap) ReadChar

func (bmp *Bitmap) ReadChar() int

ReadChar reads character input for a window and returns the Unicode value of the last key pressed. If no key is pressed, ReadChar returns 0.

func (*Bitmap) Rect

func (bmp *Bitmap) Rect(x, y, w, h int, color Pixel)

Rect draws an empty rectangle (exclusive coords).

func (*Bitmap) SetPostFX

func (bmp *Bitmap) SetPostFX(hBlur, vBlur bool, scanlines, contrast float32)

SetPostFX sets post-FX properties for a window. hBlur/vBlur = whether to use bilinear filtering along that axis. scanlines = CRT scanlines effect (0-1). contrast = contrast boost (1 = no change, 2 = 2X contrast, etc)

func (*Bitmap) Update

func (bmp *Bitmap) Update()

Update displays a window's content onto screen.

type Codepage

type Codepage int

Codepage is a number representing a codepage.

const (
	// ASCII represents regular 7-bit ASCII codepage.
	ASCII Codepage = 0
	// Windows1252 represents Windows 1252 codepage.
	Windows1252 Codepage = 1252
)

Codepages.

type Font

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

Font represents a font consisting of glyphs.

func DefaultFont

func DefaultFont() *Font

DefaultFont returns the default built-in font.

func LoadFont

func LoadFont(bmp *Bitmap, codepage Codepage) *Font

LoadFont loads a font. The font bitmap should contain all characters for the given codepage, excluding the first 32 control codes. Supported codepages:

0    - Regular 7-bit ASCII
1252 - Windows 1252

func (*Font) TextHeight

func (font *Font) TextHeight(text string) int

TextHeight returns the height of a string.

func (*Font) TextWidth

func (font *Font) TextWidth(text string) int

TextWidth returns the width of a string.

type Glyph

type Glyph struct {
	Code int
	X    int
	Y    int
	W    int
	H    int
}

Glyph represents a glyph.

type Key

type Key int

Key represents a key scancode. ASCII ('A'-'Z' and '0'-'9') is used for letters/numbers.

const (
	Pad0 Key = 128 + iota
	Pad1
	Pad2
	Pad3
	Pad4
	Pad5
	Pad6
	Pad7
	Pad8
	Pad9
	PadMul
	PadAdd
	PadEnter
	PadSub
	PadDot
	PadDiv
	F1
	F2
	F3
	F4
	F5
	F6
	F7
	F8
	F9
	F10
	F11
	F12
	Backspace
	Tab
	Return
	Shift
	Control
	Alt
	Pause
	CapsLock
	Escape
	Space
	PageUp
	PageDown
	End
	Home
	Left
	Up
	Right
	Down
	Insert
	Delete
	LWin
	RWin
	NumLock
	ScrollLock
	LShift
	RShift
	LControl
	RControl
	LAlt
	RAlt
	SemiColon
	Equals
	Comma
	Minus
	Dot
	Slash
	BackTick
	LSquare
	BackSlash
	RSquare
	Tick
)

Key scancode constants.

type Pixel

type Pixel struct {
	B uint8
	G uint8
	R uint8
	A uint8
}

Pixel represents one pixel.

func RGB

func RGB(r, g, b uint8) Pixel

RGB is a helper function for making colors.

func RGBA

func RGBA(r, g, b, a uint8) Pixel

RGBA is a helper function for making colors with alpha value.

type WindowFlag

type WindowFlag int

WindowFlag reprensets a flag for window sizing mode.

const (
	// WindowFixed means a window's bitmap has a fixed size.
	WindowFixed WindowFlag = 1 << iota
	// WindowAuto means a window's bitmap will automatically resize after each Update.
	WindowAuto
	// Window2X enforces (at least) 2X pixel scale.
	Window2X
	// Window3X enforces (at least) 3X pixel scale.
	Window3X
	// Window4X enforces (at least) 4X pixel scale.
	Window4X
	// WindowRetina enables retina support on macOS.
	WindowRetina
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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