CtrlLib, Doc: added tutorial about time callback (23).

This commit is contained in:
Zbigniew Rębacz 2023-10-27 23:44:46 +02:00
parent 42a65fc354
commit e029af614f
6 changed files with 206 additions and 47 deletions

View file

@ -1,12 +1,11 @@
description "Internationalizing applications (i18n)\377";
uses
CtrlLib;
file
main.cpp,
Gui23.t;
mainconfig
"" = "GUI";
description "Refreshing GUI periodically\377";
uses
CtrlLib;
file
main.cpp;
mainconfig
"" = "GUI";

View file

@ -1,40 +1,47 @@
#include <CtrlLib/CtrlLib.h>
#define TFILE <Gui23/Gui23.t>
#include <Core/t.h>
using namespace Upp;
struct MyAppWindow : TopWindow {
MyAppWindow() {
Title(t_("My application"));
Zoomable().Sizeable().SetRect(0, 0, 550, 100);
}
void Paint(Draw& w) override {
w.DrawRect(GetSize(), SLtYellow);
w.DrawText(20, 20, t_("Hello translation engine!"), Arial(30), Blue);
}
Rect rect;
Color color;
MyAppWindow() {
Zoomable().SetRect(0, 0, 200, 200);
RandomizeRect();
SetTimeCallback(-2000, [=] { OnTimer(); });
}
~MyAppWindow() {
KillTimeCallback();
}
void Paint(Draw& w) override {
Size sz = GetSize();
w.DrawRect(sz, White());
w.DrawRect(rect, color);
}
void OnTimer() {
RandomizeRect();
Refresh();
}
void RandomizeRect() {
Size sz = GetSize();
int length = 50;
int x = Random() % (sz.cx - length);
int y = Random() % (sz.cy - length);
rect = Rect(x, y, x + length, y + length);
color = Color(Random() % 255, Random() % 255, Random() % 255);
}
};
GUI_APP_MAIN
{
// Set system language for whole application
SetLanguage(GetSystemLNG());
// Uncomment to force specific language...
// SetLanguage("en-us"); // English = default
// SetLanguage("cs-cz"); // Czech
// SetLanguage("de-de"); // German
// SetLanguage("es-es"); // Spanish
// SetLanguage("fr-fr"); // French
// SetLanguage("it-it"); // Italian
// SetLanguage("ja-jp"); // Japanese
// SetLanguage("pl-pl"); // Polish
// SetLanguage("pt-pt"); // Portuguese
// SetLanguage("ru-ru"); // Russian
// SetLanguage("tr-tr"); // Turkish
// SetLanguage("zh-cn"); // Traditional Chinese
MyAppWindow().Run();
MyAppWindow().Run();
}

12
tutorial/Gui24/Gui24.upp Normal file
View file

@ -0,0 +1,12 @@
description "Internationalizing applications (i18n)\377";
uses
CtrlLib;
file
main.cpp,
Gui24.t;
mainconfig
"" = "GUI";

40
tutorial/Gui24/main.cpp Normal file
View file

@ -0,0 +1,40 @@
#include <CtrlLib/CtrlLib.h>
#define TFILE <Gui24/Gui24.t>
#include <Core/t.h>
using namespace Upp;
struct MyAppWindow : TopWindow {
MyAppWindow() {
Title(t_("My application"));
Zoomable().Sizeable().SetRect(0, 0, 550, 100);
}
void Paint(Draw& w) override {
w.DrawRect(GetSize(), SLtYellow);
w.DrawText(20, 20, t_("Hello translation engine!"), Arial(30), Blue);
}
};
GUI_APP_MAIN
{
// Set system language for whole application
SetLanguage(GetSystemLNG());
// Uncomment to force specific language...
// SetLanguage("en-us"); // English = default
// SetLanguage("cs-cz"); // Czech
// SetLanguage("de-de"); // German
// SetLanguage("es-es"); // Spanish
// SetLanguage("fr-fr"); // French
// SetLanguage("it-it"); // Italian
// SetLanguage("ja-jp"); // Japanese
// SetLanguage("pl-pl"); // Polish
// SetLanguage("pt-pt"); // Portuguese
// SetLanguage("ru-ru"); // Russian
// SetLanguage("tr-tr"); // Turkish
// SetLanguage("zh-cn"); // Traditional Chinese
MyAppWindow().Run();
}