fSplitterC.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <Graphics.hpp>
  4. #pragma hdrstop
  5. #include "fSplitterC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12. : TForm(Owner)
  13. {
  14. SetCurrentDir(ExtractFilePath(ExtractFileDir(Application->ExeName))+"\\Data");
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TForm1::Button1Click(TObject *Sender)
  18. {
  19. TPicture *pic;
  20. Graphics::TBitmap *bmp, *bmp2;
  21. int s, sd, f;
  22. int x, y;
  23. PathJpgIn = GetCurrentAssetPath() + "\\map";
  24. SetCurrentDir(PathJpgIn);
  25. s = StrToInt(EDTileSize->Text);
  26. pic = new TPicture();
  27. if (RBHalf->Checked)
  28. f = 2;
  29. else if (RBLow->Checked)
  30. f = 4;
  31. else f = 1;
  32. sd = s/f;
  33. ProgressBar->Position = 0;
  34. Screen->Cursor = crHourGlass;
  35. bmp = new Graphics::TBitmap();
  36. bmp->PixelFormat = pf24bit;
  37. bmp->Width = sd;
  38. bmp->Height = sd;
  39. if (f != 1) {
  40. bmp2 = new Graphics::TBitmap();
  41. bmp2->PixelFormat = pf24bit;
  42. bmp2->Width = s;
  43. bmp2->Height = s;
  44. } else bmp2 = NULL;
  45. LAAction->Caption = "Loading Jpeg texture...";
  46. LAAction->Visible = true;
  47. Refresh();
  48. pic->LoadFromFile(EDFile->Text);
  49. x = 0; while (x<pic->Width) {
  50. y = 0; while (y<pic->Height) {
  51. if (sd != s) {
  52. bmp2->Canvas->Draw(-x, -y, pic->Graphic);
  53. bmp->Canvas->StretchDraw(Rect(0, 0, sd, sd), bmp2);
  54. } else bmp->Canvas->Draw(-x, -y, pic->Graphic);
  55. LAAction->Caption = Format("Generating tile %d-%d...", ARRAYOFCONST((x/s, y/s)));
  56. Refresh();
  57. PathJpgOut = ExtractFilePath(ParamStr(0));
  58. SetCurrentDir(PathJpgOut);
  59. bmp->SaveToFile(Format(EDMask->Text, ARRAYOFCONST((x/s, y/s))));
  60. ProgressBar->StepBy(1);
  61. y += s;
  62. }
  63. x += s;
  64. }
  65. delete bmp2;
  66. delete bmp;
  67. delete pic;
  68. Screen->Cursor = crDefault;
  69. LAAction->Caption = "Completed";
  70. ShowMessage("Done!");
  71. Application->Terminate();
  72. }
  73. //---------------------------------------------------------------------------