| View previous topic :: View next topic |
| Author |
Message |
Boo Valued Contributor


Joined: 31 Oct 2003 Posts: 599 Location: Gulf Breeze, Florida USA
|
Posted: Sat Dec 06, 2003 10:41 pm Post subject: Zooming in on an element proportionally (code attached)... |
|
|
Hi All,
I was playing around with some code and figured I would ask you guys for some assistance (no need to reinvent the wheel, eh?).
Anyway, I will attach the aformentioned code below. When you run it, you will notice that you can drag the line element by clicking on it. (We'll call the line element a "ruler" for measuring the shape element.)
Now, what I need to figure out is this... When you move the line element to a new position and then click on the Zoom In button to zoom in, how can I reposition the enlarged line element (ruler) proportionally in relation to the new size of the shape element? (That is, I want an exact, enlarged view of the smaller version.) Also, when the Zoom Out button is clicked, how can I maintain the relative position of the line element to the shape element when the dialog is resized?
Please feel free to modify the code accordingly. I look forward to your feedback...
Thanks,
Keith L.
| Code: |
Title Zoom
%%mode = out
DIALOG CREATE,Zoom,-1,0,683,490
DIALOG ADD,SHAPE,SHAPE1,88,282,378,252,WHITE,BLACK,,RECTANGLE
DIALOG ADD,BUTTON,BUTTON1,443,414,64,24,Zoom In
DIALOG ADD,BUTTON,BUTTON2,442,486,64,24,Zoom Out
DIALOG ADD,LINE,LINE1,204,459,378,11
DIALOG ADD,BITMAP,BITMAP1,204,459,378,11,,This is a ruler!,CLICK,hand
DIALOG SHOW
%%winpos = @winpos(Zoom,TLWH)
parse "%%top1;%%left1;%%width1;%%height1", %%winpos
:Evloop
wait event
goto @event()
:Close
exit
:BITMAP1CLICK
%%posx = @diff(@mousepos(x),@dlgpos(line1,L))
%%posy = @diff(@mousepos(y),@dlgpos(line1,T))
if @equal(%%mode,in)
goto ch4
else
goto ch3
end
:ch3
%x = @diff(@mousepos(X),%%posx)
%y = @diff(@mousepos(Y),%%posy)
if @greater(270,%x)
dialog setpos,line1,%y,282
goto evloop
end
if @greater(85,%y)
dialog setpos,line1,88,%x
goto evloop
end
if @greater(%y,334)
dialog setpos,line1,328,%x
goto evloop
end
if @greater(%x,658)
dialog setpos,line1,%y,658
goto evloop
end
dialog setpos,line1,%y,%x
if @event() @null(@mousedown(L))
goto EVLOOP
end
goto ch3
:ch4
%x = @diff(@mousepos(X),%%posx)
%y = @diff(@mousepos(Y),%%posy)
if @greater(193,%x)
dialog setpos,line1,%y,195
goto evloop
end
if @greater(86,%y)
dialog setpos,line1,88,%x
goto evloop
end
if @greater(%y,397)
dialog setpos,line1,395,%x
goto evloop
end
if @greater(%x,680)
dialog setpos,line1,%y,680
goto evloop
end
dialog setpos,line1,%y,%x
if @event() @null(@mousedown(L))
goto EVLOOP
end
goto ch4
:button1button
%%mode = in
%%screeninfo = @sysinfo(screenrect)
parse "%%screent;%%screenl;%%screenw;%%screenh",%%screeninfo
if @equal(%%screenw %%screenh,800 600)
window position,Zoom,3,43,712,590
end
if @equal(%%screenw %%screenh,1024 768)
window position,Zoom,,,712,590
end
dialog setpos,line1,,,487,16
dialog setpos,bitmap1,,,487,16
dialog setpos,shape1,88,195,487,325
goto evloop
:button2button
%%mode = out
window position,Zoom,%%Top1,%%Left1,%%Width1,%%Height1
dialog setpos,shape1,88,282,378,252
dialog setpos,line1,,,378,11
dialog setpos,bitmap1,,,378,11
goto evloop
end
|
|
|
| Back to top |
|
 |
Boo Valued Contributor


Joined: 31 Oct 2003 Posts: 599 Location: Gulf Breeze, Florida USA
|
Posted: Sun Dec 07, 2003 5:07 am Post subject: Figured it out! (Here is the revised code...) |
|
|
Okay, finally figured it out...
Here is the revised code (changes "remmed" below).
Using this example, the programmer could create (for example) a graphics viewing program with ruler. The user could view the graphic and ruler in two separate sizes (i.e. by zooming in/out). Ruler remains relative to the resized graphic...
Cheers,
Keith L.
| Code: |
Title Zoom
%%mode = out
DIALOG CREATE,Zoom,-1,0,683,490
DIALOG ADD,SHAPE,SHAPE1,88,282,378,252,WHITE,BLACK,,RECTANGLE
DIALOG ADD,BUTTON,BUTTON1,443,414,64,24,Zoom In
DIALOG ADD,BUTTON,BUTTON2,442,486,64,24,Zoom Out
DIALOG ADD,LINE,LINE1,204,459,378,11
DIALOG ADD,BITMAP,BITMAP1,204,459,378,11,,This is a ruler!,CLICK,hand
dialog disable,button2
DIALOG SHOW
%%winpos = @winpos(Zoom,TLWH)
parse "%%top1;%%left1;%%width1;%%height1", %%winpos
:Evloop
wait event
goto @event()
:Close
exit
:BITMAP1CLICK
%%posx = @diff(@mousepos(x),@dlgpos(line1,L))
%%posy = @diff(@mousepos(y),@dlgpos(line1,T))
if @equal(%%mode,in)
goto ch4
else
goto ch3
end
:ch3
%x = @diff(@mousepos(X),%%posx)
%y = @diff(@mousepos(Y),%%posy)
if @greater(270,%x)
dialog setpos,line1,%y,282
goto evloop
end
if @greater(85,%y)
dialog setpos,line1,88,%x
goto evloop
end
if @greater(%y,334)
dialog setpos,line1,328,%x
goto evloop
end
if @greater(%x,658)
dialog setpos,line1,%y,658
goto evloop
end
dialog setpos,line1,%y,%x
if @event() @null(@mousedown(L))
goto EVLOOP
end
goto ch3
:ch4
%x = @diff(@mousepos(X),%%posx)
%y = @diff(@mousepos(Y),%%posy)
if @greater(193,%x)
dialog setpos,line1,%y,195
goto evloop
end
if @greater(86,%y)
dialog setpos,line1,88,%x
goto evloop
end
if @greater(%y,397)
dialog setpos,line1,395,%x
goto evloop
end
if @greater(%x,680)
dialog setpos,line1,%y,680
goto evloop
end
dialog setpos,line1,%y,%x
if @event() @null(@mousedown(L))
goto EVLOOP
end
goto ch4
:button1button
dialog disable,button1
dialog enable,button2
%%mode = in
%%screeninfo = @sysinfo(screenrect)
parse "%%screent;%%screenl;%%screenw;%%screenh",%%screeninfo
if @equal(%%screenw %%screenh,800 600)
window position,Zoom,3,43,712,590
end
if @equal(%%screenw %%screenh,1024 768)
window position,Zoom,,,712,590
end
rem Begin revised code---------------------------------------------------------
%%pos = @dlgpos(line1,TL)
parse "%%tp;%%lft",%%pos
%%tp = @diff(%%tp,8
%%tp2 = @format(@fabs(@fmul(%%tp,1.285)),3.0)
%%lft = @diff(%%lft,282)
%%lft2 = @format(@fabs(@fmul(%%lft,1.285)),3.0)
dialog setpos,line1,@fadd(88,%%tp2),@fadd(195,%%lft2),487,16
dialog setpos,bitmap1,@fadd(88,%%tp2),@fadd(195,%%lft2),487,16
rem End Revised code ----------------------------------------------------------
dialog setpos,shape1,88,195,487,325
goto evloop
:button2button
dialog disable,button2
dialog enable,button1
%%mode = out
window position,Zoom,%%Top1,%%Left1,%%Width1,%%Height1
dialog setpos,shape1,88,282,378,252
rem Begin Revised code -------------------------------------------------------
%%pos = @dlgpos(line1,TL)
parse "%%tp;%%lft",%%pos
%%tp = @diff(%%tp,8
%%tp2 = @format(@fabs(@fdiv(%%tp,1.285)),3.0)
%%lft = @diff(%%lft,195)
%%lft2 = @format(@fabs(@fdiv(%%lft,1.285)),3.0)
dialog setpos,line1,@fadd(88,%%tp2),@fadd(282,%%lft2),378,11
dialog setpos,bitmap1,@fadd(88,%%tp2),@fadd(282,%%lft2),378,11
rem End Revised code ----------------------------------------------------------
goto evloop
end
|
|
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Dec 07, 2003 1:59 pm Post subject: |
|
|
Nice work!
I'll move this to the VDS 5 Source Code Section _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Mon Dec 08, 2003 9:26 am Post subject: |
|
|
indeed...nice work boo
serge _________________
|
|
| Back to top |
|
 |
GeoTrail Valued Contributor


Joined: 18 Feb 2003 Posts: 572 Location: Bergen, Norway
|
Posted: Wed Dec 17, 2003 3:56 am Post subject: |
|
|
Yeah, nice.
Btw, I had to add | Code: | | option decimalsep,. | at the top of the document to avoid getting error. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|