Game Development Reference
In-Depth Information
{ return m_rectangle; }
event_handler<listboxitem*>& OnSelected()
{ return m_onSelected; }
protected:
virtual void SetPosition(const math::vector2& position)
{ m_rectangle.SetPosition(position); }
virtual void SetSize(const math::vector2& size)
{ m_rectangle.SetSize(size); }
bool m_visible;
bool m_selected;
math::rectangle m_rectangle;
event_handler<listboxitem*> m_onSelected;
listbox* m_owner;
};
With this listbox item base class we can implement all of the listbox's behavior and defer
the actual responsibility of handling input and drawing to a specialized class, this gives the
ability to create any number of items, whether text, image or more complex items that use
containers of UI controls.
To keep things simple we will implement a text based item that handles the basic set of
features we would expect from a list box.
class listboxitemtext : public listboxitem
{
public:
listboxitemtext(listbox* owner, const math::vector2& size, const std::wstring& text, const render::color& color = render::color::WHITE)
: listboxitem(owner)
, m_size(size)
, m_text(text)
, m_color(color)
, m_inputDelay(0.1f)
{
}
virtual void Draw(const math::vector2& position, std::shared_ptr<DirectX::SpriteFont> font, std::shared_ptr<DirectX::SpriteBatch>
spriteBatch);
virtual bool HandleInput(float deltaTime, const input::input_state& inputState);
protected:
math::vector2 m_size;
render::color m_color;
std::wstring m_text;
bool m_mouseOver;
countdown m_inputDelay;
};
Search WWH ::




Custom Search