Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retina Bitmaps #259

Merged
merged 2 commits into from
Jan 12, 2019
Merged

Conversation

baconpaul
Copy link
Collaborator

@kurasu and others - I would really appreciate a review of this. While it works, I made design choices you may not like, so please take a look. I will not sweep it without a positive ack from @kurasu.

And note that in default configuration this does nothing.

If scalable bitmaps are present we can begin to implement zoom.
Step one is to implement Mac Retina display. We do that here
by loading 2x bitmaps if available and drawing them at 0.5x
scale. On retina displays this looks great. On regular displays
it is a no-op basically. See #226 for more.

None of this is activated if the skins aren't installed and
by default it falls back to the standard bitmaps.

If scalable bitmaps are present we can begin to implement zoom.
Step one is to implement Mac Retina display. We do that here
by loading 2x bitmaps if available and drawing them at 0.5x
scale. On retina displays this looks great. On regular displays
it is a no-op basically. See surge-synthesizer#226 for more.

None of this is activated if the skins aren't installed and
by default it falls back to the standard bitmaps.
scales = {{ 100, 200 }};
scaleFilePostfixes[ 100 ] = "";
scaleFilePostfixes[ 200 ] = "@2x";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or?

    scales = {{100, 200}};
    scaleFilePostfixes[100] = "";
    scaleFilePostfixes[200] = "@2x";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the numbers are not 1 and 2 but instead multiplied by a factor 100?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why you need all this complexity given that you have only two different sizes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just have something like

int scaleFilePostfixes[2];
VSTGUI::CBitmap *scaleBitmaps[2];

The need to use std::map comes only from the fact that you have factored your scales.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have 2 sizes; I have 4 or 5 (1, 1.5, 2, 3, 4 at least). I chose an int because the 1.5 size is a float and I didn't want to hash float. When we do zoom properly this will be a longer list so I built it to scale to that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per slack convo I will add a comment here explaining a bit more

{
auto postfix = scaleFilePostfixes[ sc ];
char filename [PATH_MAX];
sprintf (filename, "scalable/bmp%05d%s.png", id, postfix.c_str() );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sprintf() vs sprintf ()?

Copy link
Collaborator

@jarkkojs jarkkojs Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, why not just std::string for filename? If we are in C++, why don't we then just use proudly std::ostringstream? I mean in many companies, projects and organizations (many of the have so called secure programming practices) the of sprintf() is strictly forbidden because it does not do any range checks. When using libc, the practice is to always use snprintf(). I understand this kind of security measures are maybe an overkill for a synth plug-in but high-level C++ constructs would provide all the security measures in an easy-to-use package.

@@ -72,7 +80,11 @@ void SurgeBitmaps::addEntry(int id)
{
assert(bitmap_registry.find(id) == bitmap_registry.end());

#ifdef USE_SCALABLE_BITMAPS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, could add some prefix for all feature flags i.e. compilation flags that enable/disable a feature. Actually USE_ is quite common and would be fine but can be take it as a convention?


//fprintf( stderr, "\n" );
for( auto sc : scales )
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (auto sc : scales) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird spacing is everywhere in this commit...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean "correct spacing is everywhere in this commit and the rest of the world uses weird spacing" surely ;)

That spacing will never leave my fingers. I'll clean it up when I clean up other review comments.

scaleFilePostfixes[ 200 ] = "@2x";

//fprintf( stderr, "\n" );
for( auto sc : scales )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is commented out cruft that ought to be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I left those in since I want them back for debugging when I go to 1.5x 3x and 4x

VSTGUI::CBitmap* bitmap = new VSTGUI::CBitmap(CResourceDescription(id));
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you always use CScalableBitmap even if it does not make difference? Do not understand this complexity...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "if mac" has to go somewhere until we sort out resources and loading them on windows and linux. I put it outside the class. I could put it inside the class. Outside the class seemed cleaner.

Activate for VST2 and VST3 also, which was in the scripts,
but not the code.
@baconpaul
Copy link
Collaborator Author

OK I incorporated @jsakkine review comments and had a lengthy conversation with him about it on slack. As a step on the way and as optionally off, he understood. So I'll merge this so I can put skin switchers in now we have @itsmedavep skin.

@baconpaul baconpaul merged commit 26adc86 into surge-synthesizer:master Jan 12, 2019
@baconpaul baconpaul deleted the retina-bitmaps-226 branch January 13, 2019 00:20
@baconpaul baconpaul restored the retina-bitmaps-226 branch January 13, 2019 01:20
@baconpaul baconpaul deleted the retina-bitmaps-226 branch January 14, 2019 13:41
baconpaul added a commit to baconpaul/surge that referenced this pull request Jul 10, 2019
…s-226

Retina Bitmaps

Former-commit-id: becb7af8c2a497ac23ec072b85500aa6fe3a5dd4 [formerly 26adc86]
Former-commit-id: 1321aff292859206bc8d0647825f2a36077caa76
Former-commit-id: c0936314c03067958a8ac586b713e110ba2d5395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants