This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
The-Powder-Toy/src/gui/interface/Checkbox.cpp
Ryan Jacobs 55a30673c4 Remove unnecessary pointer checks.
There are *no* more spacing issues. I used tabs exclusively.
Also, I made changes off of the develop branch.

Here's the Ruby regex that I used:
text.gsub!(/(( |\t)*)if ?\((.*)\) ?{?\n?( |\t)*(free ?\(|delete |delete\[\] )(.*)\)?;/, "\\1\\5\\6;")
2015-02-14 22:13:26 -08:00

107 lines
2.0 KiB
C++

#include "Checkbox.h"
using namespace ui;
Checkbox::Checkbox(ui::Point position, ui::Point size, std::string text, std::string toolTip):
Component(position, size),
text(text),
toolTip(toolTip),
checked(false),
isMouseOver(false),
actionCallback(NULL)
{
}
void Checkbox::SetText(std::string text)
{
this->text = text;
}
std::string Checkbox::GetText()
{
return text;
}
void Checkbox::SetIcon(Icon icon)
{
Appearance.icon = icon;
iconPosition.X = 16;
iconPosition.Y = 3;
}
void Checkbox::OnMouseClick(int x, int y, unsigned int button)
{
if(checked)
{
checked = false;
}
else
{
checked = true;
}
if(actionCallback)
actionCallback->ActionCallback(this);
}
void Checkbox::OnMouseUp(int x, int y, unsigned int button)
{
}
void Checkbox::OnMouseEnter(int x, int y)
{
isMouseOver = true;
}
void Checkbox::OnMouseHover(int x, int y)
{
if(toolTip.length()>0 && GetParentWindow())
{
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip);
}
}
void Checkbox::OnMouseLeave(int x, int y)
{
isMouseOver = false;
}
void Checkbox::Draw(const Point& screenPos)
{
Graphics * g = Engine::Ref().g;
if(checked)
{
g->fillrect(screenPos.X+5, screenPos.Y+5, 6, 6, 255, 255, 255, 255);
}
if(isMouseOver)
{
g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 255);
g->fillrect(screenPos.X+5, screenPos.Y+5, 6, 6, 255, 255, 255, 170);
if (!Appearance.icon)
g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 255);
else
g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 255);
}
else
{
g->drawrect(screenPos.X+2, screenPos.Y+2, 12, 12, 255, 255, 255, 200);
if (!Appearance.icon)
g->drawtext(screenPos.X+18, screenPos.Y+4, text, 255, 255, 255, 200);
else
g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon, 200);
}
}
void Checkbox::SetActionCallback(CheckboxAction * action)
{
delete actionCallback;
actionCallback = action;
}
Checkbox::~Checkbox() {
delete actionCallback;
}