RoundButton.st
author Claus Gittinger <cg@exept.de>
Fri, 15 Jun 2018 10:54:35 +0200
changeset 5816 7876c07931a7
parent 3150 e3a55f15ef7e
child 4770 6634b540fea2
permissions -rw-r--r--
#DOCUMENTATION by cg class: ComboListView class comment/format in: #documentation
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
3150
e3a55f15ef7e package information
Claus Gittinger <cg@exept.de>
parents: 1232
diff changeset
    13
"{ Package: 'stx:libwidg2' }"
e3a55f15ef7e package information
Claus Gittinger <cg@exept.de>
parents: 1232
diff changeset
    14
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    15
Button subclass:#RoundButton
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    16
	instanceVariableNames:''
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    17
	classVariableNames:''
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    18
	poolDictionaries:''
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    19
	category:'Views-Interactors'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    20
!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    21
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    22
!RoundButton class methodsFor:'documentation'!
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
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    25
"
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    27
	      All Rights Reserved
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    28
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    29
 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
    30
 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
    31
 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
    32
 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
    33
 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
    34
 hereby transferred.
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
!
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    37
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    38
documentation
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    39
"
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    40
    this is not finished - please do not look at it
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    41
    and do not use it (i.e. simply ignore it ;-).
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    42
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    43
    Notice - this only works under graphic displays which
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    44
    support arbitrary shaped views (i.e. XWindow).
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    45
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    46
    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
    47
"
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    48
!
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    49
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    50
examples
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 b|
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    53
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    54
    top := StandardSystemView extent:300@300.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    55
    b := RoundButton label:'hello' in:top.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    56
    top open
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    57
"
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    58
! !
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    59
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    60
!RoundButton methodsFor:'drawing'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    61
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    62
drawWith:fg and:bg
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    63
    self paint:bg.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    64
    self fillRectangleX:0 y:0 width:width height:height.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    65
    super drawWith:fg and:bg
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    66
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    67
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    68
!RoundButton methodsFor:'private'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    69
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    70
roundCornerFormWidth:width height:height offset:off
7
19b36b78ee01 *** empty log message ***
claus
parents: 1
diff changeset
    71
    |form wCorn hCorn wCornHalf wCornHalfRest hCornHalf hCornHalfRest
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    72
     left top right bot w h|
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    73
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    74
     "compute a shape form"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    75
     form := Form width:width height:height.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    76
     form fill:(Color colorId:0).
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    77
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    78
     left := off. right := width-(off*2)-1.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    79
     top := off. bot := height-(2*off)-1.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    80
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    81
     w := width - off - off.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    82
     h := height - off - off.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    83
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    84
     wCorn := (w * 0.33) rounded asInteger.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    85
     hCorn := (h * 0.75) rounded asInteger.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    86
     wCornHalf := wCorn // 2.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    87
     hCornHalf := hCorn // 2.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    88
     wCorn odd ifTrue:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    89
	 wCornHalfRest := 1
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    90
     ] ifFalse:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    91
	 wCornHalfRest := 0
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    92
     ].
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    93
     hCorn odd ifTrue:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    94
	 hCornHalfRest := 1
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    95
     ] ifFalse:[
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
    96
	 hCornHalfRest := 0
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    97
     ].
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    98
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    99
     form paint:(Color colorId:1).
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   100
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   101
     form fillArcX:left y:top w:wCorn h:hCorn from:0 angle:360.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   102
3150
e3a55f15ef7e package information
Claus Gittinger <cg@exept.de>
parents: 1232
diff changeset
   103
     form fillRectangleX:(left + wCornHalf) y:top
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
   104
			 width:(w - wCorn + wCornHalfRest) height:hCornHalf.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   105
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   106
     "top right arc"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   107
     form fillArcX:(right - wCorn) y:top w:wCorn h:hCorn from:0 angle:90.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   108
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   109
     "big middle rect"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   110
     form fillRectangleX:left y:(top + hCornHalf)
86
4d7dbb5f1719 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 7
diff changeset
   111
		    width:w height:(h - hCorn + hCornHalfRest).
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   112
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   113
     "bottom left arc"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   114
     form fillArcX:left y:(bot - hCorn) w:wCorn h:hCorn from:180 angle:90.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   115
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   116
     "bottom rect"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   117
     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
   118
		    width:(w - wCorn + wCornHalfRest) height:hCornHalf.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   119
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   120
     "bottom right arc"
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   121
     form fillArcX:(right - wCorn) y:(bot - hCorn) w:wCorn h:hCorn from:270 angle:90.
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   122
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   123
     ^ form
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   124
! !
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   125
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   126
!RoundButton methodsFor:'window events'!
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   127
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   128
sizeChanged:how
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   129
    |shapeForm borderForm|
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   130
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   131
    super sizeChanged:how.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   132
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   133
    "compute a new shape form"
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   134
3150
e3a55f15ef7e package information
Claus Gittinger <cg@exept.de>
parents: 1232
diff changeset
   135
    borderForm := self roundCornerFormWidth:width+(borderWidth * 2)
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   136
				     height:height+(borderWidth * 2)
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   137
				     offset:0.
3150
e3a55f15ef7e package information
Claus Gittinger <cg@exept.de>
parents: 1232
diff changeset
   138
    shapeForm := self roundCornerFormWidth:width+(borderWidth * 2)
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   139
				    height:height+(borderWidth * 2)
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   140
				    offset:borderWidth.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   141
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   142
    self borderShape:borderForm.
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   143
    self viewShape:shapeForm
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   144
! !
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   145
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   146
!RoundButton class methodsFor:'documentation'!
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   147
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   148
version
3150
e3a55f15ef7e package information
Claus Gittinger <cg@exept.de>
parents: 1232
diff changeset
   149
    ^ '$Header: /cvs/stx/stx/libwidg2/RoundButton.st,v 1.5 2006-11-13 16:11:31 cg Exp $'
1232
e501018bd562 comment
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   150
! !