Class: CTioga2::Graphics::Types::MarginsBox
- Defined in:
- lib/ctioga2/graphics/types/boxes.rb
Overview
A box defined by its margins
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Margin specifications.
-
#left ⇒ Object
Margin specifications.
-
#right ⇒ Object
Margin specifications.
-
#top ⇒ Object
Margin specifications.
Instance Method Summary collapse
-
#expand_to!(t, other) ⇒ Object
Augments the margins so that they also encompass those given in other.
-
#initialize(left, right, top, bottom) ⇒ MarginsBox
constructor
Creates a new MarginsBox object with the specified margins, as String (passed on to Dimension::to_text), float (defaults to frame coordinates) or directly as Dimension objects.
-
#margins ⇒ Object
Returns the dimensions composing the MarginsBox, in the order left, right, top, bottom, suitable for feeding to MarginsBox.new.
- #to_frame_coordinates(t) ⇒ Object
-
#to_output(t, fact = 1.0) ⇒ Object
Converts to output coordinates.
Methods inherited from Box
Constructor Details
#initialize(left, right, top, bottom) ⇒ MarginsBox
Creates a new MarginsBox object with the specified margins, as String (passed on to Dimension::to_text), float (defaults to frame coordinates) or directly as Dimension objects.
The Dimension’s orientation is automatically tweaked.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 61 def initialize(left, right, top, bottom) # First, convert any float into Dimension: a = [left, right, top, bottom] a.each_index do |i| if ! a[i].is_a? Dimension a[i] = Dimension::from_text(a[i].to_s, :x, :frame) end end left, right, top, bottom = a # Then assign to the appropriate stuff: @left = left @left.orientation = :x @right = right @right.orientation = :x @top = top @top.orientation = :y @bottom = bottom @bottom.orientation = :y end |
Instance Attribute Details
#bottom ⇒ Object
Margin specifications. These are Dimension objects.
54 55 56 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 54 def bottom @bottom end |
#left ⇒ Object
Margin specifications. These are Dimension objects.
54 55 56 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 54 def left @left end |
#right ⇒ Object
Margin specifications. These are Dimension objects.
54 55 56 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 54 def right @right end |
#top ⇒ Object
Margin specifications. These are Dimension objects.
54 55 56 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 54 def top @top end |
Instance Method Details
#expand_to!(t, other) ⇒ Object
Augments the margins so that they also encompass those given in other. Based on the current interpretation of the measures as bp.
110 111 112 113 114 115 116 117 118 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 110 def (t, other) for w in %w(left right top bottom) mine = self.send(w) theirs = other.send(w) if mine.to_bp(t) < theirs.to_bp(t) self.send("#{w}=", theirs) end end end |
#margins ⇒ Object
Returns the dimensions composing the MarginsBox, in the order left, right, top, bottom, suitable for feeding to MarginsBox.new.
103 104 105 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 103 def margins return [@left, @right, @top, @bottom] end |
#to_frame_coordinates(t) ⇒ Object
82 83 84 85 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 82 def to_frame_coordinates(t) return [@left.to_frame(t), 1 - @top.to_frame(t), 1 - @right.to_frame(t), @bottom.to_frame(t)] end |
#to_output(t, fact = 1.0) ⇒ Object
Converts to output coordinates
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ctioga2/graphics/types/boxes.rb', line 88 def to_output(t, fact = 1.0) a = to_frame_coordinates(t) 4.times do |i| a[i] = if (i % 2 == 0) fact * t.convert_page_to_output_x(t.convert_frame_to_page_x(a[i])) else fact * t.convert_page_to_output_y(t.convert_frame_to_page_y(a[i])) end end return a end |