void cHorizontalScrollbar::onChangeBounds(int oldx, int oldy, int oldwidth, int oldheight) {
	if (btnRight && btnLeft && background && handle) {
		btnRight->setX(width_ - btnRight->width());
		pixelPerStep = qMax<float>(0, (float)getInnerWidth() / (float)getValues());
		handle->setX(getTrackerXFromPos(pos_));		
		background->setBounds(btnLeft->width(), 0, width_ - btnLeft->width() - btnRight->width(), btnLeft->height());
	}

	pixelPerStep = qMax<float>(0, (float)getInnerWidth() / (float)getValues());
	cContainer::onChangeBounds(oldx, oldy, oldwidth, oldheight);
}
void cHorizontalScrollbar::setHandleId(ushort id) {
	if (handle) {
		handle->setId(id);
		handle->update();
		handle->setX(getTrackerXFromPos(pos_));
		pixelPerStep = qMax<float>(0, (float)getInnerWidth() / (float)getValues());
	}
}
unsigned int cHorizontalScrollbar::getTrackerXFromPos(int pos) {
	if (pos == (int)min_) {
		return btnLeft->width();
	} else if (pos == (int)max_) {
		return btnRight->x() - handle->width();
	} else {
		return btnLeft->width() + getInnerWidth() * ((pos_ - min_) / qMax<float>(1, max_ - min_));
	}
}
void cHorizontalScrollbar::setLeftButtonIds(ushort unpressed, ushort pressed, ushort hover) {
	if (btnLeft) {
		btnLeft->setStateGump(BS_UNPRESSED, unpressed);
		btnLeft->setStateGump(BS_PRESSED, pressed);
		btnLeft->setStateGump(BS_HOVER, hover);
		setBounds(x_, y_, width_, btnLeft->height()); // Set Width before adding another button

		// Reposition background
		background->setBounds(btnLeft->width(), 0, width_ - btnLeft->width() - btnRight->width(), btnLeft->height());
		handle->setX(getTrackerXFromPos(pos_));
		pixelPerStep = qMax<float>(0, (float)getInnerWidth() / (float)getValues());
	}
}
Example #5
0
	bool ScrollPane::intersectionWithPoint( const Point &p ) const
	{
		return Rectangle(getMargin(SIDE_LEFT),
			getMargin(SIDE_TOP),getInnerWidth(),getInnerHeight()).pointInside(p);
	}
Example #6
0
	void FlowLayout::layoutChildren()
	{
			int curX = 0;
			int curY = 0;

			int highestWidget = 0;
			int numWidgets = 0;
			int rlOffset = 0;
			int btOffset = 0;
			int numRows = 1;
			int numOnRow = 0;

			std::vector<Widget*> curRow;
			Widget* firstWidget = NULL;

			int lowestPoint = 0;
			for(WidgetArray::iterator it = getChildBegin(); 
				it != getChildEnd(); ++it)
			{
				if(!(*it)->isVisible() && isFilteringVisibility())
				{
					continue;
				}

				if(!firstWidget)
				{
					firstWidget = (*it);
				}

				if(isResizingRowToWidth())
				{
					(*it)->setSize(getInnerWidth(),(*it)->getHeight());
				}

				if((maxOnRow > 0 && numOnRow >= maxOnRow) || isResizingRowToWidth() ||
					(curX + (*it)->getWidth() > getInnerWidth() && numWidgets > 0 && !singleRow))
				{
					numRows++;
					numOnRow = 0;
					curX = 0;
					curY += highestWidget + getVerticalSpacing();
					highestWidget = 0;

					if(center && !curRow.empty())
					{
						int x1 = curRow[0]->getLocation().getX();
						int x2 = curRow.back()->getLocation().getX() +
							curRow.back()->getWidth();

						int w = x2 - x1;
						int centerOffset = (getInnerWidth() - w) / 2;

						for(size_t i = 0; i < curRow.size(); ++i)
						{
							curRow[i]->setLocation(
								curRow[i]->getLocation().getX() + centerOffset,
								curRow[i]->getLocation().getY());
						}
					}

					curRow.clear();
				}
				numOnRow++;

				if(!topToBottom)
				{
					btOffset = getInnerHeight() - (*it)->getHeight() - (curY + curY);
				}
				if(!leftToRight && !center)
				{
					rlOffset = getInnerWidth() - (*it)->getWidth() - (curX + curX);
				}
				(*it)->setLocation(curX + rlOffset,curY + btOffset);
				curX += (*it)->getWidth() + getHorizontalSpacing();
				numWidgets++;

				if((*it)->getHeight() > highestWidget)
				{
					highestWidget = (*it)->getHeight();
				}

				curRow.push_back((*it));

				//find the content height
				int l = (*it)->getLocation().getY() + (*it)->getHeight();
				if(l > lowestPoint)
				{
					lowestPoint = l;
				}
		}

			//code duplication, I know :(
			if(center && !curRow.empty())
			{
				if(alignLastRow && numRows > 1 && firstWidget)
				{
					int x1 = curRow[0]->getLocation().getX();
					int x2 = firstWidget->getLocation().getX();
					int diff = x2 - x1;

					for(size_t i = 0; i < curRow.size(); ++i)
					{
						curRow[i]->setLocation(
							curRow[i]->getLocation().getX() + diff,
							curRow[i]->getLocation().getY());
					}
				}

				else
				{
					int x1 = curRow[0]->getLocation().getX();
					int x2 = curRow.back()->getLocation().getX() +
						curRow.back()->getWidth();

					int w = x2 - x1;
					int centerOffset = (getInnerWidth() - w) / 2;

					for(size_t i = 0; i < curRow.size(); ++i)
					{
						curRow[i]->setLocation(
							curRow[i]->getLocation().getX() + centerOffset,
							curRow[i]->getLocation().getY());
					}
				}
			}

			//set content height
			contentHSz = lowestPoint + getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM);
	}
unsigned int cHorizontalScrollbar::getPosFromTrackerX(int x) {
	if (x < btnLeft->width()) {
		return min_;
	} else if (x > btnRight->x() - handle->width()) {
		return max_;
	} else {
		return qMin<int>(max_, qMax<int>(min_, min_ + ((x - (int)btnLeft->width()) / (float)getInnerWidth()) * getValues()));
	}
}
Example #8
0
	void PopUpMenu::paintComponent( const agui::PaintEvent &paintEvent )
	{
		int totalHeight = 0;
		agui::Color regularColor = agui::Color(
			getFontColor().getR(),getFontColor().getG(),getFontColor().getB(),getOpacity());
		agui::Color disabledColor = agui::Color(
			getDisabledFontColor().getR(),getDisabledFontColor().getG(),
			getDisabledFontColor().getB(),getOpacity());

		for(int i = 0; i < getLength(); ++i)
		{
			int w = 0;
			agui::PopUpMenuItem* item = getItemAt(i);

			if(i == getSelectedIndex() && item->getItemType() != agui::PopUpMenuItem::SEPARATOR)
			{
				paintEvent.graphics()->drawNinePatchImage(
					m_highlightImg,agui::Point(0,totalHeight),
					agui::Dimension(getInnerWidth(),getItemHeight()),getOpacity());
			}

			//draw the icon
			if(isShowingIcon())
			{
				if(item->getIcon())
				{
					paintEvent.graphics()->
						drawImage(item->getIcon(),getIconPosition(i,totalHeight),getOpacity());
				}

				w += getIconWidth();
			}

			if(item->isSeparator())
			{
				paintEvent.graphics()->drawLine(
					agui::Point(w,totalHeight + (getItemHeight(item) / 2)),
					agui::Point(getInnerWidth(),totalHeight + (getItemHeight(item) / 2)),
					agui::Color(90,90,90));

				paintEvent.graphics()->drawLine(
					agui::Point(w,totalHeight + (getItemHeight(item) / 2) + 1),
					agui::Point(getInnerWidth(),totalHeight + (getItemHeight(item) / 2) + 1),
					agui::Color(200,200,200));
			}

			w += getStartTextGap();

			agui::Color* fontColor = item->isEnabled() ? &regularColor : &disabledColor;

			paintEvent.graphics()->drawText(agui::Point(w,getTextCenter() + totalHeight),
				item->getText().c_str(),
				*fontColor,
				getFont());

			w+= getMiddleTextGap();

			agui::Point shortcutPoint = alignString(item->getShortcutText(),agui::ALIGN_MIDDLE_RIGHT);
			shortcutPoint.setX(shortcutPoint.getX() - getEndTextGap());
			shortcutPoint.setY(getTextCenter() + totalHeight);


			paintEvent.graphics()->drawText(shortcutPoint,
				item->getShortcutText().c_str(),*fontColor,
				getFont());

			if(item->isSubMenu())
			{
				paintEvent.graphics()->drawImage(m_subArrowImg,
					createAlignedPosition(agui::ALIGN_MIDDLE_CENTER,
					agui::Rectangle(getInnerWidth() - getEndTextGap(),
					totalHeight,getEndTextGap(),getItemHeight()),
					agui::Dimension(m_subArrowImg->getWidth(),m_subArrowImg->getHeight())),
					getOpacity());
			}

			totalHeight += getItemHeight(item);
		}
	}
Example #9
0
	void Button::setFont( const Font *font )
	{
		Widget::setFont(font);
		resizableText.makeTextLines(getFont(),getText(),wrappedText,getInnerWidth());
	}
Example #10
0
	void Button::setSize( const Dimension &size )
	{
		Widget::setSize(size);
		resizableText.makeTextLines(getFont(),getText(),wrappedText,getInnerWidth());

	}
Example #11
0
	void Button::setText( const std::string &text )
	{
		Widget::setText(text);
		resizableText.makeTextLines(getFont(),getText(),wrappedText,getInnerWidth());
	}
Example #12
0
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++;

    }
}