Index: ps/trunk/source/ps/Shapes.cpp =================================================================== --- ps/trunk/source/ps/Shapes.cpp (revision 25164) +++ ps/trunk/source/ps/Shapes.cpp (nonexistent) @@ -1,221 +0,0 @@ -/* Copyright (C) 2021 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#include "precompiled.h" - -#include "Shapes.h" - -#include "maths/Size2D.h" -#include "maths/Vector2D.h" - -CRect::CRect() : - left(0.f), top(0.f), right(0.f), bottom(0.f) -{ -} - -CRect::CRect(const CRect& rect) : - left(rect.left), top(rect.top), right(rect.right), bottom(rect.bottom) -{ -} - -CRect::CRect(const CVector2D& pos) : - left(pos.X), top(pos.Y), right(pos.X), bottom(pos.Y) -{ -} - -CRect::CRect(const CSize2D& size) : - left(0.f), top(0.f), right(size.Width), bottom(size.Height) -{ -} - -CRect::CRect(const CVector2D& upperleft, const CVector2D& bottomright) : - left(upperleft.X), top(upperleft.Y), right(bottomright.X), bottom(bottomright.Y) -{ -} - -CRect::CRect(const CVector2D& pos, const CSize2D& size) : - left(pos.X), top(pos.Y), right(pos.X + size.Width), bottom(pos.Y + size.Height) -{ -} - -CRect::CRect(const float l, const float t, const float r, const float b) : - left(l), top(t), right(r), bottom(b) -{ -} - -CRect& CRect::operator=(const CRect& a) -{ - left = a.left; - top = a.top; - right = a.right; - bottom = a.bottom; - return *this; -} - -bool CRect::operator==(const CRect &a) const -{ - return (left == a.left && - top == a.top && - right == a.right && - bottom == a.bottom); -} - -bool CRect::operator!=(const CRect& a) const -{ - return !(*this == a); -} - -CRect CRect::operator-() const -{ - return CRect(-left, -top, -right, -bottom); -} - -CRect CRect::operator+() const -{ - return *this; -} - -CRect CRect::operator+(const CRect& a) const -{ - return CRect(left + a.left, top + a.top, right + a.right, bottom + a.bottom); -} - -CRect CRect::operator+(const CVector2D& a) const -{ - return CRect(left + a.X, top + a.Y, right + a.X, bottom + a.Y); -} - -CRect CRect::operator+(const CSize2D& a) const -{ - return CRect(left + a.Width, top + a.Height, right + a.Width, bottom + a.Height); -} - -CRect CRect::operator-(const CRect& a) const -{ - return CRect(left - a.left, top - a.top, right - a.right, bottom - a.bottom); -} - -CRect CRect::operator-(const CVector2D& a) const -{ - return CRect(left - a.X, top - a.Y, right - a.X, bottom - a.Y); -} - -CRect CRect::operator-(const CSize2D& a) const -{ - return CRect(left - a.Width, top - a.Height, right - a.Width, bottom - a.Height); -} - -void CRect::operator+=(const CRect& a) -{ - left += a.left; - top += a.top; - right += a.right; - bottom += a.bottom; -} - -void CRect::operator+=(const CVector2D& a) -{ - left += a.X; - top += a.Y; - right += a.X; - bottom += a.Y; -} - -void CRect::operator+=(const CSize2D& a) -{ - left += a.Width; - top += a.Height; - right += a.Width; - bottom += a.Height; -} - -void CRect::operator-=(const CRect& a) -{ - left -= a.left; - top -= a.top; - right -= a.right; - bottom -= a.bottom; -} - -void CRect::operator-=(const CVector2D& a) -{ - left -= a.X; - top -= a.Y; - right -= a.X; - bottom -= a.Y; -} - -void CRect::operator-=(const CSize2D& a) -{ - left -= a.Width; - top -= a.Height; - right -= a.Width; - bottom -= a.Height; -} - -float CRect::GetWidth() const -{ - return right-left; -} - -float CRect::GetHeight() const -{ - return bottom-top; -} - -CSize2D CRect::GetSize() const -{ - return CSize2D(right - left, bottom - top); -} - -CVector2D CRect::TopLeft() const -{ - return CVector2D(left, top); -} - -CVector2D CRect::TopRight() const -{ - return CVector2D(right, top); -} - -CVector2D CRect::BottomLeft() const -{ - return CVector2D(left, bottom); -} - -CVector2D CRect::BottomRight() const -{ - return CVector2D(right, bottom); -} - -CVector2D CRect::CenterPoint() const -{ - return CVector2D((left + right) / 2.f, (top + bottom) / 2.f); -} - -bool CRect::PointInside(const CVector2D& point) const -{ - return (point.X >= left && - point.X <= right && - point.Y >= top && - point.Y <= bottom); -} - -CRect CRect::Scale(float x, float y) const -{ - return CRect(left * x, top * y, right * x, bottom * y); -} Property changes on: ps/trunk/source/ps/Shapes.cpp ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Index: ps/trunk/source/ps/Shapes.h =================================================================== --- ps/trunk/source/ps/Shapes.h (revision 25164) +++ ps/trunk/source/ps/Shapes.h (nonexistent) @@ -1,121 +0,0 @@ -/* Copyright (C) 2021 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#ifndef INCLUDED_SHAPES -#define INCLUDED_SHAPES - -class CSize2D; -class CVector2D; - - -/** - * Rectangle class used for screen rectangles. It's very similar to the MS - * CRect, but with FLOATS because it's meant to be used with OpenGL which - * takes float values. - */ -class CRect -{ -public: - CRect(); - CRect(const CVector2D& pos); - CRect(const CSize2D& size); - CRect(const CVector2D& upperleft, const CVector2D& bottomright); - CRect(const CVector2D& pos, const CSize2D& size); - CRect(const float l, const float t, const float r, const float b); - CRect(const CRect&); - - CRect& operator=(const CRect& a); - bool operator==(const CRect& a) const; - bool operator!=(const CRect& a) const; - CRect operator-() const; - CRect operator+() const; - - CRect operator+(const CRect& a) const; - CRect operator+(const CVector2D& a) const; - CRect operator+(const CSize2D& a) const; - CRect operator-(const CRect& a) const; - CRect operator-(const CVector2D& a) const; - CRect operator-(const CSize2D& a) const; - - void operator+=(const CRect& a); - void operator+=(const CVector2D& a); - void operator+=(const CSize2D& a); - void operator-=(const CRect& a); - void operator-=(const CVector2D& a); - void operator-=(const CSize2D& a); - - /** - * @return Width of Rectangle - */ - float GetWidth() const; - - /** - * @return Height of Rectangle - */ - float GetHeight() const; - - /** - * Get Size - */ - CSize2D GetSize() const; - - /** - * Get Position equivalent to top/left corner - */ - CVector2D TopLeft() const; - - /** - * Get Position equivalent to top/right corner - */ - CVector2D TopRight() const; - - /** - * Get Position equivalent to bottom/left corner - */ - CVector2D BottomLeft() const; - - /** - * Get Position equivalent to bottom/right corner - */ - CVector2D BottomRight() const; - - /** - * Get Position equivalent to the center of the rectangle - */ - CVector2D CenterPoint() const; - - /** - * Evalutates if point is within the rectangle - * @param point CVector2D representing point - * @return true if inside. - */ - bool PointInside(const CVector2D &point) const; - - CRect Scale(float x, float y) const; - - /** - * Returning CVector2D representing each corner. - */ - -public: - /** - * Dimensions - */ - float left, top, right, bottom; -}; - -#endif // INCLUDED_SHAPES Property changes on: ps/trunk/source/ps/Shapes.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Index: ps/trunk/source/graphics/TextRenderer.h =================================================================== --- ps/trunk/source/graphics/TextRenderer.h (revision 25164) +++ ps/trunk/source/graphics/TextRenderer.h (revision 25165) @@ -1,181 +1,181 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ #ifndef INCLUDED_TEXTRENDERER #define INCLUDED_TEXTRENDERER #include "graphics/Color.h" #include "graphics/ShaderProgramPtr.h" #include "maths/Matrix3D.h" +#include "maths/Rect.h" #include "ps/CStrIntern.h" -#include "ps/Shapes.h" #include class CFont; class CTextRenderer { public: CTextRenderer(const CShaderProgramPtr& shader); /** * Reset the text transform to the default, with (0,0) in the top-left of the screen. */ void ResetTransform(); CMatrix3D GetTransform(); void SetTransform(const CMatrix3D& transform); void Translate(float x, float y, float z); /** * Set clipping rectangle, in pre-transform coordinates (i.e. text is clipped against * this rect based purely on the x,y values passed into Put()). Text fully outside the * clipping rectangle may not be rendered. Should be used in conjunction with glScissor * for precise clipping - this is just an optimisation. */ void SetClippingRect(const CRect& rect); /** * Set the color for subsequent print calls. */ void Color(const CColor& color); /** * Set the color for subsequent print calls. */ void Color(float r, float g, float b, float a = 1.0); /** * Set the font for subsequent print calls. */ void Font(CStrIntern font); /** * Print formatted text at (0,0) under the current transform, * and advance the transform by the width of the text. */ void PrintfAdvance(const wchar_t* fmt, ...); /** * Print formatted text at (x,y) under the current transform. * Does not alter the current transform. */ void PrintfAt(float x, float y, const wchar_t* fmt, ...); /** * Print text at (0,0) under the current transform, * and advance the transform by the width of the text. */ void PutAdvance(const wchar_t* buf); /** * Print text at (x,y) under the current transform. * Does not alter the current transform. */ void Put(float x, float y, const wchar_t* buf); /** * Print text at (x,y) under the current transform. * Does not alter the current transform. * @p buf must be a UTF-8 string. */ void Put(float x, float y, const char* buf); /** * Print text at (x,y) under the current transform. * Does not alter the current transform. * @p buf must remain valid until Render() is called. * (This should be used to minimise memory copies when possible.) */ void Put(float x, float y, const std::wstring* buf); /** * Render all of the previously printed text calls. */ void Render(); private: friend struct SBatchCompare; /** * A string (optionally owned by this object, or else pointing to an * externally-owned string) with a position. */ struct SBatchRun { private: SBatchRun& operator=(const SBatchRun&); public: SBatchRun() : text(NULL), owned(false) { } SBatchRun(const SBatchRun& str) : x(str.x), y(str.y), owned(str.owned) { if (owned) text = new std::wstring(*str.text); else text = str.text; } ~SBatchRun() { if (owned) delete text; } float x, y; const std::wstring* text; bool owned; }; /** * A list of SBatchRuns, with a single font/color/transform, * to be rendered in a single GL call. */ struct SBatch { size_t chars; // sum of runs[i].text->size() CMatrix3D transform; CColor color; shared_ptr font; std::list runs; }; void PutString(float x, float y, const std::wstring* buf, bool owned); CShaderProgramPtr m_Shader; CMatrix3D m_Transform; CRect m_Clipping; CColor m_Color; CStrIntern m_FontName; shared_ptr m_Font; bool m_Dirty; std::list m_Batches; }; #endif // INCLUDED_TEXTRENDERER Index: ps/trunk/source/gui/CGUI.h =================================================================== --- ps/trunk/source/gui/CGUI.h (revision 25164) +++ ps/trunk/source/gui/CGUI.h (revision 25165) @@ -1,686 +1,686 @@ /* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * 0 A.D. is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 0 A.D. If not, see . */ /* * This is the top class of the whole GUI, all objects * and settings are stored within this class. */ #ifndef INCLUDED_CGUI #define INCLUDED_CGUI #include "gui/GUITooltip.h" #include "gui/SettingTypes/CGUIColor.h" #include "gui/SGUIIcon.h" #include "gui/SGUIStyle.h" #include "lib/input.h" +#include "maths/Rect.h" #include "maths/Size2D.h" #include "maths/Vector2D.h" -#include "ps/Shapes.h" #include "ps/XML/Xeromyces.h" #include "scriptinterface/ScriptInterface.h" #include #include #include #include extern const double SELECT_DBLCLICK_RATE; class CGUISpriteInstance; class CGUISprite; class IGUIObject; struct SGUIImageEffects; struct SGUIScrollBarStyle; namespace js { class BaseProxyHandler; } class GUIProxyProps; using map_pObjects = std::map; /** * The main object that represents a whole GUI page. */ class CGUI { NONCOPYABLE(CGUI); private: // Private typedefs using ConstructObjectFunction = IGUIObject* (*)(CGUI&); public: CGUI(const shared_ptr& context); ~CGUI(); /** * Informs the GUI page which GUI object types may be constructed from XML. */ void AddObjectTypes(); /** * Performs processing that should happen every frame * (including sending the "Tick" event to scripts) */ void TickObjects(); /** * Sends a specified script event to every object * * @param eventName String representation of event name */ void SendEventToAll(const CStr& eventName); /** * Sends a specified script event to every object * * @param eventName String representation of event name * @param paramData JS::HandleValueArray storing the arguments passed to the event handler. */ void SendEventToAll(const CStr& eventName, const JS::HandleValueArray& paramData); /** * Displays the whole GUI */ void Draw(); /** * Draw GUI Sprite * * @param Sprite Object referring to the sprite (which also caches * calculations for faster rendering) * @param Z Drawing order, depth value * @param Rect Position and Size * @param Clipping The sprite shouldn't be drawn outside this rectangle */ void DrawSprite(const CGUISpriteInstance& Sprite, const float& Z, const CRect& Rect, const CRect& Clipping = CRect()); /** * The replacement of Process(), handles an SDL_Event_ * * @param ev SDL Event, like mouse/keyboard input */ InReaction HandleEvent(const SDL_Event_* ev); /** * Load a GUI XML file into the GUI. * * VERY IMPORTANT! All \-files must be read before * everything else! * * @param Filename Name of file * @param Paths Set of paths; all XML and JS files loaded will be added to this */ void LoadXmlFile(const VfsPath& Filename, std::unordered_set& Paths); /** * Called after all XML files linked in the page file were loaded. */ void LoadedXmlFiles(); /** * Allows the JS side to modify the hotkey setting assigned to a GUI object. */ void SetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag); void UnsetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag); /** * Allows the JS side to modify the style setting assigned to a GUI object. */ void SetObjectStyle(IGUIObject* pObject, const CStr& styleName); void UnsetObjectStyle(IGUIObject* pObject); /** * Allows the JS side to add or remove global hotkeys. */ void SetGlobalHotkey(const CStr& hotkeyTag, const CStr& eventName, JS::HandleValue function); void UnsetGlobalHotkey(const CStr& hotkeyTag, const CStr& eventName); /** * Return the object which is an ancestor of every other GUI object. */ IGUIObject* GetBaseObject(); /** * Checks if object exists and return true or false accordingly * * @param Name String name of object * @return true if object exists */ bool ObjectExists(const CStr& Name) const; /** * Returns the GUI object with the desired name, or nullptr * if no match is found, * * @param Name String name of object * @return Matching object, or nullptr */ IGUIObject* FindObjectByName(const CStr& Name) const; /** * Returns the GUI object under the mouse, or nullptr if none. */ IGUIObject* FindObjectUnderMouse(); /** * Returns the current screen coordinates of the cursor. */ const CVector2D& GetMousePos() const { return m_MousePos; }; /** * Returns the currently pressed mouse buttons. */ const unsigned int& GetMouseButtons() { return m_MouseButtons; }; const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const; /** * The GUI needs to have all object types inputted and * their constructors. Also it needs to associate a type * by a string name of the type. * * To add a type: * @code * AddObjectType("button", &CButton::ConstructObject); * @endcode * * @param str Reference name of object type * @param pFunc Pointer of function ConstuctObject() in the object * * @see CGUI#ConstructObject() */ void AddObjectType(const CStr& str, ConstructObjectFunction pFunc) { m_ObjectTypes[str] = pFunc; } /** * Update Resolution, should be called every time the resolution * of the OpenGL screen has been changed, this is because it needs * to re-cache all its actual sizes * * Needs no input since screen resolution is global. * * @see IGUIObject#UpdateCachedSize() */ void UpdateResolution(); /** * Check if an icon exists */ bool HasIcon(const CStr& name) const { return (m_Icons.find(name) != m_Icons.end()); } /** * Get Icon (a const reference, can never be changed) */ const SGUIIcon& GetIcon(const CStr& name) const { return m_Icons.at(name); } /** * Check if a style exists */ bool HasStyle(const CStr& name) const { return (m_Styles.find(name) != m_Styles.end()); } /** * Get Style if it exists, otherwise throws an exception. */ const SGUIStyle& GetStyle(const CStr& name) const { return m_Styles.at(name); } /** * Check if a predefined color of that name exists. */ bool HasPreDefinedColor(const CStr& name) const { return (m_PreDefinedColors.find(name) != m_PreDefinedColors.end()); } /** * Resolve the predefined color if it exists, otherwise throws an exception. */ const CGUIColor& GetPreDefinedColor(const CStr& name) const { return m_PreDefinedColors.at(name); } GUIProxyProps* GetProxyData(const js::BaseProxyHandler* ptr) { return m_ProxyData.at(ptr).get(); } shared_ptr GetScriptInterface() { return m_ScriptInterface; }; private: /** * The CGUI takes ownership of the child object and links the parent with the child. * Returns false on failure to take over ownership of the child object. */ bool AddObject(IGUIObject& parent, IGUIObject& child); /** * You input the name of the object type, and let's * say you input "button", then it will construct a * CGUIObjet* as a CButton. * * @param str Name of object type * @return Newly constructed IGUIObject (but constructed as a subclass) */ IGUIObject* ConstructObject(const CStr& str); public: /** * Get Focused Object. */ IGUIObject* GetFocusedObject() { return m_FocusedObject; } /** * Change focus to new object. * Will send LOST_FOCUS/GOT_FOCUS messages as appropriate. * pObject can be nullptr to remove all focus. */ void SetFocusedObject(IGUIObject* pObject); /** * Reads a string value and modifies the given value of type T if successful. * Does not change the value upon conversion failure. * * @param pGUI The GUI page which may contain data relevant to the parsing * (for example predefined colors). * @param Value The value in string form, like "0 0 100% 100%" * @param tOutput Parsed value of type T * @return True at success. */ template static bool ParseString(const CGUI* pGUI, const CStrW& Value, T& tOutput); private: //-------------------------------------------------------- /** @name XML Reading Xeromyces specific subroutines * * These does not throw! * Because when reading in XML files, it won't be fatal * if an error occurs, perhaps one particular object * fails, but it'll still continue reading in the next. * All Error are reported with ReportParseError */ //-------------------------------------------------------- /* Xeromyces_* functions tree (ReadRootObjects) | +-