add ui and viewport scale option, fix combobox items height from parent

This commit is contained in:
2019-08-04 12:00:49 +02:00
parent a1436eec4a
commit cc087746bd
10 changed files with 107 additions and 39 deletions

View File

@@ -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);