More go fmt. That completes the main package go fmt. Won't bother with test or tools.

This commit is contained in:
Pietro Gagliardi 2014-06-10 16:03:10 -04:00
parent a210775287
commit 5fa1bd22e2
2 changed files with 68 additions and 66 deletions

106
area.go
View File

@ -4,10 +4,10 @@ package ui
import (
"fmt"
"sync"
"image"
"unsafe"
"reflect"
"sync"
"unsafe"
)
// Area represents a blank canvas upon which programs may draw anything and receive arbitrary events from the user.
@ -16,10 +16,10 @@ import (
// The coordinate system of an Area always has an origin of (0,0) which maps to the top-left corner; all image.Points and image.Rectangles sent across Area's channels conform to this.
// The size of an Area must be at least 1x1 (that is, neither its width nor its height may be zero or negative).
// For control layout purposes, an Area prefers to be at the size you set it to (so if an Area is not stretchy in its layout, it will ask to have that size).
//
//
// To handle events to the Area, an Area must be paired with an AreaHandler.
// See AreaHandler for details.
//
//
// Do not use an Area if you intend to read text.
// Area reads keys based on their position on a standard
// 101-key keyboard, and does no character processing.
@ -28,12 +28,12 @@ import (
// to lead to trouble.
// [FOR FUTURE PLANNING Use TextArea instead, providing a TextAreaHandler.]
type Area struct {
lock sync.Mutex
created bool
sysData *sysData
handler AreaHandler
initwidth int
initheight int
lock sync.Mutex
created bool
sysData *sysData
handler AreaHandler
initwidth int
initheight int
}
// AreaHandler represents the events that an Area should respond to.
@ -78,40 +78,40 @@ type AreaHandler interface {
// The association between button numbers and physical buttons are system-defined.
// For example, on Windows, buttons 4 and 5 are mapped to what are internally referred to as "XBUTTON1" and "XBUTTON2", which often correspond to the dedicated back/forward navigation buttons on the sides of many mice.
// The examples here are NOT a guarantee as to how many buttons maximum will be available on a given system.
//
//
// If the user clicked on the Area to switch to the Window it is contained in from another window in the OS, the Area will receive a MouseEvent for that click.
type MouseEvent struct {
// Pos is the position of the mouse in the Area at the time of the event.
Pos image.Point
Pos image.Point
// If the event was generated by a mouse button being pressed, Down contains the ID of that button.
// Otherwise, Down contains 0.
// If Down contains nonzero, the Area will also receive keyboard focus.
Down uint
Down uint
// If the event was generated by a mouse button being released, Up contains the ID of that button.
// Otherwise, Up contains 0.
// If both Down and Up are 0, the event represents mouse movement (with optional held buttons for dragging; see below).
// Down and Up shall not both be nonzero.
Up uint
Up uint
// If Down is nonzero, Count indicates the number of clicks: 1 for single-click, 2 for double-click, 3 for triple-click, and so on.
// The order of events will be Down:Count=1 -> Up -> Down:Count=2 -> Up -> Down:Count=3 -> Up -> ...
Count uint
Count uint
// Modifiers is a bit mask indicating the modifier keys being held during the event.
Modifiers Modifiers
Modifiers Modifiers
// Held is a slice of button IDs that indicate which mouse buttons are being held during the event.
// Held will not include Down and Up.
// Held will be sorted.
// Only buttons 1, 2, and 3 are guaranteed to be detected by Held properly; whether or not any others are is implementation-defined.
//
//
// If Held is non-empty but Up and Down are both zero, the mouse is being dragged, with all the buttons in Held being held.
// Whether or not a drag into an Area generates MouseEvents is implementation-defined.
// Whether or not a drag over an Area when the program is inactive generates MouseEvents is also implementation-defined.
// Moving the mouse over an Area when the program is inactive and no buttons are held will, however, generate MouseEvents.
Held []uint
Held []uint
}
// HeldBits returns Held as a bit mask.
@ -124,12 +124,12 @@ func (e MouseEvent) HeldBits() (h uintptr) {
}
// A KeyEvent represents a keypress in an Area.
//
//
// Key presses are based on their positions on a standard
// 101-key keyboard found on most computers. The
// names chosen for keys here are based on their names
// on US English QWERTY keyboards; see Key for details.
//
//
// If a key is pressed that is not supported by Key, ExtKey,
// or Modifiers, no KeyEvent will be produced.
type KeyEvent struct {
@ -156,24 +156,24 @@ type KeyEvent struct {
// - '\n' if the typewriter Enter key was pressed
// - '\b' if the typewriter Backspace key was pressed
// If this value is zero, see ExtKey.
Key byte
Key byte
// If Key is zero, ExtKey contains a predeclared identifier
// naming an extended key. See ExtKey for details.
// If both Key and ExtKey are zero, a Modifier by itself
// was pressed. Key and ExtKey will not both be nonzero.
ExtKey ExtKey
ExtKey ExtKey
// If both Key and ExtKey are zero, Modifier will contain exactly one of its bits set, indicating which Modifier was pressed or released.
// As with Modifiers itself, there is no way to differentiate between left and right modifier keys.
// As such, the result of pressing and/or releasing both left and right of the same Modifier is system-defined.
// Furthermore, the result of holding down a Key or ExtKey, then pressing a Modifier, and then releasing the original key is system-defined.
// Under no condition shall Key, ExtKey, AND Modifier all be zero.
Modifier Modifiers
Modifier Modifiers
// Modifiers contains all the modifier keys currently being held at the time of the KeyEvent.
// If Modifier is nonzero, Modifiers will not contain Modifier itself.
Modifiers Modifiers
Modifiers Modifiers
// If Up is true, the key was released; if not, the key was pressed.
// There is no guarantee that all pressed keys shall have
@ -181,14 +181,15 @@ type KeyEvent struct {
// programs while holding the key down, then releases the key).
// Keys that have been held down are reported as multiple
// key press events.
Up bool
Up bool
}
// ExtKey represents keys that are not in the typewriter section of the keyboard.
type ExtKey uintptr
const (
Escape ExtKey = iota + 1
Insert // equivalent to "Help" on Apple keyboards
Insert // equivalent to "Help" on Apple keyboards
Delete
Home
End
@ -198,7 +199,7 @@ const (
Down
Left
Right
F1 // F1..F12 are guaranteed to be consecutive
F1 // F1..F12 are guaranteed to be consecutive
F2
F3
F4
@ -210,8 +211,8 @@ const (
F10
F11
F12
N0 // numpad keys; independent of Num Lock state
N1 // N0..N9 are guaranteed to be consecutive
N0 // numpad keys; independent of Num Lock state
N1 // N0..N9 are guaranteed to be consecutive
N2
N3
N4
@ -226,7 +227,7 @@ const (
NSubtract
NMultiply
NDivide
_nextkeys // for sanity check
_nextkeys // for sanity check
)
// EffectiveKey returns e.Key if it is set.
@ -241,7 +242,7 @@ func (e KeyEvent) EffectiveKey() byte {
k := e.ExtKey
switch {
case k >= N0 && k <= N9:
return byte(k - N0) + '0'
return byte(k-N0) + '0'
case k == NDot:
return '.'
case k == NEnter:
@ -262,11 +263,12 @@ func (e KeyEvent) EffectiveKey() byte {
// There is no way to differentiate between left and right modifier keys.
// As such, what KeyEvents get sent if the user does something unusual with both of a certain modifier key at once is undefined.
type Modifiers uintptr
const (
Ctrl Modifiers = 1 << iota // the keys labelled Ctrl or Control on all platforms
Alt // the keys labelled Alt or Option or Meta on all platforms
Shift // the Shift keys
Super // the Super keys on platforms that have one, or the Windows keys on Windows, or the Command keys on Mac OS X
Ctrl Modifiers = 1 << iota // the keys labelled Ctrl or Control on all platforms
Alt // the keys labelled Alt or Option or Meta on all platforms
Shift // the Shift keys
Super // the Super keys on platforms that have one, or the Windows keys on Windows, or the Command keys on Mac OS X
)
func checkAreaSize(width int, height int, which string) {
@ -283,10 +285,10 @@ func NewArea(width int, height int, handler AreaHandler) *Area {
panic("handler passed to NewArea() must not be nil")
}
return &Area{
sysData: mksysdata(c_area),
handler: handler,
initwidth: width,
initheight: height,
sysData: mksysdata(c_area),
handler: handler,
initwidth: width,
initheight: height,
}
}
@ -336,11 +338,11 @@ func (a *Area) make(window *sysData) error {
func (a *Area) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
*rr = append(*rr, resizerequest{
sysData: a.sysData,
x: x,
y: y,
width: width,
height: height,
sysData: a.sysData,
x: x,
y: y,
width: width,
height: height,
})
}
@ -373,16 +375,16 @@ func toARGB(i *image.RGBA, memory uintptr, memstride int) {
nextp := p + i.Stride
nextq := q + memstride
for x := i.Rect.Min.X; x < i.Rect.Max.X; x++ {
argb := uint32(i.Pix[p + 3]) << 24 // A
argb |= uint32(i.Pix[p + 0]) << 16 // R
argb |= uint32(i.Pix[p + 1]) << 8 // G
argb |= uint32(i.Pix[p + 2]) // B
argb := uint32(i.Pix[p+3]) << 24 // A
argb |= uint32(i.Pix[p+0]) << 16 // R
argb |= uint32(i.Pix[p+1]) << 8 // G
argb |= uint32(i.Pix[p+2]) // B
// the magic of conversion
native := (*[4]byte)(unsafe.Pointer(&argb))
realbits[q + 0] = native[0]
realbits[q + 1] = native[1]
realbits[q + 2] = native[2]
realbits[q + 3] = native[3]
realbits[q+0] = native[0]
realbits[q+1] = native[1]
realbits[q+2] = native[2]
realbits[q+3] = native[3]
p += 4
q += 4
}

View File

@ -3,8 +3,8 @@
package ui
import (
"unsafe"
"image"
"unsafe"
)
// #include <stdlib.h>
@ -28,10 +28,10 @@ func areaView_drawRect(self C.id, rect C.struct_xrect) {
s := getSysData(self)
// no need to clear the clip rect; the NSScrollView does that for us (see the setDrawsBackground: call in objc_darwin.m)
// rectangles in Cocoa are origin/size, not point0/point1; if we don't watch for this, weird things will happen when scrolling
cliprect := image.Rect(int(rect.x), int(rect.y), int(rect.x + rect.width), int(rect.y + rect.height))
cliprect := image.Rect(int(rect.x), int(rect.y), int(rect.x+rect.width), int(rect.y+rect.height))
max := C.frame(self)
cliprect = image.Rect(0, 0, int(max.width), int(max.height)).Intersect(cliprect)
if cliprect.Empty() { // no intersection; nothing to paint
if cliprect.Empty() { // no intersection; nothing to paint
return
}
i := s.handler.Paint(cliprect)
@ -42,10 +42,10 @@ func areaView_drawRect(self C.id, rect C.struct_xrect) {
func parseModifiers(e C.id) (m Modifiers) {
const (
_NSShiftKeyMask = 1 << 17
_NSControlKeyMask = 1 << 18
_NSShiftKeyMask = 1 << 17
_NSControlKeyMask = 1 << 18
_NSAlternateKeyMask = 1 << 19
_NSCommandKeyMask = 1 << 20
_NSCommandKeyMask = 1 << 20
)
mods := uintptr(C.modifierFlags(e))
@ -77,7 +77,7 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool) {
}
me.Modifiers = parseModifiers(e)
which := uint(C.buttonNumber(e)) + 1
if which == 3 { // swap middle and right button numbers
if which == 3 { // swap middle and right button numbers
which = 2
} else if which == 2 {
which = 3
@ -89,22 +89,22 @@ func areaMouseEvent(self C.id, e C.id, click bool, up bool) {
// this already works the way we want it to so nothing special needed like with Windows and GTK+
me.Count = uint(C.clickCount(e))
} else {
which = 0 // reset for Held processing below
which = 0 // reset for Held processing below
}
// the docs do say don't use this for tracking (mouseMoved:) since it returns the state now, and mouse move events work by tracking, but as far as I can tell dragging the mouse over the inactive window does not generate an event on Mac OS X, so :/ (tracking doesn't touch dragging anyway except during mouseEntered: and mouseExited:, which we don't handle, and the only other tracking message, cursorChanged:, we also don't handle (yet...? need to figure out if this is how to set custom cursors or not), so)
held := C.pressedMouseButtons()
if which != 1 && (held & 1) != 0 { // button 1
if which != 1 && (held&1) != 0 { // button 1
me.Held = append(me.Held, 1)
}
if which != 2 && (held & 4) != 0 { // button 2; mind the swap
if which != 2 && (held&4) != 0 { // button 2; mind the swap
me.Held = append(me.Held, 2)
}
if which != 3 && (held & 2) != 0 { // button 3
if which != 3 && (held&2) != 0 { // button 3
me.Held = append(me.Held, 3)
}
held >>= 3
for i := uint(4); held != 0; i++ {
if which != i && (held & 1) != 0 {
if which != i && (held&1) != 0 {
me.Held = append(me.Held, i)
}
held >>= 1
@ -173,8 +173,8 @@ func areaView_flagsChanged(self C.id, e C.id) {
// Mac OS X sends this event on both key up and key down.
// Fortunately -[e keyCode] IS valid here, so we can simply map from key code to Modifiers, get the value of [e modifierFlags], and check if the respective bit is set or not — that will give us the up/down state
keyCode := uintptr(C.keyCode(e))
mod, ok := keycodeModifiers[keyCode] // comma-ok form to avoid adding entries
if !ok { // unknown modifier; ignore
mod, ok := keycodeModifiers[keyCode] // comma-ok form to avoid adding entries
if !ok { // unknown modifier; ignore
return
}
ke.Modifiers = parseModifiers(e)