purple_shoes 0.0.126 → 0.5.149

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,10 @@ class Shoes
10
10
  @margin_bottom ||= margin_bottom
11
11
  end
12
12
 
13
+ def hided
14
+ @app.hided or @hided
15
+ end
16
+
13
17
  def click &blk
14
18
  @app.clickable self, :click, &blk
15
19
  end
@@ -18,12 +22,23 @@ class Shoes
18
22
  @app.clickable self, :release, &blk
19
23
  end
20
24
 
21
- attr_reader :margin_left, :margin_top, :margin_right, :margin_bottom
25
+ def hover &blk
26
+ @hover_proc = blk
27
+ (@app.mhcs << self) unless @app.mhcs.include? self
28
+ end
29
+
30
+ def leave &blk
31
+ @leave_proc = blk
32
+ (@app.mhcs << self) unless @app.mhcs.include? self
33
+ end
34
+
35
+ attr_reader :margin_left, :margin_top, :margin_right, :margin_bottom, :hover_proc, :leave_proc
36
+ attr_accessor :hovered
22
37
  end
23
38
 
24
39
  module Mod2
25
40
  def init_app_vars
26
- @contents, @mmcs, @mscs, @order = [], [], [], []
41
+ @contents, @mmcs, @mscs, @mhcs, @order = [], [], [], [], []
27
42
  @location = '/'
28
43
  @mouse_button, @mouse_pos = 0, [0, 0]
29
44
  @fill, @stroke = black, black
@@ -224,7 +239,9 @@ class Shoes
224
239
  vb = app.shell.getVerticalBar
225
240
  vb.setVisible(scrollable_height > h)
226
241
  if scrollable_height > h
227
- vb.setMaximum scrollable_height - h + 12
242
+ vb.setThumb h * h / scrollable_height
243
+ vb.setMaximum scrollable_height - h + vb.getThumb
244
+ vb.setIncrement h / 2
228
245
  else
229
246
  location = app.cs.getLocation
230
247
  location.y = 0
@@ -245,6 +262,30 @@ class Shoes
245
262
  def self.mouse_motion_control app
246
263
  app.mmcs.each{|blk| blk[*app.mouse_pos]}
247
264
  end
265
+
266
+ def self.mouse_hover_control app
267
+ app.mhcs.each do |e|
268
+ if mouse_on?(e) and !e.hovered
269
+ e.hovered = true
270
+ e.hover_proc[e] if e.hover_proc
271
+ end
272
+ end
273
+ end
274
+
275
+ def self.mouse_leave_control app
276
+ app.mhcs.each do |e|
277
+ if !mouse_on?(e) and e.hovered
278
+ e.hovered = false
279
+ e.leave_proc[e] if e.leave_proc
280
+ end
281
+ end
282
+ end
283
+
284
+ def self.mouse_on? e
285
+ mb, mx, my = e.app.mouse
286
+ dx, dy = e.is_a?(Star) ? [e.width / 2.0, e.height / 2.0] : [0, 0]
287
+ e.left - dx <= mx and mx <= e.left - dx + e.width and e.top - dy <= my and my <= e.top - dy + e.height
288
+ end
248
289
 
249
290
  def self.mouse_shape_control app
250
291
  flag = false
data/lib/shoes/main.rb CHANGED
@@ -77,6 +77,8 @@ class Shoes
77
77
  app.mouse_pos = [e.x, e.y]
78
78
  Shoes.mouse_motion_control app
79
79
  Shoes.mouse_shape_control app
80
+ Shoes.mouse_hover_control app
81
+ Shoes.mouse_leave_control app
80
82
  end
81
83
  end
82
84
  cs.addMouseMoveListener mml
data/lib/shoes/slot.rb CHANGED
@@ -19,14 +19,24 @@ class Shoes
19
19
  (@parent.contents << self) unless @nocontrol
20
20
 
21
21
  if block_given?
22
+ if args[:hidden]
23
+ @hided = true
24
+ BASIC_ATTRIBUTES_DEFAULT.merge! hidden: true
25
+ SLOT_ATTRIBUTES_DEFAULT.merge! hidden: true
26
+ @hidden_flag = true unless @parent.instance_variable_get '@hidden'
27
+ end
22
28
  yield
29
+ if @hidden_flag
30
+ BASIC_ATTRIBUTES_DEFAULT.delete :hidden
31
+ SLOT_ATTRIBUTES_DEFAULT.delete :hidden
32
+ end
23
33
  @app.cslot = @parent
24
34
  else
25
35
  @left = @top = 0
26
36
  end
27
37
  end
28
38
 
29
- attr_accessor :contents
39
+ attr_accessor :contents, :ln
30
40
  attr_reader :parent, :initials
31
41
  attr_writer :app
32
42
 
@@ -74,6 +84,11 @@ class Shoes
74
84
  tmp = self.is_a?(Stack) ? Stack.new(@app.slot_attributes(args), &blk) : Flow.new(@app.slot_attributes(args), &blk)
75
85
  self.contents = tmp.contents
76
86
  contents.each{|e| e.parent = self if e.is_a? Basic}
87
+ elsif !@app.cs.isDisposed
88
+ @app.cs.removeListener Swt::SWT::MouseDown, ln if ln
89
+ @app.cs.removeListener Swt::SWT::MouseUp, ln if ln
90
+ @app.mscs -= [self]
91
+ @app.mhcs -= [self]
77
92
  end
78
93
  @app.flush
79
94
  end
@@ -88,9 +103,19 @@ class Shoes
88
103
  yield
89
104
  self.contents += tmp
90
105
  @app.cslot = cslot
91
- Shoes.call_back_procs @app
106
+ @app.aflush
107
+ end
108
+
109
+ def before e, &blk
110
+ prepend contents.index(e).to_i, &blk
92
111
  end
93
112
 
113
+ def after e, &blk
114
+ n = contents.index e
115
+ n = n ? n+1 : contents.length
116
+ prepend n, &blk
117
+ end
118
+
94
119
  def show
95
120
  @hided = true
96
121
  toggle
data/lib/shoes/style.rb CHANGED
@@ -8,7 +8,8 @@ class Shoes
8
8
  end
9
9
 
10
10
  class Basic
11
- def style args
11
+ def style args = nil
12
+ return @args unless args
12
13
  set_args args
13
14
  @app.cs.redraw @left, @top, @width, @height, false unless @app.cs.isDisposed
14
15
  end
@@ -21,7 +22,8 @@ class Shoes
21
22
  end
22
23
 
23
24
  class Star < ShapeBase
24
- def style args
25
+ def style args = nil
26
+ return @args unless args
25
27
  set_args args
26
28
  w, h = @width+@strokewidth+1, @height+@strokewidth+1
27
29
  @app.cs.redraw @left-w/2 , @top-h/2, w, h, false unless @app.cs.isDisposed
@@ -29,7 +31,8 @@ class Shoes
29
31
  end
30
32
 
31
33
  class TextBlock
32
- def style args
34
+ def style args = nil
35
+ return @args unless args
33
36
  set_args args
34
37
  return if @app.cs.isDisposed
35
38
 
data/samples/sample43.rb CHANGED
@@ -6,7 +6,11 @@ Shoes.app do
6
6
  status = para "One moment..."
7
7
  msg = para '0%'
8
8
  dl = download "http://antwrp.gsfc.nasa.gov/apod/image/1009/venusmoon_pascual_big.jpg",
9
- save: "venusmoon_pascual_big.jpg"
9
+ save: "venusmoon_pascual_big.jpg" do
10
+ status.text = "Okay, is downloaded."
11
+ status.style stroke: orangered
12
+ image("venusmoon_pascual_big.jpg", width: 580, height: 380).move 10, 100
13
+ end
10
14
 
11
15
  pg = progress left: 10, top: 100, width: width - 20
12
16
  a = animate do
@@ -15,9 +19,6 @@ Shoes.app do
15
19
  msg.text = "%2d%" % (pg.fraction * 100)
16
20
  end
17
21
  if dl.finished?
18
- status.text = "Okay, is downloaded."
19
- status.style stroke: orangered
20
- image("venusmoon_pascual_big.jpg", width: 580, height: 380).move 10, 100
21
22
  pg.hide
22
23
  a.stop
23
24
  end
@@ -0,0 +1,33 @@
1
+ require 'purple_shoes'
2
+
3
+ Shoes.app do
4
+ extend HH::Markup
5
+ colors = {
6
+ :comment => {:stroke => "#bba"},
7
+ :keyword => {:stroke => "#FCF91F"},
8
+ :method => {:stroke => "#C09"},
9
+ :symbol => {:stroke => "#9DF3C6"},
10
+ :string => {:stroke => "#C9F5A5"},
11
+ :number => {:stroke => "#C9F5A5"},
12
+ :regex => {:stroke => "#000", :fill => "#FFC" },
13
+ :attribute => {:stroke => "#C9F5A5"},
14
+ :expr => {:stroke => "#f33" },
15
+ :ident => {:stroke => "#6e7"},
16
+ :any => {:stroke => "#FFF"},
17
+ :constant => {:stroke => "#55f"},
18
+ :class => {:stroke => "#55f"},
19
+ :matching => {:stroke => "#f00"},
20
+ }
21
+ code = IO.read(ask_open_file)
22
+ button 'change color' do
23
+ @slot.clear do
24
+ background gray 0.1
25
+ para *highlight(code, nil, colors)
26
+ end
27
+ aflush
28
+ end
29
+ @slot = stack do
30
+ background gainsboro
31
+ para *highlight(code)
32
+ end
33
+ end
Binary file
Binary file
data/static/manual-en.txt CHANGED
@@ -126,7 +126,7 @@ Still, Shoes does have a few widgets like buttons and edit boxes. And many
126
126
  missing elements (like tabbed controls or toolbars) can be simulated with
127
127
  images.
128
128
 
129
- Shoes is written in part thanks to a very good graphical widget toolkit called '''SWT'''.
129
+ Purple Shoes is written in part thanks to a very good graphical widget toolkit called '''SWT'''.
130
130
  In this way, Shoes is inspired by NodeBox and Processing, two very good languages
131
131
  for drawing animated graphics.
132
132
 
@@ -1000,6 +1000,7 @@ query google's search engine.
1000
1000
  '''Note:''' Purple Shoes doesn't support the `:method`, `:headers` and `:body` styles.
1001
1001
 
1002
1002
  {{{
1003
+ # Not yet available
1003
1004
  include Hpricot
1004
1005
  Shoes.app do
1005
1006
  status = para "One moment..."
@@ -1014,11 +1015,6 @@ query google's search engine.
1014
1015
  end
1015
1016
  }}}
1016
1017
 
1017
- As you can see from the above example, Purple Shoes includes the Hpricot
1018
- library for parsing HTML.
1019
-
1020
- '''Note:''' Windows platform only so far.
1021
-
1022
1018
  === location() » a string ===
1023
1019
 
1024
1020
  Gets a string containing the URL of the current app.
@@ -1095,16 +1091,16 @@ available on every element and slot.
1095
1091
  Most styles can also be set by calling them as methods. (I'd use the manual
1096
1092
  search to find the method.)
1097
1093
 
1098
- '''Note:''' Purple Shoes doesn't support them as methods.
1094
+ '''Note:''' Purple Shoes supports them as methods, but needs to add `flush`.
1099
1095
 
1100
1096
  {{{
1101
- # Not yet available
1102
1097
  Shoes.app title: "A Styling Sample" do
1103
1098
  choose =
1104
1099
  lambda{[red, blue, green, yellow].sample}
1105
- s = star 100, 50, 30, 200, 180, strokewidth: 5
1100
+ s = star 300, 250, 30, 200, 180, strokewidth: 5
1106
1101
  button 'change colors' do
1107
1102
  s.stroke = choose.call; s.fill = choose.call
1103
+ flush
1108
1104
  end
1109
1105
  end
1110
1106
  }}}
@@ -1196,7 +1192,7 @@ Indicates whether the `:top` and `:left` coordinates refer to the center of the
1196
1192
  shape or not. If set to `true`, this is similar to setting the
1197
1193
  [[Art.transform]] method to `:center`.
1198
1194
 
1199
- '''Note:''' Purple Shoes doesn't support `:center` style.
1195
+ '''Note:''' Purple Shoes supports `:center` style only for oval and rect for now.
1200
1196
 
1201
1197
  === :change » a proc ===
1202
1198
 
@@ -1348,9 +1344,6 @@ displayed on the screen. Neither are its children.
1348
1344
  end
1349
1345
  }}}
1350
1346
 
1351
- '''Note:''' Purple Shoes supports `:hidden` style for only slots, shapes, textblocks
1352
- and images so far.
1353
-
1354
1347
  === :inner » a number ===
1355
1348
 
1356
1349
  For: ''star''.
@@ -1483,7 +1476,7 @@ scrollbar will appear and disappear as needed. It will also appear inside the
1483
1476
  width of the slot, meaning the slot's width will never change, regardless of
1484
1477
  whether there is a scrollbar or not.
1485
1478
 
1486
- '''Note:''' Purple Shoes has restrictions. `:scroll` style is just a trial so far.
1479
+ '''Note:''' Purple Shoes doesn't support `:scroll` style.
1487
1480
 
1488
1481
  * common Slot instance methods, i.e. clear, hide, etc., don't work well
1489
1482
  * doesn't manage any mouse events
@@ -1785,7 +1778,7 @@ setting `:angle1` to 0 and `:angle2` to `2*Math::PI`.)
1785
1778
  cap :curve
1786
1779
 
1787
1780
  a = animate 12 do |i|
1788
- @e.remove if @e
1781
+ @e.clear if @e
1789
1782
  r = i * (Math::PI * 0.01)
1790
1783
  @e = arc 100, 50, 180, 360, 0, r
1791
1784
  a.stop if r >= 2*Math::PI
@@ -1841,7 +1834,8 @@ To draw a star with an image pattern:
1841
1834
  {{{
1842
1835
  #!ruby
1843
1836
  Shoes.app do
1844
- fill File.join(DIR, "../static/gshoes-icon.png")
1837
+ fill File.join(DIR,
1838
+ "../static/purple_shoes-icon.png")
1845
1839
  star 200, 200, 5, 100, 50
1846
1840
  end
1847
1841
  }}}
@@ -1897,8 +1891,6 @@ Draw circular form using a style hash. The following styles are supported:
1897
1891
 
1898
1892
  These styles may also be altered using the `style` method on the Shape object.
1899
1893
 
1900
- '''Note:''' Purple Shoes doesn't support `center` style.
1901
-
1902
1894
  === rect(top, left, width, height) » Shoes::Rect ===
1903
1895
 
1904
1896
  Draws a rectangle starting from coordinates (top, left) with dimensions of
@@ -1932,8 +1924,6 @@ Draw a rectangle using a style hash. The following styles are supported:
1932
1924
 
1933
1925
  These styles may also be altered using the `style` method on the Shape object.
1934
1926
 
1935
- '''Note:''' Purple Shoes doesn't support `center` style.
1936
-
1937
1927
  === rotate(degrees: a number) » self ===
1938
1928
 
1939
1929
  Rotates the pen used for drawing by a certain number of `degrees`, so that any
@@ -1945,7 +1935,7 @@ In this example below, the rectangle drawn at (30, 30) will be rotated 45 degree
1945
1935
  #!ruby
1946
1936
  Shoes.app do
1947
1937
  fill "#333"
1948
- rotate 45
1938
+ rotate 45, 30, 30
1949
1939
  rect 30, 30, 40, 40
1950
1940
  end
1951
1941
  }}}
@@ -1962,7 +1952,7 @@ and arcs and bends.
1962
1952
  fill yellow
1963
1953
  shape do
1964
1954
  move_to 50, 30
1965
- curve_to 100, 100, 10, 20, 100, 50
1955
+ quad_to 100, 100, 80, 20
1966
1956
  line_to 20, 100
1967
1957
  line_to 30, 30
1968
1958
  end
@@ -1975,7 +1965,7 @@ the other methods in this [[Art]] section) inside a shape, but they will not be
1975
1965
  part of the line. They will be more like a group of shapes are all drawn as
1976
1966
  one.
1977
1967
 
1978
- '''Note:''' The above `line_to`, `move_to` and `curve_to` are Cairo::Context methods.
1968
+ '''Note:''' The above `line_to`, `move_to` and `quad_to` are SWT methods.
1979
1969
  Purple Shoes uses them directly inside the block. So, Purple Shoes doesn't support `arc_to`.
1980
1970
  Also Purple Shoes shape can not contain other shapes.
1981
1971
 
@@ -2397,18 +2387,18 @@ Whenever a key (or combination of keys) is pressed, the block gets called. The
2397
2387
  block is sent a `key` which is a string representing the character (such as the
2398
2388
  letter or number) on the key.
2399
2389
 
2400
- So, for example, if `Shift-a` is pressed, the block will get the string `"Shift_L"` and `"A"`.
2390
+ So, for example, if `Shift-a` is pressed, the block will get the string `"SHIFT"` and `"A"`.
2401
2391
 
2402
2392
  And if the `F1` key is pressed, the `"F1"` string is received.
2403
2393
 
2404
- The left side modifier keys are `"Control_L"`, `"Shift_L"` and `"Alt_L"`. They appear in that order.
2394
+ The modifier keys are `"CTRL"`, `"SHIFT"` and `"ALT"`. They appear in that order.
2405
2395
  If `Shift-Control-Alt-PgUp` is pressed, the strings will be
2406
- `"Shift_L"`, `"Control_L"`, `"Alt_L"` and `"Page_Up"`.
2396
+ `"SHIFT"`, `"CTRL"`, `"ALT"` and `"PAGE_UP"`.
2407
2397
 
2408
2398
  One thing about the shift key. On
2409
- US keyboards, `Shift-7` is an ampersand. So you'll get the string `"Shift_L"` and `"ampersand"` rather
2410
- than `"Shift_L"` and `"7"`. And, if you press `Shift-Alt-7` on such a keyboard, you'll
2411
- get the strings: `"Shift_L"`, `"Alt_L"` and `"ampersand"`.
2399
+ US keyboards, `Shift-7` is an ampersand. So you'll get the string `"SHIFT"` and `"&"` rather
2400
+ than `"SHIFT"` and `"7"`. And, if you press `Shift-Alt-7` on such a keyboard, you'll
2401
+ get the strings: `"SHIFT"`, `"ALT"` and `"&"`.
2412
2402
 
2413
2403
  {{{
2414
2404
  #!ruby
@@ -3349,7 +3339,7 @@ You can use web URLs directly as well.
3349
3339
  {{{
3350
3340
  #!ruby
3351
3341
  Shoes.app do
3352
- image "http://is.gd/c0mBtb"
3342
+ image "http://is.gd/GVAGF7"
3353
3343
  end
3354
3344
  }}}
3355
3345
 
@@ -3393,10 +3383,11 @@ Rotates the Image element by a certain number of `degrees`.
3393
3383
 
3394
3384
  {{{
3395
3385
  Shoes.app do
3396
- img = image File.join(DIR, '../samples/cy.png')
3397
- img.move 200, 200
3386
+ g = image File.join(DIR, '../samples/cy.png')
3387
+ g.move 200, 200
3398
3388
  animate do |i|
3399
- img.rotate i*10
3389
+ g.rotate =
3390
+ [i*10, g.left+g.width/2, g.top+g.height/2]
3400
3391
  end
3401
3392
  end
3402
3393
  }}}
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.126
4
+ version: 0.5.149
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-10 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: swt
16
- requirement: &17597616 !ruby/object:Gem::Requirement
16
+ requirement: &16443456 !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: *17597616
24
+ version_requirements: *16443456
25
25
  description: Purple Shoes is one of colorful Shoes, written in JRuby and SWT.
26
26
  email: ashbbb@gmail.com
27
27
  executables:
@@ -33,6 +33,10 @@ files:
33
33
  - VERSION
34
34
  - bin/pshoes
35
35
  - bin/pshoes.bat
36
+ - lib/ext/highlighter.rb
37
+ - lib/ext/highlighter/common.rb
38
+ - lib/ext/highlighter/lang/ruby.rb
39
+ - lib/ext/highlighter/markup.rb
36
40
  - lib/plugins/video.rb
37
41
  - lib/purple_shoes.rb
38
42
  - lib/shoes/anim.rb
@@ -153,6 +157,7 @@ files:
153
157
  - samples/sample49.rb
154
158
  - samples/sample5.rb
155
159
  - samples/sample50.rb
160
+ - samples/sample52.rb
156
161
  - samples/sample58.rb
157
162
  - samples/sample6.rb
158
163
  - samples/sample7.rb
@@ -207,6 +212,7 @@ files:
207
212
  - snapshots/sample49.png
208
213
  - snapshots/sample5.png
209
214
  - snapshots/sample50.png
215
+ - snapshots/sample52.png
210
216
  - snapshots/sample58.png
211
217
  - snapshots/sample6.png
212
218
  - snapshots/sample7.png
@@ -215,6 +221,7 @@ files:
215
221
  - snapshots/sample99.png
216
222
  - static/code_highlighter.js
217
223
  - static/code_highlighter_ruby.js
224
+ - static/downloading.png
218
225
  - static/man-editor-notepad.png
219
226
  - static/man-editor-osx.png
220
227
  - static/man-ele-background.png