HorizontalScale.st
changeset 1229 a0a54048f8ee
parent 86 4d7dbb5f1719
child 3150 e3a55f15ef7e
equal deleted inserted replaced
1228:0aae4f7389ca 1229:a0a54048f8ee
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 SimpleView subclass:#HorizontalScale
    13 SimpleView subclass:#HorizontalScale
    14 	 instanceVariableNames:'slider range action'
    14 	instanceVariableNames:'slider range action'
    15 	 classVariableNames:''
    15 	classVariableNames:''
    16 	 poolDictionaries:''
    16 	poolDictionaries:''
    17 	 category:'Views-Interactors'
    17 	category:'Views-Interactors'
    18 !
    18 !
    19 
    19 
    20 !HorizontalScale class methodsFor:'documentation'!
    20 !HorizontalScale class methodsFor:'documentation'!
    21 
    21 
    22 copyright
    22 copyright
    31  other person.  No title to or ownership of the software is
    31  other person.  No title to or ownership of the software is
    32  hereby transferred.
    32  hereby transferred.
    33 "
    33 "
    34 !
    34 !
    35 
    35 
    36 version
       
    37     ^ '$Header: /cvs/stx/stx/libwidg2/HorizontalScale.st,v 1.4 1995-11-11 16:28:57 cg Exp $'
       
    38 !
       
    39 
       
    40 documentation
    36 documentation
    41 "
    37 "
    42     like a slider, but with a range (i.e. may be different from 0..100)
    38     like a slider, but with a range (i.e. may be different from 0..100)
    43     and displaying the current value.
    39     and displaying the current value.
    44 "
    40 "
    45 ! !
    41 !
    46 
    42 
    47 !HorizontalScale methodsFor:'slider actions'!
    43 examples 
       
    44 "
       
    45     |top s1 s2|
    48 
    46 
    49 scroll:percent
    47     top := StandardSystemView new.
    50     |value x label|
    48     top extent:200@200.
       
    49     s1 := HorizontalScale origin:0.0 @ 0.0 in:top.
       
    50     s1 extent:1.0 @ 50.
    51 
    51 
    52     action notNil ifTrue:[
    52     s2 := HorizontalScale origin:0.0 @ 0.5 in:top.
    53 	value := (range last - range first) * (percent / 100).
    53     s2 extent:1.0 @ 50.
    54 	value := value + range first.
    54     s2 range:(-50 to:50).
    55 	action value:value.
    55     top open
       
    56 "
    56 
    57 
    57 	x := slider thumbFrame left + (slider thumbFrame width // 2).
       
    58 	self clear.
       
    59 	self paint:Black.
       
    60 	value := value roundTo:(range last - range first) / 100.
       
    61 	label := value asFloat printString.
       
    62 	(label endsWith:'.0') ifTrue:[
       
    63 	    label := value asInteger printString
       
    64 	].
       
    65 	self displayString:label
       
    66 			 x:x + ((font widthOf:label) // 2)
       
    67 			 y:slider height + device verticalPixelPerMillimeter
       
    68     ]
       
    69 ! !
    58 ! !
    70 
    59 
    71 !HorizontalScale methodsFor:'accessing'!
    60 !HorizontalScale methodsFor:'accessing'!
    72 
    61 
    73 range:anInterval
    62 range:anInterval
    76 
    65 
    77 scrollAction:aBlock
    66 scrollAction:aBlock
    78     action := aBlock
    67     action := aBlock
    79 ! !
    68 ! !
    80 
    69 
       
    70 !HorizontalScale methodsFor:'drawing'!
       
    71 
       
    72 redraw
       
    73     |percent value x label|
       
    74 
       
    75     percent := slider thumbOrigin.
       
    76 
       
    77     value := (range last - range first) * (percent / 100).
       
    78     value := value + range first.
       
    79 
       
    80     x := slider thumbFrame left + (slider thumbFrame width // 2).
       
    81     self clear.
       
    82     self paint:Black.
       
    83     value := value roundTo:(range last - range first) / 100.
       
    84     label := value asFloat printString.
       
    85     (label endsWith:'.0') ifTrue:[
       
    86         label := value asInteger printString
       
    87     ].
       
    88     self displayString:label
       
    89                      x:x - ((font widthOf:label) // 2)
       
    90                      y:font ascent + device verticalPixelPerMillimeter
       
    91 
       
    92     "Created: / 7.3.1999 / 00:16:54 / cg"
       
    93     "Modified: / 7.3.1999 / 00:26:19 / cg"
       
    94 ! !
       
    95 
    81 !HorizontalScale methodsFor:'initialization'!
    96 !HorizontalScale methodsFor:'initialization'!
    82 
    97 
    83 initialize
    98 initialize
    84     super initialize.
    99     super initialize.
    85 
   100 
    86     range := (0 to:100).
   101     range := (0 to:100).
    87     slider := HorizontalSlider in:self.
   102     slider := HorizontalSlider in:self.
    88     slider origin:0.0 @ (font height + device verticalPixelPerMillimeter rounded).
   103     slider origin:0.0 @ (font height + device verticalPixelPerMillimeter rounded).
    89     slider extent:1.0 @ slider height.
   104     slider width:1.0.
    90     self height:(slider height  
   105 
    91 		+ (font height)
   106 "/    self height:(slider height  
    92 		+ (device verticalPixelPerMillimeter * 2) rounded).
   107 "/                + (font height)
       
   108 "/                + (device verticalPixelPerMillimeter * 2) rounded).
    93 
   109 
    94     slider scrollAction:[:percent | self scroll:percent].
   110     slider scrollAction:[:percent | self scroll:percent].
       
   111 
       
   112     "Modified: / 7.3.1999 / 00:21:52 / cg"
    95 ! !
   113 ! !
       
   114 
       
   115 !HorizontalScale methodsFor:'queries'!
       
   116 
       
   117 preferredExtent
       
   118     ^ slider preferredExtent + (0 @ (font height + device verticalPixelPerMillimeter rounded))
       
   119 
       
   120     "Created: / 7.3.1999 / 00:18:28 / cg"
       
   121     "Modified: / 7.3.1999 / 00:24:40 / cg"
       
   122 ! !
       
   123 
       
   124 !HorizontalScale methodsFor:'slider actions'!
       
   125 
       
   126 scroll:percent
       
   127     |value|
       
   128 
       
   129     value := (range last - range first) * (percent / 100).
       
   130     value := value + range first.
       
   131     action notNil ifTrue:[
       
   132         action value:value.
       
   133     ].
       
   134     self redraw
       
   135 
       
   136     "Modified: / 7.3.1999 / 00:17:33 / cg"
       
   137 ! !
       
   138 
       
   139 !HorizontalScale class methodsFor:'documentation'!
       
   140 
       
   141 version
       
   142     ^ '$Header: /cvs/stx/stx/libwidg2/HorizontalScale.st,v 1.5 1999-03-07 13:25:09 cg Exp $'
       
   143 ! !