Add a gui2 progress bar widget.

This commit is contained in:
Mark de Wever 2010-04-01 17:50:43 +00:00
parent f18985f2a4
commit 177a425baf
11 changed files with 336 additions and 0 deletions

View file

@ -13,6 +13,7 @@ Version 1.9.0-svn:
* Enabled alignment in labels
* Avoid resizing when next or previous button is pressed in the
--new-widgets title screen
* Added gui2 progress bar widget
* WML Engine:
* Deprecated [set_variable]'s random key, use rand instead
* Renamed [unit][status] healable to unhealable so it can default to 'no'

View file

@ -18,6 +18,7 @@ src/gui/auxiliary/widget_definition/listbox.cpp
src/gui/auxiliary/widget_definition/minimap.cpp
src/gui/auxiliary/widget_definition/multi_page.cpp
src/gui/auxiliary/widget_definition/panel.cpp
src/gui/auxiliary/widget_definition/progress_bar.cpp
src/gui/auxiliary/widget_definition/repeating_button.cpp
src/gui/auxiliary/widget_definition/scrollbar_panel.cpp
src/gui/auxiliary/widget_definition/scroll_label.cpp
@ -43,6 +44,7 @@ src/gui/auxiliary/window_builder/listbox.cpp
src/gui/auxiliary/window_builder/minimap.cpp
src/gui/auxiliary/window_builder/multi_page.cpp
src/gui/auxiliary/window_builder/panel.cpp
src/gui/auxiliary/window_builder/progress_bar.cpp
src/gui/auxiliary/window_builder/password_box.cpp
src/gui/auxiliary/window_builder/repeating_button.cpp
src/gui/auxiliary/window_builder/scrollbar_panel.cpp
@ -89,6 +91,7 @@ src/gui/widgets/minimap.cpp
src/gui/widgets/multi_page.cpp
src/gui/widgets/panel.cpp
src/gui/widgets/password_box.cpp
src/gui/widgets/progress_bar.cpp
src/gui/widgets/repeating_button.cpp
src/gui/widgets/scrollbar_container.cpp
src/gui/widgets/scrollbar.cpp

View file

@ -290,6 +290,7 @@ set(wesnoth-main_SRC
gui/auxiliary/widget_definition/minimap.cpp
gui/auxiliary/widget_definition/multi_page.cpp
gui/auxiliary/widget_definition/panel.cpp
gui/auxiliary/widget_definition/progress_bar.cpp
gui/auxiliary/widget_definition/repeating_button.cpp
gui/auxiliary/widget_definition/scroll_label.cpp
gui/auxiliary/widget_definition/scrollbar_panel.cpp
@ -323,6 +324,7 @@ set(wesnoth-main_SRC
gui/auxiliary/window_builder/toggle_button.cpp
gui/auxiliary/window_builder/vertical_scrollbar.cpp
gui/auxiliary/window_builder/panel.cpp
gui/auxiliary/window_builder/progress_bar.cpp
gui/auxiliary/window_builder/password_box.cpp
gui/auxiliary/window_builder/toggle_panel.cpp
gui/auxiliary/window_builder/tree_view.cpp
@ -364,6 +366,7 @@ set(wesnoth-main_SRC
gui/widgets/minimap.cpp
gui/widgets/multi_page.cpp
gui/widgets/panel.cpp
gui/widgets/progress_bar.cpp
gui/widgets/password_box.cpp
gui/widgets/repeating_button.cpp
gui/widgets/settings.cpp

View file

@ -116,6 +116,7 @@ wesnoth_source = \
gui/auxiliary/widget_definition/minimap.cpp \
gui/auxiliary/widget_definition/multi_page.cpp \
gui/auxiliary/widget_definition/panel.cpp \
gui/auxiliary/widget_definition/progress_bar.cpp \
gui/auxiliary/widget_definition/repeating_button.cpp \
gui/auxiliary/widget_definition/scroll_label.cpp \
gui/auxiliary/widget_definition/scrollbar_panel.cpp \
@ -149,6 +150,7 @@ wesnoth_source = \
gui/auxiliary/window_builder/toggle_button.cpp \
gui/auxiliary/window_builder/vertical_scrollbar.cpp \
gui/auxiliary/window_builder/panel.cpp \
gui/auxiliary/window_builder/progress_bar.cpp \
gui/auxiliary/window_builder/password_box.cpp \
gui/auxiliary/window_builder/toggle_panel.cpp \
gui/auxiliary/window_builder/tree_view.cpp \
@ -190,6 +192,7 @@ wesnoth_source = \
gui/widgets/minimap.cpp \
gui/widgets/multi_page.cpp \
gui/widgets/panel.cpp \
gui/widgets/progress_bar.cpp \
gui/widgets/password_box.cpp \
gui/widgets/repeating_button.cpp \
gui/widgets/settings.cpp \

View file

@ -274,6 +274,7 @@ wesnoth_sources = Split("""
gui/auxiliary/widget_definition/minimap.cpp
gui/auxiliary/widget_definition/multi_page.cpp
gui/auxiliary/widget_definition/panel.cpp
gui/auxiliary/widget_definition/progress_bar.cpp
gui/auxiliary/widget_definition/repeating_button.cpp
gui/auxiliary/widget_definition/scroll_label.cpp
gui/auxiliary/widget_definition/vertical_scrollbar.cpp
@ -307,6 +308,7 @@ wesnoth_sources = Split("""
gui/auxiliary/window_builder/toggle_button.cpp
gui/auxiliary/window_builder/vertical_scrollbar.cpp
gui/auxiliary/window_builder/panel.cpp
gui/auxiliary/window_builder/progress_bar.cpp
gui/auxiliary/window_builder/password_box.cpp
gui/auxiliary/window_builder/toggle_panel.cpp
gui/auxiliary/window_builder/tree_view.cpp
@ -348,6 +350,7 @@ wesnoth_sources = Split("""
gui/widgets/minimap.cpp
gui/widgets/multi_page.cpp
gui/widgets/panel.cpp
gui/widgets/progress_bar.cpp
gui/widgets/password_box.cpp
gui/widgets/repeating_button.cpp
gui/widgets/settings.cpp

View file

@ -0,0 +1,55 @@
/* $Id$ */
/*
Copyright (C) 2010 by Mark de Wever <koraq@xs4all.nl>
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 version 2
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 "gui/auxiliary/widget_definition/progress_bar.hpp"
#include "gui/auxiliary/log.hpp"
namespace gui2 {
tprogress_bar_definition::tprogress_bar_definition(const config& cfg) :
tcontrol_definition(cfg)
{
DBG_GUI_P << "Parsing progress bar " << id << '\n';
load_resolutions<tresolution>(cfg);
}
tprogress_bar_definition::tresolution::tresolution(const config& cfg) :
tresolution_definition_(cfg)
{
/*WIKI
* @page = GUIWidgetDefinitionWML
* @order = 1_progress_bar
*
* == Progress bar ==
*
* @macro = progress_bar_description
*
* The definition of a progress bar. This object shows the progress of a certain
* action, or the value state of a certain item.
*
* The following states exist:
* * state_enabled, the progress bar is enabled.
*
*/
// Note the order should be the same as the enum tstate is progress_bar.hpp.
state.push_back(tstate_definition(cfg.child("state_enabled")));
}
} // namespace gui2

View file

@ -0,0 +1,37 @@
/* $Id$ */
/*
Copyright (C) 2010 by Mark de Wever <koraq@xs4all.nl>
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 version 2
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 GUI_AUXILIARY_WIDGET_DEFINITION_PROGRESS_BAR_HPP_INCLUDED
#define GUI_AUXILIARY_WIDGET_DEFINITION_PROGRESS_BAR_HPP_INCLUDED
#include "gui/auxiliary/widget_definition.hpp"
namespace gui2 {
struct tprogress_bar_definition
: public tcontrol_definition
{
explicit tprogress_bar_definition(const config& cfg);
struct tresolution
: public tresolution_definition_
{
explicit tresolution(const config& cfg);
};
};
} // namespace gui2
#endif

View file

@ -0,0 +1,66 @@
/* $Id$ */
/*
Copyright (C) 2010 by Mark de Wever <koraq@xs4all.nl>
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 version 2
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 "gui/auxiliary/window_builder/progress_bar.hpp"
#include "config.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/widgets/progress_bar.hpp"
namespace gui2 {
namespace implementation {
tbuilder_progress_bar::tbuilder_progress_bar(const config& cfg)
: tbuilder_control(cfg)
{
}
twidget* tbuilder_progress_bar::build() const
{
tprogress_bar* widget = new tprogress_bar();
init_control(widget);
DBG_GUI_G << "Window builder: placed progress bar '"
<< id << "' with defintion '"
<< definition << "'.\n";
return widget;
}
} // namespace implementation
} // namespace gui2
/*WIKI_MACRO
* @start_macro = progress_bar_description
*
* A progress bar shows the progress of a certain object.
* @end_macro
*/
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 2_progress_bar
*
* == Image ==
*
* @macro = progress_bar_description
*
* An progress bar has no extra fields.
*/

View file

@ -0,0 +1,39 @@
/* $Id$ */
/*
Copyright (C) 2010 by Mark de Wever <koraq@xs4all.nl>
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 version 2
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 GUI_AUXILIARY_WINDOW_BUILDER_PROGRESS_BAR_HPP_INCLUDED
#define GUI_AUXILIARY_WINDOW_BUILDER_PROGRESS_BAR_HPP_INCLUDED
#include "gui/auxiliary/window_builder/control.hpp"
namespace gui2 {
namespace implementation {
struct tbuilder_progress_bar
: public tbuilder_control
{
tbuilder_progress_bar(const config& cfg);
twidget* build () const;
};
} // namespace implementation
} // namespace gui2
#endif

View file

@ -0,0 +1,54 @@
/* $Id$ */
/*
Copyright (C) 2010 by Mark de Wever <koraq@xs4all.nl>
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 version 2
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 "gui/widgets/progress_bar.hpp"
#include "gui/auxiliary/widget_definition/progress_bar.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/widgets/settings.hpp"
#include <boost/bind.hpp>
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
namespace gui2 {
REGISTER_WIDGET(progress_bar)
void tprogress_bar::set_precentage(const unsigned percentage)
{
assert(percentage <= 100);
if(percentage_ != percentage) {
percentage_ = percentage;
foreach(tcanvas& c, canvas()) {
c.set_variable("percentage", variant(percentage));
}
set_dirty();
}
}
const std::string& tprogress_bar::get_control_type() const
{
static const std::string type = "progress_bar";
return type;
}
} // namespace gui2

View file

@ -0,0 +1,72 @@
/* $Id$ */
/*
Copyright (C) 2010 by Mark de Wever <koraq@xs4all.nl>
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 version 2
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 GUI_WIDGETS_PROGRESS_BAR_HPP_INCLUDED
#define GUI_WIDGETS_PROGRESS_BAR_HPP_INCLUDED
#include "gui/widgets/control.hpp"
namespace gui2 {
class tprogress_bar
: public tcontrol
{
public:
tprogress_bar()
: tcontrol(COUNT)
, percentage_(0)
{
}
/***** ***** ***** ***** Inherited ***** ***** ***** *****/
/** Inherited from tcontrol. */
void set_active(const bool /*active*/) {}
/** Inherited from tcontrol. */
bool get_active() const { return true; }
/** Inherited from tcontrol. */
unsigned get_state() const { return ENABLED; }
/** Inherited from tcontrol. */
bool disable_click_dismiss() const { return false; }
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_precentage(const unsigned percentage);
unsigned get_percentage() const { return percentage_; }
private:
/**
* Possible states of the widget.
*
* Note the order of the states must be the same as defined in settings.hpp.
*/
enum tstate { ENABLED, COUNT };
/** The percentage done. */
unsigned percentage_;
/** Inherited from tcontrol. */
const std::string& get_control_type() const;
};
} // namespace gui2
#endif