Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  


Added a simple button class. Seems to be working fine, but it involved two things that I'm not happy about:
-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):


#ifndef BUTTON_H
#define BUTTON_H

#include "UI.h"
#include "../../Graphics/Header Files/GeometryBuffer.h"

namespace ISO
namespace Graphics
class Renderer;

namespace UI
class Button
Button(Graphics::Renderer* renderer, LPDIRECT3DDEVICE9 device, std::string texName, std::string texOverName, std::string texClickedName, float x, float y, float w, float h);

int GetTextureIndex() const;

void OnClick(float mouseX, float mouseY);
void OnUnClick(float mouseX, float mouseY);
void OnMouseOver(float mouseX, float mouseY);
int m_ActiveIndex, m_TextureIndex, m_TexOverIndex, m_TexClickedIndex;
AABB m_Bounds;
int m_Position;



#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);


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
Sign in to follow this  

1 Comment

Recommended Comments

Not familiar with you design but it sounds like you want to encapsulate all your data in an event object. Then when you need to pass new data you can extend the event object and all your objects will then have access to the new data.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!