LayoutOrigin.st
author Claus Gittinger <cg@exept.de>
Wed, 08 May 1996 21:07:16 +0200
changeset 242 5b7f59450c65
parent 229 612861ef768a
child 275 d500c08871ab
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
claus
parents: 83
diff changeset
     1
"
claus
parents: 83
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
     3
	      All Rights Reserved
88
claus
parents: 83
diff changeset
     4
claus
parents: 83
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 83
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 83
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 83
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 83
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 83
diff changeset
    10
 hereby transferred.
claus
parents: 83
diff changeset
    11
"
claus
parents: 83
diff changeset
    12
77
claus
parents:
diff changeset
    13
Layout subclass:#LayoutOrigin
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    14
	instanceVariableNames:'leftFraction topFraction leftOffset topOffset'
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    15
	classVariableNames:''
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    16
	poolDictionaries:''
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    17
	category:'Graphics-Geometry'
77
claus
parents:
diff changeset
    18
!
claus
parents:
diff changeset
    19
88
claus
parents: 83
diff changeset
    20
!LayoutOrigin class methodsFor:'documentation'!
claus
parents: 83
diff changeset
    21
claus
parents: 83
diff changeset
    22
copyright
claus
parents: 83
diff changeset
    23
"
claus
parents: 83
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    25
	      All Rights Reserved
88
claus
parents: 83
diff changeset
    26
claus
parents: 83
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents: 83
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents: 83
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents: 83
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents: 83
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents: 83
diff changeset
    32
 hereby transferred.
claus
parents: 83
diff changeset
    33
"
claus
parents: 83
diff changeset
    34
!
claus
parents: 83
diff changeset
    35
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    36
documentation
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    37
"
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    38
    This class is provided to make porting of existing ST-80 applications
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    39
    easier. Instances can be used to control the geometry of a subview, within
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    40
    its superview. It provides the same functionality as a relative origin
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    41
    combined with insets.
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    42
    A layoutOrigin controls the origin of a subcomponent, given a fractional
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    43
    component and an offset component.
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    44
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    45
    Notice: 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    46
        this class was implemented using protocol information
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    47
        from alpha testers - it may not be complete or compatible to
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    48
        the corresponding ST-80 class. 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    49
        If you encounter any incompatibilities, please forward a note 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    50
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
219
106b86ca81da documentation
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
    51
106b86ca81da documentation
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
    52
    [author:]
106b86ca81da documentation
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
    53
        Claus Gittinger
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    54
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    55
    [see also:]
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    56
        View
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    57
        LayoutFrame AlignmentOrigin Layout 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    58
        Rectangle Point
94
8888ddd11323 *** empty log message ***
claus
parents: 93
diff changeset
    59
"
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    60
!
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    61
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    62
examples
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    63
"
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    64
    Although the examples below use a button as component,
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    65
    they work of course with any type of subview ....
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    66
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    67
    using a LayoutOrigin, to arrange for
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    68
    the TOPLEFT of a component be positions
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    69
    at the center (i.e. buttons origin at:0.5 @ 0.5):
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    70
                                                                        [exBegin]
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    71
        |top button|
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    72
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    73
        top := StandardSystemView new.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    74
        top extent:300@300.
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    75
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    76
        button := Button label:'component'.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    77
        top add:button in:(LayoutOrigin new
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    78
                                leftFraction:0.5;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    79
                                topFraction:0.5).
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    80
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    81
        top open
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    82
                                                                        [exEnd]
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    83
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    84
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    85
    like above, but adds an additional offset:
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    86
    (i.e. center of button at:0.5 @ 0.5 OFFSET by 10 @ 20):
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    87
                                                                        [exBegin]
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    88
        |top button|
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    89
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    90
        top := StandardSystemView new.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    91
        top extent:300@300.
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    92
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    93
        button := Button label:'component'.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    94
        top add:button in:(LayoutOrigin new
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    95
                                leftFraction:0.5;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    96
                                topFraction:0.5;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    97
                                leftOffset:10;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    98
                                topOffset:20).
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    99
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   100
        top open
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   101
                                                                        [exEnd]
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   102
"
88
claus
parents: 83
diff changeset
   103
! !
claus
parents: 83
diff changeset
   104
77
claus
parents:
diff changeset
   105
!LayoutOrigin class methodsFor:'instance creation'!
claus
parents:
diff changeset
   106
claus
parents:
diff changeset
   107
fractionalFromPoint:aPoint
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   108
    "given a point, create a layoutOrigin representing the same 
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   109
     relative origin."
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   110
83
claus
parents: 77
diff changeset
   111
    ^ (self new) leftFraction:aPoint x topFraction:aPoint y
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   112
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   113
    "
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   114
     LayoutOrigin fractionalFromPoint:0.5@0.5
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   115
    "
77
claus
parents:
diff changeset
   116
!
claus
parents:
diff changeset
   117
claus
parents:
diff changeset
   118
fromPoint:aPoint
claus
parents:
diff changeset
   119
    "return a new LayoutOrigin from  aPoint.
claus
parents:
diff changeset
   120
     If the coordinates are between 0 and 1, take
claus
parents:
diff changeset
   121
     them as fractional parts (relative to superview).
claus
parents:
diff changeset
   122
     Otherwise, treat them as absolute offsets."
claus
parents:
diff changeset
   123
claus
parents:
diff changeset
   124
    |x y layout|
claus
parents:
diff changeset
   125
claus
parents:
diff changeset
   126
    x := aPoint x.
claus
parents:
diff changeset
   127
    y := aPoint y.
claus
parents:
diff changeset
   128
    layout := self new.
claus
parents:
diff changeset
   129
    ((x between:0 and:1)
claus
parents:
diff changeset
   130
    and:[y between:0 and:1]) ifTrue:[
claus
parents:
diff changeset
   131
	layout leftFraction:x topFraction:y
claus
parents:
diff changeset
   132
    ] ifFalse:[
claus
parents:
diff changeset
   133
	layout leftOffset:x topOffset:y
claus
parents:
diff changeset
   134
    ].
claus
parents:
diff changeset
   135
    ^ layout
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   136
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   137
    "
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   138
     LayoutOrigin fromPoint:100@100
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   139
     LayoutOrigin fromPoint:0.5@0.5
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   140
     LayoutOrigin fromPoint:0.5@100
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   141
    "
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   142
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   143
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   144
offsetFromPoint:aPoint
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   145
    "given a point, create a layoutOrigin representing the same 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   146
     absolute (pixel) origin."
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   147
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   148
    ^ self new leftOffset:aPoint x topOffset:aPoint y
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   149
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   150
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   151
     LayoutOrigin offsetFromPoint:100@100
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   152
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   153
! !
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   154
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   155
!LayoutOrigin methodsFor:'accessing'!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   156
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   157
leftFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   158
    "return leftFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   159
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   160
    ^ leftFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   161
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   162
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   163
leftFraction:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   164
    "set leftFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   165
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   166
    leftFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   167
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   168
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   169
leftFraction:something offset:o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   170
    "set leftFraction and offset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   171
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   172
    leftFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   173
    leftOffset := o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   174
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   175
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   176
leftFraction:newLeft topFraction:newTop 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   177
    "set leftFraction and topFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   178
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   179
    leftFraction := newLeft.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   180
    topFraction := newTop.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   181
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   182
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   183
leftOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   184
    "return leftOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   185
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   186
    ^ leftOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   187
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   188
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   189
leftOffset:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   190
    "set leftOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   191
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   192
    leftOffset := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   193
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   194
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   195
leftOffset:newLeft topOffset:newTop 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   196
    "set leftOffset and topOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   197
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   198
    leftOffset := newLeft.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   199
    topOffset := newTop.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   200
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   201
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   202
topFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   203
    "return topFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   204
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   205
    ^ topFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   206
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   207
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   208
topFraction:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   209
    "set topFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   210
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   211
    topFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   212
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   213
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   214
topFraction:something offset:o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   215
    "set topFraction and offset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   216
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   217
    topFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   218
    topOffset := o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   219
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   220
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   221
topOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   222
    "return topOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   223
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   224
    ^ topOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   225
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   226
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   227
topOffset:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   228
    "set topOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   229
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   230
    topOffset := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   231
! !
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   232
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   233
!LayoutOrigin methodsFor:'converting'!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   234
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   235
fromLiteralArrayEncoding:encoding
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   236
    "read my values from an encoding.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   237
     The encoding is supposed to be of the form: 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   238
	(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   239
     This is the reverse operation to #literalArrayEncoding."
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   240
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   241
    leftOffset := encoding at:2.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   242
    leftFraction := encoding at:3.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   243
    topOffset := encoding at:4.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   244
    topFraction := encoding at:5.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   245
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   246
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   247
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   248
      LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   249
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   250
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   251
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   252
literalArrayEncoding
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   253
    "encode myself as an array, from which a copy of the receiver
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   254
     can be reconstructed with #decodeAsLiteralArray.
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   255
     The encoding is: 
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   256
        (#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   257
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   258
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   259
    ^ Array
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   260
        with:self class name asSymbol
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   261
        with:leftOffset
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   262
        with:leftFraction
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   263
        with:topOffset
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   264
        with:topFraction
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   265
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   266
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   267
      LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   268
      (LayoutOrigin new leftOffset:10; leftFraction:0.2;
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   269
                       topOffset:20; topFraction:0.4) literalArrayEncoding 
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   270
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   271
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   272
    "Modified: 1.9.1995 / 02:43:48 / claus"
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   273
    "Modified: 22.4.1996 / 13:00:21 / cg"
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   274
! !
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   275
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   276
!LayoutOrigin methodsFor:'initialization'!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   277
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   278
initialize
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   279
    leftOffset := topOffset := 0.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   280
    leftFraction := topFraction := 0.
77
claus
parents:
diff changeset
   281
! !
claus
parents:
diff changeset
   282
83
claus
parents: 77
diff changeset
   283
!LayoutOrigin methodsFor:'printing & storing'!
claus
parents: 77
diff changeset
   284
claus
parents: 77
diff changeset
   285
displayString
claus
parents: 77
diff changeset
   286
    ^ (self class name) , '(' 
claus
parents: 77
diff changeset
   287
	, 'l: ' , leftFraction displayString
claus
parents: 77
diff changeset
   288
	, '+' , leftOffset displayString
claus
parents: 77
diff changeset
   289
	, ' t: ' , topFraction displayString
claus
parents: 77
diff changeset
   290
	, '+' , topOffset displayString
claus
parents: 77
diff changeset
   291
	, ')'
claus
parents: 77
diff changeset
   292
! !
claus
parents: 77
diff changeset
   293
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   294
!LayoutOrigin methodsFor:'queries'!
77
claus
parents:
diff changeset
   295
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   296
origin
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   297
    ^ leftFraction asFloat @ topFraction asFloat
77
claus
parents:
diff changeset
   298
!
claus
parents:
diff changeset
   299
claus
parents:
diff changeset
   300
rectangleRelativeTo:superRectangle preferred:prefRect
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   301
    "compute the rectangle represented by the receiver,
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   302
     given the superViews rectangle and the views preferredExtent."
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   303
77
claus
parents:
diff changeset
   304
    |x y|
claus
parents:
diff changeset
   305
claus
parents:
diff changeset
   306
    leftOffset isNil ifTrue:[
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   307
        x := 0
77
claus
parents:
diff changeset
   308
    ] ifFalse:[
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   309
        x := leftOffset
77
claus
parents:
diff changeset
   310
    ].
claus
parents:
diff changeset
   311
    topOffset isNil ifTrue:[
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   312
        y := 0
77
claus
parents:
diff changeset
   313
    ] ifFalse:[
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   314
        y := topOffset
77
claus
parents:
diff changeset
   315
    ].
claus
parents:
diff changeset
   316
    leftFraction notNil ifTrue:[
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   317
        x := x + (superRectangle width * leftFraction)
77
claus
parents:
diff changeset
   318
    ].
claus
parents:
diff changeset
   319
    topFraction notNil ifTrue:[
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   320
        y := y + (superRectangle height * topFraction)
77
claus
parents:
diff changeset
   321
    ].
242
5b7f59450c65 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 229
diff changeset
   322
    ^ Rectangle left:x top:y extent:prefRect extent
83
claus
parents: 77
diff changeset
   323
claus
parents: 77
diff changeset
   324
    "
claus
parents: 77
diff changeset
   325
     |superRect lO|
claus
parents: 77
diff changeset
   326
claus
parents: 77
diff changeset
   327
     superRect := 0@0 corner:100@100.
claus
parents: 77
diff changeset
   328
     lO := (LayoutOrigin new).
claus
parents: 77
diff changeset
   329
     lO leftFraction:0.5;
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   330
        topFraction:0.5.
83
claus
parents: 77
diff changeset
   331
     lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
claus
parents: 77
diff changeset
   332
    "
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   333
242
5b7f59450c65 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 229
diff changeset
   334
    "Modified: 8.5.1996 / 20:58:53 / cg"
77
claus
parents:
diff changeset
   335
! !
100
claus
parents: 96
diff changeset
   336
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   337
!LayoutOrigin class methodsFor:'documentation'!
100
claus
parents: 96
diff changeset
   338
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   339
version
242
5b7f59450c65 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 229
diff changeset
   340
    ^ '$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.13 1996-05-08 19:07:11 cg Exp $'
100
claus
parents: 96
diff changeset
   341
! !