uMain.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. unit uMain;
  2. // RU: îáðàòèòå âíèìàíèå!!!
  3. // Ïðîåêòû LCL èìåþò ñâîè êîíôèãóðàöèîííûå ôàéëû "zgl_config.cfg". Ëó÷øå âñåãî äëÿ êàæäîãî âàøåãî ïðîåêòà èìåòü ñâîé
  4. // êîíôèãóðàöèîííûé ôàéë, ýòî ìîæåò ðåøèòü ìíîãèå ïðîáëåìû, åñëè âäðóã âû áóäåòå âíîñèòü èçìåíåíèÿ â êîíôèãóðàöèþ ïðîåêòà
  5. // è, ýòî îòîáðàçèòñÿ íà äðóãèõ âàøèõ ïðîåêòàõ èñïîëüçóþùèõ òîò æå êîíôèãóðàöèîííûé ôàéë.
  6. // EN: note!!!
  7. // LCL projects have their own configuration files "zgl_config.cfg". It's best to have a separate config file for each of
  8. // your projects, this can solve many problems if you suddenly make changes to the project config and it will show up on
  9. // your other projects using the same config file.
  10. interface
  11. uses
  12. Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  13. ExtCtrls, ComCtrls,
  14. zgl_application,
  15. zgl_screen,
  16. zgl_window,
  17. zgl_utils,
  18. zgl_primitives_2d,
  19. zgl_sprite_2d,
  20. zgl_font,
  21. zgl_text,
  22. zgl_file,
  23. zgl_font_gen,
  24. Spin;
  25. type
  26. { TForm1 }
  27. TForm1 = class(TForm)
  28. ButtonRebuildFont: TButton;
  29. ButtonImportSymbols: TButton;
  30. ButtonDefaultSymbols: TButton;
  31. ButtonExit: TButton;
  32. ButtonSaveFont: TButton;
  33. ButtonChooseFont: TButton;
  34. CheckBoxAntialiasing: TCheckBox;
  35. CheckBoxPack: TCheckBox;
  36. ComboBoxPageSize: TComboBox;
  37. EditChars: TEdit;
  38. EditTest: TEdit;
  39. FontDialog: TFontDialog;
  40. GroupBox1: TGroupBox;
  41. GroupBox2: TGroupBox;
  42. GroupBox3: TGroupBox;
  43. GroupBox4: TGroupBox;
  44. Label1: TLabel;
  45. Label2: TLabel;
  46. Label3: TLabel;
  47. Label4: TLabel;
  48. LabelPageSize: TLabel;
  49. LabelCurrentPage: TLabel;
  50. OpenDialog: TOpenDialog;
  51. Panel1: TPanel;
  52. SaveFontDialog: TSaveDialog;
  53. SpinCurrentPage: TSpinEdit;
  54. SpinTop: TSpinEdit;
  55. SpinLeft: TSpinEdit;
  56. SpinRight: TSpinEdit;
  57. SpinBottom: TSpinEdit;
  58. Timer1: TTimer;
  59. procedure ButtonChooseFontClick(Sender: TObject);
  60. procedure ButtonDefaultSymbolsClick(Sender: TObject);
  61. procedure ButtonExitClick(Sender: TObject);
  62. procedure ButtonImportSymbolsClick(Sender: TObject);
  63. procedure ButtonRebuildFontClick(Sender: TObject);
  64. procedure ButtonSaveFontClick(Sender: TObject);
  65. procedure CheckBoxAntialiasingChange(Sender: TObject);
  66. procedure CheckBoxPackChange(Sender: TObject);
  67. procedure ComboBoxPageSizeChange(Sender: TObject);
  68. procedure FormActivate(Sender: TObject);
  69. procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  70. procedure FormResize(Sender: TObject);
  71. procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  72. Shift: TShiftState; X, Y: Integer);
  73. procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  74. procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  75. Shift: TShiftState; X, Y: Integer);
  76. procedure SpinLeftChange(Sender: TObject);
  77. procedure SpinTopChange(Sender: TObject);
  78. procedure SpinBottomChange(Sender: TObject);
  79. procedure SpinRightChange(Sender: TObject);
  80. procedure SpinCurrentPageChange(Sender: TObject);
  81. procedure Timer1Timer(Sender: TObject);
  82. private
  83. { private declarations }
  84. public
  85. { public declarations }
  86. procedure SetDefaultSymbolList;
  87. procedure UpdateSymbolList;
  88. procedure UpdateFont;
  89. end;
  90. var
  91. Form1 : TForm1;
  92. zgl_Inited : Boolean = False;
  93. fontMoving : Boolean;
  94. fontX, fontY : Integer;
  95. lastX, lastY : Integer;
  96. utf8chars : array[0..65535, 0..5] of AnsiChar;
  97. implementation
  98. {$R *.dfm}
  99. procedure Init;
  100. var
  101. i : Integer;
  102. begin
  103. wnd_SetSize( Form1.Panel1.ClientWidth, Form1.Panel1.ClientHeight);
  104. scrVSync := True;
  105. fontgen_Init();
  106. fg_Font := font_Add();
  107. Form1.SetDefaultSymbolList();
  108. Form1.UpdateFont();
  109. fontX := (Form1.Panel1.Width - fg_PageSize) div 2;
  110. fontY := (Form1.Panel1.Height - fg_PageSize) div 2;
  111. end;
  112. procedure Draw;
  113. var
  114. w : Single;
  115. begin
  116. pr2d_Rect(0, 0, Form1.Panel1.Width, Form1.Panel1.Height, $505050, 255, PR2D_FILL);
  117. pr2d_Rect(fontX, fontY, fg_PageSize, fg_PageSize, $000000, 255, PR2D_FILL);
  118. if (fg_Font <> 0) and Assigned(managerFont.Font[fg_Font].Pages) Then
  119. begin
  120. ssprite2d_Draw(managerFont.Font[fg_Font].Pages[Form1.SpinCurrentPage.Value - 1], fontX, fontY, fg_PageSize, fg_PageSize, 0);
  121. w := text_GetWidth(fg_Font, Form1.EditTest.Text);
  122. pr2d_Rect((Form1.Panel1.Width - w) / 2, Form1.Panel1.Height - managerFont.Font[fg_Font].MaxShiftY - managerFont.Font[fg_Font].MaxHeight, w, managerFont.Font[fg_Font].MaxShiftY + managerFont.Font[fg_Font].MaxHeight, $000000, 255, PR2D_FILL);
  123. text_Draw(fg_Font, Form1.Panel1.Width div 2, Form1.Panel1.Height - managerFont.Font[fg_Font].MaxHeight, Form1.EditTest.Text, TEXT_HALIGN_CENTER);
  124. end;
  125. Application.ProcessMessages();
  126. u_Sleep(10);
  127. end;
  128. { TForm1 }
  129. procedure TForm1.SetDefaultSymbolList;
  130. begin
  131. EditChars.Text := ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}' +
  132. '~¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿№' +
  133. '�ЄІЇ�БВГДЕЖЗИЙКЛМ�ОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопр�туфхцчшщъыь�ю�ёєії�ґ';
  134. end;
  135. procedure TForm1.UpdateSymbolList;
  136. var
  137. i, j, len : Integer;
  138. c : Word;
  139. begin
  140. // Panel1.Canvas.Clear();
  141. Panel1.Update;
  142. Application.ProcessMessages();
  143. i := 1;
  144. FillChar(fg_CharsUse, 65536, 0);
  145. managerFont.Font[fg_Font].Count.Chars := 0;
  146. len := length(EditChars.Text);
  147. while i <= len do
  148. begin
  149. c := utf8_GetID(EditChars.Text, i, @j);
  150. if not fg_CharsUse[c] Then
  151. begin
  152. fg_CharsUse[c] := TRUE;
  153. FillChar(utf8chars[c, 0], 6, 0);
  154. Move(EditChars.Text[i], utf8chars[c, 0], j - i);
  155. INC(managerFont.Font[fg_Font].Count.Chars);
  156. end;
  157. i := j;
  158. end;
  159. EditChars.Text := '';
  160. i := 0;
  161. while i < 65536 do
  162. begin
  163. if fg_CharsUse[i] Then
  164. EditChars.Text := EditChars.Text + utf8chars[i];
  165. inc(i);
  166. end;
  167. Application.ProcessMessages();
  168. end;
  169. procedure TForm1.UpdateFont;
  170. begin
  171. UpdateSymbolList();
  172. fontgen_BuildFont(fg_Font, FontDialog.Font.Name);
  173. SpinCurrentPage.MaxValue := managerFont.Font[fg_Font].Count.Pages;
  174. if (managerFont.Font[fg_Font].Count.Pages = 0) or (managerFont.Font[fg_Font].Count.Pages = 1) then
  175. begin
  176. SpinCurrentPage.Enabled := False;
  177. SpinCurrentPage.Value := managerFont.Font[fg_Font].Count.Pages;
  178. Exit;
  179. end
  180. else
  181. SpinCurrentPage.Enabled := True;
  182. if SpinCurrentPage.Value > SpinCurrentPage.MaxValue Then
  183. SpinCurrentPage.Value := SpinCurrentPage.MaxValue;
  184. end;
  185. procedure TForm1.ButtonChooseFontClick(Sender: TObject);
  186. begin
  187. Timer1.Enabled := False;
  188. if FontDialog.Execute() Then
  189. begin
  190. fg_FontSize := FontDialog.Font.Size;
  191. fg_FontBold := fsBold in FontDialog.Font.Style;
  192. fg_FontItalic := fsItalic in FontDialog.Font.Style;
  193. UpdateFont();
  194. end;
  195. Timer1.Enabled := True;
  196. end;
  197. procedure TForm1.ButtonDefaultSymbolsClick(Sender: TObject);
  198. begin
  199. Timer1.Enabled := False;
  200. SetDefaultSymbolList();
  201. UpdateFont();
  202. Timer1.Enabled := True;
  203. end;
  204. procedure TForm1.ButtonExitClick(Sender: TObject);
  205. begin
  206. Form1.Close;
  207. end;
  208. procedure TForm1.ButtonImportSymbolsClick(Sender: TObject);
  209. var
  210. i : Integer;
  211. s : TStrings;
  212. begin
  213. Timer1.Enabled := False;
  214. s := TStringList.Create;
  215. if OpenDialog.Execute() Then
  216. begin
  217. s.LoadFromFile(OpenDialog.FileName);
  218. for i := 0 to s.Count - 1 do
  219. EditChars.Text := EditChars.Text + s.Strings[i];
  220. UpdateFont();
  221. end;
  222. Timer1.Enabled := True;
  223. end;
  224. procedure TForm1.ButtonRebuildFontClick(Sender: TObject);
  225. begin
  226. Timer1.Enabled := False;
  227. UpdateFont();
  228. Timer1.Enabled := True;
  229. end;
  230. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  231. begin
  232. Timer1.Enabled := False;
  233. winOn := False;
  234. zgl_Destroy;
  235. Application.Terminate;
  236. end;
  237. procedure TForm1.FormResize(Sender: TObject);
  238. begin
  239. wnd_SetSize(Panel1.ClientWidth, Panel1.ClientHeight);
  240. end;
  241. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  242. Shift: TShiftState; X, Y: Integer);
  243. begin
  244. if not fontMoving Then
  245. begin
  246. fontMoving := TRUE;
  247. lastX := X;
  248. lastY := Y;
  249. end;
  250. end;
  251. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  252. Y: Integer);
  253. begin
  254. if fontMoving Then
  255. begin
  256. fontX := fontX + (X - lastX);
  257. fontY := fontY + (Y - lastY);
  258. lastX := X;
  259. lastY := Y;
  260. end;
  261. end;
  262. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  263. Shift: TShiftState; X, Y: Integer);
  264. begin
  265. fontMoving := FALSE;
  266. end;
  267. procedure TForm1.SpinLeftChange(Sender: TObject);
  268. begin
  269. Timer1.Enabled := False;
  270. if SpinLeft.Value < 0 then
  271. SpinLeft.Value := 0;
  272. if fg_FontPadding[0] <> SpinLeft.Value Then
  273. begin
  274. fg_FontPadding[0] := SpinLeft.Value;
  275. UpdateFont();
  276. end;
  277. Timer1.Enabled := True;
  278. end;
  279. procedure TForm1.SpinTopChange(Sender: TObject);
  280. begin
  281. Timer1.Enabled := False;
  282. if SpinTop.Value < 0 then
  283. SpinTop.Value := 0;
  284. if fg_FontPadding[1] <> SpinTop.Value Then
  285. begin
  286. fg_FontPadding[1] := SpinTop.Value;
  287. UpdateFont();
  288. end;
  289. Timer1.Enabled := True;
  290. end;
  291. procedure TForm1.SpinRightChange(Sender: TObject);
  292. begin
  293. Timer1.Enabled := False;
  294. if SpinRight.Value < 0 then
  295. SpinRight.Value := 0;
  296. if fg_FontPadding[2] <> SpinRight.Value Then
  297. begin
  298. fg_FontPadding[2] := SpinRight.Value;
  299. UpdateFont();
  300. end;
  301. Timer1.Enabled := True;
  302. end;
  303. procedure TForm1.SpinBottomChange(Sender: TObject);
  304. begin
  305. Timer1.Enabled := False;
  306. if SpinBottom.Value < 0 then
  307. SpinBottom.Value := 0;
  308. if fg_FontPadding[3] <> SpinBottom.Value Then
  309. begin
  310. fg_FontPadding[3] := SpinBottom.Value;
  311. UpdateFont();
  312. end;
  313. Timer1.Enabled := True;
  314. end;
  315. procedure TForm1.ButtonSaveFontClick(Sender: TObject);
  316. var
  317. style : String;
  318. name : String;
  319. dir : String;
  320. begin
  321. if fg_FontBold and fg_FontItalic Then
  322. style := 'BoldItalic'
  323. else
  324. if fg_FontBold Then
  325. style := 'Bold'
  326. else
  327. if fg_FontItalic Then
  328. style := 'Italic'
  329. else
  330. style := 'Regular';
  331. Timer1.Enabled := False;
  332. SaveFontDialog.FileName := FontDialog.Font.Name + '-' + style + '-' + IntToStr(fg_FontSize) + 'pt';
  333. name := file_GetName(SaveFontDialog.FileName);
  334. dir := file_GetDirectory(SaveFontDialog.FileName);
  335. fontgen_SaveFont(fg_Font, name);
  336. ShowMessage(name + ' save');
  337. Timer1.Enabled := True;
  338. end;
  339. procedure TForm1.CheckBoxAntialiasingChange(Sender: TObject);
  340. begin
  341. Timer1.Enabled := False;
  342. fg_FontAA := CheckBoxAntialiasing.Checked;
  343. UpdateFont();
  344. Timer1.Enabled := True;
  345. end;
  346. procedure TForm1.CheckBoxPackChange(Sender: TObject);
  347. begin
  348. Timer1.Enabled := False;
  349. fg_FontPack := CheckBoxPack.Checked;
  350. UpdateFont();
  351. Timer1.Enabled := True;
  352. end;
  353. procedure TForm1.ComboBoxPageSizeChange(Sender: TObject);
  354. begin
  355. Timer1.Enabled := False;
  356. fg_PageSize := StrToInt(ComboBoxPageSize.Items[ComboBoxPageSize.ItemIndex]);
  357. UpdateFont();
  358. Timer1.Enabled := True;
  359. end;
  360. procedure TForm1.FormActivate(Sender: TObject);
  361. begin
  362. if not zgl_Inited then
  363. begin
  364. zgl_Inited := True;
  365. zgl_Disable(APP_USE_LOG);
  366. zgl_Reg(SYS_LOAD, @Init);
  367. zgl_Reg(SYS_DRAW, @Draw);
  368. zgl_InitToHandle(Panel1.Handle);
  369. Timer1.Enabled := True;
  370. end;
  371. end;
  372. procedure TForm1.SpinCurrentPageChange(Sender: TObject);
  373. begin
  374. if SpinCurrentPage.Value < 1 then
  375. SpinCurrentPage.Value := 1;
  376. end;
  377. procedure TForm1.Timer1Timer(Sender: TObject);
  378. begin
  379. app_PLoop;
  380. end;
  381. end.