don't draw checkerboard when image field has default

This commit is contained in:
GenevensiS
2025-06-02 14:05:26 +02:00
parent 0d1b5a6be0
commit c36cd2d4da
2 changed files with 8 additions and 7 deletions
+7 -6
View File
@@ -99,19 +99,20 @@ bool very_light(const Image& image) {
return total >= 210 * 3; return total >= 210 * 3;
} }
Bitmap ImageValueViewer::imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& background, bool editing) { Bitmap ImageValueViewer::imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& default_image, bool editing) {
// Bitmap and memory dc // Bitmap and memory dc
Bitmap bmp(w, h, 24); Bitmap bmp(w, h, 32);
wxMemoryDC mdc; wxMemoryDC mdc;
mdc.SelectObject(bmp); mdc.SelectObject(bmp);
RealRect rect(0,0,w,h); RealRect rect(0,0,w,h);
RotatedDC dc(mdc, 0, rect, 1.0, QUALITY_AA); RotatedDC dc(mdc, 0, rect, 1.0, QUALITY_AA);
// Draw (checker) background // Draw (checker) background
if (!background.Ok() || background.HasAlpha()) { if (!default_image.Ok()) {
draw_checker(dc, rect); draw_checker(dc, rect);
} }
if (background.Ok()) { else {
dc.DrawImage(background, RealPoint(0,0)); if (default_image.HasAlpha()) bmp.UseAlpha(true);
dc.DrawImage(default_image, RealPoint(0,0));
} }
// Draw text // Draw text
if (editing) { if (editing) {
@@ -122,7 +123,7 @@ Bitmap ImageValueViewer::imagePlaceholder(const Rotation& rot, UInt w, UInt h, c
if (rs.width <= w - 10 && rs.height < h - 10) { if (rs.width <= w - 10 && rs.height < h - 10) {
// text fits // text fits
RealPoint pos = align_in_rect(ALIGN_MIDDLE_CENTER, rs, rect); RealPoint pos = align_in_rect(ALIGN_MIDDLE_CENTER, rs, rect);
bool black_on_white = !background.Ok() || very_light(background); bool black_on_white = !default_image.Ok() || very_light(default_image);
dc.SetTextForeground(black_on_white ? *wxWHITE : *wxBLACK); dc.SetTextForeground(black_on_white ? *wxWHITE : *wxBLACK);
dc.DrawText(_("double click to load image"), pos, 2, 4); // blurred dc.DrawText(_("double click to load image"), pos, 2, 4); // blurred
dc.SetTextForeground(black_on_white ? *wxBLACK : *wxWHITE); dc.SetTextForeground(black_on_white ? *wxBLACK : *wxWHITE);
+1 -1
View File
@@ -32,6 +32,6 @@ private:
bool is_default; ///< Is the default placeholder image used? bool is_default; ///< Is the default placeholder image used?
/// Generate a placeholder image /// Generate a placeholder image
static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& background, bool editing); static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& default_image, bool editing);
}; };