glimmer-dsl-gtk 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 908b538188d1ca4fd8c7b96bcc1a890febf29a55d2f37d09a81fa1849b15e7fa
4
- data.tar.gz: c88057203f02fed224707cf1ee12f5b66f71d6b9b4632986f0ac3b7f973fd59c
3
+ metadata.gz: 13f25c4ca569b9dd667c4d87e2e175d9c953f9e613ab572cffda63f8cb181fb1
4
+ data.tar.gz: 4b28c418c1957467b0eaa9de2dbbd03cf9e63542a3e3d6425c6d101c04f90c09
5
5
  SHA512:
6
- metadata.gz: ec820ca1c3782e2b7311bf917bf97f2369da65fff6cf110f887a60e164775ad2b41df9f25a9c904beffd67f3ebd9b6e7decd57f6a222f1a24a5725c5f396d8c1
7
- data.tar.gz: 759f1b973090ed6df0ef78daee7a4220b0261090b300a4a9164fcda5a3779d3a831048fa25d9936848903e639358d5942fec4694e6174bb950f908b7abaeec0b
6
+ metadata.gz: 62541e82fbb67f300bee346c685942a24c98a93662830021d75b4c4fe6b4e0eba0ca4ad048f745f54b051d52e990d9d3220c551d47cb33f163d9c3c9812d3bce
7
+ data.tar.gz: 7a0af395ce5e7ed8da206052341dc98ef7a4eb0d967413bdb9deb21f15647a07713fea1b0fca1296acc6bff46d96251ff2a9fb0a9962f34383328f36e041560a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.4
4
+
5
+ - Tetris Menu Bar
6
+ - Tetris Score Board
7
+ - Tetris Next Tetromino Preview
8
+
3
9
  ## 0.0.3
4
10
 
5
11
  - samples/elaborate/tetris.rb (basic Tetris implementation)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for GTK 0.0.3
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for GTK 0.0.4
2
2
  ## Ruby-GNOME Desktop Development GUI Library
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-gtk.svg)](http://badge.fury.io/rb/glimmer-dsl-gtk)
4
4
  [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -61,6 +61,7 @@ sudo apt install -y -V libgirepository1.0-dev
61
61
  On the Mac, make sure to:
62
62
  - Have [Homebrew](https://brew.sh/) installed
63
63
  - Run this [Homebrew](https://brew.sh/) command to have GTK display GUI icons: `brew install adwaita-icon-theme`
64
+ - (Optional) You can upgrade your GTK3/GTK4/GTK+ by running: `brew install gtk+3` / `brew install gtk+4` / `brew install gtk+`
64
65
 
65
66
  ### Windows
66
67
 
@@ -79,7 +80,7 @@ gem install glimmer-dsl-gtk
79
80
 
80
81
  Add the following to `Gemfile`:
81
82
  ```
82
- gem 'glimmer-dsl-gtk', '~> 0.0.3'
83
+ gem 'glimmer-dsl-gtk', '~> 0.0.4'
83
84
  ```
84
85
 
85
86
  And, then run:
@@ -842,7 +843,14 @@ class Tetris
842
843
  default_size Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE # + 98
843
844
 
844
845
  box(:vertical) {
845
- @playfield_blocks = playfield(playfield_width: @game.playfield_width, playfield_height: @game.playfield_height, block_size: BLOCK_SIZE)
846
+ tetris_menu_bar
847
+
848
+ box(:horizontal) {
849
+ @playfield_blocks = playfield(playfield_width: @game.playfield_width, playfield_height: @game.playfield_height, block_size: BLOCK_SIZE)
850
+
851
+ score_board
852
+ }
853
+
846
854
  }
847
855
 
848
856
  on(:key_press_event) do |widget, key_event|
@@ -900,6 +908,135 @@ class Tetris
900
908
  end
901
909
  end
902
910
  end
911
+
912
+ Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
913
+ Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
914
+ observe(@game.preview_playfield[row][column], :color) do |new_color|
915
+ color = new_color
916
+ block = @preview_playfield_blocks[row][column]
917
+ block[:background_square].fill = color
918
+ block[:top_bevel_edge].fill = [color[0] + 4*BEVEL_CONSTANT, color[1] + 4*BEVEL_CONSTANT, color[2] + 4*BEVEL_CONSTANT]
919
+ block[:right_bevel_edge].fill = [color[0] - BEVEL_CONSTANT, color[1] - BEVEL_CONSTANT, color[2] - BEVEL_CONSTANT]
920
+ block[:bottom_bevel_edge].fill = [color[0] - BEVEL_CONSTANT, color[1] - BEVEL_CONSTANT, color[2] - BEVEL_CONSTANT]
921
+ block[:left_bevel_edge].fill = [color[0] - BEVEL_CONSTANT, color[1] - BEVEL_CONSTANT, color[2] - BEVEL_CONSTANT]
922
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
923
+ block[:drawing_area].queue_draw
924
+ end
925
+ end
926
+ end
927
+
928
+ observe(@game, :score) do |new_score|
929
+ @score_label.text = new_score.to_s
930
+ end
931
+
932
+ observe(@game, :lines) do |new_lines|
933
+ @lines_label.text = new_lines.to_s
934
+ end
935
+
936
+ observe(@game, :level) do |new_level|
937
+ @level_label.text = new_level.to_s
938
+ end
939
+ end
940
+
941
+ def tetris_menu_bar
942
+ menu_bar {
943
+ menu_item(label: 'Game') { |mi|
944
+ m = menu {
945
+ check_menu_item(label: 'Pause') {
946
+ on(:activate) do
947
+ @game.paused = !@game.paused?
948
+ end
949
+ }
950
+
951
+ menu_item(label: 'Restart') {
952
+ on(:activate) do
953
+ @game.restart!
954
+ end
955
+ }
956
+
957
+ separator_menu_item
958
+
959
+ menu_item(label: 'Exit') {
960
+ on(:activate) do
961
+ @main_window.close
962
+ end
963
+ }
964
+ }
965
+ mi.submenu = m.gtk
966
+ }
967
+
968
+ menu_item(label: 'View') { |mi|
969
+ m = menu {
970
+ menu_item(label: 'Show High Scores') {
971
+ on(:activate) do
972
+ show_high_score_dialog
973
+ end
974
+ }
975
+
976
+ menu_item(label: 'Clear High Scores') {
977
+ on(:activate) do
978
+ @game.clear_high_scores!
979
+ end
980
+ }
981
+ }
982
+ mi.submenu = m.gtk
983
+ }
984
+
985
+ menu_item(label: 'Options') { |mi|
986
+ m = menu {
987
+ rmi = radio_menu_item(nil, 'Instant Down on Up') {
988
+ on(:activate) do
989
+ @game.instant_down_on_up!
990
+ end
991
+ }
992
+
993
+ default_rmi = radio_menu_item(rmi.group, 'Rotate Right on Up') {
994
+ on(:activate) do
995
+ @game.rotate_right_on_up!
996
+ end
997
+ }
998
+ default_rmi.activate
999
+
1000
+ radio_menu_item(rmi.group, 'Rotate Left on Up') {
1001
+ on(:activate) do
1002
+ @game.rotate_left_on_up!
1003
+ end
1004
+ }
1005
+ }
1006
+ mi.submenu = m.gtk
1007
+ }
1008
+
1009
+ menu_item(label: 'Options') { |mi|
1010
+ m = menu {
1011
+ menu_item(label: 'About') {
1012
+ on(:activate) do
1013
+ show_about_dialog
1014
+ end
1015
+ }
1016
+ }
1017
+ mi.submenu = m.gtk
1018
+ }
1019
+ }
1020
+ end
1021
+
1022
+ def score_board
1023
+ box(:vertical) {
1024
+ label
1025
+ @preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
1026
+
1027
+ label
1028
+ label('Score')
1029
+ @score_label = label
1030
+
1031
+ label
1032
+ label('Lines')
1033
+ @lines_label = label
1034
+
1035
+ label
1036
+ label('Level')
1037
+ @level_label = label
1038
+ label
1039
+ }
903
1040
  end
904
1041
 
905
1042
  def playfield(playfield_width: , playfield_height: , block_size: , &extra_content)
@@ -978,6 +1115,41 @@ class Tetris
978
1115
  @game.restart!
979
1116
  false
980
1117
  end
1118
+
1119
+ def show_high_score_dialog
1120
+ game_paused = !!@game.paused
1121
+ @game.paused = true
1122
+
1123
+ if @game.high_scores.empty?
1124
+ high_scores_string = "No games have been scored yet."
1125
+ else
1126
+ high_scores_string = @game.high_scores.map do |high_score|
1127
+ "#{high_score.name} | Score: #{high_score.score} | Lines: #{high_score.lines} | Level: #{high_score.level}"
1128
+ end.join("\n")
1129
+ end
1130
+
1131
+ message_dialog(@main_window) { |md|
1132
+ title 'High Scores'
1133
+ text high_scores_string
1134
+
1135
+ on(:response) do
1136
+ md.destroy
1137
+ end
1138
+ }.show
1139
+
1140
+ @game.paused = game_paused
1141
+ end
1142
+
1143
+ def show_about_dialog
1144
+ message_dialog(@main_window) { |md|
1145
+ title 'About'
1146
+ text "Glimmer Tetris\n\nGlimmer DSL for GTK\n\nElaborate Sample\n\nCopyright (c) 2021-2022 Andy Maleh"
1147
+
1148
+ on(:response) do
1149
+ md.destroy
1150
+ end
1151
+ }.show
1152
+ end
981
1153
  end
982
1154
 
983
1155
  Tetris.new.launch
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
Binary file
@@ -147,8 +147,8 @@ module Glimmer
147
147
 
148
148
  # Subclasses may override to perform post initialization work on an added child (normally must also call super)
149
149
  def post_initialize_child(child)
150
- @gtk.add(child.gtk)
151
- child.gtk.show
150
+ @gtk.add(child.gtk) if @gtk.respond_to?(:add)
151
+ child.gtk&.show if child.gtk&.respond_to?(:show)
152
152
  end
153
153
 
154
154
  def window_proxy
@@ -215,6 +215,10 @@ class Tetris
215
215
  self.up_arrow_action == :instant_down
216
216
  end
217
217
 
218
+ def instant_down_on_up!
219
+ self.up_arrow_action = :instant_down
220
+ end
221
+
218
222
  def rotate_right_on_up=(value)
219
223
  self.up_arrow_action = :rotate_right if value
220
224
  end
@@ -223,6 +227,10 @@ class Tetris
223
227
  self.up_arrow_action == :rotate_right
224
228
  end
225
229
 
230
+ def rotate_right_on_up!
231
+ self.up_arrow_action = :rotate_right
232
+ end
233
+
226
234
  def rotate_left_on_up=(value)
227
235
  self.up_arrow_action = :rotate_left if value
228
236
  end
@@ -231,6 +239,10 @@ class Tetris
231
239
  self.up_arrow_action == :rotate_left
232
240
  end
233
241
 
242
+ def rotate_left_on_up!
243
+ self.up_arrow_action = :rotate_left
244
+ end
245
+
234
246
  def reset_tetrominoes
235
247
  @tetrominoes = []
236
248
  end
@@ -26,7 +26,14 @@ class Tetris
26
26
  default_size Model::Game::PLAYFIELD_WIDTH * BLOCK_SIZE, Model::Game::PLAYFIELD_HEIGHT * BLOCK_SIZE # + 98
27
27
 
28
28
  box(:vertical) {
29
- @playfield_blocks = playfield(playfield_width: @game.playfield_width, playfield_height: @game.playfield_height, block_size: BLOCK_SIZE)
29
+ tetris_menu_bar
30
+
31
+ box(:horizontal) {
32
+ @playfield_blocks = playfield(playfield_width: @game.playfield_width, playfield_height: @game.playfield_height, block_size: BLOCK_SIZE)
33
+
34
+ score_board
35
+ }
36
+
30
37
  }
31
38
 
32
39
  on(:key_press_event) do |widget, key_event|
@@ -84,6 +91,135 @@ class Tetris
84
91
  end
85
92
  end
86
93
  end
94
+
95
+ Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
96
+ Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
97
+ observe(@game.preview_playfield[row][column], :color) do |new_color|
98
+ color = new_color
99
+ block = @preview_playfield_blocks[row][column]
100
+ block[:background_square].fill = color
101
+ block[:top_bevel_edge].fill = [color[0] + 4*BEVEL_CONSTANT, color[1] + 4*BEVEL_CONSTANT, color[2] + 4*BEVEL_CONSTANT]
102
+ block[:right_bevel_edge].fill = [color[0] - BEVEL_CONSTANT, color[1] - BEVEL_CONSTANT, color[2] - BEVEL_CONSTANT]
103
+ block[:bottom_bevel_edge].fill = [color[0] - BEVEL_CONSTANT, color[1] - BEVEL_CONSTANT, color[2] - BEVEL_CONSTANT]
104
+ block[:left_bevel_edge].fill = [color[0] - BEVEL_CONSTANT, color[1] - BEVEL_CONSTANT, color[2] - BEVEL_CONSTANT]
105
+ block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : color
106
+ block[:drawing_area].queue_draw
107
+ end
108
+ end
109
+ end
110
+
111
+ observe(@game, :score) do |new_score|
112
+ @score_label.text = new_score.to_s
113
+ end
114
+
115
+ observe(@game, :lines) do |new_lines|
116
+ @lines_label.text = new_lines.to_s
117
+ end
118
+
119
+ observe(@game, :level) do |new_level|
120
+ @level_label.text = new_level.to_s
121
+ end
122
+ end
123
+
124
+ def tetris_menu_bar
125
+ menu_bar {
126
+ menu_item(label: 'Game') { |mi|
127
+ m = menu {
128
+ check_menu_item(label: 'Pause') {
129
+ on(:activate) do
130
+ @game.paused = !@game.paused?
131
+ end
132
+ }
133
+
134
+ menu_item(label: 'Restart') {
135
+ on(:activate) do
136
+ @game.restart!
137
+ end
138
+ }
139
+
140
+ separator_menu_item
141
+
142
+ menu_item(label: 'Exit') {
143
+ on(:activate) do
144
+ @main_window.close
145
+ end
146
+ }
147
+ }
148
+ mi.submenu = m.gtk
149
+ }
150
+
151
+ menu_item(label: 'View') { |mi|
152
+ m = menu {
153
+ menu_item(label: 'Show High Scores') {
154
+ on(:activate) do
155
+ show_high_score_dialog
156
+ end
157
+ }
158
+
159
+ menu_item(label: 'Clear High Scores') {
160
+ on(:activate) do
161
+ @game.clear_high_scores!
162
+ end
163
+ }
164
+ }
165
+ mi.submenu = m.gtk
166
+ }
167
+
168
+ menu_item(label: 'Options') { |mi|
169
+ m = menu {
170
+ rmi = radio_menu_item(nil, 'Instant Down on Up') {
171
+ on(:activate) do
172
+ @game.instant_down_on_up!
173
+ end
174
+ }
175
+
176
+ default_rmi = radio_menu_item(rmi.group, 'Rotate Right on Up') {
177
+ on(:activate) do
178
+ @game.rotate_right_on_up!
179
+ end
180
+ }
181
+ default_rmi.activate
182
+
183
+ radio_menu_item(rmi.group, 'Rotate Left on Up') {
184
+ on(:activate) do
185
+ @game.rotate_left_on_up!
186
+ end
187
+ }
188
+ }
189
+ mi.submenu = m.gtk
190
+ }
191
+
192
+ menu_item(label: 'Options') { |mi|
193
+ m = menu {
194
+ menu_item(label: 'About') {
195
+ on(:activate) do
196
+ show_about_dialog
197
+ end
198
+ }
199
+ }
200
+ mi.submenu = m.gtk
201
+ }
202
+ }
203
+ end
204
+
205
+ def score_board
206
+ box(:vertical) {
207
+ label
208
+ @preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
209
+
210
+ label
211
+ label('Score')
212
+ @score_label = label
213
+
214
+ label
215
+ label('Lines')
216
+ @lines_label = label
217
+
218
+ label
219
+ label('Level')
220
+ @level_label = label
221
+ label
222
+ }
87
223
  end
88
224
 
89
225
  def playfield(playfield_width: , playfield_height: , block_size: , &extra_content)
@@ -162,6 +298,41 @@ class Tetris
162
298
  @game.restart!
163
299
  false
164
300
  end
301
+
302
+ def show_high_score_dialog
303
+ game_paused = !!@game.paused
304
+ @game.paused = true
305
+
306
+ if @game.high_scores.empty?
307
+ high_scores_string = "No games have been scored yet."
308
+ else
309
+ high_scores_string = @game.high_scores.map do |high_score|
310
+ "#{high_score.name} | Score: #{high_score.score} | Lines: #{high_score.lines} | Level: #{high_score.level}"
311
+ end.join("\n")
312
+ end
313
+
314
+ message_dialog(@main_window) { |md|
315
+ title 'High Scores'
316
+ text high_scores_string
317
+
318
+ on(:response) do
319
+ md.destroy
320
+ end
321
+ }.show
322
+
323
+ @game.paused = game_paused
324
+ end
325
+
326
+ def show_about_dialog
327
+ message_dialog(@main_window) { |md|
328
+ title 'About'
329
+ text "Glimmer Tetris\n\nGlimmer DSL for GTK\n\nElaborate Sample\n\nCopyright (c) 2021-2022 Andy Maleh"
330
+
331
+ on(:response) do
332
+ md.destroy
333
+ end
334
+ }.show
335
+ end
165
336
  end
166
337
 
167
338
  Tetris.new.launch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-gtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-27 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glimmer