forked from jcowgar/go-iup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.go
216 lines (161 loc) · 4.95 KB
/
resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
Copyright (C) 2011 by Jeremy Cowgar <[email protected]>
This file is part of go-iup.
go-iup is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
go-iup is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with go-iup. If not, see <http://www.gnu.org/licenses/>.
*/
package iup
/*
#include <stdlib.h>
#include <iup.h>
#include <iupim.h>
*/
import "C"
import "unsafe"
/*******************************************************************************
**
** Fonts
**
*******************************************************************************/
func MapFont(iupfont string) string {
cIupfont := C.CString(iupfont)
defer C.free(unsafe.Pointer(cIupfont))
return C.GoString(C.IupMapFont(cIupfont))
}
func UnMapFont(driverfont string) string {
cDriverfont := C.CString(driverfont)
defer C.free(unsafe.Pointer(cDriverfont))
return C.GoString(C.IupUnMapFont(cDriverfont))
}
/*******************************************************************************
**
** Images
**
*******************************************************************************/
func Image(width, height int, pixels []byte) *Ihandle {
cPixels := ByteArrayToCUCharArray(pixels)
return (*Ihandle)(C.IupImage(C.int(width), C.int(height), &cPixels[0]))
}
func ImageRGB(width, height int, pixels []byte) *Ihandle {
cPixels := ByteArrayToCUCharArray(pixels)
return (*Ihandle)(C.IupImageRGB(C.int(width), C.int(height), &cPixels[0]))
}
func ImageRGBA(width, height int, pixels []byte) *Ihandle {
cPixels := ByteArrayToCUCharArray(pixels)
return (*Ihandle)(C.IupImageRGBA(C.int(width), C.int(height), &cPixels[0]))
}
func LoadImage(file_name string) *Ihandle {
cFile_Name := C.CString(file_name)
defer C.free(unsafe.Pointer(cFile_Name))
return (*Ihandle)(C.IupLoadImage(cFile_Name))
}
func SaveImage(ih *Ihandle, file_name, format string) int {
cFile_Name := C.CString(file_name)
defer C.free(unsafe.Pointer(cFile_Name))
cFormat := C.CString(format)
defer C.free(unsafe.Pointer(cFormat))
return int(C.IupSaveImage(ih.C(), cFile_Name, cFormat))
}
func SaveImageAsText(ih *Ihandle, file_name, format, name string) int {
cFile_Name := C.CString(file_name)
defer C.free(unsafe.Pointer(cFile_Name))
cFormat := C.CString(format)
defer C.free(unsafe.Pointer(cFormat))
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
return int(C.IupSaveImageAsText(ih.C(), cFile_Name, cFormat, cName))
}
/*******************************************************************************
**
** Keyboard
**
*******************************************************************************/
func NextField(ih *Ihandle) *Ihandle {
return (*Ihandle)(C.IupNextField(ih.C()))
}
func PreviousField(ih *Ihandle) *Ihandle {
return (*Ihandle)(C.IupPreviousField(ih.C()))
}
func GetFocus() *Ihandle {
return (*Ihandle)(C.IupGetFocus())
}
func SetFocus(ih *Ihandle) *Ihandle {
return (*Ihandle)(C.IupSetFocus(ih.C()))
}
/*******************************************************************************
**
** Menus
**
*******************************************************************************/
func Item(title string, opts ...interface{}) *Ihandle {
cTitle := C.CString(title)
defer C.free(unsafe.Pointer(cTitle))
ih := (*Ihandle)(C.IupItem(cTitle, nil))
for _, o := range opts {
switch v := o.(type) {
case ActionFunc:
SetActionFunc(ih, v)
default:
Decorate(ih, v)
}
}
return ih
}
func menuv(ihs []*C.Ihandle) *Ihandle {
return (*Ihandle)(C.IupMenuv(&ihs[0]))
}
func Menu(args ...*Ihandle) *Ihandle {
return menuv(IHandleArrayToC(args))
}
func Menuv(args []*Ihandle, opts ...interface{}) *Ihandle {
ih := menuv(IHandleArrayToC(args))
for _, o := range opts {
switch v := o.(type) {
default:
Decorate(ih, v)
}
}
return ih
}
func Separator() *Ihandle {
return (*Ihandle)(C.IupSeparator())
}
func Submenu(title string, menu *Ihandle, opts ...interface{}) *Ihandle {
cTitle := C.CString(title)
defer C.free(unsafe.Pointer(cTitle))
ih := (*Ihandle)(C.IupSubmenu(cTitle, menu.C()))
for _, o := range opts {
switch v := o.(type) {
default:
Decorate(ih, v)
}
}
return ih
}
/*******************************************************************************
**
** Miscellaneous
**
*******************************************************************************/
func Clipboard() *Ihandle {
return (*Ihandle)(C.IupClipboard())
}
func Timer() *Ihandle {
return (*Ihandle)(C.IupTimer())
}
func User() *Ihandle {
return (*Ihandle)(C.IupUser())
}
func Help(url string) int {
cUrl := C.CString(url)
defer C.free(unsafe.Pointer(cUrl))
return int(C.IupHelp(cUrl))
}