iup-ffi 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENCE.txt +21 -0
- data/README.rdoc +348 -0
- data/lib/iup-ffi-plain.rb +9 -0
- data/lib/iup-ffi.rb +76 -0
- data/lib/plain/iupcdlib.rb +107 -0
- data/lib/plain/iupcontrolslib.rb +24 -0
- data/lib/plain/iupimglib.rb +14 -0
- data/lib/plain/iupimlib.rb +16 -0
- data/lib/plain/iuplib.rb +209 -0
- data/lib/plain/scintilla-lib.rb +15 -0
- data/lib/wrapped/attribute-builders.rb +105 -0
- data/lib/wrapped/attribute-reference.rb +27 -0
- data/lib/wrapped/background-box.rb +33 -0
- data/lib/wrapped/button.rb +108 -0
- data/lib/wrapped/callback-setter.rb +78 -0
- data/lib/wrapped/canvas.rb +467 -0
- data/lib/wrapped/colourbar.rb +94 -0
- data/lib/wrapped/colourdialog.rb +63 -0
- data/lib/wrapped/common-attributes.rb +64 -0
- data/lib/wrapped/constants.rb +953 -0
- data/lib/wrapped/dial.rb +87 -0
- data/lib/wrapped/dialog.rb +176 -0
- data/lib/wrapped/dialogs.rb +106 -0
- data/lib/wrapped/drag-drop-attributes.rb +57 -0
- data/lib/wrapped/dynamic-fill-methods.rb +27 -0
- data/lib/wrapped/expander.rb +65 -0
- data/lib/wrapped/filedialog.rb +93 -0
- data/lib/wrapped/fill.rb +26 -0
- data/lib/wrapped/fontdialog.rb +42 -0
- data/lib/wrapped/frame.rb +47 -0
- data/lib/wrapped/gridbox.rb +94 -0
- data/lib/wrapped/hbox.rb +49 -0
- data/lib/wrapped/image-attributes.rb +27 -0
- data/lib/wrapped/image.rb +118 -0
- data/lib/wrapped/internal-drag-drop-attributes.rb +21 -0
- data/lib/wrapped/iup-global.rb +51 -0
- data/lib/wrapped/label.rb +98 -0
- data/lib/wrapped/link.rb +59 -0
- data/lib/wrapped/list.rb +353 -0
- data/lib/wrapped/matrix.rb +233 -0
- data/lib/wrapped/menu.rb +50 -0
- data/lib/wrapped/menuitem.rb +80 -0
- data/lib/wrapped/messagedialog.rb +51 -0
- data/lib/wrapped/progressbar.rb +48 -0
- data/lib/wrapped/progressdialog.rb +111 -0
- data/lib/wrapped/radio.rb +43 -0
- data/lib/wrapped/scintilla.rb +277 -0
- data/lib/wrapped/scrollbar-attributes.rb +141 -0
- data/lib/wrapped/scrollbox.rb +147 -0
- data/lib/wrapped/separator.rb +11 -0
- data/lib/wrapped/splitbox.rb +48 -0
- data/lib/wrapped/stretchbox.rb +42 -0
- data/lib/wrapped/submenu.rb +34 -0
- data/lib/wrapped/tabs.rb +149 -0
- data/lib/wrapped/text.rb +225 -0
- data/lib/wrapped/timer.rb +42 -0
- data/lib/wrapped/toggle.rb +98 -0
- data/lib/wrapped/tree.rb +465 -0
- data/lib/wrapped/val.rb +97 -0
- data/lib/wrapped/vbox.rb +51 -0
- data/lib/wrapped/widget.rb +137 -0
- data/lib/wrapped/zbox.rb +54 -0
- metadata +124 -0
data/lib/plain/iuplib.rb
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
module IupLib # :nodoc:
|
|
2
|
+
extend FFI::Library
|
|
3
|
+
|
|
4
|
+
this_dir = File.dirname(__FILE__)
|
|
5
|
+
case RbConfig::CONFIG['host_os']
|
|
6
|
+
when /mswin|mingw/
|
|
7
|
+
ffi_lib 'lib/library/iup.dll'
|
|
8
|
+
when /linux|cygwin/
|
|
9
|
+
ffi_lib 'libiup'
|
|
10
|
+
else
|
|
11
|
+
raise Exception, 'iup libraries not found for this platform'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Attributes
|
|
15
|
+
attach_function :IupSetAttribute, [:pointer, :string, :string], :void
|
|
16
|
+
attach_function :IupSetAttributes, [:pointer, :string], :pointer
|
|
17
|
+
attach_function :IupGetAttribute, [:pointer, :string], :strptr
|
|
18
|
+
attach_function :IupSetAttributeHandle, [:pointer, :string, :pointer], :void
|
|
19
|
+
attach_function :IupSetGlobal, [:string, :string], :void
|
|
20
|
+
attach_function :IupGetGlobal, [:string], :strptr
|
|
21
|
+
|
|
22
|
+
callback :iup_callback, [], :int
|
|
23
|
+
attach_function :IupSetFunction, [:string, :iup_callback], :iup_callback
|
|
24
|
+
|
|
25
|
+
attach_function :IupGetInt, [:pointer, :string], :int
|
|
26
|
+
|
|
27
|
+
# Events
|
|
28
|
+
attach_function :IupOpen, [:int, :pointer], :int
|
|
29
|
+
attach_function :IupMainLoop, [], :void
|
|
30
|
+
attach_function :IupClose, [], :void
|
|
31
|
+
attach_function :IupDestroy, [:pointer], :void
|
|
32
|
+
attach_function :IupRedraw, [:pointer], :void
|
|
33
|
+
|
|
34
|
+
attach_function :IupMap, [:pointer], :void
|
|
35
|
+
|
|
36
|
+
# -- Callbacks
|
|
37
|
+
callback :iup_callback_d_i, [:pointer, :double], :int
|
|
38
|
+
callback :iup_callback_ff_i, [:pointer, :float, :float], :int
|
|
39
|
+
callback :iup_callback_fiis_i, [:pointer, :float, :int, :int, :string], :int
|
|
40
|
+
callback :iup_callback_s_i, [:pointer, :string], :int
|
|
41
|
+
callback :iup_callback_sii_i, [:pointer, :string, :int, :int], :int
|
|
42
|
+
callback :iup_callback_i_i, [:pointer, :int], :int
|
|
43
|
+
callback :iup_callback_i_s, [:pointer, :int], :strptr
|
|
44
|
+
callback :iup_callback_iff_i, [:pointer, :int, :float, :float], :int
|
|
45
|
+
callback :iup_callback_ii_i, [:pointer, :int, :int], :int
|
|
46
|
+
callback :iup_callback_iiff_i, [:pointer, :int, :int, :float, :float], :int
|
|
47
|
+
callback :iup_callback_iiffi_i, [:pointer, :int, :int, :float, :float, :int], :int
|
|
48
|
+
callback :iup_callback_iiffff_i, [:pointer, :int, :int, :float, :float, :float, :float], :int
|
|
49
|
+
callback :iup_callback_is_i, [:pointer, :int, :string], :int
|
|
50
|
+
callback :iup_callback_iis_i, [:pointer, :int, :int, :string], :int
|
|
51
|
+
callback :iup_callback_iii_i, [:pointer, :int, :int, :int], :int
|
|
52
|
+
callback :iup_callback_iiii_i, [:pointer, :int, :int, :int, :int], :int
|
|
53
|
+
callback :iup_callback_iiis_i, [:pointer, :int, :int, :string], :int
|
|
54
|
+
callback :iup_callback_iis_i, [:pointer, :int, :int, :string], :int
|
|
55
|
+
callback :iup_callback_iiiis_i, [:pointer, :int, :int, :int, :int, :string], :int
|
|
56
|
+
callback :iup_callback_plain, [:pointer], :int
|
|
57
|
+
callback :iup_callback_plain_v, [:pointer], :void
|
|
58
|
+
callback :iup_callback_p_i, [:pointer, :pointer], :int
|
|
59
|
+
callback :iup_callback_pp_i, [:pointer, :pointer, :pointer], :int
|
|
60
|
+
callback :iup_callback_ss_i, [:pointer, :string, :string], :int
|
|
61
|
+
callback :iup_callback_ssi_i, [:pointer, :string, :string, :int], :int
|
|
62
|
+
callback :iup_callback_ssiii_i, [:pointer, :string, :string, :int, :int, :int], :int
|
|
63
|
+
|
|
64
|
+
attach_function :IupSetCallbackD_I, :IupSetCallback, [:pointer, :string, :iup_callback_d_i], :iup_callback_d_i
|
|
65
|
+
attach_function :IupSetCallbackFF_I, :IupSetCallback, [:pointer, :string, :iup_callback_ff_i], :iup_callback_ff_i
|
|
66
|
+
attach_function :IupSetCallbackFIIS_I, :IupSetCallback, [:pointer, :string, :iup_callback_fiis_i], :iup_callback_fiis_i
|
|
67
|
+
attach_function :IupSetCallbackS_I, :IupSetCallback, [:pointer, :string, :iup_callback_s_i], :iup_callback_s_i
|
|
68
|
+
attach_function :IupSetCallbackSII_I, :IupSetCallback, [:pointer, :string, :iup_callback_sii_i], :iup_callback_sii_i
|
|
69
|
+
attach_function :IupSetCallbackI_I, :IupSetCallback, [:pointer, :string, :iup_callback_i_i], :iup_callback_i_i
|
|
70
|
+
attach_function :IupSetCallbackI_S, :IupSetCallback, [:pointer, :string, :iup_callback_i_s], :iup_callback_i_s
|
|
71
|
+
attach_function :IupSetCallbackIFF_I, :IupSetCallback, [:pointer, :string, :iup_callback_iff_i], :iup_callback_iff_i
|
|
72
|
+
attach_function :IupSetCallbackII_I, :IupSetCallback, [:pointer, :string, :iup_callback_ii_i], :iup_callback_ii_i
|
|
73
|
+
attach_function :IupSetCallbackIIFF_I, :IupSetCallback, [:pointer, :string, :iup_callback_iiff_i], :iup_callback_iiff_i
|
|
74
|
+
attach_function :IupSetCallbackIIFFI_I, :IupSetCallback, [:pointer, :string, :iup_callback_iiffi_i], :iup_callback_iiffi_i
|
|
75
|
+
attach_function :IupSetCallbackIIFFFF_I, :IupSetCallback, [:pointer, :string, :iup_callback_iiffff_i], :iup_callback_iiffff_i
|
|
76
|
+
attach_function :IupSetCallbackIS_I, :IupSetCallback, [:pointer, :string, :iup_callback_is_i], :iup_callback_is_i
|
|
77
|
+
attach_function :IupSetCallbackIIS_I, :IupSetCallback, [:pointer, :string, :iup_callback_iis_i], :iup_callback_iis_i
|
|
78
|
+
attach_function :IupSetCallbackIII_I, :IupSetCallback, [:pointer, :string, :iup_callback_iii_i], :iup_callback_iii_i
|
|
79
|
+
attach_function :IupSetCallbackIIII_I, :IupSetCallback, [:pointer, :string, :iup_callback_iiii_i], :iup_callback_iiii_i
|
|
80
|
+
attach_function :IupSetCallbackIIS_I, :IupSetCallback, [:pointer, :string, :iup_callback_iis_i], :iup_callback_iis_i
|
|
81
|
+
attach_function :IupSetCallbackIIIIS_I, :IupSetCallback, [:pointer, :string, :iup_callback_iiiis_i], :iup_callback_iiiis_i
|
|
82
|
+
attach_function :IupSetCallbackPlain, :IupSetCallback, [:pointer, :string, :iup_callback_plain], :iup_callback_plain
|
|
83
|
+
attach_function :IupSetCallbackPlain_V, :IupSetCallback, [:pointer, :string, :iup_callback_plain_v], :iup_callback_plain_v
|
|
84
|
+
attach_function :IupSetCallbackP_I, :IupSetCallback, [:pointer, :string, :iup_callback_p_i], :iup_callback_p_i
|
|
85
|
+
attach_function :IupSetCallbackPP_I, :IupSetCallback, [:pointer, :string, :iup_callback_pp_i], :iup_callback_pp_i
|
|
86
|
+
attach_function :IupSetCallbackSS_I, :IupSetCallback, [:pointer, :string, :iup_callback_ss_i], :iup_callback_ss_i
|
|
87
|
+
attach_function :IupSetCallbackSSI_I, :IupSetCallback, [:pointer, :string, :iup_callback_ssi_i], :iup_callback_ssi_i
|
|
88
|
+
attach_function :IupSetCallbackSSIII_I, :IupSetCallback, [:pointer, :string, :iup_callback_ssiii_i], :iup_callback_ssiii_i
|
|
89
|
+
|
|
90
|
+
# Layout
|
|
91
|
+
# -- Composition
|
|
92
|
+
attach_function :IupFill, [], :pointer
|
|
93
|
+
attach_function :IupGridBox, [:pointer, :varargs], :pointer
|
|
94
|
+
attach_function :IupVbox, [:pointer, :varargs], :pointer
|
|
95
|
+
attach_function :IupHbox, [:pointer, :varargs], :pointer
|
|
96
|
+
attach_function :IupZbox, [:pointer, :varargs], :pointer
|
|
97
|
+
attach_function :IupRadio, [:pointer], :pointer
|
|
98
|
+
attach_function :IupNormalizer, [:pointer, :varargs], :pointer
|
|
99
|
+
attach_function :IupBackgroundBox, [:pointer], :pointer
|
|
100
|
+
attach_function :IupCbox, [:pointer, :varargs], :pointer
|
|
101
|
+
attach_function :IupDetachBox, [:pointer], :pointer
|
|
102
|
+
attach_function :IupExpander, [:pointer], :pointer
|
|
103
|
+
attach_function :IupSbox, [:pointer], :pointer
|
|
104
|
+
attach_function :IupScrollBox, [:pointer], :pointer
|
|
105
|
+
attach_function :IupSplit, [:pointer, :pointer], :pointer
|
|
106
|
+
# -- Hierarchy
|
|
107
|
+
attach_function :IupAppend, [:pointer, :pointer], :pointer
|
|
108
|
+
attach_function :IupDetach, [:pointer], :void
|
|
109
|
+
attach_function :IupInsert, [:pointer, :pointer, :pointer], :pointer
|
|
110
|
+
attach_function :IupReparent, [:pointer, :pointer, :pointer], :int
|
|
111
|
+
attach_function :IupGetParent, [:pointer], :pointer
|
|
112
|
+
attach_function :IupGetChild, [:pointer, :int], :pointer
|
|
113
|
+
attach_function :IupGetChildPos, [:pointer, :pointer], :int
|
|
114
|
+
attach_function :IupGetChildCount, [:pointer], :int
|
|
115
|
+
attach_function :IupGetNextChild, [:pointer, :pointer], :pointer
|
|
116
|
+
attach_function :IupGetBrother, [:pointer], :pointer
|
|
117
|
+
attach_function :IupGetDialog, [:pointer], :pointer
|
|
118
|
+
attach_function :IupGetDialogChild, [:pointer, :string], :pointer
|
|
119
|
+
# -- Utilities
|
|
120
|
+
attach_function :IupRefresh, [:pointer], :void
|
|
121
|
+
attach_function :IupRefreshChildren, [:pointer], :void
|
|
122
|
+
attach_function :IupUpdate, [:pointer], :void
|
|
123
|
+
attach_function :IupRedraw, [:pointer, :int], :void
|
|
124
|
+
attach_function :IupConvertXYToPos, [:pointer, :int, :int], :int
|
|
125
|
+
|
|
126
|
+
# Dialogs
|
|
127
|
+
# -- reference
|
|
128
|
+
attach_function :IupDialog, [:pointer], :pointer
|
|
129
|
+
attach_function :IupPopup, [:pointer, :int, :int], :int
|
|
130
|
+
attach_function :IupShow, [:pointer], :void
|
|
131
|
+
attach_function :IupShowXY, [:pointer, :int, :int], :int
|
|
132
|
+
attach_function :IupHide, [:pointer], :void
|
|
133
|
+
|
|
134
|
+
# -- predefined
|
|
135
|
+
attach_function :IupFileDlg, [], :pointer
|
|
136
|
+
attach_function :IupMessageDlg, [], :pointer
|
|
137
|
+
attach_function :IupColorDlg, [], :pointer
|
|
138
|
+
attach_function :IupFontDlg, [], :pointer
|
|
139
|
+
attach_function :IupProgressDlg, [], :pointer
|
|
140
|
+
attach_function :IupAlarm, [:string, :string, :string, :string, :string], :int
|
|
141
|
+
attach_function :IupGetFile, [:string], :int
|
|
142
|
+
attach_function :IupGetColor, [:int, :int, :pointer, :pointer, :pointer], :int
|
|
143
|
+
attach_function :IupGetText, [:pointer, :pointer], :int
|
|
144
|
+
attach_function :IupListDialog, [:int, :string, :int, :pointer, :int, :int, :int, :pointer], :int
|
|
145
|
+
attach_function :IupMessage, [:string, :string], :void
|
|
146
|
+
|
|
147
|
+
# Controls
|
|
148
|
+
# -- standard
|
|
149
|
+
attach_function :IupButton, [:string, :string], :pointer
|
|
150
|
+
attach_function :IupCanvas, [:string], :pointer
|
|
151
|
+
attach_function :IupFrame, [:pointer], :pointer
|
|
152
|
+
attach_function :IupLabel, [:string], :pointer
|
|
153
|
+
attach_function :IupLink, [:string, :string], :pointer
|
|
154
|
+
attach_function :IupList, [:string], :pointer
|
|
155
|
+
attach_function :IupProgressBar, [], :pointer
|
|
156
|
+
attach_function :IupSpin, [], :pointer
|
|
157
|
+
attach_function :IupTabs, [:pointer, :varargs], :pointer
|
|
158
|
+
attach_function :IupText, [:string], :pointer
|
|
159
|
+
attach_function :IupToggle, [:string, :string], :pointer
|
|
160
|
+
attach_function :IupTree, [], :pointer
|
|
161
|
+
attach_function :IupVal, [:string], :pointer
|
|
162
|
+
|
|
163
|
+
# Resources
|
|
164
|
+
# -- images
|
|
165
|
+
attach_function :IupImage, [:int, :int, :pointer], :pointer
|
|
166
|
+
attach_function :IupImageRGB, [:int, :int, :pointer], :pointer
|
|
167
|
+
attach_function :IupImageRGBA, [:int, :int, :pointer], :pointer
|
|
168
|
+
attach_function :IupSaveImageAsText, [:pointer, :string, :string, :string], :int
|
|
169
|
+
# -- keyboard
|
|
170
|
+
attach_function :IupNextField, [:pointer], :pointer
|
|
171
|
+
attach_function :IupPreviousField, [:pointer], :pointer
|
|
172
|
+
attach_function :IupGetFocus, [], :pointer
|
|
173
|
+
attach_function :IupSetFocus, [:pointer], :pointer
|
|
174
|
+
# -- menus
|
|
175
|
+
attach_function :IupItem, [:string, :string], :pointer
|
|
176
|
+
attach_function :IupMenu, [:pointer, :varargs], :pointer
|
|
177
|
+
attach_function :IupSeparator, [], :pointer
|
|
178
|
+
attach_function :IupSubmenu, [:string, :pointer], :pointer
|
|
179
|
+
# -- handle names
|
|
180
|
+
attach_function :IupSetHandle, [:string, :pointer], :void
|
|
181
|
+
attach_function :IupGetHandle, [:string], :pointer
|
|
182
|
+
attach_function :IupGetName, [:pointer], :strptr
|
|
183
|
+
# -- string names
|
|
184
|
+
attach_function :IupSetLanguage, [:string], :void
|
|
185
|
+
attach_function :IupGetLanguage, [], :strptr
|
|
186
|
+
|
|
187
|
+
attach_function :IupClipboard, [], :pointer
|
|
188
|
+
attach_function :IupTimer, [], :pointer
|
|
189
|
+
attach_function :IupHelp, [:string], :int
|
|
190
|
+
|
|
191
|
+
# helper functions, to create memory structures from arrays
|
|
192
|
+
|
|
193
|
+
# Input:: an array of chars
|
|
194
|
+
# Output:: pointer to memory holding array of chars
|
|
195
|
+
def IupLib.pointer_from_chars array
|
|
196
|
+
ptr = FFI::MemoryPointer.new :char, array.size
|
|
197
|
+
ptr.write_array_of_char array
|
|
198
|
+
return ptr
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# Input:: an array of ints
|
|
202
|
+
# Output:: pointer to memory holding array of ints
|
|
203
|
+
def IupLib.pointer_from_ints array
|
|
204
|
+
ptr = FFI::MemoryPointer.new :int, array.size
|
|
205
|
+
ptr.write_array_of_int array
|
|
206
|
+
return ptr
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module ScintillaLib # :nodoc:
|
|
2
|
+
extend FFI::Library
|
|
3
|
+
|
|
4
|
+
case RbConfig::CONFIG['host_os']
|
|
5
|
+
# when /mswin|mingw/
|
|
6
|
+
# ffi_lib 'lib/library/iupimglib.lib'
|
|
7
|
+
when /linux|cygwin/
|
|
8
|
+
ffi_lib 'libiup_scintilla'
|
|
9
|
+
else
|
|
10
|
+
raise Exception, 'iup scintilla library not found for this platform'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attach_function :IupScintilla, [], :pointer
|
|
14
|
+
attach_function :IupScintillaOpen, [], :void
|
|
15
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# methods to help construct attribute methods
|
|
4
|
+
#
|
|
5
|
+
module AttributeBuilders
|
|
6
|
+
|
|
7
|
+
# Given the name of an attribute, this method creates a new
|
|
8
|
+
# method which accepts an optional value. Providing the value
|
|
9
|
+
# will set the named attribute for this object, or else its
|
|
10
|
+
# current value will be returned.
|
|
11
|
+
def define_attribute name
|
|
12
|
+
attribute = name.to_s.upcase
|
|
13
|
+
define_method name do |val=nil|
|
|
14
|
+
if val.nil?
|
|
15
|
+
IupLib.IupGetAttribute(@handle, attribute).first
|
|
16
|
+
else
|
|
17
|
+
IupLib.IupSetAttribute @handle, attribute, val.to_s
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Given the name of an attribute, this method creates a new
|
|
23
|
+
# method which returns its current value.
|
|
24
|
+
def define_readonly name
|
|
25
|
+
attribute = name.to_s.upcase
|
|
26
|
+
define_method name do
|
|
27
|
+
IupLib.IupGetAttribute(@handle, attribute).first
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Given the name of an attribute, this method creates a new
|
|
32
|
+
# method which accepts a value and sets the named attribute
|
|
33
|
+
# for this object.
|
|
34
|
+
def define_writeonly name
|
|
35
|
+
attribute = name.to_s.upcase
|
|
36
|
+
define_method name do |val|
|
|
37
|
+
IupLib.IupSetAttribute @handle, attribute, val
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Given the name of an attribute, this method creates a new
|
|
42
|
+
# method requiring an id number as a parameter and an optional value.
|
|
43
|
+
# Providing the value will set the named attribute for this object using the
|
|
44
|
+
# id number, e.g. "ITEM1", or else the current value will be returned.
|
|
45
|
+
# This supports attributes such as "ITEM1" "ITEM2" by making the id number a parameter.
|
|
46
|
+
def define_id_attribute name
|
|
47
|
+
define_method name do |id, val=nil|
|
|
48
|
+
attribute = "#{name}#{id}".upcase
|
|
49
|
+
if val.nil?
|
|
50
|
+
IupLib.IupGetAttribute(@handle, attribute).first
|
|
51
|
+
else
|
|
52
|
+
IupLib.IupSetAttribute @handle, attribute, val.to_s
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Given the name of an attribute, this method creates a new
|
|
58
|
+
# method requiring an id number as a parameter.
|
|
59
|
+
# The current value of the attribute name + id will be returned.
|
|
60
|
+
# This supports attributes such as "ITEM1" "ITEM2" by making the id number a parameter.
|
|
61
|
+
def define_id_readonly name
|
|
62
|
+
define_method name do |id|
|
|
63
|
+
IupLib.IupGetAttribute(@handle, "#{name}#{id}".upcase).first
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Given the name of an attribute, this method creates a new
|
|
68
|
+
# method requiring an id number as a parameter and a value.
|
|
69
|
+
# Providing the value will set the named attribute for this object using the
|
|
70
|
+
# id number, e.g. "ITEM1".
|
|
71
|
+
# This supports attributes such as "ITEM1" "ITEM2" by making the id number a parameter.
|
|
72
|
+
def define_id_writeonly name
|
|
73
|
+
define_method name do |id, val|
|
|
74
|
+
IupLib.IupSetAttribute @handle, "#{name}#{id}".upcase, val.to_s
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Given the name of an attribute, this method creates a new method taking a
|
|
79
|
+
# property name and an optional value.
|
|
80
|
+
# If given the value, the new method will set the attribute's property to the value.
|
|
81
|
+
# Otherwise, the current value of the attribute's property will be returned.
|
|
82
|
+
# This supports attributes such as "ITEM=val", providing a parameter for the property name.
|
|
83
|
+
def define_property_attribute name
|
|
84
|
+
attribute = name.to_s.upcase
|
|
85
|
+
define_method name do |property, val=nil|
|
|
86
|
+
if val.nil?
|
|
87
|
+
IupLib.IupGetAttribute(@handle, attribute, property.upcase).first
|
|
88
|
+
else
|
|
89
|
+
IupLib.IupSetAttribute @handle, attribute, "#{property}=#{val}".upcase
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Given the name of an attribute, this method creates a new method taking a
|
|
95
|
+
# property name and a value.
|
|
96
|
+
# The new method will set the attribute's property to the value.
|
|
97
|
+
# This supports attributes such as "ITEM=val", providing a parameter for the property name.
|
|
98
|
+
def define_property_writeonly name
|
|
99
|
+
attribute = name.to_s.upcase
|
|
100
|
+
define_method name do |property, val|
|
|
101
|
+
IupLib.IupSetAttribute @handle, attribute, "#{property}=#{val}".upcase
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# Defines method for getting/setting attribute values.
|
|
4
|
+
module AttributeReference
|
|
5
|
+
|
|
6
|
+
# Method used to get or set the value of attributes.
|
|
7
|
+
# when retrieving:: simply return the attribute with given name.
|
|
8
|
+
# when setting:: an attribute reference can be defined by its
|
|
9
|
+
# string name or directly as an instance of target class
|
|
10
|
+
def attribute_reference name, target, val=nil
|
|
11
|
+
case val
|
|
12
|
+
when NilClass
|
|
13
|
+
IupLib.IupGetAttribute(@handle, name).first
|
|
14
|
+
when String
|
|
15
|
+
IupLib.IupSetAttribute @handle, name, val
|
|
16
|
+
when target
|
|
17
|
+
image_name = IupLib.IupGetName(name).first
|
|
18
|
+
if image_name.nil? or image_name.empty?
|
|
19
|
+
image_name = SecureRandom.uuid
|
|
20
|
+
val.assign_handle image_name
|
|
21
|
+
end
|
|
22
|
+
IupLib.IupSetAttribute @handle, name, image_name
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# Used to contain a child widget, but itself provides no visible decorations.
|
|
4
|
+
#
|
|
5
|
+
# == Attributes
|
|
6
|
+
#
|
|
7
|
+
# border:: Shows a border around the box, values 'yes' / 'no'.
|
|
8
|
+
# canfocus:: Value is read-only and always 'no'.
|
|
9
|
+
# clientoffset:: read-only, returns current offset of box in its client
|
|
10
|
+
# as "widthxheight".
|
|
11
|
+
# clientsize:: read-only, returns current size of box as "widthxheight".
|
|
12
|
+
# expand:: Allows box to fill available space in indicated direction.
|
|
13
|
+
# Values 'no' / 'horizontal' / 'vertical' / 'yes'.
|
|
14
|
+
#
|
|
15
|
+
class BackgroundBox < Widget
|
|
16
|
+
|
|
17
|
+
# Creates an instance of the box.
|
|
18
|
+
# widget:: the child widget to contain
|
|
19
|
+
# block:: optional block to set up the box's attributes.
|
|
20
|
+
def initialize widget, &block
|
|
21
|
+
@handle = IupLib.IupBackgroundBox widget.handle
|
|
22
|
+
|
|
23
|
+
# run any provided block on instance, to set up further attributes
|
|
24
|
+
self.instance_eval &block if block_given?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
define_attribute :border
|
|
28
|
+
define_readonly :canfocus
|
|
29
|
+
define_attribute :clientoffset
|
|
30
|
+
define_attribute :clientsize
|
|
31
|
+
define_attribute :expand
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# A button can display some text, an image, or both.
|
|
4
|
+
# When clicked, a specified _action_ function is called.
|
|
5
|
+
# The action should return +Iup::DEFAULT+, or,
|
|
6
|
+
# if the button should exit the application, +Iup::CLOSE+.
|
|
7
|
+
#
|
|
8
|
+
# # Example 1: A button with some text and an action
|
|
9
|
+
# Button.new 'click me', ->{
|
|
10
|
+
# puts 'clicked'
|
|
11
|
+
# DEFAULT
|
|
12
|
+
# }
|
|
13
|
+
# ---
|
|
14
|
+
# # Example 2: a button with an image stored in +img+ and
|
|
15
|
+
# # action specified by a separate method; some padding around
|
|
16
|
+
# # the image within the button.
|
|
17
|
+
# def click_fn
|
|
18
|
+
# puts 'clicked'
|
|
19
|
+
# DEFAULT
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# Button.new '', ->{ click_fn } do
|
|
23
|
+
# image img
|
|
24
|
+
# padding '50x20'
|
|
25
|
+
# end
|
|
26
|
+
# ---
|
|
27
|
+
# # Example 3: a button with text and image, image placed above
|
|
28
|
+
# # text. The text contains an & before the "x", so the action
|
|
29
|
+
# # can be triggered using ALT+x, and closes the application.
|
|
30
|
+
# Button.new 'e&xit', ->{ puts 'exit'; CLOSE } do
|
|
31
|
+
# image img
|
|
32
|
+
# imageposition 'top'
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
# == Attributes
|
|
36
|
+
#
|
|
37
|
+
# alignment:: Sets the horizontal and vertical alignment.
|
|
38
|
+
# The value is a string "horizontal:vertical", with
|
|
39
|
+
# options ALEFT, ACENTER, ARIGHT or none.
|
|
40
|
+
# canfocus:: Enables the control to gain focus. Values 'yes' / 'no'.
|
|
41
|
+
# expand:: Allows button to fill available space in indicated direction.
|
|
42
|
+
# Values 'no' / 'horizontal' / 'vertical' / 'yes'.
|
|
43
|
+
# flat:: If set, hides the button's border until mouse enters the button area.
|
|
44
|
+
# Values 'yes' / 'no'.
|
|
45
|
+
# impressborder:: If set, shows button borders even if impress defined.
|
|
46
|
+
# Values 'yes' / 'no'.
|
|
47
|
+
# imageposition:: Position of image relative to text.
|
|
48
|
+
# Values 'left' / 'right' / 'top' / 'bottom'/
|
|
49
|
+
# padding:: Margin in x and y directions, value as "mxn".
|
|
50
|
+
# position:: <b>read-only</b> returns position in pixels within client window
|
|
51
|
+
# as "x,y".
|
|
52
|
+
# rastersize:: Size of the button, in pixels, value as "widthxheight".
|
|
53
|
+
# screenposition:: <b>read-only</b> returns position in pixels on screen
|
|
54
|
+
# as "x,y".
|
|
55
|
+
# spacing:: Space between image and text, value as a number.
|
|
56
|
+
# tip:: Tooltip string.
|
|
57
|
+
# title:: Label text displayed on the button.
|
|
58
|
+
#
|
|
59
|
+
class Button < Widget
|
|
60
|
+
include ImageAttributes
|
|
61
|
+
|
|
62
|
+
# Creates an instance of a button.
|
|
63
|
+
# title:: the text to display on the button.
|
|
64
|
+
# callback:: procedure to call when button is left-clicked.
|
|
65
|
+
# block:: optional block to set up the button's attributes.
|
|
66
|
+
def initialize title='', callback = nil, &block
|
|
67
|
+
@handle = IupLib.IupButton title, nil
|
|
68
|
+
|
|
69
|
+
action callback unless callback.nil?
|
|
70
|
+
|
|
71
|
+
# run any provided block on instance, to set up further attributes
|
|
72
|
+
self.instance_eval &block if block_given?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# -- attributes
|
|
76
|
+
|
|
77
|
+
define_attribute :alignment
|
|
78
|
+
define_attribute :canfocus
|
|
79
|
+
define_attribute :expand
|
|
80
|
+
define_attribute :flat
|
|
81
|
+
define_attribute :focus
|
|
82
|
+
define_attribute :impressborder
|
|
83
|
+
define_attribute :imageposition
|
|
84
|
+
define_attribute :padding
|
|
85
|
+
define_readonly :position
|
|
86
|
+
define_attribute :rastersize
|
|
87
|
+
define_readonly :screenposition
|
|
88
|
+
define_attribute :spacing
|
|
89
|
+
define_attribute :tip
|
|
90
|
+
define_attribute :title
|
|
91
|
+
|
|
92
|
+
# -- callbacks
|
|
93
|
+
|
|
94
|
+
# Action generated when the button 1 (usually left) is selected.
|
|
95
|
+
def action callback
|
|
96
|
+
unless callback.arity.zero?
|
|
97
|
+
raise ArgumentError, 'action must take 0 arguments'
|
|
98
|
+
end
|
|
99
|
+
cb = Proc.new do |ih|
|
|
100
|
+
callback.call
|
|
101
|
+
end
|
|
102
|
+
define_callback cb, 'ACTION', :plain
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
include ButtonCallback
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
module CallbackSetter
|
|
4
|
+
def define_callback callback, name, type=:plain
|
|
5
|
+
# use a hash to store callbacks
|
|
6
|
+
@callbacks = {} unless @callbacks
|
|
7
|
+
@callbacks[name] = callback
|
|
8
|
+
|
|
9
|
+
case type
|
|
10
|
+
when :d_i
|
|
11
|
+
IupLib.IupSetCallbackD_I @handle, name, callback
|
|
12
|
+
when :ff_i
|
|
13
|
+
IupLib.IupSetCallbackFF_I @handle, name, callback
|
|
14
|
+
when :fiis_i
|
|
15
|
+
IupLib.IupSetCallbackFIIS_I @handle, name, callback
|
|
16
|
+
when :s_i
|
|
17
|
+
IupLib.IupSetCallbackS_I @handle, name, callback
|
|
18
|
+
when :sii_i
|
|
19
|
+
IupLib.IupSetCallbackSII_I @handle, name, callback
|
|
20
|
+
when :i_i
|
|
21
|
+
IupLib.IupSetCallbackI_I @handle, name, callback
|
|
22
|
+
when :i_s
|
|
23
|
+
IupLib.IupSetCallbackI_S @handle, name, callback
|
|
24
|
+
when :ii_i
|
|
25
|
+
IupLib.IupSetCallbackII_I @handle, name, callback
|
|
26
|
+
when :iff_i
|
|
27
|
+
IupLib.IupSetCallbackIFF_I @handle, name, callback
|
|
28
|
+
when :iiff_i
|
|
29
|
+
IupLib.IupSetCallbackIIFF_I @handle, name, callback
|
|
30
|
+
when :iiffi_i
|
|
31
|
+
IupLib.IupSetCallbackIIFFI_I @handle, name, callback
|
|
32
|
+
when :iiffff_i
|
|
33
|
+
IupLib.IupSetCallbackIIFFFF_I @handle, name, callback
|
|
34
|
+
when :is_i
|
|
35
|
+
IupLib.IupSetCallbackIS_I @handle, name, callback
|
|
36
|
+
when :iis_i
|
|
37
|
+
IupLib.IupSetCallbackIIS_I @handle, name, callback
|
|
38
|
+
when :iii_i
|
|
39
|
+
IupLib.IupSetCallbackIII_I @handle, name, callback
|
|
40
|
+
when :iiii_i
|
|
41
|
+
IupLib.IupSetCallbackIIII_I @handle, name, callback
|
|
42
|
+
when :iiis_i
|
|
43
|
+
IupLib.IupSetCallbackIIIS_I @handle, name, callback
|
|
44
|
+
when :iiiis_i
|
|
45
|
+
IupLib.IupSetCallbackIIIIS_I @handle, name, callback
|
|
46
|
+
when :plain
|
|
47
|
+
IupLib.IupSetCallbackPlain @handle, name, callback
|
|
48
|
+
when :plain_v
|
|
49
|
+
IupLib.IupSetCallbackPlain_v @handle, name, callback
|
|
50
|
+
when :p_i
|
|
51
|
+
IupLib.IupSetCallbackP_I @handle, name, callback
|
|
52
|
+
when :pp_i
|
|
53
|
+
IupLib.IupSetCallbackPP_I @handle, name, callback
|
|
54
|
+
when :ss_i
|
|
55
|
+
IupLib.IupSetCallbackSS_I @handle, name, callback
|
|
56
|
+
when :ssi_i
|
|
57
|
+
IupLib.IupSetCallbackSSI_I @handle, name, callback
|
|
58
|
+
when :ssiii_i
|
|
59
|
+
IupLib.IupSetCallbackSSIII_I @handle, name, callback
|
|
60
|
+
else
|
|
61
|
+
raise ArgumentError, "unknown callback type #{type}, name #{name}"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def num_args arity
|
|
68
|
+
result = ""
|
|
69
|
+
|
|
70
|
+
arity.times do |i|
|
|
71
|
+
result << "a#{i},"
|
|
72
|
+
end
|
|
73
|
+
result.sub!(/,$/, "")
|
|
74
|
+
return result
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|