On Wed, 30 Nov 2011, Felipe Monteiro de Carvalho wrote:

Hello,

I am facing a problem with clipping in TFPCustomCanvas because it has
these properties:

   property ClipRect : TRect read GetClipRect write SetClipRect;
   property Clipping : boolean read GetClipping write SetClipping;

Which obviously is not extensible for non-rectangular formats. I
already have written my own extensible and object oriented clipper,
but I'm unsure how to properly integrate it into TFPCustomCanvas. To
diminish code duplication and to allow fpvectorial to use
TFPCustomCanvas it would be good if TFPCustomCanvas and it's
descendents are at least aware that someone might use a different kind
of Clipping.

So I am thinking of adding these properties in TFPCustomCanvas:
 property ClipRegion: TObject read GetClipRegion write SetClipRegion;
 property RegionClipping: Boolean read GetRegionClipping write
SetRegionClipping;

So TFPCustomCanvas would be aware that we are can have an extended
clipping, although it by itself does not know how to process it. Here
I see 2 options of how to interprete the 2 clipping systems:
1> Make them independent, so if you set both Clipping and
RegionClipping you might get 2 clippings done o.O
2> Make them dependent, so RegionClipping only sets if ClipRect or
ClipRegion should be used. Instead of checking for Clipping it would
check for (Clipping and not RegionClipping) to apply the ClipRect

The generic object TObject is utilized here for ClipRegion because
TCanvas and TLazCanvas will use different regions, which match only in
LCL-CustomDrawn.

what do you think?

Good basics.

What about the following:

Create TBaseClipRegion with abstract method PointIsInRegion(P : TPoint)
(and maybe some others, like line intersections or so).

Create a descendent TRectClipRegion with property ClipRect: TRect.
It can implement the abstract method(s).

Then implement the ClipRegion property, as you propose.

Setting the ClipRect property just sets ClipRegion to a TRectClipRegion instance with the Rect filled in. (TFPCustomCanvas should own this instance, i.e.
destroy when canvas is destroyed)

Property clipping just determines whether the ClipRegion object is used, yes or no.

Seems pretty straightforward to me, backwards compatible, and only a single
extra property is introduced (ClipRegion).

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to