Finished migrating the GTK+ Table to not use ImageList.

This commit is contained in:
Pietro Gagliardi 2015-02-17 23:33:25 -05:00
parent 2e4c278301
commit 366460a46e
2 changed files with 10 additions and 13 deletions

View File

@ -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)

View File

@ -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)