DisplayMedium.st
author claus
Mon, 06 Feb 1995 01:38:04 +0100
changeset 89 ea2bf46eb669
parent 80 eb8373679a9f
child 157 891eff44c2e7
permissions -rw-r--r--
*** empty log message ***

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

GraphicsContext subclass:#DisplayMedium
       instanceVariableNames:'width height
			      clipRect window'
       classVariableNames:''
       poolDictionaries:''
       category:'Graphics-Support'
!

DisplayMedium comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libview/Attic/DisplayMedium.st,v 1.9 1995-02-06 00:35:42 claus Exp $
'!

!DisplayMedium 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/libview/Attic/DisplayMedium.st,v 1.9 1995-02-06 00:35:42 claus Exp $
"
!

documentation
"
    this is an abstract superclass for all kinds of drawables which
    have a physical representation (i.e. have an extent). Dont use messages
    from here - it will vanish soon.

    Instance variables:

    width           <SmallInteger>  the width (device dependent, usually pixels or inches)
    height          <SmallInteger>  the height (device dependent, usually pixels or inches)
    clipRect        <Rectangle>     a clip rectangle (device dep. usually pixels or inches)
"
! !

!DisplayMedium methodsFor:'initialization'!

initialize
    "set up some useful default values"

    super initialize.

    width := 0.
    height := 0
! !

!DisplayMedium methodsFor:'accessing'!

isView
    "return true, if the receiver is a view"

    ^ false
!

origin
    "return the origin i.e. coordinate of top-left of the receiver"

    ^ 0 @ 0
!

left
    "return the left i.e. x-coordinate of top-left of the receiver"

    ^ 0
!

top
    "return the top i.e. y-coordinate of top-left of the receiver"

    ^ 0
!

insideLeftOffset
    "return the left offset for drawing in the receiver;
     this is 0 here, but Views/Pages may add margins"

    ^ 0
!
 
insideTopOffset
    "return the top offset for drawing in the receiver;
     this is 0 here, but Views/Pages may add margins"

    ^ 0
!
 
width
    "return the width of the receiver"

    ^ width
!

width:anInteger
    "set the width of the receiver"

    width := anInteger
!

height
    "return the height of the receiver"

    ^ height
!

height:anInteger
    "set the height of the receiver"

    height := anInteger
!

width:w height:h
    "set both width and height of the receiver"

    width := w.
    height := h
!

setWidth:w height:h
    "set both width and height - not to be redefined"

    width := w.
    height := h
!

insideWidth
    "return the usable width for drawing in the receiver;
     this is width here, but Views/Pages may subtract margins"

    ^ width
!
 
insideHeight
    "return the usable height for drawing in the receiver;
     this is height here, but Views/Pages may subtract margins"

    ^ height
!
 
extent
    "return the extent i.e. a point with width as x, height as y
     coordinate"

    ^ width @ height
!

extent:extent
    "set the extent"

    width := extent x.
    height := extent y
!

center
    "return the point at the center of the receiver"

    ^ (self left + (width // 2)) @ (self top + (height // 2))
!

corner
    "return the corner point i.e. the bottom-right point"

    ^ (self left + width - 1) @ (self top + height - 1)
!

corner:aPoint
    "set the corner point i.e. change extent so that corner will be
     aPoint while leaving the origin unchanging "

    self extent:(aPoint x - self left + 1)
		@
		(aPoint y - self top + 1)
! !

!DisplayMedium methodsFor:'GC access'!

clipRect:aRectangle
    "set the drawing clip-rectangle"

    ^ self subclassResponsibility
!

at:aPoint
    "return pixel value at coordinate"

    ^ self subclassResponsibility
!

drawPattern:aPattern
    "set the pattern to be drawn with - the pattern may be a color,
     a bitmap or pixmap"

    aPattern isColor ifTrue:[
	self paint:aPattern
    ] ifFalse:[
	self mask:aPattern
    ]
! !

!DisplayMedium methodsFor:'filling'!

black
    "fill the receiver with black"

    self fill:Black
!

white
    "fill the receiver with white"

    self fill:White
!

clearInside
    "clear the receiver with background - ST-80 compatibility"

    ^ self clear
!

clear
    "clear the receiver with background"

    "currently need this kludge for form ..."
    transformation isNil ifTrue:[
	self clearRectangleX:0 y:0 width:width height:height
    ] ifFalse:[
	self clearDeviceRectangleX:0 y:0 width:width height:height
    ]
!

clearRectangle:aRectangle
    "clear the rectangular area in the receiver to background"

    self clearRectangleX:(aRectangle left)
		       y:(aRectangle top)
		   width:(aRectangle width)
		  height:(aRectangle height)
!

clearRectangleX:left y:top width:w height:h
    "clear the rectangular area in the receiver to background"

    self fillRectangleX:left
		      y:top
		  width:w
		 height:h
		   with:bgPaint
!

fill:something
    "fill the receiver with something;
     something may be a Form, Color or colorIndex"

    self fillRectangleX:0 y:0 width:width height:height with:something
!

fillRectangle:aRectangle with:something
    "fill the rectangular area in the receiver with something;
     something may be a Form, Color or colorIndex"

    self fillRectangleX:(aRectangle left)
		      y:(aRectangle top)
		  width:(aRectangle width)
		 height:(aRectangle height)
		   with:something
!

fillRectangleX:x y:y width:w height:h with:aPattern
    "fill the rectangular area in the receiver with aPattern,
     which may be a Form or Color"

    self withPattern:aPattern do:[
	self fillRectangleX:x y:y width:w height:h
    ]

    "
     RootView fillRectangleX:0
			   y:0
		       width:50
		      height:50
			with:(Color grey:50)
    "
!

fillPolygon:aPolygon with:aPattern
    "fill a polygon in the receiver with aPattern,
     which may be a Form or Color"

    self withPattern:aPattern do:[
	self fillPolygon:aPolygon
    ]
!

invertRectangle:aRectangle
    "invert a rectangle in the receiver"

    self xoring:[
	self fillRectangle:aRectangle
    ]
!

fillCircle:aPoint radius:aNumber with:aPattern
    "fill a circle in the receiver with aPattern,
     which may be a Color or Form"

    self fillCircleX:(aPoint x) y:(aPoint y) radius:aNumber with:aPattern
!

fillCircleX:x y:y radius:r with:aPattern
    "fill a circle with aPattern,
     which may be a Color or Form"

    |d|
    d := 2 * r.
    self fillArcX:(x - r) y:(y - r) w:d  h:d from:0 angle:360 with:aPattern
!

fillArcX:x y:y w:w h:h from:startAngle angle:angle with:aPattern
    "fill an arc in the receiver with aPattern,
     which may be a Color or Form"

    self withPattern:aPattern do:[
	self fillArcX:x y:y w:w h:h from:startAngle angle:angle
    ]
! !

!DisplayMedium methodsFor:'evaluating in another context'!

withPattern:aPattern do:aBlock
    |old|

    aPattern isColor ifTrue:[
	old := paint.
	self paint:aPattern.
	aBlock value.
	self paint:old
    ] ifFalse:[
	old := mask.
	self mask:aPattern.
	aBlock value.
	self mask:old
    ]
!

withMask:aMask do:aBlock
    "evaluate aBlock with mask set to aMask"

    |oldMask|

    oldMask := mask.
    self mask:aMask.
    aBlock value.
    self mask:oldMask
!

withFunction:aFunction do:aBlock
    "evaluate aBlock with function set to aFunction"

    |oldFun|

    oldFun := function.
    self function:aFunction.
    aBlock value.
    self function:oldFun
!

clippedTo:aRectangle do:aBlock
    "evaluate aBlock with clipping rectangle set to aRectangle"

    |oldClip|
    
    oldClip := clipRect.
    self clipRect:aRectangle.
    aBlock value.
    self clipRect:oldClip
! !