Example #1
0
	void read_rect_node(grect& rect, hlxml::Node* node, bool allowNoSize)
	{
		rect.set(0.0f, 0.0f, 0.0f, 0.0f);
		if (allowNoSize)
		{
			rect.setSize(-1.0f, -1.0f);
		}
		if (node->pexists("rect"))
		{
			rect = hstr_to_grect(node->pstr("rect"));
		}
		else
		{
			if (node->pexists("position"))
			{
				rect.setPosition(hstr_to_gvec2(node->pstr("position")));
			}
			else
			{
				rect.setPosition(node->pfloat("x"), node->pfloat("y"));
			}
			if (node->pexists("size"))
			{
				rect.setSize(hstr_to_gvec2(node->pstr("size")));
			}
			else if (!allowNoSize)
			{
				rect.setSize(node->pfloat("w"), node->pfloat("h"));
			}
			else
			{
				rect.setSize(node->pfloat("w", -1.0f), node->pfloat("h", -1.0f));
			}
		}
	}
Example #2
0
	RenderRectangle Font::makeRenderRectangle(const grect& rect, grect area, unsigned int code)
	{
		static RenderRectangle result;
		result.src.set(0.0f, 0.0f, 0.0f, 0.0f);
		result.dest = area;
		// if destination rectangle not entirely inside drawing area
		if (rect.intersects(result.dest))
		{
			static gvec2 fullSize(1.0f, 1.0f);
			static gvec2 leftTop;
			static gvec2 rightBottom;
			static gvec2 textureInvertedSize;
			static CharacterDefinition* chr = NULL;
			static grect charRect;
			static april::Texture* texture = NULL;
			texture = this->getTexture(code);
			textureInvertedSize.set(1.0f / texture->getWidth(), 1.0f / texture->getHeight());
			chr = &this->characters[code];
			charRect.set(chr->x, chr->y, chr->w, chr->h);
			// vertical/horizontal cutoff of destination rectangle (using left/right/top/bottom semantics for consistency)
			leftTop.x = (area.left() < rect.left() ? (area.right() - rect.left()) / area.w : fullSize.x);
			leftTop.y = (area.top() < rect.top() ? (area.bottom() - rect.top()) / area.h : fullSize.y);
			rightBottom.x = (rect.right() < area.right() ? (rect.right() - area.left()) / area.w : fullSize.x);
			rightBottom.y = (rect.bottom() < area.bottom() ? (rect.bottom() - area.top()) / area.h : fullSize.y);
			// apply cutoff on destination
			result.dest.setPosition(area.getPosition() + area.getSize() * (fullSize - leftTop));
			result.dest.setSize(area.getSize() * (leftTop + rightBottom - fullSize));
			// apply cutoff on source
			result.src.setPosition((charRect.getPosition() + charRect.getSize() * (fullSize - leftTop)) * textureInvertedSize);
			result.src.setSize((charRect.getSize() * (leftTop + rightBottom - fullSize)) * textureInvertedSize);
		}
		return result;
	}