glimmer-dsl-swt 4.21.2.4 → 4.22.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +208 -167
  3. data/README.md +18 -11
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_COMMAND.md +2 -2
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +14 -3
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +277 -112
  8. data/docs/reference/GLIMMER_SAMPLES.md +26 -0
  9. data/glimmer-dsl-swt.gemspec +0 -0
  10. data/lib/ext/glimmer/config.rb +41 -24
  11. data/lib/glimmer/data_binding/observable_widget.rb +6 -6
  12. data/lib/glimmer/data_binding/widget_binding.rb +4 -3
  13. data/lib/glimmer/dsl/swt/observe_expression.rb +2 -1
  14. data/lib/glimmer/dsl/swt/sync_call_expression.rb +38 -0
  15. data/lib/glimmer/dsl/swt/transform_expression.rb +1 -1
  16. data/lib/glimmer/launcher.rb +15 -14
  17. data/lib/glimmer/rake_task/package.rb +5 -3
  18. data/lib/glimmer/rake_task/scaffold.rb +2 -14
  19. data/lib/glimmer/swt/color_proxy.rb +5 -5
  20. data/lib/glimmer/swt/custom/drawable.rb +8 -2
  21. data/lib/glimmer/swt/custom/shape/line.rb +0 -1
  22. data/lib/glimmer/swt/custom/shape/path.rb +2 -2
  23. data/lib/glimmer/swt/custom/shape/path_segment.rb +2 -2
  24. data/lib/glimmer/swt/custom/shape/point.rb +8 -1
  25. data/lib/glimmer/swt/custom/shape.rb +170 -69
  26. data/lib/glimmer/swt/display_proxy.rb +15 -10
  27. data/lib/glimmer/swt/image_proxy.rb +5 -5
  28. data/lib/glimmer/swt/message_box_proxy.rb +5 -5
  29. data/lib/glimmer/swt/shape_listener_proxy.rb +55 -0
  30. data/lib/glimmer/swt/shell_proxy.rb +1 -1
  31. data/lib/glimmer/swt/transform_proxy.rb +3 -3
  32. data/lib/glimmer/swt/tray_proxy.rb +4 -4
  33. data/lib/glimmer/swt/widget_proxy.rb +14 -10
  34. data/lib/glimmer/ui/custom_shape.rb +34 -10
  35. data/lib/glimmer/ui/custom_widget.rb +7 -10
  36. data/lib/glimmer-dsl-swt.rb +6 -2
  37. data/samples/elaborate/battleship/view/cell.rb +10 -2
  38. data/samples/elaborate/klondike_solitaire/model/column_pile.rb +0 -1
  39. data/samples/elaborate/klondike_solitaire/view/column_pile.rb +3 -16
  40. data/samples/elaborate/klondike_solitaire/view/dealing_pile.rb +1 -1
  41. data/samples/elaborate/klondike_solitaire/view/dealt_pile.rb +12 -5
  42. data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +2 -1
  43. data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +2 -2
  44. data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +2 -2
  45. data/samples/elaborate/klondike_solitaire/view/klondike_solitaire_menu_bar.rb +60 -0
  46. data/samples/elaborate/klondike_solitaire/view/playing_card.rb +3 -2
  47. data/samples/elaborate/klondike_solitaire.rb +13 -55
  48. data/samples/elaborate/mandelbrot_fractal.rb +3 -1
  49. data/samples/elaborate/quarto/model/game.rb +124 -0
  50. data/samples/elaborate/quarto/model/piece/cube.rb +31 -0
  51. data/samples/elaborate/quarto/model/piece/cylinder.rb +31 -0
  52. data/samples/elaborate/quarto/model/piece.rb +70 -0
  53. data/samples/elaborate/quarto/view/available_pieces_area.rb +72 -0
  54. data/samples/elaborate/quarto/view/board.rb +65 -0
  55. data/samples/elaborate/quarto/view/cell.rb +85 -0
  56. data/samples/elaborate/quarto/view/cube.rb +73 -0
  57. data/samples/elaborate/quarto/view/cylinder.rb +72 -0
  58. data/samples/elaborate/quarto/view/message_box_panel.rb +114 -0
  59. data/samples/elaborate/quarto/view/piece.rb +56 -0
  60. data/samples/elaborate/quarto/view/selected_piece_area.rb +69 -0
  61. data/samples/elaborate/quarto.rb +190 -0
  62. data/samples/hello/hello_custom_widget.rb +23 -5
  63. data/samples/hello/hello_scrolled_composite.rb +95 -0
  64. data/samples/hello/hello_world.rb +1 -0
  65. data/vendor/swt/linux/swt.jar +0 -0
  66. data/vendor/swt/linux_aarch64/swt.jar +0 -0
  67. data/vendor/swt/mac/swt.jar +0 -0
  68. data/vendor/swt/mac_aarch64/swt.jar +0 -0
  69. data/vendor/swt/windows/swt.jar +0 -0
  70. metadata +21 -25
  71. data/bin/glimmer_runner.rb +0 -4
@@ -0,0 +1,124 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative 'piece'
23
+ require_relative 'piece/cube'
24
+ require_relative 'piece/cylinder'
25
+
26
+ class Quarto
27
+ module Model
28
+ class Game
29
+ MOVES = [:select_piece, :place_piece]
30
+ PLAYER_NUMBERS = [1, 2]
31
+ ROW_COUNT = 4
32
+ COLUMN_COUNT = 4
33
+
34
+ attr_accessor :board, :available_pieces, :selected_piece, :current_move, :current_player_number, :over, :winner_player_number
35
+ alias over? over
36
+
37
+ def initialize
38
+ start
39
+ end
40
+
41
+ def start
42
+ self.over = false
43
+ self.board = ROW_COUNT.times.map {COLUMN_COUNT.times.map {nil}}
44
+ self.available_pieces = Piece.all_pieces.dup
45
+ self.selected_piece = nil
46
+ self.current_player_number = 1
47
+ self.current_move = MOVES.first
48
+ self.winner_player_number = nil
49
+ end
50
+ alias restart start
51
+
52
+ def select_piece(piece)
53
+ self.selected_piece = piece
54
+ next_player
55
+ next_move
56
+ end
57
+
58
+ def place_piece(piece, row:, column:)
59
+ if @board[row][column].nil?
60
+ @board[row][column] = piece
61
+ if win?
62
+ self.winner_player_number = current_player_number # must set before updating observed over attribute
63
+ self.over = true
64
+ elsif draw?
65
+ self.winner_player_number = nil # must set before updating observed over attribute
66
+ self.over = true
67
+ else
68
+ next_move
69
+ end
70
+ end
71
+ end
72
+
73
+ def next_move
74
+ last_move = current_move
75
+ last_move_index = MOVES.index(last_move)
76
+ self.current_move = MOVES[(last_move_index + 1)%MOVES.size]
77
+ end
78
+
79
+ def next_player
80
+ last_player_number = current_player_number
81
+ last_player_number_index = PLAYER_NUMBERS.index(current_player_number)
82
+ self.current_player_number = PLAYER_NUMBERS[(last_player_number_index + 1)%PLAYER_NUMBERS.size]
83
+ end
84
+
85
+ def draw?
86
+ !win? && board.flatten.compact.count == 12
87
+ end
88
+
89
+ def win?
90
+ row_win? || column_win? || diagonal_win?
91
+ end
92
+
93
+ def row_win?
94
+ ROW_COUNT.times.any? { |row| equivalent_pieces?(@board[row]) }
95
+ end
96
+
97
+ def column_win?
98
+ COLUMN_COUNT.times.any? do |column|
99
+ equivalent_pieces?(ROW_COUNT.times.map {|row| @board[row][column]})
100
+ end
101
+ end
102
+
103
+ def diagonal_win?
104
+ diagonal1_win? || diagonal2_win?
105
+ end
106
+
107
+ def diagonal1_win?
108
+ equivalent_pieces?(ROW_COUNT.times.map { |n| @board[n][n] })
109
+ end
110
+
111
+ def diagonal2_win?
112
+ equivalent_pieces?(ROW_COUNT.times.map { |n| @board[ROW_COUNT - 1 - n][n] })
113
+ end
114
+
115
+ def equivalent_pieces?(the_pieces)
116
+ return false if the_pieces.any?(&:nil?)
117
+ the_pieces.map(&:class).uniq.size == 1 ||
118
+ the_pieces.map(&:pitted).uniq.size == 1 ||
119
+ the_pieces.map(&:height).uniq.size == 1 ||
120
+ the_pieces.map(&:color).uniq.size == 1
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative '../piece'
23
+
24
+ class Quarto
25
+ module Model
26
+ class Piece
27
+ class Cube < Piece
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative '../piece'
23
+
24
+ class Quarto
25
+ module Model
26
+ class Piece
27
+ class Cylinder < Piece
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,70 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Quarto
23
+ module Model
24
+ class Piece
25
+ class << self
26
+ def all_pieces
27
+ [
28
+ Cube.new(pitted: false, height: :tall, color: :light),
29
+ Cylinder.new(pitted: false, height: :tall, color: :light),
30
+ Cube.new(pitted: true, height: :short, color: :light),
31
+ Cube.new(pitted: false, height: :short, color: :light),
32
+ Cube.new(pitted: false, height: :tall, color: :dark),
33
+ Cylinder.new(pitted: true, height: :short, color: :dark),
34
+ Cylinder.new(pitted: false, height: :short, color: :dark),
35
+ Cylinder.new(pitted: true, height: :tall, color: :dark),
36
+ Cylinder.new(pitted: false, height: :tall, color: :dark),
37
+ Cube.new(pitted: true, height: :short, color: :dark),
38
+ Cube.new(pitted: false, height: :short, color: :dark),
39
+ Cube.new(pitted: true, height: :tall, color: :dark),
40
+ ].freeze
41
+ end
42
+ end
43
+
44
+ attr_reader :pitted, :height, :color
45
+ alias pitted? pitted
46
+
47
+ def initialize(pitted: , height: , color: )
48
+ @pitted = pitted
49
+ @height = height
50
+ @color = color
51
+ end
52
+
53
+ def light?
54
+ @color == :light
55
+ end
56
+
57
+ def dark?
58
+ @color == :dark
59
+ end
60
+
61
+ def tall?
62
+ @height == :tall
63
+ end
64
+
65
+ def short?
66
+ @height == :short
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,72 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative 'piece'
23
+
24
+ class Quarto
25
+ module View
26
+ class AvailablePiecesArea
27
+ include Glimmer::UI::CustomShape
28
+
29
+ options :game
30
+ option :location_x, default: 0
31
+ option :location_y, default: 0
32
+
33
+ attr_reader :pieces
34
+
35
+ after_body do
36
+ reset_pieces
37
+ end
38
+
39
+ body {
40
+ rectangle(location_x, location_y, PIECES_AREA_WIDTH, AVAILABLE_PIECES_AREA_HEIGHT) {
41
+ background COLOR_WOOD
42
+
43
+ rectangle(0, 0, :max, :max, round: true) { # border
44
+ foreground :black
45
+ line_width 2
46
+ }
47
+
48
+ text('Available Pieces', 15, 10) {
49
+ font height: 18, style: :bold
50
+ }
51
+ }
52
+ }
53
+
54
+ def reset_pieces
55
+ @pieces&.dup&.each { |piece| piece.dispose(redraw: false) }
56
+ body_root.content {
57
+ x_offset = 15
58
+ y_offset = 10 + 18 + 10
59
+ x_spacing = 10
60
+ y_spacing = 35
61
+ row_count = 3
62
+ column_count = 4
63
+ @pieces = row_count.times.map do |row|
64
+ column_count.times.map do |column|
65
+ piece(game: game, model: game.available_pieces[row*column_count + column], location_x: x_offset + column*(View::Piece::BASIC_SHAPE_WIDTH + x_spacing), location_y: y_offset + row*(View::Piece::SIZE_TALL + y_spacing))
66
+ end
67
+ end.flatten
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,65 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative 'cell'
23
+
24
+ class Quarto
25
+ module View
26
+ class Board
27
+ include Glimmer::UI::CustomShape
28
+
29
+ option :game
30
+ option :location_x, default: 0
31
+ option :location_y, default: 0
32
+
33
+ after_body do
34
+ reset_cells
35
+ end
36
+
37
+ body {
38
+ rectangle(location_x, location_y, BOARD_DIAMETER, BOARD_DIAMETER, round: true) {
39
+ background :black
40
+
41
+ text("Glimmer\nQuarto", BOARD_DIAMETER - 69, BOARD_DIAMETER - 43) {
42
+ foreground COLOR_WOOD
43
+ }
44
+
45
+ @cell_container = oval(0, 0, :max, :max) {
46
+ foreground COLOR_WOOD
47
+ line_width CELL_LINE_WIDTH
48
+
49
+ }
50
+ }
51
+ }
52
+
53
+ def reset_cells
54
+ @cell_container.shapes.dup.each(&:dispose)
55
+ @cell_container.content {
56
+ @cells = ROW_COUNT.times.map do |row|
57
+ COLUMN_COUNT.times.map do |column|
58
+ cell(game: game, row: row, column: column)
59
+ end
60
+ end.flatten
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,85 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Quarto
23
+ module View
24
+ class Cell
25
+ include Glimmer::UI::CustomShape
26
+
27
+ options :game, :row, :column
28
+
29
+ attr_reader :placed_piece
30
+
31
+ before_body do
32
+ @board_x_offset = (BOARD_DIAMETER - COLUMN_COUNT * (CELL_DIAMETER + CELL_LINE_WIDTH + CELL_MARGIN) + CELL_LINE_WIDTH + CELL_MARGIN) / 2.0
33
+ @board_y_offset = (BOARD_DIAMETER - ROW_COUNT * (CELL_DIAMETER + CELL_LINE_WIDTH + CELL_MARGIN) + CELL_LINE_WIDTH + CELL_MARGIN) / 2.0
34
+ end
35
+
36
+ body {
37
+ oval(@board_x_offset + column * (CELL_DIAMETER + CELL_LINE_WIDTH + CELL_MARGIN),
38
+ @board_y_offset + row * (CELL_DIAMETER + CELL_LINE_WIDTH + CELL_MARGIN),
39
+ CELL_DIAMETER,
40
+ CELL_DIAMETER) {
41
+ background :black
42
+ line_width CELL_LINE_WIDTH
43
+ transform board_rotation_transform
44
+
45
+ oval { # this draws an outline around max dimensions by default (when no x,y,w,h specified)
46
+ foreground COLOR_WOOD
47
+ line_width CELL_LINE_WIDTH
48
+ transform board_rotation_transform
49
+ }
50
+
51
+ on_drop do |drop_event|
52
+ dragged_piece = drop_event.dragged_shape
53
+ if dragged_piece.parent.get_data('custom_shape').is_a?(SelectedPieceArea)
54
+ model = dragged_piece.get_data('custom_shape').model
55
+ dragged_piece.dispose
56
+ new_x, new_y = body_root.transform_point(body_root.absolute_x, body_root.absolute_y)
57
+ parent_proxy.content {
58
+ piece(game: game, model: model, location_x: new_x, location_y: new_y) {
59
+ transform {
60
+ translate -38, -14
61
+ }
62
+ }
63
+ }
64
+ game.place_piece(model, row: row, column: column)
65
+ else
66
+ drop_event.doit = false
67
+ end
68
+ end
69
+ }
70
+ }
71
+
72
+ def board_rotation_transform
73
+ @board_rotation_transform ||= transform {
74
+ # main rotation is done by moving shape to be centered in origin, rotating, and then moving shape back
75
+ translate (SHELL_MARGIN + BOARD_DIAMETER)/2.0, (SHELL_MARGIN + BOARD_DIAMETER)/2.0
76
+ rotate 45
77
+ translate -(SHELL_MARGIN + BOARD_DIAMETER)/2.0, -(SHELL_MARGIN + BOARD_DIAMETER)/2.0
78
+
79
+ # extra translation to improve location of rotated cells
80
+ translate 7, -4
81
+ }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,73 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Quarto
23
+ module View
24
+ class Cube
25
+ include Glimmer::UI::CustomShape
26
+
27
+ DEFAULT_SIZE = 28
28
+
29
+ options :location_x, :location_y, :rectangle_width, :rectangle_height, :cube_height, :pitted, :background_color, :line_thickness
30
+ alias pitted? pitted
31
+
32
+ before_body do
33
+ self.location_x ||= 0
34
+ self.location_y ||= 0
35
+ self.rectangle_width ||= rectangle_height || cube_height || DEFAULT_SIZE
36
+ self.rectangle_height ||= rectangle_width || cube_height || DEFAULT_SIZE
37
+ self.cube_height ||= rectangle_width || rectangle_height || DEFAULT_SIZE
38
+ self.line_thickness ||= 1
39
+ end
40
+
41
+ body {
42
+ shape(location_x, location_y) {
43
+ polygon(0, cube_height + rectangle_height / 2.0, rectangle_width / 2.0, cube_height, rectangle_width, cube_height + rectangle_height / 2.0, rectangle_width / 2.0, cube_height + rectangle_height) {
44
+ background background_color
45
+ }
46
+ polygon(0, cube_height + rectangle_height / 2.0, rectangle_width / 2.0, cube_height, rectangle_width, cube_height + rectangle_height / 2.0, rectangle_width / 2.0, cube_height + rectangle_height) {
47
+ line_width line_thickness
48
+ }
49
+ rectangle(0, rectangle_height / 2.0, rectangle_width, cube_height) {
50
+ background background_color
51
+ }
52
+ polyline(0, rectangle_height / 2.0 + cube_height, 0, rectangle_height / 2.0, rectangle_width, rectangle_height / 2.0, rectangle_width, rectangle_height / 2.0 + cube_height) {
53
+ line_width line_thickness
54
+ }
55
+ polygon(0, rectangle_height / 2.0, rectangle_width / 2.0, 0, rectangle_width, rectangle_height / 2.0, rectangle_width / 2.0, rectangle_height) {
56
+ background background_color
57
+ }
58
+ polygon(0, rectangle_height / 2.0, rectangle_width / 2.0, 0, rectangle_width, rectangle_height / 2.0, rectangle_width / 2.0, rectangle_height) {
59
+ line_width line_thickness
60
+ }
61
+ line(rectangle_width / 2.0, cube_height + rectangle_height, rectangle_width / 2.0, rectangle_height) {
62
+ line_width line_thickness
63
+ }
64
+ if pitted?
65
+ oval(rectangle_width / 4.0, rectangle_height / 4.0, rectangle_width / 2.0, rectangle_height / 2.0) {
66
+ background :black
67
+ }
68
+ end
69
+ }
70
+ }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,72 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Quarto
23
+ module View
24
+ class Cylinder
25
+ include Glimmer::UI::CustomShape
26
+
27
+ DEFAULT_SIZE = 28
28
+
29
+ options :location_x, :location_y, :oval_width, :oval_height, :cylinder_height, :pitted, :background_color, :line_thickness
30
+ alias pitted? pitted
31
+
32
+ before_body do
33
+ self.location_x ||= 0
34
+ self.location_y ||= 0
35
+ self.oval_width ||= oval_height || cylinder_height || DEFAULT_SIZE
36
+ self.oval_height ||= oval_width || cylinder_height || DEFAULT_SIZE
37
+ self.cylinder_height ||= oval_width || oval_height || DEFAULT_SIZE
38
+ self.line_thickness ||= 1
39
+ end
40
+
41
+ body {
42
+ shape(location_x, location_y) {
43
+ oval(0, cylinder_height, oval_width, oval_height) {
44
+ background background_color
45
+
46
+ oval { # draws with foreground :black and has max size within parent by default
47
+ line_width line_thickness
48
+ }
49
+ }
50
+ rectangle(0, oval_height / 2.0, oval_width, cylinder_height) {
51
+ background background_color
52
+ }
53
+ polyline(0, oval_height / 2.0 + cylinder_height, 0, oval_height / 2.0, oval_width, oval_height / 2.0, oval_width, oval_height / 2.0 + cylinder_height) {
54
+ line_width line_thickness
55
+ }
56
+ oval(0, 0, oval_width, oval_height) {
57
+ background background_color
58
+
59
+ oval { # draws with foreground :black and has max size within parent by default
60
+ line_width line_thickness
61
+ }
62
+ }
63
+ if pitted?
64
+ oval(oval_width / 4.0, oval_height / 4.0, oval_width / 2.0, oval_height / 2.0) {
65
+ background :black
66
+ }
67
+ end
68
+ }
69
+ }
70
+ end
71
+ end
72
+ end