GradientBackground.st
author Claus Gittinger <cg@exept.de>
Sun, 23 Jan 2011 12:53:48 +0100
changeset 5687 d4ab14b6cf0a
parent 5684 c6029a2cf7c0
child 5688 0fec2a60ad63
permissions -rw-r--r--
changed: #fillRectangleX:y:width:height:in:
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"
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    61
! !
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    62
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    63
!GradientBackground methodsFor:'drawing'!
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    64
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    65
fillRectangleX:x y:y width:w height:h in:aView
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    66
    "this is a first (very inefficient) try"
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    67
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    68
    |hAll r1 r2 g1 g2 b1 b2 dR r dG g dB b xRight rC gC bC lastR lastG lastB|
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    69
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    70
    hAll := 1000. "/ aView height.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    71
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    72
    r1 := color1 redByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    73
    r2 := color2 redByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    74
    g1 := color1 greenByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    75
    g2 := color2 greenByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    76
    b1 := color1 blueByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    77
    b2 := color2 blueByte.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    78
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    79
    direction = #horizontal ifTrue:[
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    80
        self halt
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    81
    ] ifFalse:[
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    82
        dR := (r2 - r1) / hAll.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    83
        r := r1 + (dR * y).
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    84
        dG := (g2 - g1) / hAll.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    85
        g := g1 + (dG * y).
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
    86
        dB := (b2 - b1) / hAll.
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    87
        b := b1 + (dB * y).
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
        xRight := x+w-1.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    90
        0 to:h-1 do:[:yP |
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    91
            rC := r asInteger.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    92
            gC := g asInteger.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    93
            bC := b asInteger.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    94
            (rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    95
                aView foreground:(Color redByte:rC greenByte:gC blueByte:bC).
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    96
                lastR := rC. lastG := gC. lastB := bC.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    97
            ].
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    98
            aView displayLineFromX:x y:y+yP toX:xRight y:y+yP.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
    99
            r := r + dR.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   100
            g := g + dG.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   101
            b := b + dB.
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   102
        ].
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   103
    ]
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   104
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   105
    "Created: / 23-01-2011 / 01:59:29 / cg"
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
   106
    "Modified: / 23-01-2011 / 12:53:36 / cg"
5684
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   107
! !
c6029a2cf7c0 added:8 methods
Claus Gittinger <cg@exept.de>
parents: 5461
diff changeset
   108
5461
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
!GradientBackground class methodsFor:'documentation'!
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
version_CVS
5687
d4ab14b6cf0a changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents: 5684
diff changeset
   112
    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.3 2011-01-23 11:53:48 cg Exp $'
5461
2451688b8d25 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
! !