Opened 5 weeks ago

Last modified 5 weeks ago

#19330 new enhancement

missing symmetry in View API to draw Region outline like StrokeRegion() for FillRegion()

Reported by: grexe Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: Kits/Interface Kit Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description (last modified by grexe)

I would like to draw only the outline of a BRegion. The View API only provides FillRegion() but for other forms like Rects or even Polygons it provides variants to only draw the outline via matching Stroke() calls, not so for Regions.

Since there is no way to convert between polygons and regions, this is quite cumbersome and requires manually building a polygon from a point array taken from the region, or draw individual rectangular outlines via StrokeRect(), which is not quite the same if the region is divided e.g. between lines in a TextView.

Change History (4)

comment:1 by grexe, 5 weeks ago

Description: modified (diff)

comment:2 by grexe, 5 weeks ago

I implemented this like so:

BRegion* region; // input
int32 regionRects = region->CountRects();
BPoint points[regionRects * 4];

for (int32 rectNum = 0; rectNum < regionRects; rectNum++) {
    int32 rectPoint = 0;
    BRect rect = region->RectAt(rectNum);

    points[rectPoint++] = rect.LeftTop();
    points[rectPoint++] = rect.RightTop();
    points[rectPoint++] = rect.RightBottom();
    points[rectPoint++] = rect.LeftBottom();
}
BPolygon poly(points, regionRects * 4);
StrokePolygon(&poly);
Last edited 5 weeks ago by grexe (previous) (diff)

comment:3 by waddlesplash, 5 weeks ago

I don't know if it makes much sense to provide this. BRegions may have a very odd arrangement of rectangles, they're more useful as an implementation detail than as a drawing method, I think?

comment:4 by grexe, 5 weeks ago

maybe it's just my use case but in a TextView, e.g. selections are provided as a BRegion and contain contiguous BRects. If you want to do your own highlighting, you might want to just draw the outline.

It would be interesting to see where and how BRegions are used in the API and whether it makes sense to provide the missing function, or if this is really just a special case in my use case.

Nevertheless it wouldn't hurt to provide this as a convenience, feel free to use the (trivial) sample code above as a basis.

Version 0, edited 5 weeks ago by grexe (next)
Note: See TracTickets for help on using tickets.