Beispiel #1
0
void Text::PrintString(std::string text, Position position, Color color, Size size) {
  std::transform(text.begin(), text.end(), text.begin(), tolower);

  for (size_t i = 0; i < text.length(); ++i) {
    DrawGlyph(text.at(i), Position(position.x + i * size.width, position.y), color, size);
  }
}
void SpriteManager::DrawGlyphs(FontCode fontID, vec2f scale, char* phrase, vec2f pos, vec4f tint, Alignment align)
{
	char* charPos = phrase;

	if (align != ALIGN_LEFT)
	{
		float width = 0;
		//Precalculate text size
		while (*charPos != '\0')
		{
			Glyph& g = mGlyphsData[fontID][*charPos - 32];
			width += (g.xadvance/1.0f) * scale.x;
			charPos++;
		}

		if (align == ALIGN_CENTER)
			pos.x -= width / 2;
		else if (align == ALIGN_RIGHT)
			pos.x -= width;
	}

	charPos = phrase;
	while(*charPos != '\0')
	{
		if (*charPos >= 32 || *charPos <= 126) {
			Glyph& g = mGlyphsData[fontID][*charPos - 32];
			DrawGlyph(fontID, scale, g, pos + vec2f(g.xoffset / 1.0f, g.yoffset / 1.0f) * scale, tint);
			pos += vec2f(g.xadvance / 1.0f, 0) * scale;
		}
		charPos++;
	}
}
//------------------------------------------------------------
void QGLWidgetTest::DrawAnimCard(const GAnimCard& AnimCard) {

	GTimeInterval validInterval;
	GMatrix33 worldMatrix;
	GReal t = AnimCard.ElapsedTicks / AnimCard.LifeTicks;

	worldMatrix = AnimCard.Animation->Matrix(t, G_WORLD_SPACE, validInterval);
	DrawGlyph(AnimCard.Card, worldMatrix);
}
Beispiel #4
0
CSize CXTPDocumentStructurePaintManager::DrawCollapsedBitmap(CDC* pDC, const CXTPReportRow* pRow, CRect& rcBitmap) {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    rcBitmap.left += 2;
    CSize sizeGlyph = DrawGlyph(pDC, rcBitmap, pRow->IsExpanded() ? 6 : 7);
    if (sizeGlyph.cx != 0 && pDC) {
        rcBitmap.right = rcBitmap.left + sizeGlyph.cx;
    }
    return CSize(2 + sizeGlyph.cx, 2 + sizeGlyph.cy);
}
Beispiel #5
0
/// Draw text to the specified surface
/// @param surface			SDL surface to draw text to
/// @param s				Character string to draw
/// @param rect				Destination rectangle for the text
/// @param clip				If true, clip the text output to the destination rect
void FontEngine::DrawText(SDL_Surface* surface, const char *s, SDL_Rect& rect, bool clip)
{
	if (fontImg)
		{
		if (clip)
			SDL_SetClipRect(surface, &rect);
			
		int destx = rect.x;
		const char* p = s;
		while (*p)
			{
			DrawGlyph(surface, *p, destx, rect.y);
			destx += fontCharWidth;
			p++;	
			}

		if (clip)
			SDL_SetClipRect(surface, NULL);
		}
}
Beispiel #6
0
	void DrawTextString(uword_t x0, uword_t y0, 
						const char* string, uword_t sz, Color foreColor, Color backColor)
	{
		uword_t x = x0;
		uword_t y = y0;
		uword_t cx = 6;
		uword_t cy = 8;
		if (y+cy > SCREENY) {
			return;
		}
		for(uword_t i=0; i<sz; i++) {
			DrawGlyph(x,y,string[i],
				cx,cy,1,1,foreColor,backColor);
			x += cx;
			if (x+cx > SCREENX) {
				return;
			}
		}
		return;
	}
/** 
 * @brief Draw text on an image 
 * @param Image the destination image
 * @param Width, Height the image dimensions
 * @param x0, y0 the upper-left corner of the text
 * @param Value the grayscale value of the drawn text
 * @param Text the text to be drawn
 */
void DrawText(unsigned char *Image, int Width, int Height,
    int x0, int y0, unsigned char Value, const char *Text)
{
    int c;
    
    if(!Text || !*Text)
        return;
    
    while((c = *(Text++)))
    {
        if(!(32 <= c && c <= 126))
            c = 63;
        
        c -= 32;
        DrawGlyph(Image, Width, Height, 
            FontBitmapData + FontInfo[c].Offset,
            FontInfo[c].Width, FontInfo[c].Height,
            x0, y0 + FontInfo[c].YShift, Value);
        
        x0 += FontInfo[c].Width + FontInfo[c].Spacing;
    }
}
//------------------------------------------------------------
void QGLWidgetTest::DrawGlyph(const GAnimTRSNode2D *Node, const GMatrix33 AnimMatrix) const {

	G_ASSERT(Node);

	GUInt32 i, j;
	GTimeInterval validInterval;
	GMatrix33 worldTransform, pivotMatrix, totalMatrix;
	GMatrix44 oglMatrix;

	GGlyphStyle *style = (GGlyphStyle *)Node->CustomData();
	G_ASSERT(style != NULL);
	const GTesselatedGlyph *tessGlyph = (const GTesselatedGlyph *)gTesselatedGlyphs[style->GlyphIndex()];
	G_ASSERT(tessGlyph != NULL);

	// extract world transformation
	worldTransform = Node->Matrix(0, G_WORLD_SPACE, validInterval);
	pivotMatrix = Node->PivotMatrix();
	totalMatrix = (AnimMatrix * (worldTransform * pivotMatrix));
	Matrix33To44(totalMatrix, oglMatrix);


	glMatrixMode(GL_MODELVIEW);
#ifdef DOUBLE_REAL_TYPE
	glLoadMatrixd((GLdouble *)oglMatrix.Data());
	glColor3d(style->Color()[G_X], style->Color()[G_Y], style->Color()[G_Z]);
#else
	glLoadMatrixf((GLfloat *)oglMatrix.Data());
	glColor3f(style->Color()[G_X], style->Color()[G_Y], style->Color()[G_Z]);
#endif

	// draw the display list
	glCallList(tessGlyph->DisplayList());

	// draw children
	j = Node->ChildrenCounts();
	for (i = 0; i < j; ++i)
		DrawGlyph(Node->Child(i), AnimMatrix);
}
Beispiel #9
0
void GuiPhaseBar::Render()
{
    JQuadPtr quad = WResourceManager::Instance()->GetQuad("phasebar");
    JQuadPtr phaseinfo = WResourceManager::Instance()->RetrieveTempQuad("fakebar.png"); //new fakebar graphics
    //uncomment to draw a hideous line across hires screens.
    // JRenderer::GetInstance()->DrawLine(0, CENTER, SCREEN_WIDTH, CENTER, ARGB(255, 255, 255, 255));

    const float radius  = 25 * zoomFactor;

    for(int i = 0; i < 6; ++i)
    {
        //the position of the glyphe in the circle
        const float circPos = (i - 2) * step + angle;
        const float glyphY = this->y + this->mHeight / 2 + sin(circPos) * radius;

        //the scale is computed so that the glyphes touch each other
        //hint: sin(circPos + PI/2) = cos(circPos)
        const float glyphScale = float(zoomFactor * cosf(circPos) * 0.5f);

        if (observer->currentPlayer && observer->currentPlayer->isAI() && !observer->currentPlayer->opponent()->isAI())
            DrawGlyph(quad.get(), (displayedPhaseId - 2 + i + kPhases) % kPhases, 0, glyphY, glyphScale, 29);
        else
            DrawGlyph(quad.get(), (displayedPhaseId - 2 + i + kPhases) % kPhases, 0, glyphY, glyphScale, 0);
    }

    //print phase name
    WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
    string currentP = _("your turn");
    string interrupt = "";
    if (observer->currentPlayer == mpDuelLayers->getRenderedPlayerOpponent())
    {
        currentP = _("opponent's turn");
    }
    font->SetColor(ARGB(255, 255, 255, 255));
    if (observer->currentlyActing() && observer->currentlyActing()->isAI())
    {
        font->SetColor(ARGB(255, 128, 128, 128));
    }
    if (observer->currentlyActing() != observer->currentPlayer)
    {
        if (observer->currentPlayer == mpDuelLayers->getRenderedPlayer())
        {
            interrupt = _(" - ") + _("opponent plays");
        }
        else
        {
            interrupt = _(" - ") + _("you play");
        }
    }

    char buf[200];
    //running this string through translate returns gibberish even though we defined the variables in the lang.txt
    //the conversion from phase bar phases to mtg phases is x%kPhases + 1
    //todo: just to this when the displayedPhaseId updates
    string phaseNameToTranslate = observer->phaseRing->phaseName(displayedPhaseId%kPhases + 1);
    phaseNameToTranslate = _(phaseNameToTranslate);
    sprintf(buf, _("(%s%s) %s").c_str(), currentP.c_str(), interrupt.c_str(),phaseNameToTranslate.c_str());
#if !defined (PSP)
    if(phaseinfo.get())
    {
        
        phaseinfo->mWidth = font->GetStringWidth(buf)+12.f;
        phaseinfo->SetHotSpot(phaseinfo->mWidth -4, 0);
        //phaseinfo->mHeight = font->GetHeight()+5.f;
        JRenderer::GetInstance()->RenderQuad(phaseinfo.get(),SCREEN_WIDTH_F,0,0,2.2f, SCREEN_HEIGHT_F / phaseinfo->mHeight);
    }
#endif
    font->DrawString(buf, SCREEN_WIDTH - 5, 2, JGETEXT_RIGHT);
}
Beispiel #10
0
void DrawBillboards()
{
	Billboard* billb;
	BillboardT* t;
	float size;

	Player* py = &g_player[g_curP];
	Camera* cam = &py->camera;
	
	//Vec3f vertical = cam->up2();
	Vec3f vertical = cam->m_up;
	Vec3f horizontal = cam->m_strafe;
	Vec3f a, b, c, d;
	Vec3f vert, horiz;

	Particle* part;
	ParticleT* pT;

	Shader* s = &g_shader[SHADER_BILLBOARD];

	//glDisable(GL_CULL_FACE);

	for(int i=0; i<BILLBOARDS; i++)
	{
		billb = &g_billb[i];
		if(!billb->on)
			continue;

		t = &g_billbT[billb->type];
		Font* f = &g_font[MAINFONT16];
		Glyph* g = &f->glyph[t->glyph];

		glActiveTexture(GL_TEXTURE0);
		//glBindTexture(GL_TEXTURE_2D, g_texture[t->tex].texname);
		glBindTexture(GL_TEXTURE_2D, g_texture[f->texindex].texname);
		glUniform1i(s->m_slot[SSLOT_TEXTURE0], 0);

		if(billb->particle >= 0)
		{
			part = &g_particle[billb->particle];
			pT = &g_particleT[part->type];
			size = pT->minsize + pT->sizevariation*(1.0f - part->life);
			glUniform4f(s->m_slot[SSLOT_COLOR], 1, 1, 1, part->life);
		}
		else
		{
			size = billb->size;
			glUniform4f(s->m_slot[SSLOT_COLOR], 1, 1, 1, 1);
		}

		vert = vertical*size*g->texsize[1];
		horiz = horizontal*size*g->texsize[0];
		//Vec3f off = vertical*size*g->offset[1] + horizontal*size*g->offset[0];
		Vec3f off = vertical*size*g->offset[1];	// + horizontal*size*g->offset[0];

#if 0
	if(g_rtextp->m_type == RICHTEXT_ICON)
	{
		Icon* icon = &g_icon[g_rtextp->m_icon];
		float hscale = f->gheight / (float)icon->m_height;

		UseIconTex(g_rtextp->m_icon);
		glUniform4f(g_shader[g_curS].m_slot[SSLOT_COLOR], 1, 1, 1, 1);

		int left = x;
		int right = left + (float)icon->m_width * hscale;
		int top = y;
		int bottom = top + f->gheight;
		DrawGlyph(left, top, right, bottom, 0, 0, 1, 1);

		UseFontTex();
		glUniform4f(g_shader[g_curS].m_slot[SSLOT_COLOR], currcolor[0], currcolor[1], currcolor[2], currcolor[3]);

		//g_log<<"color[3] = "<<currcolor[3]<<std::endl;
	}
	else if(g_rtextp->m_type == RICHTEXT_TEXT)
	{
		unsigned int k = g_rtextp->m_text.m_data[pi];
		Glyph* g = &f->glyph[k];

		int left = x + g->offset[0];
		int right = left + g->texsize[0];
		int top = y + g->offset[1];
		int bottom = top + g->texsize[1];
		DrawGlyph(left, top, right, bottom, g->texcoord[0], g->texcoord[1], g->texcoord[2], g->texcoord[3]);
	}
#endif

#if 0
		a = billb->pos - horiz + vert + off;
		b = billb->pos + horiz + vert + off;
		c = billb->pos + horiz - vert + off;
		d = billb->pos - horiz - vert + off;
#else
		a = billb->pos - horiz + vert*2 + off;
		b = billb->pos + horiz + vert*2 + off;
		c = billb->pos + horiz + off;
		d = billb->pos - horiz + off;
#endif

		const float vertices[] =
		{
			//posx, posy posz   texx, texy
			a.x, a.y, a.z,          g->texcoord[0], g->texcoord[1],
			b.x, b.y, b.z,          g->texcoord[2], g->texcoord[1],
			c.x, c.y, c.z,          g->texcoord[2], g->texcoord[3],

			c.x, c.y, c.z,          g->texcoord[2], g->texcoord[3],
			d.x, d.y, d.z,          g->texcoord[0], g->texcoord[3],
			a.x, a.y, a.z,          g->texcoord[0], g->texcoord[1]
		};

		//glVertexPointer(3, GL_FLOAT, sizeof(float)*5, &vertices[0]);
		//glTexCoordPointer(2, GL_FLOAT, sizeof(float)*5, &vertices[3]);

		glVertexAttribPointer(s->m_slot[SSLOT_POSITION], 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, &vertices[0]);
		glVertexAttribPointer(s->m_slot[SSLOT_TEXCOORD0], 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, &vertices[3]);
		//glVertexAttribPointer(s->m_slot[SSLOT_NORMAL], 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, va->normals);

		glDrawArrays(GL_TRIANGLES, 0, 6);

		//g_log<<"draw"<<std::endl;
	}

	//glEnable(GL_CULL_FACE);

	/*
	CEntity* e;
	CPlayer* p;
	CHold* h;
	CItemType* iT;
	size = 8.0f;
	vert = vertical*size;
	horiz = horizontal*size;
	Vec3f muzz;
	Camera* cam;
	Vec3f offset;

	for(int i=0; i<ENTITIES; i++)
	{
	e = &g_entity[i];

	if(!e->on)
	continue;

	if(e->controller < 0)
	continue;

	p = &g_player[e->controller];

	if(p->equipped < 0)
	continue;

	h = &p->items[p->equipped];
	iT = &g_itemType[h->type];

	if((e->frame[BODY_UPPER] < ANIM_SHOTSHOULDER_S || e->frame[BODY_UPPER] > ANIM_SHOTSHOULDER_S+4))
	continue;

	glBindTexture(GL_TEXTURE_2D, g_muzzle[rand()%4]);

	cam = &e->camera;

	if(p == &g_player[g_localP] && g_viewmode == FIRSTPERSON)
	muzz = Rotate(iT->front, -cam->Pitch(), 1, 0, 0);
	else
	muzz = RotateAround(iT->front, Vec3f(0, MID_HEIGHT_OFFSET, 0), -cam->Pitch(), 1, 0, 0);

	muzz = cam->m_pos + Rotate(muzz, cam->Yaw(), 0, 1, 0);

	a = muzz - horiz + vert;
	b = muzz - horiz - vert;
	c = muzz + horiz - vert;
	d = muzz + horiz + vert;

	float vertices[] =
	{
	//posx, posy posz   texx, texy
	a.x, a.y, a.z,          1, 0,
	b.x, b.y, b.z,          1, 1,
	c.x, c.y, c.z,          0, 1,

	c.x, c.y, c.z,          0, 1,
	d.x, d.y, d.z,          0, 0,
	a.x, a.y, a.z,          1, 0
	};

	glVertexPointer(3, GL_FLOAT, sizeof(float)*5, &vertices[0]);
	glTexCoordPointer(2, GL_FLOAT, sizeof(float)*5, &vertices[3]);

	glDrawArrays(GL_TRIANGLES, 0, 6);
	}*/
}
Beispiel #11
0
void DrawTextToMemory(
	_Inout_ _Notnull_ unsigned char *const surface,
	_In_ const int sw,
	_In_ const int sh,
	_In_ _Notnull_ const wchar_t* text,
	_In_ int penx,
	_In_ int peny,
	_In_ const int fontsize,
	_In_opt_ float* tint
	)
{
	int ch, i, j;
	const int penx0 = penx;

	for (ch = 0; ch < (int)wcslen(text); ++ch)
	{
		unsigned char* bitmap = NULL;
		int pitch, rows, advance, horiBearingY;

		if (text[ch] == L'\n')
		{
			penx = penx0;
			peny += fontsize;
			continue;
		}

		if (DrawGlyph(text[ch], fontsize, &pitch, &rows, &advance, &horiBearingY, &bitmap))
		{
			// draw font failed
			free(bitmap);
			break;
		}

		for (i = 0; i < rows; ++i)
		{
			for (j = 0; j < pitch; ++j)
			{
				unsigned char glyphPixel = bitmap[pitch * i + j];
				
				const int pixelOffset = 4*(sw * (sh - 1 - (peny - horiBearingY + i)) + penx + j);
				
				if (glyphPixel && pixelOffset >= 0 && pixelOffset < 4*sw*sh-3)
				{
					int alphaacc = (int)surface[pixelOffset + 3] + glyphPixel;
					
					surface[pixelOffset + 0] = glyphPixel;
					surface[pixelOffset + 1] = glyphPixel;
					surface[pixelOffset + 2] = glyphPixel;
					surface[pixelOffset + 3] = alphaacc > 255 ? 255 : alphaacc;

					if (tint)
					{
						surface[pixelOffset + 0] = (unsigned char)(surface[pixelOffset + 0] * tint[0]);
						surface[pixelOffset + 1] = (unsigned char)(surface[pixelOffset + 1] * tint[1]);
						surface[pixelOffset + 2] = (unsigned char)(surface[pixelOffset + 2] * tint[2]);
					}
				}
			}
		}

		penx += advance;

		free(bitmap);
	}
}