-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from baconpaul/retina-bitmaps-226
Retina Bitmaps
- Loading branch information
Showing
6 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "CScalableBitmap.h" | ||
#if MAC | ||
#include <CoreFoundation/CoreFoundation.h> | ||
#endif | ||
|
||
CScalableBitmap::CScalableBitmap(CResourceDescription desc) : CBitmap(desc) | ||
{ | ||
int id = 0; | ||
if(desc.type == CResourceDescription::kIntegerType) | ||
id = (int32_t)desc.u.id; | ||
|
||
/* | ||
** At this stage this scales array may seem like overkill since it only has two | ||
** values. But to impelemnt scalability we will end up with multiple sizes, including | ||
** 1.5x maybe 1.25x and so on. So build the architecture now to support that even | ||
** though we only populate with two types. And since our sizes will include a 1.25x | ||
** hash on integer percentages (so 100 -> 1x), not on floats. | ||
*/ | ||
|
||
scales = {{ 100, 200 }}; | ||
scaleFilePostfixes[ 100 ] = ""; | ||
scaleFilePostfixes[ 200 ] = "@2x"; | ||
|
||
for(auto sc : scales) | ||
{ | ||
auto postfix = scaleFilePostfixes[sc]; | ||
|
||
char filename [PATH_MAX]; | ||
sprintf (filename, "scalable/bmp%05d%s.png", id, postfix.c_str()); | ||
|
||
CBitmap *tmp = new CBitmap(CResourceDescription( filename )); | ||
|
||
if(tmp->getWidth() > 0) | ||
{ | ||
scaledBitmaps[sc] = tmp; | ||
} | ||
else | ||
{ | ||
scaledBitmaps[sc] = NULL; | ||
} | ||
|
||
} | ||
} | ||
|
||
void CScalableBitmap::draw (CDrawContext* context, const CRect& rect, const CPoint& offset, float alpha ) | ||
{ | ||
/* | ||
** For now this is a fixed 'retina' style draw of using 2x bitmaps at 0.5 scale if they exist | ||
*/ | ||
if (scaledBitmaps[ 200 ] != NULL) | ||
{ | ||
CGraphicsTransform tf = CGraphicsTransform().scale( 0.5, 0.5 ); | ||
CGraphicsTransform invtf = tf.inverse(); | ||
|
||
CDrawContext::Transform tr(*context, tf); | ||
|
||
// Have to de-const these to do the transform alas | ||
CRect ncrect = rect; | ||
CRect nr = invtf.transform(ncrect); | ||
|
||
CPoint ncoff = offset; | ||
CPoint no = invtf.transform(ncoff); | ||
|
||
scaledBitmaps[ 200 ]->draw(context, nr, no, alpha); | ||
} | ||
else | ||
{ | ||
CBitmap::draw(context, rect, offset, alpha); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
** CScalableBitmap is an implmentation of VSGTUI::CBitmap which can | ||
** load bitmaps at multiple resolutions and draw them scaled accordingly | ||
*/ | ||
|
||
#include <vstgui/vstgui.h> | ||
|
||
#include <vector> | ||
#include <map> | ||
|
||
class CScalableBitmap : public VSTGUI::CBitmap | ||
{ | ||
public: | ||
CScalableBitmap( CResourceDescription d ); | ||
|
||
std::vector< int > scales; // 100, 150, 200, 300 etc... - int percentages | ||
std::map< int, VSTGUI::CBitmap * > scaledBitmaps; | ||
std::map< int, std::string > scaleFilePostfixes; | ||
|
||
virtual void draw (CDrawContext* context, const CRect& rect, const CPoint& offset, float alpha); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters