|
@@ -1,7 +1,6 @@
|
|
library demo03;
|
|
library demo03;
|
|
-
|
|
|
|
-{$I zglCustomConfig.cfg}
|
|
|
|
{$I zgl_config.cfg}
|
|
{$I zgl_config.cfg}
|
|
|
|
+{$I zglCustomConfig.cfg}
|
|
|
|
|
|
uses
|
|
uses
|
|
zgl_application,
|
|
zgl_application,
|
|
@@ -18,42 +17,49 @@ uses
|
|
zgl_textures,
|
|
zgl_textures,
|
|
zgl_textures_png,
|
|
zgl_textures_png,
|
|
zgl_types,
|
|
zgl_types,
|
|
- {$IfDef USE_VKEYBOARD}
|
|
|
|
- gegl_draw_gui,
|
|
|
|
- gegl_menu_gui,
|
|
|
|
- {$EndIf}
|
|
|
|
|
|
+ zgl_log,
|
|
|
|
+ zgl_utils
|
|
{$IfDef OLD_METHODS}
|
|
{$IfDef OLD_METHODS}
|
|
- zgl_collision_2d,
|
|
|
|
- {$Else}
|
|
|
|
|
|
+ zgl_collision_2d
|
|
|
|
+ {$else}
|
|
|
|
+ , gegl_draw_gui,
|
|
|
|
+ gegl_menu_gui,
|
|
gegl_VElements,
|
|
gegl_VElements,
|
|
gegl_utils,
|
|
gegl_utils,
|
|
|
|
+ gegl_color
|
|
{$EndIf}
|
|
{$EndIf}
|
|
- gegl_color,
|
|
|
|
- zgl_log,
|
|
|
|
- zgl_utils
|
|
|
|
;
|
|
;
|
|
|
|
|
|
-var
|
|
|
|
- dirRes : UTF8String = 'assets/';
|
|
|
|
|
|
+ (* проблема данной демки, не в самой демке. Обработка клавиатуры - её проблема. Постоянные вызовы "setFontTextScale" убивают всю производительность
|
|
|
|
+ необходимо перевести все кнопки в текстуры. Текстуры нажатия и отжатия. Тогда работа клавиатуры/джойстиков станет выше.
|
|
|
|
+ Перевод в текстуры должен происходить однажды, при запуске программы и при восстановлении программы. Так как когда программа уходит в "спящий" режим
|
|
|
|
+ все текстуры уничтожаются (как я понимаю, контекст уничтожается и из-за этого приходится всё восстанавливать).
|
|
|
|
|
|
- // Rus: номера шрифтов. Вся работа со шрифтами происходит именно от этих номеров.
|
|
|
|
- // Eng: font numbers. All work with fonts comes from these numbers.
|
|
|
|
- fntMain, fntEdit: LongWord;
|
|
|
|
|
|
+ У меня уже есть демка, где я делал меню, там есть перевод графических данных в текстуры.
|
|
|
|
|
|
- // Rus: номер цвета. Работа с цветом происходит именно от этого номера.
|
|
|
|
- // Eng: color number. Work with color comes from this number.
|
|
|
|
- EditColor: LongWord;
|
|
|
|
|
|
+ не сделана обработка кругового джойстика.
|
|
|
|
+ *)
|
|
|
|
+
|
|
|
|
+var
|
|
|
|
+ dirRes : UTF8String = 'assets/';
|
|
|
|
|
|
// RU: строка для получения значения из поля ввода
|
|
// RU: строка для получения значения из поля ввода
|
|
// EN: string to get value from input field
|
|
// EN: string to get value from input field
|
|
userInput : UTF8String;
|
|
userInput : UTF8String;
|
|
{$IfDef OLD_METHODS}
|
|
{$IfDef OLD_METHODS}
|
|
trackInput : Boolean;
|
|
trackInput : Boolean;
|
|
- inputRect : zglTRect2D;
|
|
|
|
|
|
+ inputRect : zglTRect;
|
|
lineAlpha : LongWord;
|
|
lineAlpha : LongWord;
|
|
|
|
|
|
TimeStart : LongWord;
|
|
TimeStart : LongWord;
|
|
{$Else}
|
|
{$Else}
|
|
|
|
+ // Rus: номера шрифтов. Вся работа со шрифтами происходит именно от этих номеров.
|
|
|
|
+ // Eng: font numbers. All work with fonts comes from these numbers.
|
|
|
|
+ fntMain, fntEdit: LongWord;
|
|
|
|
+
|
|
|
|
+ // Rus: номер цвета. Работа с цветом происходит именно от этого номера.
|
|
|
|
+ // Eng: color number. Work with color comes from this number.
|
|
|
|
+ EditColor: LongWord;
|
|
// RU: прямоугольник описывающий поле ввода
|
|
// RU: прямоугольник описывающий поле ввода
|
|
// EN: rectangle describing the input field
|
|
// EN: rectangle describing the input field
|
|
myRect: zglTRect2D;
|
|
myRect: zglTRect2D;
|
|
@@ -71,8 +77,7 @@ begin
|
|
// Текст будет выведен поверх того, что вы здесь нарисуете.
|
|
// Текст будет выведен поверх того, что вы здесь нарисуете.
|
|
// EN: displacement and rotation will be done prior to performing the procedure. I am showing you how to draw a frame.
|
|
// EN: displacement and rotation will be done prior to performing the procedure. I am showing you how to draw a frame.
|
|
// The text will be drawn on top of what you draw here.
|
|
// The text will be drawn on top of what you draw here.
|
|
-
|
|
|
|
- pr2d_Rect(- 2, - 1, myRect.W + 5, myRect.H, {$IfnDef OLD_METHODS}cl_White{$else}, $FFFFFF, 128{$EndIf}, PR2D_FILL);
|
|
|
|
|
|
+ pr2d_Rect(- 2, - 1, myRect.W + 5, myRect.H, {$IfnDef OLD_METHODS}cl_White{$else}, $FFFFFF, 128{$EndIf}, PR2D_FILL);
|
|
end;
|
|
end;
|
|
{$EndIf}
|
|
{$EndIf}
|
|
|
|
|
|
@@ -82,91 +87,93 @@ var
|
|
EScale: LongWord;
|
|
EScale: LongWord;
|
|
{$EndIf}
|
|
{$EndIf}
|
|
begin
|
|
begin
|
|
-
|
|
|
|
zgl_Enable(CORRECT_RESOLUTION);
|
|
zgl_Enable(CORRECT_RESOLUTION);
|
|
scr_CorrectResolution( 800, 600 );
|
|
scr_CorrectResolution( 800, 600 );
|
|
- log_Add('winOn = ' + u_BoolToStr(winOn));
|
|
|
|
|
|
|
|
file_OpenArchive(PAnsiChar(zgl_Get(DIRECTORY_APPLICATION)));
|
|
file_OpenArchive(PAnsiChar(zgl_Get(DIRECTORY_APPLICATION)));
|
|
|
|
|
|
|
|
+ // RU: Загружаем данные о шрифтах.
|
|
|
|
+ // EN: Loading font data.
|
|
fntMain := font_LoadFromFile( dirRes + 'font.zfi' );
|
|
fntMain := font_LoadFromFile( dirRes + 'font.zfi' );
|
|
|
|
+ fontUse := font_LoadFromFile( dirRes + 'CalibriBold50pt.zfi');
|
|
|
|
+ // note
|
|
|
|
+ // RU: Мы дважды загружаем один и тот же фонт для того, чтоб работать с ними по раздельности. Один фонт для клавиатуры, другой фонт для поля ввода.
|
|
|
|
+ // EN: We download the same font twice in order to work with them separately. One font for the keyboard, another font for the input field.
|
|
{$IfNDef OLD_METHODS}
|
|
{$IfNDef OLD_METHODS}
|
|
|
|
+ // обязательный код! Данные для отображения клавиатуры.
|
|
// RU: Загружаем данные о шрифте.
|
|
// RU: Загружаем данные о шрифте.
|
|
// EN: Load the font.
|
|
// EN: Load the font.
|
|
- fntEdit := font_LoadFromFile( dirRes + 'CalibriBold50pt.zfi');
|
|
|
|
- // Rus: для клавиатуры.
|
|
|
|
- // Eng:
|
|
|
|
- fontUse := font_LoadFromFile( dirRes + 'CalibriBold50pt.zfi');
|
|
|
|
- JoyArrow := tex_LoadFromFile(dirRes + 'arrow.png');
|
|
|
|
-
|
|
|
|
- if fLoadTextClearing then
|
|
|
|
- begin
|
|
|
|
- txt_LoadFromFile(dirRes + 'Rus.dat', LoadText);
|
|
|
|
- set_FlagForLoadText(False);
|
|
|
|
- end
|
|
|
|
- else
|
|
|
|
- log_Add('Rus.dat not loading. Global string false.');
|
|
|
|
|
|
+ fntEdit := font_LoadFromFile(dirRes + 'CalibriBold50pt.zfi');
|
|
|
|
+ JoyArrow := tex_LoadFromFile(dirRes + 'arrow.png'); // загрузили текстуру
|
|
|
|
+ tex_SetFrameSize(JoyArrow, 64, 64); // и разбили её на части, но в записях не будет указано количество полученных текстур
|
|
|
|
+ // RU: Данные для виртуальной клавиатуры.
|
|
|
|
+ // EN: Data for the virtual keyboard.
|
|
|
|
+ txt_LoadFromFile(dirRes + 'Rus.txt', LoadText);
|
|
|
|
+ // RU: Создаём виртуальную клавиатуру. Для мобильных систем это будет обязательным кодом в дальнейшем.
|
|
|
|
+ // EN: We create a virtual keyboard. For mobile systems, this will be a mandatory code in the future.
|
|
|
|
+ CreateTouchKeyboard;
|
|
{$EndIf}
|
|
{$EndIf}
|
|
|
|
|
|
file_CloseArchive();
|
|
file_CloseArchive();
|
|
- {$IfNDef OLD_METHODS}
|
|
|
|
- // Rus: очередной код для клавиатуры.
|
|
|
|
- // Eng:
|
|
|
|
- tex_SetFrameSize(JoyArrow, 64, 64); // разбили текстуру на части, но в записях не будет указано количество полученных текстур
|
|
|
|
|
|
|
|
|
|
+ {$IfNDef OLD_METHODS}
|
|
|
|
+ // RU: устанавливаем размеры шрифтов
|
|
|
|
+ // EN: set font sizes
|
|
|
|
+ setFontTextScale(15, fntMain);
|
|
|
|
+ setFontTextScale(20, fntEdit);
|
|
// RU: размер шрифта поля ввода (для понимания что происходит). Изменяя размер шрифта, мы должны менять и
|
|
// RU: размер шрифта поля ввода (для понимания что происходит). Изменяя размер шрифта, мы должны менять и
|
|
// размеры поля ввода - myRect в данном случае. Сами они не изменятся.
|
|
// размеры поля ввода - myRect в данном случае. Сами они не изменятся.
|
|
// EN: the font size of the input field (to understand what's going on). By changing the font size,
|
|
// EN: the font size of the input field (to understand what's going on). By changing the font size,
|
|
// we must also change the size of the input field - myRect in this case. They themselves will not change.
|
|
// we must also change the size of the input field - myRect in this case. They themselves will not change.
|
|
EScale := 20;
|
|
EScale := 20;
|
|
setFontTextScale(EScale, fntEdit);
|
|
setFontTextScale(EScale, fntEdit);
|
|
- // RU: указываем размеры поля ввода.
|
|
|
|
- // EN: specify the size of the input field.
|
|
|
|
|
|
+ // RU: указываем размеры поля ввода
|
|
|
|
+ // EN: specify the size of the input field
|
|
myRect.X := 200;
|
|
myRect.X := 200;
|
|
myRect.Y := 150;
|
|
myRect.Y := 150;
|
|
myRect.W := 200;
|
|
myRect.W := 200;
|
|
myRect.H := 33;
|
|
myRect.H := 33;
|
|
- // RU: указываем точку вращения, в данном случае центр поля ввода (по необходимости) и угол поворота (например 45).
|
|
|
|
- // EN: specify the point of rotation, in this case the center of the input field (if necessary) and the angle of rotation (for example 45).
|
|
|
|
|
|
+ // RU: указываем точку вращения, в данном случае центр поля ввода (по необходимости) и угол поворота (например 45)
|
|
|
|
+ // EN: specify the point of rotation, in this case the center of the input field (if necessary) and the angle of rotation (for example 45)
|
|
SetOfRotateAngleAndPoint(myRect.x + myRect.W / 2, myRect.y + myRect.H / 2, 30);
|
|
SetOfRotateAngleAndPoint(myRect.x + myRect.W / 2, myRect.y + myRect.H / 2, 30);
|
|
|
|
|
|
// RU: указываем цвет текста (добавляем новый номер цвета, хотя данная функция вам возвратит цвет, если он уже был прописан).
|
|
// RU: указываем цвет текста (добавляем новый номер цвета, хотя данная функция вам возвратит цвет, если он уже был прописан).
|
|
// EN: specify the color of the text (we add a new color number, although this function will return the color to you if it
|
|
// EN: specify the color of the text (we add a new color number, although this function will return the color to you if it
|
|
// has already been assigned).
|
|
// has already been assigned).
|
|
- EditColor := Color_FindOrAdd($40a055FF);
|
|
|
|
|
|
+ EditColor := Color_FindOrAdd($208055FF);
|
|
// Ru: устанавливаем цвета по умолчанию для всех элементов API. Эти цвета будут задействованы только при создании
|
|
// Ru: устанавливаем цвета по умолчанию для всех элементов API. Эти цвета будут задействованы только при создании
|
|
// определённого элемента. Для изменения цвета в самом (уже созданном) элементе, ни чего не прилагается.
|
|
// определённого элемента. Для изменения цвета в самом (уже созданном) элементе, ни чего не прилагается.
|
|
// Дальнейшие измениня этих значений цвета, ни как не скажется на уже созданных элементах.
|
|
// Дальнейшие измениня этих значений цвета, ни как не скажется на уже созданных элементах.
|
|
// En: set default colors for all API elements. These colors will only be used when creating a specific element.
|
|
// En: set default colors for all API elements. These colors will only be used when creating a specific element.
|
|
// To change the color in the (already created) element itself, nothing is attached. Further changes to these
|
|
// To change the color in the (already created) element itself, nothing is attached. Further changes to these
|
|
// color values will not affect the already created elements in any way.
|
|
// color values will not affect the already created elements in any way.
|
|
- SetDefColor(EditColor, cl_Black);
|
|
|
|
|
|
+ SetDefColor(EditColor, cl_Green, cl_Black);
|
|
|
|
|
|
- // RU: создаём само поле ввода с данными указанными выше и передаваемыми данными.
|
|
|
|
- // EN: create the input field itself with the data specified above and the data that needs to be transferred.
|
|
|
|
|
|
+ // RU: создаём само поле ввода с данными указанными выше и передаваемыми данными
|
|
|
|
+ // EN: create the input field itself with the data specified above and the data that needs to be transferred
|
|
myEdit := CreateEdit(myRect, fntEdit, EScale, @EditCont);
|
|
myEdit := CreateEdit(myRect, fntEdit, EScale, @EditCont);
|
|
|
|
|
|
- // RU: корректируем курсор.
|
|
|
|
- // EN: adjust the cursor.
|
|
|
|
|
|
+ // RU: корректируем курсор
|
|
|
|
+ // EN: adjust the cursor
|
|
CorrectEditCursor(myEdit, 2);
|
|
CorrectEditCursor(myEdit, 2);
|
|
|
|
|
|
|
|
+ // RU: задаём очистку экрана заданным цветом
|
|
|
|
+ // EN: set the screen to clear with a specified color
|
|
|
|
+ scr_SetClearColor(true, $7090af);
|
|
|
|
+
|
|
{$Else}
|
|
{$Else}
|
|
inputRect.X := 400 - 192;
|
|
inputRect.X := 400 - 192;
|
|
inputRect.Y := 300 - 100 - 32;
|
|
inputRect.Y := 300 - 100 - 32;
|
|
inputRect.W := 384;
|
|
inputRect.W := 384;
|
|
inputRect.H := 96;
|
|
inputRect.H := 96;
|
|
- {$EndIf}
|
|
|
|
- // RU: задаём очистку экрана заданным цветом.
|
|
|
|
- // EN: set the screen to clear with a specified color.
|
|
|
|
- scr_SetClearColor(true, $7090af);
|
|
|
|
-
|
|
|
|
- CreateTouchKeyboard;
|
|
|
|
setFontTextScale(15, fntMain);
|
|
setFontTextScale(15, fntMain);
|
|
|
|
+ {$EndIf}
|
|
|
|
+ log_Add('Initialization - end');
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure Draw;
|
|
procedure Draw;
|
|
-var
|
|
|
|
- w : Single;
|
|
|
|
|
|
+ var
|
|
|
|
+ w : Single;
|
|
begin
|
|
begin
|
|
batch2d_Begin;
|
|
batch2d_Begin;
|
|
setTextColor(Get_Color(cl_Blue));
|
|
setTextColor(Get_Color(cl_Blue));
|
|
@@ -190,17 +197,17 @@ begin
|
|
pr2d_Rect( inputRect.X, inputRect.Y, inputRect.W, inputRect.H, $FFFFFF, 255 );
|
|
pr2d_Rect( inputRect.X, inputRect.Y, inputRect.W, inputRect.H, $FFFFFF, 255 );
|
|
if trackInput Then
|
|
if trackInput Then
|
|
begin
|
|
begin
|
|
- text_Draw( fntMain, 400, 300 - 100, 'Press Done to stop track text input:', TEXT_HALIGN_CENTER );
|
|
|
|
|
|
+ text_Draw( fntMain, 400, 300 - 100, 'Press Enter to stop track text input:', TEXT_HALIGN_CENTER );
|
|
w := text_GetWidth( fntMain, userInput );
|
|
w := text_GetWidth( fntMain, userInput );
|
|
pr2d_Rect( 400 + w / 2 + 2, 300 - 70, 10, 20, $FFFFFF, lineAlpha, PR2D_FILL );
|
|
pr2d_Rect( 400 + w / 2 + 2, 300 - 70, 10, 20, $FFFFFF, lineAlpha, PR2D_FILL );
|
|
end else
|
|
end else
|
|
- text_Draw( fntMain, 400, 300 - 100, 'Tap here to enter text(maximum - 24 symbols):', TEXT_HALIGN_CENTER );
|
|
|
|
|
|
+ text_Draw( fntMain, 400, 300 - 100, 'Click here to enter text(maximum - 24 symbols):', TEXT_HALIGN_CENTER );
|
|
text_Draw( fntMain, 400, 300 - 70, userInput, TEXT_HALIGN_CENTER );
|
|
text_Draw( fntMain, 400, 300 - 70, userInput, TEXT_HALIGN_CENTER );
|
|
{$Else}
|
|
{$Else}
|
|
-{ text_Draw(fntMain, 0, 36, 'Press F5 to copy from Edit and draw'); // какой я нафиг англичанин? ))))
|
|
|
|
- text_Draw(fntMain, 0, 54, 'Press F12 - Rus/Eng'); // переделать для Android
|
|
|
|
|
|
+ text_Draw(fntMain, 0, 36, 'Press F5 to copy from Edit and draw'); // какой я нафиг англичанин? ))))
|
|
|
|
+ text_Draw(fntMain, 0, 54, 'Press F12 - Rus/Eng');
|
|
if userInput <> '' then
|
|
if userInput <> '' then
|
|
- text_Draw(fntMain, 400, 300 - 70, userInput, TEXT_HALIGN_CENTER); }
|
|
|
|
|
|
+ text_Draw(fntMain, 400, 300 - 70, userInput, TEXT_HALIGN_CENTER);
|
|
{$EndIf}
|
|
{$EndIf}
|
|
batch2d_End;
|
|
batch2d_End;
|
|
end;
|
|
end;
|
|
@@ -212,7 +219,12 @@ begin
|
|
DEC( lineAlpha, 10 )
|
|
DEC( lineAlpha, 10 )
|
|
else
|
|
else
|
|
lineAlpha := 255;
|
|
lineAlpha := 255;
|
|
|
|
+end;
|
|
|
|
+{$EndIf}
|
|
|
|
|
|
|
|
+procedure KeyMouseEvent;
|
|
|
|
+begin
|
|
|
|
+ {$IfDef OLD_METHODS}
|
|
// RU: Проверить тапнул ли пользователь в пределах inputRect и начать отслеживать ввод текста.
|
|
// RU: Проверить тапнул ли пользователь в пределах inputRect и начать отслеживать ввод текста.
|
|
// EN: Check if there was tap inside inputRect and start to track text input.
|
|
// EN: Check if there was tap inside inputRect and start to track text input.
|
|
if touch_Tap( 0 ) and col2d_PointInRect( touch_X( 0 ), touch_Y( 0 ), inputRect ) Then
|
|
if touch_Tap( 0 ) and col2d_PointInRect( touch_X( 0 ), touch_Y( 0 ), inputRect ) Then
|
|
@@ -233,30 +245,34 @@ begin
|
|
// EN: Get inputted by user text.
|
|
// EN: Get inputted by user text.
|
|
if trackInput Then
|
|
if trackInput Then
|
|
userInput := key_GetText();
|
|
userInput := key_GetText();
|
|
-
|
|
|
|
- // RU: Обязательно очищаем состояния всех подсистем ввода.
|
|
|
|
- // EN: Necessarily clear all the states of input subsystems.
|
|
|
|
- touch_ClearState();
|
|
|
|
- key_ClearState();
|
|
|
|
|
|
+ {$Else}
|
|
|
|
+ // RU: по нажатию F5 копируем то, что написано в поле ввода
|
|
|
|
+ // EN: by pressing F5, copy what is written in the input field
|
|
|
|
+ if keysDown[K_F5] then
|
|
|
|
+ begin
|
|
|
|
+ userInput := GetEditToText(myEdit);
|
|
|
|
+ end;
|
|
|
|
+ {$EndIf}
|
|
end;
|
|
end;
|
|
-{$EndIf}
|
|
|
|
|
|
|
|
procedure Restore;
|
|
procedure Restore;
|
|
begin
|
|
begin
|
|
file_OpenArchive( PAnsiChar( zgl_Get( DIRECTORY_APPLICATION ) ) );
|
|
file_OpenArchive( PAnsiChar( zgl_Get( DIRECTORY_APPLICATION ) ) );
|
|
font_RestoreFromFile( fntMain, dirRes + 'font.zfi' );
|
|
font_RestoreFromFile( fntMain, dirRes + 'font.zfi' );
|
|
- font_RestoreFromFile( fntEdit, dirRes + 'CalibriBold50pt.zfi' );
|
|
|
|
- tex_RestoreFromFile(JoyArrow, dirRes + 'arrow.png');
|
|
|
|
|
|
+ {$IfNDef OLD_METHODS}
|
|
|
|
+ font_RestoreFromFile( fntMain, dirRes + 'CalibriBold50pt.zfi' );
|
|
|
|
+ tex_RestoreFromFile( JoyArrow, dirRes + 'arrow.png' );
|
|
|
|
+ {$EndIf}
|
|
file_CloseArchive();
|
|
file_CloseArchive();
|
|
- log_Add('Restored true!!!');
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure Java_zengl_android_ZenGL_Main( var env; var thiz ); cdecl;
|
|
procedure Java_zengl_android_ZenGL_Main( var env; var thiz ); cdecl;
|
|
begin
|
|
begin
|
|
{$IfDef OLD_METHODS}
|
|
{$IfDef OLD_METHODS}
|
|
- TimerStart := timer_Add( @Timer, 16, t_Start );
|
|
|
|
|
|
+ TimerStart := timer_Add( @Timer, 16, Start );
|
|
{$EndIf}
|
|
{$EndIf}
|
|
|
|
|
|
|
|
+ zgl_Reg(SYS_EVENTS, @KeyMouseEvent);
|
|
zgl_Reg( SYS_LOAD, @Init );
|
|
zgl_Reg( SYS_LOAD, @Init );
|
|
zgl_Reg( SYS_DRAW, @Draw );
|
|
zgl_Reg( SYS_DRAW, @Draw );
|
|
zgl_Reg( SYS_ANDROID_RESTORE, @Restore );
|
|
zgl_Reg( SYS_ANDROID_RESTORE, @Restore );
|