If you have comments or questions concerning this source file, discuss them in the forum.
/*
Copyright (c) 2002 Nicolai Haehnle
See the license.txt for details. If that file was not included in the
source distributions, please email <prefect@rtts.org>
*/
// gui_checkbox.cpp
#include "library.h"
#include "hal.h"
#include "gui_checkbox.h"
/*
==============
GCheckBox::GCheckBox
Initialize the checkbox in off-state
==============
*/
GCheckBox::GCheckBox(GPanel *pParent, int x, int y, int w, int h, const char *szText,
int iAlign, int id)
: GButton(pParent, x, y, w, h, szText, iAlign, id)
{
m_bOn = false;
Clicked.Connect(this, &GCheckBox::Toggle);
}
GCheckBox::GCheckBox(GPanel *pParent, const char *szPic, int type, u32 colorkey,
int x, int y, int w, int h, int id)
: GButton(pParent, szPic, type, colorkey, x, y, w, h, id)
{
m_bOn = false;
Clicked.Connect(this, &GCheckBox::Toggle);
}
/*
==============
GCheckBox::SetOn
Emit OnChanged signal if appropriate
==============
*/
void GCheckBox::SetOn(bool on)
{
if (m_bOn == on)
return;
m_bOn = on;
OnChanged.Emit(on);
}
/*
==============
GCheckBox::Toggle
Toggle the on state and emit the OnChanged signal
==============
*/
void GCheckBox::Toggle(int dummy)
{
m_bOn = !m_bOn;
OnChanged.Emit(m_bOn);
}
/*
==============
GCheckBox::GetIconSize
Return the size of the small icon next to the text
==============
*/
void GCheckBox::GetIconSize(int *pw, int *ph)
{
*pw = 11;
*ph = 11;
}
/*
==============
GCheckBox::DrawIcon
Actually draw the icon
==============
*/
void GCheckBox::DrawIcon(int x, int y, int r, int g, int b, int a)
{
hal->DrawLine(x-5, y-5, x+5, y-5, r, g, b, a);
hal->DrawLine(x+5, y-5, x+5, y+5, r, g, b, a);
hal->DrawLine(x+5, y+5, x-5, y+5, r, g, b, a);
hal->DrawLine(x-5, y+5, x-5, y-5, r, g, b, a);
if (m_bOn)
hal->FillRect(x-3, y-3, 7, 7, r, g, b, a);
}