ENABLE_MODIFIED_TOOLBAR_TEXTURES set as default

This commit is contained in:
Enrico Turri 2020-02-13 09:50:06 +01:00
parent 5797c9edc2
commit b0218daafe
5 changed files with 0 additions and 98 deletions

View file

@ -47,9 +47,6 @@
//================== //==================
#define ENABLE_2_2_0_BETA1 1 #define ENABLE_2_2_0_BETA1 1
// Enable a modified version of the toolbar textures where all the icons are separated by 1 pixel
#define ENABLE_MODIFIED_TOOLBAR_TEXTURES (1 && ENABLE_2_2_0_BETA1)
// Enable configurable paths export (fullpath or not) to 3mf and amf // Enable configurable paths export (fullpath or not) to 3mf and amf
#define ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF (1 && ENABLE_2_2_0_BETA1) #define ENABLE_CONFIGURABLE_PATHS_EXPORT_TO_3MF_AND_AMF (1 && ENABLE_2_2_0_BETA1)

View file

@ -168,25 +168,15 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::stri
if (filenames.empty() || states.empty() || (sprite_size_px == 0)) if (filenames.empty() || states.empty() || (sprite_size_px == 0))
return false; return false;
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
// every tile needs to have a 1px border around it to avoid artifacts when linear sampling on its edges // every tile needs to have a 1px border around it to avoid artifacts when linear sampling on its edges
unsigned int sprite_size_px_ex = sprite_size_px + 1; unsigned int sprite_size_px_ex = sprite_size_px + 1;
m_width = 1 + (int)(sprite_size_px_ex * states.size()); m_width = 1 + (int)(sprite_size_px_ex * states.size());
m_height = 1 + (int)(sprite_size_px_ex * filenames.size()); m_height = 1 + (int)(sprite_size_px_ex * filenames.size());
#else
m_width = (int)(sprite_size_px * states.size());
m_height = (int)(sprite_size_px * filenames.size());
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
int n_pixels = m_width * m_height; int n_pixels = m_width * m_height;
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
int sprite_n_pixels = sprite_size_px_ex * sprite_size_px_ex; int sprite_n_pixels = sprite_size_px_ex * sprite_size_px_ex;
int sprite_stride = sprite_size_px_ex * 4; int sprite_stride = sprite_size_px_ex * 4;
#else
int sprite_n_pixels = sprite_size_px * sprite_size_px;
int sprite_stride = sprite_size_px * 4;
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
int sprite_bytes = sprite_n_pixels * 4; int sprite_bytes = sprite_n_pixels * 4;
if (n_pixels <= 0) if (n_pixels <= 0)
@ -225,12 +215,8 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::stri
float scale = (float)sprite_size_px / std::max(image->width, image->height); float scale = (float)sprite_size_px / std::max(image->width, image->height);
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
// offset by 1 to leave the first pixel empty (both in x and y) // offset by 1 to leave the first pixel empty (both in x and y)
nsvgRasterize(rast, image, 1, 1, scale, sprite_data.data(), sprite_size_px, sprite_size_px, sprite_stride); nsvgRasterize(rast, image, 1, 1, scale, sprite_data.data(), sprite_size_px, sprite_size_px, sprite_stride);
#else
nsvgRasterize(rast, image, 0, 0, scale, sprite_data.data(), sprite_size_px, sprite_size_px, sprite_stride);
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
// makes white only copy of the sprite // makes white only copy of the sprite
::memcpy((void*)sprite_white_only_data.data(), (const void*)sprite_data.data(), sprite_bytes); ::memcpy((void*)sprite_white_only_data.data(), (const void*)sprite_data.data(), sprite_bytes);
@ -250,11 +236,7 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::stri
::memset((void*)&sprite_gray_only_data.data()[offset], 128, 3); ::memset((void*)&sprite_gray_only_data.data()[offset], 128, 3);
} }
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
int sprite_offset_px = sprite_id * (int)sprite_size_px_ex * m_width; int sprite_offset_px = sprite_id * (int)sprite_size_px_ex * m_width;
#else
int sprite_offset_px = sprite_id * sprite_size_px * m_width;
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
int state_id = -1; int state_id = -1;
for (const std::pair<int, bool>& state : states) for (const std::pair<int, bool>& state : states)
{ {
@ -273,7 +255,6 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::stri
// applies background, if needed // applies background, if needed
if (state.second) if (state.second)
{ {
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
float inv_255 = 1.0f / 255.0f; float inv_255 = 1.0f / 255.0f;
// offset by 1 to leave the first pixel empty (both in x and y) // offset by 1 to leave the first pixel empty (both in x and y)
for (unsigned int r = 1; r <= sprite_size_px; ++r) for (unsigned int r = 1; r <= sprite_size_px; ++r)
@ -289,32 +270,13 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::stri
output_data.data()[offset + 3] = (unsigned char)(128 * (1.0f - alpha) + output_data.data()[offset + 3] * alpha); output_data.data()[offset + 3] = (unsigned char)(128 * (1.0f - alpha) + output_data.data()[offset + 3] * alpha);
} }
} }
#else
for (int i = 0; i < sprite_n_pixels; ++i)
{
int offset = i * 4;
float alpha = (float)output_data.data()[offset + 3] / 255.0f;
output_data.data()[offset + 0] = (unsigned char)(output_data.data()[offset + 0] * alpha);
output_data.data()[offset + 1] = (unsigned char)(output_data.data()[offset + 1] * alpha);
output_data.data()[offset + 2] = (unsigned char)(output_data.data()[offset + 2] * alpha);
output_data.data()[offset + 3] = (unsigned char)(128 * (1.0f - alpha) + output_data.data()[offset + 3] * alpha);
}
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
} }
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
int state_offset_px = sprite_offset_px + state_id * sprite_size_px_ex; int state_offset_px = sprite_offset_px + state_id * sprite_size_px_ex;
for (int j = 0; j < (int)sprite_size_px_ex; ++j) for (int j = 0; j < (int)sprite_size_px_ex; ++j)
{ {
::memcpy((void*)&data.data()[(state_offset_px + j * m_width) * 4], (const void*)&output_data.data()[j * sprite_stride], sprite_stride); ::memcpy((void*)&data.data()[(state_offset_px + j * m_width) * 4], (const void*)&output_data.data()[j * sprite_stride], sprite_stride);
} }
#else
int state_offset_px = sprite_offset_px + state_id * sprite_size_px;
for (int j = 0; j < (int)sprite_size_px; ++j)
{
::memcpy((void*)&data.data()[(state_offset_px + j * m_width) * 4], (const void*)&output_data.data()[j * sprite_stride], sprite_stride);
}
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
} }
nsvgDelete(image); nsvgDelete(image);

View file

@ -86,7 +86,6 @@ bool GLToolbarItem::update_enabled_state()
void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const
{ {
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) ->GLTexture::Quad_UVs auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) ->GLTexture::Quad_UVs
{ {
assert((tex_width != 0) && (tex_height != 0)); assert((tex_width != 0) && (tex_height != 0));
@ -112,9 +111,6 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b
}; };
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size)); GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size));
#else
GLTexture::render_sub_texture(tex_id, left, right, bottom, top, get_uvs(tex_width, tex_height, icon_size));
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
if (is_pressed()) if (is_pressed())
{ {
@ -125,29 +121,6 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b
} }
} }
#if !ENABLE_MODIFIED_TOOLBAR_TEXTURES
GLTexture::Quad_UVs GLToolbarItem::get_uvs(unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const
{
GLTexture::Quad_UVs uvs;
float inv_tex_width = (tex_width != 0) ? 1.0f / (float)tex_width : 0.0f;
float inv_tex_height = (tex_height != 0) ? 1.0f / (float)tex_height : 0.0f;
float scaled_icon_width = (float)icon_size * inv_tex_width;
float scaled_icon_height = (float)icon_size * inv_tex_height;
float left = (float)m_state * scaled_icon_width;
float right = left + scaled_icon_width;
float top = (float)m_data.sprite_id * scaled_icon_height;
float bottom = top + scaled_icon_height;
uvs.left_top = { left, top };
uvs.left_bottom = { left, bottom };
uvs.right_bottom = { right, bottom };
uvs.right_top = { right, top };
return uvs;
}
#endif // !ENABLE_MODIFIED_TOOLBAR_TEXTURES
BackgroundTexture::Metadata::Metadata() BackgroundTexture::Metadata::Metadata()
: filename("") : filename("")
, left(0) , left(0)

View file

@ -143,9 +143,6 @@ public:
void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const;
private: private:
#if !ENABLE_MODIFIED_TOOLBAR_TEXTURES
GLTexture::Quad_UVs get_uvs(unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const;
#endif // !ENABLE_MODIFIED_TOOLBAR_TEXTURES
void set_visible(bool visible) { m_data.visible = visible; } void set_visible(bool visible) { m_data.visible = visible; }
friend class GLToolbar; friend class GLToolbar;

View file

@ -889,14 +889,9 @@ void GLGizmosManager::render_background(float left, float top, float right, floa
void GLGizmosManager::do_render_overlay() const void GLGizmosManager::do_render_overlay() const
{ {
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
std::vector<size_t> selectable_idxs = get_selectable_idxs(); std::vector<size_t> selectable_idxs = get_selectable_idxs();
if (selectable_idxs.empty()) if (selectable_idxs.empty())
return; return;
#else
if (m_gizmos.empty())
return;
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
float cnv_w = (float)m_parent.get_canvas_size().get_width(); float cnv_w = (float)m_parent.get_canvas_size().get_width();
float cnv_h = (float)m_parent.get_canvas_size().get_height(); float cnv_h = (float)m_parent.get_canvas_size().get_height();
@ -928,7 +923,6 @@ void GLGizmosManager::do_render_overlay() const
int tex_width = m_icons_texture.get_width(); int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height(); int tex_height = m_icons_texture.get_height();
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
if ((icons_texture_id == 0) || (tex_width <= 1) || (tex_height <= 1)) if ((icons_texture_id == 0) || (tex_width <= 1) || (tex_height <= 1))
return; return;
@ -938,39 +932,18 @@ void GLGizmosManager::do_render_overlay() const
// tiles in the texture are spaced by 1 pixel // tiles in the texture are spaced by 1 pixel
float u_offset = 1.0f / (float)tex_width; float u_offset = 1.0f / (float)tex_width;
float v_offset = 1.0f / (float)tex_height; float v_offset = 1.0f / (float)tex_height;
#else
if ((icons_texture_id == 0) || (tex_width <= 0) || (tex_height <= 0))
return;
float inv_tex_width = (tex_width != 0) ? 1.0f / tex_width : 0.0f;
float inv_tex_height = (tex_height != 0) ? 1.0f / tex_height : 0.0f;
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
for (size_t idx : selectable_idxs) for (size_t idx : selectable_idxs)
#else
for (size_t idx : get_selectable_idxs())
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
{ {
GLGizmoBase* gizmo = m_gizmos[idx].get(); GLGizmoBase* gizmo = m_gizmos[idx].get();
unsigned int sprite_id = gizmo->get_sprite_id(); unsigned int sprite_id = gizmo->get_sprite_id();
int icon_idx = (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable()? 0 : 3)); int icon_idx = (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable()? 0 : 3));
#if ENABLE_MODIFIED_TOOLBAR_TEXTURES
float v_top = v_offset + sprite_id * dv; float v_top = v_offset + sprite_id * dv;
float u_left = u_offset + icon_idx * du; float u_left = u_offset + icon_idx * du;
float v_bottom = v_top + dv - v_offset; float v_bottom = v_top + dv - v_offset;
float u_right = u_left + du - u_offset; float u_right = u_left + du - u_offset;
#else
float u_icon_size = icons_size * inv_tex_width;
float v_icon_size = icons_size * inv_tex_height;
float v_top = sprite_id * v_icon_size;
float u_left = icon_idx * u_icon_size;
float v_bottom = v_top + v_icon_size;
float u_right = u_left + u_icon_size;
#endif // ENABLE_MODIFIED_TOOLBAR_TEXTURES
GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } });
if (idx == m_current) { if (idx == m_current) {