Class: Fox::Canvas::Shape
- Inherits:
-
Object
- Object
- Fox::Canvas::Shape
- Defined in:
- lib/fox16/canvas.rb
Direct Known Subclasses
CircleShape, ImageShape, LineShape, PolygonShape, RectangleShape, TextShape
Instance Attribute Summary collapse
-
#foreground ⇒ Object
Returns the value of attribute foreground.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#target ⇒ Object
Returns the value of attribute target.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #apply_dc(dc) ⇒ Object protected
-
#bounds ⇒ Object
Return the bounding box for this shape.
-
#deselect ⇒ Object
Deselect this shape.
-
#disable ⇒ Object
Disable this shape.
-
#draggable=(d) ⇒ Object
Set this shape’s draggability.
-
#draggable? ⇒ Boolean
Is this shape draggable?.
-
#draw(dc) ⇒ Object
Draw this shape into the specificed device context.
-
#drawOutline(dc, x, y, w, h) ⇒ Object
Draws outline.
-
#enable ⇒ Object
Enable this shape.
-
#enabled? ⇒ Boolean
Is this shape enabled?.
-
#hide ⇒ Object
Hide this shape.
-
#hit?(xpos, ypos) ⇒ Boolean
Hit test.
-
#initialize(x, y) ⇒ Shape
constructor
A new instance of Shape.
-
#makeControlPoints ⇒ Object
Default: make 6 control points.
-
#move(x, y) ⇒ Object
Move shape to specified position.
-
#position(x, y, w, h) ⇒ Object
Move and resize the shape.
-
#resize(w, h) ⇒ Object
Resize shape to specified width and height.
-
#select ⇒ Object
Select this shape.
-
#selected? ⇒ Boolean
Is this shape selected?.
-
#show ⇒ Object
Show this shape.
-
#visible? ⇒ Boolean
Is this shape visible?.
Constructor Details
#initialize(x, y) ⇒ Shape
Returns a new instance of Shape.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fox16/canvas.rb', line 26 def initialize(x, y) @enabled = true @visible = true @selected = false @draggable = false @x = x @y = y @foreground = FXRGB(0, 0, 0) @target = nil @selector = 0 end |
Instance Attribute Details
#foreground ⇒ Object
Returns the value of attribute foreground.
24 25 26 |
# File 'lib/fox16/canvas.rb', line 24 def foreground @foreground end |
#selector ⇒ Object
Returns the value of attribute selector.
24 25 26 |
# File 'lib/fox16/canvas.rb', line 24 def selector @selector end |
#target ⇒ Object
Returns the value of attribute target.
24 25 26 |
# File 'lib/fox16/canvas.rb', line 24 def target @target end |
#x ⇒ Object
Returns the value of attribute x.
24 25 26 |
# File 'lib/fox16/canvas.rb', line 24 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
24 25 26 |
# File 'lib/fox16/canvas.rb', line 24 def y @y end |
Instance Method Details
#apply_dc(dc) ⇒ Object (protected)
137 138 139 140 141 142 |
# File 'lib/fox16/canvas.rb', line 137 protected def apply_dc(dc) oldForeground = dc.foreground dc.foreground = foreground yield dc.foreground = oldForeground end |
#bounds ⇒ Object
Return the bounding box for this shape
39 40 41 |
# File 'lib/fox16/canvas.rb', line 39 def bounds FXRectangle.new(x, y, width, height) end |
#deselect ⇒ Object
Deselect this shape
99 100 101 |
# File 'lib/fox16/canvas.rb', line 99 def deselect @selected = false end |
#disable ⇒ Object
Disable this shape
69 70 71 |
# File 'lib/fox16/canvas.rb', line 69 def disable @enabled = false end |
#draggable=(d) ⇒ Object
Set this shape’s draggability
109 110 111 |
# File 'lib/fox16/canvas.rb', line 109 def draggable=(d) @draggable = d end |
#draggable? ⇒ Boolean
Is this shape draggable?
114 115 116 |
# File 'lib/fox16/canvas.rb', line 114 def draggable? @draggable end |
#draw(dc) ⇒ Object
Draw this shape into the specificed device context
119 120 |
# File 'lib/fox16/canvas.rb', line 119 def draw(dc) end |
#drawOutline(dc, x, y, w, h) ⇒ Object
Draws outline
123 124 125 126 127 128 129 130 131 |
# File 'lib/fox16/canvas.rb', line 123 def drawOutline(dc, x, y, w, h) points = [] points << FXPoint.new(x - 0.5*w, y - 0.5*h) points << FXPoint.new(x + 0.5*w, y) points << FXPoint.new(x + 0.5*w, y + 0.5*h) points << FXPoint.new(x - 0.5*w, y + 0.5*h) points << points[0] dc.drawLines(points) end |
#enable ⇒ Object
Enable this shape
64 65 66 |
# File 'lib/fox16/canvas.rb', line 64 def enable @enabled = true end |
#enabled? ⇒ Boolean
Is this shape enabled?
74 75 76 |
# File 'lib/fox16/canvas.rb', line 74 def enabled? @enabled end |
#hide ⇒ Object
Hide this shape
84 85 86 |
# File 'lib/fox16/canvas.rb', line 84 def hide @visible = false end |
#hit?(xpos, ypos) ⇒ Boolean
Hit test
44 45 46 |
# File 'lib/fox16/canvas.rb', line 44 def hit?(xpos, ypos) (xpos >= x) && (xpos < x+width) && (ypos >= y) && (ypos < y+height) end |
#makeControlPoints ⇒ Object
Default: make 6 control points
134 135 |
# File 'lib/fox16/canvas.rb', line 134 def makeControlPoints end |
#move(x, y) ⇒ Object
Move shape to specified position
49 50 51 |
# File 'lib/fox16/canvas.rb', line 49 def move(x, y) @x, @y = x, y end |
#position(x, y, w, h) ⇒ Object
Move and resize the shape
58 59 60 61 |
# File 'lib/fox16/canvas.rb', line 58 def position(x, y, w, h) move(x, y) resize(w, h) end |
#resize(w, h) ⇒ Object
Resize shape to specified width and height
54 55 |
# File 'lib/fox16/canvas.rb', line 54 def resize(w, h) end |
#select ⇒ Object
Select this shape
94 95 96 |
# File 'lib/fox16/canvas.rb', line 94 def select @selected = true end |
#selected? ⇒ Boolean
Is this shape selected?
104 105 106 |
# File 'lib/fox16/canvas.rb', line 104 def selected? @selected end |
#show ⇒ Object
Show this shape
79 80 81 |
# File 'lib/fox16/canvas.rb', line 79 def show @visible = true end |
#visible? ⇒ Boolean
Is this shape visible?
89 90 91 |
# File 'lib/fox16/canvas.rb', line 89 def visible? @visible end |