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

Allow using wxBitmapBundle with wxDataViewBitmapRenderer #22411

Merged
merged 8 commits into from May 23, 2022

Conversation

vadz
Copy link
Contributor

@vadz vadz commented May 8, 2022

While looking at #22359, I've realized that we couldn't use wxBitmapBundle to show images in wxDVC, so I've fixed this and now the following diff

diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp
index 4b2f1d933e..4057a43959 100644
--- a/samples/dataview/dataview.cpp
+++ b/samples/dataview/dataview.cpp
@@ -904,7 +904,7 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel,
             wxDataViewColumn* const colCheckIconText = new wxDataViewColumn
                 (
                      L"\u2714 + icon + text",
-                     new wxDataViewCheckIconTextRenderer(),
+                     new wxDataViewBitmapRenderer(), // also works with explicit "wxBitmap"
                      MyListModel::Col_ToggleIconText,
                      wxCOL_WIDTH_AUTOSIZE
                 );
diff --git a/samples/dataview/mymodels.cpp b/samples/dataview/mymodels.cpp
index d6d76c2414..5aa6f20388 100644
--- a/samples/dataview/mymodels.cpp
+++ b/samples/dataview/mymodels.cpp
@@ -472,6 +472,11 @@ void MyListModel::GetValueByRow( wxVariant &variant,
             break;

         case Col_ToggleIconText:
+            if ( row % 2 )
+                variant << m_icon[row % 2]; // .GetBitmap(wxSize(16, 16)); -- not needed any longer, but still works too
+            else
+                variant = wxNullVariant;
+            break;
             {
                 wxString text;
                 wxCheckBoxState state;

compiles and works, i.e. shows crisp and not scaled bitmaps in high DPI.

@vslavik If you could please test this with Poedit, it would be great.

@MaartenBent @csomor Your review would be welcome as always, TIA!

vadz added 5 commits May 8, 2022 15:54
This is just a convenient helper for resetting the bundle contents which
seems more readable than assigning an empty bundle to it.
Instead of using either a wxBitmap or a wxIcon, always use the same
wxBitmapBundle object to store whatever we are rendering.

This slightly simplifies the code and prepares for further changes, but
nothing real changes yet.
Instead of checking for the exact variant type match, call the new
IsCompatibleVariantType() virtual function, which still does the same
check by default, but can be overridden to allow other types as well if
they're accepted by the renderer.

This will be soon used to allow accepting both wxBitmap (which must
still be accepted for compatibility) and wxBitmapBundle (which is the
simplest way to support high DPI) in wxDataViewBitmapRenderer at once.
Allow using either wxBitmap or wxIcon in wxDataViewBitmapRenderer
independently of the type the renderer was created with because this is
convenient and there is no real danger in allowing to mix and match
bitmaps and icons together.

Override the just added IsCompatibleVariantType() to implement this.
Define wxBitmapBundleVariantData without using the standard macros that
only work for wxObject-derived classes, but using more or less what they
expand into.

This will allow using wxBitmapBundle with wxDataViewCustomRenderer
subclasses in the upcoming commit.
@vadz vadz added this to the 3.1.7 milestone May 8, 2022
@vadz vadz requested a review from vslavik May 8, 2022 19:31
vadz added 2 commits May 9, 2022 14:36
This allows returning the entire bundle from the model GetValue()
function to let the renderer itself to select the best matching bitmap
to use.
The default type doesn't really matter after the previous commits, as
the renderer accepts both wxBitmap and wxBitmapBundle (and also wxIcon)
in any case anyhow, but it seems better to use the preferred type as the
default one.

Also make the documentation more useful, although an example is still
lacking.
@vadz vadz force-pushed the dvc-bitmap-renderer-bundle branch from 34fd6d4 to 1b82a9f Compare May 9, 2022 12:52
@vadz
Copy link
Contributor Author

vadz commented May 11, 2022

Apparently nobody feels brave enough to have a look at this, so I'm going to use the only reliably working method for getting comments on my changes: merge it and see if it breaks anything.

@vslavik
Copy link
Member

vslavik commented May 11, 2022

Apparently nobody feels brave enough to have a look at this,

Sorry I wasn't able to accommodate you in the past 3 business days :/

It looks fine to me. I wanted to actually test it, as you asked, which means updating Poedit's build to it first on macOS and Windows, and I just wasn't able to do it yet.

@vadz
Copy link
Contributor Author

vadz commented May 11, 2022

Apparently nobody feels brave enough to have a look at this,

Sorry I wasn't able to accommodate you in the past 3 business days :/

Sorry, my comment was intended to be a light-hearted one, nothing more. But, also, IME any comments about the PRs tend to come either relatively quickly (1-2 days) or not at all, so I thought it was safe to assume that none were upcoming here. I'm glad to be proven wrong, thanks for looking at this!

It looks fine to me. I wanted to actually test it, as you asked, which means updating Poedit's build to it first on macOS and Windows, and I just wasn't able to do it yet.

Please let me know if you'd prefer me to wait until you can test it before I merge it. If you can, it would, of course, be better to wait until you can check that there are no unexpected problems with this. But I'd definitely like to merge this one before 3.1.7 (supposed to be released on 2022-06-06).

Thanks again!

Explain what it is in the ctor documentation and link to the new
IsCompatibleVariantType() in GetVariantType() docs.
Copy link
Contributor

@MaartenBent MaartenBent left a comment

Choose a reason for hiding this comment

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

Tested provided example on Windows and it seems to work good.

include/wx/qt/dvrenderers.h Show resolved Hide resolved
bool
wxDataViewBitmapRenderer::IsCompatibleVariantType(const wxString& variantType) const
{
return variantType == wxS("wxBitmap")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it needs wxBitmapBundle like the other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess... But then this seems to be completely unimplemented in wxQt anyhow, and wxBitmapBundle is not implemented for it neither, so it's a bit of a moot point anyhow.

@vadz
Copy link
Contributor Author

vadz commented May 20, 2022

@vslavik Do you still plan to test this relatively soon?

@vslavik
Copy link
Member

vslavik commented May 21, 2022

@vadz I was slowed down by wxBitmapBundle changes breaking, of all things, the one platform that did natively handle bundles in wxBitmap just fine previously, and none of bitmaps, including in wxDVC, work in Poedit on macOS. Figuring that out seemed rather more pressing (patches incoming now that I did).

Testing of this so far: macOS is fine. wxGTK scales bitmaps in the list differently for HiDPI (NN instead of bilinear - unclear which is more correct, I'm fine with this). Didn't test Windows yet.

@vadz
Copy link
Contributor Author

vadz commented May 21, 2022

@vadz I was slowed down by wxBitmapBundle changes breaking, of all things, the one platform that did natively handle bundles in wxBitmap just fine previously, and none of bitmaps, including in wxDVC, work in Poedit on macOS.

Oops, this was definitely unexpected. But now I'm even more glad that you could test it!

Figuring that out seemed rather more pressing (patches incoming now that I did).

Looking forward to them, I'd like to understand how did I break it this time...

Testing of this so far: macOS is fine. wxGTK scales bitmaps in the list differently for HiDPI (NN instead of bilinear - unclear which is more correct, I'm fine with this). Didn't test Windows yet.

As per 84cb293 (Make wxBitmap::Rescale() less horrible for commonly used icons, 2022-02-23), I think NN is better (well, less worse). If macOS does bilinear, we're probably not going to (be able?) change it, however.

@vslavik
Copy link
Member

vslavik commented May 23, 2022

I confirm that I couldn't find anything wrong with this patchset in Poedit on either of the 3 platforms.

I created #22449 for some other issues with wxBitmapBundle transition.

As per 84cb293 ... I think NN is better (well, less worse).

I have somewhat different opinion: while NN can "preserve sharp edges", it can also eradicate said edges altogether if rounding goes the wrong way when scaling down. However, I was commenting on 2x upscaling, where its reasonable (and I frankly don't know what macOS does in absence of Retina versions or what GTK+ native does).

@vadz
Copy link
Contributor Author

vadz commented May 23, 2022

Thanks again for testing this, I'm going to merge this now as this shouldn't be affected by the art provider-related changes that still remain to be done.

@vadz vadz merged commit 9042b52 into wxWidgets:master May 23, 2022
@vadz vadz deleted the dvc-bitmap-renderer-bundle branch May 23, 2022 21:32
vadz pushed a commit that referenced this pull request May 27, 2022
Correct the wrong wxVariant type check in 8d3e7fd (Accept
wxBitmapBundle in wxDataViewBitmapRenderer too, 2022-05-08) and actually
verify that we have a wxBitmapBundle, not a wxBitmap, before accessing
it.

See #22411, #22460.
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.

None yet

4 participants