Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   SDL2 en Delphi (https://www.clubdelphi.com/foros/showthread.php?t=94384)

MaxiDucoli 13-01-2020 03:13:41

SDL2 en Delphi
 
Buenas noches (acá en Argentina)
Estoy teniendo un problema con las librerías SDL2 para Delphi que no puedo resolver y en la web están todos los códigos fuentes como yo lo estoy haciendo.
Quizás alguien que entienda un poco me pueda guiar en qué estoy haciendo mal.

El asunto es el siguiente:

Estoy queriendo hacer que al presionar un botón del joystick, el programa se dé cuenta y me diga qué joystick es, el nombre el GUID, etc,etc.
Pero no me reconoce las presiones de los botones.

El código es el siguiente:

Código Delphi [-]
unit GetSDL2Joy;


interface

uses
  SDL2,Forms, System.Classes,sysutils,dialogs,Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);

  private
  public
  end;

var
  Form1: TForm1;
  NJoysticks : integer;
  SDL_JOY : PSDL_JOYSTICK;

implementation

{$R *.dfm}

function SDL_JOYS() : string;
var
i :integer;
s : String;
sdlEvent: PSDL_Event;
exitloop: boolean;
begin
NJoysticks := SDL_NumJoysticks;
if SDL_Init(SDL_INIT_JOYSTICK) = -1 then  ShowMessage('No Joysticks Found');
if  NJoysticks >= 1 then
    begin
        SDL_JOY := SDL_JoystickOpen(0);
          if SDL_JOY = nil then ShowMessage('Joystick open error');
    end;

    for i := 0 to NJoysticks -1  do
      begin
      SDL_JOY := SDL_JoystickOpen(i);
      SDL_JoystickEventState(SDL_ENABLE);
      SDL_JOYSTICKUPDATE();
     // s := SDL_JoystickName(SDL_JOY);

          new( sdlEvent );
               while SDL_PollEvent( sdlEvent) = 1 do
                begin
                      case Evento^.type_ of

                      SDL_JOYBUTTONDOWN: begin
                      s :=  'FUNCIONA!!!!!!';
                      end;

                end;;

 SDL_JoystickClose(SDL_JOY);

 Result := s;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//NJoysticks := SDL_NumJoysticks;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Memo1.Text := SDL_JOYS();

end;

end.

Por lo que creo, en el while del evento SDL_JOYBUTTONDOWN cuando presione la variable "s" me tiene que cargar un dato y mostrarlo en el MEMO.

Por ahora cargaría cualquier dato, eso no me importa. Una vez que me cargue el dato sé que funciona y ahí intento poner el código para que haga lo que quiero.

Alguien tiene idea de esto?

escafandra 13-01-2020 12:37:07

Puedes probar con este pogramita de consola usando SDL2 así:


Código Delphi [-]
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows, Dialogs, SDL2;

var
  i: integer;
  sdlEvent: TSDL_Event;
  SDL_JOY : PSDL_JOYSTICK;
  s: String;
  Salir: boolean = false;
begin
  if SDL_Init(SDL_INIT_JOYSTICK) = -1 then  Writeln('No se encontraron Joysticks');
  for i := 0 to SDL_NumJoysticks -1  do
  begin
    SDL_JOY := SDL_JoystickOpen(i);
     Writeln(SDL_JoystickName(SDL_JOY)+#13);
  end;
  repeat
    while SDL_PollEvent(@sdlEvent) = 1 do
    begin
      if sdlEvent.type_  = SDL_JOYBUTTONDOWN then
      begin
        SDL_JOY := SDL_JoystickOpen(sdlEvent.jbutton.which);
        Writeln('Pulsado Boton de ' + SDL_JoystickName(SDL_JOY)+#13);
        Windows.Beep(1000, 100);
      end;
    end;
  until Salir;

end.




O usando Win Joystick:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Mmsystem,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    procedure JOY1ButtonDown(var Message: TMessage); message MM_JOY1BUTTONDOWN;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   if joySetCapture(Handle, JOYSTICKID1, 0, true) <> 0 then
     ShowMessage('No se puede capturar el Joystick');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  joyReleaseCapture(JOYSTICKID1);
end;

procedure TForm1.JOY1ButtonDown(var Message: TMessage);
begin
  ShowMessage('Se ha pulsado un botón del Joystick');
end;

end.




Saludos.


La franja horaria es GMT +2. Ahora son las 12:43:36.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi