draw a rectangle then draw a line clipped to that rectangle - createjs

Can someone explain the concepts/actions required to do the following:
On my stage I add a myShape then draw a rectangle using the its .graphics. Then I want to draw lines on that rectangle but have them clip automatically to the rectangle i.e. so they don't leak onto the rest of the stage.
It looks as if I could do this using a mask but I am wondering if there is something much simpler I am not understanding.

Related

Draw rectangle on image in Avalonia

Problem : I have an image with zoom and pan attached. I need to draw rectangles over it.
What I have done : I created a Canvas as an overlay over the image and made rectangle the children of canvas. Everything works well with zoom and pan etc but if the user resizes my the window then the added rectangles starts moving from their places because the rectangle position is set with respect to top and left of canvas.
I am thinking of drawing rectangles over the image and overriding the render. Any suggestions how can I achieve it easily?

fill UIBezierPath but keep path clear

Can't find solution for fill closed UIBezierPath with some color and some width, but keep the path line transparent.
[[UIColor clearColor] setStroke] does not work.
What i have:
What i want:
Shared line of two rectangles have same coordinates, that's why i need some shift when i draw them.
If what you are trying to do is erase everything within the thick outline of a path, use CGContextReplacePathWithStrokedPath to convert the stroke to a path. Then fill it with a clear blend mode, thus erasing the drawing along the thick path. Alternatively, just stroke the path, again using a clear blend mode.
In this drawing, the thick yellow ellipse is not stroked or filled yellow; the ellipse is clear, and the yellow is the view behind, seen through the red rectangle. In other words, the ellipse erases an elliptical shape through the red rectangle.
Here's the code that drew the ellipse:
CGContextAddEllipseInRect(con, CGRectMake(100,100,200,50))
CGContextSetLineWidth(con, 10)
CGContextSetBlendMode(con, kCGBlendModeClear)
CGContextReplacePathWithStrokedPath(con)
CGContextFillPath(con)
Or you could do it this way:
CGContextAddEllipseInRect(con, CGRectMake(100,100,200,50))
CGContextSetLineWidth(con, 10)
CGContextSetBlendMode(con, kCGBlendModeClear)
CGContextStrokePath(con)
stroking with [UIColor clearColor] is not the same thing as taking an eraser to the fill you've already done, it is just drawing over it with a pen with transparent ink.
You could make a second path with pathByStrokingPath and then use an EOClip to 'mask' this area from your fill, or you can just stroke your path with whatever backgroundColor is behind...

how to draw UIButton with tint color and rounder from single side only

I wanna draw a UIButton filled with a red tint color or some color else presented by rgb and only the upper edges are rounded.
some people answer me to get an image to do that but every time i want to change it i have to bring new image and replace it, I wanna ask can i do it from code without get an image.
There is no direct way. Only way to achieve this to create a segment control and keep only a single segment in that.
See this post for detailed implementation,
Update:
If you want to round only two corners check Round two corners in UIView or Just two rounded corners? as mentioned in rdurand's comment. Since segment control is a subview of UIView, this should work.
You can draw the rounded corners using NSBezierPath s bezierPathWithRoundedRect:xRadius:yRadius: method. And then draw over it with another bezier path. Or you could just define a custom bezier path using moveToPoint: lineToPoint: and curveToPoint:controlPoint1:controlPoint2:
Take a look at this:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html

cache drawing in a uiview

I have a UIView that allows the user to draw a line (myLine) on the screen. This UIView is directly above another UIView that has several shapes drawn with CGPaths. When the user taps on one of these shapes I need to erase any portion of myLine that is above one of these other shapes as if I was erasing the pixels with an eraser.
What would be the best way to approach this?
I need the light blue part of the line to be erased leaving the dark blue portion
1) (current approach partially works) I'm able to use the path shape from the bottom view as a mask in the top view but it is only masking the UIView. If I later need to change the mask location the vector strokes are still there. (I know this is because all off my lines are being redrawn in the drawrect of the view)
2) After I draw each line should I somehow cache the drawing as an image and THEN
slice out the parts inside the triangle?
3)Is there a better approach to this?
This link provided the answer:
Building a Simple Drawing App
I cache the drawing to a bitmap context and then clip out
the unneeded parts of the bitmap.

Difference between stroke and fill?

What's the difference between Stroke and Fill drawing in graphics context (iPhone SDK)
Stroke is line drawing, Fill is "colouring in" (for want of a better term).
So in the case of a shape (like a circle), the stroke is the border (circumference) and the fill is the body (interior).
Stroke only draws stuff on the border of the path.
Fill only draws stuff in the interior of the path.