purple_shoes 0.0.101

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/README.md +56 -0
  2. data/VERSION +1 -0
  3. data/bin/pshoes +23 -0
  4. data/bin/pshoes.bat +2 -0
  5. data/lib/plugins/video.rb +88 -0
  6. data/lib/purple_shoes.rb +51 -0
  7. data/lib/shoes/anim.rb +47 -0
  8. data/lib/shoes/app.rb +688 -0
  9. data/lib/shoes/basic.rb +254 -0
  10. data/lib/shoes/colors.rb +149 -0
  11. data/lib/shoes/download.rb +26 -0
  12. data/lib/shoes/help.rb +473 -0
  13. data/lib/shoes/helper_methods.rb +295 -0
  14. data/lib/shoes/main.rb +96 -0
  15. data/lib/shoes/manual.rb +6 -0
  16. data/lib/shoes/ruby.rb +61 -0
  17. data/lib/shoes/slot.rb +104 -0
  18. data/lib/shoes/style.rb +41 -0
  19. data/lib/shoes/text.rb +46 -0
  20. data/lib/shoes/url.rb +14 -0
  21. data/lib/shoes/widget.rb +23 -0
  22. data/samples/class-book.yaml +387 -0
  23. data/samples/cy.png +0 -0
  24. data/samples/loogink.png +0 -0
  25. data/samples/potato_chopping/1258_s001.gif +0 -0
  26. data/samples/potato_chopping/1258_s002.gif +0 -0
  27. data/samples/potato_chopping/1258_s003.gif +0 -0
  28. data/samples/potato_chopping/1258_s004.gif +0 -0
  29. data/samples/potato_chopping/1258_s005.gif +0 -0
  30. data/samples/potato_chopping/1258_s006.gif +0 -0
  31. data/samples/potato_chopping/1258_s007.gif +0 -0
  32. data/samples/potato_chopping/1258_s008.gif +0 -0
  33. data/samples/potato_chopping/1258_s009.gif +0 -0
  34. data/samples/potato_chopping/1258_s010.gif +0 -0
  35. data/samples/potato_chopping/1258_s011.gif +0 -0
  36. data/samples/potato_chopping/1258_s012.gif +0 -0
  37. data/samples/potato_chopping/1258_s013.gif +0 -0
  38. data/samples/potato_chopping/1258_s014.gif +0 -0
  39. data/samples/potato_chopping/1258_s015.gif +0 -0
  40. data/samples/potato_chopping/1258_s016.gif +0 -0
  41. data/samples/potato_chopping/1258_s017.gif +0 -0
  42. data/samples/potato_chopping/1258_s018.gif +0 -0
  43. data/samples/potato_chopping/1258_s019.gif +0 -0
  44. data/samples/potato_chopping/1258_s020.gif +0 -0
  45. data/samples/potato_chopping/1258_s021.gif +0 -0
  46. data/samples/potato_chopping/1258_s022.gif +0 -0
  47. data/samples/potato_chopping/1258_s023.gif +0 -0
  48. data/samples/potato_chopping/1258_s024.gif +0 -0
  49. data/samples/potato_chopping/1258_s025.gif +0 -0
  50. data/samples/potato_chopping/1258_s026.gif +0 -0
  51. data/samples/potato_chopping/1258_s027.gif +0 -0
  52. data/samples/potato_chopping/1258_s028.gif +0 -0
  53. data/samples/potato_chopping/1258_s029.gif +0 -0
  54. data/samples/potato_chopping/1258_s030.gif +0 -0
  55. data/samples/potato_chopping/1258_s031.gif +0 -0
  56. data/samples/potato_chopping/1258_s032.gif +0 -0
  57. data/samples/potato_chopping/1258_s033.gif +0 -0
  58. data/samples/potato_chopping/1258_s034.gif +0 -0
  59. data/samples/potato_chopping/1258_s035.gif +0 -0
  60. data/samples/potato_chopping/1258_s036.gif +0 -0
  61. data/samples/potato_chopping/1258_s037.gif +0 -0
  62. data/samples/potato_chopping/1258_s038.gif +0 -0
  63. data/samples/potato_chopping/1258_s039.gif +0 -0
  64. data/samples/potato_chopping/1258_s040.gif +0 -0
  65. data/samples/potato_chopping/1258_s041.gif +0 -0
  66. data/samples/potato_chopping/1258_s042.gif +0 -0
  67. data/samples/potato_chopping/1258_s043.gif +0 -0
  68. data/samples/potato_chopping/1258_s044.gif +0 -0
  69. data/samples/potato_chopping/1258_s045.gif +0 -0
  70. data/samples/potato_chopping/1258_s046.gif +0 -0
  71. data/samples/potato_chopping/1258_s047.gif +0 -0
  72. data/samples/potato_chopping/1258_s048.gif +0 -0
  73. data/samples/potato_chopping/1258_s049.gif +0 -0
  74. data/samples/potato_chopping/1258_s050.gif +0 -0
  75. data/samples/potato_chopping/1258_s051.gif +0 -0
  76. data/samples/potato_chopping/1258_s052.gif +0 -0
  77. data/samples/potato_chopping/1258_s053.gif +0 -0
  78. data/samples/potato_chopping/1258_s054.gif +0 -0
  79. data/samples/potato_chopping/1258_s055.gif +0 -0
  80. data/samples/potato_chopping/1258_s056.gif +0 -0
  81. data/samples/potato_chopping/1258_s057.gif +0 -0
  82. data/samples/potato_chopping/1258_s058.gif +0 -0
  83. data/samples/potato_chopping/1258_s059.gif +0 -0
  84. data/samples/sample1.rb +30 -0
  85. data/samples/sample10.rb +11 -0
  86. data/samples/sample11.rb +12 -0
  87. data/samples/sample12.rb +22 -0
  88. data/samples/sample13.rb +15 -0
  89. data/samples/sample14.rb +75 -0
  90. data/samples/sample15.rb +20 -0
  91. data/samples/sample16.rb +12 -0
  92. data/samples/sample17.rb +12 -0
  93. data/samples/sample18.rb +24 -0
  94. data/samples/sample19.rb +39 -0
  95. data/samples/sample2.rb +16 -0
  96. data/samples/sample20.rb +26 -0
  97. data/samples/sample21.rb +7 -0
  98. data/samples/sample22.rb +13 -0
  99. data/samples/sample23.rb +10 -0
  100. data/samples/sample24.rb +22 -0
  101. data/samples/sample25.rb +22 -0
  102. data/samples/sample27.rb +19 -0
  103. data/samples/sample28.rb +64 -0
  104. data/samples/sample29.rb +12 -0
  105. data/samples/sample3.rb +10 -0
  106. data/samples/sample30.rb +30 -0
  107. data/samples/sample31.rb +24 -0
  108. data/samples/sample34.rb +29 -0
  109. data/samples/sample35.rb +33 -0
  110. data/samples/sample36.rb +48 -0
  111. data/samples/sample37.rb +10 -0
  112. data/samples/sample38.rb +14 -0
  113. data/samples/sample4.rb +9 -0
  114. data/samples/sample40.rb +19 -0
  115. data/samples/sample42.rb +15 -0
  116. data/samples/sample43.rb +26 -0
  117. data/samples/sample44.rb +57 -0
  118. data/samples/sample45.rb +12 -0
  119. data/samples/sample46.rb +35 -0
  120. data/samples/sample47.rb +20 -0
  121. data/samples/sample48.rb +33 -0
  122. data/samples/sample49.rb +33 -0
  123. data/samples/sample5.rb +8 -0
  124. data/samples/sample50.rb +326 -0
  125. data/samples/sample58.rb +19 -0
  126. data/samples/sample6.rb +11 -0
  127. data/samples/sample7.rb +5 -0
  128. data/samples/sample8.rb +9 -0
  129. data/samples/sample9.rb +12 -0
  130. data/samples/sample99.rb +4 -0
  131. data/samples/sounds/102719__sarge4267__explosion.mp3 +0 -0
  132. data/samples/sounds/145622__andybrannan__train-fog-horn-long-wyomming.aiff +0 -0
  133. data/samples/sounds/46492__phreaksaccount__shields1.ogg +0 -0
  134. data/samples/sounds/61847__simon-rue__boink-v3.wav +0 -0
  135. data/snapshots/sample1.png +0 -0
  136. data/snapshots/sample10.png +0 -0
  137. data/snapshots/sample11.png +0 -0
  138. data/snapshots/sample12.png +0 -0
  139. data/snapshots/sample13.png +0 -0
  140. data/snapshots/sample14.png +0 -0
  141. data/snapshots/sample15.png +0 -0
  142. data/snapshots/sample16.png +0 -0
  143. data/snapshots/sample17.png +0 -0
  144. data/snapshots/sample18.png +0 -0
  145. data/snapshots/sample19.png +0 -0
  146. data/snapshots/sample2.png +0 -0
  147. data/snapshots/sample20.png +0 -0
  148. data/snapshots/sample21.png +0 -0
  149. data/snapshots/sample22.png +0 -0
  150. data/snapshots/sample23.png +0 -0
  151. data/snapshots/sample24.png +0 -0
  152. data/snapshots/sample25.png +0 -0
  153. data/snapshots/sample27.png +0 -0
  154. data/snapshots/sample28.png +0 -0
  155. data/snapshots/sample29.png +0 -0
  156. data/snapshots/sample3-osx.png +0 -0
  157. data/snapshots/sample3.png +0 -0
  158. data/snapshots/sample30.png +0 -0
  159. data/snapshots/sample31.png +0 -0
  160. data/snapshots/sample33.png +0 -0
  161. data/snapshots/sample34.png +0 -0
  162. data/snapshots/sample35.png +0 -0
  163. data/snapshots/sample36.png +0 -0
  164. data/snapshots/sample37.png +0 -0
  165. data/snapshots/sample38.png +0 -0
  166. data/snapshots/sample4.png +0 -0
  167. data/snapshots/sample40.png +0 -0
  168. data/snapshots/sample42.png +0 -0
  169. data/snapshots/sample43.png +0 -0
  170. data/snapshots/sample44-linux.png +0 -0
  171. data/snapshots/sample44.png +0 -0
  172. data/snapshots/sample45.png +0 -0
  173. data/snapshots/sample46.png +0 -0
  174. data/snapshots/sample47.png +0 -0
  175. data/snapshots/sample48.png +0 -0
  176. data/snapshots/sample49.png +0 -0
  177. data/snapshots/sample5.png +0 -0
  178. data/snapshots/sample50.png +0 -0
  179. data/snapshots/sample58.png +0 -0
  180. data/snapshots/sample6.png +0 -0
  181. data/snapshots/sample7.png +0 -0
  182. data/snapshots/sample8.png +0 -0
  183. data/snapshots/sample9.png +0 -0
  184. data/snapshots/sample99.png +0 -0
  185. data/static/code_highlighter.js +188 -0
  186. data/static/code_highlighter_ruby.js +26 -0
  187. data/static/man-editor-notepad.png +0 -0
  188. data/static/man-editor-osx.png +0 -0
  189. data/static/man-ele-background.png +0 -0
  190. data/static/man-ele-border.png +0 -0
  191. data/static/man-ele-button.png +0 -0
  192. data/static/man-ele-check.png +0 -0
  193. data/static/man-ele-editbox.png +0 -0
  194. data/static/man-ele-editline.png +0 -0
  195. data/static/man-ele-image.png +0 -0
  196. data/static/man-ele-listbox.png +0 -0
  197. data/static/man-ele-progress.png +0 -0
  198. data/static/man-ele-radio.png +0 -0
  199. data/static/man-ele-shape.png +0 -0
  200. data/static/man-ele-textblock.png +0 -0
  201. data/static/man-ele-video.png +0 -0
  202. data/static/man-shot1.png +0 -0
  203. data/static/manual-en.txt +3969 -0
  204. data/static/manual-ja.txt +3882 -0
  205. data/static/manual.css +184 -0
  206. data/static/purple_shoes-icon.png +0 -0
  207. data/static/rshoes-icon.png +0 -0
  208. data/static/shoes-manual-apps.png +0 -0
  209. data/static/sound_jars/jl1.0.1.jar +0 -0
  210. data/static/sound_jars/jogg-0.0.7.jar +0 -0
  211. data/static/sound_jars/jorbis-0.0.15.jar +0 -0
  212. data/static/sound_jars/mp3spi1.9.5.jar +0 -0
  213. data/static/sound_jars/tritonus_share.jar +0 -0
  214. data/static/sound_jars/vorbisspi1.0.3.jar +0 -0
  215. metadata +271 -0
@@ -0,0 +1,295 @@
1
+ class Shoes
2
+ module Mod
3
+ def set_margin
4
+ @margin ||= [0, 0, 0, 0]
5
+ @margin = [@margin, @margin, @margin, @margin] if @margin.is_a? Integer
6
+ margin_left, margin_top, margin_right, margin_bottom = @margin
7
+ @margin_left ||= margin_left
8
+ @margin_top ||= margin_top
9
+ @margin_right ||= margin_right
10
+ @margin_bottom ||= margin_bottom
11
+ end
12
+
13
+ def click &blk
14
+ @app.clickable self, :click, &blk
15
+ end
16
+
17
+ def release &blk
18
+ @app.clickable self, :release, &blk
19
+ end
20
+
21
+ attr_reader :margin_left, :margin_top, :margin_right, :margin_bottom
22
+ end
23
+
24
+ module Mod2
25
+ def init_app_vars
26
+ @contents, @mmcs, @mscs, @order = [], [], [], []
27
+ @location = '/'
28
+ @mouse_button, @mouse_pos = 0, [0, 0]
29
+ @fill, @stroke = black, black
30
+ end
31
+ end
32
+
33
+ class App
34
+ def basic_attributes args={}
35
+ default = BASIC_ATTRIBUTES_DEFAULT
36
+ default.merge!({nocontrol: true}) if @nolayout
37
+ replace_string_to_float args
38
+ default.merge args
39
+ end
40
+
41
+ def slot_attributes args={}
42
+ default = SLOT_ATTRIBUTES_DEFAULT
43
+ replace_string_to_float args
44
+ default.merge args
45
+ end
46
+
47
+ def replace_string_to_float args={}
48
+ [:width, :height, :left, :top].each do |k|
49
+ if args[k].is_a? String
50
+ args[k] = args[k].include?('%') ? args[k].to_f / 100 : args[k].to_i
51
+ end
52
+ end
53
+ end
54
+
55
+ def clickable s, flag = :click, &blk
56
+ if blk
57
+ ln = Swt::Listener.new
58
+ s.ln = ln
59
+ @mscs << s
60
+ class << ln; self end.
61
+ instance_eval do
62
+ define_method :handleEvent do |e|
63
+ if s.is_a?(Link) and !s.parent.hided
64
+ mouse_x, mouse_y = e.x, e.y
65
+ blk[s] if ((s.pl..(s.pl+s.pw)).include?(mouse_x) and (s.sy..s.ey).include?(mouse_y) and !((s.pl..s.sx).include?(mouse_x) and (s.sy..(s.sy+s.lh)).include?(mouse_y)) and !((s.ex..(s.pl+s.pw)).include?(mouse_x) and ((s.ey-s.lh)..s.ey).include?(mouse_y)))
66
+ elsif !s.is_a?(Link) and !s.hided
67
+ dx, dy = s.is_a?(Star) ? [s.width / 2.0, s.height / 2.0] : [0, 0]
68
+ blk[s] if s.left - dx <= e.x and e.x <= s.left - dx + s.width and s.top - dy <= e.y and e.y <= s.top - dy + s.height
69
+ end
70
+ end
71
+ end
72
+ @cs.addListener Swt::SWT::MouseDown, ln if flag == :click
73
+ @cs.addListener Swt::SWT::MouseUp, ln if flag == :release
74
+ end
75
+ end
76
+
77
+ def get_styles msg, styles=[], spoint=0
78
+ msg.each do |e|
79
+ if e.is_a? Text
80
+ epoint = spoint + e.to_s.length - 1
81
+ styles << [e, spoint..epoint]
82
+ get_styles e.str, styles, spoint
83
+ end
84
+ spoint += e.to_s.length
85
+ end
86
+ styles
87
+ end
88
+
89
+ def set_styles s, args
90
+ tl = s.real
91
+ tl.setJustify args[:justify]
92
+ tl.setSpacing(args[:leading] || 4)
93
+ tl.setAlignment case args[:align]
94
+ when 'center'; Swt::SWT::CENTER
95
+ when 'right'; Swt::SWT::RIGHT
96
+ else Swt::SWT::LEFT
97
+ end
98
+ font = Swt::Font.new Shoes.display, args[:font], args[:size], Swt::SWT::NORMAL
99
+ fgc = Swt::Color.new Shoes.display, *args[:stroke]
100
+ bgc = args[:fill] ? Swt::Color.new(Shoes.display, *args[:fill]) : nil
101
+ style = Swt::TextStyle.new font, fgc, bgc
102
+ tl.setStyle style, 0, args[:markup].length - 1
103
+ s.dps << font << fgc << bgc
104
+
105
+ args[:styles].each do |st|
106
+ font, ft, fg, bg, cmds, small = args[:font], Swt::SWT::NORMAL, fgc, bgc, [], 1
107
+ nested_styles(args[:styles], st).each do |e|
108
+ case e[0].style
109
+ when :strong
110
+ ft = ft | Swt::SWT::BOLD
111
+ when :em
112
+ ft = ft | Swt::SWT::ITALIC
113
+ when :fg
114
+ fg = Swt::Color.new Shoes.display, *e[0].color[0,3]
115
+ when :bg
116
+ bg = Swt::Color.new Shoes.display, *e[0].color[0,3]
117
+ when :ins
118
+ cmds << "underline = true"
119
+ when :del
120
+ cmds << "strikeout = true"
121
+ when :sub
122
+ small *= 0.8
123
+ cmds << "rise = -5"
124
+ when :sup
125
+ small *= 0.8
126
+ cmds << "rise = 5"
127
+ when :code
128
+ font = "Lucida Console"
129
+ when :link
130
+ cmds << "underline = true"
131
+ fg = Swt::Color.new Shoes.display, *blue
132
+ spos = tl.getLocation e[1].first, false
133
+ epos = tl.getLocation e[1].last, true
134
+ e[0].lh = tl.getLineBounds(0).height
135
+ e[0].sx, e[0].sy = s.left + spos.x, s.top + spos.y
136
+ e[0].ex, e[0].ey = s.left + epos.x, s.top + epos.y + e[0].lh
137
+ e[0].pl, e[0].pt, e[0].pw, e[0].ph = s.left, s.top, s.width, s.height
138
+ s.links << e[0]
139
+ unless e[0].clickabled
140
+ e[0].parent = s
141
+ clickable e[0], &e[0].blk
142
+ e[0].clickabled = true
143
+ end
144
+ else
145
+ end
146
+ end
147
+ ft = Swt::Font.new Shoes.display, font, args[:size]*small, ft
148
+ style = Swt::TextStyle.new ft, fg, bg
149
+ cmds.each do |cmd|
150
+ eval "style.#{cmd}"
151
+ end
152
+ tl.setStyle style, st[1].first, st[1].last
153
+ s.dps << ft
154
+ end if args[:styles]
155
+ end
156
+
157
+ def nested_styles styles, st
158
+ styles.map do |e|
159
+ (e[1].first <= st[1].first and st[1].last <= e[1].last) ? e : nil
160
+ end - [nil]
161
+ end
162
+
163
+ def pattern_pos left, top, w, h, a
164
+ w, h = w*0.5, h*0.5
165
+ a = Math::PI*(a/180.0)
166
+ a = a % (Math::PI*2.0)
167
+ cal = proc do
168
+ l = Math.sqrt(w**2 + h**2)
169
+ b = Math.atan(h/w)
170
+ c = Math::PI*0.5 - a - b
171
+ r = l * Math.cos(c.abs)
172
+ [r * Math.cos(b+c), r * Math.sin(b+c)]
173
+ end
174
+ if 0 <= a and a < Math::PI*0.5
175
+ x, y = cal.call
176
+ [left+w+x, top+h-y, left+w-x, top+h+y]
177
+ elsif Math::PI*0.5 <= a and a < Math::PI
178
+ a -= Math::PI*0.5
179
+ w, h = h, w
180
+ x, y = cal.call
181
+ [left+h+y, top+w+x, left+h-y, top+w-x]
182
+ elsif Math::PI <= a and a < Math::PI*1.5
183
+ a -= Math::PI
184
+ x, y = cal.call
185
+ [left+w-x, top+h+y, left+w+x, top+h-y]
186
+ elsif Math::PI*1.5 <= a and a < Math::PI*2.0
187
+ a -= Math::PI*1.5
188
+ w, h = h, w
189
+ x, y = cal.call
190
+ [left+h-y, top+w-x, left+h+y, top+w+x]
191
+ end
192
+ end
193
+ end
194
+
195
+ def self.contents_alignment slot
196
+ x, y = slot.left.to_i, slot.top.to_i
197
+ max = Struct.new(:top, :height).new
198
+ max.top, max.height = y, 0
199
+ slot_height, slot_top = 0, y
200
+
201
+ slot.contents.each do |ele|
202
+ tmp = max
203
+ max = ele.positioning x, y, max
204
+ x, y = ele.left + ele.width, ele.top + ele.height
205
+ unless max == tmp
206
+ slot_height = max.top + max.height - slot_top
207
+ end
208
+ end
209
+ slot_height
210
+ end
211
+
212
+ def self.repaint_all slot
213
+ slot.contents.each do |ele|
214
+ ele.is_a?(Basic) ? ele.move2(ele.left + ele.margin_left, ele.top + ele.margin_top) : repaint_all(ele)
215
+ end
216
+ end
217
+
218
+ def self.call_back_procs app
219
+ init_contents app.cslot.contents
220
+ w, h = app.width, app.height
221
+ app.cslot.width, app.cslot.height = w, h
222
+ scrollable_height = contents_alignment app.cslot
223
+ app.cs.setSize w, [scrollable_height, h].max
224
+ vb = app.shell.getVerticalBar
225
+ vb.setVisible(scrollable_height > h)
226
+ if scrollable_height > h
227
+ vb.setMaximum scrollable_height - h + 12
228
+ else
229
+ location = app.cs.getLocation
230
+ location.y = 0
231
+ app.cs.setLocation location
232
+ end
233
+ repaint_all app.cslot
234
+ end
235
+
236
+ def self.init_contents contents
237
+ contents.each do |ele|
238
+ next unless ele.is_a? Slot
239
+ ele.initials.each do |k, v|
240
+ ele.send "#{k}=", v
241
+ end
242
+ end
243
+ end
244
+
245
+ def self.mouse_motion_control app
246
+ app.mmcs.each{|blk| blk[*app.mouse_pos]}
247
+ end
248
+
249
+ def self.mouse_shape_control app
250
+ flag = false
251
+ mouse_x, mouse_y = app.mouse_pos
252
+ app.mscs.each do |s|
253
+ if s.is_a?(Link) and !s.parent.hided
254
+ flag = true if ((s.pl..(s.pl+s.pw)).include?(mouse_x) and (s.sy..s.ey).include?(mouse_y) and !((s.pl..s.sx).include?(mouse_x) and (s.sy..(s.sy+s.lh)).include?(mouse_y)) and !((s.ex..(s.pl+s.pw)).include?(mouse_x) and ((s.ey-s.lh)..s.ey).include?(mouse_y)))
255
+ elsif !s.is_a?(Link) and !s.hided
256
+ dx, dy = s.is_a?(Star) ? [s.width / 2.0, s.height / 2.0] : [0, 0]
257
+ flag = true if s.left - dx <= mouse_x and mouse_x <= s.left - dx + s.width and s.top - dy <= mouse_y and mouse_y <= s.top - dy + s.height
258
+ end
259
+ end
260
+ cursor = flag ? Swt::SWT::CURSOR_HAND : Swt::SWT::CURSOR_ARROW
261
+ app.shell.setCursor Shoes.display.getSystemCursor(cursor)
262
+ end
263
+
264
+ def self.set_pattern s, gc, pat, m = :Background
265
+ pat = s.app.tr_color(pat) if pat.is_a? String
266
+ if pat.is_a? Array
267
+ eval "gc.set#{m} Swt::Color.new(Shoes.display, *pat[0,3])"
268
+ gc.setAlpha(pat[3] ? pat[3]*255 : 255)
269
+ elsif pat.is_a? Range
270
+ if s.is_a? Star
271
+ eval "gc.set#{m}Pattern s.app.gradient(pat, s.left-s.width/2.0, s.top-s.height/2.0, s.width, s.height, s.angle)"
272
+ else
273
+ eval "gc.set#{m}Pattern s.app.gradient(pat, s.left, s.top, s.width, s.height, s.angle)"
274
+ end
275
+ elsif pat.is_a? String
276
+ eval "gc.set#{m}Pattern Swt::Pattern.new(Shoes.display, Swt::Image.new(Shoes.display, pat))"
277
+ end
278
+ end
279
+
280
+ def self.set_rotate gc, angle, left, top
281
+ if block_given?
282
+ tr = Swt::Transform.new Shoes.display
283
+ reset_rotate tr, gc, angle, left, top
284
+ yield
285
+ reset_rotate tr, gc, -angle, left, top
286
+ end
287
+ end
288
+
289
+ def self.reset_rotate tr, gc, angle, left, top
290
+ tr.translate left, top
291
+ tr.rotate angle
292
+ tr.translate -left, -top
293
+ gc.setTransform tr
294
+ end
295
+ end
data/lib/shoes/main.rb ADDED
@@ -0,0 +1,96 @@
1
+ class Shoes
2
+ $urls = {}
3
+ include Swt
4
+
5
+ def self.display
6
+ @display
7
+ end
8
+
9
+ def self.app args={}, &blk
10
+ args[:width] ||= 600
11
+ args[:height] ||= 500
12
+ args[:title] ||= 'purple shoes'
13
+ args[:left] ||= 0
14
+ args[:top] ||= 0
15
+
16
+ @display ||= Swt::Display.new
17
+ shell = Swt::Shell.new @display, Swt::SWT::SHELL_TRIM | Swt::SWT::V_SCROLL
18
+ shell.setSize args[:width] + 16, args[:height] + 38
19
+ shell.setText args[:title]
20
+ color = @display.getSystemColor Swt::SWT::COLOR_WHITE
21
+ shell.setBackground color
22
+ icon = Swt::Image.new @display, File.join(DIR, '../static/purple_shoes-icon.png')
23
+ shell.setImage icon
24
+
25
+ cs = Swt::Composite.new shell, Swt::SWT::TRANSPARENT
26
+ cs.setSize args[:width], args[:height]
27
+
28
+ args[:shell], args[:cs] = shell, cs
29
+ app = App.new args
30
+ @main_app ||= app
31
+ app.top_slot = Flow.new app.slot_attributes(app: app, left: 0, top: 0)
32
+
33
+ class << app; self end.class_eval do
34
+ define_method(:width){shell.isDisposed ? 0 : shell.getSize.x - 16}
35
+ define_method(:height){shell.isDisposed ? 0 : shell.getSize.y - 38}
36
+ end
37
+
38
+ app.hided = true
39
+ blk ? app.instance_eval(&blk) : app.instance_eval{$urls[/^#{'/'}$/].call app}
40
+
41
+ shell.open
42
+ call_back_procs app
43
+ app.aflush
44
+
45
+ cl = Swt::ControlListener.new
46
+ class << cl; self end.
47
+ instance_eval do
48
+ define_method(:controlResized){|e| Shoes.call_back_procs app}
49
+ define_method(:controlMoved){|e|}
50
+ end
51
+ shell.addControlListener cl
52
+
53
+ vb = shell.getVerticalBar
54
+ vb.setVisible false
55
+ ln = Swt::SelectionListener.new
56
+ class << ln; self end.
57
+ instance_eval do
58
+ define_method :widgetSelected do |e|
59
+ unless e.detail == Swt::SWT::DRAG
60
+ location = cs.getLocation
61
+ location.y = -vb.getSelection
62
+ cs.setLocation location
63
+ end
64
+ end
65
+ end
66
+ vb.addSelectionListener ln
67
+
68
+ mml = Swt::MouseMoveListener.new
69
+ class << mml; self end.
70
+ instance_eval do
71
+ define_method :mouseMove do |e|
72
+ app.mouse_pos = [e.x, e.y]
73
+ Shoes.mouse_motion_control app
74
+ Shoes.mouse_shape_control app
75
+ end
76
+ end
77
+ cs.addMouseMoveListener mml
78
+
79
+ ml = Swt::MouseListener.new
80
+ class << ml; self end.
81
+ instance_eval do
82
+ define_method(:mouseDown){|e| app.mouse_button = e.button; app.mouse_pos = [e.x, e.y]}
83
+ define_method(:mouseUp){|e| app.mouse_button = 0; app.mouse_pos = [e.x, e.y]}
84
+ define_method(:mouseDoubleClick){|e|}
85
+ end
86
+ cs.addMouseListener ml
87
+
88
+ if @main_app == app
89
+ while !shell.isDisposed do
90
+ @display.sleep unless @display.readAndDispatch
91
+ end
92
+ @display.dispose
93
+ end
94
+ app
95
+ end
96
+ end
@@ -0,0 +1,6 @@
1
+ class Shoes
2
+ def self.show_manual lang='English'
3
+ $lang = lang
4
+ load File.join(DIR, 'shoes/help.rb')
5
+ end
6
+ end
data/lib/shoes/ruby.rb ADDED
@@ -0,0 +1,61 @@
1
+ class Range
2
+ def rand
3
+ conv = (Integer === self.end && Integer === self.begin ? :to_i : :to_f)
4
+ ((Kernel.rand * (self.end - self.begin)) + self.begin).send(conv)
5
+ end
6
+ end
7
+
8
+ class Object
9
+ include Types
10
+
11
+ def alert msg
12
+ shell = Swt::Shell.new Shoes.display
13
+ mb = Swt::MessageBox.new shell, Swt::SWT::OK | Swt::SWT::ICON_INFORMATION
14
+ mb.setMessage msg.to_s
15
+ mb.open
16
+ end
17
+
18
+ def ask_open_file
19
+ dialog_chooser 'Open File...'
20
+ end
21
+
22
+ def ask_save_file
23
+ dialog_chooser 'Save File...'
24
+ end
25
+
26
+ def ask_open_folder
27
+ dialog_chooser 'Open Folder...', :folder
28
+ end
29
+
30
+ def ask_save_folder
31
+ dialog_chooser 'Save Folder...', :folder
32
+ end
33
+
34
+ def dialog_chooser title, folder=false, style=Swt::SWT::OPEN
35
+ shell = Swt::Shell.new Shoes.display
36
+ fd = folder ? Swt::DirectoryDialog.new(shell, style) : Swt::FileDialog.new(shell, style)
37
+ fd.setText title
38
+ fd.open
39
+ end
40
+ end
41
+
42
+ class Array
43
+ def / len
44
+ a = []
45
+ each_with_index do |x, i|
46
+ a << [] if i % len == 0
47
+ a.last << x
48
+ end
49
+ a
50
+ end
51
+
52
+ def dark?
53
+ r, g, b = self
54
+ r + g + b < 0x55 * 3
55
+ end
56
+
57
+ def light?
58
+ r, g, b = self
59
+ r + g + b > 0xAA * 3
60
+ end
61
+ end