strife Build Status

A simple game framework that wraps around SDL2.


The largest example use of the Strife framework is the Phi text editor, a text editor written entirely from scratch with syntax highlighting, a command palette, multiple buffer support, etc.

Though there are some smaller examples demonstrating components of the Strife API in the examples/ folder.


This is a work in progress. It provides a very minimal toolset for rendering shapes, images, and text as well as capturing user input. This is not at a production level and is mostly being worked on when the needs of my other projects (that depend on this) evolve.

There is no documentation either! If you want to use it you will have to check out the examples. I may get round to writing some documentation but the API is very volatile at the moment.


Simple as

$ go get

Make sure you have SDL2 installed as well as the ttf and img addons:

$ brew install SDL2 SDL2_ttf SDL2_img

getting started

This is a commented code snippet to help you get started:

func main() {
	// create a nice shiny window
	window := strife.SetupRenderWindow(1280, 720, strife.DefaultConfig())
	window.SetTitle("Hello world!")

	// this is our event handler
	window.HandleEvents(func(evt strife.StrifeEvent) {
		switch event := evt.(type) {
		case *strife.CloseEvent:
			println("closing window!")
		case *strife.WindowResizeEvent:
			println("resize to ", event.Width, "x", event.Height)

	// game loop
	for {
		// handle the events before we do any
		// rendering etc.

		// if we have a window close event
		// from the previous poll, break out of
		// our game loop
		if window.CloseRequested() {

		// rendering context stuff here
		// clear and display is typical
		// all your rendering code should
		// go...
		ctx := window.GetRenderContext()
			// this section here
			ctx.Rect(10, 10, 50, 50, strife.Fill)

			// check out some other examples!






View Source
const (
	// mapping to sdl.K_UNKNOWN
	UNKNOWN = sdl.K_UNKNOWN // "" (no name, empty string)

	KEY_RETURN     = sdl.K_RETURN     // "Return" (the Enter key (main keyboard))
	KEY_ESCAPE     = sdl.K_ESCAPE     // "Escape" (the Esc key)
	KEY_BACKSPACE  = sdl.K_BACKSPACE  // "Backspace"
	KEY_TAB        = sdl.K_TAB        // "Tab" (the Tab key)
	KEY_SPACE      = sdl.K_SPACE      // "Space" (the Space Bar key(s))
	KEY_EXCLAIM    = sdl.K_EXCLAIM    // "!"
	KEY_QUOTEDBL   = sdl.K_QUOTEDBL   // """
	KEY_HASH       = sdl.K_HASH       // "#"
	KEY_PERCENT    = sdl.K_PERCENT    // "%"
	KEY_DOLLAR     = sdl.K_DOLLAR     // "$"
	KEY_QUOTE      = sdl.K_QUOTE      // "'"
	KEY_ASTERISK   = sdl.K_ASTERISK   // "*"
	KEY_PLUS       = sdl.K_PLUS       // "+"
	KEY_COMMA      = sdl.K_COMMA      // ","
	KEY_MINUS      = sdl.K_MINUS      // "-"
	KEY_PERIOD     = sdl.K_PERIOD     // "."
	KEY_SLASH      = sdl.K_SLASH      // "/"
	KEY_0          = sdl.K_0          // "0"
	KEY_1          = sdl.K_1          // "1"
	KEY_2          = sdl.K_2          // "2"
	KEY_3          = sdl.K_3          // "3"
	KEY_4          = sdl.K_4          // "4"
	KEY_5          = sdl.K_5          // "5"
	KEY_6          = sdl.K_6          // "6"
	KEY_7          = sdl.K_7          // "7"
	KEY_8          = sdl.K_8          // "8"
	KEY_9          = sdl.K_9          // "9"
	KEY_COLON      = sdl.K_COLON      // ":"
	KEY_LESS       = sdl.K_LESS       // "<"
	KEY_EQUALS     = sdl.K_EQUALS     // "="
	KEY_GREATER    = sdl.K_GREATER    // ">"
	KEY_QUESTION   = sdl.K_QUESTION   // "?"
	KEY_AT         = sdl.K_AT         // "@"

	KEY_BACKSLASH    = sdl.K_BACKSLASH    // "\"
	KEY_CARET        = sdl.K_CARET        // "^"
	KEY_BACKQUOTE    = sdl.K_BACKQUOTE    // "`"
	KEY_A            = sdl.K_a            // "A"
	KEY_B            = sdl.K_b            // "B"
	KEY_C            = sdl.K_c            // "C"
	KEY_D            = sdl.K_d            // "D"
	KEY_E            = sdl.K_e            // "E"
	KEY_F            = sdl.K_f            // "F"
	KEY_G            = sdl.K_g            // "G"
	KEY_H            = sdl.K_h            // "H"
	KEY_I            = sdl.K_i            // "I"
	KEY_J            = sdl.K_j            // "J"
	KEY_K            = sdl.K_k            // "K"
	KEY_L            = sdl.K_l            // "L"
	KEY_M            = sdl.K_m            // "M"
	KEY_N            = sdl.K_n            // "N"
	KEY_O            = sdl.K_o            // "O"
	KEY_P            = sdl.K_p            // "P"
	KEY_Q            = sdl.K_q            // "Q"
	KEY_R            = sdl.K_r            // "R"
	KEY_S            = sdl.K_s            // "S"
	KEY_T            = sdl.K_t            // "T"
	KEY_U            = sdl.K_u            // "U"
	KEY_V            = sdl.K_v            // "V"
	KEY_W            = sdl.K_w            // "W"
	KEY_X            = sdl.K_x            // "X"
	KEY_Y            = sdl.K_y            // "Y"
	KEY_Z            = sdl.K_z            // "Z"

	KEY_CAPSLOCK = sdl.K_CAPSLOCK // "CapsLock"

	KEY_F1  = sdl.K_F1  // "F1"
	KEY_F2  = sdl.K_F2  // "F2"
	KEY_F3  = sdl.K_F3  // "F3"
	KEY_F4  = sdl.K_F4  // "F4"
	KEY_F5  = sdl.K_F5  // "F5"
	KEY_F6  = sdl.K_F6  // "F6"
	KEY_F7  = sdl.K_F7  // "F7"
	KEY_F8  = sdl.K_F8  // "F8"
	KEY_F9  = sdl.K_F9  // "F9"
	KEY_F10 = sdl.K_F10 // "F10"
	KEY_F11 = sdl.K_F11 // "F11"
	KEY_F12 = sdl.K_F12 // "F12"

	KEY_SCROLLLOCK  = sdl.K_SCROLLLOCK  // "ScrollLock"
	KEY_PAUSE       = sdl.K_PAUSE       // "Pause" (the Pause / Break key)
	KEY_INSERT      = sdl.K_INSERT      // "Insert" (insert on PC, help on some Mac keyboards (but does send code 73, not 117))
	KEY_HOME        = sdl.K_HOME        // "Home"
	KEY_PAGEUP      = sdl.K_PAGEUP      // "PageUp"
	KEY_DELETE      = sdl.K_DELETE      // "Delete"
	KEY_END         = sdl.K_END         // "End"
	KEY_PAGEDOWN    = sdl.K_PAGEDOWN    // "PageDown"
	KEY_RIGHT       = sdl.K_RIGHT       // "Right" (the Right arrow key (navigation keypad))
	KEY_LEFT        = sdl.K_LEFT        // "Left" (the Left arrow key (navigation keypad))
	KEY_DOWN        = sdl.K_DOWN        // "Down" (the Down arrow key (navigation keypad))
	KEY_UP          = sdl.K_UP          // "Up" (the Up arrow key (navigation keypad))

	KEY_NUMLOCKCLEAR = sdl.K_NUMLOCKCLEAR // "Numlock" (the Num Lock key (PC) / the Clear key (Mac))
	KEY_KP_DIVIDE    = sdl.K_KP_DIVIDE    // "Keypad /" (the / key (numeric keypad))
	KEY_KP_MULTIPLY  = sdl.K_KP_MULTIPLY  // "Keypad *" (the * key (numeric keypad))
	KEY_KP_MINUS     = sdl.K_KP_MINUS     // "Keypad -" (the - key (numeric keypad))
	KEY_KP_PLUS      = sdl.K_KP_PLUS      // "Keypad +" (the + key (numeric keypad))
	KEY_KP_ENTER     = sdl.K_KP_ENTER     // "Keypad Enter" (the Enter key (numeric keypad))
	KEY_KP_1         = sdl.K_KP_1         // "Keypad 1" (the 1 key (numeric keypad))
	KEY_KP_2         = sdl.K_KP_2         // "Keypad 2" (the 2 key (numeric keypad))
	KEY_KP_3         = sdl.K_KP_3         // "Keypad 3" (the 3 key (numeric keypad))
	KEY_KP_4         = sdl.K_KP_4         // "Keypad 4" (the 4 key (numeric keypad))
	KEY_KP_5         = sdl.K_KP_5         // "Keypad 5" (the 5 key (numeric keypad))
	KEY_KP_6         = sdl.K_KP_6         // "Keypad 6" (the 6 key (numeric keypad))
	KEY_KP_7         = sdl.K_KP_7         // "Keypad 7" (the 7 key (numeric keypad))
	KEY_KP_8         = sdl.K_KP_8         // "Keypad 8" (the 8 key (numeric keypad))
	KEY_KP_9         = sdl.K_KP_9         // "Keypad 9" (the 9 key (numeric keypad))
	KEY_KP_0         = sdl.K_KP_0         // "Keypad 0" (the 0 key (numeric keypad))
	KEY_KP_PERIOD    = sdl.K_KP_PERIOD    // "Keypad ." (the . key (numeric keypad))

	KEY_APPLICATION    = sdl.K_APPLICATION    // "Application" (the Application / Compose / Context Menu (Windows) key)
	KEY_POWER          = sdl.K_POWER          // "Power" (The USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key.)
	KEY_KP_EQUALS      = sdl.K_KP_EQUALS      // "Keypad =" (the = key (numeric keypad))
	KEY_F13            = sdl.K_F13            // "F13"
	KEY_F14            = sdl.K_F14            // "F14"
	KEY_F15            = sdl.K_F15            // "F15"
	KEY_F16            = sdl.K_F16            // "F16"
	KEY_F17            = sdl.K_F17            // "F17"
	KEY_F18            = sdl.K_F18            // "F18"
	KEY_F19            = sdl.K_F19            // "F19"
	KEY_F20            = sdl.K_F20            // "F20"
	KEY_F21            = sdl.K_F21            // "F21"
	KEY_F22            = sdl.K_F22            // "F22"
	KEY_F23            = sdl.K_F23            // "F23"
	KEY_F24            = sdl.K_F24            // "F24"
	KEY_EXECUTE        = sdl.K_EXECUTE        // "Execute"
	KEY_HELP           = sdl.K_HELP           // "Help"
	KEY_MENU           = sdl.K_MENU           // "Menu"
	KEY_SELECT         = sdl.K_SELECT         // "Select"
	KEY_STOP           = sdl.K_STOP           // "Stop"
	KEY_AGAIN          = sdl.K_AGAIN          // "Again" (the Again key (Redo))
	KEY_UNDO           = sdl.K_UNDO           // "Undo"
	KEY_CUT            = sdl.K_CUT            // "Cut"
	KEY_COPY           = sdl.K_COPY           // "Copy"
	KEY_PASTE          = sdl.K_PASTE          // "Paste"
	KEY_FIND           = sdl.K_FIND           // "Find"
	KEY_MUTE           = sdl.K_MUTE           // "Mute"
	KEY_VOLUMEUP       = sdl.K_VOLUMEUP       // "VolumeUp"
	KEY_VOLUMEDOWN     = sdl.K_VOLUMEDOWN     // "VolumeDown"
	KEY_KP_COMMA       = sdl.K_KP_COMMA       // "Keypad ," (the Comma key (numeric keypad))
	KEY_KP_EQUALSAS400 = sdl.K_KP_EQUALSAS400 // "Keypad = (AS400)" (the Equals AS400 key (numeric keypad))

	KEY_ALTERASE   = sdl.K_ALTERASE   // "AltErase" (Erase-Eaze)
	KEY_SYSREQ     = sdl.K_SYSREQ     // "SysReq" (the SysReq key)
	KEY_CANCEL     = sdl.K_CANCEL     // "Cancel"
	KEY_CLEAR      = sdl.K_CLEAR      // "Clear"
	KEY_PRIOR      = sdl.K_PRIOR      // "Prior"
	KEY_RETURN2    = sdl.K_RETURN2    // "Return"
	KEY_SEPARATOR  = sdl.K_SEPARATOR  // "Separator"
	KEY_OUT        = sdl.K_OUT        // "Out"
	KEY_OPER       = sdl.K_OPER       // "Oper"
	KEY_CLEARAGAIN = sdl.K_CLEARAGAIN // "Clear / Again"
	KEY_CRSEL      = sdl.K_CRSEL      // "CrSel"
	KEY_EXSEL      = sdl.K_EXSEL      // "ExSel"

	KEY_KP_00              = sdl.K_KP_00              // "Keypad 00" (the 00 key (numeric keypad))
	KEY_KP_000             = sdl.K_KP_000             // "Keypad 000" (the 000 key (numeric keypad))
	KEY_THOUSANDSSEPARATOR = sdl.K_THOUSANDSSEPARATOR // "ThousandsSeparator" (the Thousands Separator key)
	KEY_DECIMALSEPARATOR   = sdl.K_DECIMALSEPARATOR   // "DecimalSeparator" (the Decimal Separator key)
	KEY_CURRENCYUNIT       = sdl.K_CURRENCYUNIT       // "CurrencyUnit" (the Currency Unit key)
	KEY_CURRENCYSUBUNIT    = sdl.K_CURRENCYSUBUNIT    // "CurrencySubUnit" (the Currency Subunit key)
	KEY_KP_LEFTPAREN       = sdl.K_KP_LEFTPAREN       // "Keypad (" (the Left Parenthesis key (numeric keypad))
	KEY_KP_RIGHTPAREN      = sdl.K_KP_RIGHTPAREN      // "Keypad )" (the Right Parenthesis key (numeric keypad))
	KEY_KP_LEFTBRACE       = sdl.K_KP_LEFTBRACE       // "Keypad {" (the Left Brace key (numeric keypad))
	KEY_KP_RIGHTBRACE      = sdl.K_KP_RIGHTBRACE      // "Keypad }" (the Right Brace key (numeric keypad))
	KEY_KP_TAB             = sdl.K_KP_TAB             // "Keypad Tab" (the Tab key (numeric keypad))
	KEY_KP_BACKSPACE       = sdl.K_KP_BACKSPACE       // "Keypad Backspace" (the Backspace key (numeric keypad))
	KEY_KP_A               = sdl.K_KP_A               // "Keypad A" (the A key (numeric keypad))
	KEY_KP_B               = sdl.K_KP_B               // "Keypad B" (the B key (numeric keypad))
	KEY_KP_C               = sdl.K_KP_C               // "Keypad C" (the C key (numeric keypad))
	KEY_KP_D               = sdl.K_KP_D               // "Keypad D" (the D key (numeric keypad))
	KEY_KP_E               = sdl.K_KP_E               // "Keypad E" (the E key (numeric keypad))
	KEY_KP_F               = sdl.K_KP_F               // "Keypad F" (the F key (numeric keypad))
	KEY_KP_XOR             = sdl.K_KP_XOR             // "Keypad XOR" (the XOR key (numeric keypad))
	KEY_KP_POWER           = sdl.K_KP_POWER           // "Keypad ^" (the Power key (numeric keypad))
	KEY_KP_PERCENT         = sdl.K_KP_PERCENT         // "Keypad %" (the Percent key (numeric keypad))
	KEY_KP_LESS            = sdl.K_KP_LESS            // "Keypad <" (the Less key (numeric keypad))
	KEY_KP_GREATER         = sdl.K_KP_GREATER         // "Keypad >" (the Greater key (numeric keypad))
	KEY_KP_AMPERSAND       = sdl.K_KP_AMPERSAND       // "Keypad &" (the & key (numeric keypad))
	KEY_KP_DBLAMPERSAND    = sdl.K_KP_DBLAMPERSAND    // "Keypad &&" (the && key (numeric keypad))
	KEY_KP_VERTICALBAR     = sdl.K_KP_VERTICALBAR     // "Keypad |" (the | key (numeric keypad))
	KEY_KP_DBLVERTICALBAR  = sdl.K_KP_DBLVERTICALBAR  // "Keypad ||" (the || key (numeric keypad))
	KEY_KP_COLON           = sdl.K_KP_COLON           // "Keypad :" (the : key (numeric keypad))
	KEY_KP_HASH            = sdl.K_KP_HASH            // "Keypad #" (the # key (numeric keypad))
	KEY_KP_SPACE           = sdl.K_KP_SPACE           // "Keypad Space" (the Space key (numeric keypad))
	KEY_KP_AT              = sdl.K_KP_AT              // "Keypad @" (the @ key (numeric keypad))
	KEY_KP_EXCLAM          = sdl.K_KP_EXCLAM          // "Keypad !" (the ! key (numeric keypad))
	KEY_KP_MEMSTORE        = sdl.K_KP_MEMSTORE        // "Keypad MemStore" (the Mem Store key (numeric keypad))
	KEY_KP_MEMRECALL       = sdl.K_KP_MEMRECALL       // "Keypad MemRecall" (the Mem Recall key (numeric keypad))
	KEY_KP_MEMCLEAR        = sdl.K_KP_MEMCLEAR        // "Keypad MemClear" (the Mem Clear key (numeric keypad))
	KEY_KP_MEMADD          = sdl.K_KP_MEMADD          // "Keypad MemAdd" (the Mem Add key (numeric keypad))
	KEY_KP_MEMSUBTRACT     = sdl.K_KP_MEMSUBTRACT     // "Keypad MemSubtract" (the Mem Subtract key (numeric keypad))
	KEY_KP_MEMMULTIPLY     = sdl.K_KP_MEMMULTIPLY     // "Keypad MemMultiply" (the Mem Multiply key (numeric keypad))
	KEY_KP_MEMDIVIDE       = sdl.K_KP_MEMDIVIDE       // "Keypad MemDivide" (the Mem Divide key (numeric keypad))
	KEY_KP_PLUSMINUS       = sdl.K_KP_PLUSMINUS       // "Keypad +/-" (the +/- key (numeric keypad))
	KEY_KP_CLEAR           = sdl.K_KP_CLEAR           // "Keypad Clear" (the Clear key (numeric keypad))
	KEY_KP_CLEARENTRY      = sdl.K_KP_CLEARENTRY      // "Keypad ClearEntry" (the Clear Entry key (numeric keypad))
	KEY_KP_BINARY          = sdl.K_KP_BINARY          // "Keypad Binary" (the Binary key (numeric keypad))
	KEY_KP_OCTAL           = sdl.K_KP_OCTAL           // "Keypad Octal" (the Octal key (numeric keypad))
	KEY_KP_DECIMAL         = sdl.K_KP_DECIMAL         // "Keypad Decimal" (the Decimal key (numeric keypad))
	KEY_KP_HEXADECIMAL     = sdl.K_KP_HEXADECIMAL     // "Keypad Hexadecimal" (the Hexadecimal key (numeric keypad))

	KEY_LCTRL  = sdl.K_LCTRL  // "Left Ctrl"
	KEY_LSHIFT = sdl.K_LSHIFT // "Left Shift"
	KEY_LALT   = sdl.K_LALT   // "Left Alt" (alt, option)
	KEY_LGUI   = sdl.K_LGUI   // "Left GUI" (windows, command (apple), meta)
	KEY_RCTRL  = sdl.K_RCTRL  // "Right Ctrl"
	KEY_RSHIFT = sdl.K_RSHIFT // "Right Shift"
	KEY_RALT   = sdl.K_RALT   // "Right Alt" (alt, option)
	KEY_RGUI   = sdl.K_RGUI   // "Right GUI" (windows, command (apple), meta)

	KEY_MODE = sdl.K_MODE // "ModeSwitch" (I'm not sure if this is really not covered by any of the above, but since there's a special KMOD_MODE for it I'm adding it here)

	KEY_AUDIONEXT    = sdl.K_AUDIONEXT    // "AudioNext" (the Next Track media key)
	KEY_AUDIOPREV    = sdl.K_AUDIOPREV    // "AudioPrev" (the Previous Track media key)
	KEY_AUDIOSTOP    = sdl.K_AUDIOSTOP    // "AudioStop" (the Stop media key)
	KEY_AUDIOPLAY    = sdl.K_AUDIOPLAY    // "AudioPlay" (the Play media key)
	KEY_AUDIOMUTE    = sdl.K_AUDIOMUTE    // "AudioMute" (the Mute volume key)
	KEY_MEDIASELECT  = sdl.K_MEDIASELECT  // "MediaSelect" (the Media Select key)
	KEY_WWW          = sdl.K_WWW          // "WWW" (the WWW/World Wide Web key)
	KEY_MAIL         = sdl.K_MAIL         // "Mail" (the Mail/eMail key)
	KEY_CALCULATOR   = sdl.K_CALCULATOR   // "Calculator" (the Calculator key)
	KEY_COMPUTER     = sdl.K_COMPUTER     // "Computer" (the My Computer key)
	KEY_AC_SEARCH    = sdl.K_AC_SEARCH    // "AC Search" (the Search key (application control keypad))
	KEY_AC_HOME      = sdl.K_AC_HOME      // "AC Home" (the Home key (application control keypad))
	KEY_AC_BACK      = sdl.K_AC_BACK      // "AC Back" (the Back key (application control keypad))
	KEY_AC_FORWARD   = sdl.K_AC_FORWARD   // "AC Forward" (the Forward key (application control keypad))
	KEY_AC_STOP      = sdl.K_AC_STOP      // "AC Stop" (the Stop key (application control keypad))
	KEY_AC_REFRESH   = sdl.K_AC_REFRESH   // "AC Refresh" (the Refresh key (application control keypad))
	KEY_AC_BOOKMARKS = sdl.K_AC_BOOKMARKS // "AC Bookmarks" (the Bookmarks key (application control keypad))

	KEY_BRIGHTNESSDOWN = sdl.K_BRIGHTNESSDOWN // "BrightnessDown" (the Brightness Down key)
	KEY_BRIGHTNESSUP   = sdl.K_BRIGHTNESSUP   // "BrightnessUp" (the Brightness Up key)
	KEY_DISPLAYSWITCH  = sdl.K_DISPLAYSWITCH  // "DisplaySwitch" (display mirroring/dual display switch, video mode switch)
	KEY_KBDILLUMTOGGLE = sdl.K_KBDILLUMTOGGLE // "KBDIllumToggle" (the Keyboard Illumination Toggle key)
	KEY_KBDILLUMDOWN   = sdl.K_KBDILLUMDOWN   // "KBDIllumDown" (the Keyboard Illumination Down key)
	KEY_KBDILLUMUP     = sdl.K_KBDILLUMUP     // "KBDIllumUp" (the Keyboard Illumination Up key)
	KEY_EJECT          = sdl.K_EJECT          // "Eject" (the Eject key)
	KEY_SLEEP          = sdl.K_SLEEP          // "Sleep" (the Sleep key)

A mapping of _all_ the SDL keys.


View Source
var (
	White = RGB(255, 255, 255)
	Red   = RGB(255, 0, 0)
	Green = RGB(0, 255, 0)
	Blue  = RGB(0, 0, 255)
	Black = RGB(0, 0, 0)

List of preset colours


func CurrentTimeMillis

func CurrentTimeMillis() int64

CurrentTimeMillis wraps over SDL_GetTicks. Use time.Now() instead.

func EnableDPI

func EnableDPI()

EnableDPI will setup DPI for windows ... currently unimplemented!

func GetDisplayDPI

func GetDisplayDPI(displayIndex int) (dpi float32, def float32)

GetDisplayDPI returns the dpi and default dpi of the given display

func HandleEvent

func HandleEvent(event StrifeEvent)

HandleEvent will trigger the given StrifeEvent

func KeyPressed

func KeyPressed(keyCode int) bool

KeyPressed will query if a key is pressed in the KeyboardHandler

func KeyState

func KeyState() []uint8

KeyState wraps over SDL GetKeyboardState

func MouseCoords

func MouseCoords() (int, int)

MouseCoords returns the coords of the mouse

func PollKeys

func PollKeys() bool

PollKeys returns if there are in key presses in the buffer

func PopKey

func PopKey() int

PopKey pops a key from the key press queue.


type BaseEvent

type BaseEvent struct{}

BaseEvent is a simple helper structure for events to satisfy sdl2

func (*BaseEvent) GetTimestamp

func (b *BaseEvent) GetTimestamp() uint32

GetTimestamp returns the timestamp of the event FIXME

func (*BaseEvent) GetType

func (b *BaseEvent) GetType() uint32

GetType returns the type of this event FIXME

func (*BaseEvent) Trigger

func (b *BaseEvent) Trigger()

Trigger is invoked when the event is triggered

type CloseEvent

type CloseEvent struct {

CloseEvent is invoked when the window requests to close.

type Color

type Color struct {
	R, G, B, A uint8

Color is an RGBA colour

func HexRGB

func HexRGB(col uint32) *Color

HexRGB will convert the given hex uint32 value to a Color TODO: alpha channel >> 24.

func RGB

func RGB(r, g, b int) *Color

RGB will create a colour from the given RGB, alpha is set to full.

func RGBA

func RGBA(r, g, b, a int) *Color

RGBA will create a colour from the given r, g, b, a

func (Color) AsHex

func (c Color) AsHex() uint32

AsHex will return the Color as a uint32/hex

func (*Color) Equals

func (c *Color) Equals(o *Color) bool

Equals will compare this colour with another colour o including alpha channels.

func (Color) ToSDLColor

func (c Color) ToSDLColor() sdl.Color

ToSDLColor Converts to an SDL colour object

type Focus

type Focus int

Focus represents the state of focus for the window

const (
	FocusGained Focus = iota

Currently two types: focus gained, and focus lost. i.e. the window is clicked onto or the window is clicked off of.

type Font

type Font struct {
	// contains filtered or unexported fields

Font is a TrueTypeFont, stores the path as well as the texture cache for the glyphs

func LoadFont

func LoadFont(path string, size int) (*Font, error)

LoadFont will try and load the font from the given path of the given size.

func (*Font) DeriveFont

func (f *Font) DeriveFont(size int) (*Font, error)

DeriveFont will create a new font object from this font of a different size.

func (*Font) Destroy

func (f *Font) Destroy()

Destroy will destroy the given font as well as clear the texture cache.

type Image

type Image struct {
	Width, Height int

Image wraps a SDL texture _and_ SDL surface

func LoadImage

func LoadImage(path string) (*Image, error)

LoadImage will load the image at the given path. It will return the loaded image, and any errors encountered.

func (*Image) Destroy

func (i *Image) Destroy()

Destroy must be invoked when finished with the resource.

func (*Image) GetSurface

func (i *Image) GetSurface() *sdl.Surface

GetSurface returns a pointer to the SDL_Surface object

type KeyDownEvent

type KeyDownEvent struct {
	KeyCode int

KeyDownEvent is invoked when a key is pressed and held down

type KeyUpEvent

type KeyUpEvent struct {
	KeyCode int

KeyUpEvent is invoked when the key is _released_

type KeyboardHandler

type KeyboardHandler struct {
	// contains filtered or unexported fields

KeyboardHandler is a wrapper to handle key press

type MouseButtonState

type MouseButtonState int

MouseButtonState contains the state of the mouse button, i.e. if its left/right is down no buttons are down, or the scroll wheel is clicked

const (
	NoMouseButtonsDown MouseButtonState = iota

The types of mouse button state.

func MouseButtonsState

func MouseButtonsState() MouseButtonState

MouseButtonsState returns the current state of the mouse

type MouseHandler

type MouseHandler struct {
	X, Y        int
	ButtonState MouseButtonState

MouseHandler is a wrapper to store the X, Y location of the mouse + the current state

type MouseMoveEvent

type MouseMoveEvent struct {
	X, Y int

MouseMoveEvent represents a mouse movement event

type MouseWheelEvent

type MouseWheelEvent struct {
	X, Y int

MouseWheelEvent represents a mouse scroll wheel event

type RenderConfig

type RenderConfig struct {
	Alias        bool
	Accelerated  bool
	VerticalSync bool

RenderConfig is the configuration settings for the renderer. Alias => Controls if the fonts are smoothed; Accelerated => The renderer is hardware accelerated if true; and VerticalSync => Will synchronize the FPS with the monitors refresh rate

func DefaultConfig

func DefaultConfig() *RenderConfig

DefaultConfig with all of the rendering options enabled.

func GoGoStrifeFast

func GoGoStrifeFast() *RenderConfig

GoGoStrifeFast is the default configuration with all pretty settings turned off. vertical synchronisation is enabled.

type RenderWindow

type RenderWindow struct {
	// contains filtered or unexported fields

RenderWindow is a window context with a rendererer. It contains the handlers for events, as well as the render configuration options.

func SetupRenderWindow

func SetupRenderWindow(w, h int, config *RenderConfig) *RenderWindow

SetupRenderWindow will create a render window of the given width and height, with the specified configuration. You can specify a default configuration with `strife.DefaultConfig()`. Note that this will spawn the window at the centre of the main display.

func (*RenderWindow) AllowHighDPI

func (w *RenderWindow) AllowHighDPI()

AllowHighDPI will allow a high DPI, must be called before Create()

func (*RenderWindow) Close

func (w *RenderWindow) Close()

Close will close the render window and destroy the context.

func (*RenderWindow) CloseRequested

func (w *RenderWindow) CloseRequested() bool

CloseRequested will return if the window has had a CloseRequest even triggered.

func (*RenderWindow) Create

func (w *RenderWindow) Create() error

Create window take all of the settings and create a window with a rendering context

func (*RenderWindow) GetRenderContext

func (w *RenderWindow) GetRenderContext() *Renderer

GetRenderContext returns the render context

func (*RenderWindow) GetSize

func (w *RenderWindow) GetSize() (int, int)

GetSize will return the window width and height

func (*RenderWindow) HandleEvents

func (w *RenderWindow) HandleEvents(handler func(StrifeEvent))

HandleEvents will set the event handler predicate.

func (*RenderWindow) PollEvents

func (w *RenderWindow) PollEvents()

PollEvents will poll for any events. All events are unhandled, _except_ for the Quit Event, which will destroy the render context, render window, and cause this function to return true.

func (*RenderWindow) SetIconImage

func (w *RenderWindow) SetIconImage(img *Image)

SetIconImage will set the window icon from the given Image

func (*RenderWindow) SetResizable

func (w *RenderWindow) SetResizable(resizable bool)

SetResizable will add the resizable flag, must be called before Create()

type Renderer

type Renderer struct {
	// contains filtered or unexported fields

Renderer contains the renderers current configuration, as well as the colour state and font state and a wrapper over the SDL renderer.

var RenderInstance *Renderer

RenderInstance is the current render instance, in an ideal world this will only be set once. This is exists because SDL wants to have the render instance for loading images, fonts, etc.

func CreateRenderer

func CreateRenderer(parent *RenderWindow, config *RenderConfig) (*Renderer, error)

CreateRenderer will create a rendering instance for the given window. It takes the configuration specifying if the renderer is software or hardware accelerated, as well as if the renderer should be vertically synchronized. It returns the renderer and any error that is encountered during the creation.

func (*Renderer) Clear

func (r *Renderer) Clear()

Clear will clear the screen to black. By default it will immediately set the colour state to render things as white.

func (*Renderer) Display

func (r *Renderer) Display()

Display the renderer to the window

func (*Renderer) GetFont

func (r *Renderer) GetFont() *Font

GetFont returns the current font that was last set

func (*Renderer) GetSize

func (r *Renderer) GetSize() (int, int)

GetSize returns the size of the renderer. on error it will return -1, -1

func (*Renderer) GetStringDimension

func (r *Renderer) GetStringDimension(message string) (int, int)

func (*Renderer) Image

func (r *Renderer) Image(image *Image, x, y int)

Image will render the given image at the given x, y co-ordinates at the images full size.

func (*Renderer) ImageScale

func (r *Renderer) ImageScale(image *Image, x, y, w, h int)

ImageScale will render the image at the given co-ordinate scaled to the given size.

func (*Renderer) Rect

func (r *Renderer) Rect(x, y, w, h int, mode Style)

Rect will draw a rectangle at the given x, y co-ordinates of the specified size. It takes the mode to render the rectangle as: fill or line.

func (*Renderer) SetColor

func (r *Renderer) SetColor(color *Color)

SetColor sets the current colour state

func (*Renderer) SetFont

func (r *Renderer) SetFont(font *Font)

SetFont will set the font state

func (*Renderer) SubImage

func (r *Renderer) SubImage(image *Image, x, y int, tx, ty, tw, th int)

SubImage will render a sub-section of the given image. tx, ty are the x, y pixel coordinates of the sub-image in the image to render. tw, th are the size of the sub-image.

func (*Renderer) SubImageScale

func (r *Renderer) SubImageScale(image *Image, x, y int, tx, ty, tw, th int, sw, sh int)

SubImageScale will render a sub-section of the given image scaled to the given width and height. See the documentation for SubImage.

func (*Renderer) Text

func (r *Renderer) Text(message string, x, y int) (int, int)

Text renders the given text to the given x, y coordinates. Note that the text is cached, i.e. each glyph rendered will be cached and re-used. UncachedText is the alternative, though it's slower.

func (*Renderer) UncachedText

func (r *Renderer) UncachedText(message string, x, y int) (int, int)

UncachedText is the same as Text, it draws the given string to the given x,y note that it doesn't cache the glyphs, however, so should not be used for lots of text rendering!

type StrifeEvent

type StrifeEvent interface {

StrifeEvent wraps an SDL event

type Style

type Style uint

Style to render primitive shapes (Rectangles, Circles, etc). Fill meaning fill the shape with colour, and Line meaning to draw the outline of the shape.

const (
	Line Style = iota

Types of render styles, Line for stroke e.g. outline of a shape, vs fill which will fill a rectangle.

type Visibility

type Visibility int

Visibility of the window, e.g. hidden, shown.

const (
	Shown Visibility = iota

The types of visibilities available for the window.

type WindowFocusEvent

type WindowFocusEvent struct {

WindowFocusEvent ...

type WindowMoveEvent

type WindowMoveEvent struct {
	X, Y int

WindowMoveEvent is invoked when the window is moved contains the new x, y position of the window.

type WindowResizeEvent

type WindowResizeEvent struct {
	Width, Height int

WindowResizeEvent is invoked when the window is resized. contains the new width and height

type WindowVisibilityEvent

type WindowVisibilityEvent struct {

WindowVisibilityEvent ...


Path Synopsis