Class: Glimmer::SWT::Custom::Shape

Inherits:
Object
  • Object
show all
Includes:
Properties
Defined in:
lib/glimmer/swt/custom/shape/arc.rb,
lib/glimmer/swt/custom/shape/line.rb,
lib/glimmer/swt/custom/shape/oval.rb,
lib/glimmer/swt/custom/shape/path.rb,
lib/glimmer/swt/custom/shape/quad.rb,
lib/glimmer/swt/custom/shape/text.rb,
lib/glimmer/swt/custom/shape/cubic.rb,
lib/glimmer/swt/custom/shape/focus.rb,
lib/glimmer/swt/custom/shape/image.rb,
lib/glimmer/swt/custom/shape/point.rb,
lib/glimmer/swt/custom/shape/polygon.rb,
lib/glimmer/swt/custom/shape/polyline.rb,
lib/glimmer/swt/custom/shape/rectangle.rb,
lib/glimmer/swt/custom/shape/path_segment.rb,
lib/glimmer/swt/custom/shape.rb

Overview

Represents a shape (graphics) to be drawn on a control/widget/canvas/display That is because Shape is drawn on a parent as graphics and doesn’t have an SWT widget for itself

Direct Known Subclasses

Arc, Focus, Image, Line, Oval, Path, Point, Polygon, Polyline, Rectangle, Text

Defined Under Namespace

Modules: PathSegment Classes: Arc, Cubic, DropEvent, Focus, Image, Line, Oval, Path, Point, Polygon, Polyline, Quad, Rectangle, Text

Constant Summary collapse

String =
Text

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties

attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter

Constructor Details

#initialize(parent, keyword, *args, &property_block) ⇒ Shape

TODO consider making shapes return a dup, always, in case consumers want to dispose



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/glimmer/swt/custom/shape.rb', line 144

def initialize(parent, keyword, *args, &property_block)
  @parent = parent
  @drawable = @parent.is_a?(Drawable) ? @parent : @parent.drawable
  @name = keyword
  @options = self.class.arg_options(args, extract: true)
  @method_name = self.class.method_name(keyword, @options) unless keyword.to_s == 'shape'
  @args = args
  @properties = {}
  @shapes = [] # nested shapes
  @options.reject {|key, value| %w[fill gradient round].include?(key.to_s)}.each do |property, property_args|
    @properties[property] = property_args
  end
  @parent.add_shape(self)
  post_add_content if property_block.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



739
740
741
742
743
744
745
746
747
748
749
# File 'lib/glimmer/swt/custom/shape.rb', line 739

def method_missing(method_name, *args, &block)
  if method_name.to_s.end_with?('=')
    set_attribute(method_name, *args)
  elsif has_attribute?(method_name)
    get_attribute(method_name)
  elsif block && can_handle_observation_request?(method_name)
    handle_observation_request(method_name, &block)
  else
    super
  end
end

Class Attribute Details

.dragged_shapeObject

Returns the value of attribute dragged_shape.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def dragged_shape
  @dragged_shape
end

.dragged_shape_original_xObject

Returns the value of attribute dragged_shape_original_x.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def dragged_shape_original_x
  @dragged_shape_original_x
end

.dragged_shape_original_yObject

Returns the value of attribute dragged_shape_original_y.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def dragged_shape_original_y
  @dragged_shape_original_y
end

.draggingObject Also known as: dragging?

Returns the value of attribute dragging.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def dragging
  @dragging
end

.dragging_xObject

Returns the value of attribute dragging_x.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def dragging_x
  @dragging_x
end

.dragging_yObject

Returns the value of attribute dragging_y.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def dragging_y
  @dragging_y
end

.drop_shape_handling_countObject

Returns the value of attribute drop_shape_handling_count.



69
70
71
# File 'lib/glimmer/swt/custom/shape.rb', line 69

def drop_shape_handling_count
  @drop_shape_handling_count
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def args
  @args
end

#disposedObject (readonly) Also known as: disposed?, is_disposed

Returns the value of attribute disposed.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def disposed
  @disposed
end

#drawableObject (readonly)

Returns the value of attribute drawable.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def drawable
  @drawable
end

#extentObject

Returns the value of attribute extent.



139
140
141
# File 'lib/glimmer/swt/custom/shape.rb', line 139

def extent
  @extent
end

#nameObject (readonly)

Returns the value of attribute name.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def parent
  @parent
end

#propertiesObject (readonly)

Returns the value of attribute properties.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def properties
  @properties
end

#shapesObject (readonly)

Returns the value of attribute shapes.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def shapes
  @shapes
end

#widget_listener_proxiesObject (readonly)

Returns the value of attribute widget_listener_proxies.



138
139
140
# File 'lib/glimmer/swt/custom/shape.rb', line 138

def widget_listener_proxies
  @widget_listener_proxies
end

Class Method Details

.arg_options(args, extract: false) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/glimmer/swt/custom/shape.rb', line 101

def arg_options(args, extract: false)
  arg_options_method = extract ? :pop : :last
  options = args.send(arg_options_method).symbolize_keys if args.last.is_a?(Hash)
  # normalize :filled option as an alias to :fill
#             options[:fill] = options.delete(:filled) if options&.keys&.include?(:filled)
  options.nil? ? {} : options
end

.create(parent, keyword, *args, &property_block) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/glimmer/swt/custom/shape.rb', line 72

def create(parent, keyword, *args, &property_block)
  potential_shape_class_name = keyword.to_s.camelcase(:upper).to_sym
  if constants.include?(potential_shape_class_name)
    const_get(potential_shape_class_name).new(parent, keyword, *args, &property_block)
  else
    new(parent, keyword, *args, &property_block)
  end
end

.flyweight_method_namesObject



121
122
123
# File 'lib/glimmer/swt/custom/shape.rb', line 121

def flyweight_method_names
  @flyweight_method_names ||= {}
end

.flyweight_patternsObject



133
134
135
# File 'lib/glimmer/swt/custom/shape.rb', line 133

def flyweight_patterns
  @flyweight_patterns ||= {}
end

.gc_instance_methodsObject



87
88
89
# File 'lib/glimmer/swt/custom/shape.rb', line 87

def gc_instance_methods
  @gc_instance_methods ||= org.eclipse.swt.graphics.GC.instance_methods.map(&:to_s)
end

.keywordsObject



91
92
93
94
95
96
97
98
99
# File 'lib/glimmer/swt/custom/shape.rb', line 91

def keywords
  @keywords ||= gc_instance_methods.select do |method_name|
    !method_name.end_with?('=') && (method_name.start_with?('draw_') || method_name.start_with?('fill_'))
  end.reject do |method_name|
    gc_instance_methods.include?("#{method_name}=") || gc_instance_methods.include?("set_#{method_name}")
  end.map do |method_name|
    method_name.gsub(/(draw|fill|gradient|round)_/, '')
  end.uniq.compact.to_a
end

.method_name(keyword, method_arg_options) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/glimmer/swt/custom/shape.rb', line 109

def method_name(keyword, method_arg_options)
  keyword = keyword.to_s
  method_arg_options = method_arg_options.select {|key, value| %w[fill gradient round].include?(key.to_s)}
  unless flyweight_method_names.keys.include?([keyword, method_arg_options])
    gradient = 'Gradient' if method_arg_options[:gradient]
    round = 'Round' if method_arg_options[:round]
    gc_instance_method_name_prefix = !['polyline', 'point', 'image', 'focus'].include?(keyword) && (method_arg_options[:fill] || method_arg_options[:gradient]) ? 'fill' : 'draw'
    flyweight_method_names[[keyword, method_arg_options]] = "#{gc_instance_method_name_prefix}#{gradient}#{round}#{keyword.capitalize}"
  end
  flyweight_method_names[[keyword, method_arg_options]]
end

.pattern(*args) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/glimmer/swt/custom/shape.rb', line 125

def pattern(*args)
  found_pattern = flyweight_patterns[args]
  if found_pattern.nil? || found_pattern.is_disposed
    found_pattern = flyweight_patterns[args] = org.eclipse.swt.graphics.Pattern.new(*args)
  end
  found_pattern
end

.valid?(parent, keyword, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
# File 'lib/glimmer/swt/custom/shape.rb', line 81

def valid?(parent, keyword, *args, &block)
  return true if keyword.to_s == 'shape'
  gc_instance_methods.include?(method_name(keyword, arg_options(args))) ||
    constants.include?(keyword.to_s.camelcase(:upper).to_sym)
end

Instance Method Details

#absolute_xObject



1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
# File 'lib/glimmer/swt/custom/shape.rb', line 1393

def absolute_x
  absolute_x_dependencies = [calculated_x, parent.is_a?(Shape) && parent.absolute_x]
  if absolute_x_dependencies != @absolute_x_dependencies
    # do not repeat calculations
    calculated_x, parent_absolute_x = @absolute_x_dependencies = absolute_x_dependencies
    x = calculated_x
    @absolute_x = if parent.is_a?(Shape)
      parent_absolute_x + x
    else
      x
    end
  end
  @absolute_x
end

#absolute_yObject



1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
# File 'lib/glimmer/swt/custom/shape.rb', line 1408

def absolute_y
  absolute_y_dependencies = [calculated_y, parent.is_a?(Shape) && parent.absolute_y]
  if absolute_y_dependencies != @absolute_y_dependencies
    calculated_y, parent_absolute_y = @absolute_y_dependencies = absolute_y_dependencies
    y = calculated_y
    @absolute_y = if parent.is_a?(Shape)
      parent_absolute_y + y
    else
      y
    end
  end
  @absolute_y
end

#add_shape(shape) ⇒ Object



160
161
162
163
# File 'lib/glimmer/swt/custom/shape.rb', line 160

def add_shape(shape)
  @shapes << shape
  calculated_args_changed_for_defaults!
end

#all_parent_propertiesObject



970
971
972
973
974
# File 'lib/glimmer/swt/custom/shape.rb', line 970

def all_parent_properties
  @all_parent_properties ||= parent_shape_containers.reverse.reduce({}) do |all_properties, parent_shape|
    all_properties.merge(parent_shape.converted_properties)
  end
end

#amend_method_name_options_based_on_properties!Object



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/glimmer/swt/custom/shape.rb', line 511

def amend_method_name_options_based_on_properties!
  @original_method_name = @method_name
  return if @name == 'point'
  if (@name != 'text' && @name != 'string' && has_some_background? && !has_some_foreground?) || (@name == 'path' && has_some_background?)
    @options[:fill] = true
  elsif !has_some_background? && has_some_foreground?
    @options[:fill] = false
  elsif @name == 'rectangle' && has_some_background? && has_some_foreground?
    @options[:fill] = true
    @options[:gradient] = true
  end
  if @name == 'rectangle' && @args.size > 4 && @args.last.is_a?(Numeric)
    @options[:round] = true
  end
  @method_name = self.class.method_name(@name, @options)
end

#any_potential_drop_targets?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


834
835
836
# File 'lib/glimmer/swt/custom/shape.rb', line 834

def any_potential_drop_targets?(x, y)
  drawable.drop_shapes.any? { |shape| shape.include_with_children?(x, y, except_shape: Shape.dragged_shape) }
end

#apply_property_arg_conversions(property, args) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/glimmer/swt/custom/shape.rb', line 366

def apply_property_arg_conversions(property, args)
  method_name = attribute_setter(property)
  args = args.dup
  the_java_method = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.detect {|m| m.name == method_name}
  return args if the_java_method.nil?
  if the_java_method.parameter_types.first == org.eclipse.swt.graphics.Color.java_class && args.first.is_a?(org.eclipse.swt.graphics.RGB)
    args[0] = [args[0].red, args[0].green, args[0].blue]
  end
  if ['setBackground', 'setForeground'].include?(method_name.to_s) && args.first.is_a?(Array)
    args[0] = ColorProxy.new(args[0])
  end
  if method_name.to_s == 'setLineDash' && args.size > 1
    args[0] = args.dup
    args[1..-1] = []
  end
  if method_name.to_s == 'setAntialias' && [nil, true, false].include?(args.first)
    args[0] = case args.first
    when true
      args[0] = :on
    when false
      args[0] = :off
    when nil
      args[0] = :default
    end
  end
  if args.first.is_a?(Symbol) || args.first.is_a?(::String)
    if the_java_method.parameter_types.first == org.eclipse.swt.graphics.Color.java_class
      args[0] = ColorProxy.new(args[0])
    end
    if method_name.to_s == 'setLineStyle'
      args[0] = "line_#{args[0]}" if !args[0].to_s.downcase.start_with?('line_')
    end
    if method_name.to_s == 'setFillRule'
      args[0] = "fill_#{args[0]}" if !args[0].to_s.downcase.start_with?('fill_')
    end
    if method_name.to_s == 'setLineCap'
      args[0] = "cap_#{args[0]}" if !args[0].to_s.downcase.start_with?('cap_')
    end
    if method_name.to_s == 'setLineJoin'
      args[0] = "join_#{args[0]}" if !args[0].to_s.downcase.start_with?('join_')
    end
    if the_java_method.parameter_types.first == Java::int.java_class
      args[0] = SWTProxy.constant(args[0])
    end
  end
  if args.first.is_a?(ColorProxy)
    args[0] = args[0].swt_color
  end
  if (args.first.is_a?(Hash) || args.first.is_a?(org.eclipse.swt.graphics.FontData)) && the_java_method.parameter_types.first == org.eclipse.swt.graphics.Font.java_class
    args[0] = FontProxy.new(args[0])
  end
  if args.first.is_a?(FontProxy)
    args[0] = args[0].swt_font
  end
  if args.first.is_a?(TransformProxy)
    args[0] = args[0].swt_transform
  end
  if ['setBackgroundPattern', 'setForegroundPattern'].include?(method_name.to_s)
    @drawable.requires_shape_disposal = true
    args = args.first if args.first.is_a?(Array)
    args.each_with_index do |arg, i|
      arg = ColorProxy.new(arg.red, arg.green, arg.blue) if arg.is_a?(org.eclipse.swt.graphics.RGB)
      arg = ColorProxy.new(arg) if arg.is_a?(Symbol) || arg.is_a?(::String)
      arg = arg.swt_color if arg.is_a?(ColorProxy)
      args[i] = arg
    end
    @pattern_args ||= {}
    pattern_type = method_name.to_s.match(/set(.+)Pattern/)[1]
    if args.first.is_a?(org.eclipse.swt.graphics.Pattern)
      new_args = @pattern_args[pattern_type]
    else
      new_args = args.first.is_a?(org.eclipse.swt.widgets.Display) ? args : ([DisplayProxy.instance.swt_display] + args)
      @pattern_args[pattern_type] = new_args.dup
    end
    args[0] = pattern(*new_args, type: pattern_type)
    args[1..-1] = []
  end
  args
end

#apply_shape_arg_conversions!Object



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/glimmer/swt/custom/shape.rb', line 446

def apply_shape_arg_conversions!
  if @args.size > 1 && (['polygon', 'polyline'].include?(@name))
    @args[0] = @args.dup
    @args[1..-1] = []
  end
  if @name == 'image'
    if @args.first.is_a?(::String)
      @args[0] = ImageProxy.create(@args[0])
    end
    if @args.first.is_a?(ImageProxy)
      @image = @args[0] = @args[0].swt_image
    end
    if @args.first.nil?
      @image = nil
    end
  end
  if @name == 'text'
    if @args[3].is_a?(Symbol) || @args[3].is_a?(::String)
      @args[3] = [@args[3]]
    end
    if @args[3].is_a?(Array)
      if @args[3].size == 1 && @args[3].first.is_a?(Array)
        @args[3] = @args[3].first
      end
      @args[3] = SWTProxy[*@args[3]]
    end
  end
end

#apply_shape_arg_defaults!Object



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/glimmer/swt/custom/shape.rb', line 475

def apply_shape_arg_defaults!
  if current_parameter_name?(:dest_x) && dest_x.nil?
    self.dest_x = :default
  elsif parameter_name?(:x) && x.nil?
    self.x = :default
  end
  if current_parameter_name?(:dest_y) && dest_y.nil?
    self.dest_y = :default
  elsif parameter_name?(:y) && y.nil?
    self.y = :default
  end
  self.width = :default if current_parameter_name?(:width) && width.nil?
  self.height = :default if current_parameter_name?(:height) && height.nil?
  if @name.include?('rectangle') && round? && @args.size.between?(4, 5)
    (6 - @args.size).times {@args << 60}
  elsif @name.include?('rectangle') && gradient? && @args.size == 4
    set_attribute('vertical', true, redraw: false)
  elsif (@name.include?('text') || @name.include?('string')) && !@properties.keys.map(&:to_s).include?('background') && @args.size < 4
    set_attribute('is_transparent', true, redraw: false)
  end
  if @name.include?('image')
    @drawable.requires_shape_disposal = true
  end
end

#background_pattern_argsObject



860
861
862
# File 'lib/glimmer/swt/custom/shape.rb', line 860

def background_pattern_args
  pattern_args(type: 'background')
end

#boundsObject

The bounding box top-left x, y, width, height in absolute positioning



184
185
186
187
188
189
190
191
192
# File 'lib/glimmer/swt/custom/shape.rb', line 184

def bounds
  bounds_dependencies = [absolute_x, absolute_y, calculated_width, calculated_height]
  if bounds_dependencies != @bounds_dependencies
    # avoid repeating calculations
    absolute_x, absolute_y, calculated_width, calculated_height = @bounds_dependencies = bounds_dependencies
    @bounds = org.eclipse.swt.graphics.Rectangle.new(absolute_x, absolute_y, calculated_width, calculated_height)
  end
  @bounds
end

#bounds_contain?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


237
238
239
240
# File 'lib/glimmer/swt/custom/shape.rb', line 237

def bounds_contain?(x, y)
  x, y = inverse_transform_point(x, y)
  bounds.contains(x, y)
end

#calculate_args!Object

args translated to absolute coordinates



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
# File 'lib/glimmer/swt/custom/shape.rb', line 1084

def calculate_args!
  return @args if parent.is_a?(Drawable) && !default_x? && !default_y? && !default_width? && !default_height? && !max_width? && !max_height?
  calculated_args_dependencies = [
    x,
    y,
    parent.is_a?(Shape) && parent.absolute_x,
    parent.is_a?(Shape) && parent.absolute_y,
    default_width? && default_width,
    default_width? && width_delta,
    default_height? && default_height,
    default_height? && height_delta,
    max_width? && max_width,
    max_width? && width_delta,
    max_height? && max_height,
    max_height? && height_delta,
    default_x? && default_x,
    default_x? && x_delta,
    default_y? && default_y,
    default_y? && y_delta,
  ]
  if calculated_args_dependencies != @calculated_args_dependencies
    # avoid recalculating values again
    x, y, parent_absolute_x, parent_absolute_y, default_width, default_width_delta, default_height, default_height_delta, max_width, max_width_delta, max_height, max_height_delta, default_x, default_x_delta, default_y, default_y_delta = @calculated_args_dependencies = calculated_args_dependencies
    # Note: Must set x and move_by because not all shapes have a real x and some must translate all their points with move_by
    # TODO change that by setting a bounding box for all shapes with a calculated top-left x, y and
    # a setter that does the moving inside them instead so that I could rely on absolute_x and absolute_y
    # here to get the job done of calculating absolute args
    @perform_redraw = false
    original_x = nil
    original_y = nil
    original_width = nil
    original_height = nil
    if parent.is_a?(Shape)
      @parent_absolute_x = parent_absolute_x
      @parent_absolute_y = parent_absolute_y
    end
    if default_width?
      original_width = width
      self.width = default_width + default_width_delta
    end
    if default_height?
      original_height = height
      self.height = default_height + default_height_delta
    end
    if max_width?
      original_width = width
      self.width = max_width + max_width_delta
    end
    if max_height?
      original_height = height
      self.height = max_height + max_height_delta
    end
    if default_x?
      original_x = x
      self.x = default_x + default_x_delta
    end
    if default_y?
      original_y = y
      self.y = default_y + default_y_delta
    end
    if parent.is_a?(Shape)
      move_by(@parent_absolute_x, @parent_absolute_y)
      @result_calculated_args = @args.clone
      move_by(-1*@parent_absolute_x, -1*@parent_absolute_y)
    else
      @result_calculated_args = @args.clone
    end
    if original_x
      self.x = original_x
    end
    if original_y
      self.y = original_y
    end
    if original_width
      self.width = original_width
    end
    if original_height
      self.height = original_height
    end
    @perform_redraw = true
  end
  @result_calculated_args
end

#calculate_paint_args!Object



1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
# File 'lib/glimmer/swt/custom/shape.rb', line 1437

def calculate_paint_args!
  unless @calculated_paint_args
    if @name == 'pixel'
      @name = 'point'
      # optimized performance calculation for pixel points
      if !@properties[:foreground].is_a?(org.eclipse.swt.graphics.Color)
        if @properties[:foreground].is_a?(Array)
          @properties[:foreground] = ColorProxy.new(@properties[:foreground], ensure_bounds: false)
        end
        if @properties[:foreground].is_a?(Symbol) || @properties[:foreground].is_a?(::String)
         @properties[:foreground] = ColorProxy.new(@properties[:foreground], ensure_bounds: false)
        end
        if @properties[:foreground].is_a?(ColorProxy)
          @properties[:foreground] = @properties[:foreground].swt_color
        end
      end
    else
      @original_properties ||= @properties
      @properties = all_parent_properties.merge(@original_properties)
      @properties['background'] = [@drawable.background] if fill? && !has_some_background?
      @properties['foreground'] = [@drawable.foreground] if @drawable.respond_to?(:foreground) && draw? && !has_some_foreground?
      # TODO regarding alpha, make sure to reset it to parent stored alpha once we allow setting shape properties on parents directly without shapes
      @properties['font'] = [@drawable.font] if @drawable.respond_to?(:font) && @name == 'text' && draw? && !@properties.keys.map(&:to_s).include?('font')
      # TODO regarding transform, make sure to reset it to parent stored transform once we allow setting shape properties on parents directly without shapes
      # Also do that with all future-added properties
      convert_properties!
      apply_shape_arg_conversions!
      apply_shape_arg_defaults!
      tolerate_shape_extra_args!
      @calculated_paint_args = true
    end
  end
end

#calculated_args?Boolean

Returns:

  • (Boolean)


1079
1080
1081
# File 'lib/glimmer/swt/custom/shape.rb', line 1079

def calculated_args?
  !!@calculated_args
end

#calculated_args_changed!(children: true) ⇒ Object



1051
1052
1053
1054
# File 'lib/glimmer/swt/custom/shape.rb', line 1051

def calculated_args_changed!(children: true)
  @calculated_args = nil
  shapes.each(&:calculated_args_changed!) if children
end

#calculated_args_changed_for_defaults!Object

Notifies object that calculated args changed for defaults. Returns true if redrawing and false otherwise.



1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/glimmer/swt/custom/shape.rb', line 1063

def calculated_args_changed_for_defaults!
  has_default_dimensions = default_width? || default_height?
  parent_calculated_args_changed_for_defaults = has_default_dimensions
  calculated_args_changed!(children: false) if default_x? || default_y? || has_default_dimensions
  if has_default_dimensions && parent.is_a?(Shape)
    parent.calculated_args_changed_for_defaults!
  elsif @content_added && !drawable.is_disposed
    # TODO consider optimizing in the future if needed by ensuring one redraw for all parents in the hierarchy at the end instead of doing one per parent that needs it
    if !@painting && !drawable.is_a?(ImageProxy)
      drawable.redraw
      return true
    end
  end
  false
end

#calculated_heightObject



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'lib/glimmer/swt/custom/shape.rb', line 1315

def calculated_height
  calculated_height_dependencies = [height, default_height? && (default_height + height_delta), max_height? && (max_height + height_delta)]
  if calculated_height_dependencies != @calculated_height_dependencies
    @calculated_height_dependencies = calculated_height_dependencies
    result_height = height
    result_height = (default_height + height_delta) if default_height?
    result_height = (max_height + height_delta) if max_height?
    @calculated_height = result_height
  end
  @calculated_height
end

#calculated_paint_args_changed!(children: true) ⇒ Object



1056
1057
1058
1059
1060
# File 'lib/glimmer/swt/custom/shape.rb', line 1056

def calculated_paint_args_changed!(children: true)
  @calculated_paint_args = nil
  @all_parent_properties = nil
  shapes.each(&:calculated_paint_args_changed!) if children
end

#calculated_widthObject



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
# File 'lib/glimmer/swt/custom/shape.rb', line 1303

def calculated_width
  calculated_width_dependencies = [width, default_width? && (default_width + width_delta), max_width? && (max_width + width_delta)]
  if calculated_width_dependencies != @calculated_width_dependencies
    @calculated_width_dependencies = calculated_width_dependencies
    result_width = width
    result_width = (default_width + width_delta) if default_width?
    result_width = (max_width + width_delta) if max_width?
    @calculated_width = result_width
  end
  @calculated_width
end

#calculated_xObject



1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
# File 'lib/glimmer/swt/custom/shape.rb', line 1371

def calculated_x
  calculated_x_dependencies = [default_x? && default_x, !default_x? && self.x, self.x_delta]
  if calculated_x_dependencies != @calculated_x_dependencies
    default_x, x, x_delta = @calculated_x_dependencies = calculated_x_dependencies
    result = default_x? ? default_x : x
    result += x_delta
    @calculated_x = result
  end
  @calculated_x
end

#calculated_yObject



1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
# File 'lib/glimmer/swt/custom/shape.rb', line 1382

def calculated_y
  calculated_y_dependencies = [default_y? && default_y, !default_y? && self.y, self.y_delta]
  if calculated_y_dependencies != @calculated_y_dependencies
    default_y, y, y_delta = @calculated_y_dependencies = calculated_y_dependencies
    result = default_y? ? default_y : y
    result += y_delta
    @calculated_y = result
  end
  @calculated_y
end

#can_handle_observation_request?(observation_request) ⇒ Boolean

Returns:

  • (Boolean)


629
630
631
632
633
634
635
636
637
638
639
# File 'lib/glimmer/swt/custom/shape.rb', line 629

def can_handle_observation_request?(observation_request)
  observation_request = observation_request.to_s
  observation_request.start_with?('on_') &&
  (
    observation_request == 'on_shape_disposed' ||
    (
      drawable.respond_to?(:can_handle_observation_request?) &&
      drawable.can_handle_observation_request?(observation_request)
    )
  )
end

#cancel_dragging!Object



838
839
840
841
842
843
844
845
# File 'lib/glimmer/swt/custom/shape.rb', line 838

def cancel_dragging!
  Shape.dragging = false
  if Shape.dragged_shape
    Shape.dragged_shape.x = Shape.dragged_shape_original_x
    Shape.dragged_shape.y = Shape.dragged_shape_original_y
    Shape.dragged_shape = nil
  end
end

#center_xObject



322
323
324
325
326
327
328
329
330
# File 'lib/glimmer/swt/custom/shape.rb', line 322

def center_x
  center_x_dependencies = [x_end, calculated_width]
  if center_x_dependencies != @center_x_dependencies
    @center_x_dependencies = center_x_dependencies
    the_x_end, the_calculated_width = center_x_dependencies
    @center_x = the_x_end - the_calculated_width/2.0
  end
  @center_x
end

#center_yObject



332
333
334
335
336
337
338
339
340
# File 'lib/glimmer/swt/custom/shape.rb', line 332

def center_y
  center_y_dependencies = [y_end, calculated_height]
  if center_y_dependencies != @center_y_dependencies
    @center_y_dependencies = center_y_dependencies
    the_y_end, the_calculated_height = center_y_dependencies
    @center_y = the_y_end - the_calculated_height/2.0
  end
  @center_y
end

#clear_shapes(dispose_images: true, dispose_patterns: true, redraw: :all) ⇒ Object Also known as: dispose_shapes

clear all shapes indicate whether to dispose images, dispose patterns, and redraw after clearing shapes. redraw can be ‘:all` or `true` to mean redraw after all shapes are disposed, `:each` to mean redraw after each shape is disposed, or `false` to avoid redraw altogether



894
895
896
897
898
899
900
901
902
903
# File 'lib/glimmer/swt/custom/shape.rb', line 894

def clear_shapes(dispose_images: true, dispose_patterns: true, redraw: :all)
  if redraw == true || redraw == :all
    shapes.dup.each {|shape| shape.dispose(dispose_images: dispose_images, dispose_patterns: dispose_patterns, redraw: false) }
    drawable.redraw if redraw && !drawable.is_a?(ImageProxy)
  elsif redraw == :each
    shapes.dup.each {|shape| shape.dispose(dispose_images: dispose_images, dispose_patterns: dispose_patterns, redraw: true) }
  else
    shapes.dup.each {|shape| shape.dispose(dispose_images: dispose_images, dispose_patterns: dispose_patterns, redraw: false) }
  end
end

#composite?Boolean

Indicate if this is a composite shape (meaning a shape that contains nested shapes like a rectangle with ovals inside it)

Returns:

  • (Boolean)


912
913
914
# File 'lib/glimmer/swt/custom/shape.rb', line 912

def composite?
  !shapes.empty?
end

#contain?(x, y) ⇒ Boolean

Returns if shape contains a point Subclasses (like polygon) may override to indicate if a point x,y coordinates falls inside the shape some shapes may choose to provide a fuzz factor to make usage of this method for mouse clicking more user friendly

Returns:

  • (Boolean)


217
218
219
220
221
# File 'lib/glimmer/swt/custom/shape.rb', line 217

def contain?(x, y)
  x, y = inverse_transform_point(x, y)
  # assume a rectangular filled shape by default (works for several shapes like image, text, and focus)
  x.between?(self.absolute_x, self.absolute_x + calculated_width.to_f) && y.between?(self.absolute_y, self.absolute_y + calculated_height.to_f)
end

#container?Boolean

Indicate if this is a container shape (meaning a shape bag that is just there to contain nested shapes, but doesn’t render anything of its own)

Returns:

  • (Boolean)


907
908
909
# File 'lib/glimmer/swt/custom/shape.rb', line 907

def container?
  @name == 'shape'
end

#content(&block) ⇒ Object



342
343
344
345
346
347
348
# File 'lib/glimmer/swt/custom/shape.rb', line 342

def content(&block)
  # TODO consider supporting adding content without redraw (redraw: false)
  Glimmer::SWT::DisplayProxy.instance.auto_exec do
    Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::ShapeExpression.new, @name, &block)
    calculated_args_changed!(children: false)
  end
end

#convert_properties!Object



956
957
958
959
960
961
962
963
# File 'lib/glimmer/swt/custom/shape.rb', line 956

def convert_properties!
  if @properties != @converted_properties
    @properties.each do |property, args|
      @properties[property] = apply_property_arg_conversions(property, args)
    end
    @converted_properties = @properties.dup
  end
end

#converted_propertiesObject



965
966
967
968
# File 'lib/glimmer/swt/custom/shape.rb', line 965

def converted_properties
  convert_properties!
  @properties
end

#current_parameter_name?(attribute_name) ⇒ Boolean

Returns:

  • (Boolean)


547
548
549
# File 'lib/glimmer/swt/custom/shape.rb', line 547

def current_parameter_name?(attribute_name)
  parameter_names.include?(attribute_name.to_s.to_sym)
end

#default_heightObject



1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
# File 'lib/glimmer/swt/custom/shape.rb', line 1267

def default_height
  default_height_dependencies = [shapes.empty? && max_height, shapes.size == 1 && shapes.first.max_height? && parent.size.y, shapes.size >= 1 && !shapes.first.max_height? && shapes.map {|s| s.max_height? ? 0 : s.y_end}]
  if default_height_dependencies != @default_height_dependencies
    # Do not repeat calculations
    max_height, parent_size_y, y_ends = @default_height_dependencies = default_height_dependencies
    @default_height = if shapes.empty?
      max_height
    elsif shapes.size == 1 && shapes.first.max_height?
      parent_size_y
    else
      y_ends.max.to_f
    end
  end
  @default_height
end

#default_height?Boolean

Returns:

  • (Boolean)


1186
1187
1188
1189
1190
# File 'lib/glimmer/swt/custom/shape.rb', line 1186

def default_height?
  return false unless current_parameter_name?(:height)
  height = self.height
  (height.nil? || height == :default || height == 'default' || (height.is_a?(Array) && (height.first.to_s == :default || height.first.to_s == 'default')))
end

#default_widthObject



1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
# File 'lib/glimmer/swt/custom/shape.rb', line 1251

def default_width
  default_width_dependencies = [shapes.empty? && max_width, shapes.size == 1 && shapes.first.max_width? && parent.size.x, shapes.size >= 1 && !shapes.first.max_width? && shapes.map {|s| s.max_width? ? 0 : s.x_end}]
  if default_width_dependencies != @default_width_dependencies
    # Do not repeat calculations
    max_width, parent_size_x, x_ends = @default_width_dependencies = default_width_dependencies
    @default_width = if shapes.empty?
      max_width
    elsif shapes.size == 1 && shapes.first.max_width?
      parent_size_x
    else
      x_ends.max.to_f
    end
  end
  @default_width
end

#default_width?Boolean

Returns:

  • (Boolean)


1180
1181
1182
1183
1184
# File 'lib/glimmer/swt/custom/shape.rb', line 1180

def default_width?
  return false unless current_parameter_name?(:width)
  width = self.width
  (width.nil? || width == :default || width == 'default' || (width.is_a?(Array) && (width.first.to_s == :default || width.first.to_s == 'default')))
end

#default_xObject



1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
# File 'lib/glimmer/swt/custom/shape.rb', line 1204

def default_x
  default_x_dependencies = [parent.size.x, size.x, parent.is_a?(Shape) && parent.irregular? && parent.bounds.x, parent.is_a?(Shape) && parent.irregular? && parent.absolute_x]
  if default_x_dependencies != @default_x_dependencies
    @default_x_dependencies = default_x_dependencies
    result = ((parent.size.x - size.x) / 2)
    result += parent.bounds.x - parent.absolute_x if parent.is_a?(Shape) && parent.irregular?
    @default_x = result
  end
  @default_x
end

#default_x?Boolean

Returns:

  • (Boolean)


1168
1169
1170
1171
1172
# File 'lib/glimmer/swt/custom/shape.rb', line 1168

def default_x?
  return false unless current_parameter_name?(:x)
  x = self.x
  x.nil? || x.to_s == 'default' || (x.is_a?(Array) && x.first.to_s == 'default')
end

#default_yObject



1215
1216
1217
1218
1219
1220
1221
1222
1223
# File 'lib/glimmer/swt/custom/shape.rb', line 1215

def default_y
  default_y_dependencies = [parent.size.y, size.y, parent.is_a?(Shape) && parent.irregular? && parent.bounds.y, parent.is_a?(Shape) && parent.irregular? && parent.absolute_y]
  if default_y_dependencies != @default_y_dependencies
    result = ((parent.size.y - size.y) / 2)
    result += parent.bounds.y - parent.absolute_y if parent.is_a?(Shape) && parent.irregular?
    @default_y = result
  end
  @default_y
end

#default_y?Boolean

Returns:

  • (Boolean)


1174
1175
1176
1177
1178
# File 'lib/glimmer/swt/custom/shape.rb', line 1174

def default_y?
  return false unless current_parameter_name?(:y)
  y = self.y
  y.nil? || y.to_s == 'default' || (y.is_a?(Array) && y.first.to_s == 'default')
end

#deregister_drag_listenersObject



751
752
753
754
755
756
757
758
# File 'lib/glimmer/swt/custom/shape.rb', line 751

def deregister_drag_listeners
  @on_drag_detected&.deregister
  @on_drag_detected = nil
  @drawable_on_mouse_move&.deregister
  @drawable_on_mouse_move = nil
  @drawable_on_mouse_up&.deregister
  @drawable_on_mouse_up = nil
end

#dispose(dispose_images: true, dispose_patterns: true, redraw: true) ⇒ Object



868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
# File 'lib/glimmer/swt/custom/shape.rb', line 868

def dispose(dispose_images: true, dispose_patterns: true, redraw: true)
  return if drawable.respond_to?(:shell_proxy) && drawable&.shell_proxy&.last_shell_closing?
  return if @disposed
  @disposed = true
  deregister_drag_listeners
  @widget_listener_proxies&.each(&:deregister)
  if dispose_patterns
    @background_pattern&.dispose
    @background_pattern = nil
    @foreground_pattern&.dispose
    @foreground_pattern = nil
  end
  if dispose_images
    @image&.dispose
    @image = nil
  end
  shapes.dup.each { |shape| shape.dispose(dispose_images: dispose_images, dispose_patterns: dispose_patterns, redraw: false) }
  @parent.shapes.delete(self)
  drawable.drop_shapes.delete(self)
  @on_shape_disposed_handlers&.each {|handler| handler.call(self)} # TODO pass a custom event argument to handler
  drawable.redraw if redraw && !drawable.is_a?(ImageProxy)
end

#drag_and_moveObject



794
795
796
# File 'lib/glimmer/swt/custom/shape.rb', line 794

def drag_and_move
  @drag_and_move
end

#drag_and_move=(drag_and_move_value) ⇒ Object

Enables dragging for drag and move within parent widget drag_and_move and drag_source are mutually exclusive if shape had drag_source true, it is disabled by deregistering its listeners



763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/glimmer/swt/custom/shape.rb', line 763

def drag_and_move=(drag_and_move_value)
  deregister_drag_listeners if @drag_source
  drag_and_move_old_value = @drag_and_move
  @drag_and_move = drag_and_move_value
  if @drag_and_move && !drag_and_move_old_value
    @on_drag_detected ||= handle_observation_request('on_drag_detected') do |event|
      Shape.dragging = true
      Shape.dragging_x = event.x
      Shape.dragging_y = event.y
      Shape.drop_shape_handling_count = 0
      Shape.dragged_shape = self
      Shape.dragged_shape_original_x = x
      Shape.dragged_shape_original_y = y
    end
    @drawable_on_mouse_move ||= drawable.handle_observation_request('on_mouse_move') do |event|
      if Shape.dragging && Shape.dragged_shape.equal?(self)
        Shape.dragged_shape.move_by((event.x - Shape.dragging_x), (event.y - Shape.dragging_y))
        Shape.dragging_x = event.x
        Shape.dragging_y = event.y
      end
    end
    @drawable_on_mouse_up ||= drawable.handle_observation_request('on_mouse_up') do |event|
      if Shape.dragging && Shape.dragged_shape.equal?(self)
        Shape.dragging = false
      end
    end
  elsif !@drag_and_move && drag_and_move_old_value
    deregister_drag_listeners
  end
end

#drag_sourceObject



830
831
832
# File 'lib/glimmer/swt/custom/shape.rb', line 830

def drag_source
  @drag_source
end

#drag_source=(drag_source_value) ⇒ Object

Makes shape a drag source (enables dragging for drag and drop) drag_source and drag_and_move are mutually exclusive if shape had drag_and_move true, it is disabled by deregistering its listeners



801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'lib/glimmer/swt/custom/shape.rb', line 801

def drag_source=(drag_source_value)
  deregister_drag_listeners if @drag_and_move
  drag_source_old_value = @drag_source
  @drag_source = drag_source_value
  if @drag_source && !drag_source_old_value
    @on_drag_detected ||= handle_observation_request('on_drag_detected') do |event|
      Shape.dragging = true
      Shape.dragging_x = event.x
      Shape.dragging_y = event.y
      Shape.drop_shape_handling_count = 0
      Shape.dragged_shape = self
      Shape.dragged_shape_original_x = x
      Shape.dragged_shape_original_y = y
    end
    @drawable_on_mouse_move ||= drawable.handle_observation_request('on_mouse_move') do |event|
      if Shape.dragging && Shape.dragged_shape.equal?(self)
        Shape.dragged_shape.move_by((event.x - Shape.dragging_x), (event.y - Shape.dragging_y))
        Shape.dragging_x = event.x
        Shape.dragging_y = event.y
      end
    end
    @drawable_on_mouse_up ||= drawable.handle_observation_request('on_mouse_up') do |event|
      cancel_dragging! if Shape.dragging && Shape.dragged_shape.equal?(self) && !any_potential_drop_targets?(event.x, event.y)
    end
  elsif !@drag_source && drag_source_old_value
    deregister_drag_listeners
  end
end

#draw?Boolean Also known as: drawn?

Returns:

  • (Boolean)


165
166
167
# File 'lib/glimmer/swt/custom/shape.rb', line 165

def draw?
  !fill?
end

#ensure_extent(paint_event) ⇒ Object



1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
# File 'lib/glimmer/swt/custom/shape.rb', line 1026

def ensure_extent(paint_event)
  old_extent = @extent
  if ['text', 'string'].include?(@name)
    extent_args = [string]
    extent_flags = SWTProxy[:draw_transparent, :draw_delimiter] if current_parameter_name?(:is_transparent) && is_transparent
    extent_flags = flags if current_parameter_name?(:flags)
    extent_args << extent_flags unless extent_flags.nil?
    self.extent = paint_event.gc.send("#{@name}Extent", *extent_args)
  end
  if !@extent.nil? && (old_extent&.x != @extent&.x || old_extent&.y != @extent&.y) # TODO add a check to text content changing too
    calculated_args_changed!
    parent.calculated_args_changed_for_defaults! if parent.is_a?(Shape)
  end
end

#expanded_shapes(except_shape: nil) ⇒ Object



1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/glimmer/swt/custom/shape.rb', line 1041

def expanded_shapes(except_shape: nil)
  if shapes.to_a.any?
    shapes.map do |shape|
      shape.equal?(except_shape) ? [] : ([shape] + shape.expanded_shapes(except_shape: except_shape))
    end.flatten
  else
    []
  end
end

#fill?Boolean Also known as: filled?

Returns:

  • (Boolean)


170
171
172
# File 'lib/glimmer/swt/custom/shape.rb', line 170

def fill?
  @options[:fill]
end

#foreground_pattern_argsObject



864
865
866
# File 'lib/glimmer/swt/custom/shape.rb', line 864

def foreground_pattern_args
  pattern_args(type: 'foreground')
end

#get_attribute(attribute_name) ⇒ Object



618
619
620
621
622
623
624
625
626
627
# File 'lib/glimmer/swt/custom/shape.rb', line 618

def get_attribute(attribute_name)
  if parameter_name?(attribute_name)
    arg_index = parameter_index(attribute_name)
    @args[arg_index] if arg_index
  elsif (respond_to?(attribute_name, super: true) and respond_to?(ruby_attribute_setter(attribute_name), super: true))
    self.send(attribute_name)
  else
    @properties[attribute_name.to_s]
  end
end

#get_data(key = nil) ⇒ Object Also known as: getData, data

Gets data just like SWT widgets



716
717
718
719
# File 'lib/glimmer/swt/custom/shape.rb', line 716

def get_data(key=nil)
  @data ||= {}
  @data[key]
end

#get_parameter_attribute(attribute_name) ⇒ Object



555
556
557
# File 'lib/glimmer/swt/custom/shape.rb', line 555

def get_parameter_attribute(attribute_name)
  @args[parameter_index(ruby_attribute_getter(attribute_name))]
end

#gradient?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/glimmer/swt/custom/shape.rb', line 175

def gradient?
  @options[:gradient]
end

#handle_observation_request(observation_request, source_observation_request: nil, &block) ⇒ Object



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'lib/glimmer/swt/custom/shape.rb', line 641

def handle_observation_request(observation_request, source_observation_request: nil, &block)
  if observation_request.to_s == 'on_shape_disposed'
    @on_shape_disposed_handlers ||= []
    @on_shape_disposed_handlers << block
    return ShapeListenerProxy.new(shape: self, drawable: drawable, shape_listener_block: block, observation_request: 'on_shape_disposed')
  end
  if observation_request == 'on_drop'
    drawable.drop_shapes << self
    handle_observation_request('on_mouse_up', source_observation_request: 'on_drop') do |event|
      if Shape.dragging && include_with_children?(event.x, event.y, except_shape: Shape.dragged_shape)
        drop_event = DropEvent.new(
          doit: true,
          dragged_shape: Shape.dragged_shape,
          dragged_shape_original_x: Shape.dragged_shape_original_x,
          dragged_shape_original_y: Shape.dragged_shape_original_y,
          dragging_x: Shape.dragging_x,
          dragging_y: Shape.dragging_y,
          drop_shapes: drawable.drop_shapes,
          x: event.x,
          y: event.y
        )
        begin
          block.call(drop_event)
        rescue => e
          Glimmer::Config.logger.error {e.full_message}
        ensure
          if drop_event.doit
            Shape.dragging = false
            Shape.dragged_shape = nil
          elsif Shape.drop_shape_handling_count.to_i >= drawable.drop_shapes.count && Shape.dragged_shape
            cancel_dragging!
          end
        end
      else
        if Shape.drop_shape_handling_count.to_i >= drawable.drop_shapes.count
          cancel_dragging!
        end
      end
    end
  else
    widget_listener_proxy = nil
    shape_block = lambda do |event|
      if @disposed
        widget_listener_proxy.deregister
        @widget_listener_proxies.delete(widget_listener_proxy)
      else
        Shape.drop_shape_handling_count += 1 if source_observation_request == 'on_drop' && event.x == Shape.dragging_x && event.y == Shape.dragging_y
        if !event.respond_to?(:x) || !event.respond_to?(:y) || include_with_children?(event.x, event.y)
          block.call(event)
        elsif source_observation_request == 'on_drop' && Shape.drop_shape_handling_count.to_i >= drawable.drop_shapes.count
          cancel_dragging!
        end
      end
    end
    widget_listener_proxy = drawable.respond_to?(:handle_observation_request) && drawable.handle_observation_request(observation_request, &shape_block)
    @widget_listener_proxies ||= []
    if widget_listener_proxy
      @widget_listener_proxies << widget_listener_proxy
      ShapeListenerProxy.new(shape: self, drawable: drawable, shape_listener_block: shape_block, observation_request: source_observation_request || observation_request, widget_listener_proxy: widget_listener_proxy)
    end
  end
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


563
564
565
566
567
# File 'lib/glimmer/swt/custom/shape.rb', line 563

def has_attribute?(attribute_name, *args)
  self.class.gc_instance_methods.include?(attribute_setter(attribute_name)) or
    parameter_name?(attribute_name) or
    (respond_to?(attribute_name, super: true) and respond_to?(ruby_attribute_setter(attribute_name), super: true))
end

#has_some_background?Boolean

Returns:

  • (Boolean)


350
351
352
# File 'lib/glimmer/swt/custom/shape.rb', line 350

def has_some_background?
  @properties.keys.map(&:to_s).include?('background') || @properties.keys.map(&:to_s).include?('background_pattern')
end

#has_some_foreground?Boolean

Returns:

  • (Boolean)


354
355
356
# File 'lib/glimmer/swt/custom/shape.rb', line 354

def has_some_foreground?
  @properties.keys.map(&:to_s).include?('foreground') || @properties.keys.map(&:to_s).include?('foreground_pattern')
end

#height_deltaObject



1342
1343
1344
1345
# File 'lib/glimmer/swt/custom/shape.rb', line 1342

def height_delta
  return 0 unless height.is_a?(Array) && (default_height? || max_height?)
  height[1].to_f
end

#height_delta=(delta) ⇒ Object



1365
1366
1367
1368
1369
# File 'lib/glimmer/swt/custom/shape.rb', line 1365

def height_delta=(delta)
  return unless default_height?
  symbol = height.is_a?(Array) ? height.first : height
  self.height = [symbol, delta]
end

#include?(x, y) ⇒ Boolean

Returns if shape includes a point. When the shape is filled, this is the same as contain. When the shape is drawn, it only returns true if the point lies on the edge (boundary/border) Subclasses (like polygon) may override to indicate if a point x,y coordinates falls on the edge of a drawn shape or inside a filled shape some shapes may choose to provide a fuzz factor to make usage of this method for mouse clicking more user friendly

Returns:

  • (Boolean)


226
227
228
229
# File 'lib/glimmer/swt/custom/shape.rb', line 226

def include?(x, y)
  # assume a rectangular shape by default
  contain?(x, y)
end

#include_shape?(other) ⇒ Boolean

Recursively checks if other shape is included in this shape, beginning by comparing to self and then recursing into children shapes.

Returns:

  • (Boolean)


244
245
246
# File 'lib/glimmer/swt/custom/shape.rb', line 244

def include_shape?(other)
  self == other || shapes.any? { |shape| shape.include_shape?(other) }
end

#include_with_children?(x, y, except_shape: nil) ⇒ Boolean

Returns:

  • (Boolean)


231
232
233
234
235
# File 'lib/glimmer/swt/custom/shape.rb', line 231

def include_with_children?(x, y, except_shape: nil)
  included_in_self = (!self.equal?(except_shape) && include?(x, y))
  # TODO note that expanded shapes does not filter when reject below happens, keeping nested shapes
  included_in_self || expanded_shapes(except_shape: except_shape).any? { |shape| shape.include?(x, y) }
end

#inspect(recursive: 1, calculated: false, args: true, properties: true, calculated_args: false) ⇒ Object

Overriding inspect to avoid printing very long nested shape hierarchies (recurses onces only)



1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
# File 'lib/glimmer/swt/custom/shape.rb', line 1423

def inspect(recursive: 1, calculated: false, args: true, properties: true, calculated_args: false)
  recurse = recursive == true || recursive.is_a?(Integer) && recursive.to_i > 0
  recursive = [recursive -= 1, 0].max if recursive.is_a?(Integer)
  args_string = " args=#{@args.inspect}" if args
  properties_string = " properties=#{@properties.inspect}}" if properties
  calculated_args_string = " calculated_args=#{@calculated_args.inspect}" if calculated_args
  calculated_string = " absolute_x=#{absolute_x} absolute_y=#{absolute_y} calculated_width=#{calculated_width} calculated_height=#{calculated_height}" if calculated
  recursive_string = " shapes=#{@shapes.map {|s| s.inspect(recursive: recursive, calculated: calculated, args: args, properties: properties)}}" if recurse
  "#<#{self.class.name}:0x#{self.hash.to_s(16)}#{args_string}#{properties_string}#{calculated_args_string}#{calculated_string}#{recursive_string}>"
rescue => e
  Glimmer::Config.logger.error { e.full_message }
  "#<#{self.class.name}:0x#{self.hash.to_s(16)}"
end

#inverse_transform_point(x, y) ⇒ Object

if there is a transform, invert it and apply on x, y point coordinates



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/glimmer/swt/custom/shape.rb', line 262

def inverse_transform_point(x, y)
  # keep in mind that transform is an array of a single element that is the transform object
  current_transform = (transform || parent_shape_containers.map(&:transform).compact.first)&.first
  if current_transform
    transform_array = [1,2,3,4,5,6].to_java(:float) # just placeholder data that gets overwritten with getElements
    current_transform.getElements(transform_array)
    inverse_transform = TransformProxy.new(DisplayProxy.instance.swt_display, *transform_array.to_a)
    inverse_transform_array = [1,2,3,4,5,6].to_java(:float) # just placeholder data that gets overwritten with getElements
    inverse_transform.getElements(inverse_transform_array)
    matrix = Matrix[[inverse_transform_array[0], inverse_transform_array[1]], [inverse_transform_array[2], inverse_transform_array[3]]]
    result = matrix * Matrix.column_vector([x, y])
    x, y = result.to_a.flatten
    x += inverse_transform_array[5]
    y += inverse_transform_array[4]
  end
  [x, y]
end

#irregular?Boolean

Indicates if a shape’s x, y, width, height differ from its bounds calculation (e.g. arc / polygon)

Returns:

  • (Boolean)


281
282
283
# File 'lib/glimmer/swt/custom/shape.rb', line 281

def irregular?
  false
end

#locationObject

The bounding box top-left x and y



195
196
197
# File 'lib/glimmer/swt/custom/shape.rb', line 195

def location
  org.eclipse.swt.graphics.Point.new(bounds.x, bounds.y)
end

#location_parameter_namesObject

subclasses may override to specify location parameter names if different from x and y (e.g. all polygon points are location parameters) used in calculating movement changes



535
536
537
# File 'lib/glimmer/swt/custom/shape.rb', line 535

def location_parameter_names
  [:x, :y]
end

#max_heightObject



1293
1294
1295
1296
1297
1298
1299
1300
1301
# File 'lib/glimmer/swt/custom/shape.rb', line 1293

def max_height
  max_height_dependencies = [parent.is_a?(Drawable) && parent.size.y, !parent.is_a?(Drawable) && parent.calculated_height]
  if max_height_dependencies != @max_height_dependencies
    # do not repeat calculations
    parent_size_y, parent_calculated_height = @max_height_dependencies = max_height_dependencies
    @max_height = parent.is_a?(Drawable) ? parent_size_y : parent_calculated_height
  end
  @max_height
end

#max_height?Boolean

Returns:

  • (Boolean)


1198
1199
1200
1201
1202
# File 'lib/glimmer/swt/custom/shape.rb', line 1198

def max_height?
  return false unless current_parameter_name?(:height)
  height = self.height
  (height.nil? || height.to_s == 'max' || (height.is_a?(Array) && height.first.to_s == 'max'))
end

#max_widthObject



1283
1284
1285
1286
1287
1288
1289
1290
1291
# File 'lib/glimmer/swt/custom/shape.rb', line 1283

def max_width
  max_width_dependencies = [parent.is_a?(Drawable) && parent.size.x, !parent.is_a?(Drawable) && parent.calculated_width]
  if max_width_dependencies != @max_width_dependencies
    # do not repeat calculations
    parent_size_x, parent_calculated_width = @max_width_dependencies = max_width_dependencies
    @max_width = parent.is_a?(Drawable) ? parent_size_x : parent_calculated_width
  end
  @max_width
end

#max_width?Boolean

Returns:

  • (Boolean)


1192
1193
1194
1195
1196
# File 'lib/glimmer/swt/custom/shape.rb', line 1192

def max_width?
  return false unless current_parameter_name?(:width)
  width = self.width
  (width.nil? || width.to_s == 'max' || (width.is_a?(Array) && width.first.to_s == 'max'))
end

#move_by(x_delta, y_delta) ⇒ Object Also known as: translate

moves by x delta and y delta. Subclasses must implement provdies a default implementation that assumes moving x and y is sufficient by default (not for polygons though, which must override)



287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/glimmer/swt/custom/shape.rb', line 287

def move_by(x_delta, y_delta)
  if respond_to?(:x) && respond_to?(:y) && respond_to?(:x=) && respond_to?(:y=)
    if default_x?
      self.x_delta += x_delta
    else
      self.x += x_delta
    end
    if default_y?
      self.y_delta += y_delta
    else
      self.y += y_delta
    end
  end
end

#paint(paint_event) ⇒ Object



976
977
978
979
980
981
982
983
984
985
# File 'lib/glimmer/swt/custom/shape.rb', line 976

def paint(paint_event)
  paint_children(paint_event) if default_width? || default_height?
  paint_self(paint_event)
  # re-paint children from scratch in the special case of pre-calculating parent width/height to re-center within new parent dimensions
  shapes.each(&:calculated_args_changed!) if default_width? || default_height?
  paint_children(paint_event)
rescue => e
  Glimmer::Config.logger.error {"Error encountered in painting shape (#{self.inspect}) with calculated args (#{@calculated_args}) and args (#{@args})"}
  Glimmer::Config.logger.error {e.full_message}
end

#paint_children(paint_event) ⇒ Object



1020
1021
1022
1023
1024
# File 'lib/glimmer/swt/custom/shape.rb', line 1020

def paint_children(paint_event)
  shapes.to_a.each do |shape|
    shape.paint(paint_event)
  end
end

#paint_self(paint_event) ⇒ Object



987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# File 'lib/glimmer/swt/custom/shape.rb', line 987

def paint_self(paint_event)
  @painting = true
  unless container?
    calculate_paint_args!
    @original_gc_properties = {} # this stores GC properties before making calls to updates TODO avoid using in pixel graphics
    @properties.each do |property, args|
      method_name = attribute_setter(property)
      @original_gc_properties[method_name] = paint_event.gc.send(method_name.sub('set', 'get')) rescue nil
      paint_event.gc.send(method_name, *args)
      if property == 'transform' && args.first.is_a?(TransformProxy)
        args.first.swt_transform.dispose
      end
    end
    ensure_extent(paint_event)
  end
  @calculated_args ||= calculate_args!
  unless container?
    # paint unless parent's calculated args are not calculated yet, meaning it is about to get painted and trigger a paint on this child anyways
    passed_args = @calculated_args.dup
    passed_args[0] = passed_args[0].to_java(:int) if @method_name == 'drawPolyline' # a weird fix needed for Linux JRuby 9.3.1.0 only (seems to lack a feature from Mac JRuby that automatically converts to appropriate java array type)
    paint_event.gc.send(@method_name, *passed_args) unless (parent.is_a?(Shape) && !parent.calculated_args?)
    @original_gc_properties.each do |method_name, value|
      paint_event.gc.send(method_name, value)
    end
  end
  @painting = false
rescue => e
  Glimmer::Config.logger.error {"Error encountered in painting shape (#{self.inspect}) with method (#{@method_name}) calculated args (#{@calculated_args}) and args (#{@args})"}
  Glimmer::Config.logger.error {e.full_message}
ensure
  @painting = false
end

#parameter_index(attribute_name) ⇒ Object



551
552
553
# File 'lib/glimmer/swt/custom/shape.rb', line 551

def parameter_index(attribute_name)
  parameter_names.index(attribute_name.to_s.to_sym)
end

#parameter_name?(attribute_name) ⇒ Boolean

Returns:

  • (Boolean)


543
544
545
# File 'lib/glimmer/swt/custom/shape.rb', line 543

def parameter_name?(attribute_name)
  possible_parameter_names.map(&:to_s).include?(ruby_attribute_getter(attribute_name))
end

#parameter_namesObject

parameter names for arguments to pass to SWT GC.xyz method for rendering shape (e.g. draw_image(image, x, y) yields :image, :x, :y parameter names)



529
530
531
# File 'lib/glimmer/swt/custom/shape.rb', line 529

def parameter_names
  [:x, :y, :width, :height]
end

#parent_shape_compositesObject

ordered from closest to farthest parent



943
944
945
946
947
948
949
950
951
952
953
954
# File 'lib/glimmer/swt/custom/shape.rb', line 943

def parent_shape_composites
  if @parent_shape_composites.nil?
    if parent.is_a?(Drawable)
      @parent_shape_composites = []
    elsif !parent.container?
      @parent_shape_composites = parent.parent_shape_composites
    else
      @parent_shape_composites = parent.parent_shape_composites + [parent]
    end
  end
  @parent_shape_composites
end

#parent_shape_containersObject

ordered from closest to farthest parent



929
930
931
932
933
934
935
936
937
938
939
940
# File 'lib/glimmer/swt/custom/shape.rb', line 929

def parent_shape_containers
  if @parent_shape_containers.nil?
    if parent.is_a?(Drawable)
      @parent_shape_containers = []
    elsif !parent.container?
      @parent_shape_containers = parent.parent_shape_containers
    else
      @parent_shape_containers = parent.parent_shape_containers + [parent]
    end
  end
  @parent_shape_containers
end

#parent_shapesObject

ordered from closest to farthest parent



917
918
919
920
921
922
923
924
925
926
# File 'lib/glimmer/swt/custom/shape.rb', line 917

def parent_shapes
  if @parent_shapes.nil?
    if parent.is_a?(Drawable)
      @parent_shapes = []
    else
      @parent_shapes = parent.parent_shapes + [parent]
    end
  end
  @parent_shapes
end

#pattern(*args, type: nil) ⇒ Object



847
848
849
850
851
852
853
854
# File 'lib/glimmer/swt/custom/shape.rb', line 847

def pattern(*args, type: nil)
  instance_variable_name = "@#{type}_pattern"
  the_pattern = instance_variable_get(instance_variable_name)
  if the_pattern.nil? || the_pattern.is_disposed
    the_pattern = self.class.pattern(*args)
  end
  the_pattern
end

#pattern_args(type: nil) ⇒ Object



856
857
858
# File 'lib/glimmer/swt/custom/shape.rb', line 856

def pattern_args(type: nil)
  @pattern_args && @pattern_args[type.to_s.capitalize]
end

#possible_parameter_namesObject



539
540
541
# File 'lib/glimmer/swt/custom/shape.rb', line 539

def possible_parameter_names
  parameter_names
end

#post_add_contentObject



358
359
360
361
362
363
364
# File 'lib/glimmer/swt/custom/shape.rb', line 358

def post_add_content
  amend_method_name_options_based_on_properties!
  if !@content_added || @method_name != @original_method_name
    @drawable.setup_shape_painting unless @drawable.is_a?(ImageProxy)
    @content_added = true
  end
end

#remove_shape_disposed_listener(listener_block) ⇒ Object



704
705
706
# File 'lib/glimmer/swt/custom/shape.rb', line 704

def remove_shape_disposed_listener(listener_block)
  @on_shape_disposed_handlers.delete(listener_block)
end

#respond_to?(method_name, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


727
728
729
730
731
732
733
734
735
736
737
# File 'lib/glimmer/swt/custom/shape.rb', line 727

def respond_to?(method_name, *args, &block)
  options = args.last if args.last.is_a?(Hash)
  super_invocation = options && options[:super]
  if !super_invocation && has_attribute?(method_name)
    true
  else
    result = super
    return true if result
    can_handle_observation_request?(method_name)
  end
end

#rotate(angle) ⇒ Object

rotates shape for an angle around its center this operation is not cumulative (it resets angle every time) consumers may inspect corresponding rotation_angle attribute to know which angle the shape is currently at for convenience this overrides any pre-existing transforms that are applied to shape



307
308
309
310
311
312
# File 'lib/glimmer/swt/custom/shape.rb', line 307

def rotate(angle)
  half_width = calculated_width/2.0
  half_height = calculated_height/2.0
  self.transform = Glimmer::SWT::TransformProxy.new(self).translate(half_width, half_height).rotate(angle).translate(-1.0*half_width, -1.0*half_height)
  @rotation_angle = angle
end

#rotation_angleObject

returns rotation angle consumers may inspect rotation_angle attribute to know which angle the shape is rotated at via rotate method it is not guaranteed to give the right result if a transform is applied outside of rotate method. starts at 0



318
319
320
# File 'lib/glimmer/swt/custom/shape.rb', line 318

def rotation_angle
  @rotation_angle.to_f
end

#round?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/glimmer/swt/custom/shape.rb', line 179

def round?
  @options[:round]
end

#set_attribute(attribute_name, *args) ⇒ Object



569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/glimmer/swt/custom/shape.rb', line 569

def set_attribute(attribute_name, *args)
  options = args.last if args.last.is_a?(Hash)
  args.pop if !options.nil? && !options[:redraw].nil?
  options ||= {}
  perform_redraw = @perform_redraw
  perform_redraw = options[:redraw] if perform_redraw.nil? && !options.nil?
  perform_redraw ||= true
  property_change = nil
  ruby_attribute_getter_name = ruby_attribute_getter(attribute_name)
  ruby_attribute_setter_name = ruby_attribute_setter(attribute_name)
  if parameter_name?(attribute_name)
    return if ruby_attribute_getter_name == (args.size == 1 ? args.first : args)
    set_parameter_attribute(ruby_attribute_getter_name, *args)
  elsif (respond_to?(attribute_name, super: true) and respond_to?(ruby_attribute_setter_name, super: true))
    return if self.send(ruby_attribute_getter_name) == (args.size == 1 ? args.first : args)
    self.send(ruby_attribute_setter_name, *args)
  else
    # TODO consider this optimization of preconverting args (removing conversion from other methods) to reject equal args
    args = apply_property_arg_conversions(ruby_attribute_getter_name, args)
    return if @properties[ruby_attribute_getter_name] == args
    new_property = !@properties.keys.include?(ruby_attribute_getter_name)
    @properties[ruby_attribute_getter_name] = args
    amend_method_name_options_based_on_properties! if @content_added && new_property
    property_change = true
    calculated_paint_args_changed! if container?
  end
  if @content_added && perform_redraw && !drawable.is_disposed
    redrawn = false
    unless property_change
      calculated_paint_args_changed!(children: false)
      if is_a?(PathSegment)
        root_path&.calculated_path_args = @calculated_path_args = false
        calculated_args_changed!
        root_path&.calculated_args_changed!
      end
      if location_parameter_names.map(&:to_s).include?(ruby_attribute_getter_name)
        calculated_args_changed!(children: true)
        redrawn = parent.calculated_args_changed_for_defaults! if parent.is_a?(Shape)
      end
      if ['width', 'height'].include?(ruby_attribute_getter_name)
        redrawn = calculated_args_changed_for_defaults!
      end
    end
    # TODO consider redrawing an image proxy's gc in the future
    # TODO consider ensuring only a single redraw happens for a hierarchy of nested shapes
    drawable.redraw if !redrawn && !drawable.is_a?(ImageProxy)
  end
end

#set_data(key = nil, value) ⇒ Object Also known as: setData

Sets data just like SWT widgets



709
710
711
712
# File 'lib/glimmer/swt/custom/shape.rb', line 709

def set_data(key=nil, value)
  @data ||= {}
  @data[key] = value
end

#set_parameter_attribute(attribute_name, *args) ⇒ Object



559
560
561
# File 'lib/glimmer/swt/custom/shape.rb', line 559

def set_parameter_attribute(attribute_name, *args)
  @args[parameter_index(ruby_attribute_getter(attribute_name))] = args.size == 1 ? args.first : args
end

#shell_proxyObject



723
724
725
# File 'lib/glimmer/swt/custom/shape.rb', line 723

def shell_proxy
  drawable.shell_proxy
end

#sizeObject

The bounding box width and height (as a Point object with x being width and y being height)



200
201
202
203
204
205
206
207
208
# File 'lib/glimmer/swt/custom/shape.rb', line 200

def size
  size_dependencies = [calculated_width, calculated_height]
  if size_dependencies != @size_dependencies
    # avoid repeating calculations
    calculated_width, calculated_height = @size_dependencies = size_dependencies
    @size = org.eclipse.swt.graphics.Point.new(calculated_width, calculated_height)
  end
  @size
end

#tolerate_shape_extra_args!Object

Tolerates shape extra args added by user by mistake (e.g. happens when switching from round rectangle to a standard one without removing all extra args)



502
503
504
505
506
507
508
509
# File 'lib/glimmer/swt/custom/shape.rb', line 502

def tolerate_shape_extra_args!
  the_java_method_arg_count = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.select do |m|
    m.name == @method_name.camelcase(:lower)
  end.map(&:parameter_types).map(&:size).max
  if the_java_method_arg_count && @args.to_a.size > the_java_method_arg_count
    @args[the_java_method_arg_count..-1] = []
  end
end

#transform_point(x, y) ⇒ Object

if there is a transform, apply on x, y point coordinates



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/glimmer/swt/custom/shape.rb', line 249

def transform_point(x, y)
  # keep in mind that transform is an array of a single element that is the transform object
  current_transform = (transform || parent_shape_containers.map(&:transform).first)&.first
  if current_transform
    transform_array = [x, y].to_java(:float) # just placeholder data that gets overwritten with getElements
    current_transform.transform(transform_array)
    x = transform_array[0]
    y = transform_array[1]
  end
  [x, y]
end

#width_deltaObject



1337
1338
1339
1340
# File 'lib/glimmer/swt/custom/shape.rb', line 1337

def width_delta
  return 0 unless width.is_a?(Array) && (default_width? || max_width?)
  width[1].to_f
end

#width_delta=(delta) ⇒ Object



1359
1360
1361
1362
1363
# File 'lib/glimmer/swt/custom/shape.rb', line 1359

def width_delta=(delta)
  return unless default_width?
  symbol = width.is_a?(Array) ? width.first : width
  self.width = [symbol, delta]
end

#x_deltaObject



1327
1328
1329
1330
# File 'lib/glimmer/swt/custom/shape.rb', line 1327

def x_delta
  return 0 unless x.is_a?(Array) && default_x?
  x[1].to_f
end

#x_delta=(delta) ⇒ Object



1347
1348
1349
1350
1351
# File 'lib/glimmer/swt/custom/shape.rb', line 1347

def x_delta=(delta)
  return unless default_x?
  symbol = x.is_a?(Array) ? x.first : x
  self.x = [symbol, delta]
end

#x_endObject

right-most x coordinate in this shape (adding up its width and location)



1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# File 'lib/glimmer/swt/custom/shape.rb', line 1226

def x_end
  x_end_dependencies = [calculated_width, default_x?, !default_x? && x]
  if x_end_dependencies != @x_end_dependencies
    # avoid recalculation of dependencies
    calculated_width, is_default_x, x = @x_end_dependencies = x_end_dependencies
    shape_width = calculated_width.to_f
    shape_x = is_default_x ? 0 : x.to_f
    @x_end = shape_x + shape_width
  end
  @x_end
end

#y_deltaObject



1332
1333
1334
1335
# File 'lib/glimmer/swt/custom/shape.rb', line 1332

def y_delta
  return 0 unless y.is_a?(Array) && default_y?
  y[1].to_f
end

#y_delta=(delta) ⇒ Object



1353
1354
1355
1356
1357
# File 'lib/glimmer/swt/custom/shape.rb', line 1353

def y_delta=(delta)
  return unless default_y?
  symbol = y.is_a?(Array) ? y.first : y
  self.y = [symbol, delta]
end

#y_endObject

bottom-most y coordinate in this shape (adding up its height and location)



1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
# File 'lib/glimmer/swt/custom/shape.rb', line 1239

def y_end
  y_end_dependencies = [calculated_height, default_y?, !default_y? && y]
  if y_end_dependencies != @y_end_dependencies
    # avoid recalculation of dependencies
    calculated_height, is_default_y, y = @y_end_dependencies = y_end_dependencies
    shape_height = calculated_height.to_f
    shape_y = is_default_y ? 0 : y.to_f
    @y_end = shape_y + shape_height
  end
  @y_end
end