Move CRenderTools::DrawCircle to IGraphics::DrawCircle

As this method does not depend on any game components it is be moved to the engine graphics interface.
This commit is contained in:
Robert Müller 2022-07-09 13:16:12 +02:00
parent 249f6800ff
commit 237fdc76db
10 changed files with 44 additions and 49 deletions

View file

@ -1237,6 +1237,38 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe
}
}
void CGraphics_Threaded::DrawCircle(float x, float y, float r, int Segments)
{
IGraphics::CFreeformItem Array[32];
int NumItems = 0;
float FSegments = (float)Segments;
for(int i = 0; i < Segments; i += 2)
{
float a1 = i / FSegments * 2 * pi;
float a2 = (i + 1) / FSegments * 2 * pi;
float a3 = (i + 2) / FSegments * 2 * pi;
float Ca1 = cosf(a1);
float Ca2 = cosf(a2);
float Ca3 = cosf(a3);
float Sa1 = sinf(a1);
float Sa2 = sinf(a2);
float Sa3 = sinf(a3);
Array[NumItems++] = IGraphics::CFreeformItem(
x, y,
x + Ca1 * r, y + Sa1 * r,
x + Ca3 * r, y + Sa3 * r,
x + Ca2 * r, y + Sa2 * r);
if(NumItems == 32)
{
QuadsDrawFreeform(Array, 32);
NumItems = 0;
}
}
if(NumItems)
QuadsDrawFreeform(Array, NumItems);
}
void CGraphics_Threaded::RenderTileLayer(int BufferContainerIndex, const ColorRGBA &Color, char **pOffsets, unsigned int *pIndicedVertexDrawNum, size_t NumIndicesOffset)
{
if(NumIndicesOffset == 0)

View file

@ -1127,6 +1127,8 @@ public:
void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) override;
void QuadsText(float x, float y, float Size, const char *pText) override;
void DrawCircle(float x, float y, float r, int Segments) override;
const GL_STexCoord *GetCurTextureCoordinates() override
{
return m_aTexture;

View file

@ -442,6 +442,8 @@ public:
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;
virtual void DrawCircle(float x, float y, float r, int Segments) = 0;
struct CColorVertex
{
int m_Index;

View file

@ -58,11 +58,6 @@ bool CEmoticon::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
return true;
}
void CEmoticon::DrawCircle(float x, float y, float r, int Segments)
{
RenderTools()->DrawCircle(x, y, r, Segments);
}
void CEmoticon::OnRender()
{
if(!m_Active)
@ -107,7 +102,7 @@ void CEmoticon::OnRender()
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0, 0, 0, 0.3f);
DrawCircle(Screen.w / 2, Screen.h / 2, 190.0f, 64);
Graphics()->DrawCircle(Screen.w / 2, Screen.h / 2, 190.0f, 64);
Graphics()->QuadsEnd();
Graphics()->WrapClamp();
@ -138,7 +133,7 @@ void CEmoticon::OnRender()
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0, 1.0, 1.0, 0.3f);
DrawCircle(Screen.w / 2, Screen.h / 2, 100.0f, 64);
Graphics()->DrawCircle(Screen.w / 2, Screen.h / 2, 100.0f, 64);
Graphics()->QuadsEnd();
CTeeRenderInfo *pTeeInfo = &m_pClient->m_aClients[m_pClient->m_aLocalIDs[g_Config.m_ClDummy]].m_RenderInfo;
@ -162,7 +157,7 @@ void CEmoticon::OnRender()
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0, 0, 0, 0.3f);
DrawCircle(Screen.w / 2, Screen.h / 2, 30.0f, 64);
Graphics()->DrawCircle(Screen.w / 2, Screen.h / 2, 30.0f, 64);
Graphics()->QuadsEnd();
}
else

View file

@ -7,8 +7,6 @@
class CEmoticon : public CComponent
{
void DrawCircle(float x, float y, float r, int Segments);
bool m_WasActive;
bool m_Active;

View file

@ -1242,9 +1242,9 @@ void CMenus::RenderColorPicker()
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(MarkerOutline);
RenderTools()->DrawCircle(MarkerX, MarkerY, 4.5f, 32);
Graphics()->DrawCircle(MarkerX, MarkerY, 4.5f, 32);
Graphics()->SetColor(color_cast<ColorRGBA, ColorHSVA>(PickerColorHSV));
RenderTools()->DrawCircle(MarkerX, MarkerY, 3.5f, 32);
Graphics()->DrawCircle(MarkerX, MarkerY, 3.5f, 32);
Graphics()->QuadsEnd();
// Marker Hue Area

View file

@ -529,38 +529,6 @@ void CRenderTools::DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 Col
DrawRect4(pRect->x, pRect->y, pRect->w, pRect->h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding);
}
void CRenderTools::DrawCircle(float x, float y, float r, int Segments)
{
IGraphics::CFreeformItem Array[32];
int NumItems = 0;
float FSegments = (float)Segments;
for(int i = 0; i < Segments; i += 2)
{
float a1 = i / FSegments * 2 * pi;
float a2 = (i + 1) / FSegments * 2 * pi;
float a3 = (i + 2) / FSegments * 2 * pi;
float Ca1 = cosf(a1);
float Ca2 = cosf(a2);
float Ca3 = cosf(a3);
float Sa1 = sinf(a1);
float Sa2 = sinf(a2);
float Sa3 = sinf(a3);
Array[NumItems++] = IGraphics::CFreeformItem(
x, y,
x + Ca1 * r, y + Sa1 * r,
x + Ca3 * r, y + Sa3 * r,
x + Ca2 * r, y + Sa2 * r);
if(NumItems == 32)
{
Graphics()->QuadsDrawFreeform(Array, 32);
NumItems = 0;
}
}
if(NumItems)
Graphics()->QuadsDrawFreeform(Array, NumItems);
}
void CRenderTools::GetRenderTeeAnimScaleAndBaseSize(CAnimState *pAnim, CTeeRenderInfo *pInfo, float &AnimScale, float &BaseSize)
{
AnimScale = pInfo->m_Size * 1.0f / 64.0f;

View file

@ -117,8 +117,6 @@ public:
void DrawRect4(float x, float y, float w, float h, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding);
void DrawUIRect4(const CUIRect *pRect, vec4 ColorTopLeft, vec4 ColorTopRight, vec4 ColorBottomLeft, vec4 ColorBottomRight, int Corners, float Rounding);
void DrawCircle(float x, float y, float r, int Segments);
// larger rendering methods
void GetRenderTeeBodySize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &BodyOffset, float &Width, float &Height);
void GetRenderTeeFeetSize(class CAnimState *pAnim, CTeeRenderInfo *pInfo, vec2 &FeetOffset, float &Width, float &Height);

View file

@ -2936,7 +2936,7 @@ void CEditor::DoMapEditor(CUIRect View)
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0, 0, 1, 0.3f);
RenderTools()->DrawCircle(m_WorldOffsetX, m_WorldOffsetY - 3.0f, 20.0f, 32);
Graphics()->DrawCircle(m_WorldOffsetX, m_WorldOffsetY - 3.0f, 20.0f, 32);
Graphics()->QuadsEnd();
}
}

View file

@ -40,12 +40,12 @@ void CLayerSounds::Render(bool Tileset)
{
case CSoundShape::SHAPE_CIRCLE:
{
m_pEditor->RenderTools()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY,
m_pEditor->Graphics()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY,
Source.m_Shape.m_Circle.m_Radius, 32);
float Falloff = ((float)Source.m_Falloff / 255.0f);
if(Falloff > 0.0f)
m_pEditor->RenderTools()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY,
m_pEditor->Graphics()->DrawCircle(fx2f(Source.m_Position.x) + OffsetX, fx2f(Source.m_Position.y) + OffsetY,
Source.m_Shape.m_Circle.m_Radius * Falloff, 32);
break;
}