Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
- Subject: Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
- From: Michael Robinson <email@hidden>
- Date: Thu, 2 Oct 2008 01:46:14 +1300
Ah, thank you for that. This will allow me to scrap much of my HTML
generation code.
The images spat out seem to be quite small, which is a real bonus.
I need to use CGShading, because a lot of people will be running this
on 10.4 (I assume they won't be able to use the other way)?
Unsurprisingly, I need my hand held again.
1. how do I initialize a CGShading object, with my two colours (left
right/top bottom)
2. how do I fill my NSBitmapImageRep with this pretty gradient?
Yes, I know it is "in the docs" but they confuse the **** out of me.
Thanks for all your help
On 1 Oct 2008, at 11:55, Michael Robinson wrote:
On 1/10/2008, at 11:44 PM, Alastair Houghton wrote:
The CSS could be something like
div.box { position: relative }
div.box div.tl { position: absolute; top: 0px; left: 0px; z-index:
100 }
div.box div.tr { position: absolute; top: 0px; right: 0px; z-
index: 100 }
div.box div.bl { position: absolute; bottom: 0px; left: 0px; z-
index: 100 }
div.box div.br { position: absolute; bottom: 0px; left: 0px; z-
index: 100 }
CSS must be inline, don't see why I can't put this CSS inline, do
you?
No, there's no reason that this couldn't be done inline. I forgot
to add the background image, width and height properties for the tl,
tr, bl and br elements, but you get the idea, I'm sure.
Likewise, it wouldn't be hard to set up a bitmap in Cocoa and then
render a gradient-filled box with rounded corners into it. Nor
would this restrict you to a particular final size, since you
could just slice it up into pieces in your code before saving the
pieces to disk as .png files or whatever.
You don't happen to know a good place to look for info on this, do
you?
Well, drawing into an image file in Cocoa is pretty easy. You can
either make an NSImage and the send it -lockFocus, then draw
whatever you please, or if you need more control, you can make an
NSBitmapImageRep and use +graphicsContextWithBitmapImageRep: to
create a graphics context.
e.g.
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL pixelsWide:256 pixelsHigh:256
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:
0];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:rep];
// Draw here
[NSGraphicsContext restoreGraphicsState];
// You now have an NSBitmapImageRep with your drawing in it. You
can do as you please with it from here on out.
To draw gradients, on OS X 10.5 and later you can use NSGradient;
otherwise you'll need to use a CGShading, which is a little trickier
but still not difficult.
*lightbulb* so the image could be _the box with rounded corners_?
Well you could do it with a single background image, if you wanted,
yes. That would probably work better than you might think too
because PNG should be able to do a decent job of compressing it,
even with a gradient fill. It won't work if you need to change the
size of the box, obviously (unless you can use some of the recently
added WebKit features, but that won't work for a public site since
only WebKit supports it).
If it needs to be resizable, you could split the image up into nine
pieces and do
<div class="box">
<div class="tl"></div>
<div class="t"></div>
<div class="tr"></div>
<div class="l"></div>
<div class="c"></div>
<div class="r"></div>
<div class="bl"></div>
<div class="b"></div>
<div class="br"></div>
<div class="content">
<!-- Content here -->
</div>
</div>
with similar styles to before. The reason you'd need the extra divs
in the case of a filled box is that you wouldn't want to set the
background on the "box" part, because then that would show through
under the corners. As a result, you'd need to set the styles up to
tile the inner divs like this:
+---+---------+---+
|tl | t | tr|
+---+---------+---+
| | | |
| l | c | r |
| | | |
+---+---------+---+
|bl | b | br|
+---+---------+---+
The "content" div could simply have its z-index set above those of
the corners (depending on the desired effect, obviously), and then
use margin to keep it from going outside the rounded box.
The nine piece method is (a lot) more complicated to set up, but it
could be made to work if the size of the box itself varied.
Is it possible to output it as a png, so the parts behind the
rounded corners allow anything behind to show through?
Yes. Just use e.g.
NSData *pngData = [rep representationUsingType:NSPNGFileType
properties:nil];
[pngData writeToFile:@"MyFile.png" atomically:YES];
You could set the properties if you really wanted, but I don't think
you need to.
You sir, are a genius.
<pastedGraphic.tiff>
Like that?
Potentially, yes.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden