bool ScottHandler::ScottPackerNode::addRectangle(sf::IntRect * inputRectangle)
		{
			if(leftChild != 0 || rightChild != 0)
			{
				bool leftSuccess = leftChild->addRectangle(inputRectangle);
				if(!leftSuccess)
				{
					return rightChild->addRectangle(inputRectangle);
				}
				return leftSuccess;
			}
			else
			{
				if(filled || inputRectangle->Width > rectangle.Width || inputRectangle->Height > rectangle.Height)
				{
					return false;
				}

				if(inputRectangle->Width == rectangle.Width && inputRectangle->Height == rectangle.Height)
				{
					filled = true;
					inputRectangle->Left = rectangle.Left;
					inputRectangle->Top = rectangle.Top;
					inputRectangle->Width = rectangle.Width;
					inputRectangle->Height = rectangle.Height;

					return true;
				}

				int widthDifference = rectangle.Width - inputRectangle->Width;
				int heightDifference = rectangle.Height - inputRectangle->Height;

				sf::IntRect leftRectangle(rectangle);
				sf::IntRect rightRectangle(rectangle);

				if(widthDifference > heightDifference)
				{
					leftRectangle.Width = inputRectangle->Width;
					rightRectangle.Left += inputRectangle->Width;
					rightRectangle.Width -= inputRectangle->Width;
				}
				else
				{
					leftRectangle.Height = inputRectangle->Height;
					rightRectangle.Top += inputRectangle->Height;
					rightRectangle.Height -= inputRectangle->Height;
				}

				leftChild = new ScottPackerNode(leftRectangle);
				rightChild = new ScottPackerNode(rightRectangle);

				return leftChild->addRectangle(inputRectangle);
			}
		}
Ejemplo n.º 2
0
void MacPlatformStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
	switch (element)
	{
		case QStyle::PE_IndicatorTabClose:
			{
				QRect rectangle(option->rect);

				if (rectangle.width() > 8)
				{
					rectangle = QRect((rectangle.left() + ((rectangle.width() - 8) / 2)), (rectangle.top() + ((rectangle.height() - 8) / 2)), 8, 8);
				}

				QPen pen(QColor(60, 60, 60));
				pen.setWidthF(1.25);

				painter->save();
				painter->setRenderHint(QPainter::Antialiasing);
				painter->setPen(pen);
				painter->drawLine(rectangle.topLeft(), rectangle.bottomRight());
				painter->drawLine(rectangle.topRight(), rectangle.bottomLeft());
				painter->restore();
			}

			return;
		case QStyle::PE_PanelStatusBar:
			QProxyStyle::drawPrimitive(element, option, painter, widget);

			return;
		case QStyle::PE_FrameTabBarBase:
			{
				const QStyleOptionTabBarBase *tabBarBaseOption(qstyleoption_cast<const QStyleOptionTabBarBase*>(option));

				if (tabBarBaseOption && tabBarBaseOption->documentMode)
				{
					painter->save();
					painter->setPen(QColor(100, 100, 100, 200));

					if (tabBarBaseOption->selectedTabRect.isValid())
					{
						QRect leftRectangle(tabBarBaseOption->tabBarRect);
						leftRectangle.setRight(tabBarBaseOption->selectedTabRect.left());
						leftRectangle.setLeft(option->rect.left());

						QRect rightRectangle(tabBarBaseOption->tabBarRect);
						rightRectangle.setLeft(tabBarBaseOption->selectedTabRect.right());
						rightRectangle.setRight(option->rect.right());

						painter->fillRect(leftRectangle, QColor(0, 0, 0, 50));
						painter->fillRect(rightRectangle, QColor(0, 0, 0, 50));
					}
					else
					{
						painter->fillRect(tabBarBaseOption->tabBarRect, QColor(0, 0, 0, 50));
					}

					painter->drawLine(QPoint(option->rect.left(), tabBarBaseOption->tabBarRect.top()), QPoint(option->rect.right(), tabBarBaseOption->tabBarRect.top()));
					painter->drawLine(QPoint(option->rect.left(), tabBarBaseOption->tabBarRect.bottom()), QPoint(option->rect.right(), tabBarBaseOption->tabBarRect.bottom()));

					if (tabBarBaseOption->tabBarRect.left() != option->rect.left())
					{
						painter->drawLine(tabBarBaseOption->tabBarRect.topLeft(), tabBarBaseOption->tabBarRect.bottomLeft());
					}

					if (tabBarBaseOption->tabBarRect.right() != option->rect.right())
					{
						painter->drawLine(tabBarBaseOption->tabBarRect.topRight(), tabBarBaseOption->tabBarRect.bottomRight());
					}

					painter->restore();

					return;
				}
			}

			break;
		default:
			break;
	}

	Style::drawPrimitive(element, option, painter, widget);
}