author | Claus Gittinger <cg@exept.de> |
Fri, 01 Sep 2017 14:24:45 +0200 | |
changeset 6201 | 5493871b7dd2 |
parent 6177 | e80cfdebfdbe |
child 6238 | 341edb64b989 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2192
e9068416fd41
foreground-, backgroundChannel moved to superclass (#destroy)
Stefan Vogel <sv@exept.de>
parents:
2098
diff
changeset
|
12 |
"{ Package: 'stx:libwidg' }" |
e9068416fd41
foreground-, backgroundChannel moved to superclass (#destroy)
Stefan Vogel <sv@exept.de>
parents:
2098
diff
changeset
|
13 |
|
5445 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
0 | 16 |
View subclass:#Label |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
17 |
instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust |
2496 | 18 |
hSpace vSpace bgColor fgColor etchedFgColor fixSize labelMsg |
19 |
converter labelChannel' |
|
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
20 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor' |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
21 |
poolDictionaries:'' |
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
22 |
category:'Views-Layout' |
0 | 23 |
! |
24 |
||
5751 | 25 |
Object subclass:#AnimatorState |
5755 | 26 |
instanceVariableNames:'timedBlock nextOffset logoShown moveDirection pointerEntered' |
5751 | 27 |
classVariableNames:'' |
28 |
poolDictionaries:'' |
|
29 |
privateIn:Label |
|
30 |
! |
|
31 |
||
935 | 32 |
!Label class methodsFor:'documentation'! |
3 | 33 |
|
38 | 34 |
copyright |
35 |
" |
|
36 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 37 |
All Rights Reserved |
38 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
3 | 48 |
documentation |
49 |
" |
|
38 | 50 |
This class implements labels, which are views to display a string or image. |
51 |
The Label will try to do its best to make its contents fit into the |
|
52 |
view. The contents can be a String, a collection of Strings (i.e. |
|
118 | 53 |
a StringCollection) or a Form/Image. |
63 | 54 |
|
55 |
The contents is drawn in fgColor/bgColor, which can be changed using: |
|
56 |
||
585 | 57 |
aLabel foregroundColor:aColor |
58 |
aLabel backgroundColor:aColor |
|
3 | 59 |
|
38 | 60 |
When a label is assigned a contents, it will resize itself to fit |
61 |
the required size. This resizing can be suppressed by setting the |
|
62 |
fixsize attribute to true using: |
|
63 | 63 |
|
585 | 64 |
aLabel sizeFixed:true |
3 | 65 |
|
38 | 66 |
This can be used, if resizing of the label is not wanted. |
63 | 67 |
However, in this case you have to make certain that the size is big enough |
118 | 68 |
to hold any changed logos later. (usually, you create the label first with |
69 |
the longest string first to have it compute its size, then set the fixSize |
|
70 |
attribute to avoid resizing later). |
|
125 | 71 |
Be careful when placing self-resizing labels into panels - by default, |
72 |
panels do not react on the size change - leading to ugly looking geometry. |
|
73 |
(but you can tell the panel to watch for changes with #elementsCHangeSize:) |
|
38 | 74 |
|
75 |
The placement of the contents within the label is controlled by |
|
63 | 76 |
the adjust attribute, it can be set with: |
77 |
||
585 | 78 |
aLabel adjust:how |
3 | 79 |
|
1946 | 80 |
where how is one of the symbols left, #right, #center, #centerEach, |
81 |
#centerLeft, #centerRight, #leftRight or #rightLeft |
|
82 |
(see the comment in Label>>adjust:). The default is #center. |
|
3 | 83 |
|
145 | 84 |
model-less operation (ok for static labels): |
118 | 85 |
if no model is set, the labels contents is set with: |
86 |
||
585 | 87 |
aLabel label:aStringOrImage |
118 | 88 |
|
89 |
and stays constant unless changed by new calls to #label:. |
|
90 |
||
91 |
||
145 | 92 |
model operation (ST-80 style): |
118 | 93 |
labels with a model, aspectMsg and labelMsg react to |
94 |
changes of the aspect, and send a labelMsg-message |
|
5782 | 95 |
to the model in order to acquire a new labelString or image. |
118 | 96 |
The model should send 'self changed:aspectMsg' if it thinks the label |
97 |
should change and return a string or image from the labelMsg-message. |
|
98 |
||
585 | 99 |
label model:aModel. |
100 |
label aspect:aspectSymbol. |
|
101 |
label labelMessage:labelSymbol. |
|
118 | 102 |
|
585 | 103 |
model sends #changed:aspectSymbol |
104 |
---> label will redraw its label from value of model perform:labelSymbol |
|
118 | 105 |
|
106 |
Having a labelSymbol different from the aspectSymbol allows for two labels |
|
107 |
to react on the same aspect-change, but use different messages when asking |
|
108 |
the model for a new label contents. By default, the labelMsg is nil, |
|
109 |
so the label does NOT update its shown contents. |
|
110 |
The aspectMsg defaults to #value. |
|
111 |
||
125 | 112 |
|
145 | 113 |
|
114 |
channel operation (new ST/X style): |
|
115 |
||
116 |
the label will react on changes of the token found in the |
|
117 |
channels: foregroundChannel, backgroundChannel and labelChannel. |
|
118 |
These are valueHolders and can be shared between labels. |
|
119 |
||
120 |
||
121 |
||
585 | 122 |
[Instance variables:] |
3 | 123 |
|
585 | 124 |
logo <Object> the logo, can be a Form, String or Text |
125 |
labelWidth <Integer> the width of the logo in device units |
|
126 |
labelHeight <Integer> the height of the logo in device units |
|
127 |
labelOriginX <Integer> the x-position of the logo withing the Label |
|
128 |
labelOriginY <Integer> the y-position of the logo withing the Label |
|
129 |
adjust <Symbol> controls how the logo is positioned within the |
|
130 |
label. Can be one of:#left,#right,#center, |
|
131 |
#centerLeft or #centerRight (see comment in adjust:) |
|
132 |
hSpace <Integer> number of horizontal pixels around logo |
|
133 |
vSpace <Integer> number of vertical pixels around logo |
|
3 | 134 |
|
585 | 135 |
bgColor <Color> background color |
136 |
fgColor <Color> foreground color |
|
38 | 137 |
|
585 | 138 |
fixSize <Boolean> if true, a change of the logo change will not |
139 |
resize the label; otherwise, its size is adjusted. |
|
140 |
default:false. |
|
50 | 141 |
|
585 | 142 |
labelMsg <Symbol> if non-nil, this is sent to the model to |
5782 | 143 |
acquire the labelString or labelImage. |
585 | 144 |
If nil, the label stays as is |
113 | 145 |
|
585 | 146 |
[styleSheet parameters:] |
50 | 147 |
|
118 | 148 |
labelForegroundColor <Color> color to draw foreground pixels (i.e. the string) |
149 |
labelBackgroundColor <Color> color to draw background pixels |
|
150 |
labelFont <Font> font to use for textual labels |
|
585 | 151 |
|
152 |
[author:] |
|
153 |
Claus Gittinger |
|
593 | 154 |
|
155 |
[see also:] |
|
156 |
Panel HorizontalPanel VerticalPanel |
|
157 |
TextView EditTextView |
|
158 |
Button |
|
159 |
InfoBox WarningBox |
|
3 | 160 |
" |
63 | 161 |
! |
162 |
||
163 |
examples |
|
164 |
" |
|
165 |
Notice, that Buttons and others inherit from Label; |
|
166 |
therefore, the following geometry examples apply to all subclasses too. |
|
167 |
||
168 |
||
113 | 169 |
simple (default position is 0@0): |
593 | 170 |
[exBegin] |
171 |
|top l| |
|
63 | 172 |
|
593 | 173 |
top := StandardSystemView new. |
174 |
top extent:(200 @ 200). |
|
63 | 175 |
|
593 | 176 |
l := Label in:top. |
177 |
l label:'hello world'. |
|
63 | 178 |
|
593 | 179 |
top open |
180 |
[exEnd] |
|
6177 | 181 |
[exBegin] |
182 |
|top l| |
|
183 |
||
184 |
top := StandardSystemView new. |
|
185 |
top extent:(200 @ 200). |
|
186 |
||
187 |
l := Label in:top. |
|
188 |
l label:'hello\world' withCRs. |
|
189 |
||
190 |
top open |
|
191 |
[exEnd] |
|
63 | 192 |
|
113 | 193 |
|
626 | 194 |
simple with emphasis: |
195 |
[exBegin] |
|
196 |
|top l| |
|
197 |
||
198 |
top := StandardSystemView new. |
|
199 |
top extent:(300 @ 100). |
|
200 |
||
201 |
l := Label in:top. |
|
202 |
l level:-1. |
|
203 |
l label:('hello world - this is text in a label ' asText |
|
204 |
emphasizeFrom:7 to:11 with:#italic; |
|
205 |
emphasizeFrom:23 to:26 with:#bold). |
|
206 |
top open |
|
207 |
[exEnd] |
|
208 |
||
209 |
||
113 | 210 |
there is also a creation message which sets the label: |
593 | 211 |
[exBegin] |
212 |
|top l| |
|
113 | 213 |
|
593 | 214 |
top := StandardSystemView new. |
215 |
top extent:(200 @ 200). |
|
113 | 216 |
|
593 | 217 |
l := Label label:'hello world' in:top. |
113 | 218 |
|
593 | 219 |
top open |
220 |
[exEnd] |
|
113 | 221 |
|
222 |
||
63 | 223 |
placement: |
593 | 224 |
[exBegin] |
225 |
|top l| |
|
63 | 226 |
|
593 | 227 |
top := StandardSystemView new. |
228 |
top extent:(200 @ 200). |
|
63 | 229 |
|
593 | 230 |
l := Label in:top. |
231 |
l label:'hello world'. |
|
232 |
l origin:50@100. |
|
63 | 233 |
|
593 | 234 |
top open |
235 |
[exEnd] |
|
63 | 236 |
|
113 | 237 |
|
63 | 238 |
level: |
593 | 239 |
[exBegin] |
240 |
|top l| |
|
63 | 241 |
|
593 | 242 |
top := StandardSystemView new. |
243 |
top extent:(200 @ 200). |
|
63 | 244 |
|
593 | 245 |
l := Label in:top. |
246 |
l level:5. |
|
247 |
l label:'hello world'. |
|
248 |
l origin:50@100. |
|
63 | 249 |
|
593 | 250 |
top open |
251 |
[exEnd] |
|
63 | 252 |
|
113 | 253 |
|
63 | 254 |
another level: |
593 | 255 |
[exBegin] |
256 |
|top l| |
|
63 | 257 |
|
593 | 258 |
top := StandardSystemView new. |
259 |
top extent:(200 @ 200). |
|
63 | 260 |
|
593 | 261 |
l := Label in:top. |
262 |
l level:-1. |
|
263 |
l label:'hello world'. |
|
264 |
l origin:50@100. |
|
63 | 265 |
|
593 | 266 |
top open |
267 |
[exEnd] |
|
63 | 268 |
|
113 | 269 |
|
118 | 270 |
colors & font: |
593 | 271 |
[exBegin] |
272 |
|top l| |
|
118 | 273 |
|
593 | 274 |
top := StandardSystemView new. |
275 |
top extent:(200 @ 200). |
|
118 | 276 |
|
593 | 277 |
l := Label in:top. |
278 |
l level:-1. |
|
279 |
l font:(Font family:'Times' size:18). |
|
280 |
l foregroundColor:Color yellow. |
|
281 |
l backgroundColor:Color red. |
|
282 |
l label:'hello world'. |
|
283 |
l origin:50@100. |
|
118 | 284 |
|
593 | 285 |
top open |
286 |
[exEnd] |
|
118 | 287 |
|
288 |
||
63 | 289 |
border & colors: |
593 | 290 |
[exBegin] |
291 |
|top l| |
|
63 | 292 |
|
593 | 293 |
top := StandardSystemView new. |
294 |
top extent:(200 @ 200). |
|
63 | 295 |
|
593 | 296 |
l := Label in:top. |
297 |
l level:0. |
|
298 |
l borderWidth:1. |
|
299 |
l borderColor:Color red. |
|
300 |
l foregroundColor:Color green darkened. |
|
301 |
l backgroundColor:Color green lightened. |
|
302 |
l label:'hello world'. |
|
303 |
l origin:50@100. |
|
63 | 304 |
|
593 | 305 |
top open |
306 |
[exEnd] |
|
63 | 307 |
|
113 | 308 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
309 |
different adjusts (resize to see): |
593 | 310 |
[exBegin] |
311 |
|top l| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
312 |
|
593 | 313 |
top := StandardSystemView new. |
314 |
top extent:(300 @ 250). |
|
315 |
top label:'make me smaller'. |
|
316 |
||
317 |
l := Label in:top. |
|
318 |
l borderWidth:1. |
|
319 |
l label:'default - #centered'. |
|
320 |
l origin:0.1@40. |
|
321 |
l width:0.8. |
|
63 | 322 |
|
593 | 323 |
l := Label in:top. |
324 |
l borderWidth:1. |
|
325 |
l adjust:#left. |
|
326 |
l label:'#left adjust'. |
|
327 |
l origin:0.1@70. |
|
328 |
l width:0.8. |
|
63 | 329 |
|
593 | 330 |
l := Label in:top. |
331 |
l borderWidth:1. |
|
332 |
l adjust:#right. |
|
333 |
l label:'#right adjust'. |
|
334 |
l origin:0.1@100. |
|
335 |
l width:0.8. |
|
118 | 336 |
|
593 | 337 |
l := Label in:top. |
338 |
l borderWidth:1. |
|
339 |
l adjust:#centerLeft. |
|
340 |
l label:'#centerLeft adjust with a long text'. |
|
341 |
l origin:0.1@130. |
|
342 |
l width:0.8. |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
343 |
|
593 | 344 |
l := Label in:top. |
345 |
l borderWidth:1. |
|
346 |
l adjust:#centerRight. |
|
347 |
l label:'#centerRight adjust with a long text'. |
|
348 |
l origin:0.1@160. |
|
349 |
l width:0.8. |
|
63 | 350 |
|
593 | 351 |
l := Label in:top. |
352 |
l borderWidth:1. |
|
353 |
l adjust:#leftRight. |
|
354 |
l label:'#leftRight adjust with a long text'. |
|
355 |
l origin:0.1@190. |
|
356 |
l width:0.8. |
|
63 | 357 |
|
593 | 358 |
l := Label in:top. |
359 |
l borderWidth:1. |
|
360 |
l adjust:#rightLeft. |
|
361 |
l label:'#rightLeft adjust with a long text'. |
|
362 |
l origin:0.1@220. |
|
363 |
l width:0.8. |
|
118 | 364 |
|
593 | 365 |
top open |
366 |
[exEnd] |
|
63 | 367 |
|
113 | 368 |
|
1945 | 369 |
center vs. centerEach adjust (only with multiline labels): |
370 |
[exBegin] |
|
371 |
|top l| |
|
372 |
||
373 |
top := StandardSystemView new. |
|
374 |
top extent:(300 @ 250). |
|
375 |
top label:'resize me'. |
|
376 |
||
377 |
l := Label in:top. |
|
378 |
l borderWidth:1. |
|
379 |
l label:'this labels logo |
|
1946 | 380 |
consists of multiple lines |
381 |
with #center adjust'. |
|
1945 | 382 |
l origin:0.1@0.1. |
383 |
l corner:0.9@0.9. |
|
384 |
l adjust:#center. |
|
385 |
||
386 |
top open. |
|
387 |
||
388 |
top := StandardSystemView new. |
|
389 |
top extent:(300 @ 250). |
|
390 |
top label:'resize me'. |
|
391 |
||
392 |
l := Label in:top. |
|
393 |
l borderWidth:1. |
|
394 |
l label:'this labels logo |
|
1946 | 395 |
consists of multiple lines |
396 |
with #centerEach adjust'. |
|
1945 | 397 |
l origin:0.1@0.1. |
398 |
l corner:0.9@0.9. |
|
399 |
l adjust:#centerEach. |
|
400 |
||
401 |
top open |
|
402 |
||
403 |
[exEnd] |
|
404 |
||
131 | 405 |
fitting-adjust (resize to see): |
406 |
Warning: #fit is experimental and should not be used. |
|
593 | 407 |
[exBegin] |
408 |
|top l| |
|
131 | 409 |
|
593 | 410 |
top := StandardSystemView new. |
411 |
top extent:(200 @ 200). |
|
131 | 412 |
|
593 | 413 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
414 |
l label:'stretch'. |
|
415 |
l level:-1. |
|
416 |
l adjust:#fit. |
|
131 | 417 |
|
593 | 418 |
top open |
419 |
[exEnd] |
|
131 | 420 |
|
421 |
or: |
|
422 |
Warning: #fit is experimental and should not be used. |
|
593 | 423 |
[exBegin] |
424 |
|top l| |
|
131 | 425 |
|
593 | 426 |
top := StandardSystemView new. |
427 |
top extent:(200 @ 200). |
|
131 | 428 |
|
593 | 429 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
430 |
l label:(Image fromFile:'bitmaps/SBrowser.xbm'). |
|
431 |
l level:-1. |
|
432 |
l adjust:#fit. |
|
131 | 433 |
|
593 | 434 |
top open |
435 |
[exEnd] |
|
131 | 436 |
|
437 |
||
63 | 438 |
just a reminder, that instead of doing placement manually |
113 | 439 |
as in ...: |
593 | 440 |
[exBegin] |
441 |
|top l| |
|
63 | 442 |
|
593 | 443 |
top := StandardSystemView new. |
444 |
top extent:(200 @ 200). |
|
63 | 445 |
|
593 | 446 |
l := Label in:top. |
447 |
l borderWidth:1. |
|
448 |
l label:'default - centered'. |
|
449 |
l origin:0.1@70. |
|
450 |
l width:0.8. |
|
63 | 451 |
|
593 | 452 |
l := Label in:top. |
453 |
l borderWidth:1. |
|
454 |
l adjust:#left. |
|
455 |
l label:'left adjust'. |
|
456 |
l origin:0.1@100. |
|
457 |
l width:0.8. |
|
63 | 458 |
|
593 | 459 |
l := Label in:top. |
460 |
l borderWidth:1. |
|
461 |
l adjust:#right. |
|
462 |
l label:'right adjust'. |
|
463 |
l origin:0.1@130. |
|
464 |
l width:0.8. |
|
63 | 465 |
|
593 | 466 |
top open |
467 |
[exEnd] |
|
63 | 468 |
|
113 | 469 |
|
470 |
... it is much easier, to use a geometry handler, such as |
|
63 | 471 |
a VerticalPanel. Try: |
593 | 472 |
[exBegin] |
473 |
|top panel l| |
|
63 | 474 |
|
593 | 475 |
top := StandardSystemView new. |
476 |
top extent:(200 @ 200). |
|
63 | 477 |
|
593 | 478 |
panel := VerticalPanelView |
479 |
origin:0.1 @ 0.0 |
|
480 |
corner:0.9 @ 1.0 |
|
481 |
in:top. |
|
63 | 482 |
|
593 | 483 |
panel horizontalLayout:#fit. |
484 |
panel verticalLayout:#center. |
|
63 | 485 |
|
593 | 486 |
l := Label in:panel. |
487 |
l borderWidth:1. |
|
488 |
l label:'default - centered'. |
|
63 | 489 |
|
593 | 490 |
l := Label in:panel. |
491 |
l borderWidth:1. |
|
492 |
l adjust:#left. |
|
493 |
l label:'left adjust'. |
|
63 | 494 |
|
593 | 495 |
l := Label in:panel. |
496 |
l borderWidth:1. |
|
497 |
l adjust:#right. |
|
498 |
l label:'right adjust'. |
|
63 | 499 |
|
593 | 500 |
top open |
501 |
[exEnd] |
|
63 | 502 |
|
113 | 503 |
|
63 | 504 |
labels with bitmaps or images: |
593 | 505 |
[exBegin] |
506 |
|top l| |
|
63 | 507 |
|
593 | 508 |
top := StandardSystemView new. |
509 |
top extent:(200 @ 200). |
|
63 | 510 |
|
593 | 511 |
l := Label in:top. |
512 |
l level:-1. |
|
5855 | 513 |
l label:((Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') magnifiedBy:0.2 @ 0.2). |
593 | 514 |
l origin:50@100. |
63 | 515 |
|
593 | 516 |
top open |
517 |
[exEnd] |
|
113 | 518 |
|
519 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
520 |
that even works with #fit: |
593 | 521 |
[exBegin] |
522 |
|top l| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
523 |
|
593 | 524 |
top := StandardSystemView new. |
525 |
top extent:(200 @ 200). |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
526 |
|
593 | 527 |
l := Label in:top. |
528 |
l adjust:#fit. |
|
529 |
l level:-1. |
|
5855 | 530 |
l label:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
593 | 531 |
l origin:0.2@0.2 corner:0.8@0.8. |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
532 |
|
593 | 533 |
top open |
534 |
[exEnd] |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
535 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
536 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
537 |
notice, that Buttons inherit from Label; thus: |
593 | 538 |
[exBegin] |
539 |
|top b| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
540 |
|
593 | 541 |
top := StandardSystemView new. |
542 |
top extent:(200 @ 200). |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
543 |
|
593 | 544 |
b := Button in:top. |
545 |
b adjust:#fit. |
|
5855 | 546 |
b label:(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'). |
593 | 547 |
b origin:0.2@0.2 corner:0.8@0.8. |
655 | 548 |
b action:[Transcript showCR:'wow']. |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
549 |
|
593 | 550 |
top open |
551 |
[exEnd] |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
552 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
553 |
|
1374 | 554 |
Channel operation (controlling fg, bg and labelText via ValueHolders) |
145 | 555 |
----------------- |
593 | 556 |
[exBegin] |
557 |
|top panel logoChannel fgChannel bgChannel l b| |
|
145 | 558 |
|
593 | 559 |
top := StandardSystemView new. |
560 |
top extent:(450 @ 200). |
|
145 | 561 |
|
593 | 562 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
145 | 563 |
|
593 | 564 |
l := Label in:panel. |
565 |
l level:-1. |
|
566 |
l label:'change my colors'. |
|
567 |
l origin:50@100. |
|
568 |
l sizeFixed:true. |
|
145 | 569 |
|
593 | 570 |
fgChannel := Color blue asValue. |
571 |
bgChannel := Color grey asValue. |
|
572 |
logoChannel := 'change me' asValue. |
|
145 | 573 |
|
593 | 574 |
b := Toggle label:'change fg' in:panel. b showLamp:false; onLevel:-2. |
575 |
b pressAction:[fgChannel value:Color red]. |
|
576 |
b releaseAction:[fgChannel value:Color blue]. |
|
145 | 577 |
|
593 | 578 |
b := Toggle label:'change bg' in:panel. |
579 |
b pressAction:[bgChannel value:Color yellow]. |
|
580 |
b releaseAction:[bgChannel value:Color grey]. |
|
145 | 581 |
|
593 | 582 |
b := Toggle label:'change text' in:panel. |
583 |
b pressAction:[logoChannel value:'wow']. |
|
584 |
b releaseAction:[logoChannel value:'not bad' ]. |
|
145 | 585 |
|
593 | 586 |
l labelChannel:logoChannel. |
587 |
l foregroundChannel:fgChannel. |
|
588 |
l backgroundChannel:bgChannel. |
|
145 | 589 |
|
593 | 590 |
top open |
591 |
[exEnd] |
|
145 | 592 |
|
593 |
||
146 | 594 |
multiple labels on one channel: |
593 | 595 |
[exBegin] |
596 |
|l1 l2 b conv| |
|
146 | 597 |
|
593 | 598 |
l1 := Label label:'label1'. |
146 | 599 |
|
593 | 600 |
l2 := Label label:'label2'. |
146 | 601 |
|
593 | 602 |
b := Button label:'change'. |
603 |
conv := (ConvertedValue new |
|
604 |
conversion:[:input | |
|
605 |
input ifTrue:[ |
|
606 |
Color red |
|
607 |
] ifFalse:[ |
|
608 |
Color blue |
|
609 |
]]). |
|
610 |
conv value:false. |
|
146 | 611 |
|
593 | 612 |
b controller pressChannel:conv. |
613 |
l1 foregroundChannel:conv. |
|
614 |
l2 foregroundColor:Color white; backgroundChannel:conv. |
|
146 | 615 |
|
593 | 616 |
b open. |
617 |
l1 open. |
|
618 |
l2 open. |
|
619 |
[exEnd] |
|
146 | 620 |
|
621 |
||
125 | 622 |
MVC operation |
145 | 623 |
------------- |
624 |
||
125 | 625 |
model provides the label): |
626 |
(have to use a plug to simulate a model which responds to |
|
593 | 627 |
the #someAspect message): |
628 |
|top l model| |
|
113 | 629 |
|
593 | 630 |
model := Plug new. |
631 |
model respondTo:#someAspect with:['models labelString']. |
|
113 | 632 |
|
593 | 633 |
top := StandardSystemView new. |
634 |
top extent:(200 @ 200). |
|
113 | 635 |
|
593 | 636 |
l := Label in:top. |
637 |
l model:model; labelMessage:#someAspect. |
|
113 | 638 |
|
593 | 639 |
top open |
640 |
... |
|
118 | 641 |
|
593 | 642 |
model changed:#someAspect |
643 |
... |
|
113 | 644 |
|
645 |
||
118 | 646 |
concrete example (track a counters value): |
125 | 647 |
(here, the default aspect #value is used both to notify the label about |
5782 | 648 |
changes and to acquire a new value from the model). |
593 | 649 |
[exBegin] |
650 |
|top l model| |
|
113 | 651 |
|
593 | 652 |
model := ValueHolder new. |
653 |
model value:'0'. |
|
654 |
[ |
|
655 |
1 to:20 do:[:i | |
|
656 |
(Delay forSeconds:1) wait. |
|
657 |
model value:i printString |
|
658 |
]. |
|
659 |
top destroy |
|
660 |
] fork. |
|
113 | 661 |
|
593 | 662 |
top := StandardSystemView new. |
663 |
top extent:(200 @ 200). |
|
113 | 664 |
|
593 | 665 |
l := Label in:top. |
666 |
l level:-1. |
|
667 |
l model:model; labelMessage:#value. |
|
118 | 668 |
|
593 | 669 |
top open |
670 |
[exEnd] |
|
118 | 671 |
|
672 |
||
133 | 673 |
with a printConverter: |
593 | 674 |
[exBegin] |
675 |
|top l model| |
|
133 | 676 |
|
593 | 677 |
model := Date today asValue. |
678 |
[ |
|
679 |
1 to:50 do:[:i | |
|
680 |
(Delay forSeconds:1) wait. |
|
681 |
model value:(model value addDays:1) |
|
682 |
]. |
|
683 |
top destroy |
|
684 |
] fork. |
|
133 | 685 |
|
593 | 686 |
top := StandardSystemView new. |
687 |
top extent:(200 @ 200). |
|
133 | 688 |
|
593 | 689 |
l := Label in:top. |
690 |
l level:-1. |
|
691 |
l converter:(PrintConverter new initForDate). |
|
692 |
l model:model; labelMessage:#value. |
|
133 | 693 |
|
593 | 694 |
top open |
695 |
[exEnd] |
|
133 | 696 |
|
697 |
||
125 | 698 |
model changes aspect after a while; two labels on the same model: |
593 | 699 |
[exBegin] |
700 |
|top l model| |
|
118 | 701 |
|
593 | 702 |
model := Plug new. |
703 |
model respondTo:#labelValue1 with:['models labelString1']. |
|
704 |
model respondTo:#labelValue2 with:['models labelString2']. |
|
118 | 705 |
|
593 | 706 |
top := StandardSystemView new. |
707 |
top extent:(200 @ 200). |
|
118 | 708 |
|
593 | 709 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
710 |
l model:model; aspect:#someAspect; labelMessage:#labelValue1. |
|
711 |
l := Label origin:0.0@0.5 corner:1.0@1.0 in:top. |
|
712 |
l model:model; aspect:#someAspect; labelMessage:#labelValue2. |
|
713 |
||
714 |
top open. |
|
113 | 715 |
|
593 | 716 |
(Delay forSeconds:5) wait. |
717 |
model respondTo:#labelValue1 with:['new string1']. |
|
718 |
model respondTo:#labelValue2 with:['new string2']. |
|
118 | 719 |
|
593 | 720 |
model changed:#someAspect |
721 |
[exEnd] |
|
118 | 722 |
|
723 |
||
125 | 724 |
plugged MVC operation (getBlock returns the label): |
593 | 725 |
[exBegin] |
726 |
|top l model| |
|
118 | 727 |
|
593 | 728 |
model := PluggableAdaptor new |
729 |
getBlock:[:m | 'hello'] |
|
730 |
putBlock:nil |
|
731 |
updateBlock:nil. |
|
118 | 732 |
|
593 | 733 |
top := StandardSystemView new. |
734 |
top extent:(200 @ 200). |
|
118 | 735 |
|
593 | 736 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
737 |
l model:model; labelMessage:#value. |
|
118 | 738 |
|
593 | 739 |
top open. |
740 |
[exEnd] |
|
125 | 741 |
|
742 |
||
743 |
use different label-selectors to access fields of a complex model: |
|
593 | 744 |
[exBegin] |
745 |
|top panel model| |
|
125 | 746 |
|
593 | 747 |
model := Plug new. |
748 |
model respondTo:#field1 with:['value1']. |
|
749 |
model respondTo:#field2 with:['value2']. |
|
750 |
model respondTo:#field3 with:['value3']. |
|
751 |
model respondTo:#field4 with:['value4']. |
|
125 | 752 |
|
593 | 753 |
top := StandardSystemView new. |
754 |
||
755 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
756 |
panel elementsChangeSize:true. |
|
125 | 757 |
|
593 | 758 |
panel addSubView:((Label on:model) labelMessage:#field1). |
759 |
panel addSubView:((Label on:model) labelMessage:#field2). |
|
760 |
panel addSubView:((Label on:model) labelMessage:#field3). |
|
761 |
panel addSubView:((Label on:model) labelMessage:#field4). |
|
125 | 762 |
|
593 | 763 |
top extent:(200 @ 200). |
764 |
top open. |
|
125 | 765 |
|
593 | 766 |
(Delay forSeconds:5) wait. |
125 | 767 |
|
593 | 768 |
model respondTo:#field2 with:['new value2']. |
769 |
model changed:#value |
|
770 |
[exEnd] |
|
125 | 771 |
|
772 |
||
773 |
same as above, using default aspects in the label, and an adaptor |
|
774 |
to translate aspects: |
|
593 | 775 |
[exBegin] |
776 |
|top panel model v1| |
|
125 | 777 |
|
593 | 778 |
model := Plug new. |
779 |
model respondTo:#field1 with:[v1]. |
|
780 |
model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1]. |
|
781 |
model respondTo:#field2 with:['value2']. |
|
782 |
model respondTo:#field2: with:[:arg |]. |
|
783 |
model respondTo:#field3 with:['value3']. |
|
784 |
model respondTo:#field3: with:[:arg |]. |
|
785 |
model respondTo:#field4 with:['value4']. |
|
786 |
model respondTo:#field4: with:[:arg |]. |
|
125 | 787 |
|
593 | 788 |
top := StandardSystemView new. |
125 | 789 |
|
593 | 790 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
791 |
panel elementsChangeSize:true. |
|
792 |
||
793 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value). |
|
794 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value). |
|
795 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value). |
|
796 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value). |
|
125 | 797 |
|
593 | 798 |
top extent:(200 @ 200). |
799 |
top open. |
|
125 | 800 |
|
593 | 801 |
(Delay forSeconds:5) wait. |
125 | 802 |
|
593 | 803 |
model field1:'new value1'. |
804 |
[exEnd] |
|
125 | 805 |
|
806 |
||
807 |
use an adapter to access fields of a complex model: |
|
593 | 808 |
[exBegin] |
809 |
|top l panel model| |
|
125 | 810 |
|
593 | 811 |
model := #('one' 'two' 'three') asValue. |
125 | 812 |
|
593 | 813 |
top := StandardSystemView new. |
125 | 814 |
|
593 | 815 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
816 |
panel elementsChangeSize:true. |
|
125 | 817 |
|
593 | 818 |
panel addSubView:((Label on:(ProtocolAdaptor |
819 |
subjectChannel:model |
|
820 |
accessPath:#(1))) labelMessage:#value). |
|
821 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
822 |
subjectChannel:model |
|
823 |
accessPath:#(2))) labelMessage:#value). |
|
824 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
825 |
subjectChannel:model |
|
826 |
accessPath:#(3))) labelMessage:#value). |
|
125 | 827 |
|
593 | 828 |
top extent:(200 @ 200). |
829 |
top open. |
|
125 | 830 |
|
593 | 831 |
(Delay forSeconds:5) wait. |
125 | 832 |
|
593 | 833 |
model value:#('oneone' 'twotwo' 'threethree'). |
834 |
[exEnd] |
|
63 | 835 |
" |
3 | 836 |
! ! |
837 |
||
935 | 838 |
!Label class methodsFor:'instance creation'! |
105 | 839 |
|
840 |
form:aForm |
|
118 | 841 |
"return a new Label showing a form. |
842 |
OBSOLETE: you should now use #label: for both text and bitmap labels." |
|
105 | 843 |
|
2366 | 844 |
<resource:#obsolete> |
845 |
||
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
846 |
self obsoleteMethodWarning:'use #label:'. |
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
847 |
^ (self onDevice:Screen current) label:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
848 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
849 |
"Modified: 16.6.1997 / 11:47:38 / cg" |
105 | 850 |
! |
851 |
||
852 |
form:aForm in:aView |
|
118 | 853 |
"return a new Label showing a form. |
854 |
OBSOLETE: you should now use #label:in: for both text and bitmap labels." |
|
105 | 855 |
|
2366 | 856 |
<resource:#obsolete> |
857 |
||
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
858 |
self obsoleteMethodWarning:'use #label:in:'. |
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
859 |
^ (self in:aView) label:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
860 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
861 |
"Modified: 16.6.1997 / 11:47:57 / cg" |
105 | 862 |
! ! |
863 |
||
935 | 864 |
!Label class methodsFor:'defaults'! |
0 | 865 |
|
866 |
defaultExtent |
|
571 | 867 |
"return the default extent of my instances. |
868 |
The value returned here is usually ignored, and |
|
869 |
the value from preferredExtent taken instead." |
|
0 | 870 |
|
871 |
^ 16 @ 16 |
|
571 | 872 |
|
873 |
"Modified: 22.4.1996 / 23:36:11 / cg" |
|
59 | 874 |
! |
875 |
||
2098
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
876 |
defaultForegroundColor |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
877 |
"return the default foregroundColor of my instances." |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
878 |
|
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
879 |
^ DefaultForegroundColor |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
880 |
|
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
881 |
! |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
882 |
|
59 | 883 |
updateStyleCache |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
884 |
"extract values from the styleSheet and cache them in class variables" |
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
885 |
|
1356 | 886 |
<resource: #style (#'label.foregroundColor' #'label.backgroundColor' |
442 | 887 |
#foregroundColor #backgroundColor |
1356 | 888 |
#'label.font')> |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
889 |
|
1872 | 890 |
DefaultForegroundColor := StyleSheet colorAt:#'label.foregroundColor'. |
77 | 891 |
DefaultForegroundColor isNil ifTrue:[ |
1374 | 892 |
"/ fallBack: comon value |
4915 | 893 |
DefaultForegroundColor := StyleSheet colorAt:#'foregroundColor' default:Color black. |
77 | 894 |
]. |
1872 | 895 |
DefaultBackgroundColor := StyleSheet colorAt:#'label.backgroundColor'. |
77 | 896 |
DefaultBackgroundColor isNil ifTrue:[ |
1374 | 897 |
"/ fallBack: comon value |
1872 | 898 |
DefaultBackgroundColor := StyleSheet colorAt:#'backgroundColor'. |
77 | 899 |
]. |
1872 | 900 |
DefaultFont := StyleSheet fontAt:#'label.font'. |
60 | 901 |
|
902 |
" |
|
903 |
self updateStyleCache |
|
904 |
" |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
905 |
|
1374 | 906 |
"Modified: / 31.10.1997 / 14:53:48 / cg" |
0 | 907 |
! ! |
908 |
||
4670 | 909 |
!Label class methodsFor:'menu specs'! |
910 |
||
911 |
middleButtonMenu |
|
912 |
"This resource specification was automatically generated |
|
913 |
by the MenuEditor of ST/X." |
|
914 |
||
915 |
"Do not manually edit this!! If it is corrupted, |
|
916 |
the MenuEditor may not be able to read the specification." |
|
917 |
||
918 |
||
919 |
" |
|
920 |
MenuEditor new openOnClass:Label andSelector:#middleButtonMenu |
|
921 |
(Menu new fromLiteralArrayEncoding:(Label middleButtonMenu)) startUp |
|
922 |
" |
|
923 |
||
924 |
<resource: #menu> |
|
925 |
||
926 |
^ |
|
927 |
#(Menu |
|
928 |
( |
|
929 |
(MenuItem |
|
930 |
label: 'Copy Label Text' |
|
931 |
itemValue: copyLabelText |
|
932 |
enabled: isTextLabel |
|
933 |
) |
|
934 |
) |
|
935 |
nil |
|
936 |
nil |
|
937 |
) |
|
938 |
! ! |
|
939 |
||
202 | 940 |
!Label methodsFor:'accessing-channels'! |
105 | 941 |
|
260 | 942 |
labelChannel |
1374 | 943 |
"return the labelChannel - or nil" |
944 |
||
260 | 945 |
^ labelChannel. |
946 |
||
1374 | 947 |
"Created: / 16.12.1995 / 15:50:18 / cg" |
948 |
"Modified: / 31.10.1997 / 14:43:14 / cg" |
|
260 | 949 |
! |
950 |
||
145 | 951 |
labelChannel:aValueHolder |
1374 | 952 |
"set the labelChannel - a valueHolder holding a string or image |
953 |
which is shown as my logo" |
|
954 |
||
146 | 955 |
|prev| |
956 |
||
957 |
prev := labelChannel. |
|
145 | 958 |
labelChannel := aValueHolder. |
3927 | 959 |
self setupChannel:aValueHolder for:nil withOld:prev. |
960 |
self getLabelFromLabelChannel. |
|
1374 | 961 |
|
962 |
"Modified: / 31.10.1997 / 14:37:02 / cg" |
|
145 | 963 |
! ! |
964 |
||
202 | 965 |
!Label methodsFor:'accessing-colors'! |
125 | 966 |
|
202 | 967 |
backgroundColor |
968 |
"return the background color" |
|
125 | 969 |
|
202 | 970 |
^ bgColor |
125 | 971 |
! |
972 |
||
202 | 973 |
backgroundColor:aColor |
974 |
"set the background color" |
|
125 | 975 |
|
263 | 976 |
aColor ~~ bgColor ifTrue:[ |
3582 | 977 |
bgColor := aColor. |
978 |
bgColor notNil ifTrue:[ |
|
5633 | 979 |
bgColor := bgColor onDevice:device. |
3597 | 980 |
self class == Label ifTrue:[ |
981 |
super viewBackground:bgColor |
|
982 |
]. |
|
1218 | 983 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
984 |
self invalidateRepairNow:true |
263 | 985 |
] |
986 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
987 |
"Modified: / 15.1.1998 / 00:14:10 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
988 |
"Modified: / 6.6.1998 / 20:01:56 / cg" |
105 | 989 |
! |
990 |
||
2496 | 991 |
etchedForegroundColor |
992 |
"return the etched foreground color (or nil)" |
|
993 |
||
994 |
^ etchedFgColor |
|
995 |
! |
|
996 |
||
997 |
etchedForegroundColor:aColor |
|
998 |
"set the etched foreground color" |
|
999 |
||
1000 |
aColor ~~ etchedFgColor ifTrue:[ |
|
1001 |
etchedFgColor := aColor. |
|
1002 |
etchedFgColor notNil ifTrue:[ |
|
5633 | 1003 |
etchedFgColor := etchedFgColor onDevice:device. |
2496 | 1004 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1005 |
self invalidateRepairNow:true |
2496 | 1006 |
]. |
1007 |
! |
|
1008 |
||
105 | 1009 |
foregroundColor |
1010 |
"return the foreground color" |
|
1011 |
||
1012 |
^ fgColor |
|
1013 |
! |
|
1014 |
||
202 | 1015 |
foregroundColor:aColor |
1016 |
"set the foreground color" |
|
105 | 1017 |
|
263 | 1018 |
aColor ~~ fgColor ifTrue:[ |
5633 | 1019 |
fgColor := aColor onDevice:device. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1020 |
self invalidateRepairNow:true |
263 | 1021 |
]. |
1022 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1023 |
"Modified: / 15.1.1998 / 00:14:22 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1024 |
"Modified: / 6.6.1998 / 20:02:02 / cg" |
105 | 1025 |
! |
1026 |
||
1027 |
foregroundColor:fg backgroundColor:bg |
|
1028 |
"set the colors to be used for drawing" |
|
1029 |
||
993 | 1030 |
(fgColor ~~ fg or:[bgColor ~~ bg]) ifTrue:[ |
5633 | 1031 |
fgColor := fg onDevice:device. |
1032 |
bgColor := bg onDevice:device. |
|
1218 | 1033 |
self class == Label ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1034 |
super viewBackground:bgColor |
1218 | 1035 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1036 |
self invalidateRepairNow:true |
993 | 1037 |
]. |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1038 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1039 |
"Modified: / 15.1.1998 / 00:14:36 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1040 |
"Modified: / 6.6.1998 / 20:02:07 / cg" |
1218 | 1041 |
! |
1042 |
||
1043 |
viewBackground:aColor |
|
1044 |
"for labels, the viewBackground is forced to be the same as |
|
1045 |
the backgroundColor" |
|
1046 |
||
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1047 |
super viewBackground:aColor. |
1218 | 1048 |
self class == Label ifTrue:[ |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1049 |
self backgroundColor:aColor |
1218 | 1050 |
]. |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1051 |
|
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1052 |
"Modified: / 6.6.1998 / 20:02:22 / cg" |
133 | 1053 |
! ! |
1054 |
||
1055 |
!Label methodsFor:'accessing-contents'! |
|
0 | 1056 |
|
202 | 1057 |
form:aForm |
1058 |
"set the labels form; adjust extent if not already realized. |
|
1059 |
OBSOLETE: you should now use #label: for both strings and images" |
|
118 | 1060 |
|
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1061 |
<resource:#obsolete> |
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1062 |
|
202 | 1063 |
self label:aForm |
1064 |
! |
|
1065 |
||
1066 |
label |
|
1067 |
"return the labels string or image" |
|
1068 |
||
1069 |
^ logo |
|
118 | 1070 |
! |
105 | 1071 |
|
118 | 1072 |
label:aStringOrFormOrImage |
4174 | 1073 |
"set the labelString or image; |
1074 |
adjust extent if not already realized and not fixedSize; |
|
1075 |
also redraw" |
|
1076 |
||
1077 |
self label:aStringOrFormOrImage redraw:true |
|
1078 |
||
1079 |
"Modified: / 13-10-2010 / 12:17:36 / cg" |
|
1080 |
! |
|
1081 |
||
1082 |
label:aStringOrFormOrImage redraw:doRedraw |
|
118 | 1083 |
"set the labelString or image; adjust extent if not already realized and |
1084 |
not fixedSize" |
|
1085 |
||
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1086 |
|newLogo numberOfLines| |
2639 | 1087 |
|
1088 |
newLogo := aStringOrFormOrImage. |
|
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1089 |
newLogo isString ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1090 |
numberOfLines := 1 + (newLogo occurrencesOf:(Character cr)). |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1091 |
(numberOfLines ~~ 1) ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1092 |
newLogo := newLogo asStringCollection |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1093 |
] |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1094 |
] ifFalse:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1095 |
newLogo isStringCollection ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1096 |
numberOfLines := newLogo size. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1097 |
(numberOfLines <= 1) ifTrue:[ |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1098 |
newLogo := newLogo asString |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1099 |
] |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1100 |
] |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1101 |
]. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1102 |
|
118 | 1103 |
(aStringOrFormOrImage ~~ logo) ifTrue:[ |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1104 |
"/ |
6106 | 1105 |
"/ avoid recompute of size, if it's an image with |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1106 |
"/ the same size |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1107 |
"/ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1108 |
aStringOrFormOrImage isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1109 |
logo notNil ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1110 |
logo isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1111 |
logo extent = aStringOrFormOrImage extent ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1112 |
logo := aStringOrFormOrImage. |
4174 | 1113 |
doRedraw ifTrue:[ self invalidateRepairNow:true ]. |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1114 |
^ self |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1115 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1116 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1117 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1118 |
] ifFalse:[ |
806
a641ed42df70
dont ignore new label setting, if the emphasis changed
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
1119 |
"/ any change ? |
4443
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1120 |
(logo isString |
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1121 |
and:[ newLogo isString |
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1122 |
and:[ newLogo = logo |
a5a69820a9b5
Avoid #isKindOf: where possible
Stefan Vogel <sv@exept.de>
parents:
4341
diff
changeset
|
1123 |
and:[ logo emphasis = newLogo emphasis]]]) ifTrue:[ |
3649 | 1124 |
^ self |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1125 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1126 |
]. |
3557
e57daeff04be
changed #label: - fix typo in comment
Stefan Vogel <sv@exept.de>
parents:
3531
diff
changeset
|
1127 |
"/ do not check using #isString here; |
3531 | 1128 |
"/ we allow for non-strings to be used as logo as well (it must understand displayOn:). |
1129 |
newLogo isNumber ifTrue:[ |
|
1130 |
logo := newLogo asString |
|
1131 |
] ifFalse:[ |
|
1132 |
logo := newLogo. |
|
1133 |
]. |
|
4174 | 1134 |
doRedraw ifTrue:[ |
1135 |
self newLayout. |
|
1136 |
self repairDamage |
|
1137 |
]. |
|
105 | 1138 |
] |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1139 |
|
4174 | 1140 |
"Created: / 13-10-2010 / 12:16:34 / cg" |
6106 | 1141 |
"Modified (format): / 13-02-2017 / 20:26:33 / cg" |
105 | 1142 |
! |
0 | 1143 |
|
1367 | 1144 |
label:newLabel suppressResize:suppress |
1145 |
"change the label and optionally suppress a resize operation" |
|
1146 |
||
1147 |
|wasFix| |
|
1148 |
||
1149 |
wasFix := fixSize. |
|
1150 |
suppress ifTrue:[ |
|
1151 |
fixSize := true. |
|
1152 |
]. |
|
1153 |
here label:newLabel. |
|
1154 |
fixSize := wasFix |
|
1155 |
||
1156 |
"Modified: / 29.10.1997 / 15:50:01 / cg" |
|
1157 |
! |
|
1158 |
||
202 | 1159 |
labelString:aString |
1160 |
"for ST-80 compatibility: same as #label: |
|
1161 |
set the label-string; adjust extent if not already realized and not fixedSize" |
|
118 | 1162 |
|
202 | 1163 |
self label:aString |
1164 |
! |
|
1165 |
||
1166 |
labelWidth |
|
1167 |
"return the logos width in pixels" |
|
1168 |
||
1169 |
^ labelWidth |
|
118 | 1170 |
! |
1171 |
||
1172 |
logo:something |
|
1173 |
"set the labels form or string. |
|
1174 |
OBSOLETE: the old version used #form: for images and #label: for strings. |
|
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1175 |
you should now use #label: for any." |
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1176 |
|
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1177 |
<resource:#obsolete> |
118 | 1178 |
|
1179 |
self label:something |
|
133 | 1180 |
! ! |
1181 |
||
1182 |
!Label methodsFor:'accessing-layout'! |
|
1183 |
||
202 | 1184 |
adjust |
1921 | 1185 |
"return the adjust symbol. See #adjust: for an explanation." |
0 | 1186 |
|
202 | 1187 |
^ adjust |
125 | 1188 |
! |
1189 |
||
105 | 1190 |
adjust:how |
1191 |
"set the adjust, how which must be one of |
|
0 | 1192 |
|
105 | 1193 |
#left -> left adjust logo |
1194 |
#right -> right adjust logo |
|
1195 |
#center -> center logo |
|
6106 | 1196 |
#centerEach -> like #center, but if it's a multiline logo, |
1945 | 1197 |
center each line individually. |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1198 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1199 |
#centerRight -> center logo if it fits; |
533 | 1200 |
BUT, if it does not fit, right adjust the logo |
1201 |
(use with filenames, where the interesting part is |
|
1202 |
at the right if the label is too small) |
|
1203 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1204 |
#centerLeft -> center logo if it fits; |
533 | 1205 |
BUT, if it does not fit, left adjust the logo |
1206 |
(use with strings where the interesting part is at the |
|
1207 |
left if the label is too small) |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1208 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1209 |
#leftRight -> left adjust logo if it fits |
533 | 1210 |
BUT, if it does not fit, right adjust the logo |
1211 |
(use with filenames, where the interesting part is |
|
1212 |
at the right if the label is too small) |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1213 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1214 |
#rightLeft -> right adjust logo if it fits |
533 | 1215 |
BUT, if it does not fit, left adjust the logo |
1216 |
(use with strings where the interesting part is at the |
|
1217 |
left if the label is too small) |
|
1218 |
||
1219 |
See examples in the documentation category. |
|
105 | 1220 |
" |
118 | 1221 |
|
105 | 1222 |
(adjust ~~ how) ifTrue:[ |
533 | 1223 |
adjust := how. |
1224 |
self newLayout |
|
105 | 1225 |
] |
533 | 1226 |
|
6106 | 1227 |
"Modified: / 13-04-1996 / 11:17:58 / cg" |
1228 |
"Modified (comment): / 13-02-2017 / 20:26:28 / cg" |
|
105 | 1229 |
! |
1230 |
||
5445 | 1231 |
extraMarginForBorder |
1232 |
"some (round) borders may need more space" |
|
1233 |
||
1234 |
^ 0 |
|
1235 |
! |
|
1236 |
||
202 | 1237 |
font:aFont |
665 | 1238 |
"set the font - if I'm not realized and not fixedSize, adjust my size. |
1239 |
CAVEAT: with the addition of Text objects, |
|
1240 |
this method is going to be obsoleted by a textStyle |
|
1241 |
method, which allows specific control over |
|
1242 |
normalFont/boldFont/italicFont parameters." |
|
125 | 1243 |
|
4891 | 1244 |
(aFont notNil and:[aFont ~~ gc font]) ifTrue:[ |
1245 |
super font:aFont. |
|
416 | 1246 |
self newLayout |
202 | 1247 |
] |
416 | 1248 |
|
665 | 1249 |
"Modified: 22.5.1996 / 12:36:29 / cg" |
133 | 1250 |
! |
1251 |
||
6089 | 1252 |
horizontalSpace |
1253 |
"get the number of pixels by which the logo |
|
1254 |
is horizontally inset from the border" |
|
1255 |
||
1256 |
^ hSpace |
|
1257 |
! |
|
1258 |
||
133 | 1259 |
horizontalSpace:aNumber |
1260 |
"set the number of pixels by which the logo |
|
1261 |
is horizontally inset from the border" |
|
1262 |
||
162 | 1263 |
hSpace := aNumber. |
1264 |
self newLayout |
|
133 | 1265 |
! |
1266 |
||
202 | 1267 |
layout:something |
1268 |
"OBSOLETE compatibility interface. Will vanish. |
|
1269 |
for protocol compatibility: alias for #adjust:. |
|
1270 |
Please use #adjust:, since #layout: conflicts with a method |
|
1271 |
in VW (which has a completely different meaning). |
|
1272 |
In future versions of ST/X, #layout: will behave the VW way. |
|
1273 |
In the meantime, try to figure out what is meant ... a kludge" |
|
1274 |
||
2366 | 1275 |
<resource:#obsolete> |
1276 |
||
3215 | 1277 |
something isSymbol ifFalse:[^ super layout:something]. |
202 | 1278 |
|
1279 |
self obsoleteMethodWarning:'use #adjust:'. |
|
1280 |
self adjust:something |
|
1281 |
||
1282 |
"Modified: 31.8.1995 / 23:08:13 / claus" |
|
1283 |
! |
|
1284 |
||
1285 |
sizeFixed |
|
1286 |
"return the fix-size attribute" |
|
1287 |
||
1288 |
^ fixSize |
|
1289 |
! |
|
1290 |
||
1291 |
sizeFixed:aBoolean |
|
1292 |
"set/clear the fix-size attribute. |
|
5708 | 1293 |
If true, the label will not change its size when the labelString/logo |
1294 |
changes. |
|
1295 |
If false (the default), it will resize itself to make the logo fit." |
|
202 | 1296 |
|
1297 |
fixSize := aBoolean |
|
1298 |
! |
|
1299 |
||
6088 | 1300 |
verticalSpace |
1301 |
"get the number of pixels by which the logo |
|
1302 |
is vertically inset from the border" |
|
1303 |
||
1304 |
^ vSpace |
|
1305 |
! |
|
1306 |
||
202 | 1307 |
verticalSpace:aNumber |
1308 |
"set the number of pixels by which the logo |
|
1309 |
is vertically inset from the border" |
|
1310 |
||
1311 |
vSpace := aNumber. |
|
1312 |
self newLayout |
|
1313 |
! ! |
|
1314 |
||
1315 |
!Label methodsFor:'accessing-mvc'! |
|
1316 |
||
1317 |
addModelInterfaceTo:aDictionary |
|
1318 |
"see comment in View>>modelInterface" |
|
1319 |
||
1320 |
super addModelInterfaceTo:aDictionary. |
|
1321 |
aDictionary at:#labelMessage put:labelMsg |
|
1322 |
! |
|
1323 |
||
1324 |
converter:aConverter |
|
1325 |
"set the printConverter; |
|
1326 |
that one is asked to convert the models value to a printed |
|
1327 |
representation (if non-nil). If nil, the model is supposed to |
|
1328 |
return a string or bitmap image." |
|
1329 |
||
1330 |
converter := aConverter |
|
1331 |
! |
|
105 | 1332 |
|
202 | 1333 |
labelMessage |
5782 | 1334 |
"return the symbol used to acquire the labelString/image from the model |
202 | 1335 |
when the aspect changes. |
1336 |
The default is nil, which means: leave the label unchanged." |
|
1337 |
||
1338 |
^ labelMsg |
|
1339 |
! |
|
1340 |
||
1341 |
labelMessage:aSymbol |
|
5782 | 1342 |
"set the symbol used to acquire the labelString/image from the model. |
202 | 1343 |
The default is nil, which means: leave the label unchanged." |
1344 |
||
1345 |
labelMsg ~~ aSymbol ifTrue:[ |
|
5782 | 1346 |
labelMsg := aSymbol. |
1347 |
self getLabelFromModel |
|
202 | 1348 |
] |
1349 |
! |
|
1350 |
||
1351 |
model:aModel |
|
1352 |
super model:aModel. |
|
1039 | 1353 |
labelMsg notNil ifTrue:[ |
1354 |
self getLabelFromModel. |
|
1355 |
] |
|
202 | 1356 |
! ! |
1357 |
||
1358 |
!Label methodsFor:'change & update'! |
|
1359 |
||
3924 | 1360 |
getLabelFromLabelChannel |
1361 |
self label:(labelChannel value). |
|
1362 |
! |
|
1363 |
||
202 | 1364 |
update:something with:aParameter from:changedObject |
1365 |
"the MVC way of changing the label ..." |
|
1366 |
||
1374 | 1367 |
changedObject notNil ifTrue:[ |
1368 |
changedObject == labelChannel ifTrue:[ |
|
3924 | 1369 |
self getLabelFromLabelChannel. |
1374 | 1370 |
^ self |
1371 |
]. |
|
1372 |
||
1373 |
changedObject == model ifTrue:[ |
|
1374 |
something == aspectMsg ifTrue:[ |
|
1375 |
self getLabelFromModel. |
|
1376 |
^ self. |
|
1377 |
] |
|
1378 |
]. |
|
202 | 1379 |
]. |
1380 |
^ super update:something with:aParameter from:changedObject |
|
1374 | 1381 |
|
1382 |
"Modified: / 31.10.1997 / 14:32:02 / cg" |
|
1828 | 1383 |
"Modified: / 30.3.1999 / 13:57:26 / stefan" |
202 | 1384 |
! ! |
1385 |
||
1386 |
!Label methodsFor:'event handling'! |
|
1387 |
||
1388 |
sizeChanged:how |
|
1389 |
"sent whenever size is changed by someone else - recompute the |
|
1390 |
logos position within the View." |
|
1391 |
||
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1392 |
|prevX prevY| |
202 | 1393 |
|
1394 |
super sizeChanged:how. |
|
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1395 |
|
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1396 |
prevX := labelOriginX. |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1397 |
prevY := labelOriginY. |
1392 | 1398 |
self computeLabelOrigin. |
202 | 1399 |
shown ifTrue:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1400 |
(adjust == #fit |
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1401 |
or:[labelOriginX ~~ prevX |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1402 |
or:[labelOriginY ~~ prevY |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1403 |
or:[how ~~ #smaller]]]) ifTrue:[ |
1509 | 1404 |
"/ self clear. |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1405 |
self invalidate. |
1509 | 1406 |
"/ self redrawEdges |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1407 |
] |
105 | 1408 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1409 |
|
1509 | 1410 |
"Modified: / 28.4.1998 / 17:07:57 / cg" |
0 | 1411 |
! ! |
1412 |
||
1867
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1413 |
!Label methodsFor:'focus handling'! |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1414 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1415 |
wantsFocusWithButtonPress |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1416 |
self class == Label ifTrue:[^ false]. |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1417 |
^ super wantsFocusWithButtonPress |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1418 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1419 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1420 |
! ! |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1421 |
|
2751 | 1422 |
!Label methodsFor:'initialization & release'! |
0 | 1423 |
|
935 | 1424 |
fetchDeviceResources |
1425 |
"fetch device colors, to avoid reallocation at redraw time" |
|
1426 |
||
1427 |
super fetchDeviceResources. |
|
1428 |
||
5633 | 1429 |
fgColor := fgColor onDevice:device. |
1430 |
bgColor := bgColor onDevice:device. |
|
935 | 1431 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1432 |
"Created: / 13.1.1997 / 23:34:30 / cg" |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1433 |
"Modified: / 15.1.1998 / 00:13:46 / stefan" |
935 | 1434 |
! |
1435 |
||
0 | 1436 |
initStyle |
967 | 1437 |
"setup viewStyle specifics" |
1438 |
||
0 | 1439 |
super initStyle. |
1440 |
||
59 | 1441 |
DefaultBackgroundColor notNil ifTrue:[ |
935 | 1442 |
bgColor := DefaultBackgroundColor |
38 | 1443 |
] ifFalse:[ |
935 | 1444 |
bgColor := viewBackground. |
59 | 1445 |
]. |
1446 |
DefaultForegroundColor notNil ifTrue:[ |
|
935 | 1447 |
fgColor := DefaultForegroundColor |
59 | 1448 |
] ifFalse:[ |
4915 | 1449 |
fgColor := self blackColor. |
1374 | 1450 |
]. |
1451 |
self class == Label ifTrue:[ |
|
4020
3b0d7d8915a8
no more direct accesses to borderWidth and borderColor
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
1452 |
self borderWidth:0. |
38 | 1453 |
] |
935 | 1454 |
|
4318 | 1455 |
"Modified: / 31-10-1997 / 14:57:23 / cg" |
1456 |
"Modified (comment): / 05-10-2011 / 15:51:09 / az" |
|
0 | 1457 |
! |
1458 |
||
105 | 1459 |
initialize |
4891 | 1460 |
|currentFont| |
1461 |
||
6077 | 1462 |
<modifier: #super> "must be called if redefined" |
1463 |
||
105 | 1464 |
super initialize. |
1465 |
||
5817 | 1466 |
currentFont := gc font. |
4891 | 1467 |
self initialHeight:(currentFont height + currentFont descent). |
105 | 1468 |
adjust := #center. |
118 | 1469 |
labelOriginX := labelOriginY := 0. |
1470 |
labelWidth := labelHeight := 0. |
|
105 | 1471 |
logo := nil. |
1472 |
fixSize := false. |
|
5943 | 1473 |
hSpace := ((self horizontalPixelPerMillimeter:0.5) max:2) rounded. |
1474 |
vSpace := ((self verticalPixelPerMillimeter:0.5) max:2) rounded |
|
6077 | 1475 |
|
1476 |
"Modified: / 08-02-2017 / 00:32:40 / cg" |
|
105 | 1477 |
! |
1478 |
||
0 | 1479 |
recreate |
2258 | 1480 |
"after snapin or a migration, labels dimensions may have changed due to |
0 | 1481 |
different font parameters" |
1482 |
||
1483 |
super recreate. |
|
1484 |
self computeLabelSize. |
|
1485 |
self computeLabelOrigin |
|
2592 | 1486 |
! |
1487 |
||
1488 |
release |
|
1489 |
labelChannel notNil ifTrue:[ |
|
1490 |
labelChannel removeDependent:self. |
|
1491 |
labelChannel := nil. |
|
1492 |
]. |
|
5746 | 1493 |
self stopAnimation. |
2592 | 1494 |
super release |
0 | 1495 |
! ! |
1496 |
||
5746 | 1497 |
!Label methodsFor:'label animation'! |
1498 |
||
1499 |
animationDelay |
|
1500 |
^ 100 milliseconds |
|
1501 |
! |
|
1502 |
||
1503 |
animationDelayTopOrBottom |
|
1504 |
^ 3 seconds |
|
1505 |
! |
|
1506 |
||
1507 |
doAnimate |
|
1508 |
"by slow scrolling the label, ensure that the label's text is readable. |
|
1509 |
(stops when the cursor enters)" |
|
1510 |
||
5751 | 1511 |
|animatorState offset atTop atBottom nextOffset nextMoveDirection nextAnimationDelay focusView| |
5746 | 1512 |
|
5751 | 1513 |
animatorState := self objectAttributeAt:#animator. |
1514 |
animatorState isNil ifTrue:[^ self "I have been stopped in the meanwhile"]. |
|
5746 | 1515 |
|
5785 | 1516 |
(gc drawableId isNil) ifTrue:[ |
5749 | 1517 |
"/ view has been closed. |
5751 | 1518 |
self stopAnimation. |
5749 | 1519 |
^ self |
1520 |
]. |
|
5751 | 1521 |
logo == (animatorState logoShown) ifFalse:[ |
5750 | 1522 |
"/ logo changed - stop it |
5751 | 1523 |
self stopAnimation. |
5750 | 1524 |
^ self |
1525 |
]. |
|
5752 | 1526 |
shown ifFalse:[ |
1527 |
"/ currently invisible (iconified/hidden) |
|
1528 |
Processor addTimedBlock:(animatorState timedBlock) after:self animationDelayTopOrBottom. |
|
1529 |
self computeLabelOrigin. |
|
1530 |
^ self. |
|
1531 |
]. |
|
5755 | 1532 |
(controller notNil and:[controller entered]) ifTrue:[ |
1533 |
"/ pause animation |
|
1534 |
Processor addTimedBlock:(animatorState timedBlock) after:0.5 seconds. |
|
1535 |
^ self. |
|
1536 |
]. |
|
5750 | 1537 |
|
5752 | 1538 |
offset := animatorState nextOffset max:0. |
1539 |
||
1540 |
atTop := (offset <= 0). |
|
1541 |
"/ Transcript printf:'labelHeight: %d offset: %d fA: %d fH: %d height: %d\n' |
|
1542 |
"/ withAll:{ labelHeight . offset . self font ascent . self font height . height }. |
|
1543 |
"/ (labelHeight - offset) is restHeight |
|
1544 |
atBottom := (labelHeight - offset) < height. |
|
5746 | 1545 |
|
5749 | 1546 |
nextAnimationDelay := (atTop | atBottom) |
1547 |
ifTrue:[ self animationDelayTopOrBottom ] |
|
1548 |
ifFalse:[ self animationDelay ]. |
|
1549 |
||
5751 | 1550 |
nextMoveDirection := animatorState moveDirection. |
1551 |
atTop ifTrue:[ |
|
1552 |
nextMoveDirection := #down |
|
1553 |
]. |
|
1554 |
||
5746 | 1555 |
atBottom ifTrue:[ |
1556 |
"/ after a longer delay, start again from top |
|
5751 | 1557 |
"/ nextOffset := 0. |
1558 |
"/ nextMoveDirection := #down. |
|
1559 |
"/ after a longer delay, start moving up again (fast) |
|
1560 |
nextOffset := offset - 1. |
|
1561 |
nextMoveDirection := #up. |
|
1562 |
] ifFalse:[ |
|
1563 |
nextMoveDirection == #down ifTrue:[ |
|
1564 |
nextOffset := offset + 1. |
|
1565 |
] ifFalse:[ |
|
5752 | 1566 |
nextOffset := offset - 2. |
1567 |
nextAnimationDelay := nextAnimationDelay / 4. "/ fast |
|
5751 | 1568 |
]. |
5746 | 1569 |
]. |
5749 | 1570 |
|
1571 |
"/ If I am not part of the active window, scroll back to top and wait longer... |
|
1572 |
((focusView := Display focusView) notNil |
|
1573 |
and:[ focusView windowGroup == self windowGroup ]) ifFalse:[ |
|
1574 |
nextOffset := offset := 0. |
|
1575 |
nextAnimationDelay := self animationDelayTopOrBottom. |
|
5751 | 1576 |
nextMoveDirection := #down. |
5749 | 1577 |
]. |
1578 |
||
5746 | 1579 |
labelOriginY := offset negated. |
5751 | 1580 |
animatorState nextOffset:nextOffset. |
1581 |
animatorState moveDirection:nextMoveDirection. |
|
5749 | 1582 |
|
5746 | 1583 |
self invalidate. |
5751 | 1584 |
Processor addTimedBlock:(animatorState timedBlock) after:nextAnimationDelay. |
5746 | 1585 |
! |
1586 |
||
1587 |
startAnimation |
|
5749 | 1588 |
"start an animator, which scrolls the label's text. |
5746 | 1589 |
(slow scroll which stops when the cursor enters)" |
1590 |
||
5751 | 1591 |
|timedBlock| |
5746 | 1592 |
|
5755 | 1593 |
self enableEnterLeaveEvents. |
1594 |
||
5746 | 1595 |
self stopAnimation. |
5749 | 1596 |
|
5751 | 1597 |
timedBlock := [ self doAnimate ]. |
1598 |
self |
|
1599 |
objectAttributeAt:#animator |
|
1600 |
put:(AnimatorState new |
|
1601 |
timedBlock:timedBlock |
|
1602 |
nextOffset:0 |
|
1603 |
moveDirection:#down |
|
1604 |
logoShown:logo). |
|
1605 |
Processor addTimedBlock:timedBlock after:(self animationDelay) |
|
5746 | 1606 |
|
1607 |
" |
|
1608 |
|l| |
|
1609 |
l := Label new. |
|
1610 |
l height:30. |
|
1611 |
l sizeFixed:true. |
|
1612 |
l label:'Line1 |
|
1613 |
Line2 |
|
1614 |
Line3 |
|
1615 |
Line4'. |
|
1616 |
l openAndWait. |
|
1617 |
l startAnimation. |
|
1618 |
Delay waitForSeconds:10. |
|
1619 |
l stopAnimation. |
|
1620 |
" |
|
1621 |
! |
|
1622 |
||
1623 |
stopAnimation |
|
5751 | 1624 |
|animatorState timedBlock| |
5746 | 1625 |
|
5751 | 1626 |
animatorState := self removeObjectAttribute:#animator. |
1627 |
animatorState notNil ifTrue:[ |
|
1628 |
timedBlock := animatorState timedBlock. |
|
1629 |
Processor removeTimedBlock:timedBlock. |
|
1630 |
||
1631 |
"/ ensure that things are in their normal state again |
|
1632 |
self computeLabelOrigin. |
|
5749 | 1633 |
shown ifTrue:[ |
1634 |
self invalidate. |
|
1635 |
]. |
|
5746 | 1636 |
]. |
1637 |
! ! |
|
1638 |
||
4670 | 1639 |
!Label methodsFor:'menu'! |
1640 |
||
1641 |
copyLabelText |
|
1642 |
|text| |
|
1643 |
||
1644 |
text := logo asString. |
|
1645 |
self setClipboardText:text. |
|
1646 |
! |
|
1647 |
||
1648 |
middleButtonMenu |
|
1649 |
|m| |
|
1650 |
||
1651 |
m := super middleButtonMenu. |
|
1652 |
m isNil ifTrue:[ |
|
4672 | 1653 |
m := self yellowButtonMenu. |
1654 |
m isNil ifTrue:[ |
|
1655 |
"/ not a customized menu |
|
1656 |
self class == Label ifTrue:[ |
|
1657 |
m := self class middleButtonMenu |
|
1658 |
] |
|
4670 | 1659 |
]. |
1660 |
]. |
|
1661 |
^ m |
|
1662 |
! ! |
|
1663 |
||
5123 | 1664 |
!Label methodsFor:'native widget support'! |
1665 |
||
1666 |
nativeWindowType |
|
1667 |
"return a symbol describing my native window type |
|
5538 | 1668 |
(may be used internally by the device as a native window creation hint, |
1669 |
if the device supports native windows)" |
|
5123 | 1670 |
|
1671 |
self class == Label ifTrue:[ |
|
1672 |
^ #Label |
|
1673 |
]. |
|
1674 |
^ nil |
|
1675 |
! ! |
|
1676 |
||
202 | 1677 |
!Label methodsFor:'private'! |
1678 |
||
1679 |
computeLabelOrigin |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1680 |
"(re)compute the origin of the label whenever label, font or view-size changes" |
202 | 1681 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1682 |
|x y a| |
202 | 1683 |
|
1684 |
labelHeight isNil ifTrue:[^ self]. |
|
1685 |
||
1686 |
adjust == #fit ifTrue:[ |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1687 |
labelOriginX := labelOriginY := margin. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1688 |
^ self |
202 | 1689 |
]. |
1690 |
||
1691 |
"if it does not fit, should we make the origin visible, |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1692 |
or the center ? |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1693 |
(for text, the center seems better. |
5587 | 1694 |
For images, I don't really know ...) |
202 | 1695 |
The commented code below makes the origin visible |
1696 |
" |
|
1697 |
"/ (labelHeight < height) ifTrue:[ |
|
1698 |
"/ y := (height - labelHeight) // 2 |
|
1699 |
"/ ] ifFalse:[ |
|
1700 |
"/ y := 0 |
|
1701 |
"/ ]. |
|
1702 |
||
1703 |
"always center vertically" |
|
1704 |
y := (height - labelHeight) // 2. |
|
1705 |
||
1706 |
labelOriginY := y. |
|
1707 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1708 |
a := adjust. |
1945 | 1709 |
a == #centerEach ifTrue:[a := #center]. |
1710 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1711 |
(width < labelWidth) ifTrue:[ |
1921 | 1712 |
((a == #centerRight) or:[a == #leftRight]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1713 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1714 |
] ifFalse:[ |
1921 | 1715 |
((a == #centerLeft) or:[a == #rightLeft]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1716 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1717 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1718 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1719 |
] ifFalse:[ |
1921 | 1720 |
((a == #centerRight) or:[a == #centerLeft]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1721 |
a := #center |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1722 |
] ifFalse:[ |
1921 | 1723 |
a == #leftRight ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1724 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1725 |
] ifFalse:[ |
1921 | 1726 |
a == #rightLeft ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1727 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1728 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1729 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1730 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1731 |
]. |
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1732 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1733 |
(a == #center) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1734 |
" center text/form in button " |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1735 |
x := (width - labelWidth) // 2. |
202 | 1736 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1737 |
(a == #left) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1738 |
x := margin |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1739 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1740 |
"/ #right |
5445 | 1741 |
x := width - labelWidth - margin - self extraMarginForBorder |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1742 |
] |
202 | 1743 |
]. |
1744 |
labelOriginX := x |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1745 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1746 |
"Modified: 13.5.1996 / 10:55:17 / cg" |
202 | 1747 |
! |
1748 |
||
1749 |
computeLabelSize |
|
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1750 |
"compute the extent needed to hold the logo" |
202 | 1751 |
|
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1752 |
|ext| |
202 | 1753 |
|
1754 |
logo isNil ifTrue:[^ self]. |
|
1755 |
||
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1756 |
ext := self rawLabelSizeOf:logo. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1757 |
labelWidth := ext x. |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
1758 |
labelHeight := ext y. |
202 | 1759 |
! |
1760 |
||
1761 |
getLabelFromModel |
|
1762 |
"ask my model for the label to show. |
|
1763 |
Here, we use labelMsg (instead of aspectMsg). |
|
1764 |
This allows multiple labels to react on the same aspect, |
|
1765 |
but show different labels when changed |
|
1766 |
(also, since labelMsg defaults to nil, constant labels |
|
5782 | 1767 |
which have a nil labelMsg will not try to acquire a labelString)." |
202 | 1768 |
|
1769 |
|val| |
|
1770 |
||
1771 |
(model notNil |
|
1772 |
and:[labelMsg notNil]) ifTrue:[ |
|
5782 | 1773 |
val := model perform:labelMsg. |
1774 |
converter notNil ifTrue:[ |
|
1775 |
val := converter printStringFor:val |
|
1776 |
]. |
|
1777 |
self label:val. |
|
202 | 1778 |
]. |
1779 |
! |
|
1780 |
||
1781 |
newLayout |
|
1782 |
"recompute position/size after a change |
|
1783 |
- helper for form:/font: etc." |
|
1784 |
||
1785 |
self computeLabelSize. |
|
3499 | 1786 |
|
202 | 1787 |
fixSize ifFalse:[ |
3499 | 1788 |
self resize. |
1789 |
] ifTrue:[ |
|
1790 |
self computeLabelOrigin. |
|
202 | 1791 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1792 |
self invalidate |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1793 |
|
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1794 |
"Modified: / 6.6.1998 / 19:23:45 / cg" |
5943 | 1795 |
! |
1796 |
||
1797 |
rawLabelSizeOf:aLogo |
|
1798 |
"compute the extent needed to hold aLogo; aForm or aString" |
|
1799 |
||
1800 |
|logoUsed numberOfLines w h textHeight textWidth bounds| |
|
1801 |
||
1802 |
logoUsed := aLogo. |
|
1803 |
aLogo isString ifTrue:[ |
|
1804 |
numberOfLines := 1 + (aLogo occurrencesOf:(Character cr)). |
|
1805 |
(numberOfLines ~~ 1) ifTrue:[ |
|
1806 |
logoUsed := aLogo asStringCollection |
|
1807 |
] |
|
1808 |
] ifFalse:[ |
|
1809 |
(aLogo isStringCollection) ifTrue:[ |
|
1810 |
numberOfLines := aLogo size. |
|
1811 |
(numberOfLines <= 1) ifTrue:[ |
|
1812 |
logoUsed := aLogo asString |
|
1813 |
] |
|
1814 |
] |
|
1815 |
]. |
|
1816 |
||
1817 |
numberOfLines isNil ifTrue:[ |
|
1818 |
"logoUsed is neither a String nor a StringCollection" |
|
1819 |
(logoUsed respondsTo:#preferredBounds) ifTrue:[ |
|
1820 |
bounds := logoUsed preferredBounds. |
|
1821 |
w := bounds width. |
|
1822 |
h := bounds height. |
|
1823 |
] ifFalse:[ |
|
1824 |
w := logoUsed widthOn:self. |
|
1825 |
h := logoUsed heightOn:self. |
|
1826 |
]. |
|
1827 |
||
1828 |
"/ b := logoUsed bounds. |
|
1829 |
"/ labelWidth := b right. |
|
1830 |
"/ labelHeight := b bottom. |
|
1831 |
logoUsed isImageOrForm ifFalse:[ |
|
1832 |
w := w + (hSpace * 2). |
|
1833 |
h := h + (vSpace * 2). |
|
1834 |
]. |
|
1835 |
^ w@h |
|
1836 |
]. |
|
1837 |
||
1838 |
logoUsed isString ifTrue:[ |
|
1839 |
"/ a string or Text |
|
1840 |
textHeight := logoUsed heightOn:self. |
|
1841 |
textWidth := logoUsed widthOn:self. |
|
1842 |
] ifFalse:[ |
|
1843 |
"/ a StringCollection |
|
1844 |
textHeight := (gc font height) * numberOfLines. |
|
1845 |
||
1846 |
textWidth := 0. |
|
1847 |
logoUsed do:[:line | |
|
1848 |
|thisWidth| |
|
1849 |
||
1850 |
line notNil ifTrue:[ |
|
1851 |
thisWidth := line asString widthOn:self. |
|
1852 |
textWidth := textWidth max:thisWidth |
|
1853 |
] |
|
1854 |
]. |
|
1855 |
]. |
|
1856 |
||
1857 |
w := textWidth + (hSpace * 2). |
|
1858 |
h := textHeight + (vSpace * 2). |
|
1859 |
^ w@h |
|
1860 |
||
1861 |
"Modified: / 05-12-2011 / 22:35:44 / cg" |
|
202 | 1862 |
! ! |
1863 |
||
1864 |
!Label methodsFor:'queries'! |
|
1865 |
||
4670 | 1866 |
isTextLabel |
1867 |
^ logo isString |
|
1868 |
! |
|
1869 |
||
202 | 1870 |
preferredExtent |
1871 |
"return my preferred extent - this is the minimum size I would like to have" |
|
1872 |
||
5943 | 1873 |
|ext m2| |
202 | 1874 |
|
4003
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1875 |
"/ If I have an explicit preferredExtent... |
3751
8c607457ad94
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3651
diff
changeset
|
1876 |
explicitExtent notNil ifTrue:[ |
8c607457ad94
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3651
diff
changeset
|
1877 |
^ explicitExtent |
8c607457ad94
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3651
diff
changeset
|
1878 |
]. |
4003
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1879 |
"/ If I have a cached preferredExtent value... |
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1880 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1881 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1882 |
]. |
4003
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1883 |
"/ If I have a frozen extent value... |
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1884 |
fixSize ifTrue:[ |
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1885 |
^ self extent |
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1886 |
]. |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1887 |
|
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1888 |
logo isNil ifTrue:[ |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1889 |
self label:'' |
202 | 1890 |
]. |
4003
1ec317f51033
preferredExtent code cleanup
Claus Gittinger <cg@exept.de>
parents:
3999
diff
changeset
|
1891 |
ext := self rawLabelSizeOf:logo. |
5943 | 1892 |
m2 := (margin + self extraMarginForBorder) * 2. |
1893 |
^ (m2 + ext x + hSpace) @ (m2 + vSpace + ext y) |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1894 |
|
799 | 1895 |
"Modified: 19.7.1996 / 20:44:41 / cg" |
993 | 1896 |
! |
1897 |
||
1898 |
redrawsFull |
|
1899 |
^ true |
|
1900 |
||
1901 |
"Created: 7.2.1997 / 16:41:41 / cg" |
|
202 | 1902 |
! ! |
1903 |
||
0 | 1904 |
!Label methodsFor:'redrawing'! |
1905 |
||
77 | 1906 |
clearInsideWith:bg |
1907 |
|cutOff mustClear| |
|
0 | 1908 |
|
1909 |
cutOff := margin * 2. |
|
1910 |
||
3 | 1911 |
mustClear := true. |
1912 |
||
87 | 1913 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[ |
6052 | 1914 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[ |
1915 |
logo width >= (width - cutOff) ifTrue:[ |
|
1916 |
logo height >= (height - cutOff) ifTrue:[ |
|
1917 |
"no need to clear before - avoid flicker" |
|
1918 |
mustClear := false |
|
1919 |
] |
|
1920 |
] |
|
1921 |
]. |
|
3 | 1922 |
]. |
1923 |
||
1924 |
mustClear ifTrue:[ |
|
6052 | 1925 |
gc paint:bg. |
1926 |
gc fillRectangleX:margin y:margin width:(width - cutOff) height:(height - cutOff). |
|
3 | 1927 |
]. |
77 | 1928 |
! |
1929 |
||
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1930 |
drawImageLogo:imageOrForm x:x y:y opaque:opaque |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1931 |
(opaque not or:[imageOrForm mask notNil]) ifTrue:[ |
6052 | 1932 |
gc displayForm:imageOrForm x:x y:y |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1933 |
] ifFalse:[ |
6052 | 1934 |
gc displayOpaqueForm:imageOrForm x:x y:y |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1935 |
] |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1936 |
! |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1937 |
|
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1938 |
drawOtherLogo:something x:x y:y opaque:opaque |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1939 |
something displayOn:self x:x y:y opaque:opaque |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1940 |
! |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1941 |
|
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1942 |
drawStringLogo:aString x:x y:y |
6052 | 1943 |
gc displayString:aString x:x y:y |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1944 |
! |
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
1945 |
|
1679 | 1946 |
drawWin95FocusFrame |
1891 | 1947 |
|m1 m2| |
1948 |
||
1949 |
m1 := margin + 1. |
|
1950 |
m2 := margin + margin + 2. |
|
1679 | 1951 |
self |
1891 | 1952 |
displayDottedRectangleX:m1 |
1953 |
y:m1 |
|
1954 |
width:(width - m2) |
|
1955 |
height:(height - m2). |
|
1679 | 1956 |
|
1957 |
"Created: / 17.9.1998 / 14:16:46 / cg" |
|
1891 | 1958 |
"Modified: / 29.4.1999 / 21:49:22 / cg" |
1679 | 1959 |
! |
1960 |
||
77 | 1961 |
drawWith:fg and:bg |
1962 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1963 |
(especially Button) to redraw the logo in different colors." |
|
1964 |
||
2496 | 1965 |
self drawWith:fg and:bg clearInside:true etchedFg:etchedFgColor. |
1966 |
! |
|
1967 |
||
1968 |
drawWith:fg and:bg clearInside:doClear etchedFg:etchedFg |
|
1969 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1970 |
(especially Button) to redraw the logo in different colors." |
|
1971 |
||
5983 | 1972 |
|x y scaleH scaleV nW nH hSep vSep m2 ascent currentTransformation |
6177 | 1973 |
logoWidth logoHeight lines logoDrawn| |
77 | 1974 |
|
2496 | 1975 |
doClear ifTrue:[self clearInsideWith:bg]. |
0 | 1976 |
|
6052 | 1977 |
gc paint:fg on:bg. |
0 | 1978 |
logo notNil ifTrue:[ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1979 |
m2 := margin * 2. |
4899 | 1980 |
hSep := hSpace*2. |
1981 |
vSep := vSpace*2. |
|
133 | 1982 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1983 |
x := labelOriginX. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1984 |
y := labelOriginY. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1985 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1986 |
logo isImageOrForm ifTrue:[ |
5983 | 1987 |
logoWidth := logo width. |
1988 |
logoHeight := logo height. |
|
1989 |
((logoWidth == 0) or:[logoHeight == 0]) ifTrue:[ |
|
1990 |
"/ do nothing; also avoids followup errors in the image creation and division by zero... |
|
1991 |
^ self. |
|
1992 |
]. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1993 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1994 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1995 |
"/ change scale to make the logo fit exactly |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1996 |
"/ |
5983 | 1997 |
scaleH := ((width - hSep) / logoWidth) asFloat. |
1998 |
scaleV := ((height - vSep) / logoHeight) asFloat. |
|
2968 | 1999 |
scaleH <= 0 ifTrue:[scaleH := Float epsilon]. |
2000 |
scaleV <= 0 ifTrue:[scaleV := Float epsilon]. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2001 |
self scale:(scaleH @ scaleV). |
4899 | 2002 |
x := currentTransformation applyInverseScaleX:x. |
2003 |
y := currentTransformation applyInverseScaleY:y. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2004 |
]. |
131 | 2005 |
|
5633 | 2006 |
logo := logo onDevice:device. |
59 | 2007 |
"/ self background:bg. |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
2008 |
self drawImageLogo:logo x:x y:y opaque:doClear. |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2009 |
] ifFalse:[ |
6177 | 2010 |
"/ convert to a line-collection if required; |
2011 |
"/ otherwise, adjust may get it wrong... |
|
2012 |
logoDrawn := logo. |
|
2013 |
(logoDrawn isString and:[(lines := logoDrawn asStringCollection) size > 1]) |
|
2014 |
ifTrue:[ |
|
2015 |
logoDrawn := lines. |
|
2016 |
]. |
|
2017 |
||
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2018 |
x := x + hSpace. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2019 |
y := y + vSpace. |
0 | 2020 |
|
1665 | 2021 |
level < 0 ifTrue:[ |
2022 |
x := x + 1. |
|
2023 |
y := y + 1 |
|
1659
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
2024 |
]. |
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
2025 |
|
6177 | 2026 |
ascent := logoDrawn ascentOn:self. |
3651
c47e8c3583cf
Remove type specific vodoo - ask logo for ascent instead.
Stefan Vogel <sv@exept.de>
parents:
3649
diff
changeset
|
2027 |
y := y + ascent. |
c47e8c3583cf
Remove type specific vodoo - ask logo for ascent instead.
Stefan Vogel <sv@exept.de>
parents:
3649
diff
changeset
|
2028 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2029 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2030 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2031 |
"/ change scale to make the logo fit exactly |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2032 |
"/ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2033 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2034 |
scaleV := ((height - m2 - vSep) / (labelHeight - vSpace)) asFloat. |
2968 | 2035 |
scaleH <= 0 ifTrue:[scaleH := Float epsilon]. |
2036 |
scaleV <= 0 ifTrue:[scaleV := Float epsilon]. |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2037 |
|
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2038 |
self scale:(scaleH min:scaleV). |
4899 | 2039 |
currentTransformation := gc transformation. |
2040 |
x := currentTransformation applyInverseScaleX:x. |
|
3651
c47e8c3583cf
Remove type specific vodoo - ask logo for ascent instead.
Stefan Vogel <sv@exept.de>
parents:
3649
diff
changeset
|
2041 |
ascent ~~ 0 ifTrue:[ |
4899 | 2042 |
y := y - ascent + (currentTransformation applyScaleY:ascent). |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
2043 |
]. |
4899 | 2044 |
y := currentTransformation applyInverseScaleY:y. |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2045 |
scaleH < scaleV ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2046 |
nH := labelHeight * scaleH. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2047 |
"/ now, center vertically |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2048 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2049 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2050 |
scaleV < scaleH ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2051 |
"/ now, center horizontally |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2052 |
nW := labelWidth * scaleV. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2053 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2) |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2054 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2055 |
]. |
131 | 2056 |
|
6177 | 2057 |
logoDrawn isString ifTrue:[ |
2496 | 2058 |
"/ doClear ifTrue:[ |
6177 | 2059 |
"/ self displayOpaqueString:logoDrawn x:x y:y |
2496 | 2060 |
"/ ] ifFalse:[ |
6177 | 2061 |
"/ self displayString:logoDrawn x:x y:y |
2496 | 2062 |
"/ ] |
2063 |
etchedFg notNil ifTrue:[ |
|
6052 | 2064 |
gc paint:etchedFg. |
6177 | 2065 |
self drawStringLogo:logoDrawn x:x+1 y:y+1. |
6052 | 2066 |
gc paint:fg. |
2496 | 2067 |
]. |
6177 | 2068 |
self drawStringLogo:logoDrawn x:x y:y |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2069 |
] ifFalse:[ |
6177 | 2070 |
(logoDrawn isStringCollection) ifTrue:[ |
2071 |
logoDrawn do:[ :line | |
|
2496 | 2072 |
|wThis str| |
2073 |
||
1945 | 2074 |
adjust == #centerEach ifTrue:[ |
2075 |
wThis := line asString widthOn:self. |
|
2076 |
x := (width - wThis) // 2. |
|
2077 |
]. |
|
2496 | 2078 |
str := line printString. |
2079 |
"/ doClear ifTrue:[ |
|
2080 |
"/ self displayOpaqueString:str x:x y:y. |
|
2081 |
"/ ] ifFalse:[ |
|
2082 |
"/ self displayString:str x:x y:y. |
|
2083 |
"/ ]. |
|
2084 |
etchedFg notNil ifTrue:[ |
|
6052 | 2085 |
gc paint:etchedFg. |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
2086 |
self drawStringLogo:str x:x+1 y:y+1. |
6052 | 2087 |
gc paint:fg. |
2496 | 2088 |
]. |
3850
8886e358dfe1
refactored to make the label drawing redefinable
Claus Gittinger <cg@exept.de>
parents:
3751
diff
changeset
|
2089 |
self drawStringLogo:str x:x y:y. |
4891 | 2090 |
y := y + (gc font height) |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2091 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2092 |
] ifFalse:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2093 |
"/ anything |
6177 | 2094 |
self drawOtherLogo:logoDrawn x:x y:y opaque:doClear |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2095 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2096 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2097 |
]. |
131 | 2098 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2099 |
adjust == #fit ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2100 |
self scale:1 |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2101 |
]. |
0 | 2102 |
] |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
2103 |
|
6177 | 2104 |
"Modified: / 11-07-2017 / 14:35:40 / cg" |
0 | 2105 |
! |
2106 |
||
2107 |
redraw |
|
2108 |
"redraw my label" |
|
2109 |
||
2110 |
shown ifTrue:[ |
|
3924 | 2111 |
self clear. |
2112 |
self drawWith:fgColor and:bgColor |
|
0 | 2113 |
] |
2114 |
! ! |
|
105 | 2115 |
|
110 | 2116 |
!Label methodsFor:'resizing'! |
2117 |
||
2118 |
forceResize |
|
118 | 2119 |
"resize myself to make text fit into myself. Here, this is done even if |
2120 |
fixSize is set." |
|
110 | 2121 |
|
2664 | 2122 |
|prevFixSize| |
2123 |
||
110 | 2124 |
logo notNil ifTrue:[ |
2664 | 2125 |
prevFixSize := fixSize. |
2126 |
fixSize := false. |
|
2127 |
self extent:self preferredExtent. |
|
2128 |
self computeLabelOrigin. |
|
3499 | 2129 |
"/ this seems the only one which might depend on my contents. |
2130 |
layout isLayout ifTrue:[ |
|
2131 |
layout isAlignmentOrigin ifTrue:[ |
|
2132 |
self containerChangedSize. |
|
2133 |
] |
|
2134 |
]. |
|
2664 | 2135 |
fixSize := prevFixSize. |
2136 |
] |
|
2137 |
! |
|
2138 |
||
2139 |
forceResizeHorizontally |
|
2140 |
"resize myself horizontally to make text fit into myself. |
|
2141 |
Here, this is done even if fixSize is set." |
|
2142 |
||
2143 |
|prevFixSize| |
|
2144 |
||
2145 |
logo notNil ifTrue:[ |
|
2146 |
prevFixSize := fixSize. |
|
2147 |
fixSize := false. |
|
3615
a99127b32e61
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3597
diff
changeset
|
2148 |
self width:self preferredWidth. |
2664 | 2149 |
self computeLabelOrigin. |
2150 |
fixSize := prevFixSize. |
|
110 | 2151 |
] |
105 | 2152 |
! |
2153 |
||
2154 |
resize |
|
2155 |
"resize myself to make text fit into myself. |
|
118 | 2156 |
but only do so, if I am not fixedSize and I have NOT been |
2157 |
given a relative extent or an extend computation block." |
|
105 | 2158 |
|
110 | 2159 |
(logo notNil |
2160 |
and:[fixSize not |
|
2161 |
and:[relativeExtent isNil |
|
2162 |
and:[extentRule isNil |
|
2163 |
and:[relativeCorner isNil |
|
2164 |
and:[cornerRule isNil]]]]]) ifTrue:[ |
|
2165 |
self forceResize |
|
2166 |
] ifFalse:[ |
|
105 | 2167 |
self computeLabelOrigin |
2168 |
] |
|
2169 |
! ! |
|
2170 |
||
5751 | 2171 |
!Label::AnimatorState methodsFor:'accessing'! |
2172 |
||
2173 |
logoShown |
|
2174 |
^ logoShown |
|
2175 |
! |
|
2176 |
||
2177 |
moveDirection |
|
2178 |
^ moveDirection |
|
2179 |
! |
|
2180 |
||
2181 |
moveDirection:something |
|
2182 |
moveDirection := something. |
|
2183 |
! |
|
2184 |
||
2185 |
nextOffset |
|
2186 |
^ nextOffset |
|
2187 |
! |
|
2188 |
||
2189 |
nextOffset:something |
|
2190 |
nextOffset := something. |
|
2191 |
! |
|
2192 |
||
5755 | 2193 |
pointerEntered |
2194 |
^ pointerEntered |
|
2195 |
! |
|
2196 |
||
2197 |
pointerEntered:something |
|
2198 |
pointerEntered := something. |
|
2199 |
! |
|
2200 |
||
5751 | 2201 |
timedBlock |
2202 |
^ timedBlock |
|
2203 |
! |
|
2204 |
||
2205 |
timedBlock:timedBlockArg nextOffset:nextOffsetArg moveDirection:moveDirectionArg logoShown:logoShownArg |
|
2206 |
timedBlock := timedBlockArg. |
|
2207 |
nextOffset := nextOffsetArg. |
|
2208 |
moveDirection := moveDirectionArg. |
|
2209 |
logoShown := logoShownArg. |
|
2210 |
! ! |
|
2211 |
||
935 | 2212 |
!Label class methodsFor:'documentation'! |
205 | 2213 |
|
2214 |
version |
|
5445 | 2215 |
^ '$Header$' |
3999
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
2216 |
! |
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
2217 |
|
f605cc13731e
computeLabelSize refactorings
Claus Gittinger <cg@exept.de>
parents:
3927
diff
changeset
|
2218 |
version_CVS |
5445 | 2219 |
^ '$Header$' |
205 | 2220 |
! ! |
4670 | 2221 |