Add vendored gotk3 GTK3 bindings for Go
Vendor gotk3 library to ensure consistent GTK3 bindings across environments and simplify dependency management. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9d33575ada
commit
d4efa91ce1
30
third_party/gotk3/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
30
third_party/gotk3/.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: "[BUG] title"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Error messages**
|
||||
If applicable, add copy the log message to help explain your problem.
|
||||
|
||||
**Environment:**
|
||||
gtk3 version: '...'
|
||||
go version: '...'
|
||||
os: '...'
|
||||
other stuff: '...'
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
20
third_party/gotk3/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
third_party/gotk3/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature] title"
|
||||
labels: enhancement, missing binding
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
10
third_party/gotk3/.github/ISSUE_TEMPLATE/project-question.md
vendored
Normal file
10
third_party/gotk3/.github/ISSUE_TEMPLATE/project-question.md
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
name: Project question
|
||||
about: Do you have a question then ask this one here
|
||||
title: "[Project question] title"
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Help us make this better
|
||||
36
third_party/gotk3/.github/workflows/linux.yml
vendored
Normal file
36
third_party/gotk3/.github/workflows/linux.yml
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
name: Build and test on Linux
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.18
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install libgtk-3-dev libcairo2-dev libglib2.0-dev
|
||||
|
||||
- name: Print versions
|
||||
run: |
|
||||
echo glib: $(pkg-config --modversion glib-2.0)
|
||||
echo gdk: $(pkg-config --modversion gdk-3.0)
|
||||
echo gtk: $(pkg-config --modversion gtk+-3.0)
|
||||
|
||||
- name: Build
|
||||
run: go build --tags=glib_deprecated -v ./...
|
||||
|
||||
# - name: Test
|
||||
# run: go test -v --tags=glib_deprecated -v ./...
|
||||
28
third_party/gotk3/.github/workflows/macos.yml
vendored
Normal file
28
third_party/gotk3/.github/workflows/macos.yml
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
name: Build and test on MacOS
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.18
|
||||
|
||||
- name: Install gtk
|
||||
run: brew install gobject-introspection gtk+3
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
48
third_party/gotk3/.github/workflows/windows.yml
vendored
Normal file
48
third_party/gotk3/.github/workflows/windows.yml
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
name: Build and test on Windows
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.18
|
||||
|
||||
- uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: MINGW64
|
||||
update: true
|
||||
install:
|
||||
git
|
||||
make
|
||||
mingw-w64-x86_64-gtk3
|
||||
mingw-w64-x86_64-glib2
|
||||
mingw-w64-x86_64-go
|
||||
mingw-w64-x86_64-gcc
|
||||
mingw-w64-x86_64-pkg-config
|
||||
glib2-devel
|
||||
|
||||
- name: Build the binary
|
||||
run: |
|
||||
# This fixes a bug in pkgconfig: invalid flag in pkg-config --libs: -Wl,-luuid
|
||||
sed -i -e 's/-Wl,-luuid/-luuid/g' /mingw64/lib/pkgconfig/gdk-3.0.pc
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
||||
3
third_party/gotk3/.gitignore
vendored
Normal file
3
third_party/gotk3/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.vscode
|
||||
.idea
|
||||
|
||||
59
third_party/gotk3/.travis.yml
vendored
Normal file
59
third_party/gotk3/.travis.yml
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
language: go
|
||||
|
||||
go_import_path: github.com/gotk3/gotk3
|
||||
|
||||
env:
|
||||
- GOARCH=amd64
|
||||
|
||||
jobs:
|
||||
include:
|
||||
# Testing on xenial, gtk 3.18.9 (gdk has same version), glib 2.48.0 (gio has same version), gdk-pixbuf 2.32.2
|
||||
- os: linux
|
||||
dist: xenial
|
||||
go: "1.13"
|
||||
|
||||
# Testing on bionic, gtk 3.22.30 (gdk has same version), glib 2.56.1 (gio has same version), gdk-pixbuf 2.36.11
|
||||
- os: linux
|
||||
dist: bionic
|
||||
go: "1.14"
|
||||
|
||||
# Testing on focal, gtk 3.24.14 (gdk has same version), glib 2.64.1 (gio has same version), gdk-pixbuf 2.40.0
|
||||
# Majority of the go versions here for compatibility checking
|
||||
- os: linux
|
||||
dist: focal
|
||||
go: "1.12"
|
||||
- os: linux
|
||||
dist: focal
|
||||
go: "1.13"
|
||||
- os: linux
|
||||
dist: focal
|
||||
go: "1.14"
|
||||
- os: linux
|
||||
dist: focal
|
||||
go: "1.15"
|
||||
- os: linux
|
||||
dist: focal
|
||||
go: tip
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gtk+3.0
|
||||
- libgtk-3-dev
|
||||
- xvfb
|
||||
|
||||
before_install:
|
||||
- "export DISPLAY=:99.0"
|
||||
- sudo /usr/bin/Xvfb $DISPLAY &> /dev/null &
|
||||
- "export GTK_VERSION=$(pkg-config --modversion gtk+-3.0 | tr . _| cut -d '_' -f 1-2)"
|
||||
- "export Glib_VERSION=$(pkg-config --modversion glib-2.0 | tr . _| cut -d '_' -f 1-2)"
|
||||
- "export GDK_Pixbuf_VERSION=$(pkg-config --modversion gdk-pixbuf-2.0 | tr . _| cut -d '_' -f 1-2)"
|
||||
- "export Cairo_VERSION=$(pkg-config --modversion cairo)"
|
||||
- "export Pango_VERSION=$(pkg-config --modversion pango)"
|
||||
- echo "GTK/GDK version ${GTK_VERSION} Glib/Gio version ${Glib_VERSION} Gdk-Pixbuf version ${GDK_Pixbuf_VERSION} (Cairo ${Cairo_VERSION}, Pango ${Pango_VERSION})"
|
||||
|
||||
install:
|
||||
- go get -t -tags "gtk_${GTK_VERSION} glib_${Glib_VERSION} gdk_pixbuf_${GDK_Pixbuf_VERSION}" ./...
|
||||
|
||||
script:
|
||||
- go test -tags "gtk_${GTK_VERSION} glib_${Glib_VERSION} gdk_pixbuf_${GDK_Pixbuf_VERSION}" ./...
|
||||
37
third_party/gotk3/CHANGES.md
vendored
Normal file
37
third_party/gotk3/CHANGES.md
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
|
||||
### User visible changes for gotk3 Go bindings for GTK3
|
||||
|
||||
---
|
||||
|
||||
Changes for Version after 0.6.1:
|
||||
|
||||
* **2021-08**: Glib version 2.68 deprecated glib.Binding. **GetSource** and **GetTarget** in favor of **DupSource** and **DupTarget**. Those using glib.Binding should check the [glib changes](https://gitlab.gnome.org/GNOME/glib/-/tags/2.67.1). For those who use **_Glib versions <= 2.66_**, you now need to use the build tag `-tags "glib_2_66"`, see [#828](https://github.com/gotk3/gotk3/pull/828)
|
||||
|
||||
|
||||
|
||||
Changes for next Version 0.6.0
|
||||
|
||||
- Breaking changes in API
|
||||
- General code cleanup
|
||||
- #685 Refactor Gtk callback setters and types enhancement missing binding
|
||||
- #706 Refactor internal closure handling and several API changes breaking changes
|
||||
- #746 Add build tag pango_1_42 for Pango
|
||||
- #743 Solving #741- Add possibility to use GVariant in signal handler
|
||||
- #740 Add binding for GtkRadioMenuItem
|
||||
- #738 Adds binding for gtk_cell_layout_clear_attributes()
|
||||
- #737 Adds bindings for gdk_pixbuf_new_from_resource() and gdk_pixbuf_new_from_resource_at_scale()
|
||||
- #736 Add bindings/helper methods GdkRectangle GdkPoint
|
||||
- #735 Add GtkMenuItem bindings
|
||||
- #734 Add bindings GtkMenuShell
|
||||
- #732 add as contributor
|
||||
- #731 add bindings to GtkMenu
|
||||
- #730 Solve GtkAccelKey issue with golang 1.16
|
||||
- #728 It is not safe to reference memory returned in a signal callback.
|
||||
- #687 Don't merge until publication of Golang v1.16: GtkAccelKey v1.16 issue fix next version
|
||||
- #724 Implemented CellRenderer.SetAlignment
|
||||
- #723 Added SetOrientation to gkt.SpinButton
|
||||
- #720 Add Prgname getter and setter
|
||||
- #716 Add (Get/Set) methods to GdkRGBA & GdkVisual & GdkDisplayManager bind…
|
||||
- #715 Add some GtkRange bindings
|
||||
- #712 glib.Take to return nil and gtk.marshal* to allow nil
|
||||
14
third_party/gotk3/CONTRIBUTIONS.md
vendored
Normal file
14
third_party/gotk3/CONTRIBUTIONS.md
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
## CONTRIBUTIONS
|
||||
- [conformal](https://github.com/conformal/gotk3)
|
||||
- [jrick](https://github.com/jrick/gotk3)
|
||||
- [sqp](https://github.com/sqp/gotk3)
|
||||
- [dradtke](https://github.com/dradtke/gotk3)
|
||||
- [MovingtoMars](https://github.com/MovingtoMars/gotk3)
|
||||
- [shish](https://github.com/shish/gotk3)
|
||||
- [andre](https://github.com/andre-hub/gotk3)
|
||||
- [raichu](https://github.com/raichu/gotk3)
|
||||
- [juniorz](https://github.com/juniorz)
|
||||
- [thanhps42](https://github.com/thanhps42)
|
||||
- [cubiest](https://github.com/cubiest/gotk3) - [MJacred](https://github.com/MJacred) & [founderio](https://github.com/founderio)
|
||||
- [hfmrow (H.F.M)](https://github.com/hfmrow/)
|
||||
- you?
|
||||
16
third_party/gotk3/LICENSE
vendored
Normal file
16
third_party/gotk3/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ISC License
|
||||
|
||||
Copyright (c) 2013-2014 Conformal Systems LLC.
|
||||
Copyright (c) 2015-2018 gotk3 contributors
|
||||
|
||||
Permission to use, copy, modify, and/or 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.
|
||||
231
third_party/gotk3/README.md
vendored
Normal file
231
third_party/gotk3/README.md
vendored
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
gotk3 [](https://godoc.org/github.com/gotk3/gotk3)
|
||||
=====
|
||||
|
||||
[](https://travis-ci.org/gotk3/gotk3)
|
||||
|
||||
The gotk3 project provides Go bindings for GTK 3 and dependent
|
||||
projects. Each component is given its own subdirectory, which is used
|
||||
as the import path for the package. Partial binding support for the
|
||||
following libraries is currently implemented:
|
||||
|
||||
- GTK 3 (3.12 and later)
|
||||
- GDK 3 (3.12 and later)
|
||||
- GLib 2 (2.36 and later)
|
||||
- Cairo (1.10 and later)
|
||||
|
||||
Care has been taken for memory management to work seamlessly with Go's
|
||||
garbage collector without the need to use or understand GObject's
|
||||
floating references.
|
||||
|
||||
for better understanding see
|
||||
[package reference documation](https://pkg.go.dev/github.com/gotk3/gotk3/gtk?tab=doc)
|
||||
|
||||
On Linux, see which version your distribution has [here](https://pkgs.org) with the search terms:
|
||||
* libgtk-3
|
||||
* libglib2
|
||||
* libgdk-pixbuf2
|
||||
|
||||
## Sample Use
|
||||
|
||||
The following example can be found in [Examples](https://github.com/gotk3/gotk3-examples/).
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Initialize GTK without parsing any command line arguments.
|
||||
gtk.Init(nil)
|
||||
|
||||
// Create a new toplevel window, set its title, and connect it to the
|
||||
// "destroy" signal to exit the GTK main loop when it is destroyed.
|
||||
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to create window:", err)
|
||||
}
|
||||
win.SetTitle("Simple Example")
|
||||
win.Connect("destroy", func() {
|
||||
gtk.MainQuit()
|
||||
})
|
||||
|
||||
// Create a new label widget to show in the window.
|
||||
l, err := gtk.LabelNew("Hello, gotk3!")
|
||||
if err != nil {
|
||||
log.Fatal("Unable to create label:", err)
|
||||
}
|
||||
|
||||
// Add the label to the window.
|
||||
win.Add(l)
|
||||
|
||||
// Set the default window size.
|
||||
win.SetDefaultSize(800, 600)
|
||||
|
||||
// Recursively show all widgets contained in this window.
|
||||
win.ShowAll()
|
||||
|
||||
// Begin executing the GTK main loop. This blocks until
|
||||
// gtk.MainQuit() is run.
|
||||
gtk.Main()
|
||||
}
|
||||
```
|
||||
|
||||
To build the example:
|
||||
|
||||
```shell
|
||||
$ go build example.go
|
||||
```
|
||||
|
||||
To build this example with older gtk version you should use gtk_3_10 tag:
|
||||
|
||||
```shell
|
||||
$ go build -tags gtk_3_10 example.go
|
||||
```
|
||||
|
||||
### Example usage
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
)
|
||||
|
||||
// Simple Gtk3 Application written in go.
|
||||
// This application creates a window on the application callback activate.
|
||||
// More GtkApplication info can be found here -> https://wiki.gnome.org/HowDoI/GtkApplication
|
||||
|
||||
func main() {
|
||||
// Create Gtk Application, change appID to your application domain name reversed.
|
||||
const appID = "org.gtk.example"
|
||||
application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
|
||||
// Check to make sure no errors when creating Gtk Application
|
||||
if err != nil {
|
||||
log.Fatal("Could not create application.", err)
|
||||
}
|
||||
// Application signals available
|
||||
// startup -> sets up the application when it first starts
|
||||
// activate -> shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment.
|
||||
// open -> opens files and shows them in a new window. This corresponds to someone trying to open a document (or documents) using the application from the file browser, or similar.
|
||||
// shutdown -> performs shutdown tasks
|
||||
// Setup Gtk Application callback signals
|
||||
application.Connect("activate", func() { onActivate(application) })
|
||||
// Run Gtk application
|
||||
os.Exit(application.Run(os.Args))
|
||||
}
|
||||
|
||||
// Callback signal from Gtk Application
|
||||
func onActivate(application *gtk.Application) {
|
||||
// Create ApplicationWindow
|
||||
appWindow, err := gtk.ApplicationWindowNew(application)
|
||||
if err != nil {
|
||||
log.Fatal("Could not create application window.", err)
|
||||
}
|
||||
// Set ApplicationWindow Properties
|
||||
appWindow.SetTitle("Basic Application.")
|
||||
appWindow.SetDefaultSize(400, 400)
|
||||
appWindow.Show()
|
||||
}
|
||||
```
|
||||
|
||||
```Go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
"github.com/gotk3/gotk3/gtk"
|
||||
)
|
||||
|
||||
// Simple Gtk3 Application written in go.
|
||||
// This application creates a window on the application callback activate.
|
||||
// More GtkApplication info can be found here -> https://wiki.gnome.org/HowDoI/GtkApplication
|
||||
|
||||
func main() {
|
||||
// Create Gtk Application, change appID to your application domain name reversed.
|
||||
const appID = "org.gtk.example"
|
||||
application, err := gtk.ApplicationNew(appID, glib.APPLICATION_FLAGS_NONE)
|
||||
// Check to make sure no errors when creating Gtk Application
|
||||
if err != nil {
|
||||
log.Fatal("Could not create application.", err)
|
||||
}
|
||||
|
||||
// Application signals available
|
||||
// startup -> sets up the application when it first starts
|
||||
// activate -> shows the default first window of the application (like a new document). This corresponds to the application being launched by the desktop environment.
|
||||
// open -> opens files and shows them in a new window. This corresponds to someone trying to open a document (or documents) using the application from the file browser, or similar.
|
||||
// shutdown -> performs shutdown tasks
|
||||
// Setup activate signal with a closure function.
|
||||
application.Connect("activate", func() {
|
||||
// Create ApplicationWindow
|
||||
appWindow, err := gtk.ApplicationWindowNew(application)
|
||||
if err != nil {
|
||||
log.Fatal("Could not create application window.", err)
|
||||
}
|
||||
// Set ApplicationWindow Properties
|
||||
appWindow.SetTitle("Basic Application.")
|
||||
appWindow.SetDefaultSize(400, 400)
|
||||
appWindow.Show()
|
||||
})
|
||||
// Run Gtk application
|
||||
application.Run(os.Args)
|
||||
}
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Each package's internal `go doc` style documentation can be viewed
|
||||
online without installing this package by using the GoDoc site (links
|
||||
to [cairo](http://godoc.org/github.com/gotk3/gotk3/cairo),
|
||||
[glib](http://godoc.org/github.com/gotk3/gotk3/glib),
|
||||
[gdk](http://godoc.org/github.com/gotk3/gotk3/gdk), and
|
||||
[gtk](http://godoc.org/github.com/gotk3/gotk3/gtk) documentation).
|
||||
|
||||
You can also view the documentation locally once the package is
|
||||
installed with the `godoc` tool by running `godoc -http=":6060"` and
|
||||
pointing your browser to
|
||||
http://localhost:6060/pkg/github.com/gotk3/gotk3
|
||||
|
||||
## Installation
|
||||
|
||||
gotk3 currently requires GTK 3.6-3.24, GLib 2.36-2.46, and
|
||||
Cairo 1.10 or 1.12. A recent Go (1.8 or newer) is also required.
|
||||
|
||||
For detailed instructions see the wiki pages: [installation](https://github.com/gotk3/gotk3/wiki#installation)
|
||||
|
||||
## Using deprecated features
|
||||
|
||||
By default, deprecated GTK features are not included in the build.
|
||||
|
||||
By specifying the e.g. build tag `gtk_3_20`, any feature deprecated in GTK 3.20 or earlier will NOT be available.
|
||||
To enable deprecated features in the build, add the tag `gtk_deprecated`.
|
||||
Example:
|
||||
```shell
|
||||
$ go build -tags "gtk_3_10 gtk_deprecated" example.go
|
||||
```
|
||||
|
||||
The same goes for
|
||||
* gdk-pixbuf: gdk_pixbuf_deprecated
|
||||
|
||||
## TODO
|
||||
|
||||
- Add bindings for all of GTK functions
|
||||
- Add tests for each implemented binding
|
||||
- See the next steps: [wiki page](https://github.com/gotk3/gotk3/wiki/The-future-and-what-happens-next) and add [your suggestion](https://github.com/gotk3/gotk3/issues/576)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Package gotk3 is licensed under the liberal ISC License.
|
||||
|
||||
Actually if you use gotk3, then gotk3 is statically linked into your application (with the ISC licence).
|
||||
The system libraries (e.g. GTK+, GLib) used via cgo use dynamic linking.
|
||||
27
third_party/gotk3/cairo/antialias.go
vendored
Normal file
27
third_party/gotk3/cairo/antialias.go
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Antialias is a representation of Cairo's cairo_antialias_t.
|
||||
type Antialias int
|
||||
|
||||
const (
|
||||
ANTIALIAS_DEFAULT Antialias = C.CAIRO_ANTIALIAS_DEFAULT
|
||||
ANTIALIAS_NONE Antialias = C.CAIRO_ANTIALIAS_NONE
|
||||
ANTIALIAS_GRAY Antialias = C.CAIRO_ANTIALIAS_GRAY
|
||||
ANTIALIAS_SUBPIXEL Antialias = C.CAIRO_ANTIALIAS_SUBPIXEL
|
||||
ANTIALIAS_FAST Antialias = C.CAIRO_ANTIALIAS_FAST // (since 1.12)
|
||||
ANTIALIAS_GOOD Antialias = C.CAIRO_ANTIALIAS_GOOD // (since 1.12)
|
||||
ANTIALIAS_BEST Antialias = C.CAIRO_ANTIALIAS_BEST // (since 1.12)
|
||||
)
|
||||
|
||||
func marshalAntialias(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return Antialias(c), nil
|
||||
}
|
||||
65
third_party/gotk3/cairo/cairo.go
vendored
Normal file
65
third_party/gotk3/cairo/cairo.go
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
//
|
||||
// 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.
|
||||
|
||||
// Package cairo implements Go bindings for Cairo. Supports version 1.10 and
|
||||
// later.
|
||||
package cairo
|
||||
|
||||
// #cgo pkg-config: cairo cairo-gobject gobject-2.0
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
tm := []glib.TypeMarshaler{
|
||||
// Enums
|
||||
{glib.Type(C.cairo_gobject_antialias_get_type()), marshalAntialias},
|
||||
{glib.Type(C.cairo_gobject_content_get_type()), marshalContent},
|
||||
{glib.Type(C.cairo_gobject_fill_rule_get_type()), marshalFillRule},
|
||||
{glib.Type(C.cairo_gobject_line_cap_get_type()), marshalLineCap},
|
||||
{glib.Type(C.cairo_gobject_line_join_get_type()), marshalLineJoin},
|
||||
{glib.Type(C.cairo_gobject_operator_get_type()), marshalOperator},
|
||||
{glib.Type(C.cairo_gobject_status_get_type()), marshalStatus},
|
||||
{glib.Type(C.cairo_gobject_surface_type_get_type()), marshalSurfaceType},
|
||||
|
||||
// Boxed
|
||||
{glib.Type(C.cairo_gobject_context_get_type()), marshalContext},
|
||||
{glib.Type(C.cairo_gobject_surface_get_type()), marshalSurface},
|
||||
}
|
||||
glib.RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
// Constants
|
||||
|
||||
// Content is a representation of Cairo's cairo_content_t.
|
||||
type Content int
|
||||
|
||||
const (
|
||||
CONTENT_COLOR Content = C.CAIRO_CONTENT_COLOR
|
||||
CONTENT_ALPHA Content = C.CAIRO_CONTENT_ALPHA
|
||||
CONTENT_COLOR_ALPHA Content = C.CAIRO_CONTENT_COLOR_ALPHA
|
||||
)
|
||||
|
||||
func marshalContent(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return Content(c), nil
|
||||
}
|
||||
425
third_party/gotk3/cairo/canvas.go
vendored
Normal file
425
third_party/gotk3/cairo/canvas.go
vendored
Normal file
|
|
@ -0,0 +1,425 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func (v *Context) GetCContext() *C.cairo_t {
|
||||
return v.native()
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
|
||||
func WrapContext(p uintptr) *Context {
|
||||
context := (*C.cairo_t)(unsafe.Pointer(p))
|
||||
return wrapContext(context)
|
||||
}
|
||||
|
||||
// Closes the context. The context must not be used afterwards.
|
||||
func (v *Context) Close() {
|
||||
v.destroy()
|
||||
}
|
||||
|
||||
// Create is a wrapper around cairo_create().
|
||||
func Create(target *Surface) *Context {
|
||||
c := C.cairo_create(target.native())
|
||||
ctx := wrapContext(c)
|
||||
runtime.SetFinalizer(ctx, func(v *Context) { glib.FinalizerStrategy(v.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() {
|
||||
if v.context != nil {
|
||||
C.cairo_destroy(v.native())
|
||||
v.context = nil
|
||||
}
|
||||
}
|
||||
|
||||
// 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, func(v *Surface) { glib.FinalizerStrategy(v.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)
|
||||
// cairo_pop_group
|
||||
|
||||
// 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, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
|
||||
return s
|
||||
}
|
||||
|
||||
// SetSource is a wrapper around cairo_set_source().
|
||||
func (v *Context) SetSource(p *Pattern) {
|
||||
C.cairo_set_source(v.native(), p.native())
|
||||
}
|
||||
|
||||
// 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)
|
||||
// cairo_set_source
|
||||
|
||||
// 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)
|
||||
// cairo_get_source
|
||||
|
||||
// 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) CopyClipRectangleList (depends on RectangleList)
|
||||
// cairo_copy_clip_rectangle_list
|
||||
|
||||
// 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)
|
||||
// cairo_mask_surface
|
||||
|
||||
// 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())
|
||||
}
|
||||
7
third_party/gotk3/cairo/errors.go
vendored
Normal file
7
third_party/gotk3/cairo/errors.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package cairo
|
||||
|
||||
type ErrorStatus Status
|
||||
|
||||
func (e ErrorStatus) Error() string {
|
||||
return StatusToString(Status(e))
|
||||
}
|
||||
22
third_party/gotk3/cairo/fillrule.go
vendored
Normal file
22
third_party/gotk3/cairo/fillrule.go
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// FillRule is a representation of Cairo's cairo_fill_rule_t.
|
||||
type FillRule int
|
||||
|
||||
const (
|
||||
FILL_RULE_WINDING FillRule = C.CAIRO_FILL_RULE_WINDING
|
||||
FILL_RULE_EVEN_ODD FillRule = C.CAIRO_FILL_RULE_EVEN_ODD
|
||||
)
|
||||
|
||||
func marshalFillRule(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return FillRule(c), nil
|
||||
}
|
||||
167
third_party/gotk3/cairo/fontoptions.go
vendored
Normal file
167
third_party/gotk3/cairo/fontoptions.go
vendored
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
tm := []glib.TypeMarshaler{
|
||||
// Enums
|
||||
{glib.Type(C.cairo_gobject_subpixel_order_get_type()), marshalSubpixelOrder},
|
||||
{glib.Type(C.cairo_gobject_hint_style_get_type()), marshalHintStyle},
|
||||
{glib.Type(C.cairo_gobject_hint_metrics_get_type()), marshalHintMetrics},
|
||||
|
||||
// Boxed
|
||||
{glib.Type(C.cairo_gobject_font_options_get_type()), marshalFontOptions},
|
||||
}
|
||||
glib.RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
// SubpixelOrder is a representation of Cairo's cairo_subpixel_order_t.
|
||||
type SubpixelOrder int
|
||||
|
||||
const (
|
||||
SUBPIXEL_ORDER_DEFAULT SubpixelOrder = C.CAIRO_SUBPIXEL_ORDER_DEFAULT
|
||||
SUBPIXEL_ORDER_RGB SubpixelOrder = C.CAIRO_SUBPIXEL_ORDER_RGB
|
||||
SUBPIXEL_ORDER_BGR SubpixelOrder = C.CAIRO_SUBPIXEL_ORDER_BGR
|
||||
SUBPIXEL_ORDER_VRGB SubpixelOrder = C.CAIRO_SUBPIXEL_ORDER_VRGB
|
||||
SUBPIXEL_ORDER_VBGR SubpixelOrder = C.CAIRO_SUBPIXEL_ORDER_VBGR
|
||||
)
|
||||
|
||||
func marshalSubpixelOrder(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return SubpixelOrder(c), nil
|
||||
}
|
||||
|
||||
// HintStyle is a representation of Cairo's cairo_hint_style_t.
|
||||
type HintStyle int
|
||||
|
||||
const (
|
||||
HINT_STYLE_DEFAULT HintStyle = C.CAIRO_HINT_STYLE_DEFAULT
|
||||
HINT_STYLE_NONE HintStyle = C.CAIRO_HINT_STYLE_NONE
|
||||
HINT_STYLE_SLIGHT HintStyle = C.CAIRO_HINT_STYLE_SLIGHT
|
||||
HINT_STYLE_MEDIUM HintStyle = C.CAIRO_HINT_STYLE_MEDIUM
|
||||
HINT_STYLE_FULL HintStyle = C.CAIRO_HINT_STYLE_FULL
|
||||
)
|
||||
|
||||
func marshalHintStyle(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return HintStyle(c), nil
|
||||
}
|
||||
|
||||
// HintMetrics is a representation of Cairo's cairo_hint_metrics_t.
|
||||
type HintMetrics int
|
||||
|
||||
const (
|
||||
HINT_METRICS_DEFAULT HintMetrics = C.CAIRO_HINT_METRICS_DEFAULT
|
||||
HINT_METRICS_OFF HintMetrics = C.CAIRO_HINT_METRICS_OFF
|
||||
HINT_METRICS_ON HintMetrics = C.CAIRO_HINT_METRICS_ON
|
||||
)
|
||||
|
||||
func marshalHintMetrics(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return HintMetrics(c), nil
|
||||
}
|
||||
|
||||
// FontOptions is a representation of Cairo's cairo_font_options_t.
|
||||
type FontOptions struct {
|
||||
native *C.cairo_font_options_t
|
||||
}
|
||||
|
||||
func marshalFontOptions(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
|
||||
return &FontOptions{
|
||||
native: (*C.cairo_font_options_t)(unsafe.Pointer(c)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreatFontOptions is a wrapper around cairo_font_options_create().
|
||||
func CreateFontOptions() *FontOptions {
|
||||
native := C.cairo_font_options_create()
|
||||
|
||||
opts := &FontOptions{native}
|
||||
runtime.SetFinalizer(opts, func(v *FontOptions) { glib.FinalizerStrategy(v.destroy) })
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func (o *FontOptions) destroy() {
|
||||
C.cairo_font_options_destroy(o.native)
|
||||
}
|
||||
|
||||
// Copy is a wrapper around cairo_font_options_copy().
|
||||
func (o *FontOptions) Copy() *FontOptions {
|
||||
native := C.cairo_font_options_copy(o.native)
|
||||
|
||||
opts := &FontOptions{native}
|
||||
runtime.SetFinalizer(opts, func(v *FontOptions) { glib.FinalizerStrategy(v.destroy) })
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
// Status is a wrapper around cairo_font_options_status().
|
||||
func (o *FontOptions) Status() Status {
|
||||
return Status(C.cairo_font_options_status(o.native))
|
||||
}
|
||||
|
||||
// Merge is a wrapper around cairo_font_options_merge().
|
||||
func (o *FontOptions) Merge(other *FontOptions) {
|
||||
C.cairo_font_options_merge(o.native, other.native)
|
||||
}
|
||||
|
||||
// Hash is a wrapper around cairo_font_options_hash().
|
||||
func (o *FontOptions) Hash() uint32 {
|
||||
return uint32(C.cairo_font_options_hash(o.native))
|
||||
}
|
||||
|
||||
// Equal is a wrapper around cairo_font_options_equal().
|
||||
func (o *FontOptions) Equal(other *FontOptions) bool {
|
||||
return gobool(C.cairo_font_options_equal(o.native, other.native))
|
||||
}
|
||||
|
||||
// SetAntialias is a wrapper around cairo_font_options_set_antialias().
|
||||
func (o *FontOptions) SetAntialias(antialias Antialias) {
|
||||
C.cairo_font_options_set_antialias(o.native, C.cairo_antialias_t(antialias))
|
||||
}
|
||||
|
||||
// GetAntialias is a wrapper around cairo_font_options_get_antialias().
|
||||
func (o *FontOptions) GetAntialias() Antialias {
|
||||
return Antialias(C.cairo_font_options_get_antialias(o.native))
|
||||
}
|
||||
|
||||
// SetSubpixelOrder is a wrapper around cairo_font_options_set_subpixel_order().
|
||||
func (o *FontOptions) SetSubpixelOrder(subpixelOrder SubpixelOrder) {
|
||||
C.cairo_font_options_set_subpixel_order(o.native, C.cairo_subpixel_order_t(subpixelOrder))
|
||||
}
|
||||
|
||||
// GetSubpixelOrder is a wrapper around cairo_font_options_get_subpixel_order().
|
||||
func (o *FontOptions) GetSubpixelOrder() SubpixelOrder {
|
||||
return SubpixelOrder(C.cairo_font_options_get_subpixel_order(o.native))
|
||||
}
|
||||
|
||||
// SetHintStyle is a wrapper around cairo_font_options_set_hint_style().
|
||||
func (o *FontOptions) SetHintStyle(hintStyle HintStyle) {
|
||||
C.cairo_font_options_set_hint_style(o.native, C.cairo_hint_style_t(hintStyle))
|
||||
}
|
||||
|
||||
// GetHintStyle is a wrapper around cairo_font_options_get_hint_style().
|
||||
func (o *FontOptions) GetHintStyle() HintStyle {
|
||||
return HintStyle(C.cairo_font_options_get_hint_style(o.native))
|
||||
}
|
||||
|
||||
// SetHintMetrics is a wrapper around cairo_font_options_set_hint_metrics().
|
||||
func (o *FontOptions) SetHintMetrics(hintMetrics HintMetrics) {
|
||||
C.cairo_font_options_set_hint_metrics(o.native, C.cairo_hint_metrics_t(hintMetrics))
|
||||
}
|
||||
|
||||
// GetHintMetrics is a wrapper around cairo_font_options_get_hint_metrics().
|
||||
func (o *FontOptions) GetHintMetrics() HintMetrics {
|
||||
return HintMetrics(C.cairo_font_options_get_hint_metrics(o.native))
|
||||
}
|
||||
28
third_party/gotk3/cairo/fontoptions_since_1_16.go
vendored
Normal file
28
third_party/gotk3/cairo/fontoptions_since_1_16.go
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// +build !cairo_1_9,!cairo_1_10,!cairo_1_11,!cairo_1_12,!cairo_1_13,!cairo_1_14,!cairo_1_15
|
||||
|
||||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetVariations is a wrapper around cairo_font_options_get_variations().
|
||||
func (o *FontOptions) GetVariations() string {
|
||||
return C.GoString(C.cairo_font_options_get_variations(o.native))
|
||||
}
|
||||
|
||||
// SetVariations is a wrapper around cairo_font_options_set_variations().
|
||||
func (o *FontOptions) SetVariations(variations string) {
|
||||
var cvariations *C.char
|
||||
if variations != "" {
|
||||
cvariations = C.CString(variations)
|
||||
// Cairo will call strdup on its own.
|
||||
defer C.free(unsafe.Pointer(cvariations))
|
||||
}
|
||||
|
||||
C.cairo_font_options_set_variations(o.native, cvariations)
|
||||
}
|
||||
33
third_party/gotk3/cairo/format.go
vendored
Normal file
33
third_party/gotk3/cairo/format.go
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Format is a representation of Cairo's cairo_format_t.
|
||||
type Format int
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
func marshalFormat(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return Format(c), nil
|
||||
}
|
||||
|
||||
// FormatStrideForWidth is a wrapper for cairo_format_stride_for_width().
|
||||
func FormatStrideForWidth(format Format, width int) int {
|
||||
c := C.cairo_format_stride_for_width(C.cairo_format_t(format), C.int(width))
|
||||
return int(c)
|
||||
}
|
||||
23
third_party/gotk3/cairo/linecap.go
vendored
Normal file
23
third_party/gotk3/cairo/linecap.go
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// LineCap is a representation of Cairo's cairo_line_cap_t.
|
||||
type LineCap int
|
||||
|
||||
const (
|
||||
LINE_CAP_BUTT LineCap = C.CAIRO_LINE_CAP_BUTT
|
||||
LINE_CAP_ROUND LineCap = C.CAIRO_LINE_CAP_ROUND
|
||||
LINE_CAP_SQUARE LineCap = C.CAIRO_LINE_CAP_SQUARE
|
||||
)
|
||||
|
||||
func marshalLineCap(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return LineCap(c), nil
|
||||
}
|
||||
23
third_party/gotk3/cairo/linejoin.go
vendored
Normal file
23
third_party/gotk3/cairo/linejoin.go
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// LineJoin is a representation of Cairo's cairo_line_join_t.
|
||||
type LineJoin int
|
||||
|
||||
const (
|
||||
LINE_JOIN_MITER LineJoin = C.CAIRO_LINE_JOIN_MITER
|
||||
LINE_JOIN_ROUND LineJoin = C.CAIRO_LINE_JOIN_ROUND
|
||||
LINE_JOIN_BEVEL LineJoin = C.CAIRO_LINE_JOIN_BEVEL
|
||||
)
|
||||
|
||||
func marshalLineJoin(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return LineJoin(c), nil
|
||||
}
|
||||
98
third_party/gotk3/cairo/matrix.go
vendored
Normal file
98
third_party/gotk3/cairo/matrix.go
vendored
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Matrix struct
|
||||
type Matrix struct {
|
||||
Xx, Yx float64
|
||||
Xy, Yy float64
|
||||
X0, Y0 float64
|
||||
}
|
||||
|
||||
// NewMatrix creates a new identiy matrix
|
||||
func NewMatrix(xx, yx, xy, yy, x0, y0 float64) *Matrix {
|
||||
return &Matrix{
|
||||
Xx: xx,
|
||||
Yx: yx,
|
||||
Xy: xy,
|
||||
Yy: yy,
|
||||
X0: x0,
|
||||
Y0: y0,
|
||||
}
|
||||
}
|
||||
|
||||
// Native returns native c pointer to a matrix
|
||||
func (m *Matrix) native() *C.cairo_matrix_t {
|
||||
return (*C.cairo_matrix_t)(unsafe.Pointer(m))
|
||||
}
|
||||
|
||||
// Native returns native c pointer to a matrix
|
||||
func (m *Matrix) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(m.native()))
|
||||
}
|
||||
|
||||
// InitIdentity initializes this matrix to identity matrix
|
||||
func (m *Matrix) InitIdentity() {
|
||||
C.cairo_matrix_init_identity(m.native())
|
||||
}
|
||||
|
||||
// InitTranslate initializes a matrix with the given translation
|
||||
func (m *Matrix) InitTranslate(tx, ty float64) {
|
||||
C.cairo_matrix_init_translate(m.native(), C.double(tx), C.double(ty))
|
||||
}
|
||||
|
||||
// InitScale initializes a matrix with the give scale
|
||||
func (m *Matrix) InitScale(sx, sy float64) {
|
||||
C.cairo_matrix_init_scale(m.native(), C.double(sx), C.double(sy))
|
||||
}
|
||||
|
||||
// InitRotate initializes a matrix with the given rotation
|
||||
func (m *Matrix) InitRotate(radians float64) {
|
||||
C.cairo_matrix_init_rotate(m.native(), C.double(radians))
|
||||
}
|
||||
|
||||
// Translate translates a matrix by the given amount
|
||||
func (m *Matrix) Translate(tx, ty float64) {
|
||||
C.cairo_matrix_translate(m.native(), C.double(tx), C.double(ty))
|
||||
}
|
||||
|
||||
// Scale scales the matrix by the given amounts
|
||||
func (m *Matrix) Scale(sx, sy float64) {
|
||||
C.cairo_matrix_scale(m.native(), C.double(sx), C.double(sy))
|
||||
}
|
||||
|
||||
// Rotate rotates the matrix by the given amount
|
||||
func (m *Matrix) Rotate(radians float64) {
|
||||
C.cairo_matrix_rotate(m.native(), C.double(radians))
|
||||
}
|
||||
|
||||
// Invert inverts the matrix
|
||||
func (m *Matrix) Invert() {
|
||||
C.cairo_matrix_invert(m.native())
|
||||
}
|
||||
|
||||
// Multiply multiplies the matrix by another matrix
|
||||
func (m *Matrix) Multiply(a, b Matrix) {
|
||||
C.cairo_matrix_multiply(m.native(), a.native(), b.native())
|
||||
}
|
||||
|
||||
// TransformDistance ...
|
||||
func (m *Matrix) TransformDistance(dx, dy float64) (float64, float64) {
|
||||
C.cairo_matrix_transform_distance(m.native(),
|
||||
(*C.double)(unsafe.Pointer(&dx)), (*C.double)(unsafe.Pointer(&dy)))
|
||||
return dx, dy
|
||||
}
|
||||
|
||||
// TransformPoint ...
|
||||
func (m *Matrix) TransformPoint(x, y float64) (float64, float64) {
|
||||
C.cairo_matrix_transform_point(m.native(),
|
||||
(*C.double)(unsafe.Pointer(&x)), (*C.double)(unsafe.Pointer(&y)))
|
||||
return x, y
|
||||
}
|
||||
13
third_party/gotk3/cairo/mimetype.go
vendored
Normal file
13
third_party/gotk3/cairo/mimetype.go
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package cairo
|
||||
|
||||
// MimeType is a representation of Cairo's CAIRO_MIME_TYPE_*
|
||||
// preprocessor constants.
|
||||
type MimeType string
|
||||
|
||||
const (
|
||||
MIME_TYPE_JP2 MimeType = "image/jp2"
|
||||
MIME_TYPE_JPEG MimeType = "image/jpeg"
|
||||
MIME_TYPE_PNG MimeType = "image/png"
|
||||
MIME_TYPE_URI MimeType = "image/x-uri"
|
||||
MIME_TYPE_UNIQUE_ID MimeType = "application/x-cairo.uuid"
|
||||
)
|
||||
49
third_party/gotk3/cairo/operator.go
vendored
Normal file
49
third_party/gotk3/cairo/operator.go
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Operator is a representation of Cairo's cairo_operator_t.
|
||||
type Operator int
|
||||
|
||||
const (
|
||||
OPERATOR_CLEAR Operator = C.CAIRO_OPERATOR_CLEAR
|
||||
OPERATOR_SOURCE Operator = C.CAIRO_OPERATOR_SOURCE
|
||||
OPERATOR_OVER Operator = C.CAIRO_OPERATOR_OVER
|
||||
OPERATOR_IN Operator = C.CAIRO_OPERATOR_IN
|
||||
OPERATOR_OUT Operator = C.CAIRO_OPERATOR_OUT
|
||||
OPERATOR_ATOP Operator = C.CAIRO_OPERATOR_ATOP
|
||||
OPERATOR_DEST Operator = C.CAIRO_OPERATOR_DEST
|
||||
OPERATOR_DEST_OVER Operator = C.CAIRO_OPERATOR_DEST_OVER
|
||||
OPERATOR_DEST_IN Operator = C.CAIRO_OPERATOR_DEST_IN
|
||||
OPERATOR_DEST_OUT Operator = C.CAIRO_OPERATOR_DEST_OUT
|
||||
OPERATOR_DEST_ATOP Operator = C.CAIRO_OPERATOR_DEST_ATOP
|
||||
OPERATOR_XOR Operator = C.CAIRO_OPERATOR_XOR
|
||||
OPERATOR_ADD Operator = C.CAIRO_OPERATOR_ADD
|
||||
OPERATOR_SATURATE Operator = C.CAIRO_OPERATOR_SATURATE
|
||||
OPERATOR_MULTIPLY Operator = C.CAIRO_OPERATOR_MULTIPLY
|
||||
OPERATOR_SCREEN Operator = C.CAIRO_OPERATOR_SCREEN
|
||||
OPERATOR_OVERLAY Operator = C.CAIRO_OPERATOR_OVERLAY
|
||||
OPERATOR_DARKEN Operator = C.CAIRO_OPERATOR_DARKEN
|
||||
OPERATOR_LIGHTEN Operator = C.CAIRO_OPERATOR_LIGHTEN
|
||||
OPERATOR_COLOR_DODGE Operator = C.CAIRO_OPERATOR_COLOR_DODGE
|
||||
OPERATOR_COLOR_BURN Operator = C.CAIRO_OPERATOR_COLOR_BURN
|
||||
OPERATOR_HARD_LIGHT Operator = C.CAIRO_OPERATOR_HARD_LIGHT
|
||||
OPERATOR_SOFT_LIGHT Operator = C.CAIRO_OPERATOR_SOFT_LIGHT
|
||||
OPERATOR_DIFFERENCE Operator = C.CAIRO_OPERATOR_DIFFERENCE
|
||||
OPERATOR_EXCLUSION Operator = C.CAIRO_OPERATOR_EXCLUSION
|
||||
OPERATOR_HSL_HUE Operator = C.CAIRO_OPERATOR_HSL_HUE
|
||||
OPERATOR_HSL_SATURATION Operator = C.CAIRO_OPERATOR_HSL_SATURATION
|
||||
OPERATOR_HSL_COLOR Operator = C.CAIRO_OPERATOR_HSL_COLOR
|
||||
OPERATOR_HSL_LUMINOSITY Operator = C.CAIRO_OPERATOR_HSL_LUMINOSITY
|
||||
)
|
||||
|
||||
func marshalOperator(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return Operator(c), nil
|
||||
}
|
||||
141
third_party/gotk3/cairo/pattern.go
vendored
Normal file
141
third_party/gotk3/cairo/pattern.go
vendored
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
//--------------------------------------------[ cairo_pattern_t == Pattern ]--
|
||||
|
||||
// Filter is a representation of Cairo's cairo_filter_t.
|
||||
type Filter int
|
||||
|
||||
const (
|
||||
FILTER_FAST Filter = C.CAIRO_FILTER_FAST
|
||||
FILTER_GOOD Filter = C.CAIRO_FILTER_GOOD
|
||||
FILTER_BEST Filter = C.CAIRO_FILTER_BEST
|
||||
FILTER_NEAREST Filter = C.CAIRO_FILTER_NEAREST
|
||||
FILTER_BILINEAR Filter = C.CAIRO_FILTER_BILINEAR
|
||||
FILTER_GAUSSIAN Filter = C.CAIRO_FILTER_GAUSSIAN
|
||||
)
|
||||
|
||||
func marshalFilter(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return Filter(c), nil
|
||||
}
|
||||
|
||||
// Pattern is a representation of Cairo's cairo_pattern_t.
|
||||
type Pattern struct {
|
||||
pattern *C.cairo_pattern_t
|
||||
}
|
||||
|
||||
// NewPatternFromRGB is a wrapper around cairo_pattern_create_rgb().
|
||||
func NewPatternFromRGB(red, green, blue float64) (*Pattern, error) {
|
||||
c := C.cairo_pattern_create_rgb(C.double(red), C.double(green), C.double(blue))
|
||||
return newPatternFromNative(c)
|
||||
}
|
||||
|
||||
// NewPatternFromRGBA is a wrapper around cairo_pattern_create_rgba().
|
||||
func NewPatternFromRGBA(red, green, blue, alpha float64) (*Pattern, error) {
|
||||
c := C.cairo_pattern_create_rgba(C.double(red), C.double(green), C.double(blue), C.double(alpha))
|
||||
return newPatternFromNative(c)
|
||||
}
|
||||
|
||||
// NewPatternForSurface is a wrapper around cairo_pattern_create_for_surface().
|
||||
func NewPatternForSurface(s *Surface) (*Pattern, error) {
|
||||
c := C.cairo_pattern_create_for_surface(s.native())
|
||||
return newPatternFromNative(c)
|
||||
}
|
||||
|
||||
// NewPatternLinear is a wrapper around cairo_pattern_create_linear().
|
||||
func NewPatternLinear(x0, y0, x1, y1 float64) (*Pattern, error) {
|
||||
c := C.cairo_pattern_create_linear(C.double(x0), C.double(y0), C.double(x1), C.double(y1))
|
||||
return newPatternFromNative(c)
|
||||
}
|
||||
|
||||
// NewPatternRadial is a wrapper around cairo_pattern_create_radial().
|
||||
func NewPatternRadial(x0, y0, r0, x1, y1, r1 float64) (*Pattern, error) {
|
||||
c := C.cairo_pattern_create_radial(C.double(x0), C.double(y0), C.double(r0),
|
||||
C.double(x1), C.double(y1), C.double(r1))
|
||||
return newPatternFromNative(c)
|
||||
}
|
||||
|
||||
func newPatternFromNative(patternNative *C.cairo_pattern_t) (*Pattern, error) {
|
||||
ptr := wrapPattern(patternNative)
|
||||
e := ptr.Status().ToError()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
runtime.SetFinalizer(ptr, func(v *Pattern) { glib.FinalizerStrategy(v.destroy) })
|
||||
return ptr, nil
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying cairo_pattern_t.
|
||||
func (v *Pattern) native() *C.cairo_pattern_t {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return v.pattern
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying cairo_pattern_t.
|
||||
func (v *Pattern) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalPattern(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
|
||||
pattern := (*C.cairo_pattern_t)(unsafe.Pointer(c))
|
||||
return wrapPattern(pattern), nil
|
||||
}
|
||||
|
||||
func wrapPattern(pattern *C.cairo_pattern_t) *Pattern {
|
||||
return &Pattern{pattern}
|
||||
}
|
||||
|
||||
// reference is a wrapper around cairo_pattern_reference().
|
||||
func (v *Pattern) reference() {
|
||||
v.pattern = C.cairo_pattern_reference(v.native())
|
||||
}
|
||||
|
||||
// destroy is a wrapper around cairo_pattern_destroy().
|
||||
func (v *Pattern) destroy() {
|
||||
C.cairo_pattern_destroy(v.native())
|
||||
}
|
||||
|
||||
// Status is a wrapper around cairo_pattern_status().
|
||||
func (v *Pattern) Status() Status {
|
||||
c := C.cairo_pattern_status(v.native())
|
||||
return Status(c)
|
||||
}
|
||||
|
||||
// AddColorStopRGB is a wrapper around cairo_pattern_add_color_stop_rgb().
|
||||
func (v *Pattern) AddColorStopRGB(offset, red, green, blue float64) error {
|
||||
C.cairo_pattern_add_color_stop_rgb(v.native(), C.double(offset),
|
||||
C.double(red), C.double(green), C.double(blue))
|
||||
return v.Status().ToError()
|
||||
}
|
||||
|
||||
// AddColorStopRGBA is a wrapper around cairo_pattern_add_color_stop_rgba().
|
||||
func (v *Pattern) AddColorStopRGBA(offset, red, green, blue, alpha float64) error {
|
||||
C.cairo_pattern_add_color_stop_rgba(v.native(), C.double(offset),
|
||||
C.double(red), C.double(green), C.double(blue), C.double(alpha))
|
||||
return v.Status().ToError()
|
||||
}
|
||||
|
||||
// PatternSetFilter is a wrapper around cairo_pattern_set_filter().
|
||||
func (v *Pattern) PatternSetFilter(filter Filter) {
|
||||
C.cairo_pattern_set_filter(v.native(), C.cairo_filter_t(filter))
|
||||
}
|
||||
|
||||
// PatternGetFilter is a wrapper around cairo_pattern_get_filter().
|
||||
func (v *Pattern) PatternGetFilter() Filter {
|
||||
return Filter(C.cairo_pattern_get_filter(v.native()))
|
||||
}
|
||||
381
third_party/gotk3/cairo/region.go
vendored
Normal file
381
third_party/gotk3/cairo/region.go
vendored
Normal file
|
|
@ -0,0 +1,381 @@
|
|||
// region.go
|
||||
|
||||
package cairo
|
||||
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
tm := []glib.TypeMarshaler{
|
||||
// Enums
|
||||
{glib.Type(C.cairo_gobject_region_overlap_get_type()), marshalRegionOverlap},
|
||||
|
||||
// Boxed
|
||||
{glib.Type(C.cairo_gobject_region_get_type()), marshalRegion},
|
||||
}
|
||||
glib.RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
// RegionOverlap is a representation of Cairo's cairo_region_overlap_t.
|
||||
type RegionOverlap int
|
||||
|
||||
const (
|
||||
REGION_OVERLAP_IN RegionOverlap = C.CAIRO_REGION_OVERLAP_IN
|
||||
REGION_OVERLAP_OUT RegionOverlap = C.CAIRO_REGION_OVERLAP_OUT
|
||||
REGION_OVERLAP_PART RegionOverlap = C.CAIRO_REGION_OVERLAP_PART
|
||||
)
|
||||
|
||||
func marshalRegionOverlap(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return RegionOverlap(c), nil
|
||||
}
|
||||
|
||||
/*
|
||||
* Rectangle
|
||||
*/
|
||||
|
||||
// Rectangle is a representation of Cairo's cairo_rectangle_int_t.
|
||||
type Rectangle struct {
|
||||
X, Y int
|
||||
Width, Height int
|
||||
}
|
||||
|
||||
// commodity function to ceate Rectangle cairo object.
|
||||
func RectangleNew(x, y, width, height int) *Rectangle {
|
||||
r := new(Rectangle)
|
||||
r.X = x
|
||||
r.Y = y
|
||||
r.Width = width
|
||||
r.Height = height
|
||||
return r
|
||||
}
|
||||
|
||||
func (v *Rectangle) native() *C.cairo_rectangle_int_t {
|
||||
r := new(C.cairo_rectangle_int_t)
|
||||
r.x = C.int(v.X)
|
||||
r.y = C.int(v.Y)
|
||||
r.width = C.int(v.Width)
|
||||
r.height = C.int(v.Height)
|
||||
return r
|
||||
}
|
||||
|
||||
func toRectangle(cr *C.cairo_rectangle_int_t) *Rectangle {
|
||||
return &Rectangle{
|
||||
X: int(cr.x), Y: int(cr.y),
|
||||
Width: int(cr.width), Height: int(cr.height)}
|
||||
}
|
||||
|
||||
/*
|
||||
* Region
|
||||
*/
|
||||
|
||||
// Region is a representation of Cairo's cairo_region_t.
|
||||
type Region struct {
|
||||
region *C.cairo_region_t
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying cairo_region_t.
|
||||
func (v *Region) native() *C.cairo_region_t {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return v.region
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying cairo_region_t.
|
||||
func (v *Region) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalRegion(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
|
||||
region := (*C.cairo_region_t)(unsafe.Pointer(c))
|
||||
return wrapRegion(region), nil
|
||||
}
|
||||
|
||||
func wrapRegion(region *C.cairo_region_t) *Region {
|
||||
return &Region{region}
|
||||
}
|
||||
|
||||
// newRegionFromNative that handle finalizer.
|
||||
func newRegionFromNative(regionNative *C.cairo_region_t) (*Region, error) {
|
||||
ptr := wrapRegion(regionNative)
|
||||
e := ptr.Status().ToError()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
runtime.SetFinalizer(ptr, func(v *Region) { glib.FinalizerStrategy(v.destroy) })
|
||||
return ptr, nil
|
||||
}
|
||||
|
||||
// RegionCreate is a wrapper around cairo_region_create().
|
||||
func RegionCreate() (*Region, error) {
|
||||
|
||||
return newRegionFromNative(C.cairo_region_create())
|
||||
}
|
||||
|
||||
// CreateRectangle is a wrapper around cairo_region_create_rectangle().
|
||||
func (v *Region) CreateRectangle(rectangle *Rectangle) (*Region, error) {
|
||||
|
||||
return newRegionFromNative(C.cairo_region_create_rectangle(
|
||||
rectangle.native()))
|
||||
}
|
||||
|
||||
// CreateRectangles is a wrapper around cairo_region_create_rectangles().
|
||||
func (v *Region) CreateRectangles(rectangles ...*Rectangle) (*Region, error) {
|
||||
|
||||
length := len(rectangles)
|
||||
|
||||
cRectangles := make([]C.cairo_rectangle_int_t, length)
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
cRectangles[i] = *rectangles[i].native()
|
||||
}
|
||||
|
||||
pRect := &cRectangles[0]
|
||||
|
||||
return newRegionFromNative(
|
||||
C.cairo_region_create_rectangles(
|
||||
pRect,
|
||||
C.int(length)))
|
||||
}
|
||||
|
||||
// Copy is a wrapper around cairo_region_copy().
|
||||
func (v *Region) Copy() (*Region, error) {
|
||||
|
||||
return newRegionFromNative(C.cairo_region_copy(v.native()))
|
||||
}
|
||||
|
||||
// reference is a wrapper around cairo_region_reference().
|
||||
func (v *Region) reference() {
|
||||
v.region = C.cairo_region_reference(v.native())
|
||||
}
|
||||
|
||||
// destroy is a wrapper around cairo_region_destroy().
|
||||
func (v *Region) destroy() {
|
||||
C.cairo_region_destroy(v.native())
|
||||
}
|
||||
|
||||
// Status is a wrapper around cairo_region_status().
|
||||
func (v *Region) Status() Status {
|
||||
c := C.cairo_region_status(v.native())
|
||||
return Status(c)
|
||||
}
|
||||
|
||||
// GetExtents is a wrapper around cairo_region_get_extents().
|
||||
func (v *Region) GetExtents(extents *Rectangle) {
|
||||
|
||||
C.cairo_region_get_extents(v.native(), extents.native())
|
||||
}
|
||||
|
||||
// NumRectangles is a wrapper around cairo_region_num_rectangles().
|
||||
func (v *Region) NumRectangles() int {
|
||||
|
||||
return int(C.cairo_region_num_rectangles(v.native()))
|
||||
}
|
||||
|
||||
// GetRectangle is a wrapper around cairo_region_get_rectangle().
|
||||
func (v *Region) GetRectangle(nth int) *Rectangle {
|
||||
|
||||
cr := new(C.cairo_rectangle_int_t)
|
||||
C.cairo_region_get_rectangle(v.native(), C.int(nth), cr)
|
||||
|
||||
return toRectangle(cr)
|
||||
}
|
||||
|
||||
// IsEmpty is a wrapper around cairo_region_is_empty().
|
||||
func (v *Region) IsEmpty() bool {
|
||||
|
||||
return gobool(C.cairo_region_is_empty(v.native()))
|
||||
}
|
||||
|
||||
// ContainsPoint is a wrapper around cairo_region_contains_point().
|
||||
func (v *Region) ContainsPoint(x, y int) bool {
|
||||
|
||||
return gobool(C.cairo_region_contains_point(
|
||||
v.native(), C.int(x), C.int(y)))
|
||||
}
|
||||
|
||||
// ContainsRectangle is a wrapper around cairo_region_contains_rectangle().
|
||||
func (v *Region) ContainsRectangle(rectangle *Rectangle) RegionOverlap {
|
||||
|
||||
return RegionOverlap(
|
||||
C.cairo_region_contains_rectangle(
|
||||
v.native(), rectangle.native()))
|
||||
}
|
||||
|
||||
// Equal is a wrapper around cairo_region_equal().
|
||||
func (v *Region) Equal(region *Region) bool {
|
||||
|
||||
return gobool(C.cairo_region_equal(v.native(), region.native()))
|
||||
}
|
||||
|
||||
// Translate is a wrapper around cairo_region_translate().
|
||||
func (v *Region) Translate(dx, dy int) {
|
||||
|
||||
C.cairo_region_translate(v.native(), C.int(dx), C.int(dy))
|
||||
}
|
||||
|
||||
// Intersect is a wrapper around cairo_region_intersect().
|
||||
// Note: contrary to the original statement, the source
|
||||
// 'Region' remains preserved.
|
||||
func (v *Region) Intersect(other *Region) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_intersect(
|
||||
dst.native(),
|
||||
other.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// IntersectRectangle is a wrapper around cairo_region_intersect_rectangle().
|
||||
// Note: contrary to the original statement, the source 'Region' remains preserved.
|
||||
func (v *Region) IntersectRectangle(rectangle *Rectangle) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_intersect_rectangle(
|
||||
dst.native(),
|
||||
rectangle.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// Substract is a wrapper around cairo_region_subtract().
|
||||
// Note: contrary to the original statement, the source
|
||||
// 'Region' remains preserved.
|
||||
func (v *Region) Substract(other *Region) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_subtract(
|
||||
dst.native(),
|
||||
other.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// SubstractRectangle is a wrapper around cairo_region_subtract_rectangle().
|
||||
// Note: contrary to the original statement, the source 'Region' remains preserved.
|
||||
func (v *Region) SubstractRectangle(rectangle *Rectangle) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_subtract_rectangle(
|
||||
dst.native(),
|
||||
rectangle.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// Union is a wrapper around cairo_region_union().
|
||||
// Note: contrary to the original statement, the source
|
||||
// 'Region' remains preserved.
|
||||
func (v *Region) Union(other *Region) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_union(
|
||||
dst.native(),
|
||||
other.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// UnionRectangle is a wrapper around cairo_region_union_rectangle().
|
||||
// Note: contrary to the original statement, the source 'Region' remains preserved.
|
||||
func (v *Region) UnionRectangle(rectangle *Rectangle) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_union_rectangle(
|
||||
dst.native(),
|
||||
rectangle.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// Xor is a wrapper around cairo_region_xor().
|
||||
// Note: contrary to the original statement, the source
|
||||
// 'Region' remains preserved.
|
||||
func (v *Region) Xor(other *Region) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_xor(
|
||||
dst.native(),
|
||||
other.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
// XorRectangle is a wrapper around cairo_region_xor_rectangle().
|
||||
// Note: contrary to the original statement, the source 'Region' remains preserved.
|
||||
func (v *Region) XorRectangle(rectangle *Rectangle) (*Region, error) {
|
||||
|
||||
dst, err := v.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = Status(
|
||||
C.cairo_region_xor_rectangle(
|
||||
dst.native(),
|
||||
rectangle.native())).ToError()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
124
third_party/gotk3/cairo/status.go
vendored
Normal file
124
third_party/gotk3/cairo/status.go
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Status is a representation of Cairo's cairo_status_t.
|
||||
type Status int
|
||||
|
||||
const (
|
||||
STATUS_SUCCESS Status = C.CAIRO_STATUS_SUCCESS
|
||||
STATUS_NO_MEMORY Status = C.CAIRO_STATUS_NO_MEMORY
|
||||
STATUS_INVALID_RESTORE Status = C.CAIRO_STATUS_INVALID_RESTORE
|
||||
STATUS_INVALID_POP_GROUP Status = C.CAIRO_STATUS_INVALID_POP_GROUP
|
||||
STATUS_NO_CURRENT_POINT Status = C.CAIRO_STATUS_NO_CURRENT_POINT
|
||||
STATUS_INVALID_MATRIX Status = C.CAIRO_STATUS_INVALID_MATRIX
|
||||
STATUS_INVALID_STATUS Status = C.CAIRO_STATUS_INVALID_STATUS
|
||||
STATUS_NULL_POINTER Status = C.CAIRO_STATUS_NULL_POINTER
|
||||
STATUS_INVALID_STRING Status = C.CAIRO_STATUS_INVALID_STRING
|
||||
STATUS_INVALID_PATH_DATA Status = C.CAIRO_STATUS_INVALID_PATH_DATA
|
||||
STATUS_READ_ERROR Status = C.CAIRO_STATUS_READ_ERROR
|
||||
STATUS_WRITE_ERROR Status = C.CAIRO_STATUS_WRITE_ERROR
|
||||
STATUS_SURFACE_FINISHED Status = C.CAIRO_STATUS_SURFACE_FINISHED
|
||||
STATUS_SURFACE_TYPE_MISMATCH Status = C.CAIRO_STATUS_SURFACE_TYPE_MISMATCH
|
||||
STATUS_PATTERN_TYPE_MISMATCH Status = C.CAIRO_STATUS_PATTERN_TYPE_MISMATCH
|
||||
STATUS_INVALID_CONTENT Status = C.CAIRO_STATUS_INVALID_CONTENT
|
||||
STATUS_INVALID_FORMAT Status = C.CAIRO_STATUS_INVALID_FORMAT
|
||||
STATUS_INVALID_VISUAL Status = C.CAIRO_STATUS_INVALID_VISUAL
|
||||
STATUS_FILE_NOT_FOUND Status = C.CAIRO_STATUS_FILE_NOT_FOUND
|
||||
STATUS_INVALID_DASH Status = C.CAIRO_STATUS_INVALID_DASH
|
||||
STATUS_INVALID_DSC_COMMENT Status = C.CAIRO_STATUS_INVALID_DSC_COMMENT
|
||||
STATUS_INVALID_INDEX Status = C.CAIRO_STATUS_INVALID_INDEX
|
||||
STATUS_CLIP_NOT_REPRESENTABLE Status = C.CAIRO_STATUS_CLIP_NOT_REPRESENTABLE
|
||||
STATUS_TEMP_FILE_ERROR Status = C.CAIRO_STATUS_TEMP_FILE_ERROR
|
||||
STATUS_INVALID_STRIDE Status = C.CAIRO_STATUS_INVALID_STRIDE
|
||||
STATUS_FONT_TYPE_MISMATCH Status = C.CAIRO_STATUS_FONT_TYPE_MISMATCH
|
||||
STATUS_USER_FONT_IMMUTABLE Status = C.CAIRO_STATUS_USER_FONT_IMMUTABLE
|
||||
STATUS_USER_FONT_ERROR Status = C.CAIRO_STATUS_USER_FONT_ERROR
|
||||
STATUS_NEGATIVE_COUNT Status = C.CAIRO_STATUS_NEGATIVE_COUNT
|
||||
STATUS_INVALID_CLUSTERS Status = C.CAIRO_STATUS_INVALID_CLUSTERS
|
||||
STATUS_INVALID_SLANT Status = C.CAIRO_STATUS_INVALID_SLANT
|
||||
STATUS_INVALID_WEIGHT Status = C.CAIRO_STATUS_INVALID_WEIGHT
|
||||
STATUS_INVALID_SIZE Status = C.CAIRO_STATUS_INVALID_SIZE
|
||||
STATUS_USER_FONT_NOT_IMPLEMENTED Status = C.CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED
|
||||
STATUS_DEVICE_TYPE_MISMATCH Status = C.CAIRO_STATUS_DEVICE_TYPE_MISMATCH
|
||||
STATUS_DEVICE_ERROR Status = C.CAIRO_STATUS_DEVICE_ERROR
|
||||
// STATUS_INVALID_MESH_CONSTRUCTION Status = C.CAIRO_STATUS_INVALID_MESH_CONSTRUCTION (since 1.12)
|
||||
// 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
|
||||
}
|
||||
|
||||
// String returns a readable status messsage usable in texts.
|
||||
func (s Status) String() string {
|
||||
str := StatusToString(s)
|
||||
str = strings.Replace(str, "CAIRO_STATUS_", "", 1)
|
||||
str = strings.Replace(str, "_", " ", 0)
|
||||
return strings.ToLower(str)
|
||||
}
|
||||
|
||||
// ToError returns the error for the status. Returns nil if success.
|
||||
func (s Status) ToError() error {
|
||||
if s == STATUS_SUCCESS {
|
||||
return nil
|
||||
}
|
||||
return errors.New(s.String())
|
||||
}
|
||||
302
third_party/gotk3/cairo/surface.go
vendored
Normal file
302
third_party/gotk3/cairo/surface.go
vendored
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
// #include <cairo-pdf.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
// CreateImageSurfaceForData is a wrapper around cairo_image_surface_create_for_data().
|
||||
func CreateImageSurfaceForData(data []byte, format Format, width, height, stride int) (*Surface, error) {
|
||||
surfaceNative := C.cairo_image_surface_create_for_data((*C.uchar)(unsafe.Pointer(&data[0])),
|
||||
C.cairo_format_t(format), C.int(width), C.int(height), C.int(stride))
|
||||
|
||||
status := Status(C.cairo_surface_status(surfaceNative))
|
||||
if status != STATUS_SUCCESS {
|
||||
return nil, ErrorStatus(status)
|
||||
}
|
||||
|
||||
s := wrapSurface(surfaceNative)
|
||||
|
||||
runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// CreateImageSurface is a wrapper around cairo_image_surface_create().
|
||||
func CreateImageSurface(format Format, width, height int) *Surface {
|
||||
c := C.cairo_image_surface_create(C.cairo_format_t(format),
|
||||
C.int(width), C.int(height))
|
||||
s := wrapSurface(c)
|
||||
runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
|
||||
return s
|
||||
}
|
||||
|
||||
/// Create a new PDF surface.
|
||||
func CreatePDFSurface(fileName string, width float64, height float64) (*Surface, error) {
|
||||
cstr := C.CString(fileName)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
surfaceNative := C.cairo_pdf_surface_create(cstr, C.double(width), C.double(height))
|
||||
|
||||
status := Status(C.cairo_surface_status(surfaceNative))
|
||||
if status != STATUS_SUCCESS {
|
||||
return nil, ErrorStatus(status)
|
||||
}
|
||||
|
||||
s := wrapSurface(surfaceNative)
|
||||
|
||||
runtime.SetFinalizer(s, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
|
||||
|
||||
return s, 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 (v *Surface) GetCSurface() *C.cairo_surface_t {
|
||||
return v.native()
|
||||
}
|
||||
|
||||
func marshalSurface(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
|
||||
return WrapSurface(uintptr(c)), 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 {
|
||||
surface := WrapSurface(s)
|
||||
if needsRef {
|
||||
surface.reference()
|
||||
}
|
||||
runtime.SetFinalizer(surface, func(v *Surface) { glib.FinalizerStrategy(v.destroy) })
|
||||
return surface
|
||||
}
|
||||
|
||||
func WrapSurface(s uintptr) *Surface {
|
||||
ptr := (*C.cairo_surface_t)(unsafe.Pointer(s))
|
||||
return wrapSurface(ptr)
|
||||
}
|
||||
|
||||
// Closes the surface. The surface must not be used afterwards.
|
||||
func (v *Surface) Close() {
|
||||
v.destroy()
|
||||
}
|
||||
|
||||
// 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, func(v *Surface) { glib.FinalizerStrategy(v.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, func(v *Surface) { glib.FinalizerStrategy(v.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() {
|
||||
if v.surface != nil {
|
||||
C.cairo_surface_destroy(v.native())
|
||||
v.surface = nil
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
// cairo_surface_get_device
|
||||
|
||||
// TODO(jrick) GetFontOptions (require FontOptions bindings)
|
||||
// cairo_surface_get_font_options
|
||||
|
||||
// TODO(jrick) GetContent (requires Content bindings)
|
||||
// cairo_surface_get_content
|
||||
|
||||
// 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)
|
||||
// cairo_surface_set_user_data
|
||||
|
||||
// TODO(jrick) GetUserData (depends on UserDataKey)
|
||||
// cairo_surface_get_user_data
|
||||
|
||||
// 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)
|
||||
// cairo_surface_set_mime_data
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
// WriteToPNG is a wrapper around cairo_surface_write_png(). It writes the Cairo
|
||||
// surface to the given file in PNG format.
|
||||
func (v *Surface) WriteToPNG(fileName string) error {
|
||||
cstr := C.CString(fileName)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
status := Status(C.cairo_surface_write_to_png(v.surface, cstr))
|
||||
|
||||
if status != STATUS_SUCCESS {
|
||||
return ErrorStatus(status)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(jrick) SupportsMimeType (since 1.12)
|
||||
// cairo_surface_supports_mime_type
|
||||
|
||||
// TODO(jrick) MapToImage (since 1.12)
|
||||
// cairo_surface_map_to_image
|
||||
|
||||
// TODO(jrick) UnmapImage (since 1.12)
|
||||
// cairo_surface_unmap_image
|
||||
|
||||
// GetHeight is a wrapper around cairo_image_surface_get_height().
|
||||
func (v *Surface) GetHeight() int {
|
||||
return int(C.cairo_image_surface_get_height(v.surface))
|
||||
}
|
||||
|
||||
// GetWidth is a wrapper around cairo_image_surface_get_width().
|
||||
func (v *Surface) GetWidth() int {
|
||||
return int(C.cairo_image_surface_get_width(v.surface))
|
||||
}
|
||||
|
||||
// GetData is a wrapper around cairo_image_surface_get_data().
|
||||
func (v *Surface) GetData() unsafe.Pointer {
|
||||
return unsafe.Pointer(C.cairo_image_surface_get_data(v.surface))
|
||||
}
|
||||
45
third_party/gotk3/cairo/surfacetype.go
vendored
Normal file
45
third_party/gotk3/cairo/surfacetype.go
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// SurfaceType is a representation of Cairo's cairo_surface_type_t.
|
||||
type SurfaceType int
|
||||
|
||||
const (
|
||||
SURFACE_TYPE_IMAGE SurfaceType = C.CAIRO_SURFACE_TYPE_IMAGE
|
||||
SURFACE_TYPE_PDF SurfaceType = C.CAIRO_SURFACE_TYPE_PDF
|
||||
SURFACE_TYPE_PS SurfaceType = C.CAIRO_SURFACE_TYPE_PS
|
||||
SURFACE_TYPE_XLIB SurfaceType = C.CAIRO_SURFACE_TYPE_XLIB
|
||||
SURFACE_TYPE_XCB SurfaceType = C.CAIRO_SURFACE_TYPE_XCB
|
||||
SURFACE_TYPE_GLITZ SurfaceType = C.CAIRO_SURFACE_TYPE_GLITZ
|
||||
SURFACE_TYPE_QUARTZ SurfaceType = C.CAIRO_SURFACE_TYPE_QUARTZ
|
||||
SURFACE_TYPE_WIN32 SurfaceType = C.CAIRO_SURFACE_TYPE_WIN32
|
||||
SURFACE_TYPE_BEOS SurfaceType = C.CAIRO_SURFACE_TYPE_BEOS
|
||||
SURFACE_TYPE_DIRECTFB SurfaceType = C.CAIRO_SURFACE_TYPE_DIRECTFB
|
||||
SURFACE_TYPE_SVG SurfaceType = C.CAIRO_SURFACE_TYPE_SVG
|
||||
SURFACE_TYPE_OS2 SurfaceType = C.CAIRO_SURFACE_TYPE_OS2
|
||||
SURFACE_TYPE_WIN32_PRINTING SurfaceType = C.CAIRO_SURFACE_TYPE_WIN32_PRINTING
|
||||
SURFACE_TYPE_QUARTZ_IMAGE SurfaceType = C.CAIRO_SURFACE_TYPE_QUARTZ_IMAGE
|
||||
SURFACE_TYPE_SCRIPT SurfaceType = C.CAIRO_SURFACE_TYPE_SCRIPT
|
||||
SURFACE_TYPE_QT SurfaceType = C.CAIRO_SURFACE_TYPE_QT
|
||||
SURFACE_TYPE_RECORDING SurfaceType = C.CAIRO_SURFACE_TYPE_RECORDING
|
||||
SURFACE_TYPE_VG SurfaceType = C.CAIRO_SURFACE_TYPE_VG
|
||||
SURFACE_TYPE_GL SurfaceType = C.CAIRO_SURFACE_TYPE_GL
|
||||
SURFACE_TYPE_DRM SurfaceType = C.CAIRO_SURFACE_TYPE_DRM
|
||||
SURFACE_TYPE_TEE SurfaceType = C.CAIRO_SURFACE_TYPE_TEE
|
||||
SURFACE_TYPE_XML SurfaceType = C.CAIRO_SURFACE_TYPE_XML
|
||||
SURFACE_TYPE_SKIA SurfaceType = C.CAIRO_SURFACE_TYPE_SKIA
|
||||
SURFACE_TYPE_SUBSURFACE SurfaceType = C.CAIRO_SURFACE_TYPE_SUBSURFACE
|
||||
// SURFACE_TYPE_COGL SurfaceType = C.CAIRO_SURFACE_TYPE_COGL (since 1.12)
|
||||
)
|
||||
|
||||
func marshalSurfaceType(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return SurfaceType(c), nil
|
||||
}
|
||||
125
third_party/gotk3/cairo/text.go
vendored
Normal file
125
third_party/gotk3/cairo/text.go
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// FontSlant is a representation of Cairo's cairo_font_slant_t
|
||||
type FontSlant int
|
||||
|
||||
const (
|
||||
FONT_SLANT_NORMAL FontSlant = C.CAIRO_FONT_SLANT_NORMAL
|
||||
FONT_SLANT_ITALIC FontSlant = C.CAIRO_FONT_SLANT_ITALIC
|
||||
FONT_SLANT_OBLIQUE FontSlant = C.CAIRO_FONT_SLANT_OBLIQUE
|
||||
)
|
||||
|
||||
// FontWeight is a representation of Cairo's cairo_font_weight_t
|
||||
type FontWeight int
|
||||
|
||||
const (
|
||||
FONT_WEIGHT_NORMAL FontWeight = C.CAIRO_FONT_WEIGHT_NORMAL
|
||||
FONT_WEIGHT_BOLD FontWeight = C.CAIRO_FONT_WEIGHT_BOLD
|
||||
)
|
||||
|
||||
func (v *Context) SelectFontFace(family string, slant FontSlant, weight FontWeight) {
|
||||
cstr := C.CString(family)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
C.cairo_select_font_face(v.native(), (*C.char)(cstr), C.cairo_font_slant_t(slant), C.cairo_font_weight_t(weight))
|
||||
}
|
||||
|
||||
func (v *Context) SetFontSize(size float64) {
|
||||
C.cairo_set_font_size(v.native(), C.double(size))
|
||||
}
|
||||
|
||||
// TODO: cairo_set_font_matrix
|
||||
|
||||
// TODO: cairo_get_font_matrix
|
||||
|
||||
// TODO: cairo_set_font_options
|
||||
|
||||
// TODO: cairo_get_font_options
|
||||
|
||||
// TODO: cairo_set_font_face
|
||||
|
||||
// TODO: cairo_get_font_face
|
||||
|
||||
// TODO: cairo_set_scaled_font
|
||||
|
||||
// TODO: cairo_get_scaled_font
|
||||
|
||||
func (v *Context) ShowText(utf8 string) {
|
||||
cstr := C.CString(utf8)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
C.cairo_show_text(v.native(), (*C.char)(cstr))
|
||||
}
|
||||
|
||||
// TODO: cairo_show_glyphs
|
||||
|
||||
// TODO: cairo_show_text_glyphs
|
||||
|
||||
type FontExtents struct {
|
||||
Ascent float64
|
||||
Descent float64
|
||||
Height float64
|
||||
MaxXAdvance float64
|
||||
MaxYAdvance float64
|
||||
}
|
||||
|
||||
func (v *Context) FontExtents() FontExtents {
|
||||
var extents C.cairo_font_extents_t
|
||||
C.cairo_font_extents(v.native(), &extents)
|
||||
return FontExtents{
|
||||
Ascent: float64(extents.ascent),
|
||||
Descent: float64(extents.descent),
|
||||
Height: float64(extents.height),
|
||||
MaxXAdvance: float64(extents.max_x_advance),
|
||||
MaxYAdvance: float64(extents.max_y_advance),
|
||||
}
|
||||
}
|
||||
|
||||
type TextExtents struct {
|
||||
XBearing float64
|
||||
YBearing float64
|
||||
Width float64
|
||||
Height float64
|
||||
XAdvance float64
|
||||
YAdvance float64
|
||||
}
|
||||
|
||||
func (v *Context) TextExtents(utf8 string) TextExtents {
|
||||
cstr := C.CString(utf8)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
var extents C.cairo_text_extents_t
|
||||
C.cairo_text_extents(v.native(), (*C.char)(cstr), &extents)
|
||||
return TextExtents{
|
||||
XBearing: float64(extents.x_bearing),
|
||||
YBearing: float64(extents.y_bearing),
|
||||
Width: float64(extents.width),
|
||||
Height: float64(extents.height),
|
||||
XAdvance: float64(extents.x_advance),
|
||||
YAdvance: float64(extents.y_advance),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: cairo_glyph_extents
|
||||
|
||||
// TODO: cairo_toy_font_face_create
|
||||
|
||||
// TODO: cairo_toy_font_face_get_family
|
||||
|
||||
// TODO: cairo_toy_font_face_get_slant
|
||||
|
||||
// TODO: cairo_toy_font_face_get_weight
|
||||
|
||||
// TODO: cairo_glyph_allocate
|
||||
|
||||
// TODO: cairo_glyph_free
|
||||
|
||||
// TODO: cairo_text_cluster_allocate
|
||||
|
||||
// TODO: cairo_text_cluster_free
|
||||
78
third_party/gotk3/cairo/translations.go
vendored
Normal file
78
third_party/gotk3/cairo/translations.go
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
import "C"
|
||||
|
||||
// Translate is a wrapper around cairo_translate.
|
||||
func (v *Context) Translate(tx, ty float64) {
|
||||
C.cairo_translate(v.native(), C.double(tx), C.double(ty))
|
||||
}
|
||||
|
||||
// Scale is a wrapper around cairo_scale.
|
||||
func (v *Context) Scale(sx, sy float64) {
|
||||
C.cairo_scale(v.native(), C.double(sx), C.double(sy))
|
||||
}
|
||||
|
||||
// Rotate is a wrapper around cairo_rotate.
|
||||
func (v *Context) Rotate(angle float64) {
|
||||
C.cairo_rotate(v.native(), C.double(angle))
|
||||
}
|
||||
|
||||
// Transform is a wrapper around cairo_transform.
|
||||
func (v *Context) Transform(matrix *Matrix) {
|
||||
C.cairo_transform(v.native(), matrix.native())
|
||||
}
|
||||
|
||||
// SetMatrix is a wrapper around cairo_set_matrix.
|
||||
func (v *Context) SetMatrix(matrix *Matrix) {
|
||||
C.cairo_set_matrix(v.native(), matrix.native())
|
||||
}
|
||||
|
||||
// GetMatrix is a wrapper around cairo_get_matrix.
|
||||
func (v *Context) GetMatrix() *Matrix {
|
||||
var matrix C.cairo_matrix_t
|
||||
C.cairo_get_matrix(v.native(), &matrix)
|
||||
return &Matrix{
|
||||
Xx: float64(matrix.xx),
|
||||
Yx: float64(matrix.yx),
|
||||
Xy: float64(matrix.xy),
|
||||
Yy: float64(matrix.yy),
|
||||
X0: float64(matrix.x0),
|
||||
Y0: float64(matrix.y0),
|
||||
}
|
||||
}
|
||||
|
||||
// IdentityMatrix is a wrapper around cairo_identity_matrix().
|
||||
//
|
||||
// Resets the current transformation matrix (CTM) by setting it equal to the
|
||||
// identity matrix. That is, the user-space and device-space axes will be
|
||||
// aligned and one user-space unit will transform to one device-space unit.
|
||||
func (v *Context) IdentityMatrix() {
|
||||
C.cairo_identity_matrix(v.native())
|
||||
}
|
||||
|
||||
// UserToDevice is a wrapper around cairo_user_to_device.
|
||||
func (v *Context) UserToDevice(x, y float64) (float64, float64) {
|
||||
C.cairo_user_to_device(v.native(), (*C.double)(&x), (*C.double)(&y))
|
||||
return x, y
|
||||
}
|
||||
|
||||
// UserToDeviceDistance is a wrapper around cairo_user_to_device_distance.
|
||||
func (v *Context) UserToDeviceDistance(dx, dy float64) (float64, float64) {
|
||||
C.cairo_user_to_device_distance(v.native(), (*C.double)(&dx), (*C.double)(&dy))
|
||||
return dx, dy
|
||||
}
|
||||
|
||||
// DeviceToUser is a wrapper around cairo_device_to_user.
|
||||
func (v *Context) DeviceToUser(x, y float64) (float64, float64) {
|
||||
C.cairo_device_to_user(v.native(), (*C.double)(&x), (*C.double)(&y))
|
||||
return x, y
|
||||
}
|
||||
|
||||
// DeviceToUserDistance is a wrapper around cairo_device_to_user_distance.
|
||||
func (v *Context) DeviceToUserDistance(x, y float64) (float64, float64) {
|
||||
C.cairo_device_to_user_distance(v.native(), (*C.double)(&x), (*C.double)(&y))
|
||||
return x, y
|
||||
}
|
||||
20
third_party/gotk3/cairo/util.go
vendored
Normal file
20
third_party/gotk3/cairo/util.go
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package cairo
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <cairo.h>
|
||||
// #include <cairo-gobject.h>
|
||||
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
|
||||
}
|
||||
2576
third_party/gotk3/gdk/gdk.go
vendored
Normal file
2576
third_party/gotk3/gdk/gdk.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
48
third_party/gotk3/gdk/gdk.go.h
vendored
Normal file
48
third_party/gotk3/gdk/gdk.go.h
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// Type Casting
|
||||
static GdkAtom toGdkAtom(void *p) { return ((GdkAtom)p); }
|
||||
|
||||
static GdkDevice *toGdkDevice(void *p) { return (GDK_DEVICE(p)); }
|
||||
|
||||
static GdkCursor *toGdkCursor(void *p) { return (GDK_CURSOR(p)); }
|
||||
|
||||
static GdkDeviceManager *toGdkDeviceManager(void *p) {
|
||||
return (GDK_DEVICE_MANAGER(p));
|
||||
}
|
||||
|
||||
static GdkDisplay *toGdkDisplay(void *p) { return (GDK_DISPLAY(p)); }
|
||||
|
||||
static GdkDisplayManager *toGdkDisplayManager(void *p) { return (GDK_DISPLAY_MANAGER(p)); }
|
||||
|
||||
static GdkKeymap *toGdkKeymap(void *p) { return (GDK_KEYMAP(p)); }
|
||||
|
||||
static GdkDragContext *toGdkDragContext(void *p) {
|
||||
return (GDK_DRAG_CONTEXT(p));
|
||||
}
|
||||
|
||||
static GdkScreen *toGdkScreen(void *p) { return (GDK_SCREEN(p)); }
|
||||
|
||||
static GdkVisual *toGdkVisual(void *p) { return (GDK_VISUAL(p)); }
|
||||
|
||||
static GdkWindow *toGdkWindow(void *p) { return (GDK_WINDOW(p)); }
|
||||
|
||||
static inline gchar **next_gcharptr(gchar **s) { return (s + 1); }
|
||||
33
third_party/gotk3/gdk/gdk_deprecated_since_3_10.go
vendored
Normal file
33
third_party/gotk3/gdk/gdk_deprecated_since_3_10.go
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
//
|
||||
// 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 wrappers for symbols deprecated beginning with GTK 3.10,
|
||||
// and should only be included in a build targeted intended to target GTK
|
||||
// 3.8 or earlier. To target an earlier build build, use the build tag
|
||||
// gtk_MAJOR_MINOR. For example, to target GTK 3.8, run
|
||||
// 'go build -tags gtk_3_8'.
|
||||
// +build gtk_3_6 gtk_3_8 gtk_deprecated
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
import "C"
|
||||
|
||||
// GetNScreens is a wrapper around gdk_display_get_n_screens().
|
||||
func (v *Display) GetNScreens() int {
|
||||
c := C.gdk_display_get_n_screens(v.native())
|
||||
return int(c)
|
||||
}
|
||||
12
third_party/gotk3/gdk/gdk_deprecated_since_3_16.go
vendored
Normal file
12
third_party/gotk3/gdk/gdk_deprecated_since_3_16.go
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
//+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_deprecated
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
import "C"
|
||||
|
||||
// SupportsComposite() is a wrapper around gdk_display_supports_composite().
|
||||
func (v *Display) SupportsComposite() bool {
|
||||
c := C.gdk_display_supports_composite(v.native())
|
||||
return gobool(c)
|
||||
}
|
||||
79
third_party/gotk3/gdk/gdk_deprecated_since_3_20.go
vendored
Normal file
79
third_party/gotk3/gdk/gdk_deprecated_since_3_20.go
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_deprecated
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// Grab() is a wrapper around gdk_device_grab().
|
||||
func (v *Device) Grab(w *Window, ownership GrabOwnership, owner_events bool, event_mask EventMask, cursor *Cursor, time uint32) GrabStatus {
|
||||
ret := C.gdk_device_grab(
|
||||
v.native(),
|
||||
w.native(),
|
||||
C.GdkGrabOwnership(ownership),
|
||||
gbool(owner_events),
|
||||
C.GdkEventMask(event_mask),
|
||||
cursor.native(),
|
||||
C.guint32(time),
|
||||
)
|
||||
return GrabStatus(ret)
|
||||
}
|
||||
|
||||
// GetClientPointer() is a wrapper around gdk_device_manager_get_client_pointer().
|
||||
func (v *DeviceManager) GetClientPointer() (*Device, error) {
|
||||
c := C.gdk_device_manager_get_client_pointer(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Device{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// ListDevices() is a wrapper around gdk_device_manager_list_devices().
|
||||
func (v *DeviceManager) ListDevices(tp DeviceType) *glib.List {
|
||||
clist := C.gdk_device_manager_list_devices(v.native(), C.GdkDeviceType(tp))
|
||||
if clist == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
//TODO: WrapList should set the finalizer
|
||||
glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
|
||||
glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
|
||||
return &Device{&glib.Object{glib.ToGObject(ptr)}}
|
||||
})
|
||||
runtime.SetFinalizer(glist, func(glist *glib.List) {
|
||||
glib.FinalizerStrategy(glist.Free)
|
||||
})
|
||||
return glist
|
||||
}
|
||||
|
||||
// Ungrab() is a wrapper around gdk_device_ungrab().
|
||||
func (v *Device) Ungrab(time uint32) {
|
||||
C.gdk_device_ungrab(v.native(), C.guint32(time))
|
||||
}
|
||||
|
||||
// GetDeviceManager() is a wrapper around gdk_display_get_device_manager().
|
||||
func (v *Display) GetDeviceManager() (*DeviceManager, error) {
|
||||
c := C.gdk_display_get_device_manager(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &DeviceManager{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// GetScreen() is a wrapper around gdk_display_get_screen().
|
||||
func (v *Display) GetScreen(screenNum int) (*Screen, error) {
|
||||
c := C.gdk_display_get_screen(v.native(), C.gint(screenNum))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Screen{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
113
third_party/gotk3/gdk/gdk_deprecated_since_3_22.go
vendored
Normal file
113
third_party/gotk3/gdk/gdk_deprecated_since_3_22.go
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
//+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20 gtk_deprecated
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
import "C"
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// GdkByteOrder
|
||||
|
||||
/*
|
||||
* GdkScreen
|
||||
*/
|
||||
|
||||
// GetActiveWindow is a wrapper around gdk_screen_get_active_window().
|
||||
func (v *Screen) GetActiveWindow() (*Window, error) {
|
||||
return toWindow(C.gdk_screen_get_active_window(v.native()))
|
||||
}
|
||||
|
||||
// GetHeight is a wrapper around gdk_screen_get_height().
|
||||
func (v *Screen) GetHeight() int {
|
||||
c := C.gdk_screen_get_height(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetHeightMM is a wrapper around gdk_screen_get_height_mm().
|
||||
func (v *Screen) GetHeightMM() int {
|
||||
return int(C.gdk_screen_get_height_mm(v.native()))
|
||||
}
|
||||
|
||||
// GetMonitorAtPoint is a wrapper around gdk_screen_get_monitor_at_point().
|
||||
func (v *Screen) GetMonitorAtPoint(x, y int) int {
|
||||
return int(C.gdk_screen_get_monitor_at_point(v.native(), C.gint(x), C.gint(y)))
|
||||
}
|
||||
|
||||
// GetMonitorAtWindow is a wrapper around gdk_screen_get_monitor_at_window().
|
||||
func (v *Screen) GetMonitorAtWindow(w *Window) int {
|
||||
return int(C.gdk_screen_get_monitor_at_window(v.native(), w.native()))
|
||||
}
|
||||
|
||||
// GetMonitorHeightMM is a wrapper around gdk_screen_get_monitor_height_mm().
|
||||
func (v *Screen) GetMonitorHeightMM(m int) int {
|
||||
return int(C.gdk_screen_get_monitor_height_mm(v.native(), C.gint(m)))
|
||||
}
|
||||
|
||||
// GetMonitorPlugName is a wrapper around gdk_screen_get_monitor_plug_name().
|
||||
func (v *Screen) GetMonitorPlugName(m int) (string, error) {
|
||||
return toString(C.gdk_screen_get_monitor_plug_name(v.native(), C.gint(m)))
|
||||
}
|
||||
|
||||
// GetMonitorScaleFactor is a wrapper around gdk_screen_get_monitor_scale_factor().
|
||||
func (v *Screen) GetMonitorScaleFactor(m int) int {
|
||||
return int(C.gdk_screen_get_monitor_scale_factor(v.native(), C.gint(m)))
|
||||
}
|
||||
|
||||
// GetMonitorWidthMM is a wrapper around gdk_screen_get_monitor_width_mm().
|
||||
func (v *Screen) GetMonitorWidthMM(m int) int {
|
||||
return int(C.gdk_screen_get_monitor_width_mm(v.native(), C.gint(m)))
|
||||
}
|
||||
|
||||
// GetNMonitors is a wrapper around gdk_screen_get_n_monitors().
|
||||
func (v *Screen) GetNMonitors() int {
|
||||
return int(C.gdk_screen_get_n_monitors(v.native()))
|
||||
}
|
||||
|
||||
// GetNumber is a wrapper around gdk_screen_get_number().
|
||||
func (v *Screen) GetNumber() int {
|
||||
return int(C.gdk_screen_get_number(v.native()))
|
||||
}
|
||||
|
||||
// GetPrimaryMonitor is a wrapper around gdk_screen_get_primary_monitor().
|
||||
func (v *Screen) GetPrimaryMonitor() int {
|
||||
return int(C.gdk_screen_get_primary_monitor(v.native()))
|
||||
}
|
||||
|
||||
// GetWidth is a wrapper around gdk_screen_get_width().
|
||||
func (v *Screen) GetWidth() int {
|
||||
c := C.gdk_screen_get_width(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetWidthMM is a wrapper around gdk_screen_get_width_mm().
|
||||
func (v *Screen) GetWidthMM() int {
|
||||
return int(C.gdk_screen_get_width_mm(v.native()))
|
||||
}
|
||||
|
||||
// MakeDisplayName is a wrapper around gdk_screen_make_display_name().
|
||||
func (v *Screen) MakeDisplayName() (string, error) {
|
||||
return toString(C.gdk_screen_make_display_name(v.native()))
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkVisuals
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// gdk_query_depths().
|
||||
// gdk_query_visual_types().
|
||||
// gdk_list_visuals().
|
||||
// gdk_visual_get_bits_per_rgb().
|
||||
// gdk_visual_get_byte_order().
|
||||
// gdk_visual_get_colormap_size().
|
||||
// gdk_visual_get_best_depth().
|
||||
// gdk_visual_get_best_type().
|
||||
// gdk_visual_get_system().
|
||||
// gdk_visual_get_best().
|
||||
// gdk_visual_get_best_with_depth().
|
||||
// gdk_visual_get_best_with_type().
|
||||
// gdk_visual_get_best_with_both().
|
||||
51
third_party/gotk3/gdk/gdk_since_3_10.go
vendored
Normal file
51
third_party/gotk3/gdk/gdk_since_3_10.go
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// +build !gtk_3_6,!gtk_3_8
|
||||
// Supports building with gtk 3.10+
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/cairo"
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// TODO:
|
||||
// gdk_device_get_position_double().
|
||||
|
||||
// GetScaleFactor is a wrapper around gdk_window_get_scale_factor().
|
||||
func (v *Window) GetScaleFactor() int {
|
||||
return int(C.gdk_window_get_scale_factor(v.native()))
|
||||
}
|
||||
|
||||
// CreateSimilarImageSurface is a wrapper around gdk_window_create_similar_image_surface().
|
||||
func (v *Window) CreateSimilarImageSurface(format cairo.Format, w, h, scale int) (*cairo.Surface, error) {
|
||||
surface := C.gdk_window_create_similar_image_surface(v.native(), C.cairo_format_t(format), C.gint(w), C.gint(h), C.gint(scale))
|
||||
|
||||
status := cairo.Status(C.cairo_surface_status(surface))
|
||||
if status != cairo.STATUS_SUCCESS {
|
||||
return nil, cairo.ErrorStatus(status)
|
||||
}
|
||||
|
||||
return cairo.NewSurface(uintptr(unsafe.Pointer(surface)), false), nil
|
||||
}
|
||||
|
||||
// CairoSurfaceCreateFromPixbuf is a wrapper around gdk_cairo_surface_create_from_pixbuf().
|
||||
func CairoSurfaceCreateFromPixbuf(pixbuf *Pixbuf, scale int, window *Window) (*cairo.Surface, error) {
|
||||
v := C.gdk_cairo_surface_create_from_pixbuf(pixbuf.native(), C.gint(scale), window.native())
|
||||
|
||||
status := cairo.Status(C.cairo_surface_status(v))
|
||||
if status != cairo.STATUS_SUCCESS {
|
||||
return nil, cairo.ErrorStatus(status)
|
||||
}
|
||||
|
||||
surface := cairo.WrapSurface(uintptr(unsafe.Pointer(v)))
|
||||
runtime.SetFinalizer(surface, func(v *cairo.Surface) { glib.FinalizerStrategy(v.Close) })
|
||||
|
||||
return surface, nil
|
||||
}
|
||||
7
third_party/gotk3/gdk/gdk_since_3_12.go
vendored
Normal file
7
third_party/gotk3/gdk/gdk_since_3_12.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// +build !gtk_3_6,!gtk_3_8,!gtk_3_10
|
||||
// Supports building with gtk 3.12+
|
||||
|
||||
package gdk
|
||||
|
||||
// TODO:
|
||||
// gdk_device_get_last_event_window().
|
||||
197
third_party/gotk3/gdk/gdk_since_3_16.go
vendored
Normal file
197
third_party/gotk3/gdk/gdk_since_3_16.go
vendored
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
// +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14
|
||||
// Supports building with gtk 3.16+
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk_since_3_16.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
tm := []glib.TypeMarshaler{
|
||||
{glib.Type(C.gdk_gl_context_get_type()), marshalGLContext},
|
||||
}
|
||||
|
||||
glib.RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
const (
|
||||
GRAB_FAILED GrabStatus = C.GDK_GRAB_FAILED
|
||||
)
|
||||
|
||||
/*
|
||||
* GdkDevice
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// gdk_device_get_vendor_id().
|
||||
// gdk_device_get_product_id().
|
||||
|
||||
/*
|
||||
* GdkGLContext
|
||||
*/
|
||||
|
||||
// GLContext is a representation of GDK's GdkGLContext.
|
||||
type GLContext struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkGLContext.
|
||||
func (v *GLContext) native() *C.GdkGLContext {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkGLContext(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkGLContext.
|
||||
func (v *GLContext) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalGLContext(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
return &GLContext{obj}, nil
|
||||
}
|
||||
|
||||
// GetDisplay is a wrapper around gdk_gl_context_get_display().
|
||||
func (v *GLContext) GetDisplay() (*Display, error) {
|
||||
c := C.gdk_gl_context_get_display(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Display{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// GetWindow is a wrapper around gdk_gl_context_get_window().
|
||||
func (v *GLContext) GetSurface() (*Window, error) {
|
||||
c := C.gdk_gl_context_get_window(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Window{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// GetSharedContext is a wrapper around gdk_gl_context_get_shared_context().
|
||||
func (v *GLContext) GetSharedContext() (*GLContext, error) {
|
||||
c := C.gdk_gl_context_get_shared_context(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &GLContext{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// MajorVersion is a representation of OpenGL major version.
|
||||
type MajorVersion int
|
||||
|
||||
// MinorVersion is a representation of OpenGL minor version.
|
||||
type MinorVersion int
|
||||
|
||||
// GetVersion is a wrapper around gdk_gl_context_get_version().
|
||||
func (v *GLContext) GetVersion() (MajorVersion, MinorVersion) {
|
||||
var major, minor int
|
||||
C.gdk_gl_context_get_version(v.native(),
|
||||
(*C.int)(unsafe.Pointer(&major)), (*C.int)(unsafe.Pointer(&minor)))
|
||||
|
||||
return MajorVersion(major), MinorVersion(minor)
|
||||
}
|
||||
|
||||
// GetRequiredVersion is a wrapper around gdk_gl_context_get_required_version().
|
||||
func (v *GLContext) GetRequiredVersion() (MajorVersion, MinorVersion) {
|
||||
var major, minor int
|
||||
C.gdk_gl_context_get_required_version(v.native(),
|
||||
(*C.int)(unsafe.Pointer(&major)), (*C.int)(unsafe.Pointer(&minor)))
|
||||
|
||||
return MajorVersion(major), MinorVersion(minor)
|
||||
}
|
||||
|
||||
// SetRequiredVersion is a wrapper around gdk_gl_context_set_required_version().
|
||||
func (v *GLContext) SetRequiredVersion(major, minor int) {
|
||||
C.gdk_gl_context_set_required_version(v.native(), (C.int)(major), (C.int)(minor))
|
||||
}
|
||||
|
||||
// GetDebugEnabled is a wrapper around gdk_gl_context_get_debug_enabled().
|
||||
func (v *GLContext) GetDebugEnabled() bool {
|
||||
return gobool(C.gdk_gl_context_get_debug_enabled(v.native()))
|
||||
}
|
||||
|
||||
// SetDebugEnabled is a wrapper around gdk_gl_context_set_debug_enabled().
|
||||
func (v *GLContext) SetDebugEnabled(enabled bool) {
|
||||
C.gdk_gl_context_set_debug_enabled(v.native(), gbool(enabled))
|
||||
}
|
||||
|
||||
// GetForwardCompatible is a wrapper around gdk_gl_context_get_forward_compatible().
|
||||
func (v *GLContext) GetForwardCompatible() bool {
|
||||
return gobool(C.gdk_gl_context_get_forward_compatible(v.native()))
|
||||
}
|
||||
|
||||
// SetForwardCompatible is a wrapper around gdk_gl_context_set_forward_compatible().
|
||||
func (v *GLContext) SetForwardCompatible(compatible bool) {
|
||||
C.gdk_gl_context_set_forward_compatible(v.native(), gbool(compatible))
|
||||
}
|
||||
|
||||
// Realize is a wrapper around gdk_gl_context_realize().
|
||||
func (v *GLContext) Realize() (bool, error) {
|
||||
var err *C.GError
|
||||
r := gobool(C.gdk_gl_context_realize(v.native(), &err))
|
||||
if !r {
|
||||
defer C.g_error_free(err)
|
||||
return r, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// MakeCurrent is a wrapper around gdk_gl_context_make_current().
|
||||
func (v *GLContext) MakeCurrent() {
|
||||
C.gdk_gl_context_make_current(v.native())
|
||||
}
|
||||
|
||||
// GetCurrent is a wrapper around gdk_gl_context_get_current().
|
||||
func GetCurrent() (*GLContext, error) {
|
||||
c := C.gdk_gl_context_get_current()
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &GLContext{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// ClearCurrent is a wrapper around gdk_gl_context_clear_current().
|
||||
func ClearCurrent() {
|
||||
C.gdk_gl_context_clear_current()
|
||||
}
|
||||
22
third_party/gotk3/gdk/gdk_since_3_16.go.h
vendored
Normal file
22
third_party/gotk3/gdk/gdk_since_3_16.go.h
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// Type Casting
|
||||
static GdkGLContext *toGdkGLContext(void *p) { return (GDK_GL_CONTEXT(p)); }
|
||||
32
third_party/gotk3/gdk/gdk_since_3_18.go
vendored
Normal file
32
third_party/gotk3/gdk/gdk_since_3_18.go
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16
|
||||
// Supports building with gtk 3.18+
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
import "C"
|
||||
|
||||
/*
|
||||
* GdkKeymap
|
||||
*/
|
||||
|
||||
// GetScrollLockState is a wrapper around gdk_keymap_get_scroll_lock_state().
|
||||
func (v *Keymap) GetScrollLockState() bool {
|
||||
return gobool(C.gdk_keymap_get_scroll_lock_state(v.native()))
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkWindow
|
||||
*/
|
||||
|
||||
// SetPassThrough is a wrapper around gdk_window_set_pass_through().
|
||||
func (v *Window) SetPassThrough(passThrough bool) {
|
||||
C.gdk_window_set_pass_through(v.native(), gbool(passThrough))
|
||||
}
|
||||
|
||||
// GetPassThrough is a wrapper around gdk_window_get_pass_through().
|
||||
func (v *Window) GetPassThrough() bool {
|
||||
return gobool(C.gdk_window_get_pass_through(v.native()))
|
||||
}
|
||||
89
third_party/gotk3/gdk/gdk_since_3_20.go
vendored
Normal file
89
third_party/gotk3/gdk/gdk_since_3_20.go
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
// +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18
|
||||
// Supports building with gtk 3.20+
|
||||
|
||||
package gdk
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk_since_3_20.go.h"
|
||||
import "C"
|
||||
|
||||
/*
|
||||
* GdkGLContext
|
||||
*/
|
||||
|
||||
// IsLegacy is a wrapper around gdk_gl_context_is_legacy().
|
||||
func (v *GLContext) IsLegacy() bool {
|
||||
return gobool(C.gdk_gl_context_is_legacy(v.native()))
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkDisplay
|
||||
*/
|
||||
|
||||
func (v *Display) GetDefaultSeat() (*Seat, error) {
|
||||
return toSeat(C.gdk_display_get_default_seat(v.native()))
|
||||
}
|
||||
|
||||
// gdk_display_list_seats().
|
||||
|
||||
/*
|
||||
* GdkDevice
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// gdk_device_get_axes().
|
||||
// gdk_device_get_seat().
|
||||
|
||||
/*
|
||||
* GdkSeat
|
||||
*/
|
||||
|
||||
type Seat struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
func (v *Seat) native() *C.GdkSeat {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkSeat(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkCursor.
|
||||
func (v *Seat) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalSeat(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
return &Seat{obj}, nil
|
||||
}
|
||||
|
||||
func toSeat(s *C.GdkSeat) (*Seat, error) {
|
||||
if s == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
|
||||
return &Seat{obj}, nil
|
||||
}
|
||||
|
||||
func (v *Seat) GetPointer() (*Device, error) {
|
||||
return toDevice(C.gdk_seat_get_pointer(v.native()))
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkRectangle
|
||||
*/
|
||||
|
||||
// RectangleEqual is a wrapper around gdk_rectangle_equal().
|
||||
func (v *Rectangle) RectangleEqual(rect *Rectangle) bool {
|
||||
return gobool(C.gdk_rectangle_equal(v.native(), rect.native()))
|
||||
}
|
||||
21
third_party/gotk3/gdk/gdk_since_3_20.go.h
vendored
Normal file
21
third_party/gotk3/gdk/gdk_since_3_20.go.h
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//#include <stdlib.h>
|
||||
|
||||
static GdkSeat *toGdkSeat(void *p) { return ((GdkSeat *)p); }
|
||||
22
third_party/gotk3/gdk/gdk_since_3_22.go.h
vendored
Normal file
22
third_party/gotk3/gdk/gdk_since_3_22.go.h
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//#include <stdlib.h>
|
||||
|
||||
// Type Casting
|
||||
static GdkMonitor *toGdkMonitor(void *p) { return (GDK_MONITOR(p)); }
|
||||
231
third_party/gotk3/gdk/gdk_since_3_8.go
vendored
Normal file
231
third_party/gotk3/gdk/gdk_since_3_8.go
vendored
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
// +build !gtk_3_6
|
||||
// Supports building with gtk 3.8+
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk_since_3_8.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
tm := []glib.TypeMarshaler{
|
||||
// Enums
|
||||
{glib.Type(C.gdk_frame_clock_phase_get_type()), marshalClockPhase},
|
||||
|
||||
// Objects/Interfaces
|
||||
{glib.Type(C.gdk_frame_clock_get_type()), marshalFrameClock},
|
||||
{glib.Type(C.gdk_frame_timings_get_type()), marshalFrameTimings},
|
||||
}
|
||||
|
||||
glib.RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
// ClockPhase is a representation of GDK's GdkFrameClockPhase.
|
||||
type ClockPhase int
|
||||
|
||||
const (
|
||||
PHASE_NONE ClockPhase = C.GDK_FRAME_CLOCK_PHASE_NONE
|
||||
PHASE_FLUSH_EVENTS ClockPhase = C.GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS
|
||||
PHASE_BEFORE_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_BEFORE_PAINT
|
||||
PHASE_UPDATE ClockPhase = C.GDK_FRAME_CLOCK_PHASE_UPDATE
|
||||
PHASE_LAYOUT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_LAYOUT
|
||||
PHASE_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_PAINT
|
||||
PHASE_RESUME_EVENTS ClockPhase = C.GDK_FRAME_CLOCK_PHASE_RESUME_EVENTS
|
||||
PHASE_AFTER_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_AFTER_PAINT
|
||||
)
|
||||
|
||||
func marshalClockPhase(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return ClockPhase(c), nil
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkFrameClock
|
||||
*/
|
||||
|
||||
// FrameClock is a representation of GDK's GdkFrameClock.
|
||||
type FrameClock struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkFrameClock.
|
||||
func (v *FrameClock) native() *C.GdkFrameClock {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkFrameClock(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkFrameClock.
|
||||
func (v *FrameClock) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalFrameClock(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return WrapFrameClock(unsafe.Pointer(c)), nil
|
||||
}
|
||||
|
||||
func WrapFrameClock(ptr unsafe.Pointer) *FrameClock {
|
||||
obj := &glib.Object{glib.ToGObject(ptr)}
|
||||
return &FrameClock{obj}
|
||||
}
|
||||
|
||||
// BeginUpdating is a wrapper around gdk_frame_clock_begin_updating().
|
||||
func (v *FrameClock) BeginUpdating() {
|
||||
C.gdk_frame_clock_begin_updating(v.native())
|
||||
}
|
||||
|
||||
// EndUpdating is a wrapper around gdk_frame_clock_end_updating().
|
||||
func (v *FrameClock) EndUpdating() {
|
||||
C.gdk_frame_clock_end_updating(v.native())
|
||||
}
|
||||
|
||||
// GetFrameTime is a wrapper around gdk_frame_clock_get_frame_time().
|
||||
func (v *FrameClock) GetFrameTime() int64 {
|
||||
return int64(C.gdk_frame_clock_get_frame_time(v.native()))
|
||||
}
|
||||
|
||||
// GetFrameCounter is a wrapper around gdk_frame_clock_get_frame_counter().
|
||||
func (v *FrameClock) GetFrameCounter() int64 {
|
||||
return int64(C.gdk_frame_clock_get_frame_counter(v.native()))
|
||||
}
|
||||
|
||||
// GetHistoryStart is a wrapper around gdk_frame_clock_get_history_start().
|
||||
func (v *FrameClock) GetHistoryStart() int64 {
|
||||
return int64(C.gdk_frame_clock_get_history_start(v.native()))
|
||||
}
|
||||
|
||||
// GetTimings is a wrapper around gdk_frame_clock_get_timings().
|
||||
func (v *FrameClock) GetTimings(frameCounter int64) (*FrameTimings, error) {
|
||||
c := C.gdk_frame_clock_get_timings(v.native(), C.gint64(frameCounter))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return wrapFrameTimings(unsafe.Pointer(c)), nil
|
||||
}
|
||||
|
||||
// GetCurrentTimings is a wrapper around dk_frame_clock_get_current_timings().
|
||||
func (v *FrameClock) GetCurrentTimings() (*FrameTimings, error) {
|
||||
c := C.gdk_frame_clock_get_current_timings(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return wrapFrameTimings(unsafe.Pointer(c)), nil
|
||||
}
|
||||
|
||||
// GetRefreshInfo is a wrapper around gdk_frame_clock_get_refresh_info().
|
||||
func (v *FrameClock) GetRefreshInfo(baseTime int64) (int64, int64) {
|
||||
var cr, cp (*C.gint64)
|
||||
defer C.free(unsafe.Pointer(cr))
|
||||
defer C.free(unsafe.Pointer(cp))
|
||||
b := C.gint64(baseTime)
|
||||
|
||||
C.gdk_frame_clock_get_refresh_info(v.native(), b, cr, cp)
|
||||
r, p := int64(*cr), int64(*cp)
|
||||
return r, p
|
||||
}
|
||||
|
||||
// RequestPhase is a wrapper around gdk_frame_clock_request_phase().
|
||||
func (v *FrameClock) RequestPhase(phase ClockPhase) {
|
||||
C.gdk_frame_clock_request_phase(v.native(), C.GdkFrameClockPhase(phase))
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkFrameTimings
|
||||
*/
|
||||
|
||||
// FrameTimings is a representation of GDK's GdkFrameTimings.
|
||||
type FrameTimings struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkFrameTimings.
|
||||
func (v *FrameTimings) native() *C.GdkFrameTimings {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkFrameTimings(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkFrameTimings.
|
||||
func (v *FrameTimings) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func wrapFrameTimings(ptr unsafe.Pointer) *FrameTimings {
|
||||
obj := &glib.Object{glib.ToGObject(ptr)}
|
||||
return &FrameTimings{obj}
|
||||
}
|
||||
|
||||
func marshalFrameTimings(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapFrameTimings(unsafe.Pointer(c)), nil
|
||||
}
|
||||
|
||||
// Ref is a wrapper around gdk_frame_timings_ref().
|
||||
func (v *FrameTimings) Ref() {
|
||||
c := C.gdk_frame_timings_ref(v.native())
|
||||
v = wrapFrameTimings(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
// Unref is a wrapper around gdk_frame_timings_unref().
|
||||
func (v *FrameTimings) Unref() {
|
||||
C.gdk_frame_timings_unref(v.native())
|
||||
}
|
||||
|
||||
// GetFrameCounter is a wrapper around gdk_frame_timings_get_frame_counter().
|
||||
func (v *FrameTimings) GetFrameCounter() int64 {
|
||||
return int64(C.gdk_frame_timings_get_frame_counter(v.native()))
|
||||
}
|
||||
|
||||
// GetComplete is a wrapper around gdk_frame_timings_get_complete().
|
||||
func (v *FrameTimings) GetComplete() bool {
|
||||
return gobool(C.gdk_frame_timings_get_complete(v.native()))
|
||||
}
|
||||
|
||||
// GetFrameTime is a wrapper around gdk_frame_timings_get_frame_time().
|
||||
func (v *FrameTimings) GetFrameTime() int64 {
|
||||
return int64(C.gdk_frame_timings_get_frame_time(v.native()))
|
||||
}
|
||||
|
||||
// GetPresentationTime is a wrapper around gdk_frame_timings_get_presentation_time().
|
||||
func (v *FrameTimings) GetPresentationTime() int64 {
|
||||
return int64(C.gdk_frame_timings_get_presentation_time(v.native()))
|
||||
}
|
||||
|
||||
// GetRefreshInterval is a wrapper around gdk_frame_timings_get_refresh_interval().
|
||||
func (v *FrameTimings) GetRefreshInterval() int64 {
|
||||
return int64(C.gdk_frame_timings_get_refresh_interval(v.native()))
|
||||
}
|
||||
|
||||
// GetPredictedPresentationTime is a wrapper around gdk_frame_timings_get_predicted_presentation_time().
|
||||
func (v *FrameTimings) GetPredictedPresentationTime() int64 {
|
||||
return int64(C.gdk_frame_timings_get_predicted_presentation_time(v.native()))
|
||||
}
|
||||
26
third_party/gotk3/gdk/gdk_since_3_8.go.h
vendored
Normal file
26
third_party/gotk3/gdk/gdk_since_3_8.go.h
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// Type Casting
|
||||
static GdkFrameClock *toGdkFrameClock(void *p) { return (GDK_FRAME_CLOCK(p)); }
|
||||
|
||||
static GdkFrameTimings *toGdkFrameTimings(void *p) {
|
||||
return ((GdkFrameTimings *)p);
|
||||
}
|
||||
2278
third_party/gotk3/gdk/keys.go
vendored
Normal file
2278
third_party/gotk3/gdk/keys.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
668
third_party/gotk3/gdk/pixbuf.go
vendored
Normal file
668
third_party/gotk3/gdk/pixbuf.go
vendored
Normal file
|
|
@ -0,0 +1,668 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
func init() {
|
||||
tm := []glib.TypeMarshaler{
|
||||
// Enums
|
||||
{glib.Type(C.gdk_pixbuf_alpha_mode_get_type()), marshalPixbufAlphaMode},
|
||||
|
||||
// Objects/Interfaces
|
||||
{glib.Type(C.gdk_pixbuf_get_type()), marshalPixbuf},
|
||||
{glib.Type(C.gdk_pixbuf_animation_get_type()), marshalPixbufAnimation},
|
||||
{glib.Type(C.gdk_pixbuf_loader_get_type()), marshalPixbufLoader},
|
||||
}
|
||||
glib.RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// GdkPixbufError
|
||||
|
||||
// PixbufRotation is a representation of GDK's GdkPixbufRotation.
|
||||
type PixbufRotation int
|
||||
|
||||
const (
|
||||
PIXBUF_ROTATE_NONE PixbufRotation = C.GDK_PIXBUF_ROTATE_NONE
|
||||
PIXBUF_ROTATE_COUNTERCLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
|
||||
PIXBUF_ROTATE_UPSIDEDOWN PixbufRotation = C.GDK_PIXBUF_ROTATE_UPSIDEDOWN
|
||||
PIXBUF_ROTATE_CLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_CLOCKWISE
|
||||
)
|
||||
|
||||
// PixbufAlphaMode is a representation of GDK's GdkPixbufAlphaMode.
|
||||
type PixbufAlphaMode int
|
||||
|
||||
const (
|
||||
GDK_PIXBUF_ALPHA_BILEVEL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_BILEVEL
|
||||
GDK_PIXBUF_ALPHA_FULL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_FULL
|
||||
)
|
||||
|
||||
func marshalPixbufAlphaMode(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
|
||||
return PixbufAlphaMode(c), nil
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkPixbuf
|
||||
*/
|
||||
|
||||
// PixbufGetType is a wrapper around gdk_pixbuf_get_type().
|
||||
func PixbufGetType() glib.Type {
|
||||
return glib.Type(C.gdk_pixbuf_get_type())
|
||||
}
|
||||
|
||||
// Pixbuf is a representation of GDK's GdkPixbuf.
|
||||
type Pixbuf struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkPixbuf.
|
||||
func (v *Pixbuf) native() *C.GdkPixbuf {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkPixbuf(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkPixbuf.
|
||||
func (v *Pixbuf) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func (v *Pixbuf) NativePrivate() *C.GdkPixbuf {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkPixbuf(p)
|
||||
}
|
||||
|
||||
func marshalPixbuf(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
return &Pixbuf{obj}, nil
|
||||
}
|
||||
|
||||
// PixbufNew is a wrapper around gdk_pixbuf_new().
|
||||
func PixbufNew(colorspace Colorspace, hasAlpha bool, bitsPerSample, width, height int) (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_new(C.GdkColorspace(colorspace), gbool(hasAlpha),
|
||||
C.int(bitsPerSample), C.int(width), C.int(height))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// File Loading
|
||||
|
||||
// PixbufNewFromFile is a wrapper around gdk_pixbuf_new_from_file().
|
||||
func PixbufNewFromFile(filename string) (*Pixbuf, error) {
|
||||
cstr := C.CString(filename)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
var err *C.GError
|
||||
c := C.gdk_pixbuf_new_from_file((*C.char)(cstr), &err)
|
||||
if c == nil {
|
||||
defer C.g_error_free(err)
|
||||
return nil, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Image Data in Memory
|
||||
|
||||
// PixbufNewFromData is a wrapper around gdk_pixbuf_new_from_data().
|
||||
func PixbufNewFromData(pixbufData []byte, cs Colorspace, hasAlpha bool, bitsPerSample, width, height, rowStride int) (*Pixbuf, error) {
|
||||
arrayPtr := (*C.guchar)(unsafe.Pointer(&pixbufData[0]))
|
||||
|
||||
c := C.gdk_pixbuf_new_from_data(
|
||||
arrayPtr,
|
||||
C.GdkColorspace(cs),
|
||||
gbool(hasAlpha),
|
||||
C.int(bitsPerSample),
|
||||
C.int(width),
|
||||
C.int(height),
|
||||
C.int(rowStride),
|
||||
nil, // TODO: missing support for GdkPixbufDestroyNotify
|
||||
nil,
|
||||
)
|
||||
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// PixbufNewFromDataOnly is a convenient alternative to PixbufNewFromData() and also a wrapper around gdk_pixbuf_new_from_data().
|
||||
func PixbufNewFromDataOnly(pixbufData []byte) (*Pixbuf, error) {
|
||||
pixbufLoader, err := PixbufLoaderNew()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pixbufLoader.WriteAndReturnPixbuf(pixbufData)
|
||||
}
|
||||
|
||||
// PixbufNewFromResource is a wrapper around gdk_pixbuf_new_from_resource()
|
||||
func PixbufNewFromResource(resourcePath string) (*Pixbuf, error) {
|
||||
var gerr *C.GError
|
||||
|
||||
cstr := C.CString(resourcePath)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
c := C.gdk_pixbuf_new_from_resource((*C.gchar)(cstr), &gerr)
|
||||
|
||||
if gerr != nil {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, errors.New(C.GoString(gerr.message))
|
||||
}
|
||||
|
||||
obj := glib.Take(unsafe.Pointer(c))
|
||||
return &Pixbuf{obj}, nil
|
||||
}
|
||||
|
||||
// PixbufNewFromResourceAtScale is a wrapper around gdk_pixbuf_new_from_resource_at_scale()
|
||||
func PixbufNewFromResourceAtScale(resourcePath string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
|
||||
var gerr *C.GError
|
||||
|
||||
cstr := C.CString(resourcePath)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
cPreserveAspectRatio := gbool(preserveAspectRatio)
|
||||
|
||||
c := C.gdk_pixbuf_new_from_resource_at_scale(
|
||||
(*C.gchar)(cstr),
|
||||
C.gint(width),
|
||||
C.gint(height),
|
||||
C.gboolean(cPreserveAspectRatio),
|
||||
&gerr,
|
||||
)
|
||||
|
||||
if gerr != nil {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, errors.New(C.GoString(gerr.message))
|
||||
}
|
||||
|
||||
obj := glib.Take(unsafe.Pointer(c))
|
||||
return &Pixbuf{obj}, nil
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_new_from_xpm_data().
|
||||
// gdk_pixbuf_new_subpixbuf()
|
||||
|
||||
// PixbufCopy is a wrapper around gdk_pixbuf_copy().
|
||||
func PixbufCopy(v *Pixbuf) (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_copy(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// The GdkPixbuf Structure
|
||||
|
||||
// GetColorspace is a wrapper around gdk_pixbuf_get_colorspace().
|
||||
func (v *Pixbuf) GetColorspace() Colorspace {
|
||||
c := C.gdk_pixbuf_get_colorspace(v.native())
|
||||
return Colorspace(c)
|
||||
}
|
||||
|
||||
// GetNChannels is a wrapper around gdk_pixbuf_get_n_channels().
|
||||
func (v *Pixbuf) GetNChannels() int {
|
||||
c := C.gdk_pixbuf_get_n_channels(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetHasAlpha is a wrapper around gdk_pixbuf_get_has_alpha().
|
||||
func (v *Pixbuf) GetHasAlpha() bool {
|
||||
c := C.gdk_pixbuf_get_has_alpha(v.native())
|
||||
return gobool(c)
|
||||
}
|
||||
|
||||
// GetBitsPerSample is a wrapper around gdk_pixbuf_get_bits_per_sample().
|
||||
func (v *Pixbuf) GetBitsPerSample() int {
|
||||
c := C.gdk_pixbuf_get_bits_per_sample(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetPixels is a wrapper around gdk_pixbuf_get_pixels_with_length().
|
||||
// A Go slice is used to represent the underlying Pixbuf data array, one
|
||||
// byte per channel.
|
||||
func (v *Pixbuf) GetPixels() (channels []byte) {
|
||||
var length C.guint
|
||||
c := C.gdk_pixbuf_get_pixels_with_length(v.native(), &length)
|
||||
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&channels))
|
||||
sliceHeader.Data = uintptr(unsafe.Pointer(c))
|
||||
sliceHeader.Len = int(length)
|
||||
sliceHeader.Cap = int(length)
|
||||
|
||||
// To make sure the slice doesn't outlive the Pixbuf, add a reference
|
||||
v.Ref()
|
||||
runtime.SetFinalizer(&channels, func(_ *[]byte) {
|
||||
glib.FinalizerStrategy(v.Unref)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// GetWidth is a wrapper around gdk_pixbuf_get_width().
|
||||
func (v *Pixbuf) GetWidth() int {
|
||||
c := C.gdk_pixbuf_get_width(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetHeight is a wrapper around gdk_pixbuf_get_height().
|
||||
func (v *Pixbuf) GetHeight() int {
|
||||
c := C.gdk_pixbuf_get_height(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetRowstride is a wrapper around gdk_pixbuf_get_rowstride().
|
||||
func (v *Pixbuf) GetRowstride() int {
|
||||
c := C.gdk_pixbuf_get_rowstride(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// GetOption is a wrapper around gdk_pixbuf_get_option(). ok is true if
|
||||
// the key has an associated value.
|
||||
func (v *Pixbuf) GetOption(key string) (value string, ok bool) {
|
||||
cstr := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
c := C.gdk_pixbuf_get_option(v.native(), (*C.gchar)(cstr))
|
||||
if c == nil {
|
||||
return "", false
|
||||
}
|
||||
return C.GoString((*C.char)(c)), true
|
||||
}
|
||||
|
||||
// Scaling
|
||||
|
||||
// ScaleSimple is a wrapper around gdk_pixbuf_scale_simple().
|
||||
func (v *Pixbuf) ScaleSimple(destWidth, destHeight int, interpType InterpType) (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_scale_simple(v.native(), C.int(destWidth),
|
||||
C.int(destHeight), C.GdkInterpType(interpType))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Scale is a wrapper around gdk_pixbuf_scale().
|
||||
func (v *Pixbuf) Scale(dest *Pixbuf, destX, destY, destWidth, destHeight int, offsetX, offsetY, scaleX, scaleY float64, interpType InterpType) {
|
||||
C.gdk_pixbuf_scale(
|
||||
v.native(),
|
||||
dest.native(),
|
||||
C.int(destX),
|
||||
C.int(destY),
|
||||
C.int(destWidth),
|
||||
C.int(destHeight),
|
||||
C.double(offsetX),
|
||||
C.double(offsetY),
|
||||
C.double(scaleX),
|
||||
C.double(scaleY),
|
||||
C.GdkInterpType(interpType),
|
||||
)
|
||||
}
|
||||
|
||||
// Composite is a wrapper around gdk_pixbuf_composite().
|
||||
func (v *Pixbuf) Composite(dest *Pixbuf, destX, destY, destWidth, destHeight int, offsetX, offsetY, scaleX, scaleY float64, interpType InterpType, overallAlpha int) {
|
||||
C.gdk_pixbuf_composite(
|
||||
v.native(),
|
||||
dest.native(),
|
||||
C.int(destX),
|
||||
C.int(destY),
|
||||
C.int(destWidth),
|
||||
C.int(destHeight),
|
||||
C.double(offsetX),
|
||||
C.double(offsetY),
|
||||
C.double(scaleX),
|
||||
C.double(scaleY),
|
||||
C.GdkInterpType(interpType),
|
||||
C.int(overallAlpha),
|
||||
)
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_composite_color_simple().
|
||||
// gdk_pixbuf_composite_color().
|
||||
|
||||
// Utilities
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_copy_area().
|
||||
// gdk_pixbuf_saturate_and_pixelate().
|
||||
|
||||
// Fill is a wrapper around gdk_pixbuf_fill(). The given pixel is an RGBA value.
|
||||
func (v *Pixbuf) Fill(pixel uint32) {
|
||||
C.gdk_pixbuf_fill(v.native(), C.guint32(pixel))
|
||||
}
|
||||
|
||||
// AddAlpha is a wrapper around gdk_pixbuf_add_alpha(). If substituteColor is
|
||||
// true, then the color specified by r, g and b will be assigned zero opacity.
|
||||
func (v *Pixbuf) AddAlpha(substituteColor bool, r, g, b uint8) *Pixbuf {
|
||||
c := C.gdk_pixbuf_add_alpha(v.native(), gbool(substituteColor), C.guchar(r), C.guchar(g), C.guchar(b))
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// File saving
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_savev().
|
||||
// gdk_pixbuf_save().
|
||||
|
||||
// SaveJPEG is a convenience wrapper around gdk_pixbuf_save() for saving image as jpeg file.
|
||||
// Quality is a number between 0...100
|
||||
func (v *Pixbuf) SaveJPEG(path string, quality int) error {
|
||||
cpath := C.CString(path)
|
||||
cquality := C.CString(strconv.Itoa(quality))
|
||||
defer C.free(unsafe.Pointer(cpath))
|
||||
defer C.free(unsafe.Pointer(cquality))
|
||||
|
||||
var err *C.GError
|
||||
c := C._gdk_pixbuf_save_jpeg(v.native(), cpath, &err, cquality)
|
||||
if !gobool(c) {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SavePNG is a convenience wrapper around gdk_pixbuf_save() for saving image as png file.
|
||||
// Compression is a number between 0...9
|
||||
func (v *Pixbuf) SavePNG(path string, compression int) error {
|
||||
cpath := C.CString(path)
|
||||
ccompression := C.CString(strconv.Itoa(compression))
|
||||
defer C.free(unsafe.Pointer(cpath))
|
||||
defer C.free(unsafe.Pointer(ccompression))
|
||||
|
||||
var err *C.GError
|
||||
c := C._gdk_pixbuf_save_png(v.native(), cpath, &err, ccompression)
|
||||
if !gobool(c) {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
* PixbufFormat
|
||||
*/
|
||||
|
||||
type PixbufFormat struct {
|
||||
format *C.GdkPixbufFormat
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkPixbuf.
|
||||
func (v *PixbufFormat) native() *C.GdkPixbufFormat {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return v.format
|
||||
}
|
||||
|
||||
func wrapPixbufFormat(obj *C.GdkPixbufFormat) *PixbufFormat {
|
||||
return &PixbufFormat{obj}
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkPixbuf.
|
||||
func (v *PixbufFormat) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
/*
|
||||
* GdkPixbufAnimation
|
||||
*/
|
||||
|
||||
// PixbufAnimation is a representation of GDK's GdkPixbufAnimation.
|
||||
type PixbufAnimation struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkPixbufAnimation.
|
||||
func (v *PixbufAnimation) native() *C.GdkPixbufAnimation {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkPixbufAnimation(p)
|
||||
}
|
||||
|
||||
func (v *PixbufAnimation) NativePrivate() *C.GdkPixbufAnimation {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkPixbufAnimation(p)
|
||||
}
|
||||
|
||||
func (v *PixbufAnimation) GetStaticImage() *Pixbuf {
|
||||
c := C.gdk_pixbuf_animation_get_static_image(v.native())
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
|
||||
// Add a reference so the pixbuf doesn't outlive the parent pixbuf
|
||||
// animation.
|
||||
v.Ref()
|
||||
runtime.SetFinalizer(p, func(*Pixbuf) { glib.FinalizerStrategy(v.Unref) })
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func marshalPixbufAnimation(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
return &PixbufAnimation{obj}, nil
|
||||
}
|
||||
|
||||
// PixbufAnimationNewFromFile is a wrapper around gdk_pixbuf_animation_new_from_file().
|
||||
func PixbufAnimationNewFromFile(filename string) (*PixbufAnimation, error) {
|
||||
cstr := C.CString(filename)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
var err *C.GError
|
||||
c := C.gdk_pixbuf_animation_new_from_file((*C.char)(cstr), &err)
|
||||
if c == nil {
|
||||
defer C.g_error_free(err)
|
||||
return nil, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &PixbufAnimation{obj}
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_animation_new_from_resource().
|
||||
|
||||
/*
|
||||
* GdkPixbufLoader
|
||||
*/
|
||||
|
||||
// PixbufLoader is a representation of GDK's GdkPixbufLoader.
|
||||
// Users of PixbufLoader are expected to call Close() when they are finished.
|
||||
type PixbufLoader struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native() returns a pointer to the underlying GdkPixbufLoader.
|
||||
func (v *PixbufLoader) native() *C.GdkPixbufLoader {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkPixbufLoader(p)
|
||||
}
|
||||
|
||||
func marshalPixbufLoader(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
return &PixbufLoader{obj}, nil
|
||||
}
|
||||
|
||||
// PixbufLoaderNew() is a wrapper around gdk_pixbuf_loader_new().
|
||||
func PixbufLoaderNew() (*PixbufLoader, error) {
|
||||
c := C.gdk_pixbuf_loader_new()
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return &PixbufLoader{glib.AssumeOwnership(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// PixbufLoaderNewWithType() is a wrapper around gdk_pixbuf_loader_new_with_type().
|
||||
func PixbufLoaderNewWithType(t string) (*PixbufLoader, error) {
|
||||
var err *C.GError
|
||||
|
||||
cstr := C.CString(t)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
c := C.gdk_pixbuf_loader_new_with_type((*C.char)(cstr), &err)
|
||||
if err != nil {
|
||||
defer C.g_error_free(err)
|
||||
return nil, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &PixbufLoader{glib.AssumeOwnership(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// Write() is a wrapper around gdk_pixbuf_loader_write(). The
|
||||
// function signature differs from the C equivalent to satisify the
|
||||
// io.Writer interface.
|
||||
func (v *PixbufLoader) Write(data []byte) (int, error) {
|
||||
// n is set to 0 on error, and set to len(data) otherwise.
|
||||
// This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
|
||||
// which would allow access to all io and ioutil goodies,
|
||||
// and play along nice with go environment.
|
||||
|
||||
if len(data) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var err *C.GError
|
||||
c := C.gdk_pixbuf_loader_write(v.native(),
|
||||
(*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)),
|
||||
&err)
|
||||
|
||||
if !gobool(c) {
|
||||
defer C.g_error_free(err)
|
||||
return 0, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
// Convenient function like above for Pixbuf. Write data, close loader and return Pixbuf.
|
||||
func (v *PixbufLoader) WriteAndReturnPixbuf(data []byte) (*Pixbuf, error) {
|
||||
_, err := v.Write(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := v.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return v.GetPixbuf()
|
||||
}
|
||||
|
||||
// Close is a wrapper around gdk_pixbuf_loader_close(). An error is
|
||||
// returned instead of a bool like the native C function to support the
|
||||
// io.Closer interface.
|
||||
func (v *PixbufLoader) Close() error {
|
||||
var err *C.GError
|
||||
|
||||
if ok := gobool(C.gdk_pixbuf_loader_close(v.native(), &err)); !ok {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPixbuf is a wrapper around gdk_pixbuf_loader_get_pixbuf().
|
||||
func (v *PixbufLoader) GetPixbuf() (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_loader_get_pixbuf(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Pixbuf{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// GetAnimation is a wrapper around gdk_pixbuf_loader_get_animation().
|
||||
func (v *PixbufLoader) GetAnimation() (*PixbufAnimation, error) {
|
||||
c := C.gdk_pixbuf_loader_get_animation(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &PixbufAnimation{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// Convenient function like above for Pixbuf. Write data, close loader and return PixbufAnimation.
|
||||
func (v *PixbufLoader) WriteAndReturnPixbufAnimation(data []byte) (*PixbufAnimation, error) {
|
||||
_, err := v.Write(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := v.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return v.GetAnimation()
|
||||
}
|
||||
26
third_party/gotk3/gdk/pixbuf.go.h
vendored
Normal file
26
third_party/gotk3/gdk/pixbuf.go.h
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static GdkPixbuf *toGdkPixbuf(void *p) { return (GDK_PIXBUF(p)); }
|
||||
|
||||
static GdkPixbufAnimation *toGdkPixbufAnimation(void *p) {
|
||||
return (GDK_PIXBUF_ANIMATION(p));
|
||||
}
|
||||
static gboolean
|
||||
|
||||
_gdk_pixbuf_save_png(GdkPixbuf *pixbuf, const char *filename, GError **err,
|
||||
const char *compression) {
|
||||
return gdk_pixbuf_save(pixbuf, filename, "png", err, "compression",
|
||||
compression, NULL);
|
||||
}
|
||||
|
||||
static gboolean _gdk_pixbuf_save_jpeg(GdkPixbuf *pixbuf, const char *filename,
|
||||
GError **err, const char *quality) {
|
||||
return gdk_pixbuf_save(pixbuf, filename, "jpeg", err, "quality", quality,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GdkPixbufLoader *toGdkPixbufLoader(void *p) {
|
||||
return (GDK_PIXBUF_LOADER(p));
|
||||
}
|
||||
16
third_party/gotk3/gdk/pixbuf_deprecated_since_2_32.go
vendored
Normal file
16
third_party/gotk3/gdk/pixbuf_deprecated_since_2_32.go
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
//+build gdk_pixbuf_2_2 gdk_pixbuf_2_4 gdk_pixbuf_2_6 gdk_pixbuf_2_8 gdk_pixbuf_2_12 gdk_pixbuf_2_14 gdk_pixbuf_2_24 gdk_pixbuf_2_26 gdk_pixbuf_2_28 gdk_pixbuf_2_30 gdk_pixbuf_deprecated
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
|
||||
// Image Data in Memory
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_new_from_inline().
|
||||
33
third_party/gotk3/gdk/pixbuf_since_2_12.go
vendored
Normal file
33
third_party/gotk3/gdk/pixbuf_since_2_12.go
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// Utilities
|
||||
|
||||
// ApplyEmbeddedOrientation is a wrapper around gdk_pixbuf_apply_embedded_orientation().
|
||||
func (v *Pixbuf) ApplyEmbeddedOrientation() (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_apply_embedded_orientation(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
23
third_party/gotk3/gdk/pixbuf_since_2_14.go
vendored
Normal file
23
third_party/gotk3/gdk/pixbuf_since_2_14.go
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
|
||||
// File Loading
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_new_from_stream().
|
||||
// gdk_pixbuf_new_from_stream_async().
|
||||
// gdk_pixbuf_new_from_stream_at_scale().
|
||||
|
||||
// File saving
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_save_to_stream().
|
||||
100
third_party/gotk3/gdk/pixbuf_since_2_2.go
vendored
Normal file
100
third_party/gotk3/gdk/pixbuf_since_2_2.go
vendored
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// The GdkPixbuf Structure
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_set_option().
|
||||
|
||||
/*
|
||||
* GdkPixbufLoader
|
||||
*/
|
||||
|
||||
// SetSize is a wrapper around gdk_pixbuf_loader_set_size().
|
||||
func (v *PixbufLoader) SetSize(width, height int) {
|
||||
C.gdk_pixbuf_loader_set_size(v.native(), C.int(width), C.int(height))
|
||||
}
|
||||
|
||||
/*
|
||||
* PixbufFormat
|
||||
*/
|
||||
|
||||
// PixbufGetFormats is a wrapper around gdk_pixbuf_get_formats().
|
||||
func PixbufGetFormats() []*PixbufFormat {
|
||||
l := (*C.struct__GSList)(C.gdk_pixbuf_get_formats())
|
||||
formats := glib.WrapSList(uintptr(unsafe.Pointer(l)))
|
||||
if formats == nil {
|
||||
return nil // no error. A nil list is considered to be empty.
|
||||
}
|
||||
|
||||
// "The structures themselves are owned by GdkPixbuf". Free the list only.
|
||||
defer formats.Free()
|
||||
|
||||
ret := make([]*PixbufFormat, 0, formats.Length())
|
||||
formats.Foreach(func(item interface{}) {
|
||||
ret = append(
|
||||
ret,
|
||||
&PixbufFormat{
|
||||
(*C.GdkPixbufFormat)(item.(unsafe.Pointer))})
|
||||
})
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetName is a wrapper around gdk_pixbuf_format_get_name().
|
||||
func (f *PixbufFormat) GetName() (string, error) {
|
||||
c := C.gdk_pixbuf_format_get_name(f.native())
|
||||
return C.GoString((*C.char)(c)), nil
|
||||
}
|
||||
|
||||
// GetDescription is a wrapper around gdk_pixbuf_format_get_description().
|
||||
func (f *PixbufFormat) GetDescription() (string, error) {
|
||||
c := C.gdk_pixbuf_format_get_description(f.native())
|
||||
return C.GoString((*C.char)(c)), nil
|
||||
}
|
||||
|
||||
// GetMimeTypes is a wrapper around gdk_pixbuf_format_get_mime_types().
|
||||
func (f *PixbufFormat) GetMimeTypes() []string {
|
||||
var types []string
|
||||
c := C.gdk_pixbuf_format_get_mime_types(f.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
for *c != nil {
|
||||
types = append(types, C.GoString((*C.char)(*c)))
|
||||
c = C.next_gcharptr(c)
|
||||
}
|
||||
return types
|
||||
}
|
||||
|
||||
// GetExtensions is a wrapper around gdk_pixbuf_format_get_extensions().
|
||||
func (f *PixbufFormat) GetExtensions() []string {
|
||||
var extensions []string
|
||||
c := C.gdk_pixbuf_format_get_extensions(f.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
for *c != nil {
|
||||
extensions = append(extensions, C.GoString((*C.char)(*c)))
|
||||
c = C.next_gcharptr(c)
|
||||
}
|
||||
return extensions
|
||||
}
|
||||
|
||||
// GetLicense is a wrapper around gdk_pixbuf_format_get_license().
|
||||
func (f *PixbufFormat) GetLicense() (string, error) {
|
||||
c := C.gdk_pixbuf_format_get_license(f.native())
|
||||
return C.GoString((*C.char)(c)), nil
|
||||
}
|
||||
18
third_party/gotk3/gdk/pixbuf_since_2_22.go
vendored
Normal file
18
third_party/gotk3/gdk/pixbuf_since_2_22.go
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
|
||||
/*
|
||||
* PixbufFormat
|
||||
*/
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_format_copy().
|
||||
23
third_party/gotk3/gdk/pixbuf_since_2_24.go
vendored
Normal file
23
third_party/gotk3/gdk/pixbuf_since_2_24.go
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
|
||||
// File Loading
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_new_from_stream_finish().
|
||||
// gdk_pixbuf_new_from_stream_at_scale_async().
|
||||
|
||||
// File saving
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_save_to_stream_async().
|
||||
// gdk_pixbuf_save_to_stream_finish().
|
||||
25
third_party/gotk3/gdk/pixbuf_since_2_26.go
vendored
Normal file
25
third_party/gotk3/gdk/pixbuf_since_2_26.go
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22,!gdk_pixbuf_2_24
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
|
||||
// File Loading
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_new_from_resource().
|
||||
// gdk_pixbuf_new_from_resource_at_scale().
|
||||
|
||||
// The GdkPixbuf Structure
|
||||
|
||||
// GetByteLength is a wrapper around gdk_pixbuf_get_byte_length().
|
||||
func (v *Pixbuf) GetByteLength() int {
|
||||
c := C.gdk_pixbuf_get_byte_length(v.native())
|
||||
return int(c)
|
||||
}
|
||||
68
third_party/gotk3/gdk/pixbuf_since_2_32.go
vendored
Normal file
68
third_party/gotk3/gdk/pixbuf_since_2_32.go
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22,!gdk_pixbuf_2_24,!gdk_pixbuf_2_26,!gdk_pixbuf_2_28,!gdk_pixbuf_2_30
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// Image Data in Memory
|
||||
|
||||
// PixbufNewFromBytes is a wrapper around gdk_pixbuf_new_from_bytes().
|
||||
// see go package "encoding/base64"
|
||||
func PixbufNewFromBytes(pixbufData []byte, cs Colorspace, hasAlpha bool, bitsPerSample, width, height, rowStride int) (*Pixbuf, error) {
|
||||
arrayPtr := (*C.GBytes)(unsafe.Pointer(&pixbufData[0]))
|
||||
|
||||
c := C.gdk_pixbuf_new_from_bytes(
|
||||
arrayPtr,
|
||||
C.GdkColorspace(cs),
|
||||
gbool(hasAlpha),
|
||||
C.int(bitsPerSample),
|
||||
C.int(width),
|
||||
C.int(height),
|
||||
C.int(rowStride),
|
||||
)
|
||||
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// PixbufNewFromBytesOnly is a convenient alternative to PixbufNewFromBytes() and also a wrapper around gdk_pixbuf_new_from_bytes().
|
||||
// see go package "encoding/base64"
|
||||
func PixbufNewFromBytesOnly(pixbufData []byte) (*Pixbuf, error) {
|
||||
pixbufLoader, err := PixbufLoaderNew()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pixbufLoader.WriteAndReturnPixbuf(pixbufData)
|
||||
}
|
||||
|
||||
// File loading
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_get_file_info_async().
|
||||
// gdk_pixbuf_get_file_info_finish().
|
||||
|
||||
// The GdkPixbuf Structure
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_get_options().
|
||||
// gdk_pixbuf_read_pixels().
|
||||
23
third_party/gotk3/gdk/pixbuf_since_2_36.go
vendored
Normal file
23
third_party/gotk3/gdk/pixbuf_since_2_36.go
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22,!gdk_pixbuf_2_24,!gdk_pixbuf_2_26,!gdk_pixbuf_2_28,!gdk_pixbuf_2_30,!gdk_pixbuf_2_32
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
|
||||
// File saving
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_save_to_streamv().
|
||||
// gdk_pixbuf_save_to_streamv_async().
|
||||
|
||||
// The GdkPixbuf Structure
|
||||
|
||||
// TODO:
|
||||
// gdk_pixbuf_remove_option().
|
||||
// gdk_pixbuf_copy_options().
|
||||
143
third_party/gotk3/gdk/pixbuf_since_2_4.go
vendored
Normal file
143
third_party/gotk3/gdk/pixbuf_since_2_4.go
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0 gmodule-2.0
|
||||
// #include <glib.h>
|
||||
// #include <gmodule.h>
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
// #include "pixbuf_since_2_4.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
"github.com/gotk3/gotk3/internal/callback"
|
||||
)
|
||||
|
||||
// File saving
|
||||
|
||||
//export goPixbufSaveCallback
|
||||
func goPixbufSaveCallback(buf *C.gchar, count C.gsize, gerr **C.GError, id C.gpointer) C.gboolean {
|
||||
v := callback.Get(uintptr(id))
|
||||
|
||||
if v == nil {
|
||||
C._pixbuf_error_set_callback_not_found(gerr)
|
||||
return C.FALSE
|
||||
}
|
||||
|
||||
var bytes []byte
|
||||
header := (*reflect.SliceHeader)((unsafe.Pointer(&bytes)))
|
||||
header.Cap = int(count)
|
||||
header.Len = int(count)
|
||||
header.Data = uintptr(unsafe.Pointer(buf))
|
||||
|
||||
_, err := v.(io.Writer).Write(bytes)
|
||||
if err != nil {
|
||||
cerr := C.CString(err.Error())
|
||||
defer C.free(unsafe.Pointer(cerr))
|
||||
|
||||
C._pixbuf_error_set(gerr, cerr)
|
||||
return C.FALSE
|
||||
}
|
||||
|
||||
return C.TRUE
|
||||
}
|
||||
|
||||
// WritePNG is a convenience wrapper around gdk_pixbuf_save_to_callback() for
|
||||
// saving images using a streaming callback API. Compression is a number from 0
|
||||
// to 9.
|
||||
func (v *Pixbuf) WritePNG(w io.Writer, compression int) error {
|
||||
ccompression := C.CString(strconv.Itoa(compression))
|
||||
defer C.free(unsafe.Pointer(ccompression))
|
||||
|
||||
id := callback.Assign(w)
|
||||
|
||||
var err *C.GError
|
||||
c := C._gdk_pixbuf_save_png_writer(v.native(), C.gpointer(id), &err, ccompression)
|
||||
|
||||
callback.Delete(id)
|
||||
|
||||
if !gobool(c) {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteJPEG is a convenience wrapper around gdk_pixbuf_save_to_callback() for
|
||||
// saving images using a streaming callback API. Quality is a number from 0 to
|
||||
// 100.
|
||||
func (v *Pixbuf) WriteJPEG(w io.Writer, quality int) error {
|
||||
cquality := C.CString(strconv.Itoa(quality))
|
||||
defer C.free(unsafe.Pointer(cquality))
|
||||
|
||||
id := callback.Assign(w)
|
||||
|
||||
var err *C.GError
|
||||
c := C._gdk_pixbuf_save_jpeg_writer(v.native(), C.gpointer(id), &err, cquality)
|
||||
|
||||
callback.Delete(id)
|
||||
|
||||
if !gobool(c) {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// GdkPixbufSaveFunc
|
||||
// gdk_pixbuf_save_to_callback().
|
||||
// gdk_pixbuf_save_to_callbackv().
|
||||
// gdk_pixbuf_save_to_buffer().
|
||||
// gdk_pixbuf_save_to_bufferv().
|
||||
|
||||
// File Loading
|
||||
|
||||
// PixbufNewFromFileAtSize is a wrapper around gdk_pixbuf_new_from_file_at_size().
|
||||
func PixbufNewFromFileAtSize(filename string, width, height int) (*Pixbuf, error) {
|
||||
cstr := C.CString(filename)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
var err *C.GError = nil
|
||||
c := C.gdk_pixbuf_new_from_file_at_size(cstr, C.int(width), C.int(height), &err)
|
||||
if err != nil {
|
||||
defer C.g_error_free(err)
|
||||
return nil, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// PixbufGetFileInfo is a wrapper around gdk_pixbuf_get_file_info().
|
||||
func PixbufGetFileInfo(filename string) (*PixbufFormat, int, int, error) {
|
||||
cstr := C.CString(filename)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
var cw, ch C.gint
|
||||
format := C.gdk_pixbuf_get_file_info((*C.gchar)(cstr), &cw, &ch)
|
||||
if format == nil {
|
||||
return nil, -1, -1, nilPtrErr
|
||||
}
|
||||
// The returned PixbufFormat value is owned by Pixbuf and should not be freed.
|
||||
return wrapPixbufFormat(format), int(cw), int(ch), nil
|
||||
}
|
||||
34
third_party/gotk3/gdk/pixbuf_since_2_4.go.h
vendored
Normal file
34
third_party/gotk3/gdk/pixbuf_since_2_4.go.h
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
extern gboolean goPixbufSaveCallback(gchar *buf, gsize count, GError **error,
|
||||
gpointer data);
|
||||
|
||||
static inline gboolean _gdk_pixbuf_save_png_writer(GdkPixbuf *pixbuf,
|
||||
gpointer callback_id,
|
||||
GError **err,
|
||||
const char *compression) {
|
||||
return gdk_pixbuf_save_to_callback(
|
||||
pixbuf, (GdkPixbufSaveFunc)(goPixbufSaveCallback), callback_id, "png",
|
||||
err, "compression", compression, NULL);
|
||||
}
|
||||
|
||||
static inline gboolean _gdk_pixbuf_save_jpeg_writer(GdkPixbuf *pixbuf,
|
||||
gpointer callback_id,
|
||||
GError **err,
|
||||
const char *quality) {
|
||||
return gdk_pixbuf_save_to_callback(
|
||||
pixbuf, (GdkPixbufSaveFunc)(goPixbufSaveCallback), callback_id, "jpeg",
|
||||
err, "quality", quality, NULL);
|
||||
}
|
||||
|
||||
static inline void _pixbuf_error_set_callback_not_found(GError **err) {
|
||||
GQuark domain = g_quark_from_static_string("go error");
|
||||
g_set_error_literal(err, domain, 1, "pixbuf callback not found");
|
||||
}
|
||||
|
||||
static inline void _pixbuf_error_set(GError **err, char *message) {
|
||||
GQuark domain = g_quark_from_static_string("go error");
|
||||
g_set_error_literal(err, domain, 1, message);
|
||||
}
|
||||
74
third_party/gotk3/gdk/pixbuf_since_2_6.go
vendored
Normal file
74
third_party/gotk3/gdk/pixbuf_since_2_6.go
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4
|
||||
|
||||
package gdk
|
||||
|
||||
// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
// #include "pixbuf.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// File Loading
|
||||
|
||||
// PixbufNewFromFileAtScale is a wrapper around gdk_pixbuf_new_from_file_at_scale().
|
||||
func PixbufNewFromFileAtScale(filename string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
|
||||
cstr := C.CString(filename)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
var err *C.GError = nil
|
||||
c := C.gdk_pixbuf_new_from_file_at_scale(cstr, C.int(width), C.int(height),
|
||||
gbool(preserveAspectRatio), &err)
|
||||
if err != nil {
|
||||
defer C.g_error_free(err)
|
||||
return nil, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Scaling
|
||||
|
||||
// RotateSimple is a wrapper around gdk_pixbuf_rotate_simple().
|
||||
func (v *Pixbuf) RotateSimple(angle PixbufRotation) (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_rotate_simple(v.native(), C.GdkPixbufRotation(angle))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Flip is a wrapper around gdk_pixbuf_flip().
|
||||
func (v *Pixbuf) Flip(horizontal bool) (*Pixbuf, error) {
|
||||
c := C.gdk_pixbuf_flip(v.native(), gbool(horizontal))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
p := &Pixbuf{obj}
|
||||
//obj.Ref()
|
||||
runtime.SetFinalizer(p, func(_ interface{}) { glib.FinalizerStrategy(obj.Unref) })
|
||||
return p, nil
|
||||
}
|
||||
114
third_party/gotk3/gdk/screen.go
vendored
Normal file
114
third_party/gotk3/gdk/screen.go
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
// #include "gdk.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
/*
|
||||
* GdkScreen
|
||||
*/
|
||||
|
||||
// Screen is a representation of GDK's GdkScreen.
|
||||
type Screen struct {
|
||||
*glib.Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GdkScreen.
|
||||
func (v *Screen) native() *C.GdkScreen {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGdkScreen(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GdkScreen.
|
||||
func (v *Screen) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalScreen(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
|
||||
return &Screen{obj}, nil
|
||||
}
|
||||
|
||||
func toScreen(s *C.GdkScreen) (*Screen, error) {
|
||||
if s == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
|
||||
return &Screen{obj}, nil
|
||||
}
|
||||
|
||||
// GetRGBAVisual is a wrapper around gdk_screen_get_rgba_visual().
|
||||
func (v *Screen) GetRGBAVisual() (*Visual, error) {
|
||||
c := C.gdk_screen_get_rgba_visual(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Visual{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// GetSystemVisual is a wrapper around gdk_screen_get_system_visual().
|
||||
func (v *Screen) GetSystemVisual() (*Visual, error) {
|
||||
c := C.gdk_screen_get_system_visual(v.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
|
||||
return &Visual{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// ScreenGetDefault is a wrapper around gdk_screen_get_default().
|
||||
func ScreenGetDefault() (*Screen, error) {
|
||||
return toScreen(C.gdk_screen_get_default())
|
||||
}
|
||||
|
||||
// IsComposited is a wrapper around gdk_screen_is_composited().
|
||||
func (v *Screen) IsComposited() bool {
|
||||
return gobool(C.gdk_screen_is_composited(v.native()))
|
||||
}
|
||||
|
||||
// GetRootWindow is a wrapper around gdk_screen_get_root_window().
|
||||
func (v *Screen) GetRootWindow() (*Window, error) {
|
||||
return toWindow(C.gdk_screen_get_root_window(v.native()))
|
||||
}
|
||||
|
||||
// GetDisplay is a wrapper around gdk_screen_get_display().
|
||||
func (v *Screen) GetDisplay() (*Display, error) {
|
||||
return toDisplay(C.gdk_screen_get_display(v.native()))
|
||||
}
|
||||
|
||||
func toString(c *C.gchar) (string, error) {
|
||||
if c == nil {
|
||||
return "", nilPtrErr
|
||||
}
|
||||
return C.GoString((*C.char)(c)), nil
|
||||
}
|
||||
|
||||
// GetResolution is a wrapper around gdk_screen_get_resolution().
|
||||
func (v *Screen) GetResolution() float64 {
|
||||
return float64(C.gdk_screen_get_resolution(v.native()))
|
||||
}
|
||||
|
||||
// SetResolution is a wrapper around gdk_screen_set_resolution().
|
||||
func (v *Screen) SetResolution(r float64) {
|
||||
C.gdk_screen_set_resolution(v.native(), C.gdouble(r))
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// void gdk_screen_set_font_options ()
|
||||
// gboolean gdk_screen_get_setting ()
|
||||
// const cairo_font_options_t * gdk_screen_get_font_options ()
|
||||
// GList * gdk_screen_get_window_stack ()
|
||||
// GList * gdk_screen_list_visuals ()
|
||||
// GList * gdk_screen_get_toplevel_windows ()
|
||||
// void gdk_screen_get_monitor_geometry ()
|
||||
// void gdk_screen_get_monitor_workarea ()
|
||||
25
third_party/gotk3/gdk/screen_no_x11.go
vendored
Normal file
25
third_party/gotk3/gdk/screen_no_x11.go
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// +build !linux no_x11
|
||||
|
||||
package gdk
|
||||
|
||||
func WorkspaceControlSupported() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// GetScreenNumber is a wrapper around gdk_x11_screen_get_screen_number().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Screen) GetScreenNumber() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// GetNumberOfDesktops is a wrapper around gdk_x11_screen_get_number_of_desktops().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Screen) GetNumberOfDesktops() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// GetCurrentDesktop is a wrapper around gdk_x11_screen_get_current_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Screen) GetCurrentDesktop() uint32 {
|
||||
return 0
|
||||
}
|
||||
30
third_party/gotk3/gdk/screen_x11.go
vendored
Normal file
30
third_party/gotk3/gdk/screen_x11.go
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// +build linux
|
||||
// +build !no_x11
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
// #include <gdk/gdkx.h>
|
||||
import "C"
|
||||
|
||||
func WorkspaceControlSupported() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// GetScreenNumber is a wrapper around gdk_x11_screen_get_screen_number().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Screen) GetScreenNumber() int {
|
||||
return int(C.gdk_x11_screen_get_screen_number(v.native()))
|
||||
}
|
||||
|
||||
// GetNumberOfDesktops is a wrapper around gdk_x11_screen_get_number_of_desktops().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Screen) GetNumberOfDesktops() uint32 {
|
||||
return uint32(C.gdk_x11_screen_get_number_of_desktops(v.native()))
|
||||
}
|
||||
|
||||
// GetCurrentDesktop is a wrapper around gdk_x11_screen_get_current_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Screen) GetCurrentDesktop() uint32 {
|
||||
return uint32(C.gdk_x11_screen_get_current_desktop(v.native()))
|
||||
}
|
||||
38
third_party/gotk3/gdk/testing.go
vendored
Normal file
38
third_party/gotk3/gdk/testing.go
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
import "C"
|
||||
|
||||
// TestRenderSync retrieves a pixel from window to force the windowing system to carry out any pending rendering commands.
|
||||
// This function is intended to be used to synchronize with rendering pipelines, to benchmark windowing system rendering operations.
|
||||
// This is a wrapper around gdk_test_render_sync().
|
||||
func TestRenderSync(window *Window) {
|
||||
C.gdk_test_render_sync(window.native())
|
||||
}
|
||||
|
||||
// TestSimulateButton simulates a single mouse button event (press or release) at the given coordinates relative to the window.
|
||||
// Hint: a single click of a button requires this method to be called twice, once for pressed and once for released.
|
||||
// In most cases, gtk.TestWidgetClick() should be used.
|
||||
//
|
||||
// button: Mouse button number, starts with 0
|
||||
// modifiers: Keyboard modifiers for the button event
|
||||
// buttonPressRelease: either GDK_BUTTON_PRESS or GDK_BUTTON_RELEASE
|
||||
//
|
||||
// This is a wrapper around gdk_test_simulate_button().
|
||||
func TestSimulateButton(window *Window, x, y int, button Button, modifiers ModifierType, buttonPressRelease EventType) bool {
|
||||
return gobool(C.gdk_test_simulate_button(window.native(), C.gint(x), C.gint(y), C.guint(button), C.GdkModifierType(modifiers), C.GdkEventType(buttonPressRelease)))
|
||||
}
|
||||
|
||||
// TestSimulateButton simulates a keyboard event (press or release) at the given coordinates relative to the window.
|
||||
// If the coordinates (-1, -1) are used, the window origin is used instead.
|
||||
// Hint: a single key press requires this method to be called twice, once for pressed and once for released.
|
||||
// In most cases, gtk.TestWidgetSendKey() should be used.
|
||||
//
|
||||
// keyval: A GDK keyboard value (See KeyvalFromName(), UnicodeToKeyval(), ...)
|
||||
// modifiers: Keyboard modifiers for the key event
|
||||
// buttonPressRelease: either GDK_BUTTON_PRESS or GDK_BUTTON_RELEASE
|
||||
//
|
||||
// This is a wrapper around gdk_test_simulate_key().
|
||||
func TestSimulateKey(window *Window, x, y int, keyval uint, modifiers ModifierType, buttonPressRelease EventType) bool {
|
||||
return gobool(C.gdk_test_simulate_key(window.native(), C.gint(x), C.gint(y), C.guint(keyval), C.GdkModifierType(modifiers), C.GdkEventType(buttonPressRelease)))
|
||||
}
|
||||
17
third_party/gotk3/gdk/window_no_x11.go
vendored
Normal file
17
third_party/gotk3/gdk/window_no_x11.go
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// +build !linux no_x11
|
||||
|
||||
package gdk
|
||||
|
||||
func (v *Window) MoveToCurrentDesktop() {
|
||||
}
|
||||
|
||||
// GetDesktop is a wrapper around gdk_x11_window_get_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Window) GetDesktop() uint32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// MoveToDesktop is a wrapper around gdk_x11_window_move_to_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Window) MoveToDesktop(d uint32) {
|
||||
}
|
||||
47
third_party/gotk3/gdk/window_x11.go
vendored
Normal file
47
third_party/gotk3/gdk/window_x11.go
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// +build linux
|
||||
// +build !no_x11
|
||||
|
||||
package gdk
|
||||
|
||||
// #include <gdk/gdk.h>
|
||||
// #include <gdk/gdkx.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/glib"
|
||||
)
|
||||
|
||||
// MoveToCurrentDesktop is a wrapper around gdk_x11_window_move_to_current_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Window) MoveToCurrentDesktop() {
|
||||
C.gdk_x11_window_move_to_current_desktop(v.native())
|
||||
}
|
||||
|
||||
// GetDesktop is a wrapper around gdk_x11_window_get_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Window) GetDesktop() uint32 {
|
||||
return uint32(C.gdk_x11_window_get_desktop(v.native()))
|
||||
}
|
||||
|
||||
// MoveToDesktop is a wrapper around gdk_x11_window_move_to_desktop().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Window) MoveToDesktop(d uint32) {
|
||||
C.gdk_x11_window_move_to_desktop(v.native(), C.guint32(d))
|
||||
}
|
||||
|
||||
// GetXID is a wrapper around gdk_x11_window_get_xid().
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Window) GetXID() uint32 {
|
||||
return uint32(C.gdk_x11_window_get_xid(v.native()))
|
||||
}
|
||||
|
||||
//ForeignNewForDisplay is a wrapper around gdk_x11_window_foreign_new_for_display()
|
||||
// It only works on GDK versions compiled with X11 support - its return value can't be used if WorkspaceControlSupported returns false
|
||||
func (v *Display) ForeignNewForDisplay(xid uint32) (*Window, error) {
|
||||
c := C.gdk_x11_window_foreign_new_for_display(v.native(), C.Window(xid))
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return &Window{glib.Take(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
102
third_party/gotk3/gio/gresource.go
vendored
Normal file
102
third_party/gotk3/gio/gresource.go
vendored
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
// package resource wraps operations over GResource
|
||||
package gio
|
||||
|
||||
// #cgo pkg-config: gio-2.0 glib-2.0 gobject-2.0
|
||||
// #include <gio/gio.h>
|
||||
// #include <stdlib.h>
|
||||
// #include "gresource.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// ResourceLookupFlags is a representation of GTK's GResourceLookupFlags
|
||||
type ResourceLookupFlags int
|
||||
|
||||
func (f ResourceLookupFlags) native() C.GResourceLookupFlags {
|
||||
return (C.GResourceLookupFlags)(f)
|
||||
}
|
||||
|
||||
const (
|
||||
G_RESOURCE_LOOKUP_FLAGS_NONE ResourceLookupFlags = C.G_RESOURCE_LOOKUP_FLAGS_NONE
|
||||
)
|
||||
|
||||
// GResource wraps native GResource object
|
||||
//
|
||||
// See: https://developer.gnome.org/gio/stable/GResource.html
|
||||
type GResource *C.GResource
|
||||
|
||||
// LoadGResource is a wrapper around g_resource_load()
|
||||
//
|
||||
// See: https://developer.gnome.org/gio/stable/GResource.html#g-resource-load
|
||||
func LoadGResource(path string) (GResource, error) {
|
||||
cpath := C.CString(path)
|
||||
defer C.free(unsafe.Pointer(cpath))
|
||||
var gerr *C.GError
|
||||
|
||||
resPtr := C.g_resource_load((*C.gchar)(unsafe.Pointer(cpath)), &gerr)
|
||||
if gerr != nil {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, errors.New(goString(gerr.message))
|
||||
}
|
||||
|
||||
res := wrapGResource(resPtr)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// NewGResourceFromData is a wrapper around g_resource_new_from_data()
|
||||
//
|
||||
// See: https://developer.gnome.org/gio/stable/GResource.html#g-resource-new-from-data
|
||||
func NewGResourceFromData(data []byte) (GResource, error) {
|
||||
arrayPtr := (*C.GBytes)(unsafe.Pointer(&data[0]))
|
||||
var gerr *C.GError
|
||||
resPtr := C.g_resource_new_from_data(arrayPtr, &gerr)
|
||||
if gerr != nil {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, errors.New(goString(gerr.message))
|
||||
}
|
||||
|
||||
res := wrapGResource(resPtr)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Register wraps g_resources_register()
|
||||
//
|
||||
// See: https://developer.gnome.org/gio/stable/GResource.html#g-resources-register
|
||||
func RegisterGResource(res GResource) {
|
||||
C.g_resources_register(res)
|
||||
}
|
||||
|
||||
// Unregister wraps g_resources_unregister()
|
||||
//
|
||||
// See: https://developer.gnome.org/gio/stable/GResource.html#g-resources-unregister
|
||||
func UnregisterGResource(res GResource) {
|
||||
C.g_resources_unregister(res)
|
||||
}
|
||||
|
||||
// GResourceEnumerateChildren wraps g_resources_enumerate_children()
|
||||
//
|
||||
// See: https://developer.gnome.org/gio/stable/GResource.html#g-resources-enumerate-children
|
||||
func GResourceEnumerateChildren(path string, flags ResourceLookupFlags) ([]string, error) {
|
||||
cpath := C.CString(path)
|
||||
defer C.free(unsafe.Pointer(cpath))
|
||||
var gerr *C.GError
|
||||
arrChildren := C.g_resources_enumerate_children(cpath, flags.native(), &gerr)
|
||||
if gerr != nil {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, errors.New(goString(gerr.message))
|
||||
}
|
||||
|
||||
if arrChildren == nil {
|
||||
return nil, errors.New("unexpected nil pointer from g_resources_enumerate_children")
|
||||
}
|
||||
|
||||
arr := toGoStringArray(arrChildren)
|
||||
return arr, nil
|
||||
}
|
||||
|
||||
func wrapGResource(resPtr *C.GResource) GResource {
|
||||
res := GResource(resPtr)
|
||||
return res
|
||||
}
|
||||
11
third_party/gotk3/gio/gresource.go.h
vendored
Normal file
11
third_party/gotk3/gio/gresource.go.h
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline char **next_charptr(char **s) { return (s + 1); }
|
||||
|
||||
static inline void char_g_strfreev(char **s) { g_strfreev((gchar **)s); }
|
||||
34
third_party/gotk3/gio/utils.go
vendored
Normal file
34
third_party/gotk3/gio/utils.go
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package gio
|
||||
|
||||
// #include <glib.h>
|
||||
// #include "gresource.go.h"
|
||||
import "C"
|
||||
|
||||
// same implementation as package glib
|
||||
func toGoStringArray(c **C.char) []string {
|
||||
var strs []string
|
||||
originalc := c
|
||||
defer C.char_g_strfreev(originalc)
|
||||
|
||||
for *c != nil {
|
||||
strs = append(strs, C.GoString((*C.char)(*c)))
|
||||
c = C.next_charptr(c)
|
||||
}
|
||||
|
||||
return strs
|
||||
}
|
||||
|
||||
func goString(cstr *C.gchar) string {
|
||||
return C.GoString((*C.char)(cstr))
|
||||
}
|
||||
|
||||
func gbool(b bool) C.gboolean {
|
||||
if b {
|
||||
return C.gboolean(1)
|
||||
}
|
||||
return C.gboolean(0)
|
||||
}
|
||||
|
||||
func gobool(b C.gboolean) bool {
|
||||
return b != C.FALSE
|
||||
}
|
||||
196
third_party/gotk3/glib/application.go
vendored
Normal file
196
third_party/gotk3/glib/application.go
vendored
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// Application is a representation of GApplication.
|
||||
type Application struct {
|
||||
*Object
|
||||
|
||||
// Interfaces
|
||||
IActionMap
|
||||
IActionGroup
|
||||
}
|
||||
|
||||
// native() returns a pointer to the underlying GApplication.
|
||||
func (v *Application) native() *C.GApplication {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGApplication(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func (v *Application) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalApplication(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapApplication(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapApplication(obj *Object) *Application {
|
||||
am := wrapActionMap(obj)
|
||||
ag := wrapActionGroup(obj)
|
||||
return &Application{obj, am, ag}
|
||||
}
|
||||
|
||||
// ApplicationIDIsValid is a wrapper around g_application_id_is_valid().
|
||||
func ApplicationIDIsValid(id string) bool {
|
||||
cstr1 := (*C.gchar)(C.CString(id))
|
||||
defer C.free(unsafe.Pointer(cstr1))
|
||||
|
||||
return gobool(C.g_application_id_is_valid(cstr1))
|
||||
}
|
||||
|
||||
// ApplicationNew is a wrapper around g_application_new().
|
||||
func ApplicationNew(appID string, flags ApplicationFlags) *Application {
|
||||
cstr1 := (*C.gchar)(C.CString(appID))
|
||||
defer C.free(unsafe.Pointer(cstr1))
|
||||
|
||||
c := C.g_application_new(cstr1, C.GApplicationFlags(flags))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapApplication(wrapObject(unsafe.Pointer(c)))
|
||||
}
|
||||
|
||||
// GetApplicationID is a wrapper around g_application_get_application_id().
|
||||
func (v *Application) GetApplicationID() string {
|
||||
c := C.g_application_get_application_id(v.native())
|
||||
|
||||
return C.GoString((*C.char)(c))
|
||||
}
|
||||
|
||||
// SetApplicationID is a wrapper around g_application_set_application_id().
|
||||
func (v *Application) SetApplicationID(id string) {
|
||||
cstr1 := (*C.gchar)(C.CString(id))
|
||||
defer C.free(unsafe.Pointer(cstr1))
|
||||
|
||||
C.g_application_set_application_id(v.native(), cstr1)
|
||||
}
|
||||
|
||||
// GetInactivityTimeout is a wrapper around g_application_get_inactivity_timeout().
|
||||
func (v *Application) GetInactivityTimeout() uint {
|
||||
return uint(C.g_application_get_inactivity_timeout(v.native()))
|
||||
}
|
||||
|
||||
// SetInactivityTimeout is a wrapper around g_application_set_inactivity_timeout().
|
||||
func (v *Application) SetInactivityTimeout(timeout uint) {
|
||||
C.g_application_set_inactivity_timeout(v.native(), C.guint(timeout))
|
||||
}
|
||||
|
||||
// GetFlags is a wrapper around g_application_get_flags().
|
||||
func (v *Application) GetFlags() ApplicationFlags {
|
||||
return ApplicationFlags(C.g_application_get_flags(v.native()))
|
||||
}
|
||||
|
||||
// SetFlags is a wrapper around g_application_set_flags().
|
||||
func (v *Application) SetFlags(flags ApplicationFlags) {
|
||||
C.g_application_set_flags(v.native(), C.GApplicationFlags(flags))
|
||||
}
|
||||
|
||||
// GetDbusObjectPath is a wrapper around g_application_get_dbus_object_path().
|
||||
func (v *Application) GetDbusObjectPath() string {
|
||||
c := C.g_application_get_dbus_object_path(v.native())
|
||||
|
||||
return C.GoString((*C.char)(c))
|
||||
}
|
||||
|
||||
// GetIsRegistered is a wrapper around g_application_get_is_registered().
|
||||
func (v *Application) GetIsRegistered() bool {
|
||||
return gobool(C.g_application_get_is_registered(v.native()))
|
||||
}
|
||||
|
||||
// GetIsRemote is a wrapper around g_application_get_is_remote().
|
||||
func (v *Application) GetIsRemote() bool {
|
||||
return gobool(C.g_application_get_is_remote(v.native()))
|
||||
}
|
||||
|
||||
// Hold is a wrapper around g_application_hold().
|
||||
func (v *Application) Hold() {
|
||||
C.g_application_hold(v.native())
|
||||
}
|
||||
|
||||
// Release is a wrapper around g_application_release().
|
||||
func (v *Application) Release() {
|
||||
C.g_application_release(v.native())
|
||||
}
|
||||
|
||||
// Quit is a wrapper around g_application_quit().
|
||||
func (v *Application) Quit() {
|
||||
C.g_application_quit(v.native())
|
||||
}
|
||||
|
||||
// Activate is a wrapper around g_application_activate().
|
||||
func (v *Application) Activate() {
|
||||
C.g_application_activate(v.native())
|
||||
}
|
||||
|
||||
// SendNotification is a wrapper around g_application_send_notification().
|
||||
func (v *Application) SendNotification(id string, notification *Notification) {
|
||||
cstr1 := (*C.gchar)(C.CString(id))
|
||||
defer C.free(unsafe.Pointer(cstr1))
|
||||
|
||||
C.g_application_send_notification(v.native(), cstr1, notification.native())
|
||||
}
|
||||
|
||||
// WithdrawNotification is a wrapper around g_application_withdraw_notification().
|
||||
func (v *Application) WithdrawNotification(id string) {
|
||||
cstr1 := (*C.gchar)(C.CString(id))
|
||||
defer C.free(unsafe.Pointer(cstr1))
|
||||
|
||||
C.g_application_withdraw_notification(v.native(), cstr1)
|
||||
}
|
||||
|
||||
// SetDefault is a wrapper around g_application_set_default().
|
||||
func (v *Application) SetDefault() {
|
||||
C.g_application_set_default(v.native())
|
||||
}
|
||||
|
||||
// ApplicationGetDefault is a wrapper around g_application_get_default().
|
||||
func ApplicationGetDefault() *Application {
|
||||
c := C.g_application_get_default()
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapApplication(wrapObject(unsafe.Pointer(c)))
|
||||
}
|
||||
|
||||
// MarkBusy is a wrapper around g_application_mark_busy().
|
||||
func (v *Application) MarkBusy() {
|
||||
C.g_application_mark_busy(v.native())
|
||||
}
|
||||
|
||||
// UnmarkBusy is a wrapper around g_application_unmark_busy().
|
||||
func (v *Application) UnmarkBusy() {
|
||||
C.g_application_unmark_busy(v.native())
|
||||
}
|
||||
|
||||
// Run is a wrapper around g_application_run().
|
||||
func (v *Application) Run(args []string) int {
|
||||
cargs := C.make_strings(C.int(len(args)))
|
||||
defer C.destroy_strings(cargs)
|
||||
|
||||
for i, arg := range args {
|
||||
cstr := C.CString(arg)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
C.set_string(cargs, C.int(i), (*C.char)(cstr))
|
||||
}
|
||||
|
||||
return int(C.g_application_run(v.native(), C.int(len(args)), cargs))
|
||||
}
|
||||
|
||||
// void g_application_bind_busy_property ()
|
||||
// void g_application_unbind_busy_property ()
|
||||
// gboolean g_application_register () // requires GCancellable
|
||||
// void g_application_set_action_group () // Deprecated since 2.32
|
||||
// GDBusConnection * g_application_get_dbus_connection () // No support for GDBusConnection
|
||||
// void g_application_open () // Needs GFile
|
||||
// void g_application_add_main_option_entries () //Needs GOptionEntry
|
||||
// void g_application_add_main_option () //Needs GOptionFlags and GOptionArg
|
||||
// void g_application_add_option_group () // Needs GOptionGroup
|
||||
7
third_party/gotk3/glib/cast.go
vendored
Normal file
7
third_party/gotk3/glib/cast.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package glib
|
||||
|
||||
type WrapFn interface{}
|
||||
|
||||
var WrapMap = map[string]WrapFn{
|
||||
"GMenu": wrapMenuModel,
|
||||
}
|
||||
152
third_party/gotk3/glib/connect.go
vendored
Normal file
152
third_party/gotk3/glib/connect.go
vendored
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
package glib
|
||||
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/internal/closure"
|
||||
)
|
||||
|
||||
/*
|
||||
* Events
|
||||
*/
|
||||
|
||||
// SignalHandle is the ID of a signal handler.
|
||||
type SignalHandle uint
|
||||
|
||||
// Connect is a wrapper around g_signal_connect_closure(). f must be a function
|
||||
// with at least one parameter matching the type it is connected to.
|
||||
//
|
||||
// It is optional to list the rest of the required types from Gtk, as values
|
||||
// that don't fit into the function parameter will simply be ignored; however,
|
||||
// extraneous types will trigger a runtime panic. Arguments for f must be a
|
||||
// matching Go equivalent type for the C callback, or an interface type which
|
||||
// the value may be packed in. If the type is not suitable, a runtime panic will
|
||||
// occur when the signal is emitted.
|
||||
//
|
||||
// Circular References
|
||||
//
|
||||
// To prevent circular references, prefer declaring Connect functions like so:
|
||||
//
|
||||
// obj.Connect(func(obj *ObjType) { obj.Do() })
|
||||
//
|
||||
// Instead of directly referencing the object from outside like so:
|
||||
//
|
||||
// obj.Connect(func() { obj.Do() })
|
||||
//
|
||||
// When using Connect, beware of referencing variables outside the closure that
|
||||
// may cause a circular reference that prevents both Go from garbage collecting
|
||||
// the callback and GTK from successfully unreferencing its values.
|
||||
//
|
||||
// Below is an example piece of code that is considered "leaky":
|
||||
//
|
||||
// type ChatBox struct {
|
||||
// gtk.TextView
|
||||
// Loader *gdk.PixbufLoader
|
||||
//
|
||||
// State State
|
||||
// }
|
||||
//
|
||||
// func (box *ChatBox) Method() {
|
||||
// box.Loader.Connect("size-allocate", func(loader *gdk.PixbufLoader) {
|
||||
// // Here, we're dereferencing box to get the state, which might
|
||||
// // keep box alive along with the PixbufLoader, causing a circular
|
||||
// // reference.
|
||||
// loader.SetSize(box.State.Width, box.State.Height)
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// There are many solutions to fix the above piece of code. For example,
|
||||
// box.Loader could be discarded manually immediately after it's done by setting
|
||||
// it to nil, or the signal handle could be disconnected manually, or box could
|
||||
// be set to nil after its first call in the callback.
|
||||
func (v *Object) Connect(detailedSignal string, f interface{}) SignalHandle {
|
||||
return v.connectClosure(false, detailedSignal, f)
|
||||
}
|
||||
|
||||
// ConnectAfter is a wrapper around g_signal_connect_closure(). The difference
|
||||
// between Connect and ConnectAfter is that the latter will be invoked after the
|
||||
// default handler, not before. For more information, refer to Connect.
|
||||
func (v *Object) ConnectAfter(detailedSignal string, f interface{}) SignalHandle {
|
||||
return v.connectClosure(true, detailedSignal, f)
|
||||
}
|
||||
|
||||
// ClosureCheckReceiver, if true, will make GLib check for every single
|
||||
// closure's first argument to ensure that it is correct, otherwise it will
|
||||
// panic with a message warning about the possible circular references. The
|
||||
// receiver in this case is most often the first argument of the callback.
|
||||
//
|
||||
// This constant can be changed by using go.mod's replace directive for
|
||||
// debugging purposes.
|
||||
const ClosureCheckReceiver = false
|
||||
|
||||
func (v *Object) connectClosure(after bool, detailedSignal string, f interface{}) SignalHandle {
|
||||
fs := closure.NewFuncStack(f, 2)
|
||||
|
||||
if ClosureCheckReceiver {
|
||||
// This is a bit slow, but we could be careful.
|
||||
objValue, err := v.goValue()
|
||||
if err == nil {
|
||||
fsType := fs.Func.Type()
|
||||
if fsType.NumIn() < 1 {
|
||||
fs.Panicf("callback should have the object receiver to avoid circular references")
|
||||
}
|
||||
objType := reflect.TypeOf(objValue)
|
||||
if first := fsType.In(0); !objType.ConvertibleTo(first) {
|
||||
fs.Panicf("receiver not convertible to expected type %s, got %s", objType, first)
|
||||
}
|
||||
}
|
||||
|
||||
// Allow the type check to fail if we can't get a value marshaler. This
|
||||
// rarely happens, but it might, and we want to at least allow working
|
||||
// around it.
|
||||
}
|
||||
|
||||
cstr := C.CString(detailedSignal)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
gclosure := ClosureNewFunc(fs)
|
||||
c := C.g_signal_connect_closure(C.gpointer(v.native()), (*C.gchar)(cstr), gclosure, gbool(after))
|
||||
|
||||
// TODO: There's a slight race condition here, where
|
||||
// g_signal_connect_closure may trigger signal callbacks before the signal
|
||||
// is registered. It is therefore ideal to have another intermediate ID to
|
||||
// pass into the connect function. This is not a big issue though, since
|
||||
// there isn't really any guarantee that signals should arrive until after
|
||||
// the Connect functions return successfully.
|
||||
closure.RegisterSignal(uint(c), unsafe.Pointer(gclosure))
|
||||
|
||||
return SignalHandle(c)
|
||||
}
|
||||
|
||||
// ClosureNew creates a new GClosure and adds its callback function to the
|
||||
// internal registry. It's exported for visibility to other gotk3 packages and
|
||||
// should not be used in a regular application.
|
||||
func ClosureNew(f interface{}) *C.GClosure {
|
||||
return ClosureNewFunc(closure.NewFuncStack(f, 2))
|
||||
}
|
||||
|
||||
// ClosureNewFunc creates a new GClosure and adds its callback function to the
|
||||
// internal registry. It's exported for visibility to other gotk3 packages; it
|
||||
// cannot be used in application code, as package closure is part of the
|
||||
// internals.
|
||||
func ClosureNewFunc(funcStack closure.FuncStack) *C.GClosure {
|
||||
gclosure := C._g_closure_new()
|
||||
closure.Assign(unsafe.Pointer(gclosure), funcStack)
|
||||
|
||||
return gclosure
|
||||
}
|
||||
|
||||
// removeClosure removes a closure from the internal closures map. This is
|
||||
// needed to prevent a leak where Go code can access the closure context
|
||||
// (along with rf and userdata) even after an object has been destroyed and
|
||||
// the GClosure is invalidated and will never run.
|
||||
//
|
||||
//export removeClosure
|
||||
func removeClosure(_ C.gpointer, gclosure *C.GClosure) {
|
||||
closure.Delete(unsafe.Pointer(gclosure))
|
||||
}
|
||||
14
third_party/gotk3/glib/finalizers.go
vendored
Normal file
14
third_party/gotk3/glib/finalizers.go
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package glib
|
||||
|
||||
// Finalizer is a function that when called will finalize an object
|
||||
type Finalizer func()
|
||||
|
||||
// FinalizerStrategy will be called by every runtime finalizer in gotk3
|
||||
// The simple version will just call the finalizer given as an argument
|
||||
// but in larger programs this might cause problems with the UI thread.
|
||||
// The FinalizerStrategy function will always be called in the goroutine that
|
||||
// `runtime.SetFinalizer` uses. It is a `var` to explicitly allow clients to
|
||||
// change the strategy to something more advanced.
|
||||
var FinalizerStrategy = func(f Finalizer) {
|
||||
f()
|
||||
}
|
||||
227
third_party/gotk3/glib/gaction.go
vendored
Normal file
227
third_party/gotk3/glib/gaction.go
vendored
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
tm := []TypeMarshaler{
|
||||
// Objects/Interfaces
|
||||
{Type(C.g_simple_action_get_type()), marshalSimpleAction},
|
||||
{Type(C.g_action_get_type()), marshalAction},
|
||||
{Type(C.g_property_action_get_type()), marshalPropertyAction},
|
||||
}
|
||||
RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
// Action is a representation of glib's GAction GInterface.
|
||||
type Action struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// IAction is an interface type implemented by all structs
|
||||
// embedding an Action. It is meant to be used as an argument type
|
||||
// for wrapper functions that wrap around a C function taking a
|
||||
// GAction.
|
||||
type IAction interface {
|
||||
toGAction() *C.GAction
|
||||
toAction() *Action
|
||||
}
|
||||
|
||||
func (v *Action) toGAction() *C.GAction {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return v.native()
|
||||
}
|
||||
|
||||
func (v *Action) toAction() *Action {
|
||||
return v
|
||||
}
|
||||
|
||||
// gboolean g_action_parse_detailed_name (const gchar *detailed_name, gchar **action_name, GVariant **target_value, GError **error);
|
||||
|
||||
// ActionPrintDetailedName is a wrapper around g_action_print_detailed_name().
|
||||
func ActionPrintDetailedName(action_name string, target_value *Variant) string {
|
||||
cstr := C.CString(action_name)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
return C.GoString((*C.char)(C.g_action_print_detailed_name((*C.gchar)(cstr), target_value.native())))
|
||||
}
|
||||
|
||||
// native() returns a pointer to the underlying GAction.
|
||||
func (v *Action) native() *C.GAction {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGAction(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func (v *Action) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalAction(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapAction(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapAction(obj *Object) *Action {
|
||||
return &Action{obj}
|
||||
}
|
||||
|
||||
// ActionNameIsValid is a wrapper around g_action_name_is_valid
|
||||
func ActionNameIsValid(actionName string) bool {
|
||||
cstr := (*C.gchar)(C.CString(actionName))
|
||||
return gobool(C.g_action_name_is_valid(cstr))
|
||||
}
|
||||
|
||||
// GetName is a wrapper around g_action_get_name
|
||||
func (v *Action) GetName() string {
|
||||
return C.GoString((*C.char)(C.g_action_get_name(v.native())))
|
||||
}
|
||||
|
||||
// GetEnabled is a wrapper around g_action_get_enabled
|
||||
func (v *Action) GetEnabled() bool {
|
||||
return gobool(C.g_action_get_enabled(v.native()))
|
||||
}
|
||||
|
||||
// GetState is a wrapper around g_action_get_state
|
||||
func (v *Action) GetState() *Variant {
|
||||
c := C.g_action_get_state(v.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariant((*C.GVariant)(c))
|
||||
}
|
||||
|
||||
// GetStateHint is a wrapper around g_action_get_state_hint
|
||||
func (v *Action) GetStateHint() *Variant {
|
||||
c := C.g_action_get_state_hint(v.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariant((*C.GVariant)(c))
|
||||
}
|
||||
|
||||
// GetParameterType is a wrapper around g_action_get_parameter_type
|
||||
func (v *Action) GetParameterType() *VariantType {
|
||||
c := C.g_action_get_parameter_type(v.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariantType((*C.GVariantType)(c))
|
||||
}
|
||||
|
||||
// GetStateType is a wrapper around g_action_get_state_type
|
||||
func (v *Action) GetStateType() *VariantType {
|
||||
c := C.g_action_get_state_type(v.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariantType((*C.GVariantType)(c))
|
||||
}
|
||||
|
||||
// ChangeState is a wrapper around g_action_change_state
|
||||
func (v *Action) ChangeState(value *Variant) {
|
||||
C.g_action_change_state(v.native(), value.native())
|
||||
}
|
||||
|
||||
// Activate is a wrapper around g_action_activate
|
||||
func (v *Action) Activate(parameter *Variant) {
|
||||
C.g_action_activate(v.native(), parameter.native())
|
||||
}
|
||||
|
||||
// SimpleAction is a representation of GSimpleAction
|
||||
type SimpleAction struct {
|
||||
Action
|
||||
}
|
||||
|
||||
func (v *SimpleAction) native() *C.GSimpleAction {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGSimpleAction(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func (v *SimpleAction) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalSimpleAction(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapSimpleAction(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapSimpleAction(obj *Object) *SimpleAction {
|
||||
return &SimpleAction{Action{obj}}
|
||||
}
|
||||
|
||||
// SimpleActionNew is a wrapper around g_simple_action_new
|
||||
func SimpleActionNew(name string, parameterType *VariantType) *SimpleAction {
|
||||
c := C.g_simple_action_new((*C.gchar)(C.CString(name)), parameterType.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapSimpleAction(wrapObject(unsafe.Pointer(c)))
|
||||
}
|
||||
|
||||
// SimpleActionNewStateful is a wrapper around g_simple_action_new_stateful
|
||||
func SimpleActionNewStateful(name string, parameterType *VariantType, state *Variant) *SimpleAction {
|
||||
c := C.g_simple_action_new_stateful((*C.gchar)(C.CString(name)), parameterType.native(), state.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapSimpleAction(wrapObject(unsafe.Pointer(c)))
|
||||
}
|
||||
|
||||
// SetEnabled is a wrapper around g_simple_action_set_enabled
|
||||
func (v *SimpleAction) SetEnabled(enabled bool) {
|
||||
C.g_simple_action_set_enabled(v.native(), gbool(enabled))
|
||||
}
|
||||
|
||||
// SetState is a wrapper around g_simple_action_set_state
|
||||
// This should only be called by the implementor of the action.
|
||||
// Users of the action should not attempt to directly modify the 'state' property.
|
||||
// Instead, they should call ChangeState [g_action_change_state()] to request the change.
|
||||
func (v *SimpleAction) SetState(value *Variant) {
|
||||
C.g_simple_action_set_state(v.native(), value.native())
|
||||
}
|
||||
|
||||
// PropertyAction is a representation of GPropertyAction
|
||||
type PropertyAction struct {
|
||||
Action
|
||||
}
|
||||
|
||||
func (v *PropertyAction) native() *C.GPropertyAction {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGPropertyAction(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func (v *PropertyAction) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalPropertyAction(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapPropertyAction(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapPropertyAction(obj *Object) *PropertyAction {
|
||||
return &PropertyAction{Action{obj}}
|
||||
}
|
||||
|
||||
// PropertyActionNew is a wrapper around g_property_action_new
|
||||
func PropertyActionNew(name string, object *Object, propertyName string) *PropertyAction {
|
||||
c := C.g_property_action_new((*C.gchar)(C.CString(name)), C.gpointer(unsafe.Pointer(object.native())), (*C.gchar)(C.CString(propertyName)))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapPropertyAction(wrapObject(unsafe.Pointer(c)))
|
||||
}
|
||||
113
third_party/gotk3/glib/gactiongroup.go
vendored
Normal file
113
third_party/gotk3/glib/gactiongroup.go
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// IActionGroup is an interface representation of ActionGroup,
|
||||
// used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
|
||||
type IActionGroup interface {
|
||||
Native() uintptr
|
||||
|
||||
HasAction(actionName string) bool
|
||||
GetActionEnabled(actionName string) bool
|
||||
GetActionParameterType(actionName string) *VariantType
|
||||
GetActionStateType(actionName string) *VariantType
|
||||
GetActionState(actionName string) *Variant
|
||||
GetActionStateHint(actionName string) *Variant
|
||||
ChangeActionState(actionName string, value *Variant)
|
||||
Activate(actionName string, parameter *Variant)
|
||||
}
|
||||
|
||||
// ActionGroup is a representation of glib's GActionGroup GInterface
|
||||
type ActionGroup struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// g_action_group_list_actions()
|
||||
// g_action_group_query_action()
|
||||
// should only called from implementations:
|
||||
// g_action_group_action_added
|
||||
// g_action_group_action_removed
|
||||
// g_action_group_action_enabled_changed
|
||||
// g_action_group_action_state_changed
|
||||
|
||||
// native() returns a pointer to the underlying GActionGroup.
|
||||
func (v *ActionGroup) native() *C.GActionGroup {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGActionGroup(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func (v *ActionGroup) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalActionGroup(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapActionGroup(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapActionGroup(obj *Object) *ActionGroup {
|
||||
return &ActionGroup{obj}
|
||||
}
|
||||
|
||||
// HasAction is a wrapper around g_action_group_has_action().
|
||||
func (v *ActionGroup) HasAction(actionName string) bool {
|
||||
return gobool(C.g_action_group_has_action(v.native(), (*C.gchar)(C.CString(actionName))))
|
||||
}
|
||||
|
||||
// GetActionEnabled is a wrapper around g_action_group_get_action_enabled().
|
||||
func (v *ActionGroup) GetActionEnabled(actionName string) bool {
|
||||
return gobool(C.g_action_group_get_action_enabled(v.native(), (*C.gchar)(C.CString(actionName))))
|
||||
}
|
||||
|
||||
// GetActionParameterType is a wrapper around g_action_group_get_action_parameter_type().
|
||||
func (v *ActionGroup) GetActionParameterType(actionName string) *VariantType {
|
||||
c := C.g_action_group_get_action_parameter_type(v.native(), (*C.gchar)(C.CString(actionName)))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariantType((*C.GVariantType)(c))
|
||||
}
|
||||
|
||||
// GetActionStateType is a wrapper around g_action_group_get_action_state_type().
|
||||
func (v *ActionGroup) GetActionStateType(actionName string) *VariantType {
|
||||
c := C.g_action_group_get_action_state_type(v.native(), (*C.gchar)(C.CString(actionName)))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariantType((*C.GVariantType)(c))
|
||||
}
|
||||
|
||||
// GetActionState is a wrapper around g_action_group_get_action_state().
|
||||
func (v *ActionGroup) GetActionState(actionName string) *Variant {
|
||||
c := C.g_action_group_get_action_state(v.native(), (*C.gchar)(C.CString(actionName)))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariant((*C.GVariant)(c))
|
||||
}
|
||||
|
||||
// GetActionStateHint is a wrapper around g_action_group_get_action_state_hint().
|
||||
func (v *ActionGroup) GetActionStateHint(actionName string) *Variant {
|
||||
c := C.g_action_group_get_action_state_hint(v.native(), (*C.gchar)(C.CString(actionName)))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return newVariant((*C.GVariant)(c))
|
||||
}
|
||||
|
||||
// ChangeActionState is a wrapper around g_action_group_change_action_state
|
||||
func (v *ActionGroup) ChangeActionState(actionName string, value *Variant) {
|
||||
C.g_action_group_change_action_state(v.native(), (*C.gchar)(C.CString(actionName)), value.native())
|
||||
}
|
||||
|
||||
// Activate is a wrapper around g_action_group_activate_action
|
||||
func (v *ActionGroup) Activate(actionName string, parameter *Variant) {
|
||||
C.g_action_group_activate_action(v.native(), (*C.gchar)(C.CString(actionName)), parameter.native())
|
||||
}
|
||||
66
third_party/gotk3/glib/gactionmap.go
vendored
Normal file
66
third_party/gotk3/glib/gactionmap.go
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// IActionMap is an interface representation of ActionMap,
|
||||
// used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
|
||||
type IActionMap interface {
|
||||
Native() uintptr
|
||||
|
||||
LookupAction(actionName string) *Action
|
||||
AddAction(action IAction)
|
||||
RemoveAction(actionName string)
|
||||
}
|
||||
|
||||
// ActionMap is a representation of glib's GActionMap GInterface
|
||||
type ActionMap struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// void g_action_map_add_action_entries (GActionMap *action_map, const GActionEntry *entries, gint n_entries, gpointer user_data);
|
||||
// struct GActionEntry
|
||||
|
||||
// native() returns a pointer to the underlying GActionMap.
|
||||
func (v *ActionMap) native() *C.GActionMap {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGActionMap(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func (v *ActionMap) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalActionMap(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapActionMap(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapActionMap(obj *Object) *ActionMap {
|
||||
return &ActionMap{obj}
|
||||
}
|
||||
|
||||
// LookupAction is a wrapper around g_action_map_lookup_action
|
||||
func (v *ActionMap) LookupAction(actionName string) *Action {
|
||||
c := C.g_action_map_lookup_action(v.native(), (*C.gchar)(C.CString(actionName)))
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapAction(wrapObject(unsafe.Pointer(c)))
|
||||
}
|
||||
|
||||
// AddAction is a wrapper around g_action_map_add_action
|
||||
func (v *ActionMap) AddAction(action IAction) {
|
||||
C.g_action_map_add_action(v.native(), action.toGAction())
|
||||
}
|
||||
|
||||
// RemoveAction is a wrapper around g_action_map_remove_action
|
||||
func (v *ActionMap) RemoveAction(actionName string) {
|
||||
C.g_action_map_remove_action(v.native(), (*C.gchar)(C.CString(actionName)))
|
||||
}
|
||||
73
third_party/gotk3/glib/gasyncresult.go
vendored
Normal file
73
third_party/gotk3/glib/gasyncresult.go
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// IAsyncResult is an interface representation of AsyncResult,
|
||||
// used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
|
||||
type IAsyncResult interface {
|
||||
GetUserData() uintptr
|
||||
GetSourceObject() *Object
|
||||
IsTagged(sourceTag uintptr) bool
|
||||
LegacyPropagateError() error
|
||||
}
|
||||
|
||||
// AsyncReadyCallback is a representation of GAsyncReadyCallback
|
||||
type AsyncReadyCallback func(object *Object, res *AsyncResult)
|
||||
|
||||
// AsyncResult is a representation of GIO's GAsyncResult.
|
||||
type AsyncResult struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native() returns a pointer to the underlying GAsyncResult.
|
||||
func (v *AsyncResult) native() *C.GAsyncResult {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGAsyncResult(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func wrapAsyncResult(obj *Object) *AsyncResult {
|
||||
return &AsyncResult{obj}
|
||||
}
|
||||
|
||||
// GetUserData is a wrapper around g_async_result_get_user_data()
|
||||
func (v *AsyncResult) GetUserData() uintptr {
|
||||
c := C.g_async_result_get_user_data(v.native())
|
||||
return uintptr(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
// GetSourceObject is a wrapper around g_async_result_get_source_object
|
||||
func (v *AsyncResult) GetSourceObject() *Object {
|
||||
obj := C.g_async_result_get_source_object(v.native())
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapObject(unsafe.Pointer(obj))
|
||||
}
|
||||
|
||||
// IsTagged is a wrapper around g_async_result_is_tagged
|
||||
func (v *AsyncResult) IsTagged(sourceTag uintptr) bool {
|
||||
c := C.g_async_result_is_tagged(v.native(), C.gpointer(sourceTag))
|
||||
return gobool(c)
|
||||
}
|
||||
|
||||
// LegacyPropagateError is a wrapper around g_async_result_legacy_propagate_error
|
||||
func (v *AsyncResult) LegacyPropagateError() error {
|
||||
var err *C.GError
|
||||
c := C.g_async_result_legacy_propagate_error(v.native(), &err)
|
||||
isSimpleAsyncResult := gobool(c)
|
||||
if isSimpleAsyncResult {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
73
third_party/gotk3/glib/gbinding.go
vendored
Normal file
73
third_party/gotk3/glib/gbinding.go
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
type BindingFlags int
|
||||
|
||||
const (
|
||||
BINDING_DEFAULT BindingFlags = C.G_BINDING_DEFAULT
|
||||
BINDING_BIDIRECTIONAL BindingFlags = C.G_BINDING_BIDIRECTIONAL
|
||||
BINDING_SYNC_CREATE = C.G_BINDING_SYNC_CREATE
|
||||
BINDING_INVERT_BOOLEAN = C.G_BINDING_INVERT_BOOLEAN
|
||||
)
|
||||
|
||||
type Binding struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
func (v *Binding) native() *C.GBinding {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toGBinding(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func marshalBinding(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return &Binding{wrapObject(unsafe.Pointer(c))}, nil
|
||||
}
|
||||
|
||||
// Creates a binding between source property on source and target property on
|
||||
// target . Whenever the source property is changed the target_property is
|
||||
// updated using the same value.
|
||||
func BindProperty(source *Object, sourceProperty string,
|
||||
target *Object, targetProperty string,
|
||||
flags BindingFlags) *Binding {
|
||||
srcStr := (*C.gchar)(C.CString(sourceProperty))
|
||||
defer C.free(unsafe.Pointer(srcStr))
|
||||
tgtStr := (*C.gchar)(C.CString(targetProperty))
|
||||
defer C.free(unsafe.Pointer(tgtStr))
|
||||
obj := C.g_object_bind_property(
|
||||
C.gpointer(source.GObject), srcStr,
|
||||
C.gpointer(target.GObject), tgtStr,
|
||||
C.GBindingFlags(flags),
|
||||
)
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
return &Binding{wrapObject(unsafe.Pointer(obj))}
|
||||
}
|
||||
|
||||
// Explicitly releases the binding between the source and the target property
|
||||
// expressed by Binding
|
||||
func (v *Binding) Unbind() {
|
||||
C.g_binding_unbind(v.native())
|
||||
}
|
||||
|
||||
// Retrieves the name of the property of “target” used as the target of
|
||||
// the binding.
|
||||
func (v *Binding) GetTargetProperty() string {
|
||||
s := C.g_binding_get_target_property(v.native())
|
||||
return C.GoString((*C.char)(s))
|
||||
}
|
||||
|
||||
// Retrieves the flags passed when constructing the GBinding.
|
||||
func (v *Binding) GetFlags() BindingFlags {
|
||||
flags := C.g_binding_get_flags(v.native())
|
||||
return BindingFlags(flags)
|
||||
}
|
||||
28
third_party/gotk3/glib/gbinding_deprecated_since_2_68.go
vendored
Normal file
28
third_party/gotk3/glib/gbinding_deprecated_since_2_68.go
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// +build glib_deprecated
|
||||
|
||||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// GetSource is a wrapper around g_binding_get_source().
|
||||
func (v *Binding) GetSource() *Object {
|
||||
obj := C.g_binding_get_source(v.native())
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapObject(unsafe.Pointer(obj))
|
||||
}
|
||||
|
||||
// GetTarget is a wrapper around g_binding_get_target().
|
||||
func (v *Binding) GetTarget() *Object {
|
||||
obj := C.g_binding_get_target(v.native())
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapObject(unsafe.Pointer(obj))
|
||||
}
|
||||
29
third_party/gotk3/glib/gbinding_since_2_68.go
vendored
Normal file
29
third_party/gotk3/glib/gbinding_since_2_68.go
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
//go:build !glib_deprecated && !glib_2_40 && !glib_2_42 && !glib_2_44 && !glib_2_46 && !glib_2_48 && !glib_2_50 && !glib_2_52 && !glib_2_54 && !glib_2_56 && !glib_2_58 && !glib_2_60 && !glib_2_62 && !glib_2_64 && !glib_2_66
|
||||
// +build !glib_deprecated,!glib_2_40,!glib_2_42,!glib_2_44,!glib_2_46,!glib_2_48,!glib_2_50,!glib_2_52,!glib_2_54,!glib_2_56,!glib_2_58,!glib_2_60,!glib_2_62,!glib_2_64,!glib_2_66
|
||||
|
||||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// DupSource is a wrapper around g_binding_dup_source().
|
||||
func (v *Binding) DupSource() *Object {
|
||||
obj := C.g_binding_dup_source(v.native())
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapObject(unsafe.Pointer(obj))
|
||||
}
|
||||
|
||||
// DupTarget is a wrapper around g_binding_dup_target().
|
||||
func (v *Binding) DupTarget() *Object {
|
||||
obj := C.g_binding_dup_target(v.native())
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapObject(unsafe.Pointer(obj))
|
||||
}
|
||||
93
third_party/gotk3/glib/gcancellable.go
vendored
Normal file
93
third_party/gotk3/glib/gcancellable.go
vendored
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Cancellable is a representation of GIO's GCancellable.
|
||||
type Cancellable struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GCancellable.
|
||||
func (v *Cancellable) native() *C.GCancellable {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
return C.toCancellable(unsafe.Pointer(v.GObject))
|
||||
}
|
||||
|
||||
func marshalCancellable(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
return wrapCancellable(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
func wrapCancellable(obj *Object) *Cancellable {
|
||||
return &Cancellable{obj}
|
||||
}
|
||||
|
||||
// CancellableNew is a wrapper around g_cancellable_new().
|
||||
func CancellableNew() (*Cancellable, error) {
|
||||
c := C.g_cancellable_new()
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return wrapCancellable(wrapObject(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
// IsCancelled is a wrapper around g_cancellable_is_cancelled().
|
||||
func (v *Cancellable) IsCancelled() bool {
|
||||
c := C.g_cancellable_is_cancelled(v.native())
|
||||
return gobool(c)
|
||||
}
|
||||
|
||||
// SetErrorIfCancelled is a wrapper around g_cancellable_set_error_if_cancelled().
|
||||
func (v *Cancellable) SetErrorIfCancelled() error {
|
||||
var err *C.GError
|
||||
c := C.g_cancellable_set_error_if_cancelled(v.native(), &err)
|
||||
cancelled := gobool(c)
|
||||
if cancelled {
|
||||
defer C.g_error_free(err)
|
||||
return errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFD is a wrapper around g_cancellable_get_fd().
|
||||
func (v *Cancellable) GetFD() int {
|
||||
c := C.g_cancellable_get_fd(v.native())
|
||||
return int(c)
|
||||
}
|
||||
|
||||
// MakePollFD is a wrapper around g_cancellable_make_pollfd().
|
||||
// func (v *Cancellable) MakePollFD(pollFD *PollFD) bool {
|
||||
// c := C.g_cancellable_make_pollfd(v.native(), )
|
||||
// return gobool(c)
|
||||
// }
|
||||
|
||||
// ReleaseFD is a wrapper around g_cancellable_release_fd().
|
||||
func (v *Cancellable) ReleaseFD() {
|
||||
C.g_cancellable_release_fd(v.native())
|
||||
}
|
||||
|
||||
// SourceNew is a wrapper around g_cancellable_source_new().
|
||||
func (v *Cancellable) SourceNew() *Source {
|
||||
c := C.g_cancellable_source_new(v.native())
|
||||
return wrapSource(c)
|
||||
}
|
||||
|
||||
// Reset is a wrapper around g_cancellable_reset().
|
||||
func (v *Cancellable) Reset() {
|
||||
C.g_cancellable_reset(v.native())
|
||||
}
|
||||
|
||||
// Cancel is a wrapper around g_cancellable_cancel().
|
||||
func (v *Cancellable) Cancel() {
|
||||
C.g_cancellable_cancel(v.native())
|
||||
}
|
||||
367
third_party/gotk3/glib/gfile.go
vendored
Normal file
367
third_party/gotk3/glib/gfile.go
vendored
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
// #include "gfile.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
tm := []TypeMarshaler{
|
||||
{Type(C.g_file_get_type()), marshalFile},
|
||||
{Type(C.g_file_input_stream_get_type()), marshalFileInputStream},
|
||||
{Type(C.g_file_output_stream_get_type()), marshalFileOutputStream},
|
||||
}
|
||||
|
||||
RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
func goString(cstr *C.gchar) string {
|
||||
return C.GoString((*C.char)(cstr))
|
||||
}
|
||||
|
||||
/*
|
||||
* GFile
|
||||
*/
|
||||
|
||||
// File is a representation of GIO's GFile.
|
||||
type File struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GFile.
|
||||
func (v *File) native() *C.GFile {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFile(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *File) NativePrivate() *C.GFile {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFile(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GFile.
|
||||
func (v *File) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalFile(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapFile(obj), nil
|
||||
}
|
||||
|
||||
func wrapFile(obj *Object) *File {
|
||||
return &File{obj}
|
||||
}
|
||||
|
||||
// FileNew is a wrapper around g_file_new_for_path().
|
||||
// To avoid breaking previous implementation of GFile ...
|
||||
func FileNew(path string) *File {
|
||||
f, e := FileNewForPath(path)
|
||||
if e != nil {
|
||||
return nil
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// FileNewForPath is a wrapper around g_file_new_for_path().
|
||||
func FileNewForPath(path string) (*File, error) {
|
||||
cstr := (*C.char)(C.CString(path))
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
c := C.g_file_new_for_path(cstr)
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return wrapFile(Take(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
// TODO g_file_*** and more
|
||||
/*
|
||||
void (*GFileProgressCallback) ()
|
||||
gboolean (*GFileReadMoreCallback) ()
|
||||
void (*GFileMeasureProgressCallback) ()
|
||||
GFile * g_file_new_for_uri ()
|
||||
GFile * g_file_new_for_commandline_arg ()
|
||||
GFile * g_file_new_for_commandline_arg_and_cwd ()
|
||||
GFile * g_file_new_tmp ()
|
||||
GFile * g_file_parse_name ()
|
||||
GFile * g_file_new_build_filename ()
|
||||
GFile * g_file_dup ()
|
||||
guint g_file_hash ()
|
||||
gboolean g_file_equal ()
|
||||
char * g_file_get_basename ()
|
||||
*/
|
||||
|
||||
/*
|
||||
char *
|
||||
g_file_get_path (GFile *file);
|
||||
*/
|
||||
// GetPath is a wrapper around g_file_get_path().
|
||||
func (v *File) GetPath() string {
|
||||
var s string
|
||||
if c := C.g_file_get_path(v.native()); c != nil {
|
||||
s = C.GoString(c)
|
||||
defer C.g_free((C.gpointer)(c))
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
/*
|
||||
const char * g_file_peek_path ()
|
||||
char * g_file_get_uri ()
|
||||
char * g_file_get_parse_name ()
|
||||
GFile * g_file_get_parent ()
|
||||
gboolean g_file_has_parent ()
|
||||
GFile * g_file_get_child ()
|
||||
GFile * g_file_get_child_for_display_name ()
|
||||
gboolean g_file_has_prefix ()
|
||||
char * g_file_get_relative_path ()
|
||||
GFile * g_file_resolve_relative_path ()
|
||||
gboolean g_file_is_native ()
|
||||
gboolean g_file_has_uri_scheme ()
|
||||
char * g_file_get_uri_scheme ()
|
||||
*/
|
||||
|
||||
/*
|
||||
GFileInputStream *
|
||||
g_file_read (GFile *file,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
*/
|
||||
// Read is a wrapper around g_file_read().
|
||||
// Object.Unref() must be used after use
|
||||
func (v *File) Read(cancellable *Cancellable) (*FileInputStream, error) {
|
||||
var gerr *C.GError
|
||||
c := C.g_file_read(
|
||||
v.native(),
|
||||
cancellable.native(),
|
||||
&gerr)
|
||||
if c == nil {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, errors.New(goString(gerr.message))
|
||||
}
|
||||
return wrapFileInputStream(Take(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
/*
|
||||
void g_file_read_async ()
|
||||
GFileInputStream * g_file_read_finish ()
|
||||
GFileOutputStream * g_file_append_to ()
|
||||
GFileOutputStream * g_file_create ()
|
||||
GFileOutputStream * g_file_replace ()
|
||||
void g_file_append_to_async ()
|
||||
GFileOutputStream * g_file_append_to_finish ()
|
||||
void g_file_create_async ()
|
||||
GFileOutputStream * g_file_create_finish ()
|
||||
void g_file_replace_async ()
|
||||
GFileOutputStream * g_file_replace_finish ()
|
||||
GFileInfo * g_file_query_info ()
|
||||
void g_file_query_info_async ()
|
||||
GFileInfo * g_file_query_info_finish ()
|
||||
gboolean g_file_query_exists ()
|
||||
GFileType g_file_query_file_type ()
|
||||
GFileInfo * g_file_query_filesystem_info ()
|
||||
void g_file_query_filesystem_info_async ()
|
||||
GFileInfo * g_file_query_filesystem_info_finish ()
|
||||
GAppInfo * g_file_query_default_handler ()
|
||||
void g_file_query_default_handler_async ()
|
||||
GAppInfo * g_file_query_default_handler_finish ()
|
||||
gboolean g_file_measure_disk_usage ()
|
||||
void g_file_measure_disk_usage_async ()
|
||||
gboolean g_file_measure_disk_usage_finish ()
|
||||
GMount * g_file_find_enclosing_mount ()
|
||||
void g_file_find_enclosing_mount_async ()
|
||||
GMount * g_file_find_enclosing_mount_finish ()
|
||||
GFileEnumerator * g_file_enumerate_children ()
|
||||
void g_file_enumerate_children_async ()
|
||||
GFileEnumerator * g_file_enumerate_children_finish ()
|
||||
GFile * g_file_set_display_name ()
|
||||
void g_file_set_display_name_async ()
|
||||
GFile * g_file_set_display_name_finish ()
|
||||
gboolean g_file_delete ()
|
||||
void g_file_delete_async ()
|
||||
gboolean g_file_delete_finish ()
|
||||
gboolean g_file_trash ()
|
||||
void g_file_trash_async ()
|
||||
gboolean g_file_trash_finish ()
|
||||
gboolean g_file_copy ()
|
||||
void g_file_copy_async ()
|
||||
gboolean g_file_copy_finish ()
|
||||
gboolean g_file_move ()
|
||||
gboolean g_file_make_directory ()
|
||||
void g_file_make_directory_async ()
|
||||
gboolean g_file_make_directory_finish ()
|
||||
gboolean g_file_make_directory_with_parents ()
|
||||
gboolean g_file_make_symbolic_link ()
|
||||
GFileAttributeInfoList * g_file_query_settable_attributes ()
|
||||
GFileAttributeInfoList * g_file_query_writable_namespaces ()
|
||||
gboolean g_file_set_attribute ()
|
||||
gboolean g_file_set_attributes_from_info ()
|
||||
void g_file_set_attributes_async ()
|
||||
gboolean g_file_set_attributes_finish ()
|
||||
gboolean g_file_set_attribute_string ()
|
||||
gboolean g_file_set_attribute_byte_string ()
|
||||
gboolean g_file_set_attribute_uint32 ()
|
||||
gboolean g_file_set_attribute_int32 ()
|
||||
gboolean g_file_set_attribute_uint64 ()
|
||||
gboolean g_file_set_attribute_int64 ()
|
||||
void g_file_mount_mountable ()
|
||||
GFile * g_file_mount_mountable_finish ()
|
||||
void g_file_unmount_mountable ()
|
||||
gboolean g_file_unmount_mountable_finish ()
|
||||
void g_file_unmount_mountable_with_operation ()
|
||||
gboolean g_file_unmount_mountable_with_operation_finish ()
|
||||
void g_file_eject_mountable ()
|
||||
gboolean g_file_eject_mountable_finish ()
|
||||
void g_file_eject_mountable_with_operation ()
|
||||
gboolean g_file_eject_mountable_with_operation_finish ()
|
||||
void g_file_start_mountable ()
|
||||
gboolean g_file_start_mountable_finish ()
|
||||
void g_file_stop_mountable ()
|
||||
gboolean g_file_stop_mountable_finish ()
|
||||
void g_file_poll_mountable ()
|
||||
gboolean g_file_poll_mountable_finish ()
|
||||
void g_file_mount_enclosing_volume ()
|
||||
gboolean g_file_mount_enclosing_volume_finish ()
|
||||
GFileMonitor * g_file_monitor_directory ()
|
||||
GFileMonitor * g_file_monitor_file ()
|
||||
GFileMonitor * g_file_monitor ()
|
||||
GBytes * g_file_load_bytes ()
|
||||
void g_file_load_bytes_async ()
|
||||
GBytes * g_file_load_bytes_finish ()
|
||||
gboolean g_file_load_contents ()
|
||||
void g_file_load_contents_async ()
|
||||
gboolean g_file_load_contents_finish ()
|
||||
void g_file_load_partial_contents_async ()
|
||||
gboolean g_file_load_partial_contents_finish ()
|
||||
gboolean g_file_replace_contents ()
|
||||
void g_file_replace_contents_async ()
|
||||
void g_file_replace_contents_bytes_async ()
|
||||
gboolean g_file_replace_contents_finish ()
|
||||
gboolean g_file_copy_attributes ()
|
||||
GFileIOStream * g_file_create_readwrite ()
|
||||
void g_file_create_readwrite_async ()
|
||||
GFileIOStream * g_file_create_readwrite_finish ()
|
||||
GFileIOStream * g_file_open_readwrite ()
|
||||
void g_file_open_readwrite_async ()
|
||||
GFileIOStream * g_file_open_readwrite_finish ()
|
||||
GFileIOStream * g_file_replace_readwrite ()
|
||||
void g_file_replace_readwrite_async ()
|
||||
GFileIOStream * g_file_replace_readwrite_finish ()
|
||||
gboolean g_file_supports_thread_contexts ()
|
||||
*/
|
||||
|
||||
/*
|
||||
* GFileInputStream
|
||||
*/
|
||||
|
||||
// FileInputStream is a representation of GIO's GFileInputStream.
|
||||
type FileInputStream struct {
|
||||
*InputStream
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GFileInputStream.
|
||||
func (v *FileInputStream) native() *C.GFileInputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFileInputStream(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *FileInputStream) NativePrivate() *C.GFileInputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFileInputStream(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GFileInputStream.
|
||||
func (v *FileInputStream) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalFileInputStream(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapFileInputStream(obj), nil
|
||||
}
|
||||
|
||||
func wrapFileInputStream(obj *Object) *FileInputStream {
|
||||
return &FileInputStream{wrapInputStream(obj)}
|
||||
}
|
||||
|
||||
// TODO g_file_input_stream_query_info and more
|
||||
/*
|
||||
GFileInfo * g_file_input_stream_query_info ()
|
||||
void g_file_input_stream_query_info_async ()
|
||||
GFileInfo * g_file_input_stream_query_info_finish ()
|
||||
*/
|
||||
|
||||
/*
|
||||
* GFileOutputStream
|
||||
*/
|
||||
|
||||
// FileOutputStream is a representation of GIO's GFileOutputStream.
|
||||
type FileOutputStream struct {
|
||||
*OutputStream
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GFileOutputStream.
|
||||
func (v *FileOutputStream) native() *C.GFileOutputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFileOutputStream(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *FileOutputStream) NativePrivate() *C.GFileOutputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFileOutputStream(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GFileOutputStream.
|
||||
func (v *FileOutputStream) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalFileOutputStream(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapFileOutputStream(obj), nil
|
||||
}
|
||||
|
||||
func wrapFileOutputStream(obj *Object) *FileOutputStream {
|
||||
return &FileOutputStream{wrapOutputStream(obj)}
|
||||
}
|
||||
|
||||
// TODO g_file_output_stream_query_info and more
|
||||
/*
|
||||
GFileInfo * g_file_output_stream_query_info ()
|
||||
void g_file_output_stream_query_info_async ()
|
||||
GFileInfo * g_file_output_stream_query_info_finish ()
|
||||
char * g_file_output_stream_get_etag ()
|
||||
*/
|
||||
13
third_party/gotk3/glib/gfile.go.h
vendored
Normal file
13
third_party/gotk3/glib/gfile.go.h
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
static GFileInputStream *toGFileInputStream(void *p) {
|
||||
return (G_FILE_INPUT_STREAM(p));
|
||||
}
|
||||
|
||||
static GFileOutputStream *toGFileOutputStream(void *p) {
|
||||
return (G_FILE_OUTPUT_STREAM(p));
|
||||
}
|
||||
177
third_party/gotk3/glib/gicon.go
vendored
Normal file
177
third_party/gotk3/glib/gicon.go
vendored
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
tm := []TypeMarshaler{
|
||||
{Type(C.g_file_get_type()), marshalFile},
|
||||
{Type(C.g_file_icon_get_type()), marshalFileIcon},
|
||||
}
|
||||
|
||||
RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
/*
|
||||
* GIcon
|
||||
*/
|
||||
|
||||
// Icon is a representation of GIO's GIcon.
|
||||
// Interface for icons
|
||||
type Icon struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GIcon.
|
||||
func (v *Icon) native() *C.GIcon {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGIcon(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *Icon) NativePrivate() *C.GIcon {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGIcon(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GIcon.
|
||||
func (v *Icon) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalIcon(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapIcon(obj), nil
|
||||
}
|
||||
|
||||
func wrapIcon(obj *Object) *Icon {
|
||||
return &Icon{obj}
|
||||
}
|
||||
|
||||
// TODO I dont know how to handle it ...
|
||||
/*
|
||||
guint
|
||||
g_icon_hash (gconstpointer icon);
|
||||
*/
|
||||
|
||||
// Equal is a wrapper around g_icon_equal().
|
||||
func (v *Icon) Equal(icon *Icon) bool {
|
||||
return gobool(C.g_icon_equal(v.native(), icon.native()))
|
||||
}
|
||||
|
||||
// ToString is a wrapper around g_icon_to_string().
|
||||
func (v *Icon) ToString() string {
|
||||
var s string
|
||||
if c := C.g_icon_to_string(v.native()); c != nil {
|
||||
s = goString(c)
|
||||
defer C.g_free((C.gpointer)(c))
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// IconNewForString is a wrapper around g_icon_new_for_string().
|
||||
func IconNewForString(str string) (*Icon, error) {
|
||||
cstr := C.CString(str)
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
|
||||
var err *C.GError
|
||||
c := C.g_icon_new_for_string((*C.gchar)(cstr), &err)
|
||||
if c == nil {
|
||||
defer C.g_error_free(err)
|
||||
return nil, errors.New(C.GoString((*C.char)(err.message)))
|
||||
}
|
||||
|
||||
obj := &Object{ToGObject(unsafe.Pointer(c))}
|
||||
i := &Icon{obj}
|
||||
|
||||
runtime.SetFinalizer(i, func(_ interface{}) { FinalizerStrategy(obj.Unref) })
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// TODO Requiere GVariant
|
||||
/*
|
||||
GVariant * g_icon_serialize ()
|
||||
GIcon * g_icon_deserialize ()
|
||||
*/
|
||||
|
||||
/*
|
||||
* GFileIcon
|
||||
*/
|
||||
|
||||
// FileIcon is a representation of GIO's GFileIcon.
|
||||
type FileIcon struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GFileIcon.
|
||||
func (v *FileIcon) native() *C.GFileIcon {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFileIcon(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *FileIcon) NativePrivate() *C.GFileIcon {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGFileIcon(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GFileIcon.
|
||||
func (v *FileIcon) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalFileIcon(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapFileIcon(obj), nil
|
||||
}
|
||||
|
||||
func wrapFileIcon(obj *Object) *FileIcon {
|
||||
return &FileIcon{obj}
|
||||
}
|
||||
|
||||
// FileIconNewN is a wrapper around g_file_icon_new().
|
||||
// This version respect Gtk3 documentation.
|
||||
func FileIconNewN(file *File) (*Icon, error) {
|
||||
|
||||
c := C.g_file_icon_new(file.native())
|
||||
if c == nil {
|
||||
return nil, nilPtrErr
|
||||
}
|
||||
return wrapIcon(Take(unsafe.Pointer(c))), nil
|
||||
}
|
||||
|
||||
// FileIconNew is a wrapper around g_file_icon_new().
|
||||
// To not break previous implementation of GFileIcon ...
|
||||
func FileIconNew(path string) *Icon {
|
||||
file := FileNew(path)
|
||||
|
||||
c := C.g_file_icon_new(file.native())
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return wrapIcon(Take(unsafe.Pointer(c)))
|
||||
}
|
||||
437
third_party/gotk3/glib/giostream.go
vendored
Normal file
437
third_party/gotk3/glib/giostream.go
vendored
Normal file
|
|
@ -0,0 +1,437 @@
|
|||
package glib
|
||||
|
||||
// #cgo pkg-config: gio-2.0 glib-2.0 gobject-2.0
|
||||
// #include <gio/gio.h>
|
||||
// #include <stdlib.h>
|
||||
// #include "giostream.go.h"
|
||||
import "C"
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
tm := []TypeMarshaler{
|
||||
{Type(C.g_io_stream_get_type()), marshalIOStream},
|
||||
{Type(C.g_output_stream_get_type()), marshalOutputStream},
|
||||
{Type(C.g_input_stream_get_type()), marshalInputStream},
|
||||
}
|
||||
|
||||
RegisterGValueMarshalers(tm)
|
||||
}
|
||||
|
||||
// OutputStreamSpliceFlags is a representation of GTK's GOutputStreamSpliceFlags.
|
||||
type OutputStreamSpliceFlags int
|
||||
|
||||
const (
|
||||
OUTPUT_STREAM_SPLICE_NONE OutputStreamSpliceFlags = C.G_OUTPUT_STREAM_SPLICE_NONE
|
||||
OUTPUT_STREAM_SPLICE_CLOSE_SOURCE = C.G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE
|
||||
OUTPUT_STREAM_SPLICE_CLOSE_TARGET = C.G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET
|
||||
)
|
||||
|
||||
/*
|
||||
* GIOStream
|
||||
*/
|
||||
|
||||
// IOStream is a representation of GIO's GIOStream.
|
||||
// Base class for implementing read/write streams
|
||||
type IOStream struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GIOStream.
|
||||
func (v *IOStream) native() *C.GIOStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGIOStream(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *IOStream) NativePrivate() *C.GIOStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGIOStream(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GIOStream.
|
||||
func (v *IOStream) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalIOStream(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapIOStream(obj), nil
|
||||
}
|
||||
|
||||
func wrapIOStream(obj *Object) *IOStream {
|
||||
return &IOStream{obj}
|
||||
}
|
||||
|
||||
/*
|
||||
GInputStream * g_io_stream_get_input_stream ()
|
||||
GOutputStream * g_io_stream_get_output_stream ()
|
||||
void g_io_stream_splice_async ()
|
||||
gboolean g_io_stream_splice_finish ()
|
||||
*/
|
||||
|
||||
// Close is a wrapper around g_io_stream_close().
|
||||
func (v *IOStream) Close(cancellable *Cancellable) (bool, error) {
|
||||
var gerr *C.GError
|
||||
ok := gobool(C.g_io_stream_close(
|
||||
v.native(),
|
||||
cancellable.native(),
|
||||
&gerr))
|
||||
if !ok {
|
||||
defer C.g_error_free(gerr)
|
||||
return false, errors.New(goString(gerr.message))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
/*
|
||||
void g_io_stream_close_async ()
|
||||
gboolean g_io_stream_close_finish ()
|
||||
gboolean g_io_stream_is_closed ()
|
||||
gboolean g_io_stream_has_pending ()
|
||||
gboolean g_io_stream_set_pending ()
|
||||
void g_io_stream_clear_pending ()
|
||||
*/
|
||||
|
||||
/*
|
||||
* GInputStream
|
||||
*/
|
||||
|
||||
// InputStream is a representation of GIO's GInputStream.
|
||||
// Base class for implementing streaming input
|
||||
type InputStream struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GInputStream.
|
||||
func (v *InputStream) native() *C.GInputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGInputStream(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *InputStream) NativePrivate() *C.GInputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGInputStream(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GInputStream.
|
||||
func (v *InputStream) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalInputStream(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapInputStream(obj), nil
|
||||
}
|
||||
|
||||
func wrapInputStream(obj *Object) *InputStream {
|
||||
return &InputStream{obj}
|
||||
}
|
||||
|
||||
// Read is a wrapper around g_input_stream_read().
|
||||
func (v *InputStream) Read(length uint, cancellable *Cancellable) (*bytes.Buffer, int, error) {
|
||||
var gerr *C.GError
|
||||
var buffer = bytes.NewBuffer(make([]byte, length))
|
||||
|
||||
c := C.g_input_stream_read(
|
||||
v.native(),
|
||||
unsafe.Pointer(&buffer.Bytes()[0]),
|
||||
C.gsize(length),
|
||||
cancellable.native(),
|
||||
&gerr)
|
||||
if c == -1 {
|
||||
defer C.g_error_free(gerr)
|
||||
return nil, -1, errors.New(goString(gerr.message))
|
||||
}
|
||||
return buffer, int(c), nil
|
||||
}
|
||||
|
||||
// TODO find a way to get size to be read without asking for ...
|
||||
/*
|
||||
gboolean
|
||||
g_input_stream_read_all (GInputStream *stream,
|
||||
void *buffer,
|
||||
gsize count,
|
||||
gsize *bytes_read,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
*/
|
||||
|
||||
/*
|
||||
void g_input_stream_read_all_async ()
|
||||
gboolean g_input_stream_read_all_finish ()
|
||||
gssize g_input_stream_skip ()
|
||||
*/
|
||||
|
||||
// Close is a wrapper around g_input_stream_close().
|
||||
func (v *InputStream) Close(cancellable *Cancellable) (bool, error) {
|
||||
var gerr *C.GError
|
||||
ok := gobool(C.g_input_stream_close(
|
||||
v.native(),
|
||||
cancellable.native(),
|
||||
&gerr))
|
||||
if !ok {
|
||||
defer C.g_error_free(gerr)
|
||||
return false, errors.New(goString(gerr.message))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// TODO g_input_stream***
|
||||
/*
|
||||
void g_input_stream_read_async ()
|
||||
gssize g_input_stream_read_finish ()
|
||||
void g_input_stream_skip_async ()
|
||||
gssize g_input_stream_skip_finish ()
|
||||
void g_input_stream_close_async ()
|
||||
gboolean g_input_stream_close_finish ()
|
||||
*/
|
||||
|
||||
// IsClosed is a wrapper around g_input_stream_is_closed().
|
||||
func (v *InputStream) IsClosed() bool {
|
||||
return gobool(C.g_input_stream_is_closed(v.native()))
|
||||
}
|
||||
|
||||
// HasPending is a wrapper around g_input_stream_has_pending().
|
||||
func (v *InputStream) HasPending() bool {
|
||||
return gobool(C.g_input_stream_has_pending(v.native()))
|
||||
}
|
||||
|
||||
// SetPending is a wrapper around g_input_stream_set_pending().
|
||||
func (v *InputStream) SetPending() (bool, error) {
|
||||
var gerr *C.GError
|
||||
ok := gobool(C.g_input_stream_set_pending(
|
||||
v.native(),
|
||||
&gerr))
|
||||
if !ok {
|
||||
defer C.g_error_free(gerr)
|
||||
return false, errors.New(goString(gerr.message))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// ClearPending is a wrapper around g_input_stream_clear_pending().
|
||||
func (v *InputStream) ClearPending() {
|
||||
C.g_input_stream_clear_pending(v.native())
|
||||
}
|
||||
|
||||
/* Useless functions due to Go language specification and actual
|
||||
implementation of (*InputStream).Read that do same thing.
|
||||
|
||||
GBytes * g_input_stream_read_bytes ()
|
||||
void g_input_stream_read_bytes_async ()
|
||||
GBytes * g_input_stream_read_bytes_finish ()
|
||||
*/
|
||||
|
||||
/*
|
||||
* GOutputStream
|
||||
*/
|
||||
|
||||
// OutputStream is a representation of GIO's GOutputStream.
|
||||
// Base class for implementing streaming output
|
||||
type OutputStream struct {
|
||||
*Object
|
||||
}
|
||||
|
||||
// native returns a pointer to the underlying GOutputStream.
|
||||
func (v *OutputStream) native() *C.GOutputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGOutputStream(p)
|
||||
}
|
||||
|
||||
// NativePrivate: to be used inside Gotk3 only.
|
||||
func (v *OutputStream) NativePrivate() *C.GOutputStream {
|
||||
if v == nil || v.GObject == nil {
|
||||
return nil
|
||||
}
|
||||
p := unsafe.Pointer(v.GObject)
|
||||
return C.toGOutputStream(p)
|
||||
}
|
||||
|
||||
// Native returns a pointer to the underlying GOutputStream.
|
||||
func (v *OutputStream) Native() uintptr {
|
||||
return uintptr(unsafe.Pointer(v.native()))
|
||||
}
|
||||
|
||||
func marshalOutputStream(p uintptr) (interface{}, error) {
|
||||
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
|
||||
obj := Take(unsafe.Pointer(c))
|
||||
return wrapOutputStream(obj), nil
|
||||
}
|
||||
|
||||
func wrapOutputStream(obj *Object) *OutputStream {
|
||||
return &OutputStream{obj}
|
||||
}
|
||||
|
||||
/*
|
||||
gssize
|
||||
g_output_stream_write (GOutputStream *stream,
|
||||
const void *buffer,
|
||||
gsize count,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
*/
|
||||
|
||||
// Write is a wrapper around g_output_stream_write().
|
||||
// buffer := bytes.NewBuffer(make([]byte, length))
|
||||
func (v *OutputStream) Write(buffer *bytes.Buffer, cancellable *Cancellable) (int, error) {
|
||||
var gerr *C.GError
|
||||
length := buffer.Len()
|
||||
|
||||
c := C.g_output_stream_write(
|
||||
v.native(),
|
||||
unsafe.Pointer(&buffer.Bytes()[0]),
|
||||
C.gsize(length),
|
||||
cancellable.native(),
|
||||
&gerr)
|
||||
if c == -1 {
|
||||
defer C.g_error_free(gerr)
|
||||
return -1, errors.New(goString(gerr.message))
|
||||
}
|
||||
return int(c), nil
|
||||
}
|
||||
|
||||
// Write is a wrapper around g_output_stream_write().
|
||||
// func (v *OutputStream) Write(buffer *[]byte, cancellable *Cancellable) (int, error) {
|
||||
// // cdata := C.CString(data)
|
||||
// // defer C.free(unsafe.Pointer(cdata))
|
||||
// var gerr *C.GError
|
||||
// c := C.g_output_stream_write(
|
||||
// v.native(),
|
||||
// unsafe.Pointer(buffer),
|
||||
// C.gsize(len(*buffer)),
|
||||
// cancellable.native(),
|
||||
// &gerr)
|
||||
// if c == -1 {
|
||||
// defer C.g_error_free(gerr)
|
||||
// return 0, errors.New(goString(gerr.message))
|
||||
// }
|
||||
// return int(c), nil
|
||||
// }
|
||||
|
||||
/*
|
||||
gboolean g_output_stream_write_all ()
|
||||
*/
|
||||
|
||||
// TODO outputStream asynch functions
|
||||
/*
|
||||
void g_output_stream_write_all_async ()
|
||||
gboolean g_output_stream_write_all_finish ()
|
||||
gboolean g_output_stream_writev ()
|
||||
gboolean g_output_stream_writev_all ()
|
||||
void g_output_stream_writev_async ()
|
||||
gboolean g_output_stream_writev_finish ()
|
||||
void g_output_stream_writev_all_async ()
|
||||
gboolean g_output_stream_writev_all_finish ()
|
||||
*/
|
||||
/*
|
||||
gssize
|
||||
g_output_stream_splice (GOutputStream *stream,
|
||||
GInputStream *source,
|
||||
GOutputStreamSpliceFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
*/
|
||||
|
||||
// Flush is a wrapper around g_output_stream_flush().
|
||||
func (v *OutputStream) Flush(cancellable *Cancellable) (bool, error) {
|
||||
var gerr *C.GError
|
||||
ok := gobool(C.g_output_stream_flush(
|
||||
v.native(),
|
||||
cancellable.native(),
|
||||
&gerr))
|
||||
if !ok {
|
||||
defer C.g_error_free(gerr)
|
||||
return false, errors.New(goString(gerr.message))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// Close is a wrapper around g_output_stream_close().
|
||||
func (v *OutputStream) Close(cancellable *Cancellable) (bool, error) {
|
||||
var gerr *C.GError
|
||||
ok := gobool(C.g_output_stream_close(
|
||||
v.native(),
|
||||
cancellable.native(),
|
||||
&gerr))
|
||||
if !ok {
|
||||
defer C.g_error_free(gerr)
|
||||
return false, errors.New(goString(gerr.message))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// TODO outputStream asynch functions
|
||||
/*
|
||||
void g_output_stream_write_async ()
|
||||
gssize g_output_stream_write_finish ()
|
||||
void g_output_stream_splice_async ()
|
||||
gssize g_output_stream_splice_finish ()
|
||||
void g_output_stream_flush_async ()
|
||||
gboolean g_output_stream_flush_finish ()
|
||||
void g_output_stream_close_async ()
|
||||
gboolean g_output_stream_close_finish ()
|
||||
*/
|
||||
|
||||
// IsClosing is a wrapper around g_output_stream_is_closing().
|
||||
func (v *OutputStream) IsClosing() bool {
|
||||
return gobool(C.g_output_stream_is_closing(v.native()))
|
||||
}
|
||||
|
||||
// IsClosed is a wrapper around g_output_stream_is_closed().
|
||||
func (v *OutputStream) IsClosed() bool {
|
||||
return gobool(C.g_output_stream_is_closed(v.native()))
|
||||
}
|
||||
|
||||
// HasPending is a wrapper around g_output_stream_has_pending().
|
||||
func (v *OutputStream) HasPending() bool {
|
||||
return gobool(C.g_output_stream_has_pending(v.native()))
|
||||
}
|
||||
|
||||
// SetPending is a wrapper around g_output_stream_set_pending().
|
||||
func (v *OutputStream) SetPending() (bool, error) {
|
||||
var gerr *C.GError
|
||||
ok := gobool(C.g_output_stream_set_pending(
|
||||
v.native(),
|
||||
&gerr))
|
||||
if !ok {
|
||||
defer C.g_error_free(gerr)
|
||||
return false, errors.New(goString(gerr.message))
|
||||
}
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// ClearPending is a wrapper around g_output_stream_clear_pending().
|
||||
func (v *OutputStream) ClearPending() {
|
||||
C.g_output_stream_clear_pending(v.native())
|
||||
}
|
||||
|
||||
/*
|
||||
gssize g_output_stream_write_bytes ()
|
||||
void g_output_stream_write_bytes_async ()
|
||||
gssize g_output_stream_write_bytes_finish ()
|
||||
gboolean g_output_stream_printf ()
|
||||
gboolean g_output_stream_vprintf ()
|
||||
*/
|
||||
14
third_party/gotk3/glib/giostream.go.h
vendored
Normal file
14
third_party/gotk3/glib/giostream.go.h
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static GIOStream *toGIOStream(void *p) { return (G_IO_STREAM(p)); }
|
||||
|
||||
static GInputStream *toGInputStream(void *p) { return (G_INPUT_STREAM(p)); }
|
||||
|
||||
static GOutputStream *toGOutputStream(void *p) { return (G_OUTPUT_STREAM(p)); }
|
||||
1474
third_party/gotk3/glib/glib.go
vendored
Normal file
1474
third_party/gotk3/glib/glib.go
vendored
Normal file
File diff suppressed because it is too large
Load Diff
196
third_party/gotk3/glib/glib.go.h
vendored
Normal file
196
third_party/gotk3/glib/glib.go.h
vendored
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIB_GO_H__
|
||||
#define __GLIB_GO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gio/gio.h>
|
||||
#define G_SETTINGS_ENABLE_BACKEND
|
||||
#include <gio/gsettingsbackend.h>
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <locale.h>
|
||||
|
||||
/* GObject Type Casting */
|
||||
static GObject *toGObject(void *p) { return (G_OBJECT(p)); }
|
||||
|
||||
static GAction *toGAction(void *p) { return (G_ACTION(p)); }
|
||||
|
||||
static GActionGroup *toGActionGroup(void *p) { return (G_ACTION_GROUP(p)); }
|
||||
|
||||
static GActionMap *toGActionMap(void *p) { return (G_ACTION_MAP(p)); }
|
||||
|
||||
static GAsyncResult *toGAsyncResult(void *p) { return (G_ASYNC_RESULT(p)); }
|
||||
|
||||
static GSimpleAction *toGSimpleAction(void *p) { return (G_SIMPLE_ACTION(p)); }
|
||||
|
||||
static GSimpleActionGroup *toGSimpleActionGroup(void *p) {
|
||||
return (G_SIMPLE_ACTION_GROUP(p));
|
||||
}
|
||||
|
||||
static GPropertyAction *toGPropertyAction(void *p) {
|
||||
return (G_PROPERTY_ACTION(p));
|
||||
}
|
||||
|
||||
static GMenuModel *toGMenuModel(void *p) { return (G_MENU_MODEL(p)); }
|
||||
|
||||
static GMenu *toGMenu(void *p) { return (G_MENU(p)); }
|
||||
|
||||
static GMenuItem *toGMenuItem(void *p) { return (G_MENU_ITEM(p)); }
|
||||
|
||||
static GNotification *toGNotification(void *p) { return (G_NOTIFICATION(p)); }
|
||||
|
||||
static GPermission *toGPermission(void *p) { return (G_PERMISSION(p)); }
|
||||
|
||||
static GCancellable *toCancellable(void *p) { return (G_CANCELLABLE(p)); }
|
||||
|
||||
static GIcon *toGIcon(void *p) { return (G_ICON(p)); }
|
||||
static GFileIcon *toGFileIcon(void *p) { return (G_FILE_ICON(p)); }
|
||||
|
||||
static GFile *toGFile(void *p) { return (G_FILE(p)); }
|
||||
|
||||
static GApplication *toGApplication(void *p) { return (G_APPLICATION(p)); }
|
||||
|
||||
static GSettings *toGSettings(void *p) { return (G_SETTINGS(p)); }
|
||||
|
||||
static GSettingsBackend *toGSettingsBackend(void *p) {
|
||||
return (G_SETTINGS_BACKEND(p));
|
||||
}
|
||||
|
||||
static GBinding *toGBinding(void *p) { return (G_BINDING(p)); }
|
||||
|
||||
static GType _g_type_from_instance(gpointer instance) {
|
||||
return (G_TYPE_FROM_INSTANCE(instance));
|
||||
}
|
||||
|
||||
/* Wrapper to avoid variable arg list */
|
||||
static void _g_object_set_one(gpointer object, const gchar *property_name,
|
||||
void *val) {
|
||||
g_object_set(object, property_name, *(gpointer **)val, NULL);
|
||||
}
|
||||
|
||||
static GValue *alloc_gvalue_list(int n) {
|
||||
GValue *valv;
|
||||
|
||||
valv = g_new0(GValue, n);
|
||||
return (valv);
|
||||
}
|
||||
|
||||
static void val_list_insert(GValue *valv, int i, GValue *val) {
|
||||
valv[i] = *val;
|
||||
}
|
||||
|
||||
/*
|
||||
* GValue
|
||||
*/
|
||||
|
||||
static GValue *_g_value_alloc() { return (g_new0(GValue, 1)); }
|
||||
|
||||
static GValue *_g_value_init(GType g_type) {
|
||||
GValue *value;
|
||||
|
||||
value = g_new0(GValue, 1);
|
||||
return (g_value_init(value, g_type));
|
||||
}
|
||||
|
||||
static gboolean _g_type_is_value(GType g_type) {
|
||||
return (G_TYPE_IS_VALUE(g_type));
|
||||
}
|
||||
|
||||
static gboolean _g_is_value(GValue *val) { return (G_IS_VALUE(val)); }
|
||||
|
||||
static GType _g_value_type(GValue *val) { return (G_VALUE_TYPE(val)); }
|
||||
|
||||
static const gchar *_g_value_type_name(GValue *val) {
|
||||
return (G_VALUE_TYPE_NAME(val));
|
||||
}
|
||||
|
||||
static GType _g_value_fundamental(GType type) {
|
||||
return (G_TYPE_FUNDAMENTAL(type));
|
||||
}
|
||||
|
||||
static GObjectClass *_g_object_get_class(GObject *object) {
|
||||
return (G_OBJECT_GET_CLASS(object));
|
||||
}
|
||||
|
||||
/*
|
||||
* Closure support
|
||||
*/
|
||||
|
||||
extern void removeSourceFunc(gpointer data);
|
||||
extern gboolean sourceFunc(gpointer data);
|
||||
|
||||
extern void goMarshal(GClosure *, GValue *, guint, GValue *, gpointer,
|
||||
GValue *);
|
||||
extern void removeClosure(gpointer, GClosure *);
|
||||
|
||||
static inline GClosure *_g_closure_new() {
|
||||
GClosure *closure;
|
||||
|
||||
closure = g_closure_new_simple(sizeof(GClosure), NULL);
|
||||
g_closure_set_marshal(closure, (GClosureMarshal)(goMarshal));
|
||||
g_closure_add_finalize_notifier(closure, NULL,
|
||||
(GClosureNotify)(removeClosure));
|
||||
return closure;
|
||||
}
|
||||
|
||||
static inline guint _g_signal_new(const gchar *name) {
|
||||
return g_signal_new(name, G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||
0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
static inline guint _g_signal_newv(const gchar *name, const GType return_type,
|
||||
const guint n_params, GType *const param_types) {
|
||||
return g_signal_newv(name, G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||
NULL, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
||||
return_type, n_params, param_types);
|
||||
}
|
||||
|
||||
static void init_i18n(const char *domain, const char *dir) {
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(domain, dir);
|
||||
bind_textdomain_codeset(domain, "UTF-8");
|
||||
textdomain(domain);
|
||||
}
|
||||
|
||||
static const char *localize(const char *string) { return _(string); }
|
||||
|
||||
static inline char **make_strings(int count) {
|
||||
return (char **)malloc(sizeof(char *) * count);
|
||||
}
|
||||
|
||||
static inline void destroy_strings(char **strings) { free(strings); }
|
||||
|
||||
static inline char *get_string(char **strings, int n) { return strings[n]; }
|
||||
|
||||
static inline void set_string(char **strings, int n, char *str) {
|
||||
strings[n] = str;
|
||||
}
|
||||
|
||||
static inline gchar **next_gcharptr(gchar **s) { return (s + 1); }
|
||||
|
||||
extern gint goCompareDataFuncs(gconstpointer a, gconstpointer b,
|
||||
gpointer user_data);
|
||||
|
||||
#endif
|
||||
27
third_party/gotk3/glib/glib_export.go
vendored
Normal file
27
third_party/gotk3/glib/glib_export.go
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package glib
|
||||
|
||||
// #cgo pkg-config: gio-2.0
|
||||
// #include <gio/gio.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gotk3/gotk3/internal/callback"
|
||||
)
|
||||
|
||||
//export goAsyncReadyCallbacks
|
||||
func goAsyncReadyCallbacks(sourceObject *C.GObject, res *C.GAsyncResult, userData C.gpointer) {
|
||||
var source *Object
|
||||
if sourceObject != nil {
|
||||
source = wrapObject(unsafe.Pointer(sourceObject))
|
||||
}
|
||||
|
||||
fn := callback.Get(uintptr(userData)).(AsyncReadyCallback)
|
||||
fn(source, wrapAsyncResult(wrapObject(unsafe.Pointer(res))))
|
||||
}
|
||||
|
||||
//export goCompareDataFuncs
|
||||
func goCompareDataFuncs(a, b C.gconstpointer, userData C.gpointer) C.gint {
|
||||
fn := callback.Get(uintptr(userData)).(CompareDataFunc)
|
||||
return C.gint(fn(uintptr(a), uintptr(b)))
|
||||
}
|
||||
18
third_party/gotk3/glib/glib_extension.go
vendored
Normal file
18
third_party/gotk3/glib/glib_extension.go
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
//glib_extension contains definitions and functions to interface between glib/gtk/gio and go universe
|
||||
|
||||
package glib
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Should be implemented by any class which need special conversion like
|
||||
// gtk.Application -> gio.Application
|
||||
type IGlibConvert interface {
|
||||
// If conversion can't be done, the function has to panic with a message that it can't convert to type
|
||||
Convert(reflect.Type) reflect.Value
|
||||
}
|
||||
|
||||
var (
|
||||
IGlibConvertType reflect.Type
|
||||
)
|
||||
50
third_party/gotk3/glib/glib_since_2_42.go
vendored
Normal file
50
third_party/gotk3/glib/glib_since_2_42.go
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !glib_2_40
|
||||
|
||||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
/*
|
||||
* Notification
|
||||
*/
|
||||
|
||||
// NotificationPriority is a representation of GLib's GNotificationPriority.
|
||||
type NotificationPriority int
|
||||
|
||||
const (
|
||||
NOTIFICATION_PRIORITY_NORMAL NotificationPriority = C.G_NOTIFICATION_PRIORITY_NORMAL
|
||||
NOTIFICATION_PRIORITY_LOW NotificationPriority = C.G_NOTIFICATION_PRIORITY_LOW
|
||||
NOTIFICATION_PRIORITY_HIGH NotificationPriority = C.G_NOTIFICATION_PRIORITY_HIGH
|
||||
NOTIFICATION_PRIORITY_URGENT NotificationPriority = C.G_NOTIFICATION_PRIORITY_URGENT
|
||||
)
|
||||
|
||||
// SetPriority is a wrapper around g_notification_set_priority().
|
||||
func (v *Notification) SetPriority(prio NotificationPriority) {
|
||||
C.g_notification_set_priority(v.native(), C.GNotificationPriority(prio))
|
||||
}
|
||||
|
||||
/*
|
||||
* Application
|
||||
*/
|
||||
|
||||
// GetResourceBasePath is a wrapper around g_application_get_resource_base_path().
|
||||
func (v *Application) GetResourceBasePath() string {
|
||||
c := C.g_application_get_resource_base_path(v.native())
|
||||
|
||||
return C.GoString((*C.char)(c))
|
||||
}
|
||||
|
||||
// SetResourceBasePath is a wrapper around g_application_set_resource_base_path().
|
||||
func (v *Application) SetResourceBasePath(bp string) {
|
||||
cstr1 := (*C.gchar)(C.CString(bp))
|
||||
defer C.free(unsafe.Pointer(cstr1))
|
||||
|
||||
C.g_application_set_resource_base_path(v.native(), cstr1)
|
||||
}
|
||||
30
third_party/gotk3/glib/glib_since_2_44.go
vendored
Normal file
30
third_party/gotk3/glib/glib_since_2_44.go
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !glib_2_40,!glib_2_42
|
||||
|
||||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
// #include "glib_since_2_44.go.h"
|
||||
import "C"
|
||||
|
||||
/*
|
||||
* Application
|
||||
*/
|
||||
|
||||
// GetIsBusy is a wrapper around g_application_get_is_busy().
|
||||
func (v *Application) GetIsBusy() bool {
|
||||
return gobool(C.g_application_get_is_busy(v.native()))
|
||||
}
|
||||
|
||||
/*
|
||||
* SimpleAction
|
||||
*/
|
||||
|
||||
// SetStateHint is a wrapper around g_simple_action_set_state_hint
|
||||
func (v *SimpleAction) SetStateHint(stateHint *Variant) {
|
||||
C.g_simple_action_set_state_hint(v.native(), stateHint.native())
|
||||
}
|
||||
16
third_party/gotk3/glib/glib_since_2_44.go.h
vendored
Normal file
16
third_party/gotk3/glib/glib_since_2_44.go.h
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
static GListModel *toGListModel(void *p) { return (G_LIST_MODEL(p)); }
|
||||
|
||||
static GListStore *toGListStore(void *p) { return (G_LIST_STORE(p)); }
|
||||
|
||||
static inline void _g_list_store_insert_sorted(GListStore *model, gpointer item,
|
||||
gpointer user_data) {
|
||||
g_list_store_insert_sorted(model, item,
|
||||
(GCompareDataFunc)(goCompareDataFuncs), user_data);
|
||||
}
|
||||
23
third_party/gotk3/glib/glib_since_2_46.go
vendored
Normal file
23
third_party/gotk3/glib/glib_since_2_46.go
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !glib_2_40,!glib_2_42,!glib_2_44
|
||||
|
||||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
// #include "glib_since_2_44.go.h"
|
||||
// #include "glib_since_2_46.go.h"
|
||||
import "C"
|
||||
import "github.com/gotk3/gotk3/internal/callback"
|
||||
|
||||
/*
|
||||
* GListStore
|
||||
*/
|
||||
|
||||
// Sort is a wrapper around g_list_store_sort().
|
||||
func (v *ListStore) Sort(compareFunc CompareDataFunc) {
|
||||
C._g_list_store_sort(v.native(), C.gpointer(callback.Assign(compareFunc)))
|
||||
}
|
||||
10
third_party/gotk3/glib/glib_since_2_46.go.h
vendored
Normal file
10
third_party/gotk3/glib/glib_since_2_46.go.h
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <glib.h>
|
||||
|
||||
static inline void _g_list_store_sort(GListStore *model, gpointer user_data) {
|
||||
g_list_store_sort(model, (GCompareDataFunc)(goCompareDataFuncs), user_data);
|
||||
}
|
||||
15
third_party/gotk3/glib/glib_since_2_58.go
vendored
Normal file
15
third_party/gotk3/glib/glib_since_2_58.go
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Same copyright and license as the rest of the files in this project
|
||||
|
||||
// +build !glib_2_40,!glib_2_42,!glib_2_44,!glib_2_46,!glib_2_48,!glib_2_50,!glib_2_52,!glib_2_54,!glib_2_56
|
||||
|
||||
package glib
|
||||
|
||||
// #include <gio/gio.h>
|
||||
// #include <glib.h>
|
||||
// #include <glib-object.h>
|
||||
// #include "glib.go.h"
|
||||
import "C"
|
||||
|
||||
const (
|
||||
FORMAT_SIZE_BITS FormatSizeFlags = C.G_FORMAT_SIZE_BITS
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user