DisplayObject.st
author claus
Wed, 30 Aug 1995 19:54:43 +0200
changeset 99 a656b0c9dd21
parent 96 948318b2fbd4
child 114 e577a2f332d0
permissions -rw-r--r--
.

"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Object subclass:#DisplayObject
       instanceVariableNames:'frame'
       classVariableNames:''
       poolDictionaries:''
       category:'Graphics-Display Objects'
!

!DisplayObject class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libview2/DisplayObject.st,v 1.12 1995-08-30 17:53:47 claus Exp $
"
!

documentation
"
    generic superclass for Display Objects held in ObjectViews
    see DrawObject/LogicObject/DeskTopObject and subclasses for example use
"
! !

!DisplayObject class methodsFor:'instance creation'!

new
    ^ self basicNew initialize
! !

!DisplayObject class methodsFor:'behavior'!

dragOutline
    "if true, dragging is done by drawing outline only;
     if false, dragging is done by full draw (fast servers only)
     - can be redefined in subclasses"

    ^ true
! !

!DisplayObject methodsFor:'initialization'!

initialize
    ^ self
!

computeBoundingBox
    "compute my boundingBox into the local 'frame'"

    ^ self subclassResponsibility
! !

!DisplayObject methodsFor:'queries'!

handlesKeyboardInput
    "return true, if the receiver handles keyboard input"

    ^ false
!

canBeMoved
    "return true, if the receiver can be moved around"

    ^ true
!

hasFixedSize
    "return true, if the receiver has fixed size i.e. cannot be
     resized
     - by default, we do not allow resizing"

    ^ true
!

isContainedIn:aRectangle
    "object must decide, if its within a rectangle"

    ^ aRectangle contains:frame
!

containsPoint: aPoint
    ^ frame containsPoint: aPoint
!

intersects:aRectangle
    "object must decide, if its intersecting a rectangle"

    ^ frame intersects:aRectangle
!

isOpaque
    "return true, if the object fully covers its frame (i.e. is rectangular
     and has no 'holes'. Since we dont know, return false here"

    ^ false
! !

!DisplayObject methodsFor:'converting'!

asDisplayObject
    ^ self
! !

!DisplayObject methodsFor:'accessing'!

frame
    "object must return a frame boundary rectangle"

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    ^ frame
!

width
    "return the width of the frame"

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    ^ frame width
!

height
    "return the height of the frame"

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    ^ frame height
!

extent
    "return the extent of the frame"

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    ^ frame extent
!

origin
    "return the frame origin"

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    ^ frame origin
!

corner
    "return the frame corner"

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    ^ frame corner
!

origin:origin
    "object must calculate its dimension from outline"

    ^ self subclassResponsibility
!

origin:origin corner:corner
    "object must calculate its dimension from outline"

    ^ self subclassResponsibility
! !

!DisplayObject methodsFor:'users actions'!

moveTo:aPoint
    "object must move to new origin
     - default is to stay; ought to be redefined in subclass"

    ^ self
!

keyInput:akey
    ^ self
! !

!DisplayObject methodsFor:'queries'!

isHitBy:aPoint withDelta:delta
    "object must decide, if hit by a click at aPoint;
     usually this method is redefined in subclasses for a more complete
     check (i.e. if objects boundary is not rectangular)"

    |org left right top bott px py d2|

    frame isNil ifTrue:[
	frame := self computeBoundingBox
    ].
    (delta == 0) ifTrue:[
	^ frame containsPoint:aPoint
    ].

    "
     its quicker to not create a new rectangle for the test
     (which is not obvious for simple lines, but complex polygons 
      or grouped objects may call this for many of its components)
    "
    org := frame origin.
    left := org x - delta.

    px := aPoint x.
    (px < left) ifTrue:[^ false].   "aPoint is to the left of my left edge"

    d2 := delta * 2.
    right := left + frame width + d2.
    (px > right) ifTrue:[^ false].  "aPoint is to the right of my right edge"

    top := org y - delta.
    py := aPoint y.
    (py < top) ifTrue:[^ false].    "aPoint is above my top edge"

    bott := top + frame height + d2.
    (py > bott) ifTrue:[^ false].   "aPoint is below my bottom edge"

    ^ true
!

isHitBy:aPoint
    "object must decide, if hit by a click at aPoint"

    ^ self isHitBy:aPoint withDelta:0
! !

!DisplayObject methodsFor:'ST-80 drawing'!

displayOn: aDisplayMedium
    self displayOn:aDisplayMedium 
		at:0@0 
       clippingBox:nil 
	      rule:#copy
	      mask:nil
!

displayOn:aDisplayMedium at:aPoint 
    self displayOn:aDisplayMedium 
		at:aPoint 
       clippingBox:nil 
	      rule:#copy
	      mask:nil
!

displayOn:aDisplayMedium at:aPoint clippingBox:clipRectangle
    ^ self displayOn:aDisplayMedium 
		  at:aPoint 
	 clippingBox:clipRectangle 
		rule:#copy
		mask:nil
!

displayOn:aDisplayMedium at:aPoint clippingBox:clip rule:rule mask: aForm
    "in ST-80 programs, this is redefined"

    aDisplayMedium function:rule.
    ^ self drawIn:aDisplayMedium 
	       at:(aPoint + self origin)
! !

!DisplayObject methodsFor:'drawing'!

drawIn:aView offset:anOffset
    "draw the receiver at its origin offset by anOffset, aPoint"

    ^ self subclassResponsibility
!

drawIn:aView
    "draw the receiver at its origin"

    self drawIn:aView offset:(0@0)
!

drawIn:aView at:drawOrigin
    "draw the receiver at drawOrigin, aPoint"

    self drawIn:aView offset:(drawOrigin - (self origin))
!

drawSelectedIn:aView offset:anOffset
    "draw the receiver highlighted - this is usually redefined"

    self drawIn:aView offset:anOffset.
    self drawOutlineIn:aView offset:anOffset
!

drawSelectedIn:aView
    "draw the receiver highlighted at its position"

    self drawSelectedIn:aView offset:(0@0)
!

drawOutlineIn:aView offset:anOffset
    "draw the receivers outline at its origin offset by anOffset, aPoint"

    |org|
    org := self origin + anOffset.
    aView displayRectangleX:org x y:org y
		      width:frame width height:frame height
!

drawOutlineIn:aView
    "draw the receivers outline at its origin"

    self drawOutlineIn:aView offset:(0@0)
!

drawOutlineIn:aView at:drawOrigin
    "draw the receivers outline at drawOrigin, aPoint"

    self drawOutlineIn:aView offset:(drawOrigin - self origin)
!

drawDragIn:aView at:drawOrigin
    "draw the receiver for dragging"

    self class dragOutline ifTrue:[
	self drawOutlineIn:aView offset:(drawOrigin - (self origin))
    ] ifFalse: [
	self drawIn:aView offset:(drawOrigin - (self origin))
    ]
!

drawDragIn:aView offset:drawOrigin
    self class dragOutline ifTrue:[
	self drawOutlineIn:aView offset:drawOrigin
    ] ifFalse: [
	self drawIn:aView offset:drawOrigin
    ]
!

drawDragIn:aView
    self class dragOutline ifTrue:[
	self drawOutlineIn:aView offset:(0 @ 0)
    ] ifFalse: [
	self drawIn:aView offset:(0 @ 0)
    ]
! !