LCOV - code coverage report
Current view: top level - source/gui/SettingTypes - CGUISize.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 3 3 100.0 %
Date: 2023-01-19 00:18:29 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* Copyright (C) 2021 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_CGUISIZE
      19             : #define INCLUDED_CGUISIZE
      20             : 
      21             : #include "maths/Rect.h"
      22             : #include "ps/CStrForward.h"
      23             : #include "scriptinterface/ScriptForward.h"
      24             : 
      25             : /**
      26             :  * This class represents a rectangle relative to a parent rectangle
      27             :  * The value can be initialized from a string or JS object.
      28             :  */
      29          18 : class CGUISize
      30             : {
      31             : public:
      32             :     // COPYABLE, since there are only primitives involved, making move and copy identical,
      33             :     // and since some temporaries cannot be avoided.
      34             :     CGUISize();
      35             :     CGUISize(const CRect& pixel, const CRect& percent);
      36             : 
      37             :     static CGUISize Full();
      38             : 
      39             :     /// Pixel modifiers
      40             :     CRect pixel;
      41             : 
      42             :     /// Percent modifiers
      43             :     CRect percent;
      44             : 
      45             :     /**
      46             :      * Get client area rectangle when the parent is given
      47             :      */
      48             :     CRect GetSize(const CRect& parent) const;
      49             : 
      50             :     /**
      51             :      * The value can be set from a string looking like:
      52             :      *
      53             :      * "0 0 100% 100%"
      54             :      * "50%-10 50%-10 50%+10 50%+10"
      55             :      *
      56             :      * i.e. First percent modifier, then + or - and the pixel modifier.
      57             :      * Although you can use just the percent or the pixel modifier. Notice
      58             :      * though that the percent modifier must always be the first when
      59             :      * both modifiers are inputted.
      60             :      *
      61             :      * @return true if success, otherwise size will remain unchanged.
      62             :      */
      63             :     bool FromString(const CStr8& Value);
      64             : 
      65           6 :     bool operator==(const CGUISize& other) const
      66             :     {
      67           6 :         return pixel == other.pixel && percent == other.percent;
      68             :     }
      69             : 
      70             :     void ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret) const;
      71             :     bool FromJSVal(const ScriptRequest& rq, JS::HandleValue v);
      72             : };
      73             : 
      74             : #endif // INCLUDED_CGUISIZE

Generated by: LCOV version 1.13