glimmer-dsl-swt 4.22.0.0 → 4.22.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +191 -169
  3. data/README.md +5 -5
  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 +98 -20
  8. data/docs/reference/GLIMMER_SAMPLES.md +13 -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 +2 -1
  13. data/lib/glimmer/dsl/swt/observe_expression.rb +2 -1
  14. data/lib/glimmer/dsl/swt/transform_expression.rb +1 -1
  15. data/lib/glimmer/launcher.rb +15 -14
  16. data/lib/glimmer/rake_task/scaffold.rb +2 -14
  17. data/lib/glimmer/swt/color_proxy.rb +5 -5
  18. data/lib/glimmer/swt/custom/drawable.rb +4 -0
  19. data/lib/glimmer/swt/custom/shape/line.rb +0 -1
  20. data/lib/glimmer/swt/custom/shape/path.rb +2 -2
  21. data/lib/glimmer/swt/custom/shape/path_segment.rb +2 -2
  22. data/lib/glimmer/swt/custom/shape/point.rb +8 -1
  23. data/lib/glimmer/swt/custom/shape.rb +170 -69
  24. data/lib/glimmer/swt/display_proxy.rb +15 -10
  25. data/lib/glimmer/swt/image_proxy.rb +5 -5
  26. data/lib/glimmer/swt/message_box_proxy.rb +5 -5
  27. data/lib/glimmer/swt/shape_listener_proxy.rb +55 -0
  28. data/lib/glimmer/swt/transform_proxy.rb +3 -3
  29. data/lib/glimmer/swt/tray_proxy.rb +4 -4
  30. data/lib/glimmer/swt/widget_proxy.rb +5 -7
  31. data/lib/glimmer/ui/custom_shape.rb +34 -10
  32. data/lib/glimmer/ui/custom_widget.rb +3 -8
  33. data/lib/glimmer-dsl-swt.rb +6 -2
  34. data/samples/elaborate/klondike_solitaire/model/column_pile.rb +0 -1
  35. data/samples/elaborate/klondike_solitaire/view/column_pile.rb +3 -16
  36. data/samples/elaborate/klondike_solitaire/view/dealing_pile.rb +1 -1
  37. data/samples/elaborate/klondike_solitaire/view/dealt_pile.rb +12 -5
  38. data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +2 -1
  39. data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +2 -2
  40. data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +2 -2
  41. data/samples/elaborate/klondike_solitaire/view/klondike_solitaire_menu_bar.rb +60 -0
  42. data/samples/elaborate/klondike_solitaire/view/playing_card.rb +3 -2
  43. data/samples/elaborate/klondike_solitaire.rb +13 -55
  44. data/samples/elaborate/mandelbrot_fractal.rb +3 -1
  45. data/samples/elaborate/quarto/model/game.rb +124 -0
  46. data/samples/elaborate/quarto/model/piece/cube.rb +31 -0
  47. data/samples/elaborate/quarto/model/piece/cylinder.rb +31 -0
  48. data/samples/elaborate/quarto/model/piece.rb +70 -0
  49. data/samples/elaborate/quarto/view/available_pieces_area.rb +72 -0
  50. data/samples/elaborate/quarto/view/board.rb +65 -0
  51. data/samples/elaborate/quarto/view/cell.rb +85 -0
  52. data/samples/elaborate/quarto/view/cube.rb +73 -0
  53. data/samples/elaborate/quarto/view/cylinder.rb +72 -0
  54. data/samples/elaborate/quarto/view/message_box_panel.rb +114 -0
  55. data/samples/elaborate/quarto/view/piece.rb +56 -0
  56. data/samples/elaborate/quarto/view/selected_piece_area.rb +69 -0
  57. data/samples/elaborate/quarto.rb +190 -0
  58. data/samples/hello/hello_custom_widget.rb +23 -5
  59. metadata +17 -23
  60. data/bin/glimmer_runner.rb +0 -4
@@ -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
@@ -0,0 +1,114 @@
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 MessageBoxPanel
25
+ include Glimmer::UI::CustomShape
26
+
27
+ FONT_HEIGHT_DEFAULT = 12
28
+ BUTTON_TEXT_DEFAULT = 'OK'
29
+
30
+ option :message
31
+ option :location_x, default: :default
32
+ option :location_y, default: :default
33
+ option :size_width
34
+ option :size_height
35
+ option :background_color, default: :white
36
+ option :foreground_color, default: :black
37
+ option :border_line_width, default: 1
38
+ option :text_font, default: {height: FONT_HEIGHT_DEFAULT}
39
+ option :text_color, default: :black
40
+
41
+ attr_reader :closed
42
+ alias closed? closed
43
+
44
+ def can_handle_observation_request?(observation_request)
45
+ observation_request == 'on_closed' || super
46
+ end
47
+
48
+ def handle_observation_request(observation_request, &block)
49
+ if observation_request == 'on_closed'
50
+ @on_closed_handlers ||= []
51
+ @on_closed_handlers << block
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ before_body do
58
+ @font_height = text_font[:height] || FONT_HEIGHT_DEFAULT
59
+ self.size_width ||= [:default, @font_height*4.0]
60
+ self.size_height ||= [:default, @font_height*4.0]
61
+ @text_offset = -1.2*@font_height
62
+
63
+ display {
64
+ on_swt_keyup do |key_event|
65
+ close if key_event.keyCode == swt(:cr)
66
+ end
67
+ }
68
+ end
69
+
70
+ body {
71
+ rectangle(location_x, location_y, size_width, size_height, round: true) {
72
+ background background_color
73
+
74
+ text(message, :default, [:default, @text_offset]) {
75
+ foreground :black
76
+ font text_font
77
+ }
78
+
79
+ rectangle(0, 0, :max, :max, round: true) { # border drawn around max dimensions of parent
80
+ foreground foreground_color
81
+ line_width border_line_width
82
+ }
83
+
84
+ rectangle(:default, [:default, @font_height + (@font_height/2.0)], @font_height*5.5, @font_height*2.0, @font_height, @font_height, round: true) {
85
+ background background_color
86
+
87
+ text(BUTTON_TEXT_DEFAULT) {
88
+ foreground text_color
89
+ font text_font
90
+ }
91
+
92
+ on_mouse_up do
93
+ close
94
+ end
95
+ }
96
+
97
+ rectangle(:default, [:default, @font_height + (@font_height/2.0)], @font_height*5.5, @font_height*2.0, @font_height, @font_height, round: true) { # border
98
+ foreground foreground_color
99
+ line_width border_line_width
100
+ }
101
+ }
102
+ }
103
+
104
+ def close
105
+ unless @closed
106
+ @closed = true
107
+ @on_closed_handlers&.each {|handler| handler.call}
108
+ @on_closed_handlers&.clear
109
+ body_root.dispose
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,56 @@
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 'cylinder'
23
+ require_relative 'cube'
24
+
25
+ class Quarto
26
+ module View
27
+ class Piece
28
+ include Glimmer::UI::CustomShape
29
+
30
+ SIZE_SHORT = 28
31
+ SIZE_TALL = 48
32
+ BASIC_SHAPE_WIDTH = 48
33
+ BASIC_SHAPE_HEIGHT = 28
34
+ LINE_THICKNESS = 2
35
+
36
+ options :game, :model, :location_x, :location_y
37
+
38
+ before_body do
39
+ @background_color = model.light? ? COLOR_LIGHT_WOOD : COLOR_DARK_WOOD
40
+ @size = model.short? ? SIZE_SHORT : SIZE_TALL
41
+ @shape_location_x = 0
42
+ @shape_location_y = model.short? ? 20 : 0
43
+ end
44
+
45
+ body {
46
+ shape(location_x, location_y) {
47
+ if model.is_a?(Model::Piece::Cylinder)
48
+ cylinder(location_x: @shape_location_x, location_y: @shape_location_y, cylinder_height: @size, oval_width: BASIC_SHAPE_WIDTH, oval_height: BASIC_SHAPE_HEIGHT, pitted: model.pitted?, background_color: @background_color, line_thickness: LINE_THICKNESS)
49
+ else
50
+ cube(location_x: @shape_location_x, location_y: @shape_location_y, cube_height: @size, rectangle_width: BASIC_SHAPE_WIDTH, rectangle_height: BASIC_SHAPE_HEIGHT, pitted: model.pitted?, background_color: @background_color, line_thickness: LINE_THICKNESS)
51
+ end
52
+ }
53
+ }
54
+ end
55
+ end
56
+ end