purple_shoes 0.0.115 → 0.0.126

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.115
1
+ 0.0.126
data/lib/purple_shoes.rb CHANGED
@@ -10,6 +10,9 @@ Types = module Shoes; self end
10
10
  module Shoes
11
11
  DIR = Pathname.new(__FILE__).realpath.dirname.to_s
12
12
  FONTS = []
13
+ LINK_DEFAULT = {underline: true}
14
+ BANNER_DEFAULT, TITLE_DEFAULT, SUBTITLE_DEFAULT, TAGLINE_DEFAULT, CAPTION_DEFAULT, PARA_DEFAULT, INSCRIPTION_DEFAULT =
15
+ {}, {}, {}, {}, {}, {}, {}
13
16
  SHOES_VERSION = IO.read(File.join(DIR, '../VERSION')).chomp
14
17
  BASIC_ATTRIBUTES_DEFAULT = {left: 0, top: 0, width: 0, height: 0, angle: 0, curve: 0}
15
18
  SLOT_ATTRIBUTES_DEFAULT = {left: nil, top: nil, width: 1.0, height: 0}
data/lib/shoes/app.rb CHANGED
@@ -11,6 +11,7 @@ class Shoes
11
11
  end
12
12
  init_app_vars
13
13
  @top_slot, @cslot = nil, self
14
+ Shoes.APPS << self
14
15
  end
15
16
 
16
17
  attr_accessor :cslot, :top_slot, :contents, :mmcs, :mscs, :order, :mouse_pos, :hided
@@ -51,19 +52,20 @@ class Shoes
51
52
  def click &blk
52
53
  if blk
53
54
  app = self
54
- ln = Swt::Listener.new
55
- class << ln; self end.
56
- instance_eval do
57
- define_method :handleEvent do |e|
58
- blk[*app.mouse]
55
+ Swt::Listener.new.tap do |ln|
56
+ class << ln; self end.
57
+ instance_eval do
58
+ define_method(:handleEvent){|e| blk[*app.mouse]}
59
+ define_method(:clear){app.cs.removeListener Swt::SWT::MouseDown, ln}
59
60
  end
61
+ @cs.addListener Swt::SWT::MouseDown, ln unless @cs.isDisposed
60
62
  end
61
- @cs.addListener Swt::SWT::MouseDown, ln unless @cs.isDisposed
62
63
  end
63
64
  end
64
65
 
65
66
  def textblock klass, font_size, *msg
66
67
  args = msg.last.class == Hash ? msg.pop : {}
68
+ args = eval("#{klass.to_s[7..-1].upcase}_DEFAULT").merge args
67
69
  args = basic_attributes args
68
70
  args[:markup] = msg.map(&:to_s).join
69
71
 
@@ -152,10 +154,14 @@ class Shoes
152
154
  end
153
155
  end
154
156
 
155
- def button name, args={}
157
+ def buttonbase klass, name, args, &blk
156
158
  args = basic_attributes args
157
- b = Swt::Button.new @cs, Swt::SWT::NULL
158
- b.setText name
159
+ args[:block] = blk
160
+ opt = if klass == Button then Swt::SWT::NULL
161
+ elsif klass == Radio then Swt::SWT::RADIO
162
+ elsif klass == Check then Swt::SWT::CHECK end
163
+ b = Swt::Button.new @cs, opt
164
+ b.setText name if klass == Button
159
165
  b.setLocation args[:left], args[:top]
160
166
  if args[:width] > 0 and args[:height] > 0
161
167
  b.setSize args[:width], args[:height]
@@ -163,31 +169,25 @@ class Shoes
163
169
  b.pack
164
170
  end
165
171
  args[:real], args[:text], args[:app] = b, name, self
166
- Button.new(args).tap do |s|
172
+ klass.new(args).tap do |s|
167
173
  b.addSelectionListener do |e|
168
- yield s
169
- end if block_given?
174
+ klass == Button ? blk[s] : (blk[s] if b.getSelection)
175
+ end if blk
170
176
  end
171
177
  end
172
178
 
179
+ def button name, args={}, &blk
180
+ buttonbase Button, name, args, &blk
181
+ end
182
+
173
183
  def radio args={}, &blk
174
- args = basic_attributes args
175
- args[:block] = blk
176
- b = Swt::Button.new @cs, Swt::SWT::RADIO
177
- b.setLocation args[:left], args[:top]
178
- if args[:width] > 0 and args[:height] > 0
179
- b.setSize args[:width], args[:height]
180
- else
181
- b.pack
182
- end
183
- args[:real], args[:app] = b, self
184
- Radio.new(args).tap do |s|
185
- b.addSelectionListener do |e|
186
- blk[s] if b.getSelection
187
- end if blk
188
- end
184
+ buttonbase Radio, nil, args, &blk
189
185
  end
190
186
 
187
+ def check args={}, &blk
188
+ buttonbase Check, nil, args, &blk
189
+ end
190
+
191
191
  def edit_text attrs
192
192
  klass, w, h, style, blk, attrs = attrs
193
193
  args = attrs.last.class == Hash ? attrs.pop : {}
@@ -251,13 +251,15 @@ class Shoes
251
251
  end
252
252
 
253
253
  def keypress &blk
254
- kl = Swt::KeyListener.new
255
- class << kl; self end.
256
- instance_eval do
257
- define_method(:keyPressed){|e| blk[KEY_NAMES[e.keyCode] || e.character.chr]}
258
- define_method(:keyReleased){|e|}
254
+ Swt::KeyListener.new.tap do |kl|
255
+ class << kl; self end.
256
+ instance_eval do
257
+ define_method(:keyPressed){|e| blk[KEY_NAMES[e.keyCode] || e.character.chr]}
258
+ define_method(:keyReleased){|e|}
259
+ define_method(:clear){Shoes.shell.removeKeyListener kl}
260
+ end
261
+ @shell.addKeyListener kl
259
262
  end
260
- @shell.addKeyListener kl
261
263
  end
262
264
 
263
265
  def mouse
@@ -280,6 +282,7 @@ class Shoes
280
282
  instance_eval do
281
283
  define_method :paintControl do |e|
282
284
  unless s.hided
285
+ s.real = Swt::Path.new(Shoes.display) if s.real.isDisposed
283
286
  gc = e.gc
284
287
  Shoes.dps_reset s.dps, gc
285
288
  gc.setAntialias Swt::SWT::ON
@@ -679,6 +682,7 @@ class Shoes
679
682
 
680
683
  def close
681
684
  @shell.close
685
+ Shoes.APPS.delete self
682
686
  end
683
687
 
684
688
  def flush
data/lib/shoes/basic.rb CHANGED
@@ -73,15 +73,17 @@ class Shoes
73
73
  end
74
74
 
75
75
  def clear
76
- @app.cs.removePaintListener pl if pl
77
- @app.cs.removeListener Swt::SWT::MouseDown, ln if ln
78
- @app.cs.removeListener Swt::SWT::MouseUp, ln if ln
79
- @real.dispose unless @real.is_a? Symbol
80
- @dps.each{|dp| dp.dispose if dp}
81
- @dps.clear
82
- @parent.contents -= [self]
83
- @app.mscs -= [self]
84
- hide
76
+ unless @app.cs.isDisposed
77
+ @app.cs.removePaintListener pl if pl
78
+ @app.cs.removeListener Swt::SWT::MouseDown, ln if ln
79
+ @app.cs.removeListener Swt::SWT::MouseUp, ln if ln
80
+ @real.dispose unless @real.is_a? Symbol
81
+ @dps.each{|dp| dp.dispose if dp}
82
+ @dps.clear
83
+ @parent.contents -= [self]
84
+ @app.mscs -= [self]
85
+ hide
86
+ end
85
87
  end
86
88
 
87
89
  def show
@@ -158,7 +160,7 @@ class Shoes
158
160
  class Star < ShapeBase
159
161
  def move3 x, y
160
162
  unless @app.cs.isDisposed
161
- w, h = @width + 1, @height + 1
163
+ w, h = @width + @strokewidth + 1, @height + @strokewidth + 1
162
164
  hw, hh = w / 2, h / 2
163
165
  @app.cs.redraw @left - hw, @top - hh, w, h, false
164
166
  @app.cs.redraw x-hw, y - hh, w, h, false
@@ -167,6 +169,12 @@ class Shoes
167
169
  end
168
170
  end
169
171
  class Shape < ShapeBase
172
+ def move3 x, y
173
+ unless @app.cs.isDisposed
174
+ real.dispose
175
+ end
176
+ @left, @top = x, y
177
+ end
170
178
  def move_to x, y
171
179
  real.moveTo x + left, y + top
172
180
  end
@@ -190,6 +198,7 @@ class Shoes
190
198
  def text= s
191
199
  style markup: s
192
200
  end
201
+ alias :replace :text=
193
202
  def positioning x, y, max
194
203
  self.text = @args[:markup]
195
204
  super.tap{|s| s.height += (@margin_top + @margin_bottom) if s == self}
@@ -249,6 +258,7 @@ class Shoes
249
258
  end
250
259
  end
251
260
  class Radio < ToggleButton; end
261
+ class Check < ToggleButton; end
252
262
 
253
263
  class EditLine < Native; end
254
264
  class EditBox < Native; end
@@ -60,12 +60,12 @@ class Shoes
60
60
  class << ln; self end.
61
61
  instance_eval do
62
62
  define_method :handleEvent do |e|
63
+ mb, mx, my = e.button, e.x, e.y
63
64
  if s.is_a?(Link) and !s.parent.hided
64
- mouse_x, mouse_y = e.x, e.y
65
- blk[s] if ((s.pl..(s.pl+s.pw)).include?(mouse_x) and (s.sy..s.ey).include?(mouse_y) and !((s.pl..s.sx).include?(mouse_x) and (s.sy..(s.sy+s.lh)).include?(mouse_y)) and !((s.ex..(s.pl+s.pw)).include?(mouse_x) and ((s.ey-s.lh)..s.ey).include?(mouse_y)))
65
+ blk[mb, mx, my] if ((s.pl..(s.pl+s.pw)).include?(mx) and (s.sy..s.ey).include?(my) and !((s.pl..s.sx).include?(mx) and (s.sy..(s.sy+s.lh)).include?(my)) and !((s.ex..(s.pl+s.pw)).include?(mx) and ((s.ey-s.lh)..s.ey).include?(my)))
66
66
  elsif !s.is_a?(Link) and !s.hided
67
67
  dx, dy = s.is_a?(Star) ? [s.width / 2.0, s.height / 2.0] : [0, 0]
68
- blk[s] if s.left - dx <= e.x and e.x <= s.left - dx + s.width and s.top - dy <= e.y and e.y <= s.top - dy + s.height
68
+ blk[mb, mx, my] if s.left - dx <= mx and mx <= s.left - dx + s.width and s.top - dy <= my and my <= s.top - dy + s.height
69
69
  end
70
70
  end
71
71
  end
@@ -127,7 +127,7 @@ class Shoes
127
127
  when :code
128
128
  font = "Lucida Console"
129
129
  when :link
130
- cmds << "underline = true"
130
+ (cmds << "underline = true") if LINK_DEFAULT[:underline]
131
131
  fg = Swt::Color.new Shoes.display, *blue
132
132
  spos = tl.getLocation e[1].first, false
133
133
  epos = tl.getLocation e[1].last, true
data/lib/shoes/main.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  class Shoes
2
2
  $urls = {}
3
+ APPS = []
3
4
  include Swt
4
5
 
5
6
  def self.display
6
7
  @display
7
8
  end
8
9
 
10
+ def self.APPS; APPS end
11
+
9
12
  def self.app args={}, &blk
10
13
  args[:width] ||= 600
11
14
  args[:height] ||= 500
@@ -89,6 +92,7 @@ class Shoes
89
92
 
90
93
  if @main_app == app
91
94
  while !shell.isDisposed do
95
+ APPS.each{|a| APPS.delete a if a.shell.isDisposed}
92
96
  @display.sleep unless @display.readAndDispatch
93
97
  end
94
98
  @display.dispose
data/lib/shoes/style.rb CHANGED
@@ -1,4 +1,12 @@
1
1
  class Shoes
2
+ class App
3
+ def style klass, args={}
4
+ if klass.superclass == Shoes::TextBlock or klass == Shoes::Link
5
+ eval("#{klass.to_s[7..-1].upcase}_DEFAULT").clear.merge! args
6
+ end
7
+ end
8
+ end
9
+
2
10
  class Basic
3
11
  def style args
4
12
  set_args args
@@ -11,7 +19,15 @@ class Shoes
11
19
  @args.each{|k, v| instance_variable_set "@#{k}", v}
12
20
  end
13
21
  end
14
-
22
+
23
+ class Star < ShapeBase
24
+ def style args
25
+ set_args args
26
+ w, h = @width+@strokewidth+1, @height+@strokewidth+1
27
+ @app.cs.redraw @left-w/2 , @top-h/2, w, h, false unless @app.cs.isDisposed
28
+ end
29
+ end
30
+
15
31
  class TextBlock
16
32
  def style args
17
33
  set_args args
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
data/static/manual-en.txt CHANGED
@@ -966,8 +966,8 @@ Another simple use of `download` is to save some web data to a file, using the
966
966
 
967
967
  download "http://is.gd/GVAGF7",
968
968
  :save => "nasa50th.gif" do
969
- @status.text = "Okay, is downloaded."
970
- image "nasa50th.gif", top: 100
969
+ @status.text = "Okay, is downloaded."
970
+ image "nasa50th.gif", top: 100
971
971
  end
972
972
  end
973
973
  end
@@ -1081,13 +1081,11 @@ app, a center `:align` style and 50 font `:size` style.
1081
1081
  The style hash can also be changed by using the [[Common.style]] method,
1082
1082
  available on every element and slot.
1083
1083
 
1084
- '''Note:''' Purple Shoes can change style hash on Shape element only so far.
1085
-
1086
1084
  {{{
1087
1085
  Shoes.app title: "A Styling Sample" do
1088
1086
  choose =
1089
1087
  lambda{[red, blue, green, yellow].sample}
1090
- s = star 100, 50, 30, 200, 180, strokewidth: 5
1088
+ s = star 300, 250, 30, 200, 180, strokewidth: 5
1091
1089
  button 'change colors' do
1092
1090
  s.style stroke: choose.call, fill: choose.call
1093
1091
  end
@@ -2964,7 +2962,7 @@ method again. So, to set the button to 150 pixels wide: `@b.style(width: 150)`.
2964
2962
 
2965
2963
  A background is a color, a gradient or an image that is painted across an
2966
2964
  entire slot. Both backgrounds and borders are a type of Shoes::Pattern.
2967
- !{:margin_left => 100}man-ele-background.png!
2965
+ !{:margin_left => 70}man-ele-background.png!
2968
2966
 
2969
2967
  Even though it's called a ''background'', you may still place this element in
2970
2968
  front of other elements. If a background comes after something else painted on
@@ -3019,7 +3017,7 @@ backgrounds and borders. Reuse it as you like.
3019
3017
 
3020
3018
  A border is a color, gradient or image painted in a line around the edge of any
3021
3019
  slot. Like the Background element in the last section, a Border is a kind of
3022
- Shoes::Pattern. !{:margin_left => 100}man-ele-border.png!
3020
+ Shoes::Pattern. !{:margin_left => 70}man-ele-border.png!
3023
3021
 
3024
3022
  The first, crucial thing to know about border is that all borders paint a line
3025
3023
  around the '''inside''' of a slot, not the outside. So, if you have a slot
@@ -3076,7 +3074,7 @@ backgrounds.
3076
3074
 
3077
3075
  Buttons are, you know, push buttons. You click them and they do something.
3078
3076
  Buttons are known to say "OK" or "Are you sure?" And, then, if you're sure,
3079
- you click the button. !{:margin_left => 100}man-ele-button.png!
3077
+ you click the button. !{:margin_left => 70}man-ele-button.png!
3080
3078
 
3081
3079
  {{{
3082
3080
  #!ruby
@@ -3144,7 +3142,7 @@ hits Enter, the button will be clicked.
3144
3142
 
3145
3143
  Check boxes are clickable square boxes than can be either checked or unchecked.
3146
3144
  A single checkbox usually asks a "yes" or "no" question. Sets of checkboxes
3147
- are also seen in to-do lists. !{:margin_left => 100}man-ele-check.png!
3145
+ are also seen in to-do lists. !{:margin_left => 70}man-ele-check.png!
3148
3146
 
3149
3147
  Here's a sample checklist.
3150
3148
 
@@ -3224,7 +3222,7 @@ Enter, the check will be toggled between its checked and unchecked states.
3224
3222
 
3225
3223
  Edit boxes are wide, rectangular boxes for entering text. On the web, they
3226
3224
  call these textareas. These are multi-line edit boxes for entering longer
3227
- descriptions. Essays, even! !{:margin_left => 100}man-ele-editbox.png!
3225
+ descriptions. Essays, even! !{:margin_left => 70}man-ele-editbox.png!
3228
3226
 
3229
3227
  Without any other styling, edit boxes are sized 200 pixels by 108 pixels. You
3230
3228
  can also use `:width` and `:height` styles to set specific sizes.
@@ -3281,7 +3279,7 @@ Fills the edit box with the characters of `a string`.
3281
3279
 
3282
3280
  Edit lines are a slender, little box for entering text. While the EditBox is
3283
3281
  multi-line, an edit line is just one. Line, that is. Horizontal, in fact.
3284
- !{:margin_left => 100}man-ele-editline.png!
3282
+ !{:margin_left => 70}man-ele-editline.png!
3285
3283
 
3286
3284
  The unstyled edit line is 200 pixels wide and 28 pixels wide. Roughly. The
3287
3285
  height may vary on some platforms.
@@ -3329,7 +3327,7 @@ Fills the edit line with the characters of `a string`.
3329
3327
 
3330
3328
  An image is a picture in PNG, JPEG or GIF format. Purple Shoes can resize images or
3331
3329
  flow them in with text. Images can be loaded from a file or directly off the
3332
- web. !{:margin_left => 100}man-ele-image.png!
3330
+ web. !{:margin_left => 70}man-ele-image.png!
3333
3331
 
3334
3332
  To create an image, use the `image` method in a slot:
3335
3333
 
@@ -3407,7 +3405,7 @@ Rotates the Image element by a certain number of `degrees`.
3407
3405
 
3408
3406
  List boxes (also called "combo boxes" or "drop-down boxes" or "select boxes" in
3409
3407
  some places) are a list of options that drop down when you click on the box.
3410
- !{:margin_left => 100}man-ele-listbox.png!
3408
+ !{:margin_left => 70}man-ele-listbox.png!
3411
3409
 
3412
3410
  A list box gets its options from an array. An array (a list) of strings,
3413
3411
  passed into the `:items` style.
@@ -3481,7 +3479,7 @@ now. If nothing is selected, `nil` will be the reply.
3481
3479
  Progress bars show you how far along you are in an activity. Usually, a
3482
3480
  progress bar represents a percentage (from 0% to 100%.) Purple Shoes thinks of
3483
3481
  progress in terms of the decimal numbers 0.0 to 1.0. !{:margin_left =>
3484
- 100}man-ele-progress.png!
3482
+ 70}man-ele-progress.png!
3485
3483
 
3486
3484
  A simple progress bar is 150 pixels wide, but you can use the `:width` style
3487
3485
  (as with all Purple Shoes elements) to lengthen it.
@@ -3515,7 +3513,7 @@ Sets the progress to a decimal number between 0.0 and 1.0.
3515
3513
  Radio buttons are a group of clickable circles. Click a circle and it'll be
3516
3514
  marked. Only one radio button can be marked at a time. (This is similar to the
3517
3515
  ListBox, where only one option can be selected at a time.) !{:margin_left =>
3518
- 100}man-ele-radio.png!
3516
+ 70}man-ele-radio.png!
3519
3517
 
3520
3518
  So, how do you decide when to use radio buttons and when to use list boxes?
3521
3519
  Well, list boxes only show one highlighted item unless you click on the box and
@@ -3623,7 +3621,7 @@ Moves focus to the radio. The radio will be highlighted.
3623
3621
  == Shape ==
3624
3622
 
3625
3623
  A shape is a path outline usually created by drawing methods like `oval` and
3626
- `rect`. !{:margin_left => 100}man-ele-shape.png!
3624
+ `rect`. !{:margin_left => 70}man-ele-shape.png!
3627
3625
 
3628
3626
  See the [[Common]] methods page. Shapes respond to all of those methods.
3629
3627
 
@@ -3632,7 +3630,7 @@ See the [[Common]] methods page. Shapes respond to all of those methods.
3632
3630
  The TextBlock object represents a group of text organized as a single element.
3633
3631
  A paragraph containing bolded text, for example. A caption containing links and
3634
3632
  bolded text. (So, a `caption` is a TextBlock type. However, `link` and
3635
- `strong` are Text types.) !{:margin_left => 100}man-ele-textblock.png!
3633
+ `strong` are Text types.) !{:margin_left => 70}man-ele-textblock.png!
3636
3634
 
3637
3635
  All of the various types of TextBlock are found on the [[Element Element
3638
3636
  Creation]] page.
@@ -3784,7 +3782,7 @@ already running, it is stopped.
3784
3782
  == Video ==
3785
3783
 
3786
3784
  Purple Shoes supports embedding of MP4, AVI, WMV, QuickTime and various other popular video formats.
3787
- This is all thanks to Ruby/GStreamer. Use the `video` method to setup a Shoes::Video object. !{:margin_left => 70}man-ele-video.png!
3785
+ This is all thanks to Ruby/GStreamer. Use the `video` method to setup a Shoes::Video object. !{:margin_left => 30}man-ele-video.png!
3788
3786
 
3789
3787
  {{{
3790
3788
  Shoes.app width: 400, height: 300 do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purple_shoes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.115
4
+ version: 0.0.126
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-01 00:00:00.000000000 Z
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: swt
16
- requirement: &18076020 !ruby/object:Gem::Requirement
16
+ requirement: &17597616 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18076020
24
+ version_requirements: *17597616
25
25
  description: Purple Shoes is one of colorful Shoes, written in JRuby and SWT.
26
26
  email: ashbbb@gmail.com
27
27
  executables: