FNavForm.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. unit FNavForm;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Classes,
  6. Vcl.Graphics,
  7. Vcl.Controls,
  8. Vcl.Forms,
  9. Vcl.Dialogs,
  10. //GR32
  11. GR32_Image,
  12. GR32,
  13. GR32_Layers,
  14. GLS.HeightTileFileHDS;
  15. type
  16. TNavForm = class(TForm)
  17. Image: TImage32;
  18. procedure ImageMouseDown(Sender: TObject; Button: TMouseButton;
  19. Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
  20. private
  21. FPickX, FPickY : Integer;
  22. public
  23. function Execute(htf : TGLHeightTileFile) : Boolean;
  24. property PickX : Integer read FPickX;
  25. property PickY : Integer read FPickY;
  26. end;
  27. var
  28. NavForm: TNavForm;
  29. implementation
  30. {$R *.dfm}
  31. uses
  32. FViewerForm;
  33. function TNavForm.Execute(htf : TGLHeightTileFile) : Boolean;
  34. var
  35. i, x, y, w, s, wx, wy : Integer;
  36. begin
  37. // Computes scaling so that preview window isn't too small
  38. with htf do begin
  39. wx:=(SizeX+TileSize div 2) div TileSize;
  40. wy:=(SizeY+TileSize div 2) div TileSize;
  41. end;
  42. if wx<wy then
  43. w:=wy
  44. else w:=wx;
  45. s:=1;
  46. while w<256 do begin
  47. w:=w*2;
  48. s:=s*2;
  49. end;
  50. Image.Scale:=s;
  51. // Prepare the world tile map
  52. with Image.Bitmap do begin
  53. Width:=wx;
  54. Height:=wy;
  55. Clear(clGray32);
  56. for i:=0 to htf.TileCount-1 do with htf.Tiles[i]^ do begin
  57. x:=(left+(width div 2)) div htf.TileSize;
  58. y:=(top+(height div 2)) div htf.TileSize;
  59. PixelS[x, y]:=heightColor[average];
  60. end;
  61. end;
  62. // Couldn't get the form's AutoSize to work...
  63. Image.Width:=wx*s;
  64. Image.Height:=wy*s;
  65. Width:=Image.Width;
  66. Height:=Image.Height;
  67. // Show the Nav map
  68. Result:=(ShowModal=mrOk);
  69. // Convert back to world coordinates
  70. if Result then begin
  71. FPickX:=(FPickX*htf.TileSize) div s - htf.TileSize;
  72. FPickY:=(FPickY*htf.TileSize) div s - htf.TileSize;
  73. end;
  74. end;
  75. procedure TNavForm.ImageMouseDown(Sender: TObject; Button: TMouseButton;
  76. Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer);
  77. begin
  78. FPickX:=X;
  79. FPickY:=Y;
  80. ModalResult:=mrOk;
  81. end;
  82. end.