From 91c19bff55e6c5ddb871c67b2ceb5b3c705cdc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 24 Dec 2021 03:18:10 +0100 Subject: [PATCH] Refactored Math::Point in control classes --- src/ui/controls/button.cpp | 4 +- src/ui/controls/button.h | 2 +- src/ui/controls/check.cpp | 4 +- src/ui/controls/check.h | 2 +- src/ui/controls/color.cpp | 4 +- src/ui/controls/color.h | 2 +- src/ui/controls/control.cpp | 62 +++++++++++++------------ src/ui/controls/control.h | 36 +++++++-------- src/ui/controls/edit.cpp | 50 ++++++++++---------- src/ui/controls/edit.h | 30 ++++++------ src/ui/controls/editvalue.cpp | 8 ++-- src/ui/controls/editvalue.h | 6 +-- src/ui/controls/gauge.cpp | 4 +- src/ui/controls/gauge.h | 2 +- src/ui/controls/group.cpp | 4 +- src/ui/controls/group.h | 2 +- src/ui/controls/image.cpp | 4 +- src/ui/controls/image.h | 2 +- src/ui/controls/key.cpp | 6 +-- src/ui/controls/key.h | 2 +- src/ui/controls/label.cpp | 4 +- src/ui/controls/label.h | 2 +- src/ui/controls/list.cpp | 16 ++++--- src/ui/controls/list.h | 10 ++-- src/ui/controls/map.cpp | 66 ++++++++++++++------------ src/ui/controls/map.h | 32 ++++++------- src/ui/controls/scroll.cpp | 22 ++++----- src/ui/controls/scroll.h | 10 ++-- src/ui/controls/shortcut.cpp | 36 +++++++-------- src/ui/controls/shortcut.h | 2 +- src/ui/controls/slider.cpp | 22 ++++----- src/ui/controls/slider.h | 10 ++-- src/ui/controls/target.cpp | 6 +-- src/ui/controls/target.h | 6 +-- src/ui/controls/window.cpp | 87 ++++++++++++++++++----------------- src/ui/controls/window.h | 64 +++++++++++++------------- 36 files changed, 325 insertions(+), 306 deletions(-) diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index d397c05f..0c0c632e 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -53,7 +53,7 @@ CButton::~CButton() // Creates a new button. -bool CButton::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CButton::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -139,7 +139,7 @@ bool CButton::EventProcess(const Event &event) void CButton::Draw() { - Math::Point pos, dim, uv1, uv2; + glm::vec2 pos, dim, uv1, uv2; float dp; auto device = m_engine->GetDevice(); diff --git a/src/ui/controls/button.h b/src/ui/controls/button.h index 224ef1cc..31189201 100644 --- a/src/ui/controls/button.h +++ b/src/ui/controls/button.h @@ -32,7 +32,7 @@ public: CButton(); virtual ~CButton(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/check.cpp b/src/ui/controls/check.cpp index 77579e26..17cedff0 100644 --- a/src/ui/controls/check.cpp +++ b/src/ui/controls/check.cpp @@ -48,7 +48,7 @@ CCheck::~CCheck() // Creates a new button. -bool CCheck::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CCheck::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -89,7 +89,7 @@ bool CCheck::EventProcess(const Event &event) void CCheck::Draw() { - Math::Point iDim, pos; + glm::vec2 iDim, pos; float zoomExt, zoomInt; int icon; diff --git a/src/ui/controls/check.h b/src/ui/controls/check.h index 8a815b51..2bb98cb1 100644 --- a/src/ui/controls/check.h +++ b/src/ui/controls/check.h @@ -30,7 +30,7 @@ public: CCheck(); virtual ~CCheck(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/color.cpp b/src/ui/controls/color.cpp index 2210e8b3..6d67b986 100644 --- a/src/ui/controls/color.cpp +++ b/src/ui/controls/color.cpp @@ -60,7 +60,7 @@ CColor::~CColor() // Creates a new button. -bool CColor::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CColor::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -127,7 +127,7 @@ void CColor::Draw() { Gfx::Vertex2D vertex[4]; // 2 triangles Gfx::Color color; - Math::Point p1, p2; + glm::vec2 p1, p2; if ( (m_state & STATE_VISIBLE) == 0 ) return; diff --git a/src/ui/controls/color.h b/src/ui/controls/color.h index 64776d56..42a9f823 100644 --- a/src/ui/controls/color.h +++ b/src/ui/controls/color.h @@ -32,7 +32,7 @@ public: CColor(); virtual ~CColor(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/control.cpp b/src/ui/controls/control.cpp index 4714bf24..476fd0a7 100644 --- a/src/ui/controls/control.cpp +++ b/src/ui/controls/control.cpp @@ -51,10 +51,10 @@ CControl::CControl() m_icon = 0; m_fontStretch = false; m_bGlint = false; - m_glintCorner1 = Math::Point(0.0f, 0.0f); - m_glintCorner2 = Math::Point(0.0f, 0.0f); + m_glintCorner1 = { 0.0f, 0.0f }; + m_glintCorner2 = { 0.0f, 0.0f }; m_glintProgress = 999.0f; - m_glintMouse = Math::Point(0.0f, 0.0f); + m_glintMouse = { 0.0f, 0.0f }; } // Object's destructor. @@ -67,11 +67,13 @@ CControl::~CControl() // Creates a new button. // pos: [0..1] -bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CControl::Create(const glm::vec2& position, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); + glm::vec2 pos = position; + m_pos = pos; m_dim = dim; m_icon = icon; @@ -98,32 +100,26 @@ bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType even } -void CControl::SetPos(Math::Point pos) +void CControl::SetPos(const glm::vec2& pos) { m_pos = pos; - pos.x = m_pos.x; - pos.y = m_pos.y + m_dim.y; - GlintCreate(pos); + GlintCreate({ m_pos.x, m_pos.y + m_dim.y }); } -Math::Point CControl::GetPos() +glm::vec2 CControl::GetPos() { return m_pos; } -void CControl::SetDim(Math::Point dim) +void CControl::SetDim(const glm::vec2& dim) { - Math::Point pos; - m_dim = dim; - pos.x = m_pos.x; - pos.y = m_pos.y + m_dim.y; - GlintCreate(pos); + GlintCreate({ m_pos.x, m_pos.y + m_dim.y }); } -Math::Point CControl::GetDim() +glm::vec2 CControl::GetDim() { return m_dim; } @@ -269,7 +265,7 @@ bool CControl::SetTooltip(std::string name) return true; } -bool CControl::GetTooltip(Math::Point pos, std::string &name) +bool CControl::GetTooltip(const glm::vec2& pos, std::string &name) { if ( m_tooltip.length() == 0 ) return false; if ( (m_state & STATE_VISIBLE) == 0 ) return false; @@ -377,7 +373,7 @@ void CControl::GlintDelete() // Creates a reflection for that button. -void CControl::GlintCreate(Math::Point ref, bool bLeft, bool bUp) +void CControl::GlintCreate(const glm::vec2& ref, bool bLeft, bool bUp) { float offset; @@ -417,7 +413,7 @@ void CControl::GlintCreate(Math::Point ref, bool bLeft, bool bUp) void CControl::GlintFrame(const Event &event) { Math::Vector pos, speed; - Math::Point dim; + glm::vec2 dim; if ( (m_state & STATE_GLINT ) == 0 || (m_state & STATE_ENABLE ) == 0 || @@ -447,7 +443,7 @@ void CControl::GlintFrame(const Event &event) void CControl::Draw() { - Math::Point pos; + glm::vec2 pos; float zoomExt, zoomInt; int icon; @@ -562,7 +558,7 @@ void CControl::Draw() void CControl::DrawPart(int icon, float zoom, float ex) { - Math::Point p1, p2, c, uv1, uv2; + glm::vec2 p1, p2, c, uv1, uv2; float dp; p1.x = m_pos.x; @@ -604,7 +600,7 @@ void CControl::DrawPart(int icon, float zoom, float ex) // Draws an icon made up of a rectangular (if x = 0) // or 3 pieces. -void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, +void CControl::DrawIcon(const glm::vec2& pos, const glm::vec2& dim, const glm::vec2& uv1, const glm::vec2& uv2, float ex) { Gfx::Vertex2D vertex[8]; // 6 triangles @@ -668,12 +664,14 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: // Draws a rectangular icon made up of 9 pieces. -void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, - Math::Point corner, float ex) +void CControl::DrawIcon(const glm::vec2& pos, const glm::vec2& dim, const glm::vec2& uv1, const glm::vec2& uv2, + const glm::vec2& cor, float ex) { Gfx::Vertex2D vertices[8]; // 6 triangles glm::vec2 p1, p2, p3, p4; + glm::vec2 corner = cor; + auto renderer = m_engine->GetDevice()->GetUIRenderer(); p1.x = pos.x; @@ -735,11 +733,14 @@ void CControl::DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math: // Draw round the hatch of a button. -void CControl::DrawWarning(Math::Point pos, Math::Point dim) +void CControl::DrawWarning(const glm::vec2& position, const glm::vec2& dimension) { - Math::Point uv1, uv2; + glm::vec2 uv1, uv2; float dp; + glm::vec2 pos = position; + glm::vec2 dim = dimension; + dp = 0.5f / 256.0f; m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -780,11 +781,14 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim) // Draw the shade under a button. -void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep) +void CControl::DrawShadow(const glm::vec2& position, const glm::vec2& dimension, float deep) { - Math::Point uv1, uv2, corner; + glm::vec2 uv1, uv2, corner; float dp; + glm::vec2 pos = position; + glm::vec2 dim = dimension; + dp = 0.5f/256.0f; m_engine->SetState( Gfx::ENG_RSTATE_TTEXTURE_WHITE); @@ -815,7 +819,7 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep) // Detects whether a position is in the button. -bool CControl::Detect(Math::Point pos) +bool CControl::Detect(const glm::vec2& pos) { return ( pos.x >= m_pos.x && pos.x <= m_pos.x + m_dim.x && diff --git a/src/ui/controls/control.h b/src/ui/controls/control.h index c5bd691e..7292f849 100644 --- a/src/ui/controls/control.h +++ b/src/ui/controls/control.h @@ -23,7 +23,7 @@ #include "graphics/engine/text.h" -#include "math/point.h" +#include #include @@ -71,14 +71,14 @@ public: CControl(); virtual ~CControl(); - virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType); + virtual bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType); virtual bool EventProcess(const Event &event); - virtual void SetPos(Math::Point pos); - virtual Math::Point GetPos(); - virtual void SetDim(Math::Point dim); - virtual Math::Point GetDim(); + virtual void SetPos(const glm::vec2& pos); + virtual glm::vec2 GetPos(); + virtual void SetDim(const glm::vec2& dim); + virtual glm::vec2 GetDim(); virtual bool SetState(int state, bool bState); virtual bool SetState(int state); virtual bool ClearState(int state); @@ -97,7 +97,7 @@ public: virtual void SetFontType(Gfx::FontType font); virtual Gfx::FontType GetFontType(); virtual bool SetTooltip(std::string name); - virtual bool GetTooltip(Math::Point pos, std::string &name); + virtual bool GetTooltip(const glm::vec2& pos, std::string &name); virtual void SetFocus(CControl* focusControl); virtual bool GetFocus(); @@ -107,14 +107,14 @@ public: protected: void GlintDelete(); - void GlintCreate(Math::Point ref, bool bLeft=true, bool bUp=true); + void GlintCreate(const glm::vec2& ref, bool bLeft=true, bool bUp=true); void GlintFrame(const Event &event); void DrawPart(int icon, float zoom, float ex); - void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, float ex=0.0f); - void DrawIcon(Math::Point pos, Math::Point dim, Math::Point uv1, Math::Point uv2, Math::Point corner, float ex); - void DrawWarning(Math::Point pos, Math::Point dim); - void DrawShadow(Math::Point pos, Math::Point dim, float deep=1.0f); - virtual bool Detect(Math::Point pos); + void DrawIcon(const glm::vec2& pos, const glm::vec2& dim, const glm::vec2& uv1, const glm::vec2& uv2, float ex=0.0f); + void DrawIcon(const glm::vec2& pos, const glm::vec2& dim, const glm::vec2& uv1, const glm::vec2& uv2, const glm::vec2& corner, float ex); + void DrawWarning(const glm::vec2& pos, const glm::vec2& dim); + void DrawShadow(const glm::vec2& pos, const glm::vec2& dim, float deep=1.0f); + virtual bool Detect(const glm::vec2& pos); std::string GetResourceName(EventType eventType); @@ -133,8 +133,8 @@ protected: CSoundInterface* m_sound; CSettings* m_settings; - Math::Point m_pos; // corner upper / left - Math::Point m_dim; // dimensions + glm::vec2 m_pos; // corner upper / left + glm::vec2 m_dim; // dimensions int m_icon; EventType m_eventType; // message to send when clicking int m_state; // states (STATE_ *) @@ -148,10 +148,10 @@ protected: bool m_bCapture; bool m_bGlint; - Math::Point m_glintCorner1; - Math::Point m_glintCorner2; + glm::vec2 m_glintCorner1; + glm::vec2 m_glintCorner2; float m_glintProgress; - Math::Point m_glintMouse; + glm::vec2 m_glintMouse; }; } // namespace Ui diff --git a/src/ui/controls/edit.cpp b/src/ui/controls/edit.cpp index 282ed8e2..cbc00d2f 100644 --- a/src/ui/controls/edit.cpp +++ b/src/ui/controls/edit.cpp @@ -159,7 +159,7 @@ CEdit::~CEdit() // Creates a new editable line. -bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CEdit::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventType); @@ -190,13 +190,13 @@ bool CEdit::Create(Math::Point pos, Math::Point dim, int icon, EventType eventTy } -void CEdit::SetPos(Math::Point pos) +void CEdit::SetPos(const glm::vec2& pos) { CControl::SetPos(pos); MoveAdjust(); } -void CEdit::SetDim(Math::Point dim) +void CEdit::SetDim(const glm::vec2& dim) { CControl::SetDim(dim); MoveAdjust(); @@ -204,7 +204,7 @@ void CEdit::SetDim(Math::Point dim) void CEdit::MoveAdjust() { - Math::Point pos, dim; + glm::vec2 pos, dim; float height; m_lineDescent = m_engine->GetText()->GetDescent(m_fontType, m_fontSize); @@ -587,7 +587,7 @@ void CEdit::SendModifEvent() // Detects whether the mouse is over a hyperlink character. -bool CEdit::IsLinkPos(Math::Point pos) +bool CEdit::IsLinkPos(const glm::vec2& pos) { int i; @@ -604,7 +604,7 @@ bool CEdit::IsLinkPos(Math::Point pos) // Positions the cursor after a double click. -void CEdit::MouseDoubleClick(Math::Point mouse) +void CEdit::MouseDoubleClick(const glm::vec2& mouse) { int i, character; @@ -643,7 +643,7 @@ void CEdit::MouseDoubleClick(Math::Point mouse) // Positions the cursor when clicked. -void CEdit::MouseClick(Math::Point mouse) +void CEdit::MouseClick(const glm::vec2& mouse) { int i; @@ -662,7 +662,7 @@ void CEdit::MouseClick(Math::Point mouse) // Positions the cursor when clicked released. -void CEdit::MouseRelease(Math::Point mouse) +void CEdit::MouseRelease(const glm::vec2& mouse) { int i = MouseDetect(mouse); if ( i == -1 ) return; @@ -689,27 +689,27 @@ void CEdit::MouseRelease(Math::Point mouse) // Positions the cursor after movement. -void CEdit::MouseMove(Math::Point mouse) +void CEdit::MouseMove(const glm::vec2& mouse) { - int i; + glm::vec2 pos = mouse; if ( m_bMulti && m_timeLastScroll+DELAY_SCROLL <= m_time ) { - if ( mouse.y > m_pos.y+m_dim.y ) // above? + if (pos.y > m_pos.y+m_dim.y ) // above? { Scroll(m_lineFirst-1, false); - mouse.y = m_pos.y+m_dim.y-MARGY-m_lineHeight/2.0f; + pos.y = m_pos.y+m_dim.y-MARGY-m_lineHeight/2.0f; } - if ( mouse.y < m_pos.y ) // lower? + if (pos.y < m_pos.y ) // lower? { Scroll(m_lineFirst+1, false); - mouse.y = m_pos.y+m_dim.y-MARGY-m_lineVisible*m_lineHeight+m_lineHeight/2.0f; + pos.y = m_pos.y+m_dim.y-MARGY-m_lineVisible*m_lineHeight+m_lineHeight/2.0f; } m_timeLastScroll = m_time; } - i = MouseDetect(mouse); + int i = MouseDetect(pos); if ( i != -1 ) { m_cursor1 = i; @@ -721,9 +721,9 @@ void CEdit::MouseMove(Math::Point mouse) // Positions the cursor when clicked. -int CEdit::MouseDetect(Math::Point mouse) +int CEdit::MouseDetect(const glm::vec2& mouse) { - Math::Point pos; + glm::vec2 pos; float indentLength = 0.0f, offset, size; int i, len, c; bool bTitle; @@ -908,7 +908,7 @@ bool CEdit::HyperGo(EventType event) void CEdit::Draw() { - Math::Point pos, ppos, dim, start, end; + glm::vec2 pos, ppos, dim, start, end; float size = 0.0f, indentLength = 0.0f; int i, j, beg, len, c1, c2, o1, o2, eol, line; @@ -1169,10 +1169,10 @@ static std::string PrepareImageFilename(std::string name) return filename; } -void CEdit::DrawImage(Math::Point pos, std::string name, float width, +void CEdit::DrawImage(const glm::vec2& pos, std::string name, float width, float offset, float height, int nbLine) { - Math::Point uv1, uv2, dim; + glm::vec2 uv1, uv2, dim; float dp; m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); @@ -1208,9 +1208,9 @@ void CEdit::DrawImage(Math::Point pos, std::string name, float width, // Draw the background. -void CEdit::DrawBack(Math::Point pos, Math::Point dim) +void CEdit::DrawBack(const glm::vec2& pos, const glm::vec2& dim) { - Math::Point uv1,uv2, corner; + glm::vec2 uv1,uv2, corner; float dp; if ( m_bGeneric ) return; @@ -1258,11 +1258,11 @@ void CEdit::DrawBack(Math::Point pos, Math::Point dim) } } -void CEdit::DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color color1, Gfx::Color color2) +void CEdit::DrawHorizontalGradient(const glm::vec2& pos, const glm::vec2& dim, Gfx::Color color1, Gfx::Color color2) { m_engine->SetState(Gfx::ENG_RSTATE_OPAQUE_COLOR); - Math::Point p1, p2; + glm::vec2 p1, p2; p1.x = pos.x; p1.y = pos.y; p2.x = pos.x + dim.x; @@ -1285,7 +1285,7 @@ void CEdit::DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color m_engine->AddStatisticTriangle(2); } -void CEdit::DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color) +void CEdit::DrawColor(const glm::vec2& pos, const glm::vec2& dim, Gfx::Color color) { DrawHorizontalGradient(pos, dim, color, color); } diff --git a/src/ui/controls/edit.h b/src/ui/controls/edit.h index 8d7ae5d4..86696671 100644 --- a/src/ui/controls/edit.h +++ b/src/ui/controls/edit.h @@ -111,10 +111,10 @@ public: virtual ~CEdit(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; - void SetPos(Math::Point pos) override; - void SetDim(Math::Point dim) override; + void SetPos(const glm::vec2& pos) override; + void SetDim(const glm::vec2& dim) override; bool EventProcess(const Event &event) override; void Draw() override; @@ -178,22 +178,22 @@ public: protected: void SendModifEvent(); - bool IsLinkPos(Math::Point pos); - void MouseDoubleClick(Math::Point mouse); - void MouseClick(Math::Point mouse); - void MouseMove(Math::Point mouse); - void MouseRelease(Math::Point mouse); - int MouseDetect(Math::Point mouse); + bool IsLinkPos(const glm::vec2& pos); + void MouseDoubleClick(const glm::vec2& mouse); + void MouseClick(const glm::vec2& mouse); + void MouseMove(const glm::vec2& mouse); + void MouseRelease(const glm::vec2& mouse); + int MouseDetect(const glm::vec2& mouse); void MoveAdjust(); void HyperJump(std::string name, std::string marker); bool HyperAdd(std::string filename, int firstLine); - void DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine); - void DrawBack(Math::Point pos, Math::Point dim); + void DrawImage(const glm::vec2& pos, std::string name, float width, float offset, float height, int nbLine); + void DrawBack(const glm::vec2& pos, const glm::vec2& dim); - void DrawHorizontalGradient(Math::Point pos, Math::Point dim, Gfx::Color color1, Gfx::Color color2); - void DrawColor(Math::Point pos, Math::Point dim, Gfx::Color color); + void DrawHorizontalGradient(const glm::vec2& pos, const glm::vec2& dim, Gfx::Color color1, Gfx::Color color2); + void DrawColor(const glm::vec2& pos, const glm::vec2& dim, Gfx::Color color); void FreeImage(); void Scroll(int pos, bool bAdjustCursor); @@ -264,8 +264,8 @@ protected: float m_timeBlink; float m_timeLastClick; float m_timeLastScroll; - Math::Point m_mouseFirstPos; - Math::Point m_mouseLastPos; + glm::vec2 m_mouseFirstPos; + glm::vec2 m_mouseLastPos; float m_column; bool m_bCapture; diff --git a/src/ui/controls/editvalue.cpp b/src/ui/controls/editvalue.cpp index fd6d5ed6..5a07e887 100644 --- a/src/ui/controls/editvalue.cpp +++ b/src/ui/controls/editvalue.cpp @@ -56,7 +56,7 @@ CEditValue::~CEditValue() // Creates a new button. -bool CEditValue::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CEditValue::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventType); @@ -80,13 +80,13 @@ bool CEditValue::Create(Math::Point pos, Math::Point dim, int icon, EventType ev } -void CEditValue::SetPos(Math::Point pos) +void CEditValue::SetPos(const glm::vec2& pos) { CControl::SetPos(pos); MoveAdjust(); } -void CEditValue::SetDim(Math::Point dim) +void CEditValue::SetDim(const glm::vec2& dim) { CControl::SetDim(dim); MoveAdjust(); @@ -94,7 +94,7 @@ void CEditValue::SetDim(Math::Point dim) void CEditValue::MoveAdjust() { - Math::Point pos, dim; + glm::vec2 pos, dim; if (m_edit != nullptr) { diff --git a/src/ui/controls/editvalue.h b/src/ui/controls/editvalue.h index ee081058..6e25c41b 100644 --- a/src/ui/controls/editvalue.h +++ b/src/ui/controls/editvalue.h @@ -45,10 +45,10 @@ public: CEditValue(); virtual ~CEditValue(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; - void SetPos(Math::Point pos) override; - void SetDim(Math::Point dim) override; + void SetPos(const glm::vec2& pos) override; + void SetDim(const glm::vec2& dim) override; bool EventProcess(const Event &event) override; void Draw() override; diff --git a/src/ui/controls/gauge.cpp b/src/ui/controls/gauge.cpp index 611b2dd2..3f5a168b 100644 --- a/src/ui/controls/gauge.cpp +++ b/src/ui/controls/gauge.cpp @@ -41,7 +41,7 @@ CGauge::~CGauge() // Creates a new button. -bool CGauge::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CGauge::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -73,7 +73,7 @@ bool CGauge::EventProcess(const Event &event) void CGauge::Draw() { - Math::Point pos, dim, ddim, uv1, uv2, corner; + glm::vec2 pos, dim, ddim, uv1, uv2, corner; float dp; if ( (m_state & STATE_VISIBLE) == 0 ) return; diff --git a/src/ui/controls/gauge.h b/src/ui/controls/gauge.h index 6a472a9c..76682320 100644 --- a/src/ui/controls/gauge.h +++ b/src/ui/controls/gauge.h @@ -30,7 +30,7 @@ public: CGauge(); virtual ~CGauge(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/group.cpp b/src/ui/controls/group.cpp index a5e1ab0a..1e65c597 100644 --- a/src/ui/controls/group.cpp +++ b/src/ui/controls/group.cpp @@ -48,7 +48,7 @@ CGroup::~CGroup() // Creates a new button. -bool CGroup::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CGroup::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -76,7 +76,7 @@ bool CGroup::EventProcess(const Event &event) void CGroup::Draw() { - Math::Point uv1,uv2, corner, pos, dim; + glm::vec2 uv1,uv2, corner, pos, dim; float dp; int icon; diff --git a/src/ui/controls/group.h b/src/ui/controls/group.h index fb583aca..3f2afd7c 100644 --- a/src/ui/controls/group.h +++ b/src/ui/controls/group.h @@ -30,7 +30,7 @@ public: CGroup(); virtual ~CGroup(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/image.cpp b/src/ui/controls/image.cpp index 21298de9..1767faa5 100644 --- a/src/ui/controls/image.cpp +++ b/src/ui/controls/image.cpp @@ -47,7 +47,7 @@ CImage::~CImage() // Creates a new button. -bool CImage::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CImage::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -88,7 +88,7 @@ bool CImage::EventProcess(const Event &event) void CImage::Draw() { - Math::Point uv1,uv2, corner, pos, dim; + glm::vec2 uv1,uv2, corner, pos, dim; float dp; if ( (m_state & STATE_VISIBLE) == 0 ) return; diff --git a/src/ui/controls/image.h b/src/ui/controls/image.h index f7bfd8ff..7f0543da 100644 --- a/src/ui/controls/image.h +++ b/src/ui/controls/image.h @@ -30,7 +30,7 @@ public: CImage (); virtual ~CImage(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/key.cpp b/src/ui/controls/key.cpp index b5b73d81..fd4068e0 100644 --- a/src/ui/controls/key.cpp +++ b/src/ui/controls/key.cpp @@ -45,7 +45,7 @@ CKey::~CKey() m_input = nullptr; } -bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +bool CKey::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -128,7 +128,7 @@ void CKey::Draw() if ((m_state & STATE_VISIBLE) == 0) return; - Math::Point iDim = m_dim; + glm::vec2 iDim = m_dim; m_dim.x = 100.0f/640.0f; if (m_state & STATE_SHADOW) @@ -180,7 +180,7 @@ void CKey::Draw() std::string keyName = m_input->GetKeysString(m_binding); - Math::Point pos; + glm::vec2 pos; pos.x = m_pos.x + m_dim.x * 0.5f; pos.y = m_pos.y + m_dim.y * 0.5f; pos.y -= h; diff --git a/src/ui/controls/key.h b/src/ui/controls/key.h index 8a10af12..120d3606 100644 --- a/src/ui/controls/key.h +++ b/src/ui/controls/key.h @@ -43,7 +43,7 @@ public: virtual ~CKey(); //! Creates a new key slot button - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) override; //! Management of an event bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/label.cpp b/src/ui/controls/label.cpp index cbc7891e..ed999726 100644 --- a/src/ui/controls/label.cpp +++ b/src/ui/controls/label.cpp @@ -41,7 +41,7 @@ CLabel::~CLabel() // Creates a new button. -bool CLabel::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +bool CLabel::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -64,7 +64,7 @@ bool CLabel::EventProcess(const Event &event) void CLabel::Draw() { - Math::Point pos; + glm::vec2 pos = { 0, 0 }; if ( (m_state & STATE_VISIBLE) == 0 ) return; diff --git a/src/ui/controls/label.h b/src/ui/controls/label.h index 31afc7ce..452fd730 100644 --- a/src/ui/controls/label.h +++ b/src/ui/controls/label.h @@ -32,7 +32,7 @@ public: CLabel(); virtual ~CLabel(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) override; bool EventProcess(const Event &event) override; void Draw() override; diff --git a/src/ui/controls/list.cpp b/src/ui/controls/list.cpp index 1c57aa56..fb8d7c41 100644 --- a/src/ui/controls/list.cpp +++ b/src/ui/controls/list.cpp @@ -68,7 +68,7 @@ CList::~CList() // and try to scale items to some size, so that dim of the list would not change after // adjusting -bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand) +bool CList::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg, float expand) { m_expand = expand; @@ -84,7 +84,7 @@ bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMs } // Should never be called -bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CList::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { assert(false); return false; @@ -95,7 +95,7 @@ bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventTy bool CList::MoveAdjust() { - Math::Point ipos, idim, ppos, ddim; + glm::vec2 ipos, idim, ppos, ddim; float marging, h; for (auto& button : m_buttons) @@ -183,13 +183,13 @@ EventType CList::GetEventMsgScroll() } -void CList::SetPos(Math::Point pos) +void CList::SetPos(const glm::vec2& pos) { CControl::SetPos(pos); } -void CList::SetDim(Math::Point dim) +void CList::SetDim(const glm::vec2& dim) { m_dim = dim; MoveAdjust(); @@ -350,7 +350,7 @@ bool CList::EventProcess(const Event &event) void CList::Draw() { - Math::Point uv1, uv2, corner, pos, dim, ppos, ddim; + glm::vec2 uv1, uv2, corner, pos, dim, ppos, ddim; float dp; int i; char text[100]; @@ -548,8 +548,10 @@ void CList::Draw() // Displays text in a box. -void CList::DrawCase(const char* text, Math::Point pos, float width, Gfx::TextAlign justif) +void CList::DrawCase(const char* text, const glm::vec2& position, float width, Gfx::TextAlign justif) { + glm::vec2 pos = position; + if (justif == Gfx::TEXT_ALIGN_CENTER) pos.x += width / 2.0f; else if (justif == Gfx::TEXT_ALIGN_RIGHT) diff --git a/src/ui/controls/list.h b/src/ui/controls/list.h index 69eb4fe0..ac79670e 100644 --- a/src/ui/controls/list.h +++ b/src/ui/controls/list.h @@ -44,10 +44,10 @@ public: CList(); ~CList(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand); + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg, float expand); - void SetPos(Math::Point pos) override; - void SetDim(Math::Point dim) override; + void SetPos(const glm::vec2& pos) override; + void SetDim(const glm::vec2& dim) override; bool SetState(int state, bool bState) override; bool SetState(int state) override; @@ -92,11 +92,11 @@ protected: void UpdateButton(); void UpdateScroll(); void MoveScroll(); - void DrawCase(const char* text, Math::Point pos, float width, Gfx::TextAlign justif); + void DrawCase(const char* text, const glm::vec2& pos, float width, Gfx::TextAlign justif); private: // Overridden to avoid warning about hiding the virtual function - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; protected: std::array, LISTMAXDISPLAY> m_buttons; diff --git a/src/ui/controls/map.cpp b/src/ui/controls/map.cpp index ff11b58a..490228a7 100644 --- a/src/ui/controls/map.cpp +++ b/src/ui/controls/map.cpp @@ -31,7 +31,6 @@ #include "level/robotmain.h" #include "math/geometry.h" -#include "math/point.h" #include "object/interface/controllable_object.h" #include "object/interface/transportable_object.h" @@ -88,7 +87,7 @@ CMap::~CMap() // Creates a new button. -bool CMap::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +bool CMap::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -231,17 +230,18 @@ bool CMap::EventProcess(const Event &event) // Adjusts the offset to not exceed the card. -Math::Point CMap::AdjustOffset(Math::Point offset) +glm::vec2 CMap::AdjustOffset(const glm::vec2& offset) { - float limit; + glm::vec2 off = offset; - limit = m_half - m_half / m_zoom; - if ( offset.x < -limit ) offset.x = -limit; - if ( offset.x > limit ) offset.x = limit; - if ( offset.y < -limit ) offset.y = -limit; - if ( offset.y > limit ) offset.y = limit; + float limit = m_half - m_half / m_zoom; - return offset; + if (off.x < -limit) off.x = -limit; + if (off.x > limit) off.x = limit; + if (off.y < -limit) off.y = -limit; + if (off.y > limit) off.y = limit; + + return off; } // Indicates the object with the mouse hovers over. @@ -269,11 +269,13 @@ void CMap::SetHighlight(CObject* pObj) // Detects an object in the map. -CObject* CMap::DetectObject(Math::Point pos, bool &bInMap) +CObject* CMap::DetectObject(const glm::vec2& position, bool &bInMap) { float dist, min; int best; + glm::vec2 pos = position; + bInMap = false; if ( pos.x < m_pos.x || pos.y < m_pos.y || @@ -315,7 +317,7 @@ CObject* CMap::DetectObject(Math::Point pos, bool &bInMap) // Selects an object. -void CMap::SelectObject(Math::Point pos) +void CMap::SelectObject(const glm::vec2& pos) { CObject *pObj; bool bInMap; @@ -330,7 +332,7 @@ void CMap::SelectObject(Math::Point pos) void CMap::Draw() { - Math::Point uv1, uv2; + glm::vec2 uv1, uv2; int i; if ( (m_state & STATE_VISIBLE) == 0 ) @@ -398,9 +400,9 @@ void CMap::Draw() // Computing a point for drawFocus. -Math::Point CMap::MapInter(Math::Point pos, float dir) +glm::vec2 CMap::MapInter(const glm::vec2& pos, float dir) { - Math::Point p1; + glm::vec2 p1; float limit; p1.x = pos.x + 1.0f; @@ -443,14 +445,16 @@ Math::Point CMap::MapInter(Math::Point pos, float dir) // Draw the field of vision of the selected object. -void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color) +void CMap::DrawFocus(const glm::vec2& position, float dir, ObjectType type, MapColor color) { - Math::Point p0, p1, p2, uv1, uv2, rel; + glm::vec2 p0, p1, p2, uv1, uv2, rel; float aMin, aMax, aOct, focus, a; float limit[5]; bool bEnding; int quart; + glm::vec2 pos = position; + if (m_bToy || !m_fixImage.empty()) return; // map with still image? if ( color != MAPCOLOR_MOVE ) return; @@ -525,12 +529,14 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color // Draw an object. -void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor color, +void CMap::DrawObject(const glm::vec2& position, float dir, ObjectType type, MapColor color, bool bSelect, bool bHilite) { - Math::Point p1, p2, p3, p4, p5, dim, uv1, uv2; + glm::vec2 p1, p2, p3, p4, p5, dim, uv1, uv2; bool bOut, bUp, bDown, bLeft, bRight; + glm::vec2 pos = position; + pos.x = (pos.x-m_offset.x)*(m_zoom*0.5f)/m_half+0.5f; pos.y = (pos.y-m_offset.y)*(m_zoom*0.5f)/m_half+0.5f; @@ -796,10 +802,10 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo // Draws the icon of an object. -void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, +void CMap::DrawObjectIcon(const glm::vec2& pos, const glm::vec2& dim, MapColor color, ObjectType type, bool bHilite) { - Math::Point ppos, ddim, uv1, uv2; + glm::vec2 ppos, ddim, uv1, uv2; float dp; int icon; @@ -928,9 +934,11 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, // Draw the object with the mouse hovers over. -void CMap::DrawHighlight(Math::Point pos) +void CMap::DrawHighlight(const glm::vec2& position) { - Math::Point dim, uv1, uv2; + glm::vec2 dim, uv1, uv2; + + glm::vec2 pos = position; if (m_bToy || !m_fixImage.empty()) return; // map with still image? @@ -957,7 +965,7 @@ void CMap::DrawHighlight(Math::Point pos) // Draws a triangular icon. -void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2) +void CMap::DrawTriangle(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& p3, const glm::vec2& uv1, const glm::vec2& uv2) { Gfx::Vertex2D vertex[3]; // 1 triangle @@ -973,7 +981,7 @@ void CMap::DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Po // Draw a pentagon icon (a 5 rating, what!). -void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2) +void CMap::DrawPenta(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& p3, const glm::vec2& p4, const glm::vec2& p5, const glm::vec2& uv1, const glm::vec2& uv2) { Gfx::Vertex2D vertex[5]; // 1 pentagon @@ -991,10 +999,10 @@ void CMap::DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point // Draw the vertex array. -void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom) +void CMap::DrawVertex(const glm::vec2& uv1, const glm::vec2& uv2, float zoom) { Gfx::Vertex2D vertex[4]; // 2 triangles - Math::Point p1, p2, c; + glm::vec2 p1, p2, c; auto renderer = m_engine->GetDevice()->GetUIRenderer(); @@ -1172,8 +1180,8 @@ void CMap::UpdateObject(CObject* pObj) { ObjectType type; MapColor color; - Math::Vector pos; - Math::Point ppos; + Math::Vector pos; + glm::vec2 ppos; float dir; if ( !m_bEnable ) return; diff --git a/src/ui/controls/map.h b/src/ui/controls/map.h index c41f07a4..e14f1d4b 100644 --- a/src/ui/controls/map.h +++ b/src/ui/controls/map.h @@ -60,7 +60,7 @@ struct MapObject CObject* object = nullptr; MapColor color = MAPCOLOR_NULL; ObjectType type = OBJECT_NULL; - Math::Point pos; + glm::vec2 pos = { 0, 0 }; float dir = 0.0f; }; @@ -72,7 +72,7 @@ public: CMap(); ~CMap(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) override; bool EventProcess(const Event &event) override; void Draw() override; @@ -100,20 +100,20 @@ public: void FlushObject(); void UpdateObject(CObject* pObj); - CObject* DetectObject(Math::Point pos, bool &bInMap); + CObject* DetectObject(const glm::vec2& pos, bool &bInMap); void SetHighlight(CObject* pObj); protected: - Math::Point AdjustOffset(Math::Point offset); - void SelectObject(Math::Point pos); - Math::Point MapInter(Math::Point pos, float dir); - void DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color); - void DrawObject(Math::Point pos, float dir, ObjectType type, MapColor color, bool bSelect, bool bHilite); - void DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, ObjectType type, bool bHilite); - void DrawHighlight(Math::Point pos); - void DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2); - void DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2); - void DrawVertex(Math::Point uv1, Math::Point uv2, float zoom); + glm::vec2 AdjustOffset(const glm::vec2& offset); + void SelectObject(const glm::vec2& pos); + glm::vec2 MapInter(const glm::vec2& pos, float dir); + void DrawFocus(const glm::vec2& pos, float dir, ObjectType type, MapColor color); + void DrawObject(const glm::vec2& pos, float dir, ObjectType type, MapColor color, bool bSelect, bool bHilite); + void DrawObjectIcon(const glm::vec2& pos, const glm::vec2& dim, MapColor color, ObjectType type, bool bHilite); + void DrawHighlight(const glm::vec2& pos); + void DrawTriangle(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& p3, const glm::vec2& uv1, const glm::vec2& uv2); + void DrawPenta(const glm::vec2& p1, const glm::vec2& p2, const glm::vec2& p3, const glm::vec2& p4, const glm::vec2& p5, const glm::vec2& uv1, const glm::vec2& uv2); + void DrawVertex(const glm::vec2& uv1, const glm::vec2& uv2, float zoom); protected: Gfx::CTerrain* m_terrain; @@ -124,7 +124,7 @@ protected: float m_time; float m_half; float m_zoom; - Math::Point m_offset; + glm::vec2 m_offset; float m_angle; Gfx::Color m_floorColor; Gfx::Color m_waterColor; @@ -132,8 +132,8 @@ protected: int m_totalFix; int m_totalMove; int m_highlightRank; - Math::Point m_mapPos; - Math::Point m_mapDim; + glm::vec2 m_mapPos; + glm::vec2 m_mapDim; bool m_bRadar; std::string m_fixImage; int m_mode; diff --git a/src/ui/controls/scroll.cpp b/src/ui/controls/scroll.cpp index 56df09d0..07c816b6 100644 --- a/src/ui/controls/scroll.cpp +++ b/src/ui/controls/scroll.cpp @@ -54,7 +54,7 @@ CScroll::~CScroll() // Creates a new button. -bool CScroll::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +bool CScroll::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventMsg); @@ -64,13 +64,13 @@ bool CScroll::Create(Math::Point pos, Math::Point dim, int icon, EventType event } -void CScroll::SetPos(Math::Point pos) +void CScroll::SetPos(const glm::vec2& pos) { CControl::SetPos(pos); MoveAdjust(); } -void CScroll::SetDim(Math::Point dim) +void CScroll::SetDim(const glm::vec2& dim) { CControl::SetDim(dim); MoveAdjust(); @@ -80,7 +80,7 @@ void CScroll::SetDim(Math::Point dim) void CScroll::MoveAdjust() { - Math::Point pos, dim; + glm::vec2 pos, dim; if ( m_dim.y < m_dim.x*2.0f ) // very short lift? { @@ -92,14 +92,14 @@ void CScroll::MoveAdjust() if (m_buttonUp == nullptr) { m_buttonUp = MakeUnique(); - m_buttonUp->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 49, EVENT_NULL); + m_buttonUp->Create({ 0.0f, 0.0f }, { 0.0f, 0.0f }, 49, EVENT_NULL); m_buttonUp->SetRepeat(true); } if (m_buttonDown == nullptr) { m_buttonDown = MakeUnique(); - m_buttonDown->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 50, EVENT_NULL); + m_buttonDown->Create({ 0.0f, 0.0f }, { 0.0f, 0.0f }, 50, EVENT_NULL); m_buttonDown->SetRepeat(true); } } @@ -131,7 +131,7 @@ void CScroll::MoveAdjust() void CScroll::AdjustGlint() { - Math::Point ref; + glm::vec2 ref; float hButton, h; hButton = m_buttonUp?m_dim.x/0.75f:0.0f; @@ -222,7 +222,7 @@ bool CScroll::EventProcess(const Event &event) { if ( CControl::Detect(event.mousePos) ) { - Math::Point pos, dim; + glm::vec2 pos, dim; pos.y = m_pos.y+hButton; dim.y = m_dim.y-hButton*2.0f; @@ -303,7 +303,7 @@ bool CScroll::EventProcess(const Event &event) void CScroll::Draw() { - Math::Point pos, dim, ppos, ddim; + glm::vec2 pos, dim, ppos, ddim; float hButton; int icon, n, i; @@ -358,9 +358,9 @@ void CScroll::Draw() // Draws a rectangle. -void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon) +void CScroll::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon) { - Math::Point uv1, uv2; + glm::vec2 uv1, uv2; float ex, dp; auto device = m_engine->GetDevice(); diff --git a/src/ui/controls/scroll.h b/src/ui/controls/scroll.h index fa2fc027..bcc2dc24 100644 --- a/src/ui/controls/scroll.h +++ b/src/ui/controls/scroll.h @@ -40,10 +40,10 @@ public: CScroll(); ~CScroll(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) override; - void SetPos(Math::Point pos) override; - void SetDim(Math::Point dim) override; + void SetPos(const glm::vec2& pos) override; + void SetDim(const glm::vec2& dim) override; bool SetState(int state, bool bState) override; bool SetState(int state) override; @@ -64,7 +64,7 @@ public: protected: void MoveAdjust(); void AdjustGlint(); - void DrawVertex(Math::Point pos, Math::Point dim, int icon); + void DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon); protected: std::unique_ptr m_buttonUp; @@ -75,7 +75,7 @@ protected: float m_step; bool m_bCapture; - Math::Point m_pressPos; + glm::vec2 m_pressPos; float m_pressValue; }; diff --git a/src/ui/controls/shortcut.cpp b/src/ui/controls/shortcut.cpp index 2f2b9284..1bf4b16c 100644 --- a/src/ui/controls/shortcut.cpp +++ b/src/ui/controls/shortcut.cpp @@ -48,7 +48,7 @@ CShortcut::~CShortcut() // Creates a new button. -bool CShortcut::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CShortcut::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -137,7 +137,7 @@ void CShortcut::Draw() if ( m_state & STATE_FRAME ) { - Math::Point p1, p2, c, uv1, uv2; + glm::vec2 p1, p2, c, uv1, uv2; float dp; m_engine->SetTexture("textures/interface/button2.png"); @@ -177,7 +177,7 @@ void CShortcut::Draw() if ( (m_state & STATE_RUN) && Math::Mod(m_time, 0.7f) >= 0.3f ) { - Math::Point uv1, uv2; + glm::vec2 uv1, uv2; float dp; m_engine->SetTexture("textures/interface/button3.png"); @@ -198,24 +198,24 @@ void CShortcut::Draw() } if ( (m_state & STATE_DAMAGE) && Math::Mod(m_time, 0.7f) >= 0.3f ) { - Math::Point uv1, uv2; - float dp; + glm::vec2 uv1, uv2; + float dp; - m_engine->SetTexture("textures/interface/button2.png"); - m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); + m_engine->SetTexture("textures/interface/button2.png"); + m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); - uv1.x = 159.0f/256.0f; - uv1.y = 240.0f/256.0f; - uv2.x = 145.0f/256.0f; - uv2.y = 256.0f/256.0f; + uv1.x = 159.0f / 256.0f; + uv1.y = 240.0f / 256.0f; + uv2.x = 145.0f / 256.0f; + uv2.y = 256.0f / 256.0f; - dp = 0.5f/256.0f; - uv1.x += dp; - uv1.y += dp; - uv2.x -= dp; - uv2.y -= dp; + dp = 0.5f / 256.0f; + uv1.x += dp; + uv1.y += dp; + uv2.x -= dp; + uv2.y -= dp; - DrawIcon(m_pos, m_dim, uv1, uv2); + DrawIcon(m_pos, m_dim, uv1, uv2); } } @@ -224,7 +224,7 @@ void CShortcut::Draw() void CShortcut::DrawVertex(int icon, float zoom) { Gfx::Vertex2D vertex[4]; // 2 triangles - Math::Point p1, p2, c; + glm::vec2 p1, p2, c; float u1, u2, v1, v2, dp; p1.x = m_pos.x; diff --git a/src/ui/controls/shortcut.h b/src/ui/controls/shortcut.h index 35ff3ac8..0282d3d1 100644 --- a/src/ui/controls/shortcut.h +++ b/src/ui/controls/shortcut.h @@ -32,7 +32,7 @@ public: CShortcut(); ~CShortcut(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; diff --git a/src/ui/controls/slider.cpp b/src/ui/controls/slider.cpp index 0d041f56..3af121b8 100644 --- a/src/ui/controls/slider.cpp +++ b/src/ui/controls/slider.cpp @@ -66,7 +66,7 @@ CSlider::~CSlider() // Creates a new button. -bool CSlider::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CSlider::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventType); @@ -76,13 +76,13 @@ bool CSlider::Create(Math::Point pos, Math::Point dim, int icon, EventType event } -void CSlider::SetPos(Math::Point pos) +void CSlider::SetPos(const glm::vec2& pos) { CControl::SetPos(pos); MoveAdjust(); } -void CSlider::SetDim(Math::Point dim) +void CSlider::SetDim(const glm::vec2& dim) { CControl::SetDim(dim); MoveAdjust(); @@ -90,7 +90,7 @@ void CSlider::SetDim(Math::Point dim) void CSlider::MoveAdjust() { - Math::Point pos, dim; + glm::vec2 pos, dim; m_bHoriz = ( m_dim.x > m_dim.y ); @@ -106,7 +106,7 @@ void CSlider::MoveAdjust() if (m_buttonLeft == nullptr) { m_buttonLeft = MakeUnique(); - m_buttonLeft->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?55:49, EVENT_NULL); // Create({ 0.0f, 0.0f }, { 0.0f, 0.0f }, m_bHoriz ? 55 : 49, EVENT_NULL); // SetRepeat(true); if ( m_state & STATE_SHADOW ) m_buttonLeft->SetState(STATE_SHADOW); } @@ -114,7 +114,7 @@ void CSlider::MoveAdjust() if (m_buttonRight == nullptr) { m_buttonRight = MakeUnique(); - m_buttonRight->Create(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), m_bHoriz?48:50, EVENT_NULL); // >/v + m_buttonRight->Create({ 0.0f, 0.0f }, { 0.0f, 0.0f }, m_bHoriz ? 48 : 50, EVENT_NULL); // >/v m_buttonRight->SetRepeat(true); if ( m_state & STATE_SHADOW ) m_buttonRight->SetState(STATE_SHADOW); } @@ -169,7 +169,7 @@ void CSlider::MoveAdjust() void CSlider::AdjustGlint() { - Math::Point ref; + glm::vec2 ref; float w; if ( m_bHoriz ) @@ -232,7 +232,7 @@ bool CSlider::ClearState(int state) bool CSlider::EventProcess(const Event &event) { - Math::Point pos, dim; + glm::vec2 pos, dim; float value; if ( (m_state & STATE_VISIBLE) == 0 ) return true; @@ -368,7 +368,7 @@ bool CSlider::EventProcess(const Event &event) void CSlider::Draw() { - Math::Point pos, dim, ppos, ddim, spos; + glm::vec2 pos, dim, ppos, ddim, spos; int icon; float h; @@ -484,9 +484,9 @@ std::string CSlider::GetLabel() // Draws a rectangle. -void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon) +void CSlider::DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon) { - Math::Point uv1, uv2, corner; + glm::vec2 uv1, uv2, corner; float ex, dp; auto device = m_engine->GetDevice(); diff --git a/src/ui/controls/slider.h b/src/ui/controls/slider.h index 193ae418..f1f45adb 100644 --- a/src/ui/controls/slider.h +++ b/src/ui/controls/slider.h @@ -34,10 +34,10 @@ public: CSlider(); ~CSlider(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; - void SetPos(Math::Point pos) override; - void SetDim(Math::Point dim) override; + void SetPos(const glm::vec2& pos) override; + void SetDim(const glm::vec2& dim) override; bool SetState(int state, bool bState) override; bool SetState(int state) override; @@ -57,7 +57,7 @@ public: protected: void MoveAdjust(); void AdjustGlint(); - void DrawVertex(Math::Point pos, Math::Point dim, int icon); + void DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon); virtual std::string GetLabel(); protected: @@ -73,7 +73,7 @@ protected: float m_marginButton; bool m_bCapture; - Math::Point m_pressPos; + glm::vec2 m_pressPos; float m_pressValue; }; diff --git a/src/ui/controls/target.cpp b/src/ui/controls/target.cpp index 4db080f7..1862d419 100644 --- a/src/ui/controls/target.cpp +++ b/src/ui/controls/target.cpp @@ -43,7 +43,7 @@ CTarget::~CTarget() // Creates a new button. -bool CTarget::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) +bool CTarget::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) { if ( eventType == EVENT_NULL ) eventType = GetUniqueEventType(); @@ -114,7 +114,7 @@ void CTarget::Draw() // Returns the tooltip. -bool CTarget::GetTooltip(Math::Point pos, std::string &name) +bool CTarget::GetTooltip(const glm::vec2& pos, std::string &name) { if ( (m_state & STATE_VISIBLE) == 0 ) return false; @@ -133,7 +133,7 @@ bool CTarget::GetTooltip(Math::Point pos, std::string &name) // Detects the object aimed by the mouse. -CObject* CTarget::DetectFriendObject(Math::Point pos) +CObject* CTarget::DetectFriendObject(const glm::vec2& pos) { Math::Vector p; int objRank = m_engine->DetectObject(pos, p); diff --git a/src/ui/controls/target.h b/src/ui/controls/target.h index 06521ce7..251720f3 100644 --- a/src/ui/controls/target.h +++ b/src/ui/controls/target.h @@ -37,14 +37,14 @@ public: CTarget(); ~CTarget(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override; + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventType) override; bool EventProcess(const Event &event) override; void Draw() override; - bool GetTooltip(Math::Point pos, std::string &name) override; + bool GetTooltip(const glm::vec2& pos, std::string &name) override; protected: - CObject* DetectFriendObject(Math::Point pos); + CObject* DetectFriendObject(const glm::vec2& pos); }; diff --git a/src/ui/controls/window.cpp b/src/ui/controls/window.cpp index c3f6c8bb..d709bb80 100644 --- a/src/ui/controls/window.cpp +++ b/src/ui/controls/window.cpp @@ -54,8 +54,8 @@ CWindow::CWindow() : CControl() m_bMinimized = false; m_bFixed = false; - m_minDim = Math::Point(0.0f, 0.0f); - m_maxDim = Math::Point(1.0f, 1.0f); + m_minDim = { 0.0f, 0.0f }; + m_maxDim = { 1.0f, 1.0f }; m_bMovable = false; m_bRedim = false; @@ -88,7 +88,7 @@ void CWindow::Flush() // Creates a new window. -bool CWindow::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +bool CWindow::Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventType(); @@ -97,7 +97,7 @@ bool CWindow::Create(Math::Point pos, Math::Point dim, int icon, EventType event } template -ControlClass* CWindow::CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +ControlClass* CWindow::CreateControl(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { auto control = MakeUnique(); control->Create(pos, dim, icon, eventMsg); @@ -109,49 +109,49 @@ ControlClass* CWindow::CreateControl(Math::Point pos, Math::Point dim, int icon, // Creates a new button. -CButton* CWindow::CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CButton* CWindow::CreateButton(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CColor* CWindow::CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CColor* CWindow::CreateColor(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CCheck* CWindow::CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CCheck* CWindow::CreateCheck(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CKey* CWindow::CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CKey* CWindow::CreateKey(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CGroup* CWindow::CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CGroup* CWindow::CreateGroup(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new button. -CImage* CWindow::CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CImage* CWindow::CreateImage(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new label. -CLabel* CWindow::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name) +CLabel* CWindow::CreateLabel(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg, std::string name) { CLabel* label = CreateControl(pos, dim, icon, eventMsg); @@ -166,21 +166,21 @@ CLabel* CWindow::CreateLabel(Math::Point pos, Math::Point dim, int icon, EventTy // Creates a new editable pave. -CEdit* CWindow::CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CEdit* CWindow::CreateEdit(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new editable pave. -CEditValue* CWindow::CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CEditValue* CWindow::CreateEditValue(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { return CreateControl(pos, dim, icon, eventMsg); } // Creates a new elevator. -CScroll* CWindow::CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CScroll* CWindow::CreateScroll(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -190,7 +190,7 @@ CScroll* CWindow::CreateScroll(Math::Point pos, Math::Point dim, int icon, Event // Creates a new cursor. -CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CSlider* CWindow::CreateSlider(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -198,7 +198,7 @@ CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, Event return CreateControl(pos, dim, icon, eventMsg); } -CEnumSlider* CWindow::CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CEnumSlider* CWindow::CreateEnumSlider(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -211,7 +211,7 @@ CEnumSlider* CWindow::CreateEnumSlider(Math::Point pos, Math::Point dim, int ico // and try to scale items to some size, so that dim of the list would not change after // adjusting -CList* CWindow::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand) +CList* CWindow::CreateList(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg, float expand) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -225,7 +225,7 @@ CList* CWindow::CreateList(Math::Point pos, Math::Point dim, int icon, EventType // Creates a new shortcut. -CShortcut* CWindow::CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CShortcut* CWindow::CreateShortcut(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -235,7 +235,7 @@ CShortcut* CWindow::CreateShortcut(Math::Point pos, Math::Point dim, int icon, E // Creates a new card. -CMap* CWindow::CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CMap* CWindow::CreateMap(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -245,7 +245,7 @@ CMap* CWindow::CreateMap(Math::Point pos, Math::Point dim, int icon, EventType e // Creates a new gauge. -CGauge* CWindow::CreateGauge(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CGauge* CWindow::CreateGauge(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -255,7 +255,7 @@ CGauge* CWindow::CreateGauge(Math::Point pos, Math::Point dim, int icon, EventTy // Creates a new target. -CTarget* CWindow::CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) +CTarget* CWindow::CreateTarget(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) { if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); @@ -299,7 +299,7 @@ CControl* CWindow::SearchControl(EventType eventMsg) // Makes the tooltip binds to the window. -bool CWindow::GetTooltip(Math::Point pos, std::string &name) +bool CWindow::GetTooltip(const glm::vec2& pos, std::string &name) { for (auto& control : m_controls) { @@ -373,14 +373,16 @@ void CWindow::SetName(std::string name, bool tooltip) } -void CWindow::SetPos(Math::Point pos) +void CWindow::SetPos(const glm::vec2& pos) { CControl::SetPos(pos); MoveAdjust(); } -void CWindow::SetDim(Math::Point dim) +void CWindow::SetDim(const glm::vec2& dimension) { + glm::vec2 dim = dimension; + if ( dim.x < m_minDim.x ) dim.x = m_minDim.x; if ( dim.x > m_maxDim.x ) dim.x = m_maxDim.x; if ( dim.y < m_minDim.y ) dim.y = m_minDim.y; @@ -393,14 +395,14 @@ void CWindow::SetDim(Math::Point dim) void CWindow::MoveAdjust() { float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); - Math::Point dim; + glm::vec2 dim; dim.y = h*1.2f; dim.x = dim.y*0.75f; float offset = 0.0f; if (m_buttonClose != nullptr) { - Math::Point pos; + glm::vec2 pos; pos.x = m_pos.x+m_dim.x-0.01f-dim.x; pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f; m_buttonClose->SetPos(pos); @@ -414,7 +416,7 @@ void CWindow::MoveAdjust() if (m_buttonFull != nullptr) { - Math::Point pos; + glm::vec2 pos; pos.x = m_pos.x+m_dim.x-0.01f-dim.x-offset; pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f; m_buttonFull->SetPos(pos); @@ -423,7 +425,7 @@ void CWindow::MoveAdjust() if (m_buttonReduce != nullptr) { - Math::Point pos; + glm::vec2 pos; pos.x = m_pos.x+m_dim.x-0.01f-dim.x*2.0f-offset; pos.y = m_pos.y+m_dim.y-0.01f-h*1.2f; m_buttonReduce->SetPos(pos); @@ -432,22 +434,22 @@ void CWindow::MoveAdjust() } -void CWindow::SetMinDim(Math::Point dim) +void CWindow::SetMinDim(const glm::vec2& dim) { m_minDim = dim; } -void CWindow::SetMaxDim(Math::Point dim) +void CWindow::SetMaxDim(const glm::vec2& dim) { m_maxDim = dim; } -Math::Point CWindow::GetMinDim() +glm::vec2 CWindow::GetMinDim() { return m_minDim; } -Math::Point CWindow::GetMaxDim() +glm::vec2 CWindow::GetMaxDim() { return m_maxDim; } @@ -611,9 +613,9 @@ EventType CWindow::GetEventTypeClose() // Detects whether the mouse is in an edge of the window, to resize it. // Bit returns: 0 = left, 1 = down, 2 = right, 3 = up, 1 = all. -int CWindow::BorderDetect(Math::Point pos) +int CWindow::BorderDetect(const glm::vec2& pos) { - Math::Point dim; + glm::vec2 dim; float h; int flags; @@ -752,7 +754,7 @@ bool CWindow::EventProcess(const Event &event) if ( event.type == EVENT_MOUSE_MOVE && m_bCapture ) { - Math::Point pos = event.mousePos; + glm::vec2 pos = event.mousePos; if ( m_pressFlags == -1 ) // all moves? { m_pos.x += pos.x-m_pressPos.x; @@ -831,10 +833,10 @@ void CWindow::Draw() { float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize); - Math::Point pos, dim; + glm::vec2 pos, dim; // Draws the shadow under the title bar. { - Math::Point sPos, sDim; + glm::vec2 sPos, sDim; pos.x = m_pos.x+0.01f; dim.x = m_dim.x-0.02f; @@ -894,12 +896,15 @@ void CWindow::Draw() // Draws a rectangle. -void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) +void CWindow::DrawVertex(const glm::vec2& position, const glm::vec2& dimension, int icon) { - Math::Point p1, p2, uv1, uv2, corner; + glm::vec2 p1, p2, uv1, uv2, corner; float dp; int i; + glm::vec2 pos = position; + glm::vec2 dim = dimension; + auto device = m_engine->GetDevice(); dp = 0.5f/256.0f; @@ -1266,9 +1271,9 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon) // Draws hatching. -void CWindow::DrawHach(Math::Point pos, Math::Point dim) +void CWindow::DrawHach(const glm::vec2& pos, const glm::vec2& dim) { - Math::Point ppos, ddim, uv1, uv2; + glm::vec2 ppos, ddim, uv1, uv2; float dp, max, ndim; bool bStop; diff --git a/src/ui/controls/window.h b/src/ui/controls/window.h index 6e620c4b..8e0eeace 100644 --- a/src/ui/controls/window.h +++ b/src/ui/controls/window.h @@ -55,24 +55,24 @@ public: ~CWindow(); void Flush(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override; - CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name); - CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CEnumSlider* CreateEnumSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f); - CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CGauge* CreateGauge(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + bool Create(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg) override; + CButton* CreateButton(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CColor* CreateColor(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CCheck* CreateCheck(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CKey* CreateKey(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CGroup* CreateGroup(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CImage* CreateImage(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CLabel* CreateLabel(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg, std::string name); + CEdit* CreateEdit(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CEditValue* CreateEditValue(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CScroll* CreateScroll(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CSlider* CreateSlider(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CEnumSlider* CreateEnumSlider(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CList* CreateList(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg, float expand=1.2f); + CShortcut* CreateShortcut(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CMap* CreateMap(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CGauge* CreateGauge(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); + CTarget* CreateTarget(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); bool DeleteControl(EventType eventMsg); CControl* SearchControl(EventType eventMsg); @@ -85,13 +85,13 @@ public: void SetTrashEvent(bool bTrash); bool GetTrashEvent(); - void SetPos(Math::Point pos) override; - void SetDim(Math::Point dim) override; + void SetPos(const glm::vec2& pos) override; + void SetDim(const glm::vec2& dim) override; - void SetMinDim(Math::Point dim); - void SetMaxDim(Math::Point dim); - Math::Point GetMinDim(); - Math::Point GetMaxDim(); + void SetMinDim(const glm::vec2& dim); + void SetMaxDim(const glm::vec2& dim); + glm::vec2 GetMinDim(); + glm::vec2 GetMaxDim(); void SetMovable(bool bMode); bool GetMovable(); @@ -109,7 +109,7 @@ public: void SetFixed(bool bFix); bool GetFixed(); - bool GetTooltip(Math::Point pos, std::string &name) override; + bool GetTooltip(const glm::vec2& pos, std::string &name) override; bool EventProcess(const Event &event) override; @@ -118,13 +118,13 @@ public: void SetFocus(CControl* focusControl) override; protected: - int BorderDetect(Math::Point pos); + int BorderDetect(const glm::vec2& pos); void AdjustButtons(); void MoveAdjust(); - void DrawVertex(Math::Point pos, Math::Point dim, int icon); - void DrawHach(Math::Point pos, Math::Point dim); + void DrawVertex(const glm::vec2& pos, const glm::vec2& dim, int icon); + void DrawHach(const glm::vec2& pos, const glm::vec2& dim); template - ControlClass* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + ControlClass* CreateControl(const glm::vec2& pos, const glm::vec2& dim, int icon, EventType eventMsg); protected: std::vector> m_controls; @@ -134,8 +134,8 @@ protected: bool m_bMinimized; bool m_bFixed; - Math::Point m_minDim; - Math::Point m_maxDim; + glm::vec2 m_minDim; + glm::vec2 m_maxDim; std::unique_ptr m_buttonReduce; std::unique_ptr m_buttonFull; @@ -145,7 +145,7 @@ protected: bool m_bRedim; bool m_bClosable; bool m_bCapture; - Math::Point m_pressPos; + glm::vec2 m_pressPos; int m_pressFlags; Gfx::EngineMouseType m_pressMouse; };