DisplayObject.st
changeset 122 fe90d99734b7
parent 115 963231c512ec
child 134 f83c245371c2
equal deleted inserted replaced
121:ec8cb1bdfc9b 122:fe90d99734b7
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 Object subclass:#DisplayObject
    13 Object subclass:#DisplayObject
    14        instanceVariableNames:'frame'
    14 	 instanceVariableNames:'frame'
    15        classVariableNames:''
    15 	 classVariableNames:''
    16        poolDictionaries:''
    16 	 poolDictionaries:''
    17        category:'Graphics-Display Objects'
    17 	 category:'Graphics-Display Objects'
    18 !
    18 !
    19 
    19 
    20 !DisplayObject class methodsFor:'documentation'!
    20 !DisplayObject class methodsFor:'documentation'!
    21 
    21 
    22 copyright
    22 copyright
    31  other person.  No title to or ownership of the software is
    31  other person.  No title to or ownership of the software is
    32  hereby transferred.
    32  hereby transferred.
    33 "
    33 "
    34 !
    34 !
    35 
    35 
    36 version
       
    37     ^ '$Header: /cvs/stx/stx/libview2/DisplayObject.st,v 1.14 1995-11-15 16:23:09 cg Exp $'
       
    38 !
       
    39 
       
    40 documentation
    36 documentation
    41 "
    37 "
    42     generic superclass for Display Objects held in ObjectViews
    38     generic superclass for Display Objects held in ObjectViews
    43     see DrawObject/LogicObject/DeskTopObject and subclasses for example use
    39     see DrawObject/LogicObject/DeskTopObject and subclasses for example use
    44 "
    40 "
       
    41 !
       
    42 
       
    43 version
       
    44     ^ '$Header: /cvs/stx/stx/libview2/DisplayObject.st,v 1.15 1995-11-23 01:26:40 cg Exp $'
    45 ! !
    45 ! !
    46 
    46 
    47 !DisplayObject class methodsFor:'instance creation'!
    47 !DisplayObject class methodsFor:'instance creation'!
    48 
    48 
    49 new
    49 new
    58      - can be redefined in subclasses"
    58      - can be redefined in subclasses"
    59 
    59 
    60     ^ true
    60     ^ true
    61 ! !
    61 ! !
    62 
    62 
       
    63 !DisplayObject methodsFor:'ST-80 drawing'!
       
    64 
       
    65 displayOn: aDisplayMedium
       
    66     self displayOn:aDisplayMedium 
       
    67 		at:0@0 
       
    68        clippingBox:nil 
       
    69 	      rule:#copy
       
    70 	      mask:nil
       
    71 !
       
    72 
       
    73 displayOn:aDisplayMedium at:aPoint 
       
    74     self displayOn:aDisplayMedium 
       
    75 		at:aPoint 
       
    76        clippingBox:nil 
       
    77 	      rule:#copy
       
    78 	      mask:nil
       
    79 !
       
    80 
       
    81 displayOn:aDisplayMedium at:aPoint clippingBox:clipRectangle
       
    82     ^ self displayOn:aDisplayMedium 
       
    83 		  at:aPoint 
       
    84 	 clippingBox:clipRectangle 
       
    85 		rule:#copy
       
    86 		mask:nil
       
    87 !
       
    88 
       
    89 displayOn:aDisplayMedium at:aPoint clippingBox:clip rule:rule mask: aForm
       
    90     "in ST-80 programs, this is redefined"
       
    91 
       
    92     aDisplayMedium function:rule.
       
    93     ^ self drawIn:aDisplayMedium 
       
    94 	       at:(aPoint + self origin)
       
    95 ! !
       
    96 
       
    97 !DisplayObject methodsFor:'accessing'!
       
    98 
       
    99 corner
       
   100     "return the frame corner"
       
   101 
       
   102     frame isNil ifTrue:[
       
   103 	frame := self computeBoundingBox
       
   104     ].
       
   105     ^ frame corner
       
   106 !
       
   107 
       
   108 extent
       
   109     "return the extent of the frame"
       
   110 
       
   111     frame isNil ifTrue:[
       
   112 	frame := self computeBoundingBox
       
   113     ].
       
   114     ^ frame extent
       
   115 !
       
   116 
       
   117 frame
       
   118     "object must return a frame boundary rectangle"
       
   119 
       
   120     frame isNil ifTrue:[
       
   121 	frame := self computeBoundingBox
       
   122     ].
       
   123     ^ frame
       
   124 !
       
   125 
       
   126 height
       
   127     "return the height of the frame"
       
   128 
       
   129     frame isNil ifTrue:[
       
   130 	frame := self computeBoundingBox
       
   131     ].
       
   132     ^ frame height
       
   133 !
       
   134 
       
   135 origin
       
   136     "return the frame origin"
       
   137 
       
   138     frame isNil ifTrue:[
       
   139 	frame := self computeBoundingBox
       
   140     ].
       
   141     ^ frame origin
       
   142 !
       
   143 
       
   144 origin:origin
       
   145     "object must calculate its dimension from outline"
       
   146 
       
   147     ^ self subclassResponsibility
       
   148 !
       
   149 
       
   150 origin:origin corner:corner
       
   151     "object must calculate its dimension from outline"
       
   152 
       
   153     ^ self subclassResponsibility
       
   154 !
       
   155 
       
   156 width
       
   157     "return the width of the frame"
       
   158 
       
   159     frame isNil ifTrue:[
       
   160 	frame := self computeBoundingBox
       
   161     ].
       
   162     ^ frame width
       
   163 ! !
       
   164 
       
   165 !DisplayObject methodsFor:'converting'!
       
   166 
       
   167 asDisplayObject
       
   168     ^ self
       
   169 ! !
       
   170 
       
   171 !DisplayObject methodsFor:'drawing'!
       
   172 
       
   173 drawDragIn:aView
       
   174     self class dragOutline ifTrue:[
       
   175 	self drawOutlineIn:aView offset:(0 @ 0)
       
   176     ] ifFalse: [
       
   177 	self drawIn:aView offset:(0 @ 0)
       
   178     ]
       
   179 !
       
   180 
       
   181 drawDragIn:aView at:drawOrigin
       
   182     "draw the receiver for dragging"
       
   183 
       
   184     self class dragOutline ifTrue:[
       
   185 	self drawOutlineIn:aView offset:(drawOrigin - (self origin))
       
   186     ] ifFalse: [
       
   187 	self drawIn:aView offset:(drawOrigin - (self origin))
       
   188     ]
       
   189 !
       
   190 
       
   191 drawDragIn:aView offset:drawOrigin
       
   192     self class dragOutline ifTrue:[
       
   193 	self drawOutlineIn:aView offset:drawOrigin
       
   194     ] ifFalse: [
       
   195 	self drawIn:aView offset:drawOrigin
       
   196     ]
       
   197 !
       
   198 
       
   199 drawIn:aView
       
   200     "draw the receiver at its origin"
       
   201 
       
   202     self drawIn:aView offset:(0@0)
       
   203 !
       
   204 
       
   205 drawIn:aView at:drawOrigin
       
   206     "draw the receiver at drawOrigin, aPoint"
       
   207 
       
   208     self drawIn:aView offset:(drawOrigin - (self origin))
       
   209 !
       
   210 
       
   211 drawIn:aView offset:anOffset
       
   212     "draw the receiver at its origin offset by anOffset, aPoint"
       
   213 
       
   214     ^ self subclassResponsibility
       
   215 !
       
   216 
       
   217 drawOutlineIn:aView
       
   218     "draw the receivers outline at its origin"
       
   219 
       
   220     self drawOutlineIn:aView offset:(0@0)
       
   221 !
       
   222 
       
   223 drawOutlineIn:aView at:drawOrigin
       
   224     "draw the receivers outline at drawOrigin, aPoint"
       
   225 
       
   226     self drawOutlineIn:aView offset:(drawOrigin - self origin)
       
   227 !
       
   228 
       
   229 drawOutlineIn:aView offset:anOffset
       
   230     "draw the receivers outline at its origin offset by anOffset, aPoint"
       
   231 
       
   232     |org|
       
   233     org := self origin + anOffset.
       
   234     aView displayRectangleX:org x y:org y
       
   235 		      width:frame width height:frame height
       
   236 !
       
   237 
       
   238 drawSelectedIn:aView
       
   239     "draw the receiver highlighted at its position"
       
   240 
       
   241     self drawSelectedIn:aView offset:(0@0)
       
   242 !
       
   243 
       
   244 drawSelectedIn:aView offset:anOffset
       
   245     "draw the receiver highlighted - this is usually redefined"
       
   246 
       
   247     self drawIn:aView offset:anOffset.
       
   248     self drawOutlineIn:aView offset:anOffset
       
   249 ! !
       
   250 
    63 !DisplayObject methodsFor:'initialization'!
   251 !DisplayObject methodsFor:'initialization'!
    64 
   252 
    65 initialize
   253 computeBoundingBox
    66     ^ self
   254     "compute my boundingBox into the local variable 'frame'.
       
   255      The box should be computed for Display."
       
   256 
       
   257     ^ self subclassResponsibility
    67 !
   258 !
    68 
   259 
    69 computeBoundingBoxFor:aDevice
   260 computeBoundingBoxFor:aDevice
    70     "compute my boundingBox into the local variable 'frame'.
   261     "compute my boundingBox into the local variable 'frame'.
    71      The box is to be computed for aDevice."
   262      The box is to be computed for aDevice."
    73     "/ for backward compatibility, fall back to Display box computation
   264     "/ for backward compatibility, fall back to Display box computation
    74 
   265 
    75     ^ self computeBoundingBox
   266     ^ self computeBoundingBox
    76 !
   267 !
    77 
   268 
    78 computeBoundingBox
   269 initialize
    79     "compute my boundingBox into the local variable 'frame'.
   270     ^ self
    80      The box should be computed for Display."
       
    81 
       
    82     ^ self subclassResponsibility
       
    83 ! !
   271 ! !
    84 
   272 
    85 !DisplayObject methodsFor:'queries'!
   273 !DisplayObject methodsFor:'queries'!
       
   274 
       
   275 canBeMoved
       
   276     "return true, if the receiver can be moved around"
       
   277 
       
   278     ^ true
       
   279 !
       
   280 
       
   281 containsPoint: aPoint
       
   282     ^ frame containsPoint: aPoint
       
   283 !
    86 
   284 
    87 handlesKeyboardInput
   285 handlesKeyboardInput
    88     "return true, if the receiver handles keyboard input"
   286     "return true, if the receiver handles keyboard input"
    89 
   287 
    90     ^ false
   288     ^ false
    91 !
       
    92 
       
    93 canBeMoved
       
    94     "return true, if the receiver can be moved around"
       
    95 
       
    96     ^ true
       
    97 !
   289 !
    98 
   290 
    99 hasFixedSize
   291 hasFixedSize
   100     "return true, if the receiver has fixed size i.e. cannot be
   292     "return true, if the receiver has fixed size i.e. cannot be
   101      resized
   293      resized
   102      - by default, we do not allow resizing"
   294      - by default, we do not allow resizing"
   103 
   295 
   104     ^ true
   296     ^ true
   105 !
   297 !
   106 
   298 
       
   299 intersects:aRectangle
       
   300     "object must decide, if its intersecting a rectangle"
       
   301 
       
   302     ^ frame intersects:aRectangle
       
   303 !
       
   304 
   107 isContainedIn:aRectangle
   305 isContainedIn:aRectangle
   108     "object must decide, if its within a rectangle"
   306     "object must decide, if its within a rectangle"
   109 
   307 
   110     ^ aRectangle contains:frame
   308     ^ aRectangle contains:frame
   111 !
   309 !
   112 
   310 
   113 containsPoint: aPoint
   311 isHitBy:aPoint
   114     ^ frame containsPoint: aPoint
   312     "object must decide, if hit by a click at aPoint"
   115 !
   313 
   116 
   314     ^ self isHitBy:aPoint withDelta:0
   117 intersects:aRectangle
   315 !
   118     "object must decide, if its intersecting a rectangle"
       
   119 
       
   120     ^ frame intersects:aRectangle
       
   121 !
       
   122 
       
   123 isOpaque
       
   124     "return true, if the object fully covers its frame (i.e. is rectangular
       
   125      and has no 'holes'. Since we dont know, return false here"
       
   126 
       
   127     ^ false
       
   128 ! !
       
   129 
       
   130 !DisplayObject methodsFor:'converting'!
       
   131 
       
   132 asDisplayObject
       
   133     ^ self
       
   134 ! !
       
   135 
       
   136 !DisplayObject methodsFor:'accessing'!
       
   137 
       
   138 frame
       
   139     "object must return a frame boundary rectangle"
       
   140 
       
   141     frame isNil ifTrue:[
       
   142 	frame := self computeBoundingBox
       
   143     ].
       
   144     ^ frame
       
   145 !
       
   146 
       
   147 width
       
   148     "return the width of the frame"
       
   149 
       
   150     frame isNil ifTrue:[
       
   151 	frame := self computeBoundingBox
       
   152     ].
       
   153     ^ frame width
       
   154 !
       
   155 
       
   156 height
       
   157     "return the height of the frame"
       
   158 
       
   159     frame isNil ifTrue:[
       
   160 	frame := self computeBoundingBox
       
   161     ].
       
   162     ^ frame height
       
   163 !
       
   164 
       
   165 extent
       
   166     "return the extent of the frame"
       
   167 
       
   168     frame isNil ifTrue:[
       
   169 	frame := self computeBoundingBox
       
   170     ].
       
   171     ^ frame extent
       
   172 !
       
   173 
       
   174 origin
       
   175     "return the frame origin"
       
   176 
       
   177     frame isNil ifTrue:[
       
   178 	frame := self computeBoundingBox
       
   179     ].
       
   180     ^ frame origin
       
   181 !
       
   182 
       
   183 corner
       
   184     "return the frame corner"
       
   185 
       
   186     frame isNil ifTrue:[
       
   187 	frame := self computeBoundingBox
       
   188     ].
       
   189     ^ frame corner
       
   190 !
       
   191 
       
   192 origin:origin
       
   193     "object must calculate its dimension from outline"
       
   194 
       
   195     ^ self subclassResponsibility
       
   196 !
       
   197 
       
   198 origin:origin corner:corner
       
   199     "object must calculate its dimension from outline"
       
   200 
       
   201     ^ self subclassResponsibility
       
   202 ! !
       
   203 
       
   204 !DisplayObject methodsFor:'users actions'!
       
   205 
       
   206 moveTo:aPoint
       
   207     "object must move to new origin
       
   208      - default is to stay; ought to be redefined in subclass"
       
   209 
       
   210     ^ self
       
   211 !
       
   212 
       
   213 keyInput:akey
       
   214     ^ self
       
   215 ! !
       
   216 
       
   217 !DisplayObject methodsFor:'queries'!
       
   218 
   316 
   219 isHitBy:aPoint withDelta:delta
   317 isHitBy:aPoint withDelta:delta
   220     "object must decide, if hit by a click at aPoint;
   318     "object must decide, if hit by a click at aPoint;
   221      usually this method is redefined in subclasses for a more complete
   319      usually this method is redefined in subclasses for a more complete
   222      check (i.e. if objects boundary is not rectangular)"
   320      check (i.e. if objects boundary is not rectangular)"
   253     (py > bott) ifTrue:[^ false].   "aPoint is below my bottom edge"
   351     (py > bott) ifTrue:[^ false].   "aPoint is below my bottom edge"
   254 
   352 
   255     ^ true
   353     ^ true
   256 !
   354 !
   257 
   355 
   258 isHitBy:aPoint
   356 isOpaque
   259     "object must decide, if hit by a click at aPoint"
   357     "return true, if the object fully covers its frame (i.e. is rectangular
   260 
   358      and has no 'holes'. Since we dont know, return false here"
   261     ^ self isHitBy:aPoint withDelta:0
   359 
   262 ! !
   360     ^ false
   263 
   361 ! !
   264 !DisplayObject methodsFor:'ST-80 drawing'!
   362 
   265 
   363 !DisplayObject methodsFor:'users actions'!
   266 displayOn: aDisplayMedium
   364 
   267     self displayOn:aDisplayMedium 
   365 keyInput:akey
   268 		at:0@0 
   366     ^ self
   269        clippingBox:nil 
   367 !
   270 	      rule:#copy
   368 
   271 	      mask:nil
   369 moveTo:aPoint
   272 !
   370     "object must move to new origin
   273 
   371      - default is to stay; ought to be redefined in subclass"
   274 displayOn:aDisplayMedium at:aPoint 
   372 
   275     self displayOn:aDisplayMedium 
   373     ^ self
   276 		at:aPoint 
   374 ! !
   277        clippingBox:nil 
   375 
   278 	      rule:#copy
       
   279 	      mask:nil
       
   280 !
       
   281 
       
   282 displayOn:aDisplayMedium at:aPoint clippingBox:clipRectangle
       
   283     ^ self displayOn:aDisplayMedium 
       
   284 		  at:aPoint 
       
   285 	 clippingBox:clipRectangle 
       
   286 		rule:#copy
       
   287 		mask:nil
       
   288 !
       
   289 
       
   290 displayOn:aDisplayMedium at:aPoint clippingBox:clip rule:rule mask: aForm
       
   291     "in ST-80 programs, this is redefined"
       
   292 
       
   293     aDisplayMedium function:rule.
       
   294     ^ self drawIn:aDisplayMedium 
       
   295 	       at:(aPoint + self origin)
       
   296 ! !
       
   297 
       
   298 !DisplayObject methodsFor:'drawing'!
       
   299 
       
   300 drawIn:aView offset:anOffset
       
   301     "draw the receiver at its origin offset by anOffset, aPoint"
       
   302 
       
   303     ^ self subclassResponsibility
       
   304 !
       
   305 
       
   306 drawIn:aView
       
   307     "draw the receiver at its origin"
       
   308 
       
   309     self drawIn:aView offset:(0@0)
       
   310 !
       
   311 
       
   312 drawIn:aView at:drawOrigin
       
   313     "draw the receiver at drawOrigin, aPoint"
       
   314 
       
   315     self drawIn:aView offset:(drawOrigin - (self origin))
       
   316 !
       
   317 
       
   318 drawSelectedIn:aView offset:anOffset
       
   319     "draw the receiver highlighted - this is usually redefined"
       
   320 
       
   321     self drawIn:aView offset:anOffset.
       
   322     self drawOutlineIn:aView offset:anOffset
       
   323 !
       
   324 
       
   325 drawSelectedIn:aView
       
   326     "draw the receiver highlighted at its position"
       
   327 
       
   328     self drawSelectedIn:aView offset:(0@0)
       
   329 !
       
   330 
       
   331 drawOutlineIn:aView offset:anOffset
       
   332     "draw the receivers outline at its origin offset by anOffset, aPoint"
       
   333 
       
   334     |org|
       
   335     org := self origin + anOffset.
       
   336     aView displayRectangleX:org x y:org y
       
   337 		      width:frame width height:frame height
       
   338 !
       
   339 
       
   340 drawOutlineIn:aView
       
   341     "draw the receivers outline at its origin"
       
   342 
       
   343     self drawOutlineIn:aView offset:(0@0)
       
   344 !
       
   345 
       
   346 drawOutlineIn:aView at:drawOrigin
       
   347     "draw the receivers outline at drawOrigin, aPoint"
       
   348 
       
   349     self drawOutlineIn:aView offset:(drawOrigin - self origin)
       
   350 !
       
   351 
       
   352 drawDragIn:aView at:drawOrigin
       
   353     "draw the receiver for dragging"
       
   354 
       
   355     self class dragOutline ifTrue:[
       
   356 	self drawOutlineIn:aView offset:(drawOrigin - (self origin))
       
   357     ] ifFalse: [
       
   358 	self drawIn:aView offset:(drawOrigin - (self origin))
       
   359     ]
       
   360 !
       
   361 
       
   362 drawDragIn:aView offset:drawOrigin
       
   363     self class dragOutline ifTrue:[
       
   364 	self drawOutlineIn:aView offset:drawOrigin
       
   365     ] ifFalse: [
       
   366 	self drawIn:aView offset:drawOrigin
       
   367     ]
       
   368 !
       
   369 
       
   370 drawDragIn:aView
       
   371     self class dragOutline ifTrue:[
       
   372 	self drawOutlineIn:aView offset:(0 @ 0)
       
   373     ] ifFalse: [
       
   374 	self drawIn:aView offset:(0 @ 0)
       
   375     ]
       
   376 ! !