glimmer-dsl-swt 4.20.13.4 → 4.20.13.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae711a0eacc8c77e76d141a6eb1576b904aa95f6c3df8fa842fbec5f9c491a7a
4
- data.tar.gz: e0784d7f5899ddf32bac4212432b0b118e579e989d8e6ad2565b7f9061d0b9b8
3
+ metadata.gz: 59508a178a1694489ba4ec995672f08a0997b01c8ebaeb39cecd2db250d0f88b
4
+ data.tar.gz: 9610a96bf71aa15a581dedda77f9c11942286f1ff5f7ac96369624c97a798f28
5
5
  SHA512:
6
- metadata.gz: c34d8c0ac635256a80f21bdf0c14b0235a13f8d14415227e16de24076d46eee269834ef9c1ec59dfa608e09c5b51534d2069f25c08e8f18c77e5c8c5707f0195
7
- data.tar.gz: adae4e6f727036983b50a021fdd7401deed05227c8f32325fda605ceb046460cf6795326cb80715d45aa38abb891ae909a14c133e931196b1e100c733549ab82
6
+ metadata.gz: 1f2219231093b33e6c32637dd2a6ee2249e3c64daf3f92355c57ab170d15c6bfd4930d540c3703c0a4c926ff9e6c322ddc4dd119938be9bc23ccf19935c84675
7
+ data.tar.gz: 98c6a6e4b2f26fde8d9741eb04054866c145366c27a728343f71f6f960c5eba411fa127167101da055d96241b3c66fb7c7d8dbba91256fa9688d694165158cdc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.13.8
4
+
5
+ - Glimmer Klondike Solitaire elaborate sample
6
+
7
+ ### 4.20.13.7
8
+
9
+ - Support accepting ImageProxy objects in Canvas Shape DSL (not just image paths)
10
+ - Fix issue in ImageProxy not flattening args before selecting file path
11
+
12
+ ### 4.20.13.6
13
+
14
+ - Ensure a dragged shape can be dropped back into a parent it originally belonged to without it counting as a drop into itself.
15
+ - Add set_data and get_data to Glimmer::UI::CustomShape, which proxies calls to body_root
16
+
17
+ ### 4.20.13.5
18
+
19
+ - Fix issue occurring with shape drag & drop when the dragged shape is a drop target too, thus getting dropped back to itself.
20
+
3
21
  ### 4.20.13.4
4
22
 
5
23
  - Improved shape drag and drop checking for inclusion in drop target when there are multiple drop targets
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 SWT 4.20.13.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 SWT 4.20.13.7
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -15,7 +15,7 @@
15
15
  [<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
16
16
  Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
17
17
 
18
- [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.4 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.7 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
19
19
 
20
20
  **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still a beta, so default back to `bind` whenever needed).
21
21
 
@@ -326,7 +326,7 @@ jgem install glimmer-dsl-swt
326
326
 
327
327
  Or this command if you want a specific version:
328
328
  ```
329
- jgem install glimmer-dsl-swt -v 4.20.13.4
329
+ jgem install glimmer-dsl-swt -v 4.20.13.7
330
330
  ```
331
331
 
332
332
  `jgem` is JRuby's version of `gem` command.
@@ -354,7 +354,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
354
354
 
355
355
  Add the following to `Gemfile`:
356
356
  ```
357
- gem 'glimmer-dsl-swt', '~> 4.20.13.4'
357
+ gem 'glimmer-dsl-swt', '~> 4.20.13.7'
358
358
  ```
359
359
 
360
360
  And, then run:
@@ -375,7 +375,7 @@ glimmer
375
375
  ```
376
376
 
377
377
  ```
378
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.4
378
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.7
379
379
 
380
380
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
381
381
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.13.4
1
+ 4.20.13.8
Binary file
@@ -228,9 +228,9 @@ module Glimmer
228
228
  contain?(x, y)
229
229
  end
230
230
 
231
- def include_with_children?(x, y)
231
+ def include_with_children?(x, y, except_child: nil)
232
232
  included = include?(x, y)
233
- included ||= expanded_shapes.detect { |shape| shape.include?(x, y) }
233
+ included ||= expanded_shapes.reject {|shape| shape == except_child}.detect { |shape| shape.include?(x, y) }
234
234
  end
235
235
 
236
236
  # Indicates if a shape's x, y, width, height differ from its bounds calculation (e.g. arc / polygon)
@@ -405,7 +405,7 @@ module Glimmer
405
405
  end
406
406
  if @name == 'image'
407
407
  if @args.first.is_a?(::String)
408
- @args[0] = ImageProxy.new(@args[0])
408
+ @args[0] = ImageProxy.create(@args[0])
409
409
  end
410
410
  if @args.first.is_a?(ImageProxy)
411
411
  @image = @args[0] = @args[0].swt_image
@@ -592,7 +592,7 @@ module Glimmer
592
592
  if observation_request == 'on_drop'
593
593
  Shape.drop_shapes << self
594
594
  handle_observation_request('on_mouse_up') do |event|
595
- if Shape.dragging && include_with_children?(event.x, event.y)
595
+ if Shape.dragging && include_with_children?(event.x, event.y, except_child: Shape.dragged_shape)
596
596
  drop_event = DropEvent.new(
597
597
  doit: true,
598
598
  dragged_shape: Shape.dragged_shape,
@@ -74,8 +74,8 @@ module Glimmer
74
74
  end
75
75
  options = @args.last.is_a?(Hash) ? @args.delete_at(-1) : {}
76
76
  options[:swt_image] = @args.first if @args.size == 1 && @args.first.is_a?(Image)
77
- @file_path = @args.first if @args.first.is_a?(String)
78
77
  @args = @args.first if @args.size == 1 && @args.first.is_a?(Array)
78
+ @file_path = @args.first if @args.first.is_a?(String)
79
79
  if options&.keys&.include?(:swt_image)
80
80
  @swt_image = options[:swt_image]
81
81
  @original_image_data = @image_data = @swt_image.image_data
@@ -264,6 +264,19 @@ module Glimmer
264
264
  body_root.handle_observation_request(observation_request, &block)
265
265
  end
266
266
 
267
+ # Sets data just like SWT widgets
268
+ def set_data(key=nil, value)
269
+ body_root.set_data(key, value)
270
+ end
271
+ alias setData set_data # for compatibility with SWT APIs
272
+
273
+ # Gets data just like SWT widgets
274
+ def get_data(key=nil)
275
+ body_root.get_data(key)
276
+ end
277
+ alias getData get_data # for compatibility with SWT APIs
278
+ alias data get_data # for compatibility with SWT APIs
279
+
267
280
  def method_missing(method, *args, &block)
268
281
  # TODO Consider supporting a glimmer error silencing option for methods defined here
269
282
  # but fail the glimmer DSL for the right reason to avoid seeing noise in the log output
@@ -0,0 +1,86 @@
1
+ require 'glimmer-dsl-swt'
2
+
3
+ require_relative 'klondike_solitaire/model/game'
4
+
5
+ require_relative 'klondike_solitaire/view/action_panel'
6
+ require_relative 'klondike_solitaire/view/tableau'
7
+
8
+ class KlondikeSolitaire
9
+ include Glimmer::UI::CustomShell
10
+
11
+ PLAYING_CARD_WIDTH = 50
12
+ PLAYING_CARD_HEIGHT = 80
13
+ PLAYING_CARD_SPACING = 5
14
+
15
+ ## Add options like the following to configure CustomShell by outside consumers
16
+ #
17
+ # options :title, :background_color
18
+ # option :width, default: 320
19
+ # option :height, default: 240
20
+
21
+ ## Use before_body block to pre-initialize variables to use in body
22
+ #
23
+ #
24
+ before_body {
25
+ @game = Model::Game.new
26
+ Display.app_name = 'Glimmer Klondike Solitaire'
27
+ @display = display {
28
+ on_about {
29
+ display_about_dialog
30
+ }
31
+ on_preferences {
32
+ display_about_dialog
33
+ }
34
+ }
35
+ }
36
+
37
+ ## Use after_body block to setup observers for widgets in body
38
+ #
39
+ # after_body {
40
+ #
41
+ # }
42
+
43
+ ## Add widget content inside custom shell body
44
+ ## Top-most widget must be a shell or another custom shell
45
+ #
46
+ body {
47
+ shell(:no_resize) {
48
+ row_layout(:vertical) {
49
+ fill true
50
+ center true
51
+ }
52
+ minimum_size 400, 400
53
+ text "Glimmer Klondike Solitaire"
54
+ background :dark_green
55
+
56
+ action_panel(game: @game)
57
+ tableau(game: @game) {
58
+ layout_data {
59
+ width 380
60
+ height 400
61
+ }
62
+ }
63
+
64
+ menu_bar {
65
+ menu {
66
+ text '&Help'
67
+ menu_item {
68
+ text '&About...'
69
+ on_widget_selected {
70
+ display_about_dialog
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ def display_about_dialog
79
+ message_box(body_root) {
80
+ text 'About'
81
+ message "Glimmer Klondike Solitaire\nGlimmer DSL for SWT Elaborate Sample"
82
+ }.open
83
+ end
84
+ end
85
+
86
+ KlondikeSolitaire.launch
@@ -0,0 +1,60 @@
1
+ class KlondikeSolitaire
2
+ module Model
3
+ class ColumnPile
4
+ include Glimmer::DataBinding::ObservableModel
5
+ attr_reader :count
6
+
7
+ def initialize(game, count)
8
+ @game = game
9
+ @count = count
10
+ reset!
11
+ end
12
+
13
+ def reset!
14
+ playing_cards.clear
15
+ populate!(count.times.map { @game.deck.pop })
16
+ notify_observers(:playing_cards)
17
+ end
18
+
19
+ # this method does not validate
20
+ def populate!(new_playing_cards)
21
+ new_playing_cards.each_with_index do |playing_card, index|
22
+ playing_card.hidden = true if index < (new_playing_cards.size - 1)
23
+ playing_cards.push(playing_card)
24
+ end
25
+ end
26
+
27
+ # this method validates that playing card fits at the bottom of the column (opposite color and one number smaller)
28
+ # throws an error if it does not fit
29
+ def add!(new_playing_card)
30
+ bottom_card = playing_cards.last
31
+ if (playing_cards.empty? && new_playing_card.rank == 13) ||
32
+ (new_playing_card.color != bottom_card.color && new_playing_card.rank == (bottom_card.rank - 1))
33
+ playing_cards.push(new_playing_card)
34
+ else
35
+ raise "Cannot add #{new_playing_card} to #{self}"
36
+ end
37
+ end
38
+
39
+ def remove!(card)
40
+ remove_cards_starting_at(playing_cards.index(card)).tap do |result|
41
+ playing_cards.last&.hidden = false
42
+ end
43
+ end
44
+
45
+ def remove_cards_starting_at(index)
46
+ removed_cards = playing_cards[index...playing_cards.size]
47
+ playing_cards[index...playing_cards.size] = []
48
+ removed_cards
49
+ end
50
+
51
+ def playing_cards
52
+ @playing_cards ||= []
53
+ end
54
+
55
+ def to_s
56
+ "Column Pile #{count} (#{playing_cards.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ class KlondikeSolitaire
2
+ module Model
3
+ class DealingPile
4
+ DEALING_INITIAL_COUNT = 24
5
+
6
+ def initialize(game)
7
+ @game = game
8
+ reset!
9
+ end
10
+
11
+ def reset!
12
+ playing_cards.clear
13
+ DEALING_INITIAL_COUNT.times { playing_cards << @game.deck.pop }
14
+ end
15
+
16
+ def deal!
17
+ playing_card = playing_cards.shift
18
+ if playing_card.nil?
19
+ @game.dealt_pile.playing_cards.each do |a_playing_card|
20
+ playing_cards << a_playing_card
21
+ end
22
+ @game.dealt_pile.playing_cards.clear
23
+ else
24
+ @game.dealt_pile.push!(playing_card)
25
+ end
26
+ end
27
+
28
+ def playing_cards
29
+ @playing_cards ||= []
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ class KlondikeSolitaire
2
+ module Model
3
+ class DealtPile
4
+ def initialize(game)
5
+ @game = game
6
+ end
7
+
8
+ def reset!
9
+ playing_cards.clear
10
+ end
11
+
12
+ def push!(playing_card)
13
+ playing_cards.push(playing_card)
14
+ end
15
+
16
+ def remove!(card)
17
+ playing_cards.delete(card)
18
+ end
19
+
20
+ def playing_cards
21
+ @playing_cards ||= []
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ class KlondikeSolitaire
2
+ module Model
3
+ class FoundationPile
4
+ attr_reader :suit
5
+
6
+ def initialize(game, suit)
7
+ @game = game
8
+ @suit = suit
9
+ reset!
10
+ end
11
+
12
+ def reset!
13
+ playing_cards.clear
14
+ end
15
+
16
+ # adds a card
17
+ # validates if it is a card that belongs to the suit
18
+ def add!(playing_card)
19
+ if playing_card.suit == suit &&
20
+ (
21
+ (playing_cards.empty? && playing_card.rank == 1) ||
22
+ playing_card.rank == (playing_cards.last.rank + 1)
23
+ )
24
+ playing_cards.push(playing_card)
25
+ else
26
+ raise "Cannot add #{playing_card} to #{self}"
27
+ end
28
+ end
29
+
30
+ def playing_cards
31
+ @playing_cards ||= []
32
+ end
33
+
34
+ def to_s
35
+ "Foundation Pile #{suit} (#{playing_cards.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'playing_card'
2
+ require_relative 'dealt_pile'
3
+ require_relative 'dealing_pile'
4
+ require_relative 'column_pile'
5
+ require_relative 'foundation_pile'
6
+
7
+ class KlondikeSolitaire
8
+ module Model
9
+ class Game
10
+ COLUMN_PILE_COUNT = 7
11
+
12
+ attr_reader :deck, :dealing_pile, :dealt_pile, :column_piles, :foundation_piles
13
+
14
+ def initialize
15
+ @deck = new_deck
16
+ @dealt_pile = DealtPile.new(self)
17
+ @dealing_pile = DealingPile.new(self)
18
+ @column_piles = COLUMN_PILE_COUNT.times.map {|n| ColumnPile.new(self, n + 1)}
19
+ @foundation_piles = PlayingCard::SUITS.map {|suit| FoundationPile.new(self, suit)}
20
+ end
21
+
22
+ def restart!
23
+ @deck = new_deck
24
+ @dealt_pile.reset!
25
+ @dealing_pile.reset!
26
+ @column_piles.each(&:reset!)
27
+ @foundation_piles.each(&:reset!)
28
+ end
29
+
30
+ private
31
+
32
+ def new_deck
33
+ PlayingCard.deck.shuffle
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,50 @@
1
+ class KlondikeSolitaire
2
+ module Model
3
+ class PlayingCard
4
+ SUITS = [:spades, :hearts, :clubs, :diamonds]
5
+ BLACK_SUITS = [:spades, :clubs]
6
+ RED_SUITS = [:hearts, :diamonds]
7
+ RANK_COUNT = 13
8
+
9
+ class << self
10
+ def deck
11
+ suit_decks.flatten
12
+ end
13
+
14
+ def suit_decks
15
+ SUITS.map do |suit|
16
+ suit_deck(suit)
17
+ end
18
+ end
19
+
20
+ def suit_deck(suit)
21
+ 1.upto(RANK_COUNT).map do |rank|
22
+ new(rank, suit)
23
+ end
24
+ end
25
+ end
26
+
27
+ attr_reader :rank, :suit
28
+ attr_accessor :hidden
29
+ alias hidden? hidden
30
+
31
+ def initialize(rank, suit, hidden = false)
32
+ @rank = rank
33
+ @suit = suit
34
+ @hidden = hidden
35
+ end
36
+
37
+ def color
38
+ if BLACK_SUITS.include?(suit)
39
+ :black
40
+ elsif RED_SUITS.include?(suit)
41
+ :red
42
+ end
43
+ end
44
+
45
+ def to_s
46
+ "Playing Card #{rank}#{suit.to_s[0].upcase}"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ class KlondikeSolitaire
2
+ module View
3
+ class ActionPanel
4
+ include Glimmer::UI::CustomWidget
5
+
6
+ option :game
7
+
8
+ body {
9
+ composite {
10
+ grid_layout(1, false) {
11
+ margin_width 0
12
+ margin_height 0
13
+ }
14
+
15
+ background :dark_green
16
+
17
+ button {
18
+ layout_data :center, :center, true, false
19
+
20
+ text 'Restart Game'
21
+
22
+ on_widget_selected {
23
+ game.restart!
24
+ }
25
+ }
26
+ }
27
+ }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ require_relative '../model/column_pile'
2
+
3
+ require_relative 'playing_card'
4
+
5
+ class KlondikeSolitaire
6
+ module View
7
+ class ColumnPile
8
+ include Glimmer::UI::CustomShape
9
+
10
+ IMAGE_EMPTY = image(50, 80) {
11
+ rectangle(0, 0, 50, 80) {
12
+ background :dark_green
13
+
14
+ rectangle(0, 0, 49, 79, 15, 15) {
15
+ foreground :gray
16
+ }
17
+ }
18
+ }
19
+
20
+ options :pile_x, :pile_y, :model
21
+
22
+ after_body {
23
+ observe(model, 'playing_cards.last.hidden') do
24
+ build_column_pile(model.playing_cards)
25
+ end
26
+ build_column_pile(model.playing_cards)
27
+ }
28
+
29
+ body {
30
+ shape(pile_x, pile_y) {
31
+ on_drop do |drop_event|
32
+ begin
33
+ card_shape = drop_event.dragged_shape.get_data('custom_shape')
34
+ card = card_shape.model
35
+ model.add!(card)
36
+ card_parent_pile = card_shape.parent_pile
37
+ card_source_model = card_parent_pile.model
38
+ cards = card_source_model.remove!(card)
39
+ if cards.is_a?(Array) # if it is a column pile
40
+ cards[1..-1].each do |card|
41
+ model.add!(card)
42
+ end
43
+ end
44
+ drop_event.dragged_shape.dispose
45
+ rescue => e
46
+ # pd e
47
+ drop_event.doit = false
48
+ end
49
+ end
50
+ }
51
+ }
52
+
53
+ def build_column_pile(playing_cards)
54
+ body_root.shapes.to_a.each(&:dispose)
55
+ current_parent = body_root
56
+ playing_cards.each_with_index do |card, i|
57
+ current_parent.content {
58
+ current_parent = playing_card(card_x: 0, card_y: 20, model: card, parent_pile: self) {
59
+ drag_source true unless card.hidden?
60
+ }.body_root
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../model/dealing_pile'
2
+
3
+ require_relative 'empty_playing_card'
4
+ require_relative 'hidden_playing_card'
5
+
6
+ class KlondikeSolitaire
7
+ module View
8
+ class DealingPile
9
+ include Glimmer::UI::CustomShape
10
+
11
+ options :pile_x, :pile_y, :model
12
+
13
+ after_body {
14
+ observe(model, 'playing_cards.empty?') do |empty_value|
15
+ body_root.shapes.to_a.each(&:dispose)
16
+ if empty_value
17
+ body_root.content {
18
+ empty_playing_card
19
+ }
20
+ else
21
+ body_root.content {
22
+ hidden_playing_card
23
+ }
24
+ end
25
+ end
26
+ }
27
+
28
+ body {
29
+ shape(pile_x, pile_y) {
30
+ hidden_playing_card
31
+ }
32
+ }
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../model/dealt_pile'
2
+
3
+ require_relative 'empty_playing_card'
4
+ require_relative 'playing_card'
5
+
6
+ class KlondikeSolitaire
7
+ module View
8
+ class DealtPile
9
+ include Glimmer::UI::CustomShape
10
+
11
+ options :pile_x, :pile_y, :model
12
+
13
+ after_body do
14
+ observe(model, 'playing_cards.empty?') do |empty_value|
15
+ if empty_value
16
+ body_root.shapes.to_a.dup.each(&:dispose)
17
+ body_root.content {
18
+ empty_playing_card
19
+ }
20
+ else
21
+ body_root.content {
22
+ playing_card(model: model.playing_cards.last, parent_pile: self) {
23
+ drag_source true
24
+ }
25
+ }
26
+ end
27
+ end
28
+ end
29
+
30
+ body {
31
+ shape(pile_x, pile_y) {
32
+ empty_playing_card
33
+ }
34
+ }
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ class KlondikeSolitaire
2
+ module View
3
+ class EmptyPlayingCard
4
+ include Glimmer::UI::CustomShape
5
+
6
+ option :suit
7
+
8
+ body {
9
+ rectangle(0, 0, 49, 79, 15, 15) {
10
+ foreground :gray
11
+
12
+ if suit
13
+ text {
14
+ string suit.to_s[0].upcase
15
+ x :default
16
+ y :default
17
+ is_transparent true
18
+ }
19
+ end
20
+ }
21
+ }
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ require_relative '../model/playing_card'
2
+ require_relative '../model/foundation_pile'
3
+
4
+ class KlondikeSolitaire
5
+ module View
6
+ class FoundationPile
7
+ include Glimmer::UI::CustomShape
8
+
9
+ options :pile_x, :pile_y, :game, :suit
10
+
11
+ attr_accessor :current_image, :model
12
+
13
+ before_body {
14
+ self.current_image = image(50, 80) {empty_playing_card(suit: suit)}
15
+ self.model = game.foundation_piles[Model::PlayingCard::SUITS.index(suit)]
16
+ }
17
+
18
+ after_body {
19
+ observe(model, 'playing_cards.last') do |last_card|
20
+ if last_card
21
+ body_root.content {
22
+ playing_card(model: last_card)
23
+ }
24
+ else
25
+ body_root.clear_shapes
26
+ body_root.content {
27
+ empty_playing_card(suit: suit)
28
+ }
29
+ end
30
+ end
31
+ }
32
+
33
+ body {
34
+ shape(pile_x, pile_y) {
35
+ empty_playing_card(suit: suit)
36
+
37
+ on_drop do |drop_event|
38
+ begin
39
+ # TODO make sure one cannot drag a column pile of cards here
40
+ card_shape = drop_event.dragged_shape.get_data('custom_shape')
41
+ card = card_shape.model
42
+ card_parent_pile = card_shape.parent_pile
43
+ card_source_model = card_parent_pile.model
44
+ raise 'Cannot accept multiple cards' if card_source_model.playing_cards.index(card) != (card_source_model.playing_cards.size - 1)
45
+ model.add!(card)
46
+ card_source_model.remove!(card)
47
+ drop_event.dragged_shape.dispose
48
+ rescue => e
49
+ # pd e
50
+ drop_event.doit = false
51
+ end
52
+ end
53
+ }
54
+ }
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,19 @@
1
+ class KlondikeSolitaire
2
+ module View
3
+ class HiddenPlayingCard
4
+ include Glimmer::UI::CustomShape
5
+
6
+ body {
7
+ rectangle(0, 0, 49, 79, 15, 15) {
8
+ background :red
9
+
10
+ # border
11
+ rectangle(0, 0, 49, 79, 15, 15) {
12
+ foreground :black
13
+ }
14
+ }
15
+ }
16
+
17
+ end
18
+ end
19
+ 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 {
9
+ self.card_x ||= 0
10
+ self.card_y ||= 0
11
+ }
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} #{model.suit.to_s[0].upcase}" : ""
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: i*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, game: game, suit: suit)
22
+ end
23
+ @dealt_pile = dealt_pile(pile_x: 5*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, model: game.dealt_pile)
24
+ @dealing_pile = dealing_pile(pile_x: 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: 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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.20.13.4
4
+ version: 4.20.13.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-29 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -545,6 +545,22 @@ files:
545
545
  - samples/elaborate/contact_manager/contact.rb
546
546
  - samples/elaborate/contact_manager/contact_manager_presenter.rb
547
547
  - samples/elaborate/contact_manager/contact_repository.rb
548
+ - samples/elaborate/klondike_solitaire.rb
549
+ - samples/elaborate/klondike_solitaire/model/column_pile.rb
550
+ - samples/elaborate/klondike_solitaire/model/dealing_pile.rb
551
+ - samples/elaborate/klondike_solitaire/model/dealt_pile.rb
552
+ - samples/elaborate/klondike_solitaire/model/foundation_pile.rb
553
+ - samples/elaborate/klondike_solitaire/model/game.rb
554
+ - samples/elaborate/klondike_solitaire/model/playing_card.rb
555
+ - samples/elaborate/klondike_solitaire/view/action_panel.rb
556
+ - samples/elaborate/klondike_solitaire/view/column_pile.rb
557
+ - samples/elaborate/klondike_solitaire/view/dealing_pile.rb
558
+ - samples/elaborate/klondike_solitaire/view/dealt_pile.rb
559
+ - samples/elaborate/klondike_solitaire/view/empty_playing_card.rb
560
+ - samples/elaborate/klondike_solitaire/view/foundation_pile.rb
561
+ - samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb
562
+ - samples/elaborate/klondike_solitaire/view/playing_card.rb
563
+ - samples/elaborate/klondike_solitaire/view/tableau.rb
548
564
  - samples/elaborate/login.rb
549
565
  - samples/elaborate/mandelbrot_fractal.rb
550
566
  - samples/elaborate/meta_sample.rb