iup-ffi 0.13.0-x86_64-linux

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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +21 -0
  3. data/README.md +139 -0
  4. data/lib/iup-ffi-plain.rb +51 -0
  5. data/lib/iup-ffi.rb +70 -0
  6. data/lib/library/linux/libcd.so +0 -0
  7. data/lib/library/linux/libim.so +0 -0
  8. data/lib/library/linux/libiup.so +0 -0
  9. data/lib/library/linux/libiup_scintilla.so +0 -0
  10. data/lib/library/linux/libiupcd.so +0 -0
  11. data/lib/library/linux/libiupcontrols.so +0 -0
  12. data/lib/library/linux/libiupim.so +0 -0
  13. data/lib/library/linux/libiupimglib.so +0 -0
  14. data/lib/plain/iupcdlib.rb +158 -0
  15. data/lib/plain/iupcontrolslib.rb +28 -0
  16. data/lib/plain/iupimglib.rb +15 -0
  17. data/lib/plain/iupimlib.rb +18 -0
  18. data/lib/plain/iuplib.rb +354 -0
  19. data/lib/plain/scintilla-lib.rb +17 -0
  20. data/lib/wrapped/attribute-builders.rb +93 -0
  21. data/lib/wrapped/attribute-reference.rb +27 -0
  22. data/lib/wrapped/background-box.rb +37 -0
  23. data/lib/wrapped/button.rb +152 -0
  24. data/lib/wrapped/callback-setter.rb +78 -0
  25. data/lib/wrapped/canvas.rb +698 -0
  26. data/lib/wrapped/colorbar.rb +212 -0
  27. data/lib/wrapped/colordialog.rb +121 -0
  28. data/lib/wrapped/common-attributes.rb +34 -0
  29. data/lib/wrapped/constants.rb +504 -0
  30. data/lib/wrapped/dial.rb +129 -0
  31. data/lib/wrapped/dialog.rb +309 -0
  32. data/lib/wrapped/drag-drop-attributes.rb +98 -0
  33. data/lib/wrapped/dynamic-fill-methods.rb +22 -0
  34. data/lib/wrapped/expander.rb +128 -0
  35. data/lib/wrapped/filedialog.rb +168 -0
  36. data/lib/wrapped/fill.rb +29 -0
  37. data/lib/wrapped/fontdialog.rb +71 -0
  38. data/lib/wrapped/frame.rb +70 -0
  39. data/lib/wrapped/gridbox.rb +188 -0
  40. data/lib/wrapped/hbox.rb +90 -0
  41. data/lib/wrapped/image-attributes.rb +58 -0
  42. data/lib/wrapped/image.rb +178 -0
  43. data/lib/wrapped/iup-global.rb +46 -0
  44. data/lib/wrapped/label.rb +110 -0
  45. data/lib/wrapped/link.rb +54 -0
  46. data/lib/wrapped/list.rb +567 -0
  47. data/lib/wrapped/matrix.rb +575 -0
  48. data/lib/wrapped/menu.rb +91 -0
  49. data/lib/wrapped/menuitem.rb +150 -0
  50. data/lib/wrapped/messagedialog.rb +127 -0
  51. data/lib/wrapped/progressbar.rb +91 -0
  52. data/lib/wrapped/progressdialog.rb +85 -0
  53. data/lib/wrapped/radio.rb +74 -0
  54. data/lib/wrapped/scintilla.rb +1112 -0
  55. data/lib/wrapped/scrollbar-attributes.rb +178 -0
  56. data/lib/wrapped/scrollbox.rb +40 -0
  57. data/lib/wrapped/separator.rb +24 -0
  58. data/lib/wrapped/splitbox.rb +114 -0
  59. data/lib/wrapped/stretchbox.rb +70 -0
  60. data/lib/wrapped/submenu.rb +58 -0
  61. data/lib/wrapped/tabs.rb +223 -0
  62. data/lib/wrapped/text.rb +382 -0
  63. data/lib/wrapped/timer.rb +82 -0
  64. data/lib/wrapped/toggle.rb +150 -0
  65. data/lib/wrapped/tree.rb +612 -0
  66. data/lib/wrapped/val.rb +162 -0
  67. data/lib/wrapped/vbox.rb +93 -0
  68. data/lib/wrapped/widget.rb +282 -0
  69. data/lib/wrapped/zbox.rb +80 -0
  70. metadata +131 -0
@@ -0,0 +1,178 @@
1
+ module Iup
2
+
3
+ # Loads an image from file, returning an ImageWidget instance.
4
+ # * +filename+ - name of image file
5
+ # Raises +RuntimeError+ if no file of given filename exists.
6
+ def self.load_image filename
7
+ if File.exist?(filename)
8
+ handle = ImLib.IupLoadImage(filename)
9
+ puts handle # TODO - broken?
10
+ image = ImageWidget.new
11
+ image.handle = handle
12
+
13
+ return image
14
+ else
15
+ raise RuntimeError, "File does not exist", filename
16
+ end
17
+ end
18
+
19
+ # Parent class of images provides common attributes.
20
+ #
21
+ # See also: Image, ImageRGB, ImageRGBA, Iup.load_image.
22
+ class ImageWidget < Iup::Widget
23
+
24
+ ##
25
+ # :attr_writer: assign_handle
26
+ # The name for referring to image.
27
+ define_writer :assign_handle
28
+
29
+ ##
30
+ # :attr_reader: bpp
31
+ # Returns the number of bits per pixel.
32
+ define_reader :bpp
33
+
34
+ ##
35
+ # :attr_reader: channels
36
+ # Returns the number of channels.
37
+ define_reader :channels
38
+
39
+ ##
40
+ # :attr_reader: height
41
+ # Height of the image, in pixels.
42
+ define_reader :height
43
+
44
+ ##
45
+ # :attr: hotspot
46
+ # "x:y", coordinates of spot in image used for mouse click. Default is
47
+ # "0:0".
48
+ define_attribute :hotspot
49
+
50
+ ##
51
+ # :attr_reader: rastersize
52
+ # Size of the image, in pixels, value as "widthxheight".
53
+ define_reader :rastersize
54
+
55
+ ##
56
+ # :attr_reader: wid
57
+ # Native widget identifier.
58
+ define_reader :wid
59
+
60
+ ##
61
+ # :attr_reader: width
62
+ # Width of the image, in pixels.
63
+ define_reader :width
64
+
65
+ # Saves image to given filename.
66
+ # Optional format is one of: "BMP", "JPEG", "GIF", "TIFF", "PNG", "PNM", "PCX", "ICO", etc.
67
+ def save(filename, format = 'png')
68
+ err = IupIm.IupSaveImage @handle, filename, format
69
+ if err.zero?
70
+ raise Exception, 'Could not save image as file'
71
+ end
72
+ end
73
+ end
74
+
75
+ # \Image made from greyscale values.
76
+ # The colors are defined in a table, and their indices used when
77
+ # defining the image pixel-map.
78
+ #
79
+ # === Example
80
+ #
81
+ # The following image is built from 3 colors: the pixmap gives their
82
+ # placement in the 11x11 image, and the constructor uses a block to
83
+ # specify the color for each of the 3 values. When displayed, the
84
+ # image presents a red X on a yellow background.
85
+ #
86
+ # pixmap_x = [
87
+ # 1,2,3,3,3,3,3,3,3,2,1,
88
+ # 2,1,2,3,3,3,3,3,2,1,2,
89
+ # 3,2,1,2,3,3,3,2,1,2,3,
90
+ # 3,3,2,1,2,3,2,1,2,3,3,
91
+ # 3,3,3,2,1,2,1,2,3,3,3,
92
+ # 3,3,3,3,2,1,2,3,3,3,3,
93
+ # 3,3,3,2,1,2,1,2,3,3,3,
94
+ # 3,3,2,1,2,3,2,1,2,3,3,
95
+ # 3,2,1,2,3,3,3,2,1,2,3,
96
+ # 2,1,2,3,3,3,3,3,2,1,2,
97
+ # 1,2,3,3,3,3,3,3,3,2,1
98
+ # ]
99
+ #
100
+ # img = Iup::Image.new(11, 11, pixmap_x) do |i|
101
+ # i.color(1, '0 1 0')
102
+ # i.color(2, '255 0 0')
103
+ # i.color(3, '255 255 0')
104
+ # end
105
+ #
106
+ class Image < Iup::ImageWidget
107
+ # Constructor creates an image from raw pixels, using 1-value per pixel.
108
+ # If a block is given, the new instance is yielded to it.
109
+ # * +width+ - width of image in pixels
110
+ # * +height+ - height of image in pixels
111
+ # * +pixels+ - an array of pixel values, each value being a color index
112
+ def initialize(width, height, pixels)
113
+ @handle = IupLib.IupImage(width, height, IupLib.pointer_from_chars(pixels))
114
+
115
+ # run any provided block on instance, to set up further attributes
116
+ yield self if block_given?
117
+ end
118
+
119
+ # :call-seq:
120
+ # image.color(index) # retrieves
121
+ # image.color(index, value) # sets
122
+ #
123
+ # Access color at given index.
124
+ # * +index+ - integer of color found in pixel map
125
+ # * +value+ - 'r g b' representation of color
126
+ def color(index, value=nil)
127
+ IupLib.IupSetAttribute(@handle, index.to_s, value)
128
+ end
129
+ end
130
+
131
+ # \Image made from RGB values.
132
+ #
133
+ # === Example
134
+ #
135
+ # image_data_24 = [
136
+ # r1,g1,b1,r2,g2,b2, ... r20,g20,b20, # 3x20 triples of RGB values
137
+ # ... # 20 rows
138
+ # ]
139
+ # Iup::ImageRGB.new(20, 20, image_data_24)
140
+ #
141
+ class ImageRGB < Iup::ImageWidget
142
+ # Constructor creates an image from raw pixels.
143
+ # If a block is given, the new instance is yielded to it.
144
+ # * +width+ - width of image in pixels
145
+ # * +height+ - height of image in pixels
146
+ # * +pixels+ - an array of pixel values, using 3 values per pixel.
147
+ def initialize(width, height, pixels)
148
+ @handle = IupLib.IupImageRGB(width, height, IupLib.pointer_from_chars(pixels))
149
+
150
+ # run any provided block on instance, to set up further attributes
151
+ yield self if block_given?
152
+ end
153
+ end
154
+
155
+ # \Image made from RGBA values.
156
+ #
157
+ # === Example
158
+ #
159
+ # image_data = [
160
+ # r1,g1,b1,a1,r2,g2,b2,a2, ... r20,g20,b20,a20, # 4x20 sets of RGBA values
161
+ # ... # 20 rows
162
+ # ]
163
+ # Iup::ImageRGBA.new(20, 20, image_data)
164
+ #
165
+ class ImageRGBA < Iup::ImageWidget
166
+ # Constructor creates an image from raw pixels.
167
+ # If a block is given, the new instance is yielded to it.
168
+ # * +width+ - width of image in pixels
169
+ # * +height+ - height of image in pixels
170
+ # * +pixels+ - an array of pixel values, using 4 values per pixel.
171
+ def initialize(width, height, pixels)
172
+ @handle = IupLib.IupImageRGBA(width, height, IupLib.pointer_from_chars(pixels))
173
+
174
+ # run any provided block on instance, to set up further attributes
175
+ yield self if block_given?
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,46 @@
1
+ module Iup
2
+
3
+ # All IUP GUI code must be called via a block passed to this method, as
4
+ # in this minimal example.
5
+ #
6
+ # Iup.mainloop do
7
+ #
8
+ # label = Iup::Label.new("Hello World!")
9
+ #
10
+ # Iup::Dialog.new label do |d|
11
+ # d.title = ' ... from IUP'
12
+ # d.size = '150x50'
13
+ # end.show
14
+ # end
15
+ #
16
+ def self.mainloop
17
+ begin
18
+ IupLib.IupOpen(0, nil)
19
+ ImgLib.IupImageLibOpen()
20
+
21
+ yield
22
+ IupLib.IupMainLoop
23
+ ensure
24
+ IupLib.IupClose
25
+ end
26
+ end
27
+
28
+ # Accesses the global variable 'name'.
29
+ # Provide a value for 'val' to set the variable,
30
+ # or leave as nil to get the variable.
31
+ def self.global(name, val=nil)
32
+ if val.nil?
33
+ IupLib.IupGetGlobal(name).first
34
+ else
35
+ IupLib.IupSetGlobal(name, val)
36
+ end
37
+ end
38
+
39
+ # Sets the idle_action
40
+ def self.idle callback
41
+ unless callback.nil? or callback.arity.zero?
42
+ raise ArgumentError 'callback to idle must take no arguments'
43
+ end
44
+ IupLib.IupSetFunction('IDLE_ACTION', callback)
45
+ end
46
+ end
@@ -0,0 +1,110 @@
1
+ module Iup
2
+
3
+ # A static control used to display some text or an image, or act as a
4
+ # separator.
5
+ #
6
+ # === Example
7
+ #
8
+ # (1) label with text and setting font and colors:
9
+ #
10
+ # Iup::Label.new("Iup Label Text") do |l|
11
+ # l.bgcolor = '255 255 0'
12
+ # l.fgcolor = '0 0 255'
13
+ # l.font = 'Courier, Normal 14'
14
+ # l.alignment = 'ACENTER'
15
+ # end
16
+ #
17
+ # (2) label with image aligned to right
18
+ #
19
+ # Iup::Label.new do |l|
20
+ # l.image = img_star
21
+ # end
22
+ #
23
+ # (3) label as a horizontal separator
24
+ #
25
+ # Iup::Label.new do |l|
26
+ # l.separator = 'HORIZONTAL'
27
+ # end
28
+ #
29
+ class Label < Iup::Widget
30
+ include ImageAttributes
31
+ include DragDropAttributes
32
+
33
+ # Creates an instance of a label.
34
+ # If a block is given, the new instance is yielded to it.
35
+ # * +text+ - optional text to use for label.
36
+ def initialize text=nil
37
+ @handle = IupLib.IupLabel(text)
38
+
39
+ # run any provided block on instance, to set up further attributes
40
+ yield self if block_given?
41
+ end
42
+
43
+ # -- attributes
44
+
45
+ ##
46
+ # :attr: alignment
47
+ # Sets the horizontal and vertical alignment.
48
+ # The value is a string "horizontal:vertical", with
49
+ # horizontal options ALEFT, ACENTER, ARIGHT and
50
+ # vertical options ATOP, ACENTER, ABOTTOM.
51
+ # Partial values also accepted, e.g. "ARIGHT", ":ATOP".
52
+ define_attribute :alignment
53
+
54
+ ##
55
+ # :attr: ellipsis
56
+ # If set, adds "..." to the text if there is inadequate space,
57
+ # values 'yes' / 'no'.
58
+ define_attribute :ellipsis
59
+
60
+ ##
61
+ # :attr: expand
62
+ # Allows label to fill available space in indicated direction.
63
+ # Values 'no' / 'horizontal' / 'vertical' / 'yes'.
64
+ define_attribute :expand
65
+
66
+ ##
67
+ # :attr: padding
68
+ # Margin in x and y directions, value as "mxn".
69
+ define_attribute :padding
70
+
71
+ ##
72
+ # :attr_reader: position
73
+ # Returns position in pixels within client window as "x,y".
74
+ define_reader :position
75
+
76
+ ##
77
+ # :attr: rastersize
78
+ # Size of the label, in pixels, value as "widthxheight".
79
+ define_attribute :rastersize
80
+
81
+ ##
82
+ # :attr_reader: screenposition
83
+ # returns position in pixels on screen as "x,y".
84
+ define_reader :screenposition
85
+
86
+ ##
87
+ # :attr: separator
88
+ # 'horizontal' / 'vertical', makes line into a line separator.
89
+ define_attribute :separator
90
+
91
+ ##
92
+ # :attr: spacing
93
+ # Space between image and text, value as a number.
94
+ define_attribute :spacing
95
+
96
+ ##
97
+ # :attr: tip
98
+ # Tooltip string.
99
+ define_attribute :tip
100
+
101
+ ##
102
+ # :attr: title
103
+ # text to display (unless label has an image or is a separator).
104
+ define_attribute :title
105
+
106
+ # :section: Callbacks
107
+
108
+ include ButtonCallback
109
+ end
110
+ end
@@ -0,0 +1,54 @@
1
+ module Iup
2
+
3
+ # A static control, a kind of label which displays an underlined
4
+ # clickable text. When clicked, the text is opened in the browser
5
+ # as a url.
6
+ #
7
+ # === Example
8
+ #
9
+ # (1) Display clickable link:
10
+ #
11
+ # Iup::Link.new('https://www.ruby-lang.org')
12
+ #
13
+ # (2) Display text instead of link, and custom callback on click:
14
+ #
15
+ # Iup::Link.new('https://www.ruby-lang.org', 'Ruby Home') do |l|
16
+ # l.action = ->(url) {
17
+ # puts "you clicked on #{l.title} with URL: #{url}"
18
+ # Iup::IGNORE # return DEFAULT if you also want link to be opened
19
+ # }
20
+ # end
21
+ class Link < Iup::Label
22
+
23
+ # Creates a new link instance.
24
+ # If a block is given, the new instance is yielded to it.
25
+ # * +url+ - the URL to display / follow.
26
+ # * +text+ - optional text to display in place of URL
27
+ def initialize url, text=nil
28
+ @handle = IupLib.IupLink(url, text)
29
+
30
+ # run any provided block on instance, to set up further attributes
31
+ yield self if block_given?
32
+ end
33
+
34
+ # :section: Callbacks
35
+
36
+ ##
37
+ # :attr_writer: action
38
+ # Callback called when the link is clicked.
39
+ # The callback must respond to +call+ and takes a single argument: (url)
40
+ # * +url+ - of the link.
41
+ # Return Iup::DEFAULT to process link after action, or Iup::IGNORE.
42
+
43
+ # --
44
+ def action= callback
45
+ unless callback.arity == 1
46
+ raise ArgumentError, 'action callback must take 1 argument: the url'
47
+ end
48
+ cb = Proc.new do |ih, url|
49
+ callback.call url
50
+ end
51
+ define_callback cb, 'ACTION', :s_i
52
+ end
53
+ end
54
+ end