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,63 @@
1
+ //
2
+ // shoes/world.h
3
+ //
4
+ // The shoes_world struct contains global information about the environment which is shared between
5
+ // app windows.
6
+ //
7
+ #ifndef SHOES_WORLD_H
8
+ #define SHOES_WORLD_H
9
+
10
+ #include "shoes/config.h"
11
+ #include "shoes/ruby.h"
12
+ #include "shoes/code.h"
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ SHOES_EXTERN typedef struct _shoes_world_t {
19
+ SHOES_WORLD_OS os;
20
+ int mainloop;
21
+ char path[SHOES_BUFSIZE];
22
+ VALUE apps, msgs;
23
+ st_table *image_cache;
24
+ guint thread_event;
25
+ cairo_surface_t *blank_image;
26
+ shoes_cached_image *blank_cache;
27
+ PangoFontDescription *default_font;
28
+ #ifdef VLC_0_9
29
+ libvlc_instance_t *vlc;
30
+ #endif
31
+ } shoes_world_t;
32
+
33
+ extern SHOES_EXTERN shoes_world_t *shoes_world;
34
+
35
+ #define GLOBAL_APP(appvar) \
36
+ shoes_app *appvar = NULL; \
37
+ if (RARRAY_LEN(shoes_world->apps) > 0) \
38
+ Data_Get_Struct(rb_ary_entry(shoes_world->apps, 0), shoes_app, appvar)
39
+
40
+ //
41
+ // Shoes World
42
+ //
43
+ SHOES_EXTERN shoes_world_t *shoes_world_alloc(void);
44
+ SHOES_EXTERN void shoes_world_free(shoes_world_t *);
45
+ void shoes_update_fonts(VALUE);
46
+
47
+ //
48
+ // Shoes
49
+ //
50
+ SHOES_EXTERN shoes_code shoes_init(SHOES_INIT_ARGS);
51
+ SHOES_EXTERN shoes_code shoes_load(char *);
52
+ SHOES_EXTERN shoes_code shoes_start(char *, char *);
53
+ #ifdef SHOES_WIN32
54
+ SHOES_EXTERN int shoes_win32_cmdvector(const char *, char ***);
55
+ #endif
56
+ SHOES_EXTERN void shoes_set_argv(int, char **);
57
+ SHOES_EXTERN shoes_code shoes_final(void);
58
+
59
+ #ifdef __cplusplus
60
+ }
61
+ #endif
62
+
63
+ #endif
Binary file
Binary file
@@ -0,0 +1,188 @@
1
+ /* Unobtrustive Code Highlighter By Dan Webb 11/2005
2
+ Version: 0.4
3
+
4
+ Usage:
5
+ Add a script tag for this script and any stylesets you need to use
6
+ to the page in question, add correct class names to CODE elements,
7
+ define CSS styles for elements. That's it!
8
+
9
+ Known to work on:
10
+ IE 5.5+ PC
11
+ Firefox/Mozilla PC/Mac
12
+ Opera 7.23 + PC
13
+ Safari 2
14
+
15
+ Known to degrade gracefully on:
16
+ IE5.0 PC
17
+
18
+ Note: IE5.0 fails due to the use of lookahead in some stylesets. To avoid script errors
19
+ in older browsers use expressions that use lookahead in string format when defining stylesets.
20
+
21
+ This script is inspired by star-light by entirely cunning Dean Edwards
22
+ http://dean.edwards.name/star-light/.
23
+ */
24
+
25
+ // replace callback support for safari.
26
+ if ("a".replace(/a/, function() {return "b"}) != "b") (function(){
27
+ var default_replace = String.prototype.replace;
28
+ String.prototype.replace = function(search,replace){
29
+ // replace is not function
30
+ if(typeof replace != "function"){
31
+ return default_replace.apply(this,arguments)
32
+ }
33
+ var str = "" + this;
34
+ var callback = replace;
35
+ // search string is not RegExp
36
+ if(!(search instanceof RegExp)){
37
+ var idx = str.indexOf(search);
38
+ return (
39
+ idx == -1 ? str :
40
+ default_replace.apply(str,[search,callback(search, idx, str)])
41
+ )
42
+ }
43
+ var reg = search;
44
+ var result = [];
45
+ var lastidx = reg.lastIndex;
46
+ var re;
47
+ while((re = reg.exec(str)) != null){
48
+ var idx = re.index;
49
+ var args = re.concat(idx, str);
50
+ result.push(
51
+ str.slice(lastidx,idx),
52
+ callback.apply(null,args).toString()
53
+ );
54
+ if(!reg.global){
55
+ lastidx += RegExp.lastMatch.length;
56
+ break
57
+ }else{
58
+ lastidx = reg.lastIndex;
59
+ }
60
+ }
61
+ result.push(str.slice(lastidx));
62
+ return result.join("")
63
+ }
64
+ })();
65
+
66
+ var CodeHighlighter = { styleSets : new Array };
67
+
68
+ CodeHighlighter.addStyle = function(name, rules) {
69
+ // using push test to disallow older browsers from adding styleSets
70
+ if ([].push) this.styleSets.push({
71
+ name : name,
72
+ rules : rules,
73
+ ignoreCase : arguments[2] || false
74
+ })
75
+
76
+ function setEvent() {
77
+ // set highlighter to run on load (use LowPro if present)
78
+ if (typeof Event != 'undefined' && typeof Event.onReady == 'function')
79
+ return Event.onReady(CodeHighlighter.init.bind(CodeHighlighter));
80
+
81
+ var old = window.onload;
82
+
83
+ if (typeof window.onload != 'function') {
84
+ window.onload = function() { CodeHighlighter.init() };
85
+ } else {
86
+ window.onload = function() {
87
+ old();
88
+ CodeHighlighter.init();
89
+ }
90
+ }
91
+ }
92
+
93
+ // only set the event when the first style is added
94
+ if (this.styleSets.length==1) setEvent();
95
+ }
96
+
97
+ CodeHighlighter.init = function() {
98
+ if (!document.getElementsByTagName) return;
99
+ if ("a".replace(/a/, function() {return "b"}) != "b") return; // throw out Safari versions that don't support replace function
100
+ // throw out older browsers
101
+
102
+ var codeEls = document.getElementsByTagName("CODE");
103
+ // collect array of all pre elements
104
+ codeEls.filter = function(f) {
105
+ var a = new Array;
106
+ for (var i = 0; i < this.length; i++) if (f(this[i])) a[a.length] = this[i];
107
+ return a;
108
+ }
109
+
110
+ var rules = new Array;
111
+ rules.toString = function() {
112
+ // joins regexes into one big parallel regex
113
+ var exps = new Array;
114
+ for (var i = 0; i < this.length; i++) exps.push(this[i].exp);
115
+ return exps.join("|");
116
+ }
117
+
118
+ function addRule(className, rule) {
119
+ // add a replace rule
120
+ var exp = (typeof rule.exp != "string")?String(rule.exp).substr(1, String(rule.exp).length-2):rule.exp;
121
+ // converts regex rules to strings and chops of the slashes
122
+ rules.push({
123
+ className : className,
124
+ exp : "(" + exp + ")",
125
+ length : (exp.match(/(^|[^\\])\([^?]/g) || "").length + 1, // number of subexps in rule
126
+ replacement : rule.replacement || null
127
+ });
128
+ }
129
+
130
+ function parse(text, ignoreCase) {
131
+ // main text parsing and replacement
132
+ return text.replace(new RegExp(rules, (ignoreCase)?"gi":"g"), function() {
133
+ var i = 0, j = 1, rule;
134
+ while (rule = rules[i++]) {
135
+ if (arguments[j]) {
136
+ // if no custom replacement defined do the simple replacement
137
+ if (!rule.replacement) return "<span class=\"" + rule.className + "\">" + arguments[0] + "</span>";
138
+ else {
139
+ // replace $0 with the className then do normal replaces
140
+ var str = rule.replacement.replace("$0", rule.className);
141
+ for (var k = 1; k <= rule.length - 1; k++) str = str.replace("$" + k, arguments[j + k]);
142
+ return str;
143
+ }
144
+ } else j+= rule.length;
145
+ }
146
+ });
147
+ }
148
+
149
+ function highlightCode(styleSet) {
150
+ // clear rules array
151
+ var parsed, clsRx = new RegExp("(\\s|^)" + styleSet.name + "(\\s|$)");
152
+ rules.length = 0;
153
+
154
+ // get stylable elements by filtering out all code elements without the correct className
155
+ var stylableEls = codeEls.filter(function(item) { return clsRx.test(item.className) });
156
+
157
+ // add style rules to parser
158
+ for (var className in styleSet.rules) addRule(className, styleSet.rules[className]);
159
+
160
+
161
+ // replace for all elements
162
+ for (var i = 0; i < stylableEls.length; i++) {
163
+ // EVIL hack to fix IE whitespace badness if it's inside a <pre>
164
+ if (/MSIE/.test(navigator.appVersion) && stylableEls[i].parentNode.nodeName == 'PRE') {
165
+ stylableEls[i] = stylableEls[i].parentNode;
166
+
167
+ parsed = stylableEls[i].innerHTML.replace(/(<code[^>]*>)([^<]*)<\/code>/i, function() {
168
+ return arguments[1] + parse(arguments[2], styleSet.ignoreCase) + "</code>"
169
+ });
170
+ parsed = parsed.replace(/\n( *)/g, function() {
171
+ var spaces = "";
172
+ for (var i = 0; i < arguments[1].length; i++) spaces+= "&nbsp;";
173
+ return "\n" + spaces;
174
+ });
175
+ parsed = parsed.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");
176
+ parsed = parsed.replace(/\n(<\/\w+>)?/g, "<br />$1").replace(/<br \/>[\n\r\s]*<br \/>/g, "<p><br></p>");
177
+
178
+ } else parsed = parse(stylableEls[i].innerHTML, styleSet.ignoreCase);
179
+
180
+ stylableEls[i].innerHTML = parsed;
181
+ }
182
+ }
183
+
184
+ // run highlighter on all stylesets
185
+ for (var i=0; i < this.styleSets.length; i++) {
186
+ highlightCode(this.styleSets[i]);
187
+ }
188
+ }
@@ -0,0 +1,26 @@
1
+ CodeHighlighter.addStyle("rb",{
2
+ comment : {
3
+ exp : /#[^\n]+/
4
+ },
5
+ brackets : {
6
+ exp : /\(|\)|\{|\}/
7
+ },
8
+ string : {
9
+ exp : /'[^']*'|"[^"]*"/
10
+ },
11
+ keywords : {
12
+ exp : /\b(do|end|self|class|def|if|module|yield|then|else|for|until|unless|while|elsif|case|when|break|retry|redo|rescue|raise)\b/
13
+ },
14
+ constant : {
15
+ exp : /\b([A-Z]\w+)\b/
16
+ },
17
+ ivar : {
18
+ exp : /([^@])(@{1,2}\w+)\b/
19
+ },
20
+ ns : {
21
+ exp : /(:{2,})/
22
+ },
23
+ symbol : {
24
+ exp : /(:[A-Za-z0-9_!?]+)/
25
+ }
26
+ });
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,3531 @@
1
+ = Hello! =
2
+
3
+ Shoes is a tiny graphics toolkit. It's simple and straightforward. Shoes was
4
+ born to be easy! Really, it was made for absolute beginners. There's really
5
+ nothing to it.
6
+
7
+ You see, the trivial Shoes program can be just one line:
8
+
9
+ {{{
10
+ #!ruby
11
+ Shoes.app { button("Click me!") { alert("Good job.") } }
12
+ }}}
13
+
14
+ Shoes programs are written in a language called Ruby. When Shoes is handed
15
+ this simple line of Ruby code, a window appears with a button inside reading
16
+ "Click me!" When the button is clicked, a message pops up.
17
+
18
+ On Linux, here's how this might look: !{:margin_left => 100}man-shot1.png!
19
+
20
+ While lots of Shoes apps are graphical games and art programs, you can also
21
+ layout text and edit controls easily. !{:margin_left =>
22
+ 40}shoes-manual-apps.gif!
23
+
24
+ And, ideally, Shoes programs will run on any of the major platforms out there.
25
+ Microsoft Windows, Apple's Mac OS X, Linux and many others.
26
+
27
+ ^So, welcome to Shoes' built-in manual. This manual is a Shoes program itself!^
28
+
29
+ == Introducing Shoes ==
30
+
31
+ How does Shoes look on OS X and Windows? Does it really look okay? Is it all
32
+ ugly and awkward? People must immediately convulse! It must be so watered down
33
+ trying to do everything.
34
+
35
+ Well, before getting into the stuff about installing and running Shoes, time to
36
+ just check out some screenshots, to give you an idea of what you can do.
37
+
38
+ ==== Mac OS X ====
39
+
40
+ Shoes runs on Apple Mac OS X Leopard, as well as Tiger. Shoes supports PowerPC
41
+ machines as well, however, there is no video support on that platform.
42
+ !man-look-tiger.png!
43
+
44
+ This is the `simple-sphere.rb` sample running on Tiger. Notice that the app
45
+ runs inside a normal OS X window border.
46
+
47
+ The whole sphere is drawn with blurred ovals and shadows. You can draw and
48
+ animate shapes and apply effects to those shapes in Shoes.
49
+
50
+ ==== Windows ====
51
+
52
+ Shoes runs on all versions of '''Microsoft Windows XP''', '''Windows Vista''',
53
+ '''Windows 7''', and anything else '''Windows 2000''' compatible.
54
+ !man-look-vista.png!
55
+
56
+ Above is pictured the `simple-clock.rb` sample running on Windows Vista. This
57
+ example is also draws ovals and lines to build the clock, which is animated to
58
+ repaint itself several times each second.
59
+
60
+ Notice the text on the top of the app, showing the current time. Shoes has the
61
+ skills to layout words using any color, bold, italics, underlines, and supports
62
+ loading fonts from a file.
63
+
64
+ ==== Linux ====
65
+
66
+ Here's a screenshot of the `simple-downloader.rb` sample running on '''Ubuntu
67
+ Linux'''. !man-look-ubuntu.png!
68
+
69
+ Notice the buttons and progress bars. These types of controls look different on
70
+ OS X and Windows. The text and links would look the same, though.
71
+
72
+ Shapes, text, images and videos all look the same on every platforms. However,
73
+ native controls (like edit lines and edit boxes) will match the look of the
74
+ window theme. Shoes will try to keep native controls all within the size you
75
+ give them, only the look will vary.
76
+
77
+ == Installing Shoes ==
78
+
79
+ Okay, on to installing Shoes. I'm sure you're wondering: do I need to install
80
+ Ruby? Do I need to unzip anything? What commands do I need to type?
81
+
82
+ Nope. You don't need Ruby. You don't need WinZip. Nothing to type.
83
+
84
+ On most systems, starting Shoes is just a matter of running the installer and
85
+ clicking the Shoes icon. Shoes comes with everything built in. We'll talk
86
+ through all the steps, though, just to be clear about it.
87
+
88
+ ==== Step 1: Installing Shoes ====
89
+
90
+ You'll want to visit [[http://shoesrb.com/ the site of Shoes]] to download
91
+ the Shoes installer. Usually, you'll just want one of the installers on the
92
+ downloads page of the site. !man-builds1.png!
93
+
94
+ Here's how to run the installer:
95
+
96
+ * On '''Mac OS X''', you'll have a file ending with '''.dmg'''. Double-click this file and a window should appear with a '''Shoes''' icon and an '''Applications''' folder. Following the arrow, drag the Shoes icon into the '''Applications''' folder. !man-intro-dmg.png!
97
+ * On '''Windows''', you'll download a '''.exe''' file. Double-click this file and follow the instructions. !man-intro-exe.png!
98
+ * On '''Linux''', you'll download a file ending with '''.run'''. Double-click this file and Shoes will start up. (You can also run this file from a prompt as if it was a shell script. In fact, it is a shell script!)
99
+
100
+ ==== Step 2: Start a New Text File ====
101
+
102
+ Shoes programs are just plain text files ending with a '''.rb''' extension.
103
+
104
+ Here are a few ways to create a blank text file:
105
+
106
+ * On '''Mac OS X''', visit your '''Applications''' folder and double-click on the '''TextEdit''' app. A blank editor window should come up. Now, go to the '''Format''' menu and select the '''Make Plain Text''' option. Okay, you're all set! !man-editor-osx.png!
107
+ * On '''Windows''', go to the Start menu. Select '''All Programs''', then '''Accessories''', then '''Notepad'''. !man-editor-notepad.png!
108
+ * On '''Linux''', most distros come with '''gedit'''. You might try running that. Or, if your distro is KDE-based, run '''kate'''.
109
+
110
+ Now, in your blank window, type in the following:
111
+
112
+ {{{
113
+ Shoes.app do
114
+ background "#DFA"
115
+ para "Welcome to Shoes"
116
+ end
117
+ }}}
118
+
119
+ Save to your desktop as `welcome.rb`.
120
+
121
+ ==== Step 3: Run It! Go Shoes! ====
122
+
123
+ To run your program:
124
+
125
+ * On '''Mac OS X''', visit your '''Applications''' folder again. This time, double-click the '''Shoes''' icon in that folder. You should see the red shoes icon appear in the dock. Drag your `welcome.rb` from the desktop on to that dock icon. !man-run-osx.png!
126
+ * On '''Windows''', get to the Start menu. Go into '''All Programs''', then '''Shoes''', then '''Shoes'''. A file selector box should come up. Browse to your desktop and select `welcome.rb`. Click '''OK''' and you're on your way. !man-run-xp.png! !man-run-vista.png!
127
+ * On '''Linux''', run Shoes just like you did in step one. You should see a file selector box. Browse to your desktop, select `welcome.rb` and hit '''OK'''.
128
+
129
+ So, not much of a program yet. But it's something! You've got the knack of it, at least!
130
+
131
+ ==== What Can You Make With Shoes? ====
132
+
133
+ Well, you can make windowing applications. But Shoes is inspired by the web, so
134
+ applications tend to use images and text layout rather than a lot of widgets.
135
+ For example, Shoes doesn't come with tabbed controls or toolbars. Shoes is a
136
+ ''tiny'' toolkit, remember?
137
+
138
+ Still, Shoes does have a few widgets like buttons and edit boxes. And many
139
+ missing elements (like tabbed controls or toolbars) can be simulated with
140
+ images.
141
+
142
+ Shoes is written in part thanks to a very good art engine called Cairo, which
143
+ is used for drawing with shapes and colors. In this way, Shoes is inspired by
144
+ NodeBox and Processing, two very good languages for drawing animated graphics.
145
+
146
+ == The Rules of Shoes ==
147
+
148
+ Time to stop guessing how Shoes works. Some of the tricky things will come
149
+ back to haunt you. I've boiled down the central rules to Shoes. These are the
150
+ things you MUST know to really make it all work.
151
+
152
+ These are general rules found throughout Shoes. While Shoes has an overall
153
+ philosophy of simplicity and clarity, there are a few points that need to be
154
+ studied and remembered.
155
+
156
+ ==== Shoes Tricky Blocks ====
157
+
158
+ Okay, this is absolutely crucial. Shoes does a trick with blocks. This trick
159
+ makes everything easier to read. But it also can make blocks harder to use
160
+ once you're in deep.
161
+
162
+ '''Let's take a normal Ruby block:'''
163
+
164
+ {{{
165
+ ary = ['potion', 'swords', 'shields']
166
+ ary.each do |item|
167
+ puts item
168
+ end
169
+ }}}
170
+
171
+ In Shoes, these sorts of blocks work the same. This block above loops through
172
+ the array and stores each object in the `item` variable. The `item` variable
173
+ disappears (goes out of scope) when the block ends.
174
+
175
+ One other thing to keep in mind is that `self` stays the same inside normal
176
+ Ruby blocks. Whatever `self` was before the call to `each`, it is the same
177
+ inside the `each` block.
178
+
179
+ '''Both of these things are also true for most Shoes blocks.'''
180
+
181
+ {{{
182
+ Shoes.app do
183
+ stack do
184
+ para "First"
185
+ para "Second"
186
+ para "Third"
187
+ end
188
+ end
189
+ }}}
190
+
191
+ Here we have two blocks. The first block is sent to `Shoes.app`. This `app`
192
+ block changes `self`.
193
+
194
+ The other block is the `stack` block. That block does NOT change self.
195
+
196
+ '''For what reason does the `app` block change self?''' Let's start by
197
+ spelling out that last example completely.
198
+
199
+ {{{
200
+ Shoes.app do
201
+ self.stack do
202
+ self.para "First"
203
+ self.para "Second"
204
+ self.para "Third"
205
+ end
206
+ end
207
+ }}}
208
+
209
+ All of the `self`s in the above example are the App object. Shoes uses Ruby's
210
+ `instance_eval` to change self inside the `app` block. So the method calls to
211
+ `stack` and `para` get sent to the app.
212
+
213
+ '''This also is why you can use instance variables throughout a Shoes app:'''
214
+
215
+ {{{
216
+ Shoes.app do
217
+ @s = stack do
218
+ @p1 = para "First"
219
+ @p2 = para "Second"
220
+ @p3 = para "Third"
221
+ end
222
+ end
223
+ }}}
224
+
225
+ These instance variables will all end up inside the App object.
226
+
227
+ '''Whenever you create a new window, `self` is also changed.''' So, this means
228
+ the [[Element.window]] and [[Element.dialog]] methods, in addition to
229
+ Shoes.app.
230
+
231
+ {{{
232
+ Shoes.app :title => "MAIN" do
233
+ para self
234
+ button "Spawn" do
235
+ window :title => "CHILD" do
236
+ para self
237
+ end
238
+ end
239
+ end
240
+ }}}
241
+
242
+ ==== Block Redirection ====
243
+
244
+ The `stack` block is a different story, though. It doesn't change `self` and
245
+ it's basically a regular block.
246
+
247
+ '''But there's a trick:''' when you attach a `stack` and give it a block, the
248
+ App object places that stack in its memory. The stack gets popped off when the
249
+ block ends. So all drawing inside the block gets '''redirected''' from the
250
+ App's top slot to the new stack.
251
+
252
+ So those three `para`s will get drawn on the `stack`, even though they actually
253
+ get sent to the App object first.
254
+
255
+ {{{
256
+ Shoes.app do
257
+ stack do
258
+ para "First"
259
+ para "Second"
260
+ para "Third"
261
+ end
262
+ end
263
+ }}}
264
+
265
+ A bit tricky, you see? This can bite you even if you know about it.
266
+
267
+ One way it'll get you is if you try to edit a stack somewhere else in your
268
+ program, outside the `app` block.
269
+
270
+ Like let's say you pass around a stack object. And you have a class that edits
271
+ that object.
272
+
273
+ {{{
274
+ class Messenger
275
+ def initialize(stack)
276
+ @stack = stack
277
+ end
278
+ def add(msg)
279
+ @stack.append do
280
+ para msg
281
+ end
282
+ end
283
+ end
284
+ }}}
285
+
286
+ So, let's assume you pass the stack object into your Messenger class when the
287
+ app starts. And, later, when a message comes in, the `add` method gets used to
288
+ append a paragraph to that stack. Should work, right?
289
+
290
+ Nope, it won't work. The `para` method won't be found. The App object isn't
291
+ around any more. And it's the one with the `para` method.
292
+
293
+ Fortunately, each Shoes object has an `app` method that will let you reopen the
294
+ App object so you can do somefurther editing.
295
+
296
+ {{{
297
+ class Messenger
298
+ def initialize(stack)
299
+ @stack = stack
300
+ end
301
+ def add(msg)
302
+ @stack.app do
303
+ @stack.append do
304
+ para msg
305
+ end
306
+ end
307
+ end
308
+ end
309
+ }}}
310
+
311
+ As you can imagine, the `app` object changes `self` to the App object.
312
+
313
+ So the rules here are:
314
+
315
+ 1. '''Methods named "app" or which create new windows alter `self` to the App
316
+ object.'''[[BR]](This is true for both Shoes.app and Slot.app, as well as
317
+ [[Element.window]] and [[Element.dialog]].)[[BR]]
318
+ 2. '''Blocks attached to stacks, flows or any manipulation method (such as
319
+ append) do not change self. Instead, they pop the slot on to the app's editing
320
+ stack.'''
321
+
322
+ ==== Careful With Fixed Heights ====
323
+
324
+ Fixed widths on slots are great so you can split the window into columns.
325
+
326
+ {{{
327
+ Shoes.app do
328
+ flow do
329
+ stack :width => 200 do
330
+ caption "Column one"
331
+ para "is 200 pixels wide"
332
+ end
333
+ stack :width => -200 do
334
+ caption "Column two"
335
+ para "is 100% minus 200 pixels wide"
336
+ end
337
+ end
338
+ end
339
+ }}}
340
+
341
+ Fixed heights on slots should be less common. Usually you want your text and
342
+ images to just flow down the window as far as they can. Height usually happens
343
+ naturally.
344
+
345
+ The important thing here is that fixed heights actually force slots to behave
346
+ differently. To be sure that the end of the slot is chopped off perfectly, the
347
+ slot becomes a '''nested window'''. A new layer is created by the operating
348
+ system to keep the slot in a fixed square.
349
+
350
+ On difference between normal slots and nested window slots is that the latter
351
+ can have scrollbars.
352
+
353
+ {{{
354
+ Shoes.app do
355
+ stack :width => 200, :height => 200, :scroll => true do
356
+ background "#DFA"
357
+ 100.times do |i|
358
+ para "Paragraph No. #{i}"
359
+ end
360
+ end
361
+ end
362
+ }}}
363
+
364
+ These nested windows require more memory. They tax the application a bit more.
365
+ So if you're experiencing some slowness with hundreds of fixed-height slots,
366
+ try a different approach.
367
+
368
+ ==== Image and Shape Blocks ====
369
+
370
+ Most beginners start littering the window with shapes. It's just easier to
371
+ throw all your rectangles and ovals in a slot.
372
+
373
+ '''However, bear in mind that Shoes will create objects for all those
374
+ shapes!'''
375
+
376
+ {{{
377
+ Shoes.app do
378
+ fill black(0.1)
379
+ 100.times do |i|
380
+ oval i, i, i * 2
381
+ end
382
+ end
383
+ }}}
384
+
385
+ In this example, one-hundred Oval objects are created. This isn't too bad.
386
+ But things would be slimmer if we made these into a single shape.
387
+
388
+ {{{
389
+ Shoes.app do
390
+ fill black(0.1)
391
+ shape do
392
+ 100.times do |i|
393
+ oval i, i, i * 2
394
+ end
395
+ end
396
+ end
397
+ }}}
398
+
399
+ Oh, wait. The ovals aren't filled in this time! That's because the ovals have
400
+ been combined into a single huge shape. And Shoes isn't sure where to fill in
401
+ this case.
402
+
403
+ So you usually only want to combine into a single shape when you're dealing
404
+ strictly with outlines.
405
+
406
+ Another option is to combine all those ovals into a single image.
407
+
408
+ {{{
409
+ Shoes.app do
410
+ fill black(0.1)
411
+ image 300, 300 do
412
+ 100.times do |i|
413
+ oval i, i, i * 2
414
+ end
415
+ end
416
+ end
417
+ }}}
418
+
419
+ There we go! The ovals are all combined into a single 300 x 300 pixel image.
420
+ In this case, storing that image in memory might be much bigger than having
421
+ one-hundred ovals around. But when you're dealing with thousands of shapes,
422
+ the image block can be cheaper.
423
+
424
+ The point is: it's easy to group shapes together into image or shape blocks, so
425
+ give it a try if you're looking to gain some speed. Shape blocks particularly
426
+ will save you some memory and speed.
427
+
428
+ ==== UTF-8 Everywhere ====
429
+
430
+ Ruby itself isn't Unicode aware. And UTF-8 is a type of Unicode. (See
431
+ [[http://en.wikipedia.org/wiki/UTF-8 Wikipedia]] for a full explanation of
432
+ UTF-8.)
433
+
434
+ However, UTF-8 is common on the web. And lots of different platforms support
435
+ it. So to cut down on the amount of conversion that Shoes has to do, Shoes
436
+ expects all strings to be in UTF-8 format.
437
+
438
+ This is great because you can show a myriad of languages (Russian, Japanese,
439
+ Spanish, English) using UTF-8 in Shoes. Just be sure that your text editor
440
+ uses UTF-8!
441
+
442
+ To illustrate:
443
+
444
+ {{{
445
+ Shoes.app do
446
+ stack :margin => 10 do
447
+ @edit = edit_box :width => 1.0 do
448
+ @para.text = @edit.text
449
+ end
450
+ @para = para ""
451
+ end
452
+ end
453
+ }}}
454
+
455
+ This app will copy anything you paste into the edit box and display it in a
456
+ Shoes paragraph. You can try copying some foreign text (such as Greek or
457
+ Japanese) into this box to see how it displays.
458
+
459
+ This is a good test because it proves that the edit box gives back UTF-8
460
+ characters. And the paragraph can be set to any UTF-8 characters.
461
+
462
+ '''Important note:''' if some UTF-8 characters don't display for you, you will
463
+ need to change the paragraph's font. This is especially common on OS X.
464
+
465
+ So, a good Japanese font on OS X is '''AppleGothic''' and on Windows is '''MS
466
+ UI Gothic'''.
467
+
468
+ {{{
469
+ Shoes.app do
470
+ para "てすと (te-su-to)", :font => case RUBY_PLATFORM
471
+ when /mingw/; "MS UI Gothic"
472
+ when /darwin/; "AppleGothic, Arial"
473
+ else "Arial"
474
+ end
475
+ end
476
+ }}}
477
+
478
+ Again, anything which takes a string in Shoes will need a UTF-8 string. Edit
479
+ boxes, edit lines, list boxes, window titles and text blocks all take UTF-8. If
480
+ you give a string with bad characters in it, an error will show up in the
481
+ console.
482
+
483
+ ==== The Main App and Its Requires ====
484
+
485
+ '''NOTE:''' This rule is for Raisins. Policeman uses TOPLEVEL_BINDING. So, you
486
+ can get `main`, Ruby top-level object, with the first snippet. Although you
487
+ need to use `Shoes::Para` instead of `Para` outside `Shoes.app` block.
488
+
489
+ Each Shoes app is given a little room where it can create itself. You can
490
+ create classes and set variables and they won't be seen by other Shoes
491
+ programs. Each program runs inside its own anonymous class.
492
+
493
+ {{{
494
+ main = self
495
+ Shoes.app do
496
+ para main.to_s
497
+ end
498
+ }}}
499
+
500
+ This anonymous class is called `(shoes)` and it's just an empty, unnamed class.
501
+ The `Shoes` module is mixed into this class (using `include Shoes`) so that you
502
+ can use either `Para` or `Shoes::Para` when referring to the paragraph class.
503
+
504
+ The advantages of this approach are:
505
+
506
+ * Shoes apps cannot share local variables.
507
+ * Classes created in the main app code are temporary.
508
+ * The Shoes module can be mixed in to the anonymous class, but not the top-level environment of Ruby itself.
509
+ * Garbage collection can clean up apps entirely once they complete.
510
+
511
+ The second part is especially important to remember.
512
+
513
+ {{{
514
+ class Storage; end
515
+
516
+ Shoes.app do
517
+ para Storage.new
518
+ end
519
+ }}}
520
+
521
+ The `Storage` class will disappear once the app completes. Other apps aren't
522
+ able to use the Storage class. And it can't be gotten to from files that are
523
+ loaded using `require`.
524
+
525
+ When you `require` code, though, that code will stick around. It will be kept
526
+ in the Ruby top-level environment.
527
+
528
+ So, the rule is: '''keep your temporary classes in the code with the app and
529
+ keep your permanent classes in requires.'''
530
+
531
+ = Shoes =
532
+
533
+ Shoes is all about drawing windows and the stuff inside those windows. Let's
534
+ focus on the window itself, for now. The other sections [[Slots]] and
535
+ [[Elements]] cover everything that goes inside the window.
536
+
537
+ For here on, the manual reads more like a dictionary. Each page is mostly a
538
+ list of methods you can use for each topic covered. The idea is to be very
539
+ thorough and clear about everything.
540
+
541
+ So, if you've hit this far in the manual and you're still hazy about getting
542
+ started, you should probably either go back to the [[Hello! beginning]] of the
543
+ manual. Or you could try [[https://github.com/downloads/shoes/shoes/nks.pdf Nobody Knows
544
+ Shoes]], the beginner's leaflet PDF.
545
+
546
+ ==== Finding Your Way ====
547
+
548
+ This section covers:
549
+
550
+ * [[Built-in Built-in methods]] - general methods available anywhere in a Shoes program.
551
+ * [[App The App window]] - methods found attached to every main Shoes window.
552
+ * [[Styles The Styles Master List]] - a complete list of every style in Shoes.
553
+ * [[Classes The Classes list]] - a chart showing what Shoes classes subclass what.
554
+ * [[Colors The Colors list]] - a chart of all built-in colors and the [[Built-in.rgb]] numbers for each.
555
+
556
+ If you find yourself paging around a lot and not finding something, give the
557
+ [[Search]] page a try. It's the quickest way to get around.
558
+
559
+ After this general reference, there are two other more specific sections:
560
+
561
+ * [[Slots]] - covering [[Element.stack]] and [[Element.flow]], the two types of slots.
562
+ * [[Elements]] - documentation for all the buttons, shapes, images, and so on.
563
+
564
+ Two really important pages in there are the [[Element Element Creation]] page
565
+ (which lists all the elements you can add) and the [[Common Common Methods]]
566
+ page (which lists methods you'll find on any slot or element.)
567
+
568
+ == Built-in Methods ==
569
+
570
+ These methods can be used anywhere throughout Shoes programs.
571
+
572
+ All of these commands are unusual because you don't attach them with a dot.
573
+ '''Every other method in this manual must be attached to an object with a dot.'''
574
+ But these are built-in methods (also called: Kernel methods.) Which means no dot!
575
+
576
+ A common one is `alert`:
577
+
578
+ {{{
579
+ #!ruby
580
+ alert "No dots in sight"
581
+ }}}
582
+
583
+ Compare that to the method `reverse`, which isn't a Kernel method and is only
584
+ available for Arrays and Strings:
585
+
586
+ {{{
587
+ #!ruby
588
+ "Plaster of Paris".reverse
589
+ #=> "siraP fo retsalP"
590
+ [:dogs, :cows, :snakes].reverse
591
+ #=> [:snakes, :cows, :dogs]
592
+ }}}
593
+
594
+ Most Shoes methods for drawing and making buttons and so on are attached to
595
+ slots. See the section on [[Slots]] for more.
596
+
597
+ ==== Built-in Constants ====
598
+
599
+ Shoes also has a handful of built-in constants which may prove useful if you
600
+ are trying to sniff out what release of Shoes is running.
601
+
602
+ '''Shoes::RELEASE_NAME''' contains a string with the name of the Shoes release.
603
+ All Shoes releases are named, starting with Curious.
604
+
605
+ '''Shoes::RELEASE_ID''' contains a number representing the Shoes release. So,
606
+ for example, Curious is number 1, as it was the first official release.
607
+
608
+ '''Shoes::REVISION''' is the Subversion revision number for this build.
609
+
610
+ '''Shoes::FONTS''' is a complete list of fonts available to the app. This list
611
+ includes any fonts loaded by the [[Built-in.font]] method.
612
+
613
+ === alert(message: a string) » nil ===
614
+
615
+ Pops up a window containing a short message.
616
+
617
+ {{{
618
+ #!ruby
619
+ alert("I'm afraid I must interject!")
620
+ }}}
621
+
622
+ Please use alerts sparingly, as they are incredibly annoying! If you are using
623
+ alerts to show messages to help you debug your program, try checking out the
624
+ [[Built-in.debug]] or [[Built-in.info]] methods.
625
+
626
+ === ask(message: a string) » a string ===
627
+
628
+ Pops up a window and asks a question. For example, you may want to ask someone
629
+ their name.
630
+
631
+ {{{
632
+ #!ruby
633
+ name = ask("Please, enter your name:")
634
+ }}}
635
+
636
+ When the above script is run, the person at the computer will see a window with
637
+ a blank box for entering their name. The name will then be saved in the `name`
638
+ variable.
639
+
640
+ === ask_color(title: a string) » Shoes::Color ===
641
+
642
+ Pops up a color picker window. The program will wait for a color to be picked,
643
+ then gives you back a Color object. See the `Color` help for some ways you can
644
+ use this color.
645
+
646
+ {{{
647
+ #!ruby
648
+ backcolor = ask_color("Pick a background")
649
+ Shoes.app do
650
+ background backcolor
651
+ end
652
+ }}}
653
+
654
+ === ask_open_file() » a string ===
655
+
656
+ Pops up an "Open file..." window. It's the standard window which shows all of
657
+ your folders and lets you select a file to open. Hands you back the name of the
658
+ file.
659
+
660
+ {{{
661
+ #!ruby
662
+ filename = ask_open_file
663
+ Shoes.app do
664
+ para File.read(filename)
665
+ end
666
+ }}}
667
+
668
+ === ask_save_file() » a string ===
669
+
670
+ Pops up a "Save file..." window, similiar to `ask_open_file`, described
671
+ previously.
672
+
673
+ {{{
674
+ #!ruby
675
+ save_as = ask_save_file
676
+ }}}
677
+
678
+ === ask_open_folder() » a string ===
679
+
680
+ Pops up an "Open folder..." window. It's the standard window which shows all of
681
+ your folders and lets you select a folder to open. Hands you back the name of
682
+ the folder.
683
+
684
+ {{{
685
+ #!ruby
686
+ folder = ask_open_folder
687
+ Shoes.app do
688
+ para Dir.entries(folder)
689
+ end
690
+ }}}
691
+
692
+ === ask_save_folder() » a string ===
693
+
694
+ Pops up a "Save folder..." window, similiar to `ask_open_folder`, described
695
+ previously. On OS X, this method currently behaves like an alias of
696
+ `ask_open_folder`.
697
+
698
+ {{{
699
+ #!ruby
700
+ save_to = ask_save_folder
701
+ }}}
702
+
703
+
704
+ === confirm(question: a string) » true or false ===
705
+
706
+ Pops up a yes-or-no question. If the person at the computer, clicks '''yes''',
707
+ you'll get back a `true`. If not, you'll get back `false`.
708
+
709
+ {{{
710
+ #!ruby
711
+ if confirm("Draw a circle?")
712
+ Shoes.app{ oval :top => 0, :left => 0, :radius => 50 }
713
+ end
714
+ }}}
715
+
716
+ === debug(message: a string) » nil ===
717
+
718
+ Sends a debug message to the Shoes console. You can bring up the Shoes console
719
+ by pressing `Alt-/` on any Shoes window (or `⌘-/` on OS X.)
720
+
721
+ {{{
722
+ #!ruby
723
+ debug("Running Shoes on " + RUBY_PLATFORM)
724
+ }}}
725
+
726
+ Also check out the [[Built-in.error]], [[Built-in.warn]] and [[Built-in.info]]
727
+ methods.
728
+
729
+ === error(message: a string) » nil ===
730
+
731
+ Sends an error message to the Shoes console. This method should only be used
732
+ to log errors. Try the [[Built-in.debug]] method for logging messages to
733
+ yourself.
734
+
735
+ Oh, and, rather than a string, you may also hand exceptions directly to this
736
+ method and they'll be formatted appropriately.
737
+
738
+ === exit() ===
739
+
740
+ Stops your program. Call this anytime you want to suddenly call it quits.
741
+
742
+ '''PLEASE NOTE:''' If you need to use Ruby's own `exit` method (like in a
743
+ forked Ruby process,) call `Kernel.exit`.
744
+
745
+ === font(message: a string) » an array of font family names ===
746
+
747
+ Loads a TrueType (or other type of font) from a file. While TrueType is
748
+ supported by all platforms, your platform may support other types of fonts.
749
+ Shoes uses each operating system's built-in font system to make this work.
750
+
751
+ Here's a rough idea of what fonts work on which platforms:
752
+
753
+ * Bitmap fonts (.bdf, .pcf, .snf) - Linux
754
+ * Font resource (.fon) - Windows
755
+ * Windows bitmap font file (.fnt) - Linux, Windows
756
+ * PostScript OpenType font (.otf) - Mac OS X, Linux, Windows
757
+ * Type1 multiple master (.mmm) - Windows
758
+ * Type1 font bits (.pfb) - Linux, Windows
759
+ * Type1 font metrics (.pfm) - Linux, Windows
760
+ * TrueType font (.ttf) - Mac OS X, Linux, Windows
761
+ * TrueType collection (.ttc) - Mac OS X, Linux, Windows
762
+
763
+ If the font is properly loaded, you'll get back an array of font names found in
764
+ the file. Otherwise, `nil` is returned if no fonts were found in the file.
765
+
766
+ Also of interest: the `Shoes::FONTS` constant is a complete list of fonts
767
+ available to you on this platform. You can check for a certain font by using
768
+ `include?`.
769
+
770
+ {{{
771
+ if Shoes::FONTS.include? "Helvetica"
772
+ alert "Helvetica is available on this system."
773
+ else
774
+ alert "You do not have the Helvetica font."
775
+ end
776
+ }}}
777
+
778
+ If you have trouble with fonts showing up, make sure your app loads the font
779
+ before it is used. Especially on OS X, if fonts are used before they are
780
+ loaded, the font cache will tend to ignore loaded fonts.
781
+
782
+ === gradient(color1, color2) » Shoes::Pattern ===
783
+
784
+ Builds a linear gradient from two colors. For each color, you may pass in a
785
+ Shoes::Color object or a string describing the color.
786
+
787
+ === gray(the numbers: darkness, alpha) » Shoes::Color ===
788
+
789
+ Create a grayscale color from a level of darkness and, optionally, an alpha
790
+ level.
791
+
792
+ {{{
793
+ black = gray(0.0)
794
+ white = gray(1.0)
795
+ }}}
796
+
797
+ === info(message: a string) » nil ===
798
+
799
+ Logs an informational message to the user in the Shoes console. So, where
800
+ debug messages are designed to help the program figure out what's happening,
801
+ `info` messages tell the user extra information about the program.
802
+
803
+ {{{
804
+ #!ruby
805
+
806
+ info("You just ran the info example on Shoes #{Shoes::RELEASE_NAME}.")
807
+ }}}
808
+
809
+ For example, whenever a Shy file loads, Shoes prints an informational message
810
+ in the console describing the author of the Shy and its version.
811
+
812
+ === rgb(a series of numbers: red, green, blue, alpha) » Shoes::Color ===
813
+
814
+ Create a color from red, green and blue components. An alpha level (indicating
815
+ transparency) can also be added, optionally.
816
+
817
+ When passing in a whole number, use values from 0 to 255.
818
+
819
+ {{{
820
+ blueviolet = rgb(138, 43, 226)
821
+ darkgreen = rgb(0, 100, 0)
822
+ }}}
823
+
824
+ Or, use a decimal number from 0.0 to 1.0.
825
+
826
+ {{{
827
+ blueviolet = rgb(0.54, 0.17, 0.89)
828
+ darkgreen = rgb(0, 0.4, 0)
829
+ }}}
830
+
831
+ This method may also be called as `Shoes.rgb`.
832
+
833
+ === warn(message: a string) » nil ===
834
+
835
+ Logs a warning for the user. A warning is not a catastrophic error (see
836
+ [[Built-in.error]] for that.) It is just a notice that the program will be
837
+ changing in the future or that certain parts of the program aren't reliable
838
+ yet.
839
+
840
+ To view warnings and errors, open the Shoes console with `Alt-/` (or `⌘-/` on
841
+ OS X.)
842
+
843
+ == The App Object ==
844
+
845
+ An App is a single window running code at a URL. When you switch URLs, a new
846
+ App object is created and filled up with stacks, flows and other Shoes
847
+ elements.
848
+
849
+ The App is the window itself. Which may be closed or cleared and filled with
850
+ new elements. !{:margin_left => 100}man-app.png!
851
+
852
+ The App itself, in slot/box terminology, is a flow. See the ''Slots'' section
853
+ for more, but this just means that any elements placed directly at the
854
+ top-level will flow.
855
+
856
+ === Shoes.app(styles) { ... } » Shoes::App ===
857
+
858
+ Starts up a Shoes app window. This is the starting place for making a Shoes
859
+ program. Inside the block, you fill the window with various Shoes elements
860
+ (buttons, artwork, etc.) and, outside the block, you use the `styles` to
861
+ describe how big the window is. Perhaps also the name of the app or if it's
862
+ resizable.
863
+
864
+ {{{
865
+ #!ruby
866
+ Shoes.app(:title => "White Circle",
867
+ :width => 200, :height => 200, :resizable => false) {
868
+ background black
869
+ fill white
870
+ oval :top => 20, :left => 20, :radius => 160
871
+ }
872
+ }}}
873
+
874
+ In the case above, a small window is built. 200 pixels by 200 pixels. It's
875
+ not resizable. And, inside the window, two elements: a black background and a
876
+ white circle.
877
+
878
+ Once an app is created, it is added to the [[App.Shoes.APPS]] list. If you
879
+ want an app to spawn more windows, see the [[Element.window]] method and the
880
+ [[Element.dialog]] method.
881
+
882
+ === Shoes.APPS() » An array of Shoes::App objects ===
883
+
884
+ Builds a complete list of all the Shoes apps that are open right now. Once an
885
+ app is closed, it is removed from the list. Yes, you can run many apps at once
886
+ in Shoes. It's completely encouraged.
887
+
888
+ === clipboard() » a string ===
889
+
890
+ Returns a string containing all of the text that's on the system clipboard.
891
+ This is the global clipboard that every program on the computer cuts and pastes
892
+ into.
893
+
894
+ === clipboard = a string ===
895
+
896
+ Stores `a string` of text in the system clipboard.
897
+
898
+ === close() ===
899
+
900
+ Closes the app window. If multiple windows are open and you want to close the
901
+ entire application, use the built-in method `exit`.
902
+
903
+ === download(url: a string, styles) ===
904
+
905
+ Starts a download thread (much like XMLHttpRequest, if you're familiar with
906
+ JavaScript.) This method returns immediately and runs the download in the
907
+ background. Each download thread also fires `start`, `progress` and `finish`
908
+ events. You can send the download to a file or just get back a string (in the
909
+ `finish` event.)
910
+
911
+ If you attach a block to a download, it'll get called as the `finish` event.
912
+
913
+ {{{
914
+ #!ruby
915
+ Shoes.app do
916
+ stack do
917
+ title "Searching Google", :size => 16
918
+ @status = para "One moment..."
919
+
920
+ # Search Google for 'shoes' and print the HTTP headers
921
+ download "http://www.google.com/search?q=shoes" do |goog|
922
+ @status.text = "Headers: " + goog.response.headers.inspect
923
+ end
924
+ end
925
+ end
926
+ }}}
927
+
928
+ And, if we wanted to use the downloaded data, we'd get it using
929
+ `goog.response.body`. This example is truly the simplest form of `download`:
930
+ pulling some web data down into memory and handling it once it's done.
931
+
932
+ Another simple use of `download` is to save some web data to a file, using the
933
+ `:save` style.
934
+
935
+ {{{
936
+ #!ruby
937
+ Shoes.app do
938
+ stack do
939
+ title "Downloading Google image", :size => 16
940
+ @status = para "One moment..."
941
+
942
+ download "http://www.google.com/logos/nasa50th.gif",
943
+ :save => "nasa50th.gif" do
944
+ @status.text = "Okay, is downloaded."
945
+ end
946
+ end
947
+ end
948
+ }}}
949
+
950
+ In this case, you can still get the headers for the downloaded file, but
951
+ `response.body` will be `nil`, since the data wasn't saved to memory. You will
952
+ need to open the file to get the downloaded goods.
953
+
954
+ If you need to send certain headers or actions to the web server, you can use
955
+ the `:method`, `:headers` and `:body` styles to customize the HTTP request.
956
+ (And, if you need to go beyond these, you can always break out Ruby's OpenURI
957
+ class.)
958
+
959
+ {{{
960
+ #!ruby
961
+ Shoes.app do
962
+ stack do
963
+ title "GET Google", :size => 16
964
+ @status = para "One moment..."
965
+
966
+ download "http://www.google.com/search?q=shoes",
967
+ :method => "GET" do |dump|
968
+ @status.text = dump.response.body
969
+ end
970
+ end
971
+ end
972
+ }}}
973
+
974
+ As you can see from the above example, Shoes makes use of the "GET" method to
975
+ query google's search engine.
976
+
977
+ === location() » a string ===
978
+
979
+ Gets a string containing the URL of the current app.
980
+
981
+ === mouse() » an array of numbers: button, left, top ===
982
+
983
+ Identifies the mouse cursor's location, along with which button is being
984
+ pressed.
985
+
986
+ {{{
987
+ #!ruby
988
+ Shoes.app do
989
+ @p = para
990
+ animate do
991
+ button, left, top = self.mouse
992
+ @p.replace "mouse: #{button}, #{left}, #{top}"
993
+ end
994
+ end
995
+ }}}
996
+
997
+ === owner() » Shoes::App ===
998
+
999
+ Gets the app which launched this app. In most cases, this will be `nil`. But
1000
+ if this app was launched using the [[Element.window]] method, the owner will be
1001
+ the app which called `window`.
1002
+
1003
+ === started?() » true or false ===
1004
+
1005
+ Has the window been fully constructed and displayed? This is useful for
1006
+ threaded code which may try to use the window before it is completely built.
1007
+ (Also see the `start` event which fires once the window is open.)
1008
+
1009
+ === visit(url: a string) ===
1010
+
1011
+ Changes the location, in order to view a different Shoes URL.
1012
+
1013
+ Absolute URLs (such as http://google.com) are okay, but Shoes will be expecting
1014
+ a Shoes application to be at that address. (So, google.com won't work, as it's
1015
+ an HTML app.)
1016
+
1017
+ == The Styles Master List ==
1018
+
1019
+ You want to mess with the look of things? Well, throughout Shoes, styles are
1020
+ used to change the way elements appear. In some cases, you can even style an
1021
+ entire class of elements. (Like giving all paragraphs a certain font.)
1022
+
1023
+ Styles are easy to spot. They usually show up when the element is created.
1024
+
1025
+ {{{
1026
+ Shoes.app :title => "A Styling Sample" do
1027
+ para "Red with an underline", :stroke => red, :underline => "single"
1028
+ end
1029
+ }}}
1030
+
1031
+ Here we've got a `:title` style on the app. And on the paragraph inside the
1032
+ app, a red `:stroke` style and an `:underline` style.
1033
+
1034
+ The style hash can also be changed by using the [[Common.style]] method,
1035
+ available on every element and slot.
1036
+
1037
+ {{{
1038
+ Shoes.app :title => "A Styling Sample" do
1039
+ @text = para "Red with an underline"
1040
+ @text.style(:stroke => red, :underline => "single")
1041
+ end
1042
+ }}}
1043
+
1044
+ Most styles can also be set by calling them as methods. (I'd use the manual
1045
+ search to find the method.)
1046
+
1047
+ {{{
1048
+ Shoes.app :title => "A Styling Sample" do
1049
+ @text = para "Red with an underline"
1050
+ @text.stroke = red
1051
+ @text.underline = "single"
1052
+ end
1053
+ }}}
1054
+
1055
+ Rather than making you plow through the whole manual to figure out what styles
1056
+ go where, this helpful page speeds through every style in Shoes and suggests
1057
+ where that style is used.
1058
+
1059
+ === :align » a string ===
1060
+
1061
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1062
+ strong, sub, sup, subtitle, tagline, title''
1063
+
1064
+ The alignment of the text. It is either:
1065
+
1066
+ * "left" - Align the text to the left.
1067
+ * "center" - Align the text in the center.
1068
+ * "right" - Align the text to the right.
1069
+
1070
+ === :angle » a number ===
1071
+
1072
+ For: ''background, border, gradient''.
1073
+
1074
+ The angle at which to apply a gradient. Normally, gradient colors range from
1075
+ top to bottom. If the `:angle` is set to 90, the gradient will rotate 90
1076
+ degrees counter-clockwise and the gradient will go from left to right.
1077
+
1078
+ === :attach » a slot or element ===
1079
+
1080
+ For: ''flow, stack''.
1081
+
1082
+ Pins a slot relative to another slot or element. Also, one may write `:attach
1083
+ => Window` to position the slot at the window's top, left corner. Taking this
1084
+ a bit further, the style `:top => 10, :left => 10, :attach => Window` would
1085
+ place the slot at (10, 10) in the window's coordinates.
1086
+
1087
+ If a slot is attached to an element that moves, the slot will move with it. If
1088
+ the attachment is reset to `nil`, the slot will flow in with the other objects
1089
+ that surround, as normal.
1090
+
1091
+ === :autoplay » true or false ===
1092
+
1093
+ For: ''video''.
1094
+
1095
+ Should this video begin playing after it appears? If set to `true`, the video
1096
+ will start without asking the user.
1097
+
1098
+ === :bottom » a number ===
1099
+
1100
+ For: ''all slots and elements''.
1101
+
1102
+ Sets the pixel coordinate of an element's lower edge. The edge is placed
1103
+ relative to its container's lower edge. So, `:bottom => 0` will align the
1104
+ element so that its bottom edge and the bottom edge of its slot touch.
1105
+
1106
+ === :cap » :curve or :rect or :project ===
1107
+
1108
+ For: ''arc, arrow, border, flow, image, mask, rect, star, shape, stack''.
1109
+
1110
+ Sets the shape of the line endpoint, whether curved or square. See the
1111
+ [[Art.cap]] method for more explanation.
1112
+
1113
+ === :center » true or false ===
1114
+
1115
+ For: ''arc, image, oval, rect, shape''.
1116
+
1117
+ Indicates whether the `:top` and `:left` coordinates refer to the center of the
1118
+ shape or not. If set to `true`, this is similar to setting the
1119
+ [[Art.transform]] method to `:center`.
1120
+
1121
+ === :change » a proc ===
1122
+
1123
+ For: ''edit_box, edit_line, list_box''.
1124
+
1125
+ The `change` event handler is stored in this style. See the [[EditBox.change]]
1126
+ method for the edit_box, as an example.
1127
+
1128
+ === :checked » true or false ===
1129
+
1130
+ For: ''check, radio''.
1131
+
1132
+ Is this checkbox or radio button checked? If set to `true`, the box is
1133
+ checked. Also see the [[Check.checked=]] method.
1134
+
1135
+ === :choose » a string ===
1136
+
1137
+ For: ''list_box''.
1138
+
1139
+ Sets the currently chosen item in the list. More information at
1140
+ [[ListBox.choose]].
1141
+
1142
+ === :click » a proc ===
1143
+
1144
+ For: ''arc, arrow, banner, button, caption, check, flow, image, inscription,
1145
+ line, link, mask, oval, para, radio, rect, shape, stack, star, subtitle,
1146
+ tagline, title''.
1147
+
1148
+ The `click` event handler is stored in this style. See the [[Events.click]]
1149
+ method for a description.
1150
+
1151
+ === :curve » a number ===
1152
+
1153
+ For: ''background, border, rect''.
1154
+
1155
+ The radius of curved corners on each of these rectangular elements. As an
1156
+ example, if this is set to 6, the corners of the rectangle are given a curve
1157
+ with a 6-pixel radius.
1158
+
1159
+ === :displace_left » a number ===
1160
+
1161
+ For: ''all slots and elements''.
1162
+
1163
+ Moves a shape, text block or any other kind of object to the left or right. A
1164
+ positive number displaces to the right by the given number of pixels; a
1165
+ negative number displaces to the left. Displacing an object doesn't effect the
1166
+ actual layout of the page. Before using this style, be sure to read the
1167
+ [[Position.displace]] docs, since its behavior can be a bit surprising.
1168
+
1169
+ === :displace_top » a number ===
1170
+
1171
+ For: ''all slots and elements''.
1172
+
1173
+ Moves a shape, text block or any other kind of object up or down. A positive
1174
+ number moves the object down by this number of pixels; a negative number moves
1175
+ it up. Displacing doesn't effect the actual layout of the page or the object's
1176
+ true coordinates. Read the [[Position.displace]] docs, since its behavior can
1177
+ be a bit surprising.
1178
+
1179
+ === :emphasis » a string ===
1180
+
1181
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1182
+ strong, sub, sup, subtitle, tagline, title''.
1183
+
1184
+ Styles the text with an emphasis (commonly italicized.)
1185
+
1186
+ This style recognizes three possible settings:
1187
+
1188
+ * "normal" - the font is upright.
1189
+ * "oblique" - the font is slanted, but in a roman style.
1190
+ * "italic" - the font is slanted in an italic style.
1191
+
1192
+ === :family » a string ===
1193
+
1194
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1195
+ strong, sub, sup, subtitle, tagline, title''.
1196
+
1197
+ Styles the text with a given font family. The string should contain the family
1198
+ name or a comma-separated list of families.
1199
+
1200
+ === :fill » a hex code, a Shoes::Color or a range of either ===
1201
+
1202
+ For: ''arc, arrow, background, banner, caption, code, del, em, flow, image,
1203
+ ins, inscription, line, link, mask, oval, para, rect, shape, span, stack, star,
1204
+ strong, sub, sup, subtitle, tagline, title''.
1205
+
1206
+ The color of the background pen. For shapes, this is the fill color, the paint
1207
+ inside the shape. For text stuffs, this color is painted in the background (as
1208
+ if marked with a highlighter pen.)
1209
+
1210
+ === :font » a string ===
1211
+
1212
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1213
+ strong, sub, sup, subtitle, tagline, title''.
1214
+
1215
+ Styles the text with a font description. The string is pretty flexible, but
1216
+ can take the form "[FAMILY-LIST] [STYLE-OPTIONS] [SIZE]", where FAMILY-LIST is
1217
+ a comma separated list of families optionally terminated by a comma,
1218
+ STYLE_OPTIONS is a whitespace separated list of words where each WORD describes
1219
+ one of style, variant, weight, stretch, or gravity, and SIZE is a decimal
1220
+ number (size in points) or optionally followed by the unit modifier "px" for
1221
+ absolute size. Any one of the options may be absent. If FAMILY-LIST is absent,
1222
+ then the default font family (Arial) will be used.
1223
+
1224
+ === :group » a string ===
1225
+
1226
+ For: ''radio''.
1227
+
1228
+ Indicates what group a radio button belongs to. Without this setting, radio
1229
+ buttons are grouped together with other radio buttons in their immediate slot.
1230
+ "Grouping" radio buttons doesn't mean they'll be grouped next to each other on
1231
+ the screen. It means that only one radio button from the group can be selected
1232
+ at a time.
1233
+
1234
+ By giving this style a string, the radio button will be grouped with other
1235
+ radio buttons that have the same group name.
1236
+
1237
+ === :height » a number ===
1238
+
1239
+ For: ''all slots and elements''.
1240
+
1241
+ Sets the pixel height of this object. If the number is a decimal number, the
1242
+ height becomes a percentage of its parent's height (with 0.0 being 0% and 1.0
1243
+ being 100%.)
1244
+
1245
+ === :hidden » true or false ===
1246
+
1247
+ For: ''all slots and elements''.
1248
+
1249
+ Hides or shows this object. Any object with `:hidden => true` are not
1250
+ displayed on the screen. Neither are its children.
1251
+
1252
+ === :inner » a number ===
1253
+
1254
+ For: ''star''.
1255
+
1256
+ The size of the inner radius (in pixels.) The inner radius describes the solid
1257
+ circle within the star where the points begin to separate.
1258
+
1259
+ === :items » an array ===
1260
+
1261
+ For: ''list_box''.
1262
+
1263
+ The list of selections in the list box. See the [[Element.list_box]] method
1264
+ for an example.
1265
+
1266
+ === :justify » true or false ===
1267
+
1268
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1269
+ strong, sub, sup, subtitle, tagline, title''
1270
+
1271
+ Evenly spaces the text horizontally.
1272
+
1273
+ === :kerning » a number ===
1274
+
1275
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1276
+ strong, sub, sup, subtitle, tagline, title''.
1277
+
1278
+ Adds to the natural spacing between letters, in pixels.
1279
+
1280
+ === :leading » a number ===
1281
+
1282
+ For: ''banner, caption, inscription, para, subtitle, tagline, title''.
1283
+
1284
+ Sets the spacing between lines in a text block. Defaults to 4 pixels.
1285
+
1286
+ === :left » a number ===
1287
+
1288
+ For: ''all slots and elements''.
1289
+
1290
+ Sets the left coordinate of this object to a specific pixel. Setting `:left =>
1291
+ 10` places the object's left edge ten pixels away from the left edge of the
1292
+ slot containing it. If this style is left unset (or set to `nil`,) the object
1293
+ will flow in with the other objects surrounding it.
1294
+
1295
+ === :margin » a number or an array of four numbers ===
1296
+
1297
+ For: ''all slots and elements''.
1298
+
1299
+ Margins space an element out from its surroundings. Each element has a left,
1300
+ top, right, and bottom margin. If the `:margin` style is set to a single
1301
+ number, the spacing around the element uniformly matches that number. In other
1302
+ words, if `:margin => 8` is set, all the margins around the element are set to
1303
+ eight pixels in length.
1304
+
1305
+ This style can also be given an array of four numbers in the form `[left, top,
1306
+ right, bottom]`.
1307
+
1308
+ === :margin_bottom » a number ===
1309
+
1310
+ For: ''all slots and elements''.
1311
+
1312
+ Sets the bottom margin of the element to a specific pixel size.
1313
+
1314
+ === :margin_left » a number ===
1315
+
1316
+ For: ''all slots and elements''.
1317
+
1318
+ Sets the left margin of the element to a specific pixel size.
1319
+
1320
+ === :margin_right » a number ===
1321
+
1322
+ For: ''all slots and elements''.
1323
+
1324
+ Sets the right margin of the element to a specific pixel size.
1325
+
1326
+ === :margin_top » a number ===
1327
+
1328
+ For: ''all slots and elements''.
1329
+
1330
+ Sets the top margin of the element to a specific pixel size.
1331
+
1332
+ === :outer » a number ===
1333
+
1334
+ For: ''star''.
1335
+
1336
+ Sets the outer radius (half of the ''total'' width) of the star, in pixels.
1337
+
1338
+ === :points » a number ===
1339
+
1340
+ For: ''star''.
1341
+
1342
+ How many points does this star have? A style of `:points => 5` creates a
1343
+ five-pointed star.
1344
+
1345
+ === :radius » a number ===
1346
+
1347
+ For: ''arc, arrow, background, border, gradient, oval, rect, shape''.
1348
+
1349
+ Sets the radius (half of the diameter or total width) for each of these
1350
+ elements. Setting this is equivalent to setting both `:width` and `:height` to
1351
+ double this number.
1352
+
1353
+ === :right » a number ===
1354
+
1355
+ For: ''all slots and elements''.
1356
+
1357
+ Sets the pixel coordinate of an element's right edge. The edge is placed
1358
+ relative to its container's rightmost edge. So, `:right => 0` will align the
1359
+ element so that its own right edge and the right edge of its slot touch.
1360
+ Whereas `:right => 20` will position the right edge of the element off to the
1361
+ left of its slot's right edge by twenty pixels.
1362
+
1363
+ === :rise » a number ===
1364
+
1365
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1366
+ strong, sub, sup, subtitle, tagline, title''.
1367
+
1368
+ Lifts or plunges the font baseline for some text. For example, a
1369
+ [[Element.sup]] has a `:rise` of 10 pixels. Conversely, the [[Element.sub]]
1370
+ element has a `:rise` of -10 pixels.
1371
+
1372
+ === :scroll » true or false ===
1373
+
1374
+ For: ''flow, stack''.
1375
+
1376
+ Establishes this slot as a scrolling slot. If `:scroll => true` is set, the
1377
+ slot will show a scrollbar if any of its contents go past its height. The
1378
+ scrollbar will appear and disappear as needed. It will also appear inside the
1379
+ width of the slot, meaning the slot's width will never change, regardless of
1380
+ whether there is a scrollbar or not.
1381
+
1382
+ === :secret » true or false ===
1383
+
1384
+ For: ''ask, edit_line''.
1385
+
1386
+ Used for password fields, this setting keeps any characters typed in from
1387
+ becoming visible on the screen. Instead, a replacement character (such as an
1388
+ asterisk) is show for each letter typed.
1389
+
1390
+ === :size » a number ===
1391
+
1392
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1393
+ strong, sub, sup, subtitle, tagline, title''.
1394
+
1395
+ Sets the pixel size for the font used inside this text block or text fragment.
1396
+
1397
+ Font size may also be augmented, through use of the following strings:
1398
+
1399
+ * "xx-small" - 57% of present size.
1400
+ * "x-small" - 64% of present size.
1401
+ * "small" - 83% of present size.
1402
+ * "medium" - no change in size.
1403
+ * "large" - 120% of present size.
1404
+ * "x-large" - 143% of present size.
1405
+ * "xx-large" - 173% of present size.
1406
+
1407
+ === :state » a string ===
1408
+
1409
+ For: ''button, check, edit_box, edit_line, list_box, radio''.
1410
+
1411
+ The `:state` style is for disabling or locking certain controls, if you don't
1412
+ want them to be edited.
1413
+
1414
+ Here are the possible style settings:
1415
+
1416
+ * nil - the control is active and editable.
1417
+ * "readonly" - the control is active but cannot be edited.
1418
+ * "disabled" - the control is not active (grayed out) and cannot be edited.
1419
+
1420
+ === :stretch » a string ===
1421
+
1422
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1423
+ strong, sub, sup, subtitle, tagline, title''.
1424
+
1425
+ Sets the font stretching used for a text object.
1426
+
1427
+ Possible settings are:
1428
+
1429
+ * "condensed" - a smaller width of letters.
1430
+ * "normal" - the standard width of letters.
1431
+ * "expanded" - a larger width of letters.
1432
+
1433
+ === :strikecolor » a Shoes::Color ===
1434
+
1435
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1436
+ strong, sub, sup, subtitle, tagline, title''.
1437
+
1438
+ The color used to paint any lines stricken through this text.
1439
+
1440
+ === :strikethrough » a string ===
1441
+
1442
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1443
+ strong, sub, sup, subtitle, tagline, title''.
1444
+
1445
+ Is this text stricken through? Two options here:
1446
+
1447
+ * "none" - no strikethrough
1448
+ * "single" - a single-line strikethrough.
1449
+
1450
+ === :stroke » a hex code, a Shoes::Color or a range of either ===
1451
+
1452
+ For: ''arc, arrow, banner, border, caption, code, del, em, flow, image, ins,
1453
+ inscription, line, link, mask, oval, para, rect, shape, span, stack, star,
1454
+ strong, sub, sup, subtitle, tagline, title''.
1455
+
1456
+ The color of the foreground pen. In the case of shapes, this is the color the
1457
+ lines are drawn with. For paragraphs and other text, the letters are printed
1458
+ in this color.
1459
+
1460
+ === :strokewidth » a number ===
1461
+
1462
+ For: ''arc, arrow, border, flow, image, line, mask, oval, rect, shape, star, stack''.
1463
+
1464
+ The thickness of the stroke, in pixels, of the line defining each of these
1465
+ shapes. For example, the number two would set the strokewidth to 2 pixels.
1466
+
1467
+ === :text » a string ===
1468
+
1469
+ For: ''button, edit_box, edit_line''.
1470
+
1471
+ Sets the message displayed on a button control, or the contents of an edit_box
1472
+ or edit_line.
1473
+
1474
+ === :top » a number ===
1475
+
1476
+ For: ''all slots and elements''.
1477
+
1478
+ Sets the top coordinate for an object, relative to its parent slot. If an
1479
+ object is set with `:top => 40`, this means the object's top edge will be
1480
+ placed 40 pixels beneath the top edge of the slot that contains it. If no
1481
+ `:top` style is given, the object is automatically placed in the natural flow
1482
+ of its slot.
1483
+
1484
+ === :undercolor » a Shoes::Color ===
1485
+
1486
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1487
+ strong, sub, sup, subtitle, tagline, title''.
1488
+
1489
+ The color used to underline text.
1490
+
1491
+ === :underline » a string ===
1492
+
1493
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1494
+ strong, sub, sup, subtitle, tagline, title''.
1495
+
1496
+ Dictates the style of underline used in the text.
1497
+
1498
+ The choices for this setting are:
1499
+
1500
+ * "none" - no underline at all.
1501
+ * "single" - a continuous underline.
1502
+ * "double" - two continuous parallel underlines.
1503
+ * "low" - a lower underline, beneath the font baseline. (This is generally recommended only for single characters, particularly when showing keyboard accelerators.)
1504
+ * "error" - a wavy underline, usually found indicating a misspelling.
1505
+
1506
+ === :variant » a string ===
1507
+
1508
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1509
+ strong, sub, sup, subtitle, tagline, title''.
1510
+
1511
+ Vary the font for a group of text. Two choices:
1512
+
1513
+ * "normal" - standard font.
1514
+ * "smallcaps" - font with the lower case characters replaced by smaller variants of the capital characters.
1515
+
1516
+ === :weight » a string ===
1517
+
1518
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1519
+ strong, sub, sup, subtitle, tagline, title''.
1520
+
1521
+ Set the boldness of the text. Commonly, this style is set to one of the
1522
+ following strings:
1523
+
1524
+ * "ultralight" - the ultralight weight (= 200)
1525
+ * "light" - the light weight (= 300)
1526
+ * "normal" - the default weight (= 400)
1527
+ * "semibold" - a weight intermediate between normal and bold (= 600)
1528
+ * "bold" - the bold weight (= 700)
1529
+ * "ultrabold" - the ultrabold weight (= 800)
1530
+ * "heavy" - the heavy weight (= 900)
1531
+
1532
+ However, you may also pass in the numerical weight directly.
1533
+
1534
+ === :width » a number ===
1535
+
1536
+ For: ''all slots and elements''.
1537
+
1538
+ Sets the pixel width for the element. If the number is a decimal, the width is
1539
+ converted to a percentage (with 0.0 being 0% and 1.0 being 100%.) A width of
1540
+ 100% means the object fills its parent slot.
1541
+
1542
+ === :wrap » a string ===
1543
+
1544
+ For: ''banner, caption, code, del, em, ins, inscription, link, para, span,
1545
+ strong, sub, sup, subtitle, tagline, title''
1546
+
1547
+ How should the text wrap when it fills its width? Possible options are:
1548
+
1549
+ * "word" - Break lines at word breaks.
1550
+ * "char" - Break lines between characters, thus breaking some words.
1551
+ * "trim" - Cut the line off with an ellipsis if it goes too long.
1552
+
1553
+ == Classes List ==
1554
+
1555
+ Here is a complete list of all the classes introduced by Shoes. This chart is
1556
+ laid out according to how classes inherits from each other. Subclasses are
1557
+ indented one level to the right, beneath their parent class.
1558
+
1559
+ {INDEX}
1560
+
1561
+ == Colors List ==
1562
+
1563
+ The following list of colors can be used throughout Shoes. As background
1564
+ colors or border colors. As stroke and fill colors. Most of these colors come
1565
+ from the X11 and HTML palettes.
1566
+
1567
+ All of these colors can be used by name. (So calling the `tomato` method from
1568
+ inside any slot will get you a nice reddish color.) Below each color, also
1569
+ find the exact numbers which can be used with the [[Built-in.rgb]] method.
1570
+
1571
+ {COLORS}
1572
+
1573
+ = Slots =
1574
+
1575
+ Slots are boxes used to lay out images, text and so on. The two most common
1576
+ slots are `stacks` and `flows`. Slots can also be referred to as "boxes" or
1577
+ "canvases" in Shoes terminology.
1578
+
1579
+ Since the mouse wheel and PageUp and PageDown are so pervasive on every
1580
+ platform, vertical scrolling has really become the only overflow that matters.
1581
+ So, in Shoes, just as on the web, width is generally fixed. While height goes
1582
+ on and on.
1583
+
1584
+ Now, you can also just use specific widths and heights for everything, if you
1585
+ want. That'll take some math, but everything could be perfect.
1586
+
1587
+ Generally, I'd suggest using stacks and flows. The idea here is that you want
1588
+ to fill up a certain width with things, then advance down the page, filling up
1589
+ further widths. You can think of these as being analogous to HTML's "block" and
1590
+ "inline" styles.
1591
+
1592
+ ==== Stacks ====
1593
+
1594
+ A stack is simply a vertical stack of elements. Each element in a stack is
1595
+ placed directly under the element preceding it.
1596
+
1597
+ A stack is also shaped like a box. So if a stack is given a width of 250, that
1598
+ stack is itself an element which is 250 pixels wide.
1599
+
1600
+ To create a new stack, use the [[Element.stack]] method, which is available
1601
+ inside any slot. So stacks can contain other stacks and flows.
1602
+
1603
+ ==== Flows ====
1604
+
1605
+ A flow will pack elements in as tightly as it can. A width will be filled, then
1606
+ will wrap beneath those elements. Text elements placed next to each other will
1607
+ appear as a single paragraph. Images and widgets will run together as a series.
1608
+
1609
+ Like the stack, a flow is a box. So stacks and flows can safely be embedded
1610
+ and, without respect to their contents, are identical. They just treat their
1611
+ contents differently.
1612
+
1613
+ Making a flow means calling the [[Element.flow]] method. Flows may contain
1614
+ other flows and stacks.
1615
+
1616
+ Last thing: The Shoes window itself is a flow.
1617
+
1618
+ == Art for Slots ==
1619
+
1620
+ Each slot is like a canvas, a blank surface which can be covered with an
1621
+ assortment of colored shapes or gradients.
1622
+
1623
+ Many common shapes can be drawn with methods like `oval` and `rect`. You'll
1624
+ need to set up the paintbrush colors first, though.
1625
+
1626
+ The `stroke` command sets the line color. And the `fill` command sets the
1627
+ color used to paint inside the lines.
1628
+
1629
+ {{{
1630
+ #!ruby
1631
+ Shoes.app do
1632
+ stroke red
1633
+ fill blue
1634
+ oval :top => 10, :left => 10,
1635
+ :radius => 100
1636
+ end
1637
+ }}}
1638
+
1639
+ That code gives you a blue pie with a red line around it. One-hundred pixels
1640
+ wide, placed just a few pixels southeast of the window's upper left corner.
1641
+
1642
+ The `blue` and `red` methods above are Color objects. See the section on
1643
+ Colors for more on how to mix colors.
1644
+
1645
+ ==== Inspiration from Processing and NodeBox ====
1646
+
1647
+ The artful methods generally come verbatim from NodeBox, a drawing kit for
1648
+ Python. In turn, NodeBox gets much of its ideas from Processing, a Java-like
1649
+ language for graphics and animation. I owe a great debt to the creators of
1650
+ these wonderful programs!
1651
+
1652
+ Shoes does a few things differently from NodeBox and Processing. For example,
1653
+ Shoes has different color methods, including having its own Color objects,
1654
+ though these are very similar to Processing's color methods. And Shoes also
1655
+ allows images and gradients to be used for drawing lines and filling in shapes.
1656
+
1657
+ Shoes also borrows some animation ideas from Processing and will continue to
1658
+ closely consult Processing's methods as it expands.
1659
+
1660
+ === arc(left, top, width, height, angle1, angle2) » Shoes::Shape ===
1661
+
1662
+ Draws an arc shape (a section of an oval) at coordinates (left, top). This
1663
+ method just give you a bit more control than [[oval]], by offering the
1664
+ `:angle1` and `:angle2` styles. (In fact, you can mimick the `oval` method by
1665
+ setting `:angle1` to 0 and `:angle2` to `Shoes::TWO_PI`.)
1666
+
1667
+ === arrow(left, top, width) » Shoes::Shape ===
1668
+
1669
+ Draws an arrow at coordinates (left, top) with a pixel `width`.
1670
+
1671
+ === cap(:curve or :rect or :project) » self ===
1672
+
1673
+ Sets the line cap, which is the shape at the end of every line you draw. If
1674
+ set to `:curve`, the end is rounded. The default is `:rect`, a line which ends
1675
+ abruptly flat. The `:project` cap is also fat, but sticks out a bit longer.
1676
+
1677
+ === fill(pattern) » pattern ===
1678
+
1679
+ Sets the fill bucket to a specific color (or pattern.) Patterns can be colors,
1680
+ gradients or images. So, once the fill bucket is set, you can draw shapes and
1681
+ they will be colored in with the pattern you've chosen.
1682
+
1683
+ To draw a star with an image pattern:
1684
+
1685
+ {{{
1686
+ #!ruby
1687
+ Shoes.app do
1688
+ fill "static/avatar.png"
1689
+ star 200, 200, 5
1690
+ end
1691
+ }}}
1692
+
1693
+ To clear the fill bucket, use `nofill`. And to set the line color (the border
1694
+ of the star,) use the `stroke` method.
1695
+
1696
+ === nofill() » self ===
1697
+
1698
+ Blanks the fill color, so that any shapes drawn will not be filled in.
1699
+ Instead, shapes will have only a lining, leaving the middle transparent.
1700
+
1701
+ === nostroke() » self ===
1702
+
1703
+ Empties the line color. Shapes drawn will have no outer line. If `nofill` is
1704
+ also set, shapes drawn will not be visible.
1705
+
1706
+ === line(left, top, x2, y2) » Shoes::Shape ===
1707
+
1708
+ Draws a line using the current line color (aka "stroke") starting at
1709
+ coordinates (left, top) and ending at coordinates (x2, y2).
1710
+
1711
+ === oval(left, top, radius) » Shoes::Shape ===
1712
+
1713
+ Draws a circular form at pixel coordinates (left, top) with a width and height
1714
+ of `radius` pixels. The line and fill colors are used to draw the shape. By
1715
+ default, the coordinates are for the oval's leftmost, top corner, but this can
1716
+ be changed by calling the [[Art.transform]] method or by using the `:center`
1717
+ style on the next method below.
1718
+
1719
+ {{{
1720
+ #!ruby
1721
+ Shoes.app do
1722
+ stroke blue
1723
+ strokewidth 4
1724
+ fill black
1725
+ oval 10, 10, 50
1726
+ end
1727
+ }}}
1728
+
1729
+ To draw an oval of varied proportions, you may also use the syntax: `oval(left, top, width, height)`.
1730
+
1731
+ === oval(styles) » Shoes::Shape ===
1732
+
1733
+ Draw circular form using a style hash. The following styles are supported:
1734
+
1735
+ * `top`: the y-coordinate for the oval pen.
1736
+ * `left`: the x-coordinate for the oval pen.
1737
+ * `radius`: the width and height of the circle.
1738
+ * `width`: a specific pixel width for the oval.
1739
+ * `height`: a specific pixel height for the oval.
1740
+ * `center`: do the coordinates specific the oval's center? (true or false)
1741
+
1742
+ These styles may also be altered using the `style` method on the Shape object.
1743
+
1744
+ === rect(top, left, width, height, corners = 0) » Shoes::Shape ===
1745
+
1746
+ Draws a rectangle starting from coordinates (top, left) with dimensions of
1747
+ width x height. Optionally, you may give the rectangle rounded corners with a
1748
+ fifth argument: the radius of the corners in pixels.
1749
+
1750
+ As with all other shapes, the rectangle is drawn using the stroke and fill colors.
1751
+
1752
+ {{{
1753
+ #!ruby
1754
+ Shoes.app do
1755
+ stroke rgb(0.5, 0.5, 0.7)
1756
+ fill rgb(1.0, 1.0, 0.9)
1757
+ rect 10, 10, self.width - 20, self.height - 20
1758
+ end
1759
+ }}}
1760
+
1761
+ The above sample draws a rectangle which fills the area of its parent box,
1762
+ leaving a margin of 10 pixels around the edge. Also see the `background`
1763
+ method for a rectangle which defaults to filling its parent box.
1764
+
1765
+ === rect(styles) » Shoes::Shape ===
1766
+
1767
+ Draw a rectangle using a style hash. The following styles are supported:
1768
+
1769
+ * `top`: the y-coordinate for the rectangle.
1770
+ * `left`: the x-coordinate for the rectangle.
1771
+ * `curve`: the pixel radius of the rectangle's corners.
1772
+ * `width`: a specific pixel width for the rectangle.
1773
+ * `height`: a specific pixel height for the rectangle.
1774
+ * `center`: do the coordinates specific the rectangle's center? (true or false)
1775
+
1776
+ These styles may also be altered using the `style` method on the Shape object.
1777
+
1778
+ === rotate(degrees: a number) » self ===
1779
+
1780
+ Rotates the pen used for drawing by a certain number of `degrees`, so that any
1781
+ shapes will be drawn at that angle.
1782
+
1783
+ In this example below, the rectangle drawn at (30, 30) will be rotated 45 degrees.
1784
+
1785
+ {{{
1786
+ #!ruby
1787
+ Shoes.app do
1788
+ fill "#333"
1789
+ rotate 45
1790
+ rect 30, 30, 40, 40
1791
+ end
1792
+ }}}
1793
+
1794
+ === shape(left, top) { ... } » Shoes::Shape ===
1795
+
1796
+ Describes an arbitrary shape to draw, beginning at coordinates (left, top) and
1797
+ continued by calls to `line_to`, `move_to`, `curve_to` and `arc_to` inside the
1798
+ block. You can look at it as sketching a shape with a long line that curves
1799
+ and arcs and bends.
1800
+
1801
+ {{{
1802
+ #!ruby
1803
+ Shoes.app do
1804
+ fill red(0.2)
1805
+ shape do
1806
+ move_to(90, 55)
1807
+ arc_to(50, 55, 50, 50, 0, PI/2)
1808
+ arc_to(50, 55, 60, 60, PI/2, PI)
1809
+ arc_to(50, 55, 70, 70, PI, TWO_PI-PI/2)
1810
+ arc_to(50, 55, 80, 80, TWO_PI-PI/2, TWO_PI)
1811
+ end
1812
+ end
1813
+ }}}
1814
+
1815
+ A shape can also contain other shapes. So, you can place an [[Art.oval]], a
1816
+ [[Art.rect]], a [[Art.line]], a [[Art.star]] or an [[Art.arrow]] (and all of
1817
+ the other methods in this [[Art]] section) inside a shape, but they will not be
1818
+ part of the line. They will be more like a group of shapes are all drawn as
1819
+ one.
1820
+
1821
+ === star(left, top, points = 10, outer = 100.0, inner = 50.0) » Shoes::Shape ===
1822
+
1823
+ Draws a star using the stroke and fill colors. The star is positioned with its
1824
+ center point at coordinates (left, top) with a certain number of `points`. The
1825
+ `outer` width defines the full radius of the star; the `inner` width specifies
1826
+ the radius of the star's middle, where points stem from.
1827
+
1828
+ === stroke(pattern) » pattern ===
1829
+
1830
+ Set the active line color for this slot. The `pattern` may be a color, a
1831
+ gradient or an image, all of which are categorized as "patterns." The line
1832
+ color is then used to draw the borders of any subsequent shape.
1833
+
1834
+ So, to draw an arrow with a red line around it:
1835
+
1836
+ {{{
1837
+ #!ruby
1838
+ Shoes.app do
1839
+ stroke red
1840
+ arrow 0, 100, 10
1841
+ end
1842
+ }}}
1843
+
1844
+ To clear the line color, use the `nostroke` method.
1845
+
1846
+ === strokewidth(a number) » self ===
1847
+
1848
+ Sets the line size for all drawing within this slot. Whereas the `stroke`
1849
+ method alters the line color, the `strokewidth` method alters the line size in
1850
+ pixels. Calling `strokewidth(4)` will cause lines to be drawn 4 pixels wide.
1851
+
1852
+ === transform(:center or :corner) » self ===
1853
+
1854
+ Should transformations (such as `skew` and `rotate`) be performed around the
1855
+ center of the shape? Or the corner of the shape? Shoes defaults to `:corner`.
1856
+
1857
+ === translate(left, top) » self ===
1858
+
1859
+ Moves the starting point of the drawing pen for this slot. Normally, the pen
1860
+ starts at (0, 0) in the top-left corner, so that all shapes are drawn from that
1861
+ point. With `translate`, if the starting point is moved to (10, 20) and a
1862
+ shape is drawn at (50, 60), then the shape is actually drawn at (60, 80) on the
1863
+ slot.
1864
+
1865
+ == Element Creation ==
1866
+
1867
+ Shoes has a wide variety of elements, many cherry-picked from HTML. This page
1868
+ describes how to create these elements in a slot. See the Elements section of
1869
+ the manual for more on how to modify and use these elements after they have
1870
+ been placed.
1871
+
1872
+ === animate(fps) { |frame| ... } » Shoes::Animation ===
1873
+
1874
+ Starts an animation timer, which runs parallel to the rest of the app. The
1875
+ `fps` is a number, the frames per seconds. This number dictates how many times
1876
+ per second the attached block will be called.
1877
+
1878
+ The block is given a `frame` number. Starting with zero, the `frame` number
1879
+ tells the block how many frames of the animation have been shown.
1880
+
1881
+ {{{
1882
+ #!ruby
1883
+ Shoes.app do
1884
+ @counter = para "STARTING"
1885
+ animate(24) do |frame|
1886
+ @counter.replace "FRAME #{frame}"
1887
+ end
1888
+ end
1889
+ }}}
1890
+
1891
+ The above animation is shown 24 times per second. If no number is given, the
1892
+ `fps` defaults to 10.
1893
+
1894
+ === background(pattern) » Shoes::Background ===
1895
+
1896
+ Draws a Background element with a specific color (or pattern.) Patterns can be
1897
+ colors, gradients or images. Colors and images will tile across the
1898
+ background. Gradients stretch to fill the background.
1899
+
1900
+ '''PLEASE NOTE:''' Backgrounds are actual elements, not styles. HTML treats
1901
+ backgrounds like styles. Which means every box can only have one background.
1902
+ Shoes layers background elements.
1903
+
1904
+ {{{
1905
+ #!ruby
1906
+ Shoes.app do
1907
+ background black
1908
+ background white, :width => 50
1909
+ end
1910
+ }}}
1911
+
1912
+ The above example paints two backgrounds. First, a black background is painted
1913
+ over the entire app's surface area. Then a 50 pixel white stripe is painted
1914
+ along the left side.
1915
+
1916
+ === banner(text) » Shoes::Banner ===
1917
+
1918
+ Creates a Banner text block. Shoes automatically styles this text to 48 pixels high.
1919
+
1920
+ === border(text, :strokewidth => a number) » Shoes::Border ===
1921
+
1922
+ Draws a Border element using a specific color (or pattern.) Patterns can be
1923
+ colors, gradients or images. Colors and images will tile across the border.
1924
+ Gradients stretch to fill the border.
1925
+
1926
+ '''PLEASE NOTE:''' Like Backgrounds, Borders are actual elements, not styles.
1927
+ HTML treats backgrounds and borders like styles. Which means every box can
1928
+ only have one borders. Shoes layers border and background elements, along with
1929
+ text blocks, images, and everything else.
1930
+
1931
+ === button(text) { ... } » Shoes::Button ===
1932
+
1933
+ Adds a push button with the message `text` written across its surface. An
1934
+ optional block can be attached, which is called if the button is pressed.
1935
+
1936
+ === caption(text) » Shoes::Caption ===
1937
+
1938
+ Creates a Caption text block. Shoes styles this text to 14 pixels high.
1939
+
1940
+ === check() » Shoes::Check ===
1941
+
1942
+ Adds a check box.
1943
+
1944
+ === code(text) » Shoes::Code ===
1945
+
1946
+ Create a Code text fragment. This text defaults to a monospaced font.
1947
+
1948
+ === del(text) » Shoes::Del ===
1949
+
1950
+ Creates a Del text fragment (short for "deleted") which defaults to text with a
1951
+ single strikethrough in its middle.
1952
+
1953
+ === dialog(styles) { ... } » Shoes::App ===
1954
+
1955
+ Opens a new app window (just like the [[Element.window]] method does,) but the
1956
+ window is given a dialog box look.
1957
+
1958
+ === edit_box(text) » Shoes::EditBox ===
1959
+
1960
+ Adds a large, multi-line textarea to this slot. The `text` is optional and
1961
+ should be a string that will start out the box. An optional block can be
1962
+ attached here which is called any type the user changes the text in the box.
1963
+
1964
+ {{{
1965
+ #!ruby
1966
+ Shoes.app do
1967
+ edit_box
1968
+ edit_box "HORRAY EDIT ME"
1969
+ edit_box "small one", :width => 100, :height => 160
1970
+ end
1971
+ }}}
1972
+
1973
+ === edit_line(text) » Shoes::EditLine ===
1974
+
1975
+ Adds a single-line text box to this slot. The `text` is optional and should be
1976
+ a string that will start out the box. An optional block can be attached here
1977
+ which is called any type the user changes the text in the box.
1978
+
1979
+ === em(text) » Shoes::Em ===
1980
+
1981
+ Creates an Em text fragment (short for "emphasized") which, by default, is
1982
+ styled with italics.
1983
+
1984
+ === every(seconds) { |count| ... } » Shoes::Every ===
1985
+
1986
+ A timer similar to the `animation` method, but much slower. This timer fires a
1987
+ given number of seconds, running the block attached. So, for example, if you
1988
+ need to check a web site every five minutes, you'd call `every(300)` with a
1989
+ block containing the code to actually ping the web site.
1990
+
1991
+ === flow(styles) { ... } » Shoes::Flow ===
1992
+
1993
+ A flow is an invisible box (or "slot") in which you place Shoes elements. Both
1994
+ flows and stacks are explained in great detail on the main [[Slots]] page.
1995
+
1996
+ Flows organize elements horizontally. Where one would use a [[Element.stack]]
1997
+ to keep things stacked vertically, a flow places its contents end-to-end across
1998
+ the page. Once the end of the page is reached, the flow starts a new line of
1999
+ elements.
2000
+
2001
+ === image(path) » Shoes::Image ===
2002
+
2003
+ Creates an [[Image]] element for displaying a picture. PNG, JPEG and GIF
2004
+ formats are allowed.
2005
+
2006
+ The `path` can be a file path or a URL. All images loaded are temporarily
2007
+ cached in memory, but remote images are also cached locally in the user's
2008
+ personal Shoes directory. Remote images are loaded in the background; as with
2009
+ browsers, the images will not appear right away, but will be shown when they
2010
+ are loaded.
2011
+
2012
+ === imagesize(path) » [width, height] ===
2013
+
2014
+ Quickly grab the width and height of an image. The image won't be loaded into
2015
+ the cache or displayed.
2016
+
2017
+ URGENT NOTE: This method cannot be used with remote images (loaded from HTTP,
2018
+ rather than the hard drive.)
2019
+
2020
+ === ins(text) » Shoes::Ins ===
2021
+
2022
+ Creates an Ins text fragment (short for "inserted") which Shoes styles with a
2023
+ single underline.
2024
+
2025
+ === inscription(text) » Shoes::Inscription ===
2026
+
2027
+ Creates an Inscription text block. Shoes styles this text at 10 pixels high.
2028
+
2029
+ === link(text, :click => proc or string) » Shoes::Link ===
2030
+
2031
+ Creates a Link text block, which Shoes styles with a single underline and
2032
+ colors with a #06E (blue) colored stroke.
2033
+
2034
+ The default LinkHover style is also single-underlined with a #039 (dark blue) stroke.
2035
+
2036
+ === list_box(:items => [strings, ...]) » Shoes::ListBox ===
2037
+
2038
+ Adds a drop-down list box containing entries for everything in the `items`
2039
+ array. An optional block may be attached, which is called if anything in the
2040
+ box becomes selected by the user.
2041
+
2042
+ {{{
2043
+ #!ruby
2044
+ Shoes.app do
2045
+ stack :margin => 10 do
2046
+ para "Pick a card:"
2047
+ list_box :items => ["Jack", "Ace", "Joker"]
2048
+ end
2049
+ end
2050
+ }}}
2051
+
2052
+ Call `ListBox#text` to get the selected string. See the `ListBox` section
2053
+ under `Native` controls for more help.
2054
+
2055
+ === progress() » Shoes::Progress ===
2056
+
2057
+ Adds a progress bar.
2058
+
2059
+ === para(text) » Shoes::Para ===
2060
+
2061
+ Create a Para text block (short for "paragraph") which Shoes styles at 12
2062
+ pixels high.
2063
+
2064
+ === radio(group name: a string or symbol) » Shoes::Radio ===
2065
+
2066
+ Adds a radio button. If a `group name` is given, the radio button is
2067
+ considered part of a group. Among radio buttons in the same group, only one
2068
+ may be checked. (If no group name is given, the radio button is grouped with
2069
+ any other radio buttons in the same slot.)
2070
+
2071
+ === span(text) » Shoes::Span ===
2072
+
2073
+ Creates a Span text fragment, unstyled by default.
2074
+
2075
+ === stack(styles) { ... } » Shoes::Stack ===
2076
+
2077
+ Creates a new stack. A stack is a type of slot. (See the main [[Slots]] page
2078
+ for a full explanation of both stacks and flows.)
2079
+
2080
+ In short, stacks are an invisible box (a "slot") for placing stuff. As you add
2081
+ things to the stack, such as buttons or images, those things pile up
2082
+ vertically. Yes, they stack up!
2083
+
2084
+ === strong(text) » Shoes::Strong ===
2085
+
2086
+ Creates a Strong text fragment, styled in bold by default.
2087
+
2088
+ === sub(text) » Shoes::Sub ===
2089
+
2090
+ Creates a Sub text fragment (short for "subscript") which defaults to lowering
2091
+ the text by 10 pixels and styling it in an x-small font.
2092
+
2093
+ === subtitle(text) » Shoes::Subtitle ===
2094
+
2095
+ Creates a Subtitle text block. Shoes styles this text to 26 pixels high.
2096
+
2097
+ === sup(text) » Shoes::Sup ===
2098
+
2099
+ Creates a Sup text fragment (short for "superscript") which defaults to raising
2100
+ the text by 10 pixels and styling it in an x-small font.
2101
+
2102
+ === tagline(text) » Shoes::Tagline ===
2103
+
2104
+ Creates a Tagline text block. Shoes styles this text to 18 pixels high.
2105
+
2106
+ === timer(seconds) { ... } » Shoes::Timer ===
2107
+
2108
+ A one-shot timer. If you want to schedule to run some code in a few seconds
2109
+ (or minutes, hours) you can attach the code as a block here.
2110
+
2111
+ To display an alert box five seconds from now:
2112
+
2113
+ {{{
2114
+ #!ruby
2115
+ Shoes.app do
2116
+ timer(5) do
2117
+ alert("Your five seconds are up.")
2118
+ end
2119
+ end
2120
+ }}}
2121
+
2122
+ === title(text) » Shoes::Title ===
2123
+
2124
+ Creates a Title text block. Shoes styles these elements to 34 pixels high.
2125
+
2126
+ === video(path or url) » Shoes::Video ===
2127
+
2128
+ Embeds a movie in this slot.
2129
+
2130
+ === window(styles) { ... } » Shoes::App ===
2131
+
2132
+ Opens a new app window. This method is almost identical to the
2133
+ [[App.Shoes.app]] method used to start an app in the first place. The
2134
+ difference is that the `window` method sets the new window's [[App.owner]]
2135
+ property. (A normal Shoes.app has its `owner` set to `nil`.)
2136
+
2137
+ So, the new window's `owner` will be set to the Shoes::App which launched the
2138
+ window. This way the child window can call the parent.
2139
+
2140
+ {{{
2141
+ #!ruby
2142
+ Shoes.app :title => "The Owner" do
2143
+ button "Pop up?" do
2144
+ window do
2145
+ para "Okay, popped up from #{owner}"
2146
+ end
2147
+ end
2148
+ end
2149
+ }}}
2150
+
2151
+ == Events ==
2152
+
2153
+ Wondering how to catch stray mouse clicks or keyboard typing? Events are sent
2154
+ to a slot whenever a mouse moves inside the slot. Or whenever a key is
2155
+ pressed. Even when the slot is created or destroyed. You can attach a block
2156
+ to each of these events.
2157
+
2158
+ Mouse events include `motion`, `click`, `hover` and `leave`. Keyboard typing
2159
+ is represented by the `keypress` event. And the `start` and `finish` events
2160
+ indicate when a canvas comes into play or is discarded.
2161
+
2162
+ So, let's say you want to change the background of a slot whenever the mouse
2163
+ floats over it. We can use the `hover` event to change the background when the
2164
+ mouse comes inside the slot. And `leave` to change back when the mouse floats
2165
+ away.
2166
+
2167
+ {{{
2168
+ #!ruby
2169
+ Shoes.app do
2170
+ s = stack :width => 200, :height => 200 do
2171
+ background red
2172
+ hover do
2173
+ s.clear { background blue }
2174
+ end
2175
+ leave do
2176
+ s.clear { background red }
2177
+ end
2178
+ end
2179
+ end
2180
+ }}}
2181
+
2182
+ === click { |button, left, top| ... } » self ===
2183
+
2184
+ The click block is called when a mouse button is clicked. The `button` is the
2185
+ number of the mouse button which has been pressed. The `left` and `top` are
2186
+ the mouse coordinates at which the click happened.
2187
+
2188
+ To catch the moment when the mouse is unclicked, see the [[Events.release]] event.
2189
+
2190
+ === finish { |self| ... } » self ===
2191
+
2192
+ When a slot is removed, it's finish event occurs. The finish block is
2193
+ immediately handed `self`, the slot object which has been removed.
2194
+
2195
+ === hover { |self| ... } » self ===
2196
+
2197
+ The hover event happens when the mouse enters the slot. The block gets `self`,
2198
+ meaning the object which was hovered over.
2199
+
2200
+ To catch the mouse exiting the slot, check out the [[Events.leave]] event.
2201
+
2202
+ === keypress { |key| ... } » self ===
2203
+
2204
+ Whenever a key (or combination of keys) is pressed, the block gets called. The
2205
+ block is sent a `key` which is a string representing the character (such as the
2206
+ letter or number) on the key. For special keys and key combos, a Ruby symbol
2207
+ is sent, rather than a string.
2208
+
2209
+ So, for example, if `Shift-a` is pressed, the block will get the string `"A"`.
2210
+
2211
+ However, if the F1 key is pressed, the `:f1` symbol is received. For
2212
+ `Shift-F1`, the symbol would be `:shift_f1`.
2213
+
2214
+ The modifier keys are `control`, `shift` and `alt`. They appear in that order.
2215
+ If `Shift-Control-Alt-PgUp` is pressed, the symbol will be
2216
+ `:control_shift_alt_page_up`.
2217
+
2218
+ One thing about the shift key. You won't see the shift key on most keys. On
2219
+ US keyboards, `Shift-7` is an ampersand. So you'll get the string `"&"` rather
2220
+ than `:shift_5`. And, if you press `Shift-Alt-7` on such a keyboard, you'll
2221
+ get the symbol: `:alt_&`. You'll only see the shift modifier on the special
2222
+ keys listed a few paragraphs down.
2223
+
2224
+ {{{
2225
+ #!ruby
2226
+ Shoes.app do
2227
+ @info = para "NO KEY is PRESSED."
2228
+ keypress do |k|
2229
+ @info.replace "#{k.inspect} was PRESSED."
2230
+ end
2231
+ end
2232
+ }}}
2233
+
2234
+ Keep in mind that Shoes itself uses a few hotkeys. Alt-Period (`:alt_.`),
2235
+ Alt-Question (`:alt_?`) and Alt-Slash (`:alt_/`) are reserved for Shoes.
2236
+
2237
+ The list of special keys is as follows: `:escape`, `:delete`, `:backspace`,
2238
+ `:tab`, `:page_up`, `:page_down`, `:home`, `:end`, `:left`, `:up`, `:right`,
2239
+ `:down`, `:f1`, `:f2`, `:f3`, `:f4`, `:f5`, `:f6`, `:f7`, `:f8`, `:f9`, `:f10`,
2240
+ `:f11` and `:f12`.
2241
+
2242
+ One caveat to all of those rules: normally the Return key gives you a string
2243
+ `"\n"`. When pressed with modifier keys, however, you end up with
2244
+ `:control_enter`, `:control_alt_enter`, `:shift_alt_enter` and the like.
2245
+
2246
+ === leave { |self| ... } » self ===
2247
+
2248
+ The leave event takes place when the mouse cursor exits a slot. The moment it
2249
+ no longer is inside the slot's edges. When that takes place, the block is
2250
+ called with `self`, the slot object which is being left.
2251
+
2252
+ Also see [[Events.hover]] if you'd like to detect the mouse entering a slot.
2253
+
2254
+ === motion { |left, top| ... } » self ===
2255
+
2256
+ The motion block gets called every time the mouse moves around inside the slot.
2257
+ The block is handed the cursor's `left` and `top` coordinates.
2258
+
2259
+ {{{
2260
+ #!ruby
2261
+ Shoes.app :width => 200, :height => 200 do
2262
+ background black
2263
+ fill white
2264
+ @circ = oval 0, 0, 100, 100
2265
+
2266
+ motion do |top, left|
2267
+ @circ.move top - 50, left - 50
2268
+ end
2269
+ end
2270
+ }}}
2271
+
2272
+ === release { |button, left, top| ... } » self ===
2273
+
2274
+ The release block runs whenever the mouse is unclicked (on mouse up). When the
2275
+ finger is lifted. The `button` is the number of the button that was depressed.
2276
+ The `left` and `top` are the coordinates of the mouse at the time the button
2277
+ was released.
2278
+
2279
+ To catch the actual mouse click, use the [[Events.click]] event.
2280
+
2281
+ === start { |self| ... } » self ===
2282
+
2283
+ The first time the slot is drawn, the start event fires. The block is handed
2284
+ `self`, the slot object which has just been drawn.
2285
+
2286
+ == Manipulation Blocks ==
2287
+
2288
+ The manipulation methods below make quick work of shifting around slots and
2289
+ inserting new elements.
2290
+
2291
+ === append() { ... } » self ===
2292
+
2293
+ Adds elements to the end of a slot.
2294
+
2295
+ {{{
2296
+ #!ruby
2297
+ Shoes.app do
2298
+ @slot = stack { para 'Good Morning' }
2299
+ timer 3 do
2300
+ @slot.append do
2301
+ title "Breaking News"
2302
+ tagline "Astronauts arrested for space shuttle DUI."
2303
+ end
2304
+ end
2305
+ end
2306
+ }}}
2307
+
2308
+ The `title` and `tagline` elements will be added to the end of the `@slot`.
2309
+
2310
+ === after(element) { ... } » self ===
2311
+
2312
+ Adds elements to a specific place in a slot, just after the `element` which is
2313
+ a child of the slot.
2314
+
2315
+ === before(element) { ... } » self ===
2316
+
2317
+ Adds elements to a specific place in a slot, just before the `element` which is
2318
+ a child of the slot.
2319
+
2320
+ === clear() » self ===
2321
+
2322
+ Empties the slot of any elements, timers and nested slots. This is effectively
2323
+ identical to looping through the contents of the slot and calling each
2324
+ element's `remove` method.
2325
+
2326
+ === clear() { ... } » self ===
2327
+
2328
+ The clear method also takes an optional block. The block will be used to
2329
+ replace the contents of the slot.
2330
+
2331
+ {{{
2332
+ #!ruby
2333
+ Shoes.app do
2334
+ @slot = stack { para "Old text" }
2335
+ timer 3 do
2336
+ @slot.clear { para "Brand new text" }
2337
+ end
2338
+ end
2339
+ }}}
2340
+
2341
+ In this example, the "Old text" paragraph will be cleared out, replaced by the
2342
+ "Brand new text" paragraph.
2343
+
2344
+ === prepend() { ... } » self ===
2345
+
2346
+ Adds elements to the beginning of a slot.
2347
+
2348
+ {{{
2349
+ #!ruby
2350
+ Shoes.app do
2351
+ @slot = stack { para 'Good Morning' }
2352
+ timer 3 do
2353
+ @slot.prepend { para "Your car is ready." }
2354
+ end
2355
+ end
2356
+ }}}
2357
+
2358
+ The `para` element is added to the beginning of the `@slot`.
2359
+
2360
+ == Position of a Slot ==
2361
+
2362
+ Like any other element, slots can be styled and customized when they are created.
2363
+
2364
+ To set the width of a stack to 150 pixels:
2365
+
2366
+ {{{
2367
+ #!ruby
2368
+ Shoes.app do
2369
+ stack(:width => 150) { para "Now that's precision." }
2370
+ end
2371
+ }}}
2372
+
2373
+ Each style setting also has a method, which can be used to grab that particular
2374
+ setting. (So, like, the `width` method returns the width of the slot in
2375
+ pixels.)
2376
+
2377
+ === displace(left: a number, top: a number) » self ===
2378
+
2379
+ A shortcut method for setting the :displace_left and :displace_top styles.
2380
+ Displacing is a handy way of moving a slot without altering the layout. In
2381
+ fact, the `top` and `left` methods will not report displacement at all. So,
2382
+ generally, displacement is only for temporary animations. For example,
2383
+ jiggling a button in place.
2384
+
2385
+ The `left` and `top` numbers sent to `displace` are added to the slot's own
2386
+ top-left coordinates. To subtract from the top-left coordinate, use negative
2387
+ numbers.
2388
+
2389
+ === gutter() » a number ===
2390
+
2391
+ The size of the scrollbar area. When Shoes needs to show a scrollbar, the
2392
+ scrollbar may end up covering up some elements that touch the edge of the
2393
+ window. The `gutter` tells you how many pixels to expect the scrollbar to
2394
+ cover.
2395
+
2396
+ This is commonly used to pad elements on the right, like so:
2397
+
2398
+ {{{
2399
+ #!ruby
2400
+ Shoes.app do
2401
+ stack :margin_right => 20 + gutter do
2402
+ para "Insert fat and ratified declaration of independence here..."
2403
+ end
2404
+ end
2405
+ }}}
2406
+
2407
+ === height() » a number ===
2408
+
2409
+ The vertical size of the viewable slot in pixels. So, if this is a scrolling
2410
+ slot, you'll need to use `scroll_height()` to get the full size of the slot.
2411
+
2412
+ === hide() » self ===
2413
+
2414
+ Hides the slot, so that it can't be seen. See also [[Position.show]] and [[Position.toggle]].
2415
+
2416
+ === left() » a number ===
2417
+
2418
+ The left pixel location of the slot. Also known as the x-axis coordinate.
2419
+
2420
+ === move(left, top) » self ===
2421
+
2422
+ Moves the slot to specific coordinates, the (left, top) being the upper left
2423
+ hand corner of the slot.
2424
+
2425
+ === remove() » self ===
2426
+
2427
+ Removes the slot. It will no longer be displayed and will not be listed in its
2428
+ parent's contents. It's gone.
2429
+
2430
+ === scroll() » true or false ===
2431
+
2432
+ Is this slot allowed to show a scrollbar? True or false. The scrollbar will
2433
+ only appear if the height of the slot is also fixed.
2434
+
2435
+ === scroll_height() » a number ===
2436
+
2437
+ The vertical size of the full slot, including any of it which is hidden by scrolling.
2438
+
2439
+ === scroll_max() » a number ===
2440
+
2441
+ The top coordinate which this slot can be scrolled down to. The top coordinate
2442
+ of a scroll bar is always zero. The bottom coordinate is the full height of
2443
+ the slot minus one page of scrolling. This bottom coordinate is what
2444
+ `scroll_max` returns.
2445
+
2446
+ This is basically a shortcut for writing `slot.scroll_height - slot.height`.
2447
+
2448
+ To scroll to the bottom of a slot, use `slot.scroll_top = slot.scroll_max`.
2449
+
2450
+ === scroll_top() » a number ===
2451
+
2452
+ The top coordinate which this slot is scrolled down to. So, if the slot is
2453
+ scrolled down twenty pixels, this method will return `20`.
2454
+
2455
+ === scroll_top = a number ===
2456
+
2457
+ Scrolls the slot to a certain coordinate. This must be between zero and
2458
+ `scroll_max`.
2459
+
2460
+ === show() » self ===
2461
+
2462
+ Reveals the slot, if it is hidden. See also [[Position.hide]] and
2463
+ [[Position.toggle]].
2464
+
2465
+ === style() » styles ===
2466
+
2467
+ Calling the `style` method with no arguments returns a hash of the styles
2468
+ presently applied to this slot.
2469
+
2470
+ While methods such as `height` and `width` return the true pixel dimensions of
2471
+ the slot, you can use `style[:height]` or `style[:width]` to get the dimensions
2472
+ originally requested.
2473
+
2474
+ {{{
2475
+ #!ruby
2476
+ Shoes.app do
2477
+ @s = stack :width => "100%"
2478
+ para @s.style[:width]
2479
+ end
2480
+ }}}
2481
+
2482
+ In this example, the paragraph under the stack will display the string "100%".
2483
+
2484
+ === style(styles) » styles ===
2485
+
2486
+ Alter the slot using a hash of style settings. Any of the methods on this page
2487
+ (aside from this method, of course) can be used as a style setting. So, for
2488
+ example, there is a `width` method, thus there is also a `width` style.
2489
+
2490
+ {{{
2491
+ #!ruby
2492
+ Shoes.app do
2493
+ @s = stack { background green }
2494
+ @s.style(:width => 400, :height => 200)
2495
+ end
2496
+ }}}
2497
+
2498
+ === toggle() » self ===
2499
+
2500
+ Hides the slot, if it is shown. Or shows the slot, if it is hidden.
2501
+
2502
+ === top() » a number ===
2503
+
2504
+ The top pixel location of the slot. Also known as the y-axis coordinate.
2505
+
2506
+ === width() » a number ===
2507
+
2508
+ The horizontal size of the slot in pixels.
2509
+
2510
+ == Traversing the Page ==
2511
+
2512
+ You may find yourself needing to loop through the elements inside a slot. Or
2513
+ maybe you need to climb the page, looking for a stack that is the parent of an
2514
+ element.
2515
+
2516
+ On any element, you may call the `parent` method to get the slot directly above
2517
+ it. And on slots, you can call the `contents` method to get all of the
2518
+ children. (Some elements, such as text blocks, also have a `contents` method
2519
+ for getting their children.)
2520
+
2521
+ === contents() » an array of elements ===
2522
+
2523
+ Lists all elements in a slot.
2524
+
2525
+ === parent() » a Shoes::Stack or Shoes::Flow ===
2526
+
2527
+ Gets the object for this element's container.
2528
+
2529
+ = Elements =
2530
+
2531
+ Ah, here's the stuff of Shoes. An element can be as simple as an oval shape. Or
2532
+ as complex as a video stream. You've encountered all of these elements before
2533
+ in the Slots section of th manual.
2534
+
2535
+ Shoes has seven native controls: the Button, the EditLine, the EditBox, the
2536
+ ListBox, the Progress meter, the Check box and the Radio. By "native"
2537
+ controls, we mean that each of these seven elements is drawn by the operating
2538
+ system. So, a Progress bar will look one way on Windows and another way on OS
2539
+ X.
2540
+
2541
+ Shoes also has seven basic other types of elements: Background, Border, Image,
2542
+ Shape, TextBlock, Timer and Video. These all should look and act the same on
2543
+ every operating system.
2544
+
2545
+ Once an element is created, you will often still want to change it. To move it
2546
+ or hide it or get rid of it. You'll use the commands in this section to do that
2547
+ sort of stuff. (Especially check out the [[Common Common Methods]] section for
2548
+ commands you can use on any element.)
2549
+
2550
+ So, for example, use the `image` method of a Slot to place a PNG on the screen.
2551
+ The `image` method gives you back an Image object. Use the methods of the Image
2552
+ object to change things up.
2553
+
2554
+ == Common Methods ==
2555
+
2556
+ A few methods are shared by every little element in Shoes. Moving, showing,
2557
+ hiding. Removing an element. Basic and very general things. This list
2558
+ encompasses those common commands.
2559
+
2560
+ One of the most general methods of all is the `style` method (which is also
2561
+ covered as the [[Position.style]] method for slots.)
2562
+
2563
+ {{{
2564
+ #!ruby
2565
+ Shoes.app do
2566
+ stack do
2567
+ # Background, text and a button: both are elements!
2568
+ @back = background green
2569
+ @text = banner "A Message for You, Rudy"
2570
+ @press = button "Stop your messin about!"
2571
+
2572
+ # And so, both can be styled.
2573
+ @text.style :size => 12, :stroke => red, :margin => 10
2574
+ @press.style :width => 400
2575
+ @back.style :height => 10
2576
+ end
2577
+ end
2578
+ }}}
2579
+
2580
+ For specific commands, see the other links to the left in the Elements section.
2581
+ Like if you want to pause or play a video file, check the [[Video]] section,
2582
+ since pausing and playing is peculiar to videos. No sense pausing a button.
2583
+
2584
+ === displace(left: a number, top: a number) » self ===
2585
+
2586
+ Displacing an element moves it. But without changing the layout around it.
2587
+ This is great for subtle animations, especially if you want to reserve a place
2588
+ for an element while it is still animating. Like maybe a quick button shake or
2589
+ a slot sliding into view.
2590
+
2591
+ When you displace an element, it moves relative to the upper-left corner where
2592
+ it was placed. So, if an element is at the coordinates (20, 40) and you
2593
+ displace it 2 pixels left and 6 pixels on top, you end up with the coordinates
2594
+ (22, 46).
2595
+
2596
+ {{{
2597
+ #!ruby
2598
+ Shoes.app do
2599
+ flow :margin => 12 do
2600
+ # Set up three buttons
2601
+ button "One"
2602
+ @two = button "Two"
2603
+ button "Three"
2604
+
2605
+ # Bounce the second button
2606
+ animate do |i|
2607
+ @two.displace(0, (Math.sin(i) * 6).to_i)
2608
+ end
2609
+ end
2610
+ end
2611
+ }}}
2612
+
2613
+ Notice that while the second button bounces, the other two buttons stay put.
2614
+ If we used a normal `move` in this situation, the second button would be moved
2615
+ out of the layout and the buttons would act as if the second button wasn't
2616
+ there at all. (See the [[Common.move]] example.)
2617
+
2618
+ '''Of particular note:''' if you use the `left` and `top` methods to get the
2619
+ coordinates of a displaced element, you'll just get back the normal
2620
+ coordinates. As if there was no displacement. Displacing is just intended for
2621
+ quick animations!
2622
+
2623
+ === height() » a number ===
2624
+
2625
+ The vertical screen size of the element in pixels. In the case of images, this
2626
+ is not the full size of the image. This is the height of the element as it is
2627
+ shown right now.
2628
+
2629
+ If you have a 150x150 pixel image and you set the width to 50 pixels, this
2630
+ method will return 50.
2631
+
2632
+ Also see the [[Common.width]] method for an example and some other comments.
2633
+
2634
+ === hide() » self ===
2635
+
2636
+ Hides the element, so that it can't be seen. See also [[Common.show]] and
2637
+ [[Common.toggle]].
2638
+
2639
+ === left() » a number ===
2640
+
2641
+ Gets you the pixel position of the left edge of the element.
2642
+
2643
+ === move(left: a number, top: a number) » self ===
2644
+
2645
+ Moves the element to a specific pixel position within its slot. The element is
2646
+ still inside the slot. But it will no longer be stacked or flowed in with the
2647
+ other stuff in the slot. The element will float freely, now absolutely
2648
+ positioned instead.
2649
+
2650
+ {{{
2651
+ #!ruby
2652
+ Shoes.app do
2653
+ flow :margin => 12 do
2654
+ # Set up three buttons
2655
+ button "One"
2656
+ @two = button "Two"
2657
+ button "Three"
2658
+
2659
+ # Bounce the second button
2660
+ animate do |i|
2661
+ @two.move(40, 40 + (Math.sin(i) * 6).to_i)
2662
+ end
2663
+ end
2664
+ end
2665
+ }}}
2666
+
2667
+ The second button is moved to a specific place, allowing the third button to
2668
+ slide over into its place. If you want to move an element without shifting
2669
+ other pieces, see the [[Common.displace]] method.
2670
+
2671
+ === parent() » a Shoes::Stack or Shoes::Flow ===
2672
+
2673
+ Gets the object for this element's container. Also see the slot's
2674
+ [[Traversing.contents]] to do the opposite: get a container's elements.
2675
+
2676
+ === remove() » self ===
2677
+
2678
+ Removes the element from its slot. (In other words: throws it in the garbage.)
2679
+ The element will no longer be displayed.
2680
+
2681
+ === show() » self ===
2682
+
2683
+ Reveals the element, if it is hidden. See also [[Common.hide]] and
2684
+ [[Common.toggle]].
2685
+
2686
+ === style() » styles ===
2687
+
2688
+ Gives you the full set of styles applied to this element, in the form of a
2689
+ Hash. While methods like `width` and `height` and `top` give you back specific
2690
+ pixel dimensions, using `style[:width]` or `style[:top]`, you can get the
2691
+ original setting (things like "100%" for width or "10px" for top.)
2692
+
2693
+ {{{
2694
+ #!ruby
2695
+ Shoes.app do
2696
+ # A button which take up the whole page
2697
+ @b = button "All of it", :width => 1.0, :height => 1.0
2698
+
2699
+ # When clicked, show the styles
2700
+ @b.click { alert(@b.style.inspect) }
2701
+ end
2702
+ }}}
2703
+
2704
+ === style(styles) » styles ===
2705
+
2706
+ Changes the style of an element. This could include the `:width` and `:height`
2707
+ of an element, the font `:size` of some text, the `:stroke` and `:fill` of a
2708
+ shape. Or any other number of style settings.
2709
+
2710
+ === toggle() » self ===
2711
+
2712
+ Hides an element if it is shown. Or shows the element, if it is hidden.
2713
+
2714
+ === top() » a number ===
2715
+
2716
+ Gets the pixel position of the top edge of the element.
2717
+
2718
+ === width() » a number ===
2719
+
2720
+ Gets the pixel width for the full size of the element. This method always
2721
+ returns an exact pixel size. In the case of images, this is not the full width
2722
+ of the image, just the size it is shown at. See the [[Common.height]] method
2723
+ for more.
2724
+
2725
+ Also, if you create an element with a width of 100% and that element is inside
2726
+ a stack which is 120 pixels wide, you'll get back `120`. However, if you call
2727
+ `style[:width]`, you'll get `"100%"`.
2728
+
2729
+ {{{
2730
+ #!ruby
2731
+ Shoes.app do
2732
+ stack :width => 120 do
2733
+ @b = button "Click me", :width => "100%" do
2734
+ alert "button.width = #{@b.width}\n" +
2735
+ "button.style[:width] = #{@b.style[:width]}"
2736
+ end
2737
+ end
2738
+ end
2739
+ }}}
2740
+
2741
+ In order to set the width, you'll have to go through the [[Common.style]]
2742
+ method again. So, to set the button to 150 pixels wide: `@b.style(:width =>
2743
+ 150)`.
2744
+
2745
+ To let Shoes pick the element's width, go with `@b.style(:width => nil)` to
2746
+ empty out the setting.
2747
+
2748
+ == Background ==
2749
+
2750
+ A background is a color, a gradient or an image that is painted across an
2751
+ entire slot. Both backgrounds and borders are a type of Shoes::Pattern.
2752
+ !{:margin_left => 100}man-ele-background.png!
2753
+
2754
+ Even though it's called a ''background'', you may still place this element in
2755
+ front of other elements. If a background comes after something else painted on
2756
+ the slot (like a `rect` or an `oval`,) the background will be painted over that
2757
+ element.
2758
+
2759
+ The simplest background is just a plain color background, created with the
2760
+ [[Element.background]] method, such as this black background:
2761
+
2762
+ {{{
2763
+ #!ruby
2764
+ Shoes.app do
2765
+ background black
2766
+ end
2767
+ }}}
2768
+
2769
+ A simple background like that paints the entire slot that contains it. (In
2770
+ this case, the whole window is painted black.)
2771
+
2772
+ You can use styles to cut down the size or move around the background to your liking.
2773
+
2774
+ To paint a black background across the top fifty pixels of the window:
2775
+
2776
+ {{{
2777
+ #!ruby
2778
+ Shoes.app do
2779
+ background black, :height => 50
2780
+ end
2781
+ }}}
2782
+
2783
+ Or, to paint a fifty pixel column on the right-side of the window:
2784
+
2785
+ {{{
2786
+ #!ruby
2787
+ Shoes.app do
2788
+ background black, :width => 50, :right => 50
2789
+ end
2790
+ }}}
2791
+
2792
+ Since Backgrounds are normal elements as well, see also the start of the
2793
+ [[Elements]] section for all of its other methods.
2794
+
2795
+ === to_pattern() » a Shoes::Pattern ===
2796
+
2797
+ Yanks out the color, gradient or image used to paint this background and places
2798
+ it in a normal Shoes::Pattern object. You can then pass that object to other
2799
+ backgrounds and borders. Reuse it as you like.
2800
+
2801
+ == Border ==
2802
+
2803
+ A border is a color, gradient or image painted in a line around the edge of any
2804
+ slot. Like the Background element in the last section, a Border is a kind of
2805
+ Shoes::Pattern. !{:margin_left => 100}man-ele-border.png!
2806
+
2807
+ The first, crucial thing to know about border is that all borders paint a line
2808
+ around the '''inside''' of a slot, not the outside. So, if you have a slot
2809
+ which is fifty pixels wide and you paint a five pixel border on it, that means
2810
+ there is a fourty pixel wide area inside the slot which is surrounded by the
2811
+ border.
2812
+
2813
+ This also means that if you paint a Border on top of a [[Background]], the
2814
+ edges of the background will be painted over by the border.
2815
+
2816
+ Here is just such a slot:
2817
+
2818
+ {{{
2819
+ #!ruby
2820
+ Shoes.app do
2821
+ stack :width => 50 do
2822
+ border black, :strokewidth => 5
2823
+ para "=^.^=", :stroke => green
2824
+ end
2825
+ end
2826
+ }}}
2827
+
2828
+ If you want to paint a border around the outside of a slot, you'll need to wrap
2829
+ that slot in another slot. Then, place the border in the outside slot.
2830
+
2831
+ {{{
2832
+ #!ruby
2833
+ Shoes.app do
2834
+ stack :width => 60 do
2835
+ border black, :strokewidth => 5
2836
+ stack :width => 50 do
2837
+ para "=^.^=", :stroke => green
2838
+ end
2839
+ end
2840
+ end
2841
+ }}}
2842
+
2843
+ In HTML and many other languages, the border is painted on the outside of the
2844
+ box, thus increasing the overall width of the box. Shoes was designed with
2845
+ consistency in mind, so that if you say that a box is fifty pixels wide, it
2846
+ stays fifty pixels wide regardless of its borders or margins or anything else.
2847
+
2848
+ Please also check out the [[Elements]] section for other methods used on borders.
2849
+
2850
+ === to_pattern() » a Shoes::Pattern ===
2851
+
2852
+ Creates a basic pattern object based on the color, gradient or image used to
2853
+ paint this border. The pattern may then be re-used in new borders and
2854
+ backgrounds.
2855
+
2856
+ == Button ==
2857
+
2858
+ Buttons are, you know, push buttons. You click them and they do something.
2859
+ Buttons are known to say "OK" or "Are you sure?" And, then, if you're sure,
2860
+ you click the button. !{:margin_left => 100}man-ele-button.png!
2861
+
2862
+ {{{
2863
+ #!ruby
2864
+ Shoes.app do
2865
+ button "OK!"
2866
+ button "Are you sure?"
2867
+ end
2868
+ }}}
2869
+
2870
+ The buttons in the example above don't do anything when you click them. In
2871
+ order to get them to work, you've got to hook up a block to each button.
2872
+
2873
+ {{{
2874
+ #!ruby
2875
+ Shoes.app do
2876
+ button "OK!" do
2877
+ append { para "Well okay then." }
2878
+ end
2879
+ button "Are you sure?" do
2880
+ append { para "Your confidence is inspiring." }
2881
+ end
2882
+ end
2883
+ }}}
2884
+
2885
+ So now we've got blocks for the buttons. Each block appends a new paragraph to
2886
+ the page. The more you click, the more paragraphs get added.
2887
+
2888
+ It doesn't go much deeper than that. A button is just a clickable phrase.
2889
+
2890
+ Just to be pedantic, though, here's another way to write that last example.
2891
+
2892
+ {{{
2893
+ #!ruby
2894
+ Shoes.app do
2895
+ @b1 = button "OK!"
2896
+ @b1.click { para "Well okay then." }
2897
+ @b2 = button "Are you sure?"
2898
+ @b2.click { para "Your confidence is inspiring." }
2899
+ end
2900
+ }}}
2901
+
2902
+ This looks dramatically different, but it does the same thing. The first
2903
+ difference: rather than attaching the block directly to the button, the block
2904
+ is attached later, through the `click` method.
2905
+
2906
+ The second change isn't related to buttons at all. The `append` block was
2907
+ dropped since Shoes allows you to add new elements directly to the slot. So we
2908
+ can just call `para` directly. (This isn't the case with the `prepend`,
2909
+ `before` or `after` methods.)
2910
+
2911
+ Beside the methods below, buttons also inherit all of the methods that are
2912
+ [[Common]].
2913
+
2914
+ === click() { |self| ... } » self ===
2915
+
2916
+ When a button is clicked, its `click` block is called. The block is handed
2917
+ `self`. Meaning: the button which was clicked.
2918
+
2919
+ === focus() » self ===
2920
+
2921
+ Moves focus to the button. The button will be highlighted and, if the user
2922
+ hits Enter, the button will be clicked.
2923
+
2924
+ == Check ==
2925
+
2926
+ Check boxes are clickable square boxes than can be either checked or unchecked.
2927
+ A single checkbox usually asks a "yes" or "no" question. Sets of checkboxes
2928
+ are also seen in to-do lists. !{:margin_left => 100}man-ele-check.png!
2929
+
2930
+ Here's a sample checklist.
2931
+
2932
+ {{{
2933
+ #!ruby
2934
+ Shoes.app do
2935
+ stack do
2936
+ flow { check; para "Frances Johnson" }
2937
+ flow { check; para "Ignatius J. Reilly" }
2938
+ flow { check; para "Winston Niles Rumfoord" }
2939
+ end
2940
+ end
2941
+ }}}
2942
+
2943
+ You basically have two ways to use a check. You can attach a block to the
2944
+ check and it'll get called when the check gets clicked. And/or you can just
2945
+ use the `checked?` method to go back and see if a box has been checked or not.
2946
+
2947
+ Okay, let's add to the above example.
2948
+
2949
+ {{{
2950
+ #!ruby
2951
+ Shoes.app do
2952
+ @list = ['Frances Johnson', 'Ignatius J. Reilly',
2953
+ 'Winston Niles Rumfoord']
2954
+
2955
+ stack do
2956
+ @list.map! do |name|
2957
+ flow { @c = check; para name }
2958
+ [@c, name]
2959
+ end
2960
+
2961
+ button "What's been checked?" do
2962
+ selected = @list.map { |c, name| name if c.checked? }.compact
2963
+ alert("You selected: " + selected.join(', '))
2964
+ end
2965
+ end
2966
+ end
2967
+ }}}
2968
+
2969
+ So, when the button gets pressed, each of the checks gets asked for its status,
2970
+ using the `checked?` method.
2971
+
2972
+ Button methods are listed below, but also see the list of [[Common]] methods,
2973
+ which all elements respond to.
2974
+
2975
+ === checked?() » true or false ===
2976
+
2977
+ Returns whether the box is checked or not. So, `true` means "yes, the box is checked!"
2978
+
2979
+ === checked = true or false ===
2980
+
2981
+ Marks or unmarks the check box. Using `checked = false`, for instance,
2982
+ unchecks the box.
2983
+
2984
+ === click() { |self| ... } » self ===
2985
+
2986
+ When the check is clicked, its `click` block is called. The block is handed
2987
+ `self`, which is the check object which was clicked.
2988
+
2989
+ Clicks are sent for both checking and unchecking the box.
2990
+
2991
+ === focus() » self ===
2992
+
2993
+ Moves focus to the check. The check will be highlighted and, if the user hits
2994
+ Enter, the check will be toggled between its checked and unchecked states.
2995
+
2996
+ == EditBox ==
2997
+
2998
+ Edit boxes are wide, rectangular boxes for entering text. On the web, they
2999
+ call these textareas. These are multi-line edit boxes for entering longer
3000
+ descriptions. Essays, even! !{:margin_left => 100}man-ele-editbox.png!
3001
+
3002
+ Without any other styling, edit boxes are sized 200 pixels by 108 pixels. You
3003
+ can also use `:width` and `:height` styles to set specific sizes.
3004
+
3005
+ {{{
3006
+ #!ruby
3007
+ Shoes.app do
3008
+ edit_box
3009
+ edit_box :width => 100, :height => 100
3010
+ end
3011
+ }}}
3012
+
3013
+ Other controls (like [[Button]] and [[Check]]) have only click events, but both
3014
+ [[EditLine]] and EditBox have a `change` event. The `change` block is called
3015
+ every time someone types into or deletes from the box.
3016
+
3017
+ {{{
3018
+ #!ruby
3019
+ Shoes.app do
3020
+ edit_box do |e|
3021
+ @counter.text = e.text.size
3022
+ end
3023
+ @counter = strong("0")
3024
+ para @counter, " characters"
3025
+ end
3026
+ }}}
3027
+
3028
+ Notice that the example also uses the [[EditBox.text]] method inside the block.
3029
+ That method gives you a string of all the characters typed into the box.
3030
+
3031
+ More edit box methods are listed below, but also see the list of [[Common]]
3032
+ methods, which all elements respond to.
3033
+
3034
+ === change() { |self| ... } » self ===
3035
+
3036
+ Each time a character is added to or removed from the edit box, its `change`
3037
+ block is called. The block is given `self`, which is the edit box object which
3038
+ has changed.
3039
+
3040
+ === focus() » self ===
3041
+
3042
+ Moves focus to the edit box. The edit box will be highlighted and the user will
3043
+ be able to type into the edit box.
3044
+
3045
+ === text() » self ===
3046
+
3047
+ Return a string of characters which have been typed into the box.
3048
+
3049
+ === text = a string ===
3050
+
3051
+ Fills the edit box with the characters of `a string`.
3052
+
3053
+ == EditLine ==
3054
+
3055
+ Edit lines are a slender, little box for entering text. While the EditBox is
3056
+ multi-line, an edit line is just one. Line, that is. Horizontal, in fact.
3057
+ !{:margin_left => 100}man-ele-editline.png!
3058
+
3059
+ The unstyled edit line is 200 pixels wide and 28 pixels wide. Roughly. The
3060
+ height may vary on some platforms.
3061
+
3062
+ {{{
3063
+ #!ruby
3064
+ Shoes.app do
3065
+ stack do
3066
+ edit_line
3067
+ edit_line :width => 400
3068
+ end
3069
+ end
3070
+ }}}
3071
+
3072
+ You can change the size by styling both the `:width` and the `:height`.
3073
+ However, you generally only want to style the `:width`, as the height will be
3074
+ sized to fit the font. (And, in current versions of Shoes, the font for edit
3075
+ lines and edit boxes cannot be altered anyway.)
3076
+
3077
+ If a block is given to an edit line, it receives `change` events. Check out the
3078
+ [[EditBox]] page for an example of using a change block. In fact, the edit box
3079
+ has all the same methods as an edit line. Also see the list of [[Common]]
3080
+ methods, which all elements respond to.
3081
+
3082
+ === change() { |self| ... } » self ===
3083
+
3084
+ Each time a character is added to or removed from the edit line, its `change`
3085
+ block is called. The block is given `self`, which is the edit line object which
3086
+ has changed.
3087
+
3088
+ === focus() » self ===
3089
+
3090
+ Moves focus to the edit line. The edit line will be highlighted and the user
3091
+ will be able to type into the edit line.
3092
+
3093
+ === text() » self ===
3094
+
3095
+ Return a string of characters which have been typed into the box.
3096
+
3097
+ === text = a string ===
3098
+
3099
+ Fills the edit line with the characters of `a string`.
3100
+
3101
+ == Image ==
3102
+
3103
+ An image is a picture in PNG, JPEG or GIF format. Shoes can resize images or
3104
+ flow them in with text. Images can be loaded from a file or directly off the
3105
+ web. !{:margin_left => 100}man-ele-image.png!
3106
+
3107
+ To create an image, use the `image` method in a slot:
3108
+
3109
+ {{{
3110
+ #!ruby
3111
+ Shoes.app do
3112
+ para "Nice, nice, very nice. Busy, busy, busy."
3113
+ image "static/shoes-manual-apps.gif"
3114
+ end
3115
+ }}}
3116
+
3117
+ When you load any image into Shoes, it is cached in memory. This means that if
3118
+ you load up many image elements from the same file, it'll only really load the
3119
+ file once.
3120
+
3121
+ You can use web URLs directly as well.
3122
+
3123
+ {{{
3124
+ #!ruby
3125
+ Shoes.app do
3126
+ image "http://hacketyhack.heroku.com/images/logo.png"
3127
+ end
3128
+ }}}
3129
+
3130
+ When an image is loaded from the web, it's cached on the hard drive as well as
3131
+ in memory. This prevents a repeat download unless the image has changed. (In
3132
+ case you're wondering: Shoes keeps track of modification times and etags just
3133
+ like a browser would.)
3134
+
3135
+ Shoes also loads remote images in the background using system threads. So,
3136
+ using remote images will not block Ruby or any intense graphical displays you
3137
+ may have going on.
3138
+
3139
+ === full_height() » a number ===
3140
+
3141
+ The full pixel height of the image. Normally, you can just use the
3142
+ [[Common.height]] method to figure out how many pixels high the image is. But
3143
+ if you've resized the image or styled it to be larger or something, then
3144
+ `height` will return the scaled size.
3145
+
3146
+ The `full_height` method gives you the height of image (in pixels) as it was
3147
+ stored in the original file.
3148
+
3149
+ === full_width() » a number ===
3150
+
3151
+ The full pixel width of the image. See the [[Image.full_height]] method for an
3152
+ explanation of why you might use this method rather than [[Common.width]].
3153
+
3154
+ === path() » a string ===
3155
+
3156
+ The URL or file name of the image.
3157
+
3158
+ === path = a string ===
3159
+
3160
+ Swaps the image with a different one, loaded from a file or URL.
3161
+
3162
+ == ListBox ==
3163
+
3164
+ List boxes (also called "combo boxes" or "drop-down boxes" or "select boxes" in
3165
+ some places) are a list of options that drop down when you click on the box.
3166
+ !{:margin_left => 100}man-ele-listbox.png!
3167
+
3168
+ A list box gets its options from an array. An array (a list) of strings,
3169
+ passed into the `:items` style.
3170
+
3171
+ {{{
3172
+ #!ruby
3173
+ Shoes.app do
3174
+ para "Choose a fruit:"
3175
+ list_box :items => ["Grapes", "Pears", "Apricots"]
3176
+ end
3177
+ }}}
3178
+
3179
+ So, the basic size of a list box is about 200 pixels wide and 28 pixels high.
3180
+ You can adjust this length using the `:width` style.
3181
+
3182
+ {{{
3183
+ #!ruby
3184
+ Shoes.app do
3185
+ para "Choose a fruit:"
3186
+ list_box :items => ["Grapes", "Pears", "Apricots"],
3187
+ :width => 120, :choose => "Apricots" do |list|
3188
+ @fruit.text = list.text
3189
+ end
3190
+
3191
+ @fruit = para "No fruit selected"
3192
+ end
3193
+ }}}
3194
+
3195
+ Next to the `:width` style, the example uses another useful option. The
3196
+ `:choose` option tells the list box which of the items should be highlighted
3197
+ from the beginning. (There's also a [[ListBox.choose]] method for highlighting
3198
+ an item after the box is created.)
3199
+
3200
+ List boxes also have a [[ListBox.change]] event. In the last example, we've got
3201
+ a block hooked up to the list box. Well, okay, see, that's a `change` block.
3202
+ The block is called each time someone changes the selected item.
3203
+
3204
+ Those are the basics. Might you also be persuaded to look at the [[Common]]
3205
+ methods page, a complete list of the methods that all elements have?
3206
+
3207
+ === change() { |self| ... } » self ===
3208
+
3209
+ Whenever someone highlights a new option in the list box (by clicking on an
3210
+ item, for instance,) its `change` block is called. The block is given `self`,
3211
+ which is the list box object which has changed.
3212
+
3213
+ === choose(item: a string) » self ===
3214
+
3215
+ Selects the option in the list box that matches the string given by `item`.
3216
+
3217
+ === focus() » self ===
3218
+
3219
+ Moves focus to the list box. The list box will be highlighted and, if the user
3220
+ hits the up and down arrow keys, other options in the list will be selected.
3221
+
3222
+ === items() » an array of strings ===
3223
+
3224
+ Returns the complete list of strings that the list box presently shows as its options.
3225
+
3226
+ === items = an array of strings ===
3227
+
3228
+ Replaces the list box's options with a new list of strings.
3229
+
3230
+ === text() » a string ===
3231
+
3232
+ A string containing whatever text is shown highlighted in the list box right
3233
+ now. If nothing is selected, `nil` will be the reply.
3234
+
3235
+ == Progress ==
3236
+
3237
+ Progress bars show you how far along you are in an activity. Usually, a
3238
+ progress bar represents a percentage (from 0% to 100%.) Shoes thinks of
3239
+ progress in terms of the decimal numbers 0.0 to 1.0. !{:margin_left =>
3240
+ 100}man-ele-progress.png!
3241
+
3242
+ A simple progress bar is 200 pixels wide, but you can use the `:width` style
3243
+ (as with all Shoes elements) to lengthen it.
3244
+
3245
+ {{{
3246
+ Shoes.app do
3247
+ stack :margin => 0.1 do
3248
+ title "Progress example"
3249
+ @p = progress :width => 1.0
3250
+
3251
+ animate do |i|
3252
+ @p.fraction = (i % 100) / 100.0
3253
+ end
3254
+ end
3255
+ end
3256
+ }}}
3257
+
3258
+ Take a look at the [[Common]] methods page for a list of methods found an all
3259
+ elements, including progress bars.
3260
+
3261
+ === fraction() » a decimal number ===
3262
+
3263
+ Returns a decimal number from 0.0 to 1.0, indicating how far along the progress bar is.
3264
+
3265
+ === fraction = a decimal number ===
3266
+
3267
+ Sets the progress to a decimal number between 0.0 and 1.0.
3268
+
3269
+ == Radio ==
3270
+
3271
+ Radio buttons are a group of clickable circles. Click a circle and it'll be
3272
+ marked. Only one radio button can be marked at a time. (This is similar to the
3273
+ ListBox, where only one option can be selected at a time.) !{:margin_left =>
3274
+ 100}man-ele-radio.png!
3275
+
3276
+ So, how do you decide when to use radio buttons and when to use list boxes?
3277
+ Well, list boxes only show one highlighted item unless you click on the box and
3278
+ the drop-down appears. But radio buttons are all shown, regardless of which is
3279
+ marked.
3280
+
3281
+ {{{
3282
+ #!ruby
3283
+ Shoes.app do
3284
+ para "Among these films, which do you prefer?\n"
3285
+ radio; para strong("The Taste of Tea"), " by Katsuhito Ishii\n"
3286
+ radio; para strong("Kin-Dza-Dza"), " by Georgi Danelia\n"
3287
+ radio; para strong("Children of Heaven"), " by Majid Majidi\n"
3288
+ end
3289
+ }}}
3290
+
3291
+ Only one of these three radios can be checked at a time, since they are grouped
3292
+ together in the same slot (along with a bunch of `para`.)
3293
+
3294
+ If we move them each into their own slot, the example breaks.
3295
+
3296
+ {{{
3297
+ #!ruby
3298
+ Shoes.app do
3299
+ stack do
3300
+ para "Among these films, which do you prefer?"
3301
+ flow { radio; para "The Taste of Tea by Katsuhito Ishii" }
3302
+ flow { radio; para "Kin-Dza-Dza by Georgi Danelia" }
3303
+ flow { radio; para "Children of Heaven by Majid Majidi" }
3304
+ end
3305
+ end
3306
+ }}}
3307
+
3308
+ This can be fixed, though. You can group together radios from different slots,
3309
+ you just have to give them all the same group name.
3310
+
3311
+ Here, let's group all these radios in the `:films` group.
3312
+
3313
+ {{{
3314
+ #!ruby
3315
+ Shoes.app do
3316
+ stack do
3317
+ para "Among these films, which do you prefer?"
3318
+ flow do
3319
+ radio :films
3320
+ para "The Taste of Tea by Katsuhito Ishii"
3321
+ end
3322
+ flow do
3323
+ radio :films
3324
+ para "Kin-Dza-Dza by Georgi Danelia"
3325
+ end
3326
+ flow do
3327
+ radio :films
3328
+ para "Children of Heaven by Majid Majidi"
3329
+ end
3330
+ end
3331
+ end
3332
+ }}}
3333
+
3334
+ For more methods beyond those listed below, also look into the [[Common]]
3335
+ methods page. Because you get those methods on every radio as well.
3336
+
3337
+ === checked?() » true or false ===
3338
+
3339
+ Returns whether the radio button is checked or not. So, `true` means "yes, it
3340
+ is checked!"
3341
+
3342
+ === checked = true or false ===
3343
+
3344
+ Marks or unmarks the radio button. Using `checked = false`, for instance,
3345
+ clears the radio.
3346
+
3347
+ === click() { |self| ... } » self ===
3348
+
3349
+ When the radio button is clicked, its `click` block is called. The block is
3350
+ handed `self`, which is an object representing the radio which was clicked.
3351
+
3352
+ Clicks are sent for both marking and unmarking the radio.
3353
+
3354
+ === focus() » self ===
3355
+
3356
+ Moves focus to the radio. The radio will be highlighted and, if the user hits
3357
+ Enter, the radio will be toggled between its marked and unmarked states.
3358
+
3359
+ == Shape ==
3360
+
3361
+ A shape is a path outline usually created by drawing methods like `oval` and
3362
+ `rect`. !{:margin_left => 100}man-ele-shape.png!
3363
+
3364
+ See the [[Common]] methods page. Shapes respond to all of those methods.
3365
+
3366
+ == TextBlock ==
3367
+
3368
+ The TextBlock object represents a group of text organized as a single element.
3369
+ A paragraph containing bolded text, for example. A caption containing links and
3370
+ bolded text. (So, a `caption` is a TextBlock type. However, `link` and
3371
+ `strong` are TextClass types.) !{:margin_left => 100}man-ele-textblock.png!
3372
+
3373
+ All of the various types of TextBlock are found on the [[Element Element
3374
+ Creation]] page.
3375
+
3376
+ * [[Element.banner]], a 48 pixel font.
3377
+ * [[Element.title]], a 34 pixel font.
3378
+ * [[Element.subtitle]], a 26 pixel font.
3379
+ * [[Element.tagline]], an 18 pixel font.
3380
+ * [[Element.caption]], a 14 pixel font.
3381
+ * [[Element.para]], a 12 pixel font.
3382
+ * [[Element.inscription]], a 10 pixel font.
3383
+
3384
+ === contents() » an array of elements ===
3385
+
3386
+ Lists all of the strings and styled text objects inside this block.
3387
+
3388
+ === replace(a string) ===
3389
+
3390
+ Replaces the text of the entire block with the characters of `a string`.
3391
+
3392
+ === text() » a string ===
3393
+
3394
+ Return a string of all of the characters in this text box. This will strip off
3395
+ any style or text classes and just return the actual characters, as if seen on
3396
+ the screen.
3397
+
3398
+ === text = a string ===
3399
+
3400
+ Replaces the text of the entire block with the characters of `a string`.
3401
+
3402
+ === to_s() » a string ===
3403
+
3404
+ An alias for [[TextBlock.text]]. Returns a flattened string of all of this
3405
+ TextBlock's contents.
3406
+
3407
+ == Timers ==
3408
+
3409
+ Shoes contains three timer classes: the Animation class, the Every class and
3410
+ the Timer class. Both Animations and Everies loop over and over after they
3411
+ start. Timers happen once. A one-shot timer.
3412
+
3413
+ Animations and Everies are basically the same thing. The difference is that
3414
+ Animations usually happen many, many times per second. And Everies happen only
3415
+ once every few seconds or rarely.
3416
+
3417
+ === start() » self ===
3418
+
3419
+ Both types of timers automatically start themselves, so there's no need to use
3420
+ this normally. But if you [[Timers.stop]] a timer and would like to start it up
3421
+ again, then by all means: use this!
3422
+
3423
+ === stop() » self ===
3424
+
3425
+ Pauses the animation or timer. In the case of a one-shot timer that's already
3426
+ happened, it's already stopped and this method will have no effect.
3427
+
3428
+ === toggle() » self ===
3429
+
3430
+ If the animation or timer is stopped, it is started. Otherwise, if it is
3431
+ already running, it is stopped.
3432
+
3433
+ == Video ==
3434
+
3435
+ Shoes supports embedding of QuickTime, Flash video (FLV), DivX, Xvid and
3436
+ various other popular video formats. This is all thanks to VideoLAN and ffmpeg,
3437
+ two sensational open source libraries. Use the `video` method on a slot to
3438
+ setup a Shoes::Video object. !{:margin_left => 100}man-ele-video.png!
3439
+
3440
+ In addition to video formats, some audio formats are also supported, such as
3441
+ MP3, WAV and Ogg Vorbis.
3442
+
3443
+ Video support is optional in Shoes and some builds do not support video. For
3444
+ example, video support is unavailable for PowerPC. When you download Shoes, the
3445
+ build for your platform will be marked `novideo` in the filename if no video
3446
+ support is available.
3447
+
3448
+ === hide() » self ===
3449
+
3450
+ Hides the video. If already playing, the video will continue to play. This just
3451
+ turns off display of the video. One possible use of this method is to collapse
3452
+ the video area when it is playing an audio file, such as an MP3.
3453
+
3454
+ === length() » a number ===
3455
+
3456
+ The full length of the video in milliseconds. Returns nil if the video is not
3457
+ yet loaded.
3458
+
3459
+ === move(left, top) » self ===
3460
+
3461
+ Moves the video to specific coordinates, the (left, top) being the upper left
3462
+ hand corner of the video.
3463
+
3464
+ === pause() » self ===
3465
+
3466
+ Pauses the video, if it is playing.
3467
+
3468
+ === playing?() » true of false ===
3469
+
3470
+ Returns true if the video is currently playing. Or, false if the video is
3471
+ paused or stopped.
3472
+
3473
+ === play() » self ===
3474
+
3475
+ Starts playing the video, if it isn't already playing. If already playing, the
3476
+ video is restarted from the beginning.
3477
+
3478
+ === position() » a decimal ===
3479
+
3480
+ The position of the video as a decimanl number (a Float) between the beginning
3481
+ (0.0) and the end (1.0). For instance, a Float value of 0.5 indicates the
3482
+ halfway point of the video.
3483
+
3484
+ === position = a decimal ===
3485
+
3486
+ Sets the position of the video using a Float value. To move the video to its
3487
+ 25% position: `@video.position = 0.25`.
3488
+
3489
+ === remove() » self ===
3490
+
3491
+ Removes the video from its slot. This will stop the video as well.
3492
+
3493
+ === show() » self ===
3494
+
3495
+ Reveals the video, if it has been hidden by the `hide()` method.
3496
+
3497
+ === stop() » self ===
3498
+
3499
+ Stops the video, if it is playing.
3500
+
3501
+ === time() » a number ===
3502
+
3503
+ The time position of the video in milliseconds. So, if the video is 10 seconds
3504
+ into play, this method would return the number 10000.
3505
+
3506
+ === time = a number ===
3507
+
3508
+ Set the position of the video to a time in milliseconds.
3509
+
3510
+ === toggle() » self ===
3511
+
3512
+ Toggles the visibility of the video. If the video can be seen, then `hide` is
3513
+ called. Otherwise, `show` is called.
3514
+
3515
+ = AndSoForth =
3516
+
3517
+ A place for some other information.
3518
+
3519
+ == Sample Apps ==
3520
+
3521
+ Have fun!
3522
+
3523
+ {SAMPLES}
3524
+
3525
+ == FAQ ==
3526
+
3527
+ Hope this helps:
3528
+
3529
+ * You can join [[http://librelist.com/browser/shoes/ Shoes ML]] and feel free ask your questions.
3530
+ * [[http://github.com/shoes/shoes/ Official Current Source Code]] is on GitHub.
3531
+ * [[http://github.com/shoes/shoes/downloads Recent Builds]] for your platform.