How do create a mask and draw on it - delphi

I have 2 rectangles like the image below :
now I want to only draw the part of yellow rectangle (B) that is inside the red rectangle. So i set clipchildreen=True to the rectangle A and I get this :
But it's not good as part of the yellow rectangle outside the red rectangle is still drawed. I want to obtain this :
How Can I do ? Eventually I can draw directly on the canvas but even like this I didn't find a simple way to achieve what I want to do

Here is a solution that might suit you, although I've made some assumptions about what your requirements are, and it's not a particularly straightforward approach. It involves using a rectangle with InnerRound corners to hide part of the yellow square.
For the steps below, I'm assuming that the form is white, the yellow square is 50 x 50, the red square is 150 x 150, the round corners have a radius of 20, and the whole thing is positioned on the form at 100,100.
I've described this as though you are manually positioning all the controls straight onto the form, but if I was doing it I'd add a couple of TLayouts and use Aligns everywhere (with negative margins in the case of the fourth step). And you might do this on a panel or other control instead of directly on the form.
Note that the z-order is important, which is why steps 2 to 5 below should be done in that order.
Set Fill.Kind of the form to Solid.
Place a TRectangle at 100,100. Set both XRadius and YRadius to 20, both Width and Height to 150, Fill.Color to Red and Stroke.Kind to None.
Place a TRectangle at 100,100. Set the Fill.Color to Yellow.
Place a TRectangle at 80,80. Set both XRadius and YRadius to 20, both Height and Width to 20, Fill.Color to White (the Fill.color of the form), Stroke.Kind to None, and CornerType to InnerRound.
Place a TRectangle at 100,100. Set both XRadius and YRadius to 20, both Height and Width to 150, and Fill.Kind to None.
This is the result:

Related

How to draw a horizontal line using prawn/rails on X axis at a specific point

A user can specify a margin-bottom for a page and I want to be able to draw a horizontal line showing where they have placed it. I have defined margin_bottom in my PDF document (A4 size).
All I need to do is add the specified margin to the X axis and draw a line. However, how can I draw this line?
From my knowledge, I could call something like this
stroke_horizontal_line(0, 0 + margin_bottom)
However, this isn't working and I need it to be the full width of the page.
First of all, I think stroke_horizontal_line works a bit different than you think (if I'm understanding what you are trying to do correctly)
stroke_horizontal_line(x1, x2, at: y) Draws a horizontal line from x1 to x2 at the vertical height of y, where y starts at 0 at the bottom of your document (after bottom margin, not at the bottom of the page).
So, I think you are trying to draw a horizontal line across the whole page, at a specific height which is defined by some variable margin_bottom, to accomplish that with stroke_horizontal_line you can do this:
# You can set a stroke color, if you set it to white it is possible that you just
# forgot to set it back to black.
stroke_color 0, 0, 0, 100
# You can also set the line width
line_width 2
# This would draw a horizontal line across the whole page (not over your side margins)
# at the height of margin_bottom + your document bottom margin (measured from the bottom up)
stroke_horizontal_line(0, bounds.width, at: margin_bottom)
You can also use stroke_horizontal_rule, which just draws a horizontal line at you current cursor position, so you would have to place the cursor on the right spot before using that method.
Easy.
stroke_horizontal_line (y), (y), at: (x)
stroke_horizontal_rule
Should do it.

Why does adding an align with centre constraint to a UIImage throw out the radius of corners setting?

I am trying to turn a square image into a circle. I am using this code to do it:
profilePicture2.layer.cornerRadius = profilePicture2.frame.size.height/2
profilePicture2.clipsToBounds = true
It works perfectly, until I try centre the image in the container view by adding a 'Align centre X to superview' constraint. When I add this constraint I simply get very rounded corners instead of a circle.
In fact, it seems to half the value of the corner radius. So if the image has a height of 100, and corner radius should be set to 50, it LOOKS like the radius value is set to 25.
No other constraints have been added to the image.
What is going on here?
You are calling this code (profilePicture2.layer.cornerRadius = profilePicture2.frame.size.height/2) before the image is being resized. You need to do it after the autolayout has finished work. The problem is that the image at the start is (for example) 100 points wide and you set the corner radius to 50 points. And after that autolayout resizes the image to (again, example) 300 points but your corner radius remains 50 points. You just need to update it after autolayout has completed.
Or if you do not want to have an image that big, make sure you put constraints on width and height and just center it the superview.

How I add circle on circle with cutting layer?

I mean that I have custom view with one big circle and one smaller. But how I could cut corner (layer) of a big circle? Background is from parent view, not from custom, which have a clear color.
Icon, name label and label notifications I have been added in my custom view. So, problem still here with two intersecting circles.
I've suggested three approaches in my comments above. Here's a demonstration of one of them. Note that I didn't really do the math or try to approximate your drawing: it's just a demonstration of the principle:
That's actually three circles:
The big central circle (green) at lower left
The larger corner circle, used to "erase" the top right corner of the first circle
The second, smaller corner circle (green) at top left
Here's the code that generated that drawing (ignore the numbers; it's the principle that's important):
CGContextSetFillColorWithColor(con, UIColor.greenColor().CGColor)
CGContextFillEllipseInRect(con, CGRectMake(0,rect.height-130-10,130,130))
CGContextSetFillColorWithColor(con, UIColor.clearColor().CGColor)
CGContextSetBlendMode(con, kCGBlendModeClear) // erase
CGContextFillEllipseInRect(con, CGRectMake(rect.width-65, -5, 70, 70))
CGContextSetFillColorWithColor(con, UIColor.greenColor().CGColor)
CGContextSetBlendMode(con, kCGBlendModeNormal)
CGContextFillEllipseInRect(con, CGRectMake(rect.width-53,3,50,50))

Indesign Bug? Choosing Fancy Corners Reverses Function of Align Stroke Inside/Outside

I think that this might be a bug in InDesign but I thought that it might be handy to know.
Here's how to recreate: Create a rectangle 200px x 200px, with a 4pt stroke. Set Align stroke to INSIDE. Set the top left xy pos of the rectangle to 100px,100px so that you can easily see changes, and leave the Reference Point in the top left. Now when you change stroke widths, everything is fine, and change corner types, everything is fine, EXCEPT the Fancy Corners. So if you choose Fancy Corners, the x/y becomes 96,96 and total width/height changes to 208 x 208 which is incorrect. Now change the Align Stroke to "OUTSIDE", and the x/y changes back to 100,100 and the rectangle size changes back to 200 x 200. Completely backwards, but just for the Fancy Corners.
Please comment if this is an expected response.

How can I avoid overlap of colors if my UIViews border color alpha is less than 1.0?

I have UIView's alpha set at .5, and its border color alpha is .5 as well, they are a similar shade of gray, but it shows up as a thicker gray on the outside. I am guessing this is because the two colors are being mixed together. Is there a way that instead of just adding a border on top, I can add a border that will displace the pixels underneath it?
You're correct, the only way around this would be to place your 0.5 alpha view inside a container view and inset it slightly and add the border to the container.
I decided to post this as an answer rather than a comment:
An alternate approach would be to subclass UIView to add a CALayer that is one pixel bigger than it's view's layer, and has a borderColor and borderWidth as desired. For a one-off you could add code to your view controller that would add a layer to the view through code rather than subclassing UIView. I doubt if a single pixel increase in width would necessitate adjusting the corner radius, unless the view is VERY small. – Duncan C 37 secs ago edit

Resources