glimmer-dsl-swt 4.18.5.2 → 4.18.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +3 -3
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +35 -3
  6. data/glimmer-dsl-swt.gemspec +3 -3
  7. data/lib/glimmer/swt/custom/drawable.rb +8 -7
  8. data/lib/glimmer/swt/custom/shape.rb +153 -13
  9. data/lib/glimmer/swt/custom/shape/arc.rb +3 -3
  10. data/lib/glimmer/swt/custom/shape/image.rb +19 -6
  11. data/lib/glimmer/swt/custom/shape/line.rb +47 -1
  12. data/lib/glimmer/swt/custom/shape/oval.rb +3 -3
  13. data/lib/glimmer/swt/custom/shape/point.rb +1 -6
  14. data/lib/glimmer/swt/custom/shape/polygon.rb +42 -1
  15. data/lib/glimmer/swt/custom/shape/polyline.rb +45 -4
  16. data/lib/glimmer/swt/custom/shape/rectangle.rb +5 -1
  17. data/lib/glimmer/swt/widget_proxy.rb +16 -0
  18. data/samples/elaborate/contact_manager.rb +2 -0
  19. data/samples/elaborate/login.rb +2 -0
  20. data/samples/elaborate/mandelbrot_fractal.rb +1 -0
  21. data/samples/elaborate/meta_sample.rb +1 -0
  22. data/samples/elaborate/tetris.rb +2 -1
  23. data/samples/elaborate/tic_tac_toe.rb +2 -0
  24. data/samples/elaborate/user_profile.rb +10 -8
  25. data/samples/hello/hello_browser.rb +2 -0
  26. data/samples/hello/hello_button.rb +2 -0
  27. data/samples/hello/hello_canvas.rb +14 -12
  28. data/samples/hello/hello_canvas_animation.rb +2 -0
  29. data/samples/hello/hello_canvas_transform.rb +2 -0
  30. data/samples/hello/hello_checkbox.rb +2 -0
  31. data/samples/hello/hello_checkbox_group.rb +2 -0
  32. data/samples/hello/hello_code_text.rb +2 -0
  33. data/samples/hello/hello_color_dialog.rb +2 -0
  34. data/samples/hello/hello_combo.rb +2 -0
  35. data/samples/hello/hello_computed.rb +2 -0
  36. data/samples/hello/hello_cursor.rb +2 -0
  37. data/samples/hello/hello_custom_shell.rb +1 -0
  38. data/samples/hello/hello_custom_widget.rb +2 -0
  39. data/samples/hello/hello_date_time.rb +2 -0
  40. data/samples/hello/hello_dialog.rb +2 -0
  41. data/samples/hello/hello_directory_dialog.rb +2 -0
  42. data/samples/hello/hello_drag_and_drop.rb +5 -3
  43. data/samples/hello/hello_expand_bar.rb +2 -0
  44. data/samples/hello/hello_file_dialog.rb +2 -0
  45. data/samples/hello/hello_font_dialog.rb +2 -0
  46. data/samples/hello/hello_group.rb +2 -0
  47. data/samples/hello/hello_link.rb +2 -0
  48. data/samples/hello/hello_list_multi_selection.rb +2 -0
  49. data/samples/hello/hello_list_single_selection.rb +2 -0
  50. data/samples/hello/hello_menu_bar.rb +2 -0
  51. data/samples/hello/hello_message_box.rb +2 -0
  52. data/samples/hello/hello_pop_up_context_menu.rb +2 -0
  53. data/samples/hello/hello_progress_bar.rb +2 -0
  54. data/samples/hello/hello_radio.rb +2 -0
  55. data/samples/hello/hello_radio_group.rb +2 -0
  56. data/samples/hello/hello_sash_form.rb +2 -0
  57. data/samples/hello/hello_spinner.rb +2 -0
  58. data/samples/hello/hello_styled_text.rb +19 -17
  59. data/samples/hello/hello_tab.rb +2 -0
  60. data/samples/hello/hello_table.rb +2 -0
  61. data/samples/hello/hello_world.rb +2 -0
  62. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03f0ab47e7617c3d595a737c755ddc05e877074fb9139cacca042c6c31f7999e
4
- data.tar.gz: f80117653d4ce70cfde372cbe660ab4d0a7ae181a24df76c79226fcb43c68549
3
+ metadata.gz: acf07c3a7c6f534f4082330369a0bacac2593675506da814ec68e70446ec02b9
4
+ data.tar.gz: ff2983c28283b30b4f7f9e6bdf9cc0bad3768331014ef281ff5397726851b39d
5
5
  SHA512:
6
- metadata.gz: a543129ea30b6a18306341b9fad1f62a36f919d83cedc27ea5b6e62c18e13827b28e05cbb01c81e0d8639d5412aeb6ba2e81de60e4c7f0ba5052b474eb07b7f3
7
- data.tar.gz: 8d757538764f6018a381bcc68583b2d2660d23c9a2f8f1b15c90ad904b84316b1a4e61197f1f618a2bb42ad5d2114cc087e9aaebe1538514a24b330bdf8ce44f
6
+ metadata.gz: d89da48eb352e555e861032de5b5fee9c1e1ad3e7796c920e354b61b5fb1e2522fa1eafd89e363259ee9c3961ab4207a51ea483ef670e072c869fb1671fecccb
7
+ data.tar.gz: d267615568ac7e20ef8b5778df77cfe36f3de061ab9dd5c4e227b2ef08d5323a27bc6742f07728a84b0760a11f64bdad822c4468f1cf24049ac536919816548e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.18.5.3
4
+
5
+ - Support nesting shapes within shapes, with relative positioning (meaning x, y coordinates are assumed relative to parent's x, y in nested shapes)
6
+ - Support passing x, y coordinates as :default (or nil or not passed in if they are the last args) in all shapes, meaning they are centered within parent taking their width and height into account
7
+ - Support default_x_delta, y_delta attributes, which add/subtract from defaults used for shape
8
+
3
9
  ### 4.18.5.2
4
10
 
5
11
  - Support checking if an `arc` shape accurately includes a point x,y coordinates within pie region only
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.18.5.2
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.18.5.3
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)
@@ -342,7 +342,7 @@ jgem install glimmer-dsl-swt
342
342
 
343
343
  Or this command if you want a specific version:
344
344
  ```
345
- jgem install glimmer-dsl-swt -v 4.18.5.2
345
+ jgem install glimmer-dsl-swt -v 4.18.5.3
346
346
  ```
347
347
 
348
348
  `jgem` is JRuby's version of `gem` command.
@@ -360,7 +360,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
360
360
 
361
361
  Add the following to `Gemfile`:
362
362
  ```
363
- gem 'glimmer-dsl-swt', '~> 4.18.5.2'
363
+ gem 'glimmer-dsl-swt', '~> 4.18.5.3'
364
364
  ```
365
365
 
366
366
  And, then run:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.18.5.2
1
+ 4.18.5.3
@@ -1385,12 +1385,10 @@ https://help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/
1385
1385
 
1386
1386
  **(ALPHA FEATURE)**
1387
1387
 
1388
- Glimmer supports drawing graphics directly on a `canvas` widget via SWT (or any widget for that matter though `canvas` is recommended for drawing).
1388
+ While other GUI toolkits only offer a way to draw graphics imperatively (e.g. fill_rectangle, draw_point, etc...), Glimmer DSL for SWT breaks away from the mold by enabling software engineers to draw graphics declaratively. Simply declare all the shapes you want to see with their attributes, like background/foreground colors, and Glimmer DSL for SWT takes care of the rest, painting graphics on a blank `canvas` widget or amending/decorating an existing widget. This is accomplished through the Canvas Shape DSL, a sub-DSL of the Glimmer GUI DSL, which makes it possible to draw graphics declaratively with very understandable and maintainable syntax. Still, for the rare cases where imperative logic is needed, Glimmer DSL for SWT supports imperative painting of graphics through direct usage of SWT.
1389
1389
 
1390
1390
  `canvas` has the `:double_buffered` SWT style by default on platforms that need it (Windows & Linux) to ensure flicker-free rendering. If you need to disable it for whatever reason, just pass the `:none` SWT style instead (e.g. `canvas(:none)`)
1391
1391
 
1392
- This is accomplished via the Shape DSL a sub-DSL of the Glimmer GUI DSL, which makes it possible to draw graphics declaratively with very understandable and maintainable syntax.
1393
-
1394
1392
  Shape keywords and their args (including defaults) are listed below (they basically match method names and arguments on [org.eclipse.swt.graphics.GC](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/GC.html) minus the `draw` or `fill` prefix in downcase):
1395
1393
  - `arc(x, y, width, height, startAngle, arcAngle, fill: false)` arc is part of a circle within an oval area, denoted by start angle (degrees) and end angle (degrees)
1396
1394
  - `focus(x, y, width, height)` this is just like rectangle but its foreground color is always that of the OS widget focus color (useful when capturing user interaction via a shape)
@@ -1474,6 +1472,10 @@ Screenshot:
1474
1472
 
1475
1473
  ![Canvas Animation Example](/images/glimmer-example-canvas.png)
1476
1474
 
1475
+ If you specify the x and y coordinates as `:default`, `nil`, or leave them out, they get calculated automatically by centering the shape within its parent `canvas`.
1476
+
1477
+ Note that you could shift a shape off its centered position within its parent `canvas` by using `x_delta` and `y_delta` instead of `x` and `y`
1478
+
1477
1479
  The round and gradient options could be dropped since Glimmer DSL for SWT supports auto-inference of them based on shape parameters.
1478
1480
 
1479
1481
  Example (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
@@ -1620,6 +1622,36 @@ shell {
1620
1622
  }.open
1621
1623
  ```
1622
1624
 
1625
+ #### Shapes inside a Shape
1626
+
1627
+ Shapes can be nested within each other. If you nest a shape within another, its coordinates are assumed to be relative to its parent.
1628
+
1629
+ As such, if you move the parent, it moves all its children with it.
1630
+
1631
+ If you specify the x and y coordinates as `:default`, `nil`, or leave them out, they get calculated automatically by centering the shape within its parent shape relatively.
1632
+
1633
+ Note that you could shift a shape off its centered position within its parent shape by using `x_delta` and `y_delta` instead of `x` and `y`
1634
+
1635
+ Check [Hello, Canvas!](GLIMMER_SAMPLES.md#hello-canvas) for an example that nests lines, points, a polyline, and an image within a drawn rectangle parent:
1636
+
1637
+ ```ruby
1638
+ rectangle(205, 50, 88, 96) {
1639
+ foreground :yellow
1640
+ 3.times { |n|
1641
+ line(45, 70 + n*10, 65 + n*10, 30 + n*10) {
1642
+ foreground :yellow
1643
+ }
1644
+ }
1645
+ 10.times {|n|
1646
+ point(15 + n*5, 50 + n*5) {
1647
+ foreground :yellow
1648
+ }
1649
+ }
1650
+ polyline(45, 60, 55, 20, 65, 60, 85, 80, 45, 60)
1651
+ image(@image_object, 0, 5)
1652
+ }
1653
+ ```
1654
+
1623
1655
  #### Shapes inside a Widget
1624
1656
 
1625
1657
  Keep in mind that the Shape DSL can be used inside any widget, not just `canvas`. Unlike shapes on a `canvas`, which are standalone graphics, when included in a widget, which already has its own look and feel, shapes are used as a decorative add-on that complements its look by getting painted on top of it. For example, shapes were used to decorate `composite` blocks in the [Tetris](GLIMMER_SAMPLES.md#tetris) sample to have a more bevel look. In summary, Shapes can be used in a hybrid approach (shapes inside a widget), not just standalone in a `canvas`.
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-dsl-swt 4.18.5.2 ruby lib
5
+ # stub: glimmer-dsl-swt 4.18.5.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-swt".freeze
9
- s.version = "4.18.5.2"
9
+ s.version = "4.18.5.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2021-02-24"
14
+ s.date = "2021-02-25"
15
15
  s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) is a native-GUI cross-platform desktop development library written in JRuby, an OS-threaded faster JVM version of Ruby. Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models (test-first) afterwards. Not only does Glimmer provide a large set of GUI widgets, but it also supports drawing Canvas Graphics like Shapes and Animations. To get started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets. Glimmer also includes native-executable packaging support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in Ruby as truly native DMG/PKG/APP files on the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged Shell Scripts on Linux.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.executables = ["glimmer".freeze, "girb".freeze]
@@ -34,19 +34,20 @@ module Glimmer
34
34
  @shapes ||= []
35
35
  end
36
36
 
37
- def image_buffered_shapes
38
- @image_buffered_shapes ||= []
37
+ def expanded_shapes
38
+ @shapes.map do |shape|
39
+ [shape] + shape.expanded_shapes
40
+ end.flatten
39
41
  end
40
42
 
41
- # Returns shapes expanded with regards to nested shapes
42
- def expand_shapes(shapes)
43
- # TODO
43
+ def image_buffered_shapes
44
+ @image_buffered_shapes ||= []
44
45
  end
45
46
 
46
47
  # TODO add a method like shapes that specifies drawable_properties to be able to adjust properties like transform in between shapes
47
48
 
48
49
  def shape_at_location(x, y)
49
- shapes.reverse.detect {|shape| shape.include?(x, y)}
50
+ expanded_shapes.reverse.detect {|shape| shape.include?(x, y)}
50
51
  end
51
52
 
52
53
  def add_shape(shape)
@@ -139,7 +140,7 @@ module Glimmer
139
140
  @paint_listener_proxy = on_swt_paint(&shape_painter)
140
141
  end
141
142
  else
142
- redraw if @finished_add_content && !is_disposed
143
+ redraw if respond_to?(:redraw) && @finished_add_content && !is_disposed
143
144
  end
144
145
  end
145
146
  alias resetup_shape_painting setup_shape_painting
@@ -99,6 +99,7 @@ module Glimmer
99
99
  end
100
100
 
101
101
  attr_reader :drawable, :parent, :name, :args, :options, :shapes
102
+ attr_accessor :x_delta, :y_delta
102
103
 
103
104
  def initialize(parent, keyword, *args, &property_block)
104
105
  @parent = parent
@@ -109,6 +110,8 @@ module Glimmer
109
110
  @args = args
110
111
  @properties = {}
111
112
  @shapes = [] # nested shapes
113
+ @x_delta = 0
114
+ @y_delta = 0
112
115
  @options.reject {|key, value| %w[fill gradient round].include?(key.to_s)}.each do |property, property_args|
113
116
  @properties[property] = property_args
114
117
  end
@@ -143,7 +146,7 @@ module Glimmer
143
146
  def contain?(x, y)
144
147
  # assume a rectangular filled shape by default (works for several shapes like image, text, and focus)
145
148
  if respond_to?(:x) && respond_to?(:y) && respond_to?(:width) && respond_to?(:height) && self.x && self.y && width && height
146
- x.between?(self.x, self.x + width) && y.between?(self.y, self.y + height)
149
+ x.between?(self.absolute_x, self.absolute_x + width) && y.between?(self.absolute_y, self.absolute_y + height)
147
150
  else
148
151
  false # subclasses must provide implementation
149
152
  end
@@ -163,9 +166,17 @@ module Glimmer
163
166
  # moves by x delta and y delta. Subclasses must implement
164
167
  # provdies a default implementation that assumes moving x and y is sufficient by default (not for polygons though, which must override)
165
168
  def move_by(x_delta, y_delta)
166
- if respond_to?(:x) && respond_to?(:y) && x && y
167
- self.x += x_delta
168
- self.y += y_delta
169
+ if respond_to?(:x) && respond_to?(:y) && respond_to?(:x=) && respond_to?(:y=)
170
+ if default_x?
171
+ self.x_delta += x_delta
172
+ else
173
+ self.x += x_delta
174
+ end
175
+ if default_y?
176
+ self.y_delta += y_delta
177
+ else
178
+ self.y += y_delta
179
+ end
169
180
  end
170
181
  end
171
182
 
@@ -276,11 +287,11 @@ module Glimmer
276
287
  end
277
288
  if @name.include?('image')
278
289
  @drawable.requires_shape_disposal = true
279
- if @args.size == 1
280
- @args[1] = 0
281
- @args[2] = 0
282
- end
283
290
  end
291
+ self.x = :default if current_parameter_name?(:x) && x.nil?
292
+ self.y = :default if current_parameter_name?(:y) && y.nil?
293
+ self.dest_x = :default if current_parameter_name?(:dest_x) && dest_x.nil?
294
+ self.dest_y = :default if current_parameter_name?(:dest_y) && dest_y.nil?
284
295
  end
285
296
 
286
297
  # Tolerates shape extra args added by user by mistake
@@ -315,6 +326,12 @@ module Glimmer
315
326
  []
316
327
  end
317
328
 
329
+ # subclasses may override to specify location parameter names if different from x and y (e.g. all polygon points are location parameters)
330
+ # used in calculating movement changes
331
+ def location_parameter_names
332
+ [:x, :y]
333
+ end
334
+
318
335
  def possible_parameter_names
319
336
  parameter_names
320
337
  end
@@ -323,6 +340,10 @@ module Glimmer
323
340
  possible_parameter_names.map(&:to_s).include?(ruby_attribute_getter(attribute_name))
324
341
  end
325
342
 
343
+ def current_parameter_name?(attribute_name)
344
+ parameter_names.map(&:to_s).include?(ruby_attribute_getter(attribute_name))
345
+ end
346
+
326
347
  def parameter_index(attribute_name)
327
348
  parameter_names.map(&:to_s).index(attribute_name.to_s)
328
349
  end
@@ -333,18 +354,29 @@ module Glimmer
333
354
 
334
355
  def has_attribute?(attribute_name, *args)
335
356
  self.class.gc_instance_methods.include?(attribute_setter(attribute_name)) or
336
- parameter_name?(attribute_name)
357
+ parameter_name?(attribute_name) or
358
+ (respond_to?(attribute_name, super: true) and respond_to?(ruby_attribute_setter(attribute_name), super: true))
337
359
  end
338
360
 
339
361
  def set_attribute(attribute_name, *args)
362
+ options = args.last if args.last.is_a?(Hash)
363
+ perform_redraw = @perform_redraw
364
+ perform_redraw = options[:redraw] if perform_redraw.nil? && !options.nil?
365
+ perform_redraw = true if perform_redraw.nil?
340
366
  if parameter_name?(attribute_name)
341
367
  set_parameter_attribute(attribute_name, *args)
368
+ elsif (respond_to?(attribute_name, super: true) and respond_to?(ruby_attribute_setter(attribute_name), super: true))
369
+ self.send(ruby_attribute_setter(attribute_name), *args)
342
370
  else
343
371
  @properties[ruby_attribute_getter(attribute_name)] = args
344
372
  end
345
- if @content_added && !@drawable.is_disposed
373
+ if @content_added && perform_redraw && !drawable.is_disposed
346
374
  @calculated_paint_args = false
347
- @drawable.redraw
375
+ attribute_name = ruby_attribute_getter(attribute_name)
376
+ @calculated_absolute_args = false if (location_parameter_names.map(&:to_s) + ['x_delta', 'y_delta']).include?(attribute_name)
377
+
378
+ # TODO consider redrawing an image proxy's gc in the future
379
+ drawable.redraw unless drawable.is_a?(ImageProxy)
348
380
  end
349
381
  end
350
382
 
@@ -352,6 +384,8 @@ module Glimmer
352
384
  if parameter_name?(attribute_name)
353
385
  arg_index = parameter_index(attribute_name)
354
386
  @args[arg_index] if arg_index
387
+ elsif (respond_to?(attribute_name, super: true) and respond_to?(ruby_attribute_setter(attribute_name), super: true))
388
+ self.send(attribute_name)
355
389
  else
356
390
  @properties.symbolize_keys[attribute_name.to_s.to_sym]
357
391
  end
@@ -368,7 +402,9 @@ module Glimmer
368
402
  end
369
403
 
370
404
  def respond_to?(method_name, *args, &block)
371
- if has_attribute?(method_name)
405
+ options = args.last if args.last.is_a?(Hash)
406
+ super_invocation = options && options[:super]
407
+ if !super_invocation && has_attribute?(method_name)
372
408
  true
373
409
  else
374
410
  super
@@ -421,12 +457,116 @@ module Glimmer
421
457
  end
422
458
  end
423
459
  self.extent = paint_event.gc.send("#{@name}Extent", *(([string, flags] if respond_to?(:flags)).compact)) if ['text', 'string'].include?(@name)
424
- paint_event.gc.send(@method_name, *@args)
460
+ if !@calculated_absolute_args || parent_shape_absolute_location_changed?
461
+ @absolute_args = absolute_args
462
+ @calculated_absolute_args = true
463
+ end
464
+ paint_event.gc.send(@method_name, *@absolute_args)
465
+ paint_children(paint_event)
425
466
  rescue => e
426
467
  Glimmer::Config.logger.error {"Error encountered in painting shape: #{self.inspect}"}
427
468
  Glimmer::Config.logger.error {e.full_message}
428
469
  end
429
470
 
471
+ def paint_children(paint_event)
472
+ shapes.to_a.each do |shape|
473
+ shape.paint(paint_event)
474
+ end
475
+ end
476
+
477
+ def expanded_shapes
478
+ if shapes.to_a.any?
479
+ shapes.map do |shape|
480
+ [shape] + shape.expanded_shapes
481
+ end.flatten
482
+ else
483
+ []
484
+ end
485
+ end
486
+
487
+ def parent_shape_absolute_location_changed?
488
+ (parent.is_a?(Shape) && (parent.absolute_x != @parent_absolute_x || parent.absolute_y != @parent_absolute_y))
489
+ end
490
+
491
+ # args translated to absolute coordinates
492
+ def absolute_args
493
+ return @args if !default_x? && !default_y? && @x_delta == 0 && @y_delta == 0 && parent.is_a?(Drawable)
494
+ @perform_redraw = false
495
+ original_x = nil
496
+ original_y = nil
497
+ if default_x?
498
+ original_x = x
499
+ self.x = default_x
500
+ end
501
+ if default_y?
502
+ original_y = y
503
+ self.y = default_y
504
+ end
505
+ move_by(@x_delta, @y_delta)
506
+ if parent.is_a?(Shape)
507
+ @parent_absolute_x = parent.absolute_x
508
+ @parent_absolute_y = parent.absolute_y
509
+ move_by(parent.absolute_x, parent.absolute_y)
510
+ calculated_absolute_args = @args.clone
511
+ move_by(-1*parent.absolute_x, -1*parent.absolute_y)
512
+ else
513
+ calculated_absolute_args = @args.clone
514
+ end
515
+ move_by(-1*@x_delta, -1*@y_delta)
516
+ if original_x
517
+ self.x = original_x
518
+ end
519
+ if original_y
520
+ self.y = original_y
521
+ end
522
+ @perform_redraw = true
523
+ calculated_absolute_args
524
+ end
525
+
526
+ def default_x?
527
+ current_parameter_name?('x') && (x.nil? || x.to_s == 'default')
528
+ end
529
+
530
+ def default_y?
531
+ current_parameter_name?('y') && (y.nil? || y.to_s == 'default')
532
+ end
533
+
534
+ def default_x
535
+ if respond_to?(:width) && width && parent.respond_to?(:width) && parent.width
536
+ (parent.width - width) / 2
537
+ else
538
+ 0
539
+ end
540
+ end
541
+
542
+ def default_y
543
+ if respond_to?(:height) && height && parent.respond_to?(:height) && parent.height
544
+ (parent.height - height) / 2
545
+ else
546
+ 0
547
+ end
548
+ end
549
+
550
+ def absolute_x
551
+ x = default_x? ? default_x : self.x
552
+ x += @x_delta
553
+ if parent.is_a?(Shape)
554
+ parent.absolute_x + x
555
+ else
556
+ x
557
+ end
558
+ end
559
+
560
+ def absolute_y
561
+ y = default_y? ? default_y : self.y
562
+ y += @y_delta
563
+ if parent.is_a?(Shape)
564
+ parent.absolute_y + y
565
+ else
566
+ y
567
+ end
568
+ end
569
+
430
570
  def calculate_paint_args!
431
571
  unless @calculated_paint_args
432
572
  if @name == 'pixel'
@@ -39,7 +39,7 @@ module Glimmer
39
39
 
40
40
  # checks if shape contains the point denoted by x and y
41
41
  def contain?(x, y)
42
- shape_geometry = java.awt.geom.Arc2D::Double.new(self.x, self.y, width, height, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
42
+ shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, width, height, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
43
43
  shape_geometry.contains(x, y)
44
44
  end
45
45
 
@@ -48,8 +48,8 @@ module Glimmer
48
48
  contain?(x, y)
49
49
  else
50
50
  # give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
51
- outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.x, self.y, width + 3, height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
52
- inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.x, self.y, width - 3, height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
51
+ outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, width + 3, height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
52
+ inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, width - 3, height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
53
53
  outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
54
54
  end
55
55
  end
@@ -78,17 +78,30 @@ module Glimmer
78
78
  dest_height || image.bounds.height
79
79
  end
80
80
 
81
- def include?(x, y)
82
- x.between?(self.x, self.x + width) && y.between?(self.y, self.y + height)
81
+ def default_x?
82
+ super ||
83
+ current_parameter_name?('dest_x') && (dest_x.nil? || dest_x.to_s == 'default')
83
84
  end
84
- alias contain? include?
85
-
85
+
86
+ def default_y?
87
+ super ||
88
+ current_parameter_name?('dest_y') && (dest_y.nil? || dest_y.to_s == 'default')
89
+ end
90
+
86
91
  def move_by(x_delta, y_delta)
87
- if dest_x
92
+ if default_x?
93
+ self.x_delta += x_delta
94
+ elsif dest_x
88
95
  self.dest_x += x_delta
89
- self.dest_y += y_delta
90
96
  else
91
97
  self.x += x_delta
98
+ end
99
+
100
+ if default_y?
101
+ self.y_delta += y_delta
102
+ elsif dest_y
103
+ self.dest_y += y_delta
104
+ else
92
105
  self.y += y_delta
93
106
  end
94
107
  end