@@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
2020/* ================ LICENSE END ================ */
2121
22- #include " android_globals .hxx"
22+ #include " globals .hxx"
2323
2424// TODO: remove
2525using namespace ruisapp ;
2626
27- namesapce
27+ namespace
2828{
2929 // struct window_wrapper : public utki::destructable {
3030 // // EGLDisplay display;
@@ -232,8 +232,6 @@ namesapce
232232 // return get_impl(get_window_pimpl(app));
233233 // }
234234
235- ruis::vector2 cur_window_dims (0 , 0 );
236-
237235 // array of current pointer positions, needed to detect which pointers have
238236 // actually moved.
239237 std::array<ruis::vector2, 10 > pointers;
@@ -243,7 +241,10 @@ namesapce
243241 const ruis::vector2& p
244242 )
245243 {
246- ruis::vector2 ret (p.x (), p.y () - (cur_window_dims.y () - win_dim.y ()));
244+ auto & glob = get_glob ();
245+
246+ ruis::vector2 ret (p.x (), //
247+ p.y () - (glob.cur_window_dims .y () - win_dim.y ()));
247248 // utki::log_debug([&](auto&o){o << "android_win_coords_to_ruis_win_rect_coords(): ret
248249 // = " << ret << std::endl;});
249250 using std::round;
@@ -725,8 +726,8 @@ void on_stop(ANativeActivity* activity)
725726
726727void on_configuration_changed (ANativeActivity* activity)
727728{
728- utki::assert (android_globals_wrapper ::native_activity, SL );
729- utki::assert (activity == android_globals_wrapper ::native_activity, SL );
729+ utki::assert (globals_wrapper ::native_activity, SL );
730+ utki::assert (activity == globals_wrapper ::native_activity, SL );
730731
731732 utki::log_debug ([](auto & o) {
732733 o << " on_configuration_changed(): invoked" << std::endl;
@@ -752,7 +753,7 @@ void on_configuration_changed(ANativeActivity* activity)
752753 case ACONFIGURATION_ORIENTATION_LAND :
753754 case ACONFIGURATION_ORIENTATION_PORT :
754755 using std::swap;
755- swap (cur_window_dims.x (), cur_window_dims.y ());
756+ swap (glob. cur_window_dims .x (), glob. cur_window_dims .y ());
756757 break ;
757758 case ACONFIGURATION_ORIENTATION_SQUARE :
758759 // do nothing
@@ -788,8 +789,8 @@ void on_native_window_created(
788789 ANativeWindow* window
789790)
790791{
791- utki::assert (android_globals_wrapper ::native_activity, SL );
792- utki::assert (activity == android_globals_wrapper ::native_activity, SL );
792+ utki::assert (globals_wrapper ::native_activity, SL );
793+ utki::assert (activity == globals_wrapper ::native_activity, SL );
793794
794795 utki::log_debug ([](auto & o) {
795796 o << " on_native_window_created(): invoked" << std::endl;
@@ -800,8 +801,8 @@ void on_native_window_created(
800801 // save window in a static var, so it is accessible for creating window surface
801802 glob.android_window = window;
802803
803- cur_window_dims.x () = float (ANativeWindow_getWidth (window));
804- cur_window_dims.y () = float (ANativeWindow_getHeight (window));
804+ glob. cur_window_dims .x () = float (ANativeWindow_getWidth (window));
805+ glob. cur_window_dims .y () = float (ANativeWindow_getHeight (window));
805806
806807 // If we have no application instance yet, create it now.
807808 // Otherwise the window was re-created after moving the app from background to foreground
@@ -848,11 +849,11 @@ void on_native_window_resized(ANativeActivity* activity,//
848849 });
849850
850851 // save window dimensions
851- cur_window_dims.x () = float (ANativeWindow_getWidth (window));
852- cur_window_dims.y () = float (ANativeWindow_getHeight (window));
852+ glob. cur_window_dims .x () = float (ANativeWindow_getWidth (window));
853+ glob. cur_window_dims .y () = float (ANativeWindow_getHeight (window));
853854
854855 utki::log_debug ([&](auto & o) {
855- o << " on_native_window_resized(): cur_window_dims = " << cur_window_dims << std::endl;
856+ o << " on_native_window_resized(): cur_window_dims = " << glob. cur_window_dims << std::endl;
856857 });
857858}
858859
@@ -988,12 +989,14 @@ void on_content_rect_changed(
988989 const ARect* rect
989990)
990991{
992+ auto & glob = get_glob ();
993+
991994 utki::log_debug ([&](auto & o) {
992995 o << " on_content_rect_changed(): invoked, left = " << rect->left << " right = " << rect->right
993996 << " top = " << rect->top << " bottom = " << rect->bottom << std::endl;
994997 });
995998 utki::log_debug ([&](auto & o) {
996- o << " on_content_rect_changed(): cur_window_dims = " << cur_window_dims << std::endl;
999+ o << " on_content_rect_changed(): cur_window_dims = " << glob. cur_window_dims << std::endl;
9971000 });
9981001
9991002 // Sometimes Android calls on_content_rect_changed() even after native window
@@ -1015,7 +1018,7 @@ void on_content_rect_changed(
10151018 app,
10161019 ruis::rect (
10171020 float (rect->left ),
1018- cur_window_dims.y () - float (rect->bottom ),
1021+ glob. cur_window_dims .y () - float (rect->bottom ),
10191022 float (rect->right - rect->left ),
10201023 float (rect->bottom - rect->top )
10211024 )
@@ -1031,7 +1034,7 @@ void on_destroy(ANativeActivity* activity)
10311034 o << " on_destroy(): invoked" << std::endl;
10321035 });
10331036
1034- android_globals_wrapper ::destroy ();
1037+ globals_wrapper ::destroy ();
10351038}
10361039} // namespace
10371040
@@ -1062,5 +1065,5 @@ void ANativeActivity_onCreate(
10621065 activity->callbacks ->onInputQueueDestroyed = &on_input_queue_destroyed;
10631066 activity->callbacks ->onContentRectChanged = &on_content_rect_changed;
10641067
1065- android_globals_wrapper ::create (activity);
1068+ globals_wrapper ::create (activity);
10661069}
0 commit comments