Trying to define a clipping region

Trying to define a clipping region

Post by Andre Rat » Mon, 05 Apr 1999 05:00:00



I have, more or less, been struggling with this problem since
I first began programming with Delphi, back in 1996.

In Turbo Pascal for DOS, there was a SetViewPort procedure
that allowed us to define a plotting region outside of which
lines would be clipped off. No such thing seems to exist in
Delphi (ClipRect is a read-only property).

The way I have managed to circumvent this was to put two TImage
objects, one on top of the other:
   - an underlying GraphImage which will hold the complete graph
     (with titles, border, tick box, labels, axes, together with
     the plot itself inside the viewport)
   - a transparent overlying, but smaller, MathImage which will
     hold only the plot inside the viewport.
The graphical elements inside MathImage will always be directly
superposed to their copy on the GraphImage.

Producing a graph usually involves:
   - drawing a border or a tick box or just axes and writing
     titles and labels on the GraphImage
   - plotting the graph on the MathImage and, at the end of the
     process, copying the result on the underlying GraphImage
   - printing or saving the GraphImage to disk.

This works fine, except for a few problems:
  a) issuing a MathImage.Update command produces flicker. This
     is solely because of the underlying GraphImage, otherwise
     it would not happen. Just hiding the GraphImage is even
     enough to eliminate the flicker.
  b) I have not found a way to put into a single component the
     two TImage objects and their associated procedures. In
     fact, I strongly suspect that this cannot be done unless
     both are placed in a single container like a Panel.
  c) a small experiment I have done showed that plotting on a
     PaintBox would be about two times faster than plotting
     on an Image. I nevertheless prefer working with images
     since, contrary to a PaintBox, an Image covered by a
     window will automatically redraw itself. This is a nice
     feature especially when working with complex graphs.

Since I already have a few thousand lines of code referring to
GraphImage and MathImage, the best thing for me would be to
work with a single Image (this would be my GraphImage) and a
sub-region of it which could be referred to as my MathImage.
Is there a way to do this?

I would also appreciate any other suggestion. The graph units
I am working on will be used for most of my major projects so
I would really like to have a firm basis.

        Andre

 
 
 

Trying to define a clipping region

Post by Dave Peter » Mon, 05 Apr 1999 05:00:00




Quote:>In Turbo Pascal for DOS, there was a SetViewPort procedure
>that allowed us to define a plotting region outside of which
>lines would be clipped off. No such thing seems to exist in
>Delphi (ClipRect is a read-only property).

Try the following:

 { var points:array[0..3] of tpoint;  }
 { var argn:hrgn;  }
 { set up the points array for the corners of the clip region you want }

{ to set the clipping region }

    argn:=createpolygonrgn(points,4,alternate);
    selectcliprgn(myform.mypaintbox.canvas.handle,argn);

{and to reset to normal }

    selectcliprgn(myform.mypaintbox.canvas.handle,0);

{ When you fnish, you must dispose of the region object }

    deleteobject(argn);

Regards

--
Dave Peters
DP Software
Cross Stitch Professional for Windows
www.dpsoftware.co.uk

 
 
 

Trying to define a clipping region

Post by Andre Rat » Tue, 06 Apr 1999 04:00:00


Thanks. I wonder why something as important as this is not
mentioned in Chapter 21 of the User's Guide.

I have implemented these commands in a little program but
the results I get are a bit weird:
  - the position of the clipping region inside the PaintBox
    depends on where I placed the PaintBox on the Form. Is it
    possible that the corners of the clipping region are
    defined with respect to the Form instead of the PaintBox
    itself?
  - once the clipping region has been defined, the pixel
    coordinates still refer to the original PaintBox and not
    to the new clipping region. (By contrast, with the
    SetViewPort of Turbo Pascal for DOS, the coordinates were
    relative to the viewport.)

I am certainly missing something (or there is a stupid bug in my
program). Where can I find more info onthis? (The Help on
Microsoft Windows Pen API didn't help.)

        Andre

 
 
 

Trying to define a clipping region

Post by Dave Peter » Thu, 08 Apr 1999 04:00:00




Quote:>  - once the clipping region has been defined, the pixel
>    coordinates still refer to the original PaintBox and not
>    to the new clipping region.

Yes, it will do.  It is just a mask and does not affect the coordinates
for drawing.

You may well find the origin is the form origin - my code always has the
paintbox at the form origin. Maybe someone else with more knowledge can
confirm that.
--
Dave Peters

 
 
 

1. how to copy a Picturebox region define by SetWindowRgn

Hi there,

Can anyone tell me how I can copy a Picturebox (visible=false)  region
that was define by SetWindowRgn to another PictureBox(visible=true).

I have tried using PaintPicture but it copies the entire picture
instead of only the region shown by SetWindowRgn.

I am using VB5.

Any help or suggestions much appreciated.

Replies here or by email are both fine.

Don


2. Polygon Containment Algorithms? (erosion/Minkowski difference)

3. define a rectangular region on screen

4. Custom Creations has Moved!

5. defining a pattern - or trying to ?

6. Snapshot from IndyCam to GIF

7. objects defined outside clipping volume causing CRASH...

8. Trax clips/vanishing animation

9. Clip region

10. Moving origin and clip region

11. Region/Shape clipping/intersection...

12. Compound edge voronoi region exclusion in V-Clip

13. Complex clipping regions