//-------------------------------------------------------------- void ofxMuiKnob::doContentBoxLayout() { // TODO: handle the case where the label is EMPTY // vertical ofxMuiLabelCaps if(label->getHeight() > getHitBoxHeight()) { setContentBoxHeight(label->getHeight()); setHitBoxY((label->getHeight() - getHitBoxHeight())/2.0); label->setY(0); } else { setContentBoxHeight(getHitBoxHeight()); label->setY((getHitBoxHeight() - label->getHeight())/2.0); setHitBoxY(0); } // label to the right label->setX(getHitBoxWidth()); // label to the right setHitBoxX(0); // value label placement valueLabel->setX(getHitBoxX()); valueLabel->setY(getHitBoxY() + (getHitBoxHeight() - valueLabel->getHeight())/2.0); // TODO: this doesn't account for auto widths ... setContentBoxWidth(getHitBoxWidth() + label->getWidth()); }
//-------------------------------------------------------------- void ofxMuiButton::doContentBoxLayout() { //cout << "0: ofxMuiButton::doContentBoxLayout=>" << endl << boxToString() << endl; /* // TODO: handle the case where the label is EMPTY // vertical ofxMuiLabelCaps if(label->getHeight() > getHitBoxHeight()) { setContentBoxHeight(label->getHeight()); setHitBoxY((label->getHeight() - getHitBoxHeight()) / 2.0f); label->setY(0); } else { setContentBoxHeight(getHitBoxHeight()); label->setY((getHitBoxHeight() - label->getHeight()) / 2.0f); setHitBoxY(0); } // label to the right label->setX(getHitBoxWidth()); // label to the right */ // setHitBoxX(0); // TODO: this doesn't account for auto widths ... setContentBoxHeight(getHitBoxHeight()); setContentBoxWidth(getHitBoxWidth());// + label->getWidth()); //cout << "1: ofxMuiButton::doContentBoxLayout=>" << endl << boxToString() << endl; }
//-------------------------------------------------------------- void ofxMuiKnob::onPress() { registerMousePosition(mousePosition); float nv = getNormalizedKnobPosition(); if(getBounds().isBounded()) { if(isRangeEnabled() && isShiftPressed()) { if(isCtrlPressed()) { setRightOrLeftRangeLimit(nv); } else { setClosestRangeLimit(nv); } } else if(isRangeEnabled() && isCtrlPressed()) { normCtrlDragStartMin = getNormalizedRangeMin(); normCtrlDragStartMax = getNormalizedRangeMax(); } else { setNormalizedValue(nv); } } else { //setNormalizedValue(nv); ofVec2f v = screenToHitBox(mousePosition); float d = v.distance(getHitBoxCenter()); float ds = ofNormalize(d,0,getHitBoxWidth()*2.0f) * 10.0f; add(ds*dKnobScaler*dKnobAngle); } }
//-------------------------------------------------------------- void ofxMuiWindow::doContentBoxLayout() { cout << "doing content box layout " << endl; int currentX = 0; int currentY = 0; int maxX = 0; int maxY = 0; // position the minmax/enable/disable buttons enableDisableButton->setPosition(0,0); currentX+=enableDisableButton->getWidth(); minMaxButton->setPosition(currentX,0); currentX+=minMaxButton->getWidth(); // position the label // TODO: center this // int labelY = (minMaxButton->getY() + minMaxButton->getHeight()) / 2.0 -label->getHeight() / 2.0 ; // label->setPosition(currentX, labelY); // // // maxX = MAX(maxX, label->getPosition().x + label->getWidth()); // // currentY+=MAX(MAX(enableDisableButton->getHeight(), // minMaxButton->getHeight()), // label->getHeight()); // // // currentX = 0; minimizedRect.x = 0; minimizedRect.y = 0; minimizedRect.width = maxX; minimizedRect.height = currentY; if(isMinimized) { } else { for(int i = 0; i < childObjects.size(); i++) { if(childObjects[i] != enableDisableButton && childObjects[i] != minMaxButton/*&& childObjects[i] != label && childObjects[i] != valueLabel*/) { currentX = 0; childObjects[i]->setPosition(currentX,currentY); currentY += childObjects[i]->getHeight(); maxX = MAX(maxX,childObjects[i]->getWidth()); } } } setHitBox(0,0,maxX,currentY); setContentBoxWidth(getHitBoxWidth()); setContentBoxHeight(getHitBoxHeight()); }
//-------------------------------------------------------------- bool ofxMuiKnob::localHitTest(float localX, float localY) { // Normalize the coordinates compared to the ellipse // having a center at 0,0 and a radius of 0.5. // via Java Ellipse2D float ellw = getHitBoxWidth(); if (ellw <= 0.0) return false; float normx = (localX - getHitBoxX()) / ellw - 0.5f; float ellh = getHitBoxHeight(); if (ellh <= 0.0) return false; float normy = (localY - getHitBoxY()) / ellh - 0.5f; return (normx * normx + normy * normy) < 0.25f; }
//-------------------------------------------------------------- void ofxMuiWindow::draw() { ofPushStyle(); ofPushMatrix(); // initial push ofTranslate(getHitBoxPosition()); ofSetColor(255,0,255); if(isMinimized) { //ofxRect(0.0f, 0.0f, width, windowButtonHeight + 1); ofxRect(0.0f, 0.0f, minimizedRect.width,minimizedRect.height); } else { ofxRect(0.0f, 0.0f, getHitBoxWidth(), getHitBoxHeight()); } ofNoFill(); /* if(name != "") { if(isMinimized) { ofPushMatrix(); ofTranslate(mGlobals->mPadLeft,mGlobals->mPadTop); drawParamString(windowButtonWidth*2, 0, name, false); ofPopMatrix(); } else { drawHeadString(mBorder, mBorder + windowButtonHeight, name, false); } } if(mBorder > 0) { // border //glColor4f(mGlobals->mBorderColor.r, mGlobals->mBorderColor.g, mGlobals->mBorderColor.b, mGlobals->mBorderColor.a); ofSetColor(mGlobals->mBorderColor); if(isMinimized) { ofxRect(0.0f, 0.0f, minimizedRect.width,minimizedRect.height); //ofxRect(0.0f, 0.0f, width, windowButtonHeight ); } else { ofxRect(0.0f, 0.0f, width, height); } } if(isEnabled && !isMinimized) { ofxMuiObject* tmpObj; for(int i = 0; i < childObjects.size(); i++) { tmpObj = (ofxMuiObject*)childObjects.at(i); tmpObj->draw(); } } else { // minMaxButton->draw(); // enableDisableButton->draw(); } */ ofPopMatrix(); ofPopStyle(); }
//-------------------------------------------------------------- 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(); }
//-------------------------------------------------------------- int ofxMuiButton::getButtonWidth() { return getHitBoxWidth(); }
//-------------------------------------------------------------- void ofxMuiColorPicker::draw() { //if(name == "MCP") { // cout << "in here" << endl; //} ofPushStyle(); ofPushMatrix(); // initial push ofTranslate(getHitBoxX(),getHitBoxY()); ofSetColor(255); picker.draw(0,0); ofFill(); ofSetColor(getValue()); ofxRect(colorPickerPreview); ofFill(); ofSetColor(30); ofLine(colorPickerPreview.x,colorPickerPreview.y,getHitBoxWidth(),colorPickerPreview.y); ofNoFill(); if(showEyeDroperPreview) { eyeDropperPreview.loadScreenData(mousePosition.x-eyeDropperPreviewPixelWidth/2.0f, mousePosition.y-eyeDropperPreviewPixelHeight/2.0f ,eyeDropperPreviewPixelWidth,eyeDropperPreviewPixelHeight); ofPushMatrix(); ofTranslate(screenToHitBox(mousePosition)); ofSetColor(255); // ofxRect(0,0, // ofPushMatrix( ofPushMatrix(); ofScale(defaults->colorPickerEyeDropperZoom,defaults->colorPickerEyeDropperZoom); ofTranslate(-eyeDropperPreviewPixelWidth/2.0, -eyeDropperPreviewPixelHeight/2.0f); eyeDropperPreview.draw(0,0); ofPopMatrix(); ofCircle(0,0,4,4); ofPopMatrix(); } else { //ofSetColor(getValue().getInverted().getBrightness()); ofCircle(cursor.x-2, cursor.y-2, 4); } /* if(isDragging) { ofFill(); ofSetColor(255); ofxRect(0,0,40,40); } */ ofPopMatrix(); // HIT RECT PUSH ofPopStyle(); }
//-------------------------------------------------------------- float ofxMuiBox::getHitBoxHalfWidth() const { return getHitBoxWidth() * 0.5f; }