|
|
@@ -22,27 +22,13 @@ CheckBox::~CheckBox()
|
|
|
|
|
|
CheckBox* CheckBox::create(Theme::Style* style, Properties* properties)
|
|
|
{
|
|
|
- CheckBox* checkbox = new CheckBox();
|
|
|
- checkbox->_style = style;
|
|
|
- properties->getVector2("position", &checkbox->_position);
|
|
|
- properties->getVector2("size", &checkbox->_size);
|
|
|
- checkbox->_checked = properties->getBool("checked");
|
|
|
-
|
|
|
- const char* id = properties->getId();
|
|
|
- if (id)
|
|
|
- {
|
|
|
- checkbox->_id = id;
|
|
|
- }
|
|
|
-
|
|
|
- const char* text = properties->getString("text");
|
|
|
- if (text)
|
|
|
- {
|
|
|
- checkbox->_text = text;
|
|
|
- }
|
|
|
-
|
|
|
- __checkBoxes.push_back(checkbox);
|
|
|
+ CheckBox* checkBox = new CheckBox();
|
|
|
+ checkBox->init(style, properties);
|
|
|
+ properties->getVector2("iconSize", &checkBox->_iconSize);
|
|
|
+ checkBox->_checked = properties->getBool("checked");
|
|
|
+ __checkBoxes.push_back(checkBox);
|
|
|
|
|
|
- return checkbox;
|
|
|
+ return checkBox;
|
|
|
}
|
|
|
|
|
|
CheckBox* CheckBox::getCheckBox(const char* id)
|
|
|
@@ -50,18 +36,28 @@ CheckBox* CheckBox::getCheckBox(const char* id)
|
|
|
std::vector<CheckBox*>::const_iterator it;
|
|
|
for (it = __checkBoxes.begin(); it < __checkBoxes.end(); it++)
|
|
|
{
|
|
|
- CheckBox* checkbox = *it;
|
|
|
- if (strcmp(id, checkbox->getID()) == 0)
|
|
|
+ CheckBox* checkBox = *it;
|
|
|
+ if (strcmp(id, checkBox->getID()) == 0)
|
|
|
{
|
|
|
- return checkbox;
|
|
|
+ return checkBox;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-void CheckBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
|
|
|
+bool CheckBox::isChecked()
|
|
|
{
|
|
|
+ return _checked;
|
|
|
+}
|
|
|
+
|
|
|
+bool CheckBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
|
|
|
+{
|
|
|
+ if (!isEnabled())
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
switch (evt)
|
|
|
{
|
|
|
case Touch::TOUCH_RELEASE:
|
|
|
@@ -78,7 +74,35 @@ void CheckBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int cont
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- Button::touchEvent(evt, x, y, contactIndex);
|
|
|
+ return Button::touchEvent(evt, x, y, contactIndex);
|
|
|
+}
|
|
|
+
|
|
|
+void CheckBox::update(const Vector2& position)
|
|
|
+{
|
|
|
+ Theme::Style::Overlay* overlay = _style->getOverlay(getOverlayType());
|
|
|
+ Theme::Icon* icon = overlay->getCheckBoxIcon();
|
|
|
+ Theme::Border border;
|
|
|
+ Theme::ContainerRegion* containerRegion = overlay->getContainerRegion();
|
|
|
+ if (containerRegion)
|
|
|
+ {
|
|
|
+ border = overlay->getContainerRegion()->getBorder();
|
|
|
+ }
|
|
|
+ Theme::Padding padding = _style->getPadding();
|
|
|
+
|
|
|
+ // Set up the text viewport.
|
|
|
+ float iconWidth = 0.0f;
|
|
|
+ if (icon)
|
|
|
+ {
|
|
|
+ iconWidth = icon->getSize().x;
|
|
|
+ }
|
|
|
+
|
|
|
+ Font* font = overlay->getFont();
|
|
|
+ Vector2 pos(position.x + _position.x + border.left + padding.left + iconWidth,
|
|
|
+ position.y + _position.y + border.top + padding.top);
|
|
|
+
|
|
|
+ _viewport.set(pos.x, pos.y,
|
|
|
+ _size.x - border.left - padding.left - border.right - padding.right - iconWidth,
|
|
|
+ _size.y - border.top - padding.top - border.bottom - padding.bottom - overlay->getFontSize());
|
|
|
}
|
|
|
|
|
|
void CheckBox::drawSprites(SpriteBatch* spriteBatch, const Vector2& position)
|
|
|
@@ -97,7 +121,12 @@ void CheckBox::drawSprites(SpriteBatch* spriteBatch, const Vector2& position)
|
|
|
}
|
|
|
const Theme::Padding padding = _style->getPadding();
|
|
|
|
|
|
- const Vector2 size = icon->getSize();
|
|
|
+ Vector2& size = _iconSize;
|
|
|
+ if (_iconSize.isZero())
|
|
|
+ {
|
|
|
+ size = icon->getSize();
|
|
|
+ }
|
|
|
+
|
|
|
const Vector4 color = icon->getColor();
|
|
|
|
|
|
Vector2 pos(position.x + _position.x + border.left + padding.left,
|
|
|
@@ -120,33 +149,11 @@ void CheckBox::drawText(const Vector2& position)
|
|
|
{
|
|
|
// TODO: Batch all labels that use the same font.
|
|
|
Theme::Style::Overlay* overlay = _style->getOverlay(getOverlayType());
|
|
|
- Theme::Icon* icon = overlay->getCheckBoxIcon();
|
|
|
- Theme::Border border;
|
|
|
- Theme::ContainerRegion* containerRegion = overlay->getContainerRegion();
|
|
|
- if (containerRegion)
|
|
|
- {
|
|
|
- border = overlay->getContainerRegion()->getBorder();
|
|
|
- }
|
|
|
- Theme::Padding padding = _style->getPadding();
|
|
|
-
|
|
|
- // Set up the text viewport.
|
|
|
- float iconWidth = 0.0f;
|
|
|
- if (icon)
|
|
|
- {
|
|
|
- iconWidth = icon->getSize().x;
|
|
|
- }
|
|
|
-
|
|
|
Font* font = overlay->getFont();
|
|
|
- Vector2 pos(position.x + _position.x + border.left + padding.left + iconWidth,
|
|
|
- position.y + _position.y + border.top + padding.top);
|
|
|
-
|
|
|
- Rectangle viewport(pos.x, pos.y,
|
|
|
- _size.x - border.left - padding.left - border.right - padding.right - iconWidth,
|
|
|
- _size.y - border.top - padding.top - border.bottom - padding.bottom - font->getSize());
|
|
|
|
|
|
// Draw the text.
|
|
|
font->begin();
|
|
|
- font->drawText(_text.c_str(), viewport, overlay->getTextColor(), overlay->getFontSize(), overlay->getTextAlignment(), true, overlay->getTextRightToLeft());
|
|
|
+ font->drawText(_text.c_str(), _viewport, overlay->getTextColor(), overlay->getFontSize(), overlay->getTextAlignment(), true, overlay->getTextRightToLeft());
|
|
|
font->end();
|
|
|
|
|
|
_dirty = false;
|