Пример #1
0
 void CCControlSlider::setValue(float value)
 {
     //clamp between the two bounds
     value=MAX(value, m_minimumValue);
     value=MIN(value, m_maximumValue);

     //if we're snapping
     if (m_snappingInterval>=0)
     {
         //int nTotal=(int)(ceil(m_maximumValue-m_minimumValue)/m_snappingInterval);
         //floor (n + 0.5f) == round(n)
         value=floor(0.5f + value/m_snappingInterval)*m_snappingInterval;
     }
     m_value=value;

    // Update thumb position for new value
    float percent               = (m_value - m_minimumValue) / (m_maximumValue - m_minimumValue);
    CCPoint pos= m_thumbItem->getPosition();
    pos.x                       = percent * m_backgroundSprite->getContentSize().width+SLIDER_MARGIN_H;
    m_thumbItem->setPosition(pos);
    
    // Stretches content proportional to newLevel
    CCRect textureRect          = m_progressSprite->getTextureRect();
    textureRect                 = CCRectMake(textureRect.origin.x, textureRect.origin.y, percent * m_backgroundSprite->getContentSize().width, textureRect.size.height);
    m_progressSprite->setTextureRect(textureRect);
    sendActionsForControlEvents(CCControlEventValueChanged);    
 }
void CCControlSaturationBrightnessPicker::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
    // Get the touch location
    CCPoint touchLocation=getTouchLocation(touch);

    //small modification: this allows changing of the colour, even if the touch leaves the bounding area
    updateSliderPosition(touchLocation);
    sendActionsForControlEvents(CCControlEventValueChanged);
    // Check the touch position on the slider
    //checkSliderPosition(touchLocation);
}
Пример #3
0
void CCControlColourPicker::hueSliderValueChanged(CCObject * sender, CCControlEvent controlEvent)
{
    m_hsv.h      = ((CCControlHuePicker*)sender)->getHue();

    // Update the value
    RGBA rgb    = CCControlUtils::RGBfromHSV(m_hsv);
    m_colorValue= ccc3((GLubyte)(rgb.r * 255.0f), (GLubyte)(rgb.g * 255.0f), (GLubyte)(rgb.b * 255.0f));
    
    // Send CCControl callback
    sendActionsForControlEvents(CCControlEventValueChanged);
    updateControlPicker();
}
void ControlColourPicker::hueSliderValueChanged(Ref * sender, Control::EventType controlEvent)
{
    _hsv.h      = ((ControlHuePicker*)sender)->getHue();

    // Update the value
    RGBA rgb    = ControlUtils::RGBfromHSV(_hsv);
    // XXX fixed me if not correct
    Control::setColor(Color3B((GLubyte)(rgb.r * 255.0f), (GLubyte)(rgb.g * 255.0f), (GLubyte)(rgb.b * 255.0f)));
    
    // Send Control callback
    sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);
    updateControlPicker();
}
Пример #5
0
void CCControlColourPicker::colourSliderValueChanged(CCObject * sender, CCControlEvent controlEvent)
{
    m_hsv.s=((CCControlSaturationBrightnessPicker*)sender)->getSaturation();
    m_hsv.v=((CCControlSaturationBrightnessPicker*)sender)->getBrightness();


     // Update the value
    RGBA rgb    = CCControlUtils::RGBfromHSV(m_hsv);
    m_colorValue=ccc3((GLubyte)(rgb.r * 255.0f), (GLubyte)(rgb.g * 255.0f), (GLubyte)(rgb.b * 255.0f));
    
    // Send CCControl callback
    sendActionsForControlEvents(CCControlEventValueChanged);
}
void ControlColourPicker::colourSliderValueChanged(Ref * sender, Control::EventType controlEvent)
{
    _hsv.s=((ControlSaturationBrightnessPicker*)sender)->getSaturation();
    _hsv.v=((ControlSaturationBrightnessPicker*)sender)->getBrightness();


     // Update the value
    RGBA rgb    = ControlUtils::RGBfromHSV(_hsv);
    // XXX fixed me if not correct
    Control::setColor(Color3B((GLubyte)(rgb.r * 255.0f), (GLubyte)(rgb.g * 255.0f), (GLubyte)(rgb.b * 255.0f)));
    
    // Send Control callback
    sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);
}
void CCControlSwitch::setOn(bool isOn, bool animated)
{
    m_bOn     = isOn;

    m_pSwitchSprite->runAction
    (
        CCActionTween::create
        (
            0.2f,
            "sliderXPosition",
            m_pSwitchSprite->getSliderXPosition(),
            (m_bOn) ? m_pSwitchSprite->getOnPosition() : m_pSwitchSprite->getOffPosition()
        )
    );

    sendActionsForControlEvents(CCControlEventValueChanged);
}
void CCControlPotentiometer::setValue(float value)
{
    // set new value with sentinel
    if (value < m_fMinimumValue)
    {
        value                   = m_fMinimumValue;
    }
	
    if (value > m_fMaximumValue) 
    {
        value                   = m_fMaximumValue;
    }
    
    m_fValue                      = value;
    
    // Update thumb and progress position for new value
    float percent               = (value - m_fMinimumValue) / (m_fMaximumValue - m_fMinimumValue);
    m_pProgressTimer->setPercentage(percent * 100.0f);
    m_pThumbSprite->setRotation(percent * 360.0f);
    
    sendActionsForControlEvents(CCControlEventValueChanged);    
}
bool ControlSaturationBrightnessPicker::checkSliderPosition(Vec2 location)
{
    // Clamp the position of the icon within the circle
    
    // get the center point of the bkgd image
    float centerX           = _startPos.x + _background->getBoundingBox().size.width*0.5f;
    float centerY           = _startPos.y + _background->getBoundingBox().size.height*0.5f;
    
    // work out the distance difference between the location and center
    float dx                = location.x - centerX;
    float dy                = location.y - centerY;
    float dist              = sqrtf(dx*dx+dy*dy);
    
    // check that the touch location is within the bounding rectangle before sending updates
    if (dist <= _background->getBoundingBox().size.width*0.5f)
    {
        updateSliderPosition(location);
        sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);
        return true;
    }
    return false;
}
Пример #10
0
void ControlPotentiometer::setValue(float value)
{
    // set new value with sentinel
    if (value < _minimumValue)
    {
        value                   = _minimumValue;
    }
	
    if (value > _maximumValue) 
    {
        value                   = _maximumValue;
    }
    
    _value                      = value;
    
    // Update thumb and progress position for new value
    float percent               = (value - _minimumValue) / (_maximumValue - _minimumValue);
    _progressTimer->setPercentage(percent * 100.0f);
    _thumbSprite->setRotation(percent * 360.0f);
    
    sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);    
}
Пример #11
0
void ControlSwitch::setOn(bool isOn, bool animated)
{
    _on     = isOn;
    
    if (animated) {
        _switchSprite->runAction
        (
            ActionTween::create
                (
                    0.2f,
                    "sliderXPosition",
                    _switchSprite->getSliderXPosition(),
                    (_on) ? _switchSprite->getOnPosition() : _switchSprite->getOffPosition()
                )
         );
    }
    else {
        _switchSprite->setSliderXPosition((_on) ? _switchSprite->getOnPosition() : _switchSprite->getOffPosition());
    }
    
    sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);
}
bool CCControlSaturationBrightnessPicker::checkSliderPosition(CCPoint location)
{
    // Clamp the position of the icon within the circle

    // get the center point of the bkgd image
    float centerX           = m_startPos.x + m_background->boundingBox().size.width*.5;
    float centerY           = m_startPos.y + m_background->boundingBox().size.height*.5;

    // work out the distance difference between the location and center
    float dx                = location.x - centerX;
    float dy                = location.y - centerY;
    float dist              = sqrtf(dx*dx+dy*dy);

    // check that the touch location is within the bounding rectangle before sending updates
    if (dist <= m_background->boundingBox().size.width*.5)
    {
        updateSliderPosition(location);
        sendActionsForControlEvents(CCControlEventValueChanged);
        return true;
    }
    return false;
}
Пример #13
0
void ControlHuePicker::updateSliderPosition(Vector2 location)
{

    // Clamp the position of the icon within the circle
    Rect backgroundBox=_background->getBoundingBox();
    
    // Get the center point of the background image
    float centerX           = _startPos.x + backgroundBox.size.width * 0.5f;
    float centerY           = _startPos.y + backgroundBox.size.height * 0.5f;

    // Work out the distance difference between the location and center
    float dx                = location.x - centerX;
    float dy                = location.y - centerY;
    
    // Update angle by using the direction of the location
    float angle             = atan2f(dy, dx);
    float angleDeg          = CC_RADIANS_TO_DEGREES(angle) + 180.0f;
    
    // use the position / slider width to determin the percentage the dragger is at
    setHue(angleDeg);
    
    // send Control callback
    sendActionsForControlEvents(Control::EventType::VALUE_CHANGED);
}