void TextField::paintComponent( const PaintEvent &paintEvent ) { int caretLoc = getCaretLocation(); int textLoc = getTextOffset(); Rectangle sideclip = getInnerRectangle(); sideclip = Rectangle(sideclip.getX() + getLeftPadding() , sideclip.getY() + 2,sideclip.getSize().getWidth() - getLeftPadding() - getRightPadding() + 1, sideclip.getHeight() - 4); if(isReadOnly()) { paintEvent.graphics()->drawFilledRectangle( getSizeRectangle(),frameColor); } else { paintEvent.graphics()->drawFilledRectangle( getSizeRectangle(),getBackColor()); } paintEvent.graphics()->pushClippingRect(sideclip); if(getSelectionStart() != getSelectionEnd() && (isFocused() || !isHidingSelection()) ) { Rectangle selRect = Rectangle( getSelectionLocation(), (getInnerHeight() / 2) - (getFont()->getLineHeight() / 2), getSelectionWidth(), getFont()->getLineHeight()); paintEvent.graphics()->drawFilledRectangle( selRect,getSelectionBackColor()); } paintEvent.graphics()->drawText(Point(textLoc, + ((getInnerSize().getHeight() - getFont()->getLineHeight()) / 2)),getText().c_str(), getFontColor(),getFont()); if(isFocused()) { if(isBlinking()) paintEvent.graphics()->drawLine(Point(caretLoc + 1, ((getInnerSize().getHeight() / 2) + (getFont()->getLineHeight() / 2))), Point(caretLoc + 1, ((getInnerSize().getHeight() / 2) - (getFont()->getLineHeight() / 2))), Color(0,0,0)); } paintEvent.graphics()->popClippingRect(); }
void HScrollBar::resizeThumb() { //the width if 1 pixel = 1 value int width = getLargeAmount(); int maxValSupport = getMaxValue() - getMinValue(); //get the ratio float change = (float)getMaxThumbSize() / (float)maxValSupport; //make height proportional to ratio width = (int)((float)width * change); //make sure the thumb never gets too small if(width < getMinThumbWidth()) { width = getMinThumbWidth(); } if(width > getMaxThumbSize()) { pChildThumb->setVisibility(false); } else if(pChildThumb->isVisible() == false) { pChildThumb->setVisibility(true); } pChildThumb->setSize(width,getInnerSize().getHeight()); }
void HScrollBar::positionArrows() { pChildLeftArrow->setLocation(0,0); pChildRightArrow->setLocation(getInnerSize().getWidth() - pChildRightArrow->getSize().getWidth(),0); }
void TabbedPane::adjustTabs() { tabContainer->setLocation(0,0); highestTab = 0; //get highest tab for(std::vector<std::pair<Tab*,Widget*> >::iterator it = tabs.begin(); it != tabs.end(); ++it) { if(it->first->getSize().getHeight() > highestTab) { highestTab = it->first->getSize().getHeight(); } } //set container size tabContainer->setSize(getInnerSize().getWidth(),highestTab); //move the tabs totalTabWidth = 0; for(std::vector<std::pair<Tab*,Widget*> >::iterator it = tabs.begin(); it != tabs.end(); ++it) { it->first->setLocation(totalTabWidth, tabContainer->getSize().getHeight() - it->first->getSize().getHeight()); totalTabWidth += it->first->getSize().getWidth() + getTabPadding(); } }
void Button::drawInternal(QPainter* p) { if (!pixmap.isNull()) { int centerX = (getInnerSize().width() - pixmap.width()) / 2; int centerY = (getInnerSize().height() - pixmap.height()) / 2; p->drawPixmap(centerX, centerY, pixmap, 0, 0, getInnerSize().width() - centerX, getInnerSize().height() - centerY); } p->save(); setFontSize(p); drawText(p, label, QPoint(0, 0), TEXTCOLOR_DEFAULT, Qt::AlignCenter); p->restore(); }
void TabbedPane::adjustWidgetContainer() { widgetContainer->setSize(getInnerSize().getWidth(), getInnerSize().getHeight() - highestTab); widgetContainer->setLocation(0,highestTab); if(isResizingTabContent() && selectedTab.second) { selectedTab.second->setSize(widgetContainer->getInnerSize()); } if(selectedTab.second) { selectedTab.second->setLocation(0,0); } }
void Button::layout(QPainter* p) { Widget::layout(p); p->save(); setFontSize(p); QRect buttonRect = p->boundingRect(QRect(QPoint(0, 0), getInnerSize()), Qt::AlignCenter, label); setSize(buttonRect.size()); p->restore(); }
sf::Vector2f ScrollablePanel::getContentSize() const { if (m_contentSize != sf::Vector2f{0, 0}) return m_contentSize; else if (m_widgets.empty()) return getInnerSize(); else return m_mostBottomRightPosition; }
void ServerInfo::layout(QPainter *p) { Widget::layout(p); int minHeight = 0; minHeight = qMax(minHeight, labelHost->getSize().height()); minHeight = qMax(minHeight, labelPort->getSize().height()); minHeight = qMax(minHeight, buttonConnect->getSize().height()); minHeight = qMax(minHeight, buttonDelete->getSize().height()); setSize(QSize(getInnerSize().width(), minHeight)); labelHost->setPos(QPoint(0, 0)); buttonDelete->setPos(QPoint(getInnerSize().width() - buttonDelete->getSize().width(), 0)); buttonConnect->setPos(QPoint(buttonDelete->getPos().x() - buttonConnect->getSize().width(), 0)); labelPort->setPos(QPoint(buttonConnect->getPos().x() - labelPort->getSize().width(), 0)); labelHost->setSize(QSize(labelHost->getSize().width(), minHeight)); labelPort->setSize(QSize(labelPort->getSize().width(), minHeight)); }
void TextField::setFont( const Font *font ) { Widget::setFont(font); if(getInnerSize().getHeight() < getFont()->getLineHeight()) { setSize(getSize().getWidth(),getFont()->getLineHeight() + getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM)); } positionCaret(getCaretPosition()); }
int TextField::getAdjustedWidth() const { int w = getInnerSize().getWidth() - getLeftPadding() - getRightPadding(); if(w > 0) { return w; } return 0; }
void ScrollablePanel::updateScrollbars() { const sf::Vector2f visibleSize = getInnerSize(); m_horizontalScrollbar.setLowValue(visibleSize.x); m_verticalScrollbar.setLowValue(visibleSize.y); const sf::Vector2f contentSize = getContentSize(); m_horizontalScrollbar.setMaximum(contentSize.x); m_verticalScrollbar.setMaximum(contentSize.y); const bool horizontalScrollbarVisible = m_horizontalScrollbar.getMaximum() > m_horizontalScrollbar.getLowValue(); if (horizontalScrollbarVisible) { m_verticalScrollbar.setSize(m_verticalScrollbar.getSize().x, getInnerSize().y - m_horizontalScrollbar.getSize().y); m_verticalScrollbar.setLowValue(m_verticalScrollbar.getLowValue() - m_horizontalScrollbar.getSize().y); const bool verticalScrollbarVisible = m_verticalScrollbar.getMaximum() > m_verticalScrollbar.getLowValue(); if (verticalScrollbarVisible) m_horizontalScrollbar.setSize(getInnerSize().x - m_verticalScrollbar.getSize().x, m_horizontalScrollbar.getSize().y); else m_horizontalScrollbar.setSize(getInnerSize().x, m_horizontalScrollbar.getSize().y); } else { m_verticalScrollbar.setSize(m_verticalScrollbar.getSize().x, getInnerSize().y); const bool verticalScrollbarVisible = m_verticalScrollbar.getMaximum() > m_verticalScrollbar.getLowValue(); if (verticalScrollbarVisible) { m_horizontalScrollbar.setSize(getInnerSize().x - m_verticalScrollbar.getSize().x, m_horizontalScrollbar.getSize().y); m_horizontalScrollbar.setLowValue(m_horizontalScrollbar.getLowValue() - m_verticalScrollbar.getSize().x); if (m_horizontalScrollbar.getMaximum() > m_horizontalScrollbar.getLowValue()) m_verticalScrollbar.setSize(m_verticalScrollbar.getSize().x, getInnerSize().y - m_horizontalScrollbar.getSize().y); } else m_horizontalScrollbar.setSize(getInnerSize().x, m_horizontalScrollbar.getSize().y); } m_verticalScrollbar.setPosition(getChildWidgetsOffset().x + getInnerSize().x - m_verticalScrollbar.getSize().x, getChildWidgetsOffset().y); m_horizontalScrollbar.setPosition(getChildWidgetsOffset().x, getChildWidgetsOffset().y + getInnerSize().y - m_horizontalScrollbar.getSize().y); m_verticalScrollbar.setScrollAmount(static_cast<unsigned int>(std::ceil((m_verticalScrollbar.getMaximum() - m_verticalScrollbar.getLowValue()) / 50.f))); m_horizontalScrollbar.setScrollAmount(static_cast<unsigned int>(std::ceil((m_verticalScrollbar.getMaximum() - m_verticalScrollbar.getLowValue()) / 50.f))); }
void ScrollPane::adjustSBRanges() { int extraH = 0; int extraV = 0; if(pChildHScroll->isVisible()) { extraH += pChildHScroll->getHeight(); } if(pChildVScroll->isVisible()) { extraV += pChildVScroll->getWidth(); } //set vertical value pChildVScroll->setRangeFromPage(getInnerSize().getHeight() - extraH,getContentHeight()); //set horizontal value pChildHScroll->setRangeFromPage(getInnerSize().getWidth() - extraV,getContentWidth()); }
void DeathCompass::layout(QPainter* p) { totalDeathsLabel->setText( tr("Total:") + "\n" + QString::number( player->getStat(StatType::DEATHS_BODY) + player->getStat(StatType::DEATHS_FALL) + player->getStat(StatType::DEATHS_LEVELLEFT) + player->getStat(StatType::DEATHS_WALL) + player->getStat(StatType::DEATHS_TIMEOUT) ) ); Widget::layout(p); setSize(QSize( compassPixmap.width(), deathsTitleLabel->getSize().height() + 40 + compassPixmap.height() + totalDeathsLabel->getSize().height() )); deathsTitleLabel->setPos(QPoint((getInnerSize().width() - deathsTitleLabel->getSize().width()) / 2, 0)); totalDeathsLabel->setPos(QPoint(0, deathsTitleLabel->getSize().height() + 40 + compassPixmap.height())); }
void ScrollPane::resizeSBsToPolicy() { pChildHScroll->setLocation(0,getInnerSize().getHeight() - pChildHScroll->getHeight()); pChildVScroll->setLocation(getInnerSize().getWidth() - pChildVScroll->getWidth(),0); if(pChildHScroll->isVisible() && pChildVScroll->isVisible()) { pChildHScroll->setSize(getInnerSize().getWidth() - pChildVScroll->getWidth() ,pChildHScroll->getHeight()); pChildVScroll->setSize(pChildVScroll->getWidth(), getInnerSize().getHeight() - pChildHScroll->getHeight()); } else if(pChildHScroll->isVisible()) { pChildHScroll->setSize(getInnerSize().getWidth(),pChildHScroll->getHeight()); } else if(pChildVScroll->isVisible()) { pChildVScroll->setSize(pChildVScroll->getWidth(),getInnerSize().getHeight()); } pChildInset->setVisibility( pChildVScroll->isVisible() && pChildHScroll->isVisible()); pChildInset->setLocation(pChildVScroll->getLocation().getX(), pChildHScroll->getLocation().getY()); pChildInset->setSize(pChildVScroll->getSize().getWidth(), pChildHScroll->getSize().getHeight()); }
void ScrollablePanel::mouseMoved(sf::Vector2f pos) { // Check if the mouse event should go to the scrollbar if ((m_verticalScrollbar.isMouseDown() && m_verticalScrollbar.isMouseDownOnThumb()) || m_verticalScrollbar.mouseOnWidget(pos - getPosition())) { m_verticalScrollbar.mouseMoved(pos - getPosition()); } else if ((m_horizontalScrollbar.isMouseDown() && m_horizontalScrollbar.isMouseDownOnThumb()) || m_horizontalScrollbar.mouseOnWidget(pos - getPosition())) { m_horizontalScrollbar.mouseMoved(pos - getPosition()); } else // Mouse not on scrollbar or dragging the scrollbar thumb { if (sf::FloatRect{getPosition().x + getChildWidgetsOffset().x, getPosition().y + getChildWidgetsOffset().y, getInnerSize().x, getInnerSize().y}.contains(pos)) { Panel::mouseMoved({pos.x + static_cast<float>(m_horizontalScrollbar.getValue()), pos.y + static_cast<float>(m_verticalScrollbar.getValue())}); } m_verticalScrollbar.mouseNoLongerOnWidget(); m_horizontalScrollbar.mouseNoLongerOnWidget(); } }
void HScrollBar::resizeArrows() { pChildLeftArrow->setSize(getArrowWidth(),getInnerSize().getHeight()); pChildRightArrow->setSize(getArrowWidth(),getInnerSize().getHeight()); }
void Slider::draw(sf::RenderTarget& target, sf::RenderStates states) const { states.transform.translate(getPosition()); // Draw the borders around the track if (m_bordersCached != Borders{0}) { if (m_mouseHover && m_borderColorHoverCached.isSet()) drawBorders(target, states, m_bordersCached, getSize(), m_borderColorHoverCached); else drawBorders(target, states, m_bordersCached, getSize(), m_borderColorCached); states.transform.translate({m_bordersCached.getLeft(), m_bordersCached.getTop()}); } // Draw the track if (m_spriteTrack.isSet() && m_spriteThumb.isSet()) { if (m_mouseHover && m_spriteTrackHover.isSet()) m_spriteTrackHover.draw(target, states); else m_spriteTrack.draw(target, states); } else // There are no textures { if (m_mouseHover && m_trackColorHoverCached.isSet()) drawRectangleShape(target, states, getInnerSize(), m_trackColorHoverCached); else drawRectangleShape(target, states, getInnerSize(), m_trackColorCached); } states.transform.translate({-m_bordersCached.getLeft() + m_thumb.left, -m_bordersCached.getTop() + m_thumb.top}); // Draw the borders around the thumb if (m_bordersCached != Borders{0}) { if (m_mouseHover && m_borderColorHoverCached.isSet()) drawBorders(target, states, m_bordersCached, {m_thumb.width, m_thumb.height}, m_borderColorHoverCached); else drawBorders(target, states, m_bordersCached, {m_thumb.width, m_thumb.height}, m_borderColorCached); states.transform.translate({m_bordersCached.getLeft(), m_bordersCached.getTop()}); } // Draw the thumb if (m_spriteTrack.isSet() && m_spriteThumb.isSet()) { if (m_mouseHover && m_spriteThumbHover.isSet()) m_spriteThumbHover.draw(target, states); else m_spriteThumb.draw(target, states); } else // There are no textures { const sf::Vector2f thumbInnerSize = {m_thumb.width - m_bordersCached.getLeft() - m_bordersCached.getRight(), m_thumb.height - m_bordersCached.getTop() - m_bordersCached.getBottom()}; if (m_mouseHover && m_thumbColorHoverCached.isSet()) drawRectangleShape(target, states, thumbInnerSize, m_thumbColorHoverCached); else drawRectangleShape(target, states, thumbInnerSize, m_thumbColorCached); } }
void Slider::setSize(const Layout2d& size) { Widget::setSize(size); m_bordersCached.updateParentSize(getSize()); if (getSize().x < getSize().y) m_verticalScroll = true; else m_verticalScroll = false; if (m_spriteTrack.isSet() && m_spriteThumb.isSet()) { float scaleFactor; if (m_verticalImage == m_verticalScroll) { m_spriteTrack.setSize(getInnerSize()); m_spriteTrackHover.setSize(getInnerSize()); if (m_verticalScroll) scaleFactor = getInnerSize().x / m_spriteTrack.getTexture().getImageSize().x; else scaleFactor = getInnerSize().y / m_spriteTrack.getTexture().getImageSize().y; } else // The image is rotated { m_spriteTrack.setSize({getInnerSize().y, getInnerSize().x}); m_spriteTrackHover.setSize({getInnerSize().y, getInnerSize().x}); if (m_verticalScroll) scaleFactor = getInnerSize().x / m_spriteTrack.getTexture().getImageSize().y; else scaleFactor = getInnerSize().y / m_spriteTrack.getTexture().getImageSize().x; } m_thumb.width = scaleFactor * m_spriteThumb.getTexture().getImageSize().x; m_thumb.height = scaleFactor * m_spriteThumb.getTexture().getImageSize().y; m_spriteThumb.setSize({m_thumb.width, m_thumb.height}); m_spriteThumbHover.setSize({m_thumb.width, m_thumb.height}); // Apply the rotation now that the size has been set if (m_verticalScroll != m_verticalImage) { m_spriteTrack.setRotation(-90); m_spriteTrackHover.setRotation(-90); m_spriteThumb.setRotation(-90); m_spriteThumbHover.setRotation(-90); } else { m_spriteTrack.setRotation(0); m_spriteTrackHover.setRotation(0); m_spriteThumb.setRotation(0); m_spriteThumbHover.setRotation(0); } } else // There are no textures { if (m_verticalScroll) { m_thumb.width = getSize().x * 1.6f; m_thumb.height = m_thumb.width / 2.0f; } else { m_thumb.height = getSize().y * 1.6f; m_thumb.width = m_thumb.height / 2.0f; } } updateThumbPosition(); }
void ListBox::paintComponent( const agui::PaintEvent &paintEvent ) { int itemsSkipped = getVisibleItemStart(); int hScrollHeight = 0; if(m_hScroll->isVisible()) { hScrollHeight = m_hScroll->getHeight(); } int maxitems = getVisibleItemCount(); int h = getItemHeight() * itemsSkipped; int rcount = 0; int diff = getItemHeight() - getFont()->getLineHeight(); agui::Color inverseFont = agui::Color(255,255,255); agui::Color* color; agui::Point absPos = getAbsolutePosition(); agui::Rectangle parentRect = m_visbilityWidget ? m_visbilityWidget->getAbsoluteRectangle() : getParent()->getAbsoluteRectangle(); int posX = absPos.getX() + (getInnerWidth() / 2); for(agui::ListItem::const_iterator it = getItemsBegin() + itemsSkipped ; it != getItemsEnd(); ++it) { if(rcount == maxitems) { break; } //if the item cannot be seen in the parent do not render it if(parentRect.pointInside(agui::Point(posX, absPos.getY() + h + getVerticalOffset())) || getSizeRectangle().pointInside(agui::Point(posX ,absPos.getY() + getItemHeight() + h + getVerticalOffset()) )) { if(it->second) { int vOffset = m_vScroll->isVisible() ? m_vScroll->getWidth() + 1 : 0; paintEvent.graphics()->drawNinePatchImage(m_selImage, agui::Point(0,h + getVerticalOffset()), agui::Dimension(getInnerSize().getWidth() - vOffset,getItemHeight())); color = &inverseFont; } else if(itemsSkipped + rcount == getHoverIndex()) { agui::Color highlight = agui::Color( getFontColor().getR() + 0.12f, getFontColor().getG() + 0.12f, getFontColor().getB() + 0.12f); color = (agui::Color*)&highlight; } else { color = (agui::Color*)&getFontColor(); } paintEvent.graphics()->drawText(agui::Point(getHorizontalOffset() + 4 , h + getVerticalOffset() + (diff / 2)),it->first.text.c_str(),*color, getFont()); } h += getItemHeight(); rcount++; } }
void ScrollablePanel::leftMouseReleased(sf::Vector2f pos) { if (m_verticalScrollbar.mouseOnWidget(pos - getPosition())) m_verticalScrollbar.leftMouseReleased(pos - getPosition()); else if (m_horizontalScrollbar.mouseOnWidget(pos - getPosition())) m_horizontalScrollbar.leftMouseReleased(pos - getPosition()); else if (sf::FloatRect{getPosition().x + getChildWidgetsOffset().x, getPosition().y + getChildWidgetsOffset().y, getInnerSize().x, getInnerSize().y}.contains(pos)) { Panel::leftMouseReleased({pos.x + static_cast<float>(m_horizontalScrollbar.getValue()), pos.y + static_cast<float>(m_verticalScrollbar.getValue())}); } }
void TextField::scrollToCaret(bool negetiveChange, bool reposition) { int retOffset = getLeftPadding(); int textWidth = getFont()->getTextWidth(getText()); if(textWidth < getAdjustedWidth()) { switch(getTextAlignment()) { case ALIGN_LEFT: alignOffset = 0; break; case ALIGN_CENTER: alignOffset = (getAdjustedWidth() - textWidth) / 2; break; case ALIGN_RIGHT: alignOffset = getAdjustedWidth() - textWidth; break; default: break; } } else { alignOffset = 0; } if(getTextLength() == 0 || getCaretPosition() == 0) { tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } if(reposition) { //do we need to move? if(getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) > -tOffset + getAdjustedWidth() + getLeftPadding() ) { //scroll to end if(getTextLength() < getCaretPosition() + getMaxCharacterSkip()) { retOffset -= solveCaretRetPos(getFont()->getTextWidth(getText()) - getAdjustedWidth(), retOffset); } else { int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() + getMaxCharacterSkip() )) - getAdjustedWidth(); retOffset -= solveCaretRetPos(initialPlace,retOffset); } tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } else if(tOffset + getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) <= leftPadding) { if(getCaretPosition() - getMaxCharacterSkip() > 0) { int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() - getMaxCharacterSkip() )); retOffset -= solveCaretRetPos(initialPlace,retOffset); } tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } else if(negetiveChange ) { int change = getCaretLocation() - getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() )) ; if(change <= getLeftPadding()) { tOffset = change; setTextOffset(change); } else { tOffset = leftPadding; setTextOffset(leftPadding + alignOffset); } return; } } //if there is more text than width //but theres not enough to fill the width //then fill the width int a = getAdjustedWidth() + getLeftPadding(); int b = getTextOffset() + textWidth; if(a > b && getTextOffset() < getLeftPadding()) { retOffset = -textWidth + getInnerSize().getWidth() - getRightPadding(); tOffset = retOffset; } else if(getTextOffset() >= getLeftPadding() ) { tOffset = leftPadding; setTextOffset(leftPadding + alignOffset); return; } setTextOffset(tOffset + alignOffset); }