Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Add gtk.OffscreenWindow implementation and bindings.
Browse files Browse the repository at this point in the history
Closes #33.
  • Loading branch information
jrick committed Jan 19, 2014
1 parent d72df24 commit 09f2a34
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cairo/cairo.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,18 @@ 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 *C.cairo_surface_t, needsRef bool) *Surface {
surface := wrapSurface(s)
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(),
Expand Down
63 changes: 63 additions & 0 deletions gtk/gtk.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import "C"
import (
"errors"
"fmt"
"github.com/conformal/gotk3/cairo"
"github.com/conformal/gotk3/gdk"
"github.com/conformal/gotk3/glib"
"runtime"
Expand Down Expand Up @@ -3339,6 +3340,66 @@ func (v *Notebook) GetActionWidget(packType PackType) (*Widget, error) {
return w, nil
}

/*
* GtkOffscreenWindow
*/

// OffscreenWindow is a representation of GTK's GtkOffscreenWindow.
type OffscreenWindow struct {
Window
}

// Native returns a pointer to the underlying GtkOffscreenWindow.
func (v *OffscreenWindow) Native() *C.GtkOffscreenWindow {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGtkOffscreenWindow(p)
}

func wrapOffscreenWindow(obj *glib.Object) *OffscreenWindow {
return &OffscreenWindow{Window{Bin{Container{Widget
glib.InitiallyUnowned{obj}}}}}}
}

// OffscreenWindowNew is a wrapper around gtk_offscreen_window_new().
func OffscreenWindowNew() (*OffscreenWindow, error) {
c := C.gtk_offscreen_window_new()
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
o := wrapOffscreenWindow(obj)
obj.RefSink()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return o, nil
}

// 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
}
s := cairo.NewSurface(c, true)
return s, nil
}

// GetPixbuf is a wrapper around gtk_offscreen_window_get_pixbuf().
func (v *OffscreenWindow) GetPixbuf() (*gdk.Pixbuf, error) {
c := C.gtk_offscreen_window_get_pixbuf(v.Native())
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
pb := &gdk.Pixbuf{obj}
// Pixbuf is returned with ref count of 1, so don't increment.
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return pb, nil
}

/*
* GtkOrientable
*/
Expand Down Expand Up @@ -5510,6 +5571,8 @@ func cast(c *C.GObject) (glib.IObject, error) {
g = wrapMisc(obj)
case "GtkNotebook":
g = wrapNotebook(obj)
case "GtkOffscreenWindow":
g = wrapOffscreenWindow(obj)
case "GtkOrientable":
g = wrapOrientable(obj)
case "GtkProgressBar":
Expand Down
6 changes: 6 additions & 0 deletions gtk/gtk.go.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ toGtkSearchEntry(void *p)
return (GTK_SEARCH_ENTRY(p));
}

static GtkOffscreenWindow *
toGtkOffscreenWindow(void *p)
{
return (GTK_OFFSCREEN_WINDOW(p));
}

static GType *
alloc_types(int n) {
return ((GType *)g_new0(GType, n));
Expand Down
2 changes: 1 addition & 1 deletion gtk/gtk_3_10.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
*/

const (
ALIGN_BASELINE Align = C.GTK_ALIGN_BASELINE
ALIGN_BASELINE Align = C.GTK_ALIGN_BASELINE
)

/*
Expand Down

0 comments on commit 09f2a34

Please sign in to comment.