Class: PREP::Core::Rectangle
Overview
矩形描画構成要素クラス
Direct Known Subclasses
Constant Summary collapse
- STYLES =
{ :solid => "solid", }
- FILL_PATTERNS =
{ :flat => "flat", }
- @@default_values =
{ :line_color => { :red => 0, :green => 0, :blue => 0 }, :line_width => 1, :line_style => STYLES[:solid], :fill_pattern => FILL_PATTERNS[:flat], :fill_color => { :red => 1, :green => 1, :blue => 1 }, :layer => 1, :expand => false, :control_visible => false, }
Instance Attribute Summary collapse
-
#expand ⇒ Object
readonly
Returns the value of attribute expand.
-
#fill_color ⇒ Object
readonly
Returns the value of attribute fill_color.
-
#fill_pattern ⇒ Object
Returns the value of attribute fill_pattern.
-
#line_color ⇒ Object
readonly
Returns the value of attribute line_color.
-
#line_style ⇒ Object
Returns the value of attribute line_style.
-
#line_width ⇒ Object
Returns the value of attribute line_width.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Attributes inherited from Drawable
Instance Method Summary collapse
- #calculate_region(prep, region, value, stop_on_drawable = nil) ⇒ Object
-
#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object
矩形の描画.
- #expand_region(setting) ⇒ Object
-
#initialize(identifier, values = { }) ⇒ Rectangle
constructor
A new instance of Rectangle.
Methods inherited from Drawable
#<=>, #calculate_pos, #key_string_to_symbol, #rewind_current_page, #visible?
Constructor Details
#initialize(identifier, values = { }) ⇒ Rectangle
Returns a new instance of Rectangle.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/core/rectangle.rb', line 37 def initialize(identifier, values = { }) values = @@default_values.merge(key_string_to_symbol(values)) super(identifier, values[:layer]) @region = Region.new(values[:region][:x].mm2pixcel, values[:region][:y].mm2pixcel, values[:region][:width].mm2pixcel, values[:region][:height].mm2pixcel) @line_color = Color.new(values[:line_color][:red], values[:line_color][:green], values[:line_color][:blue]) self.line_style = values[:line_style] self.fill_pattern = values[:fill_pattern] @fill_color = Color.new(values[:fill_color][:red], values[:fill_color][:green], values[:fill_color][:blue]) self.line_width = values[:line_width] @expand = values[:expand] @control_visible = values[:control_visible] end |
Instance Attribute Details
#expand ⇒ Object (readonly)
Returns the value of attribute expand.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def @expand end |
#fill_color ⇒ Object (readonly)
Returns the value of attribute fill_color.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def fill_color @fill_color end |
#fill_pattern ⇒ Object
Returns the value of attribute fill_pattern.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def fill_pattern @fill_pattern end |
#line_color ⇒ Object (readonly)
Returns the value of attribute line_color.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def line_color @line_color end |
#line_style ⇒ Object
Returns the value of attribute line_style.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def line_style @line_style end |
#line_width ⇒ Object
Returns the value of attribute line_width.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def line_width @line_width end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
35 36 37 |
# File 'lib/core/rectangle.rb', line 35 def region @region end |
Instance Method Details
#calculate_region(prep, region, value, stop_on_drawable = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/core/rectangle.rb', line 90 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"] ret_region = Region.new(0, 0, region.width - (@region.x + @region.width), region.height - (@region.y + @region.height)) return @region.x + @region.width, @region.y + @region.height end |
#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object
矩形の描画
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/core/rectangle.rb', line 102 def draw(prep, region, values, 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, values) if visible?(values) prep.current_page.set_line_width(@line_width.to_f) unless @line_color.white? prep.current_page.set_rgb_stroke(@line_color.red.to_f, @line_color.green.to_f, @line_color.blue.to_f) end unless @fill_color.white? prep.current_page.set_rgb_fill(@fill_color.red.to_f, @fill_color.green.to_f, @fill_color.blue.to_f) end end region_backup = @region.dup if @expand_region @region = @expand_region.dup @expand_region = nil end pos_x, pos_y = calculate_pos(prep.current_page, region, @region.x, @region.y) if visible?(values) prep.current_page.rectangle(pos_x, pos_y - @region.height, @region.width, @region.height) fill_and_or_stroke(prep) end @region = region_backup prep.current_page.drawed = true end |
#expand_region(setting) ⇒ Object
58 59 60 61 62 |
# File 'lib/core/rectangle.rb', line 58 def (setting) @expand_region = @region.dup @expand_region.width = setting[:width] if setting[:width] @expand_region.height = setting[:height] if setting[:height] end |