Module: SugarCube::CGRectExtensions
- Included in:
- CGRect, SugarCube::CoreGraphics::Rect
- Defined in:
- lib/sugarcube/core_graphics.rb
Overview
Extensions to make CGRect a “real class”
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#+(rect) ⇒ Object
# returns an intersection of self and rect, or moves the Rect using Point, or increases the size using Size.
- #==(rect) ⇒ Object
- #bottom ⇒ Object
- #center ⇒ Object
- #contains?(rect_or_point) ⇒ Boolean
- #empty? ⇒ Boolean
- #height ⇒ Object
- #infinite? ⇒ Boolean
- #inspect ⇒ Object
- #intersection(rect) ⇒ Object
- #intersects?(rect_or_point) ⇒ Boolean
- #left ⇒ Object
- #null? ⇒ Boolean
- #right ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #top ⇒ Object
- #width ⇒ Object
Class Method Details
.included(base) ⇒ Object
28 29 30 |
# File 'lib/sugarcube/core_graphics.rb', line 28 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#+(rect) ⇒ Object
# returns an intersection of self and rect, or moves the Rect using Point, or increases the size using Size
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sugarcube/core_graphics.rb', line 84 def +(rect) case rect when SugarCube::CoreGraphics::Rect, CGRect SugarCube::CoreGraphics::Rect(CGRectUnion(self, rect)) when SugarCube::CoreGraphics::Point, CGPoint SugarCube::CoreGraphics::Rect(CGRectOffset(self, rect.x, rect.y)) when SugarCube::CoreGraphics::Offset, UIOffset SugarCube::CoreGraphics::Rect(CGRectOffset(self, rect.horizontal, rect.vertical)) when SugarCube::CoreGraphics::Size, CGSize SugarCube::CoreGraphics::Rect(CGRectInset(self, - rect.width, - rect.height)) when SugarCube::CoreGraphics::EdgeInsets, UIEdgeInsets SugarCube::CoreGraphics::Rect(UIEdgeInsetsInsetRect(self, rect)) else super end end |
#==(rect) ⇒ Object
127 128 129 |
# File 'lib/sugarcube/core_graphics.rb', line 127 def ==(rect) CGRectEqualToRect(self, rect) end |
#bottom ⇒ Object
60 61 62 |
# File 'lib/sugarcube/core_graphics.rb', line 60 def bottom return CGRectGetMaxY(self) end |
#center ⇒ Object
68 69 70 |
# File 'lib/sugarcube/core_graphics.rb', line 68 def center return SugarCube::CoreGraphics::Point(CGRectGetMidX(self), CGRectGetMidY(self)) end |
#contains?(rect_or_point) ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/sugarcube/core_graphics.rb', line 116 def contains?(rect_or_point) case rect_or_point when SugarCube::CoreGraphics::Point, CGPoint CGRectContainsPoint(self, rect_or_point) when Array, CGRect CGRectContainsRect(self, rect_or_point) else super end end |
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/sugarcube/core_graphics.rb', line 32 def empty? CGRectIsEmpty(self) end |
#height ⇒ Object
64 65 66 |
# File 'lib/sugarcube/core_graphics.rb', line 64 def height return CGRectGetHeight(self) end |
#infinite? ⇒ Boolean
36 37 38 |
# File 'lib/sugarcube/core_graphics.rb', line 36 def infinite? self.size.infinite? end |
#inspect ⇒ Object
80 |
# File 'lib/sugarcube/core_graphics.rb', line 80 def inspect ; to_s ; end |
#intersection(rect) ⇒ Object
101 102 103 |
# File 'lib/sugarcube/core_graphics.rb', line 101 def intersection(rect) SugarCube::CoreGraphics::Rect(CGRectIntersection(self, rect)) end |
#intersects?(rect_or_point) ⇒ Boolean
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/sugarcube/core_graphics.rb', line 105 def intersects?(rect_or_point) case rect_or_point when SugarCube::CoreGraphics::Point, CGPoint CGRectContainsPoint(self, rect_or_point) when Array, CGRect CGRectIntersectsRect(self, rect_or_point) else super end end |
#left ⇒ Object
44 45 46 |
# File 'lib/sugarcube/core_graphics.rb', line 44 def left return CGRectGetMinX(self) end |
#null? ⇒ Boolean
40 41 42 |
# File 'lib/sugarcube/core_graphics.rb', line 40 def null? CGRectIsNull(self) end |
#right ⇒ Object
48 49 50 |
# File 'lib/sugarcube/core_graphics.rb', line 48 def right return CGRectGetMaxX(self) end |
#to_hash ⇒ Object
76 77 78 |
# File 'lib/sugarcube/core_graphics.rb', line 76 def to_hash CGRectCreateDictionaryRepresentation(self) end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/sugarcube/core_graphics.rb', line 72 def to_s "#{self.class.name}([#{self.origin.x}, #{self.origin.y}],{#{self.size.width} × #{self.size.height}})" end |
#top ⇒ Object
56 57 58 |
# File 'lib/sugarcube/core_graphics.rb', line 56 def top return CGRectGetMinY(self) end |
#width ⇒ Object
52 53 54 |
# File 'lib/sugarcube/core_graphics.rb', line 52 def width return CGRectGetWidth(self) end |