RoundButton.st
author Claus Gittinger <cg@exept.de>
Tue, 11 May 2004 14:50:21 +0200
changeset 2704 0a09fd78eb54
parent 1232 e501018bd562
child 3150 e3a55f15ef7e
permissions -rw-r--r--
ColorEditDialog made public
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     1
"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
     3
	      All Rights Reserved
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     4
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    11
"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    12
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    13
Button subclass:#RoundButton
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    14
	instanceVariableNames:''
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    15
	classVariableNames:''
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    16
	poolDictionaries:''
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    17
	category:'Views-Interactors'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    18
!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    19
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    20
!RoundButton class methodsFor:'documentation'!
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    21
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    22
copyright
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    23
"
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    25
	      All Rights Reserved
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    26
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    27
 This software is furnished under a license and may be used
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    28
 only in accordance with the terms of that license and with the
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    30
 be provided or otherwise made available to, or used by, any
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    31
 other person.  No title to or ownership of the software is
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    32
 hereby transferred.
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    33
"
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    34
!
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    35
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    36
documentation
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    37
"
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    38
    this is not finished - please do not look at it
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    39
    and do not use it (i.e. simply ignore it ;-).
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    40
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    41
    Notice - this only works under graphic displays which
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    42
    support arbitrary shaped views (i.e. XWindow).
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    43
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    44
    Under Win32, you will see a rectanglular view instead.
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    45
"
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    46
!
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    47
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    48
examples
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    49
"
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    50
    |top b|
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    51
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    52
    top := StandardSystemView extent:300@300.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    53
    b := RoundButton label:'hello' in:top.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    54
    top open
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    55
"
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    56
! !
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    57
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    58
!RoundButton methodsFor:'drawing'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    59
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    60
drawWith:fg and:bg
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    61
    self paint:bg.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    62
    self fillRectangleX:0 y:0 width:width height:height.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    63
    super drawWith:fg and:bg
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    64
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    65
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    66
!RoundButton methodsFor:'private'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    67
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    68
roundCornerFormWidth:width height:height offset:off
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
    69
    |form wCorn hCorn wCornHalf wCornHalfRest hCornHalf hCornHalfRest
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    70
     left top right bot w h|
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    71
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    72
     "compute a shape form"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    73
     form := Form width:width height:height.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    74
     form fill:(Color colorId:0).
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    75
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    76
     left := off. right := width-(off*2)-1.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    77
     top := off. bot := height-(2*off)-1.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    78
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    79
     w := width - off - off.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    80
     h := height - off - off.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    81
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    82
     wCorn := (w * 0.33) rounded asInteger.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    83
     hCorn := (h * 0.75) rounded asInteger.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    84
     wCornHalf := wCorn // 2.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    85
     hCornHalf := hCorn // 2.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    86
     wCorn odd ifTrue:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    87
	 wCornHalfRest := 1
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    88
     ] ifFalse:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    89
	 wCornHalfRest := 0
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    90
     ].
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    91
     hCorn odd ifTrue:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    92
	 hCornHalfRest := 1
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    93
     ] ifFalse:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    94
	 hCornHalfRest := 0
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    95
     ].
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    96
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    97
     form paint:(Color colorId:1).
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    98
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    99
     form fillArcX:left y:top w:wCorn h:hCorn from:0 angle:360.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   100
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   101
     form fillRectangleX:(left + wCornHalf) y:top 
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
   102
			 width:(w - wCorn + wCornHalfRest) height:hCornHalf.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   103
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   104
     "top right arc"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   105
     form fillArcX:(right - wCorn) y:top w:wCorn h:hCorn from:0 angle:90.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   106
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   107
     "big middle rect"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   108
     form fillRectangleX:left y:(top + hCornHalf)
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
   109
		    width:w height:(h - hCorn + hCornHalfRest).
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   110
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   111
     "bottom left arc"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   112
     form fillArcX:left y:(bot - hCorn) w:wCorn h:hCorn from:180 angle:90.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   113
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   114
     "bottom rect"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   115
     form fillRectangleX:(left + wCornHalf) y:(bot - hCornHalf)
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
   116
		    width:(w - wCorn + wCornHalfRest) height:hCornHalf.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   117
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   118
     "bottom right arc"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   119
     form fillArcX:(right - wCorn) y:(bot - hCorn) w:wCorn h:hCorn from:270 angle:90.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   120
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   121
     ^ form
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   122
! !
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   123
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   124
!RoundButton methodsFor:'window events'!
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   125
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   126
sizeChanged:how
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   127
    |shapeForm borderForm|
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   128
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   129
    super sizeChanged:how.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   130
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   131
    "compute a new shape form"
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   132
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   133
    borderForm := self roundCornerFormWidth:width+(borderWidth * 2) 
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   134
				     height:height+(borderWidth * 2)
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   135
				     offset:0.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   136
    shapeForm := self roundCornerFormWidth:width+(borderWidth * 2) 
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   137
				    height:height+(borderWidth * 2)
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   138
				    offset:borderWidth.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   139
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   140
    self borderShape:borderForm.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   141
    self viewShape:shapeForm
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   142
! !
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   143
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   144
!RoundButton class methodsFor:'documentation'!
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   145
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   146
version
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   147
    ^ '$Header: /cvs/stx/stx/libwidg2/RoundButton.st,v 1.4 1999-03-07 13:29:24 cg Exp $'
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   148
! !