]> git.saurik.com Git - wxWidgets.git/commitdiff
native implementation of DoGetPixel()
authorPaul Cornett <paulcor@bullseye.com>
Sun, 4 Jan 2009 02:58:52 +0000 (02:58 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Sun, 4 Jan 2009 02:58:52 +0000 (02:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57823 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/dcclient.cpp

index f81a7f8bc9247a8536696e05acf31a22c3d3165f..48405d02a92e4613a0de32c72c0a9a4688423d0d 100644 (file)
@@ -443,25 +443,33 @@ bool wxWindowDCImpl::DoFloodFill(wxCoord x, wxCoord y,
 
 bool wxWindowDCImpl::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
 {
-#if wxUSE_IMAGE
-    // Generic (and therefore rather inefficient) method.
-    // Could be improved.
-    wxMemoryDC memdc;
-    wxBitmap bitmap(1, 1);
-    memdc.SelectObject(bitmap);
-    memdc.Blit(0, 0, 1, 1, GetOwner(), x1, y1);
-    memdc.SelectObject(wxNullBitmap);
-
-    wxImage image = bitmap.ConvertToImage();
-    col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
+    GdkImage* image = NULL;
+    if (m_gdkwindow)
+    {
+        const int x = LogicalToDeviceX(x1);
+        const int y = LogicalToDeviceY(y1);
+        wxRect rect;
+        gdk_drawable_get_size(m_gdkwindow, &rect.width, &rect.height);
+        if (rect.Contains(x, y))
+            image = gdk_drawable_get_image(m_gdkwindow, x, y, 1, 1);
+    }
+    if (image == NULL)
+    {
+        *col = wxColour();
+        return false;
+    }
+    GdkColormap* colormap = gdk_image_get_colormap(image);
+    const unsigned pixel = gdk_image_get_pixel(image, 0, 0);
+    if (colormap == NULL)
+        *col = pixel ? m_textForegroundColour : m_textBackgroundColour;
+    else
+    {
+        GdkColor c;
+        gdk_colormap_query_color(colormap, pixel, &c);
+        col->Set(c.red >> 8, c.green >> 8, c.blue >> 8);
+    }
+    g_object_unref(image);
     return true;
-#else // !wxUSE_IMAGE
-    wxUnusedVar(x1);
-    wxUnusedVar(y1);
-    wxUnusedVar(col);
-
-    return false;
-#endif // wxUSE_IMAGE/!wxUSE_IMAGE
 }
 
 void wxWindowDCImpl::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )