VWNC backgrond colors

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

VWNC backgrond colors

Maarten Mostert-2
Hi,

Can anyone indicate me how to obtain the true colorvalue of backgound colors under Wrapper.

This is to adjust custom view elements to the rest of the interface.

Thanks,

Maarten,
Reply | Threaded
Open this post in threaded view
|

Re: VWNC backgrond colors

Andre Schnoor
Maarten Mostert wrote:
Can anyone indicate me how to obtain the true colorvalue of backgound colors under Wrapper.
This is to adjust custom view elements to the rest of the interface.


This can be very tricky, as it is almost impossible to guess which of the nested wrappers actually provides the opaque background property.

You could add a protocoll to the VisualComponent hierarchy and fix any exceptions and special cases in an explorative fashion (that's what I did). The default implementaion is ^self backgroundColor.

Look at some of my code I have attached. You will need to replace ChimeraTabControlComposite with TabControlComposite (probably). Possibly you can ommit the guard clause completely, because that one is specific to my custom Look & Feel.

The message #effectiveBackgroundIn: aRectangle determines, if any visual uses a background color different from the top window default background.

HTH
Andre

<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks®, 7.4.1 of 30. Mai 2006 on 13. April 2007 at 14:59:49</time-stamp>


<methods>
<class-id>Graphics.CompositePart</class-id> <category>visual properties</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: damageRect
        "Answer the effective background color at the given point.
         Answer nil, if the receiver and all of its children does not
         have a particular idea about a color other than the application
         window's normal background."
        | answer |
        components do:[ :each |
                        (answer := each effectiveBackgroundIn: damageRect)
                                notNil ifTrue:[ ^answer ] ].

        ^nil</body>
</methods>

<methods>
<class-id>Graphics.Geometric</class-id> <category>visual properties</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: windowRect
        ^nil</body>
</methods>

<methods>
<class-id>Graphics.GraphicsMedium</class-id> <category>accessing</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: damageRect
        ^nil</body>
</methods>

<methods>
<class-id>UI.ScheduledWindow</class-id> <category>component accessing</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: damageRect
        ^component isNil
                ifTrue:[ self background ]
                ifFalse:[ component effectiveBackgroundIn: damageRect ]</body>
</methods>

<methods>
<class-id>UI.SubCanvas</class-id> <category>visual properties</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: damageRect
        | local |
        (self isPartOf: ChimeraTabControlComposite)
                ifFalse:[ ^nil ].

        local := (self globalPointToLocal: damageRect origin) extent: damageRect extent.
        (self bounds contains: local) ifTrue:[
                        ^SymbolicPaint menuBarBackground ].

        ^nil</body>
</methods>

<methods>
<class-id>Graphics.VisualComponent</class-id> <category>visual properties</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: damageRect
        ^nil</body>
</methods>

<methods>
<class-id>Graphics.Wrapper</class-id> <category>visual properties</category>

<body package="CGN Chimera Look" selector="effectiveBackgroundIn:">effectiveBackgroundIn: damageRect
        ^component effectiveBackgroundIn: damageRect</body>
</methods>

</st-source>

<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks®, 7.4.1 of 30. Mai 2006 on 13. April 2007 at 15:00:41</time-stamp>


<methods>
<class-id>UI.ApplicationWindow</class-id> <category>private</category>

<body package="CGN Chimera Look" selector="isPartOf:">isPartOf: aVisualClass
        "Answer true, if the receiver is embedded below an instance of the argument"
        ^false</body>
</methods>

<methods>
<class-id>Graphics.VisualComponent</class-id> <category>bounds accessing</category>

<body package="CGN Chimera Look" selector="isPartOf:">isPartOf: aVisualClass
        "Answer true, if the receiver is embedded below an instance of the argument"
        ^false</body>
</methods>

<methods>
<class-id>Graphics.VisualPart</class-id> <category>bounds accessing</category>

<body package="CGN Chimera Look" selector="isPartOf:">isPartOf: aVisualClass
        "Answer true, if the receiver is embedded below an instance of the argument"
        ^container isNil
                ifTrue:[ false ]
                ifFalse:[
                        (container isKindOf: aVisualClass)
                                ifTrue:[ true ]
                                ifFalse:[ container isPartOf: aVisualClass ]]</body>
</methods>

</st-source>
Reply | Threaded
Open this post in threaded view
|

RE: VWNC backgrond colors

Steven Kelly
In reply to this post by Maarten Mostert-2

IIRC the only way is to draw with them on a Pixmap. You can create a 1x1 Pixmap, get a graphicsContext on it, set the background to the SymbolicPaint then clear them. Get the Pixmap contents as an Image, and look at the color of the pixel.

 

However, as Andre Schnoor points out, a SymbolicPaint used in a widget will go through a number of translations before it actually gets drawn to the Window, so the color you get may well be different.

 

IIRC there may also be differences because VW ColorValue has greater accuracy than the OS bit depth: ColorValue white may have values of 2r111111111111 but the one from the Image may be 2r111111110000. Drawing with either will produce the same results, but comparisons between them will fail.

 

HTH,

Steve

 

-----Original Message-----
From: Maarten Mostert [mailto:[hidden email]]
Sent: 13. huhtikuuta 2007 15:23
To: vwnc-list
Subject: VWNC backgrond colors

 

Hi,

Can anyone indicate me how to obtain the true colorvalue of backgound colors under Wrapper.

This is to adjust custom view elements to the rest of the interface.

Thanks,

Maarten,