Skip to content

Commit 3ce84cb

Browse files
committed
stuff
1 parent 146faac commit 3ce84cb

7 files changed

Lines changed: 195 additions & 98 deletions

File tree

src/ruisapp/glue/android/android_configuration.hxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
namespace {
66
class android_configuration_wrapper
77
{
8-
const AConfiguration* config;
8+
AConfiguration* config;
99

1010
public:
11-
android_configuration_wrapper(AAssetManager& am);
11+
explicit android_configuration_wrapper(AAssetManager& am);
12+
13+
android_configuration_wrapper(const android_configuration_wrapper&) = delete;
14+
android_configuration_wrapper& operator=(const android_configuration_wrapper&) = delete;
15+
16+
android_configuration_wrapper(android_configuration_wrapper&&) = delete;
17+
android_configuration_wrapper& operator=(android_configuration_wrapper&&) = delete;
1218

1319
~android_configuration_wrapper();
1420

src/ruisapp/glue/android/application.cxx

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "application.hxx"
22

3-
#include "android_globals.hxx"
3+
#include <ruis/render/opengles/context.hpp>
4+
45
#include "asset_file.hxx"
6+
#include "globals.hxx"
57
#include "window.hxx"
68

79
application_glue::application_glue(utki::version_duplet gl_version) :
@@ -18,11 +20,23 @@ app_window& application_glue::make_window(ruisapp::window_parameters window_para
1820

1921
utki::assert(!this->window.has_value(), SL);
2022

21-
auto ruis_native_window = utki::make_shared<native_window>(this->gl_version, window_params);
23+
auto ruis_native_window = utki::make_shared<native_window>(
24+
this->gl_version, //
25+
window_params
26+
);
2227

23-
// TODO: std::move(ruis_native_window)?
2428
auto rendering_context = utki::make_shared<ruis::render::opengles::context>(ruis_native_window);
2529

30+
auto common_render_objects = utki::make_shared<ruis::render::renderer::objects>(rendering_context);
31+
auto common_shaders = rendering_context.get().make_shaders();
32+
33+
auto ruis_resource_loader = utki::make_shared<ruis::resource_loader>(
34+
rendering_context, //
35+
common_render_objects
36+
);
37+
38+
auto ruis_style_provider = utki::make_shared<ruis::style_provider>(std::move(ruis_resource_loader));
39+
2640
auto ruis_context = utki::make_shared<ruis::context>(ruis::context::parameters{
2741
.post_to_ui_thread_function =
2842
[this](std::function<void()> procedure) {
@@ -40,19 +54,19 @@ app_window& application_glue::make_window(ruisapp::window_parameters window_para
4054
},
4155
.updater = this->updater,
4256
.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)
57+
std::move(rendering_context),
58+
std::move(common_shaders),
59+
std::move(common_render_objects)
4660
),
47-
.style_provider = this->ruis_style_provider,
61+
.style_provider = std::move(ruis_style_provider),
4862
// TODO:
4963
// .units = ruis::units(
5064
// ruis_native_window.get().get_dots_per_inch(), //
5165
// ruis_native_window.get().get_dots_per_pp()
5266
// )
5367
});
5468

55-
auto ruisapp_window = utki::make_shared<app_window>(
69+
this->window.emplace(
5670
std::move(ruis_context), //
5771
std::move(ruis_native_window)
5872
);
@@ -67,8 +81,6 @@ app_window& application_glue::make_window(ruisapp::window_parameters window_para
6781
// )
6882
// );
6983

70-
this->window = std::move(ruisapp_window);
71-
7284
utki::assert(this->window.has_value(), SL);
7385
return this->window.value();
7486
}
@@ -121,3 +133,39 @@ ruisapp::window& ruisapp::application::make_window(ruisapp::window_parameters wi
121133
auto& glue = get_glue(*this);
122134
return glue.make_window(std::move(window_params));
123135
}
136+
137+
void ruisapp::application::destroy_window(ruisapp::window& w)
138+
{
139+
auto& glue = get_glue(*this);
140+
141+
utki::assert(dynamic_cast<app_window*>(&w), SL);
142+
glue.destroy_window();
143+
}
144+
145+
void ruisapp::application::quit() noexcept
146+
{
147+
utki::assert(globals_wrapper::native_activity, SL);
148+
ANativeActivity_finish(globals_wrapper::native_activity);
149+
}
150+
151+
void ruisapp::application::show_virtual_keyboard() noexcept
152+
{
153+
// NOTE:
154+
// ANativeActivity_showSoftInput(native_activity,
155+
// ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED); did not work for some reason.
156+
157+
auto& glob = get_glob();
158+
159+
glob.java_functions.show_virtual_keyboard();
160+
}
161+
162+
void ruisapp::application::hide_virtual_keyboard() noexcept
163+
{
164+
// NOTE:
165+
// ANativeActivity_hideSoftInput(native_activity,
166+
// ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS); did not work for some reason
167+
168+
auto& glob = get_glob();
169+
170+
glob.java_functions.hide_virtual_keyboard();
171+
}

src/ruisapp/glue/android/application.hxx

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,36 @@
55
#include "../../application.hpp"
66
#include "../../window.hpp"
77

8+
#include "window.hxx"
9+
810
namespace {
911
class app_window : public ruisapp::window
1012
{
13+
ruis::rect cur_win_rect{0, 0, 0, 0};
14+
1115
public:
12-
utki::shared_ref<native_window> ruis_native_Window;
16+
utki::shared_ref<native_window> ruis_native_window;
17+
18+
app_window(utki::shared_ref<ruis::context> ruis_context, utki::shared_ref<native_window> ruis_native_window) :
19+
ruisapp::window(std::move(ruis_context)),
20+
ruis_native_window(std::move(ruis_native_window))
21+
{}
22+
23+
void set_win_rect(const ruis::rect& r)
24+
{
25+
this->cur_win_rect = r;
26+
this->gui.set_viewport(this->cur_win_rect);
27+
}
28+
29+
const ruis::rect& get_win_rect() const noexcept
30+
{
31+
return this->cur_win_rect;
32+
}
33+
34+
const ruis::vec2& get_win_dims() const noexcept
35+
{
36+
return this->get_win_rect().d;
37+
}
1338
};
1439
} // namespace
1540

@@ -28,28 +53,35 @@ public:
2853

2954
app_window& make_window(ruisapp::window_parameters window_params);
3055

56+
void destroy_window()
57+
{
58+
// TODO: defer destruction
59+
this->window.reset();
60+
}
61+
3162
void render();
3263

3364
void create_window_surface(ANativeWindow& android_window)
3465
{
3566
if (this->window.has_value()) {
36-
this->window.create_surface(android_window);
67+
this->window.value().ruis_native_window.get().create_surface(android_window);
3768
}
3869
}
3970

4071
void destroy_window_surface()
4172
{
4273
if (this->window.has_value()) {
43-
this->window.value().destroy_surface();
74+
this->window.value().ruis_native_window.get().destroy_surface();
4475
}
4576
}
4677

47-
app_window* get_window(){
48-
if(this->window.has_value()){
49-
return &this->window.value();
50-
}
51-
return nullptr;
52-
}
78+
app_window* get_window()
79+
{
80+
if (this->window.has_value()) {
81+
return &this->window.value();
82+
}
83+
return nullptr;
84+
}
5385
};
5486
} // namespace
5587

src/ruisapp/glue/android/asset_file.hxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ public:
138138
this->path().size() - 1
139139
);
140140

141-
utki::assert(java_functions, SL);
142-
return java_functions->list_dir_contents(p);
141+
auto& glob = get_glob();
142+
143+
return glob.java_functions.list_dir_contents(p);
143144
}
144145

145146
std::unique_ptr<papki::file> spawn() override

src/ruisapp/glue/android/globals.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#include "android_globals.hxx"
1+
#include "globals.hxx"
2+
3+
ANativeActivity* globals_wrapper::native_activity = nullptr;
24

35
void globals_wrapper::create(ANativeActivity* activity)
46
{
@@ -95,7 +97,7 @@ int on_update_timer_expired(
9597
}
9698
} // namespace
9799

98-
globals_wrapper()
100+
globals_wrapper::globals_wrapper()
99101
{
100102
// add timer descriptor to looper, this is needed for updatable to work
101103
if (ALooper_addFd(
@@ -124,7 +126,7 @@ globals_wrapper()
124126
}
125127
}
126128

127-
~globals_wrapper()
129+
globals_wrapper::~globals_wrapper()
128130
{
129131
// remove UI message queue descriptor from looper
130132
ALooper_removeFd(

src/ruisapp/glue/android/globals.hxx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@
1515

1616
namespace {
1717
struct globals_wrapper final {
18-
static ANativeActivity* native_activity = nullptr;
18+
static ANativeActivity* native_activity;
1919

2020
static void create(ANativeActivity* activity);
2121
static void destroy();
2222

23-
static globals_wrapper& get()
24-
{
25-
utki::assert(native_activity, SL);
26-
utki::assert(native_activity->instance, SL);
27-
return
28-
}
29-
3023
globals_wrapper();
3124

3225
globals_wrapper(const globals_wrapper&) = delete;
@@ -54,11 +47,11 @@ struct globals_wrapper final {
5447
nitki::queue ui_queue;
5548

5649
utki::unique_ref<android_configuration_wrapper> cur_android_configuration =
57-
utki::make_unique<android_configuration_wrapper>(*android_configuration_wrapper::native_activity->assetManager);
50+
utki::make_unique<android_configuration_wrapper>(*globals_wrapper::native_activity->assetManager);
5851

5952
AInputQueue* input_queue = nullptr;
6053

61-
ruis::vector2 cur_window_dims(0, 0);
54+
ruis::vector2 cur_window_dims{0, 0};
6255

6356
ruis::vector2 android_win_coords_to_ruis_win_rect_coords(
6457
const ruis::vector2& ruis_win_dims, //

0 commit comments

Comments
 (0)