Removed mutable members from class GLToolbar
This commit is contained in:
parent
4c464b35f9
commit
4da8de5f49
2 changed files with 38 additions and 58 deletions
|
@ -428,8 +428,7 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
|
||||||
bool processed = false;
|
bool processed = false;
|
||||||
|
|
||||||
// mouse anywhere
|
// mouse anywhere
|
||||||
if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && (m_mouse_capture.parent != nullptr))
|
if (!evt.Dragging() && !evt.Leaving() && !evt.Entering() && m_mouse_capture.parent != nullptr) {
|
||||||
{
|
|
||||||
if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp())) {
|
if (m_mouse_capture.any() && (evt.LeftUp() || evt.MiddleUp() || evt.RightUp())) {
|
||||||
// prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it,
|
// prevents loosing selection into the scene if mouse down was done inside the toolbar and mouse up was down outside it,
|
||||||
// as when switching between views
|
// as when switching between views
|
||||||
|
@ -441,38 +440,31 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
|
||||||
|
|
||||||
if (evt.Moving())
|
if (evt.Moving())
|
||||||
update_hover_state(mouse_pos, parent);
|
update_hover_state(mouse_pos, parent);
|
||||||
else if (evt.LeftUp())
|
else if (evt.LeftUp()) {
|
||||||
{
|
if (m_mouse_capture.left) {
|
||||||
if (m_mouse_capture.left)
|
|
||||||
{
|
|
||||||
processed = true;
|
processed = true;
|
||||||
m_mouse_capture.left = false;
|
m_mouse_capture.left = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (evt.MiddleUp())
|
else if (evt.MiddleUp()) {
|
||||||
{
|
if (m_mouse_capture.middle) {
|
||||||
if (m_mouse_capture.middle)
|
|
||||||
{
|
|
||||||
processed = true;
|
processed = true;
|
||||||
m_mouse_capture.middle = false;
|
m_mouse_capture.middle = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (evt.RightUp())
|
else if (evt.RightUp()) {
|
||||||
{
|
if (m_mouse_capture.right) {
|
||||||
if (m_mouse_capture.right)
|
|
||||||
{
|
|
||||||
processed = true;
|
processed = true;
|
||||||
m_mouse_capture.right = false;
|
m_mouse_capture.right = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (evt.Dragging())
|
else if (evt.Dragging()) {
|
||||||
{
|
|
||||||
if (m_mouse_capture.any())
|
if (m_mouse_capture.any())
|
||||||
// if the button down was done on this toolbar, prevent from dragging into the scene
|
// if the button down was done on this toolbar, prevent from dragging into the scene
|
||||||
processed = true;
|
processed = true;
|
||||||
|
@ -481,35 +473,29 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
int item_id = contains_mouse(mouse_pos, parent);
|
int item_id = contains_mouse(mouse_pos, parent);
|
||||||
if (item_id != -1)
|
if (item_id != -1) {
|
||||||
{
|
|
||||||
// mouse inside toolbar
|
// mouse inside toolbar
|
||||||
if (evt.LeftDown() || evt.LeftDClick())
|
if (evt.LeftDown() || evt.LeftDClick()) {
|
||||||
{
|
|
||||||
m_mouse_capture.left = true;
|
m_mouse_capture.left = true;
|
||||||
m_mouse_capture.parent = &parent;
|
m_mouse_capture.parent = &parent;
|
||||||
processed = true;
|
processed = true;
|
||||||
if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() &&
|
if (item_id != -2 && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() &&
|
||||||
((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Left)))
|
(m_pressed_toggable_id == -1 || m_items[item_id]->get_last_action_type() == GLToolbarItem::Left)) {
|
||||||
{
|
|
||||||
// mouse is inside an icon
|
// mouse is inside an icon
|
||||||
do_action(GLToolbarItem::Left, item_id, parent, true);
|
do_action(GLToolbarItem::Left, item_id, parent, true);
|
||||||
parent.set_as_dirty();
|
parent.set_as_dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (evt.MiddleDown())
|
else if (evt.MiddleDown()) {
|
||||||
{
|
|
||||||
m_mouse_capture.middle = true;
|
m_mouse_capture.middle = true;
|
||||||
m_mouse_capture.parent = &parent;
|
m_mouse_capture.parent = &parent;
|
||||||
}
|
}
|
||||||
else if (evt.RightDown())
|
else if (evt.RightDown()) {
|
||||||
{
|
|
||||||
m_mouse_capture.right = true;
|
m_mouse_capture.right = true;
|
||||||
m_mouse_capture.parent = &parent;
|
m_mouse_capture.parent = &parent;
|
||||||
processed = true;
|
processed = true;
|
||||||
if ((item_id != -2) && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() &&
|
if (item_id != -2 && !m_items[item_id]->is_separator() && !m_items[item_id]->is_disabled() &&
|
||||||
((m_pressed_toggable_id == -1) || (m_items[item_id]->get_last_action_type() == GLToolbarItem::Right)))
|
(m_pressed_toggable_id == -1 || m_items[item_id]->get_last_action_type() == GLToolbarItem::Right)) {
|
||||||
{
|
|
||||||
// mouse is inside an icon
|
// mouse is inside an icon
|
||||||
do_action(GLToolbarItem::Right, item_id, parent, true);
|
do_action(GLToolbarItem::Right, item_id, parent, true);
|
||||||
parent.set_as_dirty();
|
parent.set_as_dirty();
|
||||||
|
@ -522,24 +508,26 @@ bool GLToolbar::on_mouse(wxMouseEvent& evt, GLCanvas3D& parent)
|
||||||
|
|
||||||
void GLToolbar::calc_layout() const
|
void GLToolbar::calc_layout() const
|
||||||
{
|
{
|
||||||
switch (m_layout.type)
|
Layout* layout = const_cast<Layout*>(&m_layout);
|
||||||
|
|
||||||
|
switch (layout->type)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case Layout::Horizontal:
|
case Layout::Horizontal:
|
||||||
{
|
{
|
||||||
m_layout.width = get_width_horizontal();
|
layout->width = get_width_horizontal();
|
||||||
m_layout.height = get_height_horizontal();
|
layout->height = get_height_horizontal();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Layout::Vertical:
|
case Layout::Vertical:
|
||||||
{
|
{
|
||||||
m_layout.width = get_width_vertical();
|
layout->width = get_width_vertical();
|
||||||
m_layout.height = get_height_vertical();
|
layout->height = get_height_vertical();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_layout.dirty = false;
|
layout->dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GLToolbar::get_width_horizontal() const
|
float GLToolbar::get_width_horizontal() const
|
||||||
|
@ -1196,19 +1184,17 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) const
|
||||||
left += scaled_border;
|
left += scaled_border;
|
||||||
top -= scaled_border;
|
top -= scaled_border;
|
||||||
|
|
||||||
if ((tex_id == 0) || (tex_width <= 0) || (tex_height <= 0))
|
if (tex_id == 0 || tex_width <= 0 || tex_height <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// renders icons
|
// renders icons
|
||||||
for (const GLToolbarItem* item : m_items)
|
for (const GLToolbarItem* item : m_items) {
|
||||||
{
|
|
||||||
if (!item->is_visible())
|
if (!item->is_visible())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (item->is_separator())
|
if (item->is_separator())
|
||||||
top -= separator_stride;
|
top -= separator_stride;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale));
|
item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale));
|
||||||
top -= icon_stride;
|
top -= icon_stride;
|
||||||
}
|
}
|
||||||
|
@ -1219,16 +1205,14 @@ bool GLToolbar::generate_icons_texture() const
|
||||||
{
|
{
|
||||||
std::string path = resources_dir() + "/icons/";
|
std::string path = resources_dir() + "/icons/";
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
for (GLToolbarItem* item : m_items)
|
for (GLToolbarItem* item : m_items) {
|
||||||
{
|
|
||||||
const std::string& icon_filename = item->get_icon_filename();
|
const std::string& icon_filename = item->get_icon_filename();
|
||||||
if (!icon_filename.empty())
|
if (!icon_filename.empty())
|
||||||
filenames.push_back(path + icon_filename);
|
filenames.push_back(path + icon_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<int, bool>> states;
|
std::vector<std::pair<int, bool>> states;
|
||||||
if (m_type == Normal)
|
if (m_type == Normal) {
|
||||||
{
|
|
||||||
states.push_back({ 1, false }); // Normal
|
states.push_back({ 1, false }); // Normal
|
||||||
states.push_back({ 0, false }); // Pressed
|
states.push_back({ 0, false }); // Pressed
|
||||||
states.push_back({ 2, false }); // Disabled
|
states.push_back({ 2, false }); // Disabled
|
||||||
|
@ -1236,8 +1220,7 @@ bool GLToolbar::generate_icons_texture() const
|
||||||
states.push_back({ 0, false }); // HoverPressed
|
states.push_back({ 0, false }); // HoverPressed
|
||||||
states.push_back({ 2, false }); // HoverDisabled
|
states.push_back({ 2, false }); // HoverDisabled
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
states.push_back({ 1, false }); // Normal
|
states.push_back({ 1, false }); // Normal
|
||||||
states.push_back({ 1, true }); // Pressed
|
states.push_back({ 1, true }); // Pressed
|
||||||
states.push_back({ 1, false }); // Disabled
|
states.push_back({ 1, false }); // Disabled
|
||||||
|
@ -1251,9 +1234,9 @@ bool GLToolbar::generate_icons_texture() const
|
||||||
// if (sprite_size_px % 2 != 0)
|
// if (sprite_size_px % 2 != 0)
|
||||||
// sprite_size_px += 1;
|
// sprite_size_px += 1;
|
||||||
|
|
||||||
bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, states, sprite_size_px, false);
|
bool res = const_cast<GLTexture*>(&m_icons_texture)->load_from_svg_files_as_sprites_array(filenames, states, sprite_size_px, false);
|
||||||
if (res)
|
if (res)
|
||||||
m_icons_texture_dirty = false;
|
*const_cast<bool*>(&m_icons_texture_dirty) = false;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1262,8 +1245,7 @@ bool GLToolbar::update_items_visibility()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
for (GLToolbarItem* item : m_items)
|
for (GLToolbarItem* item : m_items) {
|
||||||
{
|
|
||||||
ret |= item->update_visibility();
|
ret |= item->update_visibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1272,12 +1254,10 @@ bool GLToolbar::update_items_visibility()
|
||||||
|
|
||||||
// updates separators visibility to avoid having two of them consecutive
|
// updates separators visibility to avoid having two of them consecutive
|
||||||
bool any_item_visible = false;
|
bool any_item_visible = false;
|
||||||
for (GLToolbarItem* item : m_items)
|
for (GLToolbarItem* item : m_items) {
|
||||||
{
|
|
||||||
if (!item->is_separator())
|
if (!item->is_separator())
|
||||||
any_item_visible |= item->is_visible();
|
any_item_visible |= item->is_visible();
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
item->set_visible(any_item_visible);
|
item->set_visible(any_item_visible);
|
||||||
any_item_visible = false;
|
any_item_visible = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,10 +233,10 @@ private:
|
||||||
EType m_type;
|
EType m_type;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
mutable GLTexture m_icons_texture;
|
GLTexture m_icons_texture;
|
||||||
mutable bool m_icons_texture_dirty;
|
bool m_icons_texture_dirty;
|
||||||
BackgroundTexture m_background_texture;
|
BackgroundTexture m_background_texture;
|
||||||
mutable Layout m_layout;
|
Layout m_layout;
|
||||||
|
|
||||||
ItemsList m_items;
|
ItemsList m_items;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue