PDA

View Full Version : rotation of view


thipperudra
04-17-2004, 12:29 AM
Hi Antun,

I have two problem in this code(which i attached this thread),
1. When i mousedown or click on the yellow view it moves upward,it did not drag properly.

2.The yellow view is rotating fine both clcokwise and anticlockwise,but when i want to resize the rotated yellow view by using red and blue square boxes it won't resize correctly.I think in this code for dragging problem occur when i add
'yoffset="${this.height /2}"
xoffset="${this.width / 2}" ' attribute, these two requires for rotation of view at center.Please tell me how to rectify these problems.

Thanks in advance,
Rudresh

antun
04-20-2004, 04:26 PM
Well, I managed to get the rotated view to be drggable correctly, although it took some fairly confusing trigonometry. The default dragstate doesn't work with rotated views:


<canvas debug="true" width="800" height="600">
<debug x="350" y="10" width="400" height="450" />
<class name="topleftresizestate"
extends="state">
<attribute name="xroffset"
value="$once{this.getMouse('x')}" />
<attribute name="initx"
value="$once{this.x}" />
<attribute name="initwidth"
value="$once{this.width}" />
<attribute name="width"
value="${this.initwidth+this.initx -this.immediateParent.getMouse('x')+xroffset}" />
<attribute name="x"
value="${this.immediateParent.getMouse('x') -this.xroffset}" />
<attribute name="yroffset"
value="$once{this.getMouse('y')}" />
<attribute name="inity"
value="$once{this.y}" />
<attribute name="initheight"
value="$once{this.height}" />
<attribute name="height"
value="${this.initheight+this.inity -this.immediateParent.getMouse('y')+yroffset}" />
<attribute name="y"
value="${this.immediateParent.getMouse('y') -this.yroffset}" />
</class>


<class name="rotbox"
extends="view"
width="100"
height="100"></class>


<class name="mydragger" extends="state">
<attribute name="x"
value="${parent.getMouse('x') - this.dragXOffset}" />
<attribute name="y"
value="${parent.getMouse('y') - this.dragYOffset}" />
</class>


<view bgcolor="green" x="10" y="10">
<rotbox id="v1"
bgcolor="yellow"
x="120"
y="120"
yoffset="${this.height /2}"
xoffset="${this.width/ 2}"
clickable="true"
onmouseup="draggable.remove();">

<attribute name="dragXOffset" type="number" value="0" />
<attribute name="dragYOffset" type="number" value="0" />

<method event="onmousedown">
var theta = Math.PI/180 * this.rotation;
this.dragXOffset = (this.getMouse("x")*Math.cos(theta)
- this.getMouse("y")*Math.sin(theta))
- (this.xoffset*Math.cos(theta)
- this.yoffset*Math.sin(theta));
this.dragYOffset = (this.getMouse("x")*Math.sin(theta)
+ this.getMouse("y")*Math.cos(theta))
- (this.yoffset*Math.cos(theta)
+ this.xoffset*Math.sin(theta));

draggable.apply();
</method>
<attribute name="f1"
value="20"
type="number" />
<attribute name="f2"
value="-20"
type="number" />
<resizestate name="rs" />
<topleftresizestate name="trrs" />
<mydragger name="draggable" />
<view name="crb"
align="right"
valign="bottom"
width="7"
height="7"
bgcolor="blue"
onmousedown="parent.rs.apply();"
onmouseup="parent.rs.remove()" />
<view name="crb2"
align="left"
valign="top"
width="7"
height="7"
bgcolor="red"
onmousedown="parent.trrs.apply();"
onmouseup="parent.trrs.remove()" />
</rotbox>
</view>
<button text="clockwise"
y="160">
<method event="onclick">
v1.animate('rotation',v1.f1++,1000,true);
Debug.write("clockwise"+v1.f1);</method>
</button>
<button text="anticlockwise"
x="150"
y="160">
<method event="onclick">
v1.animate('rotation',-v1.f1,1000,true);
Debug.write("anticlockwise"+v1.f1);</method>
</button>
</canvas>


-Antun

thipperudra
04-21-2004, 08:53 PM
Hi Antun,

Thank you very much antun for your kind solution(dragging problem solved). but i asked one more question in my last post
quote:
-----------------------------------------
i want to resize the rotated yellow view by using red and blue square boxes it won't resize correctly.I think in this code for dragging problem occur
----------------------------------------------
but i am facing resizing of yellow view still.Is there any method to resize of rotated view correctly, any idea regarding this problem.

Regards,

-Rudresh

thipperudra
04-25-2004, 08:17 PM
Hi Antun,

I asked one more question(for same code)in my last post
quote:
-----------------------------------------
i want to resize the rotated yellow view by using red and blue square boxes it won't resize correctly.I think in this code for dragging problem occur
----------------------------------------------
but i am facing problem for resizing of yellow view still.Is there any method to resize of rotated view correctly, any idea regarding this problem.

Regards,
-Rudresh

antun
04-25-2004, 09:53 PM
The default resizestate does not work with a rotated view. However it is possible to write your own resize state that works correctly with a rotated view, just like I wrote a dragstate that worked with a rotated view.

-Antun

thipperudra
04-26-2004, 09:45 PM
Hi Antun,

I wrote resize class for rotated view(which i attached), and i tried this code,but i don't get correct resize of rotated view.Please could you rectify this code.

Thanks in advance,

Rudresh

haplo
07-11-2007, 07:16 AM
anything new on this one? anyone found or wrote a resizestate for rotated views?

umass89
01-18-2008, 10:28 AM
Hi,

Bumping - ---

I have view rotation working with view dragging - trying to get resize working with this as well - wondering if anyone has written code to do this...? I shoulda paid more attention in trig...

Thanks!

Steve