summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-02-17 23:33:25 -0500
committerPietro Gagliardi <[email protected]>2015-02-17 23:33:25 -0500
commit366460a46e981ea402067f2b96fd15226417e3db (patch)
tree40d75118ad1ecc611a743e680ca3804fc9078aa1
parent2e4c2783012cb386b29b04237e2a198fbcfe5e4d (diff)
Finished migrating the GTK+ Table to not use ImageList.
-rw-r--r--image_unix.go5
-rw-r--r--table_unix.go18
2 files changed, 10 insertions, 13 deletions
diff --git a/image_unix.go b/image_unix.go
index 3f13d2a..4c66375 100644
--- a/image_unix.go
+++ b/image_unix.go
@@ -40,10 +40,9 @@ func toIconSizedGdkPixbuf(img *image.RGBA) *C.GdkPixbuf {
panic(fmt.Errorf("gtk_icon_size_lookup() failed in ImageList.Append() (no reason available)"))
}
if int(width) == img.Rect.Dx() && int(height) == img.Rect.Dy() {
- // just add the base pixbuf; we're good
- i.list = append(i.list, basepixbuf)
+ // just return the base pixbuf; we're good
C.cairo_surface_destroy(surface)
- return
+ return basepixbuf
}
// else scale
pixbuf := C.gdk_pixbuf_scale_simple(basepixbuf, C.int(width), C.int(height), C.GDK_INTERP_NEAREST)
diff --git a/table_unix.go b/table_unix.go
index 931a28e..0857014 100644
--- a/table_unix.go
+++ b/table_unix.go
@@ -8,6 +8,7 @@ import (
"fmt"
"reflect"
"unsafe"
+ "image"
)
// #include "gtk_unix.h"
@@ -25,8 +26,6 @@ type table struct {
modelgtk *C.GtkTreeModel
selection *C.GtkTreeSelection
- pixbufs []*C.GdkPixbuf
-
selected *event
// stuff required by GtkTreeModel
@@ -64,7 +63,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
for i := 0; i < ty.NumField(); i++ {
cname := togstr(ty.Field(i).Name)
switch {
- case ty.Field(i).Type == reflect.TypeOf(ImageIndex(0)):
+ case ty.Field(i).Type == reflect.TypeOf((*image.RGBA)(nil)):
// can't use GDK_TYPE_PIXBUF here because it's a macro that expands to a function and cgo hates that
t.types = append(t.types, C.gdk_pixbuf_get_type())
C.tableAppendColumn(t.treeview, C.gint(i), cname,
@@ -113,10 +112,6 @@ func (t *table) Unlock() {
}()
}
-func (t *table) LoadImageList(i ImageList) {
- i.apply(&t.pixbufs)
-}
-
func (t *table) Selected() int {
var iter C.GtkTreeIter
@@ -172,10 +167,13 @@ func goTableModel_do_get_value(data unsafe.Pointer, row C.gint, col C.gint, valu
d := reflect.Indirect(reflect.ValueOf(t.data))
datum := d.Index(int(row)).Field(int(col))
switch {
- case datum.Type() == reflect.TypeOf(ImageIndex(0)):
- d := datum.Interface().(ImageIndex)
+ case datum.Type() == reflect.TypeOf((*image.RGBA)(nil)):
+ d := datum.Interface().(*image.RGBA)
+ pixbuf := toIconSizedGdkPixbuf(d)
C.g_value_init(value, C.gdk_pixbuf_get_type())
- C.g_value_set_object(value, C.gpointer(unsafe.Pointer(t.pixbufs[d])))
+ object := C.gpointer(unsafe.Pointer(pixbuf))
+ // use g_value_take_object() so the GtkTreeView becomes the pixbuf's owner
+ C.g_value_take_object(value, object)
case datum.Kind() == reflect.Bool:
d := datum.Interface().(bool)
C.g_value_init(value, C.G_TYPE_BOOLEAN)