GraphicsMedium.st
author Claus Gittinger <cg@exept.de>
Tue, 23 Apr 2013 14:23:08 +0200
changeset 6045 0e3df803d990
parent 5321 714fd27c7de8
child 6217 a8a86bfb5cb5
permissions -rw-r--r--
class: GraphicsMedium gc setup & comment

"
 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.
"
"{ Package: 'stx:libview' }"

DeviceGraphicsContext subclass:#GraphicsMedium
	instanceVariableNames:'gc width height realized'
	classVariableNames:''
	poolDictionaries:''
	category:'Graphics-Support'
!

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

    [author:]
	Claus Gittinger
"
! !

!GraphicsMedium methodsFor:'Compatibility-Squeak'!

copyBits:aRectangle from:aForm at:srcOrigin clippingBox:clippingBox rule:rule fillColor:fillColor
    |f oldClip oldFunction|

    (f := rule) isInteger ifTrue:[
	"/ ST-80 compatibility: numeric rule
	f := #(#clear #and #andReverse  #copy #andInverted #noop #xor #or #nor #equiv #invert #orInverted #copyInverted
	       #orReverse #nand #set) at:(rule + 1).
    ].

    oldFunction := function.
    oldClip := clipRect.
"/
    self clippingRectangle:clippingBox.
    self function:f.

    self
	copyFrom:aForm
	x:srcOrigin x y:srcOrigin y
	toX:aRectangle left y:aRectangle top
	width:aRectangle width height:aRectangle height.

    self clippingRectangle:oldClip.
    self function:oldFunction.

    "
      |dst src|

      dst := Form width:8 height:8 fromArray:#[
					      2r00000000
					      2r00000000
					      2r00000000
					      2r00000000
					      2r11111111
					      2r11111111
					      2r11111111
					      2r11111111
					     ].
      src := Form width:8 height:8 fromArray:#[
					      2r00001111
					      2r00001111
					      2r00001111
					      2r00001111
					      2r00001111
					      2r00001111
					      2r00001111
					      2r00001111
					     ].

    dst copyBits:(0@0 corner:8@8) from:src at:0@0 clippingBox:(0@0 corner:8@8) rule:15 fillColor:Color black.
    dst inspect

    "

    "Modified: / 23.10.2000 / 16:50:44 / martin"
!

fill:aRectangle fillColor:aColor
    "fill the rectangular area specified by aRectangle with the black color"

    |oldPaint|

    oldPaint := paint.
    gc paint:aColor.
    gc fillRectangleX:aRectangle left y:aRectangle top width:aRectangle width height:aRectangle height.
    gc paint:oldPaint
!

fillBlack:aRectangle
    "fill the rectangular area specified by aRectangle with the black color"

    self fill:aRectangle fillColor:Black
!

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

    self fill:something
!

fillWhite:aRectangle
    "fill the rectangular area specified by aRectangle with the white color"

    self fill:aRectangle fillColor:White
! !

!GraphicsMedium methodsFor:'accessing'!

bottomCenter
    "return the topCenter point"

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

bottomLeft
    "return the bottomLeft point"

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

boundingBox
    ^ Rectangle
	origin: 0 @ 0
	corner: width @ height

!

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

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
!

height
    "return the height of the receiver"

    ^ height
!

height:anInteger
    "set the height of the receiver"

    height := anInteger
!

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

    ^ 0
!

leftCenter
    "return the leftCenter point"

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

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

    ^ 0 @ 0
!

realized
    "return true, if the receiver is realized.
     The receiver may still be unmapped, if the container is unrealized.
     Use reallyRealized to make certain that I am really mapped."

    ^ realized
!

reallyRealized
    "return true, if the receiver is realized and all containers
     are realized."

    ^ self realized

!

rightCenter
    "return the leftCenter point"

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

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

    width := w.
    height := h
!

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

    ^ 0
!

topCenter
    "return the topCenter point"

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

topRight
    "return the topRight point"

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

viewBackground
    "for protocol compatibility with view; return my background paint color here"

    ^ bgPaint
!

width
    "return the width of the receiver"

    ^ width
!

width:anInteger
    "set the width of the receiver"

    width := anInteger
!

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

    width := w.
    height := h
! !

!GraphicsMedium methodsFor:'copying'!

postCopy
    "this may not be enough to allow copying of views ..."

    super postCopy.
    realized := false.
!

postDeepCopy
    super postDeepCopy.
    realized := false.
! !

!GraphicsMedium methodsFor:'filling'!

black
    "fill the receiver with black"

    self fill:Black
!

clear
    "clear the receiver with background"

    self clearView.
!

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

    ^ self clear
!

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"

    |oldPaint|

    oldPaint := paint.
    gc paint:bgPaint.
    gc fillRectangleX:left y:top width:w height:h.
    gc paint:oldPaint

    "Modified: 28.5.1996 / 20:14:11 / cg"
!

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

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

    |oldPaint|

    oldPaint := paint.
    gc paint:something.
    gc fillRectangleX:0 y:0 width:width height:height.
    gc paint:oldPaint

    "Modified: 28.5.1996 / 20:13:29 / cg"
!

invertRectangle:aRectangle
    "invert a rectangle in the receiver"

    gc xoring:[
        gc fillRectangle:aRectangle
    ]
!

white
    "fill the receiver with white"

    gc fill:White
! !

!GraphicsMedium methodsFor:'initialization'!

initialize
    "set up some useful default values"

    super initialize.

    width := 0.
    height := 0.
    realized := false.

    "/ in the future, gc will be set to some object which really does
    "/ all the graphics work, and the drawXXX drawing operation methods 
    "/ will be changed to forward to it. Then, GraphicsMedium will no longer inherit
    "/ from DeviceGraphicsContext.
    "/ In the meantime (the intermediate migration phase), gc is set to alias self,
    "/ so we are backward compatible.
    "/ During the migration, all self drawXXX operations should be changed to gc drawXXX
    gc := self.
!

setRealized:aBoolean
    "low level special interface to manipulate the realized state.
     Non-public interface, only to be used by experts.
     (use to pretend a view has been realized - for example with alien views)"

    realized := aBoolean
! !

!GraphicsMedium class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview/GraphicsMedium.st,v 1.20 2013-04-23 12:23:08 cg Exp $'
! !