fix: de-scale slice preview window

This is a workaround, not a good solution. The slice doesn't really handle sizing well and doesn't set great maximum sizes on the elements within it. I _think_ that can be worked around by constraining the preview, but none of that is really properly context aware to the user's screen.
This commit is contained in:
Brendan Hagan
2022-07-03 22:06:31 -04:00
parent 8d38ab074b
commit a7014b9ee4
+8 -1
View File
@@ -389,7 +389,10 @@ void ImageSlicePreview::update() {
wxSize ImageSlicePreview::DoGetBestSize() const { wxSize ImageSlicePreview::DoGetBestSize() const {
// We know the client size we want, calculate the size that goes with that // We know the client size we want, calculate the size that goes with that
wxSize ws = GetSize(), cs = GetClientSize(); wxSize ws = GetSize(), cs = GetClientSize();
return slice.target_size + ws - cs;
// This just gets it back to 100% scale. Doesn't solve the sizing issue of the overall window.
// All the above are doing appears to be finding margins/borders and accounting for them on a fixed scale.
return slice.target_size / 2 + ws - cs;
} }
void ImageSlicePreview::onPaint(wxPaintEvent&) { void ImageSlicePreview::onPaint(wxPaintEvent&) {
@@ -414,6 +417,10 @@ void ImageSlicePreview::draw(DC& dc) {
} else { } else {
bitmap = Bitmap(image); bitmap = Bitmap(image);
} }
// Rescale the bitmap based on the available size.
auto available_size = DoGetBestSize();
bitmap = wxBitmap(bitmap.ConvertToImage().Scale(available_size.GetWidth(), available_size.GetHeight()));
} }
if (bitmap.Ok()) { if (bitmap.Ok()) {
dc.DrawBitmap(bitmap, 0, 0); dc.DrawBitmap(bitmap, 0, 0);