Ruler.st
author Claus Gittinger <cg@exept.de>
Fri, 31 May 1996 19:23:26 +0200
changeset 195 0fbaea91aa3d
parent 194 e57ac9093b2d
child 196 9311b28d1a32
permissions -rw-r--r--
use UnitConverter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     1
"
4
claus
parents: 2
diff changeset
     2
 COPYRIGHT (c) 1991 by Claus Gittinger
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
     3
	      All Rights Reserved
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     4
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
0fd7841626f6 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
0fd7841626f6 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
0fd7841626f6 Initial revision
claus
parents:
diff changeset
    11
"
0fd7841626f6 Initial revision
claus
parents:
diff changeset
    12
49
claus
parents: 42
diff changeset
    13
SimpleView subclass:#Ruler
117
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    14
	instanceVariableNames:'fgColor metric paperWidth paperHeight scale showUnit'
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    15
	classVariableNames:''
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    16
	poolDictionaries:''
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    17
	category:'Views-Misc'
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
    18
!
0fd7841626f6 Initial revision
claus
parents:
diff changeset
    19
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    20
!Ruler class methodsFor:'documentation'!
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    21
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    22
copyright
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    23
"
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    24
 COPYRIGHT (c) 1991 by Claus Gittinger
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    25
	      All Rights Reserved
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    26
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    27
 This software is furnished under a license and may be used
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    28
 only in accordance with the terms of that license and with the
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    30
 be provided or otherwise made available to, or used by, any
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    31
 other person.  No title to or ownership of the software is
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    32
 hereby transferred.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    33
"
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    34
!
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    35
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    36
documentation
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    37
"
117
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    38
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    39
    a shows some unit scale; See example use in DrawTool.
36
160b8f0dfd7d *** empty log message ***
claus
parents: 34
diff changeset
    40
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    41
    instance variables:
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    42
117
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    43
        fgColor         <Color>         color to draw text and marks with
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    44
        metric          <Symbol>        inch or mm
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    45
        paperWidth      <Number>        width of paper
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    46
        paperHeight     <Number>        height of paper
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    47
        scale           <Number>        scale factor for zoom
e52304e1b185 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
    48
        showUnit        <Boolean>       if true, a unit string is displayed
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    49
"
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    50
!
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    51
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    52
examples
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    53
"
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    54
                                                                        [exBegin]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    55
    |top ruler|
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    56
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    57
    top := StandardSystemView new.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    58
    ruler := Ruler origin:0.0@0.0 corner:1.0@30 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    59
    top open
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    60
                                                                        [exEnd]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    61
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    62
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    63
  defining paperWidth:
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    64
                                                                        [exBegin]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    65
    |top ruler|
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    66
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    67
    top := StandardSystemView new.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    68
    ruler := Ruler origin:0.0@0.0 corner:1.0@30 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    69
    ruler paperWidthInch:5.   
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    70
    top open
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    71
                                                                        [exEnd]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    72
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    73
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    74
  hide unit string:
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    75
                                                                        [exBegin]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    76
    |top ruler|
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    77
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    78
    top := StandardSystemView new.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    79
    ruler := Ruler origin:0.0@0.0 corner:1.0@30 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    80
    ruler showUnit:false.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    81
    top open
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    82
                                                                        [exEnd]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    83
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    84
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    85
  both horizontal and vertical rulers (as in DrawTool):
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    86
                                                                        [exBegin]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    87
    |top hRuler vRuler|
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
    88
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    89
    top := StandardSystemView new.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    90
    hRuler := Ruler origin:30@0.0 corner:1.0@30 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    91
    vRuler := VerticalRuler origin:0.0@30 corner:30@1.0 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    92
    vRuler showUnit:false.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    93
    top open
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    94
                                                                        [exEnd]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    95
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    96
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    97
  with some 3D effects:
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
    98
                                                                        [exBegin]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
    99
    |top hRuler vRuler|
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   100
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   101
    top := StandardSystemView new.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   102
    hRuler := Ruler origin:30@0.0 corner:1.0@30 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   103
    vRuler := VerticalRuler origin:0.0@30 corner:30@1.0 in:top.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   104
    vRuler showUnit:false.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   105
    hRuler level:1.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   106
    vRuler level:1.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   107
    top open
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   108
                                                                        [exEnd]
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   109
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   110
  see the DrawTool, for how to make it scroll in sync with some
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   111
  other view. 
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   112
"
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   113
! !
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   114
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   115
!Ruler methodsFor:'accessing'!
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   116
95
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   117
heightOfContents
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   118
    ^ (device verticalPixelPerInch * paperHeight) rounded
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   119
!
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   120
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   121
metric:aSymbol
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   122
    "set the metric. The argument may be either #inch or #mm"
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   123
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   124
    aSymbol ~~ metric ifTrue:[
194
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   125
        metric := aSymbol.
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   126
        self invalidate
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   127
    ]
194
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   128
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   129
    "Modified: 29.5.1996 / 16:42:46 / cg"
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   130
!
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   131
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   132
paperWidthInch:inches
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   133
    "set the width of the document"
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   134
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   135
    paperWidth := inches.
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   136
    shown ifTrue:[
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   137
	self redraw
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   138
    ]
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   139
!
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   140
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   141
paperWidthMM:millis
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   142
    "set the width of the document"
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   143
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   144
    paperWidth := self millimeterToInch:millis.
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   145
    shown ifTrue:[
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   146
	self redraw
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   147
    ]
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   148
!
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   149
95
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   150
scale:aFactor
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   151
    "set the scale factor. 1 is identity."
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   152
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   153
    aFactor ~= scale ifTrue:[
194
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   154
        scale := aFactor.
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   155
        self invalidate
95
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   156
    ]
194
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   157
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   158
    "Modified: 29.5.1996 / 16:42:56 / cg"
95
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   159
!
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   160
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   161
showUnit:aBoolean
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   162
    "set/clear the showUnit flag. If false, the unit string
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   163
     (i.e. 'inch' or 'mm') is not schown. Default is true."
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   164
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   165
    showUnit := aBoolean.
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   166
!
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   167
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   168
viewOrigin:origin
33
3e68e4c73db3 last version before big scrolling change
claus
parents: 30
diff changeset
   169
    origin = self viewOrigin ifTrue:[^ self].
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   170
    super setViewOrigin:origin.
194
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   171
    self invalidate
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   172
e57ac9093b2d use #invalidate instead of #redraw
Claus Gittinger <cg@exept.de>
parents: 161
diff changeset
   173
    "Modified: 29.5.1996 / 16:43:03 / cg"
28
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   174
!
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   175
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   176
widthOfContents
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   177
    ^ (device horizontalPixelPerInch * paperWidth) rounded
95
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   178
! !
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   179
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   180
!Ruler methodsFor:'initialization'!
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   181
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   182
initialize
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   183
    super initialize.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   184
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   185
    viewBackground := styleSheet colorAt:#rulerBackgroundColor default:viewBackground.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   186
    fgColor := styleSheet colorAt:#rulerForegroundColor.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   187
    fgColor isNil ifTrue:[
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   188
	fgColor := styleSheet colorAt:#foregroundColor.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   189
    ].
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   190
    fgColor isNil ifTrue:[
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   191
	viewBackground brightness > 0.5 ifTrue:[
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   192
	    fgColor := Black.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   193
	] ifFalse:[
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   194
	    fgColor := White
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   195
	].
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   196
    ].
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   197
    fgColor := fgColor on:device.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   198
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   199
    bitGravity := #NorthWest.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   200
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   201
    self height:(font height + (2 * font descent)). 
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   202
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   203
    (Smalltalk language == #english) ifTrue:[
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   204
	metric := #inch
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   205
    ] ifFalse:[
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   206
	metric := #mm
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   207
    ].
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   208
    metric := styleSheet at:#rulerMetric default:metric.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   209
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   210
    showUnit := true.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   211
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   212
    scale := 1.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   213
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   214
    paperWidth := 8.5.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   215
    paperHeight := 11.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   216
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   217
    "
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   218
     take a smaller font
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   219
    "
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   220
    font := (Font family:(font family)
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   221
		    face:(font face)
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   222
		   style:(font style)
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   223
		    size:8) on:device.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   224
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   225
    "
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   226
     Ruler new open
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   227
    "
28
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   228
!
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   229
95
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   230
reinitialize
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   231
    super reinitialize.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   232
    font := font on:device.
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   233
! !
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   234
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   235
!Ruler methodsFor:'metric conversions'!
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   236
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   237
inchToPixel:inches
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   238
    "convert inches to screen pixels"
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   239
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   240
    ^ inches * self horizontalPixelPerInch
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   241
!
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   242
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   243
millimeterToPixel:mm
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   244
    "convert mms to screen pixels"
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   245
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   246
    ^ mm * self horizontalPixelPerMillimeter
041618c4207f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   247
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   248
! !
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   249
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   250
!Ruler methodsFor:'redrawing'!
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   251
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   252
redraw
28
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   253
    "redraw the scale"
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   254
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   255
    |x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   256
     top paperWidthMM paperWidthPixel xOrigin labelRight stringRight marg|
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   257
24
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   258
    shown ifFalse:[^ self].
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   259
6704fad5eb7d *** empty log message ***
claus
parents: 11
diff changeset
   260
    self clear.
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   261
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   262
    xOrigin := self viewOrigin x.
6
ff95fd6d4e96 *** empty log message ***
claus
parents: 4
diff changeset
   263
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   264
    paperWidthPixel := ((self inchToPixel:paperWidth) * scale) rounded.
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   265
6
ff95fd6d4e96 *** empty log message ***
claus
parents: 4
diff changeset
   266
    (xOrigin + width > paperWidthPixel) ifTrue:[
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   267
        self paint:(Color darkGrey).
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   268
        self fillRectangleX:paperWidthPixel y:0
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   269
                      width:(xOrigin + width - paperWidthPixel) 
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   270
                      height:height.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   271
        self paint:fgColor.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   272
        self displayLineFromX:paperWidthPixel y:0
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   273
                          toX:paperWidthPixel y:height
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   274
    ].
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   275
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   276
    self paint:fgColor.
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   277
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   278
    top := height - font height - font ascent.
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   279
    longLen := font height.
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   280
    shortLen := longLen // 2.
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   281
    charY := top + (font ascent) + shortLen.
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   282
    mod := 1.
6
ff95fd6d4e96 *** empty log message ***
claus
parents: 4
diff changeset
   283
    marg := 3. "character shift"
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   284
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   285
    (metric == #mm) ifTrue:[
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   286
        "centimeter - long blibs every centimeter; short ones every half"
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   287
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   288
        paperWidthMM := UnitConverter inchToMillimeter:paperWidth.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   289
        pixelPerMM := (self millimeterToPixel:1) * scale.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   290
        pos := 5.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   291
        showUnit ifTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   292
            labelRight := stringRight := marg + (font widthOf:'cm') + 3 + xOrigin.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   293
        ] ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   294
            labelRight := stringRight := xOrigin.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   295
        ].
6
ff95fd6d4e96 *** empty log message ***
claus
parents: 4
diff changeset
   296
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   297
        x := (pixelPerMM * pos) rounded.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   298
        [(x < (width+xOrigin)) and:[pos <= paperWidthMM]] whileTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   299
            |l|
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   300
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   301
            l := shortLen.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   302
            (mod ~~ 1) ifTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   303
                x < stringRight ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   304
                    l := longLen
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   305
                ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   306
            ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   307
            self displayLineFromX:x y:top
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   308
                              toX:x y:(top + l).
26
ff148983c183 *** empty log message ***
claus
parents: 24
diff changeset
   309
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   310
            ((x < stringRight) or:[mod == 1]) ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   311
                self displayString:(pos // 10) printString
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   312
                                 x:(x + marg)
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   313
                                 y:charY.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   314
                stringRight := x + marg 
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   315
                                + (font widthOf:(pos // 10) printString)
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   316
            ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   317
            mod := (mod + 1) \\ 2.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   318
            pos := pos + 5.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   319
            x := (pixelPerMM * pos) rounded 
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   320
        ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   321
        self displayString:'cm ' x:marg+xOrigin y:charY.
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   322
    ].
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   323
    (metric == #inch) ifTrue:[
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   324
        "inches - long blibs every inch; short ones every half; very
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   325
         short ones every quarter"
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   326
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   327
        pixelPerInch := (self inchToPixel:1) * scale.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   328
        pos := 0.25.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   329
        showUnit ifTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   330
            labelRight := marg + (font widthOf:'inch') + 3 + xOrigin.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   331
        ] ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   332
            labelRight := xOrigin
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   333
        ].
6
ff95fd6d4e96 *** empty log message ***
claus
parents: 4
diff changeset
   334
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   335
        x := (pixelPerInch * pos) rounded.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   336
        veryShortLen := longLen // 4.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   337
        [(x < (xOrigin+width)) and:[pos <= paperWidth]] whileTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   338
            |l|
28
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   339
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   340
            l := shortLen.    
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   341
            (mod == 0) ifTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   342
                x < labelRight ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   343
                    l := longLen
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   344
                ]
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   345
            ] ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   346
                (mod == 2) ifFalse:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   347
                    l := veryShortLen
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   348
                ]
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   349
            ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   350
            self displayLineFromX:x y:top
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   351
                              toX:x y:(top + l).
28
ca403f4c5b86 *** empty log message ***
claus
parents: 26
diff changeset
   352
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   353
            (mod == 0 and:[x >= labelRight]) ifTrue:[
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   354
                self displayString:pos asInteger printString
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   355
                                 x:(x + marg)
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   356
                                 y:charY
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   357
            ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   358
            mod := (mod + 1) \\ 4.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   359
            pos := pos + 0.25.
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   360
            x := (pixelPerInch * pos) rounded
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   361
        ].
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   362
        self displayString:'inch ' x:marg+xOrigin y:charY.
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   363
    ].
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   364
    self redrawEdges
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   365
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   366
    "Modified: 31.5.1996 / 18:06:55 / cg"
0
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   367
! !
0fd7841626f6 Initial revision
claus
parents:
diff changeset
   368
99
27c080be3479 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 95
diff changeset
   369
!Ruler class methodsFor:'documentation'!
27c080be3479 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 95
diff changeset
   370
27c080be3479 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 95
diff changeset
   371
version
195
0fbaea91aa3d use UnitConverter
Claus Gittinger <cg@exept.de>
parents: 194
diff changeset
   372
    ^ '$Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.24 1996-05-31 17:23:16 cg Exp $'
99
27c080be3479 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 95
diff changeset
   373
! !