LayoutOrigin.st
author claus
Fri, 19 May 1995 18:40:45 +0200
changeset 77 e846c6f3ac50
child 83 97fd04d167c8
permissions -rw-r--r--
.

'From Smalltalk/X, Version:2.10.5 on 15-apr-1995 at 12:14:46 pm'!

Layout subclass:#LayoutOrigin
	 instanceVariableNames:'leftFraction topFraction leftOffset
		topOffset'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Graphics-Support-ST80 compatibility'
!

!LayoutOrigin class methodsFor:'instance creation'!

fractionalFromPoint:aPoint
    ^ self new leftFraction:aPointx topFraction:aPoint y
!

offsetFromPoint:aPoint
    ^ self new leftOffset:aPointx topOffset:aPoint y
!

fromPoint:aPoint
    "return a new LayoutOrigin from  aPoint.
     If the coordinates are between 0 and 1, take
     them as fractional parts (relative to superview).
     Otherwise, treat them as absolute offsets."

    |x y layout|

    x := aPoint x.
    y := aPoint y.
    layout := self new.
    ((x between:0 and:1)
    and:[y between:0 and:1]) ifTrue:[
	layout leftFraction:x topFraction:y
    ] ifFalse:[
	layout leftOffset:x topOffset:y
    ].
    ^ layout
! !

!LayoutOrigin methodsFor:'accessing'!

leftFraction:something
    "set leftFraction"

    leftFraction := something.
!

leftFraction
    "return leftFraction"

    ^ leftFraction
!

leftOffset:something
    "set leftOffset"

    leftOffset := something.
!

leftOffset
    "return leftOffset"

    ^ leftOffset
!

leftFraction:something offset:o
    "set leftFraction and offset"

    leftFraction := something.
    leftOffset := o
!

topFraction:something
    "set topFraction"

    topFraction := something.
!

topFraction
    "return topFraction"

    ^ topFraction
!

topOffset:something
    "set topOffset"

    topOffset := something.
!

topOffset
    "return topOffset"

    ^ topOffset
!

topFraction:something offset:o
    "set topFraction and offset"

    topFraction := something.
    topOffset := o
! !


!LayoutOrigin methodsFor:'queries'!

rectangleRelativeTo:superRectangle preferred:prefRect
    |x y|

    leftOffset isNil ifTrue:[
	x := 0
    ] ifFalse:[
	x := leftOffset
    ].
    topOffset isNil ifTrue:[
	y := 0
    ] ifFalse:[
	y := topOffset
    ].
    leftFraction notNil ifTrue:[
	x := x + (prefRect width * leftFraction)
    ].
    topFraction notNil ifTrue:[
	y := y + (prefRect height * topFraction)
    ].
    ^ Rectangle origin:x@y extent:prefRect extent
!

origin
    ^ leftFraction asFloat @ topFraction asFloat
! !

!LayoutOrigin methodsFor:'initialization'!

initialize
    leftOffset := topOffset := 0.
    leftFraction := topFraction := 0.
! !