コード例 #1
0
ファイル: ofxMuiButton.cpp プロジェクト: mark-hoo/ofxMui
//--------------------------------------------------------------
void ofxMuiButton::draw()
{
    
    ofPushStyle();
	ofPushMatrix(); // initial push
    
    ofTranslate(getHitBoxPosition());

    //--------- DRAW THE BUTTON BACKGROUND
    // default
    ofFill();
    ofSetColor(cActiveAreaBackground.get(isTouchOver(),isTouchDown(),isEnabled(),alphaScale));
    if(roundFrame) {
        // assuming that the icon is square ...
        ofCircle(getHitBoxWidth()/2, getHitBoxHeight()/2, getHitBoxWidth()/2);
    } else {
        ofxRect(0, 0, getHitBoxWidth(), getHitBoxHeight());
    }
    
    ofNoFill();
    ofSetColor(cActiveAreaForeground.get(isTouchOver(),isTouchDown(),isEnabled(),alphaScale));

    if(useIcon) {
        int iconWidth = icon->getIcon(getValue())->getWidth();
        int iconHeight = icon->getIcon(getValue())->getHeight();;
        int hitWidth = getHitBoxWidth();
        int hitHeight = getHitBoxHeight();
        int xlateX = 0;
        int xlateY = 0;
        
        // center the icon
        ofPushMatrix();
        
        if(iconWidth < hitWidth) {
            int diffX = hitWidth - iconWidth;
            xlateX = diffX/2;
        } else {
            int diffX = iconWidth - hitWidth;
            xlateX = -diffX/2;
        }
        
        if(iconHeight < hitHeight) {
            int diffY = hitHeight - iconHeight;
            xlateY = diffY/2;
        } else {
            int diffY = iconHeight - hitHeight;
            xlateY = -diffY/2;
        }
        
        ofTranslate(xlateX, xlateY);
        icon->getIcon(getValue())->draw(0,0);   

        ofPopMatrix();
        
        
    } else {
        ofFill();
        ofxRect(0, 0, getHitBoxWidth(), getHitBoxHeight());
    }
    
    ofNoFill();
    ofSetColor(cActiveAreaFrame.get(isTouchOver(),isTouchDown(),isEnabled(),alphaScale));
    if(roundFrame) {
        // assuming that the icon is square ...
        ofCircle(getHitBoxWidth()/2, getHitBoxHeight()/2, getHitBoxWidth()/2);
    } else {
        ofxRect(0, 0, getHitBoxWidth(), getHitBoxHeight());
    }

    ofPopMatrix(); // HIT RECT PUSH
    ofPopStyle();

    
}
コード例 #2
0
//--------------------------------------------------------------
void ofxMuiKnob::draw() {

    // pre calculate colors for reuse
    ofColor activeAreaBackground = cActiveAreaBackground.get(isTouchOver(),isTouchDown(),isEnabled(),alphaScale);
    ofColor activeAreaFrame = cActiveAreaFrame.get(isTouchOver(),isTouchDown(),isEnabled(),alphaScale);
    ofColor activeForeground = cActiveAreaForeground.get(isTouchOver(),isTouchDown(),isEnabled(),alphaScale);
    ofEnableAlphaBlending();

    ofPushStyle();
    ofPushMatrix();

    ofTranslate(getHitBoxPosition());

    ofPushMatrix();
    ofTranslate(getHitBoxCenter());
    ofRotateZ(ofRadToDeg(zeroAngle));

    ofFill();
    ofSetColor(activeAreaBackground);
    ofEllipse(0,0,innerRadiusW*2.0f,innerRadiusH*2.0f);

    // draw a little arrow
    ofNoFill();
    ofPushMatrix();
    ofRotateZ(ofRadToDeg(knobAngle));
    dialArrow.setStrokeColor(activeAreaFrame);
    dialArrow.draw(0,0);
    ofPopMatrix();


    dialRangeShape.setFillColor(activeAreaBackground);
    dialRangeShape.setFilled(true);
    dialRangeShape.draw(0,0);


    dialValueShape.setFillColor(activeForeground);
    dialValueShape.setFilled(true);
    dialValueShape.draw(0,0);

    dialShape.setStrokeColor(activeAreaFrame);
    dialShape.setFilled(false);
    dialShape.draw(0,0);

    ofSetColor(activeAreaFrame);
    ofNoFill();

    ofPushMatrix();
    ofRotateZ(angleValue0);
    ofLine(innerRadiusW,0,outerRadiusH,0);
    ofPopMatrix();

    ofPushMatrix();
    ofRotateZ(angleValue1);
    ofLine(innerRadiusW,0,outerRadiusH,0);
    ofPopMatrix();

    ofPushMatrix();
    ofRotateZ(angleRange1);
    ofLine(innerRadiusW,0,outerRadiusH,0);
    ofPopMatrix();

    if(getBounds().isBounded()) {
    } else {
    }


    ofDisableAlphaBlending();


    ofPopMatrix();


    ofPopMatrix();
    ofPopStyle();

}