Pyrogenesis  trunk
MouseEventMask.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_GUI_MOUSE_EVENT_MASK
19 #define INCLUDED_GUI_MOUSE_EVENT_MASK
20 
21 #include "gui/CGUISetting.h"
22 #include "ps/CStr.h"
23 
24 #include <string>
25 #include <memory>
26 
27 class CRect;
28 class CVector2D;
29 class IGUIObject;
30 class ScriptRequest;
31 
32 /**
33  * A custom shape that changes the object's "over-ability", and thus where one can click on it.
34  * Supported:
35  * - "texture:[path]" loads a texture and uses either the alpha or the red channel. Any non-0 is clickable.
36  * The texture is always 'stretched' in sprite terminology.
37  *
38  * TODO:
39  * - the minimap circular shape should be moved here.
40  */
42 {
43 public:
46 
47  /**
48  * @return true if the mask is initialised <=> its spec is not ""
49  */
50  explicit operator bool() const { return !!m_Impl; }
51 
52  /**
53  * @return true if the mouse pointer is over the mask. False if the mask is not initialised.
54  */
55  bool IsMouseOver(const CVector2D& mousePos, const CRect& objectSize) const;
56 
57  void ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue value) override;
58 
59  class Impl;
60 protected:
61  bool DoFromString(const CStrW& value) override;
62  bool DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value) override;
63  CStr GetName() const override;
64 
65  std::string m_Spec;
66  std::unique_ptr<Impl> m_Impl;
67 };
68 
69 #endif // INCLUDED_GUI_MOUSE_EVENT_MASK
bool IsMouseOver(const CVector2D &mousePos, const CRect &objectSize) const
Definition: MouseEventMask.cpp:75
~CGUIMouseEventMask()
Definition: MouseEventMask.cpp:53
GUI object such as a button or an input-box.
Definition: IGUIObject.h:59
void ToJSVal(const ScriptRequest &rq, JS::MutableHandleValue value) override
Converts the setting data to a JS::Value using Script::ToJSVal.
Definition: MouseEventMask.cpp:57
CStr GetName() const override
Return the name of the setting, from JS.
Definition: MouseEventMask.cpp:70
bool DoFromJSVal(const ScriptRequest &rq, JS::HandleValue value) override
Definition: MouseEventMask.cpp:62
CGUIMouseEventMask(IGUIObject *owner)
Definition: MouseEventMask.cpp:49
This setting interface allows GUI objects to call setting function functions without having to know t...
Definition: CGUISetting.h:32
Definition: Vector2D.h:31
A custom shape that changes the object&#39;s "over-ability", and thus where one can click on it...
Definition: MouseEventMask.h:41
std::unique_ptr< Impl > m_Impl
Definition: MouseEventMask.h:66
Definition: MouseEventMask.cpp:42
bool DoFromString(const CStrW &value) override
Definition: MouseEventMask.cpp:161
std::string m_Spec
Definition: MouseEventMask.h:65
Spidermonkey maintains some &#39;local&#39; state via the JSContext* object.
Definition: ScriptRequest.h:59
Rectangle class used for screen rectangles.
Definition: Rect.h:30