Esempio n. 1
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;
	}
Esempio n. 2
0
void RenderSystem::setOrthoProjection(grect rect)
{
    // TODOaa - change and improve this implementation
    // also: this variable needs to be updated in ::setProjectionMatrix() as well in order to prevent a stale value when using getOrthoProjection()
    this->orthoProjection = rect;
    rect -= rect.getSize() * this->getPixelOffset() / april::window->getSize();
    this->projectionMatrix.ortho(rect);
    this->_setProjectionMatrix(this->projectionMatrix);
}
Esempio n. 3
0
#include <april/RenderSystem.h>
#include <april/SystemDelegate.h>
#include <april/UpdateDelegate.h>
#include <april/Window.h>
#include <gtypes/Rectangle.h>
#include <gtypes/Vector2.h>
#include <hltypes/hlog.h>
#include <hltypes/hltypesUtil.h>
#include <hltypes/hstring.h>

#include "CustomRenderSystem.h"
#include "CustomWindow.h"

static april::Texture* texture = NULL;
static grect drawRect(0.0f, 0.0f, 800.0f, 600.0f);
static gvec2 offset = drawRect.getSize() * 0.5f;
static grect textureRect;
static bool mousePressed = false;

class UpdateDelegate : public april::UpdateDelegate
{
	bool onUpdate(float timeDelta)
	{
		april::rendersys->clear();
		april::rendersys->setOrthoProjection(drawRect);
		april::rendersys->drawFilledRect(drawRect, april::Color(64, 64, 64));
		april::rendersys->setTexture(texture);
		april::rendersys->drawTexturedRect(textureRect + offset, grect(0.0f, 0.0f, 1.0f, 1.0f));
		april::rendersys->drawFilledRect(grect(0.0f, 0.0f, 100.0f, 75.0f), april::Color::Orange);
		april::rendersys->drawFilledRect(grect(10.0f, 10.0f, 80.0f, 55.0f), april::Color::Yellow);
		return true;
Esempio n. 4
0
april::Texture* o_symbol = NULL;
april::Texture* line_horz = NULL;
april::Texture* line_vert = NULL;
april::Texture* line45 = NULL;
april::Texture* line315 = NULL;
int positions[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
int victory = 0;
bool player = 0;
april::TexturedVertex v[4];

#if !defined(_ANDROID) && !defined(_IOS) && !defined(_WINP8)
grect drawRect(0.0f, 0.0f, 800.0f, 600.0f);
#else
grect drawRect(0.0f, 0.0f, 480.0f, 320.0f);
#endif
gvec2 size = drawRect.getSize() * 5 / 16;

void draw_symbol(int x, int y, chstr symbol)
{
	float x1, x2, x3, x4, y1, y2, y3, y4;
	
	x1 = x * size.x - size.x + (x - 1) * 10;
	x2 = x * size.x + (x - 1) * 10;
	x3 = x * size.x - size.x + (x - 1) * 10;
	x4 = x * size.x + (x - 1) * 10;
	y1 = y * size.y - size.y + (y - 1) * 10;
	y2 = y * size.y - size.y + (y - 1) * 10;
	y3 = y * size.y + (y - 1) * 10;
	y4 = y * size.y + (y - 1) * 10;
	
	if (symbol == "x_symbol")