Fix bug #24762: Recreate buttons GUI buttons on a full redraw
This re-creates the main display-gui() buttons on a full redraw to take into account that the theme expects them to be out of sync. As a consequence I have also been forced to refactor how said buttons are managed and introduced a new method to join the same event context as another component.
This commit is contained in:
parent
f5b6fbe942
commit
64b90042c4
17 changed files with 163 additions and 131 deletions
|
@ -38,6 +38,7 @@ Version 1.13.4+dev:
|
|||
they aren't discovered yet
|
||||
* Added an option to disable the loadingscreen animation since it caused
|
||||
bugs in some configurations.
|
||||
* Fix bug #24762: Editor actions are out of sync after resizing.
|
||||
* WML engine:
|
||||
* Add color= attribute to [message].
|
||||
* Fix some issues with [foreach]
|
||||
|
|
123
src/display.cpp
123
src/display.cpp
|
@ -823,31 +823,31 @@ bool display::screenshot(const std::string& filename, bool map_screenshot)
|
|||
return res;
|
||||
}
|
||||
|
||||
gui::button* display::find_action_button(const std::string& id)
|
||||
std::shared_ptr<gui::button> display::find_action_button(const std::string& id)
|
||||
{
|
||||
for (size_t i = 0; i < action_buttons_.size(); ++i) {
|
||||
if(action_buttons_[i].id() == id) {
|
||||
return &action_buttons_[i];
|
||||
if(action_buttons_[i]->id() == id) {
|
||||
return action_buttons_[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gui::button* display::find_menu_button(const std::string& id)
|
||||
std::shared_ptr<gui::button> display::find_menu_button(const std::string& id)
|
||||
{
|
||||
for (size_t i = 0; i < menu_buttons_.size(); ++i) {
|
||||
if(menu_buttons_[i].id() == id) {
|
||||
return &menu_buttons_[i];
|
||||
if(menu_buttons_[i]->id() == id) {
|
||||
return menu_buttons_[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gui::zoom_slider* display::find_slider(const std::string& id)
|
||||
std::shared_ptr<gui::zoom_slider> display::find_slider(const std::string& id)
|
||||
{
|
||||
for (size_t i = 0; i < sliders_.size(); ++i) {
|
||||
if(sliders_[i].id() == id) {
|
||||
return &sliders_[i];
|
||||
if(sliders_[i]->id() == id) {
|
||||
return sliders_[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -859,7 +859,7 @@ void display::layout_buttons()
|
|||
DBG_DP << "positioning sliders...\n";
|
||||
const std::vector<theme::slider>& sliders = theme_.sliders();
|
||||
for(std::vector<theme::slider>::const_iterator i = sliders.begin(); i != sliders.end(); ++i) {
|
||||
gui::zoom_slider* s = find_slider(i->get_id());
|
||||
std::shared_ptr<gui::zoom_slider> s = find_slider(i->get_id());
|
||||
if (s) {
|
||||
const SDL_Rect& loc = i->location(screen_area());
|
||||
s->set_location(loc);
|
||||
|
@ -870,7 +870,7 @@ void display::layout_buttons()
|
|||
DBG_DP << "positioning menu buttons...\n";
|
||||
const std::vector<theme::menu>& buttons = theme_.menus();
|
||||
for(std::vector<theme::menu>::const_iterator i = buttons.begin(); i != buttons.end(); ++i) {
|
||||
gui::button* b = find_menu_button(i->get_id());
|
||||
std::shared_ptr<gui::button> b = find_menu_button(i->get_id());
|
||||
if(b) {
|
||||
const SDL_Rect& loc = i->location(screen_area());
|
||||
b->set_location(loc);
|
||||
|
@ -883,7 +883,7 @@ void display::layout_buttons()
|
|||
DBG_DP << "positioning action buttons...\n";
|
||||
const std::vector<theme::action>& actions = theme_.actions();
|
||||
for(std::vector<theme::action>::const_iterator i = actions.begin(); i != actions.end(); ++i) {
|
||||
gui::button* b = find_action_button(i->get_id());
|
||||
std::shared_ptr<gui::button> b = find_action_button(i->get_id());
|
||||
if(b) {
|
||||
const SDL_Rect& loc = i->location(screen_area());
|
||||
b->set_location(loc);
|
||||
|
@ -896,30 +896,33 @@ void display::layout_buttons()
|
|||
|
||||
void display::create_buttons()
|
||||
{
|
||||
std::vector<gui::button> menu_work;
|
||||
std::vector<gui::button> action_work;
|
||||
std::vector<gui::zoom_slider> slider_work;
|
||||
std::vector<std::shared_ptr<gui::button>> menu_work;
|
||||
std::vector<std::shared_ptr<gui::button>> action_work;
|
||||
std::vector<std::shared_ptr<gui::zoom_slider>> slider_work;
|
||||
|
||||
DBG_DP << "creating sliders...\n";
|
||||
const std::vector<theme::slider>& sliders = theme_.sliders();
|
||||
for(std::vector<theme::slider>::const_iterator i = sliders.begin(); i != sliders.end(); ++i) {
|
||||
gui::zoom_slider s(screen_, i->image(), i->black_line());
|
||||
std::shared_ptr<gui::zoom_slider> s(new gui::zoom_slider(screen_, i->image(), i->black_line()));
|
||||
s->leave();
|
||||
s->join_same(this);
|
||||
DBG_DP << "drawing button " << i->get_id() << "\n";
|
||||
s.set_id(i->get_id());
|
||||
s->set_id(i->get_id());
|
||||
//TODO support for non zoom sliders
|
||||
s.set_max(MaxZoom);
|
||||
s.set_min(MinZoom);
|
||||
s.set_value(zoom_);
|
||||
s->set_max(MaxZoom);
|
||||
s->set_min(MinZoom);
|
||||
s->set_value(zoom_);
|
||||
if (!i->tooltip().empty()){
|
||||
s.set_tooltip_string(i->tooltip());
|
||||
s->set_tooltip_string(i->tooltip());
|
||||
}
|
||||
|
||||
gui::zoom_slider* s_prev = find_slider(s.id());
|
||||
std::shared_ptr<gui::zoom_slider> s_prev = find_slider(s->id());
|
||||
if(s_prev) {
|
||||
s.set_max(s_prev->max_value());
|
||||
s.set_min(s_prev->min_value());
|
||||
s.set_value(s_prev->value());
|
||||
s.enable(s_prev->enabled());
|
||||
//s_prev->leave();
|
||||
s->set_max(s_prev->max_value());
|
||||
s->set_min(s_prev->min_value());
|
||||
s->set_value(s_prev->value());
|
||||
s->enable(s_prev->enabled());
|
||||
}
|
||||
|
||||
slider_work.push_back(s);
|
||||
|
@ -931,42 +934,48 @@ void display::create_buttons()
|
|||
|
||||
if (!i->is_button()) continue;
|
||||
|
||||
gui::button b(screen_, i->title(), gui::button::TYPE_PRESS, i->image(),
|
||||
gui::button::DEFAULT_SPACE, true, i->overlay());
|
||||
std::shared_ptr<gui::button> b(new gui::button(screen_, i->title(), gui::button::TYPE_PRESS, i->image(),
|
||||
gui::button::DEFAULT_SPACE, false, i->overlay()));
|
||||
DBG_DP << "drawing button " << i->get_id() << "\n";
|
||||
b.set_id(i->get_id());
|
||||
b->join_same(this);
|
||||
b->set_id(i->get_id());
|
||||
if (!i->tooltip().empty()){
|
||||
b.set_tooltip_string(i->tooltip());
|
||||
b->set_tooltip_string(i->tooltip());
|
||||
}
|
||||
|
||||
gui::button* b_prev = find_menu_button(b.id());
|
||||
if(b_prev) b.enable(b_prev->enabled());
|
||||
std::shared_ptr<gui::button> b_prev = find_menu_button(b->id());
|
||||
if(b_prev) {
|
||||
b->enable(b_prev->enabled());
|
||||
}
|
||||
|
||||
menu_work.push_back(b);
|
||||
}
|
||||
DBG_DP << "creating action buttons...\n";
|
||||
const std::vector<theme::action>& actions = theme_.actions();
|
||||
for(std::vector<theme::action>::const_iterator i = actions.begin(); i != actions.end(); ++i) {
|
||||
gui::button b(screen_, i->title(), string_to_button_type(i->type()), i->image(),
|
||||
gui::button::DEFAULT_SPACE, true, i->overlay());
|
||||
std::shared_ptr<gui::button> b(new gui::button(screen_, i->title(), string_to_button_type(i->type()), i->image(),
|
||||
gui::button::DEFAULT_SPACE, false, i->overlay()));
|
||||
|
||||
DBG_DP << "drawing button " << i->get_id() << "\n";
|
||||
b.set_id(i->get_id());
|
||||
b->set_id(i->get_id());
|
||||
b->join_same(this);
|
||||
if (!i->tooltip(0).empty()){
|
||||
b.set_tooltip_string(i->tooltip(0));
|
||||
b->set_tooltip_string(i->tooltip(0));
|
||||
}
|
||||
|
||||
gui::button* b_prev = find_action_button(b.id());
|
||||
if(b_prev) b.enable(b_prev->enabled());
|
||||
std::shared_ptr<gui::button> b_prev = find_action_button(b->id());
|
||||
if(b_prev) b->enable(b_prev->enabled());
|
||||
|
||||
action_work.push_back(b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
menu_buttons_.swap(menu_work);
|
||||
action_buttons_.swap(action_work);
|
||||
sliders_.swap(slider_work);
|
||||
menu_buttons_.clear();
|
||||
menu_buttons_.assign(menu_work.begin(), menu_work.end());
|
||||
action_buttons_.clear();
|
||||
action_buttons_.assign(action_work.begin(), action_work.end());
|
||||
sliders_.clear();
|
||||
sliders_.assign(slider_work.begin(), slider_work.end());
|
||||
|
||||
layout_buttons();
|
||||
DBG_DP << "buttons created\n";
|
||||
|
@ -974,16 +983,16 @@ void display::create_buttons()
|
|||
|
||||
void display::render_buttons()
|
||||
{
|
||||
for (gui::button &btn : menu_buttons_) {
|
||||
btn.set_dirty(true);
|
||||
for (std::shared_ptr<gui::button> btn : menu_buttons_) {
|
||||
btn->set_dirty(true);
|
||||
}
|
||||
|
||||
for (gui::button &btn : action_buttons_) {
|
||||
btn.set_dirty(true);
|
||||
for (std::shared_ptr<gui::button> btn : action_buttons_) {
|
||||
btn->set_dirty(true);
|
||||
}
|
||||
|
||||
for (gui::slider &sld : sliders_) {
|
||||
sld.set_dirty(true);
|
||||
for (std::shared_ptr<gui::slider> sld : sliders_) {
|
||||
sld->set_dirty(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1486,7 +1495,7 @@ void display::update_display()
|
|||
#ifdef SDL_GPU
|
||||
static void draw_panel(surface &target, const theme::panel& panel, std::vector<gui::button>& /*buttons*/)
|
||||
#else
|
||||
static void draw_panel(CVideo &video, const theme::panel& panel, std::vector<gui::button>& /*buttons*/)
|
||||
static void draw_panel(CVideo &video, const theme::panel& panel, std::vector<std::shared_ptr<gui::button>>& /*buttons*/)
|
||||
#endif
|
||||
{
|
||||
//log_scope("draw panel");
|
||||
|
@ -1889,9 +1898,9 @@ void display::draw_wrap(bool update, bool force)
|
|||
|
||||
const theme::action* display::action_pressed()
|
||||
{
|
||||
for(std::vector<gui::button>::iterator i = action_buttons_.begin();
|
||||
for(std::vector<std::shared_ptr<gui::button>>::iterator i = action_buttons_.begin();
|
||||
i != action_buttons_.end(); ++i) {
|
||||
if(i->pressed()) {
|
||||
if((*i)->pressed()) {
|
||||
const size_t index = i - action_buttons_.begin();
|
||||
if(index >= theme_.actions().size()) {
|
||||
assert(false);
|
||||
|
@ -1906,14 +1915,14 @@ const theme::action* display::action_pressed()
|
|||
|
||||
const theme::menu* display::menu_pressed()
|
||||
{
|
||||
for(std::vector<gui::button>::iterator i = menu_buttons_.begin(); i != menu_buttons_.end(); ++i) {
|
||||
if(i->pressed()) {
|
||||
for(std::vector<std::shared_ptr<gui::button>>::iterator i = menu_buttons_.begin(); i != menu_buttons_.end(); ++i) {
|
||||
if((*i)->pressed()) {
|
||||
const size_t index = i - menu_buttons_.begin();
|
||||
if(index >= theme_.menus().size()) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
return theme_.get_menu_item(i->id());
|
||||
return theme_.get_menu_item((*i)->id());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1933,7 +1942,7 @@ void display::enable_menu(const std::string& item, bool enable)
|
|||
if(index >= menu_buttons_.size()) {
|
||||
continue;
|
||||
}
|
||||
menu_buttons_[index].enable(enable);
|
||||
menu_buttons_[index]->enable(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2286,7 +2295,7 @@ bool display::set_zoom(int amount, bool absolute)
|
|||
}
|
||||
LOG_DP << "new_zoom = " << new_zoom << std::endl;
|
||||
if (new_zoom != zoom_) {
|
||||
gui::slider* zoom_slider = find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> zoom_slider = find_slider("map-zoom-slider");
|
||||
if (zoom_slider) {
|
||||
zoom_slider->set_value(new_zoom);
|
||||
}
|
||||
|
@ -2659,7 +2668,7 @@ void display::redraw_everything()
|
|||
|
||||
theme_.set_resolution(screen_area());
|
||||
|
||||
layout_buttons();
|
||||
create_buttons();
|
||||
render_buttons();
|
||||
|
||||
panelsDrawn_ = false;
|
||||
|
|
|
@ -71,6 +71,7 @@ namespace wb {
|
|||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
class gamemap;
|
||||
|
||||
|
@ -393,9 +394,9 @@ public:
|
|||
* these pointers for longer than strictly necessary to
|
||||
* accomplish a specific task before the next screen refresh.
|
||||
*/
|
||||
gui::button* find_action_button(const std::string& id);
|
||||
gui::button* find_menu_button(const std::string& id);
|
||||
gui::zoom_slider* find_slider(const std::string& id);
|
||||
std::shared_ptr<gui::button> find_action_button(const std::string& id);
|
||||
std::shared_ptr<gui::button> find_menu_button(const std::string& id);
|
||||
std::shared_ptr<gui::zoom_slider> find_slider(const std::string& id);
|
||||
|
||||
gui::button::TYPE string_to_button_type(std::string type);
|
||||
void create_buttons();
|
||||
|
@ -812,8 +813,8 @@ protected:
|
|||
std::map<std::string, surface> reportSurfaces_;
|
||||
#endif
|
||||
std::map<std::string, config> reports_;
|
||||
std::vector<gui::button> menu_buttons_, action_buttons_;
|
||||
std::vector<gui::zoom_slider> sliders_;
|
||||
std::vector<std::shared_ptr<gui::button>> menu_buttons_, action_buttons_;
|
||||
std::vector<std::shared_ptr<gui::zoom_slider>> sliders_;
|
||||
std::set<map_location> invalidated_;
|
||||
std::set<map_location> previous_invalidated_;
|
||||
#ifdef SDL_GPU
|
||||
|
|
|
@ -656,7 +656,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
|
|||
context_manager_->get_map_context().add_to_playlist(music_tracks_[index]);
|
||||
std::vector<std::string> items;
|
||||
items.push_back("editor-playlist");
|
||||
gui::button* b = gui_->find_menu_button("menu-playlist");
|
||||
std::shared_ptr<gui::button> b = gui_->find_menu_button("menu-playlist");
|
||||
show_menu(items, b->location().x +1, b->location().y + b->height() +1, false, *gui_);
|
||||
return true;
|
||||
}
|
||||
|
@ -1312,7 +1312,7 @@ void editor_controller::left_mouse_up(int x, int y, const bool /*browse*/)
|
|||
perform_delete(a);
|
||||
if (a) set_button_state();
|
||||
toolkit_->set_mouseover_overlay();
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change()) {
|
||||
if (gui_->set_zoom(s->value(), true)) {
|
||||
context_manager_->get_map_context().get_labels().recalculate_labels();
|
||||
|
|
|
@ -170,7 +170,7 @@ void editor_palette<Item>::set_group(const std::string& id)
|
|||
for (const item_group& group : groups_) {
|
||||
if (group.id == id) {
|
||||
found = true;
|
||||
gui::button* palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
if (palette_menu_button) {
|
||||
//palette_menu_button->set_label(group.name);
|
||||
palette_menu_button->set_tooltip_string(group.name);
|
||||
|
@ -309,7 +309,7 @@ void editor_palette<Item>::draw_contents()
|
|||
if (*active_mouse_action_)
|
||||
(*active_mouse_action_)->set_mouse_overlay(gui_);
|
||||
|
||||
gui::button* palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
if (palette_menu_button) {
|
||||
|
||||
t_string& name = groups_[active_group_index()].name;
|
||||
|
@ -324,10 +324,10 @@ void editor_palette<Item>::draw_contents()
|
|||
int starting = items_start_;
|
||||
int ending = std::min<int>(starting + nitems_, num_items());
|
||||
|
||||
gui::button* upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
if (upscroll_button)
|
||||
upscroll_button->enable(starting != 0);
|
||||
gui::button* downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
if (downscroll_button)
|
||||
downscroll_button->enable(ending != num_items());
|
||||
|
||||
|
|
|
@ -46,19 +46,19 @@ public:
|
|||
|
||||
void hide(bool hidden) {
|
||||
if (!hidden) {
|
||||
gui::button* upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
upscroll_button->enable(false);
|
||||
gui::button* downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
downscroll_button->enable(false);
|
||||
gui::button* palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
palette_menu_button->set_overlay("");
|
||||
palette_menu_button->enable(false);
|
||||
} else {
|
||||
gui::button* upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
upscroll_button->enable(true);
|
||||
gui::button* downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
downscroll_button->enable(true);
|
||||
gui::button* palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
std::shared_ptr<gui::button> palette_menu_button = gui_.find_menu_button("menu-editor-terrain");
|
||||
palette_menu_button->enable(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,10 +308,10 @@ void location_palette::draw_contents()
|
|||
const int x = palette_x_;
|
||||
const int starting = items_start_;
|
||||
int ending = std::min<int>(starting + num_visible_items(), num_items());
|
||||
gui::button* upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
if (upscroll_button)
|
||||
upscroll_button->enable(starting != 0);
|
||||
gui::button* downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
if (downscroll_button)
|
||||
downscroll_button->enable(ending != num_items());
|
||||
|
||||
|
|
|
@ -130,13 +130,13 @@ void palette_manager::draw_contents()
|
|||
|
||||
tooltips::clear_tooltips(loc);
|
||||
|
||||
gui::button* upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
std::shared_ptr<gui::button> upscroll_button = gui_.find_action_button("upscroll-button-editor");
|
||||
if (upscroll_button)
|
||||
upscroll_button->hide(false);
|
||||
gui::button* downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
std::shared_ptr<gui::button> downscroll_button = gui_.find_action_button("downscroll-button-editor");
|
||||
if (downscroll_button)
|
||||
downscroll_button->hide(false);
|
||||
gui::button* palette_menu_button = gui_.find_action_button("menu-editor-terrain");
|
||||
std::shared_ptr<gui::button> palette_menu_button = gui_.find_action_button("menu-editor-terrain");
|
||||
if (palette_menu_button)
|
||||
palette_menu_button->hide(false);
|
||||
|
||||
|
|
|
@ -41,27 +41,6 @@
|
|||
namespace events
|
||||
{
|
||||
|
||||
namespace {
|
||||
|
||||
struct context
|
||||
{
|
||||
context() :
|
||||
handlers(),
|
||||
focused_handler(-1)
|
||||
{
|
||||
}
|
||||
|
||||
void add_handler(sdl_handler* ptr);
|
||||
bool remove_handler(sdl_handler* ptr);
|
||||
int cycle_focus();
|
||||
void set_focus(const sdl_handler* ptr);
|
||||
|
||||
std::vector<sdl_handler*> handlers;
|
||||
int focused_handler;
|
||||
|
||||
void delete_handler_index(size_t handler);
|
||||
};
|
||||
|
||||
void context::add_handler(sdl_handler* ptr)
|
||||
{
|
||||
handlers.push_back(ptr);
|
||||
|
@ -148,8 +127,6 @@ context global_context;
|
|||
|
||||
std::vector<pump_monitor*> pump_monitors;
|
||||
|
||||
} //end anon namespace
|
||||
|
||||
pump_monitor::pump_monitor() {
|
||||
pump_monitors.push_back(this);
|
||||
}
|
||||
|
@ -193,24 +170,45 @@ sdl_handler::~sdl_handler()
|
|||
|
||||
}
|
||||
|
||||
void sdl_handler::join()
|
||||
void sdl_handler::join() {
|
||||
join(event_contexts.back());
|
||||
}
|
||||
|
||||
void sdl_handler::join(context &c)
|
||||
{
|
||||
if(has_joined_) {
|
||||
leave(); // should not be in multiple event contexts
|
||||
}
|
||||
//join self
|
||||
event_contexts.back().add_handler(this);
|
||||
c.add_handler(this);
|
||||
has_joined_ = true;
|
||||
|
||||
//instruct members to join
|
||||
sdl_handler_vector members = handler_members();
|
||||
if(!members.empty()) {
|
||||
for(sdl_handler_vector::iterator i = members.begin(); i != members.end(); ++i) {
|
||||
(*i)->join();
|
||||
(*i)->join(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sdl_handler::join_same(sdl_handler* parent)
|
||||
{
|
||||
if(has_joined_) {
|
||||
leave(); // should not be in multiple event contexts
|
||||
}
|
||||
|
||||
for(std::deque<context>::reverse_iterator i = event_contexts.rbegin(); i != event_contexts.rend(); ++i) {
|
||||
std::vector<sdl_handler *> &handlers = (*i).handlers;
|
||||
if (std::find(handlers.begin(), handlers.end(), parent) != handlers.end()) {
|
||||
join(*i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
join(global_context);
|
||||
|
||||
}
|
||||
|
||||
void sdl_handler::leave()
|
||||
{
|
||||
sdl_handler_vector members = handler_members();
|
||||
|
|
|
@ -31,6 +31,27 @@
|
|||
namespace events
|
||||
{
|
||||
|
||||
class sdl_handler;
|
||||
|
||||
struct context
|
||||
{
|
||||
context() :
|
||||
handlers(),
|
||||
focused_handler(-1)
|
||||
{
|
||||
}
|
||||
|
||||
void add_handler(sdl_handler* ptr);
|
||||
bool remove_handler(sdl_handler* ptr);
|
||||
int cycle_focus();
|
||||
void set_focus(const sdl_handler* ptr);
|
||||
|
||||
std::vector<sdl_handler*> handlers;
|
||||
int focused_handler;
|
||||
|
||||
void delete_handler_index(size_t handler);
|
||||
};
|
||||
|
||||
//any classes that derive from this class will automatically
|
||||
//receive sdl events through the handle function for their lifetime,
|
||||
//while the event context they were created in is active.
|
||||
|
@ -55,6 +76,8 @@ public:
|
|||
virtual void process_tooltip_string(int /*mousex*/, int /*mousey*/) {}
|
||||
|
||||
virtual void join(); /*joins the current event context*/
|
||||
virtual void join(context &c); /*joins the specified event context*/
|
||||
virtual void join_same(sdl_handler* parent); /*joins the same event context as the parent is already associated with */
|
||||
virtual void leave(); /*leave the event context*/
|
||||
|
||||
virtual void join_global(); /*join the global event context*/
|
||||
|
|
|
@ -642,7 +642,7 @@ void command_executor_default::set_button_state()
|
|||
display& disp = get_display();
|
||||
for (const theme::menu& menu : disp.get_theme().menus()) {
|
||||
|
||||
gui::button* button = disp.find_menu_button(menu.get_id());
|
||||
std::shared_ptr<gui::button> button = disp.find_menu_button(menu.get_id());
|
||||
if (!button) continue;
|
||||
bool enabled = false;
|
||||
for (const std::string& command : menu.items()) {
|
||||
|
@ -659,7 +659,7 @@ void command_executor_default::set_button_state()
|
|||
|
||||
for (const theme::action& action : disp.get_theme().actions()) {
|
||||
|
||||
gui::button* button = disp.find_action_button(action.get_id());
|
||||
std::shared_ptr<gui::button> button = disp.find_action_button(action.get_id());
|
||||
if (!button) continue;
|
||||
bool enabled = false;
|
||||
int i = 0;
|
||||
|
|
|
@ -478,7 +478,7 @@ bool mouse_handler::right_click_show_menu(int x, int y, const bool /*browse*/)
|
|||
|
||||
void mouse_handler::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
{
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change())
|
||||
if (gui_->set_zoom(s->value(), true))
|
||||
pc_.get_hotkey_command_executor()->set_button_state();
|
||||
|
@ -486,7 +486,7 @@ void mouse_handler::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
|||
|
||||
void mouse_handler::mouse_wheel_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
{
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change())
|
||||
if (gui_->set_zoom(s->value(), true))
|
||||
pc_.get_hotkey_command_executor()->set_button_state();
|
||||
|
@ -494,7 +494,7 @@ void mouse_handler::mouse_wheel_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
|||
|
||||
void mouse_handler::mouse_wheel_down(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
{
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change())
|
||||
if (gui_->set_zoom(s->value(), true))
|
||||
pc_.get_hotkey_command_executor()->set_button_state();
|
||||
|
@ -502,7 +502,7 @@ void mouse_handler::mouse_wheel_down(int /*x*/, int /*y*/, const bool /*browse*/
|
|||
|
||||
void mouse_handler::mouse_wheel_left(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
{
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change())
|
||||
if (gui_->set_zoom(s->value(), true))
|
||||
pc_.get_hotkey_command_executor()->set_button_state();
|
||||
|
@ -510,7 +510,7 @@ void mouse_handler::mouse_wheel_left(int /*x*/, int /*y*/, const bool /*browse*/
|
|||
|
||||
void mouse_handler::mouse_wheel_right(int /*x*/, int /*y*/, const bool /*browse*/)
|
||||
{
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change())
|
||||
if (gui_->set_zoom(s->value(), true))
|
||||
pc_.get_hotkey_command_executor()->set_button_state();
|
||||
|
|
|
@ -259,7 +259,7 @@ void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse)
|
|||
int movey = scrolly * preferences::scroll_speed();
|
||||
|
||||
// Don't scroll map and map zoom slider at same time
|
||||
gui::slider* s = gui().find_slider("map-zoom-slider");
|
||||
std::shared_ptr<gui::slider> s = gui().find_slider("map-zoom-slider");
|
||||
if (s && sdl::point_in_rect(x, y, s->location())) {
|
||||
movex = 0; movey = 0;
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ void playmp_controller::set_end_scenario_button()
|
|||
{
|
||||
// Modify the end-turn button
|
||||
if (! is_host()) {
|
||||
gui::button* btn_end = gui_->find_action_button("button-endturn");
|
||||
std::shared_ptr<gui::button> btn_end = gui_->find_action_button("button-endturn");
|
||||
btn_end->enable(false);
|
||||
}
|
||||
gui_->get_theme().refresh_title2("button-endturn", "title2");
|
||||
|
|
|
@ -350,7 +350,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
// The host has ended linger mode in a campaign -> enable the "End scenario" button
|
||||
// and tell we did get the notification.
|
||||
else if (cfg.child("notify_next_scenario")) {
|
||||
gui::button* btn_end = resources::screen->find_action_button("button-endturn");
|
||||
std::shared_ptr<gui::button> btn_end = resources::screen->find_action_button("button-endturn");
|
||||
if(btn_end) {
|
||||
btn_end->enable(true);
|
||||
}
|
||||
|
|
|
@ -123,32 +123,32 @@ void replay_controller::rebuild_replay_theme()
|
|||
}
|
||||
}
|
||||
|
||||
gui::button* replay_controller::play_button()
|
||||
std::shared_ptr<gui::button> replay_controller::play_button()
|
||||
{
|
||||
return controller_.get_display().find_action_button("button-playreplay");
|
||||
}
|
||||
|
||||
gui::button* replay_controller::stop_button()
|
||||
std::shared_ptr<gui::button> replay_controller::stop_button()
|
||||
{
|
||||
return controller_.get_display().find_action_button("button-stopreplay");
|
||||
}
|
||||
|
||||
gui::button* replay_controller::reset_button()
|
||||
std::shared_ptr<gui::button> replay_controller::reset_button()
|
||||
{
|
||||
return controller_.get_display().find_action_button("button-resetreplay");
|
||||
}
|
||||
|
||||
gui::button* replay_controller::play_turn_button()
|
||||
std::shared_ptr<gui::button> replay_controller::play_turn_button()
|
||||
{
|
||||
return controller_.get_display().find_action_button("button-nextturn");
|
||||
}
|
||||
|
||||
gui::button* replay_controller::play_side_button()
|
||||
std::shared_ptr<gui::button> replay_controller::play_side_button()
|
||||
{
|
||||
return controller_.get_display().find_action_button("button-nextside");
|
||||
}
|
||||
|
||||
gui::button* replay_controller::play_move_button()
|
||||
std::shared_ptr<gui::button> replay_controller::play_move_button()
|
||||
{
|
||||
return controller_.get_display().find_action_button("button-nextmove");
|
||||
}
|
||||
|
@ -158,9 +158,9 @@ void replay_controller::update_replay_ui()
|
|||
//check if we have all buttons - if someone messed with theme then some buttons may be missing
|
||||
//if any of the buttons is missing, we just disable every one
|
||||
if(!replay_ui_has_all_buttons()) {
|
||||
gui::button *play_b = play_button(), *stop_b = stop_button(),
|
||||
*reset_b = reset_button(), *play_turn_b = play_turn_button(),
|
||||
*play_side_b = play_side_button(), *play_move_b = play_move_button();
|
||||
std::shared_ptr<gui::button> play_b = play_button(), stop_b = stop_button(),
|
||||
reset_b = reset_button(), play_turn_b = play_turn_button(),
|
||||
play_side_b = play_side_button(), play_move_b = play_move_button();
|
||||
|
||||
if(play_b) {
|
||||
play_b->enable(false);
|
||||
|
@ -283,7 +283,7 @@ void replay_controller::handle_generic_event(const std::string& name)
|
|||
} else {
|
||||
add_replay_theme();
|
||||
}
|
||||
if(gui::button* skip_animation_button = controller_.get_display().find_action_button("skip-animation")) {
|
||||
if(std::shared_ptr<gui::button> skip_animation_button = controller_.get_display().find_action_button("skip-animation")) {
|
||||
skip_animation_button->set_check(controller_.is_skipping_replay());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,12 +70,12 @@ private:
|
|||
void replay_ui_playback_should_start();
|
||||
void replay_ui_playback_should_stop();
|
||||
|
||||
gui::button* play_button();
|
||||
gui::button* stop_button();
|
||||
gui::button* reset_button();
|
||||
gui::button* play_turn_button();
|
||||
gui::button* play_side_button();
|
||||
gui::button* play_move_button();
|
||||
std::shared_ptr<gui::button> play_button();
|
||||
std::shared_ptr<gui::button> stop_button();
|
||||
std::shared_ptr<gui::button> reset_button();
|
||||
std::shared_ptr<gui::button> play_turn_button();
|
||||
std::shared_ptr<gui::button> play_side_button();
|
||||
std::shared_ptr<gui::button> play_move_button();
|
||||
|
||||
bool replay_ui_has_all_buttons() {
|
||||
return play_button() && stop_button() && reset_button() &&
|
||||
|
|
Loading…
Add table
Reference in a new issue