glimmer-dsl-swt 4.20.13.6 → 4.20.13.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +5 -5
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_SAMPLES.md +13 -0
  6. data/docs/reference/GLIMMER_STYLE_GUIDE.md +2 -1
  7. data/glimmer-dsl-swt.gemspec +0 -0
  8. data/lib/glimmer/rake_task/scaffold.rb +14 -14
  9. data/lib/glimmer/swt/custom/code_text.rb +4 -4
  10. data/lib/glimmer/swt/custom/shape.rb +1 -1
  11. data/lib/glimmer/swt/image_proxy.rb +1 -1
  12. data/samples/elaborate/calculator.rb +2 -2
  13. data/samples/elaborate/contact_manager.rb +2 -2
  14. data/samples/elaborate/klondike_solitaire.rb +93 -0
  15. data/samples/elaborate/klondike_solitaire/model/column_pile.rb +60 -0
  16. data/samples/elaborate/klondike_solitaire/model/dealing_pile.rb +33 -0
  17. data/samples/elaborate/klondike_solitaire/model/dealt_pile.rb +25 -0
  18. data/samples/elaborate/klondike_solitaire/model/foundation_pile.rb +40 -0
  19. data/samples/elaborate/klondike_solitaire/model/game.rb +37 -0
  20. data/samples/elaborate/klondike_solitaire/model/playing_card.rb +86 -0
  21. data/samples/elaborate/klondike_solitaire/view/action_panel.rb +30 -0
  22. data/samples/elaborate/klondike_solitaire/view/column_pile.rb +66 -0
  23. data/samples/elaborate/klondike_solitaire/view/dealing_pile.rb +36 -0
  24. data/samples/elaborate/klondike_solitaire/view/dealt_pile.rb +38 -0
  25. data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +33 -0
  26. data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +59 -0
  27. data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +26 -0
  28. data/samples/elaborate/klondike_solitaire/view/playing_card.rb +35 -0
  29. data/samples/elaborate/klondike_solitaire/view/tableau.rb +41 -0
  30. data/samples/elaborate/login.rb +2 -2
  31. data/samples/elaborate/mandelbrot_fractal.rb +12 -12
  32. data/samples/elaborate/meta_sample.rb +2 -2
  33. data/samples/elaborate/metronome.rb +2 -2
  34. data/samples/elaborate/stock_ticker.rb +8 -8
  35. data/samples/elaborate/tetris.rb +4 -4
  36. data/samples/elaborate/tetris/view/bevel.rb +2 -2
  37. data/samples/elaborate/tetris/view/score_lane.rb +2 -2
  38. data/samples/elaborate/tic_tac_toe.rb +6 -6
  39. data/samples/elaborate/timer.rb +4 -4
  40. data/samples/elaborate/weather.rb +4 -4
  41. data/samples/hello/hello_button.rb +2 -2
  42. data/samples/hello/hello_c_combo.rb +2 -2
  43. data/samples/hello/hello_canvas.rb +4 -4
  44. data/samples/hello/hello_canvas_animation.rb +2 -2
  45. data/samples/hello/hello_canvas_data_binding.rb +2 -2
  46. data/samples/hello/hello_checkbox.rb +2 -2
  47. data/samples/hello/hello_checkbox_group.rb +2 -2
  48. data/samples/hello/hello_code_text.rb +2 -2
  49. data/samples/hello/hello_color_dialog.rb +2 -2
  50. data/samples/hello/hello_combo.rb +2 -2
  51. data/samples/hello/hello_computed.rb +14 -22
  52. data/samples/hello/hello_cool_bar.rb +2 -2
  53. data/samples/hello/hello_cursor.rb +2 -2
  54. data/samples/hello/hello_custom_shape.rb +2 -2
  55. data/samples/hello/hello_custom_shell.rb +2 -2
  56. data/samples/hello/hello_custom_widget.rb +4 -4
  57. data/samples/hello/hello_date_time.rb +2 -2
  58. data/samples/hello/hello_directory_dialog.rb +2 -2
  59. data/samples/hello/hello_file_dialog.rb +2 -2
  60. data/samples/hello/hello_font_dialog.rb +2 -2
  61. data/samples/hello/hello_group.rb +2 -2
  62. data/samples/hello/hello_list_multi_selection.rb +2 -2
  63. data/samples/hello/hello_list_single_selection.rb +2 -2
  64. data/samples/hello/hello_progress_bar.rb +2 -2
  65. data/samples/hello/hello_radio.rb +2 -2
  66. data/samples/hello/hello_radio_group.rb +2 -2
  67. data/samples/hello/hello_scale.rb +2 -2
  68. data/samples/hello/hello_spinner.rb +2 -2
  69. data/samples/hello/hello_table.rb +2 -2
  70. data/samples/hello/hello_text.rb +2 -2
  71. data/samples/hello/hello_tool_bar.rb +2 -2
  72. data/samples/hello/hello_tray_item.rb +2 -2
  73. data/samples/hello/hello_tree.rb +4 -4
  74. metadata +18 -2
@@ -0,0 +1,26 @@
1
+ class KlondikeSolitaire
2
+ module View
3
+ class HiddenPlayingCard
4
+ include Glimmer::UI::CustomShape
5
+
6
+ options :card_x, :card_y
7
+
8
+ before_body do
9
+ self.card_x ||= 0
10
+ self.card_y ||= 0
11
+ end
12
+
13
+ body {
14
+ rectangle(card_x, card_y, 49, 79, 15, 15) {
15
+ background :red
16
+
17
+ # border
18
+ rectangle(0, 0, 49, 79, 15, 15) {
19
+ foreground :black
20
+ }
21
+ }
22
+ }
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ class KlondikeSolitaire
2
+ module View
3
+ class PlayingCard
4
+ include Glimmer::UI::CustomShape
5
+
6
+ options :card_x, :card_y, :model, :parent_pile
7
+
8
+ before_body do
9
+ self.card_x ||= 0
10
+ self.card_y ||= 0
11
+ end
12
+
13
+ body {
14
+ rectangle(card_x, card_y, 49, 79, 15, 15) {
15
+ background model.hidden ? :red : :white
16
+
17
+ # border
18
+ rectangle(0, 0, 49, 79, 15, 15) {
19
+ foreground :black
20
+ }
21
+
22
+ unless model.hidden?
23
+ text {
24
+ string model ? "#{model.rank_text}#{model.suit_text}" : ""
25
+ x 5
26
+ y 5
27
+ foreground model ? model.color : :transparent
28
+ }
29
+ end
30
+ }
31
+ }
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'dealing_pile'
2
+ require_relative 'dealt_pile'
3
+ require_relative 'column_pile'
4
+ require_relative 'foundation_pile'
5
+
6
+ require_relative '../model/game'
7
+
8
+ class KlondikeSolitaire
9
+ module View
10
+ class Tableau
11
+ include Glimmer::UI::CustomWidget
12
+
13
+ option :game
14
+
15
+ body {
16
+ canvas {
17
+ background :dark_green
18
+
19
+ # row 1
20
+ @foundation_piles = Model::PlayingCard::SUITS.each_with_index.map do |suit, i|
21
+ foundation_pile(pile_x: MARGIN + i*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, game: game, suit: suit)
22
+ end
23
+ @dealt_pile = dealt_pile(pile_x: MARGIN + 5*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, model: game.dealt_pile)
24
+ @dealing_pile = dealing_pile(pile_x: MARGIN + 6*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, model: game.dealing_pile)
25
+
26
+ # row 2
27
+ @column_piles = 7.times.map do |n|
28
+ column_pile(pile_x: MARGIN + n*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: PLAYING_CARD_HEIGHT + PLAYING_CARD_SPACING, model: game.column_piles[n])
29
+ end
30
+
31
+ on_mouse_up do |event|
32
+ if @dealing_pile.body_root.include?(event.x, event.y)
33
+ game.dealing_pile.deal!
34
+ end
35
+ end
36
+ }
37
+ }
38
+
39
+ end
40
+ end
41
+ end
@@ -65,9 +65,9 @@ end
65
65
  class Login
66
66
  include Glimmer::UI::CustomShell
67
67
 
68
- before_body {
68
+ before_body do
69
69
  @presenter = LoginPresenter.new
70
- }
70
+ end
71
71
 
72
72
  body {
73
73
  shell {
@@ -149,33 +149,33 @@ class MandelbrotFractal
149
149
 
150
150
  option :zoom, default: 1.0
151
151
 
152
- before_body {
152
+ before_body do
153
153
  Display.app_name = 'Mandelbrot Fractal'
154
154
  # pre-calculate mandelbrot image
155
155
  @mandelbrot_image = build_mandelbrot_image
156
- }
156
+ end
157
157
 
158
- after_body {
159
- observe(Mandelbrot, :work_in_progress) {
158
+ after_body do
159
+ observe(Mandelbrot, :work_in_progress) do
160
160
  update_mandelbrot_shell_title!
161
- }
162
- observe(Mandelbrot, :zoom) {
161
+ end
162
+ observe(Mandelbrot, :zoom) do
163
163
  update_mandelbrot_shell_title!
164
- }
164
+ end
165
165
  # pre-calculate zoomed mandelbrot images even before the user zooms in
166
166
  puts 'Starting background calculation thread...'
167
- @thread = Thread.new {
167
+ @thread = Thread.new do
168
168
  future_zoom = 1.5
169
- loop {
169
+ loop do
170
170
  puts "Creating mandelbrot for background calculation at zoom: #{future_zoom}"
171
171
  the_mandelbrot = Mandelbrot.for(max_iterations: color_palette.size - 1, zoom: future_zoom, background: true)
172
172
  pixels = the_mandelbrot.calculate_points
173
173
  build_mandelbrot_image(mandelbrot_zoom: future_zoom)
174
174
  @canvas.cursor = :cross unless @canvas.disposed?
175
175
  future_zoom += 0.5
176
- }
177
- }
178
- }
176
+ end
177
+ end
178
+ end
179
179
 
180
180
  body {
181
181
  shell(:no_resize) {
@@ -192,13 +192,13 @@ end
192
192
  class MetaSampleApplication
193
193
  include Glimmer::UI::CustomShell
194
194
 
195
- before_body {
195
+ before_body do
196
196
  Sample.ensure_user_glimmer_directory
197
197
  selected_sample_directory = SampleDirectory.sample_directories.first
198
198
  selected_sample = selected_sample_directory.samples.first
199
199
  selected_sample_directory.selected_sample_name = selected_sample.name
200
200
  Display.app_name = 'Glimmer Meta-Sample'
201
- }
201
+ end
202
202
 
203
203
  body {
204
204
  shell(:fill_screen) {
@@ -64,9 +64,9 @@ class Metronome
64
64
 
65
65
  attr_accessor :rhythm
66
66
 
67
- before_body {
67
+ before_body do
68
68
  @rhythm = Rhythm.new(4)
69
- }
69
+ end
70
70
 
71
71
  body {
72
72
  shell(:no_resize) {
@@ -65,7 +65,7 @@ class StockTicker
65
65
 
66
66
  include Glimmer::UI::CustomShell
67
67
 
68
- before_body {
68
+ before_body do
69
69
  @stocks = [
70
70
  Stock.new('DELL', 81),
71
71
  Stock.new('AAPL', 121),
@@ -126,16 +126,16 @@ class StockTicker
126
126
  end
127
127
  end
128
128
  end
129
- }
129
+ end
130
130
 
131
- after_body {
132
- @thread = Thread.new {
133
- loop {
131
+ after_body do
132
+ @thread = Thread.new do
133
+ loop do
134
134
  @stocks.each(&:tick!)
135
135
  sleep(0.01)
136
- }
137
- }
138
- }
136
+ end
137
+ end
138
+ end
139
139
 
140
140
  body {
141
141
  shell {
@@ -43,7 +43,7 @@ class Tetris
43
43
 
44
44
  attr_reader :game
45
45
 
46
- before_body {
46
+ before_body do
47
47
  @mutex = Mutex.new
48
48
  @game = Model::Game.new(playfield_width, playfield_height)
49
49
 
@@ -99,9 +99,9 @@ class Tetris
99
99
  exit(0)
100
100
  }
101
101
  }
102
- }
102
+ end
103
103
 
104
- after_body {
104
+ after_body do
105
105
  observe(@game, :game_over) do |game_over|
106
106
  if game_over
107
107
  show_high_score_dialog
@@ -117,7 +117,7 @@ class Tetris
117
117
  end
118
118
  end
119
119
  @game.start!
120
- }
120
+ end
121
121
 
122
122
  body {
123
123
  shell(:no_resize) {
@@ -29,9 +29,9 @@ class Tetris
29
29
  option :x, default: 0
30
30
  option :y, default: 0
31
31
 
32
- before_body {
32
+ before_body do
33
33
  self.bevel_pixel_size = 0.16*size.to_f if bevel_pixel_size.nil?
34
- }
34
+ end
35
35
 
36
36
  body {
37
37
  rectangle(x, y, size, size) {
@@ -29,10 +29,10 @@ class Tetris
29
29
 
30
30
  options :block_size, :game
31
31
 
32
- before_body {
32
+ before_body do
33
33
  @font_name = FONT_NAME
34
34
  @font_height = FONT_TITLE_HEIGHT
35
- }
35
+ end
36
36
 
37
37
  body {
38
38
  composite {
@@ -26,16 +26,16 @@ require_relative "tic_tac_toe/board"
26
26
  class TicTacToe
27
27
  include Glimmer::UI::CustomShell
28
28
 
29
- before_body {
29
+ before_body do
30
30
  @tic_tac_toe_board = Board.new
31
- }
31
+ end
32
32
 
33
- after_body {
34
- observe(@tic_tac_toe_board, :game_status) { |game_status|
33
+ after_body do
34
+ observe(@tic_tac_toe_board, :game_status) do |game_status|
35
35
  display_win_message if game_status == Board::WIN
36
36
  display_draw_message if game_status == Board::DRAW
37
- }
38
- }
37
+ end
38
+ end
39
39
 
40
40
  body {
41
41
  shell {
@@ -20,7 +20,7 @@ class Timer
20
20
  ## Use before_body block to pre-initialize variables to use in body
21
21
  #
22
22
  #
23
- before_body {
23
+ before_body do
24
24
  Display.setAppName('Glimmer Timer')
25
25
 
26
26
  @display = display {
@@ -34,11 +34,11 @@ class Timer
34
34
 
35
35
  @min = 0
36
36
  @sec = 0
37
- }
37
+ end
38
38
 
39
39
  ## Use after_body block to setup observers for widgets in body
40
40
  #
41
- after_body {
41
+ after_body do
42
42
  Thread.new {
43
43
  loop {
44
44
  sleep(1)
@@ -56,7 +56,7 @@ class Timer
56
56
  end
57
57
  }
58
58
  }
59
- }
59
+ end
60
60
 
61
61
  ## Add widget content inside custom shell body
62
62
  ## Top-most widget must be a shell or another custom shell
@@ -33,13 +33,13 @@ class Weather
33
33
 
34
34
  attr_accessor :city, :temp, :temp_min, :temp_max, :feels_like, :humidity
35
35
 
36
- before_body {
36
+ before_body do
37
37
  @weather_mutex = Mutex.new
38
38
  self.city = 'Montreal, QC, CA'
39
39
  fetch_weather!
40
- }
40
+ end
41
41
 
42
- after_body {
42
+ after_body do
43
43
  Thread.new do
44
44
  loop do
45
45
  sleep(10)
@@ -47,7 +47,7 @@ class Weather
47
47
  fetch_weather!
48
48
  end
49
49
  end
50
- }
50
+ end
51
51
 
52
52
  body {
53
53
  shell(:no_resize) {
@@ -26,9 +26,9 @@ class HelloButton
26
26
 
27
27
  attr_accessor :count
28
28
 
29
- before_body {
29
+ before_body do
30
30
  @count = 0
31
- }
31
+ end
32
32
 
33
33
  body {
34
34
  shell {
@@ -38,9 +38,9 @@ class HelloCCombo
38
38
 
39
39
  include Glimmer::UI::CustomShell
40
40
 
41
- before_body {
41
+ before_body do
42
42
  @person = Person.new
43
- }
43
+ end
44
44
 
45
45
  body {
46
46
  shell {
@@ -27,19 +27,19 @@ class HelloCanvas
27
27
  attr_accessor :selected_shape
28
28
  attr_accessor :artist
29
29
 
30
- before_body {
30
+ before_body do
31
31
  @image_object = image(File.expand_path('../../icons/scaffold_app.png', __dir__), width: 50)
32
32
  @artist = ''
33
- }
33
+ end
34
34
 
35
- after_body {
35
+ after_body do
36
36
  Thread.new {
37
37
  'Picasso'.chars.each do |character|
38
38
  sleep(1)
39
39
  self.artist += character
40
40
  end
41
41
  }
42
- }
42
+ end
43
43
 
44
44
  body {
45
45
  shell {
@@ -27,14 +27,14 @@ class HelloCanvasAnimation
27
27
 
28
28
  attr_accessor :animation_every, :animation_fps, :animation_frame_count, :animation_duration_limit, :animation_started, :animation_finished
29
29
 
30
- before_body {
30
+ before_body do
31
31
  @animation_every = 0.050 # seconds
32
32
  @animation_fps = 0
33
33
  @animation_frame_count = 100
34
34
  @animation_duration_limit = 0 # seconds
35
35
  @animation_started = true
36
36
  @animation_finished = false
37
- }
37
+ end
38
38
 
39
39
  body {
40
40
  shell {
@@ -37,7 +37,7 @@ class HelloCanvasDataBinding
37
37
  [:solid, :dash, :dot, :dashdot, :dashdotdot]
38
38
  end
39
39
 
40
- before_body {
40
+ before_body do
41
41
  self.x1_value = 0
42
42
  self.y1_value = 0
43
43
  self.x2_value = CANVAS_WIDTH
@@ -47,7 +47,7 @@ class HelloCanvasDataBinding
47
47
  self.foreground_blue = 228
48
48
  self.line_width_value = 3
49
49
  self.line_style_value = :dot
50
- }
50
+ end
51
51
 
52
52
  body {
53
53
  shell {