DisplayObject.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 02:26:40 +0100
changeset 122 fe90d99734b7
parent 115 963231c512ec
child 134 f83c245371c2
permissions -rw-r--r--
checkin from browser

"
 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.
"
!

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

version
    ^ '$Header: /cvs/stx/stx/libview2/DisplayObject.st,v 1.15 1995-11-23 01:26:40 cg Exp $'
! !

!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:'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:'accessing'!

corner
    "return the frame corner"

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

extent
    "return the extent of the frame"

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

frame
    "object must return a frame boundary rectangle"

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

height
    "return the height of the frame"

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

origin
    "return the frame origin"

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

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

    ^ self subclassResponsibility
!

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

    ^ self subclassResponsibility
!

width
    "return the width of the frame"

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

!DisplayObject methodsFor:'converting'!

asDisplayObject
    ^ self
! !

!DisplayObject methodsFor:'drawing'!

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

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
    ]
!

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))
!

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

    ^ self subclassResponsibility
!

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)
!

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
!

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

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

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

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

!DisplayObject methodsFor:'initialization'!

computeBoundingBox
    "compute my boundingBox into the local variable 'frame'.
     The box should be computed for Display."

    ^ self subclassResponsibility
!

computeBoundingBoxFor:aDevice
    "compute my boundingBox into the local variable 'frame'.
     The box is to be computed for aDevice."

    "/ for backward compatibility, fall back to Display box computation

    ^ self computeBoundingBox
!

initialize
    ^ self
! !

!DisplayObject methodsFor:'queries'!

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

    ^ true
!

containsPoint: aPoint
    ^ frame containsPoint: aPoint
!

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

    ^ false
!

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

    ^ true
!

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

    ^ frame intersects:aRectangle
!

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

    ^ aRectangle contains:frame
!

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

    ^ self isHitBy:aPoint withDelta:0
!

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
!

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:'users actions'!

keyInput:akey
    ^ self
!

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

    ^ self
! !