YSTest: Main.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YDE/Clock/Main.cpp
浏览该文件的文档.
1 /*
2 © 2014, 2016-2018 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include <YSBuild.h>
29 #include <ctime>
30 using namespace std;
31 using namespace YSLib;
32
33 namespace Clock
34 {
35
36 using namespace YSLib;
37 using namespace Drawing;
38 using namespace UI;
39
40 } // namespace Clock;
41
42 int
43 main()
44 {
45 using namespace Host;
46 using namespace Clock;
47 static yconstexpr const float pi2(3.14159F * 2);
48 static yconstexpr const SDst len(400), rad(len / 2 - 6);
49 static yconstexpr const Vec center(len / 2, len / 2);
50 static std::time_t old, now;
51 GUIApplication app;
52 GAnimationSession<InvalidationUpdater> ani;
53 Timers::Timer tmr(std::chrono::milliseconds(1000 / 10));
54 MLabel lbl(Font(FetchDefaultTypeface().GetFontFamily(), 24,
55 FontStyle::Bold), {0xE0, 0x80, 0x20, 0x80}, TextAlignment::Center);
56 Panel pnl({400, 300, len, len + 80});
57
58 yunseq(
59 lbl.Margin = {0, 0, len, 0},
60 pnl.Background = SolidBrush({0x40, 0x40, 0x40, 0x40}),
61 FetchEvent<Click>(pnl) += [](CursorEventArgs&& e){
62 if(e.GetKeys()[KeyCodes::Secondary])
63 YSLib::PostQuitMessage(0);
64 },
65 FetchEvent<Paint>(pnl) += [&](PaintEventArgs&& e){
66 using namespace ColorSpace;
67 static const auto calc_pt([](float phi, float r)->Point{
68 yunseq(phi *= pi2, r *= rad);
69 return {std::sin(phi) * r, -std::cos(phi) * r};
70 });
71 const auto& g(e.Target);
72 const auto& pt(e.Location + center);
73 const auto& bounds(e.ClipArea);
74 const auto drawl([&](float phi, float r, Color c){
75 DrawLineSeg(g, bounds, pt, pt + calc_pt(phi, r), c);
76 });
77
78 DrawCircle(g, bounds, pt, rad, Blue);
79 FillCircle(g, bounds, pt, rad - 4, {211, 211, 221, 0xC0});
80 FillCircle(g, bounds, pt, 6, Navy);
81 for(size_t i(0); i < 60; ++i)
82 FillCircle(g, bounds, pt + calc_pt(i / 60.F, .95F),
83 i % 5 == 0 ? 4 : 2, i % 5 == 0 ? Color(72, 72, 192, 0xD0)
84 : Color(72, 160, 72, 0xD0));
85
86 const auto t(std::localtime(&now));
87
88 drawl((t->tm_hour + t->tm_min / 60.F) / 12, .5F, Maroon);
89 drawl((t->tm_min + t->tm_sec / 60.F) / 60, .8F, Fuchsia);
90 drawl(t->tm_sec / 60.F, .9F, Green);
91 lbl.Text = ystdex::sfmt("%d-%02d-%02d %02d:%02d:%02d",
92 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min,
93 t->tm_sec);
94 lbl(std::move(e));
95 }
96 );
97 UI::SetupByTimer(ani, pnl, tmr, [&]{
98 std::time(&now);
99
100 if(old != now)
101 {
102 YTraceDe(Informative, "Time updated.");
103 Invalidate(pnl);
104 old = now;
105 }
106 });
107 std::time(&now);
108 ShowTopLevelDraggable(pnl);
109 // TODO: Port to other hosted platforms.
110 #if YCL_Win32
111 GetWindowPtrOf(pnl)->UseOpacity = true;
112 #endif
113 Execute(app);
114 }
115
YSLib::Drawing::DrawLineSeg
The boundary is out of the DrawLineSeg
Definition: YDraw.h:161
CHRLib::e
const char const char * e
Definition: CharacterProcessing.h:112
YSLib::Drawing::SolidBrush
单色画刷。
Definition: YBrush.h:59
YSBuild.h
YSLib 库配置文件。
CHRLib::c
c
Definition: CharacterProcessing.h:84
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YSLib::PostQuitMessage
YF_API void PostQuitMessage(int=0, Messaging::Priority p=DefaultQuitPriority)
以指定错误码和优先级发起 Shell 终止请求。
Definition: YApplication.cpp:87
YSLib::UI::Panel
面板。
Definition: YPanel.h:46
YSLib::GUIApplication
平台相关的应用程序类。
Definition: GUIApplication.h:200
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::UI::CursorEventArgs
指针设备输入事件参数类。
Definition: YWidgetEvent.h:216
YSLib::Consoles::Blue
@ Blue
Definition: YConsole.h:62
platform::KeyCodes::DS::Secondary
@ Secondary
Definition: Keys.h:264
YSLib::UI::GAnimationSession< InvalidationUpdater >
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
YSLib::Execute
void Execute(GUIApplication &app, shared_ptr< Shell > p_shl)
Definition: GUIApplication.cpp:308
YSLib::UI::SetupByTimer
void SetupByTimer(_tAnimation &ani, IWidget &wgt, _tTimer &&timer, _func f)
安装以计时器控制的动画效果。
Definition: Animation.h:218
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
YSLib::Drawing::DrawCircle
bounds c YF_API void DrawCircle(const Graphics &g, const Rect &bounds, const Point &, SDst, Color)
描画圆形。
Definition: YDraw.cpp:180
platform::Descriptions::Informative
@ Informative
Definition: YCommon.h:185
std
Definition: optional.h:982
ystdex::sfmt
_tString sfmt(const typename string_traits< _tString >::value_type *fmt,...)
以 C 标准输出格式的输出 basic_string 实例的对象。
Definition: string.hpp:2028
YSLib::Drawing::GBinaryGroup< SPos >
main
int main()
Definition: YDE/Clock/Main.cpp:43
YSLib::Drawing::ColorSpace::Fuchsia
@ Fuchsia
Definition: YGDIBase.h:264
YSLib::i
return i
Definition: YCoreUtilities.h:177
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:407
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::FillCircle
YF_API void FillCircle(const Graphics &g, const Rect &bounds, const Point &, SDst, Color)
填充圆形。
Definition: YDraw.cpp:202
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
Color
Pixel Color
Definition: CharRenderer.cpp:59
YSLib::UI::MLabel
标签模块。
Definition: Label.h:62
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YSLib::Drawing::ColorSpace::Navy
@ Navy
Definition: YGDIBase.h:269
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
YSLib::Timers::Timer
计时器。
Definition: YTimer.h:78
Clock
Definition: YDE/Clock/Main.cpp:34
YSLib::Drawing::Font
字体：字模，包含字型、样式和大小。
Definition: Font.h:589
YSLib::Consoles::Green
@ Green
Definition: YConsole.h:63
YSLib::Drawing::ColorSpace::Maroon
@ Maroon
Definition: YGDIBase.h:268
YSLib::Drawing::FetchDefaultTypeface
YB_ATTR_nodiscard YF_API const Typeface & FetchDefaultTypeface()
取默认字型引用。
Definition: Font.cpp:391