Author: mordante
Date: Sat May 17 12:37:10 2008
New Revision: 26671
URL: http://svn.gna.org/viewcvs/wesnoth?rev=26671&view=rev
Log:
Show (ugly) placeholder buttons for the scrollbar in the listbox.
Made those buttons also works.
Fixes a off by one bug in at_end().
Modified:
trunk/data/gui/default/widget/listbox_default.cfg
trunk/src/gui/widgets/listbox.cpp
trunk/src/gui/widgets/listbox.hpp
trunk/src/gui/widgets/scrollbar.cpp
trunk/src/gui/widgets/scrollbar.hpp
trunk/src/gui/widgets/settings.cpp
trunk/src/gui/widgets/window_builder.cpp
Modified: trunk/data/gui/default/widget/listbox_default.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/widget/listbox_default.cfg?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/data/gui/default/widget/listbox_default.cfg (original)
+++ trunk/data/gui/default/widget/listbox_default.cfg Sat May 17 12:37:10 2008
@@ -35,7 +35,6 @@
[scrollbar]
-#ifdef USE_BUTTON
[row]
[column]
# note we want a specia button
defenition for this later.
@@ -52,7 +51,7 @@
[column]
# note we want a specia button
defenition for this later.
[button]
- id = "_jump_back"
+ id = "_page_up"
definition = "default"
label = "page up"
@@ -64,16 +63,28 @@
[column]
# note we want a specia button
defenition for this later.
[button]
- id = "_back"
+ id = "_half_page_up"
definition = "default"
- label = "up"
+ label = "half page up"
[/button]
[/column]
[/row]
-#endif
[row]
+ [column]
+ # note we want a specia button
defenition for this later.
+ [button]
+ id = "_line_up"
+ definition = "default"
+
+ label = "line up"
+ [/button]
+ [/column]
+ [/row]
+
+ [row]
+ grow_factor = 1
[column]
vertical_grow = "true"
@@ -87,29 +98,42 @@
[/row]
-#ifdef USE_BUTTON
[row]
[column]
# note we want a specia button
defenition for this later.
[button]
- id = "_forward"
+ id = "_line_down"
definition = "default"
- label = "down"
+ label = "line down"
[/button]
[/column]
[/row]
+
[row]
[column]
# note we want a specia button
defenition for this later.
[button]
- id = "_jump_forward"
+ id = "_half_page_down"
+ definition = "default"
+
+ label = "half page down"
+ [/button]
+ [/column]
+ [/row]
+
+ [row]
+ [column]
+ # note we want a specia button
defenition for this later.
+ [button]
+ id = "_page_down"
definition = "default"
label = "page down"
[/button]
[/column]
[/row]
+
[row]
[column]
# note we want a specia button
defenition for this later.
@@ -121,7 +145,6 @@
[/button]
[/column]
[/row]
-#endif
[/scrollbar]
Modified: trunk/src/gui/widgets/listbox.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.cpp?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.cpp (original)
+++ trunk/src/gui/widgets/listbox.cpp Sat May 17 12:37:10 2008
@@ -15,6 +15,7 @@
#include "gui/widgets/listbox.hpp"
#include "foreach.hpp"
+#include "gui/widgets/button.hpp"
#include "gui/widgets/helper.hpp"
#include "gui/widgets/scrollbar.hpp"
#include "gui/widgets/spacer.hpp"
@@ -63,6 +64,11 @@
static void callback_scrollbar(twidget* caller)
{
get_listbox(caller)->scrollbar_moved(caller);
+}
+
+static void callback_scrollbar_button(twidget* caller)
+{
+ get_listbox(caller)->scrollbar_click(caller);
}
tlistbox::tlistbox() :
@@ -106,6 +112,31 @@
assert(false);
}
+void tlistbox::scrollbar_click(twidget* caller)
+{
+ if(caller->id() == "_begin") {
+ scrollbar()->scroll(tscrollbar_::BEGIN);
+ } else if(caller->id() == "_line_up") {
+ scrollbar()->scroll(tscrollbar_::ITEM_BACKWARDS);
+ } else if(caller->id() == "_half_page_up") {
+ scrollbar()->scroll(tscrollbar_::HALF_JUMP_BACKWARDS);
+ } else if(caller->id() == "_page_up") {
+ scrollbar()->scroll(tscrollbar_::JUMP_BACKWARDS);
+ } else if(caller->id() == "_end") {
+ scrollbar()->scroll(tscrollbar_::END);
+ } else if(caller->id() == "_line_down") {
+ scrollbar()->scroll(tscrollbar_::ITEM_FORWARD);
+ } else if(caller->id() == "_half_page_down") {
+ scrollbar()->scroll(tscrollbar_::HALF_JUMP_FORWARD);
+ } else if(caller->id() == "_page_down") {
+ scrollbar()->scroll(tscrollbar_::JUMP_FORWARD);
+ } else {
+ assert(false);
+ }
+
+ set_scrollbar_button_status();
+}
+
void tlistbox::finalize_setup()
{
// If we have a list already set up wire in the callback routine.
@@ -149,6 +180,61 @@
}
scrollbar()->set_callback_positioner_move(callback_scrollbar);
+
+ static std::vector<std::string> button_names;
+ if(button_names.empty()) {
+ button_names.push_back("_begin");
+ button_names.push_back("_line_up");
+ button_names.push_back("_half_page_up");
+ button_names.push_back("_page_up");
+
+ button_names.push_back("_end");
+ button_names.push_back("_line_down");
+ button_names.push_back("_half_page_down");
+ button_names.push_back("_page_down");
+ }
+
+ foreach(const std::string& name, button_names) {
+ tbutton* button =
dynamic_cast<tbutton*>(get_widget_by_id(name));
+ if(button) {
+
button->set_callback_mouse_left_click(callback_scrollbar_button);
+ }
+ }
+}
+
+void tlistbox::set_scrollbar_button_status()
+{
+ // Set scroll up button status
+ static std::vector<std::string> button_up_names;
+ if(button_up_names.empty()) {
+ button_up_names.push_back("_begin");
+ button_up_names.push_back("_line_up");
+ button_up_names.push_back("_half_page_up");
+ button_up_names.push_back("_page_up");
+ }
+
+ foreach(const std::string& name, button_up_names) {
+ tbutton* button =
dynamic_cast<tbutton*>(get_widget_by_id(name));
+ if(button) {
+ button->set_active(!scrollbar()->at_begin());
+ }
+ }
+
+ // Set scroll down button status
+ static std::vector<std::string> button_down_names;
+ if(button_down_names.empty()) {
+ button_down_names.push_back("_end");
+ button_down_names.push_back("_line_down");
+ button_down_names.push_back("_half_page_down");
+ button_down_names.push_back("_page_down");
+ }
+
+ foreach(const std::string& name, button_down_names) {
+ tbutton* button =
dynamic_cast<tbutton*>(get_widget_by_id(name));
+ if(button) {
+ button->set_active(!scrollbar()->at_end());
+ }
+ }
}
/**
@@ -335,6 +421,7 @@
}
scrollbar()->set_item_count(get_item_count());
+ set_scrollbar_button_status();
}
tscrollbar_* tlistbox::scrollbar()
Modified: trunk/src/gui/widgets/listbox.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.hpp?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.hpp (original)
+++ trunk/src/gui/widgets/listbox.hpp Sat May 17 12:37:10 2008
@@ -54,7 +54,14 @@
/**
* Callback when the scrollbar moves.
*/
- void scrollbar_moved(twidget* /*caller*/) { set_dirty(); }
+ void scrollbar_moved(twidget* /*caller*/)
+ { set_scrollbar_button_status(); set_dirty(); }
+
+ /**
+ * When an item scrollbar control button is clicked we need to move the
+ * scrollbar and update the list.
+ */
+ void scrollbar_click(twidget* caller);
/** The builder needs to call us so we can write in the proper
callbacks. */
void finalize_setup();
@@ -104,6 +111,15 @@
unsigned get_selected_row() const { return selected_row_; }
private:
+
+ /**
+ * Sets the status of the scrollbar buttons.
+ *
+ * This is needed after the scrollbar moves so the status of the buttons
+ * will be active or inactive as needed.
+ */
+ void set_scrollbar_button_status();
+
//! Note the order of the states must be the same as defined in
settings.hpp.
enum tstate { ENABLED, DISABLED, COUNT };
Modified: trunk/src/gui/widgets/scrollbar.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/scrollbar.cpp?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/src/gui/widgets/scrollbar.cpp (original)
+++ trunk/src/gui/widgets/scrollbar.cpp Sat May 17 12:37:10 2008
@@ -135,12 +135,9 @@
void tscrollbar_::set_item_position(const unsigned item_position)
{
// Set the value always execute since we update a part of the state.
- item_position_ = item_position;
-
- // Adjust the item position.
- if(item_position_ >= item_count_) {
- item_position_ = item_count_ - 1;
- }
+ item_position_ = item_position + visible_items_ > item_count_ ?
+ item_count_ - visible_items_ : item_position;
+
item_position_ = (item_position_ + step_size_ - 1) / step_size_;
std::cerr << "Item position: " << item_position_ << ".\n";
@@ -149,6 +146,50 @@
std::cerr << "Positioner offset: " << positioner_offset_ << ".\n";
update_canvas();
+}
+
+void tscrollbar_::scroll(const tscroll scroll)
+{
+ switch(scroll) {
+ case BEGIN :
+ set_item_position(0);
+ break;
+
+ case ITEM_BACKWARDS :
+ if(item_position_) {
+ set_item_position(item_position_ - 1);
+ }
+ break;
+
+ case HALF_JUMP_BACKWARDS :
+ set_item_position(item_position_ > (visible_items_ / 2)
?
+ item_position_ - (visible_items_ / 2) : 0);
+ break;
+
+ case JUMP_BACKWARDS :
+ set_item_position(item_position_ > visible_items_ ?
+ item_position_ - visible_items_ : 0);
+ break;
+
+ case END :
+ set_item_position(item_count_ - 1);
+ break;
+
+ case ITEM_FORWARD :
+ set_item_position(item_position_ + 1);
+ break;
+
+ case HALF_JUMP_FORWARD :
+ set_item_position(item_position_ + (visible_items_ /
2));
+ break;
+
+ case JUMP_FORWARD :
+ set_item_position(item_position_ + visible_items_ );
+ break;
+
+ default :
+ assert(false);
+ }
}
void tscrollbar_::set_state(const tstate state)
Modified: trunk/src/gui/widgets/scrollbar.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/scrollbar.hpp?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/src/gui/widgets/scrollbar.hpp (original)
+++ trunk/src/gui/widgets/scrollbar.hpp Sat May 17 12:37:10 2008
@@ -87,6 +87,19 @@
//! the step size is honoured. The value will be rouded down
void set_item_position(const unsigned item_position);
+ enum tscroll {
+ BEGIN, /**< Go to begin position. */
+ ITEM_BACKWARDS, /**< Go one item towards the begin. */
+ HALF_JUMP_BACKWARDS, /**< Go half the visible items towards the
begin. */
+ JUMP_BACKWARDS, /**< Go the visibile items towards the
begin. */
+ END, /**< Go to the end position. */
+ ITEM_FORWARD, /**< Go one item towards the end. */
+ HALF_JUMP_FORWARD, /**< Go half the visible items towards the
end. */
+ JUMP_FORWARD }; /**< Go the visible items towards the end.
*/
+
+ /** Sets the item position. */
+ void scroll(const tscroll scroll);
+
unsigned get_visible_items() const { return visible_items_; }
void set_visible_items(const unsigned visible_items)
{ visible_items_ = visible_items; recalculate(); }
@@ -101,7 +114,7 @@
//! Is the positioner at the and of the scrollbar, note both begin and
end
//! might be true at the same time.
bool at_end() const
- { return item_position_ + visible_items_ + 1 == item_count_; }
+ { return item_position_ + visible_items_ == item_count_; }
void set_callback_positioner_move(void (*callback) (twidget*))
{ callback_positioner_move_ = callback; }
Modified: trunk/src/gui/widgets/settings.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Sat May 17 12:37:10 2008
@@ -525,7 +525,7 @@
tlistbox_definition::tresolution::tresolution(const config& cfg) :
tresolution_definition_(cfg),
- scrollbar(0) //cfg.child("scrollbar"))
+ scrollbar(0)
{
/*WIKI
@@ -541,7 +541,35 @@
* The resolution for a text box also contains the following keys:
* @start_table = config
* scrollbar (section) A grid containing the widgets for the
- * scrollbar.
+ * scrollbar. The scrollbar has some
special
+ * widgets so it can make default behaviour
+ * for certain widgets.
+ * @end_table
+ *
+ * @start_table = container
+ * [_begin] button Moves the position to the beginning of
+ * the list.
+ * [_line_up] button Move the position one item up. (NOTE if
+ * too many items to move per item it might
+ * be more items.)
+ * [_half_page_up] button Move the position half the number of
the
+ * visible items up. (See note at
_line_up.)
+ * [_page_up] button Move the position the number of visible
+ * items up. (See note at _line_up.)
+ *
+ *
+ * [_end] button Moves the position to the end of the
+ * list.
+ * [_line_down] button Move the position one item down.(See
note
+ * at _line_up.)
+ * [_half_page_down] button Move the position half the number of
the
+ * visible items down. (See note at
_line_up.)
+ * [_page_down] button Move the position the number of visible
+ * items down. (See note at _line_up.)
+ *
+ * (_scrollbar) vertical_scrollbar This is the scrollbar so the user can
+ * scroll through the list.
+ *
* @end_table
*
* The following states exist:
Modified: trunk/src/gui/widgets/window_builder.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=26671&r1=26670&r2=26671&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Sat May 17 12:37:10 2008
@@ -620,7 +620,10 @@
* initial value. This value should be
* unique or empty. Those special values
are
* documented at the window definition that
- * uses them.
+ * uses them. NOTE items starting with an
+ * underscore are used for composed
witdgets
+ * and these should be unique per composed
+ * widget.
*
* definition (string = "default") The id of the widget definition to use.
* This way it's possible to select a
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits