glimmer-dsl-libui 0.5.9 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +189 -6
- data/VERSION +1 -1
- data/examples/shape_coloring.rb +137 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/listener_expression.rb +1 -1
- data/lib/glimmer/libui/control_proxy/path_proxy.rb +4 -0
- data/lib/glimmer/libui/perfect_shaped.rb +19 -0
- data/lib/glimmer/libui/shape/arc.rb +5 -0
- data/lib/glimmer/libui/shape/bezier.rb +11 -0
- data/lib/glimmer/libui/shape/circle.rb +5 -0
- data/lib/glimmer/libui/shape/figure.rb +6 -0
- data/lib/glimmer/libui/shape/line.rb +7 -0
- data/lib/glimmer/libui/shape/polybezier.rb +4 -0
- data/lib/glimmer/libui/shape/polygon.rb +4 -0
- data/lib/glimmer/libui/shape/polyline.rb +4 -0
- data/lib/glimmer/libui/shape/rectangle.rb +5 -0
- data/lib/glimmer/libui/shape/square.rb +5 -0
- data/lib/glimmer/libui/shape.rb +11 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b379bb11d6c49f9b76fef9757561fea66425ada858b2d1cb04e51347ac0ba4f
|
4
|
+
data.tar.gz: '079b574bdfea7868853403476093875d0cee538b742c9e0f19b4e9947516980e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f1c8f35368f2438313c30533209cfb33e9e5fa34159b59ca6a2b557a7051fcb554a6eb96cc2ec10bf5afbd54b4acbba208e136ba62d579ab3e1d031cc6775e3
|
7
|
+
data.tar.gz: 31c0dfcebb130b4913330aa75d53d01c2ec6711961cb032313149cf02465976de74890fd0e11f00d33160b785415bad5dd9a7b6c00cb02e3a69aa73773506e85
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.5.12
|
4
|
+
|
5
|
+
- Upgrade `perfect-shape` gem to 1.0.5 to address Ruby 3.1 issue with `matrix` gem getting extracted from Ruby into a bundled gem
|
6
|
+
|
7
|
+
## 0.5.11
|
8
|
+
|
9
|
+
- Upgrade to perfect-shape 1.0.4
|
10
|
+
- Update examples/shape_coloring.rb with basic drag and drop support
|
11
|
+
- Support `#move_by(x_delta, y_delta)` (alias `translate`) method on all shapes and `path` (e.g. useful in drag and drop)
|
12
|
+
- Support `#move(x, y)` method on all shapes and `path` to move to x,y coordinate directly
|
13
|
+
- Support `#min_x` minimum x coordinate of shape/`path` (of top-left corner)
|
14
|
+
- Support `#min_y` minimum y coordinate of shape/`path` (of top-left corner)
|
15
|
+
- Support `#max_x` maximum x coordinate of shape/`path` (of bottom-right corner)
|
16
|
+
- Support `#max_y` maximum y coordinate of shape/`path` (of bottom-right corner)
|
17
|
+
- Support `#center_point` (`Array` of x,y) center point of shape/`path`
|
18
|
+
- Support `#center_x` center x coordinate of shape/`path`
|
19
|
+
- Support `#center_y` center y coordinate of shape/`path`
|
20
|
+
|
21
|
+
## 0.5.10
|
22
|
+
|
23
|
+
- Support nesting area mouse listeners underneath shapes directly given the newly added support for the `include?(x, y)` method, which can be used to detect if a mouse event fired for a specific shape
|
24
|
+
- examples/shape_coloring.rb
|
25
|
+
|
3
26
|
## 0.5.9
|
4
27
|
|
5
28
|
- Upgrade to glimmer v2.7.3
|
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 LibUI 0.5.
|
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 LibUI 0.5.12
|
2
2
|
## Prerequisite-Free Ruby Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
|
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)
|
@@ -428,6 +428,7 @@ DSL | Platforms | Native? | Vector Graphics? | Pros | Cons | Prereqs
|
|
428
428
|
- [Tetris](#tetris)
|
429
429
|
- [Tic Tac Toe](#tic-tac-toe)
|
430
430
|
- [Timer](#timer)
|
431
|
+
- [Shape Coloring](#shape-coloring)
|
431
432
|
- [Applications](#applications)
|
432
433
|
- [Manga2PDF](#manga2pdf)
|
433
434
|
- [Befunge98 GUI](#befunge98-gui)
|
@@ -578,7 +579,7 @@ gem install glimmer-dsl-libui
|
|
578
579
|
Or install via Bundler `Gemfile`:
|
579
580
|
|
580
581
|
```ruby
|
581
|
-
gem 'glimmer-dsl-libui', '~> 0.5.
|
582
|
+
gem 'glimmer-dsl-libui', '~> 0.5.12'
|
582
583
|
```
|
583
584
|
|
584
585
|
Test that installation worked by running the [Meta-Example](#examples):
|
@@ -1087,13 +1088,22 @@ Mac | Windows | Linux
|
|
1087
1088
|
----|---------|------
|
1088
1089
|
![glimmer-dsl-libui-mac-area-gallery.png](images/glimmer-dsl-libui-mac-area-gallery.png) | ![glimmer-dsl-libui-windows-area-gallery.png](images/glimmer-dsl-libui-windows-area-gallery.png) | ![glimmer-dsl-libui-linux-area-gallery.png](images/glimmer-dsl-libui-linux-area-gallery.png)
|
1089
1090
|
|
1090
|
-
##### Shape Methods
|
1091
|
+
##### Area Path Shape Methods
|
1091
1092
|
|
1092
1093
|
- `::parameters`: returns parameters of a shape class
|
1093
1094
|
- `#bounding_box`: returns `Array` containing `[min_x, min_y, width, height]`
|
1094
1095
|
- `#contain?(*point, outline: false, distance_tolerance: 0)`: Returns if point (`[x, y]` `Array` or args) is inside the shape when `outline` is `false` or on the outline when `outline` is `true`. `distance_tolerance` is used when `outline` is `true` as a fuzz factor for declaring a point on the outline of the shape (e.g. helps users select a shape from its outline more easily).
|
1095
1096
|
- `#include?(*point)`: Returns if point (`[x, y]` `Array` or args) is inside the shape when filled (having `fill` value) or on the outline when stroked (not having `fill` value yet `stroke` value only)
|
1096
1097
|
- `#perfect_shape`: returns [PerfectShape](https://github.com/AndyObtiva/perfect-shape) object matching the [libui](https://github.com/andlabs/libui) shape.
|
1098
|
+
- `#move_by(x_delta, y_delta)` (alias: `translate`): moves (translates) shape by x,y delta
|
1099
|
+
- `#move(x, y)`: moves (translates) shape to x,y coordinates (in the top-left x,y corner of the shape)
|
1100
|
+
- `#min_x`: minimum x coordinate of shape (of top-left corner)
|
1101
|
+
- `#min_y`: minimum y coordinate of shape (of top-left corner)
|
1102
|
+
- `#max_x`: maximum x coordinate of shape (of bottom-right corner)
|
1103
|
+
- `#max_y`: maximum y coordinate of shape (of bottom-right corner)
|
1104
|
+
- `#center_point` (`Array` of x,y): center point of shape
|
1105
|
+
- `#center_x`: center x coordinate of shape
|
1106
|
+
- `#center_y`: center y coordinate of shape
|
1097
1107
|
|
1098
1108
|
#### Area Text
|
1099
1109
|
|
@@ -1392,6 +1402,10 @@ In general, it is recommended to use declarative stable paths whenever feasible
|
|
1392
1402
|
|
1393
1403
|
#### Area Listeners
|
1394
1404
|
|
1405
|
+
`area` supports a number of keyboard and mouse listeners to enable observing the control for user interaction to execute some logic.
|
1406
|
+
|
1407
|
+
The same listeners can be nested directly under `area` shapes like `rectangle` and `circle`, and [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) will automatically detect when the mouse lands within those shapes to constrain triggering the listeners by the shape regions.
|
1408
|
+
|
1395
1409
|
`area` supported listeners are:
|
1396
1410
|
- `on_key_event {|area_key_event| ...}`: general catch-all key event (recommend using fine-grained key events below instead)
|
1397
1411
|
- `on_key_down {|area_key_event| ...}`
|
@@ -1599,7 +1613,8 @@ SpinnerExample.new.launch
|
|
1599
1613
|
- All controls nested under a `horizontal_box`, `vertical_box`, and `form` have `stretchy` property (fill maximum space) as `true` by default (passed to `box_append`/`form_append` method)
|
1600
1614
|
- If an event listener is repeated under a control (e.g. two `on_clicked {}` listeners under `button`), it does not overwrite the previous listener, yet it is added to an `Array` of listeners for the event. [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) provides multiple-event-listener support unlike [LibUI](https://github.com/kojix2/LibUI)
|
1601
1615
|
- `window` instatiation args can be left off, having the following defaults when unspecified: `title` as `''`, `width` as `190`, `height` as `150`, and `has_menubar` as `true`)
|
1602
|
-
- `window` has an `on_closing` listener by default that quits application upon hitting the close button (can be overridden with a manual `on_closing` implementation that returns integer `0` for
|
1616
|
+
- `window` has an `on_closing` listener by default that quits application upon hitting the close button (can be overridden with a manual `on_closing` implementation that returns integer `1` for closing and `0` for remaining open). When creating/showing a child window other than the main window and then closing it, the entire app closes by default unless you implement an `on_closing` listener on the secondary child window that returns `1` at the end.
|
1617
|
+
|
1603
1618
|
- `group` has `title` property default to `''` if not specified in instantiation args, so it can be instantiated without args with `title` property specified in nested block (e.g. `group {title 'Address'; ...}`)
|
1604
1619
|
- `button`, `checkbox`, and `label` have `text` default to `''` if not specified in instantiation args, so they can be instantiated without args with `text` property specified in nested block (e.g. `button {text 'Greet'; on_clicked {puts 'Hello'}}`)
|
1605
1620
|
- `quit_menu_item` has an `on_clicked` listener by default that quits application upon selecting the quit menu item (can be overridden with a manual `on_clicked` implementation that returns integer `0` for success)
|
@@ -2187,7 +2202,6 @@ Learn more from data-binding usage in [Login](#login) (4 data-binding versions),
|
|
2187
2202
|
- There is no proper way to destroy `grid` children due to [libui](https://github.com/andlabs/libui) not offering any API for deleting them from `grid` (no `grid_delete` similar to `box_delete` for `horizontal_box` and `vertical_box`).
|
2188
2203
|
- `table` `checkbox_column` checkbox editing only works on Linux and Windows (not Mac) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
|
2189
2204
|
- `table` `checkbox_text_column` checkbox editing only works on Linux (not Mac or Windows) due to a current limitation in [libui](https://github.com/andlabs/ui/issues/357).
|
2190
|
-
- `checkbox` only supports obtaining the `checked` property, but not updating it due to a current limitation in [libui](https://github.com/andlabs/libui).
|
2191
2205
|
- `text` `align` property seems not to work on the Mac ([libui](https://github.com/andlabs/libui) has an [issue](https://github.com/andlabs/libui/pull/407) about it)
|
2192
2206
|
- `text` `string` `background` does not work on Windows due to an [issue in libui](https://github.com/andlabs/libui/issues/347).
|
2193
2207
|
- `table` `progress_bar` column on Windows cannot be updated with a positive value if it started initially with `-1` (it ignores update to avoid crashing due to an issue in [libui](https://github.com/andlabs/libui) on Windows.
|
@@ -2195,7 +2209,6 @@ Learn more from data-binding usage in [Login](#login) (4 data-binding versions),
|
|
2195
2209
|
- It seems that [libui](https://github.com/andlabs/libui) does not support nesting multiple `area` controls under a `grid` as only the first one shows up in that scenario. To workaround that limitation, use a `vertical_box` with nested `horizontal_box`s instead to include multiple `area`s in a GUI.
|
2196
2210
|
- As per the code of [examples/basic_transform.rb](#basic-transform), Windows requires different ordering of transforms than Mac and Linux.
|
2197
2211
|
- `scrolling_area#scroll_to` does not seem to work on Windows and Linux, but works fine on Mac
|
2198
|
-
- When creating/showing a window other than the main window and then closing the secondary window, the entire app closes. This is a current limitation to the windowing system that should be fixed with [child window support](https://github.com/andlabs/libui/issues/137) in [libui](https://github.com/andlabs/libui)
|
2199
2212
|
|
2200
2213
|
### Original API
|
2201
2214
|
|
@@ -11016,6 +11029,176 @@ end
|
|
11016
11029
|
Timer.new
|
11017
11030
|
```
|
11018
11031
|
|
11032
|
+
#### Shape Coloring
|
11033
|
+
|
11034
|
+
This example demonstrates being able to nest listeners within shapes directly, and [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) will automatically detect when the mouse lands inside the shapes to notify listeners.
|
11035
|
+
|
11036
|
+
This example also demonstrates very basic drag and drop support, implemented manually with shape listeners.
|
11037
|
+
|
11038
|
+
[examples/shape_coloring.rb](examples/shape_coloring.rb)
|
11039
|
+
|
11040
|
+
Run with this command from the root of the project if you cloned the project:
|
11041
|
+
|
11042
|
+
```
|
11043
|
+
ruby -r './lib/glimmer-dsl-libui' examples/shape_coloring.rb
|
11044
|
+
```
|
11045
|
+
|
11046
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
11047
|
+
|
11048
|
+
```
|
11049
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/shape_coloring'"
|
11050
|
+
```
|
11051
|
+
|
11052
|
+
Shape Coloring Example
|
11053
|
+
|
11054
|
+
![glimmer-dsl-libui-mac-shape-coloring.png](images/glimmer-dsl-libui-mac-shape-coloring.png)
|
11055
|
+
|
11056
|
+
![glimmer-dsl-libui-mac-shape-coloring-drag-and-drop.png](images/glimmer-dsl-libui-mac-shape-coloring-drag-and-drop.png)
|
11057
|
+
|
11058
|
+
![glimmer-dsl-libui-mac-shape-coloring-color-dialog.png](images/glimmer-dsl-libui-mac-shape-coloring-color-dialog.png)
|
11059
|
+
|
11060
|
+
New [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
11061
|
+
|
11062
|
+
```ruby
|
11063
|
+
require 'glimmer-dsl-libui'
|
11064
|
+
|
11065
|
+
class ShapeColoring
|
11066
|
+
include Glimmer::LibUI::Application
|
11067
|
+
|
11068
|
+
COLOR_SELECTION = Glimmer::LibUI.interpret_color(:red)
|
11069
|
+
|
11070
|
+
before_body {
|
11071
|
+
@shapes = []
|
11072
|
+
}
|
11073
|
+
|
11074
|
+
body {
|
11075
|
+
window('Shape Coloring', 200, 220) {
|
11076
|
+
margined false
|
11077
|
+
|
11078
|
+
grid {
|
11079
|
+
label("Drag & drop shapes to move or\nclick a shape to select and\nchange color via color button") {
|
11080
|
+
left 0
|
11081
|
+
top 0
|
11082
|
+
hexpand true
|
11083
|
+
halign :center
|
11084
|
+
vexpand false
|
11085
|
+
}
|
11086
|
+
|
11087
|
+
color_button { |cb|
|
11088
|
+
left 0
|
11089
|
+
top 1
|
11090
|
+
hexpand true
|
11091
|
+
vexpand false
|
11092
|
+
|
11093
|
+
on_changed do
|
11094
|
+
@selected_shape&.fill = cb.color
|
11095
|
+
end
|
11096
|
+
}
|
11097
|
+
|
11098
|
+
area {
|
11099
|
+
left 0
|
11100
|
+
top 2
|
11101
|
+
hexpand true
|
11102
|
+
vexpand true
|
11103
|
+
|
11104
|
+
rectangle(0, 0, 600, 400) { # background shape
|
11105
|
+
fill :white
|
11106
|
+
}
|
11107
|
+
|
11108
|
+
@shapes << colorable(:rectangle, 20, 20, 40, 20) {
|
11109
|
+
fill :lime
|
11110
|
+
}
|
11111
|
+
|
11112
|
+
@shapes << colorable(:square, 80, 20, 20) {
|
11113
|
+
fill :blue
|
11114
|
+
}
|
11115
|
+
|
11116
|
+
@shapes << colorable(:circle, 75, 70, 20) {
|
11117
|
+
fill :green
|
11118
|
+
}
|
11119
|
+
|
11120
|
+
@shapes << colorable(:arc, 120, 70, 40, 0, 145) {
|
11121
|
+
fill :orange
|
11122
|
+
}
|
11123
|
+
|
11124
|
+
@shapes << colorable(:polygon, 120, 10, 120, 50, 150, 10, 150, 50) {
|
11125
|
+
fill :cyan
|
11126
|
+
}
|
11127
|
+
|
11128
|
+
@shapes << colorable(:polybezier, 20, 40,
|
11129
|
+
30, 100, 50, 80, 80, 110,
|
11130
|
+
40, 120, 20, 120, 30, 91) {
|
11131
|
+
fill :pink
|
11132
|
+
}
|
11133
|
+
|
11134
|
+
on_mouse_dragged do |area_mouse_event|
|
11135
|
+
mouse_dragged(area_mouse_event)
|
11136
|
+
end
|
11137
|
+
|
11138
|
+
on_mouse_dropped do |area_mouse_event|
|
11139
|
+
mouse_dropped(area_mouse_event)
|
11140
|
+
end
|
11141
|
+
}
|
11142
|
+
}
|
11143
|
+
}
|
11144
|
+
}
|
11145
|
+
|
11146
|
+
def colorable(shape_symbol, *args, &content)
|
11147
|
+
send(shape_symbol, *args) do |shape|
|
11148
|
+
on_mouse_up do |area_mouse_event|
|
11149
|
+
unless @dragged_shape
|
11150
|
+
old_stroke = Glimmer::LibUI.interpret_color(shape.stroke).slice(:r, :g, :b)
|
11151
|
+
@shapes.each {|sh| sh.stroke = nil}
|
11152
|
+
@selected_shape = nil
|
11153
|
+
unless old_stroke == COLOR_SELECTION
|
11154
|
+
shape.stroke = COLOR_SELECTION.merge(thickness: 2)
|
11155
|
+
@selected_shape = shape
|
11156
|
+
end
|
11157
|
+
end
|
11158
|
+
end
|
11159
|
+
|
11160
|
+
on_mouse_drag_started do |area_mouse_event|
|
11161
|
+
mouse_drag_started(shape, area_mouse_event)
|
11162
|
+
end
|
11163
|
+
|
11164
|
+
on_mouse_dragged do |area_mouse_event|
|
11165
|
+
mouse_dragged(area_mouse_event)
|
11166
|
+
end
|
11167
|
+
|
11168
|
+
on_mouse_dropped do |area_mouse_event|
|
11169
|
+
mouse_dropped(area_mouse_event)
|
11170
|
+
end
|
11171
|
+
|
11172
|
+
content.call(shape)
|
11173
|
+
end
|
11174
|
+
end
|
11175
|
+
|
11176
|
+
def mouse_drag_started(dragged_shape, area_mouse_event)
|
11177
|
+
@dragged_shape = dragged_shape
|
11178
|
+
@dragged_shape_x = area_mouse_event[:x]
|
11179
|
+
@dragged_shape_y = area_mouse_event[:y]
|
11180
|
+
end
|
11181
|
+
|
11182
|
+
def mouse_dragged(area_mouse_event)
|
11183
|
+
if @dragged_shape && @dragged_shape_x && @dragged_shape_y
|
11184
|
+
x_delta = area_mouse_event[:x] - @dragged_shape_x
|
11185
|
+
y_delta = area_mouse_event[:y] - @dragged_shape_y
|
11186
|
+
@dragged_shape.move_by(x_delta, y_delta)
|
11187
|
+
@dragged_shape_x = area_mouse_event[:x]
|
11188
|
+
@dragged_shape_y = area_mouse_event[:y]
|
11189
|
+
end
|
11190
|
+
end
|
11191
|
+
|
11192
|
+
def mouse_dropped(area_mouse_event)
|
11193
|
+
@dragged_shape = nil
|
11194
|
+
@dragged_shape_x = nil
|
11195
|
+
@dragged_shape_y = nil
|
11196
|
+
end
|
11197
|
+
end
|
11198
|
+
|
11199
|
+
ShapeColoring.launch
|
11200
|
+
```
|
11201
|
+
|
11019
11202
|
## Applications
|
11020
11203
|
|
11021
11204
|
Here are some applications built with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.12
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
class ShapeColoring
|
4
|
+
include Glimmer::LibUI::Application
|
5
|
+
|
6
|
+
COLOR_SELECTION = Glimmer::LibUI.interpret_color(:red)
|
7
|
+
|
8
|
+
before_body {
|
9
|
+
@shapes = []
|
10
|
+
}
|
11
|
+
|
12
|
+
body {
|
13
|
+
window('Shape Coloring', 200, 220) {
|
14
|
+
margined false
|
15
|
+
|
16
|
+
grid {
|
17
|
+
label("Drag & drop shapes to move or\nclick a shape to select and\nchange color via color button") {
|
18
|
+
left 0
|
19
|
+
top 0
|
20
|
+
hexpand true
|
21
|
+
halign :center
|
22
|
+
vexpand false
|
23
|
+
}
|
24
|
+
|
25
|
+
color_button { |cb|
|
26
|
+
left 0
|
27
|
+
top 1
|
28
|
+
hexpand true
|
29
|
+
vexpand false
|
30
|
+
|
31
|
+
on_changed do
|
32
|
+
@selected_shape&.fill = cb.color
|
33
|
+
end
|
34
|
+
}
|
35
|
+
|
36
|
+
area {
|
37
|
+
left 0
|
38
|
+
top 2
|
39
|
+
hexpand true
|
40
|
+
vexpand true
|
41
|
+
|
42
|
+
rectangle(0, 0, 600, 400) { # background shape
|
43
|
+
fill :white
|
44
|
+
}
|
45
|
+
|
46
|
+
@shapes << colorable(:rectangle, 20, 20, 40, 20) {
|
47
|
+
fill :lime
|
48
|
+
}
|
49
|
+
|
50
|
+
@shapes << colorable(:square, 80, 20, 20) {
|
51
|
+
fill :blue
|
52
|
+
}
|
53
|
+
|
54
|
+
@shapes << colorable(:circle, 75, 70, 20) {
|
55
|
+
fill :green
|
56
|
+
}
|
57
|
+
|
58
|
+
@shapes << colorable(:arc, 120, 70, 40, 0, 145) {
|
59
|
+
fill :orange
|
60
|
+
}
|
61
|
+
|
62
|
+
@shapes << colorable(:polygon, 120, 10, 120, 50, 150, 10, 150, 50) {
|
63
|
+
fill :cyan
|
64
|
+
}
|
65
|
+
|
66
|
+
@shapes << colorable(:polybezier, 20, 40,
|
67
|
+
30, 100, 50, 80, 80, 110,
|
68
|
+
40, 120, 20, 120, 30, 91) {
|
69
|
+
fill :pink
|
70
|
+
}
|
71
|
+
|
72
|
+
on_mouse_dragged do |area_mouse_event|
|
73
|
+
mouse_dragged(area_mouse_event)
|
74
|
+
end
|
75
|
+
|
76
|
+
on_mouse_dropped do |area_mouse_event|
|
77
|
+
mouse_dropped(area_mouse_event)
|
78
|
+
end
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
def colorable(shape_symbol, *args, &content)
|
85
|
+
send(shape_symbol, *args) do |shape|
|
86
|
+
on_mouse_up do |area_mouse_event|
|
87
|
+
unless @dragged_shape
|
88
|
+
old_stroke = Glimmer::LibUI.interpret_color(shape.stroke).slice(:r, :g, :b)
|
89
|
+
@shapes.each {|sh| sh.stroke = nil}
|
90
|
+
@selected_shape = nil
|
91
|
+
unless old_stroke == COLOR_SELECTION
|
92
|
+
shape.stroke = COLOR_SELECTION.merge(thickness: 2)
|
93
|
+
@selected_shape = shape
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
on_mouse_drag_started do |area_mouse_event|
|
99
|
+
mouse_drag_started(shape, area_mouse_event)
|
100
|
+
end
|
101
|
+
|
102
|
+
on_mouse_dragged do |area_mouse_event|
|
103
|
+
mouse_dragged(area_mouse_event)
|
104
|
+
end
|
105
|
+
|
106
|
+
on_mouse_dropped do |area_mouse_event|
|
107
|
+
mouse_dropped(area_mouse_event)
|
108
|
+
end
|
109
|
+
|
110
|
+
content.call(shape)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def mouse_drag_started(dragged_shape, area_mouse_event)
|
115
|
+
@dragged_shape = dragged_shape
|
116
|
+
@dragged_shape_x = area_mouse_event[:x]
|
117
|
+
@dragged_shape_y = area_mouse_event[:y]
|
118
|
+
end
|
119
|
+
|
120
|
+
def mouse_dragged(area_mouse_event)
|
121
|
+
if @dragged_shape && @dragged_shape_x && @dragged_shape_y
|
122
|
+
x_delta = area_mouse_event[:x] - @dragged_shape_x
|
123
|
+
y_delta = area_mouse_event[:y] - @dragged_shape_y
|
124
|
+
@dragged_shape.move_by(x_delta, y_delta)
|
125
|
+
@dragged_shape_x = area_mouse_event[:x]
|
126
|
+
@dragged_shape_y = area_mouse_event[:y]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def mouse_dropped(area_mouse_event)
|
131
|
+
@dragged_shape = nil
|
132
|
+
@dragged_shape_x = nil
|
133
|
+
@dragged_shape_y = nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
ShapeColoring.launch
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -27,7 +27,7 @@ module Glimmer
|
|
27
27
|
module Libui
|
28
28
|
class ListenerExpression < Expression
|
29
29
|
def can_interpret?(parent, keyword, *args, &block)
|
30
|
-
parent.is_a?(Glimmer::LibUI::ControlProxy) and
|
30
|
+
(parent.is_a?(Glimmer::LibUI::ControlProxy) or parent.is_a?(Glimmer::LibUI::Shape)) and
|
31
31
|
block_given? and
|
32
32
|
parent.can_handle_listener?(keyword)
|
33
33
|
end
|
@@ -162,6 +162,10 @@ module Glimmer
|
|
162
162
|
@parent_proxy&.request_auto_redraw
|
163
163
|
end
|
164
164
|
|
165
|
+
def move_by(x_delta, y_delta)
|
166
|
+
children.each {|child| child.move_by(x_delta, y_delta)}
|
167
|
+
end
|
168
|
+
|
165
169
|
def perfect_shape
|
166
170
|
perfect_shape_dependencies = [draw_fill_mode, children]
|
167
171
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -1,7 +1,14 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module Glimmer
|
2
4
|
module LibUI
|
3
5
|
# GUI View objects that can be represented by PerfectShape objects
|
4
6
|
module PerfectShaped
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :perfect_shape,
|
10
|
+
:min_x, :min_y, :max_x, :max_y, :center_point, :center_x, :center_y
|
11
|
+
|
5
12
|
# Returns if shape contains point on the inside when outline is false (default)
|
6
13
|
# or if point is on the outline when outline is true
|
7
14
|
# distance_tolerance is used when outline is true to enable a fuzz factor in
|
@@ -34,6 +41,18 @@ module Glimmer
|
|
34
41
|
]
|
35
42
|
end
|
36
43
|
|
44
|
+
# moves by x delta and y delta. Classes must implement
|
45
|
+
def move_by(x_delta, y_delta)
|
46
|
+
# No Op
|
47
|
+
end
|
48
|
+
alias translate move_by
|
49
|
+
|
50
|
+
def move(x, y)
|
51
|
+
x_delta = x - perfect_shape.min_x
|
52
|
+
y_delta = y - perfect_shape.min_y
|
53
|
+
move_by(x_delta, y_delta)
|
54
|
+
end
|
55
|
+
|
37
56
|
# Returns PerfectShape object matching this shape to enable
|
38
57
|
# executing computational geometry algorithms
|
39
58
|
#
|
@@ -45,6 +45,11 @@ module Glimmer
|
|
45
45
|
super
|
46
46
|
end
|
47
47
|
|
48
|
+
def move_by(x_delta, y_delta)
|
49
|
+
self.x_center += x_delta
|
50
|
+
self.y_center += y_delta
|
51
|
+
end
|
52
|
+
|
48
53
|
def perfect_shape
|
49
54
|
perfect_shape_dependencies = [x_center, y_center, radius, start_angle, sweep, is_negative]
|
50
55
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -50,6 +50,17 @@ module Glimmer
|
|
50
50
|
x && y
|
51
51
|
end
|
52
52
|
|
53
|
+
def move_by(x_delta, y_delta)
|
54
|
+
self.x += x_delta
|
55
|
+
self.y += y_delta
|
56
|
+
self.c1_x += x_delta
|
57
|
+
self.c1_y += y_delta
|
58
|
+
self.c2_x += x_delta
|
59
|
+
self.c2_y += y_delta
|
60
|
+
self.end_x += x_delta
|
61
|
+
self.end_y += y_delta
|
62
|
+
end
|
63
|
+
|
53
64
|
def perfect_shape
|
54
65
|
perfect_shape_dependencies = [x, y, c1_x, c1_y, c2_x, c2_y, end_x, end_y]
|
55
66
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -45,6 +45,11 @@ module Glimmer
|
|
45
45
|
super
|
46
46
|
end
|
47
47
|
|
48
|
+
def move_by(x_delta, y_delta)
|
49
|
+
self.x_center += x_delta
|
50
|
+
self.y_center += y_delta
|
51
|
+
end
|
52
|
+
|
48
53
|
def perfect_shape
|
49
54
|
perfect_shape_dependencies = [x_center, y_center, radius]
|
50
55
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -51,6 +51,12 @@ module Glimmer
|
|
51
51
|
alias set_closed closed
|
52
52
|
alias closed? closed
|
53
53
|
|
54
|
+
def move_by(x_delta, y_delta)
|
55
|
+
self.x += x_delta
|
56
|
+
self.y += y_delta
|
57
|
+
children.each {|child| child.move_by(x_delta, y_delta)}
|
58
|
+
end
|
59
|
+
|
54
60
|
def perfect_shape
|
55
61
|
perfect_shape_dependencies = [x, y, closed, parent.draw_fill_mode, children]
|
56
62
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -53,6 +53,13 @@ module Glimmer
|
|
53
53
|
!parent.is_a?(Figure) && end_x && end_y
|
54
54
|
end
|
55
55
|
|
56
|
+
def move_by(x_delta, y_delta)
|
57
|
+
self.x += x_delta
|
58
|
+
self.y += y_delta
|
59
|
+
self.end_x += x_delta
|
60
|
+
self.end_y += y_delta
|
61
|
+
end
|
62
|
+
|
56
63
|
def perfect_shape
|
57
64
|
perfect_shape_dependencies = [x, y, end_x, end_y]
|
58
65
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -40,6 +40,10 @@ module Glimmer
|
|
40
40
|
super
|
41
41
|
end
|
42
42
|
|
43
|
+
def move_by(x_delta, y_delta)
|
44
|
+
self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
|
45
|
+
end
|
46
|
+
|
43
47
|
def perfect_shape
|
44
48
|
perfect_shape_dependencies = PerfectShape::MultiPoint.normalize_point_array(point_array)
|
45
49
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -41,6 +41,10 @@ module Glimmer
|
|
41
41
|
super
|
42
42
|
end
|
43
43
|
|
44
|
+
def move_by(x_delta, y_delta)
|
45
|
+
self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
|
46
|
+
end
|
47
|
+
|
44
48
|
def perfect_shape
|
45
49
|
perfect_shape_dependencies = PerfectShape::MultiPoint.normalize_point_array(point_array)
|
46
50
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -40,6 +40,10 @@ module Glimmer
|
|
40
40
|
super
|
41
41
|
end
|
42
42
|
|
43
|
+
def move_by(x_delta, y_delta)
|
44
|
+
self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
|
45
|
+
end
|
46
|
+
|
43
47
|
def perfect_shape
|
44
48
|
perfect_shape_dependencies = PerfectShape::MultiPoint.normalize_point_array(point_array)
|
45
49
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -33,6 +33,11 @@ module Glimmer
|
|
33
33
|
super
|
34
34
|
end
|
35
35
|
|
36
|
+
def move_by(x_delta, y_delta)
|
37
|
+
self.x += x_delta
|
38
|
+
self.y += y_delta
|
39
|
+
end
|
40
|
+
|
36
41
|
def perfect_shape
|
37
42
|
perfect_shape_dependencies = [x, y, width, height]
|
38
43
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
@@ -35,6 +35,11 @@ module Glimmer
|
|
35
35
|
|
36
36
|
# TODO look into refactoring/unifying code with Rectangle
|
37
37
|
|
38
|
+
def move_by(x_delta, y_delta)
|
39
|
+
self.x += x_delta
|
40
|
+
self.y += y_delta
|
41
|
+
end
|
42
|
+
|
38
43
|
def perfect_shape
|
39
44
|
perfect_shape_dependencies = [x, y, length]
|
40
45
|
if perfect_shape_dependencies != @perfect_shape_dependencies
|
data/lib/glimmer/libui/shape.rb
CHANGED
@@ -147,6 +147,16 @@ module Glimmer
|
|
147
147
|
end
|
148
148
|
alias transform= transform
|
149
149
|
alias set_transform transform
|
150
|
+
|
151
|
+
def can_handle_listener?(listener_name)
|
152
|
+
area_proxy.can_handle_listener?(listener_name)
|
153
|
+
end
|
154
|
+
|
155
|
+
def handle_listener(listener_name, &listener)
|
156
|
+
area_proxy.handle_listener(listener_name) do |event|
|
157
|
+
listener.call(event) if include?(event[:x], event[:y])
|
158
|
+
end
|
159
|
+
end
|
150
160
|
|
151
161
|
def respond_to?(method_name, *args, &block)
|
152
162
|
self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
|
@@ -171,7 +181,7 @@ module Glimmer
|
|
171
181
|
super
|
172
182
|
end
|
173
183
|
end
|
174
|
-
|
184
|
+
|
175
185
|
private
|
176
186
|
|
177
187
|
def build_control
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.12
|
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-
|
11
|
+
date: 2022-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.
|
33
|
+
version: 1.0.5
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.
|
40
|
+
version: 1.0.5
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: super_module
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -355,6 +355,7 @@ files:
|
|
355
355
|
- examples/midi_player.rb
|
356
356
|
- examples/midi_player2.rb
|
357
357
|
- examples/midi_player3.rb
|
358
|
+
- examples/shape_coloring.rb
|
358
359
|
- examples/simple_notepad.rb
|
359
360
|
- examples/snake.rb
|
360
361
|
- examples/snake/model/apple.rb
|
@@ -510,7 +511,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
510
511
|
- !ruby/object:Gem::Version
|
511
512
|
version: '0'
|
512
513
|
requirements: []
|
513
|
-
rubygems_version: 3.3.
|
514
|
+
rubygems_version: 3.3.3
|
514
515
|
signing_key:
|
515
516
|
specification_version: 4
|
516
517
|
summary: Glimmer DSL for LibUI
|