forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to create a zoom of a graphics region?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Fri Jun 04, 2010 4:00 am    Post subject: How to create a zoom of a graphics region? Reply with quote

I am trying to implement some kind of zooming in a program that displays either a bitmap or a curve on a graphics window (%gr). For this purpose I use the mouse facilities and draw a rectangle in the graphics windows with handle=1 using:

IF(IsUp.AND.WasDown)THEN
grey=RGB@(170,170,170)
CALL get_graphics_selected_area@(x1,y1,x2,y2)
CALL set_graphics_selection@(0)
IF(AND(flags,MK_SHIFT).EQ.MK_SHIFT)THEN
CALL draw_rectangle@(x1,y1,x2,y2,grey)

This code draws a rectangle in window 1 and (I presume) gives me the coordinates of the subregion I want to display in a second window as a zoom. For this purpose, I call afterwards a subroutine that creates a new graphics window with handle 2 and the same vres and hres dimensions of window 1:

subroutine make_zoom(xz1,yz1,xz2,yz2)
use mswin
use my_data
implicit none
integer*4 :: xz1,yz1,xz2,yz2
ans=winio@('%ca[Zoom]&')
ans=winio@('%`gr[rgb_colours]&',hres,vres,5)
call copy_graphics_region@(5,0,0,hres,vres,1,xz1,yz1,xz2,yz2,srccopy)
ans=winio@('%ff%cn%bt[OK]')
end subroutine make_zoom

I expected as a result that the small portion of window 1 would be displayed (and stretched) on the window 2. However, what I get in window 2 is a copy of part of window 1 greater than that enclosed by the rectangle draw in window 1, i.e. it seems that the xz1,xz2,yz1,yz2 are not taken into account when the operation of copying the graphic region is made. I do not know if I was clear enough.....or my text results a little intricate...Am I doing, perhaps, a silly mistake in my code?

Agustin
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Fri Jun 04, 2010 10:00 am    Post subject: Reply with quote

I have a similar feature, which I call a porthole.
I can select a region of the plot and then redraw that region in another part of the screen, with a zoom factor of about 3 to 8 times. With %gr and full_mouse_input this can be done dynamically, so as you move the mouse, the porthole is being continually updated.
A couple of tips,
I show a box where the mouse is, to indicate what is being viewed, with the contents of this box being coupled to a virtual screen, so the full screen is not updated.
The contents of the porthole must be redrawn. If you do not do this, then the precision of the graphics in the porthole does not work.
I test how far the mouse has moved, so that I don't redraw too frequently for a mouse move. Mouse clicks force a draw.
It is good as it allows you to check a detailed graphics.
I also have the reverse when I blow up the full picture. The porthole becomes the full picture and by clicking in the porthole, I update the full screen with a zoom factor of say 3-8. My monitoring where the mouse is, I can drag the blow-up box over the view indicator in the "porthole" section of the screen.
Both approaches work well when there is a lot of detail on the screen, which can be hidden by a 1400 x 1000 pixel screen.
They do rely on having a redraw facility which is called many times. You must specify a window on the screen to clip the view you have defined, ie call update view for selected window.

John
Back to top
View user's profile Send private message
aebolzan



Joined: 06 Jul 2007
Posts: 229
Location: La Plata, Argentina

PostPosted: Fri Jun 04, 2010 12:56 pm    Post subject: Reply with quote

John,

let me see if I follow you correctly: you create a graphics window and a square whose frame moves on that window as the cursor of the mouse moves on. On the graphics window you create a second window on demand (a child window?). As you move the frame, the content of the frame (i.e. the part of the plot or image) is copied to a virtual screen and then copied to the "child" window. Am I right? If I am, let me put some queries:

1.- from my poor knowledge of the FNT95 subroutines, I cannot get how you can create a "moving" frame.
2.- in my code I do not use the virtual screen (well, I did at the very begining but then I wonder why using that if eventually I was copying the virtual to the second screen, so I thought it was unnecessary, as I can directly copy from one to the other...), but the result is not a blow up of a small portion of the first screen as I woudl expect as I take, say, 50x40 pixels and copy to a region of, say, 400x300 pixels. But maybe I am missing sometihing about the importance of virtual screens....

If you can clarify me these points, I would be very grateful...

Best regards,

Agustin
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Jun 04, 2010 10:15 pm    Post subject: Reply with quote

Agustin,

I don't often do a zoomed graphic, but there are two ways that I have used. In method 1, the zoomed image is in the main graphics window (many Windows apps do this). I have a redraw routine. This has access to all the database of coordinates etc. for the things I am drawing. When I draw an unzoomed picture, I compute the centre of the coordinates in the picture and a scale factor, and make sure the centre of the graphics area and the centre of the picture coincide. To draw the picture zoomed in, I store the old scale factor and centre coordinates, load instead the zoomed scale factor and the centre coordinates of the "zoom area", and just re-plot. The parts of the image that fall outside the boundaries of the %gr area don't cause any problems, they just don't appear. Un-zooming is a matter of reloading the original scale factor and centre coords, then re-plotting.

Method 2, which I think John is advocating, is to leave the original graphic well alone, but to create another window with a graphics region, and draw the zoomed image in that. The zoomed region can have its own callback function to handle mouse interaction. Again, you don't need to worry about clipping your image yourself. If you want to show on the original graphic the extent of the zoomed area, you will need to work out what it is (especially if the "porthole" window graphic has a pivot so it can be rescaled). You then draw the bounding box for the size and shape of the zoomed area on the original graphics area. My images are so simple (or maybe I have fast computers) so that I can redraw everything from a blank white screen each time. However, there is a trick which is to draw the bounding box in XOR mode. Then, if you want to take only the box away, you draw it a second time (still in XOR mode), and that removes it. Then, you draw it afresh to its new size and position. Always draw things you want to put on and take off in XOR mode. To set or unset this mode you use the subroutine GRAPHICS_WRITE_MODE@ (MODE). MODE=3 sets XOR mode. Remember to revert to a more conventional mode (REPLACE) for your ordinary writing.

Apologies that this is complex - it's easier to do than to explain.

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sat Jun 05, 2010 2:30 am    Post subject: Reply with quote

I have a single %gr window.
For the porthole, I first draw the full window, for the image I have selected. It may be the full picture or even zoomed.
When I select the porthole option, I then monitor the mouse moving over the screen and as it does, I redraw the image near the mouse, zoomed by a further x8 in a pre selected rectangular box, which is about 1/4 x 1/4 of the full window size. This redraw is then clipped into this smaller window (rectangular box) in the same %gr window, by clearing the box and updating the graphics in that area ( by call Redraw_Image). I only have one %gr window, typically the full screen. You could even centre the location of this rectangle over where the mouse is.
All the options of porthole zoom factor, location and relative size to the full screen are selectable in a menu option.
By moving the mouse, it allows to quickly inspect the often detailed image more closely. The dynamic provides for easy review and I find it effective.

I also have the reverse, where I use a smaller locator box, now about 1/8 x 1/8 of screen in the bottom left, which has the full image. I select a blow-up factor for the screen view, say 10 times, which defines a smaller square that I can drag around in this bottom left locator view, and when it is in a position I like, I click and this updates the full screen for this selected location. I use a small virtual screen to store what I overwrite in the small square. It only works when the mouse is over the locator box.

I think I'm overselling my approach here ! Simply, these are ways I have of quickly moving around a very detailed full image, that I have found easy to implement. They rely on having a subroutine redraw_image, which draws to a nominated zoom within a nominated rectangle on the screen. I try to minimise how often I update the screen. This works well for the images I have, mainly terrain survey data and FEM results.
Other graphics packages have more sophistocated blowup features, but mine only use monitoring the mouse movement.
An alternative I have considered, but not programmed is to select a large virtual screen, which is say 10 times as big as the %gr screen, draw this once, then simply copy the bit you want onto the %gr screen, with a mouse/wheel selection method that works for you to change the view location.
Some Ideas that may help !
John
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Jun 05, 2010 6:23 pm    Post subject: Reply with quote

Well, I clearly didn't understand what John was recommending, as he does both things I described - probably better than I do.

A further issue is whether to move the zoomed in window with the scroll bars or with a "grabber hand". I'm sure I wrote a post on cursors other than the few standard ones in FTN95.chm, but I can't find it. However, the standard cursor names (e.g. CURSOR_ARROW) are just integers, and a little bit of exploration with different numbers shows there are a lot of others to choose from.

Another source for cursors is the folder (C:\Windows\Cursors on my PC). I see that some of those are .ANI (animated) not just .CUR. (not in FTN95.chm, but in CWPLUS.ENH).

The mechanism for dynamically changing cursors is a bit byzantine in its complexity!

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group