MacFlatButtonBorder.st
author Claus Gittinger <cg@exept.de>
Sat, 03 Oct 2015 16:07:45 +0200
changeset 6943 80ae41ea8a5b
parent 6942 b804dc9f04de
child 6965 066bfdfbb5b3
permissions -rw-r--r--
initial checkin class: MacOSXRoundButtonBorder added:10 methods

"{ Encoding: utf8 }"

"{ Package: 'stx:libview' }"

"{ NameSpace: Smalltalk }"

SimpleBorder subclass:#MacFlatButtonBorder
	instanceVariableNames:'insideColor imgTopLeft imgTopRight imgBottomLeft imgBottomRight'
	classVariableNames:''
	poolDictionaries:''
	category:'Graphics-Support'
!

!MacFlatButtonBorder class methodsFor:'documentation'!

documentation
"
    an as yet unused and unfinished attempt to provide a mac-osx like
    button border. These will look like mac buttons in yosemite (i.e. ugly old 70s retro flat style).
    To be continued.
"
! !

!MacFlatButtonBorder class methodsFor:'instance creation'!

color:color1 insideColor:color2
    "create a new instance of the receiver with a border of the given color."

    ^ self new color:color1; insideColor:color2
! !

!MacFlatButtonBorder class methodsFor:'image specs'!

topLeftImageFilled
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self topLeftImageFilled inspect
     ImageEditor openOnClass:self andSelector:#topLeftImageFilled
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'MacOSXRoundButtonBorder topLeftImageFilled'
        ifAbsentPut:[(Depth8Image width:4 height:4) bits:(ByteArray fromPackedString:'@@LB@PLA@P@B@P@@@P@@@@@a') colorMapFromArray:#[44 132 251 49 107 245 95 142 236 175 196 234] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\OC0<@@a'); yourself); yourself]
!

topLeftImageUnfilled
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self topLeftImageUnfilled inspect
     ImageEditor openOnClass:self andSelector:#topLeftImageUnfilled
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilled'
        ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'9HMOO0@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\OC0<@@a'); yourself); yourself]
!

topLeftImageUnfilledMasked
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self topLeftImageUnfilledMasked inspect
     ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked'
        ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'IHA@@@@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\NC@ @@a'); yourself); yourself]
!

topLeftImageUnfilledMasked2
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self topLeftImageUnfilledMasked2 inspect
     ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked2
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked2'
        ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'IH!! @@@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\NC@ @@a'); yourself); yourself]
!

topLeftImageUnfilledMasked3
    "This resource specification was automatically generated
     by the ImageEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the ImageEditor may not be able to read the specification."

    "
     self topLeftImageUnfilledMasked3 inspect
     ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked3
     Icon flushCachedIcons
    "

    <resource: #image>

    ^Icon
        constantNamed:'MacOSXRoundButtonBorder topLeftImageUnfilledMasked3'
        ifAbsentPut:[(Depth2Image width:4 height:4) bits:(ByteArray fromPackedString:'HH  @@@a') colorMapFromArray:#[183 183 183 201 201 201 224 224 224 255 255 255] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'\NC@ @@a'); yourself); yourself]
! !

!MacFlatButtonBorder methodsFor:'accessing'!

color:newColor
    color ~= newColor ifTrue:[        
        color := newColor.
        imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil.
    ].
!

insideColor:newColor
    insideColor ~= newColor ifTrue:[        
        insideColor := newColor.
        imgTopLeft := imgTopRight := imgBottomLeft := imgBottomRight := nil.
    ].
! !

!MacFlatButtonBorder methodsFor:'displaying'!

displayOn:aGC forDisplayBox:aRectangle
    |oldPaint boxLeft boxRight boxTop boxBottom boxWidth boxHeight|

    color isNil ifTrue:[ ^ self].

    oldPaint := aGC paint.
    aGC paint:color.

    boxLeft := aRectangle left.
    boxTop := aRectangle top.
    boxWidth := aRectangle width.
    boxHeight := aRectangle height.

    boxRight := boxLeft + boxWidth.
    boxBottom := boxTop + boxHeight.
    
    imgTopLeft isNil ifTrue:[
        self makeImages.
    ].    

    aGC displayImage:imgTopLeft x:boxLeft y:boxTop.
    aGC displayImage:imgTopRight x:boxRight-4 y:boxTop.
    aGC displayImage:imgBottomRight x:boxRight-4 y:boxBottom-4.
    aGC displayImage:imgBottomLeft x:boxLeft y:boxBottom-4.

    aGC displayLineFromX:boxLeft+4 y:boxTop toX:boxRight-4 y:boxTop.
    aGC displayLineFromX:boxLeft+4 y:boxBottom-1 toX:boxRight-4 y:boxBottom-1.
    aGC displayLineFromX:boxLeft y:boxTop+4 toX:boxLeft y:boxBottom-4.
    aGC displayLineFromX:boxRight-1 y:boxTop+4 toX:boxRight-1 y:boxBottom-4.

    aGC paint:oldPaint.

    "
     |v1 v2|

     v1 := TopView new.
     v2 := View origin:10@10 corner:100@30 in:v1.
     v2 border:(MacOSXRoundButtonBorder color:Color red).
     v1 open.
    "
    "
     |v1 v2|

     v1 := TopView new.
     v2 := View origin:10@10 corner:100@30 in:v1.
     v2 border:(MacOSXRoundButtonBorder color:Color red insideColor:Color blue).
     v1 open.
    "
! !

!MacFlatButtonBorder methodsFor:'private'!

makeImages
    |protoImage img hue light sat innerHue innerLight innerSat|
    
    hue := color hue.
    light := color light.
    sat := color saturation.

    insideColor isNil ifTrue:[
        protoImage := self class topLeftImageUnfilledMasked3.
    ] ifFalse:[    
        insideColor hue isNil ifTrue:[
            protoImage := self class topLeftImageUnfilled.
        ] ifFalse:[    
            protoImage := self class topLeftImageFilled.
            innerHue := insideColor hue.
            innerLight := insideColor light.
            innerSat := insideColor saturation.
        ].
    ].
    img := protoImage copy.

    innerHue notNil ifTrue:[
        img colorMap at:1 put:insideColor.
        img colorMap at:2 put:color.
        img colorMap at:3 put:(Color hue:hue light:light+8 saturation:sat-12).
        img colorMap at:4 put:(Color hue:hue light:light+20 saturation:sat-40).
    ] ifFalse:[
        img colorMap at:1 put:color.
        img colorMap at:2 put:(Color hue:hue light:light+15 saturation:sat-12).
        img colorMap at:3 put:(Color hue:hue light:light+30 saturation:sat-40).
    ].    
    
    imgTopLeft := img.
    imgTopRight := img rotated:90.
    imgBottomLeft := img rotated:-90.
    imgBottomRight := img rotated:180.
! !

!MacFlatButtonBorder class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !