Implemented a zoom slider for the editor gui.
This commit is contained in:
parent
48e795aa6d
commit
e309a62043
6 changed files with 129 additions and 9 deletions
|
@ -648,6 +648,13 @@
|
|||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/action]
|
||||
|
||||
[slider]
|
||||
id=map-zoom-slider
|
||||
rect="=,+4,+150,+22"
|
||||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/slider]
|
||||
|
||||
####### Main Toolbar
|
||||
[panel]
|
||||
|
|
|
@ -110,6 +110,7 @@ display::display(unit_map* units, CVideo& video, const gamemap* map, const std::
|
|||
reports_(),
|
||||
menu_buttons_(),
|
||||
action_buttons_(),
|
||||
sliders_(),
|
||||
invalidated_(),
|
||||
previous_invalidated_(),
|
||||
mouseover_hex_overlay_(NULL),
|
||||
|
@ -798,10 +799,47 @@ gui::button* display::find_menu_button(const std::string& id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
gui::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];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void display::create_buttons()
|
||||
{
|
||||
std::vector<gui::button> menu_work;
|
||||
std::vector<gui::button> action_work;
|
||||
std::vector<gui::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::slider s(screen_);
|
||||
DBG_DP << "drawing button " << i->get_id() << "\n";
|
||||
s.set_id(i->get_id());
|
||||
const SDL_Rect& loc = i->location(screen_area());
|
||||
s.set_location(loc);
|
||||
//TODO support for non zoom sliders
|
||||
s.set_max(MaxZoom);
|
||||
s.set_min(MinZoom);
|
||||
s.set_value(zoom_);
|
||||
if (!i->tooltip().empty()){
|
||||
s.set_tooltip_string(i->tooltip());
|
||||
}
|
||||
if(rects_overlap(s.location(),map_outside_area())) {
|
||||
s.set_volatile(true);
|
||||
}
|
||||
|
||||
gui::slider* s_prev = find_slider(s.id());
|
||||
//TODO also copy the other states.
|
||||
if(s_prev) s.enable(s_prev->enabled());
|
||||
|
||||
slider_work.push_back(s);
|
||||
}
|
||||
|
||||
DBG_DP << "creating menu buttons...\n";
|
||||
const std::vector<theme::menu>& buttons = theme_.menus();
|
||||
|
@ -849,6 +887,7 @@ void display::create_buttons()
|
|||
|
||||
menu_buttons_.swap(menu_work);
|
||||
action_buttons_.swap(action_work);
|
||||
sliders_.swap(slider_work);
|
||||
DBG_DP << "buttons created\n";
|
||||
}
|
||||
|
||||
|
@ -1881,9 +1920,11 @@ bool display::zoom_at_min() const
|
|||
return zoom_ == MinZoom;
|
||||
}
|
||||
|
||||
void display::set_zoom(int amount)
|
||||
void display::set_zoom(int amount, bool absolute)
|
||||
{
|
||||
int new_zoom = zoom_ + amount;
|
||||
if (absolute)
|
||||
new_zoom = amount;
|
||||
if (new_zoom < MinZoom) {
|
||||
new_zoom = MinZoom;
|
||||
}
|
||||
|
@ -1891,6 +1932,10 @@ void display::set_zoom(int amount)
|
|||
new_zoom = MaxZoom;
|
||||
}
|
||||
if (new_zoom != zoom_) {
|
||||
gui::slider* zoom_slider = find_slider("map-zoom-slider");
|
||||
if (zoom_slider) {
|
||||
zoom_slider->set_value(new_zoom);
|
||||
}
|
||||
SDL_Rect const &area = map_area();
|
||||
xpos_ += (xpos_ + area.w / 2) * amount / zoom_;
|
||||
ypos_ += (ypos_ + area.h / 2) * amount / zoom_;
|
||||
|
@ -2253,7 +2298,7 @@ void display::redraw_everything()
|
|||
|
||||
theme_.set_resolution(screen_area());
|
||||
|
||||
if(menu_buttons_.empty() == false) {
|
||||
if(!menu_buttons_.empty() || !action_buttons_.empty() || !sliders_.empty() ) {
|
||||
create_buttons();
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ class arrow;
|
|||
#include "theme.hpp"
|
||||
#include "video.hpp"
|
||||
#include "widgets/button.hpp"
|
||||
#include "widgets/slider.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
|
@ -350,6 +351,7 @@ public:
|
|||
*/
|
||||
gui::button* find_action_button(const std::string& id);
|
||||
gui::button* find_menu_button(const std::string& id);
|
||||
gui::slider* find_slider(const std::string& id);
|
||||
|
||||
gui::button::TYPE string_to_button_type(std::string type);
|
||||
void create_buttons();
|
||||
|
@ -481,7 +483,7 @@ public:
|
|||
* otherwise the images might start to look odd
|
||||
* (hex_width() gets rounding errors).
|
||||
*/
|
||||
void set_zoom(int amount);
|
||||
void set_zoom(int amount, bool absolute = false);
|
||||
|
||||
bool zoom_at_max() const;
|
||||
bool zoom_at_min() const;
|
||||
|
@ -731,6 +733,7 @@ protected:
|
|||
std::map<std::string, surface> reportSurfaces_;
|
||||
std::map<std::string, config> reports_;
|
||||
std::vector<gui::button> menu_buttons_, action_buttons_;
|
||||
std::vector<gui::slider> sliders_;
|
||||
std::set<map_location> invalidated_;
|
||||
std::set<map_location> previous_invalidated_;
|
||||
surface mouseover_hex_overlay_;
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
*/
|
||||
#define GETTEXT_DOMAIN "wesnoth-editor"
|
||||
|
||||
#include "widgets/slider.hpp"
|
||||
|
||||
#include "editor/map/context_manager.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
|
@ -1007,6 +1009,9 @@ void editor_controller::left_mouse_up(int x, int y, const bool /*browse*/)
|
|||
perform_delete(a);
|
||||
if (a) set_button_state(*gui_);
|
||||
toolkit_->set_mouseover_overlay();
|
||||
gui::slider* s = gui_->find_slider("map-zoom-slider");
|
||||
if (s && s->value_change())
|
||||
gui_->set_zoom(s->value(), true);
|
||||
context_manager_->refresh_after_action();
|
||||
}
|
||||
|
||||
|
|
|
@ -499,6 +499,19 @@ theme::status_item::status_item(const config& cfg) :
|
|||
theme::panel::panel(const config& cfg) : object(cfg), image_(cfg["image"])
|
||||
{}
|
||||
|
||||
theme::slider::slider() :
|
||||
object(),
|
||||
title_(),
|
||||
tooltip_(),
|
||||
image_(),
|
||||
overlay_()
|
||||
{}
|
||||
theme::slider::slider(const config &cfg):
|
||||
object(cfg),
|
||||
title_(cfg["title"].str() + cfg["title_literal"].str()),
|
||||
tooltip_(cfg["tooltip"]), image_(cfg["image"]), overlay_(cfg["overlay"])
|
||||
{}
|
||||
|
||||
theme::menu::menu() :
|
||||
object(),
|
||||
context_(false),
|
||||
|
@ -693,6 +706,16 @@ void theme::add_object(const config& cfg)
|
|||
DBG_DP << "done adding action...\n";
|
||||
}
|
||||
|
||||
BOOST_FOREACH(const config &s, cfg.child_range("slider"))
|
||||
{
|
||||
slider new_slider(s);
|
||||
DBG_DP << "adding slider\n";
|
||||
set_object_location(new_slider, s["rect"], s["ref"]);
|
||||
sliders_.push_back(new_slider);
|
||||
|
||||
DBG_DP << "done adding slider...\n";
|
||||
}
|
||||
|
||||
if (const config &c = cfg.child("main_map_border")) {
|
||||
border_ = tborder(c);
|
||||
} else {
|
||||
|
@ -725,6 +748,12 @@ void theme::remove_object(std::string id){
|
|||
return;
|
||||
}
|
||||
}
|
||||
for(std::vector<theme::slider>::iterator s = sliders_.begin(); s != sliders_.end(); ++s) {
|
||||
if (s->get_id() == id){
|
||||
sliders_.erase(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void theme::set_object_location(theme::object& element, std::string rect_str, std::string ref_id){
|
||||
|
@ -851,20 +880,28 @@ const theme::menu *theme::get_menu_item(const std::string &key) const
|
|||
}
|
||||
|
||||
|
||||
theme::menu* theme::refresh_title(const std::string& id, const std::string& new_title){
|
||||
theme::menu* res = NULL;
|
||||
theme::object* theme::refresh_title(const std::string& id, const std::string& new_title){
|
||||
|
||||
theme::object* res = NULL;
|
||||
|
||||
for (std::vector<theme::action>::iterator a = actions_.begin(); a != actions_.end(); ++a){
|
||||
if (a->get_id() == id) {
|
||||
res = &(*a);
|
||||
a->set_title(new_title);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<theme::menu>::iterator m = menus_.begin(); m != menus_.end(); ++m){
|
||||
if (m->get_id() == id) {
|
||||
res = &(*m);
|
||||
res->set_title(new_title);
|
||||
m->set_title(new_title);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
theme::menu* theme::refresh_title2(const std::string& id, const std::string& title_tag){
|
||||
theme::object* theme::refresh_title2(const std::string& id, const std::string& title_tag){
|
||||
std::string new_title;
|
||||
|
||||
const config &cfg = find_ref(id, cfg_, false);
|
||||
|
|
|
@ -192,6 +192,27 @@ public:
|
|||
std::vector<std::string> items_;
|
||||
};
|
||||
|
||||
class slider : public object
|
||||
{
|
||||
public:
|
||||
slider();
|
||||
explicit slider(const config& cfg);
|
||||
|
||||
using object::location;
|
||||
|
||||
const std::string& title() const { return title_; }
|
||||
|
||||
const std::string& tooltip() const { return tooltip_; }
|
||||
|
||||
const std::string& image() const { return image_; }
|
||||
|
||||
const std::string& overlay() const { return overlay_; }
|
||||
|
||||
void set_title(const std::string& new_title) { title_ = new_title; }
|
||||
private:
|
||||
std::string title_, tooltip_, image_, overlay_;
|
||||
};
|
||||
|
||||
class menu : public object
|
||||
{
|
||||
public:
|
||||
|
@ -226,6 +247,7 @@ public:
|
|||
const std::vector<panel>& panels() const { return panels_; }
|
||||
const std::vector<label>& labels() const { return labels_; }
|
||||
const std::vector<menu>& menus() const { return menus_; }
|
||||
const std::vector<slider>& sliders() const { return sliders_; }
|
||||
const std::vector<action>& actions() const { return actions_; }
|
||||
|
||||
const menu* context_menu() const
|
||||
|
@ -233,8 +255,8 @@ public:
|
|||
|
||||
//refresh_title2 changes the title of a menu entry, identified by id.
|
||||
//If no menu entry is found, an empty menu object is returned.
|
||||
menu* refresh_title(const std::string& id, const std::string& new_title);
|
||||
menu* refresh_title2(const std::string& id, const std::string& title_tag);
|
||||
object* refresh_title(const std::string& id, const std::string& new_title);
|
||||
object* refresh_title2(const std::string& id, const std::string& title_tag);
|
||||
void modify_label(const std::string& id, const std::string& text);
|
||||
|
||||
const status_item* get_status_item(const std::string& item) const;
|
||||
|
@ -273,6 +295,7 @@ private:
|
|||
std::vector<label> labels_;
|
||||
std::vector<menu> menus_;
|
||||
std::vector<action> actions_;
|
||||
std::vector<slider> sliders_;
|
||||
|
||||
menu context_;
|
||||
action action_context_;
|
||||
|
|
Loading…
Add table
Reference in a new issue