hedgewars/uFLData.pas
author unc0rr
Sat, 25 Apr 2015 23:46:09 +0300
branchqmlfrontend
changeset 10900 6a805e822074
parent 10448 4cb727e029fa
permissions -rw-r--r--
Some hedgewars coding a week keeps doctor away
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     1
unit uFLData;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     2
interface
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     3
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     4
function getThemesList: PPChar; cdecl;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     5
procedure freeThemesList(list: PPChar); cdecl;
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
     6
function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
     7
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
     8
const colorsSet: array[0..8] of shortstring = (
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
     9
                                               '16712196'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    10
                                               , '4817089'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    11
                                               , '1959610'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    12
                                               , '11878895'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    13
                                               , '10526880'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    14
                                               , '2146048'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    15
                                               , '16681742'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    16
                                               , '6239749'
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    17
                                               , '16776961');
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10438
diff changeset
    18
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    19
implementation
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    20
uses uPhysFSLayer;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    21
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    22
function getThemesList: PPChar; cdecl;
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    23
var list, res, tmp: PPChar;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    24
    i, size: Longword;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    25
begin
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    26
    list:= pfsEnumerateFiles('Themes');
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    27
    size:= 0;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    28
    tmp:= list;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    29
    while tmp^ <> nil do
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    30
    begin
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    31
        inc(size);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    32
        inc(tmp)
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    33
    end;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    34
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    35
    res:= GetMem((3 + size) * sizeof(PChar));
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    36
    res^:= PChar(list);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    37
    inc(res);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    38
    res^:= PChar(res + size + 2);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    39
    inc(res);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    40
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    41
    getThemesList:= res;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    42
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    43
    for i:= 1 to size do
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    44
    begin
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    45
        if pfsExists('/Themes/' + shortstring(list^) + '/icon.png') then
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    46
        begin
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    47
            res^:= list^;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    48
            inc(res)
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    49
        end;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    50
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    51
        inc(list)
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    52
    end;
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    53
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    54
    res^:= nil
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    55
end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    56
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    57
procedure freeThemesList(list: PPChar); cdecl;
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    58
var listEnd: PPChar;
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    59
begin
10438
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    60
    dec(list);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    61
    listEnd:= PPChar(list^);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    62
    dec(list);
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    63
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    64
    pfsFreeList(PPChar(list^));
50ed968e4fee Filter out garbage from themes list
unc0rr
parents: 10436
diff changeset
    65
    freeMem(list, (listEnd - list) * sizeof(PChar))
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    66
end;
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    67
10436
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    68
function getThemeIcon(themeName: PChar; buffer: PChar; buflen: Longword): Longword; cdecl;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    69
var s: shortstring;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    70
    f: PFSFile;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    71
begin
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    72
    s:= '/Themes/' + shortstring(themeName) + '/icon@2x.png';
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    73
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    74
    f:= pfsOpenRead(s);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    75
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    76
    if f = nil then
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    77
        getThemeIcon:= 0
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    78
    else
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    79
    begin
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    80
        getThemeIcon:= pfsBlockRead(f, buffer, buflen);
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    81
        pfsClose(f)
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    82
    end;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    83
end;
084e046f6bd5 flib provides theme icons, qmlFrontend shows them
unc0rr
parents: 10434
diff changeset
    84
10434
1614b13ad35e Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff changeset
    85
end.