Changed from using image.NRGBA to image.RGBA (premultiplied alpha) in Area.Paint() since it'll be easier to work with on Windows after applying what Treeki/Ninjifox suggested I do instead of what I am doing now.

This commit is contained in:
Pietro Gagliardi 2014-04-11 13:54:50 -04:00
parent 179ddba93a
commit 6f0d114a8b
3 changed files with 17 additions and 17 deletions

12
area.go
View File

@ -46,13 +46,13 @@ type AreaHandler interface {
// Example:
// imgFromFile, _, err := image.Decode(file)
// if err != nil { panic(err) }
// img := image.NewNRGBA(imgFromFile.Rect)
// img := image.NewRGBA(imgFromFile.Rect)
// draw.Draw(img, img.Rect, imgFromFile, image.ZP, draw.Over)
// // ...
// func (h *myAreaHandler) Paint(rect image.Rectangle) *image.NRGBA {
// return img.SubImage(rect).(*image.NRGBA)
// func (h *myAreaHandler) Paint(rect image.Rectangle) *image.RGBA {
// return img.SubImage(rect).(*image.RGBA)
// }
Paint(cliprect image.Rectangle) *image.NRGBA
Paint(cliprect image.Rectangle) *image.RGBA
// Mouse is called when the Area receives a mouse event.
// You are allowed to do nothing in this handler (to ignore mouse events).
@ -328,10 +328,10 @@ func (a *Area) preferredSize() (width int, height int) {
}
// internal function, but shared by all system implementations: &img.Pix[0] is not necessarily the first pixel in the image
func pixelDataPos(img *image.NRGBA) int {
func pixelDataPos(img *image.RGBA) int {
return img.PixOffset(img.Rect.Min.X, img.Rect.Min.Y)
}
func pixelData(img *image.NRGBA) *uint8 {
func pixelData(img *image.RGBA) *uint8 {
return &img.Pix[pixelDataPos(img)]
}

View File

@ -14,7 +14,7 @@ import (
)
type keyboardArea struct {
kbd *image.NRGBA
kbd *image.RGBA
lock sync.Mutex // TODO needed?
}
@ -22,23 +22,23 @@ func mkkbArea() (width int, height int, a *keyboardArea) {
a = new(keyboardArea)
i, _, err := image.Decode(bytes.NewReader(kbpic))
if err != nil { panic(err) }
a.kbd = image.NewNRGBA(i.Bounds())
a.kbd = image.NewRGBA(i.Bounds())
draw.Draw(a.kbd, a.kbd.Rect, i, image.ZP, draw.Over)
return a.kbd.Rect.Dx(), a.kbd.Rect.Dy(), a
}
func (a *keyboardArea) Paint(cliprect image.Rectangle) *image.NRGBA {
func (a *keyboardArea) Paint(cliprect image.Rectangle) *image.RGBA {
a.lock.Lock()
defer a.lock.Unlock()
return a.kbd.SubImage(cliprect).(*image.NRGBA)
return a.kbd.SubImage(cliprect).(*image.RGBA)
}
func (a *keyboardArea) Mouse(MouseEvent) (repaint bool) {
return false
}
func markkey(dest *image.NRGBA, keypt image.Point, m Modifiers) {
func markkey(dest *image.RGBA, keypt image.Point, m Modifiers) {
xr := keyrect(m).Add(keypt)
xi := modcolor(m)
draw.Draw(dest, xr, xi, image.ZP, draw.Over)

View File

@ -147,18 +147,18 @@ func invalidTest(c *Combobox, l *Listbox, s *Stack, g *Grid) {
var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening window")
type areaHandler struct {
img *image.NRGBA
img *image.RGBA
}
func (a *areaHandler) Paint(rect image.Rectangle) *image.NRGBA {
func (a *areaHandler) Paint(rect image.Rectangle) *image.RGBA {
//fmt.Println(rect)
/*
req.Out <- img[i].SubImage(req.Rect).(*image.NRGBA)
req.Out <- img[i].SubImage(req.Rect).(*image.RGBA)
if lastrect != req.Rect {
lastrect = req.Rect
i = 1 - i
}
*/
return a.img.SubImage(rect).(*image.NRGBA)
return a.img.SubImage(rect).(*image.RGBA)
}
func (a *areaHandler) Mouse(e MouseEvent) bool {
fmt.Printf("%#v\n", e)
@ -186,7 +186,7 @@ func areaTest() {
if err != nil {
panic(err)
}
img := image.NewNRGBA(ximg.Bounds())
img := image.NewRGBA(ximg.Bounds())
draw.Draw(img, img.Rect, ximg, image.ZP, draw.Over)
w := NewWindow("Area Test", 100, 100)
a := NewArea(320, 240, &areaHandler{
@ -231,7 +231,7 @@ func areaTest() {
var areabounds = flag.Bool("areabounds", false, "run area bounds test instead")
func areaboundsTest() {
img := image.NewNRGBA(image.Rect(0, 0, 320, 240))
img := image.NewRGBA(image.Rect(0, 0, 320, 240))
a := NewArea(320, 240, &areaHandler{
img: img,
})