Hacked around the cairo issue for now; hooked everything together and fixed a few things. Added the Area test to the test program. Now to just hook up the draw event.
This commit is contained in:
parent
a7f7ea1b8d
commit
a61b43f50c
17
area_unix.go
17
area_unix.go
|
@ -1,25 +1,32 @@
|
|||
// +build ignore
|
||||
// (ignored pending Go issues 7409 and 7548)
|
||||
// x+build !windows,!darwin,!plan9
|
||||
// +build !windows,!darwin,!plan9
|
||||
|
||||
// 14 march 2014
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
"image"
|
||||
)
|
||||
|
||||
// #cgo pkg-config: gtk+-3.0
|
||||
// /* GTK+ 3.8 deprecates gtk_scrolled_window_add_with_viewport(); we need 3.4 miniimum though
|
||||
// setting MIN_REQUIRED ensures nothing older; setting MAX_ALLOWED disallows newer functions - thanks to desrt in irc.gimp.net/#gtk+
|
||||
// TODO add this to the other files too */
|
||||
// #define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_4
|
||||
// #define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4
|
||||
// #include <gtk/gtk.h>
|
||||
// extern gboolean our_draw_callback(GtkWidget *, cairo_t *, gpointer);
|
||||
// /* HACK - see https://code.google.com/p/go/issues/detail?id=7548 */
|
||||
// struct _cairo {};
|
||||
import "C"
|
||||
|
||||
func gtkAreaNew() *gtkWidget {
|
||||
drawingarea := C.gtk_drawing_area_new()
|
||||
C.gtk_widget_set_size_request(drawingarea, 320, 240)
|
||||
scrollarea := C.gtk_scrolled_window_new((*C.GtkAdjustment)(nil), (*C.GtkAdjustment)(nil))
|
||||
// need a viewport because GtkDrawingArea isn't natively scrollable
|
||||
C.gtk_scrolled_window_add_with_viewport(scrollarea, drawingarea)
|
||||
C.gtk_scrolled_window_add_with_viewport((*C.GtkScrolledWindow)(unsafe.Pointer(scrollarea)), drawingarea)
|
||||
return fromgtkwidget(scrollarea)
|
||||
}
|
||||
|
||||
|
@ -54,7 +61,7 @@ func our_draw_callback(widget *C.GtkWidget, cr *C.cairo_t, data C.gpointer) C.gb
|
|||
C.gdouble(cliprect.Min.X),
|
||||
C.gdouble(cliprect.Min.Y))
|
||||
C.g_object_unref((C.gpointer)(unsafe.Pointer(pixbuf))) // free pixbuf
|
||||
return C.FALSE // TODO what does this return value mean? docs don't say
|
||||
return C.FALSE // signals handled without stopping the event chain (thanks to desrt again)
|
||||
}
|
||||
|
||||
var draw_callback = C.GCallback(C.our_draw_callback)
|
||||
|
|
|
@ -92,6 +92,9 @@ var classTypes = [nctypes]*classData{
|
|||
c_progressbar: &classData{
|
||||
make: gtk_progress_bar_new,
|
||||
},
|
||||
c_area: &classData{
|
||||
make: gtkAreaNew,
|
||||
},
|
||||
}
|
||||
|
||||
func (s *sysData) make(initText string, window *sysData) error {
|
||||
|
|
39
test/main.go
39
test/main.go
|
@ -4,6 +4,9 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"flag"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
. "github.com/andlabs/ui"
|
||||
)
|
||||
|
||||
|
@ -110,7 +113,43 @@ func invalidTest(c *Combobox, l *Listbox, s *Stack, g *Grid) {
|
|||
|
||||
var invalidBefore = flag.Bool("invalid", false, "run invalid test before opening window")
|
||||
|
||||
var doArea = flag.Bool("area", false, "run area test instead")
|
||||
func areaTest() {
|
||||
img := [2]*image.NRGBA{}
|
||||
img[0] = image.NewNRGBA(image.Rect(0, 0, 320, 240))
|
||||
color0 := color.NRGBA{128, 128, 0, 255}
|
||||
draw.Draw(img[0], img[0].Rect, image.NewUniform(color0), image.ZP, draw.Over)
|
||||
img[1] = image.NewNRGBA(image.Rect(0, 0, 320, 240))
|
||||
color1 := color.NRGBA{0, 128, 128, 255}
|
||||
draw.Draw(img[1], img[1].Rect, image.NewUniform(color1), image.ZP, draw.Over)
|
||||
i := 0
|
||||
lastrect := image.ZR
|
||||
w := NewWindow("Area Test", 100, 100)
|
||||
a := NewArea()
|
||||
err := w.Open(a)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-w.Closing:
|
||||
return
|
||||
case req := <-a.Paint:
|
||||
fmt.Println(req)
|
||||
req.Out <- img[i].SubImage(req.Rect).(*image.NRGBA)
|
||||
if lastrect != req.Rect {
|
||||
lastrect = req.Rect
|
||||
i = 1 - i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func myMain() {
|
||||
if *doArea {
|
||||
areaTest()
|
||||
return
|
||||
}
|
||||
w := NewWindow("Main Window", 320, 240)
|
||||
b := NewButton("Click Me")
|
||||
b2 := NewButton("Or Me")
|
||||
|
|
Loading…
Reference in New Issue