umain.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. unit umain;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, Forms, Graphics, SysUtils, BCGameGrid, BGRABitmap,
  6. BGRABitmapTypes, types, Controls, Dialogs, ExtCtrls, LCLType, BCEffect;
  7. type
  8. { TForm1 }
  9. TForm1 = class(TForm)
  10. BCGameGrid2: TBCGameGrid;
  11. Timer1: TTimer;
  12. procedure BCGameGrid2ClickControl(Sender: TObject; n, x, y: integer);
  13. procedure BCGameGrid2MouseDown(Sender: TObject; Button: TMouseButton;
  14. Shift: TShiftState; X, Y: integer);
  15. procedure BCGameGrid2MouseEnter(Sender: TObject);
  16. procedure BCGameGrid2MouseLeave(Sender: TObject);
  17. procedure BCGameGrid2MouseMove(Sender: TObject; Shift: TShiftState;
  18. X, Y: integer);
  19. procedure BCGameGrid2MouseUp(Sender: TObject; Button: TMouseButton;
  20. Shift: TShiftState; X, Y: integer);
  21. procedure BCGameGrid2MouseWheel(Sender: TObject; Shift: TShiftState;
  22. WheelDelta: integer; MousePos: TPoint; var Handled: boolean);
  23. procedure BCGameGrid2MouseWheelDown(Sender: TObject; Shift: TShiftState;
  24. MousePos: TPoint; var Handled: boolean);
  25. procedure BCGameGrid2MouseWheelUp(Sender: TObject; Shift: TShiftState;
  26. MousePos: TPoint; var Handled: boolean);
  27. procedure BCGameGrid2RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
  28. r: TRect; n, x, y: integer);
  29. procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  30. procedure FormCreate(Sender: TObject);
  31. procedure FormHide(Sender: TObject);
  32. procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
  33. procedure Timer1Timer(Sender: TObject);
  34. private
  35. procedure SetFSelected(AValue: integer);
  36. { private declarations }
  37. public
  38. { public declarations }
  39. FSelected: integer;
  40. Fade: TFading;
  41. property Selected: integer read FSelected write SetFSelected;
  42. end;
  43. var
  44. Form1: TForm1;
  45. const
  46. L1 = VK_LEFT;
  47. R1 = VK_RIGHT;
  48. U1 = VK_UP;
  49. D1 = VK_DOWN;
  50. L2 = VK_A;
  51. R2 = VK_D;
  52. U2 = VK_W;
  53. D2 = VK_S;
  54. implementation
  55. {$R *.lfm}
  56. { TForm1 }
  57. procedure TForm1.BCGameGrid2RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
  58. r: TRect; n, x, y: integer);
  59. var
  60. cr, cg, cb, ca: byte;
  61. bmp: TBGRABitmap;
  62. begin
  63. cr := Random(100);
  64. cg := Random(100);
  65. cb := Random(255);
  66. ca := Random(100);
  67. // selected
  68. if Selected = n then
  69. begin
  70. ca := 255;
  71. Bitmap.FillRect(r, BGRA(0, 0, 255, Fade.Execute), dmSet);
  72. end
  73. // colors
  74. else
  75. begin
  76. Bitmap.FillRect(r, BGRA(cr, cg, cb, ca), dmSet);
  77. Bitmap.Rectangle(r, BGRA(100, 100, 100, ca), dmDrawWithTransparency);
  78. end;
  79. // text
  80. Bitmap.TextRect(r, concat('n', IntToStr(n), ',x', IntToStr(x), ',y', IntToStr(y)),
  81. taCenter, tlCenter, BGRA(0, 0, 0, ca));
  82. // crazy effect
  83. if n = BCGameGrid2.GridWidth * BCGameGrid2.GridHeight -1 then { remove this if you want to see the original thing... }
  84. if Odd(n) then { this is for improve speed... }
  85. begin
  86. bmp := Bitmap.FilterBlurRadial(1, rbFast) as TBGRABitmap;
  87. Bitmap.BlendImage(Random(4), Random(4), bmp, boLinearBlend);
  88. bmp.Free;
  89. end;
  90. end;
  91. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  92. begin
  93. Timer1.Enabled := False;
  94. end;
  95. procedure TForm1.FormCreate(Sender: TObject);
  96. begin
  97. Fade.Mode := fmFadeInOut;
  98. Fade.Step := 17;
  99. Fade.Reset;
  100. end;
  101. procedure TForm1.FormHide(Sender: TObject);
  102. begin
  103. end;
  104. procedure TForm1.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
  105. begin
  106. if (Key = L1) or (Key = L2) then
  107. Selected := Selected - 1
  108. else if (Key = R1) or (Key = R2) then
  109. Selected := Selected + 1
  110. else if (Key = U1) or (Key = U2) then
  111. Selected := Selected - BCGameGrid2.GridWidth
  112. else if (Key = D1) or (Key = D2) then
  113. Selected := Selected + BCGameGrid2.GridWidth;
  114. end;
  115. procedure TForm1.Timer1Timer(Sender: TObject);
  116. begin
  117. BCGameGrid2.RenderAndDrawControl;
  118. end;
  119. procedure TForm1.SetFSelected(AValue: integer);
  120. begin
  121. if FSelected = AValue then
  122. Exit;
  123. FSelected := AValue;
  124. end;
  125. procedure TForm1.BCGameGrid2ClickControl(Sender: TObject; n, x, y: integer);
  126. begin
  127. Selected := n;
  128. end;
  129. procedure TForm1.BCGameGrid2MouseDown(Sender: TObject; Button: TMouseButton;
  130. Shift: TShiftState; X, Y: integer);
  131. begin
  132. {if Button = mbLeft then
  133. ...}
  134. end;
  135. procedure TForm1.BCGameGrid2MouseEnter(Sender: TObject);
  136. begin
  137. //ShowMessage('Enter');
  138. end;
  139. procedure TForm1.BCGameGrid2MouseLeave(Sender: TObject);
  140. begin
  141. //ShowMessage('Leave');
  142. end;
  143. procedure TForm1.BCGameGrid2MouseMove(Sender: TObject; Shift: TShiftState;
  144. X, Y: integer);
  145. begin
  146. {if ssLeft in Shift then
  147. ...}
  148. end;
  149. procedure TForm1.BCGameGrid2MouseUp(Sender: TObject; Button: TMouseButton;
  150. Shift: TShiftState; X, Y: integer);
  151. begin
  152. {if ssLeft in Shift then
  153. ...}
  154. end;
  155. procedure TForm1.BCGameGrid2MouseWheel(Sender: TObject; Shift: TShiftState;
  156. WheelDelta: integer; MousePos: TPoint; var Handled: boolean);
  157. begin
  158. //ShowMessage('Wheeeeel!');
  159. end;
  160. procedure TForm1.BCGameGrid2MouseWheelDown(Sender: TObject; Shift: TShiftState;
  161. MousePos: TPoint; var Handled: boolean);
  162. begin
  163. { Decrease grid }
  164. BCGameGrid2.GridWidth := BCGameGrid2.GridWidth - 1;
  165. BCGameGrid2.GridHeight := BCGameGrid2.GridHeight - 1;
  166. end;
  167. procedure TForm1.BCGameGrid2MouseWheelUp(Sender: TObject; Shift: TShiftState;
  168. MousePos: TPoint; var Handled: boolean);
  169. begin
  170. { Increase grid }
  171. BCGameGrid2.GridWidth := BCGameGrid2.GridWidth + 1;
  172. BCGameGrid2.GridHeight := BCGameGrid2.GridHeight + 1;
  173. end;
  174. end.