Game Development Reference
In-Depth Information
void SetBackgroundColor(const render::color& color)
{ m_backgroundColor = color; Refresh(); }
const math::rectangle& Rectangle() const { return m_rectangle; }
typedef std::function<void(const control&)> custom_draw_function;
void SetCustomDrawFunction(custom_draw_function customDrawFunction)
{
m_customDrawFunction = customDrawFunction;
}
Wewill alsoneedtomanage thevisibility ofcontrols. There aremixed opinionsonwhatis
more intuitive, calling separate functions that represent the action, Show and Hide or call-
ing a single function that uses a parameter to set the state, SetVisibility. The fact is, it is
useful to provide both. While it is true that it seemingly exposes two ways of applying the
same behavior, there will be situations in which the visibility may be given by a parameter,
in which case SetVisibility is less verbose than an if/else to call Show/Hide .
void Show() { SetVisibility(true); }
void Hide() { SetVisibility(false); }
virtual void SetVisibility(bool show) { m_visible = show; }
The important thing is that the behavior should be exactly the same in both cases. In
otherwords, Show shouldinternally call SetVisibility(true) and Hide shouldcall SetVisibil-
ity(false) .
Show and Hide are provided as a convenience, however when there are multiple people
workingonthesamecode,itmayhappenthatsomeonemistakenly(orunknowingly)mod-
ifiesShow/Hidetohaveadifferentbehaviorthan SetVisible ,ifthishappensyoucanexpect
some difficulties down the line. If the risk of this situation is high, choose the function or
functions that will provide you and other programmers the best development experience.
However, by making SetVisibility a virtual function, we allow for more complex behaviors
to be applied during a visibility change, such as performing a fade out or a fade in. The
important part to remember is that Show and Hide should never do anything else than call
SetVisibility otherwise we could no longer guarantee any sort of consistency in our frame-
work.
Before we begin discussing individual controls and their behavior, we will need a place to
add controls into, we will create an object called a container.
Search WWH ::




Custom Search