Removed a bunch of now-unused GUI1 widgets

This commit is contained in:
Charles Dang 2016-11-12 12:25:14 +11:00
parent 04a5111379
commit 7a1fec2153
13 changed files with 0 additions and 953 deletions

View file

@ -1150,19 +1150,11 @@
<Unit filename="../../src/whiteboard/visitor.hpp" />
<Unit filename="../../src/widgets/button.cpp" />
<Unit filename="../../src/widgets/button.hpp" />
<Unit filename="../../src/widgets/combo.cpp" />
<Unit filename="../../src/widgets/combo.hpp" />
<Unit filename="../../src/widgets/combo_drag.cpp" />
<Unit filename="../../src/widgets/combo_drag.hpp" />
<Unit filename="../../src/widgets/drop_target.cpp" />
<Unit filename="../../src/widgets/drop_target.hpp" />
<Unit filename="../../src/widgets/label.cpp" />
<Unit filename="../../src/widgets/label.hpp" />
<Unit filename="../../src/widgets/menu.cpp" />
<Unit filename="../../src/widgets/menu.hpp" />
<Unit filename="../../src/widgets/menu_style.cpp" />
<Unit filename="../../src/widgets/multimenu.cpp" />
<Unit filename="../../src/widgets/multimenu.hpp" />
<Unit filename="../../src/widgets/scrollarea.cpp" />
<Unit filename="../../src/widgets/scrollarea.hpp" />
<Unit filename="../../src/widgets/scrollbar.cpp" />

View file

@ -587,9 +587,6 @@ add_library(wesnoth-gui_widget_definition
# This library contains the widgets from gui1.
set(wesnoth-gui1_widgets_SRC
widgets/combo.cpp
widgets/combo_drag.cpp
widgets/drop_target.cpp
widgets/scrollpane.cpp
)
@ -1033,7 +1030,6 @@ set(libwesnoth-game_STAT_SRC
widgets/label.cpp
widgets/menu.cpp
widgets/menu_style.cpp
widgets/multimenu.cpp
widgets/scrollarea.cpp
widgets/scrollbar.cpp
widgets/slider.cpp
@ -1323,7 +1319,6 @@ if(ENABLE_TESTS)
set(test_SRC
tests/gui/iterator.cpp
tests/gui/fire_event.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_gui2.cpp
tests/gui/test_save_dialog.cpp
tests/gui/visitor.cpp

View file

@ -144,7 +144,6 @@ libwesnoth_sources = Split("""
widgets/label.cpp
widgets/menu_style.cpp
widgets/menu.cpp
widgets/multimenu.cpp
widgets/scrollarea.cpp
widgets/scrollbar.cpp
widgets/slider.cpp
@ -587,9 +586,6 @@ wesnoth_sources = Split("""
whiteboard/side_actions.cpp
whiteboard/suppose_dead.cpp
whiteboard/utility.cpp
widgets/combo_drag.cpp
widgets/combo.cpp
widgets/drop_target.cpp
widgets/scrollpane.cpp
""")
@ -709,7 +705,6 @@ libtest_utils = test_env.Library("test_utils", test_utils_sources)
test_sources = Split("""
tests/gui/fire_event.cpp
tests/gui/iterator.cpp
tests/gui/test_drop_target.cpp
tests/gui/test_gui2.cpp
tests/gui/test_save_dialog.cpp
tests/gui/visitor.cpp

View file

@ -85,7 +85,6 @@
#include "units/udisplay.hpp"
#include "wml_separators.hpp"
#include "whiteboard/manager.hpp"
#include "widgets/combo.hpp"
static lg::log_domain log_engine("engine");
#define ERR_NG LOG_STREAM(err, log_engine)

View file

@ -1,172 +0,0 @@
/*
Copyright (C) 2008 - 2016 by Pauli Nieminen <paniemin@cc.hut.fi>
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-test"
#include <boost/test/unit_test.hpp>
#include "utils/functional.hpp"
#include "sdl/rect.hpp"
#include "sdl/utils.hpp"
#include "widgets/drop_target.hpp"
BOOST_AUTO_TEST_SUITE( test_drop_target )
/**
* Specialized testing class so unit test
* can call protected member functions to
* simulate drop operation
**/
class test_drop_target : public gui::drop_target {
public:
test_drop_target(gui::drop_group_manager_ptr group, const SDL_Rect& loc) : gui::drop_target(group, loc)
{}
int handle_drop() {
return gui::drop_target::handle_drop();
}
static bool empty() {
return gui::drop_target::empty();
}
};
BOOST_AUTO_TEST_CASE( test_create_group )
{
gui::drop_group_manager group0;
gui::drop_group_manager* group1 = new gui::drop_group_manager();
BOOST_CHECK_EQUAL(group0.get_group_id(), 0);
BOOST_CHECK_EQUAL(group1->get_group_id(), 1);
delete group1;
gui::drop_group_manager_ptr group2(new gui::drop_group_manager());
BOOST_CHECK_EQUAL(group2->get_group_id(), 2);
}
typedef std::vector<gui::drop_target_ptr> target_store;
static void create_drop_targets(const SDL_Rect& loc, gui::drop_group_manager_ptr group, target_store& targets, int& id_counter)
{
gui::drop_target_ptr new_target(new test_drop_target(group, loc));
BOOST_CHECK_EQUAL(id_counter++, new_target->get_id());
// Test that drop gives -1 correctly for non overlapping
// targets
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(new_target.get())->handle_drop(), -1);
targets.push_back(new_target);
}
BOOST_AUTO_TEST_CASE( test_create_drop_targets )
{
gui::drop_group_manager_ptr group(new gui::drop_group_manager());
BOOST_CHECK(group->get_group_id() > 0);
typedef std::vector<SDL_Rect> location_store;
location_store locations;
// Create rectangles for drop targets
locations.push_back(sdl::create_rect(50,50,20,20));
locations.push_back(sdl::create_rect(50,100,20,20));
locations.push_back(sdl::create_rect(50,150,20,20));
locations.push_back(sdl::create_rect(50,200,20,20));
locations.push_back(sdl::create_rect(50,250,20,20));
locations.push_back(sdl::create_rect(50,300,20,20));
target_store targets;
int id_counter = 0;
std::for_each(locations.begin(), locations.end(),
std::bind(create_drop_targets,_1, group, std::ref(targets), std::ref(id_counter)));
BOOST_CHECK_EQUAL(targets.size(), locations.size());
// Modify 3rd rectangle to overlap with 4th
locations[2].y = 190;
// Check for correct drop results
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[2].get())->handle_drop(), 3);
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[3].get())->handle_drop(), 2);
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[1].get())->handle_drop(), -1);
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[4].get())->handle_drop(), -1);
}
BOOST_AUTO_TEST_CASE( check_memory_leaks )
{
BOOST_CHECK(test_drop_target::empty());
}
BOOST_AUTO_TEST_CASE( test_multiple_drop_groups )
{
gui::drop_group_manager_ptr group(new gui::drop_group_manager());
gui::drop_group_manager_ptr group2(new gui::drop_group_manager());
BOOST_CHECK(group->get_group_id() > 0);
BOOST_CHECK(group2->get_group_id() > 0);
typedef std::vector<SDL_Rect> location_store;
location_store locations;
location_store locations2;
// Create rectangles for drop targets
locations.push_back(sdl::create_rect(50,50,20,20));
locations.push_back(sdl::create_rect(50,100,20,20));
locations.push_back(sdl::create_rect(50,150,20,20));
locations.push_back(sdl::create_rect(50,200,20,20));
locations.push_back(sdl::create_rect(50,250,20,20));
locations.push_back(sdl::create_rect(50,300,20,20));
locations2.push_back(sdl::create_rect(50,50,20,20));
locations2.push_back(sdl::create_rect(100,50,20,20));
locations2.push_back(sdl::create_rect(150,50,20,20));
locations2.push_back(sdl::create_rect(200,50,20,20));
locations2.push_back(sdl::create_rect(250,50,20,20));
locations2.push_back(sdl::create_rect(300,50,20,20));
target_store targets;
target_store targets2;
int id_counter = 0;
std::for_each(locations.begin(), locations.end(),
std::bind(create_drop_targets,_1, group, std::ref(targets), std::ref(id_counter)));
id_counter = 0;
std::for_each(locations2.begin(), locations2.end(),
std::bind(create_drop_targets,_1, group2, std::ref(targets2), std::ref(id_counter)));
BOOST_CHECK_EQUAL(targets.size(), locations.size());
BOOST_CHECK_EQUAL(targets2.size(), locations2.size());
// Modify 3rd rectangle to overlap with 4th
locations[2].y = 190;
// Check for correct drop results
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[2].get())->handle_drop(), 3);
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[3].get())->handle_drop(), 2);
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[1].get())->handle_drop(), -1);
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets[4].get())->handle_drop(), -1);
locations2[2].y = 180;
locations2[2].x = 50;
BOOST_CHECK_EQUAL(static_cast<test_drop_target*>(targets2[2].get())->handle_drop(), -1);
}
/* vim: set ts=4 sw=4: */
BOOST_AUTO_TEST_SUITE_END()

View file

@ -1,89 +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 "global.hpp"
#include "construct_dialog.hpp"
#include "widgets/combo.hpp"
class CVideo;
namespace gui {
const std::string combo::empty_combo_label = "";
const int combo::font_size = font::SIZE_SMALL;
const int combo::horizontal_padding = 10;
const int combo::vertical_padding = 10;
combo::combo(CVideo& video, const std::vector<std::string>& items)
: button(video, items.empty() ? empty_combo_label : items[0]),
items_(items), selected_(0), oldSelected_(0), video_(&video)
{
}
int combo::selected() const
{
return selected_;
}
bool combo::changed()
{
if (oldSelected_ != selected_) {
oldSelected_ = selected_;
return true;
} else
return false;
}
void combo::set_items(const std::vector<std::string>& items)
{
items_ = items;
selected_ = -1;
}
void combo::set_selected_internal(int val)
{
const size_t index = size_t(val);
if (val == selected_ || index >= items_.size())
return;
set_label(items_[index]);
oldSelected_ = selected_;
selected_ = val;
}
void combo::set_selected(int val)
{
set_selected_internal(val);
oldSelected_ = selected_;
}
void combo::make_drop_down_menu()
{
SDL_Rect const &loc = location();
set_selected_internal(gui::show_dialog(*video_, nullptr, "", "", gui::MESSAGE, &items_,
nullptr, "", nullptr, -1, nullptr, loc.x, loc.y + loc.h,
&gui::dialog::hotkeys_style));
}
void combo::process_event()
{
if (!pressed())
return;
make_drop_down_menu();
}
}

View file

@ -1,50 +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 COMBO_H_INCLUDED
#define COMBO_H_INCLUDED
#include "button.hpp"
class display;
namespace gui {
class combo : public button
{
public:
combo(CVideo& v, const std::vector<std::string>& items);
void set_selected(int val);
void set_items(const std::vector<std::string>& items);
int selected() const;
bool changed();
protected:
virtual void process_event();
void make_drop_down_menu();
private:
void set_selected_internal(int val);
std::vector<std::string> items_;
int selected_, oldSelected_;
CVideo* video_;
static const std::string empty_combo_label;
static const int font_size;
static const int horizontal_padding;
static const int vertical_padding;
}; //end class combo
}
#endif

View file

@ -1,170 +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 "global.hpp"
#include "widgets/combo_drag.hpp"
namespace gui {
const float combo_drag::MIN_DRAG_DISTANCE = 10.0;
const float combo_drag::RETURN_SPEED = 25.0;
combo_drag::combo_drag(CVideo& v
, const std::vector<std::string>& items
, const drop_group_manager_ptr group)
: combo(v, items)
, drop_target(group, location())
, drag_target_(-1)
, old_drag_target_(-1)
, old_location_()
, mouse_x_(-1)
, mouse_y_(-1)
, drag_(NONE)
{
}
int combo_drag::get_drop_target()
{
old_drag_target_ = drag_target_;
drag_target_ = -1;
return old_drag_target_;
}
void combo_drag::handle_move(const SDL_MouseMotionEvent& event)
{
if (drag_ == PRESSED)
{
aquire_mouse_lock();
old_location_ = location();
drag_ = PRESSED_MOVE;
}
const int diff_x = event.x - mouse_x_;
const int diff_y = event.y - mouse_y_;
if (drag_ == PRESSED_MOVE
&& std::sqrt(static_cast<float>(diff_x*diff_x + diff_y*diff_y)) > MIN_DRAG_DISTANCE)
{
return;
}
drag_ = MOVED;
SDL_Rect loc = old_location_;
loc.x += diff_x;
loc.y += diff_y;
// Don't allow moving outside clip are
if (clip_rect())
{
const SDL_Rect *clip = clip_rect();
if (loc.x < clip->x)
loc.x = clip->x;
if (loc.x + loc.w > clip->x + clip->w)
loc.x = clip->x + clip->w - loc.w;
if (loc.y < clip->y)
loc.y = clip->y;
if (loc.y + loc.h > clip->y + clip->h)
loc.y = clip->y + clip->h - loc.h;
}
set_location(loc);
}
void combo_drag::process(events::pump_info& /*info*/)
{
if (drag_ == RETURN)
{
SDL_Rect loc = location();
int x_diff = loc.x - old_location_.x;
int y_diff = loc.y - old_location_.y;
const float length = std::sqrt(static_cast<float>(x_diff*x_diff + y_diff*y_diff));
if (length > RETURN_SPEED)
{
loc.x -= static_cast<Sint16>(x_diff*(RETURN_SPEED/length));
loc.y -= static_cast<Sint16>(y_diff*(RETURN_SPEED/length));
set_location(loc);
}
else
{
drag_ = NONE;
set_location(old_location_);
}
}
}
void combo_drag::handle_drop()
{
drag_target_ = drop_target::handle_drop();
}
void combo_drag::mouse_motion(const SDL_MouseMotionEvent& event)
{
if (drag_ == PRESSED
|| drag_ == MOVED
|| drag_ == PRESSED_MOVE)
{
handle_move(event);
} else {
button::mouse_motion(event);
}
}
void combo_drag::mouse_up(const SDL_MouseButtonEvent& event)
{
if ((drag_ == PRESSED || drag_ == PRESSED_MOVE || drag_ == MOVED) && event.button == SDL_BUTTON_LEFT)
{
if (drag_ == PRESSED
|| drag_ == PRESSED_MOVE)
{
free_mouse_lock();
drag_ = DROP_DOWN;
}
else if (drag_ == MOVED)
{
free_mouse_lock();
handle_drop();
drag_ = RETURN;
hide();
}
}
button::mouse_up(event);
}
void combo_drag::mouse_down(const SDL_MouseButtonEvent& event)
{
if (hit(event.x, event.y) && event.button == SDL_BUTTON_LEFT)
{
drag_ = PRESSED;
mouse_x_ = event.x;
mouse_y_ = event.y;
}
button::mouse_down(event);
}
void combo_drag::process_event()
{
if (drag_ == DROP_DOWN)
{
drag_ = NONE;
make_drop_down_menu();
}
}
}

View file

@ -1,68 +0,0 @@
/*
Copyright (C) 2008 - 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 COMBO_DRAG_H_INCLUDED
#define COMBO_DRAG_H_INCLUDED
#include "widgets/combo.hpp"
#include "widgets/drop_target.hpp"
class CVideo;
namespace gui {
class combo_drag;
typedef std::shared_ptr<combo_drag> combo_drag_ptr;
class combo_drag : public combo, public drop_target, public events::pump_monitor
{
public:
combo_drag(CVideo& v, const std::vector<std::string>& items, const drop_group_manager_ptr group);
/**
* used to query if this object was dropped to a target
* @return: -1 if not dropped and other the id of target object
**/
int get_drop_target();
/**
* Implements return after drop
**/
virtual void process(events::pump_info& /*info*/);
protected:
virtual void process_event();
virtual void mouse_motion(const SDL_MouseMotionEvent& event);
virtual void mouse_down(const SDL_MouseButtonEvent& event);
virtual void mouse_up(const SDL_MouseButtonEvent& event);
private:
void handle_move(const SDL_MouseMotionEvent& event);
void handle_drop();
int drag_target_, old_drag_target_;
SDL_Rect old_location_;
int mouse_x_, mouse_y_;
enum drag_state {
NONE,
PRESSED,
PRESSED_MOVE,
MOVED,
RETURN,
DROP_DOWN
};
drag_state drag_;
static const float MIN_DRAG_DISTANCE;
static const float RETURN_SPEED;
}; //end class combo
}
#endif

View file

@ -1,117 +0,0 @@
/*
Copyright (C) 2008 - 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/drop_target.hpp"
#include "utils/functional.hpp"
#include <algorithm>
namespace gui {
drop_target::drop_groups drop_target::groups_;
drop_target::target_id drop_target::next_id_;
drop_target_group drop_target::next_group_ = 0;
int drop_target::next_free_id(const drop_target_group& group) const
{
target_id::iterator group_id = next_id_.insert(std::make_pair(group, 0)).first;
return group_id->second++;
}
drop_target::drop_target(const drop_group_manager_ptr group, const SDL_Rect& loc) : loc_(loc), id_(next_free_id(group->get_group_id())), group_(group)
{
groups_.insert(std::make_pair(group_->get_group_id(), this));
}
drop_target::drop_groups::iterator drop_target::find_this() const
{
return std::find_if(groups_.lower_bound(group_->get_group_id()),
groups_.upper_bound(group_->get_group_id()),
[this](const drop_groups::value_type& val) { return val.second->id_ == id_; }
);
}
drop_target::~drop_target()
{
groups_.erase(find_this());
}
int drop_target::get_id() const
{
return id_;
}
int drop_target::handle_drop()
{
drop_groups::iterator end = groups_.upper_bound(group_->get_group_id());
drop_target::drop_groups::iterator itor
= std::find_if(groups_.lower_bound(group_->get_group_id()),
end,
[this](const drop_groups::value_type& val) { return val.second->hit_rect(loc_, id_) ; }
);
if (itor == end)
return -1;
return itor->second->get_id();
}
void drop_target::delete_group(const drop_target_group id)
{
next_id_.erase(id);
groups_.erase(id);
}
drop_target_group drop_target::create_group()
{
return next_group_++;
}
bool drop_target::hit_rect(const SDL_Rect& hit_loc, const int not_id) const
{
if (id_ == not_id)
return false;
int this_right = loc_.x + loc_.w;
int this_lower = loc_.y + loc_.h;
int hit_right = hit_loc.x + hit_loc.w;
int hit_lower = hit_loc.y + hit_loc.h;
// Is it inside in x direction?
return (this_right > hit_loc.x
&& loc_.x < hit_right
// Is it inside in y direction?
&& this_lower > hit_loc.y
&& loc_.y < hit_lower);
}
drop_group_manager::drop_group_manager() : group_id_(drop_target::create_group())
{
}
drop_group_manager::~drop_group_manager()
{
drop_target::delete_group(group_id_);
}
drop_target_group drop_group_manager::get_group_id() const
{
return group_id_;
}
}

View file

@ -1,105 +0,0 @@
/*
Copyright (C) 2008 - 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 DROP_TARGET_H_INCLUDED
#define DROP_TARGET_H_INCLUDED
#include <SDL.h>
#include <map>
#include <memory>
#include <boost/noncopyable.hpp>
namespace gui {
class drop_target;
typedef std::shared_ptr<drop_target> drop_target_ptr;
typedef int drop_target_group;
class drop_group_manager;
typedef std::shared_ptr<drop_group_manager> drop_group_manager_ptr;
/**
* Handles droping for drag able ui items.
* Widget class just has to inherit from drop_target,
* call constructor and handle_drop.
**/
class drop_target : public boost::noncopyable {
typedef std::multimap<drop_target_group, drop_target*> drop_groups;
typedef std::map<drop_target_group, int> target_id;
static drop_groups groups_;
static target_id next_id_;
static drop_target_group next_group_;
int next_free_id(const drop_target_group& group) const;
bool hit_rect(const SDL_Rect& hit_loc, const int not_id) const;
drop_groups::iterator find_this() const;
const SDL_Rect& loc_;
const int id_;
drop_group_manager_ptr group_;
static drop_target_group create_group();
static void delete_group(const drop_target_group id);
protected:
/**
* Used to check if static storages are empty.
* Only for testing.
**/
static bool empty() { return groups_.empty() && next_id_.empty(); }
/**
* Called by widget object when droping happens.
*
* Droping over multiple widget objects in same group
* is undefined.
*
* @return: id which widget was hit when droping
**/
int handle_drop();
public:
/**
* Registers drop target and saves reference to location.
**/
drop_target(const drop_group_manager_ptr group, const SDL_Rect& loc);
~drop_target();
int get_id() const;
/**
* Checks if id matches id for this object.
* Used by for_each/boost:bind
**/
bool is_this_id(const int id) const;
friend class drop_group_manager;
};
/**
* Used to create and destroy drop groups.
* To create drop_target widgets one has to have
* drop_group_manager stored in drop_group_manager_ptr.
**/
class drop_group_manager : public boost::noncopyable {
const drop_target_group group_id_;
public:
drop_group_manager();
~drop_group_manager();
drop_target_group get_group_id() const;
};
}
#endif

View file

@ -1,80 +0,0 @@
/*
Copyright (C) 2015 - 2016 by Boldizsár Lipka <lipkab@zoho.com>
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.
*/
#include "widgets/multimenu.hpp"
#include "image.hpp"
#include "video.hpp"
namespace gui {
multimenu::multimenu(CVideo &video, const std::vector<std::string> &items, bool click_selects, int max_height,
int max_width, const menu::sorter *sorter_obj, menu::style *menu_style, const bool auto_join) :
menu(video, items, click_selects, max_height, max_width, sorter_obj, menu_style, auto_join),
active_items_(items.size(), false) {}
void multimenu::draw_row(const size_t row_index, const SDL_Rect &rect, menu::ROW_TYPE type) {
surface img = image::get_image(active_items_[row_index]
? "buttons/checkbox-pressed.png"
: "buttons/checkbox.png");
blit_surface(img, nullptr, video().getSurface(), &rect);
SDL_Rect newrect = {
Sint16 (rect.x + img->w + 2),
rect.y,
Uint16 (rect.w - img->w - 2),
rect.h
};
menu::draw_row(row_index, newrect, type);
}
void multimenu::handle_event(const SDL_Event &event) {
if (event.type == SDL_MOUSEBUTTONDOWN) {
int hit_box = hit_checkbox(event.button.x, event.button.y);
if (hit_box != -1) {
active_items_[hit_box] = !active_items_[hit_box];
invalidate_row_pos(hit_box);
last_changed_ = hit_box;
return;
}
}
menu::handle_event(event);
}
int multimenu::hit_checkbox(int x, int y) const {
int cb_width = image::get_image("buttons/checkbox-pressed.png")->w;
return x > inner_location().x + cb_width ? -1 : hit(x, y);
}
void multimenu::erase_item(size_t index) {
active_items_.erase(active_items_.begin() + index);
menu::erase_item(index);
last_changed_ = -1;
}
void multimenu::set_items(const std::vector<std::string> &items, bool strip_spaces, bool keep_viewport) {
active_items_.resize(items.size());
std::fill(active_items_.begin(), active_items_.end(), false);
last_changed_ = -1;
menu::set_items(items, strip_spaces, keep_viewport);
}
void multimenu::set_active(size_t index, bool active) {
active_items_[index] = active;
invalidate_row_pos(index);
}
int multimenu::last_changed() {
int result = last_changed_;
last_changed_ = -1;
return result;
}
}

View file

@ -1,83 +0,0 @@
/*
Copyright (C) 2015 - 2016 by Boldizsár Lipka <lipkab@zoho.com>
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 WIDGETS_MULTIMENU_HPP_INCLUDED
#define WIDGETS_MULTIMENU_HPP_INCLUDED
#include "menu.hpp"
namespace gui {
/**
* A widget that additionally to the normal menu contents also displays a
* checkbox in each row. An item is considered 'active' if its checkbox is checked,
* 'inactive' otherwise.
*/
class multimenu : public menu {
public:
multimenu(CVideo& video, const std::vector<std::string>& items,
bool click_selects=false, int max_height=-1, int max_width=-1,
const sorter* sorter_obj=nullptr, style *menu_style=nullptr, const bool auto_join=true);
void set_active(size_t index, bool active=true);
/**
* Tells if an item is activated.
*
* @param index the item's index
* @return true if the item is active, false if not
*/
bool is_active(size_t index) const { return active_items_[index]; }
/**
* Tell each items status
*
* @return a vector of bools. The n-th item is active if the vector's n-th item is true
*/
const std::vector<bool> &active_items() const { return active_items_; }
virtual void erase_item(size_t index);
virtual void set_items(const std::vector<std::string>& items, bool strip_spaces=true,
bool keep_viewport=false);
/**
* Returns the item last activated/deactivated. Items changed via set_active
* don't count, Invoking this function will set the last changed index to -1.
*
* @return the item's index, or -1 if no item was changed since the last
* invokation
*/
int last_changed();
protected:
virtual void draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
virtual void handle_event(const SDL_Event& event);
/**
* Determine which checkbox was hit by a mouse click.
*
* @param x the x coordinate of the click
* @param y the y coordinate of the click
* @return the row whose checkbox was clicked on, or -1 if the click didn't hit a checkbox
*/
int hit_checkbox(int x, int y) const;
private:
std::vector<bool> active_items_;
int last_changed_;
};
}
#endif