unit uMenu;

interface

uses uGlobal, SysUtils;

var
  Step: integer = 0;
  StartTime: Double = -1;
  LogoS, LogoM, Font, Caption: integer;
  
procedure InitMenu;
procedure InitMenu2;

function MenuProcess(Params: array of variant): variant; stdcall;

function menu_btnstart_click(Params: array of variant): variant; stdcall;
function menu_btnstart_exit(Params: array of variant): variant; stdcall;

implementation

var
  MainForm, btnStart, btnExit: integer;

function menu_btnstart_click(Params: array of variant): variant; stdcall;
begin
  call('GameInit',[]);
  call('glGUIVisible',[MainForm, false]);
end;

function menu_btnstart_exit(Params: array of variant): variant; stdcall;
begin
  call('shutdown',[]);
end;

procedure InitMenu2;
begin
  call('glObjectVisible', [LogoS, false]);

  Font:=call('glFontAdd',[]);
  call('glFontName', [Font, 'Courier New']);
  call('glGUIStyleFont', [Font]);

  //Create Form
  MainForm:=call('glGUIAdd',[gtPanel]);
  call('glGUIStyle',[MainForm,'panel']);
  call('glGUISize',[MainForm,190,150]);
  call('glGUIPosition',[MainForm,WndSize[0]/2-190/2,WndSize[1]/2-150/2]);
  call('glGUIAlpha', [MainForm, 1]);

  //create button
  btnStart:=call('glGUIAdd',[gtButton]);
  call('glGUIStyle',[btnStart,'button_up','button_down']);
  call('glGUISize',[btnStart,150,50]);
  call('glGUIText',[btnStart,'ÏÛÙ!']);
  call('glObjectParent', [btnStart, MainForm]);
  call('glGUIPosition', [btnStart, 20, 20]);
  call('glGUIEvent',[btnStart, caOnClick, 'menu_btnstart_click']);

  //create button
  btnExit:=call('glGUIAdd',[gtButton]);
  call('glGUIStyle',[btnExit,'button_up','button_down']);
  call('glGUISize',[btnExit,150,50]);
  call('glGUIText',[btnExit,'Âûõîä!']);
  call('glObjectParent', [btnExit, MainForm]);
  call('glGUIPosition', [btnExit, 20, 80]);
  call('glGUIEvent',[btnExit, caOnClick, 'menu_btnstart_exit']);

  //menu_btnstart_click([]);
end;

function MenuProcess(Params: array of variant): variant; stdcall;
var
  A: Double;
begin
  if (Params[1]>1)and(Step<1) then Step:=1;
  if (Params[1]>pi+1)and(Step<2) then Step:=2;
  //if (Params[1]>2*pi+1)and(Step<3) then Step:=3;

  case Step of
    1:
    begin
      A:=abs(sin(Params[1]-1));
      call('glMaterialColor', [LogoM, mfFront, mcDiffuse, A,A,A,A]);
      call('glMaterialColor', [LogoM, mfFront, mcEmission, A,A,A,A]);
    end;

    2:
    begin
      InitMenu2;
      Step:=3;
    end;
  end;
end;

procedure InitMenu;
begin
  LogoS:=call('glObjectAdd', [otHUDSprite, 'menu_logo',-1]);
  LogoM:=call('glMaterialAdd',['logo']);
  call('glPosition', [Logos, WndSize[0]/2, WndSize[1]/2, 0]) ;
  call('glObjectParams', [LogoS, 450,450]);
  Call('glMaterialTextureLoad', [LogoM, 'Data\gfx\logo.jpg']);
  Call('glMaterialTextureMode', [LogoM, tmModulate]);
  call('glMaterialTextureEnable', [LogoM, true]);
  call('glMaterialColor', [LogoM, mfFront, mcDiffuse, 0,0,0,0]);
  call('glMaterialColor', [LogoM, mfFront, mcEmission, 0,0,0,0]);

  call('glObjectMaterial', [LogoS, logoM]);
end;

end.

