add ui and viewport scale option, fix combobox items height from parent
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "asset.h"
|
||||
#include "keymap.h"
|
||||
#include "main.h"
|
||||
#include "settings.h"
|
||||
#include "com_omixlab_panopainter_MainActivity.h"
|
||||
|
||||
#ifdef __QUEST__
|
||||
@@ -692,6 +693,9 @@ static int engine_init_display(struct engine* engine) {
|
||||
|
||||
#ifdef __QUEST__
|
||||
App::I->zoom = 1.f;
|
||||
if (Settings::has("ui-scale"))
|
||||
App::I->zoom = Settings::value<Serializer::Float>("ui-scale");
|
||||
|
||||
App::I->width = 1024;
|
||||
App::I->height = 1024;
|
||||
App::I->redraw = true;
|
||||
@@ -714,8 +718,9 @@ static int engine_init_display(struct engine* engine) {
|
||||
engine_start_vr_thread();
|
||||
#else
|
||||
float density = get_display_density();
|
||||
App::I->zoom = Settings::value_or<Serializer::Float>("ui-scale", density / 1.5f);
|
||||
App::I->display_density = density;
|
||||
LOG("density %f", density);
|
||||
App::I->zoom = density / 1.5;
|
||||
App::I->width = w;
|
||||
App::I->height = h;
|
||||
App::I->redraw = true;
|
||||
|
||||
@@ -1501,6 +1501,14 @@ Here's a list of what's available in this release.
|
||||
<icon icon="resultset_next" width="20"/>
|
||||
</button-custom>
|
||||
</border>
|
||||
<button-custom height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
|
||||
<text text="UI Scale" margin="0 10 0 5" grow="1"/>
|
||||
<combobox id="tools-ui-scale" height="30" width="50" margin="0 10 0 0" combo-list="0.50,0.70,0.80,0.90,1.00,1.25,1.50,2.00,2.50"/>
|
||||
</button-custom>
|
||||
<button-custom height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
|
||||
<text text="VP Scale" margin="0 10 0 5" grow="1"/>
|
||||
<combobox id="tools-vp-scale" height="30" width="50" margin="0 10 0 0" combo-list="0.25,0.33,0.50,0.66,1.00"/>
|
||||
</button-custom>
|
||||
<button-custom id="tools-rtl" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
|
||||
<checkbox id="tools-rtl-check" width="20" height="20"/>
|
||||
<text text="Left-handed UI" margin="0 0 0 5"/>
|
||||
|
||||
@@ -139,13 +139,8 @@ public:
|
||||
glm::vec2 cursor{ 0, 0 };
|
||||
glm::vec2 gesture_p0;
|
||||
glm::vec2 gesture_p1;
|
||||
#ifdef __ANDROID__
|
||||
float zoom = 3.0;
|
||||
#elif __IOS__
|
||||
float zoom = 2.0;
|
||||
#else
|
||||
float zoom = 1.0;
|
||||
#endif // __ANDROID__
|
||||
float display_density = 1.f;
|
||||
float zoom = 1.f;
|
||||
|
||||
#if defined(__IOS__) && defined(__OBJC__)
|
||||
GameViewController* ios_view;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "node_dialog_picker.h"
|
||||
#include "node_panel_floating.h"
|
||||
#include "settings.h"
|
||||
#include "serializer.h"
|
||||
|
||||
void App::title_update()
|
||||
{
|
||||
@@ -925,6 +926,38 @@ void App::init_menu_tools()
|
||||
}
|
||||
};
|
||||
|
||||
if (auto ui_scale = popup_exp->find<NodeComboBox>("tools-ui-scale"))
|
||||
{
|
||||
// set index to current zoom level (or at least the closest in list)
|
||||
for (int i = 0; i < ui_scale->m_data.size(); i++)
|
||||
if (App::I->zoom >= ui_scale->get_float(i))
|
||||
ui_scale->set_index(i);
|
||||
|
||||
ui_scale->on_select = [ui_scale](Node* target, int index)
|
||||
{
|
||||
App::I->zoom = ui_scale->get_float(index);
|
||||
Settings::set("ui-scale", Serializer::Float(App::I->zoom));
|
||||
Settings::save();
|
||||
App::I->title_update();
|
||||
};
|
||||
}
|
||||
|
||||
if (auto vp_scale = popup_exp->find<NodeComboBox>("tools-vp-scale"))
|
||||
{
|
||||
// set index to current zoom level (or at least the closest in list)
|
||||
for (int i = 0; i < vp_scale->m_data.size(); i++)
|
||||
if (App::I->canvas->m_density >= vp_scale->get_float(i))
|
||||
vp_scale->set_index(i);
|
||||
|
||||
vp_scale->on_select = [vp_scale](Node* target, int index)
|
||||
{
|
||||
float d = vp_scale->get_float(index);
|
||||
App::I->canvas->set_density(d);
|
||||
Settings::set("vp-scale", Serializer::Float(d));
|
||||
Settings::save();
|
||||
};
|
||||
}
|
||||
|
||||
if (auto rtl_btn = popup_exp->find<NodeButtonCustom>("tools-rtl"))
|
||||
{
|
||||
NodeCheckBox* cb = rtl_btn->find<NodeCheckBox>("tools-rtl-check");
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@@ -839,11 +839,16 @@ int main(int argc, char** argv)
|
||||
RegisterClass(&wc);
|
||||
|
||||
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
|
||||
auto x = unsigned{96};
|
||||
auto y = unsigned{96};
|
||||
auto x = unsigned{ 96 };
|
||||
auto y = unsigned{ 96 };
|
||||
if (GetDpiForMonitor_fn)
|
||||
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
||||
App::I->zoom *= (float)x / 96.f;
|
||||
App::I->display_density = (float)x / 96.f;
|
||||
|
||||
if (Settings::has("ui-scale"))
|
||||
App::I->zoom = Settings::value<Serializer::Float>("ui-scale");
|
||||
else
|
||||
App::I->zoom = (float)x / 96.f;
|
||||
|
||||
int show_cmd = SW_NORMAL;
|
||||
Settings::value<Serializer::Integer>("window-show-cmd", show_cmd);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "log.h"
|
||||
#include "node_canvas.h"
|
||||
#include "node_image_texture.h"
|
||||
#include "settings.h"
|
||||
|
||||
Node* NodeCanvas::clone_instantiate() const
|
||||
{
|
||||
@@ -11,6 +12,8 @@ Node* NodeCanvas::clone_instantiate() const
|
||||
|
||||
void NodeCanvas::init()
|
||||
{
|
||||
m_density = Settings::value_or<Serializer::Float>("vp-scale", 1.f);
|
||||
|
||||
m_mouse_ignore = false;
|
||||
m_canvas = std::make_unique<Canvas>();
|
||||
m_canvas->create(CANVAS_RES, CANVAS_RES);
|
||||
@@ -64,6 +67,11 @@ void NodeCanvas::draw()
|
||||
GLfloat cc[4];
|
||||
glGetIntegerv(GL_VIEWPORT, vp);
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||
auto blend = glIsEnabled(GL_BLEND);
|
||||
auto depth = glIsEnabled(GL_DEPTH_TEST);
|
||||
auto scissor = glIsEnabled(GL_SCISSOR_TEST);
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
float zoom = root()->m_zoom;
|
||||
auto box = m_clip * zoom;
|
||||
@@ -80,10 +88,6 @@ void NodeCanvas::draw()
|
||||
m_canvas->m_box = box;
|
||||
m_canvas->m_vp = c;
|
||||
|
||||
auto blend = glIsEnabled(GL_BLEND);
|
||||
auto depth = glIsEnabled(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
float pitch = 0;
|
||||
if (auto slider = root()->find<NodeSliderH>("pitch-slider"))
|
||||
pitch = (slider->get_value() - 0.5) * glm::half_pi<float>();
|
||||
@@ -105,10 +109,10 @@ void NodeCanvas::draw()
|
||||
}
|
||||
|
||||
|
||||
if (zoom > 1.f)
|
||||
if (m_density != 1.f)
|
||||
{
|
||||
m_rtt.bindFramebuffer();
|
||||
glClearColor(1, 1, 1, 0);
|
||||
glClearColor(1, 1, 0, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight());
|
||||
}
|
||||
@@ -466,7 +470,7 @@ void NodeCanvas::draw()
|
||||
for (auto& mode : *m_canvas->m_mode)
|
||||
mode->on_Draw(ortho_proj, proj, camera);
|
||||
|
||||
if (zoom > 1.f)
|
||||
if (m_density != 1.f)
|
||||
{
|
||||
m_rtt.unbindFramebuffer();
|
||||
|
||||
@@ -485,9 +489,9 @@ void NodeCanvas::draw()
|
||||
m_rtt.unbindTexture();
|
||||
}
|
||||
|
||||
scissor ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST);
|
||||
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
||||
depth ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
||||
m_sampler.unbind();
|
||||
glViewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
}
|
||||
@@ -496,23 +500,8 @@ void NodeCanvas::handle_resize(glm::vec2 old_size, glm::vec2 new_size)
|
||||
{
|
||||
if (new_size.x != m_canvas->m_width || new_size.y != m_canvas->m_height)
|
||||
{
|
||||
// actual screen size
|
||||
//new_size = new_size * root()->m_zoom;
|
||||
//#if defined(__IOS__) || defined(__ANDROID__)
|
||||
// m_canvas->m_mixer.create((int)new_size.x * m_canvas->m_mixer_scale,
|
||||
// (int)new_size.y * m_canvas->m_mixer_scale, -1, GL_RGBA16F);
|
||||
//#else
|
||||
m_canvas->m_mixer.create((int)new_size.x * m_canvas->m_mixer_scale,
|
||||
(int)new_size.y * m_canvas->m_mixer_scale, -1, GL_RGBA8);
|
||||
//#endif
|
||||
m_blender_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8);
|
||||
m_cache_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8);
|
||||
m_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8, true);
|
||||
m_blender_bg.create((int)new_size.x, (int)new_size.y, GL_RGBA8);
|
||||
if (auto img = root()->find<NodeImageTexture>("tex-debug"))
|
||||
img->tex.assign(m_canvas->m_mixer.getTextureID());
|
||||
// m_canvas->resize((int)new_size.x, (int)new_size.y);
|
||||
// m_canvas->clear();
|
||||
new_size = new_size * m_density;
|
||||
create_buffers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,6 +618,25 @@ void NodeCanvas::reset_camera()
|
||||
m_canvas->m_pan = {0, 0};
|
||||
}
|
||||
|
||||
void NodeCanvas::create_buffers()
|
||||
{
|
||||
auto new_size = GetSize() * m_density;
|
||||
m_canvas->m_mixer.create((int)new_size.x * m_canvas->m_mixer_scale,
|
||||
(int)new_size.y * m_canvas->m_mixer_scale, -1, GL_RGBA8);
|
||||
m_blender_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8);
|
||||
m_cache_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8);
|
||||
m_rtt.create((int)new_size.x, (int)new_size.y, -1, GL_RGBA8, true);
|
||||
m_blender_bg.create((int)new_size.x, (int)new_size.y, GL_RGBA8);
|
||||
if (auto img = root()->find<NodeImageTexture>("tex-debug"))
|
||||
img->tex.assign(m_canvas->m_mixer.getTextureID());
|
||||
}
|
||||
|
||||
void NodeCanvas::set_density(float d)
|
||||
{
|
||||
m_density = d;
|
||||
create_buffers();
|
||||
}
|
||||
|
||||
void NodeCanvas::on_tick(float dt)
|
||||
{
|
||||
m_outline_pan = glm::fract(m_outline_pan + dt * 0.01f);
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
Plane m_grid;
|
||||
glm::vec2 m_outline_pan;
|
||||
int m_grid_divs = 30;
|
||||
float m_density = 1.f;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void init() override;
|
||||
virtual void restore_context() override;
|
||||
@@ -29,4 +30,6 @@ public:
|
||||
virtual void destroy_immediate() override;
|
||||
virtual void on_tick(float dt) override;
|
||||
void reset_camera();
|
||||
void create_buffers();
|
||||
void set_density(float d);
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ void NodeComboBox::loaded()
|
||||
auto btn = popup->add_child<NodeButton>();
|
||||
btn->m_text->set_text(m_data[i].c_str());
|
||||
btn->m_border->SetWidthP(100.f);
|
||||
btn->m_border->SetHeight(30.f);
|
||||
btn->m_border->SetHeight(GetHeight());
|
||||
int index = (int)m_items.size();
|
||||
if (index == m_current_index)
|
||||
m_selected_child_index = popup->get_child_index(btn);
|
||||
@@ -62,8 +62,8 @@ void NodeComboBox::loaded()
|
||||
}
|
||||
float offset = 0;
|
||||
for (int i = 0; i <= m_selected_child_index; i++)
|
||||
offset += (m_data[i] == "-") ? 5.f : 30.f;
|
||||
float height = m_items.size() * 30.f + (m_data.size() - m_items.size()) * 5.f; // add items and separators
|
||||
offset += (m_data[i] == "-") ? 5.f : GetHeight();
|
||||
float height = m_items.size() * GetHeight() + (m_data.size() - m_items.size()) * 5.f; // add items and separators
|
||||
glm::vec2 pos = m_pos + glm::vec2(0, m_size.y - offset);
|
||||
auto screen = root()->m_size;
|
||||
if ((pos.y + height) > screen.y) pos.y = screen.y - height;
|
||||
@@ -109,3 +109,8 @@ void NodeComboBox::set_index(int index)
|
||||
//if (on_select)
|
||||
// on_select(this, index);
|
||||
}
|
||||
|
||||
float NodeComboBox::get_float(int index) const noexcept
|
||||
{
|
||||
return std::stof(m_data[index]);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ public:
|
||||
virtual void loaded() override;
|
||||
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) override;
|
||||
void set_index(int index);
|
||||
float get_float(int index) const noexcept;
|
||||
};
|
||||
|
||||
@@ -32,4 +32,9 @@ public:
|
||||
{
|
||||
return I.Descriptor::value<T>(key);
|
||||
}
|
||||
template <typename T, typename D = decltype(T::value)>
|
||||
static D value_or(const std::string& key, D def)
|
||||
{
|
||||
return I.Descriptor::value_or<T, D>(key, def);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user