Class: PREP::Core::Line
Overview
直線描画構成要素クラス
Constant Summary collapse
- STYLES =
{ :solid => "solid", }
- @@default_values =
{ :color => { :red => 0, :green => 0, :blue => 0 }, :width => 1, :style => STYLES[:solid], :layer => 2, :control_visible => false, }
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#end_point ⇒ Object
readonly
Returns the value of attribute end_point.
-
#start_point ⇒ Object
readonly
Returns the value of attribute start_point.
-
#style ⇒ Object
Returns the value of attribute style.
-
#width ⇒ Object
Returns the value of attribute width.
Attributes inherited from Drawable
Instance Method Summary collapse
- #calculate_region(prep, region, value, stop_on_drawable = nil) ⇒ Object
-
#draw(prep, region, value, stop_on_drawable = nil) ⇒ Object
直線の描画.
-
#initialize(identifier, values = { }) ⇒ Line
constructor
A new instance of Line.
Methods inherited from Drawable
#<=>, #calculate_pos, #key_string_to_symbol, #rewind_current_page, #visible?
Constructor Details
#initialize(identifier, values = { }) ⇒ Line
Returns a new instance of Line.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/core/line.rb', line 30 def initialize(identifier, values = { }) values = @@default_values.merge(key_string_to_symbol(values)) super(identifier, values[:layer]) @start_point = Point.new(values[:start][:x].mm2pixcel, values[:start][:y].mm2pixcel) @end_point = Point.new(values[:end][:x].mm2pixcel, values[:end][:y].mm2pixcel) @color = Color.new(values[:color][:red], values[:color][:green], values[:color][:blue]) self.width = values[:width] self.style = values[:style] @control_visible = values[:control_visible] end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
28 29 30 |
# File 'lib/core/line.rb', line 28 def color @color end |
#end_point ⇒ Object (readonly)
Returns the value of attribute end_point.
28 29 30 |
# File 'lib/core/line.rb', line 28 def end_point @end_point end |
#start_point ⇒ Object (readonly)
Returns the value of attribute start_point.
28 29 30 |
# File 'lib/core/line.rb', line 28 def start_point @start_point end |
#style ⇒ Object
Returns the value of attribute style.
28 29 30 |
# File 'lib/core/line.rb', line 28 def style @style end |
#width ⇒ Object
Returns the value of attribute width.
28 29 30 |
# File 'lib/core/line.rb', line 28 def width @width end |
Instance Method Details
#calculate_region(prep, region, value, stop_on_drawable = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/core/line.rb', line 58 def calculate_region(prep, region, value, stop_on_drawable = nil) if self === stop_on_drawable raise ReRenderJump.new(region) end puts "Calculate region for #{self.class}: #{self.identifier} region: #{region}" if ENV["DEBUG"] width = [@start_point.x, @end_point.x].max height = [@start_point.y, @end_point.y].max ret_region = Region.new(0, 0, region.width - width, region.height - height) return width, height end |
#draw(prep, region, value, stop_on_drawable = nil) ⇒ Object
直線の描画
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/core/line.rb', line 73 def draw(prep, region, value, stop_on_drawable = nil) if self === stop_on_drawable raise ReRenderJump.new(region) end STDERR.puts("Draw on #{self.class} #{self.identifier}") if ENV['DEBUG'] # 領域判定 calculate_region(prep, region, value) if visible?(value) # 幅指定 prep.current_page.set_line_width(@width) # 色指定 prep.current_page.set_rgb_stroke(@color.red.to_f, @color.green.to_f, @color.blue.to_f) # 開始位置へ移動 start_x, start_y = calculate_pos(prep.current_page, region, @start_point.x.to_f, @start_point.y.to_f) end_x, end_y = calculate_pos(prep.current_page, region, @end_point.x.to_f, @end_point.y.to_f) prep.current_page.move_to(start_x, start_y) # 終了位置へ向けて直線描画 prep.current_page.line_to(end_x, end_y) # 実描画 prep.current_page.stroke end prep.current_page.drawed = true end |