windstorm

package module
v0.0.0-...-39b626a Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2017 License: MIT Imports: 2 Imported by: 0

README

Windstorm

Windstorm is a simple window creation library for Go. It creates OpenGL contexts and handles user input.

Why?

When I created this, there weren't as many great Go solutions to this problem. If you need a window creation library, you should use the shiny library, which is actively developed by some big names in the Go community.

Because there are better solutions to this problem now, and because this library never caught on anyway, I am no longer maintaining this library.

Installation

In many cases, Windstorm can be installed with a simple call to "go get". However, some Linux distributions may not come with the X development libraries. This should be an easy install from your package manager of choice.

Use

In many ways, Windstorm is used in a similar way to other, similar libraries. However, when it comes to user input, it takes a very different approach. Instead of using callbacks, Windstorm uses channels to communicate events. This allows for greater control over how your program is structured. Input could be managed comfortably within the main loop, handled in a separate goroutine, or set up to simply run functions in a callback-like manner, if you prefer.

As far as drawing is concerned, you're given a OpenGL context to do anything you'd like with. Just make sure to run SwapBuffers to let Windstorm know you're done drawing a frame.

TODO

  • Windows support (In progress)
  • Mac support
  • Joystick input
  • Fullscreen support

Documentation

Overview

Package windstorm is a window creation library for Go.

Index

Constants

View Source
const (
	MouseButton1 = MouseButton(C.Button1)
	MouseButton2 = MouseButton(C.Button2)
	MouseButton3 = MouseButton(C.Button3)
	MouseButton4 = MouseButton(C.Button4)
	MouseButton5 = MouseButton(C.Button5)
)

Constants representing mouse buttons.

View Source
const (
	KeySpace        = Key(C.XK_space)
	KeyApostrophe   = Key(C.XK_apostrophe)
	KeyComma        = Key(C.XK_comma)
	KeyMinus        = Key(C.XK_minus)
	KeyPeriod       = Key(C.XK_period)
	KeySlash        = Key(C.XK_slash)
	Key0            = Key(C.XK_0)
	Key1            = Key(C.XK_1)
	Key2            = Key(C.XK_2)
	Key3            = Key(C.XK_3)
	Key4            = Key(C.XK_4)
	Key5            = Key(C.XK_5)
	Key6            = Key(C.XK_6)
	Key7            = Key(C.XK_7)
	Key8            = Key(C.XK_8)
	Key9            = Key(C.XK_9)
	KeySemicolon    = Key(C.XK_semicolon)
	KeyEqual        = Key(C.XK_equal)
	KeyA            = Key(C.XK_A)
	KeyB            = Key(C.XK_B)
	KeyC            = Key(C.XK_C)
	KeyD            = Key(C.XK_D)
	KeyE            = Key(C.XK_E)
	KeyF            = Key(C.XK_F)
	KeyG            = Key(C.XK_G)
	KeyH            = Key(C.XK_H)
	KeyI            = Key(C.XK_I)
	KeyJ            = Key(C.XK_J)
	KeyK            = Key(C.XK_K)
	KeyL            = Key(C.XK_L)
	KeyM            = Key(C.XK_M)
	KeyN            = Key(C.XK_N)
	KeyO            = Key(C.XK_O)
	KeyP            = Key(C.XK_P)
	KeyQ            = Key(C.XK_Q)
	KeyR            = Key(C.XK_R)
	KeyS            = Key(C.XK_S)
	KeyT            = Key(C.XK_T)
	KeyU            = Key(C.XK_U)
	KeyV            = Key(C.XK_V)
	KeyW            = Key(C.XK_W)
	KeyX            = Key(C.XK_X)
	KeyY            = Key(C.XK_Y)
	KeyZ            = Key(C.XK_Z)
	KeyLeftBracket  = Key(C.XK_bracketleft)
	KeyBackslash    = Key(C.XK_backslash)
	KeyRightBracket = Key(C.XK_bracketright)
	KeyGraveAccent  = Key(C.XK_grave)
	KeyEscape       = Key(C.XK_Escape)
	KeyEnter        = Key(C.XK_Return)
	KeyTab          = Key(C.XK_Tab)
	KeyBackspace    = Key(C.XK_BackSpace)
	KeyInsert       = Key(C.XK_Insert)
	KeyDelete       = Key(C.XK_Delete)
	KeyRight        = Key(C.XK_Right)
	KeyLeft         = Key(C.XK_Left)
	KeyDown         = Key(C.XK_Down)
	KeyUp           = Key(C.XK_Up)
	KeyPageUp       = Key(C.XK_Page_Up)
	KeyPageDown     = Key(C.XK_Page_Down)
	KeyHome         = Key(C.XK_Home)
	KeyEnd          = Key(C.XK_End)
	KeyCapsLock     = Key(C.XK_Caps_Lock)
	KeyScrollLock   = Key(C.XK_Scroll_Lock)
	KeyNumLock      = Key(C.XK_Num_Lock)
	KeyPrKeyScreen  = Key(C.XK_3270_PrintScreen)
	KeyPause        = Key(C.XK_Pause)
	KeyF1           = Key(C.XK_F1)
	KeyF2           = Key(C.XK_F2)
	KeyF3           = Key(C.XK_F3)
	KeyF4           = Key(C.XK_F4)
	KeyF5           = Key(C.XK_F5)
	KeyF6           = Key(C.XK_F6)
	KeyF7           = Key(C.XK_F7)
	KeyF8           = Key(C.XK_F8)
	KeyF9           = Key(C.XK_F9)
	KeyF10          = Key(C.XK_F10)
	KeyF11          = Key(C.XK_F11)
	KeyF12          = Key(C.XK_F12)
	KeyF13          = Key(C.XK_F13)
	KeyF14          = Key(C.XK_F14)
	KeyF15          = Key(C.XK_F15)
	KeyF16          = Key(C.XK_F16)
	KeyF17          = Key(C.XK_F17)
	KeyF18          = Key(C.XK_F18)
	KeyF19          = Key(C.XK_F19)
	KeyF20          = Key(C.XK_F20)
	KeyF21          = Key(C.XK_F21)
	KeyF22          = Key(C.XK_F22)
	KeyF23          = Key(C.XK_F23)
	KeyF24          = Key(C.XK_F24)
	KeyKp0          = Key(C.XK_KP_0)
	KeyKp1          = Key(C.XK_KP_1)
	KeyKp2          = Key(C.XK_KP_2)
	KeyKp3          = Key(C.XK_KP_3)
	KeyKp4          = Key(C.XK_KP_4)
	KeyKp5          = Key(C.XK_KP_5)
	KeyKp6          = Key(C.XK_KP_6)
	KeyKp7          = Key(C.XK_KP_7)
	KeyKp8          = Key(C.XK_KP_8)
	KeyKp9          = Key(C.XK_KP_9)
	KeyKpDecimal    = Key(C.XK_KP_Decimal)
	KeyKpDivide     = Key(C.XK_KP_Divide)
	KeyKpMultiply   = Key(C.XK_KP_Multiply)
	KeyKpSubtract   = Key(C.XK_KP_Subtract)
	KeyKpAdd        = Key(C.XK_KP_Add)
	KeyKpEnter      = Key(C.XK_KP_Enter)
	KeyKpEqual      = Key(C.XK_KP_Equal)
	KeyLeftShift    = Key(C.XK_Shift_L)
	KeyRightShift   = Key(C.XK_Shift_R)
	KeyLeftControl  = Key(C.XK_Control_L)
	KeyLeftAlt      = Key(C.XK_Alt_L)
	KeyLeftSuper    = Key(C.XK_Super_L)
	KeyRightControl = Key(C.XK_Control_R)
	KeyRightAlt     = Key(C.XK_Alt_R)
	KeyRightSuper   = Key(C.XK_Super_R)
	KeyMenu         = Key(C.XK_Menu)
)

Constants representing keyboard buttons.

Variables

This section is empty.

Functions

func Stop

func Stop()

Stop stops the library. This should only be called if no more Windstorm tasks will be done for the duration of the program.

Types

type Action

type Action int

Action is a constant type for key and button states.

const (
	Press Action
	Release
)

Constants representing button and key states.

type CloseEvent

type CloseEvent struct {
}

CloseEvent represents a request for a window to close.

type FocusEvent

type FocusEvent struct {
	Focused bool
}

FocusEvent represents a change in window focus.

type Key

type Key int

Key is a constant type for physical keyboard keys.

type KeyboardEvent

type KeyboardEvent struct {
	Key    Key
	Action Action
}

KeyboardEvent represents a user triggered keyboard press or release event.

type MouseButton

type MouseButton int

MouseButton is a constant type for physical mouse buttons.

type MouseButtonEvent

type MouseButtonEvent struct {
	Button MouseButton
	Action Action
}

MouseButtonEvent represents a user triggered mouse button press or release event.

type MouseEnterWindowEvent

type MouseEnterWindowEvent struct {
	X int
	Y int
}

MouseEnterWindowEvent represents an event triggered by the mouse entering back into a window.

type MouseLeaveWindowEvent

type MouseLeaveWindowEvent struct {
}

MouseLeaveWindowEvent represents an event triggered by the mouse leaving a window.

type MouseMoveEvent

type MouseMoveEvent struct {
	X int
	Y int
}

MouseMoveEvent represents a movement of the mouse cursor.

type ResizeEvent

type ResizeEvent struct {
	Width  int
	Height int
}

ResizeEvent represents a user or window manager triggered resizing of a window.

type Window

type Window struct {
	OnClose            chan CloseEvent
	OnResize           chan ResizeEvent
	OnKeyboard         chan KeyboardEvent
	OnMouseMove        chan MouseMoveEvent
	OnMouseButton      chan MouseButtonEvent
	OnFocus            chan FocusEvent
	OnMouseEnterWindow chan MouseEnterWindowEvent
	OnMouseLeaveWindow chan MouseLeaveWindowEvent
	// contains filtered or unexported fields
}

Window is an object representing a window with an OpenGL context inside of it. Most operations are done through a Window object. OnX channels are exposed through this object that may be read for user input. These channels should never be written to.

func NewWindow

func NewWindow(width, height int, title string) (Window, error)

NewWindow creates a new Window object with the given width, height, and title. Width and height attributes must be above zero. The window will not immediately appear on screen. The Show method must be called first. The window will also not capture user input by default. The SetRetrievesInput method must be called first.

func (*Window) Close

func (window *Window) Close() error

Close closes the window. Drawing should not be performed on it's context after this method is called. User input will stop being fed to the window, as well.

func (*Window) CreateContext

func (window *Window) CreateContext() error

CreateContext creates a new OpenGL context.

func (*Window) Height

func (window *Window) Height() int

Height returns the current height of the window in pixels.

func (*Window) Hide

func (window *Window) Hide() error

Hide stops the window from being displayed on screen, but does not close it.

func (*Window) InFocus

func (window *Window) InFocus() bool

InFocus returns true if the window is currently in focus.

func (*Window) KeyState

func (window *Window) KeyState(key Key) Action

KeyState returns the current state of a Key.

func (*Window) MakeContextCurrent

func (window *Window) MakeContextCurrent() error

MakeContextCurrent makes the window's context current. Future OpenGL draw operations will be done on this context.

func (*Window) MouseButtonState

func (window *Window) MouseButtonState(button MouseButton) Action

MouseButtonState returns the state of a mouse button.

func (*Window) MouseInWindow

func (window *Window) MouseInWindow() bool

MouseInWindow returns true if the cursor currently resides in the window space.

func (*Window) MousePosition

func (window *Window) MousePosition() (int, int)

MousePosition returns the position of the cursor.

func (*Window) SetRecievesEvents

func (window *Window) SetRecievesEvents(recieves bool)

SetRecievesEvents toggles whether the window should recieve user input events or not. The default value is false.

func (*Window) SetSize

func (window *Window) SetSize(width, height int) error

SetSize sets the width and height of the window in pixels. Valid values must be above zero.

func (*Window) SetTitle

func (window *Window) SetTitle(title string) error

SetTitle sets the title of the window.

func (*Window) ShouldClose

func (window *Window) ShouldClose() bool

ShouldClose returns true if the window has recieved a close request from the user or the OS.

func (*Window) Show

func (window *Window) Show() error

Show displays the window on screen.

func (*Window) SwapBuffers

func (window *Window) SwapBuffers() error

SwapBuffers updates the display in the window.

func (*Window) Title

func (window *Window) Title() string

Title returns the current title of the window.

func (*Window) UpdateEvents

func (window *Window) UpdateEvents() error

UpdateEvents checks for new user input events.

func (*Window) Width

func (window *Window) Width() int

Width returns the current width of the window in pixels.

Directories

Path Synopsis
simple.go A simple program that draws a red box on screen, has it move around relative to the position of the mouse, and quits when the user hits escape.
simple.go A simple program that draws a red box on screen, has it move around relative to the position of the mouse, and quits when the user hits escape.

Jump to

Keyboard shortcuts

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