Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
MouseEventMask.h
Go to the documentation of this file.
1/* Copyright (C) 2023 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
27class CRect;
28class CVector2D;
29class IGUIObject;
30class 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{
43public:
45
50
51 /**
52 * @return true if the mask is initialised <=> its spec is not ""
53 */
54 explicit operator bool() const { return !!m_Impl; }
55
56 /**
57 * @return true if the mouse pointer is over the mask. False if the mask is not initialised.
58 */
59 bool IsMouseOver(const CVector2D& mousePos, const CRect& objectSize) const;
60
61 void ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue value) override;
62
63 class Impl;
64protected:
65 bool DoFromString(const CStrW& value) override;
66 bool DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value) override;
67
68 std::string m_Spec;
69 std::unique_ptr<Impl> m_Impl;
70};
71
72#endif // INCLUDED_GUI_MOUSE_EVENT_MASK
A custom shape that changes the object's "over-ability", and thus where one can click on it.
Definition: MouseEventMask.h:42
std::unique_ptr< Impl > m_Impl
Definition: MouseEventMask.h:69
~CGUIMouseEventMask()
Definition: MouseEventMask.cpp:53
CGUIMouseEventMask(CGUIMouseEventMask &&)=default
std::string m_Spec
Definition: MouseEventMask.h:68
bool DoFromJSVal(const ScriptRequest &rq, JS::HandleValue value) override
Definition: MouseEventMask.cpp:62
CGUIMouseEventMask(IGUIObject *owner)
Definition: MouseEventMask.cpp:49
NONCOPYABLE(CGUIMouseEventMask)
bool IsMouseOver(const CVector2D &mousePos, const CRect &objectSize) const
Definition: MouseEventMask.cpp:70
void ToJSVal(const ScriptRequest &rq, JS::MutableHandleValue value) override
Converts the setting data to a JS::Value using Script::ToJSVal.
Definition: MouseEventMask.cpp:57
bool DoFromString(const CStrW &value) override
Definition: MouseEventMask.cpp:156
CGUIMouseEventMask & operator=(CGUIMouseEventMask &&)=delete
Rectangle class used for screen rectangles.
Definition: Rect.h:31
Definition: Vector2D.h:32
GUI object such as a button or an input-box.
Definition: IGUIObject.h:60
This setting interface allows GUI objects to call setting function functions without having to know t...
Definition: CGUISetting.h:33
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:60