hedgewars/uFLThemes.pas
branchqmlfrontend
changeset 11443 1a6148b4de3b
parent 10448 4cb727e029fa
equal deleted inserted replaced
11442:6e641b5453f9 11443:1a6148b4de3b
       
     1 unit uFLThemes;
       
     2 interface
       
     3 
       
     4 function getThemesList: PPChar; cdecl;
       
     5 procedure freeThemesList(list: PPChar); cdecl;
       
     6 function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
       
     7 
       
     8 const colorsSet: array[0..8] of shortstring = (
       
     9                                                '16712196'
       
    10                                                , '4817089'
       
    11                                                , '1959610'
       
    12                                                , '11878895'
       
    13                                                , '10526880'
       
    14                                                , '2146048'
       
    15                                                , '16681742'
       
    16                                                , '6239749'
       
    17                                                , '16776961');
       
    18 
       
    19 implementation
       
    20 uses uPhysFSLayer;
       
    21 
       
    22 function getThemesList: PPChar; cdecl;
       
    23 var list, res, tmp: PPChar;
       
    24     i, size: Longword;
       
    25 begin
       
    26     list:= pfsEnumerateFiles('Themes');
       
    27     size:= 0;
       
    28     tmp:= list;
       
    29     while tmp^ <> nil do
       
    30     begin
       
    31         inc(size);
       
    32         inc(tmp)
       
    33     end;
       
    34 
       
    35     res:= GetMem((3 + size) * sizeof(PChar));
       
    36     res^:= PChar(list);
       
    37     inc(res);
       
    38     res^:= PChar(res + size + 2);
       
    39     inc(res);
       
    40 
       
    41     getThemesList:= res;
       
    42 
       
    43     for i:= 1 to size do
       
    44     begin
       
    45         if pfsExists('/Themes/' + shortstring(list^) + '/icon.png') then
       
    46         begin
       
    47             res^:= list^;
       
    48             inc(res)
       
    49         end;
       
    50 
       
    51         inc(list)
       
    52     end;
       
    53 
       
    54     res^:= nil
       
    55 end;
       
    56 
       
    57 procedure freeThemesList(list: PPChar); cdecl;
       
    58 var listEnd: PPChar;
       
    59 begin
       
    60     dec(list);
       
    61     listEnd:= PPChar(list^);
       
    62     dec(list);
       
    63 
       
    64     pfsFreeList(PPChar(list^));
       
    65     freeMem(list, (listEnd - list) * sizeof(PChar))
       
    66 end;
       
    67 
       
    68 function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
       
    69 var s: shortstring;
       
    70     f: PFSFile;
       
    71 begin
       
    72     s:= '/Themes/' + shortstring(themeName) + '/icon@2x.png';
       
    73 
       
    74     f:= pfsOpenRead(s);
       
    75 
       
    76     if f = nil then
       
    77         getThemeIcon:= 0
       
    78     else
       
    79     begin
       
    80         getThemeIcon:= pfsBlockRead(f, buffer, buflen);
       
    81         pfsClose(f)
       
    82     end;
       
    83 end;
       
    84 
       
    85 end.