Joystick position: Difference between revisions

no edit summary
No edit summary
Line 438:
90 poke sc+ox+oy*40,32
100 goto 20</lang>
=={{header|Delphi}}==
{{libheader|mmSystem}}
Form application version.
<lang Delphi>
unit uMain;
 
interface
 
uses
Winapi.Windows, System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms,
Vcl.ExtCtrls, Vcl.StdCtrls;
 
type
TForm1 = class(TForm)
tmr1: TTimer;
lblPosition: TLabel;
procedure tmr1Timer(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DrawCrosshair(X, Y: Integer);
end;
 
var
Form1: TForm1;
X: Integer = 0;
Y: Integer = 0;
 
implementation
 
uses
mmSystem, Vcl.Graphics;
 
{$R *.dfm}
 
procedure TForm1.DrawCrosshair(X, Y: Integer);
const
RADIUS = 10;
CROSS = 3;
begin
Canvas.Brush.Color := clblack;
Canvas.FillRect(ClientRect);
with Canvas do
begin
Pen.Color := clWhite;
pen.Width := 1;
Ellipse(X - RADIUS, Y - RADIUS, X + RADIUS, Y + RADIUS);
pen.Width := 2;
MoveTo(X - CROSS * RADIUS, Y);
LineTo(X + CROSS * RADIUS, Y);
MoveTo(X, Y - CROSS * RADIUS);
LineTo(X, Y + CROSS * RADIUS);
end;
end;
 
procedure TForm1.FormPaint(Sender: TObject);
begin
DrawCrosshair(X, Y);
end;
 
procedure TForm1.tmr1Timer(Sender: TObject);
var
info: TJoyInfo;
begin
if (joyGetPos(0, @info) = 0) then
begin
X := Round(ClientWidth * info.wXpos / MAXWORD);
Y := Round(ClientHeight * info.wYpos / MAXWORD);
lblPosition.Caption := Format('(%3d,%3d)', [X, Y]);
Invalidate;
end;
end;
 
end.
</lang>
Form resource:
<lang Delphi>
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 600
ClientWidth = 600
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
object lblPosition: TLabel
Left = 500
Top = 0
Width = 100
Height = 21
Alignment = taCenter
AutoSize = False
Caption = '(0,0)'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWhite
Font.Height = -20
Font.Name = 'Tahoma'
Font.Style = []
ParentFont = False
end
object tmr1: TTimer
Interval = 500
OnTimer = tmr1Timer
end
end
</lang>
{{out}}
Result preview [https://ibb.co/tc0xH3q]
 
 
=={{header|Go}}==
478

edits