mirror of
https://github.com/moparisthebest/Simba
synced 2025-03-03 02:41:54 -05:00
Added the first initial code of Freeze/Unfreeze.
Added more comments in window.pas. Added several exception-raises where required. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@66 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
ae5d0e9d5b
commit
13c2103030
@ -110,16 +110,25 @@ begin
|
|||||||
if y1 > y2 then
|
if y1 > y2 then
|
||||||
Swap(y1,y2);}
|
Swap(y1,y2);}
|
||||||
if x1 < 0 then
|
if x1 < 0 then
|
||||||
x1 := 0;
|
// x1 := 0;
|
||||||
|
raise Exception.createFMT('Any FindColor Function, you did not pass a ' +
|
||||||
|
'correct x1: %d.', [x1]);
|
||||||
if y1 < 0 then
|
if y1 < 0 then
|
||||||
y1 := 0;
|
// y1 := 0;
|
||||||
|
raise Exception.createFMT('Any FindColor Function, you did not pass a ' +
|
||||||
|
'correct y1: %d.', [y1]);
|
||||||
|
|
||||||
TClient(Self.Client).MWindow.GetDimensions(w,h);
|
TClient(Self.Client).MWindow.GetDimensions(w,h);
|
||||||
if (w <> CachedWidth) or (h <> CachedHeight) then
|
if (w <> CachedWidth) or (h <> CachedHeight) then
|
||||||
UpdateCachedValues(w,h);
|
UpdateCachedValues(w,h);
|
||||||
if x2 >= w then
|
if x2 >= w then
|
||||||
x2 := w-1;
|
// x2 := w-1;
|
||||||
|
raise Exception.createFMT('Any FindColor Function, you did not pass a ' +
|
||||||
|
'correct x2: %d.', [x2]);
|
||||||
if y2 >= h then
|
if y2 >= h then
|
||||||
y2 := h-1;
|
// y2 := h-1;
|
||||||
|
raise Exception.createFMT('Any FindColor Function, you did not pass a ' +
|
||||||
|
'correct y2: %d.', [y2]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMFinder.FindColor(var x, y: Integer; Color, x1, y1, x2, y2: Integer): Boolean;
|
function TMFinder.FindColor(var x, y: Integer; Color, x1, y1, x2, y2: Integer): Boolean;
|
||||||
@ -287,8 +296,7 @@ begin
|
|||||||
SetLength(TPA, I);
|
SetLength(TPA, I);
|
||||||
|
|
||||||
Move(ClientTPA[0], TPA[0], i * SizeOf(TPoint));
|
Move(ClientTPA[0], TPA[0], i * SizeOf(TPoint));
|
||||||
{ for xx := 0 to I - 1 do
|
|
||||||
TPA[xx] := ClientTPA[xx];}
|
|
||||||
Result := I > 0;
|
Result := I > 0;
|
||||||
|
|
||||||
TClient(Client).MWindow.FreeReturnData;
|
TClient(Client).MWindow.FreeReturnData;
|
||||||
|
@ -35,8 +35,22 @@ type
|
|||||||
function SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
|
function SetTarget(Window: THandle; NewType: TTargetWindowMode): integer; overload;
|
||||||
function SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
|
function SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
|
||||||
|
|
||||||
|
{
|
||||||
|
Freeze Client Feature.
|
||||||
|
This will force the MWindow unit to Store the current Client's
|
||||||
|
data in whatever internal structure it will use, and returndata /
|
||||||
|
copyclienttobitmap will not renew this data until Unfreeze() is
|
||||||
|
called.
|
||||||
|
}
|
||||||
|
|
||||||
|
function Freeze: boolean;
|
||||||
|
function Unfreeze: boolean;
|
||||||
|
|
||||||
constructor Create(Client: TObject);
|
constructor Create(Client: TObject);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
|
private
|
||||||
|
FreezeState: Boolean;
|
||||||
public
|
public
|
||||||
// Client
|
// Client
|
||||||
Client: TObject;
|
Client: TObject;
|
||||||
@ -95,6 +109,8 @@ type
|
|||||||
ArrayPtr: PRGB32;
|
ArrayPtr: PRGB32;
|
||||||
ArraySize: TPoint;
|
ArraySize: TPoint;
|
||||||
|
|
||||||
|
property Frozen: boolean read FreezeState;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
@ -113,6 +129,9 @@ begin
|
|||||||
|
|
||||||
Self.Client := Client;
|
Self.Client := Client;
|
||||||
|
|
||||||
|
|
||||||
|
Self.FreezeState :=False;
|
||||||
|
|
||||||
Self.ArrayPtr := nil;
|
Self.ArrayPtr := nil;
|
||||||
Self.ArraySize := Classes.Point(-1, -1);
|
Self.ArraySize := Classes.Point(-1, -1);
|
||||||
|
|
||||||
@ -202,12 +221,17 @@ begin
|
|||||||
|
|
||||||
XSetErrorHandler(Old_Handler);
|
XSetErrorHandler(Old_Handler);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
WriteLn('Windows doesn''t support XImage');
|
raise Exception.createFMT('ReturnData: You cannot use ' +
|
||||||
|
'the XImage mode on Windows.', []);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
w_ArrayPtr:
|
w_ArrayPtr:
|
||||||
begin
|
begin
|
||||||
|
// Copy the pointer as we will perform operations on it.
|
||||||
TmpData := Self.ArrayPtr;
|
TmpData := Self.ArrayPtr;
|
||||||
|
|
||||||
|
// Increase the pointer to the specified start of the data.
|
||||||
|
|
||||||
Inc(TmpData, ys * Height + xs);
|
Inc(TmpData, ys * Height + xs);
|
||||||
Result.Ptr := TmpData;
|
Result.Ptr := TmpData;
|
||||||
Result.IncPtrWith:= Self.ArraySize.x - width;
|
Result.IncPtrWith:= Self.ArraySize.x - width;
|
||||||
@ -220,7 +244,13 @@ procedure TMWindow.FreeReturnData;
|
|||||||
begin
|
begin
|
||||||
if Self.TargetMode <> w_XWindow then
|
if Self.TargetMode <> w_XWindow then
|
||||||
begin
|
begin
|
||||||
// throw exception.
|
raise Exception.createFMT('FreeReturnData - Image data must only ' +
|
||||||
|
' be freed with XGetImage', []);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
if FreezeState then
|
||||||
|
begin
|
||||||
|
raise Exception.createFMT('FreeReturnData called when Freeze = True', []);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
{$IFDEF LINUX}
|
{$IFDEF LINUX}
|
||||||
@ -235,11 +265,41 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// This will draw the ENTIRE client to a bitmap.
|
||||||
|
// And ReturnData / CopyClientToBitmap will always use this bitmap.
|
||||||
|
// They must NEVER update, unless Unfreeze is called.
|
||||||
|
|
||||||
|
// I am not entirely sure how to do this, yet.
|
||||||
|
// Best option for now seems to copy the entire data to a PRGB32,
|
||||||
|
// and use it like the ArrPtr mode.
|
||||||
|
|
||||||
|
// I currently added "Frozen", "FreezeState", "Freeze" and "Unfreeze".
|
||||||
|
// We will have to either "abuse" the current system, and set the client to
|
||||||
|
// PtrArray mode, or edit in some extra variables.
|
||||||
|
// (We will still need extra variables to remember the old mode,
|
||||||
|
// to which we will switch back with Unfreeze.)
|
||||||
|
|
||||||
|
// Several ways to do it, what's the best way?
|
||||||
|
|
||||||
|
// Also, should a box be passed to Freeze, or should we just copy the entire
|
||||||
|
// client?
|
||||||
|
|
||||||
|
function TMWindow.Freeze: Boolean;
|
||||||
|
begin
|
||||||
|
Self.FreezeState:=True;
|
||||||
|
raise Exception.createFMT('Freeze: Not yet implemented.', []);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMWindow.Unfreeze: Boolean;
|
||||||
|
begin
|
||||||
|
Self.FreezeState:=False;
|
||||||
|
raise Exception.createFMT('Unfreeze: Not yet implemented.', []);
|
||||||
|
end;
|
||||||
|
|
||||||
// Bugged. For params other than 0, 0, ClientWidth, ClientHeight
|
// Bugged. For params other than 0, 0, ClientWidth, ClientHeight
|
||||||
// if other type than w_XImage
|
// if other type than w_XImage
|
||||||
|
|
||||||
// Also thread bugged
|
// Also possibly thread bugged
|
||||||
function TMWindow.CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
|
function TMWindow.CopyClientToBitmap(xs, ys, xe, ye: integer): TBitmap;
|
||||||
var
|
var
|
||||||
w,h: Integer;
|
w,h: Integer;
|
||||||
@ -297,11 +357,25 @@ begin
|
|||||||
XDestroyImage(Img);
|
XDestroyImage(Img);
|
||||||
XSetErrorHandler(Old_Handler);
|
XSetErrorHandler(Old_Handler);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
writeln('Windows and tXWindow');
|
raise Exception.createFMT('CopyClientToBitmap: You cannot use ' +
|
||||||
|
'the XImage mode on Windows.', []);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
w_ArrayPtr:
|
w_ArrayPtr:
|
||||||
begin
|
begin
|
||||||
|
// Will only work if the coords are 0, 0, w, h.
|
||||||
|
// Otherwise, we will need to perform mem copy/move operations.
|
||||||
|
// Copy it to a XImage-alike structure,
|
||||||
|
// then pass it to ArrDataToRawImage.
|
||||||
|
|
||||||
|
// Basically, Copy the data slices from the array into a XImage,
|
||||||
|
// where the data IS aligned.
|
||||||
|
|
||||||
|
raise Exception.createFMT('Array Data to Bitmap not yet fully ' +
|
||||||
|
'implemented', []);
|
||||||
|
Result := nil;
|
||||||
|
exit;
|
||||||
|
|
||||||
|
|
||||||
ArrDataToRawImage(Self.ArrayPtr, Self.ArraySize, Raw);
|
ArrDataToRawImage(Self.ArrayPtr, Self.ArraySize, Raw);
|
||||||
|
|
||||||
@ -378,7 +452,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
XSetErrorHandler(Old_Handler);
|
XSetErrorHandler(Old_Handler);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
WriteLn('You dummy! How are you going to use w_XWindow on non Linux systems?');
|
raise Exception.createFMT('GetDimensions: You cannot use ' +
|
||||||
|
'the XImage mode on Windows.', []);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
w_ArrayPtr:
|
w_ArrayPtr:
|
||||||
@ -405,7 +480,7 @@ function TMWindow.SetTarget(Window: THandle; NewType: TTargetWindowMode): intege
|
|||||||
begin
|
begin
|
||||||
if NewType in [ w_XWindow, w_ArrayPtr ] then
|
if NewType in [ w_XWindow, w_ArrayPtr ] then
|
||||||
begin
|
begin
|
||||||
// throw exception
|
raise Exception.createFMT('SetTarget: Invalid new type.', []);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
case NewType of
|
case NewType of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user