turdgl

package module
v0.0.0-...-7b10895 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 21 Imported by: 0

README

turdgl

Turdgl is a 2D graphics library built on top of Simple Directmedia Layer. It is CPU-based, meaning it does not perform well with intensive graphics.

This project was built as a learning experience. Therefore, it is not recommended for any serious applications.

Capabilities

This library does:

  • Draw 2D shapes
  • Render text
  • Handle keyboard and mouse inputs
  • Provide fine-grained control of primitives and their interactions

This library does not:

  • Support animations*
  • Provide "game engine" like functionality

*Animations and other complex graphics can be built on top of Turdgl. See go-2048-battle as an example.

Dependencies

SDL2 - DirectMedia Layer

Advanced Packaging Tool (Ubuntu):

sudo apt-get update && sudo apt-get install -y libsdl2-dev libsdl2-image-dev

Homebrew (MacOS):

brew install sdl2_image

Documentation

Index

Constants

View Source
const (
	KeyModeNone     = sdl.KMOD_NONE     // 0 (no modifier is applicable)
	KeyModeLShift   = sdl.KMOD_LSHIFT   // the left Shift key is down
	KeyModeRShift   = sdl.KMOD_RSHIFT   // the right Shift key is down
	KeyModeLCtrl    = sdl.KMOD_LCTRL    // the left Ctrl (Control) key is down
	KeyModeRCtrl    = sdl.KMOD_RCTRL    // the right Ctrl (Control) key is down
	KeyModeLAlt     = sdl.KMOD_LALT     // the left Alt key is down
	KeyModeRAlt     = sdl.KMOD_RALT     // the right Alt key is down
	KeyModeLGui     = sdl.KMOD_LGUI     // the left GUI key (often the Windows key) is down
	KeyModeRGui     = sdl.KMOD_RGUI     // the right GUI key (often the Windows key) is down
	KeyModeNum      = sdl.KMOD_NUM      // the Num Lock key (may be located on an extended keypad) is down
	KeyModeCaps     = sdl.KMOD_CAPS     // the Caps Lock key is down
	KeyModeMode     = sdl.KMOD_MODE     // the AltGr key is down
	KeyModeCtrl     = sdl.KMOD_CTRL     // (KMOD_LCTRL|KMOD_RCTRL)
	KeyModeShift    = sdl.KMOD_SHIFT    // (KMOD_LSHIFT|KMOD_RSHIFT)
	KeyModeAlt      = sdl.KMOD_ALT      // (KMOD_LALT|KMOD_RALT)
	KeyModeGui      = sdl.KMOD_GUI      // (KMOD_LGUI|KMOD_RGUI)
	KeyModeReserved = sdl.KMOD_RESERVED // reserved for future use

	KeyUnknown    = sdl.K_UNKNOWN    // "" (no name, empty string)
	KeyReturn     = sdl.K_RETURN     // "Return" (the Enter key (main keyboard))
	KeyEscape     = sdl.K_ESCAPE     // "Escape" (the Esc key)
	KeyBackspace  = sdl.K_BACKSPACE  // "Backspace"
	KeyTab        = sdl.K_TAB        // "Tab" (the Tab key)
	KeySpace      = sdl.K_SPACE      // "Space" (the Space Bar key(s))
	KeyExclaim    = sdl.K_EXCLAIM    // "!"
	KeyQuotedBL   = sdl.K_QUOTEDBL   // """
	KeyHash       = sdl.K_HASH       // "#"
	KeyPercent    = sdl.K_PERCENT    // "%"
	KeyDollar     = sdl.K_DOLLAR     // "$"
	KeyAmpersand  = sdl.K_AMPERSAND  // "&"
	KeyQuote      = sdl.K_QUOTE      // "'"
	KeyLeftparen  = sdl.K_LEFTPAREN  // "("
	KeyRightparen = sdl.K_RIGHTPAREN // ")"
	KeyAsterisk   = sdl.K_ASTERISK   // "*"
	KeyPlus       = sdl.K_PLUS       // "+"
	KeyComma      = sdl.K_COMMA      // ","
	KeyMinus      = sdl.K_MINUS      // "-"
	KeyPeriod     = sdl.K_PERIOD     // "."
	KeySlash      = sdl.K_SLASH      // "/"
	Key0          = sdl.K_0          // "0"
	Key1          = sdl.K_1          // "1"
	Key2          = sdl.K_2          // "2"
	Key3          = sdl.K_3          // "3"
	Key4          = sdl.K_4          // "4"
	Key5          = sdl.K_5          // "5"
	Key6          = sdl.K_6          // "6"
	Key7          = sdl.K_7          // "7"
	Key8          = sdl.K_8          // "8"
	Key9          = sdl.K_9          // "9"
	KeyColon      = sdl.K_COLON      // ":"
	KeySemicolon  = sdl.K_SEMICOLON  // ";"
	KeyLess       = sdl.K_LESS       // "<"
	KeyEquals     = sdl.K_EQUALS     // "="
	KeyGreater    = sdl.K_GREATER    // ">"
	KeyQuestion   = sdl.K_QUESTION   // "?"
	KeyAt         = sdl.K_AT         // "@"

	KeyLeftBracket  = sdl.K_LEFTBRACKET  // "["
	KeyBackslash    = sdl.K_BACKSLASH    // "\"
	KeyRightBracket = sdl.K_RIGHTBRACKET // "]"
	KeyCaret        = sdl.K_CARET        // "^"
	KeyUnderscore   = sdl.K_UNDERSCORE   // "_"
	KeyBackquote    = sdl.K_BACKQUOTE    // "`"
	KeyA            = sdl.K_a            // "A"
	KeyB            = sdl.K_b            // "B"
	KeyC            = sdl.K_c            // "C"
	KeyD            = sdl.K_d            // "D"
	KeyE            = sdl.K_e            // "E"
	KeyF            = sdl.K_f            // "F"
	KeyG            = sdl.K_g            // "G"
	KeyH            = sdl.K_h            // "H"
	KeyI            = sdl.K_i            // "I"
	KeyJ            = sdl.K_j            // "J"
	KeyK            = sdl.K_k            // "K"
	KeyL            = sdl.K_l            // "L"
	KeyM            = sdl.K_m            // "M"
	KeyN            = sdl.K_n            // "N"
	KeyO            = sdl.K_o            // "O"
	KeyP            = sdl.K_p            // "P"
	KeyQ            = sdl.K_q            // "Q"
	KeyR            = sdl.K_r            // "R"
	KeyS            = sdl.K_s            // "S"
	KeyT            = sdl.K_t            // "T"
	KeyU            = sdl.K_u            // "U"
	KeyV            = sdl.K_v            // "V"
	KeyW            = sdl.K_w            // "W"
	KeyX            = sdl.K_x            // "X"
	KeyY            = sdl.K_y            // "Y"
	KeyZ            = sdl.K_z            // "Z"

	KeyCapslock = sdl.K_CAPSLOCK // "CapsLock"

	KeyF1  = sdl.K_F1  // "F1"
	KeyF2  = sdl.K_F2  // "F2"
	KeyF3  = sdl.K_F3  // "F3"
	KeyF4  = sdl.K_F4  // "F4"
	KeyF5  = sdl.K_F5  // "F5"
	KeyF6  = sdl.K_F6  // "F6"
	KeyF7  = sdl.K_F7  // "F7"
	KeyF8  = sdl.K_F8  // "F8"
	KeyF9  = sdl.K_F9  // "F9"
	KeyF10 = sdl.K_F10 // "F10"
	KeyF11 = sdl.K_F11 // "F11"
	KeyF12 = sdl.K_F12 // "F12"

	KeyPrintscreen = sdl.K_PRINTSCREEN // "PrintScreen"
	KeyScrolllock  = sdl.K_SCROLLLOCK  // "ScrollLock"
	KeyPause       = sdl.K_PAUSE       // "Pause" (the Pause / Break key)
	KeyInsert      = sdl.K_INSERT      // "Insert" (insert on PC, help on some Mac keyboards (but does send code 73, not 117))
	KeyHome        = sdl.K_HOME        // "Home"
	KeyPageup      = sdl.K_PAGEUP      // "PageUp"
	KeyDelete      = sdl.K_DELETE      // "Delete"
	KeyEnd         = sdl.K_END         // "End"
	KeyPagedown    = sdl.K_PAGEDOWN    // "PageDown"
	KeyRight       = sdl.K_RIGHT       // "Right" (the Right arrow key (navigation keypad))
	KeyLeft        = sdl.K_LEFT        // "Left" (the Left arrow key (navigation keypad))
	KeyDown        = sdl.K_DOWN        // "Down" (the Down arrow key (navigation keypad))
	KeyUp          = sdl.K_UP          // "Up" (the Up arrow key (navigation keypad))

	KeyNumlockclear = sdl.K_NUMLOCKCLEAR // "Numlock" (the Num Lock key (PC) / the Clear key (Mac))
	KeyKPDivide     = sdl.K_KP_DIVIDE    // "Keypad /" (the / key (numeric keypad))
	KeyKPMultiply   = sdl.K_KP_MULTIPLY  // "Keypad *" (the * key (numeric keypad))
	KeyKPMinus      = sdl.K_KP_MINUS     // "Keypad -" (the - key (numeric keypad))
	KeyKPPlus       = sdl.K_KP_PLUS      // "Keypad +" (the + key (numeric keypad))
	KeyKPEnter      = sdl.K_KP_ENTER     // "Keypad Enter" (the Enter key (numeric keypad))
	KeyKP1          = sdl.K_KP_1         // "Keypad 1" (the 1 key (numeric keypad))
	KeyKP2          = sdl.K_KP_2         // "Keypad 2" (the 2 key (numeric keypad))
	KeyKP3          = sdl.K_KP_3         // "Keypad 3" (the 3 key (numeric keypad))
	KeyKP4          = sdl.K_KP_4         // "Keypad 4" (the 4 key (numeric keypad))
	KeyKP5          = sdl.K_KP_5         // "Keypad 5" (the 5 key (numeric keypad))
	KeyKP6          = sdl.K_KP_6         // "Keypad 6" (the 6 key (numeric keypad))
	KeyKP7          = sdl.K_KP_7         // "Keypad 7" (the 7 key (numeric keypad))
	KeyKP8          = sdl.K_KP_8         // "Keypad 8" (the 8 key (numeric keypad))
	KeyKP9          = sdl.K_KP_9         // "Keypad 9" (the 9 key (numeric keypad))
	KeyKP0          = sdl.K_KP_0         // "Keypad 0" (the 0 key (numeric keypad))
	KeyKPPeriod     = sdl.K_KP_PERIOD    // "Keypad ." (the . key (numeric keypad))

	KeyApplication   = sdl.K_APPLICATION    // "Application" (the Application / Compose / Context Menu (Windows) key)
	KeyPower         = 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)
	KeyKPEquals      = sdl.K_KP_EQUALS      // "Keypad =" (the = key (numeric keypad))
	KeyF13           = sdl.K_F13            // "F13"
	KeyF14           = sdl.K_F14            // "F14"
	KeyF15           = sdl.K_F15            // "F15"
	KeyF16           = sdl.K_F16            // "F16"
	KeyF17           = sdl.K_F17            // "F17"
	KeyF18           = sdl.K_F18            // "F18"
	KeyF19           = sdl.K_F19            // "F19"
	KeyF20           = sdl.K_F20            // "F20"
	KeyF21           = sdl.K_F21            // "F21"
	KeyF22           = sdl.K_F22            // "F22"
	KeyF23           = sdl.K_F23            // "F23"
	KeyF24           = sdl.K_F24            // "F24"
	KeyExecute       = sdl.K_EXECUTE        // "Execute"
	KeyHelp          = sdl.K_HELP           // "Help"
	KeyMenu          = sdl.K_MENU           // "Menu"
	KeySelect        = sdl.K_SELECT         // "Select"
	KeyStop          = sdl.K_STOP           // "Stop"
	KeyAgain         = sdl.K_AGAIN          // "Again" (the Again key (Redo))
	KeyUndo          = sdl.K_UNDO           // "Undo"
	KeyCut           = sdl.K_CUT            // "Cut"
	KeyCopy          = sdl.K_COPY           // "Copy"
	KeyPaste         = sdl.K_PASTE          // "Paste"
	KeyFind          = sdl.K_FIND           // "Find"
	KeyMute          = sdl.K_MUTE           // "Mute"
	KeyVolumeUp      = sdl.K_VOLUMEUP       // "VolumeUp"
	KeyVolumeDown    = sdl.K_VOLUMEDOWN     // "VolumeDown"
	KeyKPComma       = sdl.K_KP_COMMA       // "Keypad ," (the Comma key (numeric keypad))
	KeyKPEqualsAS400 = sdl.K_KP_EQUALSAS400 // "Keypad = (AS400)" (the Equals AS400 key (numeric keypad))

	KeyAltErase   = sdl.K_ALTERASE   // "AltErase" (Erase-Eaze)
	KeySysReq     = sdl.K_SYSREQ     // "SysReq" (the SysReq key)
	KeyCancel     = sdl.K_CANCEL     // "Cancel"
	KeyClear      = sdl.K_CLEAR      // "Clear"
	KeyPrior      = sdl.K_PRIOR      // "Prior"
	KeyReturn2    = sdl.K_RETURN2    // "Return"
	KeySeparator  = sdl.K_SEPARATOR  // "Separator"
	KeyOut        = sdl.K_OUT        // "Out"
	KeyOper       = sdl.K_OPER       // "Oper"
	KeyClearAgain = sdl.K_CLEARAGAIN // "Clear / Again"
	KeyCrSel      = sdl.K_CRSEL      // "CrSel"
	KeyExSel      = sdl.K_EXSEL      // "ExSel"

	KeyKP00               = sdl.K_KP_00              // "Keypad 00" (the 00 key (numeric keypad))
	KeyKP000              = sdl.K_KP_000             // "Keypad 000" (the 000 key (numeric keypad))
	KeyThousandsSeparator = sdl.K_THOUSANDSSEPARATOR // "ThousandsSeparator" (the Thousands Separator key)
	KeyDecimalSeparator   = sdl.K_DECIMALSEPARATOR   // "DecimalSeparator" (the Decimal Separator key)
	KeyCurrencyUnit       = sdl.K_CURRENCYUNIT       // "CurrencyUnit" (the Currency Unit key)
	KeyCurrencySubUnit    = sdl.K_CURRENCYSUBUNIT    // "CurrencySubUnit" (the Currency Subunit key)
	KeyKPLeftParen        = sdl.K_KP_LEFTPAREN       // "Keypad (" (the Left Parenthesis key (numeric keypad))
	KeyKPRightParen       = sdl.K_KP_RIGHTPAREN      // "Keypad )" (the Right Parenthesis key (numeric keypad))
	KeyKPLeftBrace        = sdl.K_KP_LEFTBRACE       // "Keypad {" (the Left Brace key (numeric keypad))
	KeyKPRightBrace       = sdl.K_KP_RIGHTBRACE      // "Keypad }" (the Right Brace key (numeric keypad))
	KeyKPTab              = sdl.K_KP_TAB             // "Keypad Tab" (the Tab key (numeric keypad))
	KeyKPBackspace        = sdl.K_KP_BACKSPACE       // "Keypad Backspace" (the Backspace key (numeric keypad))
	KeyKPA                = sdl.K_KP_A               // "Keypad A" (the A key (numeric keypad))
	KeyKPB                = sdl.K_KP_B               // "Keypad B" (the B key (numeric keypad))
	KeyKPC                = sdl.K_KP_C               // "Keypad C" (the C key (numeric keypad))
	KeyKPD                = sdl.K_KP_D               // "Keypad D" (the D key (numeric keypad))
	KeyKPE                = sdl.K_KP_E               // "Keypad E" (the E key (numeric keypad))
	KeyKPF                = sdl.K_KP_F               // "Keypad F" (the F key (numeric keypad))
	KeyKPXor              = sdl.K_KP_XOR             // "Keypad XOR" (the XOR key (numeric keypad))
	KeyKPPower            = sdl.K_KP_POWER           // "Keypad ^" (the Power key (numeric keypad))
	KeyKPPercent          = sdl.K_KP_PERCENT         // "Keypad %" (the Percent key (numeric keypad))
	KeyKPLess             = sdl.K_KP_LESS            // "Keypad <" (the Less key (numeric keypad))
	KeyKPGreater          = sdl.K_KP_GREATER         // "Keypad >" (the Greater key (numeric keypad))
	KeyKPAmpersand        = sdl.K_KP_AMPERSAND       // "Keypad &" (the & key (numeric keypad))
	KeyKPDblAmpersand     = sdl.K_KP_DBLAMPERSAND    // "Keypad &&" (the && key (numeric keypad))
	KeyKPVerticalBar      = sdl.K_KP_VERTICALBAR     // "Keypad |" (the | key (numeric keypad))
	KeyKPDblVerticalBar   = sdl.K_KP_DBLVERTICALBAR  // "Keypad ||" (the || key (numeric keypad))
	KeyKPColon            = sdl.K_KP_COLON           // "Keypad :" (the : key (numeric keypad))
	KeyKPHash             = sdl.K_KP_HASH            // "Keypad #" (the # key (numeric keypad))
	KeyKPSpace            = sdl.K_KP_SPACE           // "Keypad Space" (the Space key (numeric keypad))
	KeyKPAt               = sdl.K_KP_AT              // "Keypad @" (the @ key (numeric keypad))
	KeyKPExclam           = sdl.K_KP_EXCLAM          // "Keypad !" (the ! key (numeric keypad))
	KeyKPMemStore         = sdl.K_KP_MEMSTORE        // "Keypad MemStore" (the Mem Store key (numeric keypad))
	KeyKPMemRecall        = sdl.K_KP_MEMRECALL       // "Keypad MemRecall" (the Mem Recall key (numeric keypad))
	KeyKPMemClear         = sdl.K_KP_MEMCLEAR        // "Keypad MemClear" (the Mem Clear key (numeric keypad))
	KeyKPMemAdd           = sdl.K_KP_MEMADD          // "Keypad MemAdd" (the Mem Add key (numeric keypad))
	KeyKPMemSubtract      = sdl.K_KP_MEMSUBTRACT     // "Keypad MemSubtract" (the Mem Subtract key (numeric keypad))
	KeyKPMemMultiply      = sdl.K_KP_MEMMULTIPLY     // "Keypad MemMultiply" (the Mem Multiply key (numeric keypad))
	KeyKPMemDivide        = sdl.K_KP_MEMDIVIDE       // "Keypad MemDivide" (the Mem Divide key (numeric keypad))
	KeyKPPlusMinus        = sdl.K_KP_PLUSMINUS       // "Keypad +/-" (the +/- key (numeric keypad))
	KeyKPClear            = sdl.K_KP_CLEAR           // "Keypad Clear" (the Clear key (numeric keypad))
	KeyKPClearEntry       = sdl.K_KP_CLEARENTRY      // "Keypad ClearEntry" (the Clear Entry key (numeric keypad))
	KeyKPBinary           = sdl.K_KP_BINARY          // "Keypad Binary" (the Binary key (numeric keypad))
	KeyKPOctal            = sdl.K_KP_OCTAL           // "Keypad Octal" (the Octal key (numeric keypad))
	KeyKPDecimal          = sdl.K_KP_DECIMAL         // "Keypad Decimal" (the Decimal key (numeric keypad))
	KeyKPHexadecimal      = sdl.K_KP_HEXADECIMAL     // "Keypad Hexadecimal" (the Hexadecimal key (numeric keypad))

	KeyLCtrl  = sdl.K_LCTRL  // "Left Ctrl"
	KeyLShift = sdl.K_LSHIFT // "Left Shift"
	KeyLAlt   = sdl.K_LALT   // "Left Alt" (alt, option)
	KeyLGui   = sdl.K_LGUI   // "Left GUI" (windows, command (apple), meta)
	KeyRCtrl  = sdl.K_RCTRL  // "Right Ctrl"
	KeyRShift = sdl.K_RSHIFT // "Right Shift"
	KeyRAlt   = sdl.K_RALT   // "Right Alt" (alt, option)
	KeyRGui   = sdl.K_RGUI   // "Right GUI" (windows, command (apple), meta)

	KeyMode = sdl.K_MODE // "ModeSwitch"

	KeyAudioNext   = sdl.K_AUDIONEXT    // "AudioNext" (the Next Track media key)
	KeyAudioPrev   = sdl.K_AUDIOPREV    // "AudioPrev" (the Previous Track media key)
	KeyAudioStop   = sdl.K_AUDIOSTOP    // "AudioStop" (the Stop media key)
	KeyAudioPlay   = sdl.K_AUDIOPLAY    // "AudioPlay" (the Play media key)
	KeyAudioMute   = sdl.K_AUDIOMUTE    // "AudioMute" (the Mute volume key)
	KeyMediaSelect = sdl.K_MEDIASELECT  // "MediaSelect" (the Media Select key)
	KeyWWW         = sdl.K_WWW          // "WWW" (the WWW/World Wide Web key)
	KeyMail        = sdl.K_MAIL         // "Mail" (the Mail/eMail key)
	KeyCalculator  = sdl.K_CALCULATOR   // "Calculator" (the Calculator key)
	KeyComputer    = sdl.K_COMPUTER     // "Computer" (the My Computer key)
	KeyACSearch    = sdl.K_AC_SEARCH    // "AC Search" (the Search key (application control keypad))
	KeyACHome      = sdl.K_AC_HOME      // "AC Home" (the Home key (application control keypad))
	KeyACBack      = sdl.K_AC_BACK      // "AC Back" (the Back key (application control keypad))
	KeyACForward   = sdl.K_AC_FORWARD   // "AC Forward" (the Forward key (application control keypad))
	KeyACStop      = sdl.K_AC_STOP      // "AC Stop" (the Stop key (application control keypad))
	KeyACRefresh   = sdl.K_AC_REFRESH   // "AC Refresh" (the Refresh key (application control keypad))
	KeyACBookmarks = sdl.K_AC_BOOKMARKS // "AC Bookmarks" (the Bookmarks key (application control keypad))

	KeyBrightnessDown = sdl.K_BRIGHTNESSDOWN // "BrightnessDown" (the Brightness Down key)
	KeyBrightnessUp   = sdl.K_BRIGHTNESSUP   // "BrightnessUp" (the Brightness Up key)
	KeyDisplaySwitch  = sdl.K_DISPLAYSWITCH  // "DisplaySwitch" (display mirroring/dual display switch, video mode switch)
	KeyKbdIllumtoggle = sdl.K_KBDILLUMTOGGLE // "KBDIllumToggle" (the Keyboard Illumination Toggle key)
	KeyKbdIllumdown   = sdl.K_KBDILLUMDOWN   // "KBDIllumDown" (the Keyboard Illumination Down key)
	KeyKbdIllumup     = sdl.K_KBDILLUMUP     // "KBDIllumUp" (the Keyboard Illumination Up key)
	KeyEject          = sdl.K_EJECT          // "Eject" (the Eject key)
	KeySleep          = sdl.K_SLEEP          // "Sleep" (the Sleep key)
)

Variables

View Source
var (
	Upwards    = Vec{0, -1}
	Downwards  = Vec{0, 1}
	Leftwards  = Vec{-1, 0}
	Rightwards = Vec{1, 0}
)
View Source
var (
	Black   = color.RGBA{0, 0, 0, 255}
	White   = color.RGBA{255, 255, 255, 255}
	Red     = color.RGBA{255, 0, 0, 255}
	Lime    = color.RGBA{0, 255, 0, 255}
	Blue    = color.RGBA{0, 0, 255, 255}
	Yellow  = color.RGBA{255, 255, 0, 255}
	Cyan    = color.RGBA{0, 255, 255, 255}
	Magenta = color.RGBA{255, 0, 255, 255}
	Silver  = color.RGBA{192, 192, 192, 255}
	Grey    = color.RGBA{128, 128, 128, 255}
	Maroon  = color.RGBA{128, 0, 0, 255}
	Olive   = color.RGBA{128, 128, 0, 255}
	Green   = color.RGBA{0, 128, 0, 255}
	Purple  = color.RGBA{128, 0, 128, 255}
	Teal    = color.RGBA{0, 128, 128, 255}
	Navy    = color.RGBA{0, 0, 128, 255}
)

Common colour set.

View Source
var (
	DarkRed              = color.RGBA{139, 0, 0, 255}
	Brown                = color.RGBA{165, 42, 42, 255}
	Firebrick            = color.RGBA{178, 34, 34, 255}
	Crimson              = color.RGBA{220, 20, 60, 255}
	Tomato               = color.RGBA{255, 99, 71, 255}
	Coral                = color.RGBA{255, 127, 80, 255}
	IndianRed            = color.RGBA{205, 92, 92, 255}
	LightCoral           = color.RGBA{240, 128, 128, 255}
	DarkSalmon           = color.RGBA{233, 150, 122, 255}
	Salmon               = color.RGBA{250, 128, 114, 255}
	LightSalmon          = color.RGBA{255, 160, 122, 255}
	OrangeRed            = color.RGBA{255, 69, 0, 255}
	DarkOrange           = color.RGBA{255, 140, 0, 255}
	Orange               = color.RGBA{255, 165, 0, 255}
	Gold                 = color.RGBA{255, 215, 0, 255}
	DarkGoldenRod        = color.RGBA{184, 134, 11, 255}
	GoldenRod            = color.RGBA{218, 165, 32, 255}
	PaleGoldenRod        = color.RGBA{238, 232, 170, 255}
	DarkKhaki            = color.RGBA{189, 183, 107, 255}
	Khaki                = color.RGBA{240, 230, 140, 255}
	YellowGreen          = color.RGBA{154, 205, 50, 255}
	DarkOliveGreen       = color.RGBA{85, 107, 47, 255}
	OliveDrab            = color.RGBA{107, 142, 35, 255}
	LawnGreen            = color.RGBA{124, 252, 0, 255}
	Chartreuse           = color.RGBA{127, 255, 0, 255}
	GreenYellow          = color.RGBA{173, 255, 47, 255}
	DarkGreen            = color.RGBA{0, 100, 0, 255}
	ForestGreen          = color.RGBA{34, 139, 34, 255}
	LimeGreen            = color.RGBA{50, 205, 50, 255}
	LightGreen           = color.RGBA{144, 238, 144, 255}
	PaleGreen            = color.RGBA{152, 251, 152, 255}
	DarkSeaGreen         = color.RGBA{143, 188, 143, 255}
	MediumSpringGreen    = color.RGBA{0, 250, 154, 255}
	SpringGreen          = color.RGBA{0, 255, 127, 255}
	SeaGreen             = color.RGBA{46, 139, 87, 255}
	MediumAquaMarine     = color.RGBA{102, 205, 170, 255}
	MediumSeaGreen       = color.RGBA{60, 179, 113, 255}
	LightSeaGreen        = color.RGBA{32, 178, 170, 255}
	DarkSlateGrey        = color.RGBA{47, 79, 79, 255}
	DarkCyan             = color.RGBA{0, 139, 139, 255}
	Aqua                 = color.RGBA{0, 255, 255, 255}
	LightCyan            = color.RGBA{224, 255, 255, 255}
	DarkTurquoise        = color.RGBA{0, 206, 209, 255}
	Turquoise            = color.RGBA{64, 224, 208, 255}
	MediumTurquoise      = color.RGBA{72, 209, 204, 255}
	PaleTurquoise        = color.RGBA{175, 238, 238, 255}
	AquaMarine           = color.RGBA{127, 255, 212, 255}
	PowderBlue           = color.RGBA{176, 224, 230, 255}
	CadetBlue            = color.RGBA{95, 158, 160, 255}
	SteelBlue            = color.RGBA{70, 130, 180, 255}
	CornBlowerBlue       = color.RGBA{100, 149, 237, 255}
	DeepSkyBlue          = color.RGBA{0, 191, 255, 255}
	DodgerBlue           = color.RGBA{30, 144, 255, 255}
	LightBlue            = color.RGBA{173, 216, 230, 255}
	SkyBlue              = color.RGBA{135, 206, 235, 255}
	LighSkyBlue          = color.RGBA{135, 206, 250, 255}
	MidnightBlue         = color.RGBA{25, 25, 112, 255}
	DarkBlue             = color.RGBA{0, 0, 139, 255}
	MediumBlue           = color.RGBA{0, 0, 205, 255}
	RoyalBlue            = color.RGBA{65, 105, 225, 255}
	BlueViolet           = color.RGBA{138, 43, 226, 255}
	Indigo               = color.RGBA{75, 0, 130, 255}
	DarkSlateBlue        = color.RGBA{72, 61, 139, 255}
	SlateBlue            = color.RGBA{106, 90, 205, 255}
	MediumSlateBlue      = color.RGBA{123, 104, 238, 255}
	MediumPurple         = color.RGBA{147, 112, 219, 255}
	DarkMagenta          = color.RGBA{139, 0, 139, 255}
	DarkViolet           = color.RGBA{148, 0, 211, 255}
	DarkOrchid           = color.RGBA{153, 50, 204, 255}
	MediumOrchid         = color.RGBA{186, 85, 211, 255}
	Thistle              = color.RGBA{216, 191, 216, 255}
	Plum                 = color.RGBA{221, 160, 221, 255}
	Violet               = color.RGBA{238, 130, 238, 255}
	Orchid               = color.RGBA{218, 112, 214, 255}
	MediumVioletRed      = color.RGBA{199, 21, 133, 255}
	PaleVioletRed        = color.RGBA{219, 112, 147, 255}
	DeepPink             = color.RGBA{255, 20, 147, 255}
	HotPink              = color.RGBA{255, 105, 180, 255}
	LightPink            = color.RGBA{255, 182, 193, 255}
	Pink                 = color.RGBA{255, 192, 203, 255}
	AntiqueWhite         = color.RGBA{250, 235, 215, 255}
	Beige                = color.RGBA{245, 245, 220, 255}
	Bisque               = color.RGBA{255, 228, 196, 255}
	BlanchedAlmond       = color.RGBA{255, 235, 205, 255}
	Wheat                = color.RGBA{245, 222, 179, 255}
	CornSilk             = color.RGBA{255, 248, 220, 255}
	LemonChiffon         = color.RGBA{255, 250, 205, 255}
	LightGoldenRodYellow = color.RGBA{250, 250, 210, 255}
	LightYellow          = color.RGBA{255, 255, 224, 255}
	SaddleBrown          = color.RGBA{139, 69, 19, 255}
	Sienna               = color.RGBA{160, 82, 45, 255}
	Chocolate            = color.RGBA{210, 105, 30, 255}
	Peru                 = color.RGBA{205, 133, 63, 255}
	SandyBrown           = color.RGBA{244, 164, 96, 255}
	BurlyWood            = color.RGBA{222, 184, 135, 255}
	Tan                  = color.RGBA{210, 180, 140, 255}
	RosyBrown            = color.RGBA{188, 143, 143, 255}
	Moccasin             = color.RGBA{255, 228, 181, 255}
	NavajoWhite          = color.RGBA{255, 222, 173, 255}
	PeachPuff            = color.RGBA{255, 218, 185, 255}
	MistyRose            = color.RGBA{255, 228, 225, 255}
	LavenderBlush        = color.RGBA{255, 240, 245, 255}
	Linen                = color.RGBA{250, 240, 230, 255}
	OldLace              = color.RGBA{253, 245, 230, 255}
	PapayaWhip           = color.RGBA{255, 239, 213, 255}
	SeaShell             = color.RGBA{255, 245, 238, 255}
	MintCream            = color.RGBA{245, 255, 250, 255}
	SlateGrey            = color.RGBA{112, 128, 144, 255}
	LightSlateGrey       = color.RGBA{119, 136, 153, 255}
	LightSteelBlue       = color.RGBA{176, 196, 222, 255}
	Lavender             = color.RGBA{230, 230, 250, 255}
	FloralWhite          = color.RGBA{255, 250, 240, 255}
	AliceBlue            = color.RGBA{240, 248, 255, 255}
	GhostWhite           = color.RGBA{248, 248, 255, 255}
	Honeydew             = color.RGBA{240, 255, 240, 255}
	Ivory                = color.RGBA{255, 255, 240, 255}
	Azure                = color.RGBA{240, 255, 255, 255}
	Snow                 = color.RGBA{255, 250, 250, 255}
	DimGrey              = color.RGBA{105, 105, 105, 255}
	DarkGrey             = color.RGBA{169, 169, 169, 255}
	LightGrey            = color.RGBA{211, 211, 211, 255}
	Gainsboro            = color.RGBA{220, 220, 220, 255}
	WhiteSmoke           = color.RGBA{245, 245, 245, 255}
)

Extra colours for if you're feeling artistic.

View Source
var DefaultStyle = Style{
	Colour:    color.RGBA{0xff, 0xff, 0xff, 0xff},
	Thickness: 0,
	Bloom:     0,
}

DefaultStyle is the default style for new shapes.

Functions

func Clamp

func Clamp[T constraints.Ordered](x, lower, upper T) T

Clamp constraints a variable between lower and upper bounds.

func Cross

func Cross(v1, v2 Vec) float64

Cross calculates the cross product of two vectors.

func Dist

func Dist(v1, v2 Vec) float64

Dist returns the distance between two vectors, assuming they both originate from the same point.

func Dot

func Dot(v1, v2 Vec) float64

Dot calculates the dot product between two vectors.

func DrawLine

func DrawLine(v1, v2 Vec, buf *FrameBuffer)

DrawLine draws a single pixel line using Bresenham's line drawing algorithm.

func IsColliding

func IsColliding(s1, s2 Shape) bool

IsColliding returns true if two shapes are colliding.

func RGB

func RGB(r, g, b uint8) color.RGBA

RBG constructs a color.RGBA with maximum alpha.

func RGBA8

func RGBA8(c color.Color) (r, g, b, a uint8)

RGBA8 returns a colour in uint8 format.

func Theta

func Theta(v1, v2 Vec) float64

Theta calculates the angle between two vectors, in radians.

func UNUSED

func UNUSED(...any)

Types

type Alignment

type Alignment int

Alignment is used to specify alignment relative to the position coordinate.

const (
	AlignTopLeft Alignment = iota
	AlignTopCentre
	AlignTopRight
	AlignCentreLeft
	AlignCentre
	AlignCentreRight
	AlignBottomLeft
	AlignBottomCentre
	AlignBottomRight
	AlignCustom
)

type BlendFunc

type BlendFunc func(src, dst Pixel) Pixel

BlendFunc is a function that blends a source pixel with a destination pixel.

type Button

type Button struct {
	Shape     hoverable                // the base shape the button is built on
	Label     *Text                    // the text to display on the button (if any)
	Callbacks map[ButtonTrigger]func() // mapping of triggers to callback functions
	IsEnabled bool                     // stops callbacks from executing if false
	// contains filtered or unexported fields
}

Button can be build on top of shapes to create pressable buttons.

func NewButton

func NewButton(shape hoverable, fontPath string) *Button

NewButton constructs a new button from any shape that satisfies the buttonable interface.

func (*Button) Disable

func (b *Button) Disable() *Button

Disable disables the button. If it is already disabled, nothing happens.

func (*Button) Draw

func (b *Button) Draw(buf *FrameBuffer)

Draw draws the button onto the frame buffer.

func (*Button) Enable

func (b *Button) Enable() *Button

Enable enables the button. If it is already enabled, nothing happens.

func (*Button) IsHovering

func (b *Button) IsHovering() bool

IsHovering returns whether the cursor is hovering over the button.

func (*Button) Move

func (b *Button) Move(mov Vec)

Move moves the button by a given vector.

func (*Button) SetCallback

func (b *Button) SetCallback(trigger ButtonTrigger, callback func()) *Button

SetCallback configures a callback function to execute if the conditions described by the trigger are met.

func (*Button) SetLabelAlignment

func (b *Button) SetLabelAlignment(align Alignment) *Button

SetLabelAlignment sets the alignment of the text label relative to the centre of the shape.

func (*Button) SetLabelColour

func (b *Button) SetLabelColour(c color.Color) *Button

SetLabelColour sets the label text colour.

func (*Button) SetLabelDPI

func (b *Button) SetLabelDPI(dpi float64) *Button

SetLabelDPI sets the DPI of the label font.

func (*Button) SetLabelFont

func (b *Button) SetLabelFont(path string) error

SetLabelFont sets the path of the .ttf file that is used to generate the label.

func (*Button) SetLabelOffset

func (b *Button) SetLabelOffset(offset Vec) *Button

SetLabelOffset manually sets the label's offset, providing the text is in AlignCustom mode.

func (*Button) SetLabelPos

func (b *Button) SetLabelPos(pos Vec) *Button

SetLabelPos sets the label's position on the screen.

func (*Button) SetLabelSize

func (b *Button) SetLabelSize(size float64) *Button

SetLabelSize sets the size of the label font.

func (*Button) SetLabelSpacing

func (b *Button) SetLabelSpacing(spacing float64) *Button

SetLabelSpacing sets the line spacing of the label.

func (*Button) SetLabelText

func (b *Button) SetLabelText(s string) *Button

SetLabelText sets the text label to the given string.

func (*Button) UnsetCallback

func (b *Button) UnsetCallback(trigger ButtonTrigger) *Button

UnsetCallback removes a callback for a specified trigger. If no callback is configured, nothing will happen.

func (*Button) Update

func (b *Button) Update(win *Window)

Update examines button state and executes behaviour accordingly.

type ButtonBehaviour

type ButtonBehaviour int

ButtonBehaviour represents how a button responds to being pressed.

const (
	OnAll             ButtonBehaviour = iota // execute behaviour every time Update() is called
	OnPress                                  // execute behaviour on press
	OnRelease                                // execute behaviour on release
	OnPressAndRelease                        // execute behaviour on press and release
	OnHold                                   // execute behaviour as long as button is held down
)

type ButtonTrigger

type ButtonTrigger struct {
	// State is the state of the mouse buttons in a given moment.
	State MouseState
	// Behaviour describes at what point of the mouse click to execute the callback on.
	Behaviour ButtonBehaviour
}

ButtonTrigger is a trigger for executing a button callback function.

type Circle

type Circle struct {
	Pos       Vec
	Direction Vec
	// contains filtered or unexported fields
}

Cicle is a circle shape, aligned to the centre of the circle.

func NewCircle

func NewCircle(diameter float64, pos Vec) *Circle

NewCircle constructs a new circle.

func (*Circle) Draw

func (c *Circle) Draw(buf *FrameBuffer)

Draw draws the circle onto the provided frame buffer.

func (*Circle) DrawCircleSegment

func (c *Circle) DrawCircleSegment(limitDir Vec, buf *FrameBuffer)

DrawCircleSegment draws only a segment of the circle to the frame buffer, limited by the provided vector.

func (*Circle) EdgePoint

func (c *Circle) EdgePoint(theta float64) Vec

EdgePoint generates a point the point on the circle's perimeter that is theta radians clockwise from the circle's direction.

func (*Circle) GetPos

func (c *Circle) GetPos() Vec

GetPos returns the position of the circle.

func (*Circle) GetStyle

func (c *Circle) GetStyle() Style

GetStyle returns the style of the circle.

func (*Circle) Height

func (c *Circle) Height() float64

Height returns the pixel height of the circle.

func (*Circle) IsWithin

func (c *Circle) IsWithin(pos Vec) bool

IsWithin returns whether a position lies within the circle's perimeter.

func (*Circle) Move

func (c *Circle) Move(px Vec)

Move moves the circle's position by the given pixel vector.

func (*Circle) SetDiameter

func (c *Circle) SetDiameter(px float64) *Circle

SetDiameter sets the diameter of the circle, in pixels.

func (*Circle) SetPos

func (c *Circle) SetPos(pos Vec)

SetPos sets the position of the circle.

func (*Circle) SetStyle

func (c *Circle) SetStyle(style Style) *Circle

SetStyle sets the style of the circle.

func (*Circle) String

func (c *Circle) String() string

String returns the type of shape as a string.

func (*Circle) Width

func (c *Circle) Width() float64

Width returns the pixel width of the circle.

type CurvedRect

type CurvedRect struct {
	Pos       Vec
	Direction Vec
	// contains filtered or unexported fields
}

CurvedRect is a rectangle with rounded corners, aligned to the top-left.

func NewCurvedRect

func NewCurvedRect(width, height, radius float64, pos Vec) *CurvedRect

NewCurvedRect constructs a new curved rectangle.

func (*CurvedRect) Draw

func (r *CurvedRect) Draw(buf *FrameBuffer)

Draw draws the curved rectangle onto the provided frame buffer.

func (*CurvedRect) GetPos

func (r *CurvedRect) GetPos() Vec

GetPos returns the position of the curved rectangle.

func (*CurvedRect) GetStyle

func (r *CurvedRect) GetStyle() Style

GetStyle returns's the curved rectangle's style.

func (*CurvedRect) Height

func (r *CurvedRect) Height() float64

Height returns the pixel height of the curved rectangle.

func (*CurvedRect) IsWithin

func (r *CurvedRect) IsWithin(pos Vec) bool

IsWithin returns whether a position lies within the curved rectangle's perimeter.

func (*CurvedRect) Move

func (r *CurvedRect) Move(px Vec)

Move moves the curved rectangle by the given vector.

func (*CurvedRect) SetHeight

func (r *CurvedRect) SetHeight(px float64) *CurvedRect

SetHeight sets the height of the curved rectangle.

func (*CurvedRect) SetPos

func (r *CurvedRect) SetPos(pos Vec)

SetPos sets the position of the curved rectangle.

func (*CurvedRect) SetStyle

func (r *CurvedRect) SetStyle(style Style) *CurvedRect

SetStyle sets the style of the curved rectangle.

func (*CurvedRect) SetWidth

func (r *CurvedRect) SetWidth(px float64) *CurvedRect

SetWidth sets the width of the curved rectangle.

func (*CurvedRect) String

func (r *CurvedRect) String() string

String returns the type of shape as a string.

func (*CurvedRect) Width

func (r *CurvedRect) Width() float64

Width returns the pixel width of the curved rectangle.

type Drawable

type Drawable interface {
	// Draw draws to a frame buffer.
	Draw(*FrameBuffer)
}

Drawable is an interface for things that can be drawn onto a frame buffer.

type FrameBuffer

type FrameBuffer [][]Pixel

FrameBuffer is a 2D slice of pixels which represents a screen.

func NewFrameBuffer

func NewFrameBuffer(width, height int) *FrameBuffer

NewFrameBuffer constructs a new frame buffer with a particular width and height.

func (*FrameBuffer) Bytes

func (f *FrameBuffer) Bytes() []byte

Bytes returns the frame buffer as a one-dimensional slice of bytes.

func (*FrameBuffer) Clear

func (f *FrameBuffer) Clear()

Clear sets every pixel in the frame buffer to zero.

func (*FrameBuffer) Fill

func (f *FrameBuffer) Fill(c color.Color)

Fill sets every pixel in the frame buffer to the provided colour.

func (*FrameBuffer) GetPixel

func (f *FrameBuffer) GetPixel(x, y int) Pixel

GetPixel returns a copy of the pixel at the specified coordinates.

func (*FrameBuffer) Height

func (f *FrameBuffer) Height() int

Height returns the height of the frame buffer.

func (*FrameBuffer) SetPixel

func (f *FrameBuffer) SetPixel(x, y int, p Pixel)

SetPixel sets a pixel in the frame buffer. If the requested pixel is out of bounds, nothing happens. The default alpha blending technique is used. To use other blending methods, see SetPixelFunc.

func (*FrameBuffer) SetPixelFunc

func (f *FrameBuffer) SetPixelFunc(x, y int, p Pixel, fn BlendFunc)

SetPixelFunc sets a pixe in the frame buffer using the specified blend function.

func (*FrameBuffer) Width

func (f *FrameBuffer) Width() int

Width returns the width of the frame buffer.

func (*FrameBuffer) WithinFrame

func (f *FrameBuffer) WithinFrame(point Vec, padding float64) bool

WithinFrame returns true if the given point lies within the boundary of the frame buffer, taking the padding value into account.

type KeybindMode

type KeybindMode int

KeybindMode describes how a callback is executed after a bound key is pressed.

const (
	Instantaneous KeybindMode = iota // callback executed continuously while is pressed
	KeyPress                         // callback executed on press
	KeyRelease                       // callback executed on release
)

type MouseScrollCallback

type MouseScrollCallback func(movement Vec)

MouseScrollCallback is executed when the user scrolls the mouse wheel in any direction.

Positive X movement means scrolling to the right. Positive Y movement means scrolling up.

type MouseState

type MouseState int

MouseState represents the state of the mouse buttons.

const (
	NoClick           MouseState = 0
	LeftClick         MouseState = 1
	RightClick        MouseState = 4
	LeftAndRightClick MouseState = 5
)

func (MouseState) String

func (m MouseState) String() string

String returns the mouse state as a string.

type Pixel

type Pixel [pxLen]uint8

Pixel represents a pixel, with bytes [red, green, blue, alpha].

func AdditiveBlend

func AdditiveBlend(src, dst Pixel) Pixel

AdditiveBlend blends a source pixel with a destination pixel by adding the values of each channel.

func AlphaBlend

func AlphaBlend(src, dst Pixel) Pixel

AlphaBlend blends a source pixel over a destination pixel using the Porter-Duff source-over operator. This results in the source pixel having a greater impact on the resulting colour.

func NewPixel

func NewPixel(c color.Color) Pixel

NewPixel constructs a new coloured pixel.

func (Pixel) A

func (p Pixel) A() uint8

A returns the value of the alpha channel.

func (Pixel) B

func (p Pixel) B() uint8

B returns the value of the blue channel.

func (Pixel) G

func (p Pixel) G() uint8

G returns the value of the green channel.

func (Pixel) R

func (p Pixel) R() uint8

R returns the value of the red channel.

type Polygon

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

Polygon is a 2D shape with 3 or more sides.

func NewPolygon

func NewPolygon(vecs []Vec) *Polygon

NewPolygon constructs a polygon from the specified vertices. The order of the vertices dictates the edges of the polygon. The final vertex is always linked to the first.

func (*Polygon) Draw

func (p *Polygon) Draw(buf *FrameBuffer)

Draw draws the polygon onto the provided frame buffer.

func (*Polygon) Move

func (p *Polygon) Move(mov Vec)

Move modifies the position of the polygon by the given vector.

func (*Polygon) SetStyle

func (p *Polygon) SetStyle(s Style) *Polygon

SetStyle sets the style of a polygon.

func (*Polygon) Style

func (p *Polygon) Style() Style

Style returns a copy of the polygon's style.

type Rect

type Rect struct {
	Pos       Vec
	Direction Vec
	// contains filtered or unexported fields
}

Rect is a rectangle shape, aligned to the top-left corner.

func NewRect

func NewRect(width, height float64, pos Vec) *Rect

NewRect constructs a new rectangle shape.

func (*Rect) Draw

func (r *Rect) Draw(buf *FrameBuffer)

Draw draws the rectangle onto the provided frame buffer.

func (*Rect) GetPos

func (r *Rect) GetPos() Vec

GetPos returns the position of the rectangle.

func (*Rect) GetStyle

func (r *Rect) GetStyle() Style

GetStyle returns's the rectangle's style.

func (*Rect) Height

func (r *Rect) Height() float64

Height returns the pixel height of the rectangle.

func (*Rect) IsWithin

func (r *Rect) IsWithin(pos Vec) bool

IsWithin returns whether a position lies within the rectangle's perimeter.

func (*Rect) Move

func (r *Rect) Move(px Vec)

Move moves the rectangle by the given vector.

func (*Rect) SetHeight

func (r *Rect) SetHeight(px float64) *Rect

SetHeight sets the height of the rectangle.

func (*Rect) SetPos

func (r *Rect) SetPos(pos Vec)

SetPos sets the position of the rectangle.

func (*Rect) SetStyle

func (r *Rect) SetStyle(style Style) *Rect

SetStyle sets the style of the rectangle.

func (*Rect) SetWidth

func (r *Rect) SetWidth(px float64) *Rect

SetWidth sets the width of the rectangle.

func (*Rect) String

func (r *Rect) String() string

String returns the type of shape as a string.

func (*Rect) Width

func (r *Rect) Width() float64

Width returns the pixel width of the rectangle.

type Shape

type Shape interface {
	Drawable

	// Width returns the width of the shape in pixels.
	Width() float64
	// Height returns the height of she shape in pixels.
	Height() float64
	// GetPos returns the position of the shape.
	GetPos() Vec
	// SetPos sets the position of the shape.
	SetPos(Vec)
	// GetStyle returns the shape's style.
	GetStyle() Style
	// Move moves the shape by a pixel vector.
	Move(Vec)
	// String returns the name of the shape.
	String() string
}

Shape is an interface for shapes.

type Style

type Style struct {
	Colour    color.Color
	Thickness float64 // leave 0 for solid
	Bloom     int     // bloom reach, in pixels
}

Style contains style information for a shape.

func RandomStyle

func RandomStyle() Style

RandomStyle generates a style of random colour and thickness 0.

type Text

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

Text is a customisable block of text.

func NewText

func NewText(body string, pos Vec, fontPath string) *Text

NewText constructs a new text object with default parameters. The default font size is 20.

func (*Text) Alignment

func (t *Text) Alignment() Alignment

Text returns the current alignment.

func (*Text) Colour

func (t *Text) Colour() color.Color

Colour returns the current colour.

func (*Text) DPI

func (t *Text) DPI() float64

DPI returns the current DPI of the font.

func (*Text) Draw

func (t *Text) Draw(buf *FrameBuffer)

Draw draws the text onto the provided frame buffer.

func (*Text) Move

func (t *Text) Move(mov Vec)

Move moves the text by a given vector.

func (*Text) Offset

func (t *Text) Offset() Vec

Offset returns the text's offset.

func (*Text) Pos

func (t *Text) Pos() Vec

Pos returns the current position.

func (*Text) SetAlignment

func (t *Text) SetAlignment(align Alignment) *Text

SetText sets the text alignment.

func (*Text) SetColour

func (t *Text) SetColour(c color.Color) *Text

SetColour sets the text's colour.

func (*Text) SetDPI

func (t *Text) SetDPI(dpi float64) *Text

SetDPI sets the DPI of the font.

func (*Text) SetFont

func (t *Text) SetFont(path string) error

SetPath sets the path fo the .ttf file that is used to generate the text.

func (*Text) SetOffset

func (t *Text) SetOffset(offset Vec) *Text

SetOffset sets the text's offset. Note: this overwrites existing alignment settings.

func (*Text) SetPos

func (t *Text) SetPos(pos Vec) *Text

SetPos sets the text's position.

func (*Text) SetSize

func (t *Text) SetSize(size float64) *Text

SetSize sets the size of the font.

func (*Text) SetSpacing

func (t *Text) SetSpacing(spacing float64) *Text

SetSpacing sets the line spacing.

func (*Text) SetText

func (t *Text) SetText(txt string) *Text

SetText sets the text content.

func (*Text) Size

func (t *Text) Size() float64

Size returns the current font size.

func (*Text) Spacing

func (t *Text) Spacing() float64

Spacing returns the line spacing.

func (*Text) Text

func (t *Text) Text() string

Text returns the current text content.

type TextBox

type TextBox struct {
	Shape hoverable // the base shape the text box is built on
	Text  *Text     // the text in the text box
	// contains filtered or unexported fields
}

TextBox is a shape that can be typed in.

func NewTextBox

func NewTextBox(shape hoverable, text, fontPath string) *TextBox

NewTextBox constructs a new text box from a hoverable shape.

func (*TextBox) Draw

func (t *TextBox) Draw(buf *FrameBuffer)

Draw draws the text box onto the frame buffer.

func (*TextBox) IsEditing

func (t *TextBox) IsEditing() bool

IsEditing returns whether the text box is in edit mode.

func (*TextBox) Move

func (t *TextBox) Move(mov Vec)

Move moves the text box by a given vector.

func (*TextBox) SetCallback

func (t *TextBox) SetCallback(callback func()) *TextBox

SetCallback configures a callback function to execute every time the text in the text box is updated by the user.

func (*TextBox) SetDeselectedCB

func (t *TextBox) SetDeselectedCB(fn func()) *TextBox

SetDeselectedCB sets the callback function which is triggered when the text box is deselected.

func (*TextBox) SetEditing

func (t *TextBox) SetEditing(editMode bool) *TextBox

SetEditing sets whether the text box is in edit mode or not.

func (*TextBox) SetModifiedCB

func (t *TextBox) SetModifiedCB(fn func()) *TextBox

SetModifiedCB sets the callback function which is triggered when the text is modified.

func (*TextBox) SetPos

func (t *TextBox) SetPos(pos Vec) *TextBox

SetPos sets the position of the text box.

func (*TextBox) SetSelectedCB

func (t *TextBox) SetSelectedCB(fn func()) *TextBox

SetSelectedCB sets the callback function which is triggered when the text box is selected.

func (*TextBox) SetText

func (t *TextBox) SetText(s string) *TextBox

SetText sets the text to the given string.

func (*TextBox) SetTextAlignment

func (t *TextBox) SetTextAlignment(align Alignment) *TextBox

SetTextAlignment sets the alignment of the text relative to the text box.

func (*TextBox) SetTextColour

func (t *TextBox) SetTextColour(c color.Color) *TextBox

SetTextColour sets the text colour.

func (*TextBox) SetTextDPI

func (t *TextBox) SetTextDPI(dpi float64) *TextBox

SetTextDPI sets the DPI of the text font.

func (*TextBox) SetTextFont

func (t *TextBox) SetTextFont(path string) error

SetTextFont sets the path fo the .ttf file that is used to generate the text.

func (*TextBox) SetTextOffset

func (t *TextBox) SetTextOffset(offset Vec) *TextBox

SetTextOffset manually sets the text's offset, providing the text is in AlignCustom mode.

func (*TextBox) SetTextSize

func (t *TextBox) SetTextSize(size float64) *TextBox

SetTextSize sets the size of the text font.

func (*TextBox) SetTextSpacing

func (t *TextBox) SetTextSpacing(spacing float64) *TextBox

SetTextSpacing sets the line spacing of the text.

func (*TextBox) Update

func (t *TextBox) Update(win *Window)

Update handles user interactions with the text box.

type Triangle

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

Triangle is triangle shape, defined by the position of its vertices.

func NewTriangle

func NewTriangle(v1, v2, v3 Vec) *Triangle

NewTriangle constructs a new triangle from the provided vertices.

func (*Triangle) Draw

func (t *Triangle) Draw(buf *FrameBuffer)

Draw rasterises and draws the triangle onto the provided frame buffer.

func (*Triangle) SetStyle

func (t *Triangle) SetStyle(s Style) *Triangle

SetStyle sets the style of a triangle.

func (*Triangle) Style

func (t *Triangle) Style() Style

Style returns a copy of the triangle's style.

type Vec

type Vec struct{ X, Y float64 }

Vec is a Cartesian vector.

func Add

func Add(v1, v2 Vec) Vec

Add adds vector v2 to v1.

func GenerateCatmullRomSpline

func GenerateCatmullRomSpline(points []Vec, steps int) []Vec

GenerateCatmullRomSpline generates a series of points on a Catmull-Rom spline that passes through the given points.

func Normalise

func Normalise(v Vec) Vec

Normalise returns a unit vector with the same direction.

func Sub

func Sub(v1, v2 Vec) Vec

Sub subtracts vector v2 from v1.

func (Vec) IsScrollDown

func (v Vec) IsScrollDown() bool

IsScrollDown returns true if the mouse scroll vector is downwards.

func (Vec) IsScrollLeft

func (v Vec) IsScrollLeft() bool

IsScrollLeft returns true if the mouse scroll vector is leftwards.

func (Vec) IsScrollRight

func (v Vec) IsScrollRight() bool

IsScrollRight returns true if the mouse scroll vector is rightwards.

func (Vec) IsScrollUp

func (v Vec) IsScrollUp() bool

IsScrollUp returns true if the mouse scroll vector is upwards.

func (Vec) Mag

func (v Vec) Mag() float64

Mag calculates the magnitude of a vector.

func (Vec) Rotate

func (v Vec) Rotate(theta float64) Vec

Rotate rotates a vector clockwise by theta radians, preserving the magnitude.

func (Vec) Round

func (v Vec) Round() Vec

Round rounds the components of the vector to the nearest whole numbers.

func (Vec) SetMag

func (v Vec) SetMag(newMag float64) Vec

SetMag sets the magnitude of the vector whilst preserving the direction.

func (Vec) String

func (v Vec) String() string

String returns a human-readable version of the vector.

type Window

type Window struct {
	Framebuffer *FrameBuffer
	// contains filtered or unexported fields
}

Window represents an OS Window.

func NewWindow

func NewWindow(cfg WindowCfg) (*Window, error)

NewWindow constructs a new window according to the provided configuration.

Call Destroy to deallocate the window.

func (*Window) Destroy

func (w *Window) Destroy()

Destroy deallocates the window's resources. Call it at the end of your application.

func (*Window) Draw

func (w *Window) Draw(s Drawable)

Draw draws a shape to the window.

func (*Window) DropKeybinds

func (w *Window) DropKeybinds()

DropKeybinds unregisters all keybinds.

func (*Window) GetConfig

func (w *Window) GetConfig() WindowCfg

GetConfig returns a copy of the window's config.

func (*Window) Height

func (w *Window) Height() int

Height returns the height of the window in pixels.

func (*Window) IsRunning

func (w *Window) IsRunning() bool

IsRunning returns true while the window is running.

func (*Window) KeyIsPressed

func (w *Window) KeyIsPressed(key sdl.Keycode) bool

KeyIsPressed returns whether a given key is currently pressed.

func (*Window) MouseButtonState

func (w *Window) MouseButtonState() MouseState

MouseButtonState returns the current state of the mouse buttons.

func (*Window) MouseLocation

func (w *Window) MouseLocation() Vec

MouseLocation returns the location of the mouse cursor, relative to the origin of the window.

func (*Window) Quit

func (w *Window) Quit()

Quit signals the window to exit.

func (*Window) RegisterKeybind

func (w *Window) RegisterKeybind(key sdl.Keycode, mode KeybindMode, callback func())

RegisterKeybind sets a callback function which is executed when a key is pressed. The callback can be executed always while the key is pressed, on press, or on release.

func (*Window) SetBackground

func (w *Window) SetBackground(c color.Color)

SetBackground sets the background to a uniform colour.

func (*Window) SetMouseScrollCallback

func (w *Window) SetMouseScrollCallback(cb MouseScrollCallback)

SetMouseScrollCallback sets a callback to be executed on mouse scroll events.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle sets the title of the window to the provided string.

func (*Window) UnregisterKeybind

func (w *Window) UnregisterKeybind(key sdl.Keycode, mode KeybindMode)

RegisterKeybind removes a keybind for a specific key mode combination.

func (*Window) Update

func (w *Window) Update()

func (*Window) Width

func (w *Window) Width() int

Width returns the width of the window in pixels.

type WindowCfg

type WindowCfg struct {
	// Title is the title of the window.
	Title string
	// Width, Height specifies the dimensions of the window, in pixels.
	Width, Height int
	// Icon is the image used for the window icon. Default if nil.
	Icon *os.File
	// Resizable can be set to true to allow the window to be resizable.
	Resizable bool
}

WindowCfg contains adjustable configuration for a window.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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