shoes-swt 4.0.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +84 -0
- data/Gemfile +24 -0
- data/Guardfile +11 -0
- data/LICENSE +31 -0
- data/README.md +201 -0
- data/lib/shoes/swt.rb +118 -0
- data/lib/shoes/swt/animation.rb +46 -0
- data/lib/shoes/swt/app.rb +314 -0
- data/lib/shoes/swt/arc.rb +71 -0
- data/lib/shoes/swt/background.rb +41 -0
- data/lib/shoes/swt/border.rb +41 -0
- data/lib/shoes/swt/button.rb +18 -0
- data/lib/shoes/swt/check.rb +14 -0
- data/lib/shoes/swt/check_button.rb +19 -0
- data/lib/shoes/swt/color.rb +49 -0
- data/lib/shoes/swt/color_factory.rb +32 -0
- data/lib/shoes/swt/common/child.rb +16 -0
- data/lib/shoes/swt/common/clickable.rb +68 -0
- data/lib/shoes/swt/common/container.rb +28 -0
- data/lib/shoes/swt/common/fill.rb +38 -0
- data/lib/shoes/swt/common/painter.rb +92 -0
- data/lib/shoes/swt/common/painter_updates_position.rb +12 -0
- data/lib/shoes/swt/common/remove.rb +30 -0
- data/lib/shoes/swt/common/resource.rb +29 -0
- data/lib/shoes/swt/common/selection_listener.rb +14 -0
- data/lib/shoes/swt/common/stroke.rb +42 -0
- data/lib/shoes/swt/common/update_position.rb +15 -0
- data/lib/shoes/swt/common/visibility.rb +13 -0
- data/lib/shoes/swt/dialog.rb +90 -0
- data/lib/shoes/swt/disposed_protection.rb +23 -0
- data/lib/shoes/swt/download.rb +24 -0
- data/lib/shoes/swt/font.rb +32 -0
- data/lib/shoes/swt/gradient.rb +92 -0
- data/lib/shoes/swt/image.rb +128 -0
- data/lib/shoes/swt/image_pattern.rb +31 -0
- data/lib/shoes/swt/input_box.rb +73 -0
- data/lib/shoes/swt/key_listener.rb +145 -0
- data/lib/shoes/swt/line.rb +60 -0
- data/lib/shoes/swt/link.rb +31 -0
- data/lib/shoes/swt/link_segment.rb +111 -0
- data/lib/shoes/swt/list_box.rb +48 -0
- data/lib/shoes/swt/mouse_move_listener.rb +67 -0
- data/lib/shoes/swt/oval.rb +52 -0
- data/lib/shoes/swt/progress.rb +35 -0
- data/lib/shoes/swt/radio.rb +29 -0
- data/lib/shoes/swt/radio_group.rb +54 -0
- data/lib/shoes/swt/rect.rb +30 -0
- data/lib/shoes/swt/rect_painter.rb +23 -0
- data/lib/shoes/swt/redrawing_aspect.rb +123 -0
- data/lib/shoes/swt/shape.rb +133 -0
- data/lib/shoes/swt/shoes_layout.rb +43 -0
- data/lib/shoes/swt/slot.rb +39 -0
- data/lib/shoes/swt/sound.rb +119 -0
- data/lib/shoes/swt/star.rb +50 -0
- data/lib/shoes/swt/support/jl1.0.1.jar +0 -0
- data/lib/shoes/swt/support/jogg-0.0.7.jar +0 -0
- data/lib/shoes/swt/support/jorbis-0.0.15.jar +0 -0
- data/lib/shoes/swt/support/log4j-1.2.16.jar +0 -0
- data/lib/shoes/swt/support/mp3spi1.9.5.jar +0 -0
- data/lib/shoes/swt/support/tritonus_share.jar +0 -0
- data/lib/shoes/swt/support/vorbisspi1.0.3.jar +0 -0
- data/lib/shoes/swt/swt_button.rb +56 -0
- data/lib/shoes/swt/text_block.rb +124 -0
- data/lib/shoes/swt/text_block/centered_text_segment.rb +22 -0
- data/lib/shoes/swt/text_block/cursor_painter.rb +53 -0
- data/lib/shoes/swt/text_block/fitter.rb +212 -0
- data/lib/shoes/swt/text_block/painter.rb +47 -0
- data/lib/shoes/swt/text_block/text_font_factory.rb +50 -0
- data/lib/shoes/swt/text_block/text_segment.rb +108 -0
- data/lib/shoes/swt/text_block/text_segment_collection.rb +160 -0
- data/lib/shoes/swt/text_block/text_style_factory.rb +88 -0
- data/lib/shoes/swt/timer.rb +19 -0
- data/lib/shoes/swt/tooling/leak_hunter.rb +35 -0
- data/lib/shoes/swt/version.rb +5 -0
- data/manifests/common.rb +34 -0
- data/manifests/shoes-swt.rb +29 -0
- data/shoes-swt.gemspec +24 -0
- data/spec/code_coverage.rb +14 -0
- data/spec/shoes/animation_spec.rb +65 -0
- data/spec/shoes/app_spec.rb +484 -0
- data/spec/shoes/arc_spec.rb +51 -0
- data/spec/shoes/background_spec.rb +53 -0
- data/spec/shoes/border_spec.rb +47 -0
- data/spec/shoes/builtin_methods_spec.rb +110 -0
- data/spec/shoes/button_spec.rb +44 -0
- data/spec/shoes/check_spec.rb +35 -0
- data/spec/shoes/cli_spec.rb +15 -0
- data/spec/shoes/color_spec.rb +408 -0
- data/spec/shoes/common/inspect_spec.rb +26 -0
- data/spec/shoes/common/remove_spec.rb +38 -0
- data/spec/shoes/common/style_normalizer_spec.rb +28 -0
- data/spec/shoes/common/style_spec.rb +147 -0
- data/spec/shoes/configuration_spec.rb +36 -0
- data/spec/shoes/constants_spec.rb +38 -0
- data/spec/shoes/dialog_spec.rb +163 -0
- data/spec/shoes/dimension_spec.rb +407 -0
- data/spec/shoes/dimensions_spec.rb +837 -0
- data/spec/shoes/download_spec.rb +142 -0
- data/spec/shoes/flow_spec.rb +133 -0
- data/spec/shoes/font_spec.rb +37 -0
- data/spec/shoes/framework_learning_spec.rb +30 -0
- data/spec/shoes/gradient_spec.rb +32 -0
- data/spec/shoes/helpers/fake_element.rb +17 -0
- data/spec/shoes/helpers/inspect_helpers.rb +5 -0
- data/spec/shoes/helpers/sample17_helper.rb +66 -0
- data/spec/shoes/image_spec.rb +49 -0
- data/spec/shoes/images/shoe.jpg +0 -0
- data/spec/shoes/input_box_spec.rb +80 -0
- data/spec/shoes/integration_spec.rb +20 -0
- data/spec/shoes/internal_app_spec.rb +141 -0
- data/spec/shoes/keypress_spec.rb +11 -0
- data/spec/shoes/keyrelease_spec.rb +12 -0
- data/spec/shoes/line_spec.rb +49 -0
- data/spec/shoes/link_spec.rb +105 -0
- data/spec/shoes/list_box_spec.rb +74 -0
- data/spec/shoes/logger/ruby_spec.rb +8 -0
- data/spec/shoes/logger_spec.rb +45 -0
- data/spec/shoes/oval_spec.rb +24 -0
- data/spec/shoes/point_spec.rb +71 -0
- data/spec/shoes/progress_spec.rb +54 -0
- data/spec/shoes/radio_spec.rb +32 -0
- data/spec/shoes/rect_spec.rb +39 -0
- data/spec/shoes/renamed_delegate_spec.rb +70 -0
- data/spec/shoes/shape_spec.rb +95 -0
- data/spec/shoes/shared_examples/button.rb +6 -0
- data/spec/shoes/shared_examples/changeable.rb +26 -0
- data/spec/shoes/shared_examples/clickable.rb +5 -0
- data/spec/shoes/shared_examples/common_methods.rb +35 -0
- data/spec/shoes/shared_examples/dimensions.rb +32 -0
- data/spec/shoes/shared_examples/dsl.rb +44 -0
- data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
- data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
- data/spec/shoes/shared_examples/dsl/background.rb +26 -0
- data/spec/shoes/shared_examples/dsl/border.rb +10 -0
- data/spec/shoes/shared_examples/dsl/button.rb +5 -0
- data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
- data/spec/shoes/shared_examples/dsl/check.rb +11 -0
- data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
- data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
- data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
- data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
- data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
- data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
- data/spec/shoes/shared_examples/dsl/image.rb +21 -0
- data/spec/shoes/shared_examples/dsl/line.rb +9 -0
- data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
- data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
- data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
- data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
- data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
- data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
- data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
- data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
- data/spec/shoes/shared_examples/dsl/star.rb +48 -0
- data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
- data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
- data/spec/shoes/shared_examples/dsl/style.rb +32 -0
- data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
- data/spec/shoes/shared_examples/dsl/video.rb +5 -0
- data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
- data/spec/shoes/shared_examples/hover_leave.rb +11 -0
- data/spec/shoes/shared_examples/parent.rb +6 -0
- data/spec/shoes/shared_examples/scroll.rb +41 -0
- data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
- data/spec/shoes/shared_examples/slot.rb +331 -0
- data/spec/shoes/shared_examples/state.rb +19 -0
- data/spec/shoes/shared_examples/style.rb +82 -0
- data/spec/shoes/slot_spec.rb +130 -0
- data/spec/shoes/sound_spec.rb +15 -0
- data/spec/shoes/span_spec.rb +112 -0
- data/spec/shoes/spec_helper.rb +24 -0
- data/spec/shoes/stack_spec.rb +79 -0
- data/spec/shoes/star_spec.rb +31 -0
- data/spec/shoes/text_block_dimensions_spec.rb +75 -0
- data/spec/shoes/text_block_spec.rb +270 -0
- data/spec/shoes/url_spec.rb +68 -0
- data/spec/shoes/widget_spec.rb +70 -0
- data/spec/shoes_spec.rb +44 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/swt_shoes/animation_spec.rb +86 -0
- data/spec/swt_shoes/app_spec.rb +84 -0
- data/spec/swt_shoes/arc_spec.rb +103 -0
- data/spec/swt_shoes/background_spec.rb +67 -0
- data/spec/swt_shoes/border_spec.rb +52 -0
- data/spec/swt_shoes/button_spec.rb +101 -0
- data/spec/swt_shoes/check_spec.rb +28 -0
- data/spec/swt_shoes/color_factory_spec.rb +49 -0
- data/spec/swt_shoes/color_spec.rb +67 -0
- data/spec/swt_shoes/common/painter_spec.rb +49 -0
- data/spec/swt_shoes/common/remove_spec.rb +53 -0
- data/spec/swt_shoes/configuration_spec.rb +12 -0
- data/spec/swt_shoes/dialog_spec.rb +106 -0
- data/spec/swt_shoes/disposed_protection_spec.rb +49 -0
- data/spec/swt_shoes/flow_spec.rb +36 -0
- data/spec/swt_shoes/font_spec.rb +33 -0
- data/spec/swt_shoes/gradient_spec.rb +31 -0
- data/spec/swt_shoes/image_pattern_spec.rb +35 -0
- data/spec/swt_shoes/image_spec.rb +100 -0
- data/spec/swt_shoes/input_box_spec.rb +116 -0
- data/spec/swt_shoes/integration_spec.rb +27 -0
- data/spec/swt_shoes/key_listener_spec.rb +325 -0
- data/spec/swt_shoes/line_spec.rb +49 -0
- data/spec/swt_shoes/link_segment_spec.rb +120 -0
- data/spec/swt_shoes/link_spec.rb +54 -0
- data/spec/swt_shoes/list_box_spec.rb +56 -0
- data/spec/swt_shoes/minimal.png +0 -0
- data/spec/swt_shoes/mouse_move_listener_spec.rb +123 -0
- data/spec/swt_shoes/oval_spec.rb +51 -0
- data/spec/swt_shoes/progress_spec.rb +44 -0
- data/spec/swt_shoes/radio_group_spec.rb +73 -0
- data/spec/swt_shoes/radio_spec.rb +56 -0
- data/spec/swt_shoes/rect_painter_spec.rb +45 -0
- data/spec/swt_shoes/rect_spec.rb +19 -0
- data/spec/swt_shoes/shape_spec.rb +84 -0
- data/spec/swt_shoes/shared_examples/button.rb +21 -0
- data/spec/swt_shoes/shared_examples/clickable.rb +85 -0
- data/spec/swt_shoes/shared_examples/movable.rb +36 -0
- data/spec/swt_shoes/shared_examples/paintable.rb +7 -0
- data/spec/swt_shoes/shared_examples/painter.rb +83 -0
- data/spec/swt_shoes/shared_examples/pattern.rb +32 -0
- data/spec/swt_shoes/shared_examples/removable.rb +41 -0
- data/spec/swt_shoes/shared_examples/swt_app_context.rb +23 -0
- data/spec/swt_shoes/shared_examples/visibility.rb +15 -0
- data/spec/swt_shoes/shell_control_listener_spec.rb +23 -0
- data/spec/swt_shoes/slot_spec.rb +24 -0
- data/spec/swt_shoes/sound.rb +10 -0
- data/spec/swt_shoes/spec_helper.rb +31 -0
- data/spec/swt_shoes/star_spec.rb +47 -0
- data/spec/swt_shoes/text_block/centered_text_segment_spec.rb +16 -0
- data/spec/swt_shoes/text_block/cursor_painter_spec.rb +120 -0
- data/spec/swt_shoes/text_block/fitter_spec.rb +213 -0
- data/spec/swt_shoes/text_block/painter_spec.rb +212 -0
- data/spec/swt_shoes/text_block/text_font_factory_spec.rb +40 -0
- data/spec/swt_shoes/text_block/text_segment_collection_spec.rb +256 -0
- data/spec/swt_shoes/text_block/text_segment_spec.rb +135 -0
- data/spec/swt_shoes/text_block_spec.rb +199 -0
- metadata +496 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Border
|
|
4
|
+
extend Forwardable
|
|
5
|
+
include Common::Fill
|
|
6
|
+
include Common::Stroke
|
|
7
|
+
include Common::Remove
|
|
8
|
+
include Common::Visibility
|
|
9
|
+
include ::Shoes::BackendDimensionsDelegations
|
|
10
|
+
|
|
11
|
+
def_delegators :dsl, :angle
|
|
12
|
+
|
|
13
|
+
attr_reader :app, :dsl, :painter, :transform
|
|
14
|
+
|
|
15
|
+
def initialize(dsl, app)
|
|
16
|
+
@dsl = dsl
|
|
17
|
+
@app = app
|
|
18
|
+
@container = @app.real
|
|
19
|
+
|
|
20
|
+
@painter = Painter.new(self)
|
|
21
|
+
@app.add_paint_listener @painter
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def corners
|
|
25
|
+
dsl.curve
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class Painter < RectPainter
|
|
29
|
+
|
|
30
|
+
def fill_setup(gc)
|
|
31
|
+
# don't draw
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def draw_setup(gc)
|
|
35
|
+
@obj.apply_stroke gc
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Button < SwtButton
|
|
4
|
+
include Common::Child
|
|
5
|
+
|
|
6
|
+
# Create a button
|
|
7
|
+
#
|
|
8
|
+
# @param [Shoes::Button] dsl The Shoes DSL button this represents
|
|
9
|
+
# @param [::Swt::Widgets::Composite] parent The parent element of this button
|
|
10
|
+
# @param [Proc] blk The block of code to call when this button is activated
|
|
11
|
+
def initialize(dsl, parent)
|
|
12
|
+
super(dsl, parent, ::Swt::SWT::PUSH) do |button|
|
|
13
|
+
button.set_text @dsl.text
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Check < CheckButton
|
|
4
|
+
# Create a check box
|
|
5
|
+
#
|
|
6
|
+
# @param [Shoes::Button] dsl The Shoes DSL check box this represents
|
|
7
|
+
# @param [::Swt::Widgets::Composite] parent The parent element of this button
|
|
8
|
+
# @param [Proc] blk The block of code to call when this button is activated
|
|
9
|
+
def initialize(dsl, parent)
|
|
10
|
+
super(dsl, parent, ::Swt::SWT::CHECK)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class CheckButton < SwtButton
|
|
4
|
+
include Common::Child
|
|
5
|
+
|
|
6
|
+
def initialize(dsl, parent, type)
|
|
7
|
+
super(dsl, parent, type)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def checked?
|
|
11
|
+
@real.get_selection
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def checked=(bool)
|
|
15
|
+
@real.set_selection bool
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Color
|
|
4
|
+
include DisposedProtection
|
|
5
|
+
|
|
6
|
+
def self.create(color)
|
|
7
|
+
color ? new(color) : NullColor.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# @param [Shoes::Color] color the DSL representation of this color
|
|
11
|
+
def initialize(color)
|
|
12
|
+
@dsl = color
|
|
13
|
+
@real = ::Swt::Graphics::Color.new(Shoes.display, @dsl.red, @dsl.green, @dsl.blue)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def dispose
|
|
17
|
+
@real.dispose unless @real.disposed?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
attr_reader :dsl
|
|
21
|
+
|
|
22
|
+
# @return [Integer] the alpha value, from 0 (transparent) to 255 (opaque)
|
|
23
|
+
def alpha
|
|
24
|
+
@dsl.alpha
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @param [Swt::Graphics::GC] gc the graphics context on which to apply fill
|
|
28
|
+
# @note left, top, width, height, and angle are not used in this method, and only
|
|
29
|
+
# exist to satisfy the Pattern interface
|
|
30
|
+
def apply_as_fill(gc, left = nil, top = nil, width = nil, height = nil, angle = nil)
|
|
31
|
+
gc.set_background real
|
|
32
|
+
gc.set_alpha alpha
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @param [Swt::Graphics::GC] gc the graphics context on which to apply stroke
|
|
36
|
+
def apply_as_stroke(gc, left = nil, top = nil, width = nil, height = nil, angle = nil)
|
|
37
|
+
gc.set_foreground real
|
|
38
|
+
gc.set_alpha alpha
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class NullColor
|
|
43
|
+
attr_reader :alpha, :dsl, :real
|
|
44
|
+
def apply_as_fill(gc); end
|
|
45
|
+
def apply_as_stroke(gc); end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
# ColorFactory is used for tracking SWT-backed resources related to colors
|
|
4
|
+
# that potentially need to get disposed. It can additionally take gradients
|
|
5
|
+
# and maybe other values, though, so it can't assume values will be
|
|
6
|
+
# disposable.
|
|
7
|
+
#
|
|
8
|
+
# Additionally this factory does caching against the DSL element so we
|
|
9
|
+
# don't needlessly generate things like OS colors over and over again.
|
|
10
|
+
class ColorFactory
|
|
11
|
+
def initialize
|
|
12
|
+
@swt_elements = {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def dispose
|
|
16
|
+
@swt_elements.each_value do |swt_element|
|
|
17
|
+
swt_element.dispose if swt_element.respond_to?(:dispose)
|
|
18
|
+
end
|
|
19
|
+
@swt_elements.clear
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create(element)
|
|
23
|
+
return nil if element.nil?
|
|
24
|
+
return @swt_elements[element] if @swt_elements.include?(element)
|
|
25
|
+
|
|
26
|
+
swt_element = ::Shoes.configuration.backend_for(element)
|
|
27
|
+
@swt_elements[element] = swt_element
|
|
28
|
+
swt_element
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
# Behavior for elements that act as children of other elements
|
|
5
|
+
module Child
|
|
6
|
+
# Finds the current app by asking parent elements, all the way
|
|
7
|
+
# up to the App
|
|
8
|
+
#
|
|
9
|
+
# @return [Shoes::Swt::App] The current app
|
|
10
|
+
def app
|
|
11
|
+
parent.app
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
module Clickable
|
|
5
|
+
|
|
6
|
+
attr_accessor :click_listener
|
|
7
|
+
|
|
8
|
+
# object = self is there for compatibility reasons for now
|
|
9
|
+
# it's for link (defined in text.rb) and the listener is added in the
|
|
10
|
+
# swt/text_block.rb ... moving it around would be too hard now
|
|
11
|
+
def clickable(object = self, block)
|
|
12
|
+
add_listener_for object, ::Swt::SWT::MouseDown, block
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def click(block)
|
|
16
|
+
remove_listener_for ::Swt::SWT::MouseDown
|
|
17
|
+
add_listener_for ::Swt::SWT::MouseDown, block
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def release(block)
|
|
21
|
+
remove_listener_for ::Swt::SWT::MouseUp
|
|
22
|
+
add_listener_for ::Swt::SWT::MouseUp, block
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def add_listener_for(swt_object = self, event, block)
|
|
27
|
+
# dsl objects take care of in bounds checking etc.
|
|
28
|
+
dsl_object = swt_object.dsl
|
|
29
|
+
listener = ClickListener.new(dsl_object, block)
|
|
30
|
+
swt_object.click_listener = listener
|
|
31
|
+
app.add_clickable_element dsl_object
|
|
32
|
+
app.add_listener event, listener
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def remove_listener_for(swt_object = self, event)
|
|
36
|
+
dsl_object = swt_object.dsl
|
|
37
|
+
app.clickable_elements.delete(dsl_object)
|
|
38
|
+
app.remove_listener event, swt_object.click_listener
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class ClickListener
|
|
42
|
+
include ::Swt::Widgets::Listener
|
|
43
|
+
|
|
44
|
+
def initialize(clickable_object, block)
|
|
45
|
+
@clickable_object = clickable_object
|
|
46
|
+
@block = block
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def handleEvent(mouse_event)
|
|
50
|
+
return if @clickable_object.respond_to?(:hidden?) && @clickable_object.hidden?
|
|
51
|
+
if @clickable_object.in_bounds?(mouse_event.x, mouse_event.y)
|
|
52
|
+
eval_block mouse_event
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def eval_block(mouse_event)
|
|
57
|
+
if @clickable_object.pass_coordinates?
|
|
58
|
+
@block.call mouse_event.button, mouse_event.x, mouse_event.y
|
|
59
|
+
else
|
|
60
|
+
@block.call @clickable_object
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
# Container methods
|
|
5
|
+
module Container
|
|
6
|
+
# Adds a painter to be executed when this object needs to be
|
|
7
|
+
# repainted. Delegates to `@real`
|
|
8
|
+
#
|
|
9
|
+
# @param [Painter] painter The code to be executed on paint
|
|
10
|
+
def add_paint_listener(painter)
|
|
11
|
+
@real.add_paint_listener painter
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def remove_paint_listener(painter)
|
|
15
|
+
@real.remove_paint_listener painter if painter
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_listener(event, listener)
|
|
19
|
+
@real.add_listener event, listener
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove_listener(event, listener)
|
|
23
|
+
@real.remove_listener event, listener if listener
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
# Methods for retrieving fill values from a Shoes DSL class
|
|
5
|
+
#
|
|
6
|
+
# @note Including classes must provide `#dsl`
|
|
7
|
+
module Fill
|
|
8
|
+
# This object's fill color
|
|
9
|
+
#
|
|
10
|
+
# @return [Swt::Graphics::Color] The Swt representation of this object's fill color
|
|
11
|
+
def fill
|
|
12
|
+
@color_factory ||= ::Shoes::Swt::ColorFactory.new
|
|
13
|
+
@color_factory.create(dsl.fill)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# This object's fill alpha value
|
|
17
|
+
#
|
|
18
|
+
# @return [Integer] The alpha value of this object's fill color (0-255)
|
|
19
|
+
def fill_alpha
|
|
20
|
+
fill.alpha
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Integer] the angle to use when filling with a pattern
|
|
24
|
+
def angle
|
|
25
|
+
@angle || 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def apply_fill(context)
|
|
29
|
+
if fill
|
|
30
|
+
left, top = self.is_a?(Star) ? [element_left - element_width/2.0, element_top - element_height/2.0] : [element_left, element_top]
|
|
31
|
+
fill.apply_as_fill(context, left, top, element_width, element_height, angle)
|
|
32
|
+
true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
class Painter
|
|
5
|
+
include ::Swt::Events::PaintListener
|
|
6
|
+
include Resource
|
|
7
|
+
|
|
8
|
+
LINECAP = {
|
|
9
|
+
curve: ::Swt::SWT::CAP_ROUND,
|
|
10
|
+
rect: ::Swt::SWT::CAP_FLAT,
|
|
11
|
+
project: ::Swt::SWT::CAP_SQUARE
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def initialize(obj)
|
|
15
|
+
@obj = obj
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def paint_control(event)
|
|
19
|
+
graphics_context = event.gc
|
|
20
|
+
reset_graphics_context graphics_context
|
|
21
|
+
if @obj.dsl.visible? && @obj.dsl.positioned?
|
|
22
|
+
paint_object graphics_context
|
|
23
|
+
end
|
|
24
|
+
rescue => e
|
|
25
|
+
# Really important to rescue here. Failures that escape this method
|
|
26
|
+
# cause odd-ball hangs with no backtraces. See #559 for an example.
|
|
27
|
+
#
|
|
28
|
+
puts "SWALLOWED PAINT EXCEPTION ON #{@obj} - go take care of it: " + e.to_s
|
|
29
|
+
puts 'Unfortunately we have to swallow it because it causes odd failures :('
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def paint_object(graphics_context)
|
|
33
|
+
cap = LINECAP[@obj.dsl.style[:cap]]
|
|
34
|
+
graphics_context.set_line_cap(cap) if cap
|
|
35
|
+
graphics_context.set_transform(@obj.transform)
|
|
36
|
+
obj = @obj.dsl
|
|
37
|
+
case obj
|
|
38
|
+
when ::Shoes::Oval, ::Shoes::Rect
|
|
39
|
+
set_rotate graphics_context, obj.rotate,
|
|
40
|
+
obj.element_left + obj.element_width/2.0,
|
|
41
|
+
obj.element_top + obj.element_height/2.0 do
|
|
42
|
+
fill graphics_context if fill_setup(graphics_context)
|
|
43
|
+
draw graphics_context if draw_setup(graphics_context)
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
fill graphics_context if fill_setup(graphics_context)
|
|
47
|
+
draw graphics_context if draw_setup(graphics_context)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Override in subclass and return something falsy if not using fill
|
|
52
|
+
def fill_setup(graphics_context)
|
|
53
|
+
@obj.apply_fill(graphics_context)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Implement in subclass
|
|
57
|
+
def fill(graphics_context)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Override in subclass and return something falsy if not using draw
|
|
61
|
+
def draw_setup(graphics_context)
|
|
62
|
+
@obj.apply_stroke(graphics_context)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Implement in subclass
|
|
66
|
+
def draw(graphics_context)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def set_rotate graphics_context, angle, left, top
|
|
70
|
+
angle, left, top = angle.to_i, left.to_i, top.to_i
|
|
71
|
+
if block_given?
|
|
72
|
+
begin
|
|
73
|
+
transform = ::Swt::Transform.new Shoes.display
|
|
74
|
+
reset_rotate transform, graphics_context, angle, left, top
|
|
75
|
+
yield
|
|
76
|
+
reset_rotate transform, graphics_context, -angle, left, top
|
|
77
|
+
ensure
|
|
78
|
+
transform.dispose unless transform.nil? || transform.disposed?
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def reset_rotate transform, graphics_context, angle, left, top
|
|
84
|
+
transform.translate left, top
|
|
85
|
+
transform.rotate angle
|
|
86
|
+
transform.translate -left, -top
|
|
87
|
+
graphics_context.setTransform transform
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
module PainterUpdatesPosition
|
|
5
|
+
# No-op. This object manages its own position with its own painter. The
|
|
6
|
+
# painter is triggered automatically in the event loop.
|
|
7
|
+
def update_position
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|