Skip to content

Commit

Permalink
Restored mirroring of texture feature for CUIStatic
Browse files Browse the repository at this point in the history
Using: in node of element based on `CUIStatic` class type `mirror="b"`, `b` is one of mirroring modes.

`b` - both, mirror by vertical and horizontal;
`v` - vertical, mirror by vertical;
`h` - horizontal, mirror by horizontal.
  • Loading branch information
Hrusteckiy committed Jun 5, 2024
1 parent 3cdcdbd commit 98c7c61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/xrUICore/Static/UIStaticItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CUIStaticItem::CUIStaticItem()
uFlags.zero();
vSize.set(0, 0);
TextureRect.set(0, 0, 0, 0);
eMirrorMode = tmNone;
vHeadingPivot.set(0, 0);
vHeadingOffset.set(0, 0);
dwColor = 0xffffffff;
Expand Down Expand Up @@ -56,6 +57,12 @@ void CUIStaticItem::RenderInternal(const Fvector2& in_pos)
LTt.set(TextureRect.x1 / ts.x, TextureRect.y1 / ts.y);
RBt.set(TextureRect.x2 / ts.x, TextureRect.y2 / ts.y);

// Check mirror mode
if (tmMirrorHorisontal == eMirrorMode || tmMirrorBoth == eMirrorMode)
std::swap(LTt.x, RBt.x);
if (tmMirrorVertical == eMirrorMode || tmMirrorBoth == eMirrorMode)
std::swap(LTt.y, RBt.y);

float offset = -0.5f;
if (UI().m_currentPointType == IUIRender::pttLIT)
offset = 0.0f;
Expand Down Expand Up @@ -131,6 +138,12 @@ void CUIStaticItem::RenderInternal(float angle)
LTt.set(TextureRect.x1 / ts.x + hp.x, TextureRect.y1 / ts.y + hp.y);
RBt.set(TextureRect.x2 / ts.x + hp.x, TextureRect.y2 / ts.y + hp.y);

// Check mirror mode
if (tmMirrorHorisontal == eMirrorMode || tmMirrorBoth == eMirrorMode)
std::swap(LTt.x, RBt.x);
if (tmMirrorVertical == eMirrorMode || tmMirrorBoth == eMirrorMode)
std::swap(LTt.y, RBt.y);

float kx = UI().get_current_kx();

// clip poly
Expand Down
12 changes: 12 additions & 0 deletions src/xrUICore/Static/UIStaticItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
#include "xrCore/xrstring.h"
#endif

enum EUIMirroring
{
tmNone,
tmMirrorHorisontal,
tmMirrorVertical,
tmMirrorBoth
};

class XRUICORE_API CUIStaticItem
{
protected:
Expand All @@ -22,6 +30,7 @@ class XRUICORE_API CUIStaticItem
Fvector2 vHeadingPivot;
Fvector2 vHeadingOffset;
Flags8 uFlags;
EUIMirroring eMirrorMode;

ui_shader hShader;
Fvector2 vPos;
Expand Down Expand Up @@ -65,6 +74,9 @@ class XRUICORE_API CUIStaticItem
void ResetHeadingPivot();
IC bool GetFixedLTWhileHeading() const { return !!uFlags.test(flFixedLTWhileHeading); }
Fvector2 GetHeadingPivot() { return vHeadingPivot; }
IC void SetMirrorMode(EUIMirroring m) { eMirrorMode = m; }
IC EUIMirroring GetMirrorMode() { return eMirrorMode; }

private:
void RenderInternal(const Fvector2& pos);
void RenderInternal(float angle);
Expand Down
8 changes: 8 additions & 0 deletions src/xrUICore/XML/UIXmlInitBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ bool CUIXmlInitBase::InitStatic(CUIXml& xml_doc, pcstr path, int index, CUIStati
InitTexture(xml_doc, path, index, pWnd);
InitTextureOffset(xml_doc, path, index, pWnd);

shared_str mirroring = xml_doc.ReadAttrib(path, index, "mirror", "");
if (0 == xr_strcmp(mirroring, "h"))
pWnd->GetStaticItem()->SetMirrorMode(tmMirrorHorisontal);
else if (0 == xr_strcmp(mirroring, "v"))
pWnd->GetStaticItem()->SetMirrorMode(tmMirrorVertical);
else if (0 == xr_strcmp(mirroring, "b"))
pWnd->GetStaticItem()->SetMirrorMode(tmMirrorBoth);

const int flag = xml_doc.ReadAttribInt(path, index, "heading", 0);
pWnd->EnableHeading((flag) ? true : false);

Expand Down

0 comments on commit 98c7c61

Please sign in to comment.