-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2: Added preliminary menu creation API.
- Loading branch information
Ruskiy69
committed
Jul 29, 2013
1 parent
e0a71b8
commit bd88f39
Showing
3 changed files
with
211 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* @file | ||
* Zenderer/GUI/Menu.hpp - A high-level menu creating interface. | ||
* | ||
* @author George Kudrayvtsev (halcyon) | ||
* @version 1.0 | ||
* @copyright Apache License v2.0 | ||
* Licensed under the Apache License, Version 2.0 (the "License"). \n | ||
* You may not use this file except in compliance with the License. \n | ||
* You may obtain a copy of the License at: | ||
* http://www.apache.org/licenses/LICENSE-2.0 \n | ||
* Unless required by applicable law or agreed to in writing, software \n | ||
* distributed under the License is distributed on an "AS IS" BASIS, \n | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n | ||
* See the License for the specific language governing permissions and \n | ||
* limitations under the License. | ||
* | ||
* @addtogroup GUI | ||
* @{ | ||
**/ | ||
|
||
#ifndef ZENDERER__GUI__BUTTON_HPP | ||
#define ZENDERER__GUI__BUTTON_HPP | ||
|
||
#include "Zenderer/Events/EventHandler.hpp" | ||
#include "Zenderer/Events/Mouse.hpp" | ||
#include "Zenderer/Graphics/Scene.hpp" | ||
#include "Font.hpp" | ||
#include "Button.hpp" | ||
|
||
namespace zen | ||
{ | ||
namespace gui | ||
{ | ||
class ZEN_API CMenu | ||
{ | ||
public: | ||
CMenu(gfx::CWindow& Window, asset::CAssetManager& Assets) : | ||
m_Scene(Window.GetWidth(), Window.GetHeight(), Assets), | ||
m_Background(m_Scene.AddEntity()), | ||
m_Title(m_Scene.AddEntity()), | ||
mp_Bg(nullptr), m_spacing(0) | ||
{ | ||
m_Scene.Init(); | ||
mp_menuButtons.clear(); | ||
} | ||
|
||
virtual ~CMenu() | ||
{ | ||
m_Scene.Destroy(); | ||
for(auto& i : mp_menuButtons) delete i; | ||
mp_menuButtons.clear(); | ||
} | ||
|
||
virtual int16_t HandleEvent(const evt::event_t& Evt) | ||
{ | ||
if(Evt.type == evt::EventType::MOUSE_MOTION) | ||
{ | ||
math::aabb_t MouseBox(Evt.mouse.position, | ||
math::Vector<uint32_t>(2, 2)); | ||
|
||
auto i = mp_menuButtons.begin(), | ||
j = mp_menuButtons.end(); | ||
|
||
for( ; i != j; ++i) | ||
{ | ||
if((*i)->IsOver(Box)) | ||
{ | ||
(*i)->SetActive(); | ||
} | ||
else | ||
{ | ||
(*i)->SetNormal(); | ||
} | ||
} | ||
} | ||
|
||
else if(Evt.type == evt::EventType::MOUSE_DOWN && | ||
Evt.mouse.button == evt::MouseButton::LEFT) | ||
{ | ||
math::aabb_t MouseBox(Evt.mouse.position, | ||
math::Vector<uint32_t>(2, 2)); | ||
|
||
for(size_t i = 0; i < mp_menuButtons.size(): ++i) | ||
{ | ||
if(mp_menuButtons[i]->IsOver(Box)) return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
virtual uint16_t AddButton(const string_t& text) | ||
{ | ||
CButton* pNew = new CButton(m_Scene); | ||
pNew->SetFont(m_Font); | ||
pNew->SetActiveColor(m_acolor); | ||
pNew->SetNormalColor(m_ncolor); | ||
|
||
if(mp_Bg != nullptr) pNew->SetBackground(*mp_Bg); | ||
|
||
pNew->Prepare(text); | ||
pNew->Place(m_Position); | ||
pNew->SetNormal(); | ||
|
||
m_Position.y += m_spacing; | ||
mp_menuButtons.push_back(pNew); | ||
return mp_menuButtons.size() - 1; | ||
} | ||
|
||
virtual int Update() | ||
{ | ||
m_Scene.Render(); | ||
} | ||
|
||
void SetButtonBackground(const obj::CEntity& Bg) | ||
{ | ||
mp_Bg = Bg; | ||
} | ||
|
||
void SetNormalButtonTextColor(const color4f_t& Color); | ||
void SetActiveButtonTextColor(const color4f_t& Color); | ||
|
||
void SetInitialButtonPosition(const math::vector_t& Pos) | ||
{ | ||
m_Position = Pos; | ||
} | ||
|
||
void SetSpacing(const uint16_t vertical_spacing) | ||
{ | ||
m_spacing = vertical_spacing; | ||
} | ||
|
||
private: | ||
gfx::CScene m_Scene; | ||
obj::CEntity& m_Background; | ||
obj::CEntity& m_Title; | ||
obj::CEntity* mp_Bg; | ||
std::vector<CButton*> mp_menuButtons; | ||
|
||
math::vector_t m_Position; | ||
uint16_t m_spacing; | ||
}; | ||
} // namespace gui | ||
} // namespace zen | ||
|
||
#endif // ZENDERER__GUI__BUTTON_HPP | ||
|
||
/** | ||
* @class zen::gui::CMenu | ||
* @details | ||
* A high-level wrapper that facilitates a simple method of creating | ||
* fairly customizable and high-quality menus with custom buttons, | ||
* fonts, backgrounds, and other sections. | ||
**/ | ||
|
||
/** @} **/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters