Does Expression Blend have a concept of trim/crop? - xaml

I'm rebuilding the graphic on the left as the graphic on the right in Expression Blend.
The gradient brushes are great for creating reflection effects but how do I now trim the button on the right now so that it cuts off the rest of the reflective circle?
I can rotate, scale, skew, recenter, and flip but I can't find trim or crop.
And when I select both the top and the bottom to do "combine/intersect" all options are greyed out when I select "combine".
Is trimming the way I want to here possible in Expression Blend or I am reaching the limits of what the underlying XAML could represent?
Or is there an easier way to achieve the graphic on the left?
alt text http://tanguay.info/web/external/trimInBlend.png

Have you tried using a clipping path?
http://blogs.msdn.com/expression/archive/2008/01/21/clip-path-editing-and-animating-in-blend-2.aspx

I would apply a gradient on the graphics on the right and make it fade to transparent. That way, no need to crop anything.

Related

How to control matplotlib annotate (arrow more specifically) in terms of size of figure?

I'd like to draw arrows in my plots, iif there is enough size for the arrow to be displayed properly (ie, with arrow and tail in the right position). Is there any way to control this in code?
For a better explanations, here is the problem explained in 3 examples: in this 1st figure, the arrow shouldn't be displayed as the arrow should go from the dotted line to the solid black line, and in this case there is not enough space for a proper visualisation.
When the same image is zoomed, the arrow behaves correctly though:
Here goes a final example, with a figure in its normal size (without zoom) where the arrow behaves correctly and should be drawn.
In conclusion, in case 1 I would like the arrow not to be drawn (not enough space for a correct visualisation) and to be drawn in the other cases.

Shadow inside text on NSTextField/NSTextFieldCel

I've been trying for a day or two to try and get a shadow to draw inside the text of an NSTextField (and making the foreground color transparent, so all you see is a shadow inside the text). I've yet to achieve a desirable and practical result. The only success I had with this was transforming the text into an NSBezerPath, subtracting it from the frame of the NSTextFieldCell and clipping using the setClip method (addClip does not suffice in this case, it leaves the background painted). Unfortunately, converting the text to an NSBezerPath makes the edges of the text look jagged and overly straightened. Is there an efficient and decent way to achieve this using CoreGraphics masks and clipping because I am unable to achieve this.
A very similar effect of what I would be looking for is in the Xcode IDE, if you don't have a debug session open and go to the debugger navigator it says "No Debug Session" in a subclassed NSTextField that draws the text with a shadow inside it. That is pretty nearly what I am after. Any insight on where to start and how to do this would be great.
A paste bin my current code (working, but sub-optimal, & non-working): http://pastebin.com/4pTv8ZWm
Have you played around with the shadow property of NSTextField in IB? You should be able to get pretty close using a slightly offset shadow effect on the text with the right blend of alpha transparency.

Drawing two shadows on text (Core Graphics)

I'm tying to draw two different shadows on some text to create an embossed effect. Here's the portion of my drawInRect where I draw the text with the first shadow (all the variables used are already defined):
CGContextSetShadowWithColor(context, textInnerShadowOffset, textInnerShadowBlurRadius, textInnerShadowColor.CGColor);
[textColor setFill];
[self.text drawInRect:rect withFont:self.font lineBreakMode:self.lineBreakMode alignment:self.textAlignment];
But now I'm faced with the problem of drawing the second shadow. I assume I'll need to change the shadow and draw the text again, but I need to do so without adding another copy of the text.
How can I draw text without really drawing the text itself? Changing the fill color to clearColor doesn't work. I've seen people use clipping masks for this, but AFAICT that will only work for simple shapes, not text.
Alternatively, is there an easier way to draw two shadows on the same text?
Two options, depending on the exact effect you want:
If you want the first, "upper" shadow to also contribute to the second, "lower" shadow underneath it, use a transparency layer.
Set your CGContext's shadow for the "lower" shadow
Create a transparency layer using CGContextBeginTransparencyLayer
Set the context's shadow for the "upper" shadow
Draw your text
End the transparency layer using CGContextEndTransparencyLayer
(Note that transparency layers can be quite expensive. It's best to call CGContextBeginTransparencyLayerWithRect and pass in as small a rect as you can.)
If you want the shadows to be independent -- the only thing that contributes to each shadow is the text -- you'll need to use a trick.
Set up the shadow with an additional large offset, big enough so that you can draw the text outside of the bounds of your context and have the shadow land in the correct place. That way you'll see only the shadow, but not the text.
Figure out what offset is "big enough". It will probably depend on the size of the context you're drawing into (based on your view), and maybe the bounds of the text.
Or, just fudge it: pick an absurdly large value like 5000 pt.
Set up your shadow. Add the big offset to its normal y offset.
Draw the text, offset vertically by the big offset.
Repeat 1-3 for each "lower" shadow, from back to front. Afterwards, draw the text and the "uppermost" shadow last, without the offset.

Draw panel in Cocoa

I have a NSBezierPath, in the shape of a menubar panel.
I'd like to make a header now.
Like this one for example.
But only like 30 pixels from the top.
I can't figure out how I should only get the top part of the NSBezierPath.
This is my first question.
How can I cut off a piece of the NSBezierPath, or how can I make a Union of the NSBezierPath.
Then I want to add a gradient like in the example.
The gradient is clear, but how can I add the glow at the top of it?
I have added a shadow in another app back then, but it seemed a little dirty.
So how can I make a shadow at the top of the NSBezierPath, like in the provided example.
Thanks!
I ended up using PaintCode, which did a pretty good job for me.
This is the result:
To get the 'light' edge at the top of the element you can just draw (i.e. :fill) the NSBezierPath with a vertical offset of e.g. -1 points with a brighter color. Then draw the shape (at y=+1 points) on top of that.
Not sure what you mean by making the header and cutting of bits..

How to create letterpress effect?

I'm looking to implement something like the famous "letterpress" effect in my application. Here's what I'm talking about: (just a quick example made in PShop)
As you can see, it looks like it's pressed into the background. I wonder if it's possible to do something like this on the Mac dynamically. Is there a way? Thanks!
You can do the gradient fill portion of the text using the code I provide in this answer. Check the coordinate space first, because I described that for the iPhone, which has an inverted Y axis when compared to the Mac's normal Quartz coordinates.
The text is first used to create a clipping path, and the gradient is drawn within that path.
As far as the internal shadow, you might be able to draw this after the gradient is drawn by using CGContextSetShadowWithColor() with an appropriate downward offset and black color, then drawing the text again using just the stroke of the text. deanWombourne has some sample code for a similar task in his answer here.
Draw the text with a normal font to create a black and white bitmap of the text.
Draw another image that is is the same size and completely filled with the gray-to-white gradient you have above.
Create a completely white image with the same size as your other images.
Draw your back and white text image (1) onto the white image (3) with NSCompositeDestinationOut.
This gives you a white image with your text cut out.
Draw the white image with the text cut out on top of the gradient image and apply a shadow while drawing.