glimmer-dsl-swt 4.20.13.14 → 4.20.13.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
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 '../model/grid'
23
+
24
+ require_relative 'cell'
25
+
26
+ class Battleship
27
+ module View
28
+ class Grid
29
+ include Glimmer::UI::CustomWidget
30
+
31
+ options :game, :player
32
+
33
+ body {
34
+ composite {
35
+ grid_layout(Model::Grid::WIDTH + 1, true) {
36
+ margin_width 0
37
+ margin_height 0
38
+ horizontal_spacing 0
39
+ vertical_spacing 0
40
+ }
41
+
42
+ label(:center) {
43
+ layout_data(:fill, :center, true, false) {
44
+ horizontal_span (Model::Grid::WIDTH + 1)
45
+ }
46
+
47
+ text player.to_s.capitalize
48
+ font height: 20, style: :bold
49
+ }
50
+
51
+ label # filler
52
+ Model::Grid::WIDTH.times do |column_index|
53
+ label {
54
+ text (column_index + 1).to_s
55
+ font height: 16
56
+ }
57
+ end
58
+
59
+ Model::Grid::HEIGHT.times do |row_index|
60
+ label {
61
+ text Model::Grid::ROW_ALPHABETS[row_index]
62
+ font height: 16
63
+ }
64
+ Model::Grid::WIDTH.times do |column_index|
65
+ cell(game: game, player: player, row_index: row_index, column_index: column_index) {
66
+ layout_data {
67
+ width_hint 25
68
+ height_hint 25
69
+ }
70
+ }
71
+ end
72
+ end
73
+ }
74
+ }
75
+ end
76
+ end
77
+ 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 Battleship
25
+ module View
26
+ class Ship
27
+ include Glimmer::UI::CustomWidget
28
+
29
+ options :game, :player, :ship_name, :ship_length
30
+
31
+ body {
32
+ composite {
33
+ row_layout(:vertical) {
34
+ fill true
35
+ margin_width 0
36
+ margin_height 0
37
+ }
38
+
39
+ label {
40
+ text ship_name.to_s.titlecase
41
+ font height: 16
42
+ }
43
+
44
+ composite {
45
+ grid_layout(ship_length, true) {
46
+ margin_width 0
47
+ margin_height 0
48
+ horizontal_spacing 0
49
+ vertical_spacing 0
50
+ }
51
+
52
+ ship_length.times do |column_index|
53
+ cell(game: game, player: player, type: :ship, column_index: column_index, ship: game.ship_collections[player].ships[ship_name]) {
54
+ layout_data {
55
+ width_hint 25
56
+ height_hint 25
57
+ }
58
+ }
59
+ end
60
+ }
61
+ }
62
+ }
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,49 @@
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 '../model/game'
23
+ require_relative '../model/ship_collection'
24
+
25
+ require_relative 'ship'
26
+
27
+ class Battleship
28
+ module View
29
+ class ShipCollection
30
+ include Glimmer::UI::CustomWidget
31
+
32
+ options :game, :player
33
+
34
+ body {
35
+ composite {
36
+ row_layout(:vertical) {
37
+ fill true
38
+ margin_width 0
39
+ margin_height 0
40
+ }
41
+
42
+ Model::ShipCollection::BATTLESHIPS.each do |ship_name, ship_length|
43
+ ship(game: game, player: player, ship_name: ship_name, ship_length: ship_length)
44
+ end
45
+ }
46
+ }
47
+ end
48
+ end
49
+ end
@@ -26,8 +26,6 @@ require_relative 'connect4/model/grid'
26
26
  class Connect4
27
27
  include Glimmer::UI::CustomShell
28
28
 
29
- WIDTH = 7
30
- HEIGHT = 6
31
29
  COLOR_BACKGROUND = rgb(63, 104, 212)
32
30
  COLOR_EMPTY_SLOT = :white
33
31
  COLOR_COIN1 = rgb(236, 223, 56)
@@ -36,7 +34,7 @@ class Connect4
36
34
  attr_accessor :current_player_color
37
35
 
38
36
  before_body do
39
- @grid = Model::Grid.new(WIDTH, HEIGHT)
37
+ @grid = Model::Grid.new
40
38
  select_player_color
41
39
  end
42
40
 
@@ -68,13 +66,13 @@ class Connect4
68
66
 
69
67
  body {
70
68
  shell(:no_resize) {
71
- grid_layout(7, true)
69
+ grid_layout(Model::Grid::WIDTH, true)
72
70
 
73
71
  text 'Glimmer Connect 4'
74
72
  background COLOR_BACKGROUND
75
73
 
76
- HEIGHT.times do |row_index|
77
- WIDTH.times do |column_index|
74
+ Model::Grid::HEIGHT.times do |row_index|
75
+ Model::Grid::WIDTH.times do |column_index|
78
76
  canvas {
79
77
  layout_data {
80
78
  width_hint 50
@@ -24,12 +24,13 @@ require_relative 'slot'
24
24
  class Connect4
25
25
  module Model
26
26
  class Grid
27
- attr_reader :width, :height, :slot_rows
27
+ WIDTH = 7
28
+ HEIGHT = 6
29
+
30
+ attr_reader :slot_rows
28
31
  attr_accessor :current_player, :game_over
29
32
 
30
- def initialize(width, height)
31
- @width = width
32
- @height = height
33
+ def initialize
33
34
  build_slots
34
35
  start!
35
36
  end
@@ -60,8 +61,8 @@ class Connect4
60
61
  private
61
62
 
62
63
  def build_slots
63
- @slot_rows = height.times.map do |row_index|
64
- width.times.map do |column_index|
64
+ @slot_rows = HEIGHT.times.map do |row_index|
65
+ WIDTH.times.map do |column_index|
65
66
  Slot.new(self)
66
67
  end
67
68
  end
@@ -82,10 +83,10 @@ class Connect4
82
83
  def evaluate_horizontal_win
83
84
  connections = nil
84
85
  last_slot_value = nil
85
- height.times do |row_index|
86
+ HEIGHT.times do |row_index|
86
87
  connections = nil
87
88
  last_slot_value = nil
88
- width.times do |column_index|
89
+ WIDTH.times do |column_index|
89
90
  slot = @slot_rows[row_index][column_index]
90
91
  if slot.value.to_i > 0 && slot.value == last_slot_value
91
92
  connections += 1
@@ -103,10 +104,10 @@ class Connect4
103
104
  def evaluate_vertical_win
104
105
  connections = nil
105
106
  last_slot_value = nil
106
- width.times do |column_index|
107
+ WIDTH.times do |column_index|
107
108
  connections = nil
108
109
  last_slot_value = nil
109
- height.times do |row_index|
110
+ HEIGHT.times do |row_index|
110
111
  slot = @slot_rows[row_index][column_index]
111
112
  if slot.value.to_i > 0 && slot.value == last_slot_value
112
113
  connections += 1
@@ -43,7 +43,6 @@ class KlondikeSolitaire
43
43
  end
44
44
  drop_event.dragged_shape.dispose
45
45
  rescue => e
46
- # pd e
47
46
  drop_event.doit = false
48
47
  end
49
48
  end
@@ -36,7 +36,6 @@ class KlondikeSolitaire
36
36
 
37
37
  on_drop do |drop_event|
38
38
  begin
39
- # TODO make sure one cannot drag a column pile of cards here
40
39
  card_shape = drop_event.dragged_shape.get_data('custom_shape')
41
40
  card = card_shape.model
42
41
  card_parent_pile = card_shape.parent_pile
@@ -46,7 +45,6 @@ class KlondikeSolitaire
46
45
  card_source_model.remove!(card)
47
46
  drop_event.dragged_shape.dispose
48
47
  rescue => e
49
- # pd e
50
48
  drop_event.doit = false
51
49
  end
52
50
  end
@@ -0,0 +1,67 @@
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 'glimmer-dsl-swt'
23
+
24
+ include Glimmer
25
+
26
+ shell {
27
+ row_layout(:vertical) {
28
+ fill true
29
+ center true
30
+ }
31
+
32
+ text 'Hello, Arrow!'
33
+
34
+ label(:center) {
35
+ text 'Click the arrow to get a menu.'
36
+ }
37
+
38
+ arrow { # can be customized by passing `:arrow` SWT style + `:left`, `:right`, `:up`, or `:down` (default)
39
+ menu {
40
+ menu_item {
41
+ text 'Item &1'
42
+
43
+ on_widget_selected do
44
+ message_box {
45
+ text 'Item 1'
46
+ message 'Item 1 selected!'
47
+ }.open
48
+ end
49
+ }
50
+ menu_item {
51
+ text 'Item &2'
52
+
53
+ on_widget_selected do
54
+ message_box {
55
+ text 'Item 2'
56
+ message 'Item 2 selected!'
57
+ }.open
58
+ end
59
+ }
60
+ }
61
+
62
+ on_widget_selected do |event|
63
+ event.widget.menu.visible = true
64
+ end
65
+ }
66
+
67
+ }.open
@@ -88,6 +88,8 @@ class EmailShell
88
88
  end
89
89
 
90
90
  class HelloCustomShell
91
+ include Glimmer
92
+
91
93
  Email = Struct.new(:date, :subject, :from, :message, keyword_init: true)
92
94
  EmailSystem = Struct.new(:emails, keyword_init: true)
93
95
 
@@ -0,0 +1,58 @@
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 'glimmer-dsl-swt'
23
+
24
+ class HelloScale
25
+ include Glimmer::UI::CustomShell
26
+
27
+ attr_accessor :value
28
+
29
+ before_body do
30
+ @value = 50
31
+ end
32
+
33
+ body {
34
+ shell {
35
+ row_layout(:vertical) {
36
+ fill true
37
+ center true
38
+ }
39
+
40
+ text 'Hello, Slider!'
41
+
42
+ label(:center) {
43
+ text <= [self, :value]
44
+ }
45
+
46
+ slider { # optionally takes :vertical or :horizontal (default) SWT style
47
+ minimum 0
48
+ maximum 110 # leave room for 10 extra (slider stops at 100)
49
+ page_increment 10 # page increment occurs when clicking area between slider and beginning or end
50
+ selection <=> [self, :value]
51
+ }
52
+
53
+ }
54
+
55
+ }
56
+ end
57
+
58
+ HelloScale.launch