mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-24 18:22:25 -05:00
LEKKER
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@18 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
a6a7f0b247
commit
adc6d0b6f5
@ -1,436 +1,443 @@
|
||||
unit Window;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, mufasatypes,
|
||||
{$IFDEF MSWINDOWS}
|
||||
windows, // For windows API
|
||||
{$ENDIF}
|
||||
graphics,
|
||||
LCLType,
|
||||
LCLIntf // for ReleaseDC and such
|
||||
|
||||
{$IFDEF LINUX}, xlib, x, xutil, ctypes{$ENDIF};
|
||||
|
||||
type
|
||||
|
||||
{ TMWindow }
|
||||
|
||||
TMWindow = class(TObject)
|
||||
function ReturnData(xs, ys, width, height: Integer): TRetData;
|
||||
procedure FreeReturnData;
|
||||
procedure GetDimensions(var W, H: Integer);
|
||||
function CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
|
||||
procedure ActivateClient;
|
||||
{$IFDEF LINUX}
|
||||
function SetTarget(XWindow: x.TWindow): integer; overload;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
function UpdateDrawBitmap:boolean;
|
||||
{$ENDIF}
|
||||
function SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
|
||||
function SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
|
||||
|
||||
constructor Create(Client: TObject);
|
||||
destructor Destroy; override;
|
||||
public
|
||||
// Reference to client.
|
||||
Client: TObject;
|
||||
|
||||
// Target Window Mode.
|
||||
TargetMode: TTargetWindowMode;
|
||||
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
//Target handle; HWND
|
||||
TargetHandle : Hwnd;
|
||||
DrawBmpDataPtr : PRGB32;
|
||||
|
||||
//Works on linux as well, test it out
|
||||
TargetDC : HDC;
|
||||
DrawBitmap : TBitmap;
|
||||
DrawBmpW,DrawBmpH : integer;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF LINUX}
|
||||
// X Display
|
||||
XDisplay: PDisplay;
|
||||
|
||||
// Connection Number
|
||||
XConnectionNumber: Integer;
|
||||
|
||||
// X Window
|
||||
CurWindow: x.TWindow;
|
||||
|
||||
// Desktop Window
|
||||
DesktopWindow: x.TWindow;
|
||||
|
||||
// X Screen
|
||||
XScreen: PScreen;
|
||||
|
||||
// X Screen Number
|
||||
XScreenNum: Integer;
|
||||
|
||||
// The X Image pointer.
|
||||
XWindowImage: PXImage;
|
||||
|
||||
{$IFDEF M_MEMORY_DEBUG}
|
||||
// XImageFreed should be True if there is currently no
|
||||
// XImage loaded. If one is loaded, XImageFreed is true.
|
||||
|
||||
// If ReturnData is called while XImageFreed is false,
|
||||
// we throw an exception.
|
||||
// Same for FreeReturnData with XImageFreed true.
|
||||
XImageFreed: Boolean;
|
||||
{$ENDIF}
|
||||
|
||||
{$ELSE}
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
ArrayPtr: PRGB32;
|
||||
ArraySize: TPoint;
|
||||
|
||||
|
||||
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Client, // For the Client Class
|
||||
windowutil, // For utilities such as XImageToRawImage
|
||||
GraphType // For TRawImage
|
||||
;
|
||||
|
||||
constructor TMWindow.Create(Client: TObject);
|
||||
begin
|
||||
inherited Create;
|
||||
Self.Client := Client;
|
||||
|
||||
Self.ArrayPtr := nil;
|
||||
Self.ArraySize := Classes.Point(-1, -1);
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
Self.DrawBitmap := TBitmap.Create;
|
||||
Self.DrawBitmap.PixelFormat:= pf32bit;
|
||||
Self.TargetMode:= w_Window;
|
||||
Self.TargetHandle:= windows.GetDesktopWindow;
|
||||
Self.TargetDC:= GetWindowDC(Self.TargetHandle);
|
||||
Self.UpdateDrawBitmap;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF LINUX}
|
||||
Self.TargetMode := w_XWindow;
|
||||
|
||||
Self.XDisplay := XOpenDisplay(nil);
|
||||
if Self.XDisplay = nil then
|
||||
begin
|
||||
// throw Exception
|
||||
end;
|
||||
Self.XConnectionNumber:= ConnectionNumber(Self.XDisplay);
|
||||
Self.XScreen := XDefaultScreenOfDisplay(Self.XDisplay);
|
||||
Self.XScreenNum:= DefaultScreen(Self.XDisplay);
|
||||
|
||||
// The Root Window is the Desktop. :-)
|
||||
Self.DesktopWindow:= RootWindow(Self.XDisplay, Self.XScreenNum);
|
||||
Self.CurWindow:= Self.DesktopWindow;
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
end;
|
||||
|
||||
destructor TMWindow.Destroy;
|
||||
begin
|
||||
|
||||
{$IFDEF LINUX}
|
||||
XCloseDisplay(Self.XDisplay);
|
||||
{$ENDIF}
|
||||
{$IFDEF MSWINDOWS}
|
||||
if TargetMode = w_Window then
|
||||
ReleaseDC(TargetHandle,TargetDC);
|
||||
DrawBitmap.Free;
|
||||
{$ENDIF}
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TMWindow.ReturnData(xs, ys, width, height: Integer): TRetData;
|
||||
var
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler: TXErrorHandler;
|
||||
{$ENDIF}
|
||||
TmpData: PRGB32;
|
||||
|
||||
begin
|
||||
case Self.TargetMode of
|
||||
w_Window:
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
BitBlt(Self.DrawBitmap.Canvas.Handle,0,0, width, height, Self.TargetDC, xs,ys, SRCCOPY);
|
||||
Result.Ptr:= Self.DrawBmpDataPtr;
|
||||
Result.IncPtrWith:= DrawBmpW - Width;
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_XWindow:
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
{ Should be this. }
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
|
||||
Self.XWindowImage := XGetImage(Self.XDisplay, Self.curWindow, xs, ys, width, height, AllPlanes, ZPixmap);
|
||||
if QWord(Self.XWindowImage) = 0 then
|
||||
begin
|
||||
Writeln('ReturnData: XGetImage Error. Dumping data now:');
|
||||
Writeln('xs, ys, width, height: ' + inttostr(xs) + ', ' + inttostr(ys) +
|
||||
', ' + inttostr(width) + ', ' + inttostr(height));
|
||||
Result := nil;
|
||||
XSetErrorHandler(Old_Handler);
|
||||
Exit;
|
||||
end;
|
||||
WriteLn(IntToStr(Self.XWindowImage^.width) + ', ' + IntToStr(Self.XWindowImage^.height));
|
||||
Result.Ptr := PRGB32(Self.XWindowImage^.data);
|
||||
Result.IncPtrWith := 0;
|
||||
|
||||
XSetErrorHandler(Old_Handler);
|
||||
{$ELSE}
|
||||
WriteLn('Windows doesn''t support XImage');
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_ArrayPtr:
|
||||
begin
|
||||
TmpData := Self.ArrayPtr;
|
||||
Inc(TmpData, ys * Height + xs);
|
||||
Result.Ptr := TmpData;
|
||||
Result.IncPtrWith:= Self.ArraySize.x - width;
|
||||
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMWindow.FreeReturnData;
|
||||
begin
|
||||
if Self.TargetMode <> w_XWindow then
|
||||
begin
|
||||
// throw exception.
|
||||
exit;
|
||||
end;
|
||||
{$IFDEF LINUX}
|
||||
if(QWord(Self.XWindowImage) <> 0) then // 0, nil?
|
||||
begin
|
||||
XDestroyImage(Self.XWindowImage);
|
||||
end;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TMWindow.CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
|
||||
var
|
||||
w,h : Integer;
|
||||
ww, hh: Integer;
|
||||
Raw: TRawImage;
|
||||
Bmp: TBitmap;
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler: TXErrorHandler;
|
||||
Img: PXImage;
|
||||
{$ENDIF}
|
||||
|
||||
begin
|
||||
Self.GetDimensions(w, h);
|
||||
writeln(inttostr(xs) + ', ' + inttostr(ys) + ' : ' + inttostr(xe) + ', ' +
|
||||
inttostr(ye));
|
||||
ww := xe-xs;
|
||||
hh := ye-ys;
|
||||
if(xs < 0) or (ys < 0) or (xe > W) or (ye > H) then
|
||||
begin
|
||||
writeln('Faulty coordinates');
|
||||
exit;
|
||||
end;
|
||||
|
||||
case Self.TargetMode Of
|
||||
w_Window:
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
Result := TBitmap.Create;
|
||||
Result.SetSize(ww+1,hh+1);
|
||||
BitBlt(result.canvas.handle,0,0,ww+1,hh+1,
|
||||
self.TargetDC,xs,ys, SRCCOPY);
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_XWindow:
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
|
||||
Img := XGetImage(Self.XDisplay, Self.curWindow, xs, ys, ww, hh, AllPlanes, ZPixmap);
|
||||
|
||||
Bmp := TBitmap.Create;
|
||||
Bmp.LoadFromRawImage(Raw, False);
|
||||
Result := Bmp;
|
||||
|
||||
{
|
||||
If you want to use some internal Bitmap system, BitBlt to it here.
|
||||
Don't forget to free Bmp!
|
||||
}
|
||||
//lclintf.BitBlt(Bmps[bitmap].Canvas.Handle, 0, 0, ww + 1, hh + 1, Bmp.Canvas.Handle, xs, ys, SRCCOPY);
|
||||
//Bmp.Free;
|
||||
|
||||
XDestroyImage(Img);
|
||||
XSetErrorHandler(Old_Handler);
|
||||
{$ELSE}
|
||||
writeln('Windows and tXWindow');
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_ArrayPtr:
|
||||
begin
|
||||
|
||||
ArrDataToRawImage(Self.ArrayPtr, Self.ArraySize, Raw);
|
||||
|
||||
Bmp := TBitmap.Create;
|
||||
Bmp.LoadFromRawImage(Raw, False);
|
||||
Result := Bmp;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMWindow.ActivateClient;
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
if TargetMode = w_Window then
|
||||
SetForegroundWindow(Self.TargetHandle);
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
if TargetMode = w_XWindow then
|
||||
XSetInputFocus(Self.XDisplay,Self.CurWindow,RevertToParent,CurrentTime);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
{$IFDEF MSWINDOWS} //Probably need one for Linux as well
|
||||
function TMWindow.UpdateDrawBitmap :boolean;
|
||||
var
|
||||
w,h : integer;
|
||||
BmpInfo : Windows.TBitmap;
|
||||
begin
|
||||
GetDimensions(w,h);
|
||||
DrawBitmap.SetSize(w,h);
|
||||
// DrawBitmap.PixelFormat:=
|
||||
DrawBmpW := w;
|
||||
DrawBmpH := h;
|
||||
GetObject(DrawBitmap.Handle, SizeOf(BmpInfo), @BmpInfo);
|
||||
DrawBmpDataPtr := BmpInfo.bmBits;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TMWindow.GetDimensions(var W, H: Integer);
|
||||
{$IFDEF LINUX}
|
||||
var
|
||||
Attrib: TXWindowAttributes;
|
||||
newx,newy : integer;
|
||||
childwindow : x.TWindow;
|
||||
Old_Handler: TXErrorHandler;
|
||||
{$ENDIF}
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
Rect : TRect;
|
||||
{$ENDIF}
|
||||
begin
|
||||
case TargetMode of
|
||||
w_Window:
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
GetWindowRect(Self.TargetHandle, Rect);
|
||||
w:= Rect.Right - Rect.left + 1;
|
||||
h:= Rect.Bottom - Rect.Top + 1;
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_XWindow:
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
if XGetWindowAttributes(Self.XDisplay, Self.CurWindow, @Attrib) <> 0 Then
|
||||
begin
|
||||
XTranslateCoordinates(Self.XDisplay, Self.CurWindow, Self.DesktopWindow, 0,0, @newx, @newy, @childwindow);
|
||||
W := Attrib.Width;
|
||||
H := Attrib.Height;
|
||||
end else
|
||||
begin
|
||||
W := -1;
|
||||
H := -1;
|
||||
end;
|
||||
XSetErrorHandler(Old_Handler);
|
||||
{$ELSE}
|
||||
WriteLn('You dummy! How are you going to use w_XWindow on non Linux systems?');
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_ArrayPtr:
|
||||
begin
|
||||
W := Self.ArraySize.X;
|
||||
H := Self.ArraySize.Y;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
function TMWindow.SetTarget(XWindow: x.TWindow): integer; overload;
|
||||
var
|
||||
Old_Handler: TXErrorHandler;
|
||||
begin
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
Self.CurWindow := XWindow;
|
||||
Self.TargetMode:= w_XWindow;
|
||||
XSetErrorHandler(Old_Handler);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function TMWindow.SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
|
||||
begin
|
||||
if NewType in [ w_XWindow, w_ArrayPtr ] then
|
||||
begin
|
||||
// throw exception
|
||||
Exit;
|
||||
end;
|
||||
case NewType of
|
||||
w_Window :
|
||||
begin;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
ReleaseDC(Self.TargetHandle,Self.TargetDC);
|
||||
Self.TargetHandle := Window;
|
||||
Self.TargetDC := GetWindowDC(Window);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
{$IFDEF MSWINDOWS}
|
||||
UpdateDrawBitmap;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{
|
||||
This functionality is very BETA.
|
||||
We have no way to send events to a window, so we should probably use the
|
||||
desktop window?
|
||||
|
||||
eg: In mouse/keys: if Self.TargetMode not in [w_Window, w_XWindow], send it
|
||||
to the desktop.
|
||||
}
|
||||
function TMWindow.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
|
||||
begin
|
||||
Self.ArrayPtr := ArrPtr;
|
||||
Self.ArraySize := Size;
|
||||
Self.TargetMode:= w_ArrayPtr;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
Self.CurWindow := Self.DesktopWindow;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF WINDOWS}
|
||||
Self.TargetHandle:= windows.GetDesktopWindow;
|
||||
{$ENDIF}
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
unit Window;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, mufasatypes,
|
||||
{$IFDEF MSWINDOWS}
|
||||
windows, // For windows API
|
||||
{$ENDIF}
|
||||
graphics,
|
||||
LCLType,
|
||||
LCLIntf // for ReleaseDC and such
|
||||
|
||||
{$IFDEF LINUX}, xlib, x, xutil, ctypes{$ENDIF};
|
||||
|
||||
type
|
||||
|
||||
{ TMWindow }
|
||||
|
||||
TMWindow = class(TObject)
|
||||
function ReturnData(xs, ys, width, height: Integer): TRetData;
|
||||
procedure FreeReturnData;
|
||||
procedure GetDimensions(var W, H: Integer);
|
||||
function CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
|
||||
procedure ActivateClient;
|
||||
{$IFDEF LINUX}
|
||||
function SetTarget(XWindow: x.TWindow): integer; overload;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
function UpdateDrawBitmap:boolean;
|
||||
{$ENDIF}
|
||||
function SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
|
||||
function SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
|
||||
|
||||
constructor Create(Client: TObject);
|
||||
destructor Destroy; override;
|
||||
public
|
||||
// Reference to client.
|
||||
Client: TObject;
|
||||
|
||||
// Target Window Mode.
|
||||
TargetMode: TTargetWindowMode;
|
||||
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
//Target handle; HWND
|
||||
TargetHandle : Hwnd;
|
||||
DrawBmpDataPtr : PRGB32;
|
||||
|
||||
//Works on linux as well, test it out
|
||||
TargetDC : HDC;
|
||||
DrawBitmap : TBitmap;
|
||||
DrawBmpW,DrawBmpH : integer;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF LINUX}
|
||||
// X Display
|
||||
XDisplay: PDisplay;
|
||||
|
||||
// Connection Number
|
||||
XConnectionNumber: Integer;
|
||||
|
||||
// X Window
|
||||
CurWindow: x.TWindow;
|
||||
|
||||
// Desktop Window
|
||||
DesktopWindow: x.TWindow;
|
||||
|
||||
// X Screen
|
||||
XScreen: PScreen;
|
||||
|
||||
// X Screen Number
|
||||
XScreenNum: Integer;
|
||||
|
||||
// The X Image pointer.
|
||||
XWindowImage: PXImage;
|
||||
|
||||
{$IFDEF M_MEMORY_DEBUG}
|
||||
// XImageFreed should be True if there is currently no
|
||||
// XImage loaded. If one is loaded, XImageFreed is true.
|
||||
|
||||
// If ReturnData is called while XImageFreed is false,
|
||||
// we throw an exception.
|
||||
// Same for FreeReturnData with XImageFreed true.
|
||||
XImageFreed: Boolean;
|
||||
{$ENDIF}
|
||||
|
||||
{$ELSE}
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
ArrayPtr: PRGB32;
|
||||
ArraySize: TPoint;
|
||||
|
||||
|
||||
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Client, // For the Client Class
|
||||
windowutil, // For utilities such as XImageToRawImage
|
||||
GraphType // For TRawImage
|
||||
;
|
||||
|
||||
constructor TMWindow.Create(Client: TObject);
|
||||
begin
|
||||
inherited Create;
|
||||
Self.Client := Client;
|
||||
|
||||
Self.ArrayPtr := nil;
|
||||
Self.ArraySize := Classes.Point(-1, -1);
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
Self.DrawBitmap := TBitmap.Create;
|
||||
Self.DrawBitmap.PixelFormat:= pf32bit;
|
||||
Self.TargetMode:= w_Window;
|
||||
Self.TargetHandle:= windows.GetDesktopWindow;
|
||||
Self.TargetDC:= GetWindowDC(Self.TargetHandle);
|
||||
Self.UpdateDrawBitmap;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF LINUX}
|
||||
Self.TargetMode := w_XWindow;
|
||||
|
||||
Self.XDisplay := XOpenDisplay(nil);
|
||||
if Self.XDisplay = nil then
|
||||
begin
|
||||
// throw Exception
|
||||
end;
|
||||
Self.XConnectionNumber:= ConnectionNumber(Self.XDisplay);
|
||||
Self.XScreen := XDefaultScreenOfDisplay(Self.XDisplay);
|
||||
Self.XScreenNum:= DefaultScreen(Self.XDisplay);
|
||||
|
||||
// The Root Window is the Desktop. :-)
|
||||
Self.DesktopWindow:= RootWindow(Self.XDisplay, Self.XScreenNum);
|
||||
Self.CurWindow:= Self.DesktopWindow;
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
end;
|
||||
|
||||
destructor TMWindow.Destroy;
|
||||
begin
|
||||
|
||||
{$IFDEF LINUX}
|
||||
XCloseDisplay(Self.XDisplay);
|
||||
{$ENDIF}
|
||||
{$IFDEF MSWINDOWS}
|
||||
if TargetMode = w_Window then
|
||||
ReleaseDC(TargetHandle,TargetDC);
|
||||
DrawBitmap.Free;
|
||||
{$ENDIF}
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TMWindow.ReturnData(xs, ys, width, height: Integer): TRetData;
|
||||
var
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler: TXErrorHandler;
|
||||
{$ENDIF}
|
||||
TmpData: PRGB32;
|
||||
|
||||
begin
|
||||
case Self.TargetMode of
|
||||
w_Window:
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
BitBlt(Self.DrawBitmap.Canvas.Handle,0,0, width, height, Self.TargetDC, xs,ys, SRCCOPY);
|
||||
Result.Ptr:= Self.DrawBmpDataPtr;
|
||||
Result.IncPtrWith:= DrawBmpW - Width;
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_XWindow:
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
{ Should be this. }
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
|
||||
Self.XWindowImage := XGetImage(Self.XDisplay, Self.curWindow, xs, ys, width, height, AllPlanes, ZPixmap);
|
||||
if QWord(Self.XWindowImage) = 0 then
|
||||
begin
|
||||
Writeln('ReturnData: XGetImage Error. Dumping data now:');
|
||||
Writeln('xs, ys, width, height: ' + inttostr(xs) + ', ' + inttostr(ys) +
|
||||
', ' + inttostr(width) + ', ' + inttostr(height));
|
||||
Result.Ptr := nil;
|
||||
Result.IncPtrWith := 0;
|
||||
|
||||
XSetErrorHandler(Old_Handler);
|
||||
Exit;
|
||||
end;
|
||||
WriteLn(IntToStr(Self.XWindowImage^.width) + ', ' + IntToStr(Self.XWindowImage^.height));
|
||||
Result.Ptr := PRGB32(Self.XWindowImage^.data);
|
||||
Result.IncPtrWith := 0;
|
||||
|
||||
XSetErrorHandler(Old_Handler);
|
||||
{$ELSE}
|
||||
WriteLn('Windows doesn''t support XImage');
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_ArrayPtr:
|
||||
begin
|
||||
TmpData := Self.ArrayPtr;
|
||||
Inc(TmpData, ys * Height + xs);
|
||||
Result.Ptr := TmpData;
|
||||
Result.IncPtrWith:= Self.ArraySize.x - width;
|
||||
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMWindow.FreeReturnData;
|
||||
begin
|
||||
if Self.TargetMode <> w_XWindow then
|
||||
begin
|
||||
// throw exception.
|
||||
exit;
|
||||
end;
|
||||
{$IFDEF LINUX}
|
||||
if(QWord(Self.XWindowImage) <> 0) then // 0, nil?
|
||||
begin
|
||||
XDestroyImage(Self.XWindowImage);
|
||||
end;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
// Bugged. For params other than 0, 0, ClientWidth, ClientHeight
|
||||
// if other type than w_XImage
|
||||
|
||||
// Also thread bugged
|
||||
function TMWindow.CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
|
||||
var
|
||||
w,h : Integer;
|
||||
ww, hh: Integer;
|
||||
Raw: TRawImage;
|
||||
Bmp: TBitmap;
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler: TXErrorHandler;
|
||||
Img: PXImage;
|
||||
{$ENDIF}
|
||||
|
||||
begin
|
||||
Self.GetDimensions(w, h);
|
||||
writeln(inttostr(xs) + ', ' + inttostr(ys) + ' : ' + inttostr(xe) + ', ' +
|
||||
inttostr(ye));
|
||||
ww := xe-xs;
|
||||
hh := ye-ys;
|
||||
if(xs < 0) or (ys < 0) or (xe > W) or (ye > H) then
|
||||
begin
|
||||
writeln('Faulty coordinates');
|
||||
exit;
|
||||
end;
|
||||
|
||||
case Self.TargetMode Of
|
||||
w_Window:
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
Result := TBitmap.Create;
|
||||
Result.SetSize(ww+1,hh+1);
|
||||
BitBlt(result.canvas.handle,0,0,ww+1,hh+1,
|
||||
self.TargetDC,xs,ys, SRCCOPY);
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_XWindow:
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
|
||||
Img := XGetImage(Self.XDisplay, Self.curWindow, xs, ys, ww, hh, AllPlanes, ZPixmap);
|
||||
XImageToRawImage(Img, Raw);
|
||||
|
||||
Bmp := TBitmap.Create;
|
||||
Bmp.LoadFromRawImage(Raw, False);
|
||||
Result := Bmp;
|
||||
|
||||
{
|
||||
If you want to use some internal Bitmap system, BitBlt to it here.
|
||||
Don't forget to free Bmp!
|
||||
}
|
||||
//lclintf.BitBlt(Bmps[bitmap].Canvas.Handle, 0, 0, ww + 1, hh + 1, Bmp.Canvas.Handle, xs, ys, SRCCOPY);
|
||||
//Bmp.Free;
|
||||
|
||||
XDestroyImage(Img);
|
||||
XSetErrorHandler(Old_Handler);
|
||||
{$ELSE}
|
||||
writeln('Windows and tXWindow');
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_ArrayPtr:
|
||||
begin
|
||||
|
||||
ArrDataToRawImage(Self.ArrayPtr, Self.ArraySize, Raw);
|
||||
|
||||
Bmp := TBitmap.Create;
|
||||
Bmp.LoadFromRawImage(Raw, False);
|
||||
Result := Bmp;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMWindow.ActivateClient;
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
if TargetMode = w_Window then
|
||||
SetForegroundWindow(Self.TargetHandle);
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
if TargetMode = w_XWindow then
|
||||
XSetInputFocus(Self.XDisplay,Self.CurWindow,RevertToParent,CurrentTime);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{$IFDEF MSWINDOWS} //Probably need one for Linux as well
|
||||
function TMWindow.UpdateDrawBitmap :boolean;
|
||||
var
|
||||
w,h : integer;
|
||||
BmpInfo : Windows.TBitmap;
|
||||
begin
|
||||
GetDimensions(w,h);
|
||||
DrawBitmap.SetSize(w,h);
|
||||
// DrawBitmap.PixelFormat:=
|
||||
DrawBmpW := w;
|
||||
DrawBmpH := h;
|
||||
GetObject(DrawBitmap.Handle, SizeOf(BmpInfo), @BmpInfo);
|
||||
DrawBmpDataPtr := BmpInfo.bmBits;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TMWindow.GetDimensions(var W, H: Integer);
|
||||
{$IFDEF LINUX}
|
||||
var
|
||||
Attrib: TXWindowAttributes;
|
||||
newx,newy : integer;
|
||||
childwindow : x.TWindow;
|
||||
Old_Handler: TXErrorHandler;
|
||||
{$ENDIF}
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
Rect : TRect;
|
||||
{$ENDIF}
|
||||
begin
|
||||
case TargetMode of
|
||||
w_Window:
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
GetWindowRect(Self.TargetHandle, Rect);
|
||||
w:= Rect.Right - Rect.left + 1;
|
||||
h:= Rect.Bottom - Rect.Top + 1;
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_XWindow:
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
if XGetWindowAttributes(Self.XDisplay, Self.CurWindow, @Attrib) <> 0 Then
|
||||
begin
|
||||
XTranslateCoordinates(Self.XDisplay, Self.CurWindow, Self.DesktopWindow, 0,0, @newx, @newy, @childwindow);
|
||||
W := Attrib.Width;
|
||||
H := Attrib.Height;
|
||||
end else
|
||||
begin
|
||||
W := -1;
|
||||
H := -1;
|
||||
end;
|
||||
XSetErrorHandler(Old_Handler);
|
||||
{$ELSE}
|
||||
WriteLn('You dummy! How are you going to use w_XWindow on non Linux systems?');
|
||||
{$ENDIF}
|
||||
end;
|
||||
w_ArrayPtr:
|
||||
begin
|
||||
W := Self.ArraySize.X;
|
||||
H := Self.ArraySize.Y;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
function TMWindow.SetTarget(XWindow: x.TWindow): integer; overload;
|
||||
var
|
||||
Old_Handler: TXErrorHandler;
|
||||
begin
|
||||
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
|
||||
Self.CurWindow := XWindow;
|
||||
Self.TargetMode:= w_XWindow;
|
||||
XSetErrorHandler(Old_Handler);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function TMWindow.SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
|
||||
begin
|
||||
if NewType in [ w_XWindow, w_ArrayPtr ] then
|
||||
begin
|
||||
// throw exception
|
||||
Exit;
|
||||
end;
|
||||
case NewType of
|
||||
w_Window :
|
||||
begin;
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
ReleaseDC(Self.TargetHandle,Self.TargetDC);
|
||||
Self.TargetHandle := Window;
|
||||
Self.TargetDC := GetWindowDC(Window);
|
||||
{$ENDIF}
|
||||
end;
|
||||
end;
|
||||
{$IFDEF MSWINDOWS}
|
||||
UpdateDrawBitmap;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{
|
||||
This functionality is very BETA.
|
||||
We have no way to send events to a window, so we should probably use the
|
||||
desktop window?
|
||||
|
||||
eg: In mouse/keys: if Self.TargetMode not in [w_Window, w_XWindow], send it
|
||||
to the desktop.
|
||||
}
|
||||
function TMWindow.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
|
||||
begin
|
||||
Self.ArrayPtr := ArrPtr;
|
||||
Self.ArraySize := Size;
|
||||
Self.TargetMode:= w_ArrayPtr;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
Self.CurWindow := Self.DesktopWindow;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF WINDOWS}
|
||||
Self.TargetHandle:= windows.GetDesktopWindow;
|
||||
{$ENDIF}
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
134
project1.lpi
134
project1.lpi
@ -38,7 +38,7 @@
|
||||
<CursorPos X="1" Y="19"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="51"/>
|
||||
<UsageCount Value="53"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
@ -49,7 +49,7 @@
|
||||
<UnitName Value="TestUnit"/>
|
||||
<CursorPos X="33" Y="57"/>
|
||||
<TopLine Value="32"/>
|
||||
<UsageCount Value="51"/>
|
||||
<UsageCount Value="53"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="client.pas"/>
|
||||
@ -57,7 +57,7 @@
|
||||
<UnitName Value="Client"/>
|
||||
<CursorPos X="18" Y="34"/>
|
||||
<TopLine Value="10"/>
|
||||
<UsageCount Value="51"/>
|
||||
<UsageCount Value="53"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="../cogat/Units/CogatUnits/comptypes.pas"/>
|
||||
@ -72,7 +72,7 @@
|
||||
<UnitName Value="MufasaTypes"/>
|
||||
<CursorPos X="52" Y="20"/>
|
||||
<TopLine Value="1"/>
|
||||
<UsageCount Value="51"/>
|
||||
<UsageCount Value="53"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
<Filename Value="window.pas"/>
|
||||
@ -80,7 +80,7 @@
|
||||
<UnitName Value="Window"/>
|
||||
<CursorPos X="4" Y="100"/>
|
||||
<TopLine Value="85"/>
|
||||
<UsageCount Value="51"/>
|
||||
<UsageCount Value="53"/>
|
||||
</Unit5>
|
||||
<Unit6>
|
||||
<Filename Value="../Documents/fpc/rtl/inc/systemh.inc"/>
|
||||
@ -94,7 +94,7 @@
|
||||
<UnitName Value="Input"/>
|
||||
<CursorPos X="5" Y="20"/>
|
||||
<TopLine Value="15"/>
|
||||
<UsageCount Value="50"/>
|
||||
<UsageCount Value="52"/>
|
||||
</Unit7>
|
||||
<Unit8>
|
||||
<Filename Value="../cogat/Units/CogatUnits/compinput.pas"/>
|
||||
@ -109,7 +109,7 @@
|
||||
<CursorPos X="46" Y="8"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="5"/>
|
||||
<UsageCount Value="22"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit9>
|
||||
<Unit10>
|
||||
@ -118,35 +118,35 @@
|
||||
<CursorPos X="1" Y="1"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<UsageCount Value="22"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit10>
|
||||
<Unit11>
|
||||
<Filename Value="Units/MMLCore/mufasatypes.pas"/>
|
||||
<UnitName Value="MufasaTypes"/>
|
||||
<CursorPos X="1" Y="18"/>
|
||||
<CursorPos X="1" Y="1"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<UsageCount Value="22"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit11>
|
||||
<Unit12>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<UnitName Value="Window"/>
|
||||
<CursorPos X="52" Y="394"/>
|
||||
<TopLine Value="394"/>
|
||||
<CursorPos X="5" Y="316"/>
|
||||
<TopLine Value="291"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<UsageCount Value="22"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit12>
|
||||
<Unit13>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="windowutil"/>
|
||||
<CursorPos X="53" Y="122"/>
|
||||
<TopLine Value="98"/>
|
||||
<CursorPos X="54" Y="20"/>
|
||||
<TopLine Value="80"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<UsageCount Value="43"/>
|
||||
<UsageCount Value="45"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit13>
|
||||
<Unit14>
|
||||
@ -182,10 +182,10 @@
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="TestUnit"/>
|
||||
<CursorPos X="41" Y="71"/>
|
||||
<TopLine Value="54"/>
|
||||
<CursorPos X="37" Y="112"/>
|
||||
<TopLine Value="103"/>
|
||||
<EditorIndex Value="4"/>
|
||||
<UsageCount Value="19"/>
|
||||
<UsageCount Value="20"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit18>
|
||||
<Unit19>
|
||||
@ -287,123 +287,123 @@
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="215" Column="10" TopLine="205"/>
|
||||
<Caret Line="10" Column="10" TopLine="1"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="225" Column="19" TopLine="215"/>
|
||||
<Caret Line="367" Column="46" TopLine="353"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="239" Column="19" TopLine="229"/>
|
||||
<Caret Line="115" Column="36" TopLine="106"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="261" Column="17" TopLine="251"/>
|
||||
<Caret Line="114" Column="24" TopLine="99"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="68" Column="20" TopLine="53"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="94" Column="26" TopLine="79"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="329" Column="14" TopLine="298"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="58" Column="78" TopLine="45"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="10" Column="10" TopLine="1"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="63" Column="37" TopLine="48"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="367" Column="46" TopLine="353"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="69" Column="41" TopLine="68"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="115" Column="36" TopLine="106"/>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="73" Column="37" TopLine="64"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="114" Column="24" TopLine="99"/>
|
||||
<Caret Line="26" Column="40" TopLine="11"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="94" Column="26" TopLine="79"/>
|
||||
<Caret Line="276" Column="28" TopLine="250"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="58" Column="78" TopLine="45"/>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="22" Column="5" TopLine="12"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="63" Column="37" TopLine="48"/>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="48" Column="39" TopLine="32"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="69" Column="41" TopLine="68"/>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="52" Column="50" TopLine="39"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="testunit.pas"/>
|
||||
<Caret Line="73" Column="37" TopLine="64"/>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="9" Column="10" TopLine="1"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="26" Column="40" TopLine="11"/>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="10" Column="17" TopLine="1"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="276" Column="28" TopLine="250"/>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="11" Column="3" TopLine="1"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="22" Column="5" TopLine="12"/>
|
||||
<Caret Line="12" Column="13" TopLine="1"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="48" Column="39" TopLine="32"/>
|
||||
<Caret Line="88" Column="1" TopLine="1"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="52" Column="50" TopLine="39"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="275" Column="60" TopLine="251"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="9" Column="10" TopLine="1"/>
|
||||
<Filename Value="Units/MMLCore/client.pas"/>
|
||||
<Caret Line="8" Column="46" TopLine="1"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="10" Column="17" TopLine="1"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="419" Column="3" TopLine="390"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="11" Column="3" TopLine="1"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="382" Column="66" TopLine="369"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="12" Column="13" TopLine="1"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="202" Column="11" TopLine="187"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="Units/MMLCore/windowutil.pas"/>
|
||||
<Caret Line="88" Column="1" TopLine="1"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="1" Column="1" TopLine="171"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="275" Column="60" TopLine="251"/>
|
||||
<Caret Line="180" Column="31" TopLine="175"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="Units/MMLCore/client.pas"/>
|
||||
<Caret Line="8" Column="46" TopLine="1"/>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="190" Column="23" TopLine="175"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="419" Column="3" TopLine="390"/>
|
||||
<Caret Line="198" Column="65" TopLine="176"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="382" Column="66" TopLine="369"/>
|
||||
<Caret Line="26" Column="40" TopLine="6"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="Units/MMLCore/window.pas"/>
|
||||
<Caret Line="202" Column="11" TopLine="187"/>
|
||||
<Caret Line="27" Column="37" TopLine="1"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
|
42
testunit.lfm
42
testunit.lfm
@ -1,21 +1,21 @@
|
||||
object Form1: TForm1
|
||||
Left = 462
|
||||
Height = 527
|
||||
Top = 227
|
||||
Width = 779
|
||||
ActiveControl = Button1
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 527
|
||||
ClientWidth = 779
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '0.9.29'
|
||||
object Button1: TButton
|
||||
Left = 69
|
||||
Height = 25
|
||||
Top = 32
|
||||
Width = 75
|
||||
Caption = 'Button1'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
object Form1: TForm1
|
||||
Left = 320
|
||||
Height = 527
|
||||
Top = 238
|
||||
Width = 779
|
||||
ActiveControl = Button1
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 527
|
||||
ClientWidth = 779
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '0.9.29'
|
||||
object Button1: TButton
|
||||
Left = 69
|
||||
Height = 25
|
||||
Top = 32
|
||||
Width = 75
|
||||
Caption = 'Button1'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
||||
|
18
testunit.lrs
18
testunit.lrs
@ -1,10 +1,10 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#206#1#6'Height'#3#15#2#3'Top'#3#227#0#5'W'
|
||||
+'idth'#3#11#3#13'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'Client'
|
||||
+'Height'#3#15#2#11'ClientWidth'#3#11#3#8'Position'#7#14'poScreenCenter'#10'L'
|
||||
+'CLVersion'#6#6'0.9.29'#0#7'TButton'#7'Button1'#4'Left'#2'E'#6'Height'#2#25#3
|
||||
+'Top'#2' '#5'Width'#2'K'#7'Caption'#6#7'Button1'#7'OnClick'#7#12'Button1Clic'
|
||||
+'k'#8'TabOrder'#2#0#0#0#0
|
||||
]);
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'@'#1#6'Height'#3#15#2#3'Top'#3#238#0#5'Wi'
|
||||
+'dth'#3#11#3#13'ActiveControl'#7#7'Button1'#7'Caption'#6#5'Form1'#12'ClientH'
|
||||
+'eight'#3#15#2#11'ClientWidth'#3#11#3#8'Position'#7#14'poScreenCenter'#10'LC'
|
||||
+'LVersion'#6#6'0.9.29'#0#7'TButton'#7'Button1'#4'Left'#2'E'#6'Height'#2#25#3
|
||||
+'Top'#2' '#5'Width'#2'K'#7'Caption'#6#7'Button1'#7'OnClick'#7#12'Button1Clic'
|
||||
+'k'#8'TabOrder'#2#0#0#0#0
|
||||
]);
|
||||
|
312
testunit.pas
312
testunit.pas
@ -1,149 +1,163 @@
|
||||
unit TestUnit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, Client, MufasaTypes;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Button1: TButton;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
TMyThread = class(TThread)
|
||||
private
|
||||
protected
|
||||
procedure Execute; override;
|
||||
public
|
||||
Constructor Create(CreateSuspended : boolean);
|
||||
end;
|
||||
|
||||
constructor TMyThread.Create(CreateSuspended : boolean);
|
||||
begin
|
||||
FreeOnTerminate := True;
|
||||
inherited Create(CreateSuspended);
|
||||
end;
|
||||
|
||||
procedure TMyThread.Execute;
|
||||
Var
|
||||
Client: TClient;
|
||||
w,h, x, y, xx, yy, i:integer;
|
||||
bmp: TBitmap;
|
||||
ReturnData : TRetData;
|
||||
arr: Array Of Integer;
|
||||
LoopY,LoopX : integer;
|
||||
|
||||
begin
|
||||
while (not Terminated) do
|
||||
begin
|
||||
|
||||
Writeln('Creating the client');
|
||||
Client := TClient.Create;
|
||||
Writeln('Getting the dimensions');
|
||||
Client.MWindow.GetDimensions(w, h);
|
||||
writeln(inttostr(w) + ' , ' + inttostr(h));
|
||||
Writeln('Setting target');
|
||||
// Client.MWindow.SetTarget(67232,w_window);
|
||||
|
||||
{ SetLength(Arr, 9);
|
||||
for i := 0 to high(arr) do
|
||||
arr[i] := $FFFFFF;
|
||||
|
||||
Client.MWIndow.SetTarget(PRGB32(@Arr[0]), Point(3, 3)); }
|
||||
|
||||
// Client.MWindow.ActivateClient;
|
||||
Client.MWindow.GetDimensions(w, h);
|
||||
Writeln('Copying BMP');
|
||||
bmp := Client.MWindow.CopyClientToBitmap(0, 0, w, h);
|
||||
|
||||
{$IFDEF WINDOWS}
|
||||
bmp.SaveToFile('c:\test1.bmp');
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
bmp.SaveToFile('/tmp/test1.bmp');
|
||||
{$ENDIF}
|
||||
// bmp.Free;
|
||||
|
||||
//Sleep(1000);
|
||||
Client.MInput.GetMousePos(x, y);
|
||||
writeln(inttostr(x) + ' , ' + inttostr(y));
|
||||
|
||||
Client.MInput.SetMousePos(50, 50);
|
||||
Client.MInput.GetMousePos(x, y);
|
||||
writeln(inttostr(x) + ' , ' + inttostr(y));
|
||||
|
||||
Client.MInput.ClickMouse(60, 60, mouse_Right);
|
||||
LoopX:= w div 2;
|
||||
LoopY:= h div 2;
|
||||
bmp.SetSize(Loopx + 1, Loopy + 1);
|
||||
ReturnData := Client.MWindow.ReturnData(0, 0, Loopx + 1, Loopy + 1);
|
||||
SetLength(Arr,(Loopy + 1) * (Loopx + 1));
|
||||
for yy := 0 to Loopy do
|
||||
begin;
|
||||
for xx := 0 to Loopx do
|
||||
begin
|
||||
{ Do comparison here }
|
||||
Arr[yy * (loopx + 1) + xx] :=RGBToColor(ReturnData.Ptr^.B,ReturnData.Ptr^.G,ReturnData.Ptr^.R);
|
||||
Bmp.Canvas.Pixels[xx,yy] := clwhite xor RGBToColor(ReturnData.Ptr^.R,ReturnData.Ptr^.G,ReturnData.Ptr^.B);
|
||||
inc(ReturnData.Ptr);
|
||||
end;
|
||||
Inc(ReturnData.Ptr,ReturnData.IncPtrWith);
|
||||
end;
|
||||
{$IFDEF WINDOWS}
|
||||
bmp.SaveToFile('c:\test2.bmp');
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
bmp.SaveToFile('/tmp/test2.bmp');
|
||||
{$ENDIF}
|
||||
Bmp.free;
|
||||
// Client.MWIndow.SetTarget(PRGB32(@Arr[0]), Point(Loopx + 1, Loopy + 1));
|
||||
Client.MWindow.FreeReturnData;
|
||||
|
||||
Client.MInput.IsMouseButtonDown(mouse_Left);
|
||||
Sleep(1000);
|
||||
if Client.MInput.IsMouseButtonDown(mouse_Left) then
|
||||
writeln('Left mouse is down!');
|
||||
if Client.MInput.IsMouseButtonDown(mouse_Right) then
|
||||
writeln('Right mouse is down!');
|
||||
if Client.MInput.IsMouseButtonDown(mouse_Middle) then
|
||||
writeln('Middle mouse is down!');
|
||||
Client.Destroy;
|
||||
writeln('Test completed successfully');
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
Var
|
||||
MyThread: TMyThread;
|
||||
|
||||
begin
|
||||
MyThread := TMyThread.Create(True);
|
||||
MyThread.Resume;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I testunit.lrs}
|
||||
|
||||
end.
|
||||
|
||||
unit TestUnit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls, Client, MufasaTypes;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Button1: TButton;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
TMyThread = class(TThread)
|
||||
private
|
||||
protected
|
||||
procedure Execute; override;
|
||||
public
|
||||
Constructor Create(CreateSuspended : boolean);
|
||||
end;
|
||||
|
||||
constructor TMyThread.Create(CreateSuspended : boolean);
|
||||
begin
|
||||
FreeOnTerminate := True;
|
||||
inherited Create(CreateSuspended);
|
||||
end;
|
||||
|
||||
procedure TMyThread.Execute;
|
||||
Var
|
||||
Client: TClient;
|
||||
w,h, x, y, xx, yy, i:integer;
|
||||
bmp: TBitmap;
|
||||
ReturnData : TRetData;
|
||||
arr: Array Of Integer;
|
||||
LoopY,LoopX : integer;
|
||||
|
||||
begin
|
||||
while (not Terminated) do
|
||||
begin
|
||||
|
||||
Writeln('Creating the client');
|
||||
Client := TClient.Create;
|
||||
Writeln('Getting the dimensions');
|
||||
Client.MWindow.GetDimensions(w, h);
|
||||
writeln(inttostr(w) + ' , ' + inttostr(h));
|
||||
Writeln('Setting target');
|
||||
// Client.MWindow.SetTarget(67232,w_window);
|
||||
|
||||
{ SetLength(Arr, 9);
|
||||
for i := 0 to high(arr) do
|
||||
arr[i] := $FFFFFF;
|
||||
|
||||
Client.MWIndow.SetTarget(PRGB32(@Arr[0]), Point(3, 3)); }
|
||||
|
||||
// Client.MWindow.ActivateClient;
|
||||
|
||||
Client.MWindow.GetDimensions(w, h);
|
||||
Writeln('Copying BMP');
|
||||
bmp := Client.MWindow.CopyClientToBitmap(0, 0, w, h);
|
||||
Writeln('Saving BMP');
|
||||
|
||||
{$IFDEF WINDOWS}
|
||||
bmp.SaveToFile('c:\test1.bmp');
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
bmp.SaveToFile('/tmp/test1.bmp');
|
||||
{$ENDIF}
|
||||
|
||||
writeln('Copied Bitmap');
|
||||
// bmp.Free;
|
||||
|
||||
//Sleep(1000);
|
||||
Client.MInput.GetMousePos(x, y);
|
||||
writeln(inttostr(x) + ' , ' + inttostr(y));
|
||||
|
||||
Client.MInput.SetMousePos(50, 50);
|
||||
Client.MInput.GetMousePos(x, y);
|
||||
writeln(inttostr(x) + ' , ' + inttostr(y));
|
||||
|
||||
Client.MInput.ClickMouse(60, 60, mouse_Right);
|
||||
|
||||
LoopX:= w div 2;
|
||||
LoopY:= h div 2;
|
||||
bmp.SetSize(Loopx + 1, Loopy + 1);
|
||||
ReturnData := Client.MWindow.ReturnData(0, 0, Loopx + 1, Loopy + 1);
|
||||
|
||||
SetLength(Arr,(Loopy + 1) * (Loopx + 1));
|
||||
|
||||
for yy := 0 to Loopy do
|
||||
begin;
|
||||
for xx := 0 to Loopx do
|
||||
begin
|
||||
{ Do comparison here }
|
||||
Arr[yy * (loopx + 1) + xx] :=RGBToColor(ReturnData.Ptr^.B,ReturnData.Ptr^.G,ReturnData.Ptr^.R);
|
||||
|
||||
// not thread stable on linux.
|
||||
//Bmp.Canvas.Pixels[xx,yy] := RGBToColor(ReturnData.Ptr^.R,ReturnData.Ptr^.G,ReturnData.Ptr^.B);
|
||||
|
||||
inc(ReturnData.Ptr);
|
||||
end;
|
||||
Inc(ReturnData.Ptr,ReturnData.IncPtrWith);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{$IFDEF WINDOWS}
|
||||
bmp.SaveToFile('c:\test2.bmp');
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
bmp.SaveToFile('/tmp/test2.bmp');
|
||||
{$ENDIF}
|
||||
Bmp.free;
|
||||
|
||||
// Client.MWIndow.SetTarget(PRGB32(@Arr[0]), Point(Loopx + 1, Loopy + 1));
|
||||
Client.MWindow.FreeReturnData;
|
||||
|
||||
Client.MInput.IsMouseButtonDown(mouse_Left);
|
||||
Sleep(1000);
|
||||
if Client.MInput.IsMouseButtonDown(mouse_Left) then
|
||||
writeln('Left mouse is down!');
|
||||
if Client.MInput.IsMouseButtonDown(mouse_Right) then
|
||||
writeln('Right mouse is down!');
|
||||
if Client.MInput.IsMouseButtonDown(mouse_Middle) then
|
||||
writeln('Middle mouse is down!');
|
||||
Client.Destroy;
|
||||
writeln('Test completed successfully');
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
Var
|
||||
MyThread: TMyThread;
|
||||
|
||||
begin
|
||||
MyThread := TMyThread.Create(True);
|
||||
MyThread.Resume;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I testunit.lrs}
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user