Canvas: Transform Width and Height Independently

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

Canvas: Transform Width and Height Independently

Sean P. DeNigris
Administrator
I'm implementing a SimpleImageMorph which squeezes the form into the Morph's inner bounds instead of the weird TransformMorph thing.

As a spike, I wrote:
        | transform scale |
        scale := self innerBounds width / self image width.
        transform := MorphicTransform new setScale: scale.
        aCanvas warpImage: self image transform: transform at: self innerBounds origin

But obviously this only takes the width into account. How would I transform both of the forms dimensions to the corresponding dimension of the morph's inner bounds?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Nicolai Hess
2015-02-20 23:56 GMT+01:00 Sean P. DeNigris <[hidden email]>:
I'm implementing a SimpleImageMorph which squeezes the form into the Morph's
inner bounds instead of the weird TransformMorph thing.

As a spike, I wrote:
        | transform scale |
        scale := self innerBounds width / self image width.
        transform := MorphicTransform new setScale: scale.
        aCanvas warpImage: self image transform: transform at: self innerBounds
origin

But obviously this only takes the width into account. How would I transform
both of the forms dimensions to the corresponding dimension of the morph's
inner bounds?


I think there is no direct support in Canvas API.
You can
create a new Form
warpblt into this form
use the canvas to draw the new form



|f|
f:=Form extent:100@400 depth:32.
(WarpBlt current toForm: f)
sourceForm: PolymorphSystemSettings pharoLogoForm destRect: f boundingBox;
combinationRule: Form paint; cellSize:2; warpBits.
f asMorph openInHand




 


-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Canvas-Transform-Width-and-Height-Independently-tp4806749.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Nicolai Hess
And there is
FormCanvas>>#warpImage:transform:at:sourceRect:cellSize:
this one works with a MatrixTransform2x3 (this may support scaling for x and y).


2015-02-21 0:40 GMT+01:00 Nicolai Hess <[hidden email]>:
2015-02-20 23:56 GMT+01:00 Sean P. DeNigris <[hidden email]>:
I'm implementing a SimpleImageMorph which squeezes the form into the Morph's
inner bounds instead of the weird TransformMorph thing.

As a spike, I wrote:
        | transform scale |
        scale := self innerBounds width / self image width.
        transform := MorphicTransform new setScale: scale.
        aCanvas warpImage: self image transform: transform at: self innerBounds
origin

But obviously this only takes the width into account. How would I transform
both of the forms dimensions to the corresponding dimension of the morph's
inner bounds?


I think there is no direct support in Canvas API.
You can
create a new Form
warpblt into this form
use the canvas to draw the new form



|f|
f:=Form extent:100@400 depth:32.
(WarpBlt current toForm: f)
sourceForm: PolymorphSystemSettings pharoLogoForm destRect: f boundingBox;
combinationRule: Form paint; cellSize:2; warpBits.
f asMorph openInHand




 


-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Canvas-Transform-Width-and-Height-Independently-tp4806749.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Sean P. DeNigris
Administrator
In reply to this post by Nicolai Hess
Nicolai Hess wrote
You can create a new Form... warpblt into this form...
Ah, thanks. That worked. It became:
    drawOn: aCanvas

        | tempForm |
        tempForm := Form extent: self innerBounds extent depth: self image depth.
        (WarpBlt current toForm: tempForm)
                sourceForm: self image destRect: tempForm relativeRectangle;
                combinationRule: Form paint;
                cellSize: 1;
                warpBits.
        aCanvas drawImage: tempForm at: self innerBounds origin
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
That worked
But actually, it was totally unnecessary! MorphicTransform's scaling method arguments were either named (unhelpfully) 's' or (misleadingly) 'aFloat', but apparently, I can just pass aPoint to scale x and y separately :)

So I'm back to the simple version...
drawOn: aCanvas

        | transform widthScale heightScale |
        widthScale := self innerBounds width / self image width.
        heightScale := self innerBounds height / self image height.
        transform := MorphicTransform new withScale: widthScale@heightScale.
        aCanvas warpImage: self image transform: transform at: self innerBounds origin

Thanks for talking me through it! I learned a lot...
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
MorphicTransform's scaling method arguments were either named (unhelpfully) 's' or (misleadingly) 'aFloat'

Issue 14971 MorphicTransform: Better Argument Names
Fix in inbox...
Scale: "s" -> aNumberOrPoint
Angle: "a" -> radians
Offset: a -> aPoint
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Nicolai Hess
In reply to this post by Sean P. DeNigris


2015-02-21 4:50 GMT+01:00 Sean P. DeNigris <[hidden email]>:
Sean P. DeNigris wrote
> That worked

But actually, it was totally unnecessary! MorphicTransform's scaling method
arguments were either named (unhelpfully) 's' or (misleadingly) 'aFloat',
but apparently, I can just pass aPoint to scale x and y separately :)

Good to know!

BTW I found a bug in isPureTranslation:
(MorphicTransform offset:10@10 angle:0 degreesToRadians  scale:1) isPureTranslation -> true
(MorphicTransform offset:10@10 angle:0 degreesToRadians  scale:1@1) isPureTranslation -> false



 

So I'm back to the simple version...
drawOn: aCanvas

        | transform widthScale heightScale |
        widthScale := self innerBounds width / self image width.
        heightScale := self innerBounds height / self image height.
        transform := MorphicTransform new withScale: widthScale@heightScale.
        aCanvas warpImage: self image transform: transform at: self innerBounds
origin

Thanks for talking me through it! I learned a lot...



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Canvas-Transform-Width-and-Height-Independently-tp4806749p4806767.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

stepharo
In reply to this post by Sean P. DeNigris

Le 21/2/15 05:23, Sean P. DeNigris a écrit :
> Sean P. DeNigris wrote
>> MorphicTransform's scaling method arguments were either named
>> (unhelpfully) 's' or (misleadingly) 'aFloat'
>
> Issue 14971 MorphicTransform: Better Argument Names
> Fix in inbox...
> Scale: "s" -> aNumberOrPoint
> Angle: "a" -> radians
> Offset: a -> aPoint

wonderful!

Stef

>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Canvas-Transform-Width-and-Height-Independently-tp4806749p4806771.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

stepharo
In reply to this post by Sean P. DeNigris
Sean
Could you write a little doc on what you learned?
I would love to read it.

Stef
Le 21/2/15 04:50, Sean P. DeNigris a écrit :

> Sean P. DeNigris wrote
>> That worked
> But actually, it was totally unnecessary! MorphicTransform's scaling method
> arguments were either named (unhelpfully) 's' or (misleadingly) 'aFloat',
> but apparently, I can just pass aPoint to scale x and y separately :)
>
> So I'm back to the simple version...
> drawOn: aCanvas
>
> | transform widthScale heightScale |
> widthScale := self innerBounds width / self image width.
> heightScale := self innerBounds height / self image height.
> transform := MorphicTransform new withScale: widthScale@heightScale.
> aCanvas warpImage: self image transform: transform at: self innerBounds
> origin
>
> Thanks for talking me through it! I learned a lot...
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Canvas-Transform-Width-and-Height-Independently-tp4806749p4806767.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

Sean P. DeNigris
Administrator
stepharo wrote
Could you write a little doc on what you learned?
I have to think about it. There were a lot of little ahas, but I don't know how to summarize it... The biggest realization was that "canvases + transforms" is extremely powerful!
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Canvas: Transform Width and Height Independently

stepharo
Just to not think much :)

Take a little svg and try to rotate it and show all the steps you took
and mistakes you made, until you got it right.



Le 27/2/15 01:30, Sean P. DeNigris a écrit :

> stepharo wrote
>> Could you write a little doc on what you learned?
> I have to think about it. There were a lot of little ahas, but I don't know
> how to summarize it... The biggest realization was that "canvases +
> transforms" is extremely powerful!
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Canvas-Transform-Width-and-Height-Independently-tp4806749p4808123.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>