예제 #1
0
파일: version.go 프로젝트: rosatolen/coyim
func CheckVersion(major, minor, micro uint) error {
	errChar := C.gtk_check_version(C.guint(major), C.guint(minor), C.guint(micro))
	if errChar == nil {
		return nil
	}

	return errors.New(C.GoString((*C.char)(errChar)))
}
예제 #2
0
파일: gtk.go 프로젝트: hwch/go-gtk
// const gchar* gtk_check_version (guint   required_major,
//                                 guint   required_minor,
//                                 guint   required_micro);
func CheckVersion(required_major, required_minor,
	required_micro uint32) string {
	ret := C.gtk_check_version(C.guint(required_major),
		C.guint(required_minor),
		C.guint(required_micro))
	if ret == nil {
		return ""
	}
	s := C.GoString((*C.char)(ret))
	return s
}
예제 #3
0
// TrackJoints attempts to find the joints of a human given the depth
// information, width, and height. The depth data should be in millimeters.
// The width and height values are the width and height of the depth buffer.
// Only joints present in the returned map were detected. Keep in mind that
// the default dimension reduction value is 16, so TrackJoints expects the
// depth data to have been shrunk to a 16th of it's original size.
func (skeleton *Skeleton) TrackJoints(depth []uint16, width, height int) (map[JointID]Joint, error) {

	if len(depth) != width*height {
		return make(map[JointID]Joint), errors.New("width and height values do not match depth buffer size")
	}

	var err *C.GError

	sliceHeader := *(*reflect.SliceHeader)(unsafe.Pointer(&depth))

	list := C.skeltrack_skeleton_track_joints_sync(skeleton.skeleton,
		(*C.guint16)(unsafe.Pointer(sliceHeader.Data)), C.guint(width), C.guint(height), nil, &err)

	if err != nil {
		return make(map[JointID]Joint), errors.New(C.GoString((*C.char)(err.message)))
	}

	joints := make(map[JointID]Joint)

	if list == nil {
		return joints, nil
	}

	head := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_HEAD)
	if head != nil {
		joints[JointHead] = Joint{head}
	}
	leftShoulder := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_LEFT_SHOULDER)
	if leftShoulder != nil {
		joints[JointLeftShoulder] = Joint{leftShoulder}
	}
	rightShoulder := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_RIGHT_SHOULDER)
	if rightShoulder != nil {
		joints[JointRightShoulder] = Joint{rightShoulder}
	}
	leftElbow := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_LEFT_ELBOW)
	if leftElbow != nil {
		joints[JointLeftElbow] = Joint{leftElbow}
	}
	rightElbow := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_RIGHT_ELBOW)
	if rightElbow != nil {
		joints[JointRightElbow] = Joint{rightElbow}
	}
	leftHand := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_LEFT_HAND)
	if leftHand != nil {
		joints[JointLeftHand] = Joint{leftHand}
	}
	rightHand := C.skeltrack_joint_list_get_joint(list, C.SKELTRACK_JOINT_ID_RIGHT_HAND)
	if rightHand != nil {
		joints[JointRightHand] = Joint{rightHand}
	}

	return joints, nil
}
예제 #4
0
파일: closure.go 프로젝트: napsy/go-gtk3
// SimpleGoMarshal
// Our true callback which gets called
// for all connected signals.
// It emits unique id of closure to queue manager.
//export simple_go_marshal
func simple_go_marshal(closure unsafe.Pointer,
	returnValue unsafe.Pointer,
	n_param_values C.guint,
	paramValues unsafe.Pointer,
	invocationHint unsafe.Pointer,
	marshalData unsafe.Pointer) {

	c := (*C.GClosure)(closure)
	id := uint64(*((*C.guint64)(c.data)))

	argslice := make([]interface{}, int(n_param_values))
	array := C.g_array_from_GValues(paramValues, n_param_values)
	for i := 0; i < int(n_param_values); i++ {
		v := C.get_index(array, C.guint(i))
		gv := GValue{0, &v}
		gv.ReInitializeType()
		t, e := ConvertToGo(gv.GetPtr(), gv.GetTypeID())
		if e == nil {
			argslice[i] = t
		} else {
			argslice = nil
		}
	}

	emitedSignals <- Signal{id, argslice}
	<-doneMarshal

	C.free_array(array)
}
예제 #5
0
파일: application.go 프로젝트: brl/gotk3
// GetWindowByID is a wrapper around gtk_application_get_window_by_id().
func (v *Application) GetWindowByID(id uint) *Window {
	c := C.gtk_application_get_window_by_id(v.native(), C.guint(id))
	if c == nil {
		return nil
	}
	return wrapWindow(wrapObject(unsafe.Pointer(c)))
}
예제 #6
0
파일: glib.go 프로젝트: leif/go-gtk
func (v List) NthData(n uint) interface{} {
	p := C.g_list_nth_data(v.GList, C.guint(n))
	if p == nil {
		return nil
	}
	return unsafe.Pointer(p)
}
예제 #7
0
func (db *MDB) TableIndexes(tableDef *MDBTableDef) ([]MDBIndex, error) {
	var idx *C.MdbIndex
	indexes := make([]MDBIndex, tableDef.table.num_idxs)

	for i := 0; i < int(tableDef.table.num_idxs); i++ {
		idx = C._go_ptr_idx(tableDef.table.indices, C.guint(i))

		mdbindex := MDBIndex{
			int(idx.index_num),
			C.GoString(&idx.name[0]),
			int(idx.index_type),
			int(idx.num_rows),
			int(idx.num_keys),
			int(idx.flags),
			make([]int, int(idx.num_keys)),
			make([]int, int(idx.num_keys)),
		}

		for j := 0; j < mdbindex.keys; j++ {
			mdbindex.keyColNum[j] = int(idx.key_col_num[j])
			mdbindex.keyColOrder[j] = int(idx.key_col_order[j])
		}

		indexes[i] = mdbindex
	}

	return indexes, nil
}
예제 #8
0
func (sql *MDBSQL) RunQuery(query string) ([]map[string]string, error) {
	var col *C.MdbSQLColumn
	querybuf := C.CString(query)
	defer C.free(unsafe.Pointer(querybuf))

	C.mdb_sql_run_query(sql.sql, (*C.gchar)(querybuf))
	if sql.HasError() {
		return nil, fmt.Errorf("mdbsql: query error: %s", sql.GetError())
	}

	ret := make([]map[string]string, 0)

	rowCount := 0
	for C.mdb_fetch_row(sql.sql.cur_table) == 1 {
		rowCount++
		row := make(map[string]string)
		for i := 0; i < int(sql.sql.num_columns); i++ {
			col = C._go_ptr_sqlcol(sql.sql.columns, C.guint(i))
			row[C.GoString(col.name)] = C.GoString((*C.char)(sql.sql.bound_values[i]))
		}
		ret = append(ret, row)
	}

	C.mdb_sql_reset(sql.sql)

	return ret, nil
}
예제 #9
0
파일: listbox_unix.go 프로젝트: UIKit0/ui
func gListboxSelMultiTexts(widget *C.GtkWidget) (texts []string) {
	var model *C.GtkTreeModel
	var iter C.GtkTreeIter
	var gs *C.gchar

	tv := getTreeViewFrom(widget)
	sel := C.gtk_tree_view_get_selection(tv)
	rows := C.gtk_tree_selection_get_selected_rows(sel, &model)
	defer C.g_list_free_full(rows, C.GDestroyNotify(unsafe.Pointer(C.gtk_tree_path_free)))
	len := C.g_list_length(rows)
	if len == 0 {
		return nil
	}
	texts = make([]string, len)
	for i := C.guint(0); i < len; i++ {
		path := (*C.GtkTreePath)(unsafe.Pointer(rows.data))
		if C.gtk_tree_model_get_iter(model, &iter, path) == C.FALSE {
			panic("gtk_tree_model_get_iter() failed getting Listbox selected texts; reason unknown")
		}
		C.gtkTreeModelGet(model, &iter, &gs)
		texts[i] = fromgstr(gs)
		rows = rows.next
	}
	return texts
}
예제 #10
0
파일: gdk.go 프로젝트: raichu/gotk3
func KeyvalConvertCase(v uint) (lower, upper uint) {
	var l, u C.guint
	l = 0
	u = 0
	C.gdk_keyval_convert_case(C.guint(v), &l, &u)
	return uint(l), uint(u)
}
예제 #11
0
파일: box.go 프로젝트: napsy/go-gtk3
func (self *Box) SetChildPacking(w WidgetLike, expand bool, fill bool, padding int, ptype GtkPackType) {
	e := gobject.GBool(expand)
	f := gobject.GBool(fill)
	defer e.Free()
	defer f.Free()
	C.gtk_box_set_child_packing(self.object, w.W().object, *((*C.gboolean)(e.GetPtr())), *((*C.gboolean)(f.GetPtr())),
		C.guint(padding), C.GtkPackType(ptype))
}
예제 #12
0
/*
Creates a new instance of a #GObject subtype and sets its properties.

Construction parameters (see #G_PARAM_CONSTRUCT, #G_PARAM_CONSTRUCT_ONLY)
which are not explicitly specified are set to their default values.
*/
func ObjectNewv(object_type C.GType, n_parameters uint, parameters *C.GParameter) (return__ *Object) {
	var __cgo__return__ interface{}
	__cgo__return__ = C.g_object_newv(object_type, C.guint(n_parameters), parameters)
	if __cgo__return__ != nil {
		return__ = NewObjectFromCPointer(unsafe.Pointer(reflect.ValueOf(__cgo__return__).Pointer()))
	}
	return
}
예제 #13
0
/*
Obtains the upper- and lower-case versions of the keyval @symbol.
Examples of keyvals are #GDK_KEY_a, #GDK_KEY_Enter, #GDK_KEY_F1, etc.
*/
func KeyvalConvertCase(symbol uint) (lower uint, upper uint) {
	var __cgo__lower C.guint
	var __cgo__upper C.guint
	C.gdk_keyval_convert_case(C.guint(symbol), &__cgo__lower, &__cgo__upper)
	lower = uint(__cgo__lower)
	upper = uint(__cgo__upper)
	return
}
예제 #14
0
파일: glib.go 프로젝트: leif/go-gtk
func TimeoutAdd(interval uint, f interface{}, datas ...interface{}) {
	var data interface{}
	if len(datas) > 0 {
		data = datas[0]
	}
	ctx := &SourcefuncContext{f, nil, reflect.ValueOf(data)}
	ctx.sfi = unsafe.Pointer(C._g_timeout_add(C.guint(interval), C.int(len(sourcefunc_contexts))))
	sourcefunc_contexts = append(sourcefunc_contexts, ctx)
}
예제 #15
0
파일: glib.go 프로젝트: mattn/go-gtk
func TimeoutAdd(interval uint, f interface{}, datas ...interface{}) {
	var data interface{}
	if len(datas) > 0 {
		data = datas[0]
	}
	ctx := &SourcefuncContext{reflect.ValueOf(f), reflect.ValueOf(data)}
	id := sourcefunc_contexts.Add(ctx)
	C._g_timeout_add(C.guint(interval), C.int(id))
}
예제 #16
0
파일: gdkpixbuf.go 프로젝트: hauke96/go-gtk
// guchar * gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf, guint *length);
//
// Retuns a slice of byte backed by a C array of pixbuf data.
func (p *Pixbuf) GetPixelsWithLength() []byte {
	panic_if_version_older(2, 26, 0, "gdk_pixbuf_get_pixels_with_length()")
	length := C.guint(0)
	ptr := C._gdk_pixbuf_get_pixels_with_length(
		p.GPixbuf,
		&length,
	)
	return (*[1 << 30]byte)(unsafe.Pointer(ptr))[:length]
}
예제 #17
0
// PopupAtPointer() is a wrapper for gtk_menu_popup_at_pointer(), on older versions it uses PopupAtMouseCursor
func (v *Menu) PopupAtPointer(_ *gdk.Event) {
	C.gtk_menu_popup(v.native(),
		nil,
		nil,
		nil,
		nil,
		C.guint(0),
		C.gtk_get_current_event_time())
}
예제 #18
0
파일: glib.go 프로젝트: mattn/go-gtk
func (v *GObject) Set(name string, value interface{}) {
	ptr := C.CString(name)
	defer C.free_string(ptr)

	if _, ok := value.(WrappedObject); ok {
		value = value.(WrappedObject).GetInternalValue()
	}
	if _, ok := value.(GObject); ok {
		value = value.(GObject).Object
	}
	if _, ok := value.(GValue); ok {
		value = value.(GValue).Value
	}

	switch value.(type) {
	case bool:
		bval := gbool(value.(bool))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&bval))
	case byte:
		bval := C.gchar(value.(byte))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&bval))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gchar(value.(byte))).UnsafeAddr()))
	case int:
		ival := C.int(value.(int))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&ival))
	case uint:
		uval := C.guint(value.(uint))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&uval))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.guint(value.(uint))).UnsafeAddr()))
	case float32:
		f32val := C.gfloat(value.(float32))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&f32val))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gfloat(value.(float64))).UnsafeAddr()))
	case float64:
		f64val := C.gfloat(value.(float64))
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&f64val))
		//C._g_object_set(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(reflect.ValueOf(C.gfloat(value.(float64))).UnsafeAddr()))
	case string:
		pval := C.CString(value.(string))
		defer C.free_string(pval)
		C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&pval))
	default:
		if pv, ok := value.(*[0]uint8); ok {
			C._g_object_set_ptr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(pv))
		} else {
			av := reflect.ValueOf(value)
			if av.Kind() == reflect.Ptr {
				C._g_object_set_ptr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(av.Pointer()))
			} else if av.CanAddr() {
				C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(av.UnsafeAddr()))
			} else {
				C._g_object_set_addr(C.gpointer(v.Object), C.to_gcharptr(ptr), unsafe.Pointer(&value))
			}
		}
	}
}
예제 #19
0
// AcceleratorParse is a wrapper around gtk_accelerator_parse().
func AcceleratorParse(acc string) (key uint, mods gdk.ModifierType) {
	cstr := C.CString(acc)
	defer C.free(unsafe.Pointer(cstr))

	k := C.guint(0)
	m := C.GdkModifierType(0)

	C.gtk_accelerator_parse((*C.gchar)(cstr), &k, &m)
	return uint(k), gdk.ModifierType(m)
}
예제 #20
0
func (db *MDB) TableOpen(tableName string) (*MDBTableDef, error) {
	var entry *C.MdbCatalogEntry
	var col *C.MdbColumn
	tableDef := &MDBTableDef{}

	rv := C.mdb_read_catalog(db.mdb, C.MDB_TABLE)
	if rv == nil {
		return nil, errors.New("mdb: error reading table catalog")
	}

	for i := 0; i < int(db.mdb.num_catalog); i++ {
		entry = C._go_ptr_catalog(db.mdb.catalog, C.guint(i))
		name := C.GoString(&entry.object_name[0])

		if name == tableName {
			tableDef.table = C.mdb_read_table(entry)
			if tableDef.table == nil {
				return nil, errors.New("mdb: error reading table")
			}
			tableDef.num_cols = int(tableDef.table.num_cols)

			C.mdb_read_columns(tableDef.table)
			C.mdb_read_indices(tableDef.table)
			C.mdb_rewind_table(tableDef.table)

			tableDef.column_names = make([]string, tableDef.num_cols)
			tableDef.bound_values = make([][]byte, tableDef.num_cols)
			tableDef.bound_lengths = make([]int, tableDef.num_cols)

			for j := 0; j < tableDef.num_cols; j++ {
				col = C._go_ptr_col(tableDef.table.columns, C.guint(j))
				colName := C.GoString(&col.name[0])
				tableDef.column_names[j] = colName

				tableDef.bound_values[j] = make([]byte, C.MDB_BIND_SIZE)
				C.mdb_bind_column(tableDef.table, C.int(j+1), unsafe.Pointer(&tableDef.bound_values[j][0]), (*C.int)(unsafe.Pointer(&tableDef.bound_lengths[j])))

			}
		}
	}

	return tableDef, nil
}
예제 #21
0
// Connect is a wrapper around gtk_accel_group_connect().
func (v *AccelGroup) Connect(key uint, mods gdk.ModifierType, flags AccelFlags, f interface{}) {
	closure, _ := glib.ClosureNew(f)
	cl := (*C.struct__GClosure)(unsafe.Pointer(closure))
	C.gtk_accel_group_connect(
		v.native(),
		C.guint(key),
		C.GdkModifierType(mods),
		C.GtkAccelFlags(flags),
		cl)
}
예제 #22
0
파일: box.go 프로젝트: ziutek/gtk
func (b *Box) PackEnd(child *Widget, expand, fill bool, padding uint) {
	var e, f C.gboolean
	if expand {
		e = 1
	}
	if fill {
		f = 1
	}
	C.gtk_box_pack_end(b.g(), child.g(), e, f, C.guint(padding))
}
예제 #23
0
파일: object.go 프로젝트: seokheonbae/glib
func (o *Object) EmitById(sid SignalId, detail Quark, args ...interface{}) interface{} {
	var sq C.GSignalQuery
	C.g_signal_query(C.guint(sid), &sq)
	if len(args) != int(sq.n_params) {
		panic(fmt.Sprintf(
			"*Object.EmitById "+
				"Number of input parameters #%d doesn't match signal spec #%d",
			len(args), int(sq.n_params),
		))
	}
	prms := make([]Value, len(args)+1)
	prms[0] = *ValueOf(o)
	for i, a := range args {
		prms[i+1] = *ValueOf(a)
	}
	ret := new(Value)
	C._signal_emit(prms[0].g(), C.guint(sid), C.GQuark(detail), ret.g())
	return ret.Get()
}
예제 #24
0
func sliceFromGValueArray(a *C.GValueArray) GValueArray {
	n := uint(a.n_values)
	s := make(GValueArray, n)
	for i := uint(0); i < n; i++ {
		cv := C.g_value_array_get_nth(a, C.guint(i))
		v, _ := glib.ValueFromNative(unsafe.Pointer(cv)).GoValue()
		s[i] = v
	}
	return s
}
예제 #25
0
파일: value.go 프로젝트: ziutek/glib
// Set value to i
func (v *Value) Set(i interface{}) {
	if vg, ok := i.(ValueGetter); ok {
		vg.Value().Copy(v)
		return
	}
	// Other types
	r := reflect.ValueOf(i)
	switch r.Kind() {
	case reflect.Invalid:
		C.g_value_reset(v.g())

	case reflect.Bool:
		C.g_value_set_boolean(v.g(), gBoolean(r.Bool()))

	case reflect.Int:
		C.g_value_set_long(v.g(), C.glong(i.(int)))

	case reflect.Int8:
		C.g_value_set_schar(v.g(), C.gint8(i.(int8)))

	case reflect.Int32:
		C.g_value_set_int(v.g(), C.gint(i.(int32)))

	case reflect.Int64:
		C.g_value_set_int64(v.g(), C.gint64(i.(int64)))

	case reflect.Uint:
		C.g_value_set_ulong(v.g(), C.gulong(i.(uint)))

	case reflect.Uint8:
		C.g_value_set_uchar(v.g(), C.guchar(i.(uint8)))

	case reflect.Uint32:
		C.g_value_set_uint(v.g(), C.guint(i.(uint32)))

	case reflect.Uint64:
		C.g_value_set_uint64(v.g(), C.guint64(i.(uint64)))

	case reflect.Float32:
		C.g_value_set_float(v.g(), C.gfloat(i.(float32)))

	case reflect.Float64:
		C.g_value_set_double(v.g(), C.gdouble(i.(float64)))

	case reflect.Ptr:
		C.g_value_set_pointer(v.g(), C.gpointer(r.Pointer()))

	case reflect.String:
		C.g_value_set_static_string(v.g(), (*C.gchar)(C.CString(r.String())))

	default:
		panic("Can't represent Go value in Glib type system.")
	}
}
예제 #26
0
func (v *AccelKey) native() *C.struct__GtkAccelKey {
	if v == nil {
		return nil
	}

	var val C.struct__GtkAccelKey
	val.accel_key = C.guint(v.key)
	val.accel_mods = C.GdkModifierType(v.mods)
	val.accel_flags = v.flags
	return &val
}
예제 #27
0
// AddAccelerator is a wrapper around gtk_widget_add_accelerator().
func (v *Widget) AddAccelerator(signal string, group *AccelGroup, key uint, mods gdk.ModifierType, flags AccelFlags) {
	csignal := (*C.gchar)(C.CString(signal))
	defer C.free(unsafe.Pointer(csignal))

	C.gtk_widget_add_accelerator(v.native(),
		csignal,
		group.native(),
		C.guint(key),
		C.GdkModifierType(mods),
		C.GtkAccelFlags(flags))
}
예제 #28
0
파일: glib.go 프로젝트: pauldub/go-gtk3
func (self *GList) NthData(n uint) interface{} {
	data := C.g_list_nth_data(self.object, C.guint(n))

	if data == nil {
		return nil
	}

	if self.ConversionFunc != nil {
		return self.ConversionFunc(unsafe.Pointer(data))
	}
	return data
}
예제 #29
0
파일: glib.go 프로젝트: pauldub/go-gtk3
func (self *GSList) FreeFull() {
	if self.DestroyFunc == nil {
		return
	}
	var numElements int = int(self.Length())

	for i := 0; i < numElements; i++ {
		el := C.g_slist_nth_data(self.object, C.guint(i))
		self.DestroyFunc(unsafe.Pointer(el))
	}
	self.Free()
}
예제 #30
0
func (v *Structure) fromGstStructure(s *C.GstStructure) {
	v.Name = C.GoString((*C.char)(C.gst_structure_get_name(s)))
	n := uint(C.gst_structure_n_fields(s))
	v.Data = make(map[string]interface{})
	for i := uint(0); i < n; i++ {
		fn := C.gst_structure_nth_field_name(s, C.guint(i))
		fv := glib.ValueFromNative(unsafe.Pointer(C.gst_structure_id_get_value(s, C.g_quark_from_string(fn))))
		val, _ := fv.GoValue()
		v.Data[C.GoString((*C.char)(fn))] = val
	}
	return
}