@@ -39,10 +39,151 @@ ruisapp::application::directories get_application_directories(std::string_view a
3939}
4040} // namespace
4141
42+ application_glue::application_glue (const utki::version_duplet& gl_version) :
43+ gl_version(gl_version),
44+ shared_gl_context_native_window(utki::make_shared<native_window>(
45+ this ->display,
46+ this ->gl_version,
47+ ruisapp::window_parameters{
48+ .dims = {1 , 1 },
49+ .fullscreen = false ,
50+ .visible = false
51+ },
52+ nullptr // no shared gl context
53+ )),
54+ resource_loader_ruis_rendering_context([&]() {
55+ utki::logcat_debug (" application_glue::application_glue(): creating shared gl context" , ' \n ' );
56+ auto c = utki::make_shared<ruis::render::opengl::context>(this ->shared_gl_context_native_window );
57+ utki::logcat_debug (" application_glue::application_glue(): shared gl context created" , ' \n ' );
58+ return c;
59+ }()),
60+ common_shaders (this ->resource_loader_ruis_rendering_context.get().make_shaders()),
61+ common_render_objects(
62+ utki::make_shared<ruis::render::renderer::objects>(this ->resource_loader_ruis_rendering_context)
63+ ),
64+ ruis_resource_loader( //
65+ utki::make_shared<ruis::resource_loader>(
66+ this ->resource_loader_ruis_rendering_context, //
67+ this ->common_render_objects
68+ )
69+ ),
70+ ruis_style_provider( //
71+ utki::make_shared<ruis::style_provider>(this ->ruis_resource_loader)
72+ )
73+ {}
74+
75+ void application_glue::render () {
76+ for (auto & w : this ->windows ) {
77+ w.second .get ().render ();
78+ }
79+ }
80+
81+ app_window* application_glue::get_window (native_window::window_id_type id) {
82+ auto i = this ->windows .find (id);
83+ if (i == this ->windows .end ()) {
84+ return nullptr ;
85+ }
86+
87+ return &i->second .get ();
88+ }
89+
90+ ruisapp::window& application_glue::make_window (ruisapp::window_parameters window_params) {
91+ auto ruis_native_window = utki::make_shared<native_window>(
92+ this ->display ,
93+ this ->gl_version ,
94+ window_params,
95+ &this ->shared_gl_context_native_window .get ()
96+ );
97+
98+ auto ruis_context = utki::make_shared<ruis::context>(ruis::context::parameters{
99+ .post_to_ui_thread_function =
100+ [this ](std::function<void ()> procedure) {
101+ if (PostMessage (
102+ NULL , // post message to UI thread's message queue
103+ WM_USER,
104+ 0 , // no wParam
105+ // NOLINTNEXTLINE(cppcoreguidelines-owning-memory, cppcoreguidelines-pro-type-reinterpret-cast)
106+ reinterpret_cast <LPARAM>(
107+ new std::remove_reference_t <decltype (procedure)>(std::move (procedure))
108+ )
109+ ) == 0 )
110+ {
111+ throw std::runtime_error (" PostMessage(): failed" );
112+ }
113+ },
114+ .updater = this ->updater ,
115+ .renderer = utki::make_shared<ruis::render::renderer>(
116+ #ifdef RUISAPP_RENDER_OPENGL
117+ utki::make_shared<ruis::render::opengl::context>(ruis_native_window),
118+ #elif defined(RUISAPP_RENDER_OPENGLES)
119+ utki::make_shared<ruis::render::opengles::context>(ruis_native_window),
120+ #else
121+ # error "Unknown graphics API"
122+ #endif
123+ this ->common_shaders ,
124+ this ->common_render_objects
125+ ),
126+ .style_provider = this ->ruis_style_provider
127+ });
128+
129+ auto ruisapp_window = utki::make_shared<app_window>(
130+ std::move (ruis_context), //
131+ std::move (ruis_native_window)
132+ );
133+
134+ ruisapp_window.get ().gui .set_viewport ( //
135+ ruis::rect (
136+ 0 , //
137+ 0 ,
138+ ruis::real (window_params.dims .x ()),
139+ ruis::real (window_params.dims .y ())
140+ )
141+ );
142+
143+ auto res = this ->windows .insert ( //
144+ std::make_pair (
145+ ruisapp_window.get ().ruis_native_window .get ().get_id (), //
146+ std::move (ruisapp_window)
147+ )
148+ );
149+ utki::assert (res.second , SL);
150+
151+ return res.first ->second .get ();
152+ }
153+
154+ void application_glue::destroy_window (native_window::window_id_type id){
155+ auto i = this ->windows .find (id);
156+ utki::assert (i != this ->windows .end (), SL);
157+
158+ this ->windows_to_destroy .push_back (std::move (i->second ));
159+ this ->windows .erase (i);
160+ }
161+
42162ruisapp::application::application (parameters params) :
43163 application(
44164 utki::make_unique<application_glue>(params.graphics_api_version), //
45165 get_application_directories(params.name),
46166 std::move(params)
47167 )
48168{}
169+
170+ void ruisapp::application::quit () noexcept {
171+ auto & glue = get_glue (*this );
172+
173+ PostQuitMessage (
174+ 0 // exit code
175+ );
176+ }
177+
178+ ruisapp::window& ruisapp::application::make_window (ruisapp::window_parameters window_params) {
179+ auto & glue = get_glue (*this );
180+ return glue.make_window (std::move (window_params));
181+ }
182+
183+ void ruisapp::application::destroy_window (ruisapp::window& w) {
184+ auto & glue = get_glue (*this );
185+
186+ utki::assert (dynamic_cast <app_window*>(&w), SL);
187+ auto & app_win = static_cast <app_window&>(w);
188+ glue.destroy_window (app_win.ruis_native_window .get ().get_id ());
189+ }
0 commit comments