Categorygithub.com/felixangell/strife
modulepackage
0.2.2
Repository: https://github.com/felixangell/strife.git
Documentation: pkg.go.dev

# README

strife Build Status

A simple game framework that wraps around SDL2.

example

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.

note/disclaimer

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.

installing

Simple as

$ go get github.com/felixangell/strife

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!")
	window.SetResizable(true)
	window.Create()

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

	// game loop
	for {
		// handle the events before we do any
		// rendering etc.
		window.PollEvents()

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

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

			// check out some other examples!
		}
		ctx.Display()
	}
}

license

MIT

# Packages

No description provided by the author

# Functions

CreateRenderer will create a rendering instance for the given window.
CurrentTimeMillis wraps over SDL_GetTicks.
DefaultConfig with all of the rendering options enabled.
EnableDPI will setup DPI for windows ..
GetDisplayDPI returns the dpi and default dpi of the given display.
GoGoStrifeFast is the default configuration with all pretty settings turned off.
HandleEvent will trigger the given StrifeEvent.
HexRGB will convert the given hex uint32 value to a Color TODO: alpha channel >> 24.
KeyPressed will query if a key is pressed in the KeyboardHandler.
KeyState wraps over SDL GetKeyboardState.
LoadFont will try and load the font from the given path of the given size.
LoadImage will load the image at the given path.
MouseButtonsState returns the current state of the mouse.
MouseCoords returns the coords of the mouse.
PollKeys returns if there are in key presses in the buffer.
PopKey pops a key from the key press queue.
RGB will create a colour from the given RGB, alpha is set to full.
RGBA will create a colour from the given r, g, b, a.
SetupRenderWindow will create a render window of the given width and height, with the specified configuration.

# Constants

The types of visibilities available for the window.
Types of render styles, Line for stroke e.g.
Currently two types: focus gained, and focus lost.
Currently two types: focus gained, and focus lost.
The types of visibilities available for the window.
"0".
"1".
"2".
"3".
"4".
"5".
"6".
"7".
"8".
"9".
"A".
"AC Back" (the Back key (application control keypad)).
"AC Bookmarks" (the Bookmarks key (application control keypad)).
"AC Forward" (the Forward key (application control keypad)).
"AC Home" (the Home key (application control keypad)).
"AC Refresh" (the Refresh key (application control keypad)).
"AC Search" (the Search key (application control keypad)).
"AC Stop" (the Stop key (application control keypad)).
"Again" (the Again key (Redo)).
"AltErase" (Erase-Eaze).
"&".
"Application" (the Application / Compose / Context Menu (Windows) key).
"*".
"@".
"AudioMute" (the Mute volume key).
"AudioNext" (the Next Track media key).
"AudioPlay" (the Play media key).
"AudioPrev" (the Previous Track media key).
"AudioStop" (the Stop media key).
"B".
"`".
"\".
"Backspace".
"BrightnessDown" (the Brightness Down key).
"BrightnessUp" (the Brightness Up key).
"C".
"Calculator" (the Calculator key).
"Cancel".
"CapsLock".
"^".
"Clear".
"Clear / Again".
":".
",".
"Computer" (the My Computer key).
"Copy".
"CrSel".
"CurrencySubUnit" (the Currency Subunit key).
"CurrencyUnit" (the Currency Unit key).
"Cut".
"D".
"DecimalSeparator" (the Decimal Separator key).
"Delete".
"DisplaySwitch" (display mirroring/dual display switch, video mode switch).
"$".
"Down" (the Down arrow key (navigation keypad)).
"E".
"Eject" (the Eject key).
"End".
"=".
"Escape" (the Esc key).
"!".
"Execute".
"ExSel".
"F".
"F1".
"F10".
"F11".
"F12".
"F13".
"F14".
"F15".
"F16".
"F17".
"F18".
"F19".
"F2".
"F20".
"F21".
"F22".
"F23".
"F24".
"F3".
"F4".
"F5".
"F6".
"F7".
"F8".
"F9".
"Find".
"G".
">".
"H".
"#".
"Help".
"Home".
"I".
"Insert" (insert on PC, help on some Mac keyboards (but does send code 73, not 117)).
"J".
"K".
"KBDIllumDown" (the Keyboard Illumination Down key).
"KBDIllumToggle" (the Keyboard Illumination Toggle key).
"KBDIllumUp" (the Keyboard Illumination Up key).
"Keypad 0" (the 0 key (numeric keypad)).
"Keypad 00" (the 00 key (numeric keypad)).
"Keypad 000" (the 000 key (numeric keypad)).
"Keypad 1" (the 1 key (numeric keypad)).
"Keypad 2" (the 2 key (numeric keypad)).
"Keypad 3" (the 3 key (numeric keypad)).
"Keypad 4" (the 4 key (numeric keypad)).
"Keypad 5" (the 5 key (numeric keypad)).
"Keypad 6" (the 6 key (numeric keypad)).
"Keypad 7" (the 7 key (numeric keypad)).
"Keypad 8" (the 8 key (numeric keypad)).
"Keypad 9" (the 9 key (numeric keypad)).
"Keypad A" (the A key (numeric keypad)).
"Keypad &" (the & key (numeric keypad)).
"Keypad @" (the @ key (numeric keypad)).
"Keypad B" (the B key (numeric keypad)).
"Keypad Backspace" (the Backspace key (numeric keypad)).
"Keypad Binary" (the Binary key (numeric keypad)).
"Keypad C" (the C key (numeric keypad)).
"Keypad Clear" (the Clear key (numeric keypad)).
"Keypad ClearEntry" (the Clear Entry key (numeric keypad)).
"Keypad :" (the : key (numeric keypad)).
"Keypad ," (the Comma key (numeric keypad)).
"Keypad D" (the D key (numeric keypad)).
"Keypad &&" (the && key (numeric keypad)).
"Keypad ||" (the || key (numeric keypad)).
"Keypad Decimal" (the Decimal key (numeric keypad)).
"Keypad /" (the / key (numeric keypad)).
"Keypad E" (the E key (numeric keypad)).
"Keypad Enter" (the Enter key (numeric keypad)).
"Keypad =" (the = key (numeric keypad)).
"Keypad = (AS400)" (the Equals AS400 key (numeric keypad)).
"Keypad !" (the ! key (numeric keypad)).
"Keypad F" (the F key (numeric keypad)).
"Keypad >" (the Greater key (numeric keypad)).
"Keypad #" (the # key (numeric keypad)).
"Keypad Hexadecimal" (the Hexadecimal key (numeric keypad)).
"Keypad {" (the Left Brace key (numeric keypad)).
"Keypad (" (the Left Parenthesis key (numeric keypad)).
"Keypad <" (the Less key (numeric keypad)).
"Keypad MemAdd" (the Mem Add key (numeric keypad)).
"Keypad MemClear" (the Mem Clear key (numeric keypad)).
"Keypad MemDivide" (the Mem Divide key (numeric keypad)).
"Keypad MemMultiply" (the Mem Multiply key (numeric keypad)).
"Keypad MemRecall" (the Mem Recall key (numeric keypad)).
"Keypad MemStore" (the Mem Store key (numeric keypad)).
"Keypad MemSubtract" (the Mem Subtract key (numeric keypad)).
"Keypad -" (the - key (numeric keypad)).
"Keypad *" (the * key (numeric keypad)).
"Keypad Octal" (the Octal key (numeric keypad)).
"Keypad %" (the Percent key (numeric keypad)).
"Keypad ." (the .
"Keypad +" (the + key (numeric keypad)).
"Keypad +/-" (the +/- key (numeric keypad)).
"Keypad ^" (the Power key (numeric keypad)).
"Keypad }" (the Right Brace key (numeric keypad)).
"Keypad )" (the Right Parenthesis key (numeric keypad)).
"Keypad Space" (the Space key (numeric keypad)).
"Keypad Tab" (the Tab key (numeric keypad)).
"Keypad |" (the | key (numeric keypad)).
"Keypad XOR" (the XOR key (numeric keypad)).
"L".
"Left Alt" (alt, option).
"Left Ctrl".
"Left" (the Left arrow key (navigation keypad)).
"[".
"(".
"<".
"Left GUI" (windows, command (apple), meta).
"Left Shift".
"M".
"Mail" (the Mail/eMail key).
"MediaSelect" (the Media Select key).
"Menu".
"-".
"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).
"Mute".
"N".
"Numlock" (the Num Lock key (PC) / the Clear key (Mac)).
"O".
"Oper".
"Out".
"P".
"PageDown".
"PageUp".
"Paste".
"Pause" (the Pause / Break key).
"%".
".".
"+".
"Power" (The USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key.).
"PrintScreen".
"Prior".
"Q".
"?".
"'".
""".
"R".
"Right Alt" (alt, option).
"Right Ctrl".
"Return" (the Enter key (main keyboard)).
"Return".
"Right GUI" (windows, command (apple), meta).
"Right" (the Right arrow key (navigation keypad)).
"]".
")".
"Right Shift".
"S".
"ScrollLock".
"Select".
";".
"Separator".
"/".
"Sleep" (the Sleep key).
"Space" (the Space Bar key(s)).
"Stop".
"SysReq" (the SysReq key).
"T".
"Tab" (the Tab key).
"ThousandsSeparator" (the Thousands Separator key).
"U".
"_".
"Undo".
"Up" (the Up arrow key (navigation keypad)).
"V".
"VolumeDown".
"VolumeUp".
"W".
"WWW" (the WWW/World Wide Web key).
"X".
"Y".
"Z".
The types of mouse button state.
Types of render styles, Line for stroke e.g.
The types of mouse button state.
The types of mouse button state.
The types of mouse button state.
The types of visibilities available for the window.
"" (no name, empty string).

# Variables

List of preset colours.
List of preset colours.
List of preset colours.
List of preset colours.
RenderInstance is the current render instance, in an ideal world this will only be set once.
List of preset colours.

# Structs

BaseEvent is a simple helper structure for events to satisfy sdl2.
CloseEvent is invoked when the window requests to close.
Color is an RGBA colour.
Font is a TrueTypeFont, stores the path as well as the texture cache for the glyphs.
Image wraps a SDL texture _and_ SDL surface.
KeyboardHandler is a wrapper to handle key press.
KeyDownEvent is invoked when a key is pressed and held down.
KeyUpEvent is invoked when the key is _released_.
MouseHandler is a wrapper to store the X, Y location of the mouse + the current state.
MouseMoveEvent represents a mouse movement event.
MouseWheelEvent represents a mouse scroll wheel event.
RenderConfig is the configuration settings for the renderer.
Renderer contains the renderers current configuration, as well as the colour state and font state and a wrapper over the SDL renderer.
RenderWindow is a window context with a rendererer.
WindowFocusEvent ...
WindowMoveEvent is invoked when the window is moved contains the new x, y position of the window.
WindowResizeEvent is invoked when the window is resized.
WindowVisibilityEvent ...

# Interfaces

StrifeEvent wraps an SDL event.

# Type aliases

Focus represents the state of focus for the window.
MouseButtonState contains the state of the mouse button, i.e.
Style to render primitive shapes (Rectangles, Circles, etc).
Visibility of the window, e.g.