Jump to content
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

Featured Replies

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.


Guest
Reply to this topic...

Important Information

Privacy Policy | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.