Line data Source code
1 : /* Copyright (C) 2026 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 "lib/code_annotation.h" 23 : 24 : #include <js/TypeDecls.h> 25 : #include <memory> 26 : #include <string> 27 : 28 : class CRect; 29 : class CVector2D; 30 : class IGUIObject; 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 : */ 41 : class CGUIMouseEventMask : public IGUISetting 42 : { 43 : public: 44 : NONCOPYABLE(CGUIMouseEventMask); 45 : 46 : CGUIMouseEventMask(IGUIObject* owner); 47 : CGUIMouseEventMask(CGUIMouseEventMask&&) = default; 48 : CGUIMouseEventMask& operator=(CGUIMouseEventMask&&) = delete; 49 : ~CGUIMouseEventMask(); 50 : 51 : /** 52 : * @return true if the mask is initialised <=> its spec is not "" 53 : */ 54 0 : 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 Script::Request& rq, JS::MutableHandleValue value) override; 62 : 63 : class Impl; 64 : protected: 65 : bool DoFromString(const CStrW& value) override; 66 : bool DoFromJSVal(const Script::Request& 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