Skip to content

Commit

Permalink
Merge pull request gameplay3d#1691 from seanpaultaylor/next
Browse files Browse the repository at this point in the history
Added Node::setUserObject(Ref* obj) and other fixes.
  • Loading branch information
seanpaultaylor committed Jan 23, 2015
2 parents 390d6a9 + fe9892b commit 1309fe4
Show file tree
Hide file tree
Showing 20 changed files with 741 additions and 503 deletions.
28 changes: 3 additions & 25 deletions gameplay/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ Control::AutoSize Control::parseAutoSize(const char* str)
{
if (str == NULL)
return _autoSize;

if (strcmpnocase(str, "AUTO_SIZE_WIDTH") == 0 )
return AUTO_SIZE_WIDTH;
if (strcmpnocase(str, "AUTO_SIZE_HEIGHT") == 0)
return AUTO_SIZE_HEIGHT;
if (strcmpnocase(str, "AUTO_SIZE_BOTH") == 0)
return AUTO_SIZE_BOTH;

return _autoSize;
}

Expand All @@ -69,8 +67,7 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
// The passed in style is our parent control's style : attempt to load our style from it.
_style = style->getTheme()->getStyle(styleName);
}

if (!_style)
else
{
// Use an empty style from our parent's theme
_style = style->getTheme()->getEmptyStyle();
Expand All @@ -86,17 +83,14 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
{
// Search for a style from the default theme that matches this control's name
_style = Theme::getDefault()->getStyle(typeName);

if (!_style)
{
// No style was found, use an empty style
_style = style ? style->getTheme()->getEmptyStyle() : Theme::getDefault()->getEmptyStyle();
}
}

// Increase the reference count of the style's theme while we hold the style
_style->getTheme()->addRef();

if (properties)
{
const char* id = properties->getId();
Expand All @@ -105,11 +99,8 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*

// Properties not defined by the style.
const char* alignmentString = properties->getString("alignment");

_alignment = getAlignment(alignmentString);

_consumeInputEvents = properties->getBool("consumeInputEvents", true);

_visible = properties->getBool("visible", true);

if (properties->exists("zIndex"))
Expand All @@ -120,10 +111,8 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
{
_zIndex = -1;
}

if (properties->exists("canFocus"))
_canFocus = properties->getBool("canFocus", false);

if (properties->exists("focusIndex"))
{
_focusIndex = properties->getInt("focusIndex");
Expand All @@ -132,7 +121,6 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
{
_focusIndex = -1;
}

float bounds[2];
bool boundsBits[2];
const char* position = properties->getString("position");
Expand All @@ -154,7 +142,6 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
setY(bounds[1], boundsBits[1]);
}
}

// If there is an explicitly specified size, width or height, unset the corresponding autoSize bit
const char* size = properties->getString("size");
if (size && parseCoordPair(size, &bounds[0], &bounds[1], &boundsBits[0], &boundsBits[1]))
Expand All @@ -177,7 +164,6 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
setHeight(bounds[1], boundsBits[1]);
}
}

// Backwards Compatibility: Support deprecated autoWidth and autoHeight properties,
// which resolve to width=100% and height=100%.
if (properties->getBool("autoWidth"))
Expand Down Expand Up @@ -248,7 +234,6 @@ void Control::initialize(const char* typeName, Theme::Style* style, Properties*
setPadding(innerSpace->getFloat("top"), innerSpace->getFloat("bottom"),
innerSpace->getFloat("left"), innerSpace->getFloat("right"));
}

innerSpace = properties->getNextNamespace();
}
}
Expand Down Expand Up @@ -561,10 +546,10 @@ void Control::setEnabled(bool enabled)
if (enabled != isEnabled())
{
if (!enabled)
{
Form::controlDisabled(this);

}
_state = enabled ? NORMAL : DISABLED;

setDirty(DIRTY_STATE);
}
}
Expand All @@ -578,7 +563,6 @@ bool Control::isEnabledInHierarchy() const
{
if (!isEnabled())
return false;

if (_parent)
return _parent->isEnabledInHierarchy();

Expand All @@ -596,7 +580,6 @@ void Control::setBorder(float top, float bottom, float left, float right, unsign
if (overlays[i])
overlays[i]->setBorder(top, bottom, left, right);
}

setDirty(DIRTY_BOUNDS);
}

Expand Down Expand Up @@ -1734,7 +1717,6 @@ void Control::overrideThemedProperties(Properties* properties, unsigned char sta
{
setTextRightToLeft(properties->getBool("rightToLeft"), states);
}

if (properties->exists("opacity"))
{
setOpacity(properties->getFloat("opacity"), states);
Expand All @@ -1752,7 +1734,6 @@ void Control::setImageList(Theme::ImageList* imageList, unsigned char states)
if( overlays[i] )
overlays[i]->setImageList(imageList);
}

if (_autoSize != AUTO_SIZE_NONE)
setDirty(DIRTY_BOUNDS);
}
Expand Down Expand Up @@ -1781,7 +1762,6 @@ void Control::setSkin(Theme::Skin* skin, unsigned char states)
if( overlays[i] )
overlays[i]->setSkin(skin);
}

if (_autoSize != AUTO_SIZE_NONE)
setDirty(DIRTY_BOUNDS);
}
Expand Down Expand Up @@ -1864,8 +1844,6 @@ Control::Alignment Control::getAlignment(const char* alignment)
{
GP_ERROR("Failed to get corresponding control alignment for unsupported value '%s'.", alignment);
}

// Default.
return Control::ALIGN_TOP_LEFT;
}

Expand Down
16 changes: 8 additions & 8 deletions gameplay/src/JoystickControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ unsigned int JoystickControl::getIndex() const
return _index;
}

void setBit(bool set, int& bitSetOut, int bit)
void JoystickControl::setBoundsBit(bool set, int& bitSetOut, int bit)
{
if(set)
{
Expand All @@ -140,7 +140,7 @@ void setBit(bool set, int& bitSetOut, int bit)
void JoystickControl::setRadius(float radius, bool isPercentage)
{
_radiusCoord = radius;
setBit(isPercentage, _boundsBits, BOUNDS_RADIUS_PERCENTAGE_BIT);
setBoundsBit(isPercentage, _boundsBits, BOUNDS_RADIUS_PERCENTAGE_BIT);
updateAbsoluteSizes();
}

Expand Down Expand Up @@ -174,7 +174,7 @@ void JoystickControl::initialize(const char* typeName, Theme::Style* style, Prop
const char* radiusStr = properties->getString(radiusId);
bool isPercentage = false;
_radiusCoord = parseCoord(radiusStr, &isPercentage);
setBit(isPercentage, _boundsBits, BOUNDS_RADIUS_PERCENTAGE_BIT);
setBoundsBit(isPercentage, _boundsBits, BOUNDS_RADIUS_PERCENTAGE_BIT);
}

const char* relativeId = "relative";
Expand Down Expand Up @@ -213,17 +213,17 @@ void JoystickControl::updateAbsoluteBounds(const Vector2& offset)
void JoystickControl::setRegion(const Vector2& regionSizeIn, Vector2& regionSizeOut, int& regionBoundsBitsOut, bool isWidthPercentage, bool isHeightPercentage)
{
regionSizeOut = regionSizeIn;
setBit(isWidthPercentage, regionBoundsBitsOut, BOUNDS_WIDTH_PERCENTAGE_BIT);
setBit(isHeightPercentage, regionBoundsBitsOut, BOUNDS_HEIGHT_PERCENTAGE_BIT);
setBoundsBit(isWidthPercentage, regionBoundsBitsOut, BOUNDS_WIDTH_PERCENTAGE_BIT);
setBoundsBit(isHeightPercentage, regionBoundsBitsOut, BOUNDS_HEIGHT_PERCENTAGE_BIT);
}

void JoystickControl::getRegion(Vector2& regionOut, int & regionBoundsBitsOut, const char* regionPropertyId) const
void JoystickControl::getRegion(Vector2& regionOut, int& regionBoundsBitsOut, const char* regionPropertyId)
{
bool isWidthPercent = false;
bool isHeightPercent = false;
parseCoordPair(regionPropertyId, &regionOut.x, &regionOut.y, &isWidthPercent, &isHeightPercent);
setBit(isWidthPercent, regionBoundsBitsOut, BOUNDS_WIDTH_PERCENTAGE_BIT);
setBit(isHeightPercent, regionBoundsBitsOut, BOUNDS_HEIGHT_PERCENTAGE_BIT);
setBoundsBit(isWidthPercent, regionBoundsBitsOut, BOUNDS_WIDTH_PERCENTAGE_BIT);
setBoundsBit(isHeightPercent, regionBoundsBitsOut, BOUNDS_HEIGHT_PERCENTAGE_BIT);
}

Vector2 JoystickControl::getPixelSize(const Vector2& region, const int regionBoundsBits) const
Expand Down
9 changes: 3 additions & 6 deletions gameplay/src/JoystickControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,11 @@ class JoystickControl : public Control

private:

/**
* Copy constructor.
*/
JoystickControl(const JoystickControl& copy);

void setRegion(const Vector2& regionSizeIn, Vector2& regionSizeOut, int& regionBoundsBitsOut, bool isWidthPercentage, bool isHeightPercentage);

void getRegion(Vector2& regionOut, int & regionBoundsBitsOut, const char* regionPropertyId) const;
void getRegion(Vector2& regionOut, int& regionBoundsBitsOut, const char* regionPropertyId);

Vector2 getPixelSize(const Vector2& region, const int regionBoundsBits) const;

Expand All @@ -219,17 +216,17 @@ class JoystickControl : public Control

void updateAbsoluteSizes();

void setBoundsBit(bool set, int& bitSetOut, int bit);

float _radiusCoord;
Vector2* _innerRegionCoord;
Vector2* _outerRegionCoord;
int _innerRegionCoordBoundsBits;
int _outerRegionCoordBoundsBits;

float _radiusPixels;
Vector2* _innerSizePixels;
Vector2* _outerSizePixels;
Rectangle _screenRegionPixels;

bool _relative;
Vector2 _value;
Vector2 _displacement;
Expand Down
Loading

0 comments on commit 1309fe4

Please sign in to comment.