本文整理汇总了C++中CAScale9ImageView::setPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CAScale9ImageView::setPreferredSize方法的具体用法?C++ CAScale9ImageView::setPreferredSize怎么用?C++ CAScale9ImageView::setPreferredSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAScale9ImageView
的用法示例。
在下文中一共展示了CAScale9ImageView::setPreferredSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setIndicator
void CAIndicator::setIndicator(const CCSize& parentSize, const CCRect& childrenFrame)
{
if ( !this->isVisible())
return;
CAScale9ImageView* indicator = dynamic_cast<CAScale9ImageView*>(m_pIndicator);
if (m_eType == CAIndicatorTypeHorizontal)
{
float size_scale_x = parentSize.width / childrenFrame.size.width;
size_scale_x = MIN(size_scale_x, 1.0f);
float lenght_scale_x = parentSize.width / 2 - childrenFrame.origin.x;
lenght_scale_x /= childrenFrame.size.width;
CCSize size = m_obContentSize;
size.width *= size_scale_x;
if (lenght_scale_x < size_scale_x / 2)
{
size.width *= lenght_scale_x / (size_scale_x / 2);
}
if (1 - lenght_scale_x < size_scale_x / 2)
{
size.width *= (1 - lenght_scale_x) / (size_scale_x / 2);
}
size.width = MAX(size.height, size.width);
if (!indicator->getPreferredSize().equals(size))
{
indicator->setPreferredSize(size);
}
CCPoint point = m_obContentSize;
point.y *= 0.5f;
point.x *= lenght_scale_x;
point.x = MAX(point.x, size.width/2);
point.x = MIN(point.x, m_obContentSize.width - size.width/2);
indicator->setCenterOrigin(point);
}
else if (m_eType == CAIndicatorTypeVertical)
{
float size_scale_y = parentSize.height / childrenFrame.size.height;
size_scale_y = MIN(size_scale_y, 1.0f);
float lenght_scale_y = parentSize.height / 2 - childrenFrame.origin.y;
lenght_scale_y /= childrenFrame.size.height;
CCSize size = m_obContentSize;
size.height *= size_scale_y;
if (lenght_scale_y < size_scale_y / 2)
{
size.height *= lenght_scale_y / (size_scale_y / 2);
}
if (1 - lenght_scale_y < size_scale_y / 2)
{
size.height *= (1 - lenght_scale_y) / (size_scale_y / 2);
}
size.height = MAX(size.height, size.width);
if (!indicator->getPreferredSize().equals(size))
{
indicator->setPreferredSize(size);
}
CCPoint point = m_obContentSize;
point.x *= 0.5f;
point.y *= lenght_scale_y;
point.y = MAX(point.y, size.height/2);
point.y = MIN(point.y, m_obContentSize.height - size.height/2);
indicator->setCenterOrigin(point);
}
}