src/hUGETracker.lpr3.2 KB · ObjectPascal
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
program hUGETracker;

{$MODE Delphi}

{$ifdef DARWIN}
  {$link /usr/local/lib/libSDL2.a}
  {$linkframework CoreAudio}
  {$linkframework AudioToolbox}
{$endif}

uses
{$ifdef UNIX}
  cthreads,
{$endif}
{$ifdef MSWINDOWS}
  Windows,
{$endif}
{$ifdef LCLQT5}
  qt5,
{$endif}
  FileUtil, Dialogs,
  SysUtils,
  Forms,
  Interfaces,
  LazLogger,
  hUGESettings,
  Constants,
  Tracker, EffectEditor, options, about_hugetracker, rendertowave, findreplace,
  utils;

{$R *.res}

{$ifdef MSWINDOWS}
// https://forum.lazarus.freepascal.org/index.php?topic=39124.0
function AddFontResourceExA(Dir: PAnsiChar; Flag: DWORD): LongBool; StdCall; External GDI32;
{$endif}

{$if defined(LINUX) or defined(FREEBSD) or defined(OPENBSD)}
function FcConfigAppFontAddFile(Config: Pointer; _File: PChar): Integer; cdecl; External 'libfontconfig.so';
function PangoCairoFontMapGetDefault: Pointer; cdecl; External 'libpangocairo-1.0.so' Name 'pango_cairo_font_map_get_default';
procedure PangoFcFontMapConfigChanged(FcFontMap: Pointer); cdecl; External 'libpangoft2-1.0.so' Name 'pango_fc_font_map_config_changed';
{$endif}

var
  PixelitePath: WideString;
begin
  ReturnNilIfGrowHeapFails := False;
  ChDir(ExtractFileDir(ParamStr(0)));
  InitializeTrackerSettings;

  {$if declared(useHeapTrace)}
    // Set up -gh output for the Leakview package:
    if FileExists('heap.trc') then
      DeleteFile('heap.trc');
    SetHeapTraceOutput('heap.trc');

    DebugLn('[DEBUG] Using heaptrc...');
  {$endIf}

  { Before the LCL starts, embed Pixelite so users dont have to install it.
    Unfortunately there isn't really a cross-platform way to do it. }

  {$ifdef MSWINDOWS}
    // $10 is FR_PRIVATE which uninstalls the font when the process ends
    if not AddFontResourceExA(PChar(ConcatPaths([RuntimeDir, 'PixeliteTTF.ttf'])), $10) then
      DebugLn('[ERROR] Couldn''t load Pixelite!!!');
  {$endif}

  {$if defined(LINUX) or defined(FREEBSD) or defined(OPENBSD)}
    // https://gitlab.gnome.org/GNOME/gtk/-/issues/3886
    if FcConfigAppFontAddFile(nil, PChar(ConcatPaths([RuntimeDir, 'PixeliteTTF.ttf']))) = 0 then
      DebugLn('[ERROR] Couldn''t load Pixelite!!!');

    PangoFcFontMapConfigChanged(PangoCairoFontMapGetDefault);
  {$endif}

  {$ifdef DARWIN}
    if not FileExists(ConcatPaths([GetUserDir, 'Library', 'Fonts', 'Pixelite.ttf'])) then begin
      ForceDirectories(ConcatPaths([GetUserDir, 'Library', 'Fonts']));
      CopyFile(ConcatPaths([RuntimeDir, 'PixeliteTTF.ttf']), ConcatPaths([GetUserDir, 'Library', 'Fonts', 'Pixelite.ttf']));
      ShowMessage('Successfully loaded required fonts for the first time. Please restart hUGETracker!');
      Halt;
    end;
  {$endif}

  {$ifdef LCLQT5}
    PixelitePath := WideString(ConcatPaths([RuntimeDir, 'PixeliteTTF.ttf']));
    QFontDatabase_addApplicationFont(@PixelitePath);
  {$endif}

  Application.Scaled:=True;
  Application.Initialize;
  Application.CreateForm(TfrmTracker, frmTracker);
  Application.CreateForm(TfrmAboutHugeTracker, frmAboutHugetracker);
  Application.CreateForm(TfrmEffectEditor, frmEffectEditor);
  Application.CreateForm(TfrmRenderToWave, frmRenderToWave);
  Application.CreateForm(TfrmOptions, frmOptions);
  Application.CreateForm(TfrmFindReplace, frmFindReplace);
  Application.Run;
end.