Morph shadows

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

Morph shadows

Chris Muller-4
Would someone point me to the code that renders the shadow drawn when
a Morph is picked up?  My #drawOn: involves bit-blitting a separate
scaled Form onto a particular region of the Display Canvas that comes
into drawOn:.

The shadow made of this form is not tracking properly with the picked
up morph; it slides out further and further wider and lower as I move
down and to the right.

Any advice would be appreciated.

Reply | Threaded
Open this post in threaded view
|

Re: Morph shadows

Andreas.Raab
Chris Muller wrote:

> Would someone point me to the code that renders the shadow drawn when
> a Morph is picked up?  My #drawOn: involves bit-blitting a separate
> scaled Form onto a particular region of the Display Canvas that comes
> into drawOn:.
>
> The shadow made of this form is not tracking properly with the picked
> up morph; it slides out further and further wider and lower as I move
> down and to the right.
>
> Any advice would be appreciated.

Check out Morph>>wantsToBeCachedByHand this may be your problem already
(have it return true to make sure the hand isn't having some undue
assumptions about how to cache that morph). The actual drawing happens
in HandMorph>>updateCacheCanvas: / HandMorph>>shadowForm depending on
whether it uses caching or not.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: Re: Morph shadows

Chris Muller-3
Thanks for your help.  I think I've made progress, but still have not
cracked the nut.  My morph responds false to #wantsToBeCachedByHand,
it has lots of translucent color in it.  Just to reiterate, I'm
blitting a transparent raster image with many translucent data-points
to a *particular size/position* on the Display FormCanvas that comes
into #drawOn:.

Overriding wantsToBeCachedByHand to true did not help, however, if I
change the last line of HandMorph>>#shadowForm to NOT set the #offset:
of the returned (shadow) Form, the shadow does seem to render and
track properly with the drawn morph _as long as_ it's within the
upper-left of the screen (seemingly within the upper-left bounds of
the extent of the Morph).  But the shadow is completely absent when
dragged out to the middle of the screen..

Another clue:  Rotation is not working.  When I rotate, the rendering
of my blitted Form seems to disappear entirely (surely being drawn way
out somewhere else).

I think my problem has something with the Form>>'offset'.  In my
#drawOn:, I tried changing the bit-blit to set MY (scaled) data-form's
#offset to the upper-left of where I normally draw it, and telling it
to draw at 0@0 instead.  Specifically, changed my code FROM:

paintFor: aKmlPainter
        | canvasBounds |
        super paintFor: aKmlPainter.
        aKmlPainter form == form ifFalse:
                [ (aKmlPainter clipRect intersects: (canvasBounds := self
surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:
                        [ (form scaledToSize: (canvasBounds extent))
                                displayOn: aKmlPainter form
                                at: (canvasBounds topLeft)
                                clippingBox: canvasBounds
                                rule: Form blend
                                fillColor: nil ] ]

TO:

paintFor: aKmlPainter
        | canvasBounds |
        super paintFor: aKmlPainter.
        aKmlPainter form == form ifFalse:
                [ (aKmlPainter clipRect intersects: (canvasBounds := self
surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:
                        [ (form scaledToSize: (canvasBounds extent))
offset: canvasBounds topLeft ;      <---------------------------------- added
                                displayOn: aKmlPainter form
                                at: (0@0)    <---------------------------------- changed
                                clippingBox: canvasBounds
                                rule: Form blend
                                fillColor: nil ] ]

I'm sorry, I can't really make out what Form>>#offset is for; I'm not
finding many helpful comments about it.

My other "standard" drawing, lines and polygons, etc., directly onto
the Display FormCanvas is all working fine, including rotation.  It's
just this part that is bit-blitted onto the Display FormCanvas..

Thank you,
  Chris


On Tue, Dec 8, 2009 at 5:41 PM, Andreas Raab <[hidden email]> wrote:

> Chris Muller wrote:
>>
>> Would someone point me to the code that renders the shadow drawn when
>> a Morph is picked up?  My #drawOn: involves bit-blitting a separate
>> scaled Form onto a particular region of the Display Canvas that comes
>> into drawOn:.
>>
>> The shadow made of this form is not tracking properly with the picked
>> up morph; it slides out further and further wider and lower as I move
>> down and to the right.
>>
>> Any advice would be appreciated.
>
> Check out Morph>>wantsToBeCachedByHand this may be your problem already
> (have it return true to make sure the hand isn't having some undue
> assumptions about how to cache that morph). The actual drawing happens in
> HandMorph>>updateCacheCanvas: / HandMorph>>shadowForm depending on whether
> it uses caching or not.
>
> Cheers,
>  - Andreas
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Morph shadows

Andreas.Raab
Chris Muller wrote:

> paintFor: aKmlPainter
> | canvasBounds |
> super paintFor: aKmlPainter.
> aKmlPainter form == form ifFalse:
> [ (aKmlPainter clipRect intersects: (canvasBounds := self
> surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:
> [ (form scaledToSize: (canvasBounds extent))
> displayOn: aKmlPainter form
> at: (canvasBounds topLeft)
> clippingBox: canvasBounds
> rule: Form blend
> fillColor: nil ] ]

I'm missing your morph's drawOn: method. If "aKmlPainter form" in the
above is Display, then yes, that won't work. This really should look
more like the following (assuming that there's a relation between
aKmlPainter and a FormCanvas):

        aKmlPainter form == form ifFalse:
                [ (aKmlPainter clipRect intersects: (canvasBounds := self
surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:[
        "<--- here we go -->"
        aKmlPainter canvasPassedIntoDrawOn "<-- we need this"
                translucentImage: (form scaledToSize: (canvasBounds extent))
                at: (canvasBounds topLeft)].

if you're not using the canvas protocol for performance reasons, you'll
have to add extra code in your Morph's drawOn: method, along the lines of:

Morph>>drawOn: aCanvas

        "check to see if we can operate directly on Display"
        fastPath := (aCanvas isMemberOf: FormCanvas)
                        and:[aCanvas form == Display]
                        and:[aCanvas shadowDrawing not].

        fastPath ifTrue:[
                "fast path - ignore canvas stuff and blit straight to display"
                myForm displayOn: Display at: bounds origin. "etc"
        ] ifFalse:[
                "slow path - not drawing to Display so must use canvas protocol"
                aCanvas drawImage: myForm at: bounds origin. "etc"
        ].

This will work for various other cases (like Morph>>imageForm etc) as well.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: Morph shadows

Chris Muller-4
That got it.  Shadow and rotation are now both working.

Thank you very much..!

On Thu, Dec 10, 2009 at 1:28 PM, Andreas Raab <[hidden email]> wrote:

> Chris Muller wrote:
>>
>> paintFor: aKmlPainter
>>        | canvasBounds |
>>        super paintFor: aKmlPainter.
>>        aKmlPainter form == form ifFalse:
>>                [ (aKmlPainter clipRect intersects: (canvasBounds := self
>> surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:
>>                        [ (form scaledToSize: (canvasBounds extent))
>>                                displayOn: aKmlPainter form
>>                                at: (canvasBounds topLeft)
>>                                clippingBox: canvasBounds
>>                                rule: Form blend
>>                                fillColor: nil ] ]
>
> I'm missing your morph's drawOn: method. If "aKmlPainter form" in the above
> is Display, then yes, that won't work. This really should look more like the
> following (assuming that there's a relation between aKmlPainter and a
> FormCanvas):
>
>        aKmlPainter form == form ifFalse:
>                [ (aKmlPainter clipRect intersects: (canvasBounds := self
> surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:[
>        "<--- here we go -->"
>        aKmlPainter canvasPassedIntoDrawOn "<-- we need this"
>                translucentImage: (form scaledToSize: (canvasBounds extent))
>                at: (canvasBounds topLeft)].
>
> if you're not using the canvas protocol for performance reasons, you'll have
> to add extra code in your Morph's drawOn: method, along the lines of:
>
> Morph>>drawOn: aCanvas
>
>        "check to see if we can operate directly on Display"
>        fastPath := (aCanvas isMemberOf: FormCanvas)
>                        and:[aCanvas form == Display]
>                        and:[aCanvas shadowDrawing not].
>
>        fastPath ifTrue:[
>                "fast path - ignore canvas stuff and blit straight to
> display"
>                myForm displayOn: Display at: bounds origin. "etc"
>        ] ifFalse:[
>                "slow path - not drawing to Display so must use canvas
> protocol"
>                aCanvas drawImage: myForm at: bounds origin. "etc"
>        ].
>
> This will work for various other cases (like Morph>>imageForm etc) as well.
>
> Cheers,
>  - Andreas
>

Reply | Threaded
Open this post in threaded view
|

Re: Morph shadows

Ken G. Brown
Don't know if this has any impact for you, but if you grab a rounded corner rectangle from the Objects tab in latest trunk, the shadow incorrectly appears in front of the object when dragging.

Ken G. Brown

At 11:04 AM -0600 12/11/09, Chris Muller apparently wrote:

>That got it.  Shadow and rotation are now both working.
>
>Thank you very much..!
>
>On Thu, Dec 10, 2009 at 1:28 PM, Andreas Raab <[hidden email]> wrote:
>> Chris Muller wrote:
>>>
>>> paintFor: aKmlPainter
>>>        | canvasBounds |
>>>        super paintFor: aKmlPainter.
>>>        aKmlPainter form == form ifFalse:
>>>                [ (aKmlPainter clipRect intersects: (canvasBounds := self
>>> surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:
>>>                        [ (form scaledToSize: (canvasBounds extent))
>>>                                displayOn: aKmlPainter form
>>>                                at: (canvasBounds topLeft)
>>>                                clippingBox: canvasBounds
>>>                                rule: Form blend
>>>                                fillColor: nil ] ]
>>
>> I'm missing your morph's drawOn: method. If "aKmlPainter form" in the above
>> is Display, then yes, that won't work. This really should look more like the
>> following (assuming that there's a relation between aKmlPainter and a
>> FormCanvas):
>>
>>        aKmlPainter form == form ifFalse:
>>                [ (aKmlPainter clipRect intersects: (canvasBounds := self
>> surfaceBounds geoToCanvasFor: aKmlPainter)) ifTrue:[
>>        "<--- here we go -->"
>>        aKmlPainter canvasPassedIntoDrawOn "<-- we need this"
>>                translucentImage: (form scaledToSize: (canvasBounds extent))
>>                at: (canvasBounds topLeft)].
>>
>> if you're not using the canvas protocol for performance reasons, you'll have
>> to add extra code in your Morph's drawOn: method, along the lines of:
>>
>> Morph>>drawOn: aCanvas
>>
>>        "check to see if we can operate directly on Display"
>>        fastPath := (aCanvas isMemberOf: FormCanvas)
>>                        and:[aCanvas form == Display]
>>                        and:[aCanvas shadowDrawing not].
>>
>>        fastPath ifTrue:[
>>                "fast path - ignore canvas stuff and blit straight to
>> display"
>>                myForm displayOn: Display at: bounds origin. "etc"
>>        ] ifFalse:[
>>                "slow path - not drawing to Display so must use canvas
>> protocol"
>>                aCanvas drawImage: myForm at: bounds origin. "etc"
>>        ].
>>
>> This will work for various other cases (like Morph>>imageForm etc) as well.
>>
>> Cheers,
>>  - Andreas
>>


Reply | Threaded
Open this post in threaded view
|

Re: Re: Morph shadows

K. K. Subramaniam
On Friday 11 December 2009 10:51:23 pm Ken G. Brown wrote:
> Don't know if this has any impact for you, but if you grab a rounded corner
>  rectangle from the Objects tab in latest trunk, the shadow incorrectly
>  appears in front of the object when dragging.
This is an optical illusion caused by translucency. Turn up opacity to see the
illusion vanish.

Subbu