Game Development Reference
In-Depth Information
al one, the beginning of the effective area will be the scrollbar's rectangle coordinates plus
this half size. Conversely, we need to subtract the size of the cursor from the scrollbar's
rectangle to account for the half cursor we are discarding on each edge. Finally, the ratio is
given by the cursor's coordinate, either the Top or the Left, plus the halfSize to obtain the
midpoint, to this we subtract the edge, by dividing this over the edge we will have effect-
ively calculated a value from 0 to 1 within our effective area.
4.3.10 Dropdown Box
A drop down box is a compact container that may hold multiple options yet only one of
them may be selected at a time. The selected option is visible while the remaining options
are hidden and only visible when the user activates the dropdown menu.
To create a dropdown box we will take advantage of some of the other controls we have
developed so far, we will use a button to open or close the dropdown list and we will use a
listbox to display and select the desired item.
class dropdown : public control
{
dropdown(std::shared_ptr<core> core, const std::shared_ptr<DirectX::SpriteFont>& font, const std::shared_ptr<DirectX::SpriteBatch>
spriteBatch);
virtual void Refresh();
virtual bool HandleInput(float deltaTime, const input::input_state& inputState);
virtual void Update(float deltaTime);
virtual void InternalDraw();
private:
std::shared_ptr<button> m_button;
std::shared_ptr<listbox> m_contents;
bool m_open;
countdown m_inputDelay;
};
We will start by creating and configuring both the button and the contents listbox in the
dropdown's constructor.
dropdown::dropdown(std::shared_ptr<core> core, const std::shared_ptr<DirectX::SpriteFont>& font, const
std::shared_ptr<DirectX::SpriteBatch> spriteBatch)
: control(core, font, spriteBatch)
, m_open(false)
, m_inputDelay(0.185f)
{
m_button = std::shared_ptr<button>(new button(core, font, spriteBatch));
m_button->OnReleased() += [&](void*,button&) { m_open = !m_open; Refresh(); };
Search WWH ::




Custom Search