LayoutOrigin.st
author Claus Gittinger <cg@exept.de>
Wed, 03 Sep 2008 11:52:12 +0200
changeset 2539 9ed4a786aec2
parent 2134 0ef95141831c
child 3016 e2374dddc45f
permissions -rw-r--r--
category change
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
1600
ac585461747e computed rectangle is truncated here.
Claus Gittinger <cg@exept.de>
parents: 1039
diff changeset
    13
"{ Package: 'stx:libview2' }"
ac585461747e computed rectangle is truncated here.
Claus Gittinger <cg@exept.de>
parents: 1039
diff changeset
    14
77
claus
parents:
diff changeset
    15
Layout subclass:#LayoutOrigin
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    16
	instanceVariableNames:'leftFraction topFraction leftOffset topOffset'
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    17
	classVariableNames:''
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    18
	poolDictionaries:''
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
    19
	category:'Graphics-Geometry'
77
claus
parents:
diff changeset
    20
!
claus
parents:
diff changeset
    21
88
claus
parents: 83
diff changeset
    22
!LayoutOrigin class methodsFor:'documentation'!
claus
parents: 83
diff changeset
    23
claus
parents: 83
diff changeset
    24
copyright
claus
parents: 83
diff changeset
    25
"
claus
parents: 83
diff changeset
    26
 COPYRIGHT (c) 1995 by Claus Gittinger
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    27
	      All Rights Reserved
88
claus
parents: 83
diff changeset
    28
claus
parents: 83
diff changeset
    29
 This software is furnished under a license and may be used
claus
parents: 83
diff changeset
    30
 only in accordance with the terms of that license and with the
claus
parents: 83
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
claus
parents: 83
diff changeset
    32
 be provided or otherwise made available to, or used by, any
claus
parents: 83
diff changeset
    33
 other person.  No title to or ownership of the software is
claus
parents: 83
diff changeset
    34
 hereby transferred.
claus
parents: 83
diff changeset
    35
"
claus
parents: 83
diff changeset
    36
!
claus
parents: 83
diff changeset
    37
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    38
documentation
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    39
"
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    40
    This class is provided to make porting of existing ST-80 applications
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    41
    easier. Instances can be used to control the geometry of a subview, within
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    42
    its superview. It provides the same functionality as a relative origin
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    43
    combined with insets.
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    44
    A layoutOrigin controls the origin of a subcomponent, given a fractional
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    45
    component and an offset component.
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    46
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    47
    Notice: 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    48
        this class was implemented using protocol information
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    49
        from alpha testers - it may not be complete or compatible to
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    50
        the corresponding ST-80 class. 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    51
        If you encounter any incompatibilities, please forward a note 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    52
        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
    53
106b86ca81da documentation
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
    54
    [author:]
106b86ca81da documentation
Claus Gittinger <cg@exept.de>
parents: 191
diff changeset
    55
        Claus Gittinger
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    56
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    57
    [see also:]
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    58
        View
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    59
        LayoutFrame AlignmentOrigin Layout 
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    60
        Rectangle Point
94
8888ddd11323 *** empty log message ***
claus
parents: 93
diff changeset
    61
"
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    62
!
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    63
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    64
examples
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    65
"
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    66
    Although the examples below use a button as component,
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    67
    they work of course with any type of subview ....
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    68
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    69
    using a LayoutOrigin, to arrange for
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    70
    the TOPLEFT of a component be positions
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    71
    at the center (i.e. buttons origin at:0.5 @ 0.5):
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    72
                                                                        [exBegin]
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    73
        |top button|
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    74
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    75
        top := StandardSystemView new.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    76
        top extent:300@300.
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    77
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    78
        button := Button label:'component'.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    79
        top add:button in:(LayoutOrigin new
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    80
                                leftFraction:0.5;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    81
                                topFraction:0.5).
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    82
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    83
        top open
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    84
                                                                        [exEnd]
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    85
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    86
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    87
    like above, but adds an additional offset:
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    88
    (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
    89
                                                                        [exBegin]
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    90
        |top button|
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    91
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    92
        top := StandardSystemView new.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    93
        top extent:300@300.
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
    94
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    95
        button := Button label:'component'.
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    96
        top add:button in:(LayoutOrigin new
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    97
                                leftFraction:0.5;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    98
                                topFraction:0.5;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    99
                                leftOffset:10;
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   100
                                topOffset:20).
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   101
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   102
        top open
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   103
                                                                        [exEnd]
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   104
"
88
claus
parents: 83
diff changeset
   105
! !
claus
parents: 83
diff changeset
   106
77
claus
parents:
diff changeset
   107
!LayoutOrigin class methodsFor:'instance creation'!
claus
parents:
diff changeset
   108
claus
parents:
diff changeset
   109
fractionalFromPoint:aPoint
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   110
    "given a point, create a layoutOrigin representing the same 
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   111
     relative origin."
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   112
83
claus
parents: 77
diff changeset
   113
    ^ (self new) leftFraction:aPoint x topFraction:aPoint y
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   114
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   115
    "
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   116
     LayoutOrigin fractionalFromPoint:0.5@0.5
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   117
    "
77
claus
parents:
diff changeset
   118
!
claus
parents:
diff changeset
   119
claus
parents:
diff changeset
   120
fromPoint:aPoint
1821
5539214ed293 comment
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
   121
    "return a new LayoutOrigin from aPoint.
5539214ed293 comment
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
   122
     If the coordinates are between 0 and 1, 
5539214ed293 comment
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
   123
     take them as fractional parts (relative to superview).
77
claus
parents:
diff changeset
   124
     Otherwise, treat them as absolute offsets."
claus
parents:
diff changeset
   125
claus
parents:
diff changeset
   126
    |x y layout|
claus
parents:
diff changeset
   127
claus
parents:
diff changeset
   128
    x := aPoint x.
claus
parents:
diff changeset
   129
    y := aPoint y.
claus
parents:
diff changeset
   130
    layout := self new.
claus
parents:
diff changeset
   131
    ((x between:0 and:1)
claus
parents:
diff changeset
   132
    and:[y between:0 and:1]) ifTrue:[
1821
5539214ed293 comment
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
   133
        layout leftFraction:x topFraction:y
77
claus
parents:
diff changeset
   134
    ] ifFalse:[
1821
5539214ed293 comment
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
   135
        layout leftOffset:x topOffset:y
77
claus
parents:
diff changeset
   136
    ].
claus
parents:
diff changeset
   137
    ^ layout
93
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   138
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   139
    "
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   140
     LayoutOrigin fromPoint:100@100
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   141
     LayoutOrigin fromPoint:0.5@0.5
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   142
     LayoutOrigin fromPoint:0.5@100
f2389560b8eb *** empty log message ***
claus
parents: 88
diff changeset
   143
    "
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   144
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   145
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   146
offsetFromPoint:aPoint
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   147
    "given a point, create a layoutOrigin representing the same 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   148
     absolute (pixel) origin."
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
    ^ self new leftOffset:aPoint x topOffset:aPoint y
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   151
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
     LayoutOrigin offsetFromPoint:100@100
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
! !
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
!LayoutOrigin methodsFor:'accessing'!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   158
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   159
leftFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   160
    "return 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
    ^ leftFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   163
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   164
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   165
leftFraction:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   166
    "set leftFraction"
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
    leftFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   169
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   170
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   171
leftFraction:something offset:o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   172
    "set leftFraction and offset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   173
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   174
    leftFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   175
    leftOffset := o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   176
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   177
543
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   178
leftFraction:lF offset:lO topFraction:tF offset:tO 
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   179
    "set leftFraction, leftOffset, topFraction and topOffset"
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   180
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   181
    leftFraction := lF. leftOffset := lO.
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   182
    topFraction := tF. topOffset := tO.
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   183
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   184
    "Created: 18.4.1997 / 20:07:15 / cg"
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   185
!
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   186
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   187
leftFraction:newLeft topFraction:newTop 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   188
    "set leftFraction and topFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   189
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   190
    leftFraction := newLeft.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   191
    topFraction := newTop.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   192
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   193
275
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   194
leftInset:pixels
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   195
    "set leftOffset for an inset at the left"
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   196
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   197
    leftOffset := pixels.
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   198
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   199
    "Created: 26.5.1996 / 17:38:55 / cg"
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   200
    "Modified: 26.5.1996 / 17:42:16 / cg"
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   201
!
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   202
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   203
leftOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   204
    "return leftOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   205
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   206
    ^ leftOffset
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
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   209
leftOffset:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   210
    "set leftOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   211
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   212
    leftOffset := something.
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
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   215
leftOffset:newLeft topOffset:newTop 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   216
    "set leftOffset and topOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   217
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   218
    leftOffset := newLeft.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   219
    topOffset := newTop.
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
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   222
topFraction
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   223
    "return topFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   224
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   225
    ^ topFraction
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
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   228
topFraction:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   229
    "set topFraction"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   230
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   231
    topFraction := something.
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
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   234
topFraction:something offset:o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   235
    "set topFraction and offset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   236
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   237
    topFraction := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   238
    topOffset := o
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   239
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   240
275
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   241
topInset:pixels
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   242
    "set topOffset for an inset at the top"
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   243
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   244
    topOffset := pixels.
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   245
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   246
    "Created: 26.5.1996 / 17:39:00 / cg"
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   247
    "Modified: 26.5.1996 / 17:42:12 / cg"
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   248
!
d500c08871ab added inset methods
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
   249
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   250
topOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   251
    "return topOffset"
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   252
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   253
    ^ topOffset
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   254
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   255
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   256
topOffset:something
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   257
    "set topOffset"
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
    topOffset := something.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   260
! !
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   261
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   262
!LayoutOrigin methodsFor:'converting'!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   263
543
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   264
asAlignmentOrigin
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   265
    "return an equivalent alignmentOrigin"
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   266
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   267
    ^ AlignmentOrigin new
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   268
        leftFraction:leftFraction offset:leftOffset;
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   269
        topFraction:topFraction offset:topOffset;
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   270
        leftAlignmentFraction:0 topAlignmentFraction: 0;
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   271
        yourself
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   272
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   273
    "Created: 18.4.1997 / 20:08:14 / cg"
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   274
!
1e730ed96b0b added conversion to alignmentOrigin and another access method.
Claus Gittinger <cg@exept.de>
parents: 415
diff changeset
   275
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   276
fromLiteralArrayEncoding:encoding
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   277
    "read my values from an encoding.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   278
     The encoding is supposed to be of the form: 
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   279
	(#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   280
     This is the reverse operation to #literalArrayEncoding."
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   281
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   282
    leftOffset := encoding at:2.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   283
    leftFraction := encoding at:3.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   284
    topOffset := encoding at:4.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   285
    topFraction := encoding at:5.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   286
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   287
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   288
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   289
      LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   290
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   291
!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   292
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   293
literalArrayEncoding
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   294
    "encode myself as an array, from which a copy of the receiver
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   295
     can be reconstructed with #decodeAsLiteralArray.
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   296
     The encoding is: 
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   297
        (#LayoutOrigin orgOffsX relOrgX orgOffsY relOrgY)
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   298
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   299
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   300
    ^ Array
2134
0ef95141831c Fix comments.
Stefan Vogel <sv@exept.de>
parents: 1821
diff changeset
   301
        with:self class name
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   302
        with:leftOffset
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   303
        with:leftFraction
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   304
        with:topOffset
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   305
        with:topFraction
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   306
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   307
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   308
      LayoutOrigin new fromLiteralArrayEncoding:#(#LayoutOrigin 70 0 2 0)
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   309
      (LayoutOrigin new leftOffset:10; leftFraction:0.2;
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   310
                       topOffset:20; topFraction:0.4) literalArrayEncoding 
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   311
    "
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   312
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   313
    "Modified: 1.9.1995 / 02:43:48 / claus"
191
cb2815b77100 commentary
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
   314
    "Modified: 22.4.1996 / 13:00:21 / cg"
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   315
! !
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   316
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   317
!LayoutOrigin methodsFor:'initialization'!
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   318
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   319
initialize
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   320
    leftOffset := topOffset := 0.
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   321
    leftFraction := topFraction := 0.
77
claus
parents:
diff changeset
   322
! !
claus
parents:
diff changeset
   323
83
claus
parents: 77
diff changeset
   324
!LayoutOrigin methodsFor:'printing & storing'!
claus
parents: 77
diff changeset
   325
claus
parents: 77
diff changeset
   326
displayString
700
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   327
    "return a printed representation of the receiver for displaying"
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   328
83
claus
parents: 77
diff changeset
   329
    ^ (self class name) , '(' 
700
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   330
        , 'l: ' , leftFraction displayString
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   331
        , '+' , leftOffset displayString
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   332
        , ' t: ' , topFraction displayString
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   333
        , '+' , topOffset displayString
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   334
        , ')'
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   335
67f1dccb8333 comments
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
   336
    "Modified: 20.9.1997 / 11:40:19 / cg"
83
claus
parents: 77
diff changeset
   337
! !
claus
parents: 77
diff changeset
   338
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   339
!LayoutOrigin methodsFor:'queries'!
77
claus
parents:
diff changeset
   340
415
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   341
isLayoutOrigin
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   342
    "return true, if this is a layoutOrigin"
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   343
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   344
    ^ true
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   345
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   346
!
5d1bf4dffbf5 *** empty log message ***
ca
parents: 275
diff changeset
   347
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   348
origin
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   349
    ^ leftFraction asFloat @ topFraction asFloat
77
claus
parents:
diff changeset
   350
!
claus
parents:
diff changeset
   351
949
0eb888b21192 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 700
diff changeset
   352
rectangleRelativeTo:superRectangle preferred:prefRectHolder
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   353
    "compute the rectangle represented by the receiver,
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   354
     given the superViews rectangle and the views preferredExtent."
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   355
949
0eb888b21192 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 700
diff changeset
   356
    |x y prefRect|
0eb888b21192 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 700
diff changeset
   357
0eb888b21192 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 700
diff changeset
   358
    prefRect := prefRectHolder value.
77
claus
parents:
diff changeset
   359
1039
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   360
    x := superRectangle left.
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   361
    y := superRectangle top.
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   362
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   363
    leftOffset notNil ifTrue:[
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   364
        x := x + leftOffset value
77
claus
parents:
diff changeset
   365
    ].
1039
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   366
    topOffset notNil ifTrue:[
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   367
        y := y + topOffset value
77
claus
parents:
diff changeset
   368
    ].
claus
parents:
diff changeset
   369
    leftFraction notNil ifTrue:[
1601
Claus Gittinger <cg@exept.de>
parents: 1600
diff changeset
   370
        x := x + (superRectangle width * leftFraction value)
77
claus
parents:
diff changeset
   371
    ].
claus
parents:
diff changeset
   372
    topFraction notNil ifTrue:[
1601
Claus Gittinger <cg@exept.de>
parents: 1600
diff changeset
   373
        y := y + (superRectangle height * topFraction value)
77
claus
parents:
diff changeset
   374
    ].
242
5b7f59450c65 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 229
diff changeset
   375
    ^ Rectangle left:x top:y extent:prefRect extent
83
claus
parents: 77
diff changeset
   376
claus
parents: 77
diff changeset
   377
    "
claus
parents: 77
diff changeset
   378
     |superRect lO|
claus
parents: 77
diff changeset
   379
claus
parents: 77
diff changeset
   380
     superRect := 0@0 corner:100@100.
claus
parents: 77
diff changeset
   381
     lO := (LayoutOrigin new).
claus
parents: 77
diff changeset
   382
     lO leftFraction:0.5;
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   383
        topFraction:0.5.
83
claus
parents: 77
diff changeset
   384
     lO rectangleRelativeTo:superRect preferred:(0@0 corner:30@30)
claus
parents: 77
diff changeset
   385
    "
229
612861ef768a examples
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   386
1039
4095e7721dad fixed framedBox computation.
Claus Gittinger <cg@exept.de>
parents: 949
diff changeset
   387
    "Modified: / 13.8.1998 / 18:39:49 / cg"
77
claus
parents:
diff changeset
   388
! !
100
claus
parents: 96
diff changeset
   389
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   390
!LayoutOrigin class methodsFor:'documentation'!
100
claus
parents: 96
diff changeset
   391
126
25df58661f32 version at the end
Claus Gittinger <cg@exept.de>
parents: 114
diff changeset
   392
version
2134
0ef95141831c Fix comments.
Stefan Vogel <sv@exept.de>
parents: 1821
diff changeset
   393
    ^ '$Header: /cvs/stx/stx/libview2/LayoutOrigin.st,v 1.24 2006-07-03 16:10:12 stefan Exp $'
100
claus
parents: 96
diff changeset
   394
! !