RoundedBorder.st
changeset 7000 18da82c5d44e
child 7939 f5018d46a5e7
equal deleted inserted replaced
6999:368cc9e8a698 7000:18da82c5d44e
       
     1 "
       
     2  COPYRIGHT (c) 2015 by eXept Software AG
       
     3               All Rights Reserved
       
     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 "
       
    12 "{ Package: 'stx:libview' }"
       
    13 
       
    14 "{ NameSpace: Smalltalk }"
       
    15 
       
    16 SimpleBorder subclass:#RoundedBorder
       
    17 	instanceVariableNames:'imgTopLeft imgTopRight imgBottomRight imgBottomLeft'
       
    18 	classVariableNames:'TemplateTopLeft TemplateTopRight TemplateBottomRight
       
    19 		TemplateBottomLeft'
       
    20 	poolDictionaries:''
       
    21 	category:'Graphics-Support'
       
    22 !
       
    23 
       
    24 !RoundedBorder class methodsFor:'documentation'!
       
    25 
       
    26 copyright
       
    27 "
       
    28  COPYRIGHT (c) 2015 by eXept Software AG
       
    29               All Rights Reserved
       
    30 
       
    31  This software is furnished under a license and may be used
       
    32  only in accordance with the terms of that license and with the
       
    33  inclusion of the above copyright notice.   This software may not
       
    34  be provided or otherwise made available to, or used by, any
       
    35  other person.  No title to or ownership of the software is
       
    36  hereby transferred.
       
    37 "
       
    38 !
       
    39 
       
    40 documentation
       
    41 "
       
    42     a rounded border as in modern yosemite and new adwaita
       
    43 
       
    44     [see also:]
       
    45         Border
       
    46 
       
    47     [author:]
       
    48         Claus Gittinger
       
    49 "
       
    50 !
       
    51 
       
    52 examples
       
    53 "
       
    54                                                         [exBegin]
       
    55      |v b|
       
    56 
       
    57      v := StandardSystemView extent:200@100.
       
    58      v openAndWait.
       
    59          
       
    60      b := RoundedBorder width:5 color:Color red.
       
    61      b displayOn:v forDisplayBox:(0@0 extent:100@100).
       
    62                                                         [exEnd]
       
    63 
       
    64                                                         [exBegin]
       
    65      |t v b|
       
    66 
       
    67      t := StandardSystemView extent:200@100.
       
    68      t viewBackground:Color green.
       
    69      v := View in:t.
       
    70      v viewBackground:Color red.
       
    71      v origin:10@10 corner:90@90.
       
    72      t openAndWait.
       
    73 
       
    74      b := RoundedBorder width:10 color:Color red.
       
    75      v border:b
       
    76                                                         [exEnd]
       
    77 "
       
    78 ! !
       
    79 
       
    80 !RoundedBorder class methodsFor:'image specs'!
       
    81 
       
    82 templateBottomLeftImage
       
    83     TemplateBottomLeft isNil ifTrue:[
       
    84         TemplateBottomLeft := self templateBottomRightImage rotated:90
       
    85     ].    
       
    86     ^ TemplateBottomLeft
       
    87 
       
    88     "
       
    89      self templateBottomLeftImage
       
    90     "
       
    91 !
       
    92 
       
    93 templateBottomRightImage
       
    94     TemplateBottomRight isNil ifTrue:[
       
    95         TemplateBottomRight := self templateTopRightImage rotated:90
       
    96     ].    
       
    97     ^ TemplateBottomRight
       
    98 
       
    99     "
       
   100      self templateBottomRightImage
       
   101     "
       
   102 !
       
   103 
       
   104 templateTopLeftImage    
       
   105     TemplateTopLeft isNil ifTrue:[
       
   106         TemplateTopLeft := self topLeftImageUnfilledMasked4
       
   107     ].    
       
   108     ^ TemplateTopLeft
       
   109 
       
   110     "
       
   111      TemplateTopLeft := TemplateTopRight := nil.
       
   112      TemplateBottomLeft := TemplateBottomRight := nil.
       
   113     "
       
   114 !
       
   115 
       
   116 templateTopRightImage
       
   117     TemplateTopRight isNil ifTrue:[
       
   118         TemplateTopRight := self templateTopLeftImage rotated:90
       
   119     ].    
       
   120     ^ TemplateTopRight
       
   121 
       
   122     "
       
   123      self templateTopRightImage
       
   124     "
       
   125 !
       
   126 
       
   127 topLeftImageUnfilledMasked
       
   128     "This resource specification was automatically generated
       
   129      by the ImageEditor of ST/X."
       
   130 
       
   131     "Do not manually edit this!! If it is corrupted,
       
   132      the ImageEditor may not be able to read the specification."
       
   133 
       
   134     "
       
   135      self topLeftImageUnfilledMasked inspect
       
   136      ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked
       
   137      Icon flushCachedIcons
       
   138     "
       
   139 
       
   140     <resource: #image>
       
   141 
       
   142     ^Icon
       
   143         constantNamed:'RoundedBorder topLeftImageUnfilledMasked'
       
   144         ifAbsentPut:[(Depth1Image width:4 height:4) bits:(ByteArray fromPackedString:'@@@@@@@a') colorMapFromArray:#[0 0 0] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'8LB@@@@a'); yourself); yourself]
       
   145 !
       
   146 
       
   147 topLeftImageUnfilledMasked2
       
   148     "This resource specification was automatically generated
       
   149      by the ImageEditor of ST/X."
       
   150 
       
   151     "Do not manually edit this!! If it is corrupted,
       
   152      the ImageEditor may not be able to read the specification."
       
   153 
       
   154     "
       
   155      self topLeftImageUnfilledMasked2 inspect
       
   156      ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked2
       
   157      Icon flushCachedIcons
       
   158     "
       
   159 
       
   160     <resource: #image>
       
   161 
       
   162     ^Icon
       
   163         constantNamed:'RoundedBorder topLeftImageUnfilledMasked2'
       
   164         ifAbsentPut:[(Depth1Image width:4 height:4) bits:(ByteArray fromPackedString:'@@@@@@@a') colorMapFromArray:#[0 0 0] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'<LB@ @@a'); yourself); yourself]
       
   165 !
       
   166 
       
   167 topLeftImageUnfilledMasked3
       
   168     "This resource specification was automatically generated
       
   169      by the ImageEditor of ST/X."
       
   170 
       
   171     "Do not manually edit this!! If it is corrupted,
       
   172      the ImageEditor may not be able to read the specification."
       
   173 
       
   174     "
       
   175      self topLeftImageUnfilledMasked3 inspect
       
   176      ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked3
       
   177      Icon flushCachedIcons
       
   178     "
       
   179 
       
   180     <resource: #image>
       
   181 
       
   182     ^Icon
       
   183         constantNamed:'RoundedBorder topLeftImageUnfilledMasked3'
       
   184         ifAbsentPut:[(Depth1Image width:4 height:4) bits:(ByteArray fromPackedString:'DFA@ @@a') colorMapFromArray:#[0 0 0 127 127 127] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'<NC@ @@a'); yourself); yourself]
       
   185 !
       
   186 
       
   187 topLeftImageUnfilledMasked4
       
   188     "This resource specification was automatically generated
       
   189      by the ImageEditor of ST/X."
       
   190 
       
   191     "Do not manually edit this!! If it is corrupted,
       
   192      the ImageEditor may not be able to read the specification."
       
   193 
       
   194     "
       
   195      self topLeftImageUnfilledMasked4 inspect
       
   196      ImageEditor openOnClass:self andSelector:#topLeftImageUnfilledMasked4
       
   197      Icon flushCachedIcons
       
   198     "
       
   199 
       
   200     <resource: #image>
       
   201 
       
   202     ^Icon
       
   203         constantNamed:'RoundedBorder topLeftImageUnfilledMasked4'
       
   204         ifAbsentPut:[(Depth1Image width:4 height:4) bits:(ByteArray fromPackedString:'LDB@ @@a') colorMapFromArray:#[0 0 0 127 127 127] mask:((ImageMask width:4 height:4) bits:(ByteArray fromPackedString:'<LB@ @@a'); yourself); yourself]
       
   205 ! !
       
   206 
       
   207 !RoundedBorder methodsFor:'displaying'!
       
   208 
       
   209 displayOn:aGC forDisplayBox:aRectangle
       
   210     |imgDim boxLeft boxRight boxTop boxBottom boxWidth boxHeight|
       
   211 
       
   212     color isNil ifTrue:[ ^ self].
       
   213 
       
   214     super displayOn:aGC forDisplayBox:aRectangle.
       
   215 
       
   216     imgTopLeft isNil ifTrue:[
       
   217         self makeImages.
       
   218         imgTopLeft isNil ifTrue:[
       
   219             ^ self
       
   220         ].    
       
   221     ].    
       
   222 
       
   223     imgDim :=4.
       
   224 
       
   225     boxLeft := aRectangle left + width.
       
   226     boxTop := aRectangle top + width.
       
   227     boxWidth := aRectangle width.
       
   228     boxHeight := aRectangle height.
       
   229 
       
   230     boxRight := boxLeft + boxWidth - width - 1.
       
   231     boxBottom := boxTop + boxHeight - width - 1.
       
   232     
       
   233     aGC displayImage:imgTopLeft x:boxLeft y:boxTop.
       
   234     aGC displayImage:imgTopRight x:boxRight-imgDim-imgDim y:boxTop.
       
   235     aGC displayImage:imgBottomRight x:boxRight-imgDim-imgDim y:boxBottom-imgDim-imgDim.
       
   236     aGC displayImage:imgBottomLeft x:boxLeft y:boxBottom-imgDim-imgDim.
       
   237 ! !
       
   238 
       
   239 !RoundedBorder methodsFor:'private'!
       
   240 
       
   241 makeImages
       
   242     |lightColor|
       
   243     
       
   244     imgTopLeft := self class templateTopLeftImage copy.
       
   245     imgTopRight := self class templateTopRightImage copy.
       
   246     imgBottomLeft := self class templateBottomLeftImage copy.
       
   247     imgBottomRight := self class templateBottomRightImage copy.
       
   248 
       
   249     lightColor := color lightened.
       
   250     
       
   251     imgTopLeft colorMap 
       
   252         at:1 put:color; at:2 put:lightColor.
       
   253     imgTopRight colorMap 
       
   254         at:1 put:color; at:2 put:lightColor.
       
   255     imgBottomLeft colorMap 
       
   256         at:1 put:color; at:2 put:lightColor.
       
   257     imgBottomRight colorMap 
       
   258         at:1 put:color; at:2 put:lightColor.
       
   259 ! !
       
   260 
       
   261 !RoundedBorder class methodsFor:'documentation'!
       
   262 
       
   263 version
       
   264     ^ '$Header$'
       
   265 !
       
   266 
       
   267 version_CVS
       
   268     ^ '$Header$'
       
   269 ! !
       
   270