TButtonState = (bsOnClick, bsOnHold, bsOnRelease, bsOff);
TButtonStateHelper = record helper for TButtonState
function ToString: string;
end;
TMouseButton = record
Left: TButtonState;
Middle: TButtonState;
Right: TButtonState;
end;
TMouse = record
Wheel: TVector;
Location: TPoint;
Button: TMouseButton;
end;
// Returns all mouse stuff in one call
procedure ...GetMouse;
begin
Mouse.Location := LWindow.GetMousePos;
Mouse.Wheel := LWindow.GetMouseWheel;
if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_LEFT, isWasReleased) then Mouse.Button.Left := bsOnRelease
else if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_LEFT, isWasPressed) then Mouse.Button.Left := bsOnClick
else if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_LEFT, isPressed) then Mouse.Button.Left := bsOnHold
else Mouse.Button.Left := bsOff;
if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_MIDDLE, isWasReleased) then Mouse.Button.Middle := bsOnRelease
else if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_MIDDLE, isWasPressed) then Mouse.Button.Middle := bsOnClick
else if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_MIDDLE, isPressed) then Mouse.Button.Middle := bsOnHold
else Mouse.Button.Middle := bsOff;
if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_RIGHT, isWasReleased) then Mouse.Button.Right := bsOnRelease
else if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_RIGHT, isWasPressed) then Mouse.Button.Right := bsOnClick
else if LWindow.GetMouseButton(Mamba.Core.MOUSE_BUTTON_RIGHT, isPressed) then Mouse.Button.Right := bsOnHold
else Mouse.Button.Right := bsOff;
end;
{ TTInputStateHelper }
function TButtonStateHelper.ToString: string;
begin
Result := 'Undefined';
case Self of
bsOff: Result := 'Off';
bsOnHold: Result := 'Pressed';
bsOnClick: Result := 'Was Pressed'; // Is newly pressed
bsOnRelease: Result := 'Was Released'; // Is newly off
end;
end;
Link to comment
https://mambagametoolkit.com/forums/topic/10-mouse-helper-code/Share on other sites