glimmer-dsl-opal 0.27.0 → 0.28.3
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 +4 -4
- data/CHANGELOG.md +30 -0
- data/README.md +71 -3
- data/VERSION +1 -1
- data/lib/glimmer/dsl/opal/dsl.rb +3 -0
- data/lib/glimmer/dsl/opal/image_expression.rb +64 -0
- data/lib/glimmer/dsl/opal/property_expression.rb +1 -2
- data/lib/glimmer/dsl/opal/shape_expression.rb +35 -6
- data/lib/glimmer/swt/canvas_proxy.rb +27 -0
- data/lib/glimmer/swt/composite_proxy.rb +0 -2
- data/lib/glimmer/swt/custom/shape/arc.rb +75 -0
- data/lib/glimmer/swt/custom/shape/image.rb +98 -0
- data/lib/glimmer/swt/custom/shape/line.rb +53 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +58 -0
- data/lib/glimmer/swt/custom/shape/point.rb +53 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +53 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +53 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +101 -0
- data/lib/glimmer/swt/custom/shape/text.rb +114 -0
- data/lib/glimmer/swt/custom/shape.rb +205 -0
- data/lib/glimmer/swt/image_proxy.rb +29 -0
- data/lib/glimmer/swt/menu_proxy.rb +1 -1
- data/lib/glimmer/swt/point.rb +2 -0
- data/lib/glimmer/swt/rectangle.rb +7 -0
- data/lib/glimmer/swt/widget_proxy.rb +15 -4
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/block.rb +44 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris.rb +4 -8
- data/lib/glimmer-dsl-opal/samples/elaborate/weather.rb +4 -3
- data/lib/glimmer-dsl-opal/samples/hello/hello_canvas.rb +106 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_text.rb +1 -1
- data/lib/glimmer-dsl-opal/samples/hello/images/scaffold_app.png +0 -0
- data/lib/glimmer-dsl-opal/vendor/two.min.js +24 -0
- data/lib/glimmer-dsl-opal.rb +1 -0
- metadata +19 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 07466f2f1bdce190b47b5150a6eb6dec007cc3053ff33fdcc8e0241ed859a42f
         | 
| 4 | 
            +
              data.tar.gz: 84f91160a5c1147119f9f48a1189b9d78d20791450b48a6589dcacd6adf4e4cf
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ba7a681470d023e717b3d545df05a49950d0c4b7139350c4bbe4631a885152be4e9eefbe13496493563fe6272ca95056d5b6dcd154fb98aa052ea37cc4928f23
         | 
| 7 | 
            +
              data.tar.gz: e816232d3661aa2dac6e2d9da8e54ac0cc857018ef7a25bb236c3f8802ddd4b82c8cd802f7bb89ddacf3204b25a8fc72f226b694f10d1f8dda56f187191650c4
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,35 @@ | |
| 1 1 | 
             
            # Change Log
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 0.28.3
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            - Support Canvas Shape DSL data-binding
         | 
| 6 | 
            +
            - Use Canvas Shape DSL data-binding with Hello, Canvas! text string attribute
         | 
| 7 | 
            +
            - Add bevel 3D look to Tetris elaborate sample via Canvas Shape DSL
         | 
| 8 | 
            +
            - Ensure shell height compensates for providing extra top space to menu_bar when rendered
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ## 0.28.2
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            - Support `image` Canvas Shape DSL keyword
         | 
| 13 | 
            +
            - Use `image` in Hello, Canvas! sample
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ## 0.28.1
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            - Support `arc` Canvas Shape DSL keyword (partial support whereby width is assumed to be equal to height to start from a circle basis)
         | 
| 18 | 
            +
            - Use `arc` in Hello, Canvas! sample
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ## 0.28.0
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            - Initial support for Canvas Shape DSL keywords (no-databinding, nesting, or gradients yet):
         | 
| 23 | 
            +
             - `line`
         | 
| 24 | 
            +
             - `point`
         | 
| 25 | 
            +
             - `oval`
         | 
| 26 | 
            +
             - `polygon`
         | 
| 27 | 
            +
             - `polyline`
         | 
| 28 | 
            +
             - `rectangle`
         | 
| 29 | 
            +
             - `string`
         | 
| 30 | 
            +
             - `text`
         | 
| 31 | 
            +
            - Minimal initial version of Hello, Canvas! sample
         | 
| 32 | 
            +
             | 
| 3 33 | 
             
            ## 0.27.0
         | 
| 4 34 |  | 
| 5 35 | 
             
            - Hello, Text!
         | 
    
        data/README.md
    CHANGED
    
    | @@ -145,7 +145,7 @@ Hello, Table! Game Booked | |
| 145 145 |  | 
| 146 146 | 
             
            NOTE: Glimmer DSL for Opal is an alpha project. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
         | 
| 147 147 |  | 
| 148 | 
            -
            **Alpha Version** 0. | 
| 148 | 
            +
            **Alpha Version** 0.28.3 only supports bare-minimum capabilities for the included [samples](https://github.com/AndyObtiva/glimmer-dsl-opal#samples) (originally written for [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt))
         | 
| 149 149 |  | 
| 150 150 | 
             
            Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
         | 
| 151 151 | 
             
            - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
         | 
| @@ -179,12 +179,14 @@ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems: | |
| 179 179 | 
             
                  - [Hello, Radio!](#hello-radio)
         | 
| 180 180 | 
             
                  - [Hello, Radio Group!](#hello-radio-group)
         | 
| 181 181 | 
             
                  - [Hello, Group!](#hello-group)
         | 
| 182 | 
            +
                  - [Hello, Canvas!](#hello-canvas)
         | 
| 182 183 | 
             
                  - [Hello, C Combo!](#hello-c-combo)
         | 
| 183 184 | 
             
                  - [Hello, C Tab!](#hello-c-tab)
         | 
| 184 185 | 
             
                  - [Hello, Checkbox!](#hello-checkbox)
         | 
| 185 186 | 
             
                  - [Hello, Checkbox Group!](#hello-checkbox-group)
         | 
| 186 187 | 
             
                  - [Hello, Date Time!](#hello-date-time)
         | 
| 187 188 | 
             
                  - [Hello, Table!](#hello-table)
         | 
| 189 | 
            +
                  - [Hello, Text!](#hello-text)
         | 
| 188 190 | 
             
                  - [Hello, Button!](#hello-button)
         | 
| 189 191 | 
             
                  - [Hello, Arrow!](#hello-arrow)
         | 
| 190 192 | 
             
                  - [Hello, Message Box!](#hello-message-box)
         | 
| @@ -269,7 +271,7 @@ gem 'opal', '1.0.5' | |
| 269 271 | 
             
            gem 'opal-rails', '1.1.2'
         | 
| 270 272 | 
             
            gem 'opal-async', '~> 1.4.0'
         | 
| 271 273 | 
             
            gem 'opal-jquery', '~> 0.4.4'
         | 
| 272 | 
            -
            gem 'glimmer-dsl-opal', '~> 0. | 
| 274 | 
            +
            gem 'glimmer-dsl-opal', '~> 0.28.3'
         | 
| 273 275 | 
             
            gem 'glimmer-dsl-xml', '~> 1.2.0', require: false
         | 
| 274 276 | 
             
            gem 'glimmer-dsl-css', '~> 1.2.0', require: false
         | 
| 275 277 |  | 
| @@ -392,6 +394,16 @@ Event loop: | |
| 392 394 | 
             
            - `display`: featured in [Tic Tac Toe](#tic-tac-toe)
         | 
| 393 395 | 
             
            - `async_exec`: featured in [Hello, Custom Widget!](#hello-custom-widget) / [Hello, Custom Shell!](#hello-custom-shell)
         | 
| 394 396 |  | 
| 397 | 
            +
            Canvas Shape DSL:
         | 
| 398 | 
            +
            - `line`
         | 
| 399 | 
            +
            - `point`
         | 
| 400 | 
            +
            - `oval`
         | 
| 401 | 
            +
            - `polygon`
         | 
| 402 | 
            +
            - `polyline`
         | 
| 403 | 
            +
            - `rectangle`
         | 
| 404 | 
            +
            - `string`
         | 
| 405 | 
            +
            - `text`
         | 
| 406 | 
            +
             | 
| 395 407 | 
             
            ## Samples
         | 
| 396 408 |  | 
| 397 409 | 
             
            Follow the instructions below to try out [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) samples webified via [glimmer-dsl-opal](https://rubygems.org/gems/glimmer-dsl-opal)
         | 
| @@ -1447,6 +1459,35 @@ You should see "Hello, Group!" | |
| 1447 1459 |  | 
| 1448 1460 | 
             
            
         | 
| 1449 1461 |  | 
| 1462 | 
            +
            #### Hello, Canvas!
         | 
| 1463 | 
            +
             | 
| 1464 | 
            +
            This is a minimal initial version of the [Hello, Canvas! sample included in Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#hello-canvas).
         | 
| 1465 | 
            +
             | 
| 1466 | 
            +
            It [supports](#supported-glimmer-dsl-keywords) all shapes, but with no shape nesting, data-binding, or gradient support yet.
         | 
| 1467 | 
            +
             | 
| 1468 | 
            +
            Add the following require statement to `app/assets/javascripts/application.rb`
         | 
| 1469 | 
            +
             | 
| 1470 | 
            +
            ```ruby
         | 
| 1471 | 
            +
            require 'glimmer-dsl-opal/samples/hello/hello_canvas'
         | 
| 1472 | 
            +
            ```
         | 
| 1473 | 
            +
             | 
| 1474 | 
            +
            Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
         | 
| 1475 | 
            +
             | 
| 1476 | 
            +
            
         | 
| 1477 | 
            +
             | 
| 1478 | 
            +
            Glimmer app on the web (using `glimmer-dsl-opal` gem):
         | 
| 1479 | 
            +
             | 
| 1480 | 
            +
            Start the Rails server:
         | 
| 1481 | 
            +
            ```
         | 
| 1482 | 
            +
            rails s
         | 
| 1483 | 
            +
            ```
         | 
| 1484 | 
            +
             | 
| 1485 | 
            +
            Visit `http://localhost:3000`
         | 
| 1486 | 
            +
             | 
| 1487 | 
            +
            You should see "Hello, Canvas!"
         | 
| 1488 | 
            +
             | 
| 1489 | 
            +
            
         | 
| 1490 | 
            +
             | 
| 1450 1491 | 
             
            #### Hello, C Combo!
         | 
| 1451 1492 |  | 
| 1452 1493 | 
             
            This is the low level way of using `c_combo`
         | 
| @@ -1733,6 +1774,31 @@ Hello, Table! Game Booked | |
| 1733 1774 |  | 
| 1734 1775 | 
             
            
         | 
| 1735 1776 |  | 
| 1777 | 
            +
            #### Hello, Text!
         | 
| 1778 | 
            +
             | 
| 1779 | 
            +
            Add the following require statement to `app/assets/javascripts/application.rb`
         | 
| 1780 | 
            +
             | 
| 1781 | 
            +
            ```ruby
         | 
| 1782 | 
            +
            require 'glimmer-dsl-opal/samples/hello/hello_text'
         | 
| 1783 | 
            +
            ```
         | 
| 1784 | 
            +
             | 
| 1785 | 
            +
            Glimmer app on the desktop (using [`glimmer-dsl-swt`](https://github.com/AndyObtiva/glimmer-dsl-swt) gem):
         | 
| 1786 | 
            +
             | 
| 1787 | 
            +
            
         | 
| 1788 | 
            +
             | 
| 1789 | 
            +
            Glimmer app on the web (using `glimmer-dsl-opal` gem):
         | 
| 1790 | 
            +
             | 
| 1791 | 
            +
            Start the Rails server:
         | 
| 1792 | 
            +
            ```
         | 
| 1793 | 
            +
            rails s
         | 
| 1794 | 
            +
            ```
         | 
| 1795 | 
            +
             | 
| 1796 | 
            +
            Visit `http://localhost:3000`
         | 
| 1797 | 
            +
             | 
| 1798 | 
            +
            You should see "Hello, Text!"
         | 
| 1799 | 
            +
             | 
| 1800 | 
            +
            
         | 
| 1801 | 
            +
             | 
| 1736 1802 | 
             
            #### Hello, Button!
         | 
| 1737 1803 |  | 
| 1738 1804 | 
             
            Add the following require statement to `app/assets/javascripts/application.rb`
         | 
| @@ -2587,7 +2653,7 @@ Glimmer DSL for Opal Contact Manager Edit Done | |
| 2587 2653 |  | 
| 2588 2654 | 
             
            #### Tetris
         | 
| 2589 2655 |  | 
| 2590 | 
            -
            This is a minimal  | 
| 2656 | 
            +
            This is a slightly minimal version of the [Tetris seen in Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#glimmer-tetris).
         | 
| 2591 2657 |  | 
| 2592 2658 | 
             
            Note that while the Glimmer GUI DSL code is mostly the same, some of the behavioral code around threads is changed
         | 
| 2593 2659 | 
             
            into async Opal code via the [opal-async](https://github.com/AndyObtiva/opal-async) gem due to the async nature of transpiled JavaScript.
         | 
| @@ -2677,6 +2743,8 @@ You should see "User Profile" | |
| 2677 2743 |  | 
| 2678 2744 | 
             
            #### Weather
         | 
| 2679 2745 |  | 
| 2746 | 
            +
            This sample does everything the desktop sample does except for the Canvas Shape DSL rectangle decoration (until supported).
         | 
| 2747 | 
            +
             | 
| 2680 2748 | 
             
            Code: [lib/glimmer-dsl-opal/samples/elaborate/weather](lib/glimmer-dsl-opal/samples/elaborate/weather.rb)
         | 
| 2681 2749 |  | 
| 2682 2750 | 
             
            Add the following require statement to `app/assets/javascripts/application.rb`
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.28.3
         | 
    
        data/lib/glimmer/dsl/opal/dsl.rb
    CHANGED
    
    | @@ -30,6 +30,8 @@ require 'glimmer/dsl/opal/menu_expression' | |
| 30 30 | 
             
            require 'glimmer/dsl/opal/dialog_expression'
         | 
| 31 31 | 
             
            require 'glimmer/dsl/opal/shape_expression'
         | 
| 32 32 | 
             
            require 'glimmer/dsl/opal/shine_data_binding_expression'
         | 
| 33 | 
            +
            require 'glimmer/dsl/opal/shape_expression'
         | 
| 34 | 
            +
            require 'glimmer/dsl/opal/image_expression'
         | 
| 33 35 |  | 
| 34 36 | 
             
            module Glimmer
         | 
| 35 37 | 
             
              module DSL
         | 
| @@ -46,6 +48,7 @@ module Glimmer | |
| 46 48 | 
             
                     checkbox_group_selection_data_binding
         | 
| 47 49 | 
             
                     data_binding
         | 
| 48 50 | 
             
                     font
         | 
| 51 | 
            +
                     image
         | 
| 49 52 | 
             
                     layout
         | 
| 50 53 | 
             
                     block_property
         | 
| 51 54 | 
             
                     property
         | 
| @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            # Copyright (c) 2020-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/expression'
         | 
| 23 | 
            +
            require 'glimmer/dsl/top_level_expression'
         | 
| 24 | 
            +
            require 'glimmer/dsl/parent_expression'
         | 
| 25 | 
            +
            require 'glimmer/swt/image_proxy'
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            module Glimmer
         | 
| 28 | 
            +
              module DSL
         | 
| 29 | 
            +
                module Opal
         | 
| 30 | 
            +
                  # image expression
         | 
| 31 | 
            +
                  # Note: Cannot be a static expression because it clashes with image property expression
         | 
| 32 | 
            +
                  class ImageExpression < Expression
         | 
| 33 | 
            +
                    include TopLevelExpression
         | 
| 34 | 
            +
                    include ParentExpression
         | 
| 35 | 
            +
                    
         | 
| 36 | 
            +
                    def can_interpret?(parent, keyword, *args, &block)
         | 
| 37 | 
            +
                      options = args.last.is_a?(Hash) ? args.last : {}
         | 
| 38 | 
            +
                      (
         | 
| 39 | 
            +
                        (keyword == 'image') and
         | 
| 40 | 
            +
                        (
         | 
| 41 | 
            +
                          options.keys.include?(:top_level) or
         | 
| 42 | 
            +
                          (
         | 
| 43 | 
            +
                            !parent.is_a?(Glimmer::SWT::Custom::Shape) &&
         | 
| 44 | 
            +
                            !parent.is_a?(Glimmer::SWT::CanvasProxy)
         | 
| 45 | 
            +
                          )
         | 
| 46 | 
            +
                        )
         | 
| 47 | 
            +
                      )
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
              
         | 
| 50 | 
            +
                    def interpret(parent, keyword, *args, &block)
         | 
| 51 | 
            +
            #           options = args.last.is_a?(Hash) ? args.last : {}
         | 
| 52 | 
            +
            #           args.unshift(parent) unless parent.nil? || options[:top_level]
         | 
| 53 | 
            +
                      Glimmer::SWT::ImageProxy.create(*args, &block)
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    def add_content(parent, keyword, *args, &block)
         | 
| 57 | 
            +
                      return if @create_pixel_by_pixel || block&.parameters&.count == 2
         | 
| 58 | 
            +
                      super
         | 
| 59 | 
            +
                      parent.post_add_content
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
            end
         | 
| @@ -1,11 +1,10 @@ | |
| 1 1 | 
             
            require 'glimmer/dsl/expression'
         | 
| 2 | 
            +
            require 'glimmer/swt/custom/shape'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module Glimmer
         | 
| 4 5 | 
             
              module DSL
         | 
| 5 6 | 
             
                module Opal
         | 
| 6 7 | 
             
                  class PropertyExpression < StaticExpression
         | 
| 7 | 
            -
                    include TopLevelExpression
         | 
| 8 | 
            -
             | 
| 9 8 | 
             
                    def can_interpret?(parent, keyword, *args, &block)
         | 
| 10 9 | 
             
                      parent and
         | 
| 11 10 | 
             
                        (!args.empty?) and
         | 
| @@ -1,5 +1,29 @@ | |
| 1 | 
            +
            # Copyright (c) 2020-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 | 
            +
             | 
| 1 22 | 
             
            require 'glimmer/dsl/expression'
         | 
| 2 23 | 
             
            require 'glimmer/dsl/parent_expression'
         | 
| 24 | 
            +
            require 'glimmer/swt/swt_proxy'
         | 
| 25 | 
            +
            require 'glimmer/swt/canvas_proxy'
         | 
| 26 | 
            +
            require 'glimmer/swt/custom/shape'
         | 
| 3 27 |  | 
| 4 28 | 
             
            module Glimmer
         | 
| 5 29 | 
             
              module DSL
         | 
| @@ -7,20 +31,25 @@ module Glimmer | |
| 7 31 | 
             
                  class ShapeExpression < Expression
         | 
| 8 32 | 
             
                    include ParentExpression
         | 
| 9 33 |  | 
| 10 | 
            -
                    INCLUDED_KEYWORDS = %w[rectangle polygon]
         | 
| 11 | 
            -
              
         | 
| 12 34 | 
             
                    def can_interpret?(parent, keyword, *args, &block)
         | 
| 13 | 
            -
                       | 
| 35 | 
            +
                      (parent.is_a?(Glimmer::SWT::CanvasProxy) or parent.is_a?(Glimmer::SWT::Custom::Shape)) and
         | 
| 36 | 
            +
                        Glimmer::SWT::Custom::Shape.valid?(parent, keyword, args, &block) and
         | 
| 37 | 
            +
                        ((keyword != 'text' && keyword != 'image') || args.size >= 3 || (args.empty? && block_given?))
         | 
| 14 38 | 
             
                    end
         | 
| 15 | 
            -
             | 
| 39 | 
            +
                    
         | 
| 16 40 | 
             
                    def interpret(parent, keyword, *args, &block)
         | 
| 17 | 
            -
                       | 
| 41 | 
            +
                      Glimmer::SWT::Custom::Shape.create(parent, keyword, args, &block)
         | 
| 18 42 | 
             
                    end
         | 
| 19 43 |  | 
| 20 44 | 
             
                    def add_content(parent, keyword, *args, &block)
         | 
| 21 | 
            -
                       | 
| 45 | 
            +
                      super(parent, keyword, *args, &block)
         | 
| 46 | 
            +
                      parent.post_add_content
         | 
| 22 47 | 
             
                    end
         | 
| 48 | 
            +
                  
         | 
| 23 49 | 
             
                  end
         | 
| 50 | 
            +
                  
         | 
| 24 51 | 
             
                end
         | 
| 52 | 
            +
                
         | 
| 25 53 | 
             
              end
         | 
| 54 | 
            +
              
         | 
| 26 55 | 
             
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'glimmer/swt/composite_proxy'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Glimmer
         | 
| 4 | 
            +
              module SWT
         | 
| 5 | 
            +
                class CanvasProxy < CompositeProxy
         | 
| 6 | 
            +
                  def default_layout
         | 
| 7 | 
            +
                    nil
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
                
         | 
| 10 | 
            +
                  def element
         | 
| 11 | 
            +
                    'svg'
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                  
         | 
| 14 | 
            +
                  def dom
         | 
| 15 | 
            +
                    canvas_id = id
         | 
| 16 | 
            +
                    canvas_class = name
         | 
| 17 | 
            +
                    # TODO in the future, calculate width and height from children automatically (just like Glimmer DSL for SWT)
         | 
| 18 | 
            +
                    @dom ||= html {
         | 
| 19 | 
            +
                      svg(id: canvas_id, class: canvas_class) {
         | 
| 20 | 
            +
                        'Sorry, your browser does not support inline SVG.'
         | 
| 21 | 
            +
                      }
         | 
| 22 | 
            +
                    }.to_s
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            # Copyright (c) 2020-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/swt/custom/shape'
         | 
| 23 | 
            +
            require 'glimmer/swt/swt_proxy'
         | 
| 24 | 
            +
            require 'glimmer/swt/display_proxy'
         | 
| 25 | 
            +
            require 'glimmer/swt/color_proxy'
         | 
| 26 | 
            +
            # require 'glimmer/swt/transform_proxy'
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            module Glimmer
         | 
| 29 | 
            +
              module SWT
         | 
| 30 | 
            +
                module Custom
         | 
| 31 | 
            +
                  class Shape
         | 
| 32 | 
            +
                    class Arc < Shape
         | 
| 33 | 
            +
                      def parameter_names
         | 
| 34 | 
            +
                        [:x, :y, :width, :height, :start_angle, :arc_angle]
         | 
| 35 | 
            +
                      end
         | 
| 36 | 
            +
                    
         | 
| 37 | 
            +
                      def post_add_content
         | 
| 38 | 
            +
                        @performing_post_add_content = true
         | 
| 39 | 
            +
                        render
         | 
| 40 | 
            +
                        @performing_post_add_content = false
         | 
| 41 | 
            +
                      end
         | 
| 42 | 
            +
                      
         | 
| 43 | 
            +
                      def background=(value)
         | 
| 44 | 
            +
                        super(value)
         | 
| 45 | 
            +
                        self.foreground = value
         | 
| 46 | 
            +
                      end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                      def render(custom_parent_dom_element: nil, brand_new: false)
         | 
| 49 | 
            +
                        return unless @performing_post_add_content
         | 
| 50 | 
            +
                        the_parent_element = Native(`document.getElementById(#{parent.id})`)
         | 
| 51 | 
            +
                        params = { type: `Two.Types.svg` }
         | 
| 52 | 
            +
                        two = Native(`new Two(#{params})`)
         | 
| 53 | 
            +
                        two.appendTo(the_parent_element)
         | 
| 54 | 
            +
                        x = @args[0]
         | 
| 55 | 
            +
                        y = @args[1]
         | 
| 56 | 
            +
                        width = @args[2]
         | 
| 57 | 
            +
                        height = @args[3]
         | 
| 58 | 
            +
                        start_angle = -1*@args[4]
         | 
| 59 | 
            +
                        arc_angle = -1*@args[5]
         | 
| 60 | 
            +
                        end_angle = start_angle + arc_angle
         | 
| 61 | 
            +
                        rx = width / 2.0
         | 
| 62 | 
            +
                        ry = height / 2.0
         | 
| 63 | 
            +
                        cx = x + rx
         | 
| 64 | 
            +
                        cy = y + ry
         | 
| 65 | 
            +
                        arc = two.makeArcSegment(cx, cy, 0, ry, 2*`Math.PI`*(start_angle)/360.0, 2*`Math.PI`*(end_angle)/360.0);
         | 
| 66 | 
            +
                        arc.fill = background.to_css unless background.nil?
         | 
| 67 | 
            +
                        arc.stroke = foreground.to_css unless foreground.nil?
         | 
| 68 | 
            +
                        two.update
         | 
| 69 | 
            +
                      end
         | 
| 70 | 
            +
                                
         | 
| 71 | 
            +
                    end
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
            end
         |