From 5a9dd921283707713a30eddf18ebbdcc9e9f1851 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Jul 2010 18:39:10 +0000 Subject: [PATCH] Correct creation of the mask for wxImage cursors in wxGTK. The code created the monochrome bitmap used by wxCursor(wxImage) ctor incorrectly resulting in bad cursor appearance. Use the right values for foreground and background pixels (which are inversed compared to naive expectations) to fix this. Closes #11989. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65107 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/cursor.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 6da4ba4d96..17e0243a23 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -257,20 +257,17 @@ void wxCursor::InitFromImage( const wxImage & image ) // modify image so wxBitmap can be used to convert to pixmap image_copy.SetMask(false); - int i, j; wxByte* data = image_copy.GetData(); - for (j = 0; j < h; j++) + for (int j = 0; j < h; j++) { - for (i = 0; i < w; i++, data += 3) + for (int i = 0; i < w; i++, data += 3) { - //if average value is > mid grey - if (int(data[0]) + data[1] + data[2] >= 3 * 128) - { - // wxBitmap only converts (255,255,255) to white - data[0] = 255; - data[1] = 255; - data[2] = 255; - } + // if average value of the pixel is > mid grey, convert it to + // background (0), otherwise to foreground (255, using wxBitmap + // convention) + data[0] = + data[1] = + data[2] = int(data[0]) + data[1] + data[2] >= 3 * 128 ? 0 : 255; } } wxBitmap bitmap(image_copy, 1); -- 2.45.2