-Delegates are now in the form:
void Delegate(float, float)
This is so the button even handlers can take in mouse coords to do boundary checks. Works fine for buttons, but now everything else that handled events has handlers with two unused parameters.
-The renderer class now has to know about buttons. At first I wanted this all to be abstracted away, so that the renderer would only need to store a geometry buffer for each button, but that didn't play nicely with texturing. Buttons have three textures (normal, mouse over, and clicked). Now the renderer needs to store a pointer to each button, so it can get the appropriate texture when it renders.
Pics (these three show a button in its normal state, with the mouse over it, and clicked, in that order):
Code:
Button.h
#ifndef BUTTON_H#define BUTTON_H#include #include #include #include "UI.h"#include "../../Graphics/Header Files/GeometryBuffer.h"namespace ISO{ namespace Graphics { class Renderer; } namespace UI { class Button { public: Button(Graphics::Renderer* renderer, LPDIRECT3DDEVICE9 device, std::string texName, std::string texOverName, std::string texClickedName, float x, float y, float w, float h); ~Button(); int GetTextureIndex() const; void OnClick(float mouseX, float mouseY); void OnUnClick(float mouseX, float mouseY); void OnMouseOver(float mouseX, float mouseY); private: int m_ActiveIndex, m_TextureIndex, m_TexOverIndex, m_TexClickedIndex; AABB m_Bounds; int m_Position; }; }}#endif
Button.cpp
#include "../Header Files/Button.h"#include "../../Graphics/Header Files/Renderer.h"#include "../../Graphics/Header Files/Texture.h"#include "../../Main/Header Files/Event.h"extern ISO::Base::EventManager *g_Events;ISO::UI::Button::Button(Graphics::Renderer* renderer, LPDIRECT3DDEVICE9 device, std::string texName, std::string texOverName, std::string texClickedName, float x, float y, float w, float h): m_Bounds(x, y, x+w, y+h){ m_ActiveIndex = m_TextureIndex = renderer->AddTexture(new ISO::Graphics::Texture(device, texName)); m_TexOverIndex = renderer->AddTexture(new ISO::Graphics::Texture(device, texOverName)); m_TexClickedIndex = renderer->AddTexture(new ISO::Graphics::Texture(device, texClickedName)); m_Position = renderer->AddButton(this, x, y, x+w, y+h); g_Events->RegisterEventHandler("mouseclick", this, &Button::OnClick); g_Events->RegisterEventHandler("mouseup", this, &Button::OnUnClick); g_Events->RegisterEventHandler("mouseover", this, &Button::OnMouseOver);}ISO::UI::Button::~Button(){}int ISO::UI::Button::GetTextureIndex() const{ return m_ActiveIndex;}void ISO::UI::Button::OnClick(float mouseX, float mouseY){ if (m_Bounds.IsIn(mouseX, mouseY)) { m_ActiveIndex = m_TexClickedIndex; }}void ISO::UI::Button::OnUnClick(float mouseX, float mouseY){ if (m_ActiveIndex == m_TexClickedIndex) { m_ActiveIndex = m_Bounds.IsIn(mouseX, mouseY) ? m_TexOverIndex : m_TextureIndex; }}void ISO::UI::Button::OnMouseOver(float mouseX, float mouseY){ if (m_Bounds.IsIn(mouseX, mouseY) && m_ActiveIndex != m_TexClickedIndex) { m_ActiveIndex = m_TexOverIndex; } else if (m_ActiveIndex == m_TexOverIndex) { m_ActiveIndex = m_TextureIndex; }}
Still to come:
-Editable geometry buffers, so I can edit tiles after creation.
-Font rendering
-Mouse handling to place tiles