shoes 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. data/.gitignore +12 -0
  2. data/CHANGELOG +29 -0
  3. data/COPYING +30 -0
  4. data/README.md +76 -0
  5. data/README.old +117 -0
  6. data/Rakefile +130 -0
  7. data/Rakefile.bk +651 -0
  8. data/app.yaml +7 -0
  9. data/bin/main.skel +104 -0
  10. data/bugs/issue-012e9468ddc7b0cb7e1503413a8a11c4f8707b67.yaml +21 -0
  11. data/bugs/issue-0711ff8b67baa63586f11d0096fee9dd4436bf58.yaml +23 -0
  12. data/bugs/issue-07f87998d93eb401e22395c11085676389b935c4.yaml +22 -0
  13. data/bugs/issue-0bff2d80008803cbc7efbcdacdc60ef2163664d2.yaml +22 -0
  14. data/bugs/issue-0c66f223d19efbca7b692f3b91961f407ad7abec.yaml +24 -0
  15. data/bugs/issue-183bc3c7a8f575aff2b24e0bf22aa0dfcc8e4fc2.yaml +29 -0
  16. data/bugs/issue-1bad1e60a04cb3adb6a8f3ded128af2e16b56ffe.yaml +18 -0
  17. data/bugs/issue-1f1d43f76bf4de79d7f94adbae6dd506a9d81633.yaml +41 -0
  18. data/bugs/issue-320924117cadb045cc91f2a6fca922b4d81d4bb5.yaml +20 -0
  19. data/bugs/issue-33e5c8355fbf65252ea9e939714651df8bd8cb3b.yaml +25 -0
  20. data/bugs/issue-36f7c8262a72bcd5e28cfa4ed29328b8237ea79b.yaml +20 -0
  21. data/bugs/issue-39bf04ee50c3bef67b89b8e9beb28657805587ce.yaml +18 -0
  22. data/bugs/issue-3e28ba7754f73d02ef416eef989af707a8c00f01.yaml +23 -0
  23. data/bugs/issue-3f638cc03f41f9c3fdf217355321f1563f8fee45.yaml +22 -0
  24. data/bugs/issue-41e48e14f1ef4f6deb69be68165d7dd3ffd99156.yaml +22 -0
  25. data/bugs/issue-4c9408166a2aa5dd333bbb05520deebf4ded08e0.yaml +22 -0
  26. data/bugs/issue-55c687e108ecd5aeb8e0d0aeb4294984f84acd3e.yaml +18 -0
  27. data/bugs/issue-5811d34692cc292717a58ec1df1f8948cf30d826.yaml +28 -0
  28. data/bugs/issue-5a7c1f59a0526f9cea7fb366867cf1e6ed8ef69d.yaml +22 -0
  29. data/bugs/issue-688a2c2566bef6a03efa57a4ae1f7cfa8fc74444.yaml +21 -0
  30. data/bugs/issue-78b16c7988ade2ef96e716fa8cb9a004bd4ced65.yaml +33 -0
  31. data/bugs/issue-804ee49f9800154eddf0650690c7a9bb5626253f.yaml +27 -0
  32. data/bugs/issue-807dd1c610b2e941a5d454e26b2eac27e89a0ab4.yaml +22 -0
  33. data/bugs/issue-822ee33ec11ebd25f90ea86e8438de7891e63aee.yaml +18 -0
  34. data/bugs/issue-82ff7152cebb8a1cb065b864cb4fe22de2328146.yaml +29 -0
  35. data/bugs/issue-856afbdcdd4970ad54b8ce4a6c017fbaab45f49d.yaml +31 -0
  36. data/bugs/issue-8d49e32fb21522651c67490adb4d80076dbb14e1.yaml +24 -0
  37. data/bugs/issue-91583359653a9d530c1e32be72d874d847a306e7.yaml +21 -0
  38. data/bugs/issue-af41a5229613172764e7d3c98431172db337053d.yaml +20 -0
  39. data/bugs/issue-bd9856b3788dd429c998a5af1b2aae8221cb80b7.yaml +28 -0
  40. data/bugs/issue-be22aef5c564fb7b5e9938343136a9cd6a2edb7b.yaml +22 -0
  41. data/bugs/issue-bf8697523c77c326e7e35fc82cf3dd739ae92310.yaml +27 -0
  42. data/bugs/issue-cdd4b4795f34d6ff46e56ece10f8216a4a5456b2.yaml +25 -0
  43. data/bugs/issue-d9bfb5581d745ef9deb3b9b2e08ef74d1cd43082.yaml +20 -0
  44. data/bugs/issue-e0ce2f687cc096f35715d28b0af88589f4ab6cc6.yaml +18 -0
  45. data/bugs/issue-e4b0aca4a10a574b333aeaecaaf221dbc5ed22c6.yaml +38 -0
  46. data/bugs/issue-f263746594b95ba778455730478ee8df60ee639d.yaml +22 -0
  47. data/bugs/project.yaml +72 -0
  48. data/builddeps.sh +102 -0
  49. data/fonts/Coolvetica.ttf +0 -0
  50. data/fonts/Lacuna.ttf +0 -0
  51. data/gemlib/shoes.rb +1 -0
  52. data/lib/shoes.rb +548 -0
  53. data/lib/shoes/cache.rb +54 -0
  54. data/lib/shoes/chipmunk.rb +35 -0
  55. data/lib/shoes/data.rb +39 -0
  56. data/lib/shoes/help.rb +468 -0
  57. data/lib/shoes/image.rb +25 -0
  58. data/lib/shoes/inspect.rb +128 -0
  59. data/lib/shoes/log.rb +48 -0
  60. data/lib/shoes/minitar.rb +986 -0
  61. data/lib/shoes/override.rb +38 -0
  62. data/lib/shoes/pack.rb +543 -0
  63. data/lib/shoes/search.rb +46 -0
  64. data/lib/shoes/setup.rb +329 -0
  65. data/lib/shoes/shy.rb +131 -0
  66. data/lib/shoes/shybuilder.rb +44 -0
  67. data/lib/shoes/version.rb +3 -0
  68. data/make/darwin/deps.vlc +12 -0
  69. data/make/darwin/dylibs.shoes +22 -0
  70. data/make/darwin/dylibs.video +11 -0
  71. data/make/darwin/env.rb +81 -0
  72. data/make/darwin/tasks.rb +105 -0
  73. data/make/linux/env.rb +65 -0
  74. data/make/linux/tasks.rb +61 -0
  75. data/make/make.rb +85 -0
  76. data/make/mingw/dlls +19 -0
  77. data/make/mingw/env.rb +69 -0
  78. data/make/mingw/tasks.rb +70 -0
  79. data/make/rakefile_common.rb +8 -0
  80. data/manual-snapshots/class-book.png +0 -0
  81. data/manual-snapshots/expert-definr.png +0 -0
  82. data/manual-snapshots/expert-funnies.png +0 -0
  83. data/manual-snapshots/expert-irb.png +0 -0
  84. data/manual-snapshots/expert-minesweeper.png +0 -0
  85. data/manual-snapshots/expert-othello.png +0 -0
  86. data/manual-snapshots/expert-pong.png +0 -0
  87. data/manual-snapshots/expert-tankspank.png +0 -0
  88. data/manual-snapshots/good-arc.png +0 -0
  89. data/manual-snapshots/good-clock.png +0 -0
  90. data/manual-snapshots/good-follow.png +0 -0
  91. data/manual-snapshots/good-reminder.png +0 -0
  92. data/manual-snapshots/good-vjot.png +0 -0
  93. data/manual-snapshots/simple-accordion.png +0 -0
  94. data/manual-snapshots/simple-anim-shapes.png +0 -0
  95. data/manual-snapshots/simple-anim-text.png +0 -0
  96. data/manual-snapshots/simple-arc.png +0 -0
  97. data/manual-snapshots/simple-bounce.png +0 -0
  98. data/manual-snapshots/simple-calc.png +0 -0
  99. data/manual-snapshots/simple-chipmunk.png +0 -0
  100. data/manual-snapshots/simple-control-sizes.png +0 -0
  101. data/manual-snapshots/simple-curve.png +0 -0
  102. data/manual-snapshots/simple-dialogs.png +0 -0
  103. data/manual-snapshots/simple-downloader.png +0 -0
  104. data/manual-snapshots/simple-draw.png +0 -0
  105. data/manual-snapshots/simple-editor.png +0 -0
  106. data/manual-snapshots/simple-form.png +0 -0
  107. data/manual-snapshots/simple-mask.png +0 -0
  108. data/manual-snapshots/simple-menu.png +0 -0
  109. data/manual-snapshots/simple-menu1.png +0 -0
  110. data/manual-snapshots/simple-rubygems.png +0 -0
  111. data/manual-snapshots/simple-slide.png +0 -0
  112. data/manual-snapshots/simple-sphere.png +0 -0
  113. data/manual-snapshots/simple-sqlite3.png +0 -0
  114. data/manual-snapshots/simple-timer.png +0 -0
  115. data/manual-snapshots/simple-video.png +0 -0
  116. data/platform/mac/Info.plist +55 -0
  117. data/platform/mac/build-deps.sh +658 -0
  118. data/platform/mac/command-manual.rb +1 -0
  119. data/platform/mac/deps-osx.patch +159 -0
  120. data/platform/mac/dmg_ds_store +0 -0
  121. data/platform/mac/pangorc +2 -0
  122. data/platform/mac/pkg-dmg +1447 -0
  123. data/platform/mac/shoes +31 -0
  124. data/platform/mac/shoes-launch +7 -0
  125. data/platform/mac/stub.m +178 -0
  126. data/platform/mac/version.plist +14 -0
  127. data/platform/msw/base.nsi +644 -0
  128. data/platform/msw/installer-1.bmp +0 -0
  129. data/platform/msw/installer-2.bmp +0 -0
  130. data/platform/msw/shoes.exe.manifest +17 -0
  131. data/platform/msw/shoes.ico +0 -0
  132. data/platform/msw/stub-inject.c +59 -0
  133. data/platform/msw/stub.c +271 -0
  134. data/platform/msw/stub32.h +14 -0
  135. data/platform/msw/stub32.rc +16 -0
  136. data/platform/nix/INSTALL +56 -0
  137. data/platform/nix/Makefile +144 -0
  138. data/platform/nix/shoes.launch +20 -0
  139. data/platform/skel.rb +27 -0
  140. data/rakefile_darwin.rb +7 -0
  141. data/rakefile_linux.rb +3 -0
  142. data/rakefile_mingw.rb +7 -0
  143. data/samples/class-book.rb +43 -0
  144. data/samples/class-book.yaml +387 -0
  145. data/samples/expert-definr.rb +23 -0
  146. data/samples/expert-funnies.rb +51 -0
  147. data/samples/expert-irb.rb +112 -0
  148. data/samples/expert-minesweeper.rb +267 -0
  149. data/samples/expert-othello.rb +319 -0
  150. data/samples/expert-pong.rb +62 -0
  151. data/samples/expert-tankspank.rb +385 -0
  152. data/samples/good-arc.rb +37 -0
  153. data/samples/good-clock.rb +51 -0
  154. data/samples/good-follow.rb +26 -0
  155. data/samples/good-reminder.rb +174 -0
  156. data/samples/good-vjot.rb +56 -0
  157. data/samples/simple-accordion.rb +75 -0
  158. data/samples/simple-anim-shapes.rb +17 -0
  159. data/samples/simple-anim-text.rb +13 -0
  160. data/samples/simple-arc.rb +23 -0
  161. data/samples/simple-bounce.rb +24 -0
  162. data/samples/simple-calc.rb +70 -0
  163. data/samples/simple-chipmunk.rb +26 -0
  164. data/samples/simple-control-sizes.rb +24 -0
  165. data/samples/simple-curve.rb +26 -0
  166. data/samples/simple-dialogs.rb +29 -0
  167. data/samples/simple-downloader.rb +27 -0
  168. data/samples/simple-draw.rb +13 -0
  169. data/samples/simple-editor.rb +28 -0
  170. data/samples/simple-form.rb +28 -0
  171. data/samples/simple-form.shy +0 -0
  172. data/samples/simple-mask.rb +21 -0
  173. data/samples/simple-menu.rb +31 -0
  174. data/samples/simple-menu1.rb +35 -0
  175. data/samples/simple-rubygems.rb +29 -0
  176. data/samples/simple-slide.rb +45 -0
  177. data/samples/simple-sphere.rb +28 -0
  178. data/samples/simple-sqlite3.rb +13 -0
  179. data/samples/simple-timer.rb +13 -0
  180. data/samples/simple-video.rb +13 -0
  181. data/shoes.gemspec +21 -0
  182. data/shoes/app.c +591 -0
  183. data/shoes/app.h +110 -0
  184. data/shoes/appwin32.h +13 -0
  185. data/shoes/appwin32.rc +28 -0
  186. data/shoes/canvas.c +2202 -0
  187. data/shoes/canvas.h +682 -0
  188. data/shoes/code.h +14 -0
  189. data/shoes/config.h +232 -0
  190. data/shoes/effects.c +243 -0
  191. data/shoes/effects.h +7 -0
  192. data/shoes/http.h +44 -0
  193. data/shoes/http/common.h +86 -0
  194. data/shoes/http/curl.c +259 -0
  195. data/shoes/http/nsurl.m +274 -0
  196. data/shoes/http/windownload.c +114 -0
  197. data/shoes/http/winhttp.c +216 -0
  198. data/shoes/http/winhttp.h +19 -0
  199. data/shoes/image.c +1020 -0
  200. data/shoes/internal.c +46 -0
  201. data/shoes/internal.h +63 -0
  202. data/shoes/native.h +110 -0
  203. data/shoes/native/cocoa.h +105 -0
  204. data/shoes/native/cocoa.m +1557 -0
  205. data/shoes/native/gtk.c +1257 -0
  206. data/shoes/native/windows.c +2392 -0
  207. data/shoes/ruby.c +5221 -0
  208. data/shoes/ruby.h +299 -0
  209. data/shoes/world.c +243 -0
  210. data/shoes/world.h +63 -0
  211. data/static/Shoes.icns +0 -0
  212. data/static/avatar.png +0 -0
  213. data/static/code_highlighter.js +188 -0
  214. data/static/code_highlighter_ruby.js +26 -0
  215. data/static/icon-debug.png +0 -0
  216. data/static/icon-error.png +0 -0
  217. data/static/icon-info.png +0 -0
  218. data/static/icon-warn.png +0 -0
  219. data/static/listbox_button1.png +0 -0
  220. data/static/listbox_button2.png +0 -0
  221. data/static/man-app.png +0 -0
  222. data/static/man-builds.png +0 -0
  223. data/static/man-builds1.png +0 -0
  224. data/static/man-editor-notepad.png +0 -0
  225. data/static/man-editor-osx.png +0 -0
  226. data/static/man-ele-background.png +0 -0
  227. data/static/man-ele-border.png +0 -0
  228. data/static/man-ele-button.png +0 -0
  229. data/static/man-ele-check.png +0 -0
  230. data/static/man-ele-editbox.png +0 -0
  231. data/static/man-ele-editline.png +0 -0
  232. data/static/man-ele-image.png +0 -0
  233. data/static/man-ele-listbox.png +0 -0
  234. data/static/man-ele-progress.png +0 -0
  235. data/static/man-ele-radio.png +0 -0
  236. data/static/man-ele-shape.png +0 -0
  237. data/static/man-ele-textblock.png +0 -0
  238. data/static/man-ele-video.png +0 -0
  239. data/static/man-intro-dmg.png +0 -0
  240. data/static/man-intro-exe.png +0 -0
  241. data/static/man-look-tiger.png +0 -0
  242. data/static/man-look-ubuntu.png +0 -0
  243. data/static/man-look-vista.png +0 -0
  244. data/static/man-run-osx.png +0 -0
  245. data/static/man-run-vista.png +0 -0
  246. data/static/man-run-xp.png +0 -0
  247. data/static/man-shot1.png +0 -0
  248. data/static/manual-en.txt +3531 -0
  249. data/static/manual-ja.txt +2825 -0
  250. data/static/manual.css +167 -0
  251. data/static/menu-corner1.png +0 -0
  252. data/static/menu-corner2.png +0 -0
  253. data/static/menu-gray.png +0 -0
  254. data/static/menu-left.png +0 -0
  255. data/static/menu-right.png +0 -0
  256. data/static/menu-top.png +0 -0
  257. data/static/shoes-dmg.jpg +0 -0
  258. data/static/shoes-icon-blue.png +0 -0
  259. data/static/shoes-icon.png +0 -0
  260. data/static/shoes-manual-apps.gif +0 -0
  261. data/static/shoes_main_window.png +0 -0
  262. data/static/stripe.png +0 -0
  263. data/static/stubs/blank.exe +0 -0
  264. data/static/stubs/blank.hfz +0 -0
  265. data/static/stubs/blank.run +375 -0
  266. data/static/stubs/cocoa-install +0 -0
  267. data/static/stubs/sh-install +49 -0
  268. data/static/stubs/shoes-stub-inject.exe +0 -0
  269. data/static/stubs/shoes-stub.exe +0 -0
  270. data/static/tutor-back.png +0 -0
  271. data/test/shoes_test.rb +8 -0
  272. data/test/test_helper.rb +25 -0
  273. data/use-deps +12 -0
  274. data/use-tmp-dep +8 -0
  275. metadata +509 -0
@@ -0,0 +1,45 @@
1
+ #
2
+ # mimicking the mootools demo for Fx.Slide
3
+ # http://demos.mootools.net/Fx.Slide
4
+ #
5
+ Shoes.app do
6
+ def stop_anim
7
+ @anim.stop
8
+ @anim = nil
9
+ end
10
+ def slide_anim &blk
11
+ stop_anim if @anim
12
+ @anim = animate 30, &blk
13
+ end
14
+ def slide_out slot
15
+ slide_anim do |i|
16
+ slot.height = 150 - (i * 3)
17
+ slot.contents[0].top = -i * 3
18
+ if slot.height == 0
19
+ stop_anim
20
+ slot.hide
21
+ end
22
+ end
23
+ end
24
+ def slide_in slot
25
+ slot.show
26
+ slide_anim do |i|
27
+ slot.height = i * 6
28
+ slot.contents[0].top = slot.height - 150
29
+ stop_anim if slot.height == 150
30
+ end
31
+ end
32
+
33
+ background white
34
+ stack :margin => 10 do
35
+ para link("slide out") { slide_out @lipsum }, " | ",
36
+ link("slide in") { slide_in @lipsum }
37
+ @lipsum = stack :width => 1.0, :height => 150 do
38
+ stack do
39
+ background "#ddd"
40
+ border "#eee", :strokewidth => 5
41
+ para "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", :margin => 10
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ Shoes.app :width => 500, :height => 500, :resizable => false do
2
+ image 400, 470, :top => 30, :left => 50 do
3
+ nostroke
4
+ fill "#127"
5
+ image :top => 230, :left => 0 do
6
+ oval 70, 130, 260, 40
7
+ blur 30
8
+ end
9
+ oval 10, 10, 380, 380
10
+ image :top => 0, :left => 0 do
11
+ fill "#46D"
12
+ oval 30, 30, 338, 338
13
+ blur 10
14
+ end
15
+ fill gradient(rgb(1.0, 1.0, 1.0, 0.7), rgb(1.0, 1.0, 1.0, 0.0))
16
+ oval 80, 14, 240, 176
17
+ image :top => 0, :left => 0 do
18
+ fill "#79F"
19
+ oval 134, 134, 130, 130
20
+ blur 40
21
+ end
22
+ image :top => 150, :left => 40, :width => 320, :height => 260 do
23
+ fill gradient(rgb(0.7, 0.9, 1.0, 0.0), rgb(0.7, 0.9, 1.0, 0.6))
24
+ oval 60, 60, 200, 136
25
+ blur 20
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'sqlite3'
2
+ Shoes.app :width => 350, :height => 130 do
3
+ db = SQLite3::Database.new "simple-sqlite3.db"
4
+ db.execute "create table t1 (t1key INTEGER PRIMARY KEY,data " \
5
+ "TEXT,num double,timeEnter DATE)"
6
+ db.execute "insert into t1 (data,num) values ('This is sample data',3)"
7
+ db.execute "insert into t1 (data,num) values ('More sample data',6)"
8
+ db.execute "insert into t1 (data,num) values ('Aurélio, Küng, Stärk, Uña, Łuksza',6)"
9
+ db.execute "insert into t1 (data,num) values ('And a little more',9)"
10
+ rows = db.execute "select * from t1"
11
+ rows.each{|k, d, n| para "#{k} : #{d} : #{n}\n"}
12
+ end
13
+
@@ -0,0 +1,13 @@
1
+ Shoes.app :height => 150, :width => 250 do
2
+ background rgb(240, 250, 208)
3
+ stack :margin => 10 do
4
+ button "Start" do
5
+ @time = Time.now
6
+ @label.replace "Stop watch started at #@time"
7
+ end
8
+ button "Stop" do
9
+ @label.replace "Stopped, ", strong("#{Time.now - @time}"), " seconds elapsed."
10
+ end
11
+ @label = para "Press ", strong("start"), " to begin timing."
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ Shoes.app :width => 408, :height => 346, :resizable => false do
2
+ background "#eee"
3
+ stack :margin => 4 do
4
+ @vid = video "http://www.rin-shun.com/shoes/AdventureTimewithFinnandJakeFinnTime.mp4"
5
+ end
6
+ para "controls: ",
7
+ link("play") { @vid.play }, ", ",
8
+ link("pause") { @vid.pause }, ", ",
9
+ link("stop") { @vid.stop }, ", ",
10
+ link("hide") { @vid.hide }, ", ",
11
+ link("show") { @vid.show }, ", ",
12
+ link("+5 sec") { @vid.time += 5000 }
13
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "shoes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "shoes"
7
+ s.version = Shoes::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Steve Klabnik", "Team Shoes"]
10
+ s.email = ["steve@steveklabnik.com"]
11
+ s.homepage = "http://github.com/shoes/shoes"
12
+ s.summary = %q{Shoes is the best little GUI toolkit for Ruby.}
13
+ s.description = %q{Shoes is the best little GUI toolkit for Ruby. This gem is currently a placeholder until we properly gemfiy Shoes.}
14
+
15
+ #s.add_development_dependency "watchr"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["gemlib"]
21
+ end
@@ -0,0 +1,591 @@
1
+ //
2
+ // shoes/app.c
3
+ // Abstract windowing for GTK, Quartz (OSX) and Win32.
4
+ //
5
+ #include <glib.h>
6
+ #include "shoes/app.h"
7
+ #include "shoes/internal.h"
8
+ #include "shoes/ruby.h"
9
+ #include "shoes/canvas.h"
10
+ #include "shoes/world.h"
11
+ #include "shoes/native.h"
12
+
13
+ static void
14
+ shoes_app_mark(shoes_app *app)
15
+ {
16
+ shoes_native_slot_mark(app->slot);
17
+ rb_gc_mark_maybe(app->title);
18
+ rb_gc_mark_maybe(app->location);
19
+ rb_gc_mark_maybe(app->canvas);
20
+ rb_gc_mark_maybe(app->keypresses);
21
+ rb_gc_mark_maybe(app->nestslot);
22
+ rb_gc_mark_maybe(app->nesting);
23
+ rb_gc_mark_maybe(app->extras);
24
+ rb_gc_mark_maybe(app->styles);
25
+ rb_gc_mark_maybe(app->groups);
26
+ rb_gc_mark_maybe(app->owner);
27
+ }
28
+
29
+ static void
30
+ shoes_app_free(shoes_app *app)
31
+ {
32
+ SHOE_FREE(app->slot);
33
+ cairo_destroy(app->scratch);
34
+ RUBY_CRITICAL(free(app));
35
+ }
36
+
37
+ VALUE
38
+ shoes_app_alloc(VALUE klass)
39
+ {
40
+ shoes_app *app = SHOE_ALLOC(shoes_app);
41
+ SHOE_MEMZERO(app, shoes_app, 1);
42
+ app->slot = SHOE_ALLOC(SHOES_SLOT_OS);
43
+ SHOE_MEMZERO(app->slot, SHOES_SLOT_OS, 1);
44
+ app->slot->owner = app;
45
+ app->started = FALSE;
46
+ app->owner = Qnil;
47
+ app->location = Qnil;
48
+ app->canvas = shoes_canvas_new(cShoes, app);
49
+ app->keypresses = rb_hash_new();
50
+ app->nestslot = Qnil;
51
+ app->nesting = rb_ary_new();
52
+ app->extras = rb_ary_new();
53
+ app->groups = Qnil;
54
+ app->styles = Qnil;
55
+ app->title = Qnil;
56
+ app->width = SHOES_APP_WIDTH;
57
+ app->height = SHOES_APP_HEIGHT;
58
+ app->minwidth = 0;
59
+ app->minheight = 0;
60
+ app->fullscreen = FALSE;
61
+ app->resizable = TRUE;
62
+ app->cursor = s_arrow;
63
+ app->scratch = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));
64
+ app->self = Data_Wrap_Struct(klass, shoes_app_mark, shoes_app_free, app);
65
+ rb_extend_object(app->self, cTypes);
66
+ return app->self;
67
+ }
68
+
69
+ VALUE
70
+ shoes_app_new(VALUE klass)
71
+ {
72
+ VALUE app = shoes_app_alloc(klass);
73
+ rb_ary_push(shoes_world->apps, app);
74
+ return app;
75
+ }
76
+
77
+ VALUE
78
+ shoes_apps_get(VALUE self)
79
+ {
80
+ return rb_ary_dup(shoes_world->apps);
81
+ }
82
+
83
+ static void
84
+ shoes_app_clear(shoes_app *app)
85
+ {
86
+ shoes_ele_remove_all(app->extras);
87
+ shoes_canvas_clear(app->canvas);
88
+ app->nestslot = Qnil;
89
+ app->groups = Qnil;
90
+ }
91
+
92
+ //
93
+ // When a window is finished, call this to delete it from the master
94
+ // list. Returns 1 if all windows are gone.
95
+ //
96
+ int
97
+ shoes_app_remove(shoes_app *app)
98
+ {
99
+ shoes_app_clear(app);
100
+ rb_ary_delete(shoes_world->apps, app->self);
101
+ return (RARRAY_LEN(shoes_world->apps) == 0);
102
+ }
103
+
104
+ shoes_code
105
+ shoes_app_resize(shoes_app *app, int width, int height)
106
+ {
107
+ app->width = width;
108
+ app->height = height;
109
+ shoes_native_app_resized(app);
110
+ return SHOES_OK;
111
+ }
112
+
113
+ VALUE
114
+ shoes_app_window(int argc, VALUE *argv, VALUE self, VALUE owner)
115
+ {
116
+ rb_arg_list args;
117
+ VALUE attr = Qnil;
118
+ VALUE app = shoes_app_new(self == cDialog ? cDialog : cApp);
119
+ shoes_app *app_t;
120
+ char *url = "/";
121
+ Data_Get_Struct(app, shoes_app, app_t);
122
+
123
+ switch (rb_parse_args(argc, argv, "h,s|h,", &args))
124
+ {
125
+ case 1:
126
+ attr = args.a[0];
127
+ break;
128
+
129
+ case 2:
130
+ url = RSTRING_PTR(args.a[0]);
131
+ attr = args.a[1];
132
+ break;
133
+ }
134
+
135
+ if (rb_block_given_p()) rb_iv_set(app, "@main_app", rb_block_proc());
136
+ app_t->owner = owner;
137
+ app_t->title = ATTR(attr, title);
138
+ app_t->fullscreen = RTEST(ATTR(attr, fullscreen));
139
+ app_t->resizable = (ATTR(attr, resizable) != Qfalse);
140
+ app_t->hidden = (ATTR(attr, hidden) == Qtrue);
141
+ shoes_app_resize(app_t, ATTR2(int, attr, width, SHOES_APP_WIDTH), ATTR2(int, attr, height, SHOES_APP_HEIGHT));
142
+ if (RTEST(ATTR(attr, minwidth)))
143
+ app_t->minwidth = (ATTR(attr, minwidth) - 1) / 2;
144
+ if (RTEST(ATTR(attr, minheight)))
145
+ app_t->minheight = (ATTR(attr, minheight) -1) / 2;
146
+ shoes_canvas_init(app_t->canvas, app_t->slot, attr, app_t->width, app_t->height);
147
+ if (shoes_world->mainloop)
148
+ shoes_app_open(app_t, url);
149
+ return app;
150
+ }
151
+
152
+ VALUE
153
+ shoes_app_main(int argc, VALUE *argv, VALUE self)
154
+ {
155
+ return shoes_app_window(argc, argv, self, Qnil);
156
+ }
157
+
158
+ VALUE
159
+ shoes_app_slot(VALUE app)
160
+ {
161
+ shoes_app *app_t;
162
+ Data_Get_Struct(app, shoes_app, app_t);
163
+ return app_t->nestslot;
164
+ }
165
+
166
+ VALUE
167
+ shoes_app_get_width(VALUE app)
168
+ {
169
+ shoes_app *app_t;
170
+ Data_Get_Struct(app, shoes_app, app_t);
171
+ return INT2NUM(app_t->width);
172
+ }
173
+
174
+ VALUE
175
+ shoes_app_get_height(VALUE app)
176
+ {
177
+ shoes_app *app_t;
178
+ Data_Get_Struct(app, shoes_app, app_t);
179
+ return INT2NUM(app_t->height);
180
+ }
181
+
182
+ VALUE
183
+ shoes_app_get_title(VALUE app)
184
+ {
185
+ shoes_app *app_t;
186
+ Data_Get_Struct(app, shoes_app, app_t);
187
+ return app_t->title;
188
+ }
189
+
190
+ VALUE
191
+ shoes_app_set_title(VALUE app, VALUE title)
192
+ {
193
+ shoes_app *app_t;
194
+ Data_Get_Struct(app, shoes_app, app_t);
195
+ return app_t->title = title;
196
+ }
197
+
198
+ VALUE
199
+ shoes_app_get_fullscreen(VALUE app)
200
+ {
201
+ shoes_app *app_t;
202
+ Data_Get_Struct(app, shoes_app, app_t);
203
+ return app_t->fullscreen ? Qtrue : Qfalse;
204
+ }
205
+
206
+ VALUE
207
+ shoes_app_set_fullscreen(VALUE app, VALUE yn)
208
+ {
209
+ shoes_app *app_t;
210
+ Data_Get_Struct(app, shoes_app, app_t);
211
+ shoes_native_app_fullscreen(app_t, app_t->fullscreen = RTEST(yn));
212
+ return yn;
213
+ }
214
+
215
+ void
216
+ shoes_app_title(shoes_app *app, VALUE title)
217
+ {
218
+ char *msg;
219
+ if (!NIL_P(title))
220
+ app->title = title;
221
+ else
222
+ app->title = rb_str_new2(SHOES_APPNAME);
223
+ msg = RSTRING_PTR(app->title);
224
+ shoes_native_app_title(app, msg);
225
+ }
226
+
227
+ shoes_code
228
+ shoes_app_start(VALUE allapps, char *uri)
229
+ {
230
+ int i;
231
+ shoes_code code;
232
+ shoes_app *app;
233
+
234
+ for (i = 0; i < RARRAY_LEN(allapps); i++)
235
+ {
236
+ VALUE appobj2 = rb_ary_entry(allapps, i);
237
+ Data_Get_Struct(appobj2, shoes_app, app);
238
+ if (!app->started)
239
+ {
240
+ code = shoes_app_open(app, uri);
241
+ app->started = TRUE;
242
+ if (code != SHOES_OK)
243
+ return code;
244
+ }
245
+ }
246
+
247
+ return shoes_app_loop();
248
+ }
249
+
250
+ shoes_code
251
+ shoes_app_open(shoes_app *app, char *path)
252
+ {
253
+ shoes_code code = SHOES_OK;
254
+ int dialog = (rb_obj_class(app->self) == cDialog);
255
+
256
+ code = shoes_native_app_open(app, path, dialog);
257
+ if (code != SHOES_OK)
258
+ return code;
259
+
260
+ shoes_app_title(app, app->title);
261
+ if (app->slot != NULL) shoes_native_slot_reset(app->slot);
262
+ shoes_slot_init(app->canvas, app->slot, 0, 0, app->width, app->height, TRUE, TRUE);
263
+ code = shoes_app_goto(app, path);
264
+ if (code != SHOES_OK)
265
+ return code;
266
+
267
+ if (!app->hidden)
268
+ shoes_native_app_show(app);
269
+
270
+ return code;
271
+ }
272
+
273
+ shoes_code
274
+ shoes_app_loop()
275
+ {
276
+ if (shoes_world->mainloop)
277
+ return SHOES_OK;
278
+
279
+ shoes_world->mainloop = TRUE;
280
+ INFO("RUNNING LOOP.\n");
281
+ shoes_native_loop();
282
+ return SHOES_OK;
283
+ }
284
+
285
+ typedef struct
286
+ {
287
+ shoes_app *app;
288
+ VALUE canvas;
289
+ VALUE block;
290
+ char ieval;
291
+ VALUE args;
292
+ } shoes_exec;
293
+
294
+ #ifdef RUBY_1_9
295
+ struct METHOD {
296
+ VALUE oclass; /* class that holds the method */
297
+ VALUE rklass; /* class of the receiver */
298
+ VALUE recv;
299
+ ID id, oid;
300
+ void *body; /* NODE *body; */
301
+ };
302
+ #else
303
+ struct METHOD {
304
+ VALUE klass, rklass;
305
+ VALUE recv;
306
+ ID id, oid;
307
+ int safe_level;
308
+ NODE *body;
309
+ };
310
+ #endif
311
+
312
+ static VALUE
313
+ rb_unbound_get_class(VALUE method)
314
+ {
315
+ struct METHOD *data;
316
+ Data_Get_Struct(method, struct METHOD, data);
317
+ return data->rklass;
318
+ }
319
+
320
+ static VALUE
321
+ shoes_app_run(VALUE rb_exec)
322
+ {
323
+ shoes_exec *exec = (shoes_exec *)rb_exec;
324
+ rb_ary_push(exec->app->nesting, exec->canvas);
325
+ if (exec->ieval)
326
+ {
327
+ VALUE obj;
328
+ obj = mfp_instance_eval(exec->app->self, exec->block);
329
+ return obj;
330
+ }
331
+ else
332
+ {
333
+ int i;
334
+ VALUE vargs[10];
335
+ for (i = 0; i < RARRAY_LEN(exec->args); i++)
336
+ vargs[i] = rb_ary_entry(exec->args, i);
337
+ return rb_funcall2(exec->block, s_call, RARRAY_LEN(exec->args), vargs);
338
+ }
339
+ }
340
+
341
+ static VALUE
342
+ shoes_app_exception(VALUE rb_exec, VALUE e)
343
+ {
344
+ shoes_exec *exec = (shoes_exec *)rb_exec;
345
+ rb_ary_clear(exec->app->nesting);
346
+ shoes_canvas_error(exec->canvas, e);
347
+ return Qnil;
348
+ }
349
+
350
+ shoes_code
351
+ shoes_app_visit(shoes_app *app, char *path)
352
+ {
353
+ shoes_exec exec;
354
+ shoes_canvas *canvas;
355
+ VALUE meth;
356
+ Data_Get_Struct(app->canvas, shoes_canvas, canvas);
357
+
358
+ canvas->slot->scrolly = 0;
359
+ shoes_native_slot_clear(canvas);
360
+ shoes_app_clear(app);
361
+ shoes_app_reset_styles(app);
362
+ meth = rb_funcall(cShoes, s_run, 1, app->location = rb_str_new2(path));
363
+
364
+ VALUE app_block = rb_iv_get(app->self, "@main_app");
365
+ if (!NIL_P(app_block))
366
+ rb_ary_store(meth, 0, app_block);
367
+
368
+ exec.app = app;
369
+ exec.block = rb_ary_entry(meth, 0);
370
+ exec.args = rb_ary_entry(meth, 1);
371
+ if (rb_obj_is_kind_of(exec.block, rb_cUnboundMethod)) {
372
+ VALUE klass = rb_unbound_get_class(exec.block);
373
+ exec.canvas = app->nestslot = shoes_slot_new(klass, ssNestSlot, app->canvas);
374
+ exec.block = rb_funcall(exec.block, s_bind, 1, exec.canvas);
375
+ exec.ieval = 0;
376
+ rb_ary_push(canvas->contents, exec.canvas);
377
+ } else {
378
+ exec.canvas = app->nestslot = app->canvas;
379
+ exec.ieval = 1;
380
+ }
381
+
382
+ rb_rescue2(CASTHOOK(shoes_app_run), (VALUE)&exec, CASTHOOK(shoes_app_exception), (VALUE)&exec, rb_cObject, 0);
383
+
384
+ rb_ary_clear(exec.app->nesting);
385
+ return SHOES_OK;
386
+ }
387
+
388
+ shoes_code
389
+ shoes_app_paint(shoes_app *app)
390
+ {
391
+ shoes_canvas_paint(app->canvas);
392
+ return SHOES_OK;
393
+ }
394
+
395
+ shoes_code
396
+ shoes_app_motion(shoes_app *app, int x, int y)
397
+ {
398
+ app->mousex = x; app->mousey = y;
399
+ shoes_canvas_send_motion(app->canvas, x, y, Qnil);
400
+ return SHOES_OK;
401
+ }
402
+
403
+ shoes_code
404
+ shoes_app_click(shoes_app *app, int button, int x, int y)
405
+ {
406
+ app->mouseb = button;
407
+ shoes_canvas_send_click(app->canvas, button, x, y);
408
+ return SHOES_OK;
409
+ }
410
+
411
+ shoes_code
412
+ shoes_app_release(shoes_app *app, int button, int x, int y)
413
+ {
414
+ app->mouseb = 0;
415
+ shoes_canvas_send_release(app->canvas, button, x, y);
416
+ return SHOES_OK;
417
+ }
418
+
419
+ shoes_code
420
+ shoes_app_wheel(shoes_app *app, ID dir, int x, int y)
421
+ {
422
+ shoes_canvas *canvas;
423
+ Data_Get_Struct(app->canvas, shoes_canvas, canvas);
424
+ if (canvas->slot->vscroll)
425
+ {
426
+ if (dir == s_up)
427
+ shoes_slot_scroll_to(canvas, -16, 1);
428
+ else if (dir == s_down)
429
+ shoes_slot_scroll_to(canvas, 16, 1);
430
+ }
431
+ shoes_canvas_send_wheel(app->canvas, dir, x, y);
432
+ return SHOES_OK;
433
+ }
434
+
435
+ shoes_code
436
+ shoes_app_keydown(shoes_app *app, VALUE key)
437
+ {
438
+ if (!RTEST(rb_hash_aref(app->keypresses, key))) {
439
+ rb_hash_aset(app->keypresses, key, Qtrue);
440
+ shoes_canvas_send_keydown(app->canvas, key);
441
+ }
442
+ return SHOES_OK;
443
+ }
444
+
445
+ shoes_code
446
+ shoes_app_keypress(shoes_app *app, VALUE key)
447
+ {
448
+ if (key == symAltSlash)
449
+ rb_eval_string("Shoes.show_log");
450
+ else if (key == symAltQuest)
451
+ rb_eval_string("Shoes.show_manual");
452
+ else if (key == symAltDot)
453
+ rb_eval_string("Shoes.show_selector");
454
+ else
455
+ shoes_canvas_send_keypress(app->canvas, key);
456
+ return SHOES_OK;
457
+ }
458
+
459
+ shoes_code
460
+ shoes_app_keyup(shoes_app *app, VALUE key)
461
+ {
462
+ rb_hash_aset(app->keypresses, key, Qfalse);
463
+ shoes_canvas_send_keyup(app->canvas, key);
464
+ return SHOES_OK;
465
+ }
466
+
467
+ VALUE
468
+ shoes_sys(char *cmd, int detach)
469
+ {
470
+ if (detach)
471
+ return rb_funcall(rb_mKernel, rb_intern("system"), 1, rb_str_new2(cmd));
472
+ else
473
+ return rb_funcall(rb_mKernel, '`', 1, rb_str_new2(cmd));
474
+ }
475
+
476
+ shoes_code
477
+ shoes_app_goto(shoes_app *app, char *path)
478
+ {
479
+ shoes_code code = SHOES_OK;
480
+ const char http_scheme[] = "http://";
481
+ if (strlen(path) > strlen(http_scheme) && strncmp(http_scheme, path, strlen(http_scheme)) == 0) {
482
+ shoes_browser_open(path);
483
+ } else {
484
+ code = shoes_app_visit(app, path);
485
+ if (code == SHOES_OK)
486
+ {
487
+ shoes_app_motion(app, app->mousex, app->mousey);
488
+ shoes_slot_repaint(app->slot);
489
+ }
490
+ }
491
+ return code;
492
+ }
493
+
494
+ shoes_code
495
+ shoes_slot_repaint(SHOES_SLOT_OS *slot)
496
+ {
497
+ shoes_native_slot_paint(slot);
498
+ return SHOES_OK;
499
+ }
500
+
501
+ static void
502
+ shoes_style_set(VALUE styles, VALUE klass, VALUE k, VALUE v)
503
+ {
504
+ VALUE hsh = rb_hash_aref(styles, klass);
505
+ if (NIL_P(hsh))
506
+ rb_hash_aset(styles, klass, hsh = rb_hash_new());
507
+ rb_hash_aset(hsh, k, v);
508
+ }
509
+
510
+ #define STYLE(klass, k, v) \
511
+ shoes_style_set(app->styles, klass, \
512
+ ID2SYM(rb_intern("" # k)), rb_str_new2("" # v))
513
+
514
+ void
515
+ shoes_app_reset_styles(shoes_app *app)
516
+ {
517
+ app->styles = rb_hash_new();
518
+ STYLE(cBanner, size, 48);
519
+ STYLE(cTitle, size, 34);
520
+ STYLE(cSubtitle, size, 26);
521
+ STYLE(cTagline, size, 18);
522
+ STYLE(cCaption, size, 14);
523
+ STYLE(cPara, size, 12);
524
+ STYLE(cInscription, size, 10);
525
+
526
+ STYLE(cCode, family, monospace);
527
+ STYLE(cDel, strikethrough, single);
528
+ STYLE(cEm, emphasis, italic);
529
+ STYLE(cIns, underline, single);
530
+ STYLE(cLink, underline, single);
531
+ STYLE(cLink, stroke, #06E);
532
+ STYLE(cLinkHover, underline, single);
533
+ STYLE(cLinkHover, stroke, #039);
534
+ STYLE(cStrong, weight, bold);
535
+ STYLE(cSup, rise, 10);
536
+ STYLE(cSup, size, x-small);
537
+ STYLE(cSub, rise, -10);
538
+ STYLE(cSub, size, x-small);
539
+ }
540
+
541
+ void
542
+ shoes_app_style(shoes_app *app, VALUE klass, VALUE hsh)
543
+ {
544
+ long i;
545
+ VALUE keys = rb_funcall(hsh, s_keys, 0);
546
+ for ( i = 0; i < RARRAY_LEN(keys); i++ )
547
+ {
548
+ VALUE key = rb_ary_entry(keys, i);
549
+ VALUE val = rb_hash_aref(hsh, key);
550
+ if (!SYMBOL_P(key)) key = rb_str_intern(key);
551
+ shoes_style_set(app->styles, klass, key, val);
552
+ }
553
+ }
554
+
555
+ VALUE
556
+ shoes_app_close_window(shoes_app *app)
557
+ {
558
+ shoes_native_app_close(app);
559
+ return Qnil;
560
+ }
561
+
562
+ VALUE
563
+ shoes_app_location(VALUE self)
564
+ {
565
+ shoes_app *app;
566
+ Data_Get_Struct(self, shoes_app, app);
567
+ return app->location;
568
+ }
569
+
570
+ VALUE
571
+ shoes_app_is_started(VALUE self)
572
+ {
573
+ shoes_app *app;
574
+ Data_Get_Struct(self, shoes_app, app);
575
+ return app->started ? Qtrue : Qfalse;
576
+ }
577
+
578
+ VALUE
579
+ shoes_app_contents(VALUE self)
580
+ {
581
+ shoes_app *app;
582
+ Data_Get_Struct(self, shoes_app, app);
583
+ return shoes_canvas_contents(app->canvas);
584
+ }
585
+
586
+ VALUE
587
+ shoes_app_quit(VALUE self)
588
+ {
589
+ shoes_native_quit();
590
+ return self;
591
+ }