From cc6607f05bb98ef2011b18fe941ac7a6c5f1935b Mon Sep 17 00:00:00 2001 From: envoker Date: Sun, 15 Nov 2015 20:24:36 +0200 Subject: [PATCH 01/13] Update gdk.go --- gdk/gdk.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gdk/gdk.go b/gdk/gdk.go index 6a16373..f441ffe 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -546,6 +546,56 @@ func (v *EventKey) KeyVal() uint { return uint(c) } +/* + * EventButton + */ + +type EventButton struct { + *Event +} + +func (e *EventButton) native() *C.GdkEventButton { + return (*C.GdkEventButton)(unsafe.Pointer(e.Event.native())) +} + +func (e *EventButton) Native() uintptr { + return uintptr(unsafe.Pointer(e.native())) +} + +func (e *EventButton) Pos() (x, y int) { + n := e.native() + x = int(n.x) + y = int(n.y) + return +} + +/* + * EventMotion + */ + +type EventMotion struct { + *Event +} + +func (e *EventMotion) native() *C.GdkEventMotion { + return (*C.GdkEventMotion)(unsafe.Pointer(e.Event.native())) +} + +func (e *EventMotion) Native() uintptr { + return uintptr(unsafe.Pointer(e.native())) +} + +func (e *EventMotion) Pos() (x, y int) { + n := e.native() + x = int(n.x) + y = int(n.y) + return +} + +func (e *EventMotion) State() int { + return int(e.native().state) +} + /* * GdkPixbuf */ From ed24792452f85d515491264642428978e4ad45da Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 09:41:17 +0200 Subject: [PATCH 02/13] Create enums.go --- gdk/enums.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 gdk/enums.go diff --git a/gdk/enums.go b/gdk/enums.go new file mode 100644 index 0000000..48d9e32 --- /dev/null +++ b/gdk/enums.go @@ -0,0 +1,28 @@ +package gdk + +type EventMask int + +const ( + EXPOSURE_MASK EventMask = 1 << 1 + POINTER_MOTION_MASK EventMask = 1 << 2 + POINTER_MOTION_HINT_MASK EventMask = 1 << 3 + BUTTON_MOTION_MASK EventMask = 1 << 4 + BUTTON1_MOTION_MASK EventMask = 1 << 5 + BUTTON2_MOTION_MASK EventMask = 1 << 6 + BUTTON3_MOTION_MASK EventMask = 1 << 7 + BUTTON_PRESS_MASK EventMask = 1 << 8 + BUTTON_RELEASE_MASK EventMask = 1 << 9 + KEY_PRESS_MASK EventMask = 1 << 10 + KEY_RELEASE_MASK EventMask = 1 << 11 + ENTER_NOTIFY_MASK EventMask = 1 << 12 + LEAVE_NOTIFY_MASK EventMask = 1 << 13 + FOCUS_CHANGE_MASK EventMask = 1 << 14 + STRUCTURE_MASK EventMask = 1 << 15 + PROPERTY_CHANGE_MASK EventMask = 1 << 16 + VISIBILITY_NOTIFY_MASK EventMask = 1 << 17 + PROXIMITY_IN_MASK EventMask = 1 << 18 + PROXIMITY_OUT_MASK EventMask = 1 << 19 + SUBSTRUCTURE_MASK EventMask = 1 << 20 + SCROLL_MASK EventMask = 1 << 21 + ALL_EVENTS_MASK EventMask = 0x3FFFFE +) From aa586d6ad39a4aa723af5e48720d50f602da2356 Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 09:46:03 +0200 Subject: [PATCH 03/13] Create events.go --- gdk/events.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 gdk/events.go diff --git a/gdk/events.go b/gdk/events.go new file mode 100644 index 0000000..a3a1890 --- /dev/null +++ b/gdk/events.go @@ -0,0 +1,68 @@ +package gdk + +// #cgo pkg-config: gdk-3.0 +// #include +import "C" + +import ( + "unsafe" +) + +type EventButton struct { + event *C.GdkEventButton +} + +func (e *EventButton) native() *C.GdkEventButton { + return e.event +} + +func (e *EventButton) FromNative(ptr uintptr) { + e.event = (*C.GdkEventButton)(unsafe.Pointer(ptr)) +} + +func (e *EventButton) Native() uintptr { + return uintptr(unsafe.Pointer(e.event)) +} + +func (e *EventButton) Pos() (x, y int) { + x = int(e.native().x) + y = int(e.native().y) + return +} + +/* +struct GdkEventMotion { + GdkEventType type; + GdkWindow *window; + gint8 send_event; + guint32 time; + gdouble x; + gdouble y; + gdouble *axes; + guint state; + gint16 is_hint; + GdkDevice *device; + gdouble x_root, y_root; +}; +*/ +type EventMotion struct { + event *C.GdkEventMotion +} + +func (e *EventMotion) native() *C.GdkEventMotion { + return e.event +} + +func (e *EventMotion) FromNative(ptr uintptr) { + e.event = (*C.GdkEventMotion)(unsafe.Pointer(ptr)) +} + +func (e *EventMotion) Pos() (x, y int) { + x = int(e.native().x) + y = int(e.native().y) + return +} + +func (e *EventMotion) State() int { + return int(e.native().state) +} From f2ce80a9d914de4cbae0394b9c19f3a63a7084bc Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 09:52:23 +0200 Subject: [PATCH 04/13] Update events.go --- gdk/events.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/gdk/events.go b/gdk/events.go index a3a1890..c3cd1b2 100644 --- a/gdk/events.go +++ b/gdk/events.go @@ -8,6 +8,60 @@ import ( "unsafe" ) +/* + * GdkEvent + */ + +// Event is a representation of GDK's GdkEvent. +type Event struct { + GdkEvent *C.GdkEvent +} + +// native returns a pointer to the underlying GdkEvent. +func (v *Event) native() *C.GdkEvent { + if v == nil { + return nil + } + return v.GdkEvent +} + +// Native returns a pointer to the underlying GdkEvent. +func (v *Event) Native() uintptr { + return uintptr(unsafe.Pointer(v.native())) +} + +func marshalEvent(p uintptr) (interface{}, error) { + c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p))) + return &Event{(*C.GdkEvent)(unsafe.Pointer(c))}, nil +} + +func (v *Event) free() { + C.gdk_event_free(v.native()) +} + +/* + * GdkEventKey + */ + +// EventKey is a representation of GDK's GdkEventKey. +type EventKey struct { + *Event +} + +// Native returns a pointer to the underlying GdkEventKey. +func (v *EventKey) Native() uintptr { + return uintptr(unsafe.Pointer(v.native())) +} + +func (v *EventKey) native() *C.GdkEventKey { + return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native())) +} + +func (v *EventKey) KeyVal() uint { + c := v.native().keyval + return uint(c) +} + type EventButton struct { event *C.GdkEventButton } From 26f9bb059a42558f4346a2b23841692dcc1db003 Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 09:53:47 +0200 Subject: [PATCH 05/13] Update gdk.go --- gdk/gdk.go | 104 ----------------------------------------------------- 1 file changed, 104 deletions(-) diff --git a/gdk/gdk.go b/gdk/gdk.go index f441ffe..e511c74 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -492,110 +492,6 @@ func (v *Display) NotifyStartupComplete(startupID string) { C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr)) } -/* - * GdkEvent - */ - -// Event is a representation of GDK's GdkEvent. -type Event struct { - GdkEvent *C.GdkEvent -} - -// native returns a pointer to the underlying GdkEvent. -func (v *Event) native() *C.GdkEvent { - if v == nil { - return nil - } - return v.GdkEvent -} - -// Native returns a pointer to the underlying GdkEvent. -func (v *Event) Native() uintptr { - return uintptr(unsafe.Pointer(v.native())) -} - -func marshalEvent(p uintptr) (interface{}, error) { - c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p))) - return &Event{(*C.GdkEvent)(unsafe.Pointer(c))}, nil -} - -func (v *Event) free() { - C.gdk_event_free(v.native()) -} - -/* - * GdkEventKey - */ - -// EventKey is a representation of GDK's GdkEventKey. -type EventKey struct { - *Event -} - -// Native returns a pointer to the underlying GdkEventKey. -func (v *EventKey) Native() uintptr { - return uintptr(unsafe.Pointer(v.native())) -} - -func (v *EventKey) native() *C.GdkEventKey { - return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native())) -} - -func (v *EventKey) KeyVal() uint { - c := v.native().keyval - return uint(c) -} - -/* - * EventButton - */ - -type EventButton struct { - *Event -} - -func (e *EventButton) native() *C.GdkEventButton { - return (*C.GdkEventButton)(unsafe.Pointer(e.Event.native())) -} - -func (e *EventButton) Native() uintptr { - return uintptr(unsafe.Pointer(e.native())) -} - -func (e *EventButton) Pos() (x, y int) { - n := e.native() - x = int(n.x) - y = int(n.y) - return -} - -/* - * EventMotion - */ - -type EventMotion struct { - *Event -} - -func (e *EventMotion) native() *C.GdkEventMotion { - return (*C.GdkEventMotion)(unsafe.Pointer(e.Event.native())) -} - -func (e *EventMotion) Native() uintptr { - return uintptr(unsafe.Pointer(e.native())) -} - -func (e *EventMotion) Pos() (x, y int) { - n := e.native() - x = int(n.x) - y = int(n.y) - return -} - -func (e *EventMotion) State() int { - return int(e.native().state) -} - /* * GdkPixbuf */ From b9f3eb669c81df77ed2e813c5288e18fc26bd8f6 Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 10:08:01 +0200 Subject: [PATCH 06/13] Update cairo.go --- cairo/cairo.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/cairo/cairo.go b/cairo/cairo.go index ba5386a..5b5ec61 100644 --- a/cairo/cairo.go +++ b/cairo/cairo.go @@ -24,6 +24,7 @@ package cairo // #include import "C" import ( + "errors" "reflect" "runtime" "unsafe" @@ -237,6 +238,56 @@ const ( // STATUS_DEVICE_FINISHED Status = C.CAIRO_STATUS_DEVICE_FINISHED (since 1.12) ) +var key_Status = map[Status]string{ + + STATUS_SUCCESS: "CAIRO_STATUS_SUCCESS", + STATUS_NO_MEMORY: "CAIRO_STATUS_NO_MEMORY", + STATUS_INVALID_RESTORE: "CAIRO_STATUS_INVALID_RESTORE", + STATUS_INVALID_POP_GROUP: "CAIRO_STATUS_INVALID_POP_GROUP", + STATUS_NO_CURRENT_POINT: "CAIRO_STATUS_NO_CURRENT_POINT", + STATUS_INVALID_MATRIX: "CAIRO_STATUS_INVALID_MATRIX", + STATUS_INVALID_STATUS: "CAIRO_STATUS_INVALID_STATUS", + STATUS_NULL_POINTER: "CAIRO_STATUS_NULL_POINTER", + STATUS_INVALID_STRING: "CAIRO_STATUS_INVALID_STRING", + STATUS_INVALID_PATH_DATA: "CAIRO_STATUS_INVALID_PATH_DATA", + STATUS_READ_ERROR: "CAIRO_STATUS_READ_ERROR", + STATUS_WRITE_ERROR: "CAIRO_STATUS_WRITE_ERROR", + STATUS_SURFACE_FINISHED: "CAIRO_STATUS_SURFACE_FINISHED", + STATUS_SURFACE_TYPE_MISMATCH: "CAIRO_STATUS_SURFACE_TYPE_MISMATCH", + STATUS_PATTERN_TYPE_MISMATCH: "CAIRO_STATUS_PATTERN_TYPE_MISMATCH", + STATUS_INVALID_CONTENT: "CAIRO_STATUS_INVALID_CONTENT", + STATUS_INVALID_FORMAT: "CAIRO_STATUS_INVALID_FORMAT", + STATUS_INVALID_VISUAL: "CAIRO_STATUS_INVALID_VISUAL", + STATUS_FILE_NOT_FOUND: "CAIRO_STATUS_FILE_NOT_FOUND", + STATUS_INVALID_DASH: "CAIRO_STATUS_INVALID_DASH", + STATUS_INVALID_DSC_COMMENT: "CAIRO_STATUS_INVALID_DSC_COMMENT", + STATUS_INVALID_INDEX: "CAIRO_STATUS_INVALID_INDEX", + STATUS_CLIP_NOT_REPRESENTABLE: "CAIRO_STATUS_CLIP_NOT_REPRESENTABLE", + STATUS_TEMP_FILE_ERROR: "CAIRO_STATUS_TEMP_FILE_ERROR", + STATUS_INVALID_STRIDE: "CAIRO_STATUS_INVALID_STRIDE", + STATUS_FONT_TYPE_MISMATCH: "CAIRO_STATUS_FONT_TYPE_MISMATCH", + STATUS_USER_FONT_IMMUTABLE: "CAIRO_STATUS_USER_FONT_IMMUTABLE", + STATUS_USER_FONT_ERROR: "CAIRO_STATUS_USER_FONT_ERROR", + STATUS_NEGATIVE_COUNT: "CAIRO_STATUS_NEGATIVE_COUNT", + STATUS_INVALID_CLUSTERS: "CAIRO_STATUS_INVALID_CLUSTERS", + STATUS_INVALID_SLANT: "CAIRO_STATUS_INVALID_SLANT", + STATUS_INVALID_WEIGHT: "CAIRO_STATUS_INVALID_WEIGHT", + STATUS_INVALID_SIZE: "CAIRO_STATUS_INVALID_SIZE", + STATUS_USER_FONT_NOT_IMPLEMENTED: "CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED", + STATUS_DEVICE_TYPE_MISMATCH: "CAIRO_STATUS_DEVICE_TYPE_MISMATCH", + STATUS_DEVICE_ERROR: "CAIRO_STATUS_DEVICE_ERROR", +} + +func StatusToString(status Status) string { + + s, ok := key_Status[status] + if !ok { + s = "CAIRO_STATUS_UNDEFINED" + } + + return s +} + func marshalStatus(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return Status(c), nil @@ -679,6 +730,21 @@ type Surface struct { surface *C.cairo_surface_t } +func NewSurfaceFromPNG(fileName string) (*Surface, error) { + + cstr := C.CString(fileName) + defer C.free(unsafe.Pointer(cstr)) + + surfaceNative := C.cairo_image_surface_create_from_png(cstr) + + status := Status(C.cairo_surface_status(surfaceNative)) + if status != STATUS_SUCCESS { + return nil, errors.New(StatusToString(status)) + } + + return &Surface{surfaceNative}, nil +} + // native returns a pointer to the underlying cairo_surface_t. func (v *Surface) native() *C.cairo_surface_t { if v == nil { From 201a7eabae042015dcb3b8bf5727500b2c63bf84 Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 10:17:32 +0200 Subject: [PATCH 07/13] Update cairo.go --- cairo/cairo.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cairo/cairo.go b/cairo/cairo.go index 5b5ec61..765d171 100644 --- a/cairo/cairo.go +++ b/cairo/cairo.go @@ -24,7 +24,6 @@ package cairo // #include import "C" import ( - "errors" "reflect" "runtime" "unsafe" @@ -739,7 +738,7 @@ func NewSurfaceFromPNG(fileName string) (*Surface, error) { status := Status(C.cairo_surface_status(surfaceNative)) if status != STATUS_SUCCESS { - return nil, errors.New(StatusToString(status)) + return nil, ErrorStatus(status) } return &Surface{surfaceNative}, nil From f0d38be055383e2b7689ed38fe97bd49428daa39 Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 10:18:50 +0200 Subject: [PATCH 08/13] Create errors.go --- cairo/errors.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 cairo/errors.go diff --git a/cairo/errors.go b/cairo/errors.go new file mode 100644 index 0000000..1e48a8a --- /dev/null +++ b/cairo/errors.go @@ -0,0 +1,7 @@ +package cairo + +type ErrorStatus Status + +func (e ErrorStatus) Error() string { + return StatusToString(Status(e)) +} From c7dba95abdae398764b82c17d96b4d72b0e4ebae Mon Sep 17 00:00:00 2001 From: envoker Date: Wed, 2 Dec 2015 10:33:17 +0200 Subject: [PATCH 09/13] Update events.go --- gdk/events.go | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/gdk/events.go b/gdk/events.go index c3cd1b2..556acc3 100644 --- a/gdk/events.go +++ b/gdk/events.go @@ -62,20 +62,20 @@ func (v *EventKey) KeyVal() uint { return uint(c) } -type EventButton struct { - event *C.GdkEventButton -} +/* + * GdkEventButton + */ -func (e *EventButton) native() *C.GdkEventButton { - return e.event +type EventButton struct { + *Event } -func (e *EventButton) FromNative(ptr uintptr) { - e.event = (*C.GdkEventButton)(unsafe.Pointer(ptr)) +func (e *EventButton) Native() uintptr { + return uintptr(unsafe.Pointer(e.native())) } -func (e *EventButton) Native() uintptr { - return uintptr(unsafe.Pointer(e.event)) +func (e *EventButton) native() *C.GdkEventButton { + return (*C.GdkEventButton)(unsafe.Pointer(e.Event.native())) } func (e *EventButton) Pos() (x, y int) { @@ -85,30 +85,19 @@ func (e *EventButton) Pos() (x, y int) { } /* -struct GdkEventMotion { - GdkEventType type; - GdkWindow *window; - gint8 send_event; - guint32 time; - gdouble x; - gdouble y; - gdouble *axes; - guint state; - gint16 is_hint; - GdkDevice *device; - gdouble x_root, y_root; -}; -*/ + * GdkEventMotion + */ + type EventMotion struct { - event *C.GdkEventMotion + *Event } -func (e *EventMotion) native() *C.GdkEventMotion { - return e.event +func (e *EventMotion) Native() uintptr { + return uintptr(unsafe.Pointer(e.native())) } -func (e *EventMotion) FromNative(ptr uintptr) { - e.event = (*C.GdkEventMotion)(unsafe.Pointer(ptr)) +func (e *EventMotion) native() *C.GdkEventMotion { + return (*C.GdkEventMotion)(unsafe.Pointer(e.Event.native())) } func (e *EventMotion) Pos() (x, y int) { From 5ad5672a1b0a670c7be8e6c3e4e229ec507c417a Mon Sep 17 00:00:00 2001 From: gitchander Date: Fri, 4 Dec 2015 17:47:12 +0200 Subject: [PATCH 10/13] fix cairo --- cairo/cairo.go | 602 +------------------------- cairo/canvas.go | 397 +++++++++++++++++ cairo/surface.go | 206 +++++++++ cairo/util.go | 21 + gdk/gdk.go | 2 +- glib/glib_test.go | 4 +- gtk/examples/addremove/addremove.go | 2 +- gtk/examples/boolprops/boolprops.go | 2 +- gtk/examples/drawingarea/game.go | 16 +- gtk/examples/goroutines/goroutines.go | 4 +- gtk/examples/grid/grid.go | 2 +- gtk/examples/signals/signals.go | 2 +- gtk/examples/simple/simple.go | 2 +- gtk/examples/textview/textview.go | 2 +- gtk/gtk.go | 20 +- gtk/gtk_3_10-12.go | 4 +- gtk/gtk_3_12.go | 156 ------- gtk/gtk_3_12.go.h | 23 - gtk/gtk_3_6-10.go | 2 +- gtk/gtk_3_6-8.go | 2 +- gtk/gtk_test.go | 3 +- pango/pango.go | 2 +- 22 files changed, 666 insertions(+), 810 deletions(-) create mode 100644 cairo/canvas.go create mode 100644 cairo/surface.go create mode 100644 cairo/util.go delete mode 100644 gtk/gtk_3_12.go delete mode 100644 gtk/gtk_3_12.go.h diff --git a/cairo/cairo.go b/cairo/cairo.go index 765d171..b6e17d1 100644 --- a/cairo/cairo.go +++ b/cairo/cairo.go @@ -24,11 +24,9 @@ package cairo // #include import "C" import ( - "reflect" - "runtime" "unsafe" - "github.com/conformal/gotk3/glib" + "github.com/envoker/gotk3/glib" ) func init() { @@ -50,22 +48,6 @@ func init() { glib.RegisterGValueMarshalers(tm) } -// Type conversions - -func cairobool(b bool) C.cairo_bool_t { - if b { - return C.cairo_bool_t(1) - } - return C.cairo_bool_t(0) -} - -func gobool(b C.cairo_bool_t) bool { - if b != 0 { - return true - } - return false -} - // Constants // Antialias is a representation of Cairo's cairo_antialias_t. @@ -327,585 +309,3 @@ func marshalSurfaceType(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return SurfaceType(c), nil } - -/* - * cairo_t - */ - -// Context is a representation of Cairo's cairo_t. -type Context struct { - context *C.cairo_t -} - -// native returns a pointer to the underlying cairo_t. -func (v *Context) native() *C.cairo_t { - if v == nil { - return nil - } - return v.context -} - -// Native returns a pointer to the underlying cairo_t. -func (v *Context) Native() uintptr { - return uintptr(unsafe.Pointer(v.native())) -} - -func marshalContext(p uintptr) (interface{}, error) { - c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p))) - context := (*C.cairo_t)(unsafe.Pointer(c)) - return wrapContext(context), nil -} - -func wrapContext(context *C.cairo_t) *Context { - return &Context{context} -} - -// Create is a wrapper around cairo_create(). -func Create(target *Surface) *Context { - c := C.cairo_create(target.native()) - ctx := wrapContext(c) - runtime.SetFinalizer(ctx, (*Context).destroy) - return ctx -} - -// reference is a wrapper around cairo_reference(). -func (v *Context) reference() { - v.context = C.cairo_reference(v.native()) -} - -// destroy is a wrapper around cairo_destroy(). -func (v *Context) destroy() { - C.cairo_destroy(v.native()) -} - -// Status is a wrapper around cairo_status(). -func (v *Context) Status() Status { - c := C.cairo_status(v.native()) - return Status(c) -} - -// Save is a wrapper around cairo_save(). -func (v *Context) Save() { - C.cairo_save(v.native()) -} - -// Restore is a wrapper around cairo_restore(). -func (v *Context) Restore() { - C.cairo_restore(v.native()) -} - -// GetTarget is a wrapper around cairo_get_target(). -func (v *Context) GetTarget() *Surface { - c := C.cairo_get_target(v.native()) - s := wrapSurface(c) - s.reference() - runtime.SetFinalizer(s, (*Surface).destroy) - return s -} - -// PushGroup is a wrapper around cairo_push_group(). -func (v *Context) PushGroup() { - C.cairo_push_group(v.native()) -} - -// PushGroupWithContent is a wrapper around cairo_push_group_with_content(). -func (v *Context) PushGroupWithContent(content Content) { - C.cairo_push_group_with_content(v.native(), C.cairo_content_t(content)) -} - -// TODO(jrick) PopGroup (depends on Pattern) - -// PopGroupToSource is a wrapper around cairo_pop_group_to_source(). -func (v *Context) PopGroupToSource() { - C.cairo_pop_group_to_source(v.native()) -} - -// GetGroupTarget is a wrapper around cairo_get_group_target(). -func (v *Context) GetGroupTarget() *Surface { - c := C.cairo_get_group_target(v.native()) - s := wrapSurface(c) - s.reference() - runtime.SetFinalizer(s, (*Surface).destroy) - return s -} - -// SetSourceRGB is a wrapper around cairo_set_source_rgb(). -func (v *Context) SetSourceRGB(red, green, blue float64) { - C.cairo_set_source_rgb(v.native(), C.double(red), C.double(green), - C.double(blue)) -} - -// SetSourceRGBA is a wrapper around cairo_set_source_rgba(). -func (v *Context) SetSourceRGBA(red, green, blue, alpha float64) { - C.cairo_set_source_rgba(v.native(), C.double(red), C.double(green), - C.double(blue), C.double(alpha)) -} - -// TODO(jrick) SetSource (depends on Pattern) - -// SetSourceSurface is a wrapper around cairo_set_source_surface(). -func (v *Context) SetSourceSurface(surface *Surface, x, y float64) { - C.cairo_set_source_surface(v.native(), surface.native(), C.double(x), - C.double(y)) -} - -// TODO(jrick) GetSource (depends on Pattern) - -// SetAntialias is a wrapper around cairo_set_antialias(). -func (v *Context) SetAntialias(antialias Antialias) { - C.cairo_set_antialias(v.native(), C.cairo_antialias_t(antialias)) -} - -// GetAntialias is a wrapper around cairo_get_antialias(). -func (v *Context) GetAntialias() Antialias { - c := C.cairo_get_antialias(v.native()) - return Antialias(c) -} - -// SetDash is a wrapper around cairo_set_dash(). -func (v *Context) SetDash(dashes []float64, offset float64) { - header := (*reflect.SliceHeader)(unsafe.Pointer(&dashes)) - cdashes := (*C.double)(unsafe.Pointer(header.Data)) - C.cairo_set_dash(v.native(), cdashes, C.int(header.Len), - C.double(offset)) -} - -// GetDashCount is a wrapper around cairo_get_dash_count(). -func (v *Context) GetDashCount() int { - c := C.cairo_get_dash_count(v.native()) - return int(c) -} - -// GetDash is a wrapper around cairo_get_dash(). -func (v *Context) GetDash() (dashes []float64, offset float64) { - dashCount := v.GetDashCount() - cdashes := (*C.double)(C.calloc(8, C.size_t(dashCount))) - var coffset C.double - C.cairo_get_dash(v.native(), cdashes, &coffset) - header := (*reflect.SliceHeader)((unsafe.Pointer(&dashes))) - header.Data = uintptr(unsafe.Pointer(cdashes)) - header.Len = dashCount - header.Cap = dashCount - return dashes, float64(coffset) -} - -// SetFillRule is a wrapper around cairo_set_fill_rule(). -func (v *Context) SetFillRule(fillRule FillRule) { - C.cairo_set_fill_rule(v.native(), C.cairo_fill_rule_t(fillRule)) -} - -// GetFillRule is a wrapper around cairo_get_fill_rule(). -func (v *Context) GetFillRule() FillRule { - c := C.cairo_get_fill_rule(v.native()) - return FillRule(c) -} - -// SetLineCap is a wrapper around cairo_set_line_cap(). -func (v *Context) SetLineCap(lineCap LineCap) { - C.cairo_set_line_cap(v.native(), C.cairo_line_cap_t(lineCap)) -} - -// GetLineCap is a wrapper around cairo_get_line_cap(). -func (v *Context) GetLineCap() LineCap { - c := C.cairo_get_line_cap(v.native()) - return LineCap(c) -} - -// SetLineJoin is a wrapper around cairo_set_line_join(). -func (v *Context) SetLineJoin(lineJoin LineJoin) { - C.cairo_set_line_join(v.native(), C.cairo_line_join_t(lineJoin)) -} - -// GetLineJoin is a wrapper around cairo_get_line_join(). -func (v *Context) GetLineJoin() LineJoin { - c := C.cairo_get_line_join(v.native()) - return LineJoin(c) -} - -// SetLineWidth is a wrapper around cairo_set_line_width(). -func (v *Context) SetLineWidth(width float64) { - C.cairo_set_line_width(v.native(), C.double(width)) -} - -// GetLineWidth is a wrapper cairo_get_line_width(). -func (v *Context) GetLineWidth() float64 { - c := C.cairo_get_line_width(v.native()) - return float64(c) -} - -// SetMiterLimit is a wrapper around cairo_set_miter_limit(). -func (v *Context) SetMiterLimit(limit float64) { - C.cairo_set_miter_limit(v.native(), C.double(limit)) -} - -// GetMiterLimit is a wrapper around cairo_get_miter_limit(). -func (v *Context) GetMiterLimit() float64 { - c := C.cairo_get_miter_limit(v.native()) - return float64(c) -} - -// SetOperator is a wrapper around cairo_set_operator(). -func (v *Context) SetOperator(op Operator) { - C.cairo_set_operator(v.native(), C.cairo_operator_t(op)) -} - -// GetOperator is a wrapper around cairo_get_operator(). -func (v *Context) GetOperator() Operator { - c := C.cairo_get_operator(v.native()) - return Operator(c) -} - -// SetTolerance is a wrapper around cairo_set_tolerance(). -func (v *Context) SetTolerance(tolerance float64) { - C.cairo_set_tolerance(v.native(), C.double(tolerance)) -} - -// GetTolerance is a wrapper around cairo_get_tolerance(). -func (v *Context) GetTolerance() float64 { - c := C.cairo_get_tolerance(v.native()) - return float64(c) -} - -// Clip is a wrapper around cairo_clip(). -func (v *Context) Clip() { - C.cairo_clip(v.native()) -} - -// ClipPreserve is a wrapper around cairo_clip_preserve(). -func (v *Context) ClipPreserve() { - C.cairo_clip_preserve(v.native()) -} - -// ClipExtents is a wrapper around cairo_clip_extents(). -func (v *Context) ClipExtents() (x1, y1, x2, y2 float64) { - var cx1, cy1, cx2, cy2 C.double - C.cairo_clip_extents(v.native(), &cx1, &cy1, &cx2, &cy2) - return float64(cx1), float64(cy1), float64(cx2), float64(cy2) -} - -// InClip is a wrapper around cairo_in_clip(). -func (v *Context) InClip(x, y float64) bool { - c := C.cairo_in_clip(v.native(), C.double(x), C.double(y)) - return gobool(c) -} - -// ResetClip is a wrapper around cairo_reset_clip(). -func (v *Context) ResetClip() { - C.cairo_reset_clip(v.native()) -} - -// Rectangle is a wrapper around cairo_rectangle(). -func (v *Context) Rectangle(x, y, w, h float64) { - C.cairo_rectangle(v.native(), C.double(x), C.double(y), C.double(w), C.double(h)) -} - -// Arc is a wrapper around cairo_arc(). -func (v *Context) Arc(xc, yc, radius, angle1, angle2 float64) { - C.cairo_arc(v.native(), C.double(xc), C.double(yc), C.double(radius), C.double(angle1), C.double(angle2)) -} - -// ArcNegative is a wrapper around cairo_arc_negative(). -func (v *Context) ArcNegative(xc, yc, radius, angle1, angle2 float64) { - C.cairo_arc_negative(v.native(), C.double(xc), C.double(yc), C.double(radius), C.double(angle1), C.double(angle2)) -} - -// LineTo is a wrapper around cairo_line_to(). -func (v *Context) LineTo(x, y float64) { - C.cairo_line_to(v.native(), C.double(x), C.double(y)) -} - -// CurveTo is a wrapper around cairo_curve_to(). -func (v *Context) CurveTo(x1, y1, x2, y2, x3, y3 float64) { - C.cairo_curve_to(v.native(), C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x3), C.double(y3)) -} - -// MoveTo is a wrapper around cairo_move_to(). -func (v *Context) MoveTo(x, y float64) { - C.cairo_move_to(v.native(), C.double(x), C.double(y)) -} - -// TODO(jrick) CopyRectangleList (depends on RectangleList) - -// Fill is a wrapper around cairo_fill(). -func (v *Context) Fill() { - C.cairo_fill(v.native()) -} - -// ClosePath is a wrapper around cairo_close_path(). -func (v *Context) ClosePath() { - C.cairo_close_path(v.native()) -} - -// NewPath is a wrapper around cairo_new_path(). -func (v *Context) NewPath() { - C.cairo_new_path(v.native()) -} - -// GetCurrentPoint is a wrapper around cairo_get_current_point(). -func (v *Context) GetCurrentPoint() (x, y float64) { - C.cairo_get_current_point(v.native(), (*C.double)(&x), (*C.double)(&y)) - return -} - -// FillPreserve is a wrapper around cairo_fill_preserve(). -func (v *Context) FillPreserve() { - C.cairo_fill_preserve(v.native()) -} - -// FillExtents is a wrapper around cairo_fill_extents(). -func (v *Context) FillExtents() (x1, y1, x2, y2 float64) { - var cx1, cy1, cx2, cy2 C.double - C.cairo_fill_extents(v.native(), &cx1, &cy1, &cx2, &cy2) - return float64(cx1), float64(cy1), float64(cx2), float64(cy2) -} - -// InFill is a wrapper around cairo_in_fill(). -func (v *Context) InFill(x, y float64) bool { - c := C.cairo_in_fill(v.native(), C.double(x), C.double(y)) - return gobool(c) -} - -// TODO(jrick) Mask (depends on Pattern) - -// MaskSurface is a wrapper around cairo_mask_surface(). -func (v *Context) MaskSurface(surface *Surface, surfaceX, surfaceY float64) { - C.cairo_mask_surface(v.native(), surface.native(), C.double(surfaceX), - C.double(surfaceY)) -} - -// Paint is a wrapper around cairo_paint(). -func (v *Context) Paint() { - C.cairo_paint(v.native()) -} - -// PaintWithAlpha is a wrapper around cairo_paint_with_alpha(). -func (v *Context) PaintWithAlpha(alpha float64) { - C.cairo_paint_with_alpha(v.native(), C.double(alpha)) -} - -// Stroke is a wrapper around cairo_stroke(). -func (v *Context) Stroke() { - C.cairo_stroke(v.native()) -} - -// StrokePreserve is a wrapper around cairo_stroke_preserve(). -func (v *Context) StrokePreserve() { - C.cairo_stroke_preserve(v.native()) -} - -// StrokeExtents is a wrapper around cairo_stroke_extents(). -func (v *Context) StrokeExtents() (x1, y1, x2, y2 float64) { - var cx1, cy1, cx2, cy2 C.double - C.cairo_stroke_extents(v.native(), &cx1, &cy1, &cx2, &cy2) - return float64(cx1), float64(cy1), float64(cx2), float64(cy2) -} - -// InStroke is a wrapper around cairo_in_stroke(). -func (v *Context) InStroke(x, y float64) bool { - c := C.cairo_in_stroke(v.native(), C.double(x), C.double(y)) - return gobool(c) -} - -// CopyPage is a wrapper around cairo_copy_page(). -func (v *Context) CopyPage() { - C.cairo_copy_page(v.native()) -} - -// ShowPage is a wrapper around cairo_show_page(). -func (v *Context) ShowPage() { - C.cairo_show_page(v.native()) -} - -// TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc) - -// TODO(jrick) GetUserData (depends on UserDataKey) - -/* - * cairo_surface_t - */ - -// Surface is a representation of Cairo's cairo_surface_t. -type Surface struct { - surface *C.cairo_surface_t -} - -func NewSurfaceFromPNG(fileName string) (*Surface, error) { - - cstr := C.CString(fileName) - defer C.free(unsafe.Pointer(cstr)) - - surfaceNative := C.cairo_image_surface_create_from_png(cstr) - - status := Status(C.cairo_surface_status(surfaceNative)) - if status != STATUS_SUCCESS { - return nil, ErrorStatus(status) - } - - return &Surface{surfaceNative}, nil -} - -// native returns a pointer to the underlying cairo_surface_t. -func (v *Surface) native() *C.cairo_surface_t { - if v == nil { - return nil - } - return v.surface -} - -// Native returns a pointer to the underlying cairo_surface_t. -func (v *Surface) Native() uintptr { - return uintptr(unsafe.Pointer(v.native())) -} - -func marshalSurface(p uintptr) (interface{}, error) { - c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p))) - surface := (*C.cairo_surface_t)(unsafe.Pointer(c)) - return wrapSurface(surface), nil -} - -func wrapSurface(surface *C.cairo_surface_t) *Surface { - return &Surface{surface} -} - -// NewSurface creates a gotk3 cairo Surface from a pointer to a -// C cairo_surface_t. This is primarily designed for use with other -// gotk3 packages and should be avoided by applications. -func NewSurface(s uintptr, needsRef bool) *Surface { - ptr := (*C.cairo_surface_t)(unsafe.Pointer(s)) - surface := wrapSurface(ptr) - if needsRef { - surface.reference() - } - runtime.SetFinalizer(surface, (*Surface).destroy) - return surface -} - -// CreateSimilar is a wrapper around cairo_surface_create_similar(). -func (v *Surface) CreateSimilar(content Content, width, height int) *Surface { - c := C.cairo_surface_create_similar(v.native(), - C.cairo_content_t(content), C.int(width), C.int(height)) - s := wrapSurface(c) - runtime.SetFinalizer(s, (*Surface).destroy) - return s -} - -// TODO cairo_surface_create_similar_image (since 1.12) - -// CreateForRectangle is a wrapper around cairo_surface_create_for_rectangle(). -func (v *Surface) CreateForRectangle(x, y, width, height float64) *Surface { - c := C.cairo_surface_create_for_rectangle(v.native(), C.double(x), - C.double(y), C.double(width), C.double(height)) - s := wrapSurface(c) - runtime.SetFinalizer(s, (*Surface).destroy) - return s -} - -// reference is a wrapper around cairo_surface_reference(). -func (v *Surface) reference() { - v.surface = C.cairo_surface_reference(v.native()) -} - -// destroy is a wrapper around cairo_surface_destroy(). -func (v *Surface) destroy() { - C.cairo_surface_destroy(v.native()) -} - -// Status is a wrapper around cairo_surface_status(). -func (v *Surface) Status() Status { - c := C.cairo_surface_status(v.native()) - return Status(c) -} - -// Flush is a wrapper around cairo_surface_flush(). -func (v *Surface) Flush() { - C.cairo_surface_flush(v.native()) -} - -// TODO(jrick) GetDevice (requires Device bindings) - -// TODO(jrick) GetFontOptions (require FontOptions bindings) - -// TODO(jrick) GetContent (requires Content bindings) - -// MarkDirty is a wrapper around cairo_surface_mark_dirty(). -func (v *Surface) MarkDirty() { - C.cairo_surface_mark_dirty(v.native()) -} - -// MarkDirtyRectangle is a wrapper around cairo_surface_mark_dirty_rectangle(). -func (v *Surface) MarkDirtyRectangle(x, y, width, height int) { - C.cairo_surface_mark_dirty_rectangle(v.native(), C.int(x), C.int(y), - C.int(width), C.int(height)) -} - -// SetDeviceOffset is a wrapper around cairo_surface_set_device_offset(). -func (v *Surface) SetDeviceOffset(x, y float64) { - C.cairo_surface_set_device_offset(v.native(), C.double(x), C.double(y)) -} - -// GetDeviceOffset is a wrapper around cairo_surface_get_device_offset(). -func (v *Surface) GetDeviceOffset() (x, y float64) { - var xOffset, yOffset C.double - C.cairo_surface_get_device_offset(v.native(), &xOffset, &yOffset) - return float64(xOffset), float64(yOffset) -} - -// SetFallbackResolution is a wrapper around -// cairo_surface_set_fallback_resolution(). -func (v *Surface) SetFallbackResolution(xPPI, yPPI float64) { - C.cairo_surface_set_fallback_resolution(v.native(), C.double(xPPI), - C.double(yPPI)) -} - -// GetFallbackResolution is a wrapper around -// cairo_surface_get_fallback_resolution(). -func (v *Surface) GetFallbackResolution() (xPPI, yPPI float64) { - var x, y C.double - C.cairo_surface_get_fallback_resolution(v.native(), &x, &y) - return float64(x), float64(y) -} - -// GetType is a wrapper around cairo_surface_get_type(). -func (v *Surface) GetType() SurfaceType { - c := C.cairo_surface_get_type(v.native()) - return SurfaceType(c) -} - -// TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc) - -// TODO(jrick) GetUserData (depends on UserDataKey) - -// CopyPage is a wrapper around cairo_surface_copy_page(). -func (v *Surface) CopyPage() { - C.cairo_surface_copy_page(v.native()) -} - -// ShowPage is a wrapper around cairo_surface_show_page(). -func (v *Surface) ShowPage() { - C.cairo_surface_show_page(v.native()) -} - -// HasShowTextGlyphs is a wrapper around cairo_surface_has_show_text_glyphs(). -func (v *Surface) HasShowTextGlyphs() bool { - c := C.cairo_surface_has_show_text_glyphs(v.native()) - return gobool(c) -} - -// TODO(jrick) SetMimeData (depends on DestroyFunc) - -// GetMimeData is a wrapper around cairo_surface_get_mime_data(). The -// returned mimetype data is returned as a Go byte slice. -func (v *Surface) GetMimeData(mimeType MimeType) []byte { - cstr := C.CString(string(mimeType)) - defer C.free(unsafe.Pointer(cstr)) - var data *C.uchar - var length C.ulong - C.cairo_surface_get_mime_data(v.native(), cstr, &data, &length) - return C.GoBytes(unsafe.Pointer(data), C.int(length)) -} - -// TODO(jrick) SupportsMimeType (since 1.12) - -// TODO(jrick) MapToImage (since 1.12) - -// TODO(jrick) UnmapImage (since 1.12) diff --git a/cairo/canvas.go b/cairo/canvas.go new file mode 100644 index 0000000..0d88f76 --- /dev/null +++ b/cairo/canvas.go @@ -0,0 +1,397 @@ +package cairo + +// #cgo pkg-config: cairo cairo-gobject +// #include +// #include +// #include +import "C" + +import ( + "reflect" + "runtime" + "unsafe" +) + +// Context is a representation of Cairo's cairo_t. +type Context struct { + context *C.cairo_t +} + +// native returns a pointer to the underlying cairo_t. +func (v *Context) native() *C.cairo_t { + if v == nil { + return nil + } + return v.context +} + +// Native returns a pointer to the underlying cairo_t. +func (v *Context) Native() uintptr { + return uintptr(unsafe.Pointer(v.native())) +} + +func marshalContext(p uintptr) (interface{}, error) { + c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p))) + context := (*C.cairo_t)(unsafe.Pointer(c)) + return wrapContext(context), nil +} + +func wrapContext(context *C.cairo_t) *Context { + return &Context{context} +} + +// Create is a wrapper around cairo_create(). +func Create(target *Surface) *Context { + c := C.cairo_create(target.native()) + ctx := wrapContext(c) + runtime.SetFinalizer(ctx, (*Context).destroy) + return ctx +} + +// reference is a wrapper around cairo_reference(). +func (v *Context) reference() { + v.context = C.cairo_reference(v.native()) +} + +// destroy is a wrapper around cairo_destroy(). +func (v *Context) destroy() { + C.cairo_destroy(v.native()) +} + +// Status is a wrapper around cairo_status(). +func (v *Context) Status() Status { + c := C.cairo_status(v.native()) + return Status(c) +} + +// Save is a wrapper around cairo_save(). +func (v *Context) Save() { + C.cairo_save(v.native()) +} + +// Restore is a wrapper around cairo_restore(). +func (v *Context) Restore() { + C.cairo_restore(v.native()) +} + +// GetTarget is a wrapper around cairo_get_target(). +func (v *Context) GetTarget() *Surface { + c := C.cairo_get_target(v.native()) + s := wrapSurface(c) + s.reference() + runtime.SetFinalizer(s, (*Surface).destroy) + return s +} + +// PushGroup is a wrapper around cairo_push_group(). +func (v *Context) PushGroup() { + C.cairo_push_group(v.native()) +} + +// PushGroupWithContent is a wrapper around cairo_push_group_with_content(). +func (v *Context) PushGroupWithContent(content Content) { + C.cairo_push_group_with_content(v.native(), C.cairo_content_t(content)) +} + +// TODO(jrick) PopGroup (depends on Pattern) + +// PopGroupToSource is a wrapper around cairo_pop_group_to_source(). +func (v *Context) PopGroupToSource() { + C.cairo_pop_group_to_source(v.native()) +} + +// GetGroupTarget is a wrapper around cairo_get_group_target(). +func (v *Context) GetGroupTarget() *Surface { + c := C.cairo_get_group_target(v.native()) + s := wrapSurface(c) + s.reference() + runtime.SetFinalizer(s, (*Surface).destroy) + return s +} + +// SetSourceRGB is a wrapper around cairo_set_source_rgb(). +func (v *Context) SetSourceRGB(red, green, blue float64) { + C.cairo_set_source_rgb(v.native(), C.double(red), C.double(green), + C.double(blue)) +} + +// SetSourceRGBA is a wrapper around cairo_set_source_rgba(). +func (v *Context) SetSourceRGBA(red, green, blue, alpha float64) { + C.cairo_set_source_rgba(v.native(), C.double(red), C.double(green), + C.double(blue), C.double(alpha)) +} + +// TODO(jrick) SetSource (depends on Pattern) + +// SetSourceSurface is a wrapper around cairo_set_source_surface(). +func (v *Context) SetSourceSurface(surface *Surface, x, y float64) { + C.cairo_set_source_surface(v.native(), surface.native(), C.double(x), + C.double(y)) +} + +// TODO(jrick) GetSource (depends on Pattern) + +// SetAntialias is a wrapper around cairo_set_antialias(). +func (v *Context) SetAntialias(antialias Antialias) { + C.cairo_set_antialias(v.native(), C.cairo_antialias_t(antialias)) +} + +// GetAntialias is a wrapper around cairo_get_antialias(). +func (v *Context) GetAntialias() Antialias { + c := C.cairo_get_antialias(v.native()) + return Antialias(c) +} + +// SetDash is a wrapper around cairo_set_dash(). +func (v *Context) SetDash(dashes []float64, offset float64) { + header := (*reflect.SliceHeader)(unsafe.Pointer(&dashes)) + cdashes := (*C.double)(unsafe.Pointer(header.Data)) + C.cairo_set_dash(v.native(), cdashes, C.int(header.Len), + C.double(offset)) +} + +// GetDashCount is a wrapper around cairo_get_dash_count(). +func (v *Context) GetDashCount() int { + c := C.cairo_get_dash_count(v.native()) + return int(c) +} + +// GetDash is a wrapper around cairo_get_dash(). +func (v *Context) GetDash() (dashes []float64, offset float64) { + dashCount := v.GetDashCount() + cdashes := (*C.double)(C.calloc(8, C.size_t(dashCount))) + var coffset C.double + C.cairo_get_dash(v.native(), cdashes, &coffset) + header := (*reflect.SliceHeader)((unsafe.Pointer(&dashes))) + header.Data = uintptr(unsafe.Pointer(cdashes)) + header.Len = dashCount + header.Cap = dashCount + return dashes, float64(coffset) +} + +// SetFillRule is a wrapper around cairo_set_fill_rule(). +func (v *Context) SetFillRule(fillRule FillRule) { + C.cairo_set_fill_rule(v.native(), C.cairo_fill_rule_t(fillRule)) +} + +// GetFillRule is a wrapper around cairo_get_fill_rule(). +func (v *Context) GetFillRule() FillRule { + c := C.cairo_get_fill_rule(v.native()) + return FillRule(c) +} + +// SetLineCap is a wrapper around cairo_set_line_cap(). +func (v *Context) SetLineCap(lineCap LineCap) { + C.cairo_set_line_cap(v.native(), C.cairo_line_cap_t(lineCap)) +} + +// GetLineCap is a wrapper around cairo_get_line_cap(). +func (v *Context) GetLineCap() LineCap { + c := C.cairo_get_line_cap(v.native()) + return LineCap(c) +} + +// SetLineJoin is a wrapper around cairo_set_line_join(). +func (v *Context) SetLineJoin(lineJoin LineJoin) { + C.cairo_set_line_join(v.native(), C.cairo_line_join_t(lineJoin)) +} + +// GetLineJoin is a wrapper around cairo_get_line_join(). +func (v *Context) GetLineJoin() LineJoin { + c := C.cairo_get_line_join(v.native()) + return LineJoin(c) +} + +// SetLineWidth is a wrapper around cairo_set_line_width(). +func (v *Context) SetLineWidth(width float64) { + C.cairo_set_line_width(v.native(), C.double(width)) +} + +// GetLineWidth is a wrapper cairo_get_line_width(). +func (v *Context) GetLineWidth() float64 { + c := C.cairo_get_line_width(v.native()) + return float64(c) +} + +// SetMiterLimit is a wrapper around cairo_set_miter_limit(). +func (v *Context) SetMiterLimit(limit float64) { + C.cairo_set_miter_limit(v.native(), C.double(limit)) +} + +// GetMiterLimit is a wrapper around cairo_get_miter_limit(). +func (v *Context) GetMiterLimit() float64 { + c := C.cairo_get_miter_limit(v.native()) + return float64(c) +} + +// SetOperator is a wrapper around cairo_set_operator(). +func (v *Context) SetOperator(op Operator) { + C.cairo_set_operator(v.native(), C.cairo_operator_t(op)) +} + +// GetOperator is a wrapper around cairo_get_operator(). +func (v *Context) GetOperator() Operator { + c := C.cairo_get_operator(v.native()) + return Operator(c) +} + +// SetTolerance is a wrapper around cairo_set_tolerance(). +func (v *Context) SetTolerance(tolerance float64) { + C.cairo_set_tolerance(v.native(), C.double(tolerance)) +} + +// GetTolerance is a wrapper around cairo_get_tolerance(). +func (v *Context) GetTolerance() float64 { + c := C.cairo_get_tolerance(v.native()) + return float64(c) +} + +// Clip is a wrapper around cairo_clip(). +func (v *Context) Clip() { + C.cairo_clip(v.native()) +} + +// ClipPreserve is a wrapper around cairo_clip_preserve(). +func (v *Context) ClipPreserve() { + C.cairo_clip_preserve(v.native()) +} + +// ClipExtents is a wrapper around cairo_clip_extents(). +func (v *Context) ClipExtents() (x1, y1, x2, y2 float64) { + var cx1, cy1, cx2, cy2 C.double + C.cairo_clip_extents(v.native(), &cx1, &cy1, &cx2, &cy2) + return float64(cx1), float64(cy1), float64(cx2), float64(cy2) +} + +// InClip is a wrapper around cairo_in_clip(). +func (v *Context) InClip(x, y float64) bool { + c := C.cairo_in_clip(v.native(), C.double(x), C.double(y)) + return gobool(c) +} + +// ResetClip is a wrapper around cairo_reset_clip(). +func (v *Context) ResetClip() { + C.cairo_reset_clip(v.native()) +} + +// Rectangle is a wrapper around cairo_rectangle(). +func (v *Context) Rectangle(x, y, w, h float64) { + C.cairo_rectangle(v.native(), C.double(x), C.double(y), C.double(w), C.double(h)) +} + +// Arc is a wrapper around cairo_arc(). +func (v *Context) Arc(xc, yc, radius, angle1, angle2 float64) { + C.cairo_arc(v.native(), C.double(xc), C.double(yc), C.double(radius), C.double(angle1), C.double(angle2)) +} + +// ArcNegative is a wrapper around cairo_arc_negative(). +func (v *Context) ArcNegative(xc, yc, radius, angle1, angle2 float64) { + C.cairo_arc_negative(v.native(), C.double(xc), C.double(yc), C.double(radius), C.double(angle1), C.double(angle2)) +} + +// LineTo is a wrapper around cairo_line_to(). +func (v *Context) LineTo(x, y float64) { + C.cairo_line_to(v.native(), C.double(x), C.double(y)) +} + +// CurveTo is a wrapper around cairo_curve_to(). +func (v *Context) CurveTo(x1, y1, x2, y2, x3, y3 float64) { + C.cairo_curve_to(v.native(), C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x3), C.double(y3)) +} + +// MoveTo is a wrapper around cairo_move_to(). +func (v *Context) MoveTo(x, y float64) { + C.cairo_move_to(v.native(), C.double(x), C.double(y)) +} + +// TODO(jrick) CopyRectangleList (depends on RectangleList) + +// Fill is a wrapper around cairo_fill(). +func (v *Context) Fill() { + C.cairo_fill(v.native()) +} + +// ClosePath is a wrapper around cairo_close_path(). +func (v *Context) ClosePath() { + C.cairo_close_path(v.native()) +} + +// NewPath is a wrapper around cairo_new_path(). +func (v *Context) NewPath() { + C.cairo_new_path(v.native()) +} + +// GetCurrentPoint is a wrapper around cairo_get_current_point(). +func (v *Context) GetCurrentPoint() (x, y float64) { + C.cairo_get_current_point(v.native(), (*C.double)(&x), (*C.double)(&y)) + return +} + +// FillPreserve is a wrapper around cairo_fill_preserve(). +func (v *Context) FillPreserve() { + C.cairo_fill_preserve(v.native()) +} + +// FillExtents is a wrapper around cairo_fill_extents(). +func (v *Context) FillExtents() (x1, y1, x2, y2 float64) { + var cx1, cy1, cx2, cy2 C.double + C.cairo_fill_extents(v.native(), &cx1, &cy1, &cx2, &cy2) + return float64(cx1), float64(cy1), float64(cx2), float64(cy2) +} + +// InFill is a wrapper around cairo_in_fill(). +func (v *Context) InFill(x, y float64) bool { + c := C.cairo_in_fill(v.native(), C.double(x), C.double(y)) + return gobool(c) +} + +// TODO(jrick) Mask (depends on Pattern) + +// MaskSurface is a wrapper around cairo_mask_surface(). +func (v *Context) MaskSurface(surface *Surface, surfaceX, surfaceY float64) { + C.cairo_mask_surface(v.native(), surface.native(), C.double(surfaceX), + C.double(surfaceY)) +} + +// Paint is a wrapper around cairo_paint(). +func (v *Context) Paint() { + C.cairo_paint(v.native()) +} + +// PaintWithAlpha is a wrapper around cairo_paint_with_alpha(). +func (v *Context) PaintWithAlpha(alpha float64) { + C.cairo_paint_with_alpha(v.native(), C.double(alpha)) +} + +// Stroke is a wrapper around cairo_stroke(). +func (v *Context) Stroke() { + C.cairo_stroke(v.native()) +} + +// StrokePreserve is a wrapper around cairo_stroke_preserve(). +func (v *Context) StrokePreserve() { + C.cairo_stroke_preserve(v.native()) +} + +// StrokeExtents is a wrapper around cairo_stroke_extents(). +func (v *Context) StrokeExtents() (x1, y1, x2, y2 float64) { + var cx1, cy1, cx2, cy2 C.double + C.cairo_stroke_extents(v.native(), &cx1, &cy1, &cx2, &cy2) + return float64(cx1), float64(cy1), float64(cx2), float64(cy2) +} + +// InStroke is a wrapper around cairo_in_stroke(). +func (v *Context) InStroke(x, y float64) bool { + c := C.cairo_in_stroke(v.native(), C.double(x), C.double(y)) + return gobool(c) +} + +// CopyPage is a wrapper around cairo_copy_page(). +func (v *Context) CopyPage() { + C.cairo_copy_page(v.native()) +} + +// ShowPage is a wrapper around cairo_show_page(). +func (v *Context) ShowPage() { + C.cairo_show_page(v.native()) +} diff --git a/cairo/surface.go b/cairo/surface.go new file mode 100644 index 0000000..c3acaa1 --- /dev/null +++ b/cairo/surface.go @@ -0,0 +1,206 @@ +package cairo + +// #cgo pkg-config: cairo cairo-gobject +// #include +// #include +// #include +import "C" + +import ( + "runtime" + "unsafe" +) + +// TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc) + +// TODO(jrick) GetUserData (depends on UserDataKey) + +/* + * cairo_surface_t + */ + +// Surface is a representation of Cairo's cairo_surface_t. +type Surface struct { + surface *C.cairo_surface_t +} + +func NewSurfaceFromPNG(fileName string) (*Surface, error) { + + cstr := C.CString(fileName) + defer C.free(unsafe.Pointer(cstr)) + + surfaceNative := C.cairo_image_surface_create_from_png(cstr) + + status := Status(C.cairo_surface_status(surfaceNative)) + if status != STATUS_SUCCESS { + return nil, ErrorStatus(status) + } + + return &Surface{surfaceNative}, nil +} + +// native returns a pointer to the underlying cairo_surface_t. +func (v *Surface) native() *C.cairo_surface_t { + if v == nil { + return nil + } + return v.surface +} + +// Native returns a pointer to the underlying cairo_surface_t. +func (v *Surface) Native() uintptr { + return uintptr(unsafe.Pointer(v.native())) +} + +func marshalSurface(p uintptr) (interface{}, error) { + c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p))) + surface := (*C.cairo_surface_t)(unsafe.Pointer(c)) + return wrapSurface(surface), nil +} + +func wrapSurface(surface *C.cairo_surface_t) *Surface { + return &Surface{surface} +} + +// NewSurface creates a gotk3 cairo Surface from a pointer to a +// C cairo_surface_t. This is primarily designed for use with other +// gotk3 packages and should be avoided by applications. +func NewSurface(s uintptr, needsRef bool) *Surface { + ptr := (*C.cairo_surface_t)(unsafe.Pointer(s)) + surface := wrapSurface(ptr) + if needsRef { + surface.reference() + } + runtime.SetFinalizer(surface, (*Surface).destroy) + return surface +} + +// CreateSimilar is a wrapper around cairo_surface_create_similar(). +func (v *Surface) CreateSimilar(content Content, width, height int) *Surface { + c := C.cairo_surface_create_similar(v.native(), + C.cairo_content_t(content), C.int(width), C.int(height)) + s := wrapSurface(c) + runtime.SetFinalizer(s, (*Surface).destroy) + return s +} + +// TODO cairo_surface_create_similar_image (since 1.12) + +// CreateForRectangle is a wrapper around cairo_surface_create_for_rectangle(). +func (v *Surface) CreateForRectangle(x, y, width, height float64) *Surface { + c := C.cairo_surface_create_for_rectangle(v.native(), C.double(x), + C.double(y), C.double(width), C.double(height)) + s := wrapSurface(c) + runtime.SetFinalizer(s, (*Surface).destroy) + return s +} + +// reference is a wrapper around cairo_surface_reference(). +func (v *Surface) reference() { + v.surface = C.cairo_surface_reference(v.native()) +} + +// destroy is a wrapper around cairo_surface_destroy(). +func (v *Surface) destroy() { + C.cairo_surface_destroy(v.native()) +} + +// Status is a wrapper around cairo_surface_status(). +func (v *Surface) Status() Status { + c := C.cairo_surface_status(v.native()) + return Status(c) +} + +// Flush is a wrapper around cairo_surface_flush(). +func (v *Surface) Flush() { + C.cairo_surface_flush(v.native()) +} + +// TODO(jrick) GetDevice (requires Device bindings) + +// TODO(jrick) GetFontOptions (require FontOptions bindings) + +// TODO(jrick) GetContent (requires Content bindings) + +// MarkDirty is a wrapper around cairo_surface_mark_dirty(). +func (v *Surface) MarkDirty() { + C.cairo_surface_mark_dirty(v.native()) +} + +// MarkDirtyRectangle is a wrapper around cairo_surface_mark_dirty_rectangle(). +func (v *Surface) MarkDirtyRectangle(x, y, width, height int) { + C.cairo_surface_mark_dirty_rectangle(v.native(), C.int(x), C.int(y), + C.int(width), C.int(height)) +} + +// SetDeviceOffset is a wrapper around cairo_surface_set_device_offset(). +func (v *Surface) SetDeviceOffset(x, y float64) { + C.cairo_surface_set_device_offset(v.native(), C.double(x), C.double(y)) +} + +// GetDeviceOffset is a wrapper around cairo_surface_get_device_offset(). +func (v *Surface) GetDeviceOffset() (x, y float64) { + var xOffset, yOffset C.double + C.cairo_surface_get_device_offset(v.native(), &xOffset, &yOffset) + return float64(xOffset), float64(yOffset) +} + +// SetFallbackResolution is a wrapper around +// cairo_surface_set_fallback_resolution(). +func (v *Surface) SetFallbackResolution(xPPI, yPPI float64) { + C.cairo_surface_set_fallback_resolution(v.native(), C.double(xPPI), + C.double(yPPI)) +} + +// GetFallbackResolution is a wrapper around +// cairo_surface_get_fallback_resolution(). +func (v *Surface) GetFallbackResolution() (xPPI, yPPI float64) { + var x, y C.double + C.cairo_surface_get_fallback_resolution(v.native(), &x, &y) + return float64(x), float64(y) +} + +// GetType is a wrapper around cairo_surface_get_type(). +func (v *Surface) GetType() SurfaceType { + c := C.cairo_surface_get_type(v.native()) + return SurfaceType(c) +} + +// TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc) + +// TODO(jrick) GetUserData (depends on UserDataKey) + +// CopyPage is a wrapper around cairo_surface_copy_page(). +func (v *Surface) CopyPage() { + C.cairo_surface_copy_page(v.native()) +} + +// ShowPage is a wrapper around cairo_surface_show_page(). +func (v *Surface) ShowPage() { + C.cairo_surface_show_page(v.native()) +} + +// HasShowTextGlyphs is a wrapper around cairo_surface_has_show_text_glyphs(). +func (v *Surface) HasShowTextGlyphs() bool { + c := C.cairo_surface_has_show_text_glyphs(v.native()) + return gobool(c) +} + +// TODO(jrick) SetMimeData (depends on DestroyFunc) + +// GetMimeData is a wrapper around cairo_surface_get_mime_data(). The +// returned mimetype data is returned as a Go byte slice. +func (v *Surface) GetMimeData(mimeType MimeType) []byte { + cstr := C.CString(string(mimeType)) + defer C.free(unsafe.Pointer(cstr)) + var data *C.uchar + var length C.ulong + C.cairo_surface_get_mime_data(v.native(), cstr, &data, &length) + return C.GoBytes(unsafe.Pointer(data), C.int(length)) +} + +// TODO(jrick) SupportsMimeType (since 1.12) + +// TODO(jrick) MapToImage (since 1.12) + +// TODO(jrick) UnmapImage (since 1.12) diff --git a/cairo/util.go b/cairo/util.go new file mode 100644 index 0000000..6659109 --- /dev/null +++ b/cairo/util.go @@ -0,0 +1,21 @@ +package cairo + +// #cgo pkg-config: cairo cairo-gobject +// #include +// #include +// #include +import "C" + +func cairobool(b bool) C.cairo_bool_t { + if b { + return C.cairo_bool_t(1) + } + return C.cairo_bool_t(0) +} + +func gobool(b C.cairo_bool_t) bool { + if b != 0 { + return true + } + return false +} diff --git a/gdk/gdk.go b/gdk/gdk.go index e511c74..4900358 100644 --- a/gdk/gdk.go +++ b/gdk/gdk.go @@ -27,7 +27,7 @@ import ( "runtime" "unsafe" - "github.com/conformal/gotk3/glib" + "github.com/envoker/gotk3/glib" ) func init() { diff --git a/glib/glib_test.go b/glib/glib_test.go index 8dba36b..8902695 100644 --- a/glib/glib_test.go +++ b/glib/glib_test.go @@ -1,8 +1,8 @@ package glib_test import ( - "github.com/conformal/gotk3/glib" - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/glib" + "github.com/envoker/gotk3/gtk" "runtime" "testing" ) diff --git a/gtk/examples/addremove/addremove.go b/gtk/examples/addremove/addremove.go index 9f73566..ffddada 100644 --- a/gtk/examples/addremove/addremove.go +++ b/gtk/examples/addremove/addremove.go @@ -21,7 +21,7 @@ package main import ( "container/list" "fmt" - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/gtk" "log" ) diff --git a/gtk/examples/boolprops/boolprops.go b/gtk/examples/boolprops/boolprops.go index 0592064..9587d68 100644 --- a/gtk/examples/boolprops/boolprops.go +++ b/gtk/examples/boolprops/boolprops.go @@ -1,7 +1,7 @@ package main import ( - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/gtk" ) // Setup the Window. diff --git a/gtk/examples/drawingarea/game.go b/gtk/examples/drawingarea/game.go index 8461b0c..316fd7c 100644 --- a/gtk/examples/drawingarea/game.go +++ b/gtk/examples/drawingarea/game.go @@ -1,9 +1,11 @@ package main import ( - "github.com/conformal/gotk3/cairo" - "github.com/conformal/gotk3/gdk" - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/cairo" + //"github.com/gitchander/go-lang/cairo" + + "github.com/envoker/gotk3/gdk" + "github.com/envoker/gotk3/gtk" ) const ( @@ -36,10 +38,10 @@ func main() { } // Event handlers - da.Connect("draw", func(da *gtk.DrawingArea, cr *cairo.Context) { - cr.SetSourceRGB(0, 0, 0) - cr.Rectangle(x*unitSize, y*unitSize, unitSize, unitSize) - cr.Fill() + da.Connect("draw", func(da *gtk.DrawingArea, c *cairo.Context) { + c.SetSourceRGB(0, 0, 0) + c.Rectangle(x*unitSize, y*unitSize, unitSize, unitSize) + c.Fill() }) win.Connect("key-press-event", func(win *gtk.Window, ev *gdk.Event) { keyEvent := &gdk.EventKey{ev} diff --git a/gtk/examples/goroutines/goroutines.go b/gtk/examples/goroutines/goroutines.go index fe27654..c1f2d7c 100644 --- a/gtk/examples/goroutines/goroutines.go +++ b/gtk/examples/goroutines/goroutines.go @@ -20,8 +20,8 @@ package main import ( "fmt" - "github.com/conformal/gotk3/glib" - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/glib" + "github.com/envoker/gotk3/gtk" "log" "time" ) diff --git a/gtk/examples/grid/grid.go b/gtk/examples/grid/grid.go index 70adacd..84b1c5b 100644 --- a/gtk/examples/grid/grid.go +++ b/gtk/examples/grid/grid.go @@ -19,7 +19,7 @@ package main import ( - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/gtk" "log" ) diff --git a/gtk/examples/signals/signals.go b/gtk/examples/signals/signals.go index 9a264e7..6fa493f 100644 --- a/gtk/examples/signals/signals.go +++ b/gtk/examples/signals/signals.go @@ -20,7 +20,7 @@ package main import ( "fmt" - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/gtk" "log" ) diff --git a/gtk/examples/simple/simple.go b/gtk/examples/simple/simple.go index 93111f9..3788bbb 100644 --- a/gtk/examples/simple/simple.go +++ b/gtk/examples/simple/simple.go @@ -19,7 +19,7 @@ package main import ( - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/gtk" "log" ) diff --git a/gtk/examples/textview/textview.go b/gtk/examples/textview/textview.go index 45f8e39..4d382f1 100644 --- a/gtk/examples/textview/textview.go +++ b/gtk/examples/textview/textview.go @@ -20,7 +20,7 @@ package main import ( "fmt" - "github.com/conformal/gotk3/gtk" + "github.com/envoker/gotk3/gtk" "log" ) diff --git a/gtk/gtk.go b/gtk/gtk.go index 53051a5..3d2981c 100644 --- a/gtk/gtk.go +++ b/gtk/gtk.go @@ -54,10 +54,12 @@ import ( "runtime" "unsafe" - "github.com/conformal/gotk3/cairo" - "github.com/conformal/gotk3/gdk" - "github.com/conformal/gotk3/glib" - "github.com/conformal/gotk3/pango" + //"github.com/gitchander/go-lang/cairo" + "github.com/envoker/gotk3/cairo" + + "github.com/envoker/gotk3/gdk" + "github.com/envoker/gotk3/glib" + "github.com/envoker/gotk3/pango" ) func init() { @@ -2518,6 +2520,9 @@ func (v *Container) SetBorderWidth(borderWidth uint) { // PropagateDraw is a wrapper around gtk_container_propagate_draw(). func (v *Container) PropagateDraw(child IWidget, cr *cairo.Context) { + + fmt.Println("++++") + context := (*C.cairo_t)(unsafe.Pointer(cr.Native())) C.gtk_container_propagate_draw(v.native(), child.toWidget(), context) } @@ -5416,12 +5421,15 @@ func OffscreenWindowNew() (*OffscreenWindow, error) { // GetSurface is a wrapper around gtk_offscreen_window_get_surface(). // The returned surface is safe to use over window resizes. func (v *OffscreenWindow) GetSurface() (*cairo.Surface, error) { + c := C.gtk_offscreen_window_get_surface(v.native()) if c == nil { return nil, nilPtrErr } - cairoPtr := (uintptr)(unsafe.Pointer(c)) - s := cairo.NewSurface(cairoPtr, true) + surfacePtr := (uintptr)(unsafe.Pointer(c)) + + s := cairo.NewSurface(surfacePtr, true) + return s, nil } diff --git a/gtk/gtk_3_10-12.go b/gtk/gtk_3_10-12.go index 4c53d06..a394992 100644 --- a/gtk/gtk_3_10-12.go +++ b/gtk/gtk_3_10-12.go @@ -29,8 +29,8 @@ package gtk // #include "gtk_3_10-12.go.h" import "C" import ( - "github.com/conformal/gotk3/gdk" - "github.com/conformal/gotk3/glib" + "github.com/envoker/gotk3/gdk" + "github.com/envoker/gotk3/glib" "runtime" "unsafe" ) diff --git a/gtk/gtk_3_12.go b/gtk/gtk_3_12.go deleted file mode 100644 index 87eb5c9..0000000 --- a/gtk/gtk_3_12.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (c) 2013-2014 Conformal Systems -// -// This file originated from: http://opensource.conformal.com/ -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// This file includes wrapers for symbols included since GTK 3.12, and -// and should not be included in a build intended to target any older GTK -// versions. To target an older build, such as 3.10, use -// 'go build -tags gtk_3_10'. Otherwise, if no build tags are used, GTK 3.12 -// is assumed and this file is built. -// +build !gtk_3_6,!gtk_3_8,!gtk_3_10 - -package gtk - -// #cgo pkg-config: gtk+-3.0 -// #include -// #include -// #include "gtk_3_12.go.h" -import "C" -import ( - "github.com/conformal/gotk3/glib" - "runtime" - "unsafe" -) - -func init() { - tm := []glib.TypeMarshaler{ - // Objects/Interfaces - {glib.Type(C.gtk_popover_get_type()), marshalPopover}, - } - glib.RegisterGValueMarshalers(tm) -} - -/* - * GtkPopover - */ - -// Popover is a representation of GTK's GtkPopover. -type Popover struct { - Bin -} - -// native returns a pointer to the underlying GtkPopover. -func (v *Popover) native() *C.GtkPopover { - if v == nil || v.GObject == nil { - return nil - } - p := unsafe.Pointer(v.GObject) - return C.toGtkPopover(p) -} - -func marshalPopover(p uintptr) (interface{}, error) { - c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) - obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} - return wrapPopover(obj), nil -} - -func wrapPopover(obj *glib.Object) *Popover { - return &Popover{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}} -} - -// PopoverNew is a wrapper around gtk_popover_new(). -func PopoverNew(relativeTo IWidget) (*Popover, error) { - c := C.gtk_popover_new(relativeTo.toWidget()) - if c == nil { - return nil, nilPtrErr - } - obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} - a := wrapPopover(obj) - obj.RefSink() - runtime.SetFinalizer(obj, (*glib.Object).Unref) - return a, nil -} - -// TODO: gtk_popover_new_from_model -// TODO: gtk_popover_bind_model - -// SetRelativeTo is a wrapper around gtk_popover_set_relative_to(). -func (v *Popover) SetRelativeTo(relativeTo IWidget) { - C.gtk_popover_set_relative_to(v.native(), relativeTo.toWidget()) -} - -// GetRelativeTo is a wrapper around gtk_popover_get_relative_to(). -func (v *Popover) GetRelativeTo() (*Widget, error) { - c := C.gtk_popover_get_relative_to(v.native()) - if c == nil { - return nil, nilPtrErr - } - obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} - w := wrapWidget(obj) - obj.RefSink() - runtime.SetFinalizer(obj, (*glib.Object).Unref) - return w, nil -} - -// TODO: gtk_popover_set_pointing_to -// TODO: gtk_popover_get_pointing_to - -// SetPosition is a wrapper around gtk_popover_set_position(). -func (v *Popover) SetPosition(position PositionType) { - C.gtk_popover_set_position(v.native(), C.GtkPositionType(position)) -} - -// GetPosition is a wrapper around gtk_popover_get_position(). -func (v *Popover) GetPosition() PositionType { - c := C.gtk_popover_get_position(v.native()) - return PositionType(c) -} - -// SetModal is a wrapper around gtk_popover_set_modal(). -func (v *Popover) SetModal(modal bool) { - C.gtk_popover_set_modal(v.native(), gbool(modal)) -} - -// GetModal is a wrapper around gtk_popover_get_modal(). -func (v *Popover) GetModal() bool { - c := C.gtk_popover_get_modal(v.native()) - return gobool(c) -} - -/* - * GtkWidget - */ - -// GetMarginStart is a wrapper around gtk_widget_get_margin_start(). -func (v *Widget) GetMarginStart() int { - c := C.gtk_widget_get_margin_start(v.native()) - return int(c) -} - -// SetMarginStart is a wrapper around gtk_widget_set_margin_start(). -func (v *Widget) SetMarginStart(margin int) { - C.gtk_widget_set_margin_start(v.native(), C.gint(margin)) -} - -// GetMarginEnd is a wrapper around gtk_widget_get_margin_end(). -func (v *Widget) GetMarginEnd() int { - c := C.gtk_widget_get_margin_end(v.native()) - return int(c) -} - -// SetMarginEnd is a wrapper around gtk_widget_set_margin_end(). -func (v *Widget) SetMarginEnd(margin int) { - C.gtk_widget_set_margin_end(v.native(), C.gint(margin)) -} diff --git a/gtk/gtk_3_12.go.h b/gtk/gtk_3_12.go.h deleted file mode 100644 index e33fda8..0000000 --- a/gtk/gtk_3_12.go.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2013-2014 Conformal Systems - * - * This file originated from: http://opensource.conformal.com/ - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -static GtkPopover * -toGtkPopover(void *p) -{ - return (GTK_POPOVER(p)); -} diff --git a/gtk/gtk_3_6-10.go b/gtk/gtk_3_6-10.go index 1ed24e5..a6355c4 100644 --- a/gtk/gtk_3_6-10.go +++ b/gtk/gtk_3_6-10.go @@ -27,7 +27,7 @@ package gtk // #include import "C" import ( - "github.com/conformal/gotk3/glib" + "github.com/envoker/gotk3/glib" "runtime" "unsafe" ) diff --git a/gtk/gtk_3_6-8.go b/gtk/gtk_3_6-8.go index b033c08..5c0a2a7 100644 --- a/gtk/gtk_3_6-8.go +++ b/gtk/gtk_3_6-8.go @@ -28,7 +28,7 @@ package gtk // #include import "C" import ( - "github.com/conformal/gotk3/glib" + "github.com/envoker/gotk3/glib" "runtime" "unsafe" ) diff --git a/gtk/gtk_test.go b/gtk/gtk_test.go index 8a76da4..5f36230 100644 --- a/gtk/gtk_test.go +++ b/gtk/gtk_test.go @@ -20,9 +20,10 @@ package gtk import ( "fmt" - "github.com/conformal/gotk3/glib" "log" "testing" + + "github.com/envoker/gotk3/glib" ) func init() { diff --git a/pango/pango.go b/pango/pango.go index a125a96..5bdf500 100644 --- a/pango/pango.go +++ b/pango/pango.go @@ -21,7 +21,7 @@ package pango // #include import "C" import ( - "github.com/conformal/gotk3/glib" + "github.com/envoker/gotk3/glib" "unsafe" ) From d869d62edf7b434789bcee4dcca5ca506d01179d Mon Sep 17 00:00:00 2001 From: Chander Date: Wed, 9 Mar 2016 17:31:51 +0200 Subject: [PATCH 11/13] add surface rgba32 --- cairo/enums.go | 19 ++++++++++ cairo/surface.go | 50 ++++++++++++++++++--------- gtk/examples/goroutines/goroutines.go | 6 ++-- gtk/examples/grid/grid.go | 3 +- gtk/gtk.go | 2 +- 5 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 cairo/enums.go diff --git a/cairo/enums.go b/cairo/enums.go new file mode 100644 index 0000000..b8d3948 --- /dev/null +++ b/cairo/enums.go @@ -0,0 +1,19 @@ +package cairo + +// #cgo pkg-config: cairo cairo-gobject +// #include +// #include +// #include +import "C" + +type Format int // cairo_format_t + +const ( + FORMAT_INVALID Format = C.CAIRO_FORMAT_INVALID + FORMAT_ARGB32 Format = C.CAIRO_FORMAT_ARGB32 + FORMAT_RGB24 Format = C.CAIRO_FORMAT_RGB24 + FORMAT_A8 Format = C.CAIRO_FORMAT_A8 + FORMAT_A1 Format = C.CAIRO_FORMAT_A1 + FORMAT_RGB16_565 Format = C.CAIRO_FORMAT_RGB16_565 + FORMAT_RGB30 Format = C.CAIRO_FORMAT_RGB30 +) diff --git a/cairo/surface.go b/cairo/surface.go index c3acaa1..26084cb 100644 --- a/cairo/surface.go +++ b/cairo/surface.go @@ -24,19 +24,50 @@ type Surface struct { surface *C.cairo_surface_t } +func NewSurface(format Format, width, height int) (*Surface, error) { + + surface_n := C.cairo_image_surface_create(C.cairo_format_t(format), C.int(width), C.int(height)) + + status := Status(C.cairo_surface_status(surface_n)) + if status != STATUS_SUCCESS { + return nil, ErrorStatus(status) + } + + surface := wrapSurface(surface_n) + runtime.SetFinalizer(surface, (*Surface).destroy) + + return surface, nil +} + +// NewSurface creates a gotk3 cairo Surface from a pointer to a +// C cairo_surface_t. This is primarily designed for use with other +// gotk3 packages and should be avoided by applications. +func NewSurfaceFromNative(ptr uintptr, needsRef bool) *Surface { + surface_n := (*C.cairo_surface_t)(unsafe.Pointer(ptr)) + surface := wrapSurface(surface_n) + if needsRef { + surface.reference() + } + runtime.SetFinalizer(surface, (*Surface).destroy) + return surface +} + func NewSurfaceFromPNG(fileName string) (*Surface, error) { cstr := C.CString(fileName) defer C.free(unsafe.Pointer(cstr)) - surfaceNative := C.cairo_image_surface_create_from_png(cstr) + surface_n := C.cairo_image_surface_create_from_png(cstr) - status := Status(C.cairo_surface_status(surfaceNative)) + status := Status(C.cairo_surface_status(surface_n)) if status != STATUS_SUCCESS { return nil, ErrorStatus(status) } - return &Surface{surfaceNative}, nil + surface := wrapSurface(surface_n) + runtime.SetFinalizer(surface, (*Surface).destroy) + + return surface, nil } // native returns a pointer to the underlying cairo_surface_t. @@ -62,19 +93,6 @@ func wrapSurface(surface *C.cairo_surface_t) *Surface { return &Surface{surface} } -// NewSurface creates a gotk3 cairo Surface from a pointer to a -// C cairo_surface_t. This is primarily designed for use with other -// gotk3 packages and should be avoided by applications. -func NewSurface(s uintptr, needsRef bool) *Surface { - ptr := (*C.cairo_surface_t)(unsafe.Pointer(s)) - surface := wrapSurface(ptr) - if needsRef { - surface.reference() - } - runtime.SetFinalizer(surface, (*Surface).destroy) - return surface -} - // CreateSimilar is a wrapper around cairo_surface_create_similar(). func (v *Surface) CreateSimilar(content Content, width, height int) *Surface { c := C.cairo_surface_create_similar(v.native(), diff --git a/gtk/examples/goroutines/goroutines.go b/gtk/examples/goroutines/goroutines.go index c1f2d7c..923d559 100644 --- a/gtk/examples/goroutines/goroutines.go +++ b/gtk/examples/goroutines/goroutines.go @@ -20,10 +20,11 @@ package main import ( "fmt" - "github.com/envoker/gotk3/glib" - "github.com/envoker/gotk3/gtk" "log" "time" + + "github.com/envoker/gotk3/glib" + "github.com/envoker/gotk3/gtk" ) var ( @@ -72,6 +73,7 @@ func main() { } nSets++ s = fmt.Sprintf("Set a label %d time(s)!", nSets) + _, err = glib.IdleAdd(bottomLabel.SetText, s) if err != nil { log.Fatal("IdleAdd() failed:", err) diff --git a/gtk/examples/grid/grid.go b/gtk/examples/grid/grid.go index 84b1c5b..3cd6b9f 100644 --- a/gtk/examples/grid/grid.go +++ b/gtk/examples/grid/grid.go @@ -19,8 +19,9 @@ package main import ( - "github.com/envoker/gotk3/gtk" "log" + + "github.com/envoker/gotk3/gtk" ) func main() { diff --git a/gtk/gtk.go b/gtk/gtk.go index 3d2981c..2745e67 100644 --- a/gtk/gtk.go +++ b/gtk/gtk.go @@ -5428,7 +5428,7 @@ func (v *OffscreenWindow) GetSurface() (*cairo.Surface, error) { } surfacePtr := (uintptr)(unsafe.Pointer(c)) - s := cairo.NewSurface(surfacePtr, true) + s := cairo.NewSurfaceFromNative(surfacePtr, true) return s, nil } From ed06e50779b3e9e5a90701e2d3fa1385d5478c01 Mon Sep 17 00:00:00 2001 From: Chander Date: Wed, 9 Mar 2016 18:16:46 +0200 Subject: [PATCH 12/13] ch surf --- cairo/surface.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cairo/surface.go b/cairo/surface.go index 26084cb..b034779 100644 --- a/cairo/surface.go +++ b/cairo/surface.go @@ -21,7 +21,7 @@ import ( // Surface is a representation of Cairo's cairo_surface_t. type Surface struct { - surface *C.cairo_surface_t + surface_n *C.cairo_surface_t } func NewSurface(format Format, width, height int) (*Surface, error) { @@ -75,7 +75,7 @@ func (v *Surface) native() *C.cairo_surface_t { if v == nil { return nil } - return v.surface + return v.surface_n } // Native returns a pointer to the underlying cairo_surface_t. @@ -115,7 +115,7 @@ func (v *Surface) CreateForRectangle(x, y, width, height float64) *Surface { // reference is a wrapper around cairo_surface_reference(). func (v *Surface) reference() { - v.surface = C.cairo_surface_reference(v.native()) + v.surface_n = C.cairo_surface_reference(v.native()) } // destroy is a wrapper around cairo_surface_destroy(). From 1bdac686fc3427b4b29640e54c3276d493a6465c Mon Sep 17 00:00:00 2001 From: Chander Date: Thu, 10 Mar 2016 23:39:45 +0200 Subject: [PATCH 13/13] add surf w h --- cairo/surface.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cairo/surface.go b/cairo/surface.go index b034779..3366dd3 100644 --- a/cairo/surface.go +++ b/cairo/surface.go @@ -93,6 +93,14 @@ func wrapSurface(surface *C.cairo_surface_t) *Surface { return &Surface{surface} } +func (s *Surface) GetWidth() int { + return int(C.cairo_image_surface_get_width(s.surface_n)) +} + +func (s *Surface) GetHeight() int { + return int(C.cairo_image_surface_get_height(s.surface_n)) +} + // CreateSimilar is a wrapper around cairo_surface_create_similar(). func (v *Surface) CreateSimilar(content Content, width, height int) *Surface { c := C.cairo_surface_create_similar(v.native(),