Hi, I'm updating my menubar app Battery Status to include retina graphics. Only two things can be drawn in the menubar (from an App Store acceptable app,): NSStrings for text and NSImages for images.
As I see it, I have two options:
1 - Draw doubled versions of all 49 of my icons and include them as resources.
Pros:
- Technically Easy
Cons:
- Boring
- Increased bundle size (from 300 kB of resources to 1.5 MB worth of resources... my entire app will go from 900 kB to 2.6 MB, between the new app icon resolutions and the new resources.)
- Increased amount of resources I have to manage
- The old icon was 18 pixels wide, so I made 11 different icons for battery levels... the higher resolution icon will be 36 pixels wide, but still only have 11 different icons for battery levels... if I really want to utilize the extra pixels, I aught to actually have more battery levels.
2 - Have the app draw the icons on the fly.
Pros:
- Reduces the bundle size (from 300 kB to a few lines of code... I suspect that code will take up a trivial amount of space.)
- More flexible with new resolutions.
- Capable of drawing any battery level... so it can draw a battery level of 57% rather than have to round it to 60%... there was no difference with old screens, but with Retina there is... I don't care how trivial it is.)
- Reduced resources to manage. When I decide I want to recolor something, I change a number in code, I don't have to change every resource using that color.
Cons:
- Technically... beyond what I can do right now?
So, could I have a little help? Ideally, I'd like some bare bones sample code that shows how to make an NSImage from some drawing commands that looks as good as possible on any (retina or non-retina) screen.
The points I'm confused at are... where should the context come from that's being drawn into? It seems like making a new context requires dimensions to be passed in... but that makes it so it can't be resolution independent? And then how do I get that drawing to be an NSImage?
As I see it, I have two options:
1 - Draw doubled versions of all 49 of my icons and include them as resources.
Pros:
- Technically Easy
Cons:
- Boring
- Increased bundle size (from 300 kB of resources to 1.5 MB worth of resources... my entire app will go from 900 kB to 2.6 MB, between the new app icon resolutions and the new resources.)
- Increased amount of resources I have to manage
- The old icon was 18 pixels wide, so I made 11 different icons for battery levels... the higher resolution icon will be 36 pixels wide, but still only have 11 different icons for battery levels... if I really want to utilize the extra pixels, I aught to actually have more battery levels.
2 - Have the app draw the icons on the fly.
Pros:
- Reduces the bundle size (from 300 kB to a few lines of code... I suspect that code will take up a trivial amount of space.)
- More flexible with new resolutions.
- Capable of drawing any battery level... so it can draw a battery level of 57% rather than have to round it to 60%... there was no difference with old screens, but with Retina there is... I don't care how trivial it is.)
- Reduced resources to manage. When I decide I want to recolor something, I change a number in code, I don't have to change every resource using that color.
Cons:
- Technically... beyond what I can do right now?
So, could I have a little help? Ideally, I'd like some bare bones sample code that shows how to make an NSImage from some drawing commands that looks as good as possible on any (retina or non-retina) screen.
The points I'm confused at are... where should the context come from that's being drawn into? It seems like making a new context requires dimensions to be passed in... but that makes it so it can't be resolution independent? And then how do I get that drawing to be an NSImage?