Skip to content

Commit

Permalink
Convert gui2::tvisible and gui2::tredraw_action to scoped enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz authored and CelticMinstrel committed Jul 30, 2016
1 parent 8a8316a commit 8297300
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/gui/dialogs/message.cpp
Expand Up @@ -116,7 +116,7 @@ void tmessage::set_button_caption(const tbutton_id button,
}

void tmessage::set_button_visible(const tbutton_id button,
const twidget::tvisible::scoped_enum visible)
const twidget::tvisible visible)
{
buttons_[button].visible = visible;
if(buttons_[button].button) {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/dialogs/message.hpp
Expand Up @@ -79,7 +79,7 @@ class tmessage : public tdialog
const std::string& caption);

void set_button_visible(const tbutton_id button,
const twidget::tvisible::scoped_enum visible);
const twidget::tvisible visible);

void set_button_retval(const tbutton_id button, const int retval);

Expand Down Expand Up @@ -141,7 +141,7 @@ class tmessage : public tdialog

tbutton* button;
std::string caption;
twidget::tvisible::scoped_enum visible;
twidget::tvisible visible;
int retval;
};

Expand Down
6 changes: 3 additions & 3 deletions src/gui/widgets/widget.cpp
Expand Up @@ -442,7 +442,7 @@ bool twidget::get_is_dirty() const
return is_dirty_;
}

void twidget::set_visible(const tvisible::scoped_enum visible)
void twidget::set_visible(const tvisible visible)
{
if(visible == visible_) {
return;
Expand All @@ -468,12 +468,12 @@ void twidget::set_visible(const tvisible::scoped_enum visible)
}
}

twidget::tvisible::scoped_enum twidget::get_visible() const
twidget::tvisible twidget::get_visible() const
{
return visible_;
}

twidget::tredraw_action::scoped_enum twidget::get_drawing_action() const
twidget::tredraw_action twidget::get_drawing_action() const
{
return (width_ == 0 || height_ == 0) ? tredraw_action::none
: redraw_action_;
Expand Down
142 changes: 64 additions & 78 deletions src/gui/widgets/widget.hpp
Expand Up @@ -58,50 +58,43 @@ class twidget : private boost::noncopyable,

public:
/** Visibility settings done by the user. */
class tvisible : private boost::noncopyable
enum class tvisible
{
friend class tno_such_friend_exists_but_it_makes_the_compiler_happy;
tvisible();

public:
/** @todo C++11 use a scoped enum. */
enum scoped_enum {
/**
* The user sets the widget visible, that means:
* * The widget is visible.
* * @ref find_at always 'sees' the widget (the active flag is
* tested later).
* * The widget (if active) handles events (and sends events to
* its children).
* * The widget is drawn (and sends the call to
* @ref populate_dirty_list to children).
*/
visible,

/**
* The user sets the widget hidden, that means:
* * The widget is invisible but keeps its size.
* * @ref find_at 'sees' the widget if active is @c false.
* * The widget doesn't handle events (and doesn't send events to
* its children).
* * The widget doesn't add itself @ref twindow::dirty_list_ when
* @ref populate_dirty_list is called (nor does it send the
* request to its children).
*/
hidden,

/**
* The user set the widget invisible, that means:
* * The widget is invisible and its grid cell has size 0,0.
* * @ref find_at never 'sees' the widget.
* * The widget doesn't handle events (and doesn't send events to
* its children).
* * The widget doesn't add itself @ref twindow::dirty_list_ when
* @ref populate_dirty_list is called (nor does it send the
* request to its children).
*/
invisible
};
/**
* The user sets the widget visible, that means:
* * The widget is visible.
* * @ref find_at always 'sees' the widget (the active flag is
* tested later).
* * The widget (if active) handles events (and sends events to
* its children).
* * The widget is drawn (and sends the call to
* @ref populate_dirty_list to children).
*/
visible,

/**
* The user sets the widget hidden, that means:
* * The widget is invisible but keeps its size.
* * @ref find_at 'sees' the widget if active is @c false.
* * The widget doesn't handle events (and doesn't send events to
* its children).
* * The widget doesn't add itself @ref twindow::dirty_list_ when
* @ref populate_dirty_list is called (nor does it send the
* request to its children).
*/
hidden,

/**
* The user set the widget invisible, that means:
* * The widget is invisible and its grid cell has size 0,0.
* * @ref find_at never 'sees' the widget.
* * The widget doesn't handle events (and doesn't send events to
* its children).
* * The widget doesn't add itself @ref twindow::dirty_list_ when
* @ref populate_dirty_list is called (nor does it send the
* request to its children).
*/
invisible
};

/**
Expand All @@ -110,37 +103,30 @@ class twidget : private boost::noncopyable,
* This state only will be used if @ref visible_ is @ref tvisible::visible
* depending on this state the widget might not be visible after all.
*/
class tredraw_action : private boost::noncopyable
enum class tredraw_action
{
friend class tno_such_friend_exists_but_it_makes_the_compiler_happy;
tredraw_action();

public:
/** @todo C++11 use a scoped enum. */
enum scoped_enum {
/**
* The widget is fully visible.
*
* The widget should be drawn if @ref dirty_ is @c true. The entire
* widget's rectangle should be redrawn.
*/
full,

/**
* The widget is partly visible.
*
* The should be drawn if @ref dirty_ is @c true. The rectangle to
* redraw in determined by @ref clipping_rectangle_
*/
partly,

/**
* The widget is not visible.
*
* The widget should not be drawn if @ref dirty_ is @c true.
*/
none
};
/**
* The widget is fully visible.
*
* The widget should be drawn if @ref dirty_ is @c true. The entire
* widget's rectangle should be redrawn.
*/
full,

/**
* The widget is partly visible.
*
* The should be drawn if @ref dirty_ is @c true. The rectangle to
* redraw in determined by @ref clipping_rectangle_
*/
partly,

/**
* The widget is not visible.
*
* The widget should not be drawn if @ref dirty_ is @c true.
*/
none
};


Expand Down Expand Up @@ -673,10 +659,10 @@ class twidget : private boost::noncopyable,
void set_is_dirty(const bool is_dirty);
bool get_is_dirty() const;

void set_visible(const tvisible::scoped_enum visible);
tvisible::scoped_enum get_visible() const;
void set_visible(const tvisible visible);
tvisible get_visible() const;

tredraw_action::scoped_enum get_drawing_action() const;
tredraw_action get_drawing_action() const;

#ifndef LOW_MEM

Expand All @@ -701,10 +687,10 @@ class twidget : private boost::noncopyable,
bool is_dirty_;

/** Field for the status of the visibility. */
tvisible::scoped_enum visible_;
tvisible visible_;

/** Field for the action to do on a drawing request. */
tredraw_action::scoped_enum redraw_action_;
tredraw_action redraw_action_;

/** The clipping rectangle if a widget is partly visible. */
SDL_Rect clipping_rectangle_;
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/lua_gui2.cpp
Expand Up @@ -693,7 +693,7 @@ int intf_set_dialog_visible(lua_State *L)
{
typedef gui2::tcontrol::tvisible tvisible;

tvisible::scoped_enum flag = tvisible::visible;
tvisible flag = tvisible::visible;

switch (lua_type(L, 1)) {
case LUA_TBOOLEAN:
Expand Down

0 comments on commit 8297300

Please sign in to comment.