Module: Glimmer::SWT::Custom::Drawable

Included in:
DisplayProxy, ImageProxy, WidgetProxy
Defined in:
lib/glimmer/swt/custom/drawable.rb

Overview

Represents SWT drawable controls (widgets like canvas) and display

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#image_double_bufferedObject Also known as: image_double_buffered?

Returns the value of attribute image_double_buffered.



27
28
29
# File 'lib/glimmer/swt/custom/drawable.rb', line 27

def image_double_buffered
  @image_double_buffered
end

#requires_shape_disposalObject Also known as: requires_shape_disposal?

Returns the value of attribute requires_shape_disposal.



27
28
29
# File 'lib/glimmer/swt/custom/drawable.rb', line 27

def requires_shape_disposal
  @requires_shape_disposal
end

Instance Method Details

#add_shape(shape) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/glimmer/swt/custom/drawable.rb', line 41

def add_shape(shape)
  if !@image_double_buffered || shape.args.first == @image_proxy_buffer
    shapes << shape
  else
    image_buffered_shapes << shape
  end
end

#clear_shapesObject



49
50
51
52
# File 'lib/glimmer/swt/custom/drawable.rb', line 49

def clear_shapes
  # Optimize further by having a collection of disposable_shapes independent of shapes, which is much smaller and only has shapes that require disposal (shapes with patterns or image)
  shapes.dup.each(&:dispose) if requires_shape_disposal?
end

#deregister_shape_paintingObject



54
55
56
# File 'lib/glimmer/swt/custom/drawable.rb', line 54

def deregister_shape_painting
  @paint_listener_proxy&.deregister
end

#image_buffered_shapesObject



37
38
39
# File 'lib/glimmer/swt/custom/drawable.rb', line 37

def image_buffered_shapes
  @image_buffered_shapes ||= []
end

#setup_shape_paintingObject Also known as: resetup_shape_painting



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/glimmer/swt/custom/drawable.rb', line 58

def setup_shape_painting
  # TODO consider performance optimization relating to order of shape rendering (affecting only further shapes not previous ones)
  if @paint_listener_proxy.nil?
    shape_painter = lambda do |paint_event|
      shape_painting_work = lambda do |paint_event|
        paintable_shapes = @image_double_buffered ? image_buffered_shapes : shapes
        paintable_shapes.each do |shape|
          shape.paint(paint_event)
        end
      end
      if @image_double_buffered
        if @image_proxy_buffer.nil?
          swt_image = Image.new(DisplayProxy.instance.swt_display, bounds.width, bounds.height)
          @image_proxy_buffer = ImageProxy.new(swt_image: swt_image)
          shape_painting_work.call(@image_proxy_buffer)
        end
        @image_proxy_buffer.shape(self).paint(paint_event)
      else
        shape_painting_work.call(paint_event)
      end
    end
    
    # TODO consider making this logic polymorphic (image vs other)
    if respond_to?(:swt_image)
      shape_painter.call(self) # treat self as paint event since image has its own gc and doesn't do repaints (it's a one time deal for now though could be adjusted in the future.)
    else
      @paint_listener_proxy = on_swt_paint(&shape_painter)
    end
  else
    redraw if @finished_add_content && !is_disposed
  end
end

#shapesObject



33
34
35
# File 'lib/glimmer/swt/custom/drawable.rb', line 33

def shapes
  @shapes ||= []
end