Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 10, 2023
1 parent eed380a commit d06ad21
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 263 deletions.
3 changes: 3 additions & 0 deletions Source/colormath/simba.colormath.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ interface
function AsString: String;
end;

TColor = Graphics.TColor;
PColor = ^TColor;

TColorHelper = type helper for TColor
function ToBGRA: TColorBGRA;
function ToRGB: TColorRGB;
Expand Down
11 changes: 11 additions & 0 deletions Source/components/simba.component_menubar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ TSimbaMainMenuBar = class(TCustomControl)
function GetMenus: TPopupMenuArray;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

property Menus: TPopupMenuArray read GetMenus;
procedure AddMenu(Title: String; APopupMenu: TPopupMenu);
Expand Down Expand Up @@ -235,6 +236,8 @@ procedure TSimbaMainMenuBar.MouseLeave;

procedure TSimbaMainMenuBar.DoMenuClose(Sender: TObject);
begin
if (FTrackTimer = nil) then
Exit;
FTrackTimer.Enabled := False;

Application.QueueAsyncCall(@ClearPopupIndex, 0);
Expand Down Expand Up @@ -286,6 +289,14 @@ constructor TSimbaMainMenuBar.Create(AOwner: TComponent);
CalculateSizes();
end;

destructor TSimbaMainMenuBar.Destroy;
begin
Application.RemoveAsyncCalls(Self);
FTrackTimer := nil;

inherited Destroy();
end;

procedure TSimbaMainMenuBar.AddMenu(Title: String; APopupMenu: TPopupMenu);
var
I: Integer;
Expand Down
10 changes: 4 additions & 6 deletions Source/components/simba.component_statusbar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TSimbaStatusBar = class(TCustomControl)
procedure Paint; override;
procedure PaintPanel(Index: Integer);

procedure InvalidatePanel(Index: Integer);
procedure InvalidatePanelASync(Data: PtrInt);
function PanelRect(Index: Integer): TRect;

procedure CheckIndex(Index: Integer);
Expand Down Expand Up @@ -78,10 +78,9 @@ procedure TSimbaStatusBar.SetPanelText(Index: Integer; Value: String);
begin
if (FPanelText[Index] = Value) then
Exit;

FPanelText[Index] := Value;

InvalidatePanel(Index);
Application.QueueAsyncCall(@InvalidatePanelASync, Index);
end;

procedure TSimbaStatusBar.SetPanelTextMeasure(Index: Integer; Value: String);
Expand Down Expand Up @@ -194,11 +193,11 @@ procedure TSimbaStatusBar.PaintPanel(Index: Integer);
Canvas.TextRect(R, R.Left + 5, R.Top, FPanelText[Index], Style);
end;

procedure TSimbaStatusBar.InvalidatePanel(Index: Integer);
procedure TSimbaStatusBar.InvalidatePanelASync(Data: PtrInt);
var
R: TRect;
begin
R := PanelRect(Index);
R := PanelRect(Data);

InvalidateRect(Handle, @R, False);
end;
Expand Down Expand Up @@ -226,4 +225,3 @@ function TSimbaStatusBar.PanelRect(Index: Integer): TRect;
end;

end.

4 changes: 2 additions & 2 deletions Source/imagebox/simba.imagebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface

uses
Classes, SysUtils, Forms, Controls, Graphics, ComCtrls, LCLType,
Classes, SysUtils, Forms, Controls, Graphics, GraphType, ComCtrls, LCLType,
simba.mufasatypes, simba.image, simba.dtm, simba.imagebox_image,
simba.colormath;

Expand Down Expand Up @@ -112,7 +112,7 @@ TSimbaImageBox = class(TWinControl)
implementation

uses
Math, GraphType, LCLIntf,
Math, LCLIntf,
simba.finder, simba.image_lazbridge, simba.windowhandle;

procedure TSimbaImageBox_ScrollBox.GetPreferredSize(var PreferredWidth, PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean);
Expand Down
3 changes: 1 addition & 2 deletions Source/simba.darwin_axui.pas
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ function AXUI_GetWindowInfo(PID: UInt32): TAXUIWindowInfo;
end;

initialization
SimbaIDEInitialization_AddBeforeShow(@RequestAccessibility, 'RequestAccessibility');
//SimbaIDEInitialization_AddBeforeShow(@RequestAccessibility, 'RequestAccessibility');

CreateCFStrings();

end.

1 change: 1 addition & 0 deletions Source/simba.ide_events.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SimbaIDEEvents = class


// Called every 500ms from a script instance while a script is running.
// Called on a seperate thread - synchronize if doing GUI stuff!
// Sender = TSimbaScriptInstance
class procedure CallOnScriptRunning(Sender: TObject);
class procedure RegisterMethodOnScriptRunning(Proc: TNotifyEvent);
Expand Down
15 changes: 11 additions & 4 deletions Source/simba.input.pas
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ interface
EMouseEventType = (TELEPORT, MOVING, CLICK, DOWN, UP);
{$SCOPEDENUMS OFF}
const
DEFAULT_KEY_PRESS_MIN = 30;
DEFAULT_KEY_PRESS_MAX = 140;
DEFAULT_KEY_PRESS_MIN = 20;
DEFAULT_KEY_PRESS_MAX = 125;

DEFAULT_CLICK_MIN = 40;
DEFAULT_CLICK_MAX = 220;
Expand Down Expand Up @@ -389,9 +389,16 @@ procedure TSimbaInput.MouseScroll(Scrolls: Integer);
procedure TSimbaInput.KeySend(Text: String);
var
I: Integer;
SleepTimes: TIntegerArray;
begin
for I := 1 to Length(Text) do
Target.KeySend(Text[I], GetRandomKeyPressTime() div 2, GetRandomKeyPressTime() div 2, GetRandomKeyPressTime() div 2, GetRandomKeyPressTime() div 2);
if (Length(Text) = 0) then
Exit;

SetLength(SleepTimes, Length(Text) * 5);
for I := 0 to High(SleepTimes) do
SleepTimes[I] := GetRandomKeyPressTime();

Target.KeySend(PChar(Text), @SleepTimes[0]);
end;

procedure TSimbaInput.KeyPress(Key: EKeyCode);
Expand Down
38 changes: 1 addition & 37 deletions Source/simba.nativeinterface.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ interface
type
TSimbaNativeInterface = class
public
procedure KeyDownNativeKeyCode(EKeyCode: Integer); virtual; abstract;
procedure KeyUpNativeKeyCode(EKeyCode: Integer); virtual; abstract;

function GetNativeKeyCodeAndModifiers(Character: Char; out Code: Integer; out Modifiers: TShiftState): Boolean; virtual; abstract;

function GetWindowImage(Window: TWindowHandle; X, Y, Width, Height: Integer; var ImageData: PColorBGRA): Boolean; virtual; abstract;
function GetWindowBounds(Window: TWindowHandle; out Bounds: TBox): Boolean; virtual; abstract;
function GetWindowBounds(Window: TWindowHandle): TBox; virtual; abstract;
Expand All @@ -34,6 +29,7 @@ TSimbaNativeInterface = class
function GetMousePosition: TPoint; virtual; abstract;
function GetMousePosition(Window: TWindowHandle): TPoint; virtual; abstract;

procedure KeySend(Text: PChar; TextLen: Integer; SleepTimes: PInt32); virtual; abstract;
function KeyPressed(Key: EKeyCode): Boolean; virtual; abstract;
procedure KeyDown(Key: EKeyCode); virtual; abstract;
procedure KeyUp(Key: EKeyCode); virtual; abstract;
Expand Down Expand Up @@ -84,8 +80,6 @@ TSimbaNativeInterface = class
procedure OpenURL(URL: String); virtual;

function GetVirtualKeyCode(Character: Char): Integer; virtual;

procedure KeySend(Key: Char; KeyDownTime, KeyUpTime, ModifierDownTime, ModifierUpTime: Integer); virtual;
end;

var
Expand All @@ -109,36 +103,6 @@ implementation
simba.nativeinterface_darwin;
{$ENDIF}

procedure TSimbaNativeInterface.KeySend(Key: Char; KeyDownTime, KeyUpTime, ModifierDownTime, ModifierUpTime: Integer);
var
NativeKeyCode: Integer;
KeyModifiers: TShiftState;
begin
if not GetNativeKeyCodeAndModifiers(Key, NativeKeyCode, KeyModifiers) then
raise Exception.CreateFmt('TSimbaNativeInterface.SendChar: Unknown key code for "%s"', [Key]);

if (KeyModifiers <> []) then
begin
if (ssShift in KeyModifiers) then KeyDown(EKeyCode.SHIFT);
if (ssCtrl in KeyModifiers) then KeyDown(EKeyCode.CONTROL);
if (ssAlt in KeyModifiers) then KeyDown(EKeyCode.MENU);

PreciseSleep(ModifierDownTime);
end;

KeyDownNativeKeyCode(NativeKeyCode); PreciseSleep(KeyDownTime);
KeyUpNativeKeyCode(NativeKeyCode); PreciseSleep(KeyUpTime);

if (KeyModifiers <> []) then
begin
if (ssShift in KeyModifiers) then KeyUp(EKeyCode.SHIFT);
if (ssCtrl in KeyModifiers) then KeyUp(EKeyCode.CONTROL);
if (ssAlt in KeyModifiers) then KeyUp(EKeyCode.MENU);

PreciseSleep(ModifierUpTime);
end;
end;

function TSimbaNativeInterface.WindowHandleToStr(WindowHandle: TWindowHandle): String;
begin
Result := IntToStr(WindowHandle);
Expand Down
Loading

0 comments on commit d06ad21

Please sign in to comment.