GradientBackground.st
author Claus Gittinger <cg@exept.de>
Wed, 02 Feb 2011 12:17:04 +0100
changeset 5703 b2982d12a3ad
parent 5692 3187401537b7
child 5705 56318de85b68
permissions -rw-r--r--
changed: #height: #width:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5461
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2009 by eXept Software AG
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libview' }"
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
AbstractBackground subclass:#GradientBackground
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'color1 color2 direction'
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Graphics-Support'
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!GradientBackground class methodsFor:'documentation'!
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 2009 by eXept Software AG
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
              All Rights Reserved
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
! !
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    37
!GradientBackground methodsFor:'accessing'!
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    38
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    39
color1
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    40
    ^ color1
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    41
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    42
    "Created: / 23-01-2011 / 02:01:29 / cg"
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    43
!
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    44
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    45
color1:aColor
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    46
    color1 := aColor.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    47
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    48
    "Created: / 23-01-2011 / 02:01:50 / cg"
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    49
!
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    50
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    51
color2
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    52
    ^ color2
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    53
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    54
    "Created: / 23-01-2011 / 02:01:32 / cg"
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    55
!
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    56
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    57
color2:aColor
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    58
    color2 := aColor.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    59
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    60
    "Created: / 23-01-2011 / 02:01:55 / cg"
5688
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    61
!
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    62
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    63
direction
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    64
    "possible values:
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    65
        #northSouth
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    66
        #eastWest
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    67
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    68
     others are not yet supported
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    69
    "
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    70
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    71
    ^ direction
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    72
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    73
    "Modified: / 23-01-2011 / 14:36:36 / cg"
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    74
!
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    75
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    76
direction:something
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    77
    "possible values:
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    78
        #northSouth
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    79
        #eastWest
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    80
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    81
     others are not yet supported
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    82
    "
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    83
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    84
    direction := something.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    85
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    86
    "Modified: / 23-01-2011 / 14:36:44 / cg"
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    87
! !
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    88
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    89
!GradientBackground methodsFor:'drawing'!
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    90
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    91
fillRectangleX:x y:y width:w height:h in:aView
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    92
    "this is a first (very inefficient) try"
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    93
5688
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    94
    |hAll wAll r1 r2 g1 g2 b1 b2 dR r dG g dB b 
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    95
     xRight yBot rC gC bC lastR lastG lastB|
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    96
5688
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    97
    "/ always take the full-screen as reference
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    98
    "/ (so we do not have to care for changed gradient, when view changes size)
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
    99
    hAll := Display height. "/ aView height.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   100
    wAll := Display width.  "/ aView width.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   101
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   102
    r1 := color1 redByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   103
    r2 := color2 redByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   104
    g1 := color1 greenByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   105
    g2 := color2 greenByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   106
    b1 := color1 blueByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   107
    b2 := color2 blueByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   108
5688
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   109
    "/ individual lines; from top to bottom
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   110
    (direction == #northSouth or:[direction == #vertical]) ifTrue:[
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
   111
        dR := (r2 - r1) / hAll.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   112
        r := r1 + (dR * y).
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
   113
        dG := (g2 - g1) / hAll.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   114
        g := g1 + (dG * y).
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
   115
        dB := (b2 - b1) / hAll.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   116
        b := b1 + (dB * y).
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   117
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   118
        xRight := x+w-1.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   119
        0 to:h-1 do:[:yP |
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   120
            rC := r asInteger.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   121
            gC := g asInteger.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   122
            bC := b asInteger.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   123
            (rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   124
                aView foreground:(Color redByte:rC greenByte:gC blueByte:bC).
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   125
                lastR := rC. lastG := gC. lastB := bC.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   126
            ].
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   127
            aView displayLineFromX:x y:y+yP toX:xRight y:y+yP.
5692
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   128
            r := (r + dR) min:r2.
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   129
            g := (g + dG) min:g2.
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   130
            b := (b + dB) min:b2.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   131
        ].
5688
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   132
        ^ self.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   133
    ].
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   134
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   135
    "/ individual lines; from left to right
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   136
    (direction == #eastWest or:[direction == #horizontal]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   137
        dR := (r2 - r1) / wAll.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   138
        r := r1 + (dR * y).
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   139
        dG := (g2 - g1) / wAll.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   140
        g := g1 + (dG * y).
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   141
        dB := (b2 - b1) / wAll.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   142
        b := b1 + (dB * y).
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   143
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   144
        yBot := y+h-1.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   145
        0 to:w-1 do:[:xP |
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   146
            rC := r asInteger.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   147
            gC := g asInteger.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   148
            bC := b asInteger.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   149
            (rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   150
                aView foreground:(Color redByte:rC greenByte:gC blueByte:bC).
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   151
                lastR := rC. lastG := gC. lastB := bC.
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   152
            ].
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   153
            aView displayLineFromX:x+xP y:y toX:x+xP y:yBot.
5692
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   154
            r := (r + dR) min:r2.
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   155
            g := (g + dG) min:g2.
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   156
            b := (b + dB) min:b2.
5688
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   157
        ].
Claus Gittinger <cg@exept.de>
parents: 5687
diff changeset
   158
        ^ self.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   159
    ]
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   160
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   161
    "Created: / 23-01-2011 / 01:59:29 / cg"
5692
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   162
    "Modified: / 31-01-2011 / 17:28:53 / cg"
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   163
! !
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   164
5461
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
!GradientBackground class methodsFor:'documentation'!
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
version_CVS
5692
3187401537b7 changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5688
diff changeset
   168
    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.5 2011-01-31 16:29:00 cg Exp $'
5461
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
! !