CreatePolygonRgn in Xojo

I’m trying to recreate an CAD application that I wrote years ago in Delphi for Windows. I want to duplicate it’s capabilities in Mac OSx. One thing I’m stuck on is a routine to draw a pattern on a rectangle and use the Windows CreatePolygonRgn API to create a pattern cropped to the polygonal shape.
So there would be a polygon shape with bricks or siding within those boundaries.

Does anyone have any idea how we could do such a thing in Xojo?

TIA

One way to do it is to create an offscreen picture

  1. create a picture object large enough to hold your polygon
  2. in the MASK draw a FILLED polygon in all black including the border
  3. make the reset of the MASK all WHITE
  4. using DRAWPICTURE… place your “pattern” as tiles in the PICTURE object
  5. draw your BORDER in the picture object in your border color
  6. set the TRANSPARENT=1 on this picture object
  7. using DRAWPICTURE paste it on to you main image

Sounds complex… but it really isn’t… and is the technique I use in my PAINTDS program

You have given me hope. It’s a new concept to me, though.
Can you point me to some source of information on how to make a mask and combine it with a picture? Are we talking about two pictures?

I searched in the Language Reference for “Mask” and looked in the sample programs, but can’t find much.

Give me a few days (due to the holiday) and I will see if I can throw a sample together based on the code I wrote for my Paint program

Ok… I looked at my code this morning… and what I stated above is not how I do it… it is actually simpler :slight_smile:

but since the actual code is too tightly integrated into my project to extract easily… here are the steps

  1. Draw your shape (any shape, rect, oval, polygon) as FILLED with a color that you would NEVER use (I selected &c010101)
  2. find the RECTANGLE that bounds your shape (min(x), min(y), max(x), max(y))
  3. create another picture object the same size (p=new picture(max(x)-min(x),max(y)-min(y),32)
  4. tile your pattern across that rectangle (rectangle pattern fills are super easy)
  5. create an RGBSurface of your pattern (rgbPAT)
  6. using RGBSurface (rgbA), scan that rectangle
  7. when you find a pixel of your fake fill color, replace with a pixel from the pattern
  8. finally draw your border using the normal built in function depending on the shape you used.

PSEUDO-CODE

      for y=y1 to y2
         for x=x1 to x2
            if rgbA.pixel(x,y)=&c010101 then rgbA.pixel(x,y)=rgbPat.pixel(x,y)
            end if
     next x1
   next y1

Doesn’t sound like it would be fast… but surprisingly it is very fast.

Right. That looks good in a test program. Thanks.
Will there be a problem with the big rectangular picture overwriting other drawings when it’s put in the main drawing?

No… because the picture that you tiled the pattern into is temporary, and is discarded after the fill
That is the reason for the &c010101 pixel… they are the ONLY ones on your main image that will be changed.

note one drawback is your filled area will alway be opaque… but in 99.9% of the situations that should not be an issue

Hmm. I’m trying to wrap my brain around the concept. Rather than create two new pictures and put the doctored one on the main drawing, I should draw the &c010101 filled pixel polygon directly onto the full drawing and then replace it’s pixels directly? If the main drawing is very large, would it slow things down to scan the large image just to alter a much smaller polygon?

I guess the RGBSurface would be big but we only need to scan and replace the part that has the &c010101 polygon?

You are not putting a doctored picture on the main one.
You do draw the &c010101 polygon directly on the full drawing and replace the pixels based on your pattern

The size of the pattern picture does not exceed the size of the polygon area… it does not need to be the same size as your main picture… As a matter of fact if you are filling with Hatch Patterns or something like that… you only need enough of a tile to represent the repeating parts of the pattern… Of course that means the above code gets a bit more complex… but not overly so.
As a matter of fact… I use 32x32 bit pattern tiles… then it is just a matter of using (x and &H1f) on the pattern pic to return the right pixel.

Right. I thank you for putting me on this track. It is working on my tests. The pixel replacement is quite fast. The fills are construction stuff. Some such as siding and tiles use repeating patterns. They are vector drawings that have to scale exactly. An 8 x 2 brick needs to be 8x2 no matter the zoom used, so we can’t use bitmaps. We have to draw it every time.
Thanks again. I may be back during implementation, but I think this will work.

No problem that is what this forum is (or should be) all about :slight_smile: