Class: Fox::Canvas::ShapeCanvas
- Inherits:
-
FXCanvas
- Object
- FXObject
- FXId
- FXDrawable
- FXWindow
- FXCanvas
- Fox::Canvas::ShapeCanvas
- Includes:
- Responder
- Defined in:
- lib/fox16/canvas.rb
Constant Summary collapse
- FLAG_SHOWN =
Window state flags
0x00000001
- FLAG_ENABLED =
Is shown
0x00000002
- FLAG_UPDATE =
Able to receive input
0x00000004
- FLAG_DROPTARGET =
Is subject to GUI update
0x00000008
- FLAG_FOCUSED =
Drop target
0x00000010
- FLAG_DIRTY =
Has focus
0x00000020
- FLAG_RECALC =
Needs layout
0x00000040
- FLAG_TIP =
Needs recalculation
0x00000080
- FLAG_HELP =
Show tip
0x00000100
- FLAG_DEFAULT =
Show help
0x00000200
- FLAG_INITIAL =
Default widget
0x00000400
- FLAG_SHELL =
Initial widget
0x00000800
- FLAG_ACTIVE =
Shell window
0x00001000
- FLAG_PRESSED =
Window is active
0x00002000
- FLAG_KEY =
Button has been pressed
0x00004000
- FLAG_CARET =
Keyboard key pressed
0x00008000
- FLAG_CHANGED =
Caret is on
0x00010000
- FLAG_LASSO =
Window data changed
0x00020000
- FLAG_TRYDRAG =
Lasso mode
0x00040000
- FLAG_DODRAG =
Tentative drag mode
0x00080000
- FLAG_SCROLLINSIDE =
Doing drag mode
0x00100000
- FLAG_SCROLLING =
Scroll only when inside
0x00200000
Instance Attribute Summary collapse
-
#scene ⇒ Object
Returns the value of attribute scene.
Attributes inherited from FXWindow
#accelTable, #backColor, #defaultCursor, #dragCursor, #first, #focus, #key, #last, #layoutHints, #next, #numChildren, #owner, #parent, #prev, #root, #selector, #shell, #target, #x, #y
Attributes inherited from FXDrawable
Attributes inherited from FXId
Instance Method Summary collapse
-
#deselectShape(shape, notify = false) ⇒ Object
Deselect one shape.
-
#disableShape(shape) ⇒ Object
Disable one shape.
-
#enableShape(shape) ⇒ Object
Enable one shape.
-
#findShape(x, y) ⇒ Object
Find the shape of the least depth containing this point.
-
#initialize(p, tgt = nil, sel = 0, opts = FRAME_NORMAL, x = 0, y = 0, w = 0, h = 0) ⇒ ShapeCanvas
constructor
A new instance of ShapeCanvas.
-
#killSelection(notify) ⇒ Object
Kill selection.
-
#onClicked(sender, sel, ptr) ⇒ Object
Clicked on canvas.
-
#onCommand(sender, sel, ptr) ⇒ Object
Command message.
-
#onDoubleClicked(sender, sel, ptr) ⇒ Object
Double-clicked on canvas.
-
#onLeftBtnPress(sender, sel, evt) ⇒ Object
Left button press.
-
#onLeftBtnRelease(sender, sel, evt) ⇒ Object
Left button release.
-
#onMotion(sender, sel, evt) ⇒ Object
Motion.
-
#onPaint(sender, sel, evt) ⇒ Object
Paint.
-
#onTripleClicked(sender, sel, ptr) ⇒ Object
Triple-clicked on canvas.
-
#selectShape(shape, notify = false) ⇒ Object
Select one shape.
-
#updateShape(shape) ⇒ Object
Repaint.
Methods included from Responder
#FXMAPFUNC, #FXMAPFUNCS, #FXMAPTYPE, #FXMAPTYPES, #addMapEntry, #assocIndex, #identifier, #messageMap
Methods inherited from FXWindow
#acceptDrop, #acquireClipboard, #acquireSelection, #active?, #addHotKey, #after?, after?, #before?, before?, #beginDrag, #canFocus?, #changeFocus, #childAtIndex, #childOf?, #children, #clearDragRectangle, #clearShape, colorType, colorTypeName, commonAncestor, #composeContext, #composite?, #contains?, #containsChild?, #create, #createComposeContext, #cursorPosition, #default?, #defaultHeight, #defaultWidth, deleteType, deleteTypeName, #destroy, #destroyComposeContext, #detach, #didAccept, #disable, #doesSaveUnder?, #dragging?, #dropDisable, #dropEnable, #dropEnabled?, #dropFinished, #dropTarget?, #each_child, #each_child_recursive, #enable, #enabled?, #endDrag, #forceRefresh, #getChildAt, #getDNDData, #getHeightForWidth, #getWidthForHeight, #grab, #grabKeyboard, #grabbed?, #grabbedKeyboard?, #handleDrag, #hasClipboard?, #hasFocus?, #hasSelection?, #height, #height=, #hide, imageType, #inFocusChain?, #indexOfChild, #initial?, #inquireDNDAction, #inquireDNDTypes, #killFocus, #layout, #linkAfter, #linkBefore, #lower, #move, octetType, octetTypeName, #offeredDNDType?, #position, #raiseWindow, #recalc, #releaseClipboard, #releaseSelection, #remHotKey, #removeChild, #repaint, #reparent, #resize, #scroll, #setCursorPosition, #setDNDData, #setDefault, #setDragRectangle, #setFocus, #setInitial, #setShape, #shell?, #show, #shown?, stringType, textType, textTypeName, #tr, #translateCoordinatesFrom, #translateCoordinatesTo, #underCursor?, #ungrab, #ungrabKeyboard, #update, urilistType, urilistTypeName, utf16Type, utf16TypeName, utf8Type, utf8TypeName, #visible=, #width, #width=
Methods included from Responder2
Methods inherited from FXDrawable
Methods inherited from FXId
#create, #created?, #destroy, #detach, #runOnUiThread
Methods inherited from FXObject
#bind, #handle, #load, #save, subclasses
Constructor Details
permalink #initialize(p, tgt = nil, sel = 0, opts = FRAME_NORMAL, x = 0, y = 0, w = 0, h = 0) ⇒ ShapeCanvas
Returns a new instance of ShapeCanvas.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# 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 |
Instance Attribute Details
permalink #scene ⇒ Object
Returns the value of attribute scene.
373 374 375 |
# File 'lib/fox16/canvas.rb', line 373 def scene @scene end |
Instance Method Details
permalink #deselectShape(shape, notify = false) ⇒ Object
Deselect one shape
449 450 451 452 453 454 455 |
# 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 |
permalink #disableShape(shape) ⇒ Object
Disable one shape
428 429 430 431 432 433 434 435 436 437 |
# 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 |
permalink #enableShape(shape) ⇒ Object
Enable one shape
416 417 418 419 420 421 422 423 424 425 |
# 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 |
permalink #findShape(x, y) ⇒ Object
Find the shape of the least depth containing this point
399 400 401 402 403 404 |
# 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 |
permalink #killSelection(notify) ⇒ Object
Kill selection
458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# 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, MKUINT(, SEL_DESELECTED), shape) end end end changes end |
permalink #onClicked(sender, sel, ptr) ⇒ Object
Clicked on canvas
591 592 593 |
# File 'lib/fox16/canvas.rb', line 591 def onClicked(sender, sel, ptr) return target && target.handle(self, MKUINT(, SEL_CLICKED), ptr) end |
permalink #onCommand(sender, sel, ptr) ⇒ Object
Command message
586 587 588 |
# File 'lib/fox16/canvas.rb', line 586 def onCommand(sender, sel, ptr) return target && target.handle(self, MKUINT(, SEL_COMMAND), ptr) end |
permalink #onDoubleClicked(sender, sel, ptr) ⇒ Object
Double-clicked on canvas
596 597 598 |
# File 'lib/fox16/canvas.rb', line 596 def onDoubleClicked(sender, sel, ptr) return target && target.handle(self, MKUINT(, SEL_DOUBLECLICKED), ptr) end |
permalink #onLeftBtnPress(sender, sel, evt) ⇒ Object
Left button press
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/fox16/canvas.rb', line 506 def onLeftBtnPress(sender, sel, evt) handle(self, 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, MKUINT(, 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 |
permalink #onLeftBtnRelease(sender, sel, evt) ⇒ Object
Left button release
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# 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, MKUINT(, SEL_LEFTBUTTONRELEASE), evt) != 0 # Was dragging if (flg & FLAG_DODRAG) != 0 handle(self, 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, MKUINT(0, SEL_CLICKED), @currentShape) elsif evt.click_count == 2 handle(self, MKUINT(0, SEL_DOUBLECLICKED), @currentShape) elseif evt.click_count == 3 handle(self, MKUINT(0, SEL_TRIPLECLICKED), @currentShape) end # Generate command callback only when clicked on item if @currentShape && @currentShape.enabled? handle(self, MKUINT(0, SEL_COMMAND), @currentShape) end return 1 end return 0 end end |
permalink #onMotion(sender, sel, evt) ⇒ Object
Motion
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/fox16/canvas.rb', line 486 def onMotion(sender, sel, evt) # Drag and drop mode if (@flags & FLAG_DODRAG) != 0 handle(self, 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, MKUINT(0, SEL_BEGINDRAG), evt) != 0 @flags |= FLAG_DODRAG end end return 1 end end |
permalink #onPaint(sender, sel, evt) ⇒ Object
Paint
474 475 476 477 478 479 480 481 482 483 |
# 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 |
permalink #onTripleClicked(sender, sel, ptr) ⇒ Object
Triple-clicked on canvas
601 602 603 |
# File 'lib/fox16/canvas.rb', line 601 def onTripleClicked(sender, sel, ptr) return target && target.handle(self, MKUINT(, SEL_TRIPLECLICKED), ptr) end |
permalink #selectShape(shape, notify = false) ⇒ Object
Select one shape
440 441 442 443 444 445 446 |
# 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 |
permalink #updateShape(shape) ⇒ Object
Repaint
407 408 409 410 411 412 413 |
# File 'lib/fox16/canvas.rb', line 407 def updateShape(shape) if @scene.include?(shape) update else raise CanvasError end end |