wxruby64 2.0.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. checksums.yaml +7 -0
  2. data/INSTALL +254 -0
  3. data/LICENSE +53 -0
  4. data/README +198 -0
  5. data/art/wxruby-128x128.png +0 -0
  6. data/art/wxruby-256x256.png +0 -0
  7. data/art/wxruby-64x64.png +0 -0
  8. data/art/wxruby.png +0 -0
  9. data/lib/wx.rb +53 -0
  10. data/lib/wx/accessors.rb +68 -0
  11. data/lib/wx/classes/acceleratortable.rb +28 -0
  12. data/lib/wx/classes/animation.rb +18 -0
  13. data/lib/wx/classes/app.rb +51 -0
  14. data/lib/wx/classes/artprovider.rb +31 -0
  15. data/lib/wx/classes/auinotebook.rb +9 -0
  16. data/lib/wx/classes/bitmap.rb +59 -0
  17. data/lib/wx/classes/busycursor.rb +12 -0
  18. data/lib/wx/classes/checklistbox.rb +46 -0
  19. data/lib/wx/classes/choice.rb +4 -0
  20. data/lib/wx/classes/clientdc.rb +13 -0
  21. data/lib/wx/classes/clipboard.rb +56 -0
  22. data/lib/wx/classes/colour.rb +49 -0
  23. data/lib/wx/classes/combobox.rb +4 -0
  24. data/lib/wx/classes/commandevent.rb +7 -0
  25. data/lib/wx/classes/controlwithitems.rb +10 -0
  26. data/lib/wx/classes/data_object.rb +14 -0
  27. data/lib/wx/classes/data_object_simple.rb +6 -0
  28. data/lib/wx/classes/dataformat.rb +23 -0
  29. data/lib/wx/classes/dc.rb +57 -0
  30. data/lib/wx/classes/event.rb +5 -0
  31. data/lib/wx/classes/evthandler.rb +1039 -0
  32. data/lib/wx/classes/font.rb +118 -0
  33. data/lib/wx/classes/functions.rb +44 -0
  34. data/lib/wx/classes/gauge.rb +12 -0
  35. data/lib/wx/classes/genericdirctrl.rb +36 -0
  36. data/lib/wx/classes/grid.rb +146 -0
  37. data/lib/wx/classes/hboxsizer.rb +6 -0
  38. data/lib/wx/classes/helpcontroller.rb +5 -0
  39. data/lib/wx/classes/helpcontrollerhelpprovider.rb +23 -0
  40. data/lib/wx/classes/helpprovider.rb +15 -0
  41. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  42. data/lib/wx/classes/htmlwindow.rb +14 -0
  43. data/lib/wx/classes/icon.rb +32 -0
  44. data/lib/wx/classes/iconbundle.rb +3 -0
  45. data/lib/wx/classes/image.rb +53 -0
  46. data/lib/wx/classes/imagelist.rb +3 -0
  47. data/lib/wx/classes/listbox.rb +4 -0
  48. data/lib/wx/classes/listctrl.rb +33 -0
  49. data/lib/wx/classes/locale.rb +28 -0
  50. data/lib/wx/classes/mediactrl.rb +48 -0
  51. data/lib/wx/classes/menu.rb +62 -0
  52. data/lib/wx/classes/menuitem.rb +7 -0
  53. data/lib/wx/classes/notebook.rb +9 -0
  54. data/lib/wx/classes/object.rb +14 -0
  55. data/lib/wx/classes/paintdc.rb +12 -0
  56. data/lib/wx/classes/point.rb +56 -0
  57. data/lib/wx/classes/previewframe.rb +13 -0
  58. data/lib/wx/classes/rect.rb +19 -0
  59. data/lib/wx/classes/richtextctrl.rb +63 -0
  60. data/lib/wx/classes/simplehelpprovider.rb +38 -0
  61. data/lib/wx/classes/size.rb +58 -0
  62. data/lib/wx/classes/sizer.rb +43 -0
  63. data/lib/wx/classes/sound.rb +23 -0
  64. data/lib/wx/classes/splitterwindow.rb +10 -0
  65. data/lib/wx/classes/standardpaths.rb +9 -0
  66. data/lib/wx/classes/styledtextctrl.rb +92 -0
  67. data/lib/wx/classes/textctrl.rb +14 -0
  68. data/lib/wx/classes/texturlevent.rb +18 -0
  69. data/lib/wx/classes/timer.rb +96 -0
  70. data/lib/wx/classes/toolbar.rb +36 -0
  71. data/lib/wx/classes/toolbartool.rb +4 -0
  72. data/lib/wx/classes/treectrl.rb +44 -0
  73. data/lib/wx/classes/validator.rb +7 -0
  74. data/lib/wx/classes/vboxsizer.rb +6 -0
  75. data/lib/wx/classes/window.rb +89 -0
  76. data/lib/wx/classes/xmlresource.rb +54 -0
  77. data/lib/wx/helpers.rb +54 -0
  78. data/lib/wx/keyword_ctors.rb +204 -0
  79. data/lib/wx/keyword_defs.rb +585 -0
  80. data/lib/wx/version.rb +3 -0
  81. data/lib/wxruby2.so +0 -0
  82. data/samples/SAMPLES-LICENSE.TXT +18 -0
  83. data/samples/aui/aui.rb +1356 -0
  84. data/samples/bigdemo/About.rbw +39 -0
  85. data/samples/bigdemo/ColorPanel.rbw +23 -0
  86. data/samples/bigdemo/GridSimple.rbw +78 -0
  87. data/samples/bigdemo/MDIDemo.rbw +57 -0
  88. data/samples/bigdemo/PopupMenu.rbw +149 -0
  89. data/samples/bigdemo/ShapedWindow.rbw +128 -0
  90. data/samples/bigdemo/Sizers.rbw +543 -0
  91. data/samples/bigdemo/bigdemo.rb +823 -0
  92. data/samples/bigdemo/demoTemplate.rbw +33 -0
  93. data/samples/bigdemo/helpfile.htb +0 -0
  94. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  95. data/samples/bigdemo/icons/Test 015.png +0 -0
  96. data/samples/bigdemo/icons/choice.bmp +0 -0
  97. data/samples/bigdemo/icons/choice.xpm +27 -0
  98. data/samples/bigdemo/icons/combo.bmp +0 -0
  99. data/samples/bigdemo/icons/combo.xpm +27 -0
  100. data/samples/bigdemo/icons/copy.xpm +25 -0
  101. data/samples/bigdemo/icons/cut.xpm +24 -0
  102. data/samples/bigdemo/icons/gauge.bmp +0 -0
  103. data/samples/bigdemo/icons/gauge.xpm +27 -0
  104. data/samples/bigdemo/icons/help.xpm +25 -0
  105. data/samples/bigdemo/icons/list.bmp +0 -0
  106. data/samples/bigdemo/icons/list.xpm +27 -0
  107. data/samples/bigdemo/icons/mondrian.ico +0 -0
  108. data/samples/bigdemo/icons/mondrian.xpm +44 -0
  109. data/samples/bigdemo/icons/new.xpm +24 -0
  110. data/samples/bigdemo/icons/ogl.ico +0 -0
  111. data/samples/bigdemo/icons/ogl.xpm +45 -0
  112. data/samples/bigdemo/icons/open.xpm +26 -0
  113. data/samples/bigdemo/icons/paste.bmp +0 -0
  114. data/samples/bigdemo/icons/paste.xpm +38 -0
  115. data/samples/bigdemo/icons/pointy.png +0 -0
  116. data/samples/bigdemo/icons/preview.xpm +26 -0
  117. data/samples/bigdemo/icons/print.xpm +26 -0
  118. data/samples/bigdemo/icons/radio.bmp +0 -0
  119. data/samples/bigdemo/icons/radio.xpm +27 -0
  120. data/samples/bigdemo/icons/robert.xpm +415 -0
  121. data/samples/bigdemo/icons/sashtest.ico +0 -0
  122. data/samples/bigdemo/icons/save.xpm +25 -0
  123. data/samples/bigdemo/icons/smiles.bmp +0 -0
  124. data/samples/bigdemo/icons/smiles.xpm +39 -0
  125. data/samples/bigdemo/icons/smiley.ico +0 -0
  126. data/samples/bigdemo/icons/smiley.xpm +42 -0
  127. data/samples/bigdemo/icons/stattext.xpm +24 -0
  128. data/samples/bigdemo/icons/test2.bmp +0 -0
  129. data/samples/bigdemo/icons/test2.png +0 -0
  130. data/samples/bigdemo/icons/test2.xpm +79 -0
  131. data/samples/bigdemo/icons/text.bmp +0 -0
  132. data/samples/bigdemo/icons/text.xpm +27 -0
  133. data/samples/bigdemo/icons/tog1.bmp +0 -0
  134. data/samples/bigdemo/icons/tog1.xpm +38 -0
  135. data/samples/bigdemo/icons/tog2.bmp +0 -0
  136. data/samples/bigdemo/icons/tog2.xpm +38 -0
  137. data/samples/bigdemo/icons/wxruby-128x128.png +0 -0
  138. data/samples/bigdemo/icons/wxwin.ico +0 -0
  139. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  140. data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
  141. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  142. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  143. data/samples/bigdemo/run.rb +90 -0
  144. data/samples/bigdemo/tips.txt +7 -0
  145. data/samples/bigdemo/utils.rb +12 -0
  146. data/samples/bigdemo/wxArtProvider.rbw +281 -0
  147. data/samples/bigdemo/wxBitmapButton.rbw +65 -0
  148. data/samples/bigdemo/wxButton.rbw +64 -0
  149. data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
  150. data/samples/bigdemo/wxCheckBox.rbw +50 -0
  151. data/samples/bigdemo/wxCheckListBox.rbw +65 -0
  152. data/samples/bigdemo/wxChoice.rbw +47 -0
  153. data/samples/bigdemo/wxChoicebook.rbw +78 -0
  154. data/samples/bigdemo/wxColourDialog.rbw +31 -0
  155. data/samples/bigdemo/wxComboBox.rbw +77 -0
  156. data/samples/bigdemo/wxCursor.rbw +136 -0
  157. data/samples/bigdemo/wxDialog.rbw +74 -0
  158. data/samples/bigdemo/wxDirDialog.rbw +29 -0
  159. data/samples/bigdemo/wxDragImage.rbw +70 -0
  160. data/samples/bigdemo/wxFileDialog.rbw +37 -0
  161. data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
  162. data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
  163. data/samples/bigdemo/wxFontDialog.rbw +173 -0
  164. data/samples/bigdemo/wxFrame.rbw +53 -0
  165. data/samples/bigdemo/wxGauge.rbw +71 -0
  166. data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
  167. data/samples/bigdemo/wxGrid.rbw +66 -0
  168. data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
  169. data/samples/bigdemo/wxListBox.rbw +140 -0
  170. data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -0
  171. data/samples/bigdemo/wxMDIWindows.rbw +50 -0
  172. data/samples/bigdemo/wxMenu.rbw +236 -0
  173. data/samples/bigdemo/wxMessageDialog.rbw +27 -0
  174. data/samples/bigdemo/wxMiniFrame.rbw +70 -0
  175. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
  176. data/samples/bigdemo/wxNotebook.rbw +136 -0
  177. data/samples/bigdemo/wxProgressDialog.rbw +43 -0
  178. data/samples/bigdemo/wxRadioBox.rbw +72 -0
  179. data/samples/bigdemo/wxRadioButton.rbw +125 -0
  180. data/samples/bigdemo/wxSashWindow.rbw +141 -0
  181. data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
  182. data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
  183. data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
  184. data/samples/bigdemo/wxSlider.rbw +42 -0
  185. data/samples/bigdemo/wxSpinButton.rbw +50 -0
  186. data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
  187. data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
  188. data/samples/bigdemo/wxStaticBitmap.rbw +47 -0
  189. data/samples/bigdemo/wxStaticText.rbw +55 -0
  190. data/samples/bigdemo/wxStatusBar.rbw +126 -0
  191. data/samples/bigdemo/wxTextCtrl.rbw +149 -0
  192. data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
  193. data/samples/bigdemo/wxToggleButton.rbw +49 -0
  194. data/samples/bigdemo/wxToolBar.rbw +131 -0
  195. data/samples/bigdemo/wxTreeCtrl.rbw +191 -0
  196. data/samples/calendar/calendar.rb +348 -0
  197. data/samples/caret/caret.rb +282 -0
  198. data/samples/caret/mondrian.xpm +44 -0
  199. data/samples/controls/controls.rb +1136 -0
  200. data/samples/controls/get_item_sample.rb +87 -0
  201. data/samples/controls/icons/choice.xpm +27 -0
  202. data/samples/controls/icons/combo.xpm +27 -0
  203. data/samples/controls/icons/gauge.xpm +27 -0
  204. data/samples/controls/icons/list.xpm +27 -0
  205. data/samples/controls/icons/radio.xpm +27 -0
  206. data/samples/controls/icons/stattext.xpm +24 -0
  207. data/samples/controls/icons/text.xpm +27 -0
  208. data/samples/controls/mondrian.ico +0 -0
  209. data/samples/controls/mondrian.xpm +44 -0
  210. data/samples/controls/test2.bmp +0 -0
  211. data/samples/dialogs/dialogs.rb +797 -0
  212. data/samples/dialogs/tips.txt +18 -0
  213. data/samples/dragdrop/dragdrop.rb +177 -0
  214. data/samples/drawing/bitmap.rb +49 -0
  215. data/samples/drawing/bitmap_image.rb +92 -0
  216. data/samples/drawing/graphics_drawing.rb +235 -0
  217. data/samples/drawing/maths_images.rb +265 -0
  218. data/samples/drawing/rmagic_bitmap_image.rb +110 -0
  219. data/samples/drawing/ruby-logo.jpg +0 -0
  220. data/samples/etc/activation.rb +102 -0
  221. data/samples/etc/choice.rb +67 -0
  222. data/samples/etc/miniframe.rb +79 -0
  223. data/samples/etc/sash.rb +130 -0
  224. data/samples/etc/scrollwin.rb +110 -0
  225. data/samples/etc/system_settings.rb +252 -0
  226. data/samples/etc/threaded.rb +72 -0
  227. data/samples/etc/toolbar_sizer_additem.rb +55 -0
  228. data/samples/etc/wizard.rb +74 -0
  229. data/samples/event/event.rb +182 -0
  230. data/samples/event/update_ui_event.rb +70 -0
  231. data/samples/grid/grid.rb +198 -0
  232. data/samples/grid/gridtablebase.rb +148 -0
  233. data/samples/html/html.rb +262 -0
  234. data/samples/listbook/listbook.rb +174 -0
  235. data/samples/listbook/listbook.xrc +370 -0
  236. data/samples/mdi/mdi.rb +85 -0
  237. data/samples/media/mediactrl.rb +167 -0
  238. data/samples/minimal/minimal.rb +77 -0
  239. data/samples/minimal/mondrian.ico +0 -0
  240. data/samples/minimal/mondrian.png +0 -0
  241. data/samples/minimal/nothing.rb +16 -0
  242. data/samples/opengl/cube.rb +130 -0
  243. data/samples/opengl/cube_anim_lighting.rb +191 -0
  244. data/samples/printing/mondrian.ico +0 -0
  245. data/samples/printing/mondrian.xpm +44 -0
  246. data/samples/printing/printing.rb +487 -0
  247. data/samples/sockets/SocketPackets.rb +27 -0
  248. data/samples/sockets/res/message-new.png +0 -0
  249. data/samples/sockets/res/user.png +0 -0
  250. data/samples/sockets/wxClient.rb +395 -0
  251. data/samples/sockets/wxServer.rb +422 -0
  252. data/samples/sockets/wxSocketGUI.rb +97 -0
  253. data/samples/text/document-open.png +0 -0
  254. data/samples/text/document-save.png +0 -0
  255. data/samples/text/edit-copy.png +0 -0
  256. data/samples/text/edit-cut.png +0 -0
  257. data/samples/text/edit-paste.png +0 -0
  258. data/samples/text/edit-redo.png +0 -0
  259. data/samples/text/edit-undo.png +0 -0
  260. data/samples/text/format-text-bold.png +0 -0
  261. data/samples/text/format-text-italic.png +0 -0
  262. data/samples/text/format-text-underline.png +0 -0
  263. data/samples/text/mondrian.ico +0 -0
  264. data/samples/text/mondrian.xpm +44 -0
  265. data/samples/text/preferences-desktop-font.png +0 -0
  266. data/samples/text/rich_textctrl.rb +290 -0
  267. data/samples/text/scintilla.rb +169 -0
  268. data/samples/text/textctrl.rb +111 -0
  269. data/samples/text/unicode.rb +242 -0
  270. data/samples/text/utf8.txt +15 -0
  271. data/samples/treectrl/icon1.xpm +79 -0
  272. data/samples/treectrl/icon2.xpm +53 -0
  273. data/samples/treectrl/icon3.xpm +79 -0
  274. data/samples/treectrl/icon4.xpm +43 -0
  275. data/samples/treectrl/icon5.xpm +79 -0
  276. data/samples/treectrl/treectrl.rb +1166 -0
  277. data/samples/xrc/samples.xrc +46 -0
  278. data/samples/xrc/xrc_sample.rb +76 -0
  279. metadata +330 -0
@@ -0,0 +1,265 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # wxRuby2 Sample Code. Copyright (c) 2004-2009 wxRuby development team
4
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
5
+
6
+ require 'wx'
7
+ include Wx
8
+ include Math
9
+
10
+ # This sample was originally written by Alex Fenton as an answer to Ruby
11
+ # Quiz #191, which challenged entrants to create an application which
12
+ # could draw images based on mathematical functions:
13
+ #
14
+ # http://rubyquiz.strd6.com/quizzes/191/
15
+ #
16
+ # To use the application, enter functions which take input values of x
17
+ # and y from 0 to 1, and return intensities of red, green and blue. If a
18
+ # bad function is entered, a cross is displayed; hover over this to get
19
+ # a hint on the problem.
20
+ #
21
+ # The sample demonstrates some uses of the Wx::Image class, a
22
+ # platform-independent representation of an image which can be
23
+ # manipulated (for example, resizing) and written to files in various
24
+ # formats. It also shows how an image's rgb data can be written directly, by
25
+ # using Array#pack.
26
+
27
+ # A canvas that draws and displays a mathematically generated image
28
+ class MathsDrawing < Window
29
+ # The functions which return the colour components at each pixel
30
+ attr_writer :red, :green, :blue
31
+ # The time taken to render, whether re-rendering is needed, and the
32
+ # source image
33
+ attr_reader :render_time, :done, :img
34
+
35
+ def initialize(parent)
36
+ super(parent)
37
+ # Create a dummy image
38
+ @default_image = Image.new(1, 1)
39
+ @default_image.rgb_data = [255, 255, 255].pack('CCC')
40
+ @img = @default_image
41
+
42
+ @red = lambda { | x, y | 1 }
43
+ @green = lambda { | x, y | 1 }
44
+ @blue = lambda { | x, y | 1 }
45
+
46
+ @done = true
47
+
48
+ evt_size :on_size
49
+ evt_paint :on_paint
50
+ evt_idle :on_idle
51
+ end
52
+
53
+ # Paint the image on the screen. The actual image rendering is done in
54
+ # idle time, so that the GUI is responsive whilst redrawing - eg, when
55
+ # resized. Painting is done by quickly rescaling the cached image.
56
+ def on_paint
57
+ paint do | dc |
58
+ draw_img = @img.scale(client_size.x, client_size.y)
59
+ dc.draw_bitmap(draw_img.convert_to_bitmap, 0, 0, true)
60
+ end
61
+ end
62
+
63
+ # Regenerate the image if needed, then do a refresh
64
+ def on_idle
65
+ if not @done
66
+ @img = make_image
67
+ refresh
68
+ end
69
+ @done = true
70
+ end
71
+
72
+ # Note to regenerate the image if the canvas has been resized
73
+ def on_size(event)
74
+ @done = false
75
+ event.skip
76
+ end
77
+
78
+ # Call this to force a re-render - eg if the functions have changed
79
+ def redraw
80
+ @done = false
81
+ end
82
+
83
+ # Actually make the image
84
+ def make_image
85
+ size_x, size_y = client_size.x, client_size.y
86
+ if size_x < 1 or size_y < 1
87
+ return @default_image
88
+ end
89
+
90
+ start_time = Time.now
91
+ # The string holding raw rgb data
92
+ data = ''
93
+ x_factor = size_x.to_f
94
+ y_factor = size_y.to_f
95
+
96
+ # Input values from the range 0 to 1, with origin in the bottom left
97
+ (size_y - 1).downto(0) do | y |
98
+ the_y = y.to_f / y_factor
99
+ 0.upto(size_x - 1) do | x |
100
+ the_x = x.to_f / x_factor
101
+ red = @red.call(the_x, the_y) * 255
102
+ green = @green.call(the_x, the_y) * 255
103
+ blue = @blue.call(the_x, the_y) * 255
104
+ data << [red, green, blue].pack("CCC")
105
+ end
106
+ end
107
+ img = Image.new(size_x, size_y)
108
+ img.rgb_data = data
109
+ @render_time = Time.now - start_time
110
+ img
111
+ end
112
+ end
113
+
114
+ # A helper dialog for saving the image to a file
115
+ class SaveImageDialog < FileDialog
116
+ # The image file formats on offer
117
+ TYPES = [ [ "PNG file (*.png)|*.png", BITMAP_TYPE_PNG ],
118
+ [ "TIF file (*.tif)|*.tif", BITMAP_TYPE_TIF ],
119
+ [ "BMP file (*.bmp)|*.bmp", BITMAP_TYPE_BMP ] ]
120
+
121
+ WILDCARD = TYPES.map { | type | type.first }.join("|")
122
+
123
+ def initialize(parent)
124
+ super(parent, :wildcard => WILDCARD,
125
+ :message => 'Save Image',
126
+ :style => FD_SAVE|FD_OVERWRITE_PROMPT)
127
+ end
128
+
129
+ # Returns the Wx identifier for the selected image type.
130
+ def image_type
131
+ TYPES[filter_index].last
132
+ end
133
+ end
134
+
135
+ # A Panel for displaying the image and controls to manipulate it
136
+ class MathsPanel < Panel
137
+ # Set functions to some nice initial values
138
+ RED_INITIAL = "cos(x)"
139
+ GREEN_INITIAL = "cos(y ** x)"
140
+ BLUE_INITIAL = "(x ** 4) + ( y ** 3 ) - (4.5 * x ** 2 ) + ( y * 2)"
141
+
142
+ # Symbols to show correct and incorrect functions
143
+ TICK = "\xE2\x9C\x94"
144
+ CROSS = "\xE2\x9C\x98"
145
+
146
+ attr_reader :drawing
147
+
148
+ def initialize(parent)
149
+ super(parent)
150
+ self.sizer = VBoxSizer.new
151
+ # The canvas
152
+ @drawing = MathsDrawing.new(self)
153
+ sizer.add @drawing, 1, GROW
154
+
155
+ sizer.add Wx::StaticLine.new(self)
156
+
157
+ # The text controls for entering functions
158
+ grid_sz = FlexGridSizer.new(3, 8, 8)
159
+ grid_sz.add_growable_col(1, 1)
160
+
161
+ grid_sz.add StaticText.new(self, :label => "Red")
162
+ @red_tx = TextCtrl.new(self, :value => RED_INITIAL)
163
+ grid_sz.add @red_tx, 0, GROW
164
+ @red_err = StaticText.new(self, :label => TICK)
165
+ grid_sz.add @red_err, 0, ALIGN_CENTRE
166
+
167
+ grid_sz.add StaticText.new(self, :label => "Green")
168
+ @green_tx = TextCtrl.new(self, :value => GREEN_INITIAL)
169
+ grid_sz.add @green_tx, 0, GROW
170
+ @green_err = StaticText.new(self, :label => TICK)
171
+ grid_sz.add @green_err, 0, ALIGN_CENTRE
172
+
173
+ grid_sz.add StaticText.new(self, :label => "Blue")
174
+ @blue_tx = TextCtrl.new(self, :value => BLUE_INITIAL)
175
+ grid_sz.add @blue_tx, 0, GROW
176
+ @blue_err = StaticText.new(self, :label => TICK)
177
+ grid_sz.add @blue_err, 0, ALIGN_CENTRE
178
+
179
+ # Buttons to save and render
180
+ grid_sz.add nil
181
+ butt_sz = HBoxSizer.new
182
+ render_bt = Button.new(self, :label => "Render")
183
+ butt_sz.add render_bt, 0, Wx::RIGHT, 8
184
+ evt_button render_bt, :on_render
185
+
186
+ save_bt = Button.new(self, :label => "Save Image")
187
+ butt_sz.add save_bt, 0, Wx::RIGHT, 8
188
+ evt_button save_bt, :on_save
189
+
190
+ # Disable the buttons whilst redrawing
191
+ evt_update_ui(render_bt) { | evt | evt.enable(@drawing.done) }
192
+ evt_update_ui(save_bt) { | evt | evt.enable(@drawing.done) }
193
+ grid_sz.add butt_sz
194
+
195
+ # Add the controls sizer to the whole thing
196
+ sizer.add grid_sz, 0, GROW|ALL, 10
197
+
198
+ on_render
199
+ end
200
+
201
+ # Update the functions that generate the image, then re-render it
202
+ def on_render
203
+ @drawing.red = make_a_function(@red_tx.value, @red_err)
204
+ @drawing.green = make_a_function(@green_tx.value, @green_err)
205
+ @drawing.blue = make_a_function(@blue_tx.value, @blue_err)
206
+ @drawing.redraw
207
+ end
208
+
209
+ # Display a dialog to save the image to a file
210
+ def on_save
211
+ dlg = SaveImageDialog.new(parent)
212
+ if dlg.show_modal == ID_OK
213
+ @drawing.img.save_file(dlg.path, dlg.image_type)
214
+ end
215
+ end
216
+
217
+ # A function which doesn't do anything
218
+ NULL_FUNC = lambda { | x, y | 1 }
219
+
220
+ # Takes a string source +source+, returns a lambda. If the string
221
+ # source isn't valid, flag this in the GUI static text +error_outlet+
222
+ def make_a_function(source, error_outlet)
223
+ return NULL_FUNC if source.empty?
224
+ func = nil
225
+ begin
226
+ # Create the function and test it, to check for wrong names
227
+ func = eval "lambda { | x, y | #{source} }"
228
+ func.call(0, 0)
229
+ rescue Exception => e
230
+ error_outlet.label = CROSS
231
+ error_outlet.tool_tip = e.class.name + ":\n" +
232
+ e.message.sub(/^\(eval\):\d+: /, '')
233
+ return NULL_FUNC
234
+ end
235
+
236
+ # Things are good, note this and return the function
237
+ error_outlet.label = TICK
238
+ error_outlet.tool_tip = ''
239
+ func
240
+ end
241
+ end
242
+
243
+ class MathsFrame < Frame
244
+ def initialize
245
+ super(nil, :title => 'Maths drawing',
246
+ :size => [400, 500],
247
+ :pos => [50, 50])
248
+ sb = create_status_bar(1)
249
+ evt_update_ui sb, :on_update_status
250
+ @panel = MathsPanel.new(self)
251
+ end
252
+
253
+ def on_update_status
254
+ if @panel.drawing.done
255
+ pixels = @panel.drawing.client_size
256
+ msg = "[#{pixels.x} x #{pixels.y}] drawing completed in " +
257
+ "#{@panel.drawing.render_time}s"
258
+ status_bar.status_text = msg
259
+ end
260
+ end
261
+ end
262
+
263
+ App.run do
264
+ MathsFrame.new.show
265
+ end
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+ require 'RMagick'
10
+
11
+ # RMagick sample (written by Chauk-Mean Proum)
12
+
13
+ # This sample demonstrates how to convert directly a RMagick image to
14
+ # a wxRuby image (without saving and loading the image file).
15
+ # See the magick_to_wx method.
16
+
17
+ class ImageFrame < Wx::Frame
18
+ def initialize
19
+ super(nil, :title => 'RMagick sample', :size => [600, 600])
20
+
21
+ # Create the magick image from an image file
22
+ img_file = File.join( File.dirname(__FILE__)+"/../../art",
23
+ 'wxruby-256x256.png')
24
+ @magick_image = Magick::ImageList.new(img_file)
25
+
26
+ # Create some magick images with special effects
27
+ @magick_image1 = @magick_image.sketch
28
+ @magick_image2 = @magick_image.oil_paint(4)
29
+ @magick_image3 = @magick_image.shade
30
+
31
+ # Convert the magick images to wxRuby images
32
+ @image1 = magick_to_wx(@magick_image1)
33
+ @image2 = magick_to_wx(@magick_image2)
34
+ @image3 = magick_to_wx(@magick_image3)
35
+
36
+ # Create the corresponding bitmaps
37
+ compute_bitmaps
38
+
39
+ # Set up event handling
40
+ evt_size :on_size
41
+ evt_idle :on_idle
42
+ evt_paint :on_paint
43
+ end
44
+
45
+
46
+ # Convert the RMagick image to a WxRuby image
47
+ def magick_to_wx magick_img
48
+ wx_img = Wx::Image.new(magick_img.columns, magick_img.rows)
49
+
50
+ # Set the image data
51
+ wx_img.rgb_data = magick_img.to_blob { self.format = "RGB" }
52
+
53
+ # Set the alpha (transparency) if any
54
+ if magick_img.alpha?
55
+ wx_img.alpha_data = magick_img.to_blob { self.format = "A" }
56
+ end
57
+
58
+ wx_img
59
+ end
60
+
61
+ # Create a bitmap for the specified image and size
62
+ def compute_bitmap image, width, height
63
+ rescaled_image = Wx::Image.new(image).rescale(width, height)
64
+ rescaled_image.to_bitmap
65
+ end
66
+
67
+ # Create the bitmaps corresponding to the images and with half the size of the frame
68
+ def compute_bitmaps
69
+ width = client_size.x / 2
70
+ height = client_size.y / 2
71
+ @bitmap1 = compute_bitmap(@image1, width, height)
72
+ @bitmap2 = compute_bitmap(@image2, width, height)
73
+ @bitmap3 = compute_bitmap(@image3, width, height)
74
+ @done = true
75
+ end
76
+
77
+ # Note to recompute the bitmaps on a resize
78
+ def on_size(event)
79
+ @done = false
80
+ event.skip
81
+ end
82
+
83
+ # Recompute the bitmaps if needed, then do a refresh
84
+ def on_idle
85
+ if not @done
86
+ compute_bitmaps
87
+ refresh
88
+ end
89
+ end
90
+
91
+ # Paint the frame with the bitmaps
92
+ def on_paint
93
+ paint do | dc |
94
+
95
+ if @done
96
+ offset_x = client_size.x / 4
97
+ offset_y = client_size.y / 4
98
+ dc.draw_bitmap(@bitmap1, 0, 0, true)
99
+ dc.draw_bitmap(@bitmap2, offset_x, offset_y, true)
100
+ dc.draw_bitmap(@bitmap3, offset_x*2, offset_y*2, true)
101
+ end
102
+
103
+ end
104
+ end
105
+ end
106
+
107
+ Wx::App.run do
108
+ ImageFrame.new.show
109
+ end
110
+
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+ begin
5
+ require 'rubygems'
6
+ rescue LoadError
7
+ end
8
+ require 'wx'
9
+
10
+ # This sample demonstrates the use of Activate Events. These are
11
+ # generated when a frame becomes active or inactive. This is typically
12
+ # indicated by a frame's titlebar changing colour, and a widget within
13
+ # the frame gainin focus. An event is also generated when a whole wxRuby
14
+ # app starts or stops being the current focussed desktop application.
15
+
16
+ class MinimalFrame < Wx::Frame
17
+ def initialize(title, pos, size, style = Wx::DEFAULT_FRAME_STYLE)
18
+ super(nil, -1, title, pos, size, style)
19
+
20
+
21
+ menuFile = Wx::Menu.new()
22
+ helpMenu = Wx::Menu.new()
23
+ helpMenu.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
24
+ menuFile.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
25
+ menuBar = Wx::MenuBar.new()
26
+ menuBar.append(menuFile, "&File")
27
+ menuBar.append(helpMenu, "&Help")
28
+ set_menu_bar(menuBar)
29
+
30
+ create_status_bar(2)
31
+ set_status_text("Welcome to wxRuby!")
32
+
33
+ evt_menu(Wx::ID_EXIT) { on_quit }
34
+ evt_menu(Wx::ID_ABOUT) { on_about }
35
+
36
+ evt_activate { | e | on_activate(e) }
37
+ evt_iconize { | e | on_iconize(e) }
38
+ end
39
+
40
+
41
+ def on_iconize(event)
42
+ if event.iconized
43
+ puts "Frame '#{get_title}' was iconized"
44
+ else
45
+ puts "Frame '#{get_title}' was restored"
46
+ end
47
+ end
48
+
49
+ def on_activate(event)
50
+ if event.get_active
51
+ puts "Frame '#{get_title}' became activated"
52
+ set_status_text 'Active'
53
+ else
54
+ puts "Frame '#{get_title}' became deactivated"
55
+ set_status_text 'Inactive'
56
+ end
57
+ event.skip # important
58
+ end
59
+
60
+ def on_quit
61
+ Wx::get_app.close_all
62
+ end
63
+
64
+ def on_about
65
+ msg = sprintf("This is the About dialog of the activate sample.\n" \
66
+ "Welcome to wxRuby, version %s", Wx::WXRUBY_VERSION)
67
+ Wx::message_box(msg, "About Activate", Wx::OK|Wx::ICON_INFORMATION, self)
68
+ end
69
+ end
70
+
71
+ class RbApp < Wx::App
72
+ def on_init
73
+ @frame_1 = MinimalFrame.new("Tall window",
74
+ Wx::Point.new(50, 50),
75
+ Wx::Size.new(150, 240))
76
+ @frame_2 = MinimalFrame.new("Wide window",
77
+ Wx::Point.new(100, 100),
78
+ Wx::Size.new(300, 180))
79
+ evt_activate_app { | e | on_activate_app(e) }
80
+ @frame_1.show()
81
+ @frame_2.show()
82
+
83
+ end
84
+
85
+ def on_activate_app(event)
86
+ if event.get_active
87
+ puts "The app became active"
88
+ else
89
+ puts "The app became inactive"
90
+ end
91
+ event.skip # important
92
+ end
93
+
94
+ def close_all
95
+ @frame_1.close(true)
96
+ @frame_2.close(true)
97
+ end
98
+ end
99
+
100
+ app = RbApp.new
101
+ app.main_loop()
102
+