oswin

package
v0.0.0-...-5f41422 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

package oswin provides OS-specific windows and events. It is largely copied directly from https://github.com/skelterjohn/go.wde:

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Modifications and extensions were needed for supporting the full GoGi system

Index

Constants

View Source
const (
	KeyFunction     = "function"
	KeyLeftSuper    = "left_super"
	KeyRightSuper   = "right_super"
	KeyLeftAlt      = "left_alt"
	KeyRightAlt     = "right_alt"
	KeyLeftControl  = "left_control"
	KeyRightControl = "right_control"
	KeyLeftShift    = "left_shift"
	KeyRightShift   = "right_shift"
	KeyUpArrow      = "up_arrow"
	KeyDownArrow    = "down_arrow"
	KeyLeftArrow    = "left_arrow"
	KeyRightArrow   = "right_arrow"
	KeyInsert       = "insert"
	KeyTab          = "tab"
	KeySpace        = "space"
	KeyA            = "a"
	KeyB            = "b"
	KeyC            = "c"
	KeyD            = "d"
	KeyE            = "e"
	KeyF            = "f"
	KeyG            = "g"
	KeyH            = "h"
	KeyI            = "i"
	KeyJ            = "j"
	KeyK            = "k"
	KeyL            = "l"
	KeyM            = "m"
	KeyN            = "n"
	KeyO            = "o"
	KeyP            = "p"
	KeyQ            = "q"
	KeyR            = "r"
	KeyS            = "s"
	KeyT            = "t"
	KeyU            = "u"
	KeyV            = "v"
	KeyW            = "w"
	KeyX            = "x"
	KeyY            = "y"
	KeyZ            = "z"
	Key1            = "1"
	Key2            = "2"
	Key3            = "3"
	Key4            = "4"
	Key5            = "5"
	Key6            = "6"
	Key7            = "7"
	Key8            = "8"
	Key9            = "9"
	Key0            = "0"
	KeyPadEnd       = "kp_end"
	KeyPadDown      = "kp_down"
	KeyPadNext      = "kp_next"
	KeyPadLeft      = "kp_left"
	KeyPadBegin     = "kp_begin"
	KeyPadRight     = "kp_right"
	KeyPadHome      = "kp_home"
	KeyPadUp        = "kp_up"
	KeyPadPrior     = "kp_prior"
	KeyPadInsert    = "kp_insert"
	KeyPadSlash     = "kp_slash"
	KeyPadStar      = "kp_star"
	KeyPadMinus     = "kp_minus"
	KeyPadPlus      = "kp_plus"
	KeyPadDot       = "kp_dot"
	KeyPadEqual     = "kp_equal"
	KeyPadEnter     = "kp_enter"
	KeyBackTick     = "`"
	KeyF1           = "f1"
	KeyF2           = "f2"
	KeyF3           = "f3"
	KeyF4           = "f4"
	KeyF5           = "f5"
	KeyF6           = "f6"
	KeyF7           = "f7"
	KeyF8           = "f8"
	KeyF9           = "f9"
	KeyF10          = "f10"
	KeyF11          = "f11"
	KeyF12          = "f12"
	KeyF13          = "f13"
	KeyF14          = "f14"
	KeyF15          = "f15"
	KeyF16          = "f16"
	KeyMinus        = "-"
	KeyEqual        = "="
	KeyLeftBracket  = "["
	KeyRightBracket = "]"
	KeyBackslash    = `\`
	KeySemicolon    = ";"
	KeyQuote        = "'"
	KeyComma        = ","
	KeyPeriod       = "."
	KeySlash        = "/"
	KeyReturn       = "return"
	KeyEscape       = "escape"
	KeyNumlock      = "numlock"
	KeyDelete       = "delete"
	KeyBackspace    = "backspace"
	KeyHome         = "home"
	KeyEnd          = "end"
	KeyPrior        = "prior"
	KeyNext         = "next"
	KeyCapsLock     = "caps"
)

Variables

View Source
var BackendNewWindow = func(width, height int) (OSWindow, error) {
	panic("no gi backend imported")
}
View Source
var BackendRun = func() {
	panic("no gi backend imported")
}
View Source
var BackendStop = func() {
	panic("no gi backend imported")
}
View Source
var PunctKeyShiftMap = map[string]string{
	"-": "_",
	"=": "+",
	"[": "{",
	"]": "}",
	`\`: "|",
	";": ":",
	"'": "\"",
	",": "<",
	".": ">",
	"/": "?",
	"`": "~",
	"1": "!",
	"2": "@",
	"3": "#",
	"4": "$",
	"5": "%",
	"6": "^",
	"7": "&",
	"8": "*",
	"9": "(",
	"0": ")",
}

todo: use some system-specific library that deals with diff keyboard types

Functions

func ConstructChord

func ConstructChord(keys map[string]bool) (chord string)

func KeyToLetter

func KeyToLetter(key, chord string) string

translate key / chord into a letter -- handles shift etc

func RunBackendEventLoop

func RunBackendEventLoop()

Some wde backends (cocoa) require that this function be called in the main thread. To make your code as cross-platform as possible, it is recommended that your main function look like the the code below.

func main() {
	go theRestOfYourProgram()
	gi.RunBackendEventLoop()
}

gi.Run() will return when gi.Stop() is called.

For this to work, you must import one of the gi backends. For instance,

import _ "github.com/rcoreilly/goki/gi/xgb"

or

import _ "github.com/rcoreilly/goki/gi/win"

or

import _ "github.com/rcoreilly/goki/gi/cocoa"

will register a backend with GoGi, allowing you to call gi.RunBackendEventLoop(), gi.StopBackendEventLoop() and gi.NewOSWindow() without referring to the backend explicitly.

If you pupt the registration import in a separate file filtered for the correct platform, your project will work on all three major platforms without configuration.

That is, if you import gi/xgb in a file named "gi_linux.go", gi/win in a file named "gi_windows.go" and gi/cocoa in a file named "gi_darwin.go", the go tool will import the correct one.

func StopBackendEventLoop

func StopBackendEventLoop()

Call this when you want gi.Run() to return. Usually to allow your program to exit gracefully.

Types

type ChordSorter

type ChordSorter []string

func (ChordSorter) Len

func (c ChordSorter) Len() int

func (ChordSorter) Less

func (c ChordSorter) Less(i, j int) (less bool)

func (ChordSorter) Swap

func (c ChordSorter) Swap(i, j int)

type CloseEvent

type CloseEvent struct {
	EventBase
}

CloseEvent is for when the window is closed.

func (CloseEvent) EventHasPos

func (ev CloseEvent) EventHasPos() bool

func (CloseEvent) EventOnFocus

func (ev CloseEvent) EventOnFocus() bool

func (CloseEvent) EventPos

func (ev CloseEvent) EventPos() image.Point

func (CloseEvent) EventType

func (ev CloseEvent) EventType() EventType

type Cursor

type Cursor int
const (
	NoneCursor Cursor = iota
	NormalCursor
	ResizeNCursor
	ResizeECursor
	ResizeSCursor
	ResizeWCursor
	ResizeEWCursor
	ResizeNSCursor
	ResizeNECursor
	ResizeSECursor
	ResizeSWCursor
	ResizeNWCursor
	CrosshairCursor
	IBeamCursor
	GrabHoverCursor
	GrabActiveCursor
	NotAllowedCursor
)

type CursorCtl

type CursorCtl interface {
	Set(id Cursor)
	Hide()
	Show()
}

type Event

type Event interface {
	// get the type of event associated with given event
	EventType() EventType
	// does the event have window position where it takes place?
	EventHasPos() bool
	// position where event took place -- needed for sending events to the right place
	EventPos() image.Point
	// does the event operate only on focus item (e.g., keyboard events)
	EventOnFocus() bool
	// time at which the event was generated
	EventTime() time.Time
	// has this event already been processed?
	IsProcessed() bool
	// mark as having been processed
	SetProcessed()
}

interface for GUI events

type EventBase

type EventBase struct {
	Processed bool
	Time      time.Time
}

base type for events -- records time and whether event has been processed by a receiver of the event -- in which case it is skipped

func (EventBase) EventTime

func (ev EventBase) EventTime() time.Time

func (EventBase) IsProcessed

func (ev EventBase) IsProcessed() bool

func (*EventBase) SetProcessed

func (ev *EventBase) SetProcessed()

type EventType

type EventType int64

EventType determines which type of GUI event is being sent -- need this for indexing into different event signalers based on event type, and sending event type in signals

const (
	// mouse events
	MouseMovedEventType EventType = iota
	MouseDownEventType
	MouseUpEventType
	MouseDraggedEventType

	// gesture events
	MagnifyEventType
	RotateEventType
	ScrollEventType

	// key events
	KeyDownEventType
	KeyUpEventType
	KeyTypedEventType

	// window events -- todo: need iconfiy, etc events
	MouseEnteredEventType
	MouseExitedEventType
	ResizeEventType
	CloseEventType

	// number of event types
	EventTypeN
)

func StringToEventType

func StringToEventType(s string) (EventType, error)

func (EventType) String

func (i EventType) String() string

type GestureEvent

type GestureEvent struct {
	MouseEvent
}

GestureEvent is used to represents common elements of all gesture-based events

type KeyDownEvent

type KeyDownEvent struct {
	KeyEvent
}

KeyDownEvent is for when a key is pressed.

func (KeyDownEvent) EventType

func (ev KeyDownEvent) EventType() EventType

type KeyEvent

type KeyEvent struct {
	EventBase
	Key string
}

KeyEvent is used for data common to all key events, and should not appear as an event received by the caller program.

func (KeyEvent) EventHasPos

func (ev KeyEvent) EventHasPos() bool

func (KeyEvent) EventOnFocus

func (ev KeyEvent) EventOnFocus() bool

func (KeyEvent) EventPos

func (ev KeyEvent) EventPos() image.Point

type KeyTypedEvent

type KeyTypedEvent struct {
	KeyEvent
	// The glyph is the string corresponding to what the user wants to have typed in
	// whatever data entry is active.
	Glyph string
	// The "+" joined set of keys (not glyphs) participating in the chord completed
	// by this key event. The keys will be in a consistent order, no matter what
	// order they are pressed in.
	Chord string
}

KeyTypedEvent is for when a key is typed.

func (KeyTypedEvent) EventType

func (ev KeyTypedEvent) EventType() EventType

type KeyUpEvent

type KeyUpEvent struct {
	KeyEvent
}

KeyUpEvent is for when a key is unpressed.

func (KeyUpEvent) EventType

func (ev KeyUpEvent) EventType() EventType

type MagnifyEvent

type MagnifyEvent struct {
	GestureEvent
	Magnification float64 // the multiplicative scale factor
}

MagnifyEvent is used to represent a magnification gesture.

func (MagnifyEvent) EventType

func (ev MagnifyEvent) EventType() EventType

type MouseButton

type MouseButton int

buttons that can be pressed

const (
	LeftButton MouseButton = 1 << iota
	MiddleButton
	RightButton
	WheelUpButton
	WheelDownButton
	WheelLeftButton  // only supported by xgb/win backends atm
	WheelRightButton // only supported by xgb/win backends atm
)

type MouseButtonEvent

type MouseButtonEvent struct {
	MouseEvent
	Which MouseButton
}

MouseButtonEvent is used for data common to all mouse button events, and should not appear as an event received by the caller program.

type MouseDownEvent

type MouseDownEvent MouseButtonEvent

MouseDownEvent is for when the mouse is clicked within the window.

func (MouseDownEvent) EventType

func (ev MouseDownEvent) EventType() EventType

type MouseDraggedEvent

type MouseDraggedEvent struct {
	MouseMovedEvent
	Which MouseButton
}

MouseDraggedEvent is for when the mouse is moved while a button is pressed.

func (MouseDraggedEvent) EventType

func (ev MouseDraggedEvent) EventType() EventType

type MouseEnteredEvent

type MouseEnteredEvent struct {
	MouseMovedEvent
}

MouseEnteredEvent is for when the mouse enters a window, or a widget (computed by window)

func (MouseEnteredEvent) EventType

func (ev MouseEnteredEvent) EventType() EventType

type MouseEvent

type MouseEvent struct {
	EventBase
	Where image.Point
}

MouseEvent is used for data common to all mouse events, and should not appear as an event received by the caller program.

func (MouseEvent) EventHasPos

func (ev MouseEvent) EventHasPos() bool

func (MouseEvent) EventOnFocus

func (ev MouseEvent) EventOnFocus() bool

func (MouseEvent) EventPos

func (ev MouseEvent) EventPos() image.Point

type MouseExitedEvent

type MouseExitedEvent struct {
	MouseMovedEvent
}

MouseExitedEvent is for when the mouse exits a window, or a widget (computed by window)a

func (MouseExitedEvent) EventType

func (ev MouseExitedEvent) EventType() EventType

type MouseMovedEvent

type MouseMovedEvent struct {
	MouseEvent
	From image.Point
}

MouseMovedEvent is for when the mouse moves within the window.

func (MouseMovedEvent) EventType

func (ev MouseMovedEvent) EventType() EventType

type MouseUpEvent

type MouseUpEvent MouseButtonEvent

MouseUpEvent is for when the mouse is unclicked within the window.

func (MouseUpEvent) EventType

func (ev MouseUpEvent) EventType() EventType

type OSWindow

type OSWindow interface {
	SetTitle(title string)
	SetSize(width, height int)
	Size() (width, height int)
	LockSize(lock bool)
	Show()
	Screen() (im WinImage)
	FlushImage(bounds ...image.Rectangle)
	EventChan() (events <-chan interface{})
	Close() (err error)
	SetCursor(cursor Cursor)
}

general interface into the operating-specific window structure

func NewOSWindow

func NewOSWindow(width, height int) (OSWindow, error)

Create a new OS window with the specified width and height.

type ResizeEvent

type ResizeEvent struct {
	EventBase
	Width, Height int
}

ResizeEvent is for when the window changes size.

func (ResizeEvent) EventHasPos

func (ev ResizeEvent) EventHasPos() bool

func (ResizeEvent) EventOnFocus

func (ev ResizeEvent) EventOnFocus() bool

func (ResizeEvent) EventPos

func (ev ResizeEvent) EventPos() image.Point

func (ResizeEvent) EventType

func (ev ResizeEvent) EventType() EventType

type RotateEvent

type RotateEvent struct {
	GestureEvent
	Rotation float64 // measured in degrees; positive == clockwise
}

RotateEvent is used to represent a rotation gesture.

func (RotateEvent) EventType

func (ev RotateEvent) EventType() EventType

type ScrollEvent

type ScrollEvent struct {
	GestureEvent
	Delta image.Point
}

Scroll Event is used to represent a scrolling gesture.

func (ScrollEvent) EventType

func (ev ScrollEvent) EventType() EventType

type WinImage

type WinImage interface {
	draw.Image
	// CopyRGBA() copies the source image to this image, translating
	// the source image to the provided bounds.
	CopyRGBA(src *image.RGBA, bounds image.Rectangle)
}

window image

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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