From 12d1fd006fd359b66d044d0ad36679dbd8e3c892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20L=C3=B6f?= Date: Wed, 24 Feb 2016 20:45:50 +1300 Subject: [PATCH] Resize action buttons dynamically on the main display This adds the necessary bells and whistles to resize the GUI1 buttons used in the main game display. It is rather painful as it involves re-setting most of the attributes that affect the size. These changes also adds two new draw-methods to the display class and gets rid of the default parameters. This is to avoid warnings from clang since the draw() method comes from a superclass to display now. The GUI1 button's set_image has been updated to treat the image path in the same way as it is treated in the constructor. This should not be a problem since the method is not called from anywhere but the display class, and that call is added in this commit. --- data/themes/_initial.cfg | 4 ++-- src/display.cpp | 11 +++++++++++ src/display.hpp | 6 +++++- src/widgets/button.cpp | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/data/themes/_initial.cfg b/data/themes/_initial.cfg index fb3aff6044fa..e8e8ed421065 100644 --- a/data/themes/_initial.cfg +++ b/data/themes/_initial.cfg @@ -266,7 +266,7 @@ id=minimap-button-3 items=minimap-draw-units type=checkbox - overlay=icons/action/editor-tool-unit_25 + overlay=icons/action/editor-tool-unit image=button_square/button_square_25 auto_tooltip=yes rect="+1,=,+25,+25" @@ -276,7 +276,7 @@ [action] id=minimap-button-4 items=minimap-draw-villages - overlay=icons/action/editor-tool-village_25 + overlay=icons/action/editor-tool-village type=checkbox image=button_square/button_square_25 tooltip_name_prepend=yes diff --git a/src/display.cpp b/src/display.cpp index c1a4bb67de5b..3a424bbf9086 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -898,6 +898,7 @@ void display::layout_buttons() b->set_location(loc); b->set_measurements(0,0); b->set_label(i->title()); + b->set_image(i->image()); b->set_volatile( sdl::rects_overlap(b->location(),map_outside_area())); } @@ -912,6 +913,7 @@ void display::layout_buttons() b->set_location(loc); b->set_measurements(0,0); b->set_label(i->title()); + b->set_image(i->image()); b->set_volatile( sdl::rects_overlap(b->location(),map_outside_area())); } @@ -2746,6 +2748,15 @@ void display::clear_redraw_observers() redraw_observers_.clear(); } +void display::draw() { + draw(true, false); +} + +void display::draw(bool update) { + draw(update, false); +} + + void display::draw(bool update,bool force) { // log_scope("display::draw"); diff --git a/src/display.hpp b/src/display.hpp index 7424ee9f08b5..19ca68565d4b 100644 --- a/src/display.hpp +++ b/src/display.hpp @@ -602,7 +602,11 @@ class display : public filter_context, public video2::draw_layering * Not virtual, since it gathers common actions. Calls various protected * virtuals (further below) to allow specialized behavior in derived classes. */ - void draw(bool update=true, bool force=false); + virtual void draw(); + + void draw(bool update); + + void draw(bool update, bool force); map_labels& labels(); const map_labels& labels() const; diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index ced3775c1ede..215aad9ea95e 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -572,7 +572,7 @@ static bool not_image(const std::string& str) { return !str.empty() && str[0] != void button::set_image(const std::string& image_file) { - button_image_name_ = image_file; + button_image_name_ = "buttons/" + image_file; load_images(); set_dirty(); }