cheat-engine/Cheat Engine/Tutorial/graphical/guiobject.pas

86 lines
2.1 KiB
ObjectPascal
Raw Permalink Normal View History

unit guiobject;
//not part of the game mechanics, but handles click events and wraps basic gui stuff like text
{$mode objfpc}{$H+}
interface
uses
2017-10-25 01:41:39 +02:00
Classes, SysUtils, controls, renderobject, gamepanel, types;
type
2017-10-25 01:41:39 +02:00
TNotifyEventF=function(sender: TObject): boolean of object;
TGUIObject=class(TRenderObject) //abstract
private
fOwner: TGamePanel;
2017-10-25 01:41:39 +02:00
protected
2017-10-25 01:41:39 +02:00
fOnClick: TNotifyEventF;
function getWidth:single; override;
function getHeight:single; override;
2017-10-25 01:41:39 +02:00
function getTopLeftCorner: tpointf;
function mhandler(sender: TObject; meventtype: integer; Button: TMouseButton; Shift: TShiftState; mX, mY: Integer): boolean; virtual;
public
constructor create(owner: TGamePanel=nil; zpos: integer=-1);
2017-10-27 12:49:03 +02:00
destructor destroy; override;
2017-10-25 01:41:39 +02:00
property OnClick: TNotifyEventF read fOnClick write fOnClick;
end;
implementation
2017-10-25 01:41:39 +02:00
function TGUIObject.getTopLeftCorner: TPointF;
begin
//only functions when no rotation is applied
result.x:=x-(width/2)*(rotationpoint.x+1);
result.y:=y-(height/2)*(rotationpoint.y+1);
end;
2017-10-24 21:31:06 +02:00
function TGUIObject.getWidth:single;
begin
result:=2;
end;
2017-10-24 21:31:06 +02:00
function TGUIObject.getHeight:single;
begin
result:=2;
end;
2017-10-24 21:31:06 +02:00
function TGUIObject.mhandler(sender: TObject; meventtype: integer; Button: TMouseButton; Shift: TShiftState; mX, mY: Integer): boolean;
2017-10-25 01:41:39 +02:00
var gamepos, objectpos: tpointf;
begin
2017-10-25 01:41:39 +02:00
if meventtype=0 then
begin
gamepos:=TGamePanel(sender).PixelPosToGamePos(mx,my);
objectpos:=getTopLeftCorner;
if (gamepos.x>=objectpos.x) and (gamepos.x<objectpos.x+width) and (gamepos.y>=objectpos.y) and (gamepos.y<objectpos.y+height) then
begin
if assigned(fOnClick) then
exit(fOnClick(self));
end;
end;
result:=false;
end;
2017-10-24 21:31:06 +02:00
constructor TGUIObject.create(owner: TGamePanel; zpos: integer);
begin
2017-10-27 12:49:03 +02:00
fowner:=owner;
if owner<>nil then
owner.AddMouseEventHandler(@mhandler, zpos);
inherited create;
end;
2017-10-27 12:49:03 +02:00
destructor TGUIObject.destroy;
begin
2017-11-07 02:42:53 +01:00
if fowner<>nil then
fowner.RemoveMouseEventHandler(@mhandler);
2017-10-27 12:49:03 +02:00
inherited destroy;
end;
end.