void CheckBox::draw(DrawingSurface::Ptr& surface, float xOffset, float yOffset) const
	{
		if (!pVisible)
			return;

		auto themeptr = Theme::Current();
		auto& theme = *themeptr;
		Point2D<float> pos(pPosition.x + xOffset, pPosition.y + yOffset);

		surface->beginRectangleClipping(pos.x, pos.y, theme.checkBoxSize, theme.checkBoxSize);

		// Draw the check box
		surface->drawFilledRectangle(theme.borderColor, theme.buttonColor,
			pos.x, pos.y, theme.checkBoxSize, theme.checkBoxSize, theme.borderWidth);

		// Draw the cross if the box is checked
		if (pChecked)
		{
			surface->drawLine(theme.borderColor, theme.buttonColor, pos.x, pos.y,
				pos.x + theme.checkBoxSize, pos.y + theme.checkBoxSize, theme.borderWidth);
			surface->drawLine(theme.borderColor, theme.buttonColor, pos.x + theme.checkBoxSize,
				pos.y, pos.x, pos.y + theme.checkBoxSize, theme.borderWidth);
		}
		surface->endClipping();

		// Draw the label
		surface->drawText(pText, theme.font, theme.textColor,
			pos.x + theme.checkBoxSize + theme.margin, pos.y);
		pModified = false;
	}
Exemple #2
0
	void TextEditor::draw(DrawingSurface::Ptr& surface, float xOffset, float yOffset) const
	{
		if (!pVisible)
			return;

		Point2D<float> pos(pPosition.x + xOffset, pPosition.y + yOffset);

		// Draw background
		surface->drawFilledRectangle(pBackColor, pBackColor, pos.x, pos.y, pSize.x, pSize.y, 0.0f);

		surface->beginRectangleClipping(pos.x, pos.y, pSize.x, pSize.y);

		// Draw the text
		float pixelLineHeight = pLineHeight(pConversion);
		float x = pos.x + pHorizMargin;
		float y = pos.y + pVertMargin;
		const uint lastVisibleLine = YToLine(pSize.y - pVertMargin);
		// Loop on lines of text
		uint lineNb = pScrollPos.y;
		AnyString text(pText, cursorToByte(pScrollPos));
		text.words("\n", [&](AnyString& line) -> bool
		{
			if (lineNb++ > lastVisibleLine)
				return false;
			// TODO : x scroll offset ?
			if (!line.empty())
			{
				// Crop trailing `\r` (CR) if necessary
				if ('\r' == line[line.length() - 1])
					line.truncate(line.length() - 1);
				// Ignore empty lines (test a second time to catch single "\r" lines)
				if (!line.empty())
				{
					// y is the baseline position, not the top
					surface->drawText(line, pFont, pColor, x, y - pixelLineHeight / 2, pTabWidth, true);
				}
			}
			y += pixelLineHeight;
			return true;
		}, true);

		// Draw the cursor
		if (pCursorPos.y >= pScrollPos.y && pCursorPos.y <= lastVisibleLine)
		{
			float cx = columnToX(pCursorPos.x);
			float cy = lineToY(pCursorPos.y);
			surface->drawLine(pColor, cx, cy, cx, cy + pixelLineHeight, 1.0f);
		}

		// Draw line and column numbers
		surface->drawText(String(pCursorPos.y + 1) << ':' << pCursorPos.x, pFont, pColor, pSize.x - 50, pSize.y - 15);

		surface->endClipping();
		pModified = false;
	}