Add a new repeating button widget.
A repeating button is button when pressed down will execute an action, if the user keeps it pressed down for a longer time it will repeat this action until released. The main place where the widget was missed is the MP lobby, I haven't tested it there much since the lobby is still to slow. This means once the lobby is fast enough it needs more tuning. The widget hasn't been wired in the scrollbars, which will be done in the next commit.
This commit is contained in:
parent
67335b20aa
commit
bd83d922f5
14 changed files with 604 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
Version 1.7.10+svn:
|
||||
* Language and i18n:
|
||||
* Updated translations:
|
||||
* User interface:
|
||||
* Add a new repeating button widget
|
||||
* Miscellaneous and bugfixes:
|
||||
* Scrollbar containers now use the button super class
|
||||
* Allow a gui2 timer delete itself in its callback
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
help_show_time = 0
|
||||
|
||||
double_click_time = 500
|
||||
repeat_button_repeat_time = 350
|
||||
|
||||
sound_button_click = "button.wav"
|
||||
sound_toggle_button_click = "checkbox.wav"
|
||||
|
|
153
data/gui/default/widget/repeating_button_default.cfg
Normal file
153
data/gui/default/widget/repeating_button_default.cfg
Normal file
|
@ -0,0 +1,153 @@
|
|||
#textdomain wesnoth-lib
|
||||
###
|
||||
### Definition of repeating buttons which have a 25 x 25 pixels image.
|
||||
### - down arrow button for the listbox.
|
||||
### - up arrow button for the listbox.
|
||||
|
||||
#define _GUI_RESOLUTION RESOLUTION SIZE IMAGE
|
||||
[resolution]
|
||||
|
||||
{RESOLUTION}
|
||||
|
||||
min_width = {SIZE}
|
||||
min_height = {SIZE}
|
||||
|
||||
default_width = {SIZE}
|
||||
default_height = {SIZE}
|
||||
|
||||
max_width = {SIZE}
|
||||
max_height = {SIZE}
|
||||
|
||||
[state_enabled]
|
||||
|
||||
[draw]
|
||||
|
||||
[image]
|
||||
w = {SIZE}
|
||||
h = {SIZE}
|
||||
name = {IMAGE} + ".png"
|
||||
[/image]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/state_enabled]
|
||||
|
||||
[state_disabled]
|
||||
|
||||
[draw]
|
||||
|
||||
[image]
|
||||
w = {SIZE}
|
||||
h = {SIZE}
|
||||
name = {IMAGE} + "-disabled.png"
|
||||
[/image]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/state_disabled]
|
||||
|
||||
[state_pressed]
|
||||
|
||||
[draw]
|
||||
|
||||
[image]
|
||||
w = {SIZE}
|
||||
h = {SIZE}
|
||||
name = {IMAGE} + "-pressed.png"
|
||||
[/image]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/state_pressed]
|
||||
|
||||
[state_focussed]
|
||||
|
||||
[draw]
|
||||
|
||||
[image]
|
||||
w = {SIZE}
|
||||
h = {SIZE}
|
||||
name = {IMAGE} + "-active.png"
|
||||
[/image]
|
||||
|
||||
[/draw]
|
||||
|
||||
[/state_focussed]
|
||||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
||||
#define _GUI_DEFINITION ID DESCRIPTION IMAGE
|
||||
[repeating_button_definition]
|
||||
id = {ID}
|
||||
description = {DESCRIPTION}
|
||||
|
||||
{_GUI_RESOLUTION ({GUI_TINY__RESOLUTION}) 12 ({IMAGE}) }
|
||||
{_GUI_RESOLUTION () 25 ({IMAGE}) }
|
||||
|
||||
[/repeating_button_definition]
|
||||
#enddef
|
||||
|
||||
# Default normally not used since the versions with specific images are
|
||||
# preferred.
|
||||
{_GUI_DEFINITION
|
||||
"default"
|
||||
"Default don't use."
|
||||
"buttons/button"
|
||||
}
|
||||
|
||||
# Opaques arrow buttons
|
||||
|
||||
{_GUI_DEFINITION
|
||||
"down_arrow"
|
||||
"Down arrow button for a scrollbar."
|
||||
"buttons/downarrow-button"
|
||||
}
|
||||
|
||||
{_GUI_DEFINITION
|
||||
"up_arrow"
|
||||
"Up arrow button for a scrollbar."
|
||||
"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"
|
||||
}
|
||||
|
||||
# Opaques arrow buttons
|
||||
|
||||
{_GUI_DEFINITION
|
||||
"down_arrow_transparent"
|
||||
"Down arrow button for a transparent scrollbar."
|
||||
"buttons/downarrow-button_transparent"
|
||||
}
|
||||
|
||||
{_GUI_DEFINITION
|
||||
"up_arrow_transparent"
|
||||
"Up arrow button for a transparent scrollbar."
|
||||
"buttons/uparrow-button_transparent"
|
||||
}
|
||||
|
||||
{_GUI_DEFINITION
|
||||
"left_arrow_transparent"
|
||||
"Left arrow button for a transparent scrollbar."
|
||||
"buttons/left_arrow-button_transparent"
|
||||
}
|
||||
|
||||
{_GUI_DEFINITION
|
||||
"right_arrow_transparent"
|
||||
"Right arrow button for a transparent scrollbar."
|
||||
"buttons/right_arrow-button_transparent"
|
||||
}
|
||||
|
||||
#undef _GUI_DEFINITION
|
||||
#undef _GUI_RESOLUTION
|
||||
|
|
@ -25,6 +25,7 @@ src/gui/auxiliary/window_builder/multi_page.cpp
|
|||
src/gui/auxiliary/window_builder/panel.cpp
|
||||
src/gui/auxiliary/window_builder/password_box.cpp
|
||||
src/gui/auxiliary/window_builder/scrollbar_panel.cpp
|
||||
src/gui/auxiliary/window_builder/repeating_button.cpp
|
||||
src/gui/auxiliary/window_builder/scroll_label.cpp
|
||||
src/gui/auxiliary/window_builder/slider.cpp
|
||||
src/gui/auxiliary/window_builder/spacer.cpp
|
||||
|
@ -72,6 +73,7 @@ src/gui/widgets/scrollbar_container.cpp
|
|||
src/gui/widgets/scrollbar.cpp
|
||||
src/gui/widgets/scrollbar_panel.cpp
|
||||
src/gui/widgets/scroll_label.cpp
|
||||
src/gui/widgets/repeating_button.cpp
|
||||
src/gui/widgets/settings.cpp
|
||||
src/gui/widgets/slider.cpp
|
||||
src/gui/widgets/spacer.cpp
|
||||
|
|
|
@ -237,6 +237,7 @@ set(wesnoth-main_SRC
|
|||
gui/auxiliary/window_builder/minimap.cpp
|
||||
gui/auxiliary/window_builder/menubar.cpp
|
||||
gui/auxiliary/window_builder/multi_page.cpp
|
||||
gui/auxiliary/window_builder/repeating_button.cpp
|
||||
gui/auxiliary/window_builder/scroll_label.cpp
|
||||
gui/auxiliary/window_builder/scrollbar_panel.cpp
|
||||
gui/auxiliary/window_builder/slider.cpp
|
||||
|
@ -286,6 +287,7 @@ set(wesnoth-main_SRC
|
|||
gui/widgets/multi_page.cpp
|
||||
gui/widgets/panel.cpp
|
||||
gui/widgets/password_box.cpp
|
||||
gui/widgets/repeating_button.cpp
|
||||
gui/widgets/settings.cpp
|
||||
gui/widgets/scroll_label.cpp
|
||||
gui/widgets/scrollbar_container.cpp
|
||||
|
|
|
@ -117,6 +117,7 @@ wesnoth_source = \
|
|||
gui/auxiliary/window_builder/minimap.cpp \
|
||||
gui/auxiliary/window_builder/menubar.cpp \
|
||||
gui/auxiliary/window_builder/multi_page.cpp \
|
||||
gui/auxiliary/window_builder/repeating_button.cpp \
|
||||
gui/auxiliary/window_builder/scroll_label.cpp \
|
||||
gui/auxiliary/window_builder/scrollbar_panel.cpp \
|
||||
gui/auxiliary/window_builder/slider.cpp \
|
||||
|
@ -166,6 +167,7 @@ wesnoth_source = \
|
|||
gui/widgets/multi_page.cpp \
|
||||
gui/widgets/panel.cpp \
|
||||
gui/widgets/password_box.cpp \
|
||||
gui/widgets/repeating_button.cpp \
|
||||
gui/widgets/settings.cpp \
|
||||
gui/widgets/scroll_label.cpp \
|
||||
gui/widgets/scrollbar.cpp \
|
||||
|
|
|
@ -277,6 +277,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/window_builder/minimap.cpp
|
||||
gui/auxiliary/window_builder/menubar.cpp
|
||||
gui/auxiliary/window_builder/multi_page.cpp
|
||||
gui/auxiliary/window_builder/repeating_button.cpp
|
||||
gui/auxiliary/window_builder/scroll_label.cpp
|
||||
gui/auxiliary/window_builder/scrollbar_panel.cpp
|
||||
gui/auxiliary/window_builder/slider.cpp
|
||||
|
@ -325,6 +326,7 @@ wesnoth_sources = Split("""
|
|||
gui/widgets/multi_page.cpp
|
||||
gui/widgets/panel.cpp
|
||||
gui/widgets/password_box.cpp
|
||||
gui/widgets/repeating_button.cpp
|
||||
gui/widgets/settings.cpp
|
||||
gui/widgets/scroll_label.cpp
|
||||
gui/widgets/scrollbar_container.cpp
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "gui/auxiliary/window_builder/minimap.hpp"
|
||||
#include "gui/auxiliary/window_builder/menubar.hpp"
|
||||
#include "gui/auxiliary/window_builder/multi_page.hpp"
|
||||
#include "gui/auxiliary/window_builder/repeating_button.hpp"
|
||||
#include "gui/auxiliary/window_builder/scroll_label.hpp"
|
||||
#include "gui/auxiliary/window_builder/scrollbar_panel.hpp"
|
||||
#include "gui/auxiliary/window_builder/slider.hpp"
|
||||
|
@ -77,6 +78,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
TRY(minimap);
|
||||
TRY(multi_page);
|
||||
TRY(panel);
|
||||
TRY(repeating_button);
|
||||
TRY(scroll_label);
|
||||
TRY(scrollbar_panel);
|
||||
TRY(slider);
|
||||
|
|
66
src/gui/auxiliary/window_builder/repeating_button.cpp
Normal file
66
src/gui/auxiliary/window_builder/repeating_button.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 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/repeating_button.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/widgets/repeating_button.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
tbuilder_repeating_button::tbuilder_repeating_button(const config& cfg)
|
||||
: tbuilder_control(cfg)
|
||||
{
|
||||
}
|
||||
|
||||
twidget* tbuilder_repeating_button::build() const
|
||||
{
|
||||
trepeating_button* widget = new trepeating_button();
|
||||
|
||||
init_control(widget);
|
||||
|
||||
DBG_GUI_G << "Window builder: placed repeating button '"
|
||||
<< id << "' with defintion '"
|
||||
<< definition << "'.\n";
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
/*WIKI_MACRO
|
||||
* @start_macro = repeating_button_description
|
||||
*
|
||||
* A repeating_button is a control that can be pushed down and repeat a
|
||||
* certain action. Once the button is down every x milliseconds it is
|
||||
* down a new down event is triggered.
|
||||
* @end_macro
|
||||
*/
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWidgetInstanceWML
|
||||
* @order = 2_repeating_button
|
||||
*
|
||||
* == Repeating button ==
|
||||
*
|
||||
* @macro = repeating_button_description
|
||||
*
|
||||
*/
|
40
src/gui/auxiliary/window_builder/repeating_button.hpp
Normal file
40
src/gui/auxiliary/window_builder/repeating_button.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 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_REPEATING_BUTTON_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WINDOW_BUILDER_REPEATING_BUTTON_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder/control.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
struct tbuilder_repeating_button
|
||||
: public tbuilder_control
|
||||
{
|
||||
public:
|
||||
tbuilder_repeating_button(const config& cfg);
|
||||
|
||||
twidget* build () const;
|
||||
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
158
src/gui/widgets/repeating_button.cpp
Normal file
158
src/gui/widgets/repeating_button.cpp
Normal file
|
@ -0,0 +1,158 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 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/repeating_button.hpp"
|
||||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/auxiliary/timer.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "sound.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
|
||||
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
trepeating_button::trepeating_button()
|
||||
: tcontrol(COUNT)
|
||||
, tclickable_()
|
||||
, state_(ENABLED)
|
||||
, repeat_timer_(0)
|
||||
{
|
||||
connect_signal<event::MOUSE_ENTER>(boost::bind(
|
||||
&trepeating_button::signal_handler_mouse_enter, this, _2, _3));
|
||||
connect_signal<event::MOUSE_LEAVE>(boost::bind(
|
||||
&trepeating_button::signal_handler_mouse_leave, this, _2, _3));
|
||||
|
||||
connect_signal<event::LEFT_BUTTON_DOWN>(boost::bind(
|
||||
&trepeating_button::signal_handler_left_button_down
|
||||
, this
|
||||
, _2
|
||||
, _3));
|
||||
connect_signal<event::LEFT_BUTTON_UP>(boost::bind(
|
||||
&trepeating_button::signal_handler_left_button_up
|
||||
, this
|
||||
, _2
|
||||
, _3));
|
||||
}
|
||||
|
||||
trepeating_button::~trepeating_button()
|
||||
{
|
||||
if(repeat_timer_) {
|
||||
remove_timer(repeat_timer_);
|
||||
}
|
||||
}
|
||||
|
||||
void trepeating_button::connect_signal_mouse_left_down(
|
||||
const event::tsignal_function& signal)
|
||||
{
|
||||
connect_signal<event::LEFT_BUTTON_DOWN>(signal);
|
||||
}
|
||||
|
||||
void trepeating_button::disconnect_signal_mouse_left_down(
|
||||
const event::tsignal_function& signal)
|
||||
{
|
||||
disconnect_signal<event::LEFT_BUTTON_DOWN>(signal);
|
||||
}
|
||||
|
||||
void trepeating_button::set_state(const tstate state)
|
||||
{
|
||||
if(state != state_) {
|
||||
state_ = state;
|
||||
set_dirty(true);
|
||||
|
||||
if(state_ == DISABLED && repeat_timer_) {
|
||||
remove_timer(repeat_timer_);
|
||||
repeat_timer_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& trepeating_button::get_control_type() const
|
||||
{
|
||||
static const std::string type = "repeating_button";
|
||||
return type;
|
||||
}
|
||||
|
||||
void trepeating_button::signal_handler_mouse_enter(
|
||||
const event::tevent event, bool& handled)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
set_state(FOCUSSED);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
void trepeating_button::signal_handler_mouse_leave(
|
||||
const event::tevent event, bool& handled)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
set_state(ENABLED);
|
||||
handled = true;
|
||||
}
|
||||
|
||||
void trepeating_button::signal_handler_left_button_down(
|
||||
const event::tevent event, bool& handled)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
// If the timer isn't set it's the initial down event.
|
||||
if(!repeat_timer_) {
|
||||
|
||||
// mimic the old gui and only play the sound once.
|
||||
sound::play_UI_sound(settings::sound_button_click);
|
||||
|
||||
twindow* window = get_window();
|
||||
if(window) {
|
||||
repeat_timer_ = add_timer(
|
||||
settings::repeat_button_repeat_time
|
||||
, boost::bind(
|
||||
&tdispatcher::fire
|
||||
, window
|
||||
, event::LEFT_BUTTON_DOWN
|
||||
, boost::ref(*this))
|
||||
, true);
|
||||
|
||||
window->mouse_capture();
|
||||
}
|
||||
|
||||
set_state(PRESSED);
|
||||
}
|
||||
|
||||
handled = true;
|
||||
}
|
||||
|
||||
void trepeating_button::signal_handler_left_button_up(
|
||||
const event::tevent event, bool& handled)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
|
||||
|
||||
if(repeat_timer_) {
|
||||
remove_timer(repeat_timer_);
|
||||
repeat_timer_ = 0;
|
||||
}
|
||||
|
||||
if(get_active()) {
|
||||
set_state(FOCUSSED);
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
114
src/gui/widgets/repeating_button.hpp
Normal file
114
src/gui/widgets/repeating_button.hpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 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_REPEATING_BUTTON_HPP_INCLUDED
|
||||
#define GUI_WIDGETS_REPEATING_BUTTON_HPP_INCLUDED
|
||||
|
||||
#include "gui/widgets/control.hpp"
|
||||
#include "gui/widgets/clickable.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class trepeating_button
|
||||
: public tcontrol
|
||||
, public tclickable_
|
||||
{
|
||||
public:
|
||||
trepeating_button();
|
||||
~trepeating_button();
|
||||
|
||||
/**
|
||||
* Connects a signal handler for a left mouse button down.
|
||||
*
|
||||
* This event is triggered when the button is pressed and, as long as the
|
||||
* button stays down, every x ms afterwards.
|
||||
*
|
||||
* @param signal The signal to connect.
|
||||
*/
|
||||
void connect_signal_mouse_left_down(const event::tsignal_function& signal);
|
||||
|
||||
/**
|
||||
* Disconnects a signal handler for a left mouse button down.
|
||||
*
|
||||
* @param signal The signal to disconnect (should be the same
|
||||
* as send to the connect call.
|
||||
*/
|
||||
void disconnect_signal_mouse_left_down(
|
||||
const event::tsignal_function& signal);
|
||||
|
||||
/***** ***** ***** ***** Inherited ***** ***** ***** *****/
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
void set_active(const bool active)
|
||||
{ if(get_active() != active) set_state(active ? ENABLED : DISABLED); };
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
bool get_active() const { return state_ != DISABLED; }
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Inherited from tclickable. */
|
||||
void connect_click_handler(const event::tsignal_function& signal)
|
||||
{
|
||||
connect_signal_mouse_left_down(signal);
|
||||
}
|
||||
|
||||
/** Inherited from tclickable. */
|
||||
void disconnect_click_handler(const event::tsignal_function& signal)
|
||||
{
|
||||
disconnect_signal_mouse_left_down(signal);
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Possible states of the widget.
|
||||
*
|
||||
* Note the order of the states must be the same as defined in settings.hpp.
|
||||
*/
|
||||
enum tstate { ENABLED, DISABLED, PRESSED, FOCUSSED, COUNT };
|
||||
|
||||
void set_state(const tstate state);
|
||||
/**
|
||||
* Current state of the widget.
|
||||
*
|
||||
* The state of the widget determines what to render and how the widget
|
||||
* reacts to certain 'events'.
|
||||
*/
|
||||
tstate state_;
|
||||
|
||||
/** The timer for the repeating events. */
|
||||
unsigned long repeat_timer_;
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
const std::string& get_control_type() const;
|
||||
|
||||
/***** ***** ***** signal handlers ***** ****** *****/
|
||||
|
||||
void signal_handler_mouse_enter(const event::tevent event, bool& handled);
|
||||
|
||||
void signal_handler_mouse_leave(const event::tevent event, bool& handled);
|
||||
|
||||
void signal_handler_left_button_down(
|
||||
const event::tevent event, bool& handled);
|
||||
|
||||
void signal_handler_left_button_up(
|
||||
const event::tevent event, bool& handled);
|
||||
};
|
||||
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
@ -45,6 +45,7 @@ namespace settings {
|
|||
unsigned popup_show_time = 0;
|
||||
unsigned help_show_time = 0;
|
||||
unsigned double_click_time = 0;
|
||||
unsigned repeat_button_repeat_time = 0;
|
||||
|
||||
std::string sound_button_click = "";
|
||||
std::string sound_toggle_button_click = "";
|
||||
|
@ -201,6 +202,7 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
* Minimap @macro = minimap_description
|
||||
* Multi_page @macro = multi_page_description
|
||||
* Panel @macro = panel_description
|
||||
* Repeating_button @macro = repeating_button_description
|
||||
* Scroll_label @macro = scroll_label_description
|
||||
* Slider @macro = slider_description
|
||||
* Spacer @macro = spacer_description
|
||||
|
@ -275,6 +277,7 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
load_definitions<tmulti_page_definition>("multi_page", cfg);
|
||||
load_definitions<tstacked_widget_definition>("stacked_widget", cfg);
|
||||
load_definitions<tpanel_definition>("panel", cfg);
|
||||
load_definitions<trepeating_button_definition>("repeating_button", cfg);
|
||||
load_definitions<tscroll_label_definition>("scroll_label", cfg);
|
||||
load_definitions<tscrollbar_panel_definition>("scrollbar_panel", cfg);
|
||||
load_definitions<tslider_definition>("slider", cfg);
|
||||
|
@ -323,6 +326,10 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
* widget.
|
||||
* double_click_time (unsigned) The time between two clicks to still be a
|
||||
* double click.
|
||||
* repeat_button_repeat_time (unsigned = 0)
|
||||
* The time a repeating button waits before
|
||||
* the next event is issued if the button
|
||||
* is still pressed down.
|
||||
*
|
||||
* sound_button_click (string = "")
|
||||
* The sound played if a button is
|
||||
|
@ -357,6 +364,9 @@ const std::string& tgui_definition::read(const config& cfg)
|
|||
help_show_time_ = lexical_cast_default<unsigned>(settings["help_show_time"]);
|
||||
double_click_time_ = lexical_cast_default<unsigned>(settings["double_click_time"]);
|
||||
|
||||
repeat_button_repeat_time_ = lexical_cast_default<unsigned>(
|
||||
settings["repeat_button_repeat_time"]);
|
||||
|
||||
VALIDATE(double_click_time_, missing_mandatory_wml_key("settings", "double_click_time"));
|
||||
|
||||
sound_button_click_ = settings["sound_button_click"];
|
||||
|
@ -373,6 +383,7 @@ void tgui_definition::activate() const
|
|||
settings::popup_show_time = popup_show_time_;
|
||||
settings::help_show_time = help_show_time_;
|
||||
settings::double_click_time = double_click_time_;
|
||||
settings::repeat_button_repeat_time = repeat_button_repeat_time_;
|
||||
settings::sound_button_click = sound_button_click_;
|
||||
settings::sound_toggle_button_click = sound_toggle_button_click_;
|
||||
settings::sound_toggle_panel_click = sound_toggle_panel_click_;
|
||||
|
@ -854,6 +865,40 @@ tpanel_definition::tresolution::tresolution(const config& cfg) :
|
|||
state.push_back(tstate_definition(cfg.child("foreground")));
|
||||
}
|
||||
|
||||
trepeating_button_definition::trepeating_button_definition(const config& cfg) :
|
||||
tcontrol_definition(cfg)
|
||||
{
|
||||
DBG_GUI_P << "Parsing repeating button " << id << '\n';
|
||||
|
||||
load_resolutions<tresolution>(cfg);
|
||||
}
|
||||
|
||||
trepeating_button_definition::tresolution::tresolution(const config& cfg) :
|
||||
tresolution_definition_(cfg)
|
||||
{
|
||||
/*WIKI
|
||||
* @page = GUIWidgetDefinitionWML
|
||||
* @order = 1_repeating_button
|
||||
*
|
||||
* == Repeating button ==
|
||||
*
|
||||
* @macro = repeating_button_description
|
||||
*
|
||||
* The following states exist:
|
||||
* * state_enabled, the repeating_button is enabled.
|
||||
* * state_disabled, the repeating_button is disabled.
|
||||
* * state_pressed, the left mouse repeating_button is down.
|
||||
* * state_focussed, the mouse is over the repeating_button.
|
||||
*
|
||||
*/
|
||||
// Note the order should be the same as the enum tstate in
|
||||
// repeating_button.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")));
|
||||
}
|
||||
|
||||
tscroll_label_definition::tscroll_label_definition(const config& cfg) :
|
||||
tcontrol_definition(cfg)
|
||||
{
|
||||
|
|
|
@ -233,6 +233,18 @@ struct tpanel_definition : public tcontrol_definition
|
|||
};
|
||||
};
|
||||
|
||||
struct trepeating_button_definition
|
||||
: public tcontrol_definition
|
||||
{
|
||||
trepeating_button_definition(const config& cfg);
|
||||
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
tresolution(const config& cfg);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
struct tscroll_label_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
|
@ -393,6 +405,7 @@ struct tgui_definition
|
|||
, popup_show_time_(0)
|
||||
, help_show_time_(0)
|
||||
, double_click_time_(0)
|
||||
, repeat_button_repeat_time_(0)
|
||||
, sound_button_click_()
|
||||
, sound_toggle_button_click_()
|
||||
, sound_toggle_panel_click_()
|
||||
|
@ -426,6 +439,7 @@ private:
|
|||
unsigned popup_show_time_;
|
||||
unsigned help_show_time_;
|
||||
unsigned double_click_time_;
|
||||
unsigned repeat_button_repeat_time_;
|
||||
|
||||
std::string sound_button_click_;
|
||||
std::string sound_toggle_button_click_;
|
||||
|
@ -465,6 +479,7 @@ private:
|
|||
extern unsigned popup_show_time;
|
||||
extern unsigned help_show_time;
|
||||
extern unsigned double_click_time;
|
||||
extern unsigned repeat_button_repeat_time;
|
||||
|
||||
extern std::string sound_button_click;
|
||||
extern std::string sound_toggle_button_click;
|
||||
|
|
Loading…
Add table
Reference in a new issue