summaryrefslogtreecommitdiff
path: root/src/corelib/x11
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graemeg@gmail.com>2014-10-19 20:22:13 +0100
committerGraeme Geldenhuys <graemeg@gmail.com>2014-10-19 20:22:13 +0100
commit3778ccae5b383b45c08f51f435b45714a2d1d363 (patch)
tree819d0774f077075598b6569e3ed55e0b586d2339 /src/corelib/x11
parente9d974dc967c8bb83c2cbc77d776106a782ab3b2 (diff)
downloadfpGUI-3778ccae5b383b45c08f51f435b45714a2d1d363.tar.xz
New fpgApplication.GetScreenPixelColor() for X11
We can now color pick a value on a X11 desktop.
Diffstat (limited to 'src/corelib/x11')
-rw-r--r--src/corelib/x11/fpg_x11.pas23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/corelib/x11/fpg_x11.pas b/src/corelib/x11/fpg_x11.pas
index c94cf1fb..f98e8198 100644
--- a/src/corelib/x11/fpg_x11.pas
+++ b/src/corelib/x11/fpg_x11.pas
@@ -331,6 +331,7 @@ type
procedure DoFlush;
function GetScreenWidth: TfpgCoord; override;
function GetScreenHeight: TfpgCoord; override;
+ function GetScreenPixelColor(APos: TPoint): TfpgColor; override;
function Screen_dpi_x: integer; override;
function Screen_dpi_y: integer; override;
function Screen_dpi: integer; override;
@@ -2240,6 +2241,28 @@ begin
Result := wa.Height;
end;
+function TfpgX11Application.GetScreenPixelColor(APos: TPoint): TfpgColor;
+var
+ Image: PXImage;
+ Pixel: Cardinal;
+ x_Color: TXColor;
+begin
+ Result := 0;
+ Image := XGetImage(Display, FRootWindow, APos.X, APos.Y, 1, 1, $FFFFFFFF, ZPixmap);
+ if Image = nil then
+ raise Exception.Create('fpGFX/X11: Invalid XImage');
+ try
+ Pixel := XGetPixel(Image, 0, 0);
+ x_Color.pixel := Pixel;
+ XQueryColor(Display, DefaultColorMap, @x_Color);
+ Result := TfpgColor(((x_Color.red and $00FF) shl 16) or
+ ((x_Color.green and $00FF) shl 8) or
+ (x_Color.blue and $00FF));
+ finally
+ XDestroyImage(Image);
+ end;
+end;
+
function TfpgX11Application.Screen_dpi_x: integer;
var
mm: integer;