void UIWidget::updateState(Fw::WidgetState state) { if(m_destroyed) return; bool newStatus = true; bool oldStatus = hasState(state); bool updateChildren = false; switch(state) { case Fw::ActiveState: { UIWidgetPtr widget = static_self_cast<UIWidget>(); UIWidgetPtr parent; do { parent = widget->getParent(); if(!widget->isExplicitlyEnabled() || ((parent && parent->getFocusedChild() != widget))) { newStatus = false; break; } } while((widget = parent)); updateChildren = newStatus != oldStatus; break; } case Fw::FocusState: { newStatus = (getParent() && getParent()->getFocusedChild() == static_self_cast<UIWidget>()); break; } case Fw::HoverState: { newStatus = (g_ui.getHoveredWidget() == static_self_cast<UIWidget>() && isEnabled()); break; } case Fw::PressedState: { newStatus = (g_ui.getPressedWidget() == static_self_cast<UIWidget>()); break; } case Fw::DraggingState: { newStatus = (g_ui.getDraggingWidget() == static_self_cast<UIWidget>()); break; } case Fw::DisabledState: { bool enabled = true; UIWidgetPtr widget = static_self_cast<UIWidget>(); do { if(!widget->isExplicitlyEnabled()) { enabled = false; break; } } while((widget = widget->getParent())); newStatus = !enabled; updateChildren = newStatus != oldStatus; break; } case Fw::FirstState: { newStatus = (getParent() && getParent()->getFirstChild() == static_self_cast<UIWidget>()); break; } case Fw::MiddleState: { newStatus = (getParent() && getParent()->getFirstChild() != static_self_cast<UIWidget>() && getParent()->getLastChild() != static_self_cast<UIWidget>()); break; } case Fw::LastState: { newStatus = (getParent() && getParent()->getLastChild() == static_self_cast<UIWidget>()); break; } case Fw::AlternateState: { newStatus = (getParent() && (getParent()->getChildIndex(static_self_cast<UIWidget>()) % 2) == 1); break; } case Fw::HiddenState: { bool visible = true; UIWidgetPtr widget = static_self_cast<UIWidget>(); do { if(!widget->isExplicitlyVisible()) { visible = false; break; } } while((widget = widget->getParent())); newStatus = !visible; updateChildren = newStatus != oldStatus; break; } default: return; } if(updateChildren) { // do a backup of children list, because it may change while looping it UIWidgetList children = m_children; for(const UIWidgetPtr& child : children) child->updateState(state); } if(setState(state, newStatus)) { // disabled widgets cannot have hover state if(state == Fw::DisabledState && !newStatus && isHovered()) { g_ui.updateHoveredWidget(); } else if(state == Fw::HiddenState) { onVisibilityChange(!newStatus); } } }
bool RenderThemeApollo::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) { RefPtr<Image> image = Image::loadPlatformResource( "htmlButtonStates" ); IntSize stateOffset( 0, 0 ); if ( !isEnabled( o ) ) { stateOffset = IntSize( 0, 66 ); } else if ( isPressed( o ) ) { stateOffset = IntSize( 0, 44 ); } else if ( isHovered( o ) ) { stateOffset = IntSize( 0, 22 ); } IntSize focusOffset = IntSize( 0, 88 ); const bool nodeIsFocused = isFocused( o ); IntRect destRect( 0, 0, 0, 0 ); IntRect srcRect( 0, 0, 0, 0 ); IntRect focusRingSrcRect( 0, 0, 0, 0 ); int cornerDestWidth = 6; int cornerDestHeight = 5; // top left srcRect = IntRect( 0, 0, 6, 5 ); destRect = IntRect( r.x(), r.y(), cornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // top right srcRect = IntRect( 18, 0, 6, 5 ); destRect = IntRect( r.x() + (r.width() - cornerDestWidth), r.y(), cornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // bottom left srcRect = IntRect( 0, 17, 6, 5 ); destRect = IntRect( r.x(), r.y() + (r.height() - cornerDestHeight), cornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // bottom right srcRect = IntRect( 18, 17, 6, 5 ); destRect = IntRect( r.x() + (r.width() - cornerDestWidth), r.y() + (r.height() - cornerDestHeight), cornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // top edge srcRect = IntRect( 7, 0, 8, 5 ); destRect = IntRect( r.x() + cornerDestWidth, r.y(), (r.width() - (2 * cornerDestWidth)), cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // bottom edge srcRect = IntRect( 7, 17, 8, 5 ); destRect = IntRect( r.x() + cornerDestWidth, r.y() + (r.height() - cornerDestHeight), (r.width() - (2 * cornerDestWidth)), cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // left edge srcRect = IntRect( 0, 6, 6, 8 ); destRect = IntRect( r.x(), r.y() + cornerDestHeight, cornerDestWidth, (r.height() - (2 * cornerDestHeight)) ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // right edge srcRect = IntRect( 18, 6, 6, 8 ); destRect = IntRect( r.x() + (r.width() - cornerDestWidth), r.y() + cornerDestHeight , cornerDestWidth, (r.height() - (2 * cornerDestHeight)) ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) i.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // center srcRect = IntRect( 7, 6, 8, 8 ); destRect = IntRect( r.x() + cornerDestWidth, r.y() + cornerDestHeight , r.width() - (2 * cornerDestWidth), (r.height() - (2 * cornerDestHeight)) ); srcRect.move( stateOffset ); i.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); return false; }
bool RenderThemeApollo::paintMenuListButton(RenderObject * o, const RenderObject::PaintInfo& paintInfo, const IntRect& r) { paintInfo.context->save(); #if 0 // old "move-to" "line-to" code paintInfo.context->setStrokeThickness(1); paintInfo.context->setStrokeStyle(SolidStroke); IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(), r.y() + o->style()->borderTopWidth(), r.width() - o->style()->borderLeftWidth() - o->style()->borderRightWidth(), r.height() - o->style()->borderTopWidth() - o->style()->borderBottomWidth()); float fontScale = o->style()->fontSize() / baseFontSize; float centerY = bounds.y() + bounds.height() / 2.0; float arrowHeight = baseArrowHeight * fontScale; float arrowWidth = baseArrowWidth * fontScale; float leftEdge = bounds.right() - arrowPaddingRight - arrowWidth; float spaceBetweenArrows = baseSpaceBetweenArrows * fontScale; Color buttonColor = o->style()->color(); if ( o->node()->hovered() ) { buttonColor = Color( 0xff, 0xb5, 0x31 ); } paintInfo.context->setFillColor(buttonColor); paintInfo.context->setStrokeColor(buttonColor); FloatPoint arrow1[3]; arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0); arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0); arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0, centerY - spaceBetweenArrows / 2.0 - arrowHeight); // Draw the top arrow paintInfo.context->drawConvexPolygon(3, arrow1, true); FloatPoint arrow2[3]; arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0); arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0); arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0, centerY + spaceBetweenArrows / 2.0 + arrowHeight); // Draw the bottom arrow paintInfo.context->drawConvexPolygon(3, arrow2, true); Color leftSeparatorColor(0, 0, 0, 40); Color rightSeparatorColor(255, 255, 255, 40); int separatorSpace = 2; int leftEdgeOfSeparator = static_cast<int>(leftEdge - arrowPaddingLeft); // FIXME: Round? // Draw the separator to the left of the arrows paintInfo.context->setStrokeColor(leftSeparatorColor); paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator, bounds.y()), IntPoint(leftEdgeOfSeparator, bounds.bottom())); paintInfo.context->setStrokeColor(rightSeparatorColor); paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()), IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.bottom())); // Debug // paintInfo.context->fillRect( r, Color( 0xff, 0x00, 0xff ) ); #endif RefPtr<Image> image = Image::loadPlatformResource( "popupStates" ); IntSize stateOffset( 0, 0 ); if ( !isEnabled( o ) ) { stateOffset = IntSize( 0, 66 ); } else if ( isPressed( o ) ) { stateOffset = IntSize( 0, 44 ); } else if ( isHovered( o ) ) { stateOffset = IntSize( 0, 22 ); } IntSize focusOffset = IntSize( 0, 88 ); const bool nodeIsFocused = isFocused( o ); IntRect destRect( 0, 0, 0, 0 ); IntRect srcRect( 0, 0, 0, 0 ); IntRect focusRingSrcRect( 0, 0, 0, 0 ); int leftSideCornerDestWidth = 5; int rightSideCornerDestWidth = 22; int cornerDestHeight = 4; // top left srcRect = IntRect( 0, 0, 5, 4 ); destRect = IntRect( r.x(), r.y(), leftSideCornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // top right srcRect = IntRect( 22, 0, 22, 4 ); destRect = IntRect( r.x() + (r.width() - rightSideCornerDestWidth), r.y(), rightSideCornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // bottom left srcRect = IntRect( 0, 18, 5, 4 ); destRect = IntRect( r.x(), r.y() + (r.height() - cornerDestHeight), leftSideCornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // bottom right srcRect = IntRect( 22, 18, 22, 4 ); destRect = IntRect( r.x() + (r.width() - rightSideCornerDestWidth), r.y() + (r.height() - cornerDestHeight), rightSideCornerDestWidth, cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // top edge srcRect = IntRect( 6, 0, 14, 4 ); destRect = IntRect( r.x() + leftSideCornerDestWidth, r.y(), (r.width() - (leftSideCornerDestWidth + rightSideCornerDestWidth)), cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // bottom edge srcRect = IntRect( 6, 18, 14, 4 ); destRect = IntRect( r.x() + leftSideCornerDestWidth, r.y() + (r.height() - cornerDestHeight), (r.width() - (leftSideCornerDestWidth + rightSideCornerDestWidth)), cornerDestHeight ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // left edge srcRect = IntRect( 0, 6, 5, 11 ); destRect = IntRect( r.x(), r.y() + cornerDestHeight , leftSideCornerDestWidth, (r.height() - (2 * cornerDestHeight)) ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // right edge srcRect = IntRect( 22, 6, 22, 11 ); focusRingSrcRect = getFocusRingSrcRect( srcRect, focusOffset ); destRect = IntRect( r.x() + (r.width() - rightSideCornerDestWidth), r.y() + cornerDestHeight , rightSideCornerDestWidth, (r.height() - (2 * cornerDestHeight)) ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); if ( nodeIsFocused ) paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, focusRingSrcRect ); // center srcRect = IntRect( 6, 6, 11, 11 ); destRect = IntRect( r.x() + leftSideCornerDestWidth, r.y() + cornerDestHeight , r.width() - (leftSideCornerDestWidth + rightSideCornerDestWidth), (r.height() - (2 * cornerDestHeight)) ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); // down arrow srcRect = IntRect( 45, 5, 5, 12 ); destRect = IntRect( r.x() + (r.width() - 13), r.y() + ((r.height() / 2) - ( 12/2 )), 5, 12 ); srcRect.move( stateOffset ); paintInfo.context->drawImage( image.get(), DeviceColorSpace, destRect, srcRect ); paintInfo.context->restore(); return true; }
void Dropdown::draw(void) { ofSetColor(colors["edge"]); ofRect(boundingBox); if (isEnabled()) { ofSetColor(colors["background"]); } else { ofSetColor(colors["disabled"]); } ofRect(boundingBox.x + edgeWidth, boundingBox.y + edgeWidth, boundingBox.width - (edgeWidth * 2), boundingBox.height - (edgeWidth * 2)); if (isActive()) { ofSetColor(colors["edge"]); ofRect(_dropdownBoxPosition); ofSetColor(colors["background"]); ofRect(_dropdownBoxPosition.x + edgeWidth, _dropdownBoxPosition.y + edgeWidth, _dropdownBoxPosition.width - (edgeWidth * 2), _dropdownBoxPosition.height - (edgeWidth * 2) ); //Draw the highlight. if (_highlightedSelectionIndex != NOTHING_SELECTED) { ofSetColor(colors["hovered"]); ofRect(_dropdownBoxPosition.x + edgeWidth, _dropdownBoxPosition.y + edgeWidth + (_highlightedSelectionIndex * _selectionLineHeight), _dropdownBoxPosition.width - (edgeWidth * 2), _selectionLineHeight ); } //Draw each selection in the dropdown ofSetColor(colors["text"]); for (int i = 0; i < _selectionOptions.size(); ++i) { this->drawString(_selectionOptions.at(i).label, _dropdownBoxPosition.x + edgeWidth + TEXT_HORIZ_SPACING, _dropdownBoxPosition.y + ((i + 1) * _selectionLineHeight) ); } } else { //Draw the text that is shown in the dropdown box. ofSetColor(colors["text"]); this->drawString(_displayedText, boundingBox.x + edgeWidth + TEXT_HORIZ_SPACING, boundingBox.y + _selectionLineHeight*.8 ); } ofSetColor(colors["edge"]); ofRect(_dropdownArrowPosition); if (isHovered()) { ofSetColor(colors["hovered"]); } else { ofSetColor(colors["edge"]); } ofRect(_dropdownArrowPosition.x + edgeWidth, _dropdownArrowPosition.y + edgeWidth, _dropdownArrowPosition.width - (2 * edgeWidth), _dropdownArrowPosition.height - (2 * edgeWidth)); ofSetLineWidth(1); ofSetColor(colors["background"]); ofPoint arrowCenter = _dropdownArrowPosition.getCenter(); ofLine(arrowCenter.x, arrowCenter.y + 2, arrowCenter.x - 5, arrowCenter.y - 3); ofLine(arrowCenter.x, arrowCenter.y + 2, arrowCenter.x + 5, arrowCenter.y - 3); }