Removed zoom slider code
This slider hasn't worked in ages, and we're planning to remove it anyway. The slider "groove" image remains since it's hard drawn in the background image file.
This commit is contained in:
parent
c376a27082
commit
c912f7e7e7
10 changed files with 2 additions and 659 deletions
|
@ -207,15 +207,6 @@
|
||||||
[/label]
|
[/label]
|
||||||
|
|
||||||
[status]
|
[status]
|
||||||
[zoom_level]
|
|
||||||
id=zoom-level
|
|
||||||
ref=map-zoom-slider
|
|
||||||
rect="=-25,=-1,+117,+18"
|
|
||||||
xanchor=right
|
|
||||||
yanchor=fixed
|
|
||||||
font_size=8
|
|
||||||
[/zoom_level]
|
|
||||||
|
|
||||||
# The size of these rectangles only accommodates hex coordinates
|
# The size of these rectangles only accommodates hex coordinates
|
||||||
# up to 999.
|
# up to 999.
|
||||||
[position]
|
[position]
|
||||||
|
|
|
@ -833,15 +833,6 @@
|
||||||
####### End
|
####### End
|
||||||
|
|
||||||
[status]
|
[status]
|
||||||
[zoom_level]
|
|
||||||
id=zoom-level
|
|
||||||
ref=map-zoom-slider
|
|
||||||
rect="=-25,=-1,+117,+18"
|
|
||||||
xanchor=right
|
|
||||||
yanchor=fixed
|
|
||||||
font_size=8
|
|
||||||
[/zoom_level]
|
|
||||||
|
|
||||||
# The size of these rectangles only accommodates hex coordinates
|
# The size of these rectangles only accommodates hex coordinates
|
||||||
# up to 999.
|
# up to 999.
|
||||||
[position]
|
[position]
|
||||||
|
|
|
@ -181,7 +181,6 @@ display::display(const display_context * dc, CVideo& video, std::weak_ptr<wb::ma
|
||||||
reports_(),
|
reports_(),
|
||||||
menu_buttons_(),
|
menu_buttons_(),
|
||||||
action_buttons_(),
|
action_buttons_(),
|
||||||
sliders_(),
|
|
||||||
invalidated_(),
|
invalidated_(),
|
||||||
previous_invalidated_(),
|
previous_invalidated_(),
|
||||||
mouseover_hex_overlay_(nullptr),
|
mouseover_hex_overlay_(nullptr),
|
||||||
|
@ -241,7 +240,7 @@ display::display(const display_context * dc, CVideo& video, std::weak_ptr<wb::ma
|
||||||
|
|
||||||
init_flags();
|
init_flags();
|
||||||
|
|
||||||
if(!menu_buttons_.empty() || !action_buttons_.empty() || !sliders_.empty() ) {
|
if(!menu_buttons_.empty() || !action_buttons_.empty()) {
|
||||||
create_buttons();
|
create_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,30 +829,8 @@ std::shared_ptr<gui::button> display::find_menu_button(const std::string& id)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void display::layout_buttons()
|
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) {
|
|
||||||
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);
|
|
||||||
s->set_measurements(0,0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG_DP << "positioning menu buttons...\n";
|
DBG_DP << "positioning menu buttons...\n";
|
||||||
const std::vector<theme::menu>& buttons = theme_.menus();
|
const std::vector<theme::menu>& buttons = theme_.menus();
|
||||||
for(std::vector<theme::menu>::const_iterator i = buttons.begin(); i != buttons.end(); ++i) {
|
for(std::vector<theme::menu>::const_iterator i = buttons.begin(); i != buttons.end(); ++i) {
|
||||||
|
@ -885,35 +862,6 @@ void display::create_buttons()
|
||||||
{
|
{
|
||||||
std::vector<std::shared_ptr<gui::button>> menu_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::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) {
|
|
||||||
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());
|
|
||||||
//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());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<gui::zoom_slider> s_prev = find_slider(s->id());
|
|
||||||
if(s_prev) {
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG_DP << "creating menu buttons...\n";
|
DBG_DP << "creating menu buttons...\n";
|
||||||
const std::vector<theme::menu>& buttons = theme_.menus();
|
const std::vector<theme::menu>& buttons = theme_.menus();
|
||||||
|
@ -961,8 +909,6 @@ void display::create_buttons()
|
||||||
menu_buttons_.assign(menu_work.begin(), menu_work.end());
|
menu_buttons_.assign(menu_work.begin(), menu_work.end());
|
||||||
action_buttons_.clear();
|
action_buttons_.clear();
|
||||||
action_buttons_.assign(action_work.begin(), action_work.end());
|
action_buttons_.assign(action_work.begin(), action_work.end());
|
||||||
sliders_.clear();
|
|
||||||
sliders_.assign(slider_work.begin(), slider_work.end());
|
|
||||||
|
|
||||||
layout_buttons();
|
layout_buttons();
|
||||||
DBG_DP << "buttons created\n";
|
DBG_DP << "buttons created\n";
|
||||||
|
@ -977,10 +923,6 @@ void display::render_buttons()
|
||||||
for (std::shared_ptr<gui::button> btn : action_buttons_) {
|
for (std::shared_ptr<gui::button> btn : action_buttons_) {
|
||||||
btn->set_dirty(true);
|
btn->set_dirty(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::shared_ptr<gui::slider> sld : sliders_) {
|
|
||||||
sld->set_dirty(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2079,10 +2021,6 @@ bool display::set_zoom(int amount, bool absolute)
|
||||||
}
|
}
|
||||||
LOG_DP << "new_zoom = " << new_zoom << std::endl;
|
LOG_DP << "new_zoom = " << new_zoom << std::endl;
|
||||||
if (new_zoom != zoom_) {
|
if (new_zoom != zoom_) {
|
||||||
std::shared_ptr<gui::slider> zoom_slider = find_slider("map-zoom-slider");
|
|
||||||
if (zoom_slider) {
|
|
||||||
zoom_slider->set_value(new_zoom);
|
|
||||||
}
|
|
||||||
SDL_Rect const &area = map_area();
|
SDL_Rect const &area = map_area();
|
||||||
xpos_ += (xpos_ + area.w / 2) * (absolute ? new_zoom - zoom_ : amount) / zoom_;
|
xpos_ += (xpos_ + area.w / 2) * (absolute ? new_zoom - zoom_ : amount) / zoom_;
|
||||||
ypos_ += (ypos_ + area.h / 2) * (absolute ? new_zoom - zoom_ : amount) / zoom_;
|
ypos_ += (ypos_ + area.h / 2) * (absolute ? new_zoom - zoom_ : amount) / zoom_;
|
||||||
|
@ -2448,7 +2386,7 @@ void display::redraw_everything()
|
||||||
|
|
||||||
theme_.set_resolution(screen_area());
|
theme_.set_resolution(screen_area());
|
||||||
|
|
||||||
if(!menu_buttons_.empty() || !action_buttons_.empty() || !sliders_.empty() ) {
|
if(!menu_buttons_.empty() || !action_buttons_.empty()) {
|
||||||
create_buttons();
|
create_buttons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ namespace wb {
|
||||||
#include "theme.hpp"
|
#include "theme.hpp"
|
||||||
#include "video.hpp"
|
#include "video.hpp"
|
||||||
#include "widgets/button.hpp"
|
#include "widgets/button.hpp"
|
||||||
#include "widgets/slider.hpp"
|
|
||||||
|
|
||||||
#include "overlay.hpp"
|
#include "overlay.hpp"
|
||||||
|
|
||||||
|
@ -385,7 +384,6 @@ public:
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<gui::button> find_action_button(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::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);
|
gui::button::TYPE string_to_button_type(std::string type);
|
||||||
void create_buttons();
|
void create_buttons();
|
||||||
|
@ -776,7 +774,6 @@ protected:
|
||||||
std::map<std::string, surface> reportSurfaces_;
|
std::map<std::string, surface> reportSurfaces_;
|
||||||
std::map<std::string, config> reports_;
|
std::map<std::string, config> reports_;
|
||||||
std::vector<std::shared_ptr<gui::button>> menu_buttons_, action_buttons_;
|
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> invalidated_;
|
||||||
std::set<map_location> previous_invalidated_;
|
std::set<map_location> previous_invalidated_;
|
||||||
surface mouseover_hex_overlay_;
|
surface mouseover_hex_overlay_;
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
*/
|
*/
|
||||||
#define GETTEXT_DOMAIN "wesnoth-editor"
|
#define GETTEXT_DOMAIN "wesnoth-editor"
|
||||||
|
|
||||||
#include "widgets/slider.hpp"
|
|
||||||
|
|
||||||
#include "editor/map/context_manager.hpp"
|
#include "editor/map/context_manager.hpp"
|
||||||
|
|
||||||
#include "editor/action/action.hpp"
|
#include "editor/action/action.hpp"
|
||||||
|
@ -1317,14 +1315,6 @@ void editor_controller::left_mouse_up(int x, int y, const bool /*browse*/)
|
||||||
perform_delete(a);
|
perform_delete(a);
|
||||||
if (a) set_button_state();
|
if (a) set_button_state();
|
||||||
toolkit_->set_mouseover_overlay();
|
toolkit_->set_mouseover_overlay();
|
||||||
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();
|
|
||||||
toolkit_->set_mouseover_overlay(*gui_);
|
|
||||||
set_button_state();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context_manager_->refresh_after_action();
|
context_manager_->refresh_after_action();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -468,46 +468,6 @@ bool mouse_handler::right_click_show_menu(int x, int y, const bool /*browse*/)
|
||||||
sdl::point_in_rect(x, y, gui().map_area()) );
|
sdl::point_in_rect(x, y, gui().map_area()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_handler::left_mouse_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouse_handler::mouse_wheel_up(int /*x*/, int /*y*/, const bool /*browse*/)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouse_handler::mouse_wheel_down(int /*x*/, int /*y*/, const bool /*browse*/)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouse_handler::mouse_wheel_left(int /*x*/, int /*y*/, const bool /*browse*/)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouse_handler::mouse_wheel_right(int /*x*/, int /*y*/, const bool /*browse*/)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouse_handler::select_or_action(bool browse)
|
void mouse_handler::select_or_action(bool browse)
|
||||||
{
|
{
|
||||||
if (!pc_.get_map_const().on_board(last_hex_))
|
if (!pc_.get_map_const().on_board(last_hex_))
|
||||||
|
|
|
@ -88,12 +88,6 @@ public:
|
||||||
|
|
||||||
void select_or_action(bool browse);
|
void select_or_action(bool browse);
|
||||||
|
|
||||||
void left_mouse_up(int x, int y, const bool /*browse*/);
|
|
||||||
void mouse_wheel_up(int x, int y, const bool /*browse*/);
|
|
||||||
void mouse_wheel_down(int x, int y, const bool /*browse*/);
|
|
||||||
void mouse_wheel_left(int x, int y, const bool /*browse*/);
|
|
||||||
void mouse_wheel_right(int x, int y, const bool /*browse*/);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Due to the way this class is constructed we can assume that the
|
* Due to the way this class is constructed we can assume that the
|
||||||
|
|
|
@ -257,12 +257,6 @@ void mouse_handler_base::mouse_wheel(int scrollx, int scrolly, bool browse)
|
||||||
int movex = scrollx * preferences::scroll_speed();
|
int movex = scrollx * preferences::scroll_speed();
|
||||||
int movey = scrolly * preferences::scroll_speed();
|
int movey = scrolly * preferences::scroll_speed();
|
||||||
|
|
||||||
// Don't scroll map and map zoom slider at same time
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't scroll map if cursor is not in gamemap area
|
// Don't scroll map if cursor is not in gamemap area
|
||||||
if(!sdl::point_in_rect(x, y, gui().map_area())) {
|
if(!sdl::point_in_rect(x, y, gui().map_area())) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,411 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2003 - 2016 by David White <dave@whitevine.net>
|
|
||||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY.
|
|
||||||
|
|
||||||
See the COPYING file for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
|
||||||
|
|
||||||
#include "widgets/slider.hpp"
|
|
||||||
#include "game_config.hpp"
|
|
||||||
#include "font/sdl_ttf.hpp"
|
|
||||||
#include "font/standard_colors.hpp"
|
|
||||||
#include "image.hpp"
|
|
||||||
#include "sdl/rect.hpp"
|
|
||||||
#include "sound.hpp"
|
|
||||||
#include "video.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
#include <boost/math/special_functions/sign.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
const std::string slider_image = ".png";
|
|
||||||
const std::string disabled_image = ".png~GS()";
|
|
||||||
const std::string pressed_image = "-pressed.png";
|
|
||||||
const std::string active_image = "-active.png";
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace gui {
|
|
||||||
|
|
||||||
slider::slider(CVideo &video, const std::string& image, bool black)
|
|
||||||
: widget(video), image_(image::get_image(image + slider_image)),
|
|
||||||
pressedImage_(image::get_image(image + pressed_image)),
|
|
||||||
activeImage_(image::get_image(image + active_image)),
|
|
||||||
disabledImage_(image::get_image(image + disabled_image)),
|
|
||||||
line_color_(black ? font::BLACK_COLOR : font::NORMAL_COLOR),
|
|
||||||
min_(-100000), max_(100000), value_(0),
|
|
||||||
increment_(1), value_change_(false), state_(NORMAL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::enable(bool new_val)
|
|
||||||
{
|
|
||||||
if(new_val != enabled())
|
|
||||||
{
|
|
||||||
state_ = NORMAL;
|
|
||||||
widget::enable(new_val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::set_location(SDL_Rect const &rect)
|
|
||||||
{
|
|
||||||
SDL_Rect r = rect;
|
|
||||||
r.h = image_->h;
|
|
||||||
widget::set_location(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::set_min(int value)
|
|
||||||
{
|
|
||||||
min_ = value;
|
|
||||||
if (value_ < min_) {
|
|
||||||
value_ = min_;
|
|
||||||
value_change_ = true;
|
|
||||||
}
|
|
||||||
set_dirty(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::set_max(int value)
|
|
||||||
{
|
|
||||||
max_ = value;
|
|
||||||
if (value_ > max_) {
|
|
||||||
value_ = max_;
|
|
||||||
value_change_ = true;
|
|
||||||
}
|
|
||||||
set_dirty(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::set_value(int value)
|
|
||||||
{
|
|
||||||
if (value > max_)
|
|
||||||
value = max_;
|
|
||||||
if (value < min_)
|
|
||||||
value = min_;
|
|
||||||
|
|
||||||
if (increment_ > 1) {
|
|
||||||
int hi = boost::math::sign(value) * increment_ / 2;
|
|
||||||
value = ((value + hi) / increment_) * increment_;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == value_)
|
|
||||||
return;
|
|
||||||
|
|
||||||
value_ = value;
|
|
||||||
value_change_ = true;
|
|
||||||
set_dirty(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::set_increment(int increment)
|
|
||||||
{
|
|
||||||
increment_ = increment;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slider::value() const
|
|
||||||
{
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int slider::max_value() const
|
|
||||||
{
|
|
||||||
return max_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool slider::value_change()
|
|
||||||
{
|
|
||||||
if (value_change_) {
|
|
||||||
value_change_ = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect slider::slider_area() const
|
|
||||||
{
|
|
||||||
static const SDL_Rect default_value = {0,0,0,0};
|
|
||||||
SDL_Rect const &loc = location();
|
|
||||||
if (image_.null() || image_->w >= loc.w)
|
|
||||||
return default_value;
|
|
||||||
|
|
||||||
int xpos = loc.x + (value_ - min_) * (loc.w - image_->w) / (max_ - min_);
|
|
||||||
return sdl::create_rect(xpos, loc.y, image_->w, image_->h);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::draw_contents()
|
|
||||||
{
|
|
||||||
surface image;
|
|
||||||
|
|
||||||
switch (state_) {
|
|
||||||
case NORMAL:
|
|
||||||
image.assign(image_);
|
|
||||||
break;
|
|
||||||
case ACTIVE:
|
|
||||||
image.assign(activeImage_);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
image.assign(pressedImage_);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(image != nullptr);
|
|
||||||
|
|
||||||
color_t line_color = line_color_;
|
|
||||||
if (!enabled()) {
|
|
||||||
image.assign(disabledImage_);
|
|
||||||
line_color = font::DISABLED_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Rect const &loc = location();
|
|
||||||
if (image->w >= loc.w)
|
|
||||||
return;
|
|
||||||
|
|
||||||
surface& screen = video().getSurface();
|
|
||||||
|
|
||||||
SDL_Rect line_rect = sdl::create_rect(loc.x + image->w / 2
|
|
||||||
, loc.y + loc.h / 2
|
|
||||||
, loc.w - image->w
|
|
||||||
, 1);
|
|
||||||
|
|
||||||
sdl::fill_rect(screen, &line_rect, SDL_MapRGB(screen->format,
|
|
||||||
line_color.r, line_color.g, line_color.b));
|
|
||||||
|
|
||||||
SDL_Rect const &slider = slider_area();
|
|
||||||
video().blit_surface(slider.x, slider.y, image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::set_slider_position(int x)
|
|
||||||
{
|
|
||||||
SDL_Rect const &loc = location();
|
|
||||||
int tmp = x - loc.x - image_->w / 2;
|
|
||||||
if (tmp < 0)
|
|
||||||
tmp = 0;
|
|
||||||
if (tmp > loc.w - image_->w)
|
|
||||||
tmp = loc.w - image_->w;
|
|
||||||
|
|
||||||
set_value(tmp * (max_ - min_) / (loc.w - image_->w) + min_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::mouse_motion(const SDL_MouseMotionEvent& event)
|
|
||||||
{
|
|
||||||
if (state_ == NORMAL || state_ == ACTIVE) {
|
|
||||||
bool on = sdl::point_in_rect(event.x, event.y, location());
|
|
||||||
state_ = on ? ACTIVE : NORMAL;
|
|
||||||
} else if (state_ == CLICKED || state_ == DRAGGED) {
|
|
||||||
state_ = DRAGGED;
|
|
||||||
bool prev_change = value_change_;
|
|
||||||
value_change_ = false;
|
|
||||||
set_slider_position(event.x);
|
|
||||||
if(value_change_) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::slider_adjust);
|
|
||||||
} else {
|
|
||||||
value_change_ = prev_change;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::mouse_down(const SDL_MouseButtonEvent& event)
|
|
||||||
{
|
|
||||||
bool prev_change = value_change_;
|
|
||||||
|
|
||||||
if (!sdl::point_in_rect(event.x, event.y, location()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
if (event.button != SDL_BUTTON_LEFT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
state_ = CLICKED;
|
|
||||||
set_focus(true);
|
|
||||||
if (sdl::point_in_rect(event.x, event.y, slider_area())) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::button_press);
|
|
||||||
} else {
|
|
||||||
value_change_ = false;
|
|
||||||
set_slider_position(event.x);
|
|
||||||
if(value_change_) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::slider_adjust);
|
|
||||||
} else {
|
|
||||||
value_change_ = prev_change;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::mouse_wheel(const SDL_MouseWheelEvent& event) {
|
|
||||||
bool prev_change = value_change_;
|
|
||||||
int x, y;
|
|
||||||
SDL_GetMouseState(&x, &y);
|
|
||||||
|
|
||||||
if (!sdl::point_in_rect(x, y, location()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event.y > 0 || event.x > 0) {
|
|
||||||
value_change_ = false;
|
|
||||||
set_focus(true);
|
|
||||||
set_value(value_ + increment_);
|
|
||||||
if(value_change_) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::slider_adjust);
|
|
||||||
} else {
|
|
||||||
value_change_ = prev_change;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (event.y < 0 || event.x < 0) {
|
|
||||||
value_change_ = false;
|
|
||||||
set_focus(true);
|
|
||||||
set_value(value_ - increment_);
|
|
||||||
if(value_change_) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::slider_adjust);
|
|
||||||
} else {
|
|
||||||
value_change_ = prev_change;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool slider::requires_event_focus(const SDL_Event* event) const
|
|
||||||
{
|
|
||||||
if(!focus_ || !enabled() || hidden()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(event == nullptr) {
|
|
||||||
//when event is not specified, signal that focus may be desired later
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(event->type == SDL_KEYDOWN) {
|
|
||||||
SDL_Keycode key = event->key.keysym.sym;
|
|
||||||
switch(key) {
|
|
||||||
case SDLK_LEFT:
|
|
||||||
case SDLK_RIGHT:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//mouse events are processed regardless of focus
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void slider::handle_event(const SDL_Event& event)
|
|
||||||
{
|
|
||||||
gui::widget::handle_event(event);
|
|
||||||
|
|
||||||
if (!enabled() || hidden())
|
|
||||||
return;
|
|
||||||
|
|
||||||
STATE start_state = state_;
|
|
||||||
|
|
||||||
switch(event.type) {
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
if (!mouse_locked()) {
|
|
||||||
bool on = sdl::point_in_rect(event.button.x, event.button.y, slider_area());
|
|
||||||
state_ = on ? ACTIVE : NORMAL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
if (!mouse_locked())
|
|
||||||
mouse_down(event.button);
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
if (!mouse_locked())
|
|
||||||
mouse_motion(event.motion);
|
|
||||||
break;
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
if(focus(&event) && allow_key_events()) { //allow_key_events is used by zoom_sliders to disable left-right key press, which is buggy for them
|
|
||||||
const SDL_Keysym& key = reinterpret_cast<const SDL_KeyboardEvent&>(event).keysym;
|
|
||||||
const int c = key.sym;
|
|
||||||
if(c == SDLK_LEFT) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::slider_adjust);
|
|
||||||
set_value(value_ - increment_);
|
|
||||||
} else if(c == SDLK_RIGHT) {
|
|
||||||
sound::play_UI_sound(game_config::sounds::slider_adjust);
|
|
||||||
set_value(value_ + increment_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_MOUSEWHEEL:
|
|
||||||
if (!mouse_locked())
|
|
||||||
mouse_wheel(event.wheel);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (start_state != state_)
|
|
||||||
set_dirty(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
list_slider<T>::list_slider(CVideo &video) :
|
|
||||||
slider(video)
|
|
||||||
{
|
|
||||||
set_min(0);
|
|
||||||
set_increment(1);
|
|
||||||
slider::set_value(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
list_slider<T>::list_slider(CVideo &video, const std::vector<T> &items) :
|
|
||||||
slider(video),
|
|
||||||
items_(items)
|
|
||||||
{
|
|
||||||
set_min(0);
|
|
||||||
set_increment(1);
|
|
||||||
if(items.size() > 0)
|
|
||||||
{
|
|
||||||
set_max(items.size() - 1);
|
|
||||||
}
|
|
||||||
slider::set_value(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
const T& list_slider<T>::item_selected() const
|
|
||||||
{
|
|
||||||
return items_[value()];
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool list_slider<T>::select_item(const T& item)
|
|
||||||
{
|
|
||||||
for(unsigned i = 0, nb = items_.size(); i < nb; ++i)
|
|
||||||
{
|
|
||||||
if(item == items_[i])
|
|
||||||
{
|
|
||||||
slider::set_value(i);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void list_slider<T>::set_items(const std::vector<T> &items)
|
|
||||||
{
|
|
||||||
items_ = items;
|
|
||||||
if(items.size() > 0)
|
|
||||||
{
|
|
||||||
set_max(items.size() - 1);
|
|
||||||
}
|
|
||||||
slider::set_value(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force compilation of the following template instantiations
|
|
||||||
template class list_slider< double >;
|
|
||||||
template class list_slider< int >;
|
|
||||||
template class list_slider< std::string >;
|
|
||||||
|
|
||||||
/***
|
|
||||||
*
|
|
||||||
* Zoom Slider
|
|
||||||
*
|
|
||||||
***/
|
|
||||||
|
|
||||||
zoom_slider::zoom_slider(CVideo &video, const std::string& image, bool black)
|
|
||||||
: slider(video, image, black)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} //end namespace gui
|
|
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (C) 2003 - 2016 by David White <dave@whitevine.net>
|
|
||||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY.
|
|
||||||
|
|
||||||
See the COPYING file for more details.
|
|
||||||
*/
|
|
||||||
#ifndef SLIDER_HPP_INCLUDED
|
|
||||||
#define SLIDER_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
#include "color.hpp"
|
|
||||||
#include "widget.hpp"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class surface;
|
|
||||||
|
|
||||||
namespace gui {
|
|
||||||
|
|
||||||
class slider : public widget
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
slider(CVideo &video, const std::string& image = "buttons/sliders/slider", bool black = false);
|
|
||||||
|
|
||||||
void set_min(int value);
|
|
||||||
void set_max(int value);
|
|
||||||
void set_value(int value);
|
|
||||||
void set_increment(int increment);
|
|
||||||
|
|
||||||
int value() const;
|
|
||||||
int max_value() const;
|
|
||||||
int min_value() const { return min_; }
|
|
||||||
|
|
||||||
bool value_change();
|
|
||||||
|
|
||||||
virtual void enable(bool new_val=true);
|
|
||||||
|
|
||||||
//VC++ doesn't like a 'using scrollarea::set_location' directive here, so we declare
|
|
||||||
//an inline forwarding function instead
|
|
||||||
void set_location(int x, int y) { widget::set_location(x,y); }
|
|
||||||
virtual void set_location(SDL_Rect const &rect);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool requires_event_focus(const SDL_Event *event=nullptr) const;
|
|
||||||
virtual void handle_event(const SDL_Event& event);
|
|
||||||
virtual void draw_contents();
|
|
||||||
virtual bool allow_key_events() { return true; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void mouse_motion(const SDL_MouseMotionEvent& event);
|
|
||||||
void mouse_down(const SDL_MouseButtonEvent& event);
|
|
||||||
void mouse_wheel(const SDL_MouseWheelEvent& event);
|
|
||||||
void set_slider_position(int x);
|
|
||||||
SDL_Rect slider_area() const;
|
|
||||||
surface image_, pressedImage_, activeImage_, disabledImage_;
|
|
||||||
color_t line_color_;
|
|
||||||
|
|
||||||
int min_;
|
|
||||||
int max_;
|
|
||||||
int value_;
|
|
||||||
int increment_;
|
|
||||||
|
|
||||||
bool value_change_;
|
|
||||||
|
|
||||||
enum STATE { UNINIT, NORMAL, ACTIVE, CLICKED, DRAGGED };
|
|
||||||
STATE state_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class list_slider : public slider
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
list_slider(CVideo &video);
|
|
||||||
list_slider(CVideo &video, const std::vector<T> &items);
|
|
||||||
void set_items(const std::vector<T> &items);
|
|
||||||
bool select_item(const T& item); //use select_item() instead of set_value()
|
|
||||||
const T& item_selected() const; //use item_selected() instead of value()
|
|
||||||
private:
|
|
||||||
std::vector<T> items_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// This is a different style of slider, which doesn't implement key left/right responses
|
|
||||||
class zoom_slider : public slider
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
zoom_slider(CVideo &video, const std::string& image = "buttons/sliders/slider", bool black = false);
|
|
||||||
virtual bool allow_key_events() { return false; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Add table
Reference in a new issue