I have a Button class that can either display an image or a line of text, which I am trying to use a template implement.
If it's text, then the template type is: const char*
If its an image, then the template type is: const wchar_t*
Here is the method that needs to differentiate between the two types:
template <typename T>
void Button<T>::draw(EasyGraphics* canvas)
{
canvas->setBackColour(colour);
if (mouseOver)
{
canvas->setPenColour(EasyGraphics::BLACK, 4);
}
else
{
canvas->setPenColour(EasyGraphics::BLACK, 2);
}
canvas->drawRectangle(Entity::GetX(), Entity::GetY(), Entity::getWidth(), Entity::getHeight(), true);
canvas->setFont(20, L"");
canvas->setTextColour(textColour);
switch (typeid(T))
{
// Button has display text
case typeid(const char*):
{
canvas->drawText(displayData, Entity::GetX() + textXOfset, Entity::GetY() + (Entity::getHeight() / 4) - 3);
break;
}
// Button has display image
case typeid(const wchar_t*):
{
canvas->drawBitmap(displayData, Entity::GetX() + textXOfset, Entity::GetY() + (Entity::getHeight() / 4) - 3, 60, 60, 0x0000FF00);
break;
}
}
}
I cannot seem to get the switch at the bottom to function correctly. I am not sure if a switch is the best way to go about it. Any advice would be appreciated, cheers.