Exemplo n.º 1
0
static void createSolidPolygon(	float r, float g, float b, float a,
								const std::vector<std::vector<Point2f> > & contours,
								bool evenodd,
								GraphicsBase& result)
{
	createGraphicsBase(contours, result, evenodd);
	result.setColor(r, g, b, a);
}
Exemplo n.º 2
0
static void createSolidLineStrip(float r, float g, float b, float a,
								   float thickness,
								   const std::vector<Point2f>& points,
									GraphicsBase& result)
{
	if (points.size() < 2)
		return;

	std::vector<std::vector<Point2f> > polygon(points.size() - 1);

	for (std::size_t i = 1; i < points.size(); ++i)
	{
		const Point2f& p0 = points[i - 1];
		const Point2f& p1 = points[i];

		lineToPolygon(p0.x, p0.y, p1.x, p1.y, thickness, polygon[i - 1]);
	}

	createGraphicsBase(polygon, result, false);
	result.setColor(r, g, b, a);
} 
Exemplo n.º 3
0
void Font::drawText(std::vector<GraphicsBase> * vGraphicsBase, const char* text,
		float r, float g, float b, float a, TextLayoutParameters *layout, bool hasSample,
        float minx, float miny, TextLayout &l) {
    size_t size = utf8_to_wchar(text, strlen(text), NULL, 0, 0);

	if (size == 0) {
		return;
	}

    if (!(l.styleFlags&TEXTSTYLEFLAG_SKIPLAYOUT))
        l = layoutText(text, layout);

    int gfx = vGraphicsBase->size();
    vGraphicsBase->resize(gfx+1);
    GraphicsBase *graphicsBase = &((*vGraphicsBase)[gfx]);

	graphicsBase->data = data_;
	if (fontInfo_.isSetTextColorAvailable)
	{
		if (l.styleFlags&TEXTSTYLEFLAG_COLOR)
		{
			graphicsBase->colors.resize(size * 16);
			graphicsBase->colors.Update();
		}
		else
			graphicsBase->setColor(r, g, b, a);
	}
	else
	{
		graphicsBase->setColor(1, 1, 1, 1);
		l.styleFlags&=(~TEXTSTYLEFLAG_COLOR);
	}
	graphicsBase->vertices.resize(size * 4);
	graphicsBase->texcoords.resize(size * 4);
	graphicsBase->indices.resize(size * 6);
	graphicsBase->vertices.Update();
	graphicsBase->texcoords.Update();
	graphicsBase->indices.Update();

    size_t gi=0;
	for (int pn = 0; pn < l.parts.size(); pn++) {
		ChunkLayout c = l.parts[pn];
		unsigned char rgba[4];
		if (l.styleFlags&TEXTSTYLEFLAG_COLOR)
		{
			float ca=(c.styleFlags&TEXTSTYLEFLAG_COLOR)?(1.0/255)*((c.color>>24)&0xFF):a;
			rgba[0]=(unsigned char)(ca*((c.styleFlags&TEXTSTYLEFLAG_COLOR)?(c.color>>16)&0xFF:r*255));
			rgba[1]=(unsigned char)(ca*((c.styleFlags&TEXTSTYLEFLAG_COLOR)?(c.color>>8)&0xFF:g*255));
			rgba[2]=(unsigned char)(ca*((c.styleFlags&TEXTSTYLEFLAG_COLOR)?(c.color>>0)&0xFF:b*255));
			rgba[3]=(unsigned char)(ca*255);
		}
		std::basic_string<wchar32_t> wtext;
		size_t wsize = utf8_to_wchar(c.text.c_str(), c.text.size(), NULL, 0, 0);
		wtext.resize(wsize);
		utf8_to_wchar(c.text.c_str(), c.text.size(), &wtext[0], wsize, 0);

        float x = (c.dx-minx)/sizescalex_, y = (c.dy-miny)/sizescaley_;

        /*
		if (hasSample) {
			std::map<wchar32_t, TextureGlyph>::const_iterator iter =
					fontInfo_.textureGlyphs.find(text[0]);
			const TextureGlyph &textureGlyph = iter->second;
            x = c.dx/sizescalex_-textureGlyph.left; //FIXME: is this needed ?
        }*/

		wchar32_t prev = 0;
		for (int i = 0; i < wsize; ++i) {
			std::map<wchar32_t, TextureGlyph>::const_iterator iter =
					fontInfo_.textureGlyphs.find(wtext[i]);

			if (iter == fontInfo_.textureGlyphs.end())
				continue;

			const TextureGlyph &textureGlyph = iter->second;

			int width = textureGlyph.width;
			int height = textureGlyph.height;
			int left = textureGlyph.left;
			int top = textureGlyph.top;

			x += kerning(prev, wtext[i]) >> 6;
			prev = wtext[i];

			float x0 = x + left;
			float y0 = y - top;

			float x1 = x + left + width;
			float y1 = y - top + height;

            graphicsBase->vertices[gi * 4 + 0] = Point2f(sizescalex_ * x0,
					sizescaley_ * y0);
            graphicsBase->vertices[gi * 4 + 1] = Point2f(sizescalex_ * x1,
					sizescaley_ * y0);
            graphicsBase->vertices[gi * 4 + 2] = Point2f(sizescalex_ * x1,
					sizescaley_ * y1);
            graphicsBase->vertices[gi * 4 + 3] = Point2f(sizescalex_ * x0,
					sizescaley_ * y1);

			float u0 = (float) textureGlyph.x / (float) data_->exwidth;
			float v0 = (float) textureGlyph.y / (float) data_->exheight;
			float u1 = (float) (textureGlyph.x + width)
					/ (float) data_->exwidth;
			float v1 = (float) (textureGlyph.y + height)
					/ (float) data_->exheight;

			u0 *= uvscalex_;
			v0 *= uvscaley_;
			u1 *= uvscalex_;
			v1 *= uvscaley_;

            graphicsBase->texcoords[gi * 4 + 0] = Point2f(u0, v0);
            graphicsBase->texcoords[gi * 4 + 1] = Point2f(u1, v0);
            graphicsBase->texcoords[gi * 4 + 2] = Point2f(u1, v1);
            graphicsBase->texcoords[gi * 4 + 3] = Point2f(u0, v1);

			if (l.styleFlags&TEXTSTYLEFLAG_COLOR)
			{
				for (int v=0;v<16;v+=4) {
					graphicsBase->colors[gi * 16 + 0 + v] = rgba[0];
					graphicsBase->colors[gi * 16 + 1 + v] = rgba[1];
					graphicsBase->colors[gi * 16 + 2 + v] = rgba[2];
					graphicsBase->colors[gi * 16 + 3 + v] = rgba[3];
				}
			}

            graphicsBase->indices[gi * 6 + 0] = gi * 4 + 0;
            graphicsBase->indices[gi * 6 + 1] = gi * 4 + 1;
            graphicsBase->indices[gi * 6 + 2] = gi * 4 + 2;
            graphicsBase->indices[gi * 6 + 3] = gi * 4 + 0;
            graphicsBase->indices[gi * 6 + 4] = gi * 4 + 2;
            graphicsBase->indices[gi * 6 + 5] = gi * 4 + 3;

			x += textureGlyph.advancex >> 6;

			x += layout->letterSpacing / sizescalex_;
            gi++;
		}
	}