class Fox::Canvas::ShapeCanvas
Constants
- FLAG_ACTIVE
- FLAG_CARET
- FLAG_CHANGED
- FLAG_DEFAULT
- FLAG_DIRTY
- FLAG_DODRAG
- FLAG_DROPTARGET
- FLAG_ENABLED
- FLAG_FOCUSED
- FLAG_HELP
- FLAG_INITIAL
- FLAG_KEY
- FLAG_LASSO
- FLAG_PRESSED
- FLAG_RECALC
- FLAG_SCROLLING
- FLAG_SCROLLINSIDE
- FLAG_SHELL
- FLAG_SHOWN
Window state flags
- FLAG_TIP
- FLAG_TRYDRAG
- FLAG_UPDATE
Attributes
scene[RW]
Public Class Methods
new(p, tgt=nil, sel=0, opts=FRAME_NORMAL, x=0, y=0, w=0, h=0)
click to toggle source
Calls superclass method
Fox::FXCanvas::new
# File lib/fox16/canvas.rb, line 375 def initialize(p, tgt=nil, sel=0, opts=FRAME_NORMAL, x=0, y=0, w=0, h=0) # Initialize base class super(p, tgt, sel, opts, x, y, w, h) # Start with an empty group @scene = ShapeGroup.new # Selection policy @selectionPolicy = SingleSelectionPolicy.new(self) @flags = 0 # Map FXMAPFUNC(SEL_PAINT, 0, "onPaint") FXMAPFUNC(SEL_MOTION, 0, "onMotion") FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, "onLeftBtnPress") FXMAPFUNC(SEL_LEFTBUTTONRELEASE, 0, "onLeftBtnRelease") FXMAPFUNC(SEL_CLICKED,0,"onClicked") FXMAPFUNC(SEL_DOUBLECLICKED,0,"onDoubleClicked") FXMAPFUNC(SEL_TRIPLECLICKED,0,"onTripleClicked") FXMAPFUNC(SEL_COMMAND,0,"onCommand") end
Public Instance Methods
deselectShape(shape, notify=false)
click to toggle source
Deselect one shape
# File lib/fox16/canvas.rb, line 449 def deselectShape(shape, notify=false) if @scene.include?(shape) @selectionPolicy.deselectShape(shape, notify) else raise CanvasError end end
disableShape(shape)
click to toggle source
Disable one shape
# File lib/fox16/canvas.rb, line 428 def disableShape(shape) if @scene.include?(shape) if shape.enabled? shape.disable updateShape(shape) end else raise CanvasError end end
enableShape(shape)
click to toggle source
Enable one shape
# File lib/fox16/canvas.rb, line 416 def enableShape(shape) if @scene.include?(shape) unless shape.enabled? shape.enable updateShape(shape) end else raise CanvasError end end
findShape(x, y)
click to toggle source
Find the shape of the least depth containing this point
# File lib/fox16/canvas.rb, line 399 def findShape(x, y) @scene.reverse_each do |shape| return shape if shape.hit?(x, y) end nil end
killSelection(notify)
click to toggle source
Kill selection
# File lib/fox16/canvas.rb, line 458 def killSelection(notify) changes = false @scene.each do |shape| if shape.selected? shape.deselect updateShape(shape) changes = true if notify && (target != nil) target.handle(self, Fox.MKUINT(message, SEL_DESELECTED), shape) end end end changes end
onClicked(sender, sel, ptr)
click to toggle source
Clicked on canvas
# File lib/fox16/canvas.rb, line 591 def onClicked(sender, sel, ptr) return target && target.handle(self, Fox.MKUINT(message, SEL_CLICKED), ptr) end
onCommand(sender, sel, ptr)
click to toggle source
Command message
# File lib/fox16/canvas.rb, line 586 def onCommand(sender, sel, ptr) return target && target.handle(self, Fox.MKUINT(message, SEL_COMMAND), ptr) end
onDoubleClicked(sender, sel, ptr)
click to toggle source
Double-clicked on canvas
# File lib/fox16/canvas.rb, line 596 def onDoubleClicked(sender, sel, ptr) return target && target.handle(self, Fox.MKUINT(message, SEL_DOUBLECLICKED), ptr) end
onLeftBtnPress(sender, sel, evt)
click to toggle source
Left button press
# File lib/fox16/canvas.rb, line 506 def onLeftBtnPress(sender, sel, evt) handle(self, Fox.MKUINT(0, SEL_FOCUS_SELF), evt) if enabled? grab flags &= ~FLAG_UPDATE # Give target the first chance at handling this return 1 if target && (target.handle(self, Fox.MKUINT(message, SEL_LEFTBUTTONPRESS), evt) != 0) # Locate shape shape = findShape(evt.win_x, evt.win_y) # No shape here if shape.nil? return 1 end # Change current shape @currentShape = shape # Change item selection if shape.enabled? && !shape.selected? selectShape(shape, true) end # Are we dragging? if shape.selected? && shape.draggable? flags |= FLAG_TRYDRAG end flags |= FLAG_PRESSED return 1 end return 0 end
onLeftBtnRelease(sender, sel, evt)
click to toggle source
Left button release
# File lib/fox16/canvas.rb, line 543 def onLeftBtnRelease(sender, sel, evt) flg = @flags if enabled? ungrab @flags |= FLAG_UPDATE @flags &= ~(FLAG_PRESSED|FLAG_TRYDRAG|FLAG_LASSO|FLAG_DODRAG) # First chance callback return 1 if target && target.handle(self, Fox.MKUINT(message, SEL_LEFTBUTTONRELEASE), evt) != 0 # Was dragging if (flg & FLAG_DODRAG) != 0 handle(self, Fox.MKUINT(0, SEL_ENDDRAG), evt) return 1 end # Must have pressed if (flg & FLAG_PRESSED) != 0 # Change selection if @currentShape && @currentShape.enabled? deselectShape(@currentShape, true) end # Generate clicked callbacks if evt.click_count == 1 handle(self, Fox.MKUINT(0, SEL_CLICKED), @currentShape) elsif evt.click_count == 2 handle(self, Fox.MKUINT(0, SEL_DOUBLECLICKED), @currentShape) elseif evt.click_count == 3 handle(self, Fox.MKUINT(0, SEL_TRIPLECLICKED), @currentShape) end # Generate command callback only when clicked on item if @currentShape && @currentShape.enabled? handle(self, Fox.MKUINT(0, SEL_COMMAND), @currentShape) end return 1 end return 0 end end
onMotion(sender, sel, evt)
click to toggle source
Motion
# File lib/fox16/canvas.rb, line 486 def onMotion(sender, sel, evt) # Drag and drop mode if (@flags & FLAG_DODRAG) != 0 handle(self, Fox.MKUINT(0, SEL_DRAGGED), evt) return 1 end # Tentative drag and drop if (@flags & FLAG_TRYDRAG) != 0 if evt.moved? @flags &= ~FLAG_TRYDRAG if handle(this, Fox.MKUINT(0, SEL_BEGINDRAG), evt) != 0 @flags |= FLAG_DODRAG end end return 1 end end
onPaint(sender, sel, evt)
click to toggle source
Paint
# File lib/fox16/canvas.rb, line 474 def onPaint(sender, sel, evt) dc = FXDCWindow.new(self, evt) dc.foreground = backColor dc.fillRectangle(evt.rect.x, evt.rect.y, evt.rect.w, evt.rect.h) @scene.each do |shape| shape.draw(dc) end dc.end return 1 end
onTripleClicked(sender, sel, ptr)
click to toggle source
Triple-clicked on canvas
# File lib/fox16/canvas.rb, line 601 def onTripleClicked(sender, sel, ptr) return target && target.handle(self, Fox.MKUINT(message, SEL_TRIPLECLICKED), ptr) end
selectShape(shape, notify=false)
click to toggle source
Select one shape
# File lib/fox16/canvas.rb, line 440 def selectShape(shape, notify=false) if @scene.include?(shape) @selectionPolicy.selectShape(shape, notify) else raise CanvasError end end
updateShape(shape)
click to toggle source
Repaint
# File lib/fox16/canvas.rb, line 407 def updateShape(shape) if @scene.include?(shape) update else raise CanvasError end end