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
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# A Canvas is a working area for the application.
|
|
4
|
+
#
|
|
5
|
+
# Many methods working on the Canvas are drawn from the CD library:
|
|
6
|
+
# http://webserver2.tecgraf.puc-rio.br/cd/
|
|
7
|
+
#
|
|
8
|
+
# In this example, notice how the dialog is mapped, the canvas initialised,
|
|
9
|
+
# and finally the dialog is shown.
|
|
10
|
+
#
|
|
11
|
+
# mainloop do
|
|
12
|
+
# cnv = Canvas.new do
|
|
13
|
+
# rastersize '300x200'
|
|
14
|
+
# action ->(x, y){ # called on redraw: (x,y) refer to scrollbar positions, if used
|
|
15
|
+
# clear
|
|
16
|
+
# foreground CD_BLUE
|
|
17
|
+
# box 10, 100, 10, 100
|
|
18
|
+
# foreground CD_RED
|
|
19
|
+
# rectangle 10, 100, 10, 100
|
|
20
|
+
# text 200, 180, 'hello from Ruby'
|
|
21
|
+
# DEFAULT
|
|
22
|
+
# }
|
|
23
|
+
# end
|
|
24
|
+
#
|
|
25
|
+
# dlg = Dialog.new VBox.new(cnv){ margin '10x10' } do
|
|
26
|
+
# title 'IupCanvas + Canvas Draw'
|
|
27
|
+
# size '350x220'
|
|
28
|
+
# end.map
|
|
29
|
+
#
|
|
30
|
+
# cnv.init # this has to be done after mapping the dialog
|
|
31
|
+
#
|
|
32
|
+
# dlg.show
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
#
|
|
36
|
+
# == Attributes
|
|
37
|
+
#
|
|
38
|
+
# canfocus:: Enables the control to gain focus. Values 'yes' / 'no'.
|
|
39
|
+
# cursor:: Defines the mouse shape / cursor for the canvas.
|
|
40
|
+
# drawsize:: Size of the drawing area in pixels, as "widthxheight".
|
|
41
|
+
# expand:: Allows canvas to fill available space in indicated direction.
|
|
42
|
+
# Values 'no' / 'horizontal' / 'vertical' / 'yes'.
|
|
43
|
+
# padding:: Margin in x and y directions, value as "mxn".
|
|
44
|
+
# position:: <b>read-only</b> returns position in pixels within client window
|
|
45
|
+
# as "x,y".
|
|
46
|
+
# rastersize:: Size of the canvas, in pixels, value as "widthxheight".
|
|
47
|
+
# screenposition:: <b>read-only</b> returns position in pixels on screen
|
|
48
|
+
# scrollbar:: Selects 'no' / 'horizontal' / 'vertical' / 'yes' (for both) scrollbars.
|
|
49
|
+
# tip:: Tooltip string.
|
|
50
|
+
#
|
|
51
|
+
class Canvas < Widget
|
|
52
|
+
include DragDropAttributes
|
|
53
|
+
include ScrollBarAttributes
|
|
54
|
+
|
|
55
|
+
# Creates an instance of the canvas.
|
|
56
|
+
# handle:: an optional Canvas handle.
|
|
57
|
+
# block:: optional block to set up Canvas attributes.
|
|
58
|
+
def initialize handle = IupLib.IupCanvas(''), &block
|
|
59
|
+
@handle = handle
|
|
60
|
+
|
|
61
|
+
# run any provided block on instance, to set up further attributes
|
|
62
|
+
self.instance_eval &block if block_given?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# This must be called after the widget is mapped, to create and
|
|
66
|
+
# setup the canvas.
|
|
67
|
+
def init
|
|
68
|
+
@canvas = CdLib.cdCreateCanvas CdLib.cdContextIup, @handle
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# -- attributes
|
|
72
|
+
|
|
73
|
+
define_attribute :border
|
|
74
|
+
define_attribute :canfocus
|
|
75
|
+
define_attribute :cursor
|
|
76
|
+
define_attribute :drawsize
|
|
77
|
+
define_attribute :expand
|
|
78
|
+
define_attribute :padding
|
|
79
|
+
define_readonly :position
|
|
80
|
+
define_attribute :rastersize
|
|
81
|
+
define_readonly :screenposition
|
|
82
|
+
define_attribute :tip
|
|
83
|
+
|
|
84
|
+
# -- CD method calls
|
|
85
|
+
|
|
86
|
+
# --- initialisation
|
|
87
|
+
|
|
88
|
+
# call when canvas no longer needed.
|
|
89
|
+
def kill
|
|
90
|
+
CdLib.cdKillCanvas @canvas
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# call to activate canvas.
|
|
94
|
+
# (Not usually needed - depends on driver.)
|
|
95
|
+
def activate
|
|
96
|
+
CdLib.cdCanvasActivate @canvas
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# call to deactivate canvas.
|
|
100
|
+
# (Not usually needed - depends on driver.)
|
|
101
|
+
def deactivate
|
|
102
|
+
CdLib.cdCanvasDeactivate @canvas
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Used to set coordinates of a viewport (the canvas coordinates).
|
|
106
|
+
def viewport x1, y1, x2, y2
|
|
107
|
+
CdLib.wdCanvasViewport @canvas, x1, y1, x2, y2
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Used to set coordinates of a window (the world coordinates).
|
|
111
|
+
def window x1, y1, x2, y2
|
|
112
|
+
CdLib.wdCanvasWindow @canvas, x1, y1, x2, y2
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# redraws the underlying canvas.
|
|
116
|
+
def redraw
|
|
117
|
+
IupLib.IupRedraw @handle
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# --- general attributes
|
|
121
|
+
|
|
122
|
+
# Sets the foreground colour, if a value is given, else returns current value.
|
|
123
|
+
#
|
|
124
|
+
# Colour may be one of:
|
|
125
|
+
# * string, in form "RR GG BB"
|
|
126
|
+
# * colour constant, e.g. CD_BLACK, as listed in Iup
|
|
127
|
+
def foreground colour=CD_QUERY
|
|
128
|
+
case colour
|
|
129
|
+
when String # assume in form 'RR GG BB'
|
|
130
|
+
r, g, b = colour.split(' ').collect &:to_i
|
|
131
|
+
CdLib.cdCanvasForeground @canvas, CdLib.cdEncodeColor(r, g, b)
|
|
132
|
+
else
|
|
133
|
+
CdLib.cdCanvasForeground @canvas, colour
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Sets the background colour, if a value is given, else returns current value.
|
|
138
|
+
#
|
|
139
|
+
# Colour may be one of:
|
|
140
|
+
# * string, in form "RR GG BB"
|
|
141
|
+
# * colour constant, e.g. CD_BLACK, as listed in Iup
|
|
142
|
+
def background colour=CD_QUERY
|
|
143
|
+
case colour
|
|
144
|
+
when String # assume in form 'RR GG BB'
|
|
145
|
+
r, g, b = colour.split(' ').collect &:to_i
|
|
146
|
+
CdLib.cdCanvasBackground @canvas, CdLib.cdEncodeColor(r, g, b)
|
|
147
|
+
else
|
|
148
|
+
CdLib.cdCanvasBackground @canvas, colour
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Sets the writing mode for all primitives, if a value is given.
|
|
153
|
+
# Else returns the current value.
|
|
154
|
+
# See Iup for a list of available writemode values.
|
|
155
|
+
def writemode mode=CD_QUERY
|
|
156
|
+
CdLib.cdCanvasWriteMode @canvas, mode
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# --- control
|
|
160
|
+
|
|
161
|
+
# Clears the canvas.
|
|
162
|
+
def clear
|
|
163
|
+
CdLib.cdCanvasClear @canvas
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# --- begin/end blocks
|
|
168
|
+
|
|
169
|
+
# Begin the definition of a sequence of vertices.
|
|
170
|
+
# Valid polygon mode values are listed in Iup.
|
|
171
|
+
def begin_block mode
|
|
172
|
+
CdLib.cdCanvasBegin @canvas, mode
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# Specify a vertex at position (x, y).
|
|
176
|
+
def vertex x, y
|
|
177
|
+
CdLib.cdCanvasVertex @canvas, x, y
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# End the definition of a sequence of vertices.
|
|
181
|
+
def end_block
|
|
182
|
+
CdLib.cdCanvasEnd @canvas
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Specify action for next point on path.
|
|
186
|
+
# Valid path actions are listed in Iup.
|
|
187
|
+
def pathset action
|
|
188
|
+
CdLib.cdCanvasPathSet @canvas, action
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# --- marks
|
|
192
|
+
|
|
193
|
+
# Configures pixel (x, y) with colour.
|
|
194
|
+
def pixel x, y, colour
|
|
195
|
+
CdLib.cdCanvasPixel @canvas, x, y, colour
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Draws a mark at position (x, y).
|
|
199
|
+
def mark x, y
|
|
200
|
+
CdLib.cdCanvasMark @canvas, x, y
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# Sets the marktype, if a value is given, else returns the current value.
|
|
204
|
+
# See Iup for available marktype values.
|
|
205
|
+
def marktype type=CD_QUERY
|
|
206
|
+
CdLib.cdCanvasMarkType @canvas, type
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# Sets the marksize, if a pixel value is given,
|
|
210
|
+
# else, returns the current value.
|
|
211
|
+
def marksize size=CD_QUERY
|
|
212
|
+
CdLib.cdCanvasMarkSize size
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# --- lines
|
|
216
|
+
|
|
217
|
+
# Draws a line from (x1, y1) to (x2, y2).
|
|
218
|
+
def line x1, y1, x2, y2
|
|
219
|
+
CdLib.cdCanvasLine @canvas, x1, y1, x2, y2
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Draws a rectangle bounding (xmin, ymin) to (xmax, ymax).
|
|
223
|
+
def rectangle xmin, xmax, ymin, ymax
|
|
224
|
+
CdLib.cdCanvasRect @canvas, xmin, xmax, ymin, ymax
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Draws an arc of an ellipse - a pie-shaped slice.
|
|
228
|
+
# Angles are in degrees, counterclockwise.
|
|
229
|
+
def arc xc, yc, w, h, angle1, angle2
|
|
230
|
+
CdLib.cdCanvasArc @canvas, xc, yc, w, h, angle1, angle2
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Sets linestyle, if a value is given, else returns the current style.
|
|
234
|
+
# See Iup for available linestyle values.
|
|
235
|
+
def linestyle style=CD_QUERY
|
|
236
|
+
CdLib.cdCanvasLineStyle @canvas, style
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Sets linewidth, if a pixel value is given, else returns the current width.
|
|
240
|
+
def linewidth width=CD_QUERY
|
|
241
|
+
CdLib.cdCanvasLineWidth @canvas, width
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Sets linejoin, if a value is given, else returns the current value.
|
|
245
|
+
# See Iup for available linejoin values.
|
|
246
|
+
def linejoin style=CD_QUERY
|
|
247
|
+
CdLib.cdCanvasLineJoin @canvas, style
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# Sets linecap, if a value is given, else returns the current value.
|
|
251
|
+
# See Iup for available linecap values.
|
|
252
|
+
def linecap style=CD_QUERY
|
|
253
|
+
CdLib.cdCanvasLineCap @canvas, style
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# -- filled areas
|
|
257
|
+
|
|
258
|
+
# Fills a rectangle, according to current interior style.
|
|
259
|
+
def box xmin, xmax, ymin, ymax
|
|
260
|
+
CdLib.cdCanvasBox @canvas, xmin, xmax, ymin, ymax
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Fills a sector, according to current interior style.
|
|
264
|
+
# A sector is an arc of an ellipse - a pie-shaped slice.
|
|
265
|
+
# Angles are in degrees, counterclockwise.
|
|
266
|
+
def sector xc, yc, w, h, angle1, angle2
|
|
267
|
+
CdLib.cdCanvasSector @canvas, xc, yc, w, h, angle1, angle2
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Fills a chord, according to current interior style.
|
|
271
|
+
# A chord is an arc of an ellipse - with the arc points connected.
|
|
272
|
+
# Angles are in degrees, counterclockwise.
|
|
273
|
+
def chord xc, yc, w, h, angle1, angle2
|
|
274
|
+
CdLib.cdCanvasChord @canvas, xc, yc, w, h, angle1, angle2
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Sets the opacity, if a value is given, else returns current value.
|
|
278
|
+
# See Iup for background opacity mode values.
|
|
279
|
+
def backopacity opacity=CD_QUERY
|
|
280
|
+
CdLib.cdCanvasBackOpacity @canvas, opacity
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Sets the fill mode, if a value is given, else returns current value.
|
|
284
|
+
# See Iup for fill mode values.
|
|
285
|
+
def fillmode mode=CD_QUERY
|
|
286
|
+
CdLib.cdCanvasFillMode @canvas, mode
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Sets the interior style, if a value is given, else returns current value.
|
|
290
|
+
# See Iup for interior style values.
|
|
291
|
+
def interiorstyle style=CD_QUERY
|
|
292
|
+
CdLib.cdCanvasInteriorStyle @canvas, style
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# Sets the hatch style, if a value is given, else returns current value.
|
|
296
|
+
# See Iup for hatch style values.
|
|
297
|
+
def hatch style=CD_QUERY
|
|
298
|
+
CdLib.cdCanvasHatch @canvas, style
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# fgbg is a string representing the stipple pattern in binary
|
|
302
|
+
def stipple w, h, fgbg
|
|
303
|
+
CdLib.cdCanvasStipple @canvas, w, h, fgbg
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# -- text
|
|
307
|
+
|
|
308
|
+
# Draw text str at position (x, y). Expects an ANSI-string.
|
|
309
|
+
def text x, y, str
|
|
310
|
+
CdLib.cdCanvasText @canvas, x, y, str
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# Sets text font.
|
|
314
|
+
# typeface:: 'Courier', 'Helvetica', 'Times' built-in, but any known
|
|
315
|
+
# font can be used
|
|
316
|
+
# style:: see Iup for list of text styles.
|
|
317
|
+
# size:: the font height, default is 12.
|
|
318
|
+
def font typeface, style, size
|
|
319
|
+
CdLib.cdCanvasFont @canvas, typeface, style, size
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# Sets the current font.
|
|
323
|
+
def nativefont font
|
|
324
|
+
CdLib.cdCanvasNativefont @canvas, font
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Sets vertical and horizontal alignment if a value is given,
|
|
328
|
+
# else returns current value.
|
|
329
|
+
# See Iup for text alignment values.
|
|
330
|
+
def textalignment alignment=CD_QUERY
|
|
331
|
+
CdLib.cdCanvasTextAlignment @canvas, alignment
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Sets orientation angle if a value is given,
|
|
335
|
+
# else returns current value.
|
|
336
|
+
def textorientation orientation=CD_QUERY
|
|
337
|
+
CdLib.cdCanvasTextOrientation @canvas, orientation
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# -- vector text
|
|
341
|
+
|
|
342
|
+
# Draws str as vector text at position (x, y).
|
|
343
|
+
# Respects
|
|
344
|
+
def vectortext x, y, str
|
|
345
|
+
CdLib.cdCanvasVectorText @canvas, x, y, str
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# Defines the text direction using two points: (x1, y1) and (x2, y2).
|
|
349
|
+
def vectortext_direction x1, y1, x2, y2
|
|
350
|
+
CdLib.cdCanvasVectorTextDirection @canvas, x1, y1, x2, y2
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# Modifies font size so str fits within a box width x height in size.
|
|
354
|
+
def vectortext_size width, height, str
|
|
355
|
+
CdLib.cdCanvasVectorTextSize @canvas, width, height, str
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# If a size is given, then the font size is given that height.
|
|
359
|
+
# Otherwise, the current value is returned.
|
|
360
|
+
def vectortext_charsize size=CD_QUERY
|
|
361
|
+
CdLib.cdCanvasVectorCharSize @canvas, size
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Directly modifies the font size.
|
|
365
|
+
def vectortext_fontsize size_x, size_y
|
|
366
|
+
CdLib.cdCanvasVectorFontSize @canvas, size_x, size_y
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
# Replaces current vector font with that loaded from given filename.
|
|
370
|
+
# Returns the font name, or null.
|
|
371
|
+
def vectortext_loadfont filename
|
|
372
|
+
CdLib.cdCanvasVectorFont @canvas, filename
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
# -- callbacks
|
|
376
|
+
|
|
377
|
+
# Action generated when the canvas needs to be redrawn.
|
|
378
|
+
# Action takes a callback which accepts 2 arguments (posx, posy).
|
|
379
|
+
# posx, posy are the position of the horizontal and vertical thumbs of the scrollbar.
|
|
380
|
+
def action callback
|
|
381
|
+
unless callback.arity == 2
|
|
382
|
+
raise ArgumentError, 'action must take 2 arguments: (posx, posy)'
|
|
383
|
+
end
|
|
384
|
+
cb = Proc.new do |ih, posx, posy|
|
|
385
|
+
callback.call posx, posy
|
|
386
|
+
end
|
|
387
|
+
define_callback cb, 'ACTION', :ff_i
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
include ButtonCallback
|
|
391
|
+
|
|
392
|
+
# Called when the canvas gets or loses the keyboard focus.
|
|
393
|
+
# Callback takes a single parameter: (focus)
|
|
394
|
+
# focus:: non-zero if canvas gaining focus, else zero.
|
|
395
|
+
def focus_cb callback
|
|
396
|
+
unless callback.arity == 1
|
|
397
|
+
raise ArgumentError, 'focus_cb callback must take 1 argument, the focus'
|
|
398
|
+
end
|
|
399
|
+
cb = Proc.new do |ih, focus|
|
|
400
|
+
callback.call focus
|
|
401
|
+
end
|
|
402
|
+
define_callback cb, 'FOCUS_CB', :i_i
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
# Action generated when a key is pressed or released.
|
|
406
|
+
# keypress_cb takes a 2-argument callback: (character, pressed).
|
|
407
|
+
# pressed == 1 if key is pressed,
|
|
408
|
+
# pressed == 0 if key is released.
|
|
409
|
+
def keypress_cb callback
|
|
410
|
+
unless callback.arity == 2
|
|
411
|
+
raise ArgumentError, 'keypress_cb callback must take 2 arguments: (char, press)'
|
|
412
|
+
end
|
|
413
|
+
cb = Proc.new do |ih, char, press|
|
|
414
|
+
callback.call char, press
|
|
415
|
+
end
|
|
416
|
+
define_callback cb, 'KEYPRESS_CB', :ii_i
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
# Action generated when the mouse is moved.
|
|
420
|
+
# Callback takes 3 arguments: (x, y, state)
|
|
421
|
+
# x:: x position of mouse
|
|
422
|
+
# y:: y position of mouse
|
|
423
|
+
# state:: status of mouse buttons and certain keyboard keys at the moment the event was generated.
|
|
424
|
+
#--
|
|
425
|
+
# TODO: include functions, as in button_cb
|
|
426
|
+
#
|
|
427
|
+
def motion_cb callback
|
|
428
|
+
unless callback.arity == 3
|
|
429
|
+
raise ArgumentError, 'motion_cb callback must take 3 arguments: (x, y, state)'
|
|
430
|
+
end
|
|
431
|
+
cb = Proc.new do |ih, x, y, state|
|
|
432
|
+
callback.call x, y, state
|
|
433
|
+
end
|
|
434
|
+
define_callback cb, 'MOTION_CB', :iis_i
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
# Action generated when the canvas size is changed.
|
|
438
|
+
# resize_cb a 2-argument callback: (width, height).
|
|
439
|
+
# width:: internal width of canvas (client width)
|
|
440
|
+
# height:: internal height of canvas (client height)
|
|
441
|
+
def resize_cb callback
|
|
442
|
+
unless callback.arity == 2
|
|
443
|
+
raise ArgumentError, 'resize_cb callback must take 2 arguments: (width, height)'
|
|
444
|
+
end
|
|
445
|
+
cb = Proc.new do |ih, width, height|
|
|
446
|
+
callback.call width, height
|
|
447
|
+
end
|
|
448
|
+
define_callback cb, 'RESIZE_CB', :ii_i
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
# Action generated when the mouse wheel is rotated.
|
|
452
|
+
# wheel_cb a 4-argument callback: (delta, x, y, status).
|
|
453
|
+
# delta:: the amount the wheel was rotated in notches.
|
|
454
|
+
# x, y:: position in the canvas where the event has occurred, in pixels.
|
|
455
|
+
# status:: status of mouse buttons and certain keyboard keys at the moment the event was generated.
|
|
456
|
+
def wheel_cb callback
|
|
457
|
+
unless callback.arity == 4
|
|
458
|
+
raise ArgumentError, 'wheel_cb callback must take 4 arguments: (delta, x, y, status)'
|
|
459
|
+
end
|
|
460
|
+
cb = Proc.new do |ih, delta, x, y, status_ptr|
|
|
461
|
+
status = FFI::Pointer.new(status_ptr).read_string
|
|
462
|
+
callback.call delta, x, y, status
|
|
463
|
+
end
|
|
464
|
+
define_callback cb, 'WHEEL_CB', :fiis_i
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# Colour bar
|
|
4
|
+
#
|
|
5
|
+
class ColorBar < Widget
|
|
6
|
+
def initialize &block
|
|
7
|
+
open_controls
|
|
8
|
+
@handle = ControlsLib.IupColorbar
|
|
9
|
+
|
|
10
|
+
# run any provided block on instance, to set up further attributes
|
|
11
|
+
self.instance_eval &block if block_given?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# -- attributes
|
|
15
|
+
|
|
16
|
+
define_attribute :bufferize
|
|
17
|
+
define_id_attribute :cell
|
|
18
|
+
define_attribute :num_cells
|
|
19
|
+
define_readonly :count
|
|
20
|
+
define_attribute :num_parts
|
|
21
|
+
define_attribute :orientation
|
|
22
|
+
define_attribute :preview_size
|
|
23
|
+
define_attribute :show_preview
|
|
24
|
+
define_attribute :show_secondary
|
|
25
|
+
define_attribute :primary_cell
|
|
26
|
+
define_attribute :secondary_cell
|
|
27
|
+
define_attribute :squared
|
|
28
|
+
define_attribute :shadowed
|
|
29
|
+
define_attribute :transparency
|
|
30
|
+
|
|
31
|
+
define_attribute :expand
|
|
32
|
+
define_readonly :position
|
|
33
|
+
define_attribute :rastersize
|
|
34
|
+
define_readonly :screenposition
|
|
35
|
+
define_attribute :tip
|
|
36
|
+
|
|
37
|
+
# -- callbacks
|
|
38
|
+
|
|
39
|
+
# Called when the user double clicks a color cell to change its value.
|
|
40
|
+
# Callback is a 1-argument function: (cell_index),
|
|
41
|
+
# returns a new colour (as a string), or nil if no change.
|
|
42
|
+
def cell_cb callback
|
|
43
|
+
unless callback.arity == 1
|
|
44
|
+
raise ArgumentError, 'cell_cb callback must take 1 argument: (cell_index)'
|
|
45
|
+
end
|
|
46
|
+
cb = Proc.new do |ih, cell_index|
|
|
47
|
+
callback.call cell_index
|
|
48
|
+
end
|
|
49
|
+
define_callback cb, 'CELL_CB', :i_s
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Called when the user right click a cell with the Shift key pressed
|
|
53
|
+
# Callback is a 1-argument function: (cell_index).
|
|
54
|
+
def extended_cb callback
|
|
55
|
+
unless callback.arity == 1
|
|
56
|
+
raise ArgumentError, 'extended_cb callback must take 1 argument: (cell_index)'
|
|
57
|
+
end
|
|
58
|
+
cb = Proc.new do |ih, cell_index|
|
|
59
|
+
callback.call cell_index
|
|
60
|
+
end
|
|
61
|
+
define_callback cb, 'EXTENDED_CB', :i_i
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Called when a colour is selected.
|
|
65
|
+
# The primary colour is selected with the left mouse button, and if
|
|
66
|
+
# existent the secondary is selected with the right mouse button.
|
|
67
|
+
# Callback is a 2-argument function: (cell_index / type).
|
|
68
|
+
def select_cb callback
|
|
69
|
+
unless callback.arity == 2
|
|
70
|
+
raise ArgumentError, 'select_cb callback must take 2 arguments: (cell_index, type)'
|
|
71
|
+
end
|
|
72
|
+
cb = Proc.new do |ih, cell_index, type|
|
|
73
|
+
callback.call cell_index, type
|
|
74
|
+
end
|
|
75
|
+
define_callback cb, 'SELECT_CB', :ii_i
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# called when the user double clicks the preview area outside the preview cells to
|
|
79
|
+
# switch the primary and secondary selections. It is only called if SHOW_SECONDARY=YES.
|
|
80
|
+
# Callback takes 2 arguments: index of primary and secondary cells.
|
|
81
|
+
def switch_cb callback
|
|
82
|
+
unless callback.arity == 2
|
|
83
|
+
raise ArgumentError, 'switch_cb callback must take 2 arguments: (prim_cell, sec_cell)'
|
|
84
|
+
end
|
|
85
|
+
cb = Proc.new do |ih, cell_index, type|
|
|
86
|
+
callback.call cell_index, type
|
|
87
|
+
end
|
|
88
|
+
define_callback cb, 'SWITCH_CB', :ii_i
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
ColourBar = ColorBar
|
|
93
|
+
end
|
|
94
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# A ColourDialog allows the user to select a colour.
|
|
4
|
+
#
|
|
5
|
+
# Also see: Iup#get_colour
|
|
6
|
+
#
|
|
7
|
+
# == Attributes
|
|
8
|
+
#
|
|
9
|
+
# alpha:: If defined, enables alpha selection in dialog.
|
|
10
|
+
# Returns value if user pressed 'OK'.
|
|
11
|
+
# colortable:: "m;n;..." gives a list of values for the palette.
|
|
12
|
+
# parentdialog:: This dialog will be always in front of the parent dialog.
|
|
13
|
+
# If the parent is minimized, this dialog is automatically minimized.
|
|
14
|
+
# *Important* Closing the parent will also close the child, but the
|
|
15
|
+
# child dialog's CLOSE_CB method will not be called.
|
|
16
|
+
# showalpha:: If set, shows the colour table. Values 'yes' / 'no'.
|
|
17
|
+
# showcolortable:: If set, shows the colour table. Values 'yes' / 'no'.
|
|
18
|
+
# showhelp:: Shows a help button if +help_cb+ defined. Values 'yes' / 'no'.
|
|
19
|
+
# showhex:: If set, shows a hexadecimal representation of colour. Values 'yes' / 'no'.
|
|
20
|
+
# status:: <b>read-only</b> Returns '1' if 'OK' pressed, or null.
|
|
21
|
+
# title:: Title text for the dialog.
|
|
22
|
+
# value:: Initial value for dialog, and return value if 'OK' pressed,
|
|
23
|
+
# as 'r g b' or 'r g b a'.
|
|
24
|
+
# valuehex:: Initial value for dialog, and return value if 'OK' pressed,
|
|
25
|
+
# as 'rrggbb'.
|
|
26
|
+
# valuehsi:: Initial value for dialog, and return value if 'OK' pressed,
|
|
27
|
+
# as 'H S I'.
|
|
28
|
+
#
|
|
29
|
+
class ColourDialog < Widget
|
|
30
|
+
|
|
31
|
+
# Creates a dialog, using the optional block to set its attributes.
|
|
32
|
+
def initialize &block
|
|
33
|
+
@handle = IupLib.IupColorDlg
|
|
34
|
+
|
|
35
|
+
self.instance_eval &block if block_given?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Shows the dialog at position x, y.
|
|
39
|
+
def popup x=0, y=0
|
|
40
|
+
IupLib.IupPopup @handle, x, y
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# -- attributes
|
|
44
|
+
|
|
45
|
+
define_attribute :alpha
|
|
46
|
+
define_attribute :colortable
|
|
47
|
+
|
|
48
|
+
def parentdialog parent=nil # :nodoc:
|
|
49
|
+
attribute_reference 'PARENTDIALOG', Dialog, parent
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
define_attribute :showalpha
|
|
53
|
+
define_attribute :showcolortable
|
|
54
|
+
define_attribute :showhelp
|
|
55
|
+
define_attribute :showhex
|
|
56
|
+
define_readonly :status
|
|
57
|
+
define_attribute :title
|
|
58
|
+
define_attribute :value
|
|
59
|
+
define_attribute :valuehex
|
|
60
|
+
define_attribute :valuehsi
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Iup
|
|
2
|
+
|
|
3
|
+
# Defines attributes common to most widgets
|
|
4
|
+
#
|
|
5
|
+
# == Attributes
|
|
6
|
+
#
|
|
7
|
+
# active:: Enables or prevents user interaction.
|
|
8
|
+
# Typically, a widget will appear greyed-out when inactive.
|
|
9
|
+
# Values 'yes' / 'no'.
|
|
10
|
+
# bgcolor:: Specify RGB values for background colour, as "r g b".
|
|
11
|
+
# fgcolor:: Specify RGB values for foreground colour, as "r g b".
|
|
12
|
+
# font:: Sets the widget's font, using a font description.
|
|
13
|
+
# maxsize:: Maximum size of widget, value as "widthxheight".
|
|
14
|
+
# minsize:: Minimum size of widget, value as "widthxheight".
|
|
15
|
+
# size:: Size of the widget, in character units, value as "widthxheight".
|
|
16
|
+
# visible:: Shows or hides the widget. Values 'yes' / 'no'.
|
|
17
|
+
# wid:: <b>read-only</b> Native widget identifier.
|
|
18
|
+
# zorder:: <b>write-only</b> Alters z-order, values as 'top' / 'bottom'.
|
|
19
|
+
#
|
|
20
|
+
module CommonAttributes
|
|
21
|
+
extend AttributeBuilders
|
|
22
|
+
|
|
23
|
+
define_attribute :active
|
|
24
|
+
define_attribute :bgcolor
|
|
25
|
+
define_attribute :fgcolor
|
|
26
|
+
define_attribute :font
|
|
27
|
+
define_attribute :visible
|
|
28
|
+
|
|
29
|
+
define_attribute :maxsize
|
|
30
|
+
define_attribute :minsize
|
|
31
|
+
define_attribute :size
|
|
32
|
+
|
|
33
|
+
define_readonly :wid
|
|
34
|
+
define_writeonly :zorder
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Standard callback method for when a mouse button is pressed or released.
|
|
39
|
+
module ButtonCallback
|
|
40
|
+
|
|
41
|
+
# Action generated when any mouse button is pressed or released.
|
|
42
|
+
# button_cb takes a callback which accepts 5 arguments (button, state, x, y, status)
|
|
43
|
+
# button:: the number of the button that changed, one of: BUTTON1 (left), BUTTON2 (middle), BUTTON3 (right)
|
|
44
|
+
# state:: 1 for 'pressed', 0 for 'released'
|
|
45
|
+
# x:: x-coordinate
|
|
46
|
+
# y:: y-coordinate
|
|
47
|
+
# status:: status of the mouse buttons and some keyboard keys at the moment the event is generated.
|
|
48
|
+
#--
|
|
49
|
+
# TODO: include status test methods iup_iscontrol etc
|
|
50
|
+
#
|
|
51
|
+
def button_cb callback
|
|
52
|
+
unless callback.arity == 5
|
|
53
|
+
raise ArgumentError, 'button_cb callback must take 5 arguments: (button, state, x, y, status)'
|
|
54
|
+
end
|
|
55
|
+
cb = Proc.new do |ih, b, p, x, y, status|
|
|
56
|
+
callback.call b.chr, p, x, y, status
|
|
57
|
+
end
|
|
58
|
+
define_callback cb, 'BUTTON_CB', :iiiis_i
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|