<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <AllGeneratedFiles Include="$(ApplicationRoot)\generated\fonts\**\*.*;$(ApplicationRoot)\generated\images\**\*.*;$(ApplicationRoot)\generated\texts\**\*.*" />
  </ItemGroup>

  <ItemGroup>
    <ImageConvertExecutable Include="$(TouchGFXReleasePath)\framework\tools\imageconvert\build\msvs\ImageConvert.exe"/>
  </ItemGroup>

  <PropertyGroup>
    <UseBPPOption>/DUSE_BPP=$(UseBPP)</UseBPPOption>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(LCD)'!=''">
    <LCDOption>/D$(LCD)</LCDOption>
  </PropertyGroup>
  <PropertyGroup Condition="'$(LCD)'==''">
    <LCDOption/>
  </PropertyGroup>
  
  <PropertyGroup>
    <touchgfx_env Condition="'$(TouchGFXEnvPath)'==''">$(TouchGFXReleasePath)\..\env</touchgfx_env>
    <touchgfx_env Condition="'$(TouchGFXEnvPath)'!=''">$(TouchGFXEnvPath)</touchgfx_env>
  </PropertyGroup>

  <Target Name="GenerateBitmapDatabaseFiles" BeforeTargets="ClCompile">
    <Message Text="Converting images"/>
    <Exec Command="echo Converting images"/>
    <Exec Command="&quot;%(ImageConvertExecutable.FullPath)&quot; -r assets\images -w generated\images" WorkingDirectory="$(ApplicationRoot)"/>
  </Target>

  <Target Name="GenerateTextsAndFontsFiles" BeforeTargets="ClCompile">
    <Message Text="Converting texts and fonts" />
    <Exec Command="echo Converting texts and fonts"/>
    <Exec Command="&quot;$(touchgfx_env)\MinGW\msys\1.0\ruby193\bin\ruby.exe&quot; &quot;$(TouchGFXReleasePath)\framework\tools\textconvert\main.rb&quot; &quot;$(ApplicationRoot)\assets\texts\texts.xlsx&quot; &quot;$(TouchGFXReleasePath)\framework\tools\fontconvert\build\win\fontconvert.out&quot; &quot;$(ApplicationRoot)\generated\fonts&quot; &quot;$(ApplicationRoot)\generated\texts&quot; &quot;$(ApplicationRoot)\assets\fonts&quot; &quot;$(ApplicationRoot)&quot;"/>
  </Target>

  <Target Name="CompileAllGeneratedFiles" BeforeTargets="ClCompile">
    <ItemGroup>
      <AllGeneratedCompileFiles Include="$(ApplicationRoot)\generated\fonts\**\*.cpp;$(ApplicationRoot)\generated\images\**\*.cpp;$(ApplicationRoot)\generated\texts\**\*.cpp;" />
    </ItemGroup>
    <Message Text="Creating compile items for all generated source files: @(AllGeneratedCompileFiles)"/>
    <Exec Command="echo Creating compile items for all generated source files: @(AllGeneratedCompileFiles)"/>
    <CreateItem Include="@(AllGeneratedCompileFiles)">
      <Output TaskParameter="Include" ItemName="ClCompile"/>
    </CreateItem>
  </Target>

  <Target Name="CleanupGeneratedFiles" AfterTargets="Clean">
    <Message Text="Clean-up generated files: @(AllGeneratedFiles)"/>
    <Exec Command="echo Clean-up generated files: @(AllGeneratedFiles)"/>
    <Delete Files="@(AllGeneratedFiles)"/>
  </Target>

  <Target Name="PostBuild" AfterTargets="ClCompile">
    <Exec Command="copy $(TouchGFXReleasePath)\lib\sdl2\win32\SDL2.dll $(OutDir) > nul" />
    <Exec Command="copy $(TouchGFXReleasePath)\lib\sdl2\win32\SDL2_image.dll $(OutDir) > nul" />
    <Exec Command="copy $(TouchGFXReleasePath)\lib\sdl2\win32\libpng16-16.dll $(OutDir) > nul" />
    <Exec Command="copy $(TouchGFXReleasePath)\lib\sdl2\win32\zlib1.dll $(OutDir) > nul"/>
    <Exec Command="if exist $(ApplicationRoot)\simulator\landscape.png copy /y $(ApplicationRoot)\simulator\landscape.png $(OutDir) > nul" />
    <Exec Command="if exist $(ApplicationRoot)\simulator\portrait.png copy /y $(ApplicationRoot)\simulator\portrait.png $(OutDir) > nul" />
  </Target>
</Project>
