Added a horizontal scrollbar widget.

Also added 'new' art, since the current toolkit has no art for it. The art is
of the copy-paste-rotate kind. (The scrollbar is not used yet.)
This commit is contained in:
Mark de Wever 2008-12-04 19:00:44 +00:00
parent 2de9990f1d
commit 2f700cd925
39 changed files with 429 additions and 4 deletions

View file

@ -36,6 +36,7 @@ Version 1.5.6+svn:
* Added a border and blurring to story screens' text blocks.
* Improved wrapping in the new widgets.
* Improved easy close handling.
* Added a horizontal scrollbar widget.
* WML engine:
* Added the 'round' key to [set_variable].
* Miscellaneous and bug fixes:

View file

@ -100,5 +100,17 @@
"buttons/uparrow-button"
}
{_GUI_DEFINITION
"left_arrow"
"Left arrow button for a scrollbar."
"buttons/left_arrow-button"
}
{_GUI_DEFINITION
"right_arrow"
"Right arrow button for a scrollbar."
"buttons/right_arrow-button"
}
#undef _GUI_DEFINITION
#undef _GUI_RESOLUTION

View file

@ -0,0 +1,118 @@
#textdomain wesnoth-lib
###
### Definition of a horizontal scrollbar.
###
#define _GUI_STATE GROOVE_LEFT GROOVE_RIGHT POSITIONER_LEFT POSITIONER_RIGHT IMAGE_SUFFIX
full_redraw = "true"
[draw]
#
# Groove
#
[image]
# 4 pixels wide
x = 0
y = 0
name = "buttons/scrollgroove-left.png"
[/image]
[image]
x = {GROOVE_LEFT}
y = 0
w = "(width - {GROOVE_LEFT} - {GROOVE_RIGHT})"
h = 0
stretch = true
name = "buttons/scrollgroove-horizontal.png"
[/image]
[image]
# 5 pixels wide
x = "(width - {GROOVE_RIGHT})"
y = 0
name = "buttons/scrollgroove-right.png"
[/image]
#
# Positioner
#
[image]
# 5 pixels wide
x = "(positioner_offset)"
y = 0
name = "buttons/scrollleft{IMAGE_SUFFIX}"
[/image]
[image]
x = "(positioner_offset + {POSITIONER_LEFT})"
y = 0
w = "(positioner_length - {POSITIONER_LEFT} - {POSITIONER_RIGHT})"
stretch = true
name = "buttons/scrollhorizontal{IMAGE_SUFFIX}"
[/image]
[image]
# 5 pixels wide
x = "(positioner_offset + positioner_length - {POSITIONER_RIGHT})"
y = 0
name = "buttons/scrollright{IMAGE_SUFFIX}"
[/image]
[/draw]
#enddef
#define _GUI_RESOLUTION RESOLUTION WIDTH HEIGHT POSITIONER_LENGHT GROOVE_LEFT GROOVE_RIGHT POSITIONER_LEFT POSITIONER_RIGHT
[resolution]
{RESOLUTION}
min_width = {WIDTH}
min_height = {HEIGHT}
default_width = {WIDTH}
default_height = {HEIGHT}
max_width = 0
max_height = {HEIGHT}
minimum_positioner_length = {POSITIONER_LENGHT}
top_offset = 0
bottom_offset = 0
[state_enabled]
{_GUI_STATE ({GROOVE_LEFT}) ({GROOVE_RIGHT}) ({POSITIONER_LEFT}) ({POSITIONER_RIGHT}) ".png"}
[/state_enabled]
[state_disabled]
{_GUI_STATE ({GROOVE_LEFT}) ({GROOVE_RIGHT}) ({POSITIONER_LEFT}) ({POSITIONER_RIGHT}) "-disabled.png"}
[/state_disabled]
[state_pressed]
{_GUI_STATE ({GROOVE_LEFT}) ({GROOVE_RIGHT}) ({POSITIONER_LEFT}) ({POSITIONER_RIGHT}) "-pressed.png"}
[/state_pressed]
[state_focussed]
{_GUI_STATE ({GROOVE_LEFT}) ({GROOVE_RIGHT}) ({POSITIONER_LEFT}) ({POSITIONER_RIGHT}) "-active.png"}
[/state_focussed]
[/resolution]
#enddef
[horizontal_scrollbar_definition]
id = "default"
description = "a horizontal scrollbar"
# Note a scrollbar is normally sized by the item that "masters" it
# that's why the default height is rather low.
# Tiny gui sizes haven't been tested yet so might need some tuning.
{_GUI_RESOLUTION ({GUI_TINY__RESOLUTION}) 20 12 11 2 2 2 2}
{_GUI_RESOLUTION () 20 25 11 4 5 5 5}
[/horizontal_scrollbar_definition]
#undef _GUI_STATE
#undef _GUI_RESOLUTION

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 826 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

View file

@ -21,6 +21,7 @@ src/gui/widgets/debug.cpp
src/gui/widgets/event_handler.cpp
src/gui/widgets/grid.cpp
src/gui/widgets/helper.cpp
src/gui/widgets/horizontal_scrollbar.cpp
src/gui/widgets/image.cpp
src/gui/widgets/label.cpp
src/gui/widgets/listbox.cpp

View file

@ -238,6 +238,7 @@ SET(wesnoth-main_SRC
gui/widgets/event_handler.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp
gui/widgets/horizontal_scrollbar.cpp
gui/widgets/image.cpp
gui/widgets/label.cpp
gui/widgets/listbox.cpp

View file

@ -85,6 +85,7 @@ wesnoth_source = \
gui/widgets/event_handler.cpp \
gui/widgets/grid.cpp \
gui/widgets/helper.cpp \
gui/widgets/horizontal_scrollbar.cpp \
gui/widgets/image.cpp \
gui/widgets/label.cpp \
gui/widgets/listbox.cpp \

View file

@ -227,6 +227,7 @@ wesnoth_sources = Split("""
gui/widgets/event_handler.cpp
gui/widgets/grid.cpp
gui/widgets/helper.cpp
gui/widgets/horizontal_scrollbar.cpp
gui/widgets/image.cpp
gui/widgets/label.cpp
gui/widgets/listbox.cpp

View file

@ -0,0 +1,95 @@
/* $Id$ */
/*
copyright (C) 2008 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.
*/
#include "gui/widgets/horizontal_scrollbar.hpp"
namespace gui2 {
unsigned thorizontal_scrollbar::minimum_positioner_length() const
{
boost::intrusive_ptr
<const thorizontal_scrollbar_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const thorizontal_scrollbar_definition::tresolution>(config());
assert(conf);
return conf->minimum_positioner_length;
}
unsigned thorizontal_scrollbar::maximum_positioner_length() const
{
boost::intrusive_ptr
<const thorizontal_scrollbar_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const thorizontal_scrollbar_definition::tresolution>(config());
assert(conf);
return conf->maximum_positioner_length;
}
unsigned thorizontal_scrollbar::offset_before() const
{
boost::intrusive_ptr
<const thorizontal_scrollbar_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const thorizontal_scrollbar_definition::tresolution>(config());
assert(conf);
return conf->left_offset;
}
unsigned thorizontal_scrollbar::offset_after() const
{
boost::intrusive_ptr
<const thorizontal_scrollbar_definition::tresolution> conf =
boost::dynamic_pointer_cast
<const thorizontal_scrollbar_definition::tresolution>(config());
assert(conf);
return conf->right_offset;
}
bool thorizontal_scrollbar::on_positioner(const tpoint& coordinate) const
{
// Note we assume the positioner is over the entire height of the widget.
return coordinate.x >= static_cast<int>(get_positioner_offset())
&& coordinate.x < static_cast<int>(get_positioner_offset()
+ get_positioner_length())
&& coordinate.y > 0
&& coordinate.y < static_cast<int>(get_height());
}
int thorizontal_scrollbar::on_bar(const tpoint& coordinate) const
{
// Not on the widget, leave.
if(static_cast<size_t>(coordinate.x) > get_width()
|| static_cast<size_t>(coordinate.y) > get_height()) {
return 0;
}
// we also assume the bar is over the entire width of the widget.
if(static_cast<size_t>(coordinate.y) < get_positioner_offset()) {
return -1;
} else if(static_cast<size_t>(coordinate.y) >
get_positioner_offset() + get_positioner_length()) {
return 1;
} else {
return 0;
}
}
} // namespace gui2

View file

@ -0,0 +1,67 @@
/* $Id$ */
/*
copyright (C) 2008 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_HORIZONTAL_SCROLLBAR_HPP_INCLUDED
#define GUI_WIDGETS_HORIZONTAL_SCROLLBAR_HPP_INCLUDED
#include "gui/widgets/scrollbar.hpp"
namespace gui2 {
/** A horizontal scrollbar. */
class thorizontal_scrollbar : public tscrollbar_
{
public:
thorizontal_scrollbar() :
tscrollbar_()
{
}
private:
/** Inherited from tscrollbar. */
unsigned get_length() const { return get_height(); }
/** Inherited from tscrollbar. */
unsigned minimum_positioner_length() const;
/** Inherited from tscrollbar. */
unsigned maximum_positioner_length() const;
/** Inherited from tscrollbar. */
unsigned offset_before() const;
/** Inherited from tscrollbar. */
unsigned offset_after() const;
/** Inherited from tscrollbar. */
bool on_positioner(const tpoint& coordinate) const;
/** Inherited from tscrollbar. */
int on_bar(const tpoint& coordinate) const;
/** Inherited from tscrollbar. */
int get_length_difference(const tpoint& original, const tpoint& current) const
{ return current.y - original.y; }
/** Inherited from tcontrol. */
const std::string& get_control_type() const
{ static const std::string type = "horizontal_scrollbar"; return type; }
};
} // namespace gui2
#endif

View file

@ -164,6 +164,8 @@ const std::string& tgui_definition::read(const config& cfg)
* @start_table = widget_definition
* button_definition A push button.
* image_definition An image.
* horizontal_scrollbar_definition
* A horizontal scrollbar.
* menubar_definition A menubar which is used in menus and the
* tabbar in a tabcontrol.
* minimap_definition A minimap to show the gamemap, this only
@ -207,6 +209,8 @@ const std::string& tgui_definition::read(const config& cfg)
/***** Control definitions *****/
load_definitions<tbutton_definition>("button", cfg.get_children("button_definition"));
load_definitions<thorizontal_scrollbar_definition>
("horizontal_scrollbar", cfg.get_children("horizontal_scrollbar_definition"));
load_definitions<timage_definition>("image", cfg.get_children("image_definition"));
load_definitions<tlabel_definition>("label", cfg.get_children("label_definition"));
load_definitions<tlistbox_definition>("listbox", cfg.get_children("listbox_definition"));
@ -501,6 +505,69 @@ tbutton_definition::tresolution::tresolution(const config& cfg) :
state.push_back(tstate_definition(cfg.child("state_focussed")));
}
thorizontal_scrollbar_definition::
thorizontal_scrollbar_definition(const config& cfg) :
tcontrol_definition(cfg)
{
DBG_G_P << "Parsing horizontal scrollbar " << id << '\n';
load_resolutions<tresolution>(cfg.get_children("resolution"));
}
thorizontal_scrollbar_definition::tresolution::tresolution(const config& cfg) :
tresolution_definition_(cfg),
minimum_positioner_length(
lexical_cast_default<unsigned>(cfg["minimum_positioner_length"])),
maximum_positioner_length(
lexical_cast_default<unsigned>(cfg["maximum_positioner_length"])),
left_offset(lexical_cast_default<unsigned>(cfg["left_offset"])),
right_offset(lexical_cast_default<unsigned>(cfg["right_offset"]))
{
/*WIKI
* @page = GUIToolkitWML
* @order = 1_widget_vertical_scrollbar
*
* == Horizontal scrollbar ==
*
* The definition of a horizontal scrollbar. This class is most of the time not
* used directly. Instead it's used to build other items with scrollbars.
*
* The resolution for a horizontal scrollbar also contains the following keys:
* @start_table = config
* minimum_positioner_length (unsigned)
* The minumum size the positioner is
* allowed to be. The engine needs to know
* this in order to calculate the best size
* for the positioner.
* maximum_positioner_length (unsigned = 0)
* The maximum size the positioner is
* allowed to be. If minimum and maximum are
* the same value the positioner is fixed
* size. If the maximum is 0 (and the
* minimum not) there's no maximum.
* left_offset (unsigned = 0) The number of pixels at the left which
* can't be used by the positioner.
* right_offset (unsigned = 0) The number of pixels at the right which
* can't be used by the positioner.
* @end_table
*
* The following states exist:
* * state_enabled, the horizontal scrollbar is enabled.
* * state_disabled, the horizontal scrollbar is disabled.
* * state_pressed, the left mouse button is down on the positioner of the horizontal scrollbar.
* * state_focussed, the mouse is over the positioner of the horizontal scrollbar.
*/
VALIDATE(minimum_positioner_length,
missing_mandatory_wml_key("resolution", "minimum_positioner_length"));
// Note the order should be the same as the enum tstate is scrollbar.hpp.
state.push_back(tstate_definition(cfg.child("state_enabled")));
state.push_back(tstate_definition(cfg.child("state_disabled")));
state.push_back(tstate_definition(cfg.child("state_pressed")));
state.push_back(tstate_definition(cfg.child("state_focussed")));
}
timage_definition::timage_definition(const config& cfg) :
tcontrol_definition(cfg)
{

View file

@ -157,6 +157,22 @@ struct tbutton_definition : public tcontrol_definition
};
struct thorizontal_scrollbar_definition : public tcontrol_definition
{
thorizontal_scrollbar_definition(const config& cfg);
struct tresolution : public tresolution_definition_
{
tresolution(const config& cfg);
unsigned minimum_positioner_length;
unsigned maximum_positioner_length;
unsigned left_offset;
unsigned right_offset;
};
};
struct timage_definition : public tcontrol_definition
{
timage_definition(const config& cfg);

View file

@ -17,6 +17,7 @@
#include "foreach.hpp"
#include "gettext.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/horizontal_scrollbar.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/listbox.hpp"
@ -161,6 +162,10 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
if(cfg.child("button")) {
return new tbuilder_button(*(cfg.child("button")));
} else if(cfg.child("horizontal_scrollbar")) {
return new tbuilder_horizontal_scrollbar(
*(cfg.child("horizontal_scrollbar")));
} else if(cfg.child("image")) {
return new tbuilder_image(*(cfg.child("image")));
} else if(cfg.child("label")) {
@ -186,8 +191,9 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
} else if(cfg.child("toggle_panel")) {
return new tbuilder_toggle_panel(*(cfg.child("toggle_panel")));
} else if(cfg.child("vertical_scrollbar")) {
return
new tbuilder_vertical_scrollbar(*(cfg.child("vertical_scrollbar")));
return new tbuilder_vertical_scrollbar(
*(cfg.child("vertical_scrollbar")));
} else if(cfg.child("grid")) {
return new tbuilder_grid(*(cfg.child("grid")));
} else {
@ -447,6 +453,7 @@ tbuilder_grid::tbuilder_grid(const config& cfg) :
* * button a button.
* * image an image.
* * grid a grid, this is used to nest items.
* * horizontal_scrollbar a horizontal scrollbar.
* * label a label.
* * listbox a listbox.
* * panel a panel (a grid which can be drawn on).
@ -624,6 +631,20 @@ twidget* tbuilder_button::build() const
return button;
}
twidget* tbuilder_horizontal_scrollbar::build() const
{
thorizontal_scrollbar *horizontal_scrollbar = new thorizontal_scrollbar();
init_control(horizontal_scrollbar);
DBG_GUI << "Window builder:"
<< " placed horizontal scrollbar '" << id
<< "' with defintion '" << definition
<< "'.\n";
return horizontal_scrollbar;
}
twidget* tbuilder_image::build() const
{
timage* widget = new timage();
@ -1219,8 +1240,10 @@ twidget* tbuilder_vertical_scrollbar::build() const
init_control(vertical_scrollbar);
DBG_GUI << "Window builder: placed text box '" << id << "' with defintion '"
<< definition << "'.\n";
DBG_GUI << "Window builder:"
<< " placed vertical scrollbar '" << id
<< "' with defintion '" << definition
<< "'.\n";
return vertical_scrollbar;
}

View file

@ -103,6 +103,28 @@ struct tbuilder_gridcell : public tbuilder_widget
twidget* build () const { return NULL; }
};
struct tbuilder_horizontal_scrollbar : public tbuilder_control
{
private:
tbuilder_horizontal_scrollbar();
public:
/*WIKI
* @page = GUIToolkitWML
* @order = 3_widget_horizontal_scrollbar
*
* == Horizontal scrollbar ==
*
* A horizontal scrollbar has no special fields.
*
*/
tbuilder_horizontal_scrollbar(const config& cfg) :
tbuilder_control(cfg)
{}
twidget* build () const;
};
struct tbuilder_label : public tbuilder_control
{