18 #include "precompiled.h"
34 using namespace GUIRenderer;
74 std::map<CStr, CGUISprite>::iterator it (Sprites.find(SpriteName));
75 if (it == Sprites.end())
84 if (SpriteName.substr(0, 10) ==
"stretched:")
90 if (SpriteName.substr(10, 10) ==
"grayscale:")
108 Sprites[SpriteName] = Sprite;
110 it = Sprites.find(SpriteName);
111 ENSURE(it != Sprites.end());
113 else if (SpriteName.substr(0, 8) ==
"cropped:")
118 double xRatio = SpriteName.BeforeFirst(
",").AfterLast(
"(").ToDouble();
119 double yRatio = SpriteName.BeforeFirst(
")").AfterLast(
",").ToDouble();
121 int PathStart = SpriteName.Find(
")") + 1;
133 Sprites[SpriteName] = Sprite;
135 it = Sprites.find(SpriteName);
136 ENSURE(it != Sprites.end());
138 else if (SpriteName.substr(0, 7) ==
"colour:")
146 LOGERROR(L
"GUI: Error parsing sprite 'colour' (\"%ls\")", value.c_str());
161 Sprites[SpriteName] = Sprite;
163 it = Sprites.find(SpriteName);
164 ENSURE(it != Sprites.end());
169 LOGERROR(L
"Trying to use a sprite that doesn't exist (\"%hs\").", SpriteName.c_str());
174 Calls.reserve(it->second.m_Images.size());
178 std::vector<SGUIImage>::const_iterator cit;
179 for (cit = it->second.m_Images.begin(); cit != it->second.m_Images.end(); ++cit)
183 CRect ObjectSize = cit->m_Size.GetClientArea(Size);
192 if (cit->m_RoundCoordinates)
201 if (! cit->m_TextureName.empty())
204 textureProps.
SetWrap(cit->m_WrapMode);
230 else if (cit->m_Effects)
232 if (cit->m_Effects->m_AddColor !=
CColor())
238 if (cit->m_Effects->m_AddColor.a < 0.f)
241 else if (cit->m_Effects->m_Greyscale)
255 Calls.push_back(Call);
262 float TexHeight =
m_Texture->GetHeight();
264 if (!TexWidth || !TexHeight)
266 return CRect(0, 0, 1, 1);
300 BlockTex =
CRect(0, 0, TexWidth, TexHeight);
315 .Scale(ScaleW, ScaleH)
323 TexCoords.
left /= TexWidth;
324 TexCoords.right /= TexWidth;
325 TexCoords.top /= TexHeight;
326 TexCoords.bottom /= TexHeight;
343 #warning TODO: implement GUI LOD bias for GLES
345 glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -1.f);
349 for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit)
351 cit->m_Shader->BeginPass();
353 shader->Uniform(str_transform, matrix);
355 if (cit->m_HasTexture)
357 shader->Uniform(str_color, cit->m_ShaderColorParameter);
358 shader->BindTexture(str_tex, cit->m_Texture);
360 if (cit->m_EnableBlending || cit->m_Texture->HasAlpha())
362 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
366 CRect TexCoords = cit->ComputeTexCoords();
369 CRect Verts = cit->m_Vertices;
381 std::vector<float> data;
382 #define ADD(u, v, x, y, z) STMT(data.push_back(u); data.push_back(v); data.push_back(x); data.push_back(y); data.push_back(z))
392 shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*
sizeof(
float), &data[0]);
393 shader->VertexPointer(3, GL_FLOAT, 5*
sizeof(
float), &data[2]);
394 glDrawArrays(GL_TRIANGLES, 0, 6);
398 shader->Uniform(str_color, cit->m_BackColor);
400 if (cit->m_EnableBlending)
402 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
407 CRect Verts = cit->m_Vertices;
413 std::vector<float> data;
414 #define ADD(x, y, z) STMT(data.push_back(x); data.push_back(y); data.push_back(z))
420 ADD(Verts.
left, Verts.
top, Z + cit->m_DeltaZ);
423 shader->VertexPointer(3, GL_FLOAT, 3*
sizeof(
float), &data[0]);
424 glDrawArrays(GL_TRIANGLES, 0, 6);
426 if (cit->m_BorderColor !=
CColor())
428 shader->Uniform(str_color, cit->m_BorderColor);
431 ADD(Verts.
left + 0.5f, Verts.
top + 0.5f, Z + cit->m_DeltaZ);
432 ADD(Verts.
right - 0.5f, Verts.
top + 0.5f, Z + cit->m_DeltaZ);
434 ADD(Verts.
left + 0.5f, Verts.
bottom - 0.5f, Z + cit->m_DeltaZ);
436 shader->VertexPointer(3, GL_FLOAT, 3*
sizeof(
float), &data[0]);
437 glDrawArrays(GL_LINE_LOOP, 0, 4);
442 cit->m_Shader->EndPass();
448 #warning TODO: implement GUI LOD bias for GLES
450 glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0.f);
CRect ComputeTexCoords() const
CMatrix3D GetDefaultGuiMatrix()
Path VfsPath
VFS path of the form "(dir/)*file?".
float m_FixedHAspectRatio
If non-zero, then the image's width will be adjusted when rendering so that the width:height ratio eq...
float left
Returning CPos representing each corner.
Represents the filename and GL parameters of a texture, for passing to CTextureManager::CreateTexture...
static void swap(UniqueRange &p1, UniqueRange &p2)
Includes static functions that needs one template argument.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
DrawCalls & operator=(const DrawCalls &)
void AddImage(const SGUIImage &image)
Adds an image to the sprite collage.
SGUIImageEffects * m_Effects
void UpdateDrawCallCache(DrawCalls &Calls, const CStr &SpriteName, const CRect &Size, int CellID, std::map< CStr, CGUISprite > &Sprites)
CRect m_TexturePlacementInFile
CRect GetClientArea(const CRect &parent) const
Get client area rectangle when the parent is given.
Made to represent screen positions and delta values.
std::wstring wstring_from_utf8(const std::string &src, Status *err)
convert UTF-8 to a wide string (UTF-16 or UCS-4, depending on the platform's wchar_t).
A CGUISprite is actually a collage of several real sprites, this struct represents is such real sprit...
The GUI sprite, is actually several real sprites (images) like a collage.
CColor m_ShaderColorParameter
#define ADD(u, v, x, y, z)
void Draw(DrawCalls &Calls, float Z)
const SGUIImage * m_Image
CShaderTechniquePtr m_Shader
void SetWrap(GLint wrap)
Set wrapping mode (typically GL_REPEAT, GL_CLAMP_TO_EDGE, etc).
shared_ptr< CShaderProgram > CShaderProgramPtr
CClientArea m_TextureSize
CPos TopLeft() const
Get Position equivalent to top/left corner.
Rectangle class used for screen rectangles.
Client Area is a rectangle relative to a parent rectangle.
shared_ptr< CTexture > CTexturePtr