22
33#include " android_globals.hxx"
44#include " asset_file.hxx"
5+ #include " window.hxx"
56
67application_glue::application_glue (utki::version_duplet gl_version) :
78 gl_version(std::move(gl_version))
89{}
910
10- app_window& application_glue::make_window (ruisapp::window_parameters window_params){
11+ app_window& application_glue::make_window (ruisapp::window_parameters window_params)
12+ {
13+ if (this ->window .has_value ()) {
14+ throw std::logic_error (
15+ " application::make_window(): one window already exists, only one window allowed on android"
16+ );
17+ }
18+
1119 utki::assert (!this ->window .has_value (), SL );
1220
13- // TODO:
21+ auto ruis_native_window = utki::make_shared<native_window>(this ->gl_version , window_params);
22+
23+ // TODO: std::move(ruis_native_window)?
24+ auto rendering_context = utki::make_shared<ruis::render::opengles::context>(ruis_native_window);
25+
26+ auto ruis_context = utki::make_shared<ruis::context>(ruis::context::parameters{
27+ .post_to_ui_thread_function =
28+ [this ](std::function<void ()> procedure) {
29+ // TODO:
30+ // if (PostMessage(
31+ // NULL, // post message to UI thread's message queue
32+ // WM_USER,
33+ // 0, // no wParam
34+ // // NOLINTNEXTLINE(cppcoreguidelines-owning-memory, cppcoreguidelines-pro-type-reinterpret-cast)
35+ // reinterpret_cast<LPARAM>(new std::remove_reference_t<decltype(procedure)>(std::move(procedure)))
36+ // ) == 0)
37+ // {
38+ // throw std::runtime_error("PostMessage(): failed");
39+ // }
40+ },
41+ .updater = this ->updater ,
42+ .renderer = utki::make_shared<ruis::render::renderer>(
43+ rendering_context,
44+ this ->rendering_context .get ().make_shaders (),
45+ utki::make_shared<ruis::render::renderer::objects>(rendering_context)
46+ ),
47+ .style_provider = this ->ruis_style_provider ,
48+ // TODO:
49+ // .units = ruis::units(
50+ // ruis_native_window.get().get_dots_per_inch(), //
51+ // ruis_native_window.get().get_dots_per_pp()
52+ // )
53+ });
54+
55+ auto ruisapp_window = utki::make_shared<app_window>(
56+ std::move (ruis_context), //
57+ std::move (ruis_native_window)
58+ );
59+
60+ // TODO: window surface will likely be created later, so defer setting viewport till that time?
61+ // ruisapp_window.get().gui.set_viewport( //
62+ // ruis::rect(
63+ // 0, //
64+ // 0,
65+ // ruis::real(window_params.dims.x()),
66+ // ruis::real(window_params.dims.y())
67+ // )
68+ // );
69+
70+ this ->window = std::move (ruisapp_window);
1471
1572 utki::assert (this ->window .has_value (), SL );
1673 return this ->window .value ();
1774}
1875
19- void application_glue::render (){
20- if (this ->window .has_value ()){
76+ void application_glue::render ()
77+ {
78+ if (this ->window .has_value ()) {
2179 this ->window .value ().render ();
2280 }
2381}
2482
83+ namespace {
84+ ruisapp::application::directories get_application_directories (std::string_view app_name)
85+ {
86+ auto & glob = get_glob ();
87+
88+ auto storage_dir = papki::as_dir (glob.java_functions .get_storage_dir ());
89+
90+ ruisapp::application::directories dirs;
91+
92+ dirs.cache = utki::cat (storage_dir, " cache/" );
93+ dirs.config = utki::cat (storage_dir, " config/" );
94+ dirs.state = utki::cat (storage_dir, " state/" );
95+
96+ return dirs;
97+ }
98+ } // namespace
99+
100+ ruisapp::application::application (parameters params) :
101+ application(
102+ utki::make_unique<application_glue>(params.graphics_api_version), //
103+ get_application_directories(params.name),
104+ std::move(params)
105+ )
106+ {}
107+
25108std::unique_ptr<papki::file> ruisapp::application::get_res_file (std::string_view path) const
26109{
27110 utki::assert (globals_wrapper::native_activity, SL );
@@ -33,7 +116,8 @@ std::unique_ptr<papki::file> ruisapp::application::get_res_file(std::string_view
33116 );
34117}
35118
36- ruisapp::window& ruisapp::application::make_window (ruisapp::window_parameters window_params){
119+ ruisapp::window& ruisapp::application::make_window (ruisapp::window_parameters window_params)
120+ {
37121 auto & glue = get_glue (*this );
38122 return glue.make_window (std::move (window_params));
39123}
0 commit comments