296 |
295 |
297 toggleNoAction |
296 toggleNoAction |
298 "toggle, but do NOT perform any action - can be used to change a toggle |
297 "toggle, but do NOT perform any action - can be used to change a toggle |
299 under program control (i.e. turn one toggle off from another one)" |
298 under program control (i.e. turn one toggle off from another one)" |
300 |
299 |
301 |newLevel| |
300 |newLevel pressed| |
302 |
301 |
303 pressed := pressed not. |
302 pressed := controller pressed not. |
|
303 controller pressed:pressed. |
304 pressed ifTrue:[ |
304 pressed ifTrue:[ |
305 newLevel := onLevel. |
305 newLevel := onLevel. |
306 ] ifFalse:[ |
306 ] ifFalse:[ |
307 newLevel := offLevel. |
307 newLevel := offLevel. |
308 ]. |
308 ]. |
317 ! |
317 ! |
318 |
318 |
319 toggle |
319 toggle |
320 "toggle and perform the action" |
320 "toggle and perform the action" |
321 |
321 |
322 |action| |
322 |action pressed| |
323 |
323 |
324 enabled ifTrue:[ |
324 controller enabled ifTrue:[ |
325 self toggleNoAction. |
325 self toggleNoAction. |
326 pressed ifTrue:[ |
326 (pressed := controller pressed) ifTrue:[ |
327 action := pressActionBlock |
327 action := controller pressAction |
328 ] ifFalse:[ |
328 ] ifFalse:[ |
329 action := releaseActionBlock |
329 action := controller releaseAction |
330 ]. |
330 ]. |
331 action notNil ifTrue:[action value]. |
331 action notNil ifTrue:[action value]. |
332 model notNil ifTrue:[ |
332 model notNil ifTrue:[ |
333 model value:pressed. |
333 model value:pressed. |
334 model changed |
334 model changed |
335 ]. |
335 ]. |
336 self changed |
336 self changed |
337 ] |
337 ] |
338 ! ! |
338 ! ! |
339 |
339 |
340 !Toggle methodsFor:'event handling'! |
|
341 |
|
342 buttonPress:button x:x y:y |
|
343 ((button == 1) or:[button == #select]) ifTrue:[ |
|
344 self toggle |
|
345 ] ifFalse:[ |
|
346 ^ super buttonPress:button x:x y:y |
|
347 ]. |
|
348 ! |
|
349 |
|
350 buttonRelease:button x:x y:y |
|
351 ((button == 1) or:[button == #select]) ifFalse:[ |
|
352 ^ super buttonRelease:button x:x y:y |
|
353 ]. |
|
354 "ignore" |
|
355 ! ! |
|
356 |
|
357 !Toggle methodsFor:'redrawing'! |
340 !Toggle methodsFor:'redrawing'! |
358 |
341 |
359 drawWith:fg and:bg |
342 drawWith:fg and:bg |
360 "redraw myself with fg/bg. Use super to draw the label, |
343 "redraw myself with fg/bg. Use super to draw the label, |
361 drawing of the lamp is done here." |
344 drawing of the lamp is done here." |
362 |
345 |
363 |x y| |
346 |x y clr| |
364 |
347 |
365 super drawWith:fg and:bg. "this draws the text" |
348 super drawWith:fg and:bg. "this draws the text" |
366 |
349 |
367 showLamp ifTrue:[ |
350 showLamp ifTrue:[ |
368 x := hSpace + margin. |
351 x := hSpace + margin. |
369 y := (height - lampHeight) // 2. |
352 y := (height - lampHeight) // 2. |
370 self drawEdgesForX:x y:y width:lampWidth height:lampHeight level:-1. |
353 self drawEdgesForX:x y:y width:lampWidth height:lampHeight level:-1. |
371 pressed ifTrue:[ |
354 controller pressed ifTrue:[ |
372 self paint:lampColor. |
355 clr := lampColor. |
373 ] ifFalse:[ |
356 ] ifFalse:[ |
374 self paint:bgColor. |
357 clr := bgColor. |
375 ]. |
358 ]. |
|
359 self paint:clr. |
376 self fillRectangleX:x+2 y:y+2 width:lampWidth - 4 height:lampHeight - 4 |
360 self fillRectangleX:x+2 y:y+2 width:lampWidth - 4 height:lampHeight - 4 |
377 ] |
361 ] |
378 ! ! |
362 ! ! |