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

add GtkScrollable, GtkLayout, GtkViewport (mostly complete) + GtkPixBuf, GtkPixbufLoader, and more! #12

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bdbb332
add GtkScrollable, GtkLayout, GtkViewport (mostly complete)
Sep 12, 2013
a6d5828
initial support for GtkPixbuf, GtkPixbuf loader
Sep 12, 2013
1973e79
gdk.Pixbuf functions for Image
Sep 12, 2013
13c7bf8
fix build
Sep 12, 2013
bbc2e1f
fix referencing in pixbuf and pixbuf loader, add (questionable) gdk.R…
Sep 12, 2013
d99e318
pixbuf scale, rotation and flipping functions
Sep 12, 2013
49d1a12
move Pixbuf entriely to gdkpixbuf, add methods GetWidth and GetHeight
Sep 12, 2013
b9d6dc9
add Image.SetFromPixbuf, fix Layout and Viewport structs, fix doc
Sep 12, 2013
d038d0e
added ImageMenuItem, AboutDialog, FileChooserDialog
Sep 15, 2013
236d427
fixups
jrick Sep 17, 2013
26d5dbc
FileChooser (also embed into FileChooserDialog), getters for gtk.Allo…
Sep 18, 2013
eae320f
GtkToolbar, add some missing functions, doc fix
Sep 19, 2013
087681c
initial (and questionable) access to GtkEvent fields
Sep 19, 2013
3153274
basic definitions fir ToolButton and ToolItem
Sep 19, 2013
014b626
GtkCheckMenuItem, Window.Fullscreen and Window.Unfullscreen
Sep 19, 2013
83778f8
GdkEventKey, and gdkkeysyms.h
Sep 19, 2013
04222b5
implement more bits of the propsed event system
Sep 24, 2013
0601587
Merge remote-tracking branch 'main/master'
Oct 11, 2013
5469848
temporarily allow deprecated stuff (oh and thank you gtk devs, for br…
Oct 24, 2013
ee8818f
merge from upstream
Oct 24, 2013
abb5248
goodbye GtkImageMenuItem (also remove -Wno-deprecated-declarations)
Oct 24, 2013
f465d42
implement more GtkScrollbar and GtkRange methods
Oct 24, 2013
96b8f4d
Added RadioMenuItem
Oct 30, 2013
8ec5ccf
bindings for gdk_pixbuf_save (SavePNG and SaveJPEG)
Oct 31, 2013
60b745f
More Adjustment and ScrolledWindow functions
Oct 31, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions gdk/gdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,105 @@ func (v *Event) free() {
C.gdk_event_free(v.Native())
}

type EventType C.GdkEventType

func ToEvent(c glib.CallbackArg) *Event {
// TODO: check Type field and confirm it's a valid one.
return &Event{GdkEvent: (*C.GdkEvent)(unsafe.Pointer(c))}
}

// TODO It is possible to use Type field in various places.

func (v *Event) Configure() *EventConfigure {
// TODO: check Type field and confirm it's a valid one.
c := C.toGdkEventConfigure(v.Native())
return &EventConfigure{
Type: EventType(c._type),
Window: &Window{(*glib.Object)(unsafe.Pointer(c.window))},
SendEvent: int8(c.send_event),
X: int32(c.x),
Y: int32(c.y),
Width: int32(c.width),
Height: int32(c.height),
}
}

func (v *Event) Key() *EventKey {
// TODO: check Type field and confirm it's a valid one.
c := C.toGdkEventKey(v.Native())
return &EventKey{
Type: EventType(c._type),
Window: &Window{(*glib.Object)(unsafe.Pointer(c.window))},
SendEvent: int8(c.send_event),
Time: uint32(c.time),
State: uint32(c.state),
Keyval: uint32(c.keyval),
Length: int32(c.length),
String: C.GoString((*C.char)(c.string)),
HardwareKeycode: uint16(c.hardware_keycode),
Group: uint8(c.group),
IsModifier: gobool(C.getGdkEventKeyIsModifier(c)),
}
}

func free(p unsafe.Pointer) {
C.free(p)
}

type EventKey struct {
Type EventType
Window *Window
SendEvent int8
Time uint32
State uint32
Keyval uint32
Length int32
String string
HardwareKeycode uint16
Group uint8
IsModifier bool
}

func (v *EventKey) toNative() *C.GdkEventKey {
c := &C.GdkEventKey{
_type: C.GdkEventType(v.Type),
window: v.Window.Native(),
send_event: C.gint8(v.SendEvent),
time: C.guint32(v.Time),
state: C.guint(v.State),
keyval: C.guint(v.Keyval),
length: C.gint(v.Length),
string: (*C.gchar)(C.CString(v.String)),
hardware_keycode: C.guint16(v.HardwareKeycode),
group: C.guint8(v.Group),
}

C.setGdkEventKeyIsModifier(c, gbool(v.IsModifier))
runtime.SetFinalizer(unsafe.Pointer(c.string), free)
return c
}

type EventConfigure struct {
Type EventType
Window *Window
SendEvent int8
X, Y int32
Width int32
Height int32
}

func (v *EventConfigure) toNative() *C.GdkEventConfigure {
return &C.GdkEventConfigure{
_type: C.GdkEventType(v.Type),
window: v.Window.Native(),
send_event: C.gint8(v.SendEvent),
x: C.gint(v.X),
y: C.gint(v.Y),
width: C.gint(v.Width),
height: C.gint(v.Height),
}
}

/*
* GdkScreen
*/
Expand Down Expand Up @@ -441,3 +540,37 @@ func (v *Window) Native() *C.GdkWindow {
p := unsafe.Pointer(v.GObject)
return C.toGdkWindow(p)
}

/*
* GdkRectangle
*/

// Rectangle is a representation of GDK's GdkRectangle type.
type Rectangle struct {
GdkRectangle C.GdkRectangle
}

// Native() returns a pointer to the underlying GdkRectangle.
func (r *Rectangle) Native() *C.GdkRectangle {
return &r.GdkRectangle
}

// GetX returns x field of the underlying GdkRectangle.
func (r *Rectangle) GetX() int {
return int(r.Native().x)
}

// GetY returns y field of the underlying GdkRectangle.
func (r *Rectangle) GetY() int {
return int(r.Native().y)
}

// GetWidth returns width field of the underlying GdkRectangle.
func (r *Rectangle) GetWidth() int {
return int(r.Native().width)
}

// GetHeight returns height field of the underlying GdkRectangle.
func (r *Rectangle) GetHeight() int {
return int(r.Native().height)
}
24 changes: 24 additions & 0 deletions gdk/gdk.go.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,27 @@ toGdkWindow(void *p)
{
return (GDK_WINDOW(p));
}

static GdkEventConfigure *
toGdkEventConfigure(GdkEvent *p)
{
return &p->configure;
}

static GdkEventKey *
toGdkEventKey(GdkEvent *p)
{
return &p->key;
}

static gboolean
getGdkEventKeyIsModifier(GdkEventKey *p)
{
return p->is_modifier;
}

static gboolean
setGdkEventKeyIsModifier(GdkEventKey *p, gboolean b)
{
return p->is_modifier = b;
}
Loading