Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CGUISize.h
Go to the documentation of this file.
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"
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 */
30{
31public:
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
41
42 /// Percent modifiers
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 bool operator==(const CGUISize& other) const
66 {
67 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
This class represents a rectangle relative to a parent rectangle The value can be initialized from a ...
Definition: CGUISize.h:30
bool operator==(const CGUISize &other) const
Definition: CGUISize.h:65
void ToJSVal(const ScriptRequest &rq, JS::MutableHandleValue ret) const
Definition: CGUISize.cpp:146
CGUISize()
Definition: CGUISize.cpp:28
CRect GetSize(const CRect &parent) const
Get client area rectangle when the parent is given.
Definition: CGUISize.cpp:43
static CGUISize Full()
Definition: CGUISize.cpp:38
CRect pixel
Pixel modifiers.
Definition: CGUISize.h:40
bool FromJSVal(const ScriptRequest &rq, JS::HandleValue v)
Definition: CGUISize.cpp:181
bool FromString(const CStr8 &Value)
The value can be set from a string looking like:
Definition: CGUISize.cpp:60
CRect percent
Percent modifiers.
Definition: CGUISize.h:43
Rectangle class used for screen rectangles.
Definition: Rect.h:31
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:60