Use clang-format on the gui directory.
Most of the formatting has been done automatically, but some minor manual polishing has been applied afterwards. Also add .clang-format file containing the settings used for the formatting.
This commit is contained in:
parent
2cc2f3b248
commit
e5253f3265
347 changed files with 10449 additions and 9792 deletions
45
src/.clang-format
Normal file
45
src/.clang-format
Normal file
|
@ -0,0 +1,45 @@
|
|||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
BreakBeforeBinaryOperators: true
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
BinPackParameters: false
|
||||
ColumnLimit: 80
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
DerivePointerBinding: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
IndentCaseLabels: true
|
||||
MaxEmptyLinesToKeep: 100
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerBindsToType: true
|
||||
SpacesBeforeTrailingComments: 1
|
||||
Cpp11BracedListStyle: false
|
||||
Standard: Cpp03
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Always
|
||||
BreakBeforeBraces: Linux
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInAngles: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
ContinuationIndentWidth: 8
|
||||
SpaceBeforeParens: Never
|
|
@ -32,9 +32,11 @@
|
|||
#include "utils/foreach.tpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
|
||||
/*WIKI
|
||||
* @page = GUICanvasWML
|
||||
|
@ -92,14 +94,13 @@ namespace {
|
|||
* @param x The x coordinate of the pixel to draw.
|
||||
* @param y The y coordinate of the pixel to draw.
|
||||
*/
|
||||
static void put_pixel(
|
||||
const ptrdiff_t start
|
||||
, const Uint32 color
|
||||
, const unsigned w
|
||||
, const unsigned x
|
||||
, const unsigned y)
|
||||
static void put_pixel(const ptrdiff_t start,
|
||||
const Uint32 color,
|
||||
const unsigned w,
|
||||
const unsigned x,
|
||||
const unsigned y)
|
||||
{
|
||||
*reinterpret_cast<Uint32*>(start + (y * w * 4) + x * 4) = color;
|
||||
*reinterpret_cast<Uint32*>(start + (y* w* 4) + x* 4) = color;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,27 +119,25 @@ static void put_pixel(
|
|||
* @param x2 The end x coordinate of the line to draw.
|
||||
* @param y2 The end y coordinate of the line to draw.
|
||||
*/
|
||||
static void draw_line(
|
||||
surface& canvas
|
||||
, Uint32 color
|
||||
, unsigned x1
|
||||
, unsigned y1
|
||||
, const unsigned x2
|
||||
, unsigned y2)
|
||||
static void draw_line(surface& canvas,
|
||||
Uint32 color,
|
||||
unsigned x1,
|
||||
unsigned y1,
|
||||
const unsigned x2,
|
||||
unsigned y2)
|
||||
{
|
||||
color = SDL_MapRGBA(canvas->format,
|
||||
((color & 0xFF000000) >> 24),
|
||||
((color & 0x00FF0000) >> 16),
|
||||
((color & 0x0000FF00) >> 8),
|
||||
((color & 0x000000FF)));
|
||||
((color & 0xFF000000) >> 24),
|
||||
((color & 0x00FF0000) >> 16),
|
||||
((color & 0x0000FF00) >> 8),
|
||||
((color & 0x000000FF)));
|
||||
|
||||
ptrdiff_t start = reinterpret_cast<ptrdiff_t>(canvas->pixels);
|
||||
unsigned w = canvas->w;
|
||||
|
||||
DBG_GUI_D << "Shape: draw line from "
|
||||
<< x1 << ',' << y1 << " to " << x2 << ',' << y2
|
||||
<< " canvas width " << w << " canvas height "
|
||||
<< canvas->h << ".\n";
|
||||
DBG_GUI_D << "Shape: draw line from " << x1 << ',' << y1 << " to " << x2
|
||||
<< ',' << y2 << " canvas width " << w << " canvas height "
|
||||
<< canvas->h << ".\n";
|
||||
|
||||
assert(static_cast<int>(x1) < canvas->w);
|
||||
assert(static_cast<int>(x2) < canvas->w);
|
||||
|
@ -159,7 +158,7 @@ static void draw_line(
|
|||
|
||||
// use a special case for horizontal lines
|
||||
if(y1 == y2) {
|
||||
for(unsigned x = x1; x <= x2; ++x) {
|
||||
for(unsigned x = x1; x <= x2; ++x) {
|
||||
put_pixel(start, color, w, x, y1);
|
||||
}
|
||||
return;
|
||||
|
@ -175,7 +174,7 @@ static void draw_line(
|
|||
int err = (dx > dy ? dx : -dy) / 2;
|
||||
int e2;
|
||||
|
||||
for(;;){
|
||||
for(;;) {
|
||||
put_pixel(start, color, w, x1, y1);
|
||||
if(x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
|
@ -185,7 +184,7 @@ static void draw_line(
|
|||
err -= dy;
|
||||
x1 += step_x;
|
||||
}
|
||||
if(e2 < dy) {
|
||||
if(e2 < dy) {
|
||||
err += dx;
|
||||
y1 += step_y;
|
||||
}
|
||||
|
@ -205,27 +204,24 @@ static void draw_line(
|
|||
* @param y_center The y coordinate of the center of the circle to draw.
|
||||
* @param radius The radius of the circle to draw.
|
||||
*/
|
||||
static void draw_circle(
|
||||
surface& canvas
|
||||
, Uint32 color
|
||||
, const unsigned x_center
|
||||
, const unsigned y_center
|
||||
, const unsigned radius)
|
||||
static void draw_circle(surface& canvas,
|
||||
Uint32 color,
|
||||
const unsigned x_center,
|
||||
const unsigned y_center,
|
||||
const unsigned radius)
|
||||
{
|
||||
color = SDL_MapRGBA(canvas->format,
|
||||
((color & 0xFF000000) >> 24),
|
||||
((color & 0x00FF0000) >> 16),
|
||||
((color & 0x0000FF00) >> 8),
|
||||
((color & 0x000000FF)));
|
||||
((color & 0xFF000000) >> 24),
|
||||
((color & 0x00FF0000) >> 16),
|
||||
((color & 0x0000FF00) >> 8),
|
||||
((color & 0x000000FF)));
|
||||
|
||||
ptrdiff_t start = reinterpret_cast<ptrdiff_t>(canvas->pixels);
|
||||
unsigned w = canvas->w;
|
||||
|
||||
DBG_GUI_D << "Shape: draw circle at "
|
||||
<< x_center << ',' << y_center
|
||||
<< " with radius " << radius
|
||||
<< " canvas width " << w << " canvas height "
|
||||
<< canvas->h << ".\n";
|
||||
DBG_GUI_D << "Shape: draw circle at " << x_center << ',' << y_center
|
||||
<< " with radius " << radius << " canvas width " << w
|
||||
<< " canvas height " << canvas->h << ".\n";
|
||||
|
||||
assert(static_cast<int>(x_center + radius) < canvas->w);
|
||||
assert(static_cast<int>(x_center - radius) >= 0);
|
||||
|
@ -261,11 +257,9 @@ static void draw_circle(
|
|||
/***** ***** ***** ***** ***** LINE ***** ***** ***** ***** *****/
|
||||
|
||||
/** Definition of a line shape. */
|
||||
class tline
|
||||
: public tcanvas::tshape
|
||||
class tline : public tcanvas::tshape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -276,15 +270,14 @@ public:
|
|||
explicit tline(const config& cfg);
|
||||
|
||||
/** Implement shape::draw(). */
|
||||
void draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables);
|
||||
void draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables);
|
||||
|
||||
private:
|
||||
tformula<unsigned>
|
||||
x1_, /**< The start x coordinate of the line. */
|
||||
y1_, /**< The start y coordinate of the line. */
|
||||
x2_, /**< The end x coordinate of the line. */
|
||||
y2_; /**< The end y coordinate of the line. */
|
||||
tformula<unsigned> x1_, /**< The start x coordinate of the line. */
|
||||
y1_, /**< The start y coordinate of the line. */
|
||||
x2_, /**< The end x coordinate of the line. */
|
||||
y2_; /**< The end y coordinate of the line. */
|
||||
|
||||
/** The color of the line. */
|
||||
Uint32 color_;
|
||||
|
@ -626,8 +619,8 @@ tline::tline(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void tline::draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables)
|
||||
void tline::draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
{
|
||||
/**
|
||||
* @todo formulas are now recalculated every draw cycle which is a bit silly
|
||||
|
@ -640,16 +633,15 @@ void tline::draw(surface& canvas
|
|||
const unsigned x2 = x2_(variables);
|
||||
const unsigned y2 = y2_(variables);
|
||||
|
||||
DBG_GUI_D << "Line: draw from "
|
||||
<< x1 << ',' << y1 << " to " << x2 << ',' << y2
|
||||
<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";
|
||||
DBG_GUI_D << "Line: draw from " << x1 << ',' << y1 << " to " << x2 << ','
|
||||
<< y2 << " canvas size " << canvas->w << ',' << canvas->h
|
||||
<< ".\n";
|
||||
|
||||
VALIDATE(
|
||||
static_cast<int>(x1) < canvas->w
|
||||
&& static_cast<int>(x2) < canvas->w
|
||||
&& static_cast<int>(y1) < canvas->h
|
||||
&& static_cast<int>(y2) < canvas->h
|
||||
, _("Line doesn't fit on canvas."));
|
||||
VALIDATE(static_cast<int>(x1) < canvas->w
|
||||
&& static_cast<int>(x2) < canvas->w
|
||||
&& static_cast<int>(y1) < canvas->h
|
||||
&& static_cast<int>(y2) < canvas->h,
|
||||
_("Line doesn't fit on canvas."));
|
||||
|
||||
// @todo FIXME respect the thickness.
|
||||
|
||||
|
@ -669,11 +661,9 @@ void tline::draw(surface& canvas
|
|||
/***** ***** ***** ***** ***** Rectangle ***** ***** ***** ***** *****/
|
||||
|
||||
/** Definition of a rectangle shape. */
|
||||
class trectangle
|
||||
: public tcanvas::tshape
|
||||
class trectangle : public tcanvas::tshape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -684,15 +674,14 @@ public:
|
|||
explicit trectangle(const config& cfg);
|
||||
|
||||
/** Implement shape::draw(). */
|
||||
void draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables);
|
||||
void draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables);
|
||||
|
||||
private:
|
||||
tformula<unsigned>
|
||||
x_, /**< The x coordinate of the rectangle. */
|
||||
y_, /**< The y coordinate of the rectangle. */
|
||||
w_, /**< The width of the rectangle. */
|
||||
h_; /**< The height of the rectangle. */
|
||||
tformula<unsigned> x_, /**< The x coordinate of the rectangle. */
|
||||
y_, /**< The y coordinate of the rectangle. */
|
||||
w_, /**< The width of the rectangle. */
|
||||
h_; /**< The height of the rectangle. */
|
||||
|
||||
/**
|
||||
* Border thickness.
|
||||
|
@ -768,8 +757,8 @@ trectangle::trectangle(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void trectangle::draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables)
|
||||
void trectangle::draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
{
|
||||
/**
|
||||
* @todo formulas are now recalculated every draw cycle which is a bit
|
||||
|
@ -781,16 +770,15 @@ void trectangle::draw(surface& canvas
|
|||
const unsigned w = w_(variables);
|
||||
const unsigned h = h_(variables);
|
||||
|
||||
DBG_GUI_D << "Rectangle: draw from " << x << ',' << y
|
||||
<< " width " << w << " height " << h
|
||||
<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";
|
||||
DBG_GUI_D << "Rectangle: draw from " << x << ',' << y << " width " << w
|
||||
<< " height " << h << " canvas size " << canvas->w << ','
|
||||
<< canvas->h << ".\n";
|
||||
|
||||
VALIDATE(
|
||||
static_cast<int>(x) < canvas->w
|
||||
&& static_cast<int>(x + w) <= canvas->w
|
||||
&& static_cast<int>(y) < canvas->h
|
||||
&& static_cast<int>(y + h) <= canvas->h
|
||||
, _("Rectangle doesn't fit on canvas."));
|
||||
VALIDATE(static_cast<int>(x) < canvas->w
|
||||
&& static_cast<int>(x + w) <= canvas->w
|
||||
&& static_cast<int>(y) < canvas->h
|
||||
&& static_cast<int>(y + h) <= canvas->h,
|
||||
_("Rectangle doesn't fit on canvas."));
|
||||
|
||||
|
||||
surface_lock locker(canvas);
|
||||
|
@ -835,11 +823,9 @@ void trectangle::draw(surface& canvas
|
|||
/***** ***** ***** ***** ***** CIRCLE ***** ***** ***** ***** *****/
|
||||
|
||||
/** Definition of a circle shape. */
|
||||
class tcircle
|
||||
: public tcanvas::tshape
|
||||
class tcircle : public tcanvas::tshape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -850,18 +836,16 @@ public:
|
|||
explicit tcircle(const config& cfg);
|
||||
|
||||
/** Implement shape::draw(). */
|
||||
void draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables);
|
||||
void draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables);
|
||||
|
||||
private:
|
||||
tformula<unsigned>
|
||||
x_, /**< The center x coordinate of the circle. */
|
||||
y_, /**< The center y coordinate of the circle. */
|
||||
radius_; /**< The radius of the circle. */
|
||||
tformula<unsigned> x_, /**< The center x coordinate of the circle. */
|
||||
y_, /**< The center y coordinate of the circle. */
|
||||
radius_; /**< The radius of the circle. */
|
||||
|
||||
/** The color of the circle. */
|
||||
Uint32 color_;
|
||||
|
||||
};
|
||||
|
||||
/*WIKI
|
||||
|
@ -903,8 +887,8 @@ tcircle::tcircle(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void tcircle::draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables)
|
||||
void tcircle::draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
{
|
||||
/**
|
||||
* @todo formulas are now recalculated every draw cycle which is a bit
|
||||
|
@ -916,31 +900,30 @@ void tcircle::draw(surface& canvas
|
|||
const unsigned y = y_(variables);
|
||||
const unsigned radius = radius_(variables);
|
||||
|
||||
DBG_GUI_D << "Circle: drawn at "
|
||||
<< x << ',' << y << " radius " << radius
|
||||
<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";
|
||||
DBG_GUI_D << "Circle: drawn at " << x << ',' << y << " radius " << radius
|
||||
<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";
|
||||
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(x - radius) >= 0
|
||||
, _("Circle doesn't fit on canvas.")
|
||||
, (formatter() << "x = " << x << ", radius = " << radius).str());
|
||||
static_cast<int>(x - radius) >= 0,
|
||||
_("Circle doesn't fit on canvas."),
|
||||
(formatter() << "x = " << x << ", radius = " << radius).str());
|
||||
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(y - radius) >= 0
|
||||
, _("Circle doesn't fit on canvas.")
|
||||
, (formatter() << "y = " << y << ", radius = " << radius).str());
|
||||
static_cast<int>(y - radius) >= 0,
|
||||
_("Circle doesn't fit on canvas."),
|
||||
(formatter() << "y = " << y << ", radius = " << radius).str());
|
||||
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(x + radius) < canvas->w
|
||||
, _("Circle doesn't fit on canvas.")
|
||||
, (formatter() << "x = " << x << ", radius = " << radius
|
||||
<< "', canvas width = " << canvas->w << ".").str());
|
||||
static_cast<int>(x + radius) < canvas->w,
|
||||
_("Circle doesn't fit on canvas."),
|
||||
(formatter() << "x = " << x << ", radius = " << radius
|
||||
<< "', canvas width = " << canvas->w << ".").str());
|
||||
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(y + radius) < canvas->h
|
||||
, _("Circle doesn't fit on canvas.")
|
||||
, (formatter() << "y = " << y << ", radius = " << radius
|
||||
<< "', canvas height = " << canvas->h << ".").str());
|
||||
static_cast<int>(y + radius) < canvas->h,
|
||||
_("Circle doesn't fit on canvas."),
|
||||
(formatter() << "y = " << y << ", radius = " << radius
|
||||
<< "', canvas height = " << canvas->h << ".").str());
|
||||
|
||||
// lock the surface
|
||||
surface_lock locker(canvas);
|
||||
|
@ -950,11 +933,9 @@ void tcircle::draw(surface& canvas
|
|||
/***** ***** ***** ***** ***** IMAGE ***** ***** ***** ***** *****/
|
||||
|
||||
/** Definition of an image shape. */
|
||||
class timage
|
||||
: public tcanvas::tshape
|
||||
class timage : public tcanvas::tshape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -965,15 +946,14 @@ public:
|
|||
explicit timage(const config& cfg);
|
||||
|
||||
/** Implement shape::draw(). */
|
||||
void draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables);
|
||||
void draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables);
|
||||
|
||||
private:
|
||||
tformula<unsigned>
|
||||
x_, /**< The x coordinate of the image. */
|
||||
y_, /**< The y coordinate of the image. */
|
||||
w_, /**< The width of the image. */
|
||||
h_; /**< The height of the image. */
|
||||
tformula<unsigned> x_, /**< The x coordinate of the image. */
|
||||
y_, /**< The y coordinate of the image. */
|
||||
w_, /**< The width of the image. */
|
||||
h_; /**< The height of the image. */
|
||||
|
||||
/** Contains the size of the image. */
|
||||
SDL_Rect src_clip_;
|
||||
|
@ -999,9 +979,9 @@ private:
|
|||
* by the value of this enum.
|
||||
*/
|
||||
enum tresize_mode {
|
||||
scale
|
||||
, stretch
|
||||
, tile
|
||||
scale,
|
||||
stretch,
|
||||
tile
|
||||
};
|
||||
|
||||
/** Converts a string to a resize mode. */
|
||||
|
@ -1087,8 +1067,8 @@ timage::timage(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void timage::draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables)
|
||||
void timage::draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
{
|
||||
DBG_GUI_D << "Image: draw.\n";
|
||||
|
||||
|
@ -1124,35 +1104,35 @@ void timage::draw(surface& canvas
|
|||
local_variables.add("image_original_height", variant(image_->h));
|
||||
|
||||
unsigned w = w_(local_variables);
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(w) >= 0
|
||||
, _("Image doesn't fit on canvas.")
|
||||
, (formatter() << "Image '" << name
|
||||
<< "', w = " << static_cast<int>(w) << ".").str());
|
||||
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(w) >= 0,
|
||||
_("Image doesn't fit on canvas."),
|
||||
(formatter() << "Image '" << name
|
||||
<< "', w = " << static_cast<int>(w)
|
||||
<< ".").str());
|
||||
|
||||
unsigned h = h_(local_variables);
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(h) >= 0
|
||||
, _("Image doesn't fit on canvas.")
|
||||
, (formatter() << "Image '" << name
|
||||
<< "', h = " << static_cast<int>(h) << ".").str());
|
||||
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(h) >= 0,
|
||||
_("Image doesn't fit on canvas."),
|
||||
(formatter() << "Image '" << name
|
||||
<< "', h = " << static_cast<int>(h)
|
||||
<< ".").str());
|
||||
|
||||
local_variables.add("image_width", variant(w ? w : image_->w));
|
||||
local_variables.add("image_height", variant(h ? h : image_->h));
|
||||
|
||||
const unsigned x = x_(local_variables);
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(x) >= 0
|
||||
, _("Image doesn't fit on canvas.")
|
||||
, (formatter() << "Image '" << name
|
||||
<< "', x = " << static_cast<int>(x) << ".").str());
|
||||
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(x) >= 0,
|
||||
_("Image doesn't fit on canvas."),
|
||||
(formatter() << "Image '" << name
|
||||
<< "', x = " << static_cast<int>(x)
|
||||
<< ".").str());
|
||||
|
||||
const unsigned y = y_(local_variables);
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
static_cast<int>(y) >= 0
|
||||
, _("Image doesn't fit on canvas.")
|
||||
, (formatter() << "Image '" << name
|
||||
<< "', y = " << static_cast<int>(y) << ".").str());
|
||||
VALIDATE_WITH_DEV_MESSAGE(static_cast<int>(y) >= 0,
|
||||
_("Image doesn't fit on canvas."),
|
||||
(formatter() << "Image '" << name
|
||||
<< "', y = " << static_cast<int>(y)
|
||||
<< ".").str());
|
||||
|
||||
// Copy the data to local variables to avoid overwriting the originals.
|
||||
SDL_Rect src_clip = src_clip_;
|
||||
|
@ -1165,8 +1145,8 @@ void timage::draw(surface& canvas
|
|||
bool stretch_image = (resize_mode_ == stretch) && (!!w ^ !!h);
|
||||
if(!w) {
|
||||
if(stretch_image) {
|
||||
DBG_GUI_D << "Image: vertical stretch from " << image_->w
|
||||
<< ',' << image_->h << " to a height of " << h << ".\n";
|
||||
DBG_GUI_D << "Image: vertical stretch from " << image_->w << ','
|
||||
<< image_->h << " to a height of " << h << ".\n";
|
||||
|
||||
surf = stretch_surface_vertical(image_, h, false);
|
||||
done = true;
|
||||
|
@ -1177,7 +1157,8 @@ void timage::draw(surface& canvas
|
|||
if(!h) {
|
||||
if(stretch_image) {
|
||||
DBG_GUI_D << "Image: horizontal stretch from " << image_->w
|
||||
<< ',' << image_->h << " to a width of " << w << ".\n";
|
||||
<< ',' << image_->h << " to a width of " << w
|
||||
<< ".\n";
|
||||
|
||||
surf = stretch_surface_horizontal(image_, w, false);
|
||||
done = true;
|
||||
|
@ -1188,8 +1169,8 @@ void timage::draw(surface& canvas
|
|||
if(!done) {
|
||||
|
||||
if(resize_mode_ == tile) {
|
||||
DBG_GUI_D << "Image: tiling from " << image_->w
|
||||
<< ',' << image_->h << " to " << w << ',' << h << ".\n";
|
||||
DBG_GUI_D << "Image: tiling from " << image_->w << ','
|
||||
<< image_->h << " to " << w << ',' << h << ".\n";
|
||||
|
||||
const int columns = (w + image_->w - 1) / image_->w;
|
||||
const int rows = (h + image_->h - 1) / image_->h;
|
||||
|
@ -1198,10 +1179,7 @@ void timage::draw(surface& canvas
|
|||
for(int x = 0; x < columns; ++x) {
|
||||
for(int y = 0; y < rows; ++y) {
|
||||
const SDL_Rect dest = ::create_rect(
|
||||
x * image_->w
|
||||
, y * image_->h
|
||||
, 0
|
||||
, 0);
|
||||
x * image_->w, y * image_->h, 0, 0);
|
||||
blit_surface(image_, NULL, surf, &dest);
|
||||
}
|
||||
}
|
||||
|
@ -1209,11 +1187,11 @@ void timage::draw(surface& canvas
|
|||
} else {
|
||||
if(resize_mode_ == stretch) {
|
||||
ERR_GUI_D << "Image: failed to stretch image, "
|
||||
"fall back to scaling.\n";
|
||||
"fall back to scaling.\n";
|
||||
}
|
||||
|
||||
DBG_GUI_D << "Image: scaling from " << image_->w
|
||||
<< ',' << image_->h << " to " << w << ',' << h << ".\n";
|
||||
DBG_GUI_D << "Image: scaling from " << image_->w << ','
|
||||
<< image_->h << " to " << w << ',' << h << ".\n";
|
||||
|
||||
surf = scale_surface(image_, w, h, false);
|
||||
}
|
||||
|
@ -1239,8 +1217,8 @@ timage::tresize_mode timage::get_resize_mode(const std::string& resize_mode)
|
|||
return timage::stretch;
|
||||
} else {
|
||||
if(!resize_mode.empty() && resize_mode != "scale") {
|
||||
ERR_GUI_E << "Invalid resize mode '"
|
||||
<< resize_mode << "' falling back to 'scale'.\n";
|
||||
ERR_GUI_E << "Invalid resize mode '" << resize_mode
|
||||
<< "' falling back to 'scale'.\n";
|
||||
}
|
||||
return timage::scale;
|
||||
}
|
||||
|
@ -1249,11 +1227,9 @@ timage::tresize_mode timage::get_resize_mode(const std::string& resize_mode)
|
|||
/***** ***** ***** ***** ***** TEXT ***** ***** ***** ***** *****/
|
||||
|
||||
/** Definition of a text shape. */
|
||||
class ttext
|
||||
: public tcanvas::tshape
|
||||
class ttext : public tcanvas::tshape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -1264,15 +1240,14 @@ public:
|
|||
explicit ttext(const config& cfg);
|
||||
|
||||
/** Implement shape::draw(). */
|
||||
void draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables);
|
||||
void draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables);
|
||||
|
||||
private:
|
||||
tformula<unsigned>
|
||||
x_, /**< The x coordinate of the text. */
|
||||
y_, /**< The y coordinate of the text. */
|
||||
w_, /**< The width of the text. */
|
||||
h_; /**< The height of the text. */
|
||||
tformula<unsigned> x_, /**< The x coordinate of the text. */
|
||||
y_, /**< The y coordinate of the text. */
|
||||
w_, /**< The width of the text. */
|
||||
h_; /**< The height of the text. */
|
||||
|
||||
/** The font size of the text. */
|
||||
unsigned font_size_;
|
||||
|
@ -1370,8 +1345,8 @@ ttext::ttext(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void ttext::draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables)
|
||||
void ttext::draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
{
|
||||
assert(variables.has_key("text"));
|
||||
|
||||
|
@ -1394,29 +1369,31 @@ void ttext::draw(surface& canvas
|
|||
.set_foreground_color(color_)
|
||||
.set_maximum_width(maximum_width_(variables))
|
||||
.set_maximum_height(maximum_height_(variables), true)
|
||||
.set_ellipse_mode(variables.has_key("text_wrap_mode")
|
||||
? static_cast<PangoEllipsizeMode>
|
||||
(variables.query_value("text_wrap_mode").as_int())
|
||||
: PANGO_ELLIPSIZE_END)
|
||||
.set_ellipse_mode(
|
||||
variables.has_key("text_wrap_mode")
|
||||
? static_cast<PangoEllipsizeMode>(
|
||||
variables.query_value("text_wrap_mode")
|
||||
.as_int())
|
||||
: PANGO_ELLIPSIZE_END)
|
||||
.set_characters_per_line(characters_per_line_);
|
||||
|
||||
surface surf = text_renderer.render();
|
||||
if(surf->w == 0) {
|
||||
DBG_GUI_D << "Text: Rendering '"
|
||||
<< text << "' resulted in an empty canvas, leave.\n";
|
||||
DBG_GUI_D << "Text: Rendering '" << text
|
||||
<< "' resulted in an empty canvas, leave.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
game_logic::map_formula_callable local_variables(variables);
|
||||
local_variables.add("text_width", variant(surf->w));
|
||||
local_variables.add("text_height", variant(surf->h));
|
||||
/*
|
||||
std::cerr << "Text: drawing text '" << text
|
||||
<< " maximum width " << maximum_width_(variables)
|
||||
<< " maximum height " << maximum_height_(variables)
|
||||
<< " text width " << surf->w
|
||||
<< " text height " << surf->h;
|
||||
*/
|
||||
/*
|
||||
std::cerr << "Text: drawing text '" << text
|
||||
<< " maximum width " << maximum_width_(variables)
|
||||
<< " maximum height " << maximum_height_(variables)
|
||||
<< " text width " << surf->w
|
||||
<< " text height " << surf->h;
|
||||
*/
|
||||
///@todo formulas are now recalculated every draw cycle which is a
|
||||
// bit silly unless there has been a resize. So to optimize we should
|
||||
// use an extra flag or do the calculation in a separate routine.
|
||||
|
@ -1426,23 +1403,22 @@ void ttext::draw(surface& canvas
|
|||
const unsigned w = w_(local_variables);
|
||||
const unsigned h = h_(local_variables);
|
||||
|
||||
DBG_GUI_D << "Text: drawing text '" << text
|
||||
<< "' drawn from " << x << ',' << y
|
||||
<< " width " << w << " height " << h
|
||||
<< " canvas size " << canvas->w << ',' << canvas->h << ".\n";
|
||||
DBG_GUI_D << "Text: drawing text '" << text << "' drawn from " << x << ','
|
||||
<< y << " width " << w << " height " << h << " canvas size "
|
||||
<< canvas->w << ',' << canvas->h << ".\n";
|
||||
|
||||
VALIDATE(static_cast<int>(x) < canvas->w && static_cast<int>(y) < canvas->h
|
||||
, _("Text doesn't start on canvas."));
|
||||
VALIDATE(static_cast<int>(x) < canvas->w && static_cast<int>(y) < canvas->h,
|
||||
_("Text doesn't start on canvas."));
|
||||
|
||||
// A text might be to long and will be clipped.
|
||||
if(surf->w > static_cast<int>(w)) {
|
||||
WRN_GUI_D << "Text: text is too wide for the "
|
||||
"canvas and will be clipped.\n";
|
||||
"canvas and will be clipped.\n";
|
||||
}
|
||||
|
||||
if(surf->h > static_cast<int>(h)) {
|
||||
WRN_GUI_D << "Text: text is too high for the "
|
||||
"canvas and will be clipped.\n";
|
||||
"canvas and will be clipped.\n";
|
||||
}
|
||||
|
||||
SDL_Rect dst = ::create_rect(x, y, canvas->w, canvas->h);
|
||||
|
@ -1474,8 +1450,8 @@ void tcanvas::draw(const bool force)
|
|||
|
||||
if(is_dirty_) {
|
||||
get_screen_size_variables(variables_);
|
||||
variables_.add("width",variant(w_));
|
||||
variables_.add("height",variant(h_));
|
||||
variables_.add("width", variant(w_));
|
||||
variables_.add("height", variant(h_));
|
||||
}
|
||||
|
||||
// create surface
|
||||
|
@ -1483,8 +1459,9 @@ void tcanvas::draw(const bool force)
|
|||
canvas_.assign(create_neutral_surface(w_, h_));
|
||||
|
||||
// draw items
|
||||
for(std::vector<tshape_ptr>::iterator itor =
|
||||
shapes_.begin(); itor != shapes_.end(); ++itor) {
|
||||
for(std::vector<tshape_ptr>::iterator itor = shapes_.begin();
|
||||
itor != shapes_.end();
|
||||
++itor) {
|
||||
log_scope2(log_gui_draw, "Canvas: draw shape.");
|
||||
|
||||
(*itor)->draw(canvas_, variables_);
|
||||
|
@ -1517,9 +1494,10 @@ void tcanvas::parse_cfg(const config& cfg)
|
|||
log_scope2(log_gui_parse, "Canvas: parsing config.");
|
||||
shapes_.clear();
|
||||
|
||||
FOREACH(const AUTO& shape, cfg.all_children_range()) {
|
||||
const std::string &type = shape.key;
|
||||
const config &data = shape.cfg;
|
||||
FOREACH(const AUTO & shape, cfg.all_children_range())
|
||||
{
|
||||
const std::string& type = shape.key;
|
||||
const config& data = shape.cfg;
|
||||
|
||||
DBG_GUI_P << "Canvas: found shape of the type " << type << ".\n";
|
||||
|
||||
|
@ -1536,19 +1514,20 @@ void tcanvas::parse_cfg(const config& cfg)
|
|||
} else if(type == "pre_commit") {
|
||||
|
||||
/* note this should get split if more preprocessing is used. */
|
||||
FOREACH(const AUTO& function, data.all_children_range()) {
|
||||
FOREACH(const AUTO & function, data.all_children_range())
|
||||
{
|
||||
|
||||
if(function.key == "blur") {
|
||||
blur_depth_ = function.cfg["depth"];
|
||||
} else {
|
||||
ERR_GUI_P << "Canvas: found a pre commit function"
|
||||
<< " of an invalid type " << type << ".\n";
|
||||
<< " of an invalid type " << type << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
ERR_GUI_P << "Canvas: found a shape of an invalid type "
|
||||
<< type << ".\n";
|
||||
ERR_GUI_P << "Canvas: found a shape of an invalid type " << type
|
||||
<< ".\n";
|
||||
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
class config;
|
||||
class variant;
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* A simple canvas which can be drawn upon.
|
||||
|
@ -43,7 +44,6 @@ namespace gui2 {
|
|||
class tcanvas
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Abstract base class for all other shapes.
|
||||
*
|
||||
|
@ -53,7 +53,9 @@ public:
|
|||
class tshape : public reference_counted_object
|
||||
{
|
||||
public:
|
||||
virtual ~tshape() {}
|
||||
virtual ~tshape()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the canvas.
|
||||
|
@ -64,8 +66,9 @@ public:
|
|||
* definition, this parameter contains the values
|
||||
* for these formulas.
|
||||
*/
|
||||
virtual void draw(surface& canvas
|
||||
, const game_logic::map_formula_callable& variables) = 0;
|
||||
virtual void draw(surface& canvas,
|
||||
const game_logic::map_formula_callable& variables)
|
||||
= 0;
|
||||
};
|
||||
|
||||
typedef boost::intrusive_ptr<tshape> tshape_ptr;
|
||||
|
@ -99,17 +102,37 @@ public:
|
|||
* http://www.wesnoth.org/wiki/GUICanvasWML for
|
||||
* more information.
|
||||
*/
|
||||
void set_cfg(const config& cfg) { parse_cfg(cfg); }
|
||||
void set_cfg(const config& cfg)
|
||||
{
|
||||
parse_cfg(cfg);
|
||||
}
|
||||
|
||||
/***** ***** ***** setters / getters for members ***** ****** *****/
|
||||
|
||||
void set_width(const unsigned width) { w_ = width; set_is_dirty(true); }
|
||||
unsigned get_width() const { return w_; }
|
||||
void set_width(const unsigned width)
|
||||
{
|
||||
w_ = width;
|
||||
set_is_dirty(true);
|
||||
}
|
||||
unsigned get_width() const
|
||||
{
|
||||
return w_;
|
||||
}
|
||||
|
||||
void set_height(const unsigned height) { h_ = height; set_is_dirty(true); }
|
||||
unsigned get_height() const { return h_; }
|
||||
void set_height(const unsigned height)
|
||||
{
|
||||
h_ = height;
|
||||
set_is_dirty(true);
|
||||
}
|
||||
unsigned get_height() const
|
||||
{
|
||||
return h_;
|
||||
}
|
||||
|
||||
surface& surf() { return canvas_; }
|
||||
surface& surf()
|
||||
{
|
||||
return canvas_;
|
||||
}
|
||||
|
||||
void set_variable(const std::string& key, const variant& value)
|
||||
{
|
||||
|
@ -146,7 +169,10 @@ private:
|
|||
/** The dirty state of the canvas. */
|
||||
bool is_dirty_;
|
||||
|
||||
void set_is_dirty(const bool is_dirty) { is_dirty_ = is_dirty; }
|
||||
void set_is_dirty(const bool is_dirty)
|
||||
{
|
||||
is_dirty_ = is_dirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a config object.
|
||||
|
@ -164,4 +190,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
/***** tdispatcher class. *****/
|
||||
|
||||
|
@ -51,9 +53,7 @@ void tdispatcher::connect()
|
|||
connect_dispatcher(this);
|
||||
}
|
||||
|
||||
bool tdispatcher::has_event(const tevent event
|
||||
, const tevent_type event_type
|
||||
)
|
||||
bool tdispatcher::has_event(const tevent event, const tevent_type event_type)
|
||||
{
|
||||
#if 0
|
||||
// Debug code to test whether the event is in the right queue.
|
||||
|
@ -76,17 +76,23 @@ bool tdispatcher::has_event(const tevent event
|
|||
<< ".\n";
|
||||
#endif
|
||||
|
||||
return find<tset_event>(event, tdispatcher_implementation
|
||||
::thas_handler(event_type, *this))
|
||||
|| find<tset_event_mouse>(event, tdispatcher_implementation
|
||||
::thas_handler(event_type, *this))
|
||||
|| find<tset_event_keyboard>(event, tdispatcher_implementation
|
||||
::thas_handler(event_type, *this))
|
||||
|| find<tset_event_notification>(event, tdispatcher_implementation
|
||||
::thas_handler(event_type, *this))
|
||||
|| find<tset_event_message>(event, tdispatcher_implementation
|
||||
::thas_handler(event_type, *this))
|
||||
;
|
||||
return find<tset_event>(
|
||||
event,
|
||||
tdispatcher_implementation::thas_handler(event_type, *this))
|
||||
|| find<tset_event_mouse>(event,
|
||||
tdispatcher_implementation::thas_handler(
|
||||
event_type, *this))
|
||||
|| find<tset_event_keyboard>(
|
||||
event,
|
||||
tdispatcher_implementation::thas_handler(event_type,
|
||||
*this))
|
||||
|| find<tset_event_notification>(
|
||||
event,
|
||||
tdispatcher_implementation::thas_handler(event_type,
|
||||
*this))
|
||||
|| find<tset_event_message>(event,
|
||||
tdispatcher_implementation::thas_handler(
|
||||
event_type, *this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,13 +107,12 @@ bool tdispatcher::has_event(const tevent event
|
|||
class tevent_in_set
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* If found we get executed to set the result.
|
||||
*
|
||||
* Since we need to return true if found we always return true.
|
||||
*/
|
||||
template<class T>
|
||||
template <class T>
|
||||
bool oper(tevent)
|
||||
{
|
||||
return true;
|
||||
|
@ -126,11 +131,11 @@ public:
|
|||
class ttrigger
|
||||
{
|
||||
public:
|
||||
void operator()(tsignal_function functor
|
||||
, tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt)
|
||||
void operator()(tsignal_function functor,
|
||||
tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt)
|
||||
{
|
||||
functor(dispatcher, event, handled, halt);
|
||||
}
|
||||
|
@ -140,44 +145,33 @@ bool tdispatcher::fire(const tevent event, twidget& target)
|
|||
{
|
||||
assert(find<tset_event>(event, tevent_in_set()));
|
||||
switch(event) {
|
||||
case LEFT_BUTTON_DOUBLE_CLICK :
|
||||
return fire_event_double_click<
|
||||
LEFT_BUTTON_CLICK
|
||||
, LEFT_BUTTON_DOUBLE_CLICK
|
||||
, &tevent_executor::wants_mouse_left_double_click
|
||||
, tsignal_function
|
||||
>(
|
||||
dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger());
|
||||
case LEFT_BUTTON_DOUBLE_CLICK:
|
||||
return fire_event_double_click<LEFT_BUTTON_CLICK,
|
||||
LEFT_BUTTON_DOUBLE_CLICK,
|
||||
&tevent_executor::
|
||||
wants_mouse_left_double_click,
|
||||
tsignal_function>(
|
||||
dynamic_cast<twidget*>(this), &target, ttrigger());
|
||||
|
||||
case MIDDLE_BUTTON_DOUBLE_CLICK :
|
||||
return fire_event_double_click<
|
||||
MIDDLE_BUTTON_CLICK
|
||||
, MIDDLE_BUTTON_DOUBLE_CLICK
|
||||
, &tevent_executor::wants_mouse_middle_double_click
|
||||
, tsignal_function
|
||||
>(
|
||||
dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger());
|
||||
case MIDDLE_BUTTON_DOUBLE_CLICK:
|
||||
return fire_event_double_click<MIDDLE_BUTTON_CLICK,
|
||||
MIDDLE_BUTTON_DOUBLE_CLICK,
|
||||
&tevent_executor::
|
||||
wants_mouse_middle_double_click,
|
||||
tsignal_function>(
|
||||
dynamic_cast<twidget*>(this), &target, ttrigger());
|
||||
|
||||
case RIGHT_BUTTON_DOUBLE_CLICK :
|
||||
return fire_event_double_click<
|
||||
RIGHT_BUTTON_CLICK
|
||||
, RIGHT_BUTTON_DOUBLE_CLICK
|
||||
, &tevent_executor::wants_mouse_right_double_click
|
||||
, tsignal_function
|
||||
>(
|
||||
dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger());
|
||||
case RIGHT_BUTTON_DOUBLE_CLICK:
|
||||
return fire_event_double_click<RIGHT_BUTTON_CLICK,
|
||||
RIGHT_BUTTON_DOUBLE_CLICK,
|
||||
&tevent_executor::
|
||||
wants_mouse_right_double_click,
|
||||
tsignal_function>(
|
||||
dynamic_cast<twidget*>(this), &target, ttrigger());
|
||||
|
||||
default :
|
||||
return fire_event<tsignal_function>(event
|
||||
, dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger());
|
||||
default:
|
||||
return fire_event<tsignal_function>(
|
||||
event, dynamic_cast<twidget*>(this), &target, ttrigger());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,17 +179,15 @@ bool tdispatcher::fire(const tevent event, twidget& target)
|
|||
class ttrigger_mouse
|
||||
{
|
||||
public:
|
||||
ttrigger_mouse(const tpoint& coordinate)
|
||||
: coordinate_(coordinate)
|
||||
ttrigger_mouse(const tpoint& coordinate) : coordinate_(coordinate)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void operator()(tsignal_mouse_function functor
|
||||
, tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt)
|
||||
void operator()(tsignal_mouse_function functor,
|
||||
tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt)
|
||||
{
|
||||
functor(dispatcher, event, handled, halt, coordinate_);
|
||||
}
|
||||
|
@ -204,35 +196,32 @@ private:
|
|||
tpoint coordinate_;
|
||||
};
|
||||
|
||||
bool tdispatcher::fire(const tevent event
|
||||
, twidget& target
|
||||
, const tpoint& coordinate)
|
||||
bool
|
||||
tdispatcher::fire(const tevent event, twidget& target, const tpoint& coordinate)
|
||||
{
|
||||
assert(find<tset_event_mouse>(event, tevent_in_set()));
|
||||
return fire_event<tsignal_mouse_function>(event
|
||||
, dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger_mouse(coordinate));
|
||||
return fire_event<tsignal_mouse_function>(event,
|
||||
dynamic_cast<twidget*>(this),
|
||||
&target,
|
||||
ttrigger_mouse(coordinate));
|
||||
}
|
||||
|
||||
/** Helper struct to wrap the functor call. */
|
||||
class ttrigger_keyboard
|
||||
{
|
||||
public:
|
||||
ttrigger_keyboard(const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode)
|
||||
: key_(key)
|
||||
, modifier_(modifier)
|
||||
, unicode_(unicode)
|
||||
ttrigger_keyboard(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
: key_(key), modifier_(modifier), unicode_(unicode)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(tsignal_keyboard_function functor
|
||||
, tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt)
|
||||
void operator()(tsignal_keyboard_function functor,
|
||||
tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt)
|
||||
{
|
||||
functor(dispatcher, event, handled, halt, key_, modifier_, unicode_);
|
||||
}
|
||||
|
@ -243,59 +232,57 @@ private:
|
|||
Uint16 unicode_;
|
||||
};
|
||||
|
||||
bool tdispatcher::fire(const tevent event
|
||||
, twidget& target
|
||||
, const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode)
|
||||
bool tdispatcher::fire(const tevent event,
|
||||
twidget& target,
|
||||
const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
{
|
||||
assert(find<tset_event_keyboard>(event, tevent_in_set()));
|
||||
return fire_event<tsignal_keyboard_function>(event
|
||||
, dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger_keyboard(key, modifier, unicode));
|
||||
return fire_event<tsignal_keyboard_function>(
|
||||
event,
|
||||
dynamic_cast<twidget*>(this),
|
||||
&target,
|
||||
ttrigger_keyboard(key, modifier, unicode));
|
||||
}
|
||||
|
||||
/** Helper struct to wrap the functor call. */
|
||||
class ttrigger_notification
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(tsignal_notification_function functor
|
||||
, tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt)
|
||||
void operator()(tsignal_notification_function functor,
|
||||
tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt)
|
||||
{
|
||||
functor(dispatcher, event, handled, halt, NULL);
|
||||
}
|
||||
};
|
||||
|
||||
bool tdispatcher::fire(const tevent event
|
||||
, twidget& target
|
||||
, void*)
|
||||
bool tdispatcher::fire(const tevent event, twidget& target, void*)
|
||||
{
|
||||
assert(find<tset_event_notification>(event, tevent_in_set()));
|
||||
return fire_event<tsignal_notification_function>(event
|
||||
, dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger_notification());
|
||||
return fire_event<tsignal_notification_function>(
|
||||
event,
|
||||
dynamic_cast<twidget*>(this),
|
||||
&target,
|
||||
ttrigger_notification());
|
||||
}
|
||||
|
||||
/** Helper struct to wrap the functor call. */
|
||||
class ttrigger_message
|
||||
{
|
||||
public:
|
||||
ttrigger_message(tmessage& message)
|
||||
: message_(message)
|
||||
ttrigger_message(tmessage& message) : message_(message)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(tsignal_message_function functor
|
||||
, tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt)
|
||||
void operator()(tsignal_message_function functor,
|
||||
tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt)
|
||||
{
|
||||
functor(dispatcher, event, handled, halt, message_);
|
||||
}
|
||||
|
@ -307,22 +294,22 @@ private:
|
|||
bool tdispatcher::fire(const tevent event, twidget& target, tmessage& message)
|
||||
{
|
||||
assert(find<tset_event_message>(event, tevent_in_set()));
|
||||
return fire_event<tsignal_message_function>(event
|
||||
, dynamic_cast<twidget*>(this)
|
||||
, &target
|
||||
, ttrigger_message(message));
|
||||
return fire_event<tsignal_message_function>(event,
|
||||
dynamic_cast<twidget*>(this),
|
||||
&target,
|
||||
ttrigger_message(message));
|
||||
}
|
||||
|
||||
void tdispatcher::register_hotkey(const hotkey::HOTKEY_COMMAND id
|
||||
, const thotkey_function& function)
|
||||
void tdispatcher::register_hotkey(const hotkey::HOTKEY_COMMAND id,
|
||||
const thotkey_function& function)
|
||||
{
|
||||
hotkeys_[id] = function;
|
||||
}
|
||||
|
||||
bool tdispatcher::execute_hotkey(const hotkey::HOTKEY_COMMAND id)
|
||||
{
|
||||
std::map<hotkey::HOTKEY_COMMAND, thotkey_function>::iterator
|
||||
itor = hotkeys_.find(id);
|
||||
std::map<hotkey::HOTKEY_COMMAND, thotkey_function>::iterator itor
|
||||
= hotkeys_.find(id);
|
||||
|
||||
if(itor == hotkeys_.end()) {
|
||||
return false;
|
||||
|
@ -730,4 +717,3 @@ bool tdispatcher::execute_hotkey(const hotkey::HOTKEY_COMMAND id)
|
|||
* or not, but always keep the panel selected. (That is if the panel can be
|
||||
* selected.))
|
||||
*/
|
||||
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
|
||||
#include <map>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tpoint;
|
||||
class twidget;
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
struct tmessage;
|
||||
|
||||
|
@ -41,43 +43,33 @@ struct tmessage;
|
|||
*
|
||||
* This function is used for the callbacks in tset_event.
|
||||
*/
|
||||
typedef
|
||||
boost::function<void(
|
||||
tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt)>
|
||||
tsignal_function;
|
||||
typedef boost::function<void(
|
||||
tdispatcher& dispatcher, const tevent event, bool& handled, bool& halt)>
|
||||
tsignal_function;
|
||||
|
||||
/**
|
||||
* Callback function signature.
|
||||
*
|
||||
* This function is used for the callbacks in tset_event_mouse.
|
||||
*/
|
||||
typedef
|
||||
boost::function<void(
|
||||
tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt
|
||||
, const tpoint& coordinate)>
|
||||
tsignal_mouse_function;
|
||||
typedef boost::function<void(tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt,
|
||||
const tpoint& coordinate)> tsignal_mouse_function;
|
||||
|
||||
/**
|
||||
* Callback function signature.
|
||||
*
|
||||
* This function is used for the callbacks in tset_event_keyboard.
|
||||
*/
|
||||
typedef
|
||||
boost::function<void(
|
||||
tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt
|
||||
, const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode) >
|
||||
tsignal_keyboard_function;
|
||||
typedef boost::function<void(tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt,
|
||||
const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)> tsignal_keyboard_function;
|
||||
|
||||
/**
|
||||
* Callback function signature.
|
||||
|
@ -86,35 +78,26 @@ typedef
|
|||
* Added the dummy void* parameter which will be NULL to get a different
|
||||
* signature as tsignal_function's callback.
|
||||
*/
|
||||
typedef
|
||||
boost::function<void(
|
||||
tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt
|
||||
, void*)>
|
||||
tsignal_notification_function;
|
||||
typedef boost::function<void(tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt,
|
||||
void*)> tsignal_notification_function;
|
||||
|
||||
/**
|
||||
* Callback function signature.
|
||||
*
|
||||
* This function is used for the callbacks in tset_message_notification.
|
||||
*/
|
||||
typedef
|
||||
boost::function<void(
|
||||
tdispatcher& dispatcher
|
||||
, const tevent event
|
||||
, bool& handled
|
||||
, bool& halt
|
||||
, tmessage& message)>
|
||||
tsignal_message_function;
|
||||
typedef boost::function<void(tdispatcher& dispatcher,
|
||||
const tevent event,
|
||||
bool& handled,
|
||||
bool& halt,
|
||||
tmessage& message)> tsignal_message_function;
|
||||
|
||||
/** Hotkey function handler signature. */
|
||||
typedef
|
||||
boost::function<bool(
|
||||
tdispatcher& dispatcher
|
||||
, hotkey::HOTKEY_COMMAND id)>
|
||||
thotkey_function;
|
||||
typedef boost::function<bool(tdispatcher& dispatcher,
|
||||
hotkey::HOTKEY_COMMAND id)> thotkey_function;
|
||||
|
||||
/**
|
||||
* Base class for event handling.
|
||||
|
@ -134,6 +117,7 @@ typedef
|
|||
class tdispatcher
|
||||
{
|
||||
friend struct tdispatcher_implementation;
|
||||
|
||||
public:
|
||||
tdispatcher();
|
||||
virtual ~tdispatcher();
|
||||
|
@ -163,11 +147,10 @@ public:
|
|||
*/
|
||||
virtual bool is_at(const tpoint& coordinate) const = 0;
|
||||
|
||||
enum tevent_type
|
||||
{
|
||||
pre = 1
|
||||
, child = 2
|
||||
, post = 4
|
||||
enum tevent_type {
|
||||
pre = 1,
|
||||
child = 2,
|
||||
post = 4
|
||||
};
|
||||
|
||||
bool has_event(const tevent event, const tevent_type event_type);
|
||||
|
@ -193,11 +176,11 @@ public:
|
|||
* @param modifier The SDL key modifiers used.
|
||||
* @param unicode The unicode value for the key pressed.
|
||||
*/
|
||||
bool fire(const tevent event
|
||||
, twidget& target
|
||||
, const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode);
|
||||
bool fire(const tevent event,
|
||||
twidget& target,
|
||||
const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode);
|
||||
|
||||
/**
|
||||
* Fires an event which takes notification parameters.
|
||||
|
@ -258,8 +241,7 @@ public:
|
|||
* sets the handled flag.
|
||||
* * Optionally there is another user callback invoked at this point.
|
||||
*/
|
||||
enum tposition
|
||||
{
|
||||
enum tposition {
|
||||
front_pre_child,
|
||||
back_pre_child,
|
||||
front_child,
|
||||
|
@ -285,11 +267,11 @@ public:
|
|||
* @param signal The callback function.
|
||||
* @param position The position to place the callback.
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event, boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event,
|
||||
boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_queue_.connect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -304,11 +286,11 @@ public:
|
|||
* place. (The function doesn't care whether
|
||||
* was added in front or back.)
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event, boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event,
|
||||
boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_queue_.disconnect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -320,11 +302,11 @@ public:
|
|||
* @param signal The callback function.
|
||||
* @param position The position to place the callback.
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_mouse, boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_mouse_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_mouse,
|
||||
boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_mouse_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_mouse_queue_.connect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -339,11 +321,11 @@ public:
|
|||
* place. (The function doesn't care whether
|
||||
* was added in front or back.)
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_mouse, boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_mouse_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_mouse,
|
||||
boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_mouse_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_mouse_queue_.disconnect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -355,11 +337,11 @@ public:
|
|||
* @param signal The callback function.
|
||||
* @param position The position to place the callback.
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_keyboard, boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_keyboard_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_keyboard,
|
||||
boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_keyboard_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_keyboard_queue_.connect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -374,11 +356,11 @@ public:
|
|||
* place. (The function doesn't care whether
|
||||
* was added in front or back.)
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_keyboard, boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_keyboard_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_keyboard,
|
||||
boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_keyboard_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_keyboard_queue_.disconnect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -393,11 +375,11 @@ public:
|
|||
* the pre and post positions make no sense
|
||||
* and shouldn't be used.
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_notification, boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_notification_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_notification,
|
||||
boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_notification_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_notification_queue_.connect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -417,11 +399,11 @@ public:
|
|||
* front_child and remove with
|
||||
* front_pre_child)
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_notification, boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_notification_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_notification,
|
||||
boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_notification_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_notification_queue_.disconnect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -436,11 +418,11 @@ public:
|
|||
* the pre and post positions make no sense
|
||||
* and shouldn't be used.
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_message, boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_message_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_message,
|
||||
boost::mpl::int_<E> > >::type
|
||||
connect_signal(const tsignal_message_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_message_queue_.connect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -460,11 +442,11 @@ public:
|
|||
* front_child and remove with
|
||||
* front_pre_child)
|
||||
*/
|
||||
template<tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<
|
||||
tset_event_message, boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_message_function& signal
|
||||
, const tposition position = back_child)
|
||||
template <tevent E>
|
||||
typename boost::enable_if<boost::mpl::has_key<tset_event_message,
|
||||
boost::mpl::int_<E> > >::type
|
||||
disconnect_signal(const tsignal_message_function& signal,
|
||||
const tposition position = back_child)
|
||||
{
|
||||
signal_message_queue_.disconnect_signal(E, position, signal);
|
||||
}
|
||||
|
@ -486,11 +468,10 @@ public:
|
|||
*
|
||||
* If after these tests no dispatcher is found the event is ignored.
|
||||
*/
|
||||
enum tmouse_behavior
|
||||
{
|
||||
all
|
||||
, hit
|
||||
, none
|
||||
enum tmouse_behavior {
|
||||
all,
|
||||
hit,
|
||||
none
|
||||
};
|
||||
|
||||
/** Captures the mouse. */
|
||||
|
@ -528,13 +509,10 @@ public:
|
|||
}
|
||||
|
||||
/** Helper struct to generate the various signal types. */
|
||||
template<class T>
|
||||
template <class T>
|
||||
struct tsignal
|
||||
{
|
||||
tsignal()
|
||||
: pre_child()
|
||||
, child()
|
||||
, post_child()
|
||||
tsignal() : pre_child(), child(), post_child()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -544,104 +522,99 @@ public:
|
|||
};
|
||||
|
||||
/** Helper struct to generate the various event queues. */
|
||||
template<class T>
|
||||
template <class T>
|
||||
struct tsignal_queue
|
||||
{
|
||||
tsignal_queue()
|
||||
: queue()
|
||||
tsignal_queue() : queue()
|
||||
{
|
||||
}
|
||||
|
||||
std::map<tevent, tsignal<T> > queue;
|
||||
|
||||
void connect_signal(const tevent event
|
||||
, const tposition position
|
||||
, const T& signal)
|
||||
void connect_signal(const tevent event,
|
||||
const tposition position,
|
||||
const T& signal)
|
||||
{
|
||||
switch(position) {
|
||||
case front_pre_child :
|
||||
case front_pre_child:
|
||||
queue[event].pre_child.insert(
|
||||
queue[event].pre_child.begin(), signal);
|
||||
break;
|
||||
case back_pre_child :
|
||||
case back_pre_child:
|
||||
queue[event].pre_child.push_back(signal);
|
||||
break;
|
||||
|
||||
case front_child :
|
||||
queue[event].child.insert(
|
||||
queue[event].child.begin(), signal);
|
||||
case front_child:
|
||||
queue[event]
|
||||
.child.insert(queue[event].child.begin(), signal);
|
||||
break;
|
||||
case back_child :
|
||||
case back_child:
|
||||
queue[event].child.push_back(signal);
|
||||
break;
|
||||
|
||||
case front_post_child :
|
||||
case front_post_child:
|
||||
queue[event].post_child.insert(
|
||||
queue[event].post_child.begin(), signal);
|
||||
break;
|
||||
case back_post_child :
|
||||
case back_post_child:
|
||||
queue[event].post_child.push_back(signal);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void disconnect_signal(const tevent event
|
||||
, const tposition position
|
||||
, const T& signal)
|
||||
void disconnect_signal(const tevent event,
|
||||
const tposition position,
|
||||
const T& signal)
|
||||
{
|
||||
/*
|
||||
* The function doesn't differentiate between front and back
|
||||
* position so fall down from front to back.
|
||||
*/
|
||||
switch(position) {
|
||||
case front_pre_child :
|
||||
case back_pre_child : {
|
||||
tsignal<T>& signal_queue = queue[event];
|
||||
for(typename std::vector<T>::iterator itor =
|
||||
signal_queue.child.begin()
|
||||
; itor != signal_queue.child.end()
|
||||
; ++itor) {
|
||||
case front_pre_child:
|
||||
case back_pre_child: {
|
||||
tsignal<T>& signal_queue = queue[event];
|
||||
for(typename std::vector<T>::iterator itor
|
||||
= signal_queue.child.begin();
|
||||
itor != signal_queue.child.end();
|
||||
++itor) {
|
||||
|
||||
if(signal.target_type() == itor->target_type()) {
|
||||
signal_queue.child.erase(itor);
|
||||
return;
|
||||
}
|
||||
if(signal.target_type() == itor->target_type()) {
|
||||
signal_queue.child.erase(itor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case front_child :
|
||||
case back_child : {
|
||||
tsignal<T>& signal_queue = queue[event];
|
||||
for(typename std::vector<T>::iterator itor =
|
||||
signal_queue.child.begin()
|
||||
; itor != signal_queue.child.end()
|
||||
; ++itor) {
|
||||
case front_child:
|
||||
case back_child: {
|
||||
tsignal<T>& signal_queue = queue[event];
|
||||
for(typename std::vector<T>::iterator itor
|
||||
= signal_queue.child.begin();
|
||||
itor != signal_queue.child.end();
|
||||
++itor) {
|
||||
|
||||
if(signal.target_type() == itor->target_type()) {
|
||||
signal_queue.child.erase(itor);
|
||||
return;
|
||||
}
|
||||
if(signal.target_type() == itor->target_type()) {
|
||||
signal_queue.child.erase(itor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case front_post_child :
|
||||
case back_post_child : {
|
||||
tsignal<T>& signal_queue = queue[event];
|
||||
for(typename std::vector<T>::iterator itor =
|
||||
signal_queue.child.begin()
|
||||
; itor != signal_queue.child.end()
|
||||
; ++itor) {
|
||||
case front_post_child:
|
||||
case back_post_child: {
|
||||
tsignal<T>& signal_queue = queue[event];
|
||||
for(typename std::vector<T>::iterator itor
|
||||
= signal_queue.child.begin();
|
||||
itor != signal_queue.child.end();
|
||||
++itor) {
|
||||
|
||||
if(signal.target_type() == itor->target_type()) {
|
||||
signal_queue.child.erase(itor);
|
||||
return;
|
||||
}
|
||||
if(signal.target_type() == itor->target_type()) {
|
||||
signal_queue.child.erase(itor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -657,8 +630,8 @@ public:
|
|||
* @param id The hotkey to register.
|
||||
* @param function The callback function to call.
|
||||
*/
|
||||
void register_hotkey(const hotkey::HOTKEY_COMMAND id
|
||||
, const thotkey_function& function);
|
||||
void register_hotkey(const hotkey::HOTKEY_COMMAND id,
|
||||
const thotkey_function& function);
|
||||
|
||||
/**
|
||||
* Executes a hotkey.
|
||||
|
@ -671,7 +644,6 @@ public:
|
|||
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id);
|
||||
|
||||
private:
|
||||
|
||||
/** The mouse behavior for the dispatcher. */
|
||||
tmouse_behavior mouse_behavior_;
|
||||
|
||||
|
@ -722,35 +694,31 @@ private:
|
|||
* This callback is called before the widget itself allowing you to either
|
||||
* snoop on the input or filter it.
|
||||
*/
|
||||
inline void connect_signal_pre_key_press(
|
||||
tdispatcher& dispatcher
|
||||
, const tsignal_keyboard_function& signal)
|
||||
inline void
|
||||
connect_signal_pre_key_press(tdispatcher& dispatcher,
|
||||
const tsignal_keyboard_function& signal)
|
||||
{
|
||||
dispatcher.connect_signal<SDL_KEY_DOWN>(
|
||||
signal
|
||||
, tdispatcher::front_child);
|
||||
dispatcher.connect_signal<SDL_KEY_DOWN>(signal, tdispatcher::front_child);
|
||||
}
|
||||
|
||||
/** Connects a signal handler for a left mouse button click. */
|
||||
inline void connect_signal_mouse_left_click(
|
||||
tdispatcher& dispatcher
|
||||
, const tsignal_function& signal)
|
||||
inline void connect_signal_mouse_left_click(tdispatcher& dispatcher,
|
||||
const tsignal_function& signal)
|
||||
{
|
||||
dispatcher.connect_signal<LEFT_BUTTON_CLICK>(signal);
|
||||
}
|
||||
|
||||
/** Disconnects a signal handler for a left mouse button click. */
|
||||
inline void disconnect_signal_mouse_left_click(
|
||||
tdispatcher& dispatcher
|
||||
, const tsignal_function& signal)
|
||||
inline void disconnect_signal_mouse_left_click(tdispatcher& dispatcher,
|
||||
const tsignal_function& signal)
|
||||
{
|
||||
dispatcher.disconnect_signal<LEFT_BUTTON_CLICK>(signal);
|
||||
}
|
||||
|
||||
/** Connects a signal handler for getting a notification upon modification. */
|
||||
inline void connect_signal_notify_modified(
|
||||
tdispatcher& dispatcher
|
||||
, const tsignal_notification_function& signal)
|
||||
inline void
|
||||
connect_signal_notify_modified(tdispatcher& dispatcher,
|
||||
const tsignal_notification_function& signal)
|
||||
{
|
||||
dispatcher.connect_signal<event::NOTIFY_MODIFIED>(signal);
|
||||
}
|
||||
|
@ -760,4 +728,3 @@ inline void connect_signal_notify_modified(
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
struct tdispatcher_implementation
|
||||
{
|
||||
|
@ -41,52 +43,48 @@ struct tdispatcher_implementation
|
|||
* one in that header.
|
||||
* @param QUEUE The queue in which the @p event is slotted.
|
||||
*/
|
||||
#define IMPLEMENT_EVENT_SIGNAL(SET, FUNCTION, QUEUE) \
|
||||
/** \
|
||||
* Returns the signal structure for a FUNCTION. \
|
||||
* \
|
||||
* There are several functions that only overload the return value, in \
|
||||
* order to do so they use SFINAE. \
|
||||
* \
|
||||
* @tparam F tsignal_function. \
|
||||
* @param dispatcher The dispatcher whose signal queue is used. \
|
||||
* @param event The event to get the signal for. \
|
||||
* \
|
||||
* @returns The signal of the type \
|
||||
* tdispatcher::tsignal<FUNCTION> \
|
||||
*/ \
|
||||
template<class F> \
|
||||
static typename boost::enable_if< \
|
||||
boost::is_same<F, FUNCTION> \
|
||||
, tdispatcher::tsignal<FUNCTION> \
|
||||
>::type& \
|
||||
event_signal(tdispatcher& dispatcher, const tevent event) \
|
||||
{ \
|
||||
return dispatcher.QUEUE.queue[event]; \
|
||||
} \
|
||||
\
|
||||
/** \
|
||||
* Returns the signal structure for a key in SET. \
|
||||
* \
|
||||
* There are several functions that only overload the return value, in \
|
||||
* order to do so they use SFINAE. \
|
||||
* \
|
||||
* @tparam K A key in tset_event. \
|
||||
* @param dispatcher The dispatcher whose signal queue is used. \
|
||||
* @param event The event to get the signal for. \
|
||||
* \
|
||||
* @returns The signal of the type \
|
||||
* tdispatcher::tsignal<FUNCTION> \
|
||||
*/ \
|
||||
template<class K> \
|
||||
static typename boost::enable_if< \
|
||||
boost::mpl::has_key<SET, K> \
|
||||
, tdispatcher::tsignal<FUNCTION> \
|
||||
>::type& \
|
||||
event_signal(tdispatcher& dispatcher, const tevent event) \
|
||||
{ \
|
||||
return dispatcher.QUEUE.queue[event]; \
|
||||
} \
|
||||
#define IMPLEMENT_EVENT_SIGNAL(SET, FUNCTION, QUEUE) \
|
||||
/** \
|
||||
* Returns the signal structure for a FUNCTION. \
|
||||
* \
|
||||
* There are several functions that only overload the return value, in \
|
||||
* order to do so they use SFINAE. \
|
||||
* \
|
||||
* @tparam F tsignal_function. \
|
||||
* @param dispatcher The dispatcher whose signal queue is used. \
|
||||
* @param event The event to get the signal for. \
|
||||
* \
|
||||
* @returns The signal of the type \
|
||||
* tdispatcher::tsignal<FUNCTION> \
|
||||
*/ \
|
||||
template <class F> \
|
||||
static typename boost::enable_if<boost::is_same<F, FUNCTION>, \
|
||||
tdispatcher::tsignal<FUNCTION> >::type& \
|
||||
event_signal(tdispatcher& dispatcher, const tevent event) \
|
||||
{ \
|
||||
return dispatcher.QUEUE.queue[event]; \
|
||||
} \
|
||||
\
|
||||
/** \
|
||||
* Returns the signal structure for a key in SET. \
|
||||
* \
|
||||
* There are several functions that only overload the return value, in \
|
||||
* order to do so they use SFINAE. \
|
||||
* \
|
||||
* @tparam K A key in tset_event. \
|
||||
* @param dispatcher The dispatcher whose signal queue is used. \
|
||||
* @param event The event to get the signal for. \
|
||||
* \
|
||||
* @returns The signal of the type \
|
||||
* tdispatcher::tsignal<FUNCTION> \
|
||||
*/ \
|
||||
template <class K> \
|
||||
static typename boost::enable_if<boost::mpl::has_key<SET, K>, \
|
||||
tdispatcher::tsignal<FUNCTION> >::type& \
|
||||
event_signal(tdispatcher& dispatcher, const tevent event) \
|
||||
{ \
|
||||
return dispatcher.QUEUE.queue[event]; \
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_EVENT_SIGNAL(tset_event, tsignal_function, signal_queue_)
|
||||
|
@ -100,10 +98,10 @@ struct tdispatcher_implementation
|
|||
* @param TYPE The type to wrap for @ref
|
||||
* IMPLEMENT_EVENT_SIGNAL.
|
||||
*/
|
||||
#define IMPLEMENT_EVENT_SIGNAL_WRAPPER(TYPE) \
|
||||
IMPLEMENT_EVENT_SIGNAL(tset_event_##TYPE \
|
||||
, tsignal_##TYPE##_function \
|
||||
, signal_##TYPE##_queue_) \
|
||||
#define IMPLEMENT_EVENT_SIGNAL_WRAPPER(TYPE) \
|
||||
IMPLEMENT_EVENT_SIGNAL(tset_event_##TYPE, \
|
||||
tsignal_##TYPE##_function, \
|
||||
signal_##TYPE##_queue_)
|
||||
|
||||
IMPLEMENT_EVENT_SIGNAL_WRAPPER(mouse)
|
||||
IMPLEMENT_EVENT_SIGNAL_WRAPPER(keyboard)
|
||||
|
@ -126,11 +124,11 @@ struct tdispatcher_implementation
|
|||
* @param event_type The type of event to look for.
|
||||
* @param dispatcher The dispatcher whose signal queue is used.
|
||||
*/
|
||||
thas_handler(const tdispatcher::tevent_type event_type
|
||||
, tdispatcher& dispatcher)
|
||||
: event_type_(event_type)
|
||||
, dispatcher_(dispatcher)
|
||||
{}
|
||||
thas_handler(const tdispatcher::tevent_type event_type,
|
||||
tdispatcher& dispatcher)
|
||||
: event_type_(event_type), dispatcher_(dispatcher)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a handler for an event is available.
|
||||
|
@ -145,19 +143,19 @@ struct tdispatcher_implementation
|
|||
* @returns Whether or not the handler is found.
|
||||
*/
|
||||
// not called operator() to work around a problem in MSVC 2008.
|
||||
template<class T>
|
||||
template <class T>
|
||||
bool oper(tevent event)
|
||||
{
|
||||
if((event_type_ & tdispatcher::pre)
|
||||
&& !event_signal<T>(dispatcher_, event).pre_child.empty()) {
|
||||
&& !event_signal<T>(dispatcher_, event).pre_child.empty()) {
|
||||
return true;
|
||||
}
|
||||
if((event_type_ & tdispatcher::child)
|
||||
&& !event_signal<T>(dispatcher_, event).child.empty()) {
|
||||
&& !event_signal<T>(dispatcher_, event).child.empty()) {
|
||||
return true;
|
||||
}
|
||||
if((event_type_ & tdispatcher::post)
|
||||
&& !event_signal<T>(dispatcher_, event).post_child.empty()){
|
||||
&& !event_signal<T>(dispatcher_, event).post_child.empty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -170,49 +168,30 @@ struct tdispatcher_implementation
|
|||
};
|
||||
|
||||
/** Contains the implementation details of the find function. */
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
/** Specialized class when itor == end */
|
||||
template<bool done = true>
|
||||
template <bool done = true>
|
||||
struct find
|
||||
{
|
||||
template<
|
||||
typename itor
|
||||
, typename end
|
||||
, typename E
|
||||
, typename F
|
||||
>
|
||||
static bool execute(
|
||||
itor*
|
||||
, end*
|
||||
, E
|
||||
, F
|
||||
)
|
||||
template <typename itor, typename end, typename E, typename F>
|
||||
static bool execute(itor*, end*, E, F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/** Specialized class when itor != end */
|
||||
template<>
|
||||
template <>
|
||||
struct find<false>
|
||||
{
|
||||
template<
|
||||
typename itor
|
||||
, typename end
|
||||
, typename E
|
||||
, typename F
|
||||
>
|
||||
static bool execute(
|
||||
itor*
|
||||
, end*
|
||||
, E event
|
||||
, F functor
|
||||
)
|
||||
template <typename itor, typename end, typename E, typename F>
|
||||
static bool execute(itor*, end*, E event, F functor)
|
||||
{
|
||||
typedef typename boost::mpl::deref<itor>::type item;
|
||||
typedef typename
|
||||
boost::mpl::apply1<boost::mpl::identity<>, item>::type arg;
|
||||
typedef typename boost::mpl::apply1<boost::mpl::identity<>, item>::type
|
||||
arg;
|
||||
|
||||
boost::value_initialized<arg> x;
|
||||
|
||||
|
@ -222,10 +201,10 @@ struct find<false>
|
|||
} else {
|
||||
typedef typename boost::mpl::next<itor>::type titor;
|
||||
return find<boost::is_same<titor, end>::value>::execute(
|
||||
static_cast<titor*>(NULL)
|
||||
, static_cast<end*>(NULL)
|
||||
, event
|
||||
, functor);
|
||||
static_cast<titor*>(NULL),
|
||||
static_cast<end*>(NULL),
|
||||
event,
|
||||
functor);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -252,24 +231,18 @@ struct find<false>
|
|||
*
|
||||
* @returns Whether or not the function found a result.
|
||||
*/
|
||||
template<
|
||||
typename sequence
|
||||
, typename E
|
||||
, typename F
|
||||
>
|
||||
template <typename sequence, typename E, typename F>
|
||||
inline bool find(E event, F functor)
|
||||
{
|
||||
typedef typename boost::mpl::begin<sequence>::type begin;
|
||||
typedef typename boost::mpl::end<sequence>::type end;
|
||||
|
||||
return implementation::find<boost::is_same<begin, end>::value>::execute(
|
||||
static_cast<begin*>(NULL)
|
||||
, static_cast<end*>(NULL)
|
||||
, event
|
||||
, functor);
|
||||
static_cast<begin*>(NULL), static_cast<end*>(NULL), event, functor);
|
||||
}
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
/*
|
||||
* Small sample to illustrate the effects of the various build_event_chain
|
||||
|
@ -319,11 +292,9 @@ namespace implementation {
|
|||
* * container 1
|
||||
* * dispatcher
|
||||
*/
|
||||
template<class T>
|
||||
inline std::vector<std::pair<twidget*, tevent> > build_event_chain(
|
||||
const tevent event
|
||||
, twidget* dispatcher
|
||||
, twidget* widget)
|
||||
template <class T>
|
||||
inline std::vector<std::pair<twidget*, tevent> >
|
||||
build_event_chain(const tevent event, twidget* dispatcher, twidget* widget)
|
||||
{
|
||||
assert(dispatcher);
|
||||
assert(widget);
|
||||
|
@ -334,8 +305,9 @@ inline std::vector<std::pair<twidget*, tevent> > build_event_chain(
|
|||
widget = widget->parent();
|
||||
assert(widget);
|
||||
|
||||
if(widget->has_event(event, tdispatcher::tevent_type(
|
||||
tdispatcher::pre | tdispatcher::post))) {
|
||||
if(widget->has_event(event,
|
||||
tdispatcher::tevent_type(tdispatcher::pre
|
||||
| tdispatcher::post))) {
|
||||
|
||||
result.push_back(std::make_pair(widget, event));
|
||||
}
|
||||
|
@ -353,28 +325,25 @@ inline std::vector<std::pair<twidget*, tevent> > build_event_chain(
|
|||
*
|
||||
* @returns An empty vector.
|
||||
*/
|
||||
template<>
|
||||
template <>
|
||||
inline std::vector<std::pair<twidget*, tevent> >
|
||||
build_event_chain<tsignal_notification_function>(
|
||||
const tevent event
|
||||
, twidget* dispatcher
|
||||
, twidget* widget)
|
||||
build_event_chain<tsignal_notification_function>(const tevent event,
|
||||
twidget* dispatcher,
|
||||
twidget* widget)
|
||||
{
|
||||
assert(dispatcher);
|
||||
assert(widget);
|
||||
|
||||
assert(!widget->has_event(
|
||||
event
|
||||
, tdispatcher::tevent_type(
|
||||
tdispatcher::pre
|
||||
| tdispatcher::post)));
|
||||
assert(!widget->has_event(event,
|
||||
tdispatcher::tevent_type(tdispatcher::pre
|
||||
| tdispatcher::post)));
|
||||
|
||||
return std::vector<std::pair<twidget*, tevent> >();
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4706)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4706)
|
||||
#endif
|
||||
/**
|
||||
* Build the event chain for tsignal_message_function.
|
||||
|
@ -393,12 +362,11 @@ build_event_chain<tsignal_notification_function>(
|
|||
* * container 1
|
||||
* * container 2
|
||||
*/
|
||||
template<>
|
||||
template <>
|
||||
inline std::vector<std::pair<twidget*, tevent> >
|
||||
build_event_chain<tsignal_message_function>(
|
||||
const tevent event
|
||||
, twidget* dispatcher
|
||||
, twidget* widget)
|
||||
build_event_chain<tsignal_message_function>(const tevent event,
|
||||
twidget* dispatcher,
|
||||
twidget* widget)
|
||||
{
|
||||
assert(dispatcher);
|
||||
assert(widget);
|
||||
|
@ -410,8 +378,9 @@ build_event_chain<tsignal_message_function>(
|
|||
while((widget = widget->parent())) {
|
||||
assert(widget);
|
||||
|
||||
if(widget->has_event(event, tdispatcher::tevent_type(
|
||||
tdispatcher::pre | tdispatcher::post))) {
|
||||
if(widget->has_event(event,
|
||||
tdispatcher::tevent_type(tdispatcher::pre
|
||||
| tdispatcher::post))) {
|
||||
|
||||
result.insert(result.begin(), std::make_pair(widget, event));
|
||||
}
|
||||
|
@ -420,7 +389,7 @@ build_event_chain<tsignal_message_function>(
|
|||
return result;
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -429,28 +398,29 @@ build_event_chain<tsignal_message_function>(
|
|||
* This is called with the same parameters as fire_event except for the
|
||||
* event_chain, which contains the widgets with the events to call for them.
|
||||
*/
|
||||
template<class T, class F>
|
||||
inline bool fire_event(const tevent event
|
||||
, std::vector<std::pair<twidget*, tevent> >& event_chain
|
||||
, twidget* dispatcher
|
||||
, twidget* widget
|
||||
, F functor)
|
||||
template <class T, class F>
|
||||
inline bool fire_event(const tevent event,
|
||||
std::vector<std::pair<twidget*, tevent> >& event_chain,
|
||||
twidget* dispatcher,
|
||||
twidget* widget,
|
||||
F functor)
|
||||
{
|
||||
bool handled = false;
|
||||
bool halt = false;
|
||||
|
||||
/***** ***** ***** Pre ***** ***** *****/
|
||||
for(std::vector<std::pair<twidget*, tevent> >
|
||||
::reverse_iterator ritor_widget = event_chain.rbegin();
|
||||
ritor_widget != event_chain.rend();
|
||||
++ritor_widget) {
|
||||
for(std::vector<std::pair<twidget*, tevent> >::reverse_iterator ritor_widget
|
||||
= event_chain.rbegin();
|
||||
ritor_widget != event_chain.rend();
|
||||
++ritor_widget) {
|
||||
|
||||
tdispatcher::tsignal<T>& signal = tdispatcher_implementation
|
||||
::event_signal<T>(*ritor_widget->first, ritor_widget->second);
|
||||
tdispatcher::tsignal<T>& signal
|
||||
= tdispatcher_implementation::event_signal<T>(
|
||||
*ritor_widget->first, ritor_widget->second);
|
||||
|
||||
for(typename std::vector<T>::iterator itor = signal.pre_child.begin();
|
||||
itor != signal.pre_child.end();
|
||||
++itor) {
|
||||
itor != signal.pre_child.end();
|
||||
++itor) {
|
||||
|
||||
functor(*itor, *dispatcher, ritor_widget->second, handled, halt);
|
||||
if(halt) {
|
||||
|
@ -467,12 +437,12 @@ inline bool fire_event(const tevent event
|
|||
/***** ***** ***** Child ***** ***** *****/
|
||||
if(widget->has_event(event, tdispatcher::child)) {
|
||||
|
||||
tdispatcher::tsignal<T>& signal = tdispatcher_implementation
|
||||
::event_signal<T>(*widget, event);
|
||||
tdispatcher::tsignal<T>& signal
|
||||
= tdispatcher_implementation::event_signal<T>(*widget, event);
|
||||
|
||||
for(typename std::vector<T>::iterator itor = signal.child.begin();
|
||||
itor != signal.child.end();
|
||||
++itor) {
|
||||
itor != signal.child.end();
|
||||
++itor) {
|
||||
|
||||
functor(*itor, *dispatcher, event, handled, halt);
|
||||
|
||||
|
@ -488,17 +458,18 @@ inline bool fire_event(const tevent event
|
|||
}
|
||||
|
||||
/***** ***** ***** Post ***** ***** *****/
|
||||
for(std::vector<std::pair<twidget*, tevent> >
|
||||
::iterator itor_widget = event_chain.begin();
|
||||
itor_widget != event_chain.end();
|
||||
++itor_widget) {
|
||||
for(std::vector<std::pair<twidget*, tevent> >::iterator itor_widget
|
||||
= event_chain.begin();
|
||||
itor_widget != event_chain.end();
|
||||
++itor_widget) {
|
||||
|
||||
tdispatcher::tsignal<T>& signal = tdispatcher_implementation
|
||||
::event_signal<T>(*itor_widget->first, itor_widget->second);
|
||||
tdispatcher::tsignal<T>& signal
|
||||
= tdispatcher_implementation::event_signal<T>(
|
||||
*itor_widget->first, itor_widget->second);
|
||||
|
||||
for(typename std::vector<T>::iterator itor = signal.post_child.begin();
|
||||
itor != signal.post_child.end();
|
||||
++itor) {
|
||||
itor != signal.post_child.end();
|
||||
++itor) {
|
||||
|
||||
functor(*itor, *dispatcher, itor_widget->second, handled, halt);
|
||||
if(halt) {
|
||||
|
@ -542,56 +513,49 @@ inline bool fire_event(const tevent event
|
|||
*
|
||||
* @returns Whether or not the event was handled.
|
||||
*/
|
||||
template<class T, class F>
|
||||
inline bool fire_event(const tevent event
|
||||
, twidget* dispatcher
|
||||
, twidget* widget
|
||||
, F functor)
|
||||
template <class T, class F>
|
||||
inline bool
|
||||
fire_event(const tevent event, twidget* dispatcher, twidget* widget, F functor)
|
||||
{
|
||||
assert(dispatcher);
|
||||
assert(widget);
|
||||
|
||||
std::vector<std::pair<twidget*, tevent> > event_chain =
|
||||
implementation::build_event_chain<T>(event, dispatcher, widget);
|
||||
std::vector<std::pair<twidget*, tevent> > event_chain
|
||||
= implementation::build_event_chain<T>(event, dispatcher, widget);
|
||||
|
||||
return implementation::fire_event<T>(event
|
||||
, event_chain
|
||||
, dispatcher
|
||||
, widget
|
||||
, functor);
|
||||
return implementation::fire_event<T>(
|
||||
event, event_chain, dispatcher, widget, functor);
|
||||
}
|
||||
|
||||
template<
|
||||
tevent click
|
||||
, tevent double_click
|
||||
, bool(tevent_executor::*wants_double_click) () const
|
||||
, class T
|
||||
, class F
|
||||
>
|
||||
inline bool fire_event_double_click(
|
||||
twidget* dispatcher
|
||||
, twidget* widget
|
||||
, F functor)
|
||||
template <tevent click,
|
||||
tevent double_click,
|
||||
bool (tevent_executor::*wants_double_click)() const,
|
||||
class T,
|
||||
class F>
|
||||
inline bool
|
||||
fire_event_double_click(twidget* dispatcher, twidget* widget, F functor)
|
||||
{
|
||||
assert(dispatcher);
|
||||
assert(widget);
|
||||
|
||||
std::vector<std::pair<twidget*, tevent> > event_chain;
|
||||
twidget* w = widget;
|
||||
while(w!= dispatcher) {
|
||||
while(w != dispatcher) {
|
||||
w = w->parent();
|
||||
assert(w);
|
||||
|
||||
if((w->*wants_double_click)()) {
|
||||
|
||||
if(w->has_event(double_click, tdispatcher::tevent_type(
|
||||
tdispatcher::pre | tdispatcher::post))) {
|
||||
if(w->has_event(double_click,
|
||||
tdispatcher::tevent_type(tdispatcher::pre
|
||||
| tdispatcher::post))) {
|
||||
|
||||
event_chain.push_back(std::make_pair(w, double_click));
|
||||
}
|
||||
} else {
|
||||
if(w->has_event(click, tdispatcher::tevent_type(
|
||||
tdispatcher::pre | tdispatcher::post))) {
|
||||
if(w->has_event(click,
|
||||
tdispatcher::tevent_type(tdispatcher::pre
|
||||
| tdispatcher::post))) {
|
||||
|
||||
event_chain.push_back(std::make_pair(w, click));
|
||||
}
|
||||
|
@ -599,17 +563,11 @@ inline bool fire_event_double_click(
|
|||
}
|
||||
|
||||
if((widget->*wants_double_click)()) {
|
||||
return implementation::fire_event<T>(double_click
|
||||
, event_chain
|
||||
, dispatcher
|
||||
, widget
|
||||
, functor);
|
||||
return implementation::fire_event<T>(
|
||||
double_click, event_chain, dispatcher, widget, functor);
|
||||
} else {
|
||||
return implementation::fire_event<T>(click
|
||||
, event_chain
|
||||
, dispatcher
|
||||
, widget
|
||||
, functor);
|
||||
return implementation::fire_event<T>(
|
||||
click, event_chain, dispatcher, widget, functor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -618,4 +576,3 @@ inline bool fire_event_double_click(
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,9 +25,11 @@
|
|||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace gui2{
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
/**
|
||||
* SDL_AddTimer() callback for the hover event.
|
||||
|
@ -86,8 +88,7 @@ static Uint32 popup_callback(Uint32 /*interval*/, void* /*param*/)
|
|||
class tlock
|
||||
{
|
||||
public:
|
||||
tlock(bool& locked)
|
||||
: locked_(locked)
|
||||
tlock(bool& locked) : locked_(locked)
|
||||
{
|
||||
assert(!locked_);
|
||||
locked_ = true;
|
||||
|
@ -98,6 +99,7 @@ public:
|
|||
assert(locked_);
|
||||
locked_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool& locked_;
|
||||
};
|
||||
|
@ -107,8 +109,8 @@ private:
|
|||
|
||||
#define LOG_HEADER "distributor mouse motion [" << owner_.id() << "]: "
|
||||
|
||||
tmouse_motion::tmouse_motion(twidget& owner
|
||||
, const tdispatcher::tposition queue_position)
|
||||
tmouse_motion::tmouse_motion(twidget& owner,
|
||||
const tdispatcher::tposition queue_position)
|
||||
: mouse_focus_(NULL)
|
||||
, mouse_captured_(false)
|
||||
, owner_(owner)
|
||||
|
@ -119,31 +121,29 @@ tmouse_motion::tmouse_motion(twidget& owner
|
|||
, signal_handler_sdl_mouse_motion_entered_(false)
|
||||
{
|
||||
owner.connect_signal<event::SDL_MOUSE_MOTION>(
|
||||
boost::bind(&tmouse_motion::signal_handler_sdl_mouse_motion
|
||||
, this, _2, _3, _5)
|
||||
, queue_position);
|
||||
boost::bind(&tmouse_motion::signal_handler_sdl_mouse_motion,
|
||||
this,
|
||||
_2,
|
||||
_3,
|
||||
_5),
|
||||
queue_position);
|
||||
|
||||
owner_.connect_signal<event::SDL_WHEEL_UP>(
|
||||
boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel
|
||||
, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_DOWN>(
|
||||
boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel
|
||||
, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_LEFT>(
|
||||
boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel
|
||||
, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_RIGHT>(
|
||||
boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel
|
||||
, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_UP>(boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_DOWN>(boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_LEFT>(boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel, this, _2, _3, _5));
|
||||
owner_.connect_signal<event::SDL_WHEEL_RIGHT>(boost::bind(
|
||||
&tmouse_motion::signal_handler_sdl_wheel, this, _2, _3, _5));
|
||||
|
||||
owner.connect_signal<event::SHOW_HELPTIP>(
|
||||
boost::bind(&tmouse_motion::signal_handler_show_helptip
|
||||
, this, _2, _3, _5)
|
||||
, queue_position);
|
||||
boost::bind(&tmouse_motion::signal_handler_show_helptip,
|
||||
this,
|
||||
_2,
|
||||
_3,
|
||||
_5),
|
||||
queue_position);
|
||||
}
|
||||
|
||||
tmouse_motion::~tmouse_motion()
|
||||
|
@ -151,17 +151,15 @@ tmouse_motion::~tmouse_motion()
|
|||
stop_hover_timer();
|
||||
}
|
||||
|
||||
void tmouse_motion::capture_mouse(//twidget* widget)
|
||||
const bool capture)
|
||||
void tmouse_motion::capture_mouse(const bool capture)
|
||||
{
|
||||
assert(mouse_focus_);
|
||||
mouse_captured_ = capture;
|
||||
}
|
||||
|
||||
void tmouse_motion::signal_handler_sdl_mouse_motion(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate)
|
||||
void tmouse_motion::signal_handler_sdl_mouse_motion(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate)
|
||||
{
|
||||
if(signal_handler_sdl_mouse_motion_entered_) {
|
||||
return;
|
||||
|
@ -186,7 +184,7 @@ void tmouse_motion::signal_handler_sdl_mouse_motion(
|
|||
|
||||
if(!mouse_focus_ && mouse_over) {
|
||||
mouse_enter(mouse_over);
|
||||
} else if (mouse_focus_ && !mouse_over) {
|
||||
} else if(mouse_focus_ && !mouse_over) {
|
||||
mouse_leave();
|
||||
} else if(mouse_focus_ && mouse_focus_ == mouse_over) {
|
||||
mouse_motion(mouse_over, coordinate);
|
||||
|
@ -201,10 +199,9 @@ void tmouse_motion::signal_handler_sdl_mouse_motion(
|
|||
handled = true;
|
||||
}
|
||||
|
||||
void tmouse_motion::signal_handler_sdl_wheel(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate)
|
||||
void tmouse_motion::signal_handler_sdl_wheel(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << event << ".\n";
|
||||
|
||||
|
@ -220,10 +217,9 @@ void tmouse_motion::signal_handler_sdl_wheel(
|
|||
handled = true;
|
||||
}
|
||||
|
||||
void tmouse_motion::signal_handler_show_helptip(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate)
|
||||
void tmouse_motion::signal_handler_show_helptip(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << event << ".\n";
|
||||
|
||||
|
@ -239,7 +235,6 @@ void tmouse_motion::signal_handler_show_helptip(
|
|||
if(owner_.fire(event, *mouse_over, coordinate)) {
|
||||
stop_hover_timer();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,7 +264,7 @@ void tmouse_motion::mouse_motion(twidget* mouse_over, const tpoint& coordinate)
|
|||
|
||||
if(hover_timer_) {
|
||||
if((abs(hover_position_.x - coordinate.x) > 5)
|
||||
|| (abs(hover_position_.y - coordinate.y) > 5)) {
|
||||
|| (abs(hover_position_.y - coordinate.y) > 5)) {
|
||||
|
||||
stop_hover_timer();
|
||||
start_hover_timer(mouse_over, coordinate);
|
||||
|
@ -283,8 +278,8 @@ void tmouse_motion::show_tooltip()
|
|||
|
||||
if(!hover_widget_) {
|
||||
// See tmouse_motion::stop_hover_timer.
|
||||
ERR_GUI_E << LOG_HEADER
|
||||
<< event::SHOW_TOOLTIP << " bailing out, no hover widget.\n";
|
||||
ERR_GUI_E << LOG_HEADER << event::SHOW_TOOLTIP
|
||||
<< " bailing out, no hover widget.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -327,12 +322,11 @@ void tmouse_motion::start_hover_timer(twidget* widget, const tpoint& coordinate)
|
|||
return;
|
||||
}
|
||||
|
||||
DBG_GUI_E << LOG_HEADER << "Start hover timer for widget '"
|
||||
<< widget->id() << "' at address " << widget << ".\n";
|
||||
DBG_GUI_E << LOG_HEADER << "Start hover timer for widget '" << widget->id()
|
||||
<< "' at address " << widget << ".\n";
|
||||
|
||||
hover_timer_ = add_timer(
|
||||
50
|
||||
, boost::bind(&tmouse_motion::show_tooltip, this));
|
||||
hover_timer_
|
||||
= add_timer(50, boost::bind(&tmouse_motion::show_tooltip, this));
|
||||
|
||||
if(hover_timer_) {
|
||||
hover_widget_ = widget;
|
||||
|
@ -347,8 +341,8 @@ void tmouse_motion::stop_hover_timer()
|
|||
if(hover_timer_) {
|
||||
assert(hover_widget_);
|
||||
DBG_GUI_E << LOG_HEADER << "Stop hover timer for widget '"
|
||||
<< hover_widget_->id() << "' at address "
|
||||
<< hover_widget_ << ".\n";
|
||||
<< hover_widget_->id() << "' at address " << hover_widget_
|
||||
<< ".\n";
|
||||
|
||||
if(!remove_timer(hover_timer_)) {
|
||||
ERR_GUI_E << LOG_HEADER << "Failed to remove hover timer.\n";
|
||||
|
@ -363,27 +357,24 @@ void tmouse_motion::stop_hover_timer()
|
|||
/***** ***** ***** ***** tmouse_button ***** ***** ***** ***** *****/
|
||||
|
||||
#undef LOG_HEADER
|
||||
#define LOG_HEADER "distributor mouse button " \
|
||||
<< name_ << " [" << owner_.id() << "]: "
|
||||
#define LOG_HEADER \
|
||||
"distributor mouse button " << name_ << " [" << owner_.id() << "]: "
|
||||
|
||||
template<
|
||||
tevent sdl_button_down
|
||||
, tevent sdl_button_up
|
||||
, tevent button_down
|
||||
, tevent button_up
|
||||
, tevent button_click
|
||||
, tevent button_double_click
|
||||
> tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::tmouse_button(
|
||||
const std::string& name_
|
||||
, twidget& owner
|
||||
, const tdispatcher::tposition queue_position)
|
||||
template <tevent sdl_button_down,
|
||||
tevent sdl_button_up,
|
||||
tevent button_down,
|
||||
tevent button_up,
|
||||
tevent button_click,
|
||||
tevent button_double_click>
|
||||
tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::tmouse_button(const std::string& name_,
|
||||
twidget& owner,
|
||||
const tdispatcher::tposition
|
||||
queue_position)
|
||||
: tmouse_motion(owner, queue_position)
|
||||
, last_click_stamp_(0)
|
||||
, last_clicked_widget_(NULL)
|
||||
|
@ -394,42 +385,45 @@ template<
|
|||
, signal_handler_sdl_button_up_entered_(false)
|
||||
{
|
||||
owner_.connect_signal<sdl_button_down>(
|
||||
boost::bind(&tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::signal_handler_sdl_button_down, this, _2, _3, _5)
|
||||
, queue_position);
|
||||
boost::bind(&tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::
|
||||
signal_handler_sdl_button_down,
|
||||
this,
|
||||
_2,
|
||||
_3,
|
||||
_5),
|
||||
queue_position);
|
||||
owner_.connect_signal<sdl_button_up>(
|
||||
boost::bind(&tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::signal_handler_sdl_button_up, this, _2, _3, _5)
|
||||
, queue_position);
|
||||
boost::bind(&tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::
|
||||
signal_handler_sdl_button_up,
|
||||
this,
|
||||
_2,
|
||||
_3,
|
||||
_5),
|
||||
queue_position);
|
||||
}
|
||||
|
||||
template<
|
||||
tevent sdl_button_down
|
||||
, tevent sdl_button_up
|
||||
, tevent button_down
|
||||
, tevent button_up
|
||||
, tevent button_click
|
||||
, tevent button_double_click
|
||||
> void tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::initialize_state(const bool is_down)
|
||||
template <tevent sdl_button_down,
|
||||
tevent sdl_button_up,
|
||||
tevent button_down,
|
||||
tevent button_up,
|
||||
tevent button_click,
|
||||
tevent button_double_click>
|
||||
void tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::initialize_state(const bool is_down)
|
||||
{
|
||||
last_click_stamp_ = 0;
|
||||
last_clicked_widget_ = NULL;
|
||||
|
@ -437,24 +431,21 @@ template<
|
|||
is_down_ = is_down;
|
||||
}
|
||||
|
||||
template<
|
||||
tevent sdl_button_down
|
||||
, tevent sdl_button_up
|
||||
, tevent button_down
|
||||
, tevent button_up
|
||||
, tevent button_click
|
||||
, tevent button_double_click
|
||||
> void tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::signal_handler_sdl_button_down(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate)
|
||||
template <tevent sdl_button_down,
|
||||
tevent sdl_button_up,
|
||||
tevent button_down,
|
||||
tevent button_up,
|
||||
tevent button_click,
|
||||
tevent button_double_click>
|
||||
void tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::
|
||||
signal_handler_sdl_button_down(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate)
|
||||
{
|
||||
if(signal_handler_sdl_button_down_entered_) {
|
||||
return;
|
||||
|
@ -465,8 +456,8 @@ template<
|
|||
|
||||
if(is_down_) {
|
||||
WRN_GUI_E << LOG_HEADER << event
|
||||
<< ". The mouse button is already down, "
|
||||
<< "we missed an event.\n";
|
||||
<< ". The mouse button is already down, "
|
||||
<< "we missed an event.\n";
|
||||
return;
|
||||
}
|
||||
is_down_ = true;
|
||||
|
@ -486,9 +477,8 @@ template<
|
|||
}
|
||||
|
||||
if(mouse_over != mouse_focus_) {
|
||||
WRN_GUI_E << LOG_HEADER
|
||||
<< ". Mouse down on non focussed widget "
|
||||
<< "and mouse not captured, we missed events.\n";
|
||||
WRN_GUI_E << LOG_HEADER << ". Mouse down on non focussed widget "
|
||||
<< "and mouse not captured, we missed events.\n";
|
||||
mouse_focus_ = mouse_over;
|
||||
}
|
||||
|
||||
|
@ -502,24 +492,21 @@ template<
|
|||
handled = true;
|
||||
}
|
||||
|
||||
template<
|
||||
tevent sdl_button_down
|
||||
, tevent sdl_button_up
|
||||
, tevent button_down
|
||||
, tevent button_up
|
||||
, tevent button_click
|
||||
, tevent button_double_click
|
||||
> void tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::signal_handler_sdl_button_up(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate)
|
||||
template <tevent sdl_button_down,
|
||||
tevent sdl_button_up,
|
||||
tevent button_down,
|
||||
tevent button_up,
|
||||
tevent button_click,
|
||||
tevent button_double_click>
|
||||
void tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::
|
||||
signal_handler_sdl_button_up(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate)
|
||||
{
|
||||
if(signal_handler_sdl_button_up_entered_) {
|
||||
return;
|
||||
|
@ -530,7 +517,7 @@ template<
|
|||
|
||||
if(!is_down_) {
|
||||
WRN_GUI_E << LOG_HEADER << event
|
||||
<< ". The mouse button is already up, we missed an event.\n";
|
||||
<< ". The mouse button is already up, we missed an event.\n";
|
||||
return;
|
||||
}
|
||||
is_down_ = false;
|
||||
|
@ -545,10 +532,10 @@ template<
|
|||
|
||||
twidget* mouse_over = owner_.find_at(coordinate, true);
|
||||
if(mouse_captured_) {
|
||||
const unsigned mask =
|
||||
SDL_BUTTON_LMASK | SDL_BUTTON_MMASK | SDL_BUTTON_RMASK;
|
||||
const unsigned mask = SDL_BUTTON_LMASK | SDL_BUTTON_MMASK
|
||||
| SDL_BUTTON_RMASK;
|
||||
|
||||
if((SDL_GetMouseState(NULL, NULL) & mask ) == 0) {
|
||||
if((SDL_GetMouseState(NULL, NULL) & mask) == 0) {
|
||||
mouse_captured_ = false;
|
||||
}
|
||||
|
||||
|
@ -569,28 +556,24 @@ template<
|
|||
handled = true;
|
||||
}
|
||||
|
||||
template<
|
||||
tevent sdl_button_down
|
||||
, tevent sdl_button_up
|
||||
, tevent button_down
|
||||
, tevent button_up
|
||||
, tevent button_click
|
||||
, tevent button_double_click
|
||||
> void tmouse_button<
|
||||
sdl_button_down
|
||||
, sdl_button_up
|
||||
, button_down
|
||||
, button_up
|
||||
, button_click
|
||||
, button_double_click
|
||||
>::mouse_button_click(twidget* widget)
|
||||
template <tevent sdl_button_down,
|
||||
tevent sdl_button_up,
|
||||
tevent button_down,
|
||||
tevent button_up,
|
||||
tevent button_click,
|
||||
tevent button_double_click>
|
||||
void tmouse_button<sdl_button_down,
|
||||
sdl_button_up,
|
||||
button_down,
|
||||
button_up,
|
||||
button_click,
|
||||
button_double_click>::mouse_button_click(twidget* widget)
|
||||
{
|
||||
Uint32 stamp = SDL_GetTicks();
|
||||
if(last_click_stamp_ + settings::double_click_time >= stamp
|
||||
&& last_clicked_widget_ == widget) {
|
||||
&& last_clicked_widget_ == widget) {
|
||||
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: "
|
||||
<< button_double_click << ".\n";
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: " << button_double_click << ".\n";
|
||||
|
||||
owner_.fire(button_double_click, *widget);
|
||||
last_click_stamp_ = 0;
|
||||
|
@ -614,18 +597,12 @@ template<
|
|||
* @todo Test whether the state is properly tracked when an input blocker is
|
||||
* used.
|
||||
*/
|
||||
tdistributor::tdistributor(twidget& owner
|
||||
, const tdispatcher::tposition queue_position)
|
||||
tdistributor::tdistributor(twidget& owner,
|
||||
const tdispatcher::tposition queue_position)
|
||||
: tmouse_motion(owner, queue_position)
|
||||
, tmouse_button_left("left"
|
||||
, owner
|
||||
, queue_position)
|
||||
, tmouse_button_middle("middle"
|
||||
, owner
|
||||
, queue_position)
|
||||
, tmouse_button_right("right"
|
||||
, owner
|
||||
, queue_position)
|
||||
, tmouse_button_left("left", owner, queue_position)
|
||||
, tmouse_button_middle("middle", owner, queue_position)
|
||||
, tmouse_button_right("right", owner, queue_position)
|
||||
#if 0
|
||||
, hover_pending_(false)
|
||||
, hover_id_(0)
|
||||
|
@ -643,32 +620,22 @@ tdistributor::tdistributor(twidget& owner
|
|||
}
|
||||
}
|
||||
|
||||
owner_.connect_signal<event::SDL_KEY_DOWN>(
|
||||
boost::bind(&tdistributor::signal_handler_sdl_key_down
|
||||
, this, _5, _6, _7));
|
||||
owner_.connect_signal<event::SDL_KEY_DOWN>(boost::bind(
|
||||
&tdistributor::signal_handler_sdl_key_down, this, _5, _6, _7));
|
||||
|
||||
owner_.connect_signal<event::NOTIFY_REMOVAL>(
|
||||
boost::bind(
|
||||
&tdistributor::signal_handler_notify_removal
|
||||
, this
|
||||
, _1
|
||||
, _2));
|
||||
owner_.connect_signal<event::NOTIFY_REMOVAL>(boost::bind(
|
||||
&tdistributor::signal_handler_notify_removal, this, _1, _2));
|
||||
|
||||
initialize_state();
|
||||
}
|
||||
|
||||
tdistributor::~tdistributor()
|
||||
{
|
||||
owner_.disconnect_signal<event::SDL_KEY_DOWN>(
|
||||
boost::bind(&tdistributor::signal_handler_sdl_key_down
|
||||
, this, _5, _6, _7));
|
||||
owner_.disconnect_signal<event::SDL_KEY_DOWN>(boost::bind(
|
||||
&tdistributor::signal_handler_sdl_key_down, this, _5, _6, _7));
|
||||
|
||||
owner_.disconnect_signal<event::NOTIFY_REMOVAL>(
|
||||
boost::bind(
|
||||
&tdistributor::signal_handler_notify_removal
|
||||
, this
|
||||
, _1
|
||||
, _2));
|
||||
owner_.disconnect_signal<event::NOTIFY_REMOVAL>(boost::bind(
|
||||
&tdistributor::signal_handler_notify_removal, this, _1, _2));
|
||||
}
|
||||
|
||||
void tdistributor::initialize_state()
|
||||
|
@ -685,8 +652,8 @@ void tdistributor::initialize_state()
|
|||
void tdistributor::keyboard_capture(twidget* widget)
|
||||
{
|
||||
if(keyboard_focus_) {
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: "
|
||||
<< event::LOSE_KEYBOARD_FOCUS << ".\n";
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: " << event::LOSE_KEYBOARD_FOCUS
|
||||
<< ".\n";
|
||||
|
||||
owner_.fire(event::LOSE_KEYBOARD_FOCUS, *keyboard_focus_, NULL);
|
||||
}
|
||||
|
@ -694,8 +661,8 @@ void tdistributor::keyboard_capture(twidget* widget)
|
|||
keyboard_focus_ = widget;
|
||||
|
||||
if(keyboard_focus_) {
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: "
|
||||
<< event::RECEIVE_KEYBOARD_FOCUS << ".\n";
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: " << event::RECEIVE_KEYBOARD_FOCUS
|
||||
<< ".\n";
|
||||
|
||||
owner_.fire(event::RECEIVE_KEYBOARD_FOCUS, *keyboard_focus_, NULL);
|
||||
}
|
||||
|
@ -704,10 +671,9 @@ void tdistributor::keyboard_capture(twidget* widget)
|
|||
void tdistributor::keyboard_add_to_chain(twidget* widget)
|
||||
{
|
||||
assert(widget);
|
||||
assert(std::find(keyboard_focus_chain_.begin()
|
||||
, keyboard_focus_chain_.end()
|
||||
, widget)
|
||||
== keyboard_focus_chain_.end());
|
||||
assert(std::find(keyboard_focus_chain_.begin(),
|
||||
keyboard_focus_chain_.end(),
|
||||
widget) == keyboard_focus_chain_.end());
|
||||
|
||||
keyboard_focus_chain_.push_back(widget);
|
||||
}
|
||||
|
@ -716,16 +682,16 @@ void tdistributor::keyboard_remove_from_chain(twidget* widget)
|
|||
{
|
||||
assert(widget);
|
||||
std::vector<twidget*>::iterator itor = std::find(
|
||||
keyboard_focus_chain_.begin(), keyboard_focus_chain_.end(), widget);
|
||||
keyboard_focus_chain_.begin(), keyboard_focus_chain_.end(), widget);
|
||||
|
||||
if(itor != keyboard_focus_chain_.end()) {
|
||||
keyboard_focus_chain_.erase(itor);
|
||||
}
|
||||
}
|
||||
|
||||
void tdistributor::signal_handler_sdl_key_down(const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode)
|
||||
void tdistributor::signal_handler_sdl_key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
{
|
||||
/** @todo Test whether recursion protection is needed. */
|
||||
|
||||
|
@ -737,18 +703,22 @@ void tdistributor::signal_handler_sdl_key_down(const SDLKey key
|
|||
// is enabled and ready to receive events.
|
||||
tcontrol* control = dynamic_cast<tcontrol*>(keyboard_focus_);
|
||||
if(!control || control->get_active()) {
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: " << event::SDL_KEY_DOWN << ".\n";
|
||||
if(owner_.fire(event::SDL_KEY_DOWN
|
||||
, *keyboard_focus_, key, modifier, unicode)) {
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: " << event::SDL_KEY_DOWN
|
||||
<< ".\n";
|
||||
if(owner_.fire(event::SDL_KEY_DOWN,
|
||||
*keyboard_focus_,
|
||||
key,
|
||||
modifier,
|
||||
unicode)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(std::vector<twidget*>::reverse_iterator
|
||||
ritor = keyboard_focus_chain_.rbegin()
|
||||
; ritor != keyboard_focus_chain_.rend()
|
||||
; ++ritor) {
|
||||
for(std::vector<twidget*>::reverse_iterator ritor
|
||||
= keyboard_focus_chain_.rbegin();
|
||||
ritor != keyboard_focus_chain_.rend();
|
||||
++ritor) {
|
||||
|
||||
if(*ritor == keyboard_focus_) {
|
||||
continue;
|
||||
|
@ -777,16 +747,15 @@ void tdistributor::signal_handler_sdl_key_down(const SDLKey key
|
|||
}
|
||||
|
||||
DBG_GUI_E << LOG_HEADER << "Firing: " << event::SDL_KEY_DOWN << ".\n";
|
||||
if(owner_.fire(event::SDL_KEY_DOWN
|
||||
, **ritor, key, modifier, unicode)) {
|
||||
if(owner_.fire(event::SDL_KEY_DOWN, **ritor, key, modifier, unicode)) {
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tdistributor::signal_handler_notify_removal(
|
||||
tdispatcher& widget, const tevent event)
|
||||
void tdistributor::signal_handler_notify_removal(tdispatcher& widget,
|
||||
const tevent event)
|
||||
{
|
||||
DBG_GUI_E << LOG_HEADER << event << ".\n";
|
||||
|
||||
|
@ -829,10 +798,10 @@ void tdistributor::signal_handler_notify_removal(
|
|||
if(keyboard_focus_ == &widget) {
|
||||
keyboard_focus_ = NULL;
|
||||
}
|
||||
const std::vector<twidget*>::iterator itor = std::find(
|
||||
keyboard_focus_chain_.begin()
|
||||
, keyboard_focus_chain_.end()
|
||||
, &widget);
|
||||
const std::vector<twidget*>::iterator itor
|
||||
= std::find(keyboard_focus_chain_.begin(),
|
||||
keyboard_focus_chain_.end(),
|
||||
&widget);
|
||||
if(itor != keyboard_focus_chain_.end()) {
|
||||
keyboard_focus_chain_.erase(itor);
|
||||
}
|
||||
|
@ -841,4 +810,3 @@ void tdistributor::signal_handler_notify_removal(
|
|||
} // namespace event
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -42,18 +42,19 @@
|
|||
#include "gui/widgets/event_executor.hpp"
|
||||
#include "gui/lib/types/point.hpp"
|
||||
|
||||
namespace gui2{
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class twidget;
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
/***** ***** ***** ***** tmouse_motion ***** ***** ***** ***** *****/
|
||||
|
||||
class tmouse_motion
|
||||
{
|
||||
public:
|
||||
|
||||
tmouse_motion(twidget& owner, const tdispatcher::tposition queue_position);
|
||||
|
||||
~tmouse_motion();
|
||||
|
@ -65,11 +66,11 @@ public:
|
|||
*
|
||||
* @param capture Set or release the capturing.
|
||||
*/
|
||||
void capture_mouse(//twidget* widget);
|
||||
void capture_mouse( // twidget* widget);
|
||||
const bool capture = true);
|
||||
protected:
|
||||
|
||||
/** The widget that currently has the mouse focus_. */
|
||||
protected:
|
||||
/** The widget that currently has the mouse focus_. */
|
||||
twidget* mouse_focus_;
|
||||
|
||||
/** Did the current widget capture the focus_? */
|
||||
|
@ -118,7 +119,6 @@ protected:
|
|||
void mouse_leave();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Called when the mouse moves over a widget.
|
||||
*
|
||||
|
@ -131,41 +131,33 @@ private:
|
|||
void show_tooltip();
|
||||
|
||||
bool signal_handler_sdl_mouse_motion_entered_;
|
||||
void signal_handler_sdl_mouse_motion(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate);
|
||||
void signal_handler_sdl_mouse_motion(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate);
|
||||
|
||||
void signal_handler_sdl_wheel(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate);
|
||||
void signal_handler_sdl_wheel(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate);
|
||||
|
||||
void signal_handler_show_helptip(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate);
|
||||
void signal_handler_show_helptip(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate);
|
||||
};
|
||||
|
||||
/***** ***** ***** ***** tmouse_button ***** ***** ***** ***** *****/
|
||||
|
||||
template<
|
||||
tevent sdl_button_down
|
||||
, tevent sdl_button_up
|
||||
, tevent button_down
|
||||
, tevent button_up
|
||||
, tevent button_click
|
||||
, tevent button_double_click
|
||||
>
|
||||
class tmouse_button
|
||||
: public virtual tmouse_motion
|
||||
template <tevent sdl_button_down,
|
||||
tevent sdl_button_up,
|
||||
tevent button_down,
|
||||
tevent button_up,
|
||||
tevent button_click,
|
||||
tevent button_double_click>
|
||||
class tmouse_button : public virtual tmouse_motion
|
||||
{
|
||||
public:
|
||||
tmouse_button(
|
||||
const std::string& name_
|
||||
, twidget& owner
|
||||
, const tdispatcher::tposition queue_position
|
||||
);
|
||||
tmouse_button(const std::string& name_,
|
||||
twidget& owner,
|
||||
const tdispatcher::tposition queue_position);
|
||||
|
||||
/**
|
||||
* Initializes the state of the button.
|
||||
|
@ -197,16 +189,14 @@ private:
|
|||
bool is_down_;
|
||||
|
||||
bool signal_handler_sdl_button_down_entered_;
|
||||
void signal_handler_sdl_button_down(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate);
|
||||
void signal_handler_sdl_button_down(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate);
|
||||
|
||||
bool signal_handler_sdl_button_up_entered_;
|
||||
void signal_handler_sdl_button_up(
|
||||
const event::tevent event
|
||||
, bool& handled
|
||||
, const tpoint& coordinate);
|
||||
void signal_handler_sdl_button_up(const event::tevent event,
|
||||
bool& handled,
|
||||
const tpoint& coordinate);
|
||||
|
||||
|
||||
void mouse_button_click(twidget* widget);
|
||||
|
@ -214,43 +204,35 @@ private:
|
|||
|
||||
/***** ***** ***** ***** tdistributor ***** ***** ***** ***** *****/
|
||||
|
||||
typedef tmouse_button<
|
||||
SDL_LEFT_BUTTON_DOWN
|
||||
, SDL_LEFT_BUTTON_UP
|
||||
, LEFT_BUTTON_DOWN
|
||||
, LEFT_BUTTON_UP
|
||||
, LEFT_BUTTON_CLICK
|
||||
, LEFT_BUTTON_DOUBLE_CLICK
|
||||
> tmouse_button_left;
|
||||
typedef tmouse_button<SDL_LEFT_BUTTON_DOWN,
|
||||
SDL_LEFT_BUTTON_UP,
|
||||
LEFT_BUTTON_DOWN,
|
||||
LEFT_BUTTON_UP,
|
||||
LEFT_BUTTON_CLICK,
|
||||
LEFT_BUTTON_DOUBLE_CLICK> tmouse_button_left;
|
||||
|
||||
typedef tmouse_button<
|
||||
SDL_MIDDLE_BUTTON_DOWN
|
||||
, SDL_MIDDLE_BUTTON_UP
|
||||
, MIDDLE_BUTTON_DOWN
|
||||
, MIDDLE_BUTTON_UP
|
||||
, MIDDLE_BUTTON_CLICK
|
||||
, MIDDLE_BUTTON_DOUBLE_CLICK
|
||||
> tmouse_button_middle;
|
||||
typedef tmouse_button<SDL_MIDDLE_BUTTON_DOWN,
|
||||
SDL_MIDDLE_BUTTON_UP,
|
||||
MIDDLE_BUTTON_DOWN,
|
||||
MIDDLE_BUTTON_UP,
|
||||
MIDDLE_BUTTON_CLICK,
|
||||
MIDDLE_BUTTON_DOUBLE_CLICK> tmouse_button_middle;
|
||||
|
||||
typedef tmouse_button<
|
||||
SDL_RIGHT_BUTTON_DOWN
|
||||
, SDL_RIGHT_BUTTON_UP
|
||||
, RIGHT_BUTTON_DOWN
|
||||
, RIGHT_BUTTON_UP
|
||||
, RIGHT_BUTTON_CLICK
|
||||
, RIGHT_BUTTON_DOUBLE_CLICK
|
||||
> tmouse_button_right;
|
||||
typedef tmouse_button<SDL_RIGHT_BUTTON_DOWN,
|
||||
SDL_RIGHT_BUTTON_UP,
|
||||
RIGHT_BUTTON_DOWN,
|
||||
RIGHT_BUTTON_UP,
|
||||
RIGHT_BUTTON_CLICK,
|
||||
RIGHT_BUTTON_DOUBLE_CLICK> tmouse_button_right;
|
||||
|
||||
|
||||
/** The event handler class for the widget library. */
|
||||
class tdistributor
|
||||
: public tmouse_button_left
|
||||
, public tmouse_button_middle
|
||||
, public tmouse_button_right
|
||||
class tdistributor : public tmouse_button_left,
|
||||
public tmouse_button_middle,
|
||||
public tmouse_button_right
|
||||
{
|
||||
public:
|
||||
tdistributor(twidget& owner
|
||||
, const tdispatcher::tposition queue_position);
|
||||
tdistributor(twidget& owner, const tdispatcher::tposition queue_position);
|
||||
|
||||
~tdistributor();
|
||||
|
||||
|
@ -324,9 +306,9 @@ private:
|
|||
* widget. These functions are called by the SDL event handling functions.
|
||||
*/
|
||||
|
||||
void signal_handler_sdl_key_down(const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode);
|
||||
void signal_handler_sdl_key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode);
|
||||
|
||||
void signal_handler_notify_removal(tdispatcher& widget, const tevent event);
|
||||
};
|
||||
|
|
|
@ -50,9 +50,11 @@
|
|||
/* Since this code is still very experimental it's not enabled yet. */
|
||||
//#define ENABLE
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
/***** Static data. *****/
|
||||
class thandler;
|
||||
|
@ -74,7 +76,7 @@ static unsigned event_poll_interval = 0;
|
|||
*/
|
||||
static Uint32 timer_sdl_draw_event(Uint32, void*)
|
||||
{
|
||||
// DBG_GUI_E << "Pushing draw event in queue.\n";
|
||||
// DBG_GUI_E << "Pushing draw event in queue.\n";
|
||||
|
||||
SDL_Event event;
|
||||
SDL_UserEvent data;
|
||||
|
@ -100,9 +102,12 @@ static Uint32 timer_sdl_draw_event(Uint32, void*)
|
|||
*/
|
||||
static Uint32 timer_sdl_poll_events(Uint32, void*)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
events::pump();
|
||||
} catch(CVideo::quit&) {
|
||||
}
|
||||
catch(CVideo::quit&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return event_poll_interval;
|
||||
|
@ -116,10 +121,10 @@ static Uint32 timer_sdl_poll_events(Uint32, void*)
|
|||
*
|
||||
* It's a new experimental class.
|
||||
*/
|
||||
class thandler
|
||||
: public events::handler
|
||||
class thandler : public events::handler
|
||||
{
|
||||
friend bool gui2::is_in_dialog();
|
||||
|
||||
public:
|
||||
thandler();
|
||||
|
||||
|
@ -146,7 +151,6 @@ public:
|
|||
tdispatcher* mouse_focus;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Reinitializes the state of all dispatchers.
|
||||
*
|
||||
|
@ -241,9 +245,8 @@ private:
|
|||
* @param modifier The SDL key modifiers used.
|
||||
* @param unicode The unicode value for the key pressed.
|
||||
*/
|
||||
void key_down(const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode);
|
||||
void
|
||||
key_down(const SDLKey key, const SDLMod modifier, const Uint16 unicode);
|
||||
|
||||
/**
|
||||
* Fires a keyboard event which has no parameters.
|
||||
|
@ -284,7 +287,7 @@ thandler::thandler()
|
|||
}
|
||||
}
|
||||
|
||||
// The event context is created now we join it.
|
||||
// The event context is created now we join it.
|
||||
#ifdef ENABLE
|
||||
join();
|
||||
#endif
|
||||
|
@ -310,13 +313,13 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse_button_down(tpoint(event.button.x, event.button.y)
|
||||
, event.button.button);
|
||||
mouse_button_down(tpoint(event.button.x, event.button.y),
|
||||
event.button.button);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
mouse_button_up(tpoint(event.button.x, event.button.y)
|
||||
, event.button.button);
|
||||
mouse_button_up(tpoint(event.button.x, event.button.y),
|
||||
event.button.button);
|
||||
break;
|
||||
|
||||
case SHOW_HELPTIP_EVENT:
|
||||
|
@ -324,7 +327,7 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
break;
|
||||
|
||||
case HOVER_REMOVE_POPUP_EVENT:
|
||||
// remove_popup();
|
||||
// remove_popup();
|
||||
break;
|
||||
|
||||
case DRAW_EVENT:
|
||||
|
@ -335,17 +338,15 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
execute_timer(reinterpret_cast<size_t>(event.user.data1));
|
||||
break;
|
||||
|
||||
case CLOSE_WINDOW_EVENT:
|
||||
{
|
||||
/** @todo Convert this to a proper new style event. */
|
||||
DBG_GUI_E << "Firing " << CLOSE_WINDOW << ".\n";
|
||||
case CLOSE_WINDOW_EVENT: {
|
||||
/** @todo Convert this to a proper new style event. */
|
||||
DBG_GUI_E << "Firing " << CLOSE_WINDOW << ".\n";
|
||||
|
||||
twindow* window = twindow::window_instance(event.user.code);
|
||||
if(window) {
|
||||
window->set_retval(twindow::AUTO_CLOSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
twindow* window = twindow::window_instance(event.user.code);
|
||||
if(window) {
|
||||
window->set_retval(twindow::AUTO_CLOSE);
|
||||
}
|
||||
} break;
|
||||
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
button_down(event.jbutton);
|
||||
|
@ -373,7 +374,7 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
video_resize(tpoint(event.resize.w, event.resize.h));
|
||||
break;
|
||||
|
||||
#if (defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
|
||||
#if(defined(_X11) && !defined(__APPLE__)) || defined(_WIN32)
|
||||
case SDL_SYSWMEVENT:
|
||||
/* DO NOTHING */
|
||||
break;
|
||||
|
@ -389,8 +390,8 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
break;
|
||||
|
||||
default:
|
||||
WRN_GUI_E << "Unhandled event "
|
||||
<< static_cast<Uint32>(event.type) << ".\n";
|
||||
WRN_GUI_E << "Unhandled event " << static_cast<Uint32>(event.type)
|
||||
<< ".\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -398,7 +399,7 @@ void thandler::handle_event(const SDL_Event& event)
|
|||
void thandler::connect(tdispatcher* dispatcher)
|
||||
{
|
||||
assert(std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher)
|
||||
== dispatchers_.end());
|
||||
== dispatchers_.end());
|
||||
|
||||
if(dispatchers_.empty()) {
|
||||
event_context = new events::event_context();
|
||||
|
@ -411,8 +412,8 @@ void thandler::connect(tdispatcher* dispatcher)
|
|||
void thandler::disconnect(tdispatcher* dispatcher)
|
||||
{
|
||||
/***** Validate pre conditions. *****/
|
||||
std::vector<tdispatcher*>::iterator itor =
|
||||
std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher);
|
||||
std::vector<tdispatcher*>::iterator itor
|
||||
= std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher);
|
||||
assert(itor != dispatchers_.end());
|
||||
|
||||
/***** Remove dispatcher. *****/
|
||||
|
@ -426,7 +427,8 @@ void thandler::disconnect(tdispatcher* dispatcher)
|
|||
}
|
||||
|
||||
/***** Set proper state for the other dispatchers. *****/
|
||||
FOREACH(AUTO dispatcher, dispatchers_) {
|
||||
FOREACH(AUTO dispatcher, dispatchers_)
|
||||
{
|
||||
dynamic_cast<twidget&>(*dispatcher).set_is_dirty(true);
|
||||
}
|
||||
|
||||
|
@ -434,7 +436,7 @@ void thandler::disconnect(tdispatcher* dispatcher)
|
|||
|
||||
/***** Validate post conditions. *****/
|
||||
assert(std::find(dispatchers_.begin(), dispatchers_.end(), dispatcher)
|
||||
== dispatchers_.end());
|
||||
== dispatchers_.end());
|
||||
|
||||
if(dispatchers_.empty()) {
|
||||
leave();
|
||||
|
@ -445,17 +447,17 @@ void thandler::disconnect(tdispatcher* dispatcher)
|
|||
|
||||
void thandler::activate()
|
||||
{
|
||||
FOREACH(AUTO dispatcher, dispatchers_) {
|
||||
dispatcher->fire(SDL_ACTIVATE
|
||||
, dynamic_cast<twidget&>(*dispatcher)
|
||||
, NULL);
|
||||
FOREACH(AUTO dispatcher, dispatchers_)
|
||||
{
|
||||
dispatcher->fire(
|
||||
SDL_ACTIVATE, dynamic_cast<twidget&>(*dispatcher), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void thandler::draw(const bool force)
|
||||
{
|
||||
// Don't display this event since it floods the screen
|
||||
//DBG_GUI_E << "Firing " << DRAW << ".\n";
|
||||
// DBG_GUI_E << "Firing " << DRAW << ".\n";
|
||||
|
||||
/*
|
||||
* In normal draw mode the first window in not forced to be drawn the
|
||||
|
@ -469,7 +471,8 @@ void thandler::draw(const bool force)
|
|||
*
|
||||
* For now we use a hack, but would be nice to rewrite it for 1.9/1.11.
|
||||
*/
|
||||
FOREACH(AUTO dispatcher, dispatchers_) {
|
||||
FOREACH(AUTO dispatcher, dispatchers_)
|
||||
{
|
||||
if(!first) {
|
||||
/*
|
||||
* This leaves glitches on window borders if the window beneath it
|
||||
|
@ -500,10 +503,11 @@ void thandler::video_resize(const tpoint& new_size)
|
|||
{
|
||||
DBG_GUI_E << "Firing: " << SDL_VIDEO_RESIZE << ".\n";
|
||||
|
||||
FOREACH(AUTO dispatcher, dispatchers_) {
|
||||
dispatcher->fire(SDL_VIDEO_RESIZE
|
||||
, dynamic_cast<twidget&>(*dispatcher)
|
||||
, new_size);
|
||||
FOREACH(AUTO dispatcher, dispatchers_)
|
||||
{
|
||||
dispatcher->fire(SDL_VIDEO_RESIZE,
|
||||
dynamic_cast<twidget&>(*dispatcher),
|
||||
new_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -512,27 +516,26 @@ void thandler::mouse(const tevent event, const tpoint& position)
|
|||
DBG_GUI_E << "Firing: " << event << ".\n";
|
||||
|
||||
if(mouse_focus) {
|
||||
mouse_focus->fire(event
|
||||
, dynamic_cast<twidget&>(*mouse_focus)
|
||||
, position);
|
||||
mouse_focus->fire(
|
||||
event, dynamic_cast<twidget&>(*mouse_focus), position);
|
||||
} else {
|
||||
|
||||
for(std::vector<tdispatcher*>::reverse_iterator ritor =
|
||||
dispatchers_.rbegin(); ritor != dispatchers_.rend(); ++ritor) {
|
||||
for(std::vector<tdispatcher*>::reverse_iterator ritor
|
||||
= dispatchers_.rbegin();
|
||||
ritor != dispatchers_.rend();
|
||||
++ritor) {
|
||||
|
||||
if((**ritor).get_mouse_behavior() == tdispatcher::all) {
|
||||
(**ritor).fire(event
|
||||
, dynamic_cast<twidget&>(**ritor)
|
||||
, position);
|
||||
(**ritor)
|
||||
.fire(event, dynamic_cast<twidget&>(**ritor), position);
|
||||
break;
|
||||
}
|
||||
if((**ritor).get_mouse_behavior() == tdispatcher::none) {
|
||||
continue;
|
||||
}
|
||||
if((**ritor).is_at(position)) {
|
||||
(**ritor).fire(event
|
||||
, dynamic_cast<twidget&>(**ritor)
|
||||
, position);
|
||||
(**ritor)
|
||||
.fire(event, dynamic_cast<twidget&>(**ritor), position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -542,32 +545,32 @@ void thandler::mouse(const tevent event, const tpoint& position)
|
|||
void thandler::mouse_button_up(const tpoint& position, const Uint8 button)
|
||||
{
|
||||
switch(button) {
|
||||
case SDL_BUTTON_LEFT :
|
||||
case SDL_BUTTON_LEFT:
|
||||
mouse(SDL_LEFT_BUTTON_UP, position);
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE :
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
mouse(SDL_MIDDLE_BUTTON_UP, position);
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT :
|
||||
case SDL_BUTTON_RIGHT:
|
||||
mouse(SDL_RIGHT_BUTTON_UP, position);
|
||||
break;
|
||||
|
||||
case SDL_BUTTON_WHEELLEFT :
|
||||
case SDL_BUTTON_WHEELLEFT:
|
||||
mouse(SDL_WHEEL_LEFT, get_mouse_position());
|
||||
break;
|
||||
case SDL_BUTTON_WHEELRIGHT :
|
||||
case SDL_BUTTON_WHEELRIGHT:
|
||||
mouse(SDL_WHEEL_RIGHT, get_mouse_position());
|
||||
break;
|
||||
case SDL_BUTTON_WHEELUP :
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
mouse(SDL_WHEEL_UP, get_mouse_position());
|
||||
break;
|
||||
case SDL_BUTTON_WHEELDOWN :
|
||||
case SDL_BUTTON_WHEELDOWN:
|
||||
mouse(SDL_WHEEL_DOWN, get_mouse_position());
|
||||
break;
|
||||
|
||||
default:
|
||||
WRN_GUI_E << "Unhandled 'mouse button up' event for button "
|
||||
<< static_cast<Uint32>(button) << ".\n";
|
||||
<< static_cast<Uint32>(button) << ".\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -577,27 +580,25 @@ void thandler::mouse_button_down(const tpoint& position, const Uint8 button)
|
|||
// The wheel buttons generate and up and down event we handle the
|
||||
// up event so ignore the mouse if it's a down event. Handle it
|
||||
// here to avoid a warning.
|
||||
if(button == SDL_BUTTON_WHEELUP
|
||||
|| button == SDL_BUTTON_WHEELDOWN
|
||||
|| button == SDL_BUTTON_WHEELLEFT
|
||||
|| button == SDL_BUTTON_WHEELRIGHT) {
|
||||
if(button == SDL_BUTTON_WHEELUP || button == SDL_BUTTON_WHEELDOWN
|
||||
|| button == SDL_BUTTON_WHEELLEFT || button == SDL_BUTTON_WHEELRIGHT) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch(button) {
|
||||
case SDL_BUTTON_LEFT :
|
||||
case SDL_BUTTON_LEFT:
|
||||
mouse(SDL_LEFT_BUTTON_DOWN, position);
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE :
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
mouse(SDL_MIDDLE_BUTTON_DOWN, position);
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT :
|
||||
case SDL_BUTTON_RIGHT:
|
||||
mouse(SDL_RIGHT_BUTTON_DOWN, position);
|
||||
break;
|
||||
default:
|
||||
WRN_GUI_E << "Unhandled 'mouse button down' event for button "
|
||||
<< static_cast<Uint32>(button) << ".\n";
|
||||
<< static_cast<Uint32>(button) << ".\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -608,8 +609,10 @@ tdispatcher* thandler::keyboard_dispatcher()
|
|||
return keyboard_focus_;
|
||||
}
|
||||
|
||||
for(std::vector<tdispatcher*>::reverse_iterator ritor =
|
||||
dispatchers_.rbegin(); ritor != dispatchers_.rend(); ++ritor) {
|
||||
for(std::vector<tdispatcher*>::reverse_iterator ritor
|
||||
= dispatchers_.rbegin();
|
||||
ritor != dispatchers_.rend();
|
||||
++ritor) {
|
||||
|
||||
if((**ritor).get_want_keyboard_input()) {
|
||||
return *ritor;
|
||||
|
@ -627,7 +630,8 @@ void thandler::hat_motion(const SDL_JoyHatEvent& event)
|
|||
done = hotkey_pressed(hk);
|
||||
}
|
||||
if(!done) {
|
||||
//TODO fendrin think about handling hat motions that are not bound to a hotkey.
|
||||
// TODO fendrin think about handling hat motions that are not bound to a
|
||||
// hotkey.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -639,7 +643,8 @@ void thandler::button_down(const SDL_JoyButtonEvent& event)
|
|||
done = hotkey_pressed(hk);
|
||||
}
|
||||
if(!done) {
|
||||
//TODO fendrin think about handling button down events that are not bound to a hotkey.
|
||||
// TODO fendrin think about handling button down events that are not
|
||||
// bound to a hotkey.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,18 +671,18 @@ bool thandler::hotkey_pressed(const hotkey::hotkey_item& key)
|
|||
return dispatcher->execute_hotkey(hotkey::get_id(key.get_command()));
|
||||
}
|
||||
|
||||
void thandler::key_down(const SDLKey key
|
||||
, const SDLMod modifier
|
||||
, const Uint16 unicode)
|
||||
void thandler::key_down(const SDLKey key,
|
||||
const SDLMod modifier,
|
||||
const Uint16 unicode)
|
||||
{
|
||||
DBG_GUI_E << "Firing: " << SDL_KEY_DOWN << ".\n";
|
||||
|
||||
if(tdispatcher* dispatcher = keyboard_dispatcher()) {
|
||||
dispatcher->fire(SDL_KEY_DOWN
|
||||
, dynamic_cast<twidget&>(*dispatcher)
|
||||
, key
|
||||
, modifier
|
||||
, unicode);
|
||||
dispatcher->fire(SDL_KEY_DOWN,
|
||||
dynamic_cast<twidget&>(*dispatcher),
|
||||
key,
|
||||
modifier,
|
||||
unicode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -773,54 +778,130 @@ void capture_keyboard(tdispatcher* dispatcher)
|
|||
std::ostream& operator<<(std::ostream& stream, const tevent event)
|
||||
{
|
||||
switch(event) {
|
||||
case DRAW : stream << "draw"; break;
|
||||
case CLOSE_WINDOW : stream << "close window"; break;
|
||||
case SDL_VIDEO_RESIZE : stream << "SDL video resize"; break;
|
||||
case SDL_MOUSE_MOTION : stream << "SDL mouse motion"; break;
|
||||
case MOUSE_ENTER : stream << "mouse enter"; break;
|
||||
case MOUSE_LEAVE : stream << "mouse leave"; break;
|
||||
case MOUSE_MOTION : stream << "mouse motion"; break;
|
||||
case SDL_LEFT_BUTTON_DOWN : stream << "SDL left button down"; break;
|
||||
case SDL_LEFT_BUTTON_UP : stream << "SDL left button up"; break;
|
||||
case LEFT_BUTTON_DOWN : stream << "left button down"; break;
|
||||
case LEFT_BUTTON_UP : stream << "left button up"; break;
|
||||
case LEFT_BUTTON_CLICK : stream << "left button click"; break;
|
||||
case LEFT_BUTTON_DOUBLE_CLICK
|
||||
: stream << "left button double click";
|
||||
break;
|
||||
case SDL_MIDDLE_BUTTON_DOWN : stream << "SDL middle button down"; break;
|
||||
case SDL_MIDDLE_BUTTON_UP : stream << "SDL middle button up"; break;
|
||||
case MIDDLE_BUTTON_DOWN : stream << "middle button down"; break;
|
||||
case MIDDLE_BUTTON_UP : stream << "middle button up"; break;
|
||||
case MIDDLE_BUTTON_CLICK : stream << "middle button click"; break;
|
||||
case MIDDLE_BUTTON_DOUBLE_CLICK
|
||||
: stream << "middle button double click";
|
||||
break;
|
||||
case SDL_RIGHT_BUTTON_DOWN : stream << "SDL right button down"; break;
|
||||
case SDL_RIGHT_BUTTON_UP : stream << "SDL right button up"; break;
|
||||
case RIGHT_BUTTON_DOWN : stream << "right button down"; break;
|
||||
case RIGHT_BUTTON_UP : stream << "right button up"; break;
|
||||
case RIGHT_BUTTON_CLICK : stream << "right button click"; break;
|
||||
case RIGHT_BUTTON_DOUBLE_CLICK
|
||||
: stream << "right button double click";
|
||||
break;
|
||||
case SDL_WHEEL_LEFT : stream << "SDL wheel left"; break;
|
||||
case SDL_WHEEL_RIGHT : stream << "SDL wheel right"; break;
|
||||
case SDL_WHEEL_UP : stream << "SDL wheel up"; break;
|
||||
case SDL_WHEEL_DOWN : stream << "SDL wheel down"; break;
|
||||
case SDL_KEY_DOWN : stream << "SDL key down"; break;
|
||||
case DRAW:
|
||||
stream << "draw";
|
||||
break;
|
||||
case CLOSE_WINDOW:
|
||||
stream << "close window";
|
||||
break;
|
||||
case SDL_VIDEO_RESIZE:
|
||||
stream << "SDL video resize";
|
||||
break;
|
||||
case SDL_MOUSE_MOTION:
|
||||
stream << "SDL mouse motion";
|
||||
break;
|
||||
case MOUSE_ENTER:
|
||||
stream << "mouse enter";
|
||||
break;
|
||||
case MOUSE_LEAVE:
|
||||
stream << "mouse leave";
|
||||
break;
|
||||
case MOUSE_MOTION:
|
||||
stream << "mouse motion";
|
||||
break;
|
||||
case SDL_LEFT_BUTTON_DOWN:
|
||||
stream << "SDL left button down";
|
||||
break;
|
||||
case SDL_LEFT_BUTTON_UP:
|
||||
stream << "SDL left button up";
|
||||
break;
|
||||
case LEFT_BUTTON_DOWN:
|
||||
stream << "left button down";
|
||||
break;
|
||||
case LEFT_BUTTON_UP:
|
||||
stream << "left button up";
|
||||
break;
|
||||
case LEFT_BUTTON_CLICK:
|
||||
stream << "left button click";
|
||||
break;
|
||||
case LEFT_BUTTON_DOUBLE_CLICK:
|
||||
stream << "left button double click";
|
||||
break;
|
||||
case SDL_MIDDLE_BUTTON_DOWN:
|
||||
stream << "SDL middle button down";
|
||||
break;
|
||||
case SDL_MIDDLE_BUTTON_UP:
|
||||
stream << "SDL middle button up";
|
||||
break;
|
||||
case MIDDLE_BUTTON_DOWN:
|
||||
stream << "middle button down";
|
||||
break;
|
||||
case MIDDLE_BUTTON_UP:
|
||||
stream << "middle button up";
|
||||
break;
|
||||
case MIDDLE_BUTTON_CLICK:
|
||||
stream << "middle button click";
|
||||
break;
|
||||
case MIDDLE_BUTTON_DOUBLE_CLICK:
|
||||
stream << "middle button double click";
|
||||
break;
|
||||
case SDL_RIGHT_BUTTON_DOWN:
|
||||
stream << "SDL right button down";
|
||||
break;
|
||||
case SDL_RIGHT_BUTTON_UP:
|
||||
stream << "SDL right button up";
|
||||
break;
|
||||
case RIGHT_BUTTON_DOWN:
|
||||
stream << "right button down";
|
||||
break;
|
||||
case RIGHT_BUTTON_UP:
|
||||
stream << "right button up";
|
||||
break;
|
||||
case RIGHT_BUTTON_CLICK:
|
||||
stream << "right button click";
|
||||
break;
|
||||
case RIGHT_BUTTON_DOUBLE_CLICK:
|
||||
stream << "right button double click";
|
||||
break;
|
||||
case SDL_WHEEL_LEFT:
|
||||
stream << "SDL wheel left";
|
||||
break;
|
||||
case SDL_WHEEL_RIGHT:
|
||||
stream << "SDL wheel right";
|
||||
break;
|
||||
case SDL_WHEEL_UP:
|
||||
stream << "SDL wheel up";
|
||||
break;
|
||||
case SDL_WHEEL_DOWN:
|
||||
stream << "SDL wheel down";
|
||||
break;
|
||||
case SDL_KEY_DOWN:
|
||||
stream << "SDL key down";
|
||||
break;
|
||||
|
||||
case NOTIFY_REMOVAL : stream << "notify removal"; break;
|
||||
case NOTIFY_MODIFIED : stream << "notify modified"; break;
|
||||
case RECEIVE_KEYBOARD_FOCUS : stream << "receive keyboard focus"; break;
|
||||
case LOSE_KEYBOARD_FOCUS : stream << "lose keyboard focus"; break;
|
||||
case SHOW_TOOLTIP : stream << "show tooltip"; break;
|
||||
case NOTIFY_REMOVE_TOOLTIP : stream << "notify remove tooltip"; break;
|
||||
case SDL_ACTIVATE : stream << "SDL activate"; break;
|
||||
case MESSAGE_SHOW_TOOLTIP : stream << "message show tooltip"; break;
|
||||
case SHOW_HELPTIP : stream << "show helptip"; break;
|
||||
case MESSAGE_SHOW_HELPTIP : stream << "message show helptip"; break;
|
||||
case REQUEST_PLACEMENT : stream << "request placement"; break;
|
||||
case NOTIFY_REMOVAL:
|
||||
stream << "notify removal";
|
||||
break;
|
||||
case NOTIFY_MODIFIED:
|
||||
stream << "notify modified";
|
||||
break;
|
||||
case RECEIVE_KEYBOARD_FOCUS:
|
||||
stream << "receive keyboard focus";
|
||||
break;
|
||||
case LOSE_KEYBOARD_FOCUS:
|
||||
stream << "lose keyboard focus";
|
||||
break;
|
||||
case SHOW_TOOLTIP:
|
||||
stream << "show tooltip";
|
||||
break;
|
||||
case NOTIFY_REMOVE_TOOLTIP:
|
||||
stream << "notify remove tooltip";
|
||||
break;
|
||||
case SDL_ACTIVATE:
|
||||
stream << "SDL activate";
|
||||
break;
|
||||
case MESSAGE_SHOW_TOOLTIP:
|
||||
stream << "message show tooltip";
|
||||
break;
|
||||
case SHOW_HELPTIP:
|
||||
stream << "show helptip";
|
||||
break;
|
||||
case MESSAGE_SHOW_HELPTIP:
|
||||
stream << "message show helptip";
|
||||
break;
|
||||
case REQUEST_PLACEMENT:
|
||||
stream << "request placement";
|
||||
break;
|
||||
}
|
||||
|
||||
return stream;
|
||||
|
@ -834,4 +915,3 @@ bool is_in_dialog()
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
|
||||
#include <iosfwd>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
class tdispatcher;
|
||||
|
||||
|
@ -48,100 +50,131 @@ public:
|
|||
* @note When adding a new entry to the enum also add a unit test.
|
||||
*/
|
||||
enum tevent {
|
||||
DRAW /**< Periodic redraw request. */
|
||||
|
||||
, CLOSE_WINDOW /**< A request to close the current window. */
|
||||
, SDL_VIDEO_RESIZE /**<
|
||||
* A SDL resize request, coordinate is the
|
||||
* new window size.
|
||||
*/
|
||||
|
||||
, SDL_MOUSE_MOTION /**< A SDL mouse motion event. */
|
||||
, MOUSE_ENTER /**< A mouse enter event for a widget. */
|
||||
, MOUSE_MOTION /**< A mouse motion event for a widget. */
|
||||
, MOUSE_LEAVE /**< A mouse leave event for a widget. */
|
||||
|
||||
, SDL_LEFT_BUTTON_DOWN /**< A SDL left mouse button down event. */
|
||||
, SDL_LEFT_BUTTON_UP /**< A SDL left mouse button up event. */
|
||||
, LEFT_BUTTON_DOWN /**<
|
||||
* A left mouse button down event for a widget.
|
||||
*/
|
||||
, LEFT_BUTTON_UP /**<
|
||||
* A left mouse button up event for a widget.
|
||||
*/
|
||||
, LEFT_BUTTON_CLICK /**<
|
||||
* A left mouse button click event for a
|
||||
* widget.
|
||||
*/
|
||||
, LEFT_BUTTON_DOUBLE_CLICK /**<
|
||||
* A left mouse button double click event for
|
||||
* a widget.
|
||||
*/
|
||||
, SDL_MIDDLE_BUTTON_DOWN /**< A SDL middle mouse button down event. */
|
||||
, SDL_MIDDLE_BUTTON_UP /**< A SDL middle mouse button up event. */
|
||||
, MIDDLE_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */
|
||||
, MIDDLE_BUTTON_UP /**< See LEFT_BUTTON_UP. */
|
||||
, MIDDLE_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */
|
||||
, MIDDLE_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */
|
||||
|
||||
, SDL_RIGHT_BUTTON_DOWN /**< A SDL right mouse button down event. */
|
||||
, SDL_RIGHT_BUTTON_UP /**< A SDL right mouse button up event. */
|
||||
, RIGHT_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */
|
||||
, RIGHT_BUTTON_UP /**< See LEFT_BUTTON_UP. */
|
||||
, RIGHT_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */
|
||||
, RIGHT_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */
|
||||
|
||||
, SDL_WHEEL_LEFT /**< A SDL wheel left event. */
|
||||
, SDL_WHEEL_RIGHT /**< A SDL wheel right event. */
|
||||
, SDL_WHEEL_UP /**< A SDL wheel up event. */
|
||||
, SDL_WHEEL_DOWN /**< A SDL wheel down event. */
|
||||
|
||||
, SDL_KEY_DOWN /**< A SDL key down event. */
|
||||
|
||||
, NOTIFY_REMOVAL /**<
|
||||
* Send by a widget to notify others it's
|
||||
* being destroyed.
|
||||
*/
|
||||
, NOTIFY_MODIFIED /**<
|
||||
* Send by a widget to notify others its
|
||||
* contents or state are modified.
|
||||
*
|
||||
* What modified means is documented per
|
||||
* widget. If not documented the modified
|
||||
* means nothing.
|
||||
*/
|
||||
|
||||
, RECEIVE_KEYBOARD_FOCUS /**< Widget gets keyboard focus. */
|
||||
, LOSE_KEYBOARD_FOCUS /**< Widget loses keyboard focus. */
|
||||
, SHOW_TOOLTIP /**<
|
||||
* Request the widget to show its hover
|
||||
* tooltip.
|
||||
*/
|
||||
, NOTIFY_REMOVE_TOOLTIP /**<
|
||||
* Request the widget to show its hover
|
||||
* tooltip.
|
||||
*/
|
||||
, SDL_ACTIVATE /**<
|
||||
* The main application window is activated.
|
||||
*/
|
||||
|
||||
, MESSAGE_SHOW_TOOLTIP /**<
|
||||
* Request for somebody to show the tooltip
|
||||
* based on the data send.
|
||||
*/
|
||||
, SHOW_HELPTIP /**<
|
||||
* Request the widget to show its hover
|
||||
* helptip.
|
||||
*/
|
||||
, MESSAGE_SHOW_HELPTIP /**<
|
||||
* Request for somebody to show the helptip
|
||||
* based on the data send.
|
||||
*/
|
||||
, REQUEST_PLACEMENT /**<
|
||||
* Request for somebody to place the widget.
|
||||
* This may also cause updating of more
|
||||
* layout parts.
|
||||
*/
|
||||
DRAW /**< Periodic redraw request. */
|
||||
,
|
||||
CLOSE_WINDOW /**< A request to close the current window. */
|
||||
,
|
||||
SDL_VIDEO_RESIZE /**<
|
||||
* A SDL resize request, coordinate is the
|
||||
* new window size.
|
||||
*/
|
||||
,
|
||||
SDL_MOUSE_MOTION /**< A SDL mouse motion event. */
|
||||
,
|
||||
MOUSE_ENTER /**< A mouse enter event for a widget. */
|
||||
,
|
||||
MOUSE_MOTION /**< A mouse motion event for a widget. */
|
||||
,
|
||||
MOUSE_LEAVE /**< A mouse leave event for a widget. */
|
||||
,
|
||||
SDL_LEFT_BUTTON_DOWN /**< A SDL left mouse button down event. */
|
||||
,
|
||||
SDL_LEFT_BUTTON_UP /**< A SDL left mouse button up event. */
|
||||
,
|
||||
LEFT_BUTTON_DOWN /**<
|
||||
* A left mouse button down event for a widget.
|
||||
*/
|
||||
,
|
||||
LEFT_BUTTON_UP /**<
|
||||
* A left mouse button up event for a widget.
|
||||
*/
|
||||
,
|
||||
LEFT_BUTTON_CLICK /**<
|
||||
* A left mouse button click event for a
|
||||
* widget.
|
||||
*/
|
||||
,
|
||||
LEFT_BUTTON_DOUBLE_CLICK /**<
|
||||
* A left mouse button double click event for
|
||||
* a widget.
|
||||
*/
|
||||
,
|
||||
SDL_MIDDLE_BUTTON_DOWN /**< A SDL middle mouse button down event. */
|
||||
,
|
||||
SDL_MIDDLE_BUTTON_UP /**< A SDL middle mouse button up event. */
|
||||
,
|
||||
MIDDLE_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */
|
||||
,
|
||||
MIDDLE_BUTTON_UP /**< See LEFT_BUTTON_UP. */
|
||||
,
|
||||
MIDDLE_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */
|
||||
,
|
||||
MIDDLE_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */
|
||||
,
|
||||
SDL_RIGHT_BUTTON_DOWN /**< A SDL right mouse button down event. */
|
||||
,
|
||||
SDL_RIGHT_BUTTON_UP /**< A SDL right mouse button up event. */
|
||||
,
|
||||
RIGHT_BUTTON_DOWN /**< See LEFT_BUTTON_DOWN. */
|
||||
,
|
||||
RIGHT_BUTTON_UP /**< See LEFT_BUTTON_UP. */
|
||||
,
|
||||
RIGHT_BUTTON_CLICK /**< See LEFT_BUTTON_CLICK. */
|
||||
,
|
||||
RIGHT_BUTTON_DOUBLE_CLICK /**< See LEFT_BUTTON_DOUBLE_CLICK. */
|
||||
,
|
||||
SDL_WHEEL_LEFT /**< A SDL wheel left event. */
|
||||
,
|
||||
SDL_WHEEL_RIGHT /**< A SDL wheel right event. */
|
||||
,
|
||||
SDL_WHEEL_UP /**< A SDL wheel up event. */
|
||||
,
|
||||
SDL_WHEEL_DOWN /**< A SDL wheel down event. */
|
||||
,
|
||||
SDL_KEY_DOWN /**< A SDL key down event. */
|
||||
,
|
||||
NOTIFY_REMOVAL /**<
|
||||
* Send by a widget to notify others it's
|
||||
* being destroyed.
|
||||
*/
|
||||
,
|
||||
NOTIFY_MODIFIED /**<
|
||||
* Send by a widget to notify others its
|
||||
* contents or state are modified.
|
||||
*
|
||||
* What modified means is documented per
|
||||
* widget. If not documented the modified
|
||||
* means nothing.
|
||||
*/
|
||||
,
|
||||
RECEIVE_KEYBOARD_FOCUS /**< Widget gets keyboard focus. */
|
||||
,
|
||||
LOSE_KEYBOARD_FOCUS /**< Widget loses keyboard focus. */
|
||||
,
|
||||
SHOW_TOOLTIP /**<
|
||||
* Request the widget to show its hover
|
||||
* tooltip.
|
||||
*/
|
||||
,
|
||||
NOTIFY_REMOVE_TOOLTIP /**<
|
||||
* Request the widget to show its hover
|
||||
* tooltip.
|
||||
*/
|
||||
,
|
||||
SDL_ACTIVATE /**<
|
||||
* The main application window is activated.
|
||||
*/
|
||||
,
|
||||
MESSAGE_SHOW_TOOLTIP /**<
|
||||
* Request for somebody to show the tooltip
|
||||
* based on the data send.
|
||||
*/
|
||||
,
|
||||
SHOW_HELPTIP /**<
|
||||
* Request the widget to show its hover
|
||||
* helptip.
|
||||
*/
|
||||
,
|
||||
MESSAGE_SHOW_HELPTIP /**<
|
||||
* Request for somebody to show the helptip
|
||||
* based on the data send.
|
||||
*/
|
||||
,
|
||||
REQUEST_PLACEMENT /**<
|
||||
* Request for somebody to place the widget.
|
||||
* This may also cause updating of more
|
||||
* layout parts.
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -155,51 +188,44 @@ enum tevent {
|
|||
* NOTE some mouse functions like MOUSE_ENTER don't send the mouse coordinates
|
||||
* to the callback function so they are also in this category.
|
||||
*/
|
||||
typedef
|
||||
boost::mpl::set<
|
||||
boost::mpl::int_<DRAW>
|
||||
, boost::mpl::int_<CLOSE_WINDOW>
|
||||
, boost::mpl::int_<MOUSE_ENTER>
|
||||
, boost::mpl::int_<MOUSE_LEAVE>
|
||||
, boost::mpl::int_<LEFT_BUTTON_DOWN>
|
||||
, boost::mpl::int_<LEFT_BUTTON_UP>
|
||||
, boost::mpl::int_<LEFT_BUTTON_CLICK>
|
||||
, boost::mpl::int_<LEFT_BUTTON_DOUBLE_CLICK>
|
||||
, boost::mpl::int_<MIDDLE_BUTTON_DOWN>
|
||||
, boost::mpl::int_<MIDDLE_BUTTON_UP>
|
||||
, boost::mpl::int_<MIDDLE_BUTTON_CLICK>
|
||||
, boost::mpl::int_<MIDDLE_BUTTON_DOUBLE_CLICK>
|
||||
, boost::mpl::int_<RIGHT_BUTTON_DOWN>
|
||||
, boost::mpl::int_<RIGHT_BUTTON_UP>
|
||||
, boost::mpl::int_<RIGHT_BUTTON_CLICK>
|
||||
, boost::mpl::int_<RIGHT_BUTTON_DOUBLE_CLICK>
|
||||
>
|
||||
tset_event;
|
||||
typedef boost::mpl::set<boost::mpl::int_<DRAW>,
|
||||
boost::mpl::int_<CLOSE_WINDOW>,
|
||||
boost::mpl::int_<MOUSE_ENTER>,
|
||||
boost::mpl::int_<MOUSE_LEAVE>,
|
||||
boost::mpl::int_<LEFT_BUTTON_DOWN>,
|
||||
boost::mpl::int_<LEFT_BUTTON_UP>,
|
||||
boost::mpl::int_<LEFT_BUTTON_CLICK>,
|
||||
boost::mpl::int_<LEFT_BUTTON_DOUBLE_CLICK>,
|
||||
boost::mpl::int_<MIDDLE_BUTTON_DOWN>,
|
||||
boost::mpl::int_<MIDDLE_BUTTON_UP>,
|
||||
boost::mpl::int_<MIDDLE_BUTTON_CLICK>,
|
||||
boost::mpl::int_<MIDDLE_BUTTON_DOUBLE_CLICK>,
|
||||
boost::mpl::int_<RIGHT_BUTTON_DOWN>,
|
||||
boost::mpl::int_<RIGHT_BUTTON_UP>,
|
||||
boost::mpl::int_<RIGHT_BUTTON_CLICK>,
|
||||
boost::mpl::int_<RIGHT_BUTTON_DOUBLE_CLICK> >
|
||||
tset_event;
|
||||
|
||||
/**
|
||||
* Helper for catching use error of tdispatcher::connect_signal.
|
||||
*
|
||||
* This version is for callbacks with a coordinate as extra parameter.
|
||||
*/
|
||||
typedef
|
||||
boost::mpl::set<
|
||||
boost::mpl::int_<SDL_VIDEO_RESIZE>
|
||||
, boost::mpl::int_<SDL_MOUSE_MOTION>
|
||||
, boost::mpl::int_<MOUSE_MOTION>
|
||||
, boost::mpl::int_<SDL_LEFT_BUTTON_DOWN>
|
||||
, boost::mpl::int_<SDL_LEFT_BUTTON_UP>
|
||||
, boost::mpl::int_<SDL_MIDDLE_BUTTON_DOWN>
|
||||
, boost::mpl::int_<SDL_MIDDLE_BUTTON_UP>
|
||||
, boost::mpl::int_<SDL_RIGHT_BUTTON_DOWN>
|
||||
, boost::mpl::int_<SDL_RIGHT_BUTTON_UP>
|
||||
, boost::mpl::int_<SHOW_TOOLTIP>
|
||||
, boost::mpl::int_<SHOW_HELPTIP>
|
||||
, boost::mpl::int_<SDL_WHEEL_UP>
|
||||
, boost::mpl::int_<SDL_WHEEL_DOWN>
|
||||
, boost::mpl::int_<SDL_WHEEL_LEFT>
|
||||
, boost::mpl::int_<SDL_WHEEL_RIGHT>
|
||||
>
|
||||
tset_event_mouse;
|
||||
typedef boost::mpl::set<boost::mpl::int_<SDL_VIDEO_RESIZE>,
|
||||
boost::mpl::int_<SDL_MOUSE_MOTION>,
|
||||
boost::mpl::int_<MOUSE_MOTION>,
|
||||
boost::mpl::int_<SDL_LEFT_BUTTON_DOWN>,
|
||||
boost::mpl::int_<SDL_LEFT_BUTTON_UP>,
|
||||
boost::mpl::int_<SDL_MIDDLE_BUTTON_DOWN>,
|
||||
boost::mpl::int_<SDL_MIDDLE_BUTTON_UP>,
|
||||
boost::mpl::int_<SDL_RIGHT_BUTTON_DOWN>,
|
||||
boost::mpl::int_<SDL_RIGHT_BUTTON_UP>,
|
||||
boost::mpl::int_<SHOW_TOOLTIP>,
|
||||
boost::mpl::int_<SHOW_HELPTIP>,
|
||||
boost::mpl::int_<SDL_WHEEL_UP>,
|
||||
boost::mpl::int_<SDL_WHEEL_DOWN>,
|
||||
boost::mpl::int_<SDL_WHEEL_LEFT>,
|
||||
boost::mpl::int_<SDL_WHEEL_RIGHT> > tset_event_mouse;
|
||||
|
||||
/**
|
||||
* Helper for catching use error of tdispatcher::connect_signal.
|
||||
|
@ -207,29 +233,23 @@ typedef
|
|||
* This version is for callbacks with the keyboard values (these haven't been
|
||||
* determined yet).
|
||||
*/
|
||||
typedef
|
||||
boost::mpl::set<
|
||||
boost::mpl::int_<SDL_KEY_DOWN>
|
||||
>
|
||||
tset_event_keyboard;
|
||||
typedef boost::mpl::set<boost::mpl::int_<SDL_KEY_DOWN> > tset_event_keyboard;
|
||||
|
||||
/**
|
||||
* Helper for catching use error of tdispatcher::connect_signal.
|
||||
*
|
||||
* This version is for callbacks with a sender aka notification messages. Like the
|
||||
* This version is for callbacks with a sender aka notification messages. Like
|
||||
*the
|
||||
* ones in tset_event it has no extra parameters, but this version is only
|
||||
* send to the target and not using the pre and post queue.
|
||||
*/
|
||||
typedef
|
||||
boost::mpl::set<
|
||||
boost::mpl::int_<NOTIFY_REMOVAL>
|
||||
, boost::mpl::int_<NOTIFY_MODIFIED>
|
||||
, boost::mpl::int_<RECEIVE_KEYBOARD_FOCUS>
|
||||
, boost::mpl::int_<LOSE_KEYBOARD_FOCUS>
|
||||
, boost::mpl::int_<NOTIFY_REMOVE_TOOLTIP>
|
||||
, boost::mpl::int_<SDL_ACTIVATE>
|
||||
>
|
||||
tset_event_notification;
|
||||
typedef boost::mpl::set<boost::mpl::int_<NOTIFY_REMOVAL>,
|
||||
boost::mpl::int_<NOTIFY_MODIFIED>,
|
||||
boost::mpl::int_<RECEIVE_KEYBOARD_FOCUS>,
|
||||
boost::mpl::int_<LOSE_KEYBOARD_FOCUS>,
|
||||
boost::mpl::int_<NOTIFY_REMOVE_TOOLTIP>,
|
||||
boost::mpl::int_<SDL_ACTIVATE> >
|
||||
tset_event_notification;
|
||||
|
||||
/**
|
||||
* Helper for catching use error of tdispatcher::connect_signal.
|
||||
|
@ -239,13 +259,10 @@ typedef
|
|||
* is send from a widget all the way up to the window, who always is the
|
||||
* receiver of the message (unless somebody grabbed it before).
|
||||
*/
|
||||
typedef
|
||||
boost::mpl::set<
|
||||
boost::mpl::int_<MESSAGE_SHOW_TOOLTIP>
|
||||
, boost::mpl::int_<MESSAGE_SHOW_HELPTIP>
|
||||
, boost::mpl::int_<REQUEST_PLACEMENT>
|
||||
>
|
||||
tset_event_message;
|
||||
typedef boost::mpl::set<boost::mpl::int_<MESSAGE_SHOW_TOOLTIP>,
|
||||
boost::mpl::int_<MESSAGE_SHOW_HELPTIP>,
|
||||
boost::mpl::int_<REQUEST_PLACEMENT> >
|
||||
tset_event_message;
|
||||
|
||||
/**
|
||||
* Connects a dispatcher to the event handler.
|
||||
|
@ -314,4 +331,3 @@ bool is_in_dialog();
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
|
||||
#include "gui/widgets/helper.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace event {
|
||||
namespace event
|
||||
{
|
||||
|
||||
/**
|
||||
* The message callbacks hold a reference to a message.
|
||||
|
@ -42,18 +44,16 @@ namespace event {
|
|||
*/
|
||||
struct tmessage
|
||||
{
|
||||
virtual ~tmessage() {}
|
||||
virtual ~tmessage()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/** The message for MESSAGE_SHOW_TOOLTIP. */
|
||||
struct tmessage_show_tooltip
|
||||
: public tmessage
|
||||
struct tmessage_show_tooltip : public tmessage
|
||||
{
|
||||
tmessage_show_tooltip(
|
||||
const std::string& message_
|
||||
, const tpoint& location_)
|
||||
: message(message_)
|
||||
, location(location_)
|
||||
tmessage_show_tooltip(const std::string& message_, const tpoint& location_)
|
||||
: message(message_), location(location_)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -65,14 +65,10 @@ struct tmessage_show_tooltip
|
|||
};
|
||||
|
||||
/** The message for MESSAGE_SHOW_HELPTIP. */
|
||||
struct tmessage_show_helptip
|
||||
: public tmessage
|
||||
struct tmessage_show_helptip : public tmessage
|
||||
{
|
||||
tmessage_show_helptip(
|
||||
const std::string& message_
|
||||
, const tpoint& location_)
|
||||
: message(message_)
|
||||
, location(location_)
|
||||
tmessage_show_helptip(const std::string& message_, const tpoint& location_)
|
||||
: message(message_), location(location_)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -88,4 +84,3 @@ struct tmessage_show_helptip
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -25,23 +25,21 @@
|
|||
#include "util.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
template <class T>
|
||||
inline bool sort(
|
||||
const tpane::titem& lhs
|
||||
, const tpane::titem& rhs
|
||||
, const std::string& tag
|
||||
, const bool ascending)
|
||||
inline bool sort(const tpane::titem& lhs,
|
||||
const tpane::titem& rhs,
|
||||
const std::string& tag,
|
||||
const bool ascending)
|
||||
{
|
||||
if(ascending) {
|
||||
return
|
||||
lexical_cast<T>(at(lhs.tags, tag))
|
||||
< lexical_cast<T>(at(rhs.tags, tag));
|
||||
return lexical_cast<T>(at(lhs.tags, tag))
|
||||
< lexical_cast<T>(at(rhs.tags, tag));
|
||||
} else {
|
||||
return
|
||||
lexical_cast<T>(at(lhs.tags, tag))
|
||||
> lexical_cast<T>(at(rhs.tags, tag));
|
||||
return lexical_cast<T>(at(lhs.tags, tag))
|
||||
> lexical_cast<T>(at(rhs.tags, tag));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,13 +62,12 @@ inline bool sort(
|
|||
*
|
||||
* @returns Whether or not the comparison found a match.
|
||||
*/
|
||||
inline bool contains(
|
||||
const tpane::titem& item
|
||||
, const std::string& tag
|
||||
, const ttext_box& text_box)
|
||||
inline bool contains(const tpane::titem& item,
|
||||
const std::string& tag,
|
||||
const ttext_box& text_box)
|
||||
{
|
||||
return at(item.tags, tag)
|
||||
.find(utils::lowercase(text_box.text())) != std::string::npos;
|
||||
return at(item.tags, tag).find(utils::lowercase(text_box.text()))
|
||||
!= std::string::npos;
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "utils/const_clone.tpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the first parent of a widget with a certain type.
|
||||
|
@ -30,7 +31,8 @@ namespace gui2 {
|
|||
*
|
||||
* @returns The parent widget.
|
||||
*/
|
||||
template<class T> T& get_parent(twidget& widget)
|
||||
template <class T>
|
||||
T& get_parent(twidget& widget)
|
||||
{
|
||||
T* result;
|
||||
twidget* w = &widget;
|
||||
|
@ -38,7 +40,7 @@ template<class T> T& get_parent(twidget& widget)
|
|||
w = w->parent();
|
||||
result = dynamic_cast<T*>(w);
|
||||
|
||||
} while (w && !result);
|
||||
} while(w && !result);
|
||||
|
||||
assert(result);
|
||||
return *result;
|
||||
|
@ -63,14 +65,13 @@ template<class T> T& get_parent(twidget& widget)
|
|||
*
|
||||
* @returns The widget with the id.
|
||||
*/
|
||||
template<class T>
|
||||
T* find_widget(typename utils::tconst_clone<twidget, T>::pointer widget
|
||||
, const std::string& id
|
||||
, const bool must_be_active
|
||||
, const bool must_exist)
|
||||
template <class T>
|
||||
T* find_widget(typename utils::tconst_clone<twidget, T>::pointer widget,
|
||||
const std::string& id,
|
||||
const bool must_be_active,
|
||||
const bool must_exist)
|
||||
{
|
||||
T* result =
|
||||
dynamic_cast<T*>(widget->find(id, must_be_active));
|
||||
T* result = dynamic_cast<T*>(widget->find(id, must_be_active));
|
||||
VALIDATE(!must_exist || result, missing_widget(id));
|
||||
|
||||
return result;
|
||||
|
@ -91,10 +92,10 @@ T* find_widget(typename utils::tconst_clone<twidget, T>::pointer widget
|
|||
*
|
||||
* @returns The widget with the id.
|
||||
*/
|
||||
template<class T>
|
||||
T& find_widget(typename utils::tconst_clone<twidget, T>::pointer widget
|
||||
, const std::string& id
|
||||
, const bool must_be_active)
|
||||
template <class T>
|
||||
T& find_widget(typename utils::tconst_clone<twidget, T>::pointer widget,
|
||||
const std::string& id,
|
||||
const bool must_be_active)
|
||||
{
|
||||
return *find_widget<T>(widget, id, must_be_active, true);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2{
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Template class can hold a value or a formula to calculate the value.
|
||||
|
@ -85,16 +86,16 @@ public:
|
|||
* @returns The stored result or the result of the
|
||||
* evaluation of the formula.
|
||||
*/
|
||||
T operator() (
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions = NULL
|
||||
) const;
|
||||
T operator()(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions = NULL) const;
|
||||
|
||||
/** Determine whether the class contains a formula. */
|
||||
bool has_formula() const { return !formula_.empty(); }
|
||||
bool has_formula() const
|
||||
{
|
||||
return !formula_.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Converts the string to the template type.
|
||||
*
|
||||
|
@ -122,9 +123,8 @@ private:
|
|||
*
|
||||
* @returns The calculated value.
|
||||
*/
|
||||
T execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const;
|
||||
T execute(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const;
|
||||
|
||||
/**
|
||||
* Contains the formula for the variable.
|
||||
|
@ -137,10 +137,9 @@ private:
|
|||
T value_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
tformula<T>::tformula(const std::string& str, const T value) :
|
||||
formula_(),
|
||||
value_(value)
|
||||
template <class T>
|
||||
tformula<T>::tformula(const std::string& str, const T value)
|
||||
: formula_(), value_(value)
|
||||
{
|
||||
if(str.empty()) {
|
||||
return;
|
||||
|
@ -153,81 +152,86 @@ tformula<T>::tformula(const std::string& str, const T value) :
|
|||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T tformula<T>::operator()(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
template <class T>
|
||||
inline T tformula<T>::
|
||||
operator()(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
if(has_formula()) {
|
||||
const T& result = execute(variables, functions);
|
||||
LOG_GUI_D << "Formula: execute '" << formula_
|
||||
<< "' result '" << result
|
||||
<< "'.\n";
|
||||
LOG_GUI_D << "Formula: execute '" << formula_ << "' result '" << result
|
||||
<< "'.\n";
|
||||
return result;
|
||||
} else {
|
||||
return value_;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
inline bool tformula<bool>::execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
template <>
|
||||
inline bool
|
||||
tformula<bool>::execute(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
return game_logic::formula(formula_, functions)
|
||||
.evaluate(variables).as_bool();
|
||||
.evaluate(variables)
|
||||
.as_bool();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline int tformula<int>::execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
template <>
|
||||
inline int
|
||||
tformula<int>::execute(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
return game_logic::formula(formula_, functions)
|
||||
.evaluate(variables).as_int();
|
||||
.evaluate(variables)
|
||||
.as_int();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline unsigned tformula<unsigned>::execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
template <>
|
||||
inline unsigned
|
||||
tformula<unsigned>::execute(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
return game_logic::formula(formula_, functions)
|
||||
.evaluate(variables).as_int();
|
||||
.evaluate(variables)
|
||||
.as_int();
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline std::string tformula<std::string>::execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
return game_logic::formula(formula_, functions)
|
||||
.evaluate(variables).as_string();
|
||||
.evaluate(variables)
|
||||
.as_string();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline t_string tformula<t_string>::execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
template <>
|
||||
inline t_string
|
||||
tformula<t_string>::execute(const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
return game_logic::formula(formula_, functions)
|
||||
.evaluate(variables).as_string();
|
||||
.evaluate(variables)
|
||||
.as_string();
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline PangoAlignment tformula<PangoAlignment>::execute(
|
||||
const game_logic::map_formula_callable& variables
|
||||
, game_logic::function_symbol_table* functions) const
|
||||
const game_logic::map_formula_callable& variables,
|
||||
game_logic::function_symbol_table* functions) const
|
||||
{
|
||||
return decode_text_alignment(
|
||||
game_logic::formula(formula_, functions)
|
||||
.evaluate(variables).as_string());
|
||||
return decode_text_alignment(game_logic::formula(formula_, functions)
|
||||
.evaluate(variables)
|
||||
.as_string());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T tformula<T>::execute(
|
||||
const game_logic::map_formula_callable& /*variables*/
|
||||
, game_logic::function_symbol_table* /*functions*/) const
|
||||
template <class T>
|
||||
inline T
|
||||
tformula<T>::execute(const game_logic::map_formula_callable& /*variables*/
|
||||
,
|
||||
game_logic::function_symbol_table* /*functions*/) const
|
||||
{
|
||||
// Every type needs its own execute function avoid instantiation of the
|
||||
// default execute.
|
||||
|
@ -235,31 +239,31 @@ inline T tformula<T>::execute(
|
|||
return T();
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline void tformula<bool>::convert(const std::string& str)
|
||||
{
|
||||
value_ = utils::string_bool(str);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline void tformula<std::string>::convert(const std::string& str)
|
||||
{
|
||||
value_ = str;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline void tformula<t_string>::convert(const std::string& str)
|
||||
{
|
||||
value_ = str;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline void tformula<PangoAlignment>::convert(const std::string& str)
|
||||
{
|
||||
value_ = decode_text_alignment(str);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void tformula<T>::convert(const std::string& str)
|
||||
{
|
||||
value_ = lexical_cast_default<T>(str);
|
||||
|
|
|
@ -25,18 +25,18 @@
|
|||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
/**
|
||||
* Thrown when deferring an invalid iterator.
|
||||
*
|
||||
* Invalid means the initial state at_end() == true.
|
||||
*/
|
||||
class tlogic_error
|
||||
: public std::logic_error
|
||||
, public tlua_jailbreak_exception
|
||||
class tlogic_error : public std::logic_error, public tlua_jailbreak_exception
|
||||
{
|
||||
public:
|
||||
explicit tlogic_error(const std::string& message)
|
||||
|
@ -46,7 +46,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(tlogic_error)
|
||||
};
|
||||
|
||||
|
@ -55,9 +54,7 @@ private:
|
|||
*
|
||||
* Invalid means the initial state at_end() == true.
|
||||
*/
|
||||
class trange_error
|
||||
: public std::range_error
|
||||
, public tlua_jailbreak_exception
|
||||
class trange_error : public std::range_error, public tlua_jailbreak_exception
|
||||
{
|
||||
public:
|
||||
explicit trange_error(const std::string& message)
|
||||
|
@ -67,7 +64,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(trange_error)
|
||||
};
|
||||
|
||||
|
@ -76,4 +72,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/iterator.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
|
||||
} // namespace iterator
|
||||
|
@ -184,4 +186,3 @@ for(titerator<policy> itor(root); !itor.at_end(); ++itor) {
|
|||
*
|
||||
* [GoF] http://en.wikipedia.org/wiki/Design_Patterns_%28book%29
|
||||
*/
|
||||
|
||||
|
|
|
@ -24,29 +24,27 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/policy_order.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
/**
|
||||
* The iterator class.
|
||||
*
|
||||
* See @ref gui2_iterator_iterator for more information.
|
||||
*/
|
||||
template<class order>
|
||||
class titerator
|
||||
: private order
|
||||
, private boost::noncopyable
|
||||
template <class order>
|
||||
class titerator : private order, private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param root The widget where to start the iteration.
|
||||
*/
|
||||
titerator(twidget& root)
|
||||
: order(root)
|
||||
titerator(twidget& root) : order(root)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -57,7 +55,10 @@ public:
|
|||
* @retval [true] At the end.
|
||||
* @retval [false] Not at the end.
|
||||
*/
|
||||
bool at_end() const { return order::at_end(); }
|
||||
bool at_end() const
|
||||
{
|
||||
return order::at_end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Visit the next widget.
|
||||
|
@ -71,7 +72,10 @@ public:
|
|||
* @returns Whether the next widget can be safely
|
||||
* deferred.
|
||||
*/
|
||||
bool next() { return order::next(); }
|
||||
bool next()
|
||||
{
|
||||
return order::next();
|
||||
}
|
||||
|
||||
/** See @ref next. */
|
||||
titerator<order>& operator++()
|
||||
|
@ -85,7 +89,10 @@ public:
|
|||
*
|
||||
* @returns The current widget.
|
||||
*/
|
||||
twidget& operator*() { return order::operator*(); }
|
||||
twidget& operator*()
|
||||
{
|
||||
return order::operator*();
|
||||
}
|
||||
|
||||
/** See @ref operator*. */
|
||||
twidget* operator->()
|
||||
|
@ -99,4 +106,3 @@ public:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,31 +22,29 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
namespace policy {
|
||||
namespace policy
|
||||
{
|
||||
|
||||
namespace order {
|
||||
namespace order
|
||||
{
|
||||
|
||||
template<
|
||||
bool visit_widget
|
||||
, bool visit_grid
|
||||
, bool visit_child
|
||||
>
|
||||
class tbottom_up
|
||||
: public tvisit<visit_widget, twalker_::widget>
|
||||
, public tvisit<visit_grid, twalker_::grid>
|
||||
, public tvisit<visit_child, twalker_::child>
|
||||
template <bool visit_widget, bool visit_grid, bool visit_child>
|
||||
class tbottom_up : public tvisit<visit_widget, twalker_::widget>,
|
||||
public tvisit<visit_grid, twalker_::grid>,
|
||||
public tvisit<visit_child, twalker_::child>
|
||||
{
|
||||
typedef tvisit<visit_widget, twalker_::widget> tvisit_widget;
|
||||
typedef tvisit<visit_grid, twalker_::grid> tvisit_grid;
|
||||
typedef tvisit<visit_child, twalker_::child> tvisit_child;
|
||||
|
||||
public:
|
||||
explicit tbottom_up(twidget& root)
|
||||
: root_(root.create_walker())
|
||||
, stack_()
|
||||
explicit tbottom_up(twidget& root) : root_(root.create_walker()), stack_()
|
||||
{
|
||||
TST_GUI_I << "Constructor: ";
|
||||
while(!tvisit_child::at_end(*root_)) {
|
||||
|
@ -65,9 +63,9 @@ public:
|
|||
~tbottom_up()
|
||||
{
|
||||
delete root_;
|
||||
for(std::vector<iterator::twalker_*>::iterator itor = stack_.begin()
|
||||
; itor != stack_.end()
|
||||
; ++itor) {
|
||||
for(std::vector<iterator::twalker_*>::iterator itor = stack_.begin();
|
||||
itor != stack_.end();
|
||||
++itor) {
|
||||
|
||||
delete *itor;
|
||||
}
|
||||
|
@ -75,9 +73,8 @@ public:
|
|||
|
||||
bool at_end() const
|
||||
{
|
||||
return tvisit_widget::at_end(*root_)
|
||||
&& tvisit_grid::at_end(*root_)
|
||||
&& tvisit_child::at_end(*root_);
|
||||
return tvisit_widget::at_end(*root_) && tvisit_grid::at_end(*root_)
|
||||
&& tvisit_child::at_end(*root_);
|
||||
}
|
||||
|
||||
bool next()
|
||||
|
@ -93,16 +90,16 @@ public:
|
|||
TST_GUI_I << " Iterate widget:";
|
||||
if(!tvisit_widget::at_end(*root_)) {
|
||||
switch(tvisit_widget::next(*root_)) {
|
||||
case twalker_::valid :
|
||||
case twalker_::valid:
|
||||
TST_GUI_I << " visit '" << operator*().id() << "'.\n";
|
||||
return true;
|
||||
case twalker_::invalid :
|
||||
case twalker_::invalid:
|
||||
TST_GUI_I << " reached the end.";
|
||||
break;
|
||||
case twalker_::fail:
|
||||
TST_GUI_I << "\n";
|
||||
ERR_GUI_E << "Tried to move beyond end of "
|
||||
"the widget iteration range.\n";
|
||||
"the widget iteration range.\n";
|
||||
throw trange_error("Tried to move beyond end of range.");
|
||||
}
|
||||
} else {
|
||||
|
@ -113,16 +110,16 @@ public:
|
|||
TST_GUI_I << " Iterate grid:";
|
||||
if(!tvisit_grid::at_end(*root_)) {
|
||||
switch(tvisit_grid::next(*root_)) {
|
||||
case twalker_::valid :
|
||||
case twalker_::valid:
|
||||
TST_GUI_I << " visit '" << operator*().id() << "'.\n";
|
||||
return true;
|
||||
case twalker_::invalid :
|
||||
case twalker_::invalid:
|
||||
TST_GUI_I << " reached the end.";
|
||||
break;
|
||||
case twalker_::fail:
|
||||
TST_GUI_I << "\n";
|
||||
ERR_GUI_E << "Tried to move beyond end of "
|
||||
"the grid iteration range.\n";
|
||||
"the grid iteration range.\n";
|
||||
throw trange_error("Tried to move beyond end of range.");
|
||||
}
|
||||
} else {
|
||||
|
@ -147,16 +144,16 @@ public:
|
|||
TST_GUI_I << " Iterate child:";
|
||||
if(!tvisit_child::at_end(*root_)) {
|
||||
switch(tvisit_child::next(*root_)) {
|
||||
case twalker_::valid :
|
||||
case twalker_::valid:
|
||||
TST_GUI_I << " visit '" << operator*().id() << "'.";
|
||||
break;
|
||||
case twalker_::invalid :
|
||||
case twalker_::invalid:
|
||||
TST_GUI_I << " reached the end.";
|
||||
break;
|
||||
case twalker_::fail:
|
||||
TST_GUI_I << "\n";
|
||||
ERR_GUI_E << "Tried to move beyond end of "
|
||||
"the child iteration range.\n";
|
||||
"the child iteration range.\n";
|
||||
throw trange_error("Tried to move beyond end of range.");
|
||||
}
|
||||
} else {
|
||||
|
@ -166,8 +163,7 @@ public:
|
|||
while(!tvisit_child::at_end(*root_)) {
|
||||
stack_.push_back(root_);
|
||||
root_ = tvisit_child::get(*root_)->create_walker();
|
||||
TST_GUI_I << " Down widget '"
|
||||
<< operator*().id() << "'.";
|
||||
TST_GUI_I << " Down widget '" << operator*().id() << "'.";
|
||||
}
|
||||
TST_GUI_I << " Visit '" << operator*().id() << "'.\n";
|
||||
return true;
|
||||
|
@ -177,7 +173,7 @@ public:
|
|||
{
|
||||
if(at_end()) {
|
||||
ERR_GUI_I << "Tried to defer beyond end its "
|
||||
"iteration range iterator.\n";
|
||||
"iteration range iterator.\n";
|
||||
throw tlogic_error("Tried to defer an invalid iterator.");
|
||||
}
|
||||
if(!tvisit_widget::at_end(*root_)) {
|
||||
|
@ -190,43 +186,36 @@ public:
|
|||
return *tvisit_child::get(*root_);
|
||||
}
|
||||
ERR_GUI_I << "The iterator ended in an unknown "
|
||||
"state while deferring itself.\n";
|
||||
"state while deferring itself.\n";
|
||||
throw tlogic_error("Tried to defer an invalid iterator.");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
iterator::twalker_* root_;
|
||||
|
||||
std::vector<iterator::twalker_*> stack_;
|
||||
};
|
||||
|
||||
template<
|
||||
bool visit_widget
|
||||
, bool visit_grid
|
||||
, bool visit_child
|
||||
>
|
||||
class ttop_down
|
||||
: public tvisit<visit_widget, twalker_::widget>
|
||||
, public tvisit<visit_grid, twalker_::grid>
|
||||
, public tvisit<visit_child, twalker_::child>
|
||||
template <bool visit_widget, bool visit_grid, bool visit_child>
|
||||
class ttop_down : public tvisit<visit_widget, twalker_::widget>,
|
||||
public tvisit<visit_grid, twalker_::grid>,
|
||||
public tvisit<visit_child, twalker_::child>
|
||||
{
|
||||
typedef tvisit<visit_widget, twalker_::widget> tvisit_widget;
|
||||
typedef tvisit<visit_grid, twalker_::grid> tvisit_grid;
|
||||
typedef tvisit<visit_child, twalker_::child> tvisit_child;
|
||||
|
||||
public:
|
||||
explicit ttop_down (twidget& root)
|
||||
: root_(root.create_walker())
|
||||
, stack_()
|
||||
explicit ttop_down(twidget& root) : root_(root.create_walker()), stack_()
|
||||
{
|
||||
}
|
||||
|
||||
~ttop_down()
|
||||
{
|
||||
delete root_;
|
||||
for(std::vector<iterator::twalker_*>::iterator itor = stack_.begin()
|
||||
; itor != stack_.end()
|
||||
; ++itor) {
|
||||
for(std::vector<iterator::twalker_*>::iterator itor = stack_.begin();
|
||||
itor != stack_.end();
|
||||
++itor) {
|
||||
|
||||
delete *itor;
|
||||
}
|
||||
|
@ -234,9 +223,8 @@ public:
|
|||
|
||||
bool at_end() const
|
||||
{
|
||||
return tvisit_widget::at_end(*root_)
|
||||
&& tvisit_grid::at_end(*root_)
|
||||
&& tvisit_child::at_end(*root_);
|
||||
return tvisit_widget::at_end(*root_) && tvisit_grid::at_end(*root_)
|
||||
&& tvisit_child::at_end(*root_);
|
||||
}
|
||||
|
||||
bool next()
|
||||
|
@ -252,16 +240,16 @@ public:
|
|||
TST_GUI_I << " Iterate widget:";
|
||||
if(!tvisit_widget::at_end(*root_)) {
|
||||
switch(tvisit_widget::next(*root_)) {
|
||||
case twalker_::valid :
|
||||
case twalker_::valid:
|
||||
TST_GUI_I << " visit '" << operator*().id() << "'.\n";
|
||||
return true;
|
||||
case twalker_::invalid :
|
||||
case twalker_::invalid:
|
||||
TST_GUI_I << " reached the end.";
|
||||
break;
|
||||
case twalker_::fail:
|
||||
TST_GUI_I << "\n";
|
||||
ERR_GUI_E << "Tried to move beyond end of the "
|
||||
"widget iteration range.\n";
|
||||
"widget iteration range.\n";
|
||||
throw trange_error("Tried to move beyond end of range.");
|
||||
}
|
||||
} else {
|
||||
|
@ -272,16 +260,16 @@ public:
|
|||
TST_GUI_I << " Iterate grid:";
|
||||
if(!tvisit_grid::at_end(*root_)) {
|
||||
switch(tvisit_grid::next(*root_)) {
|
||||
case twalker_::valid :
|
||||
case twalker_::valid:
|
||||
TST_GUI_I << " visit '" << operator*().id() << "'.\n";
|
||||
return true;
|
||||
case twalker_::invalid :
|
||||
case twalker_::invalid:
|
||||
TST_GUI_I << " reached the end.";
|
||||
break;
|
||||
case twalker_::fail:
|
||||
TST_GUI_I << "\n";
|
||||
ERR_GUI_E << "Tried to move beyond end of the grid "
|
||||
"iteration range.\n";
|
||||
"iteration range.\n";
|
||||
throw trange_error("Tried to move beyond end of range.");
|
||||
}
|
||||
} else {
|
||||
|
@ -316,7 +304,7 @@ public:
|
|||
{
|
||||
if(at_end()) {
|
||||
ERR_GUI_I << "Tried to defer beyond end of the iteration "
|
||||
"range iterator.\n";
|
||||
"range iterator.\n";
|
||||
throw tlogic_error("Tried to defer an invalid iterator.");
|
||||
}
|
||||
if(!tvisit_widget::at_end(*root_)) {
|
||||
|
@ -329,12 +317,11 @@ public:
|
|||
return *tvisit_child::get(*root_);
|
||||
}
|
||||
ERR_GUI_I << "The iterator ended in an unknown "
|
||||
"state while deferring iteself.\n";
|
||||
"state while deferring iteself.\n";
|
||||
throw tlogic_error("Tried to defer an invalid iterator.");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool up()
|
||||
{
|
||||
while(!stack_.empty()) {
|
||||
|
@ -371,5 +358,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -19,13 +19,17 @@
|
|||
|
||||
#include <cstring>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
namespace policy {
|
||||
namespace policy
|
||||
{
|
||||
|
||||
namespace visit {
|
||||
namespace visit
|
||||
{
|
||||
|
||||
/**
|
||||
* This policy skips the current level.
|
||||
|
@ -33,21 +37,29 @@ namespace visit {
|
|||
class tskip
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Acts like @ref twalker_::next for the level where the policy is used.
|
||||
*/
|
||||
twalker_::tstate next(twalker_&) { return twalker_::fail; }
|
||||
twalker_::tstate next(twalker_&)
|
||||
{
|
||||
return twalker_::fail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acts like @ref twalker_::at_end for the level where the policy is used.
|
||||
*/
|
||||
bool at_end(const twalker_&) const { return true; }
|
||||
bool at_end(const twalker_&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acts like @ref twalker_::get for the level where the policy is used.
|
||||
*/
|
||||
gui2::twidget* get(twalker_&) { return NULL; }
|
||||
gui2::twidget* get(twalker_&)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -55,11 +67,10 @@ public:
|
|||
*
|
||||
* @tparam level The level to visit.
|
||||
*/
|
||||
template<twalker_::tlevel level>
|
||||
template <twalker_::tlevel level>
|
||||
class tvisit
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Acts like @ref twalker_::next for the level where the policy is used.
|
||||
*/
|
||||
|
@ -92,22 +103,20 @@ public:
|
|||
*
|
||||
* @tparam level The level to determine the policy for.
|
||||
*/
|
||||
template<bool, twalker_::tlevel level>
|
||||
template <bool, twalker_::tlevel level>
|
||||
class tvisit
|
||||
{
|
||||
};
|
||||
|
||||
/** Specialized to select the @ref visit::tskip policy. */
|
||||
template<twalker_::tlevel level>
|
||||
class tvisit<false, level>
|
||||
: public visit::tskip
|
||||
template <twalker_::tlevel level>
|
||||
class tvisit<false, level> : public visit::tskip
|
||||
{
|
||||
};
|
||||
|
||||
/** Specialized to select the @ref visit::tvisit policy. */
|
||||
template<twalker_::tlevel level>
|
||||
class tvisit<true, level>
|
||||
: public visit::tvisit<level>
|
||||
template <twalker_::tlevel level>
|
||||
class tvisit<true, level> : public visit::tvisit<level>
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -118,5 +127,3 @@ class tvisit<true, level>
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -15,28 +15,32 @@
|
|||
#ifndef GUI_WIDGETS_AUXILIARY_ITERATOR_WALKER_HPP_INCLUDED
|
||||
#define GUI_WIDGETS_AUXILIARY_ITERATOR_WALKER_HPP_INCLUDED
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class twidget;
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
/** The walker abstract base class. */
|
||||
class twalker_
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~twalker_() {}
|
||||
virtual ~twalker_()
|
||||
{
|
||||
}
|
||||
|
||||
/** The level to walk at. */
|
||||
enum tlevel
|
||||
{
|
||||
enum tlevel {
|
||||
/** Visit the widget itself. */
|
||||
widget
|
||||
widget
|
||||
/** Visit its nested grid. */
|
||||
, grid
|
||||
,
|
||||
grid
|
||||
/** Visit the children of its nested grid. */
|
||||
, child
|
||||
,
|
||||
child
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -44,8 +48,7 @@ public:
|
|||
*
|
||||
* The enum is used to return the state of @ref next.
|
||||
*/
|
||||
enum tstate
|
||||
{
|
||||
enum tstate {
|
||||
/**
|
||||
* When calling next the following it has the following results.
|
||||
*
|
||||
|
@ -54,7 +57,7 @@ public:
|
|||
* @post the next widget became the current one.
|
||||
* @post at_end == false
|
||||
*/
|
||||
valid
|
||||
valid
|
||||
|
||||
/**
|
||||
* When calling next the following it has the following results.
|
||||
|
@ -64,7 +67,8 @@ public:
|
|||
* @post there is no longer a current widget.
|
||||
* @post at_end == true
|
||||
*/
|
||||
, invalid
|
||||
,
|
||||
invalid
|
||||
|
||||
/**
|
||||
* When calling next the following it has the following results.
|
||||
|
@ -73,8 +77,8 @@ public:
|
|||
*
|
||||
* @post at_end == true
|
||||
*/
|
||||
, fail
|
||||
|
||||
,
|
||||
fail
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -117,5 +121,3 @@ public:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
|
||||
#include "asserts.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
tgrid::tgrid(gui2::tgrid& grid)
|
||||
: grid_(grid)
|
||||
, widget_(&grid)
|
||||
, itor_(grid.begin())
|
||||
: grid_(grid), widget_(&grid), itor_(grid.begin())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ twalker_::tstate tgrid::next(const tlevel level)
|
|||
widget_ = NULL;
|
||||
return invalid;
|
||||
} else {
|
||||
/* FALL DOWN */
|
||||
/* FALL DOWN */
|
||||
}
|
||||
case grid:
|
||||
assert(false);
|
||||
|
@ -96,5 +96,3 @@ gui2::twidget* tgrid::get(const tlevel level)
|
|||
} // namespace iterator
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
||||
|
|
|
@ -19,16 +19,16 @@
|
|||
|
||||
#include "gui/widgets/grid.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
/** A walker for a @ref gui2::tgrid. */
|
||||
class tgrid
|
||||
: public twalker_
|
||||
class tgrid : public twalker_
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -46,7 +46,6 @@ public:
|
|||
virtual gui2::twidget* get(const tlevel level);
|
||||
|
||||
private:
|
||||
|
||||
/** The grid which the walker is attached to. */
|
||||
gui2::tgrid& grid_;
|
||||
|
||||
|
@ -72,6 +71,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,14 +19,16 @@
|
|||
#include "asserts.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
namespace walker {
|
||||
namespace walker
|
||||
{
|
||||
|
||||
twidget::twidget(gui2::twidget& widget)
|
||||
: widget_(&widget)
|
||||
twidget::twidget(gui2::twidget& widget) : widget_(&widget)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -44,7 +46,7 @@ twalker_::tstate twidget::next(const tlevel level)
|
|||
} else {
|
||||
/* FALL DOWN */
|
||||
}
|
||||
case grid: /* FALL DOWN */
|
||||
case grid: /* FALL DOWN */
|
||||
case child: /* FALL DOWN */
|
||||
;
|
||||
}
|
||||
|
@ -86,5 +88,3 @@ gui2::twidget* twidget::get(const tlevel level)
|
|||
} // namespace iterator
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
||||
|
|
|
@ -17,18 +17,19 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/walker.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace iterator {
|
||||
namespace iterator
|
||||
{
|
||||
|
||||
namespace walker {
|
||||
namespace walker
|
||||
{
|
||||
|
||||
/** A walker for a @ref gui2::tcontrol. */
|
||||
class twidget
|
||||
: public twalker_
|
||||
class twidget : public twalker_
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -46,7 +47,6 @@ public:
|
|||
virtual gui2::twidget* get(const tlevel level);
|
||||
|
||||
private:
|
||||
|
||||
/** The control which the walker is attached to. */
|
||||
gui2::twidget* widget_;
|
||||
};
|
||||
|
@ -58,4 +58,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,17 +20,22 @@
|
|||
#ifndef GUI_AUXILIRY_LAYOUT_EXCEPTION_HPP_INCLUDED
|
||||
#define GUI_AUXILIRY_LAYOUT_EXCEPTION_HPP_INCLUDED
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Exception thrown when the width has been modified during resizing.
|
||||
*
|
||||
* See layout_algorithm for more information.
|
||||
*/
|
||||
struct tlayout_exception_width_modified {};
|
||||
struct tlayout_exception_width_modified
|
||||
{
|
||||
};
|
||||
|
||||
/** Basic exception when the layout doesn't fit. */
|
||||
struct tlayout_exception_resize_failed {};
|
||||
struct tlayout_exception_resize_failed
|
||||
{
|
||||
};
|
||||
|
||||
/**
|
||||
* Exception thrown when the width resizing has failed.
|
||||
|
@ -38,7 +43,7 @@ struct tlayout_exception_resize_failed {};
|
|||
* See layout_algorithm for more information.
|
||||
*/
|
||||
struct tlayout_exception_width_resize_failed
|
||||
: public tlayout_exception_resize_failed
|
||||
: public tlayout_exception_resize_failed
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -48,7 +53,7 @@ struct tlayout_exception_width_resize_failed
|
|||
* See layout_algorithm for more information.
|
||||
*/
|
||||
struct tlayout_exception_height_resize_failed
|
||||
: public tlayout_exception_resize_failed
|
||||
: public tlayout_exception_resize_failed
|
||||
{
|
||||
};
|
||||
|
||||
|
|
|
@ -21,15 +21,15 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
lg::log_domain log_gui_draw ("gui/draw");
|
||||
lg::log_domain log_gui_event ("gui/event");
|
||||
lg::log_domain log_gui_general ("gui/general");
|
||||
lg::log_domain log_gui_draw("gui/draw");
|
||||
lg::log_domain log_gui_event("gui/event");
|
||||
lg::log_domain log_gui_general("gui/general");
|
||||
lg::log_domain log_gui_iterator("gui/iterator");
|
||||
lg::log_domain log_gui_lifetime("gui/lifetime");
|
||||
lg::log_domain log_gui_layout ("gui/layout");
|
||||
lg::log_domain log_gui_parse ("gui/parse");
|
||||
lg::log_domain log_gui_layout("gui/layout");
|
||||
lg::log_domain log_gui_parse("gui/parse");
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -22,51 +22,54 @@
|
|||
|
||||
#include "../../log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
extern lg::log_domain log_gui_draw;
|
||||
#define DBG_GUI_D LOG_STREAM_INDENT(debug, gui2::log_gui_draw)
|
||||
#define LOG_GUI_D LOG_STREAM_INDENT(info, gui2::log_gui_draw)
|
||||
#define WRN_GUI_D LOG_STREAM_INDENT(warn, gui2::log_gui_draw)
|
||||
#define ERR_GUI_D LOG_STREAM_INDENT(err, gui2::log_gui_draw)
|
||||
#define LOG_GUI_D LOG_STREAM_INDENT(info, gui2::log_gui_draw)
|
||||
#define WRN_GUI_D LOG_STREAM_INDENT(warn, gui2::log_gui_draw)
|
||||
#define ERR_GUI_D LOG_STREAM_INDENT(err, gui2::log_gui_draw)
|
||||
|
||||
extern lg::log_domain log_gui_event;
|
||||
#define DBG_GUI_E LOG_STREAM_INDENT(debug, gui2::log_gui_event)
|
||||
#define LOG_GUI_E LOG_STREAM_INDENT(info, gui2::log_gui_event)
|
||||
#define WRN_GUI_E LOG_STREAM_INDENT(warn, gui2::log_gui_event)
|
||||
#define ERR_GUI_E LOG_STREAM_INDENT(err, gui2::log_gui_event)
|
||||
#define LOG_GUI_E LOG_STREAM_INDENT(info, gui2::log_gui_event)
|
||||
#define WRN_GUI_E LOG_STREAM_INDENT(warn, gui2::log_gui_event)
|
||||
#define ERR_GUI_E LOG_STREAM_INDENT(err, gui2::log_gui_event)
|
||||
|
||||
extern lg::log_domain log_gui_general;
|
||||
#define DBG_GUI_G LOG_STREAM_INDENT(debug, gui2::log_gui_general)
|
||||
#define LOG_GUI_G LOG_STREAM_INDENT(info, gui2::log_gui_general)
|
||||
#define WRN_GUI_G LOG_STREAM_INDENT(warn, gui2::log_gui_general)
|
||||
#define ERR_GUI_G LOG_STREAM_INDENT(err, gui2::log_gui_general)
|
||||
#define LOG_GUI_G LOG_STREAM_INDENT(info, gui2::log_gui_general)
|
||||
#define WRN_GUI_G LOG_STREAM_INDENT(warn, gui2::log_gui_general)
|
||||
#define ERR_GUI_G LOG_STREAM_INDENT(err, gui2::log_gui_general)
|
||||
|
||||
extern lg::log_domain log_gui_iterator;
|
||||
#define TST_GUI_I \
|
||||
if(lg::debug.dont_log(gui2::log_gui_iterator)); \
|
||||
else lg::debug(gui2::log_gui_iterator, false, false)
|
||||
#define TST_GUI_I \
|
||||
if(lg::debug.dont_log(gui2::log_gui_iterator)) \
|
||||
; \
|
||||
else \
|
||||
lg::debug(gui2::log_gui_iterator, false, false)
|
||||
#define DBG_GUI_I LOG_STREAM_INDENT(debug, gui2::log_gui_iterator)
|
||||
#define LOG_GUI_I LOG_STREAM_INDENT(info, gui2::log_gui_iterator)
|
||||
#define WRN_GUI_I LOG_STREAM_INDENT(warn, gui2::log_gui_iterator)
|
||||
#define ERR_GUI_I LOG_STREAM_INDENT(err, gui2::log_gui_iterator)
|
||||
#define LOG_GUI_I LOG_STREAM_INDENT(info, gui2::log_gui_iterator)
|
||||
#define WRN_GUI_I LOG_STREAM_INDENT(warn, gui2::log_gui_iterator)
|
||||
#define ERR_GUI_I LOG_STREAM_INDENT(err, gui2::log_gui_iterator)
|
||||
|
||||
extern lg::log_domain log_gui_layout;
|
||||
#define DBG_GUI_L LOG_STREAM_INDENT(debug, gui2::log_gui_layout)
|
||||
#define LOG_GUI_L LOG_STREAM_INDENT(info, gui2::log_gui_layout)
|
||||
#define WRN_GUI_L LOG_STREAM_INDENT(warn, gui2::log_gui_layout)
|
||||
#define ERR_GUI_L LOG_STREAM_INDENT(err, gui2::log_gui_layout)
|
||||
#define LOG_GUI_L LOG_STREAM_INDENT(info, gui2::log_gui_layout)
|
||||
#define WRN_GUI_L LOG_STREAM_INDENT(warn, gui2::log_gui_layout)
|
||||
#define ERR_GUI_L LOG_STREAM_INDENT(err, gui2::log_gui_layout)
|
||||
|
||||
extern lg::log_domain log_gui_lifetime;
|
||||
//lifetime logging only makes sense in debug level anyway
|
||||
// lifetime logging only makes sense in debug level anyway
|
||||
#define DBG_GUI_LF LOG_STREAM_INDENT(debug, gui2::log_gui_lifetime)
|
||||
|
||||
|
||||
extern lg::log_domain log_gui_parse;
|
||||
#define DBG_GUI_P LOG_STREAM_INDENT(debug, gui2::log_gui_parse)
|
||||
#define LOG_GUI_P LOG_STREAM_INDENT(info, gui2::log_gui_parse)
|
||||
#define WRN_GUI_P LOG_STREAM_INDENT(warn, gui2::log_gui_parse)
|
||||
#define ERR_GUI_P LOG_STREAM_INDENT(err, gui2::log_gui_parse)
|
||||
#define LOG_GUI_P LOG_STREAM_INDENT(info, gui2::log_gui_parse)
|
||||
#define WRN_GUI_P LOG_STREAM_INDENT(warn, gui2::log_gui_parse)
|
||||
#define ERR_GUI_P LOG_STREAM_INDENT(err, gui2::log_gui_parse)
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
class tnotifier;
|
||||
|
||||
/**
|
||||
|
@ -27,15 +28,14 @@ class tnotifier;
|
|||
*
|
||||
* This part manages the lifetime off the callback.
|
||||
*/
|
||||
template<class FUNCTOR>
|
||||
template <class FUNCTOR>
|
||||
class tnotifiee
|
||||
{
|
||||
public:
|
||||
typedef FUNCTOR tfunctor;
|
||||
friend class tnotifier<tfunctor>;
|
||||
|
||||
tnotifiee()
|
||||
: notifier_(NULL)
|
||||
tnotifiee() : notifier_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,12 +47,10 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
/** Pointer the the tnotifier that's linked to us. */
|
||||
tnotifier<tfunctor> *notifier_;
|
||||
tnotifier<tfunctor>* notifier_;
|
||||
};
|
||||
|
||||
} //namespace gui2
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include <cassert>
|
||||
#include <map>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Helper class to implement callbacks with lifetime management.
|
||||
|
@ -30,21 +31,20 @@ namespace gui2 {
|
|||
*
|
||||
* Subclasses should implement a way to call all callback.
|
||||
*/
|
||||
template<class FUNCTOR>
|
||||
template <class FUNCTOR>
|
||||
class tnotifier
|
||||
{
|
||||
public:
|
||||
|
||||
typedef FUNCTOR tfunctor;
|
||||
|
||||
tnotifier()
|
||||
: notifiees_()
|
||||
tnotifier() : notifiees_()
|
||||
{
|
||||
}
|
||||
|
||||
~tnotifier()
|
||||
{
|
||||
FOREACH(AUTO& item, notifiees_) {
|
||||
FOREACH(AUTO & item, notifiees_)
|
||||
{
|
||||
assert(item.first);
|
||||
assert((*item.first).notifier_ == this);
|
||||
|
||||
|
@ -59,9 +59,7 @@ public:
|
|||
* the callback.
|
||||
* @param functor The callback to call.
|
||||
*/
|
||||
void connect_notifiee(
|
||||
tnotifiee<tfunctor>& notifiee
|
||||
, tfunctor functor)
|
||||
void connect_notifiee(tnotifiee<tfunctor>& notifiee, tfunctor functor)
|
||||
{
|
||||
notifiees_.insert(std::make_pair(¬ifiee, functor));
|
||||
|
||||
|
@ -79,8 +77,8 @@ public:
|
|||
*/
|
||||
void disconnect_notifiee(tnotifiee<tfunctor>& notifiee)
|
||||
{
|
||||
typename std::map<tnotifiee<tfunctor>*, tfunctor>::iterator
|
||||
itor = notifiees_.find(¬ifiee);
|
||||
typename std::map<tnotifiee<tfunctor>*, tfunctor>::iterator itor
|
||||
= notifiees_.find(¬ifiee);
|
||||
|
||||
if(itor != notifiees_.end()) {
|
||||
|
||||
|
@ -100,14 +98,10 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
/** List of registered callbacks. */
|
||||
std::map<tnotifiee<tfunctor>*, tfunctor> notifiees_;
|
||||
|
||||
};
|
||||
|
||||
} //namespace gui2
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
#include "gui/auxiliary/old_markup.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tlegacy_menu_item::tlegacy_menu_item(const std::string& str)
|
||||
: icon_(), label_(str), desc_(), default_(false)
|
||||
|
@ -31,30 +32,33 @@ tlegacy_menu_item::tlegacy_menu_item(const std::string& str)
|
|||
|
||||
// Handle the special case with an image.
|
||||
std::string::size_type pos = label_.find('=');
|
||||
if (pos != std::string::npos && (label_[0] == '&' || pos == 0)) {
|
||||
if (pos) icon_ = label_.substr(1, pos - 1);
|
||||
if(pos != std::string::npos && (label_[0] == '&' || pos == 0)) {
|
||||
if(pos)
|
||||
icon_ = label_.substr(1, pos - 1);
|
||||
label_.erase(0, pos + 1);
|
||||
}
|
||||
|
||||
// Search for an '=' symbol that is not inside markup.
|
||||
std::string::size_type prev = 0;
|
||||
bool open = false;
|
||||
while ((pos = label_.find('=', prev)) != std::string::npos) {
|
||||
for (std::string::size_type i = prev; i != pos; ++i) {
|
||||
switch (label_[i]) {
|
||||
case '<': open = true; break;
|
||||
case '>': open = false; break;
|
||||
while((pos = label_.find('=', prev)) != std::string::npos) {
|
||||
for(std::string::size_type i = prev; i != pos; ++i) {
|
||||
switch(label_[i]) {
|
||||
case '<':
|
||||
open = true;
|
||||
break;
|
||||
case '>':
|
||||
open = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!open) break;
|
||||
if(!open)
|
||||
break;
|
||||
prev = pos + 1;
|
||||
}
|
||||
if (pos != std::string::npos) {
|
||||
if(pos != std::string::npos) {
|
||||
desc_ = label_.substr(pos + 1);
|
||||
label_.erase(pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -42,23 +42,28 @@ class tlegacy_menu_item
|
|||
public:
|
||||
explicit tlegacy_menu_item(const std::string& str = std::string());
|
||||
|
||||
const std::string& icon() const {
|
||||
const std::string& icon() const
|
||||
{
|
||||
return icon_;
|
||||
}
|
||||
|
||||
const std::string& label() const {
|
||||
const std::string& label() const
|
||||
{
|
||||
return label_;
|
||||
}
|
||||
|
||||
const std::string& description() const {
|
||||
const std::string& description() const
|
||||
{
|
||||
return desc_;
|
||||
}
|
||||
|
||||
bool is_default() const {
|
||||
bool is_default() const
|
||||
{
|
||||
return default_;
|
||||
}
|
||||
|
||||
tlegacy_menu_item& operator=(const tlegacy_menu_item& rhs) {
|
||||
tlegacy_menu_item& operator=(const tlegacy_menu_item& rhs)
|
||||
{
|
||||
if(&rhs != this) {
|
||||
icon_ = rhs.icon_;
|
||||
label_ = rhs.label_;
|
||||
|
@ -84,7 +89,6 @@ private:
|
|||
*/
|
||||
bool default_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
#define ENUM_ENABLE_STREAM_OPERATORS_IMPLEMENTATION
|
||||
#define ENUM_TYPE ::gui2::tplacer_
|
||||
#define ENUM_LIST \
|
||||
ENUM(horizontal, "horizontal"); \
|
||||
ENUM(vertical, "vertical"); \
|
||||
#define ENUM_LIST \
|
||||
ENUM(horizontal, "horizontal"); \
|
||||
ENUM(vertical, "vertical");
|
||||
|
||||
#include "gui/auxiliary/placer.hpp"
|
||||
|
||||
|
@ -27,18 +27,18 @@ ENUM(vertical, "vertical"); \
|
|||
#include "gui/auxiliary/placer/vertical_list.hpp"
|
||||
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ENUM_DEFINE_STREAM_OPERATORS(::gui2::tplacer_::tgrow_direction)
|
||||
|
||||
tplacer_* tplacer_::build(
|
||||
const tgrow_direction grow_direction
|
||||
, const unsigned parallel_items)
|
||||
tplacer_* tplacer_::build(const tgrow_direction grow_direction,
|
||||
const unsigned parallel_items)
|
||||
{
|
||||
switch(grow_direction) {
|
||||
case horizontal :
|
||||
case horizontal:
|
||||
return new implementation::tplacer_horizontal_list(parallel_items);
|
||||
case vertical :
|
||||
case vertical:
|
||||
return new implementation::tplacer_vertical_list(parallel_items);
|
||||
};
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
#include "global.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tpoint;
|
||||
|
||||
|
@ -50,21 +51,18 @@ struct tpoint;
|
|||
class tplacer_
|
||||
{
|
||||
public:
|
||||
|
||||
/***** ***** Types. ***** *****/
|
||||
|
||||
/** The direction the placer should grow towards. */
|
||||
enum tgrow_direction
|
||||
{
|
||||
horizontal
|
||||
, vertical
|
||||
enum tgrow_direction {
|
||||
horizontal,
|
||||
vertical
|
||||
};
|
||||
|
||||
|
||||
/***** ***** Constructor, destructor, assignment. ***** *****/
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Builder function.
|
||||
*
|
||||
|
@ -78,9 +76,8 @@ public:
|
|||
* only horizontally or vertically placed items
|
||||
* the value should be 1.
|
||||
*/
|
||||
static tplacer_* build(
|
||||
const tgrow_direction grow_direction
|
||||
, const unsigned parallel_items);
|
||||
static tplacer_* build(const tgrow_direction grow_direction,
|
||||
const unsigned parallel_items);
|
||||
|
||||
virtual ~tplacer_();
|
||||
|
||||
|
@ -126,7 +123,8 @@ public:
|
|||
|
||||
#include "utils/enumerate.tpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ENUM_DECLARE_STREAM_OPERATORS(::gui2::tplacer_::tgrow_direction)
|
||||
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
#include <cassert>
|
||||
#include <numeric>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tplacer_horizontal_list::tplacer_horizontal_list(const unsigned maximum_rows)
|
||||
: maximum_rows_(maximum_rows)
|
||||
|
@ -51,7 +53,7 @@ void tplacer_horizontal_list::add_item(const tpoint& size)
|
|||
}
|
||||
|
||||
if(size.y > rows_[row_]) {
|
||||
rows_[row_]= size.y;
|
||||
rows_[row_] = size.y;
|
||||
}
|
||||
|
||||
++row_;
|
||||
|
@ -66,7 +68,7 @@ void tplacer_horizontal_list::add_item(const tpoint& size)
|
|||
|
||||
tpoint tplacer_horizontal_list::get_size() const
|
||||
{
|
||||
const int width = columns_.back().first + columns_.back().second;
|
||||
const int width = columns_.back().first + columns_.back().second;
|
||||
const int height = std::accumulate(rows_.begin(), rows_.end(), 0);
|
||||
return tpoint(width, height);
|
||||
}
|
||||
|
@ -76,9 +78,9 @@ tpoint tplacer_horizontal_list::get_origin(const unsigned index) const
|
|||
const unsigned row = index % maximum_rows_;
|
||||
const unsigned column = index / maximum_rows_;
|
||||
|
||||
const int height = row == 0
|
||||
? 0
|
||||
: std::accumulate(rows_.begin(), rows_.begin() + row, 0);
|
||||
const int height
|
||||
= row == 0 ? 0
|
||||
: std::accumulate(rows_.begin(), rows_.begin() + row, 0);
|
||||
|
||||
return tpoint(columns_[column].first, height);
|
||||
}
|
||||
|
|
|
@ -24,21 +24,21 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
/**
|
||||
* The placement class for a horizontal list.
|
||||
*
|
||||
* See @ref tplacer_ for more information.
|
||||
*/
|
||||
class tplacer_horizontal_list
|
||||
: public tplacer_
|
||||
class tplacer_horizontal_list : public tplacer_
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/***** ***** Constructor, destructor, assignment. ***** *****/
|
||||
|
||||
explicit tplacer_horizontal_list(const unsigned maximum_rows);
|
||||
|
@ -58,7 +58,6 @@ public:
|
|||
/***** ***** Members. ***** *****/
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The maximum number of rows to use.
|
||||
*
|
||||
|
@ -84,7 +83,6 @@ private:
|
|||
|
||||
/** The column to add an item to. */
|
||||
unsigned column_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
#include <cassert>
|
||||
#include <numeric>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tplacer_vertical_list::tplacer_vertical_list(const unsigned maximum_columns)
|
||||
: maximum_columns_(maximum_columns)
|
||||
|
@ -76,9 +78,10 @@ tpoint tplacer_vertical_list::get_origin(const unsigned index) const
|
|||
const unsigned row = index / maximum_columns_;
|
||||
const unsigned column = index % maximum_columns_;
|
||||
|
||||
const int width = column == 0
|
||||
? 0
|
||||
: std::accumulate(columns_.begin(), columns_.begin() + column, 0);
|
||||
const int width = column == 0 ? 0
|
||||
: std::accumulate(columns_.begin(),
|
||||
columns_.begin() + column,
|
||||
0);
|
||||
|
||||
return tpoint(width, rows_[row].first);
|
||||
}
|
||||
|
|
|
@ -24,20 +24,20 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
/**
|
||||
* The placement class for a vertical list.
|
||||
*
|
||||
* See @ref tplacer_ for more information.
|
||||
*/
|
||||
class tplacer_vertical_list
|
||||
: public tplacer_
|
||||
class tplacer_vertical_list : public tplacer_
|
||||
{
|
||||
public:
|
||||
|
||||
/***** ***** Constructor, destructor, assignment. ***** *****/
|
||||
|
||||
explicit tplacer_vertical_list(const unsigned maximum_columns);
|
||||
|
@ -57,7 +57,6 @@ public:
|
|||
/***** ***** Members. ***** *****/
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The maximum number of columns to use.
|
||||
*
|
||||
|
|
|
@ -23,14 +23,12 @@
|
|||
|
||||
#include <map>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct ttimer
|
||||
{
|
||||
ttimer()
|
||||
: sdl_id(0)
|
||||
, interval(0)
|
||||
, callback()
|
||||
ttimer() : sdl_id(0), interval(0), callback()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,17 +37,17 @@ struct ttimer
|
|||
boost::function<void(size_t id)> callback;
|
||||
};
|
||||
|
||||
/** Ids for the timers. */
|
||||
static size_t id = 0;
|
||||
/** Ids for the timers. */
|
||||
static size_t id = 0;
|
||||
|
||||
/** The active timers. */
|
||||
static std::map<size_t, ttimer> timers;
|
||||
/** The active timers. */
|
||||
static std::map<size_t, ttimer> timers;
|
||||
|
||||
/** The id of the event being executed, 0 if none. */
|
||||
static size_t executing_id = 0;
|
||||
/** The id of the event being executed, 0 if none. */
|
||||
static size_t executing_id = 0;
|
||||
|
||||
/** Did somebody try to remove the timer during its execution? */
|
||||
static bool executing_id_removed = false;
|
||||
/** Did somebody try to remove the timer during its execution? */
|
||||
static bool executing_id_removed = false;
|
||||
|
||||
/**
|
||||
* Helper to make removing a timer in a callback safe.
|
||||
|
@ -71,7 +69,6 @@ public:
|
|||
{
|
||||
executing_id = id;
|
||||
executing_id_removed = false;
|
||||
|
||||
}
|
||||
|
||||
~texecutor()
|
||||
|
@ -90,8 +87,8 @@ static Uint32 timer_callback(Uint32, void* id)
|
|||
{
|
||||
DBG_GUI_E << "Pushing timer event in queue.\n";
|
||||
|
||||
std::map<size_t, ttimer>::iterator itor =
|
||||
timers.find(reinterpret_cast<size_t>(id));
|
||||
std::map<size_t, ttimer>::iterator itor
|
||||
= timers.find(reinterpret_cast<size_t>(id));
|
||||
if(itor == timers.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -114,10 +111,9 @@ static Uint32 timer_callback(Uint32, void* id)
|
|||
|
||||
} // extern "C"
|
||||
|
||||
size_t
|
||||
add_timer(const Uint32 interval
|
||||
, const boost::function<void(size_t id)>& callback
|
||||
, const bool repeat)
|
||||
size_t add_timer(const Uint32 interval,
|
||||
const boost::function<void(size_t id)>& callback,
|
||||
const bool repeat)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(sizeof(size_t) == sizeof(void*));
|
||||
|
||||
|
@ -147,8 +143,7 @@ add_timer(const Uint32 interval
|
|||
return id;
|
||||
}
|
||||
|
||||
bool
|
||||
remove_timer(const size_t id)
|
||||
bool remove_timer(const size_t id)
|
||||
{
|
||||
DBG_GUI_E << "Removing timer " << id << ".\n";
|
||||
|
||||
|
@ -179,8 +174,7 @@ remove_timer(const size_t id)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
execute_timer(const size_t id)
|
||||
bool execute_timer(const size_t id)
|
||||
{
|
||||
DBG_GUI_E << "Executing timer " << id << ".\n";
|
||||
|
||||
|
@ -201,5 +195,4 @@ execute_timer(const size_t id)
|
|||
return true;
|
||||
}
|
||||
|
||||
} //namespace gui2
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
|
||||
#include <SDL_types.h>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Adds a new timer.
|
||||
|
@ -49,10 +50,9 @@ namespace gui2 {
|
|||
* @returns The id of the timer.
|
||||
* @retval [0] Failed to create a timer.
|
||||
*/
|
||||
size_t
|
||||
add_timer(const Uint32 interval
|
||||
, const boost::function<void(size_t id)>& callback
|
||||
, const bool repeat = false);
|
||||
size_t add_timer(const Uint32 interval,
|
||||
const boost::function<void(size_t id)>& callback,
|
||||
const bool repeat = false);
|
||||
|
||||
/**
|
||||
* Removes a timer.
|
||||
|
@ -67,8 +67,7 @@ add_timer(const Uint32 interval
|
|||
* @returns Status, false if the timer couldn't be
|
||||
* removed.
|
||||
*/
|
||||
bool
|
||||
remove_timer(const size_t id);
|
||||
bool remove_timer(const size_t id);
|
||||
|
||||
/**
|
||||
* Executes a timer.
|
||||
|
@ -82,10 +81,8 @@ remove_timer(const size_t id);
|
|||
* @returns Status, false if the timer couldn't be
|
||||
* executed.
|
||||
*/
|
||||
bool
|
||||
execute_timer(const size_t id);
|
||||
bool execute_timer(const size_t id);
|
||||
|
||||
} //namespace gui2
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,27 +21,27 @@
|
|||
#include "utils/foreach.tpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ttip::ttip(const t_string& text
|
||||
, const t_string& source
|
||||
, const std::string& unit_filter)
|
||||
: text_(text)
|
||||
, source_(source)
|
||||
, unit_filter_(utils::split(unit_filter))
|
||||
ttip::ttip(const t_string& text,
|
||||
const t_string& source,
|
||||
const std::string& unit_filter)
|
||||
: text_(text), source_(source), unit_filter_(utils::split(unit_filter))
|
||||
{
|
||||
}
|
||||
|
||||
namespace tips {
|
||||
namespace tips
|
||||
{
|
||||
|
||||
std::vector<ttip> load(const config& cfg)
|
||||
{
|
||||
std::vector<ttip> result;
|
||||
|
||||
FOREACH(const AUTO& tip, cfg.child_range("tip")) {
|
||||
result.push_back(ttip(tip["text"]
|
||||
, tip["source"]
|
||||
, tip["encountered_units"]));
|
||||
FOREACH(const AUTO & tip, cfg.child_range("tip"))
|
||||
{
|
||||
result.push_back(
|
||||
ttip(tip["text"], tip["source"], tip["encountered_units"]));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -53,11 +53,13 @@ std::vector<ttip> shuffle(const std::vector<ttip>& tips)
|
|||
|
||||
const std::set<std::string>& units = preferences::encountered_units();
|
||||
|
||||
FOREACH(const AUTO& tip, tips) {
|
||||
FOREACH(const AUTO & tip, tips)
|
||||
{
|
||||
if(tip.unit_filter_.empty()) {
|
||||
result.push_back(tip);
|
||||
} else {
|
||||
FOREACH(const AUTO& unit, tip.unit_filter_) {
|
||||
FOREACH(const AUTO & unit, tip.unit_filter_)
|
||||
{
|
||||
if(units.find(unit) != units.end()) {
|
||||
result.push_back(tip);
|
||||
break;
|
||||
|
|
|
@ -21,11 +21,13 @@
|
|||
|
||||
class config;
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class ttip;
|
||||
|
||||
namespace tips {
|
||||
namespace tips
|
||||
{
|
||||
|
||||
/**
|
||||
* Loads the tips from a config.
|
||||
|
@ -53,16 +55,21 @@ std::vector<ttip> shuffle(const std::vector<ttip>& tips);
|
|||
class ttip
|
||||
{
|
||||
public:
|
||||
|
||||
const t_string& text() const { return text_; }
|
||||
const t_string& source() const { return source_; }
|
||||
const t_string& text() const
|
||||
{
|
||||
return text_;
|
||||
}
|
||||
const t_string& source() const
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
|
||||
private:
|
||||
friend std::vector<ttip> tips::load(const config&);
|
||||
friend std::vector<ttip> tips::shuffle(const std::vector<ttip>& tips);
|
||||
ttip(const t_string& text
|
||||
, const t_string& source
|
||||
, const std::string& unit_filter);
|
||||
ttip(const t_string& text,
|
||||
const t_string& source,
|
||||
const std::string& unit_filter);
|
||||
|
||||
/** The text of the tip. */
|
||||
t_string text_;
|
||||
|
@ -83,4 +90,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include "gui/widgets/helper.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIToolkitWML
|
||||
|
@ -100,8 +101,8 @@ tresolution_definition_::tresolution_definition_(const config& cfg)
|
|||
, text_font_style(decode_font_style(cfg["text_font_style"]))
|
||||
, state()
|
||||
{
|
||||
DBG_GUI_P << "Parsing resolution "
|
||||
<< window_width << ", " << window_height << '\n';
|
||||
DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
/*WIKI
|
||||
|
@ -128,13 +129,11 @@ tresolution_definition_::tresolution_definition_(const config& cfg)
|
|||
* @end{parent}{name="generic/"}
|
||||
*/
|
||||
tcontrol_definition::tcontrol_definition(const config& cfg)
|
||||
: id(cfg["id"])
|
||||
, description(cfg["description"].t_str())
|
||||
, resolutions()
|
||||
: id(cfg["id"]), description(cfg["description"].t_str()), resolutions()
|
||||
{
|
||||
VALIDATE(!id.empty(), missing_mandatory_wml_key("control", "id"));
|
||||
VALIDATE(!description.empty()
|
||||
, missing_mandatory_wml_key("control", "description"));
|
||||
VALIDATE(!description.empty(),
|
||||
missing_mandatory_wml_key("control", "description"));
|
||||
|
||||
/*
|
||||
* Do this validation here instead of in load_resolutions so the
|
||||
|
@ -146,4 +145,3 @@ tcontrol_definition::tcontrol_definition(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "gui/auxiliary/canvas.hpp"
|
||||
#include "utils/foreach.tpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/**
|
||||
* Contains the state info for a resolution.
|
||||
|
@ -30,15 +31,14 @@ namespace gui2 {
|
|||
*/
|
||||
struct tstate_definition
|
||||
{
|
||||
explicit tstate_definition(const config &cfg);
|
||||
explicit tstate_definition(const config& cfg);
|
||||
|
||||
tcanvas canvas;
|
||||
};
|
||||
|
||||
|
||||
/** Base class of a resolution, contains the common keys for a resolution. */
|
||||
struct tresolution_definition_
|
||||
: public reference_counted_object
|
||||
struct tresolution_definition_ : public reference_counted_object
|
||||
{
|
||||
explicit tresolution_definition_(const config& cfg);
|
||||
|
||||
|
@ -62,13 +62,11 @@ struct tresolution_definition_
|
|||
std::vector<tstate_definition> state;
|
||||
};
|
||||
|
||||
typedef
|
||||
boost::intrusive_ptr<tresolution_definition_>
|
||||
tresolution_definition_ptr;
|
||||
typedef boost::intrusive_ptr<tresolution_definition_>
|
||||
tresolution_definition_ptr;
|
||||
|
||||
typedef
|
||||
boost::intrusive_ptr<const tresolution_definition_>
|
||||
tresolution_definition_const_ptr;
|
||||
typedef boost::intrusive_ptr<const tresolution_definition_>
|
||||
tresolution_definition_const_ptr;
|
||||
|
||||
/**
|
||||
* Casts a tresolution_definition_const_ptr to another type.
|
||||
|
@ -79,25 +77,25 @@ typedef
|
|||
*
|
||||
* @returns A reference to type casted to.
|
||||
*/
|
||||
template<class T>
|
||||
template <class T>
|
||||
const T& cast(tresolution_definition_const_ptr ptr)
|
||||
{
|
||||
boost::intrusive_ptr<const T> conf =
|
||||
boost::dynamic_pointer_cast<const T>(ptr);
|
||||
boost::intrusive_ptr<const T> conf
|
||||
= boost::dynamic_pointer_cast<const T>(ptr);
|
||||
assert(conf);
|
||||
return *conf;
|
||||
}
|
||||
|
||||
struct tcontrol_definition
|
||||
: public reference_counted_object
|
||||
struct tcontrol_definition : public reference_counted_object
|
||||
{
|
||||
explicit tcontrol_definition(const config& cfg);
|
||||
|
||||
template<class T>
|
||||
void load_resolutions(const config &cfg)
|
||||
template <class T>
|
||||
void load_resolutions(const config& cfg)
|
||||
{
|
||||
config::const_child_itors itors = cfg.child_range("resolution");
|
||||
FOREACH(const AUTO& resolution, itors) {
|
||||
FOREACH(const AUTO & resolution, itors)
|
||||
{
|
||||
resolutions.push_back(new T(resolution));
|
||||
}
|
||||
}
|
||||
|
@ -113,4 +111,3 @@ typedef boost::intrusive_ptr<tcontrol_definition> tcontrol_definition_ptr;
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tbutton_definition::tbutton_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -67,4 +68,3 @@ tbutton_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tbutton_definition
|
||||
: public tcontrol_definition
|
||||
struct tbutton_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tbutton_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct tbutton_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tdrawing_definition::tdrawing_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -65,4 +66,3 @@ tdrawing_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tdrawing_definition
|
||||
: public tcontrol_definition
|
||||
struct tdrawing_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tdrawing_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct tdrawing_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
thorizontal_scrollbar_definition::
|
||||
thorizontal_scrollbar_definition(const config& cfg)
|
||||
thorizontal_scrollbar_definition::thorizontal_scrollbar_definition(
|
||||
const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
{
|
||||
DBG_GUI_P << "Parsing horizontal scrollbar " << id << '\n';
|
||||
|
@ -85,11 +86,9 @@ thorizontal_scrollbar_definition::tresolution::tresolution(const config& cfg)
|
|||
, left_offset(cfg["left_offset"])
|
||||
, right_offset(cfg["right_offset"])
|
||||
{
|
||||
VALIDATE(
|
||||
minimum_positioner_length
|
||||
, missing_mandatory_wml_key(
|
||||
"resolution"
|
||||
, "minimum_positioner_length"));
|
||||
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")));
|
||||
|
@ -99,4 +98,3 @@ thorizontal_scrollbar_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct thorizontal_scrollbar_definition
|
||||
: public tcontrol_definition
|
||||
struct thorizontal_scrollbar_definition : public tcontrol_definition
|
||||
{
|
||||
explicit thorizontal_scrollbar_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -40,4 +39,3 @@ struct thorizontal_scrollbar_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
timage_definition::timage_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -59,4 +60,3 @@ timage_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct timage_definition
|
||||
: public tcontrol_definition
|
||||
struct timage_definition : public tcontrol_definition
|
||||
{
|
||||
explicit timage_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct timage_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tlabel_definition::tlabel_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -63,4 +64,3 @@ tlabel_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,16 +17,15 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tlabel_definition
|
||||
: public tcontrol_definition
|
||||
struct tlabel_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
explicit tlabel_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -35,4 +34,3 @@ struct tlabel_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tlistbox_definition::tlistbox_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -44,33 +45,39 @@ tlistbox_definition::tlistbox_definition(const config& cfg)
|
|||
* The resolution for a listbox also contains the following keys:
|
||||
* @begin{tag}{name="resolution"}{min=0}{max=-1}{super=generic/widget_definition/resolution}
|
||||
* @begin{table}{config}
|
||||
* scrollbar & section & & A grid containing the widgets for the
|
||||
* scrollbar & section & & A grid containing the widgets for the
|
||||
* scrollbar. The scrollbar has some special
|
||||
* widgets so it can make default behavior
|
||||
* for certain widgets. $
|
||||
* @end{table}
|
||||
* @begin{table}{dialog_widgets}
|
||||
* _begin & & clickable & o & Moves the position to the beginning of
|
||||
* the list. $
|
||||
* _line_up & & clickable & o & Move the position one item up. (NOTE if
|
||||
* too many items to move per item it might
|
||||
* be more items.) $
|
||||
* _half_page_up & & clickable & o & Move the position half the number of the
|
||||
* visible items up. (See note at _line_up.) $
|
||||
* _page_up & & clickable & o & Move the position the number of visible
|
||||
* items up. (See note at _line_up.) $
|
||||
* _begin & & clickable & o & Moves the position to the beginning
|
||||
* of the list. $
|
||||
* _line_up & & clickable & o & Move the position one item up. (NOTE
|
||||
* if too many items to move per item it
|
||||
* might be more items.) $
|
||||
* _half_page_up & & clickable & o &
|
||||
* Move the position half the number of the
|
||||
* visible items up. (See note at
|
||||
* _line_up.) $
|
||||
* _page_up & & clickable & o & Move the position the number of
|
||||
* visible items up. (See note at
|
||||
* _line_up.) $
|
||||
*
|
||||
* _end & & clickable & o & Moves the position to the end of the
|
||||
* _end & & clickable & o & Moves the position to the end of the
|
||||
* list. $
|
||||
* _line_down & & clickable & o & Move the position one item down.(See note
|
||||
* at _line_up.) $
|
||||
* _half_page_down & & clickable & o & Move the position half the number of the
|
||||
* _line_down & & clickable & o & Move the position one item down.(See
|
||||
* note at _line_up.) $
|
||||
* _half_page_down & & clickable & o &
|
||||
* Move the position half the number of the
|
||||
* visible items down. (See note at
|
||||
* _line_up.) $
|
||||
* _page_down & & clickable & o & Move the position the number of
|
||||
* visible items down. (See note at
|
||||
* _line_up.) $
|
||||
* _page_down & & clickable & o & Move the position the number of visible
|
||||
* items down. (See note at _line_up.) $
|
||||
*
|
||||
* _scrollbar & & vertical_scrollbar & m & This is the scrollbar so the user can
|
||||
* _scrollbar & & vertical_scrollbar & m &
|
||||
* This is the scrollbar so the user can
|
||||
* scroll through the list. $
|
||||
* @end{table}
|
||||
* A clickable is one of:
|
||||
|
@ -104,18 +111,16 @@ tlistbox_definition::tlistbox_definition(const config& cfg)
|
|||
* The definition of a horizontal listbox is the same as for a normal listbox.
|
||||
*/
|
||||
tlistbox_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg)
|
||||
, grid(NULL)
|
||||
: tresolution_definition_(cfg), grid(NULL)
|
||||
{
|
||||
// Note the order should be the same as the enum tstate in listbox.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled")));
|
||||
|
||||
const config &child = cfg.child("grid");
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,16 +18,15 @@
|
|||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tlistbox_definition
|
||||
: public tcontrol_definition
|
||||
struct tlistbox_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
explicit tlistbox_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -38,4 +37,3 @@ struct tlistbox_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "gettext.hpp"
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tmatrix_definition::tmatrix_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
|
|
@ -18,16 +18,15 @@
|
|||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tmatrix_definition
|
||||
: public tcontrol_definition
|
||||
struct tmatrix_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
explicit tmatrix_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -38,4 +37,3 @@ struct tmatrix_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tminimap_definition::tminimap_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -55,4 +56,3 @@ tminimap_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tminimap_definition
|
||||
: public tcontrol_definition
|
||||
struct tminimap_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tminimap_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct tminimap_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tmulti_page_definition::tmulti_page_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -52,14 +53,12 @@ tmulti_page_definition::tmulti_page_definition(const config& cfg)
|
|||
* A multipage has no states.
|
||||
*/
|
||||
tmulti_page_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg)
|
||||
, grid(NULL)
|
||||
: tresolution_definition_(cfg), grid(NULL)
|
||||
{
|
||||
const config &child = cfg.child("grid");
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tmulti_page_definition
|
||||
: public tcontrol_definition
|
||||
struct tmulti_page_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tmulti_page_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -37,4 +36,3 @@ struct tmulti_page_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tpanel_definition::tpanel_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -79,4 +80,3 @@ tpanel_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tpanel_definition
|
||||
: public tcontrol_definition
|
||||
struct tpanel_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tpanel_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -40,4 +39,3 @@ struct tpanel_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tprogress_bar_definition::tprogress_bar_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -58,4 +59,3 @@ tprogress_bar_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tprogress_bar_definition
|
||||
: public tcontrol_definition
|
||||
struct tprogress_bar_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tprogress_bar_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct tprogress_bar_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
trepeating_button_definition::trepeating_button_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -68,4 +69,3 @@ trepeating_button_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct trepeating_button_definition
|
||||
: public tcontrol_definition
|
||||
struct trepeating_button_definition : public tcontrol_definition
|
||||
{
|
||||
explicit trepeating_button_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct trepeating_button_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tscroll_label_definition::tscroll_label_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -44,7 +45,7 @@ tscroll_label_definition::tscroll_label_definition(const config& cfg)
|
|||
* @begin{tag}{name="scroll_label_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
|
||||
* @begin{tag}{name="resolution"}{min=0}{max=-1}{super="generic/widget_definition/resolution"}
|
||||
* @begin{table}{config}
|
||||
* grid & grid & & A grid containing the widgets for main
|
||||
* grid & grid & & A grid containing the widgets for main
|
||||
* widget. $
|
||||
* @end{table}
|
||||
* @allow{link}{name="gui/window/resolution/grid"}
|
||||
|
@ -52,9 +53,9 @@ tscroll_label_definition::tscroll_label_definition(const config& cfg)
|
|||
* time we use it.
|
||||
*
|
||||
* @begin{table}{dialog_widgets}
|
||||
* _content_grid & & grid & m & A grid which should only contain one
|
||||
* _content_grid & & grid & m & A grid which should only contain one
|
||||
* label widget. $
|
||||
* _scrollbar_grid & & grid & m & A grid for the scrollbar
|
||||
* _scrollbar_grid & & grid & m & A grid for the scrollbar
|
||||
* (Merge with listbox info.) $
|
||||
* @end{table}
|
||||
* @begin{tag}{name="content_grid"}{min=0}{max=1}{super="gui/window/resolution/grid"}
|
||||
|
@ -73,18 +74,16 @@ tscroll_label_definition::tscroll_label_definition(const config& cfg)
|
|||
* @end{parent}{name="gui/"}
|
||||
*/
|
||||
tscroll_label_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg)
|
||||
, grid(NULL)
|
||||
: tresolution_definition_(cfg), grid(NULL)
|
||||
{
|
||||
// Note the order should be the same as the enum tstate is scroll_label.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled")));
|
||||
|
||||
const config &child = cfg.child("grid");
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
#include "gui/auxiliary/window_builder.hpp"
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tscroll_label_definition
|
||||
: public tcontrol_definition
|
||||
struct tscroll_label_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tscroll_label_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -37,4 +36,3 @@ struct tscroll_label_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tscrollbar_panel_definition::tscrollbar_panel_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -56,18 +57,16 @@ tscrollbar_panel_definition::tscrollbar_panel_definition(const config& cfg)
|
|||
* @end{parent}{name="gui/"}
|
||||
*/
|
||||
tscrollbar_panel_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg)
|
||||
, grid()
|
||||
: tresolution_definition_(cfg), grid()
|
||||
{
|
||||
// The panel needs to know the order.
|
||||
state.push_back(tstate_definition(cfg.child("background")));
|
||||
state.push_back(tstate_definition(cfg.child("foreground")));
|
||||
|
||||
const config &child = cfg.child("grid");
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,16 +18,15 @@
|
|||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tscrollbar_panel_definition
|
||||
: public tcontrol_definition
|
||||
struct tscrollbar_panel_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
explicit tscrollbar_panel_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -38,4 +37,3 @@ struct tscrollbar_panel_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tslider_definition::tslider_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -83,10 +84,9 @@ tslider_definition::tresolution::tresolution(const config& cfg)
|
|||
, left_offset(cfg["left_offset"])
|
||||
, right_offset(cfg["right_offset"])
|
||||
{
|
||||
VALIDATE(minimum_positioner_length
|
||||
, missing_mandatory_wml_key(
|
||||
"resolution"
|
||||
, "minimum_positioner_length"));
|
||||
VALIDATE(minimum_positioner_length,
|
||||
missing_mandatory_wml_key("resolution",
|
||||
"minimum_positioner_length"));
|
||||
|
||||
// Note the order should be the same as the enum tstate is slider.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
|
@ -96,4 +96,3 @@ tslider_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tslider_definition
|
||||
: public tcontrol_definition
|
||||
struct tslider_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tslider_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -40,4 +39,3 @@ struct tslider_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tspacer_definition::tspacer_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -48,4 +49,3 @@ tspacer_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tspacer_definition
|
||||
: public tcontrol_definition
|
||||
struct tspacer_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tspacer_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct tspacer_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tstacked_widget_definition::tstacked_widget_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -51,18 +52,16 @@ tstacked_widget_definition::tstacked_widget_definition(const config& cfg)
|
|||
* @end{parent}{name="gui/"}
|
||||
*/
|
||||
tstacked_widget_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg)
|
||||
, grid(NULL)
|
||||
: tresolution_definition_(cfg), grid(NULL)
|
||||
{
|
||||
// Add a dummy state since every widget needs a state.
|
||||
static config dummy ("draw");
|
||||
static config dummy("draw");
|
||||
state.push_back(tstate_definition(dummy));
|
||||
|
||||
const config &child = cfg.child("grid");
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tstacked_widget_definition
|
||||
: public tcontrol_definition
|
||||
struct tstacked_widget_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tstacked_widget_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -37,4 +36,3 @@ struct tstacked_widget_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ttext_box_definition::ttext_box_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -76,4 +77,3 @@ ttext_box_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
#include "gui/auxiliary/formula.hpp"
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct ttext_box_definition
|
||||
: public tcontrol_definition
|
||||
struct ttext_box_definition : public tcontrol_definition
|
||||
{
|
||||
explicit ttext_box_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -38,4 +37,3 @@ struct ttext_box_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ttoggle_button_definition::ttoggle_button_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -78,4 +79,3 @@ ttoggle_button_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct ttoggle_button_definition
|
||||
: public tcontrol_definition
|
||||
struct ttoggle_button_definition : public tcontrol_definition
|
||||
{
|
||||
explicit ttoggle_button_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
};
|
||||
|
@ -34,4 +33,3 @@ struct ttoggle_button_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ttoggle_panel_definition::ttoggle_panel_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -95,4 +96,3 @@ ttoggle_panel_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct ttoggle_panel_definition
|
||||
: public tcontrol_definition
|
||||
struct ttoggle_panel_definition : public tcontrol_definition
|
||||
{
|
||||
explicit ttoggle_panel_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -40,4 +39,3 @@ struct ttoggle_panel_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
ttree_view_definition::ttree_view_definition(const config& cfg)
|
||||
: tcontrol_definition(cfg)
|
||||
|
@ -56,18 +57,16 @@ ttree_view_definition::ttree_view_definition(const config& cfg)
|
|||
* @end{parent}{name="gui/"}
|
||||
*/
|
||||
ttree_view_definition::tresolution::tresolution(const config& cfg)
|
||||
: tresolution_definition_(cfg)
|
||||
, grid(NULL)
|
||||
: tresolution_definition_(cfg), grid(NULL)
|
||||
{
|
||||
// Note the order should be the same as the enum tstate is listbox.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
state.push_back(tstate_definition(cfg.child("state_disabled")));
|
||||
|
||||
const config &child = cfg.child("grid");
|
||||
const config& child = cfg.child("grid");
|
||||
VALIDATE(child, _("No grid defined."));
|
||||
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,16 +18,15 @@
|
|||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct ttree_view_definition
|
||||
: public tcontrol_definition
|
||||
struct ttree_view_definition : public tcontrol_definition
|
||||
{
|
||||
|
||||
explicit ttree_view_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -38,4 +37,3 @@ struct ttree_view_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
tvertical_scrollbar_definition::tvertical_scrollbar_definition(
|
||||
const config& cfg)
|
||||
|
@ -55,9 +56,9 @@ tvertical_scrollbar_definition::tvertical_scrollbar_definition(
|
|||
* the same value the positioner is fixed
|
||||
* size. If the maximum is 0 (and the
|
||||
* minimum not) there's no maximum. $
|
||||
* top_offset & unsigned & 0 & The number of pixels at the top which
|
||||
* top_offset & unsigned & 0 & The number of pixels at the top which
|
||||
* can't be used by the positioner. $
|
||||
* bottom_offset & unsigned & 0 & The number of pixels at the bottom which
|
||||
* bottom_offset & unsigned & 0 & The number of pixels at the bottom which
|
||||
* can't be used by the positioner. $
|
||||
* @end{table}
|
||||
* The following states exist:
|
||||
|
@ -85,10 +86,9 @@ tvertical_scrollbar_definition::tresolution::tresolution(const config& cfg)
|
|||
, top_offset(cfg["top_offset"])
|
||||
, bottom_offset(cfg["bottom_offset"])
|
||||
{
|
||||
VALIDATE(minimum_positioner_length
|
||||
, missing_mandatory_wml_key(
|
||||
"resolution"
|
||||
, "minimum_positioner_length"));
|
||||
VALIDATE(minimum_positioner_length,
|
||||
missing_mandatory_wml_key("resolution",
|
||||
"minimum_positioner_length"));
|
||||
|
||||
// Note the order should be the same as the enum tstate in scrollbar.hpp.
|
||||
state.push_back(tstate_definition(cfg.child("state_enabled")));
|
||||
|
@ -98,4 +98,3 @@ tvertical_scrollbar_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "gui/auxiliary/widget_definition.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct tvertical_scrollbar_definition
|
||||
: public tcontrol_definition
|
||||
struct tvertical_scrollbar_definition : public tcontrol_definition
|
||||
{
|
||||
explicit tvertical_scrollbar_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tresolution_definition_
|
||||
struct tresolution : public tresolution_definition_
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -40,4 +39,3 @@ struct tvertical_scrollbar_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWidgetDefinitionWML
|
||||
|
@ -48,11 +49,10 @@ twindow_definition::twindow_definition(const config& cfg)
|
|||
}
|
||||
|
||||
twindow_definition::tresolution::tresolution(const config& cfg)
|
||||
: tpanel_definition::tresolution(cfg)
|
||||
, grid(NULL)
|
||||
: tpanel_definition::tresolution(cfg), grid(NULL)
|
||||
{
|
||||
const config &child = cfg.child("grid");
|
||||
// VALIDATE(child, _("No grid defined."));
|
||||
const config& child = cfg.child("grid");
|
||||
// VALIDATE(child, _("No grid defined."));
|
||||
|
||||
/** @todo Evaluate whether the grid should become mandatory. */
|
||||
if(child) {
|
||||
|
@ -61,4 +61,3 @@ twindow_definition::tresolution::tresolution(const config& cfg)
|
|||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
#include "gui/auxiliary/widget_definition/panel.hpp"
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
struct twindow_definition
|
||||
: public tcontrol_definition
|
||||
struct twindow_definition : public tcontrol_definition
|
||||
{
|
||||
explicit twindow_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tpanel_definition::tresolution
|
||||
struct tresolution : public tpanel_definition::tresolution
|
||||
{
|
||||
explicit tresolution(const config& cfg);
|
||||
|
||||
|
@ -37,4 +36,3 @@ struct twindow_definition
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -48,13 +48,14 @@
|
|||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
static std::map<std::string, boost::function<tbuilder_widget_ptr(config)> >&
|
||||
builder_widget_lookup()
|
||||
{
|
||||
static std::map<std::string, boost::function<tbuilder_widget_ptr(config)> >
|
||||
result;
|
||||
result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -71,48 +72,47 @@ builder_widget_lookup()
|
|||
* be tuned. This page will describe what can be tuned.
|
||||
*
|
||||
*/
|
||||
twindow *build(CVideo &video, const twindow_builder::tresolution *definition)
|
||||
twindow* build(CVideo& video, const twindow_builder::tresolution* definition)
|
||||
{
|
||||
// We set the values from the definition since we can only determine the
|
||||
// best size (if needed) after all widgets have been placed.
|
||||
twindow* window = new twindow(video
|
||||
, definition->x
|
||||
, definition->y
|
||||
, definition->width
|
||||
, definition->height
|
||||
, definition->reevaluate_best_size
|
||||
, definition->functions
|
||||
, definition->automatic_placement
|
||||
, definition->horizontal_placement
|
||||
, definition->vertical_placement
|
||||
, definition->maximum_width
|
||||
, definition->maximum_height
|
||||
, definition->definition
|
||||
, definition->tooltip
|
||||
, definition->helptip);
|
||||
twindow* window = new twindow(video,
|
||||
definition->x,
|
||||
definition->y,
|
||||
definition->width,
|
||||
definition->height,
|
||||
definition->reevaluate_best_size,
|
||||
definition->functions,
|
||||
definition->automatic_placement,
|
||||
definition->horizontal_placement,
|
||||
definition->vertical_placement,
|
||||
definition->maximum_width,
|
||||
definition->maximum_height,
|
||||
definition->definition,
|
||||
definition->tooltip,
|
||||
definition->helptip);
|
||||
assert(window);
|
||||
|
||||
FOREACH(const AUTO& lg, definition->linked_groups) {
|
||||
FOREACH(const AUTO & lg, definition->linked_groups)
|
||||
{
|
||||
|
||||
if(window->has_linked_size_group(lg.id)) {
|
||||
utils::string_map symbols;
|
||||
symbols["id"] = lg.id;
|
||||
t_string msg = vgettext(
|
||||
"Linked '$id' group has multiple definitions."
|
||||
, symbols);
|
||||
"Linked '$id' group has multiple definitions.", symbols);
|
||||
|
||||
VALIDATE(false, msg);
|
||||
}
|
||||
|
||||
window->init_linked_size_group(
|
||||
lg.id, lg.fixed_width, lg.fixed_height);
|
||||
window->init_linked_size_group(lg.id, lg.fixed_width, lg.fixed_height);
|
||||
}
|
||||
|
||||
window->set_click_dismiss(definition->click_dismiss);
|
||||
|
||||
boost::intrusive_ptr<const twindow_definition::tresolution> conf =
|
||||
boost::dynamic_pointer_cast<
|
||||
const twindow_definition::tresolution>(window->config());
|
||||
boost::intrusive_ptr<const twindow_definition::tresolution>
|
||||
conf = boost::dynamic_pointer_cast<const twindow_definition::tresolution>(
|
||||
window->config());
|
||||
assert(conf);
|
||||
|
||||
if(conf->grid) {
|
||||
|
@ -127,11 +127,11 @@ twindow *build(CVideo &video, const twindow_builder::tresolution *definition)
|
|||
return window;
|
||||
}
|
||||
|
||||
twindow *build(CVideo &video, const std::string &type)
|
||||
twindow* build(CVideo& video, const std::string& type)
|
||||
{
|
||||
std::vector<twindow_builder::tresolution>::const_iterator
|
||||
definition = get_window_builder(type);
|
||||
twindow *window = build(video, &*definition);
|
||||
std::vector<twindow_builder::tresolution>::const_iterator definition
|
||||
= get_window_builder(type);
|
||||
twindow* window = build(video, &*definition);
|
||||
window->set_id(type);
|
||||
return window;
|
||||
}
|
||||
|
@ -146,8 +146,9 @@ tbuilder_widget::tbuilder_widget(const config& cfg)
|
|||
{
|
||||
}
|
||||
|
||||
void register_builder_widget(const std::string& id
|
||||
, boost::function<tbuilder_widget_ptr(config)> functor)
|
||||
void
|
||||
register_builder_widget(const std::string& id,
|
||||
boost::function<tbuilder_widget_ptr(config)> functor)
|
||||
{
|
||||
builder_widget_lookup().insert(std::make_pair(id, functor));
|
||||
}
|
||||
|
@ -158,20 +159,21 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
size_t nb_children = std::distance(children.first, children.second);
|
||||
VALIDATE(nb_children == 1, "Grid cell does not have exactly 1 child.");
|
||||
|
||||
FOREACH(const AUTO& item, builder_widget_lookup()) {
|
||||
FOREACH(const AUTO & item, builder_widget_lookup())
|
||||
{
|
||||
if(item.first == "window" || item.first == "tooltip") {
|
||||
continue;
|
||||
}
|
||||
if(const config &c = cfg.child(item.first)) {
|
||||
if(const config& c = cfg.child(item.first)) {
|
||||
return item.second(c);
|
||||
}
|
||||
}
|
||||
|
||||
if(const config &c = cfg.child("grid")) {
|
||||
if(const config& c = cfg.child("grid")) {
|
||||
return new tbuilder_grid(c);
|
||||
}
|
||||
|
||||
if(const config &instance = cfg.child("instance")) {
|
||||
if(const config& instance = cfg.child("instance")) {
|
||||
return new implementation::tbuilder_instance(instance);
|
||||
}
|
||||
|
||||
|
@ -194,13 +196,13 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
* If this code is executed, which it will cause an assertion failure.
|
||||
*/
|
||||
#if 1
|
||||
#define TRY(name) \
|
||||
do { \
|
||||
if(const config &c = cfg.child(#name)) { \
|
||||
tbuilder_widget_ptr p = new implementation::tbuilder_##name(c);\
|
||||
assert(false); \
|
||||
} \
|
||||
} while (0)
|
||||
#define TRY(name) \
|
||||
do { \
|
||||
if(const config& c = cfg.child(#name)) { \
|
||||
tbuilder_widget_ptr p = new implementation::tbuilder_##name(c); \
|
||||
assert(false); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
TRY(stacked_widget);
|
||||
TRY(scrollbar_panel);
|
||||
|
@ -234,10 +236,11 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
* A window defines how a window looks in the game.
|
||||
*
|
||||
* @begin{table}{config}
|
||||
* id & string & & Unique id for this window. $
|
||||
* description & t_string & & Unique translatable name for this window. $
|
||||
* id & string & & Unique id for this window. $
|
||||
* description & t_string & & Unique translatable name for this
|
||||
* window. $
|
||||
*
|
||||
* resolution & section & & The definitions of the window in various
|
||||
* resolution & section & & The definitions of the window in various
|
||||
* resolutions. $
|
||||
* @end{table}
|
||||
* @end{tag}{name="window"}
|
||||
|
@ -251,13 +254,15 @@ const std::string& twindow_builder::read(const config& cfg)
|
|||
description_ = cfg["description"].str();
|
||||
|
||||
VALIDATE(!id_.empty(), missing_mandatory_wml_key("window", "id"));
|
||||
VALIDATE(!description_.empty(), missing_mandatory_wml_key("window", "description"));
|
||||
VALIDATE(!description_.empty(),
|
||||
missing_mandatory_wml_key("window", "description"));
|
||||
|
||||
DBG_GUI_P << "Window builder: reading data for window " << id_ << ".\n";
|
||||
|
||||
config::const_child_itors cfgs = cfg.child_range("resolution");
|
||||
VALIDATE(cfgs.first != cfgs.second, _("No resolution defined."));
|
||||
FOREACH(const AUTO& i, cfgs) {
|
||||
FOREACH(const AUTO & i, cfgs)
|
||||
{
|
||||
resolutions.push_back(tresolution(i));
|
||||
}
|
||||
|
||||
|
@ -341,11 +346,11 @@ const std::string& twindow_builder::read(const config& cfg)
|
|||
* @begin{tag}{name="linked_group"}{min=0}{max=-1}
|
||||
* A linked_group section has the following fields:
|
||||
* @begin{table}{config}
|
||||
* id & string & & The unique id of the group (unique in this
|
||||
* id & string & & The unique id of the group (unique in this
|
||||
* window). $
|
||||
* fixed_width & bool & false & Should widget in this group have the same
|
||||
* fixed_width & bool & false & Should widget in this group have the same
|
||||
* width. $
|
||||
* fixed_height & bool & false & Should widget in this group have the same
|
||||
* fixed_height & bool & false & Should widget in this group have the same
|
||||
* height. $
|
||||
* @end{table}
|
||||
* @end{tag}{name="linked_group"}
|
||||
|
@ -368,34 +373,33 @@ const std::string& twindow_builder::read(const config& cfg)
|
|||
* @end{tag}{name="helptip"}
|
||||
* @end{parent}{name=gui/window/resolution/}
|
||||
*/
|
||||
twindow_builder::tresolution::tresolution(const config& cfg) :
|
||||
window_width(cfg["window_width"]),
|
||||
window_height(cfg["window_height"]),
|
||||
automatic_placement(cfg["automatic_placement"].to_bool(true)),
|
||||
x(cfg["x"]),
|
||||
y(cfg["y"]),
|
||||
width(cfg["width"]),
|
||||
height(cfg["height"]),
|
||||
reevaluate_best_size(cfg["reevaluate_best_size"]),
|
||||
functions(),
|
||||
vertical_placement(
|
||||
implementation::get_v_align(cfg["vertical_placement"])),
|
||||
horizontal_placement(
|
||||
implementation::get_h_align(cfg["horizontal_placement"])),
|
||||
maximum_width(cfg["maximum_width"]),
|
||||
maximum_height(cfg["maximum_height"]),
|
||||
click_dismiss(cfg["click_dismiss"].to_bool()),
|
||||
definition(cfg["definition"]),
|
||||
linked_groups(),
|
||||
tooltip(cfg.child_or_empty("tooltip")),
|
||||
helptip(cfg.child_or_empty("helptip")),
|
||||
grid(0)
|
||||
twindow_builder::tresolution::tresolution(const config& cfg)
|
||||
: window_width(cfg["window_width"])
|
||||
, window_height(cfg["window_height"])
|
||||
, automatic_placement(cfg["automatic_placement"].to_bool(true))
|
||||
, x(cfg["x"])
|
||||
, y(cfg["y"])
|
||||
, width(cfg["width"])
|
||||
, height(cfg["height"])
|
||||
, reevaluate_best_size(cfg["reevaluate_best_size"])
|
||||
, functions()
|
||||
, vertical_placement(implementation::get_v_align(cfg["vertical_placement"]))
|
||||
, horizontal_placement(
|
||||
implementation::get_h_align(cfg["horizontal_placement"]))
|
||||
, maximum_width(cfg["maximum_width"])
|
||||
, maximum_height(cfg["maximum_height"])
|
||||
, click_dismiss(cfg["click_dismiss"].to_bool())
|
||||
, definition(cfg["definition"])
|
||||
, linked_groups()
|
||||
, tooltip(cfg.child_or_empty("tooltip"))
|
||||
, helptip(cfg.child_or_empty("helptip"))
|
||||
, grid(0)
|
||||
{
|
||||
if(!cfg["functions"].empty()) {
|
||||
game_logic::formula(cfg["functions"], &functions).evaluate();
|
||||
}
|
||||
|
||||
const config &c = cfg.child("grid");
|
||||
const config& c = cfg.child("grid");
|
||||
|
||||
VALIDATE(c, _("No grid defined."));
|
||||
|
||||
|
@ -403,34 +407,35 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
|||
|
||||
if(!automatic_placement) {
|
||||
VALIDATE(width.has_formula() || width(),
|
||||
missing_mandatory_wml_key("resolution", "width"));
|
||||
missing_mandatory_wml_key("resolution", "width"));
|
||||
VALIDATE(height.has_formula() || height(),
|
||||
missing_mandatory_wml_key("resolution", "height"));
|
||||
missing_mandatory_wml_key("resolution", "height"));
|
||||
}
|
||||
|
||||
DBG_GUI_P << "Window builder: parsing resolution "
|
||||
<< window_width << ',' << window_height << '\n';
|
||||
DBG_GUI_P << "Window builder: parsing resolution " << window_width << ','
|
||||
<< window_height << '\n';
|
||||
|
||||
if(definition.empty()) {
|
||||
definition = "default";
|
||||
}
|
||||
|
||||
FOREACH(const AUTO& lg, cfg.child_range("linked_group")) {
|
||||
FOREACH(const AUTO & lg, cfg.child_range("linked_group"))
|
||||
{
|
||||
tlinked_group linked_group;
|
||||
linked_group.id = lg["id"].str();
|
||||
linked_group.fixed_width = lg["fixed_width"].to_bool();
|
||||
linked_group.fixed_height = lg["fixed_height"].to_bool();
|
||||
|
||||
VALIDATE(!linked_group.id.empty()
|
||||
, missing_mandatory_wml_key("linked_group", "id"));
|
||||
VALIDATE(!linked_group.id.empty(),
|
||||
missing_mandatory_wml_key("linked_group", "id"));
|
||||
|
||||
if(!(linked_group.fixed_width || linked_group.fixed_height)) {
|
||||
utils::string_map symbols;
|
||||
symbols["id"] = linked_group.id;
|
||||
t_string msg = vgettext(
|
||||
"Linked '$id' group needs a 'fixed_width' or "
|
||||
"'fixed_height' key."
|
||||
, symbols);
|
||||
t_string msg
|
||||
= vgettext("Linked '$id' group needs a 'fixed_width' or "
|
||||
"'fixed_height' key.",
|
||||
symbols);
|
||||
|
||||
VALIDATE(false, msg);
|
||||
}
|
||||
|
@ -439,11 +444,10 @@ twindow_builder::tresolution::tresolution(const config& cfg) :
|
|||
}
|
||||
}
|
||||
|
||||
twindow_builder::tresolution::ttip::ttip(const config& cfg)
|
||||
: id(cfg["id"])
|
||||
twindow_builder::tresolution::ttip::ttip(const config& cfg) : id(cfg["id"])
|
||||
{
|
||||
VALIDATE(!id.empty()
|
||||
, missing_mandatory_wml_key("[window][resolution][tip]", "id"));
|
||||
VALIDATE(!id.empty(),
|
||||
missing_mandatory_wml_key("[window][resolution][tip]", "id"));
|
||||
}
|
||||
|
||||
/*WIKI
|
||||
|
@ -475,11 +479,11 @@ twindow_builder::tresolution::ttip::ttip(const config& cfg)
|
|||
* @allow{link}{name="gui/window/resolution/grid"}
|
||||
* For every column the following variables are available:
|
||||
* @begin{table}{config}
|
||||
* grow_factor & unsigned & 0 & The grow factor for a column, this value
|
||||
* is only read for the first row. $
|
||||
* grow_factor & unsigned & 0 & The grow factor for a column, this
|
||||
* value is only read for the first row. $
|
||||
*
|
||||
* border_size & unsigned & 0 & The border size for this grid cell. $
|
||||
* border & border & "" & Where to place the border in this grid
|
||||
* border_size & unsigned & 0 & The border size for this grid cell. $
|
||||
* border & border & "" & Where to place the border in this grid
|
||||
* cell. $
|
||||
*
|
||||
* vertical_alignment & v_align & "" &
|
||||
|
@ -508,24 +512,26 @@ twindow_builder::tresolution::ttip::ttip(const config& cfg)
|
|||
* @end{parent}{name="gui/window/resolution/"}
|
||||
*
|
||||
*/
|
||||
tbuilder_grid::tbuilder_grid(const config& cfg) :
|
||||
tbuilder_widget(cfg),
|
||||
rows(0),
|
||||
cols(0),
|
||||
row_grow_factor(),
|
||||
col_grow_factor(),
|
||||
flags(),
|
||||
border_size(),
|
||||
widgets()
|
||||
tbuilder_grid::tbuilder_grid(const config& cfg)
|
||||
: tbuilder_widget(cfg)
|
||||
, rows(0)
|
||||
, cols(0)
|
||||
, row_grow_factor()
|
||||
, col_grow_factor()
|
||||
, flags()
|
||||
, border_size()
|
||||
, widgets()
|
||||
{
|
||||
log_scope2(log_gui_parse, "Window builder: parsing a grid");
|
||||
|
||||
FOREACH(const AUTO& row, cfg.child_range("row")) {
|
||||
FOREACH(const AUTO & row, cfg.child_range("row"))
|
||||
{
|
||||
unsigned col = 0;
|
||||
|
||||
row_grow_factor.push_back(row["grow_factor"]);
|
||||
|
||||
FOREACH(const AUTO& c, row.child_range("column")) {
|
||||
FOREACH(const AUTO & c, row.child_range("column"))
|
||||
{
|
||||
flags.push_back(implementation::read_flags(c));
|
||||
border_size.push_back(c["border_size"]);
|
||||
if(rows == 0) {
|
||||
|
@ -538,17 +544,16 @@ tbuilder_grid::tbuilder_grid(const config& cfg) :
|
|||
}
|
||||
|
||||
++rows;
|
||||
if (rows == 1) {
|
||||
if(rows == 1) {
|
||||
cols = col;
|
||||
} else {
|
||||
VALIDATE(col, _("A row must have a column."));
|
||||
VALIDATE(col == cols, _("Number of columns differ."));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DBG_GUI_P << "Window builder: grid has "
|
||||
<< rows << " rows and " << cols << " columns.\n";
|
||||
DBG_GUI_P << "Window builder: grid has " << rows << " rows and " << cols
|
||||
<< " columns.\n";
|
||||
}
|
||||
|
||||
tgrid* tbuilder_grid::build() const
|
||||
|
@ -563,7 +568,7 @@ twidget* tbuilder_grid::build(const treplacements& replacements) const
|
|||
return result;
|
||||
}
|
||||
|
||||
tgrid* tbuilder_grid::build (tgrid* grid) const
|
||||
tgrid* tbuilder_grid::build(tgrid* grid) const
|
||||
{
|
||||
grid->set_id(id);
|
||||
grid->set_linked_group(linked_group);
|
||||
|
@ -571,9 +576,8 @@ tgrid* tbuilder_grid::build (tgrid* grid) const
|
|||
|
||||
log_scope2(log_gui_general, "Window builder: building grid");
|
||||
|
||||
DBG_GUI_G << "Window builder: grid '" << id
|
||||
<< "' has " << rows << " rows and "
|
||||
<< cols << " columns.\n";
|
||||
DBG_GUI_G << "Window builder: grid '" << id << "' has " << rows
|
||||
<< " rows and " << cols << " columns.\n";
|
||||
|
||||
for(unsigned x = 0; x < rows; ++x) {
|
||||
grid->set_row_grow_factor(x, row_grow_factor[x]);
|
||||
|
@ -583,10 +587,15 @@ tgrid* tbuilder_grid::build (tgrid* grid) const
|
|||
grid->set_column_grow_factor(y, col_grow_factor[y]);
|
||||
}
|
||||
|
||||
DBG_GUI_G << "Window builder: adding child at " << x << ',' << y << ".\n";
|
||||
DBG_GUI_G << "Window builder: adding child at " << x << ',' << y
|
||||
<< ".\n";
|
||||
|
||||
twidget* widget = widgets[x * cols + y]->build();
|
||||
grid->set_child(widget, x, y, flags[x * cols + y], border_size[x * cols + y]);
|
||||
grid->set_child(widget,
|
||||
x,
|
||||
y,
|
||||
flags[x * cols + y],
|
||||
border_size[x * cols + y]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,9 +610,8 @@ void tbuilder_grid::build(tgrid& grid, const treplacements& replacements) const
|
|||
|
||||
log_scope2(log_gui_general, "Window builder: building grid");
|
||||
|
||||
DBG_GUI_G << "Window builder: grid '" << id
|
||||
<< "' has " << rows << " rows and "
|
||||
<< cols << " columns.\n";
|
||||
DBG_GUI_G << "Window builder: grid '" << id << "' has " << rows
|
||||
<< " rows and " << cols << " columns.\n";
|
||||
|
||||
for(unsigned x = 0; x < rows; ++x) {
|
||||
grid.set_row_grow_factor(x, row_grow_factor[x]);
|
||||
|
@ -613,15 +621,14 @@ void tbuilder_grid::build(tgrid& grid, const treplacements& replacements) const
|
|||
grid.set_column_grow_factor(y, col_grow_factor[y]);
|
||||
}
|
||||
|
||||
DBG_GUI_G << "Window builder: adding child at "
|
||||
<< x << ',' << y << ".\n";
|
||||
DBG_GUI_G << "Window builder: adding child at " << x << ',' << y
|
||||
<< ".\n";
|
||||
|
||||
grid.set_child(
|
||||
widgets[x * cols + y]->build(replacements)
|
||||
, x
|
||||
, y
|
||||
, flags[x * cols + y]
|
||||
, border_size[x * cols + y]);
|
||||
grid.set_child(widgets[x * cols + y]->build(replacements),
|
||||
x,
|
||||
y,
|
||||
flags[x * cols + y],
|
||||
border_size[x * cols + y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -644,4 +651,3 @@ void tbuilder_grid::build(tgrid& grid, const treplacements& replacements) const
|
|||
* [[Category: GUI WML Reference]]
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
class config;
|
||||
class CVideo;
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class twindow;
|
||||
|
||||
|
@ -38,11 +39,9 @@ class twindow;
|
|||
twindow* build(CVideo& video, const std::string& type);
|
||||
|
||||
/** Contains the info needed to instantiate a widget. */
|
||||
struct tbuilder_widget
|
||||
: public reference_counted_object
|
||||
struct tbuilder_widget : public reference_counted_object
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The replacements type is used to define replacement types.
|
||||
*
|
||||
|
@ -51,14 +50,14 @@ public:
|
|||
* using and `[instance]' widget this decision can be postponed until
|
||||
* instantiation.
|
||||
*/
|
||||
typedef std::map<
|
||||
std::string
|
||||
, boost::intrusive_ptr<tbuilder_widget>
|
||||
> treplacements;
|
||||
typedef std::map<std::string, boost::intrusive_ptr<tbuilder_widget> >
|
||||
treplacements;
|
||||
|
||||
explicit tbuilder_widget(const config& cfg);
|
||||
|
||||
virtual ~tbuilder_widget() {}
|
||||
virtual ~tbuilder_widget()
|
||||
{
|
||||
}
|
||||
|
||||
virtual twidget* build() const = 0;
|
||||
|
||||
|
@ -86,8 +85,9 @@ typedef boost::intrusive_ptr<const tbuilder_widget> const_tbuilder_widget_ptr;
|
|||
* @param id The id of the widget as used in WML.
|
||||
* @param functor The functor to create the widget.
|
||||
*/
|
||||
void register_builder_widget(const std::string& id
|
||||
, boost::function<tbuilder_widget_ptr(config)> functor);
|
||||
void
|
||||
register_builder_widget(const std::string& id,
|
||||
boost::function<tbuilder_widget_ptr(config)> functor);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -112,14 +112,13 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg);
|
|||
*
|
||||
* @returns A generic widget builder pointer.
|
||||
*/
|
||||
template<class T>
|
||||
template <class T>
|
||||
tbuilder_widget_ptr build_widget(const config& cfg)
|
||||
{
|
||||
return new T(cfg);
|
||||
}
|
||||
|
||||
struct tbuilder_grid
|
||||
: public tbuilder_widget
|
||||
struct tbuilder_grid : public tbuilder_widget
|
||||
{
|
||||
public:
|
||||
explicit tbuilder_grid(const config& cfg);
|
||||
|
@ -154,11 +153,7 @@ typedef boost::intrusive_ptr<const tbuilder_grid> tbuilder_grid_const_ptr;
|
|||
class twindow_builder
|
||||
{
|
||||
public:
|
||||
|
||||
twindow_builder()
|
||||
: resolutions()
|
||||
, id_()
|
||||
, description_()
|
||||
twindow_builder() : resolutions(), id_(), description_()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -194,10 +189,7 @@ public:
|
|||
|
||||
struct tlinked_group
|
||||
{
|
||||
tlinked_group()
|
||||
: id()
|
||||
, fixed_width(false)
|
||||
, fixed_height(false)
|
||||
tlinked_group() : id(), fixed_width(false), fixed_height(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -232,9 +224,8 @@ private:
|
|||
/**
|
||||
* Builds a window.
|
||||
*/
|
||||
twindow *build(CVideo &video, const twindow_builder::tresolution *res);
|
||||
twindow* build(CVideo& video, const twindow_builder::tresolution* res);
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
#include "gui/auxiliary/window_builder/helper.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tbuilder_button::tbuilder_button(const config& cfg)
|
||||
: tbuilder_control(cfg)
|
||||
|
@ -40,9 +42,8 @@ twidget* tbuilder_button::build() const
|
|||
|
||||
widget->set_retval(get_retval(retval_id_, retval_, id));
|
||||
|
||||
DBG_GUI_G << "Window builder: placed button '"
|
||||
<< id << "' with definition '"
|
||||
<< definition << "'.\n";
|
||||
DBG_GUI_G << "Window builder: placed button '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -88,4 +89,3 @@ twidget* tbuilder_button::build() const
|
|||
* @end{tag}{name="button"}
|
||||
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
|
||||
*/
|
||||
|
||||
|
|
|
@ -17,21 +17,22 @@
|
|||
|
||||
#include "gui/auxiliary/window_builder/control.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class tcontrol;
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
struct tbuilder_button
|
||||
: public tbuilder_control
|
||||
struct tbuilder_button : public tbuilder_control
|
||||
{
|
||||
public:
|
||||
explicit tbuilder_button(const config& cfg);
|
||||
|
||||
using tbuilder_control::build;
|
||||
|
||||
twidget* build () const;
|
||||
|
||||
twidget* build() const;
|
||||
|
||||
private:
|
||||
std::string retval_id_;
|
||||
|
@ -43,4 +44,3 @@ private:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
#include "gui/widgets/control.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tbuilder_control::tbuilder_control(const config& cfg)
|
||||
: tbuilder_widget(cfg)
|
||||
|
@ -39,15 +41,15 @@ tbuilder_control::tbuilder_control(const config& cfg)
|
|||
definition = "default";
|
||||
}
|
||||
|
||||
VALIDATE_WITH_DEV_MESSAGE(help.empty() || !tooltip.empty()
|
||||
, _("Found a widget with a helptip and without a tooltip.")
|
||||
, (formatter() << "id '" << id
|
||||
<< "' label '" << label
|
||||
<< "' helptip '" << help << "'.").str());
|
||||
VALIDATE_WITH_DEV_MESSAGE(
|
||||
help.empty() || !tooltip.empty(),
|
||||
_("Found a widget with a helptip and without a tooltip."),
|
||||
(formatter() << "id '" << id << "' label '" << label
|
||||
<< "' helptip '" << help << "'.").str());
|
||||
|
||||
|
||||
DBG_GUI_P << "Window builder: found control with id '"
|
||||
<< id << "' and definition '" << definition << "'.\n";
|
||||
DBG_GUI_P << "Window builder: found control with id '" << id
|
||||
<< "' and definition '" << definition << "'.\n";
|
||||
}
|
||||
|
||||
void tbuilder_control::init_control(tcontrol* control) const
|
||||
|
@ -153,4 +155,3 @@ twidget* tbuilder_control::build(const treplacements& /*replacements*/) const
|
|||
* @end{tag}{name="widget_instance"}
|
||||
* @end{parent}{name="generic/"}
|
||||
*/
|
||||
|
||||
|
|
|
@ -17,17 +17,17 @@
|
|||
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
class tcontrol;
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
struct tbuilder_control
|
||||
: public tbuilder_widget
|
||||
struct tbuilder_control : public tbuilder_widget
|
||||
{
|
||||
public:
|
||||
|
||||
tbuilder_control(const config& cfg);
|
||||
|
||||
using tbuilder_widget::build;
|
||||
|
@ -50,4 +50,3 @@ public:
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/widgets/drawing.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tbuilder_drawing::tbuilder_drawing(const config& cfg)
|
||||
: tbuilder_control(cfg)
|
||||
|
@ -39,8 +41,7 @@ twidget* tbuilder_drawing::build() const
|
|||
|
||||
init_control(widget);
|
||||
|
||||
const game_logic::map_formula_callable& size =
|
||||
get_screen_size_variables();
|
||||
const game_logic::map_formula_callable& size = get_screen_size_variables();
|
||||
|
||||
const unsigned w = width(size);
|
||||
const unsigned h = height(size);
|
||||
|
@ -51,9 +52,8 @@ twidget* tbuilder_drawing::build() const
|
|||
|
||||
widget->canvas().front().set_cfg(draw);
|
||||
|
||||
DBG_GUI_G << "Window builder: placed drawing '"
|
||||
<< id << "' with definition '"
|
||||
<< definition << "'.\n";
|
||||
DBG_GUI_G << "Window builder: placed drawing '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -95,4 +95,3 @@ twidget* tbuilder_drawing::build() const
|
|||
* http://www.wesnoth.org/wiki/GUIToolkitWML#Resolution_2 for the list of
|
||||
* items.
|
||||
*/
|
||||
|
||||
|
|
|
@ -18,18 +18,19 @@
|
|||
#include "config.hpp"
|
||||
#include "gui/auxiliary/window_builder/control.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
struct tbuilder_drawing
|
||||
: public tbuilder_control
|
||||
struct tbuilder_drawing : public tbuilder_control
|
||||
{
|
||||
explicit tbuilder_drawing(const config& cfg);
|
||||
|
||||
using tbuilder_control::build;
|
||||
|
||||
twidget* build () const;
|
||||
twidget* build() const;
|
||||
|
||||
/** The width of the widget. */
|
||||
tformula<unsigned> width;
|
||||
|
@ -46,4 +47,3 @@ struct tbuilder_drawing
|
|||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
#include "gui/widgets/window.hpp"
|
||||
#include "utils/foreach.tpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
unsigned get_v_align(const std::string& v_align)
|
||||
{
|
||||
|
@ -34,8 +36,8 @@ unsigned get_v_align(const std::string& v_align)
|
|||
return tgrid::VERTICAL_ALIGN_BOTTOM;
|
||||
} else {
|
||||
if(!v_align.empty() && v_align != "center") {
|
||||
ERR_GUI_E << "Invalid vertical alignment '"
|
||||
<< v_align << "' falling back to 'center'.\n";
|
||||
ERR_GUI_E << "Invalid vertical alignment '" << v_align
|
||||
<< "' falling back to 'center'.\n";
|
||||
}
|
||||
return tgrid::VERTICAL_ALIGN_CENTER;
|
||||
}
|
||||
|
@ -49,8 +51,8 @@ unsigned get_h_align(const std::string& h_align)
|
|||
return tgrid::HORIZONTAL_ALIGN_RIGHT;
|
||||
} else {
|
||||
if(!h_align.empty() && h_align != "center") {
|
||||
ERR_GUI_E << "Invalid horizontal alignment '"
|
||||
<< h_align << "' falling back to 'center'.\n";
|
||||
ERR_GUI_E << "Invalid horizontal alignment '" << h_align
|
||||
<< "' falling back to 'center'.\n";
|
||||
}
|
||||
return tgrid::HORIZONTAL_ALIGN_CENTER;
|
||||
}
|
||||
|
@ -59,7 +61,8 @@ unsigned get_h_align(const std::string& h_align)
|
|||
unsigned get_border(const std::vector<std::string>& borders)
|
||||
{
|
||||
unsigned result = 0;
|
||||
FOREACH(const AUTO& border, borders) {
|
||||
FOREACH(const AUTO & border, borders)
|
||||
{
|
||||
if(border == "all") {
|
||||
return tgrid::BORDER_ALL;
|
||||
} else if(border == "top") {
|
||||
|
@ -81,25 +84,25 @@ unsigned read_flags(const config& cfg)
|
|||
|
||||
const unsigned v_flags = get_v_align(cfg["vertical_alignment"]);
|
||||
const unsigned h_flags = get_h_align(cfg["horizontal_alignment"]);
|
||||
flags |= get_border( utils::split(cfg["border"]));
|
||||
flags |= get_border(utils::split(cfg["border"]));
|
||||
|
||||
if (cfg["vertical_grow"].to_bool()) {
|
||||
if(cfg["vertical_grow"].to_bool()) {
|
||||
flags |= tgrid::VERTICAL_GROW_SEND_TO_CLIENT;
|
||||
|
||||
if(! (cfg["vertical_alignment"]).empty()) {
|
||||
if(!(cfg["vertical_alignment"]).empty()) {
|
||||
ERR_GUI_P << "vertical_grow and vertical_alignment "
|
||||
"can't be combined, alignment is ignored.\n";
|
||||
"can't be combined, alignment is ignored.\n";
|
||||
}
|
||||
} else {
|
||||
flags |= v_flags;
|
||||
}
|
||||
|
||||
if (cfg["horizontal_grow"].to_bool()) {
|
||||
if(cfg["horizontal_grow"].to_bool()) {
|
||||
flags |= tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT;
|
||||
|
||||
if(! (cfg["horizontal_alignment"]).empty()) {
|
||||
if(!(cfg["horizontal_alignment"]).empty()) {
|
||||
ERR_GUI_P << "horizontal_grow and horizontal_alignment "
|
||||
"can't be combined, alignment is ignored.\n";
|
||||
"can't be combined, alignment is ignored.\n";
|
||||
}
|
||||
} else {
|
||||
flags |= h_flags;
|
||||
|
@ -109,7 +112,7 @@ unsigned read_flags(const config& cfg)
|
|||
}
|
||||
|
||||
tscrollbar_container::tscrollbar_mode
|
||||
get_scrollbar_mode(const std::string& scrollbar_mode)
|
||||
get_scrollbar_mode(const std::string& scrollbar_mode)
|
||||
{
|
||||
if(scrollbar_mode == "always") {
|
||||
return tscrollbar_container::always_visible;
|
||||
|
@ -119,24 +122,24 @@ tscrollbar_container::tscrollbar_mode
|
|||
return tscrollbar_container::auto_visible;
|
||||
} else {
|
||||
if(!scrollbar_mode.empty() && scrollbar_mode != "initial_auto") {
|
||||
ERR_GUI_E << "Invalid scrollbar mode '"
|
||||
<< scrollbar_mode << "' falling back to 'initial_auto'.\n";
|
||||
ERR_GUI_E << "Invalid scrollbar mode '" << scrollbar_mode
|
||||
<< "' falling back to 'initial_auto'.\n";
|
||||
}
|
||||
return tscrollbar_container::auto_visible_first_run;
|
||||
}
|
||||
}
|
||||
|
||||
int get_retval(const std::string& retval_id
|
||||
, const int retval
|
||||
, const std::string& id)
|
||||
int get_retval(const std::string& retval_id,
|
||||
const int retval,
|
||||
const std::string& id)
|
||||
{
|
||||
if(!retval_id.empty()) {
|
||||
int result = twindow::get_retval_by_id(retval_id);
|
||||
if(result) {
|
||||
return result;
|
||||
} else {
|
||||
ERR_GUI_E << "Window builder: retval_id '"
|
||||
<< retval_id << "' is unknown.\n";
|
||||
ERR_GUI_E << "Window builder: retval_id '" << retval_id
|
||||
<< "' is unknown.\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,4 +153,3 @@ int get_retval(const std::string& retval_id
|
|||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
|
||||
class config;
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the vertical alignment.
|
||||
|
@ -70,7 +72,7 @@ unsigned read_flags(const config& cfg);
|
|||
* @returns The scrollbar mode flags.
|
||||
*/
|
||||
tscrollbar_container::tscrollbar_mode
|
||||
get_scrollbar_mode(const std::string& scrollbar_mode);
|
||||
get_scrollbar_mode(const std::string& scrollbar_mode);
|
||||
|
||||
/**
|
||||
* Returns the return value for a widget.
|
||||
|
@ -79,13 +81,12 @@ tscrollbar_container::tscrollbar_mode
|
|||
* Else if there's a retval that's returned.
|
||||
* Else it falls back to the id.
|
||||
*/
|
||||
int get_retval(const std::string& retval_id
|
||||
, const int retval
|
||||
, const std::string& id);
|
||||
int get_retval(const std::string& retval_id,
|
||||
const int retval,
|
||||
const std::string& id);
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,54 +28,58 @@
|
|||
#include "utils/foreach.tpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
namespace implementation {
|
||||
namespace implementation
|
||||
{
|
||||
|
||||
tbuilder_horizontal_listbox::tbuilder_horizontal_listbox(const config& cfg)
|
||||
: tbuilder_control(cfg)
|
||||
, vertical_scrollbar_mode(
|
||||
get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
|
||||
get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
|
||||
, horizontal_scrollbar_mode(
|
||||
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
|
||||
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
|
||||
, list_builder(NULL)
|
||||
, list_data()
|
||||
{
|
||||
const config &l = cfg.child("list_definition");
|
||||
const config& l = cfg.child("list_definition");
|
||||
|
||||
VALIDATE(l, _("No list defined."));
|
||||
list_builder = new tbuilder_grid(l);
|
||||
assert(list_builder);
|
||||
VALIDATE(list_builder->rows == 1
|
||||
, _("A 'list_definition' should contain one row."));
|
||||
VALIDATE(list_builder->rows == 1,
|
||||
_("A 'list_definition' should contain one row."));
|
||||
|
||||
const config &data = cfg.child("list_data");
|
||||
if (!data) return;
|
||||
const config& data = cfg.child("list_data");
|
||||
if(!data)
|
||||
return;
|
||||
|
||||
FOREACH(const AUTO& row, data.child_range("row")) {
|
||||
FOREACH(const AUTO & row, data.child_range("row"))
|
||||
{
|
||||
unsigned col = 0;
|
||||
|
||||
FOREACH(const AUTO& c, row.child_range("column")) {
|
||||
FOREACH(const AUTO & c, row.child_range("column"))
|
||||
{
|
||||
list_data.push_back(string_map());
|
||||
FOREACH(const AUTO& i, c.attribute_range()) {
|
||||
FOREACH(const AUTO & i, c.attribute_range())
|
||||
{
|
||||
list_data.back()[i.first] = i.second;
|
||||
}
|
||||
++col;
|
||||
}
|
||||
|
||||
VALIDATE(col == list_builder->cols, _("'list_data' must have "
|
||||
"the same number of columns as the 'list_definition'."));
|
||||
VALIDATE(col == list_builder->cols,
|
||||
_("'list_data' must have "
|
||||
"the same number of columns as the 'list_definition'."));
|
||||
}
|
||||
}
|
||||
|
||||
twidget* tbuilder_horizontal_listbox::build() const
|
||||
{
|
||||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
tlist *widget = new tlist(true
|
||||
, true
|
||||
, tgenerator_::horizontal_list
|
||||
, true
|
||||
, list_builder);
|
||||
tlist* widget = new tlist(
|
||||
true, true, tgenerator_::horizontal_list, true, list_builder);
|
||||
|
||||
init_control(widget);
|
||||
if(!list_data.empty()) {
|
||||
|
@ -83,8 +87,8 @@ twidget* tbuilder_horizontal_listbox::build() const
|
|||
}
|
||||
return widget;
|
||||
#else
|
||||
tlistbox *widget = new tlistbox(
|
||||
true, true, tgenerator_::horizontal_list, true);
|
||||
tlistbox* widget
|
||||
= new tlistbox(true, true, tgenerator_::horizontal_list, true);
|
||||
|
||||
init_control(widget);
|
||||
|
||||
|
@ -93,13 +97,12 @@ twidget* tbuilder_horizontal_listbox::build() const
|
|||
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
|
||||
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
|
||||
|
||||
DBG_GUI_G << "Window builder: placed listbox '"
|
||||
<< id << "' with definition '"
|
||||
<< definition << "'.\n";
|
||||
DBG_GUI_G << "Window builder: placed listbox '" << id
|
||||
<< "' with definition '" << definition << "'.\n";
|
||||
|
||||
boost::intrusive_ptr<const tlistbox_definition::tresolution> conf =
|
||||
boost::dynamic_pointer_cast
|
||||
<const tlistbox_definition::tresolution>(widget->config());
|
||||
boost::intrusive_ptr<const tlistbox_definition::tresolution>
|
||||
conf = boost::dynamic_pointer_cast<const tlistbox_definition::tresolution>(
|
||||
widget->config());
|
||||
assert(conf);
|
||||
|
||||
widget->init_grid(conf->grid);
|
||||
|
@ -172,4 +175,3 @@ twidget* tbuilder_horizontal_listbox::build() const
|
|||
* @end{tag}{name="horizontal_listbox"}
|
||||
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
|
||||
*/
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue