PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ModSnap.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLGUI_MODSNAP_H__ 00024 #define __PLGUI_MODSNAP_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLMath/Vector2i.h> 00032 #include "PLGui/Modifiers/Modifier.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLGui { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * Modifier that snaps a widget to window borders 00047 */ 00048 class ModSnap : public Modifier { 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ Class definition ] 00053 //[-------------------------------------------------------] 00054 pl_class(PLGUI_RTTI_EXPORT, ModSnap, "PLGui", PLGui::Modifier, "Modifier that snaps a widget to window borders") 00055 // Constructors 00056 pl_constructor_0(DefaultConstructor, "Default constructor", "") 00057 pl_class_end 00058 00059 00060 //[-------------------------------------------------------] 00061 //[ Public functions ] 00062 //[-------------------------------------------------------] 00063 public: 00064 /** 00065 * @brief 00066 * Constructor 00067 */ 00068 PLGUI_API ModSnap(); 00069 00070 /** 00071 * @brief 00072 * Destructor 00073 */ 00074 PLGUI_API virtual ~ModSnap(); 00075 00076 00077 //[-------------------------------------------------------] 00078 //[ Protected virtual Modifier functions ] 00079 //[-------------------------------------------------------] 00080 protected: 00081 virtual void OnAttach(Widget &cWidget) override; 00082 virtual void OnDetach(Widget &cWidget) override; 00083 00084 00085 //[-------------------------------------------------------] 00086 //[ Protected virtual WidgetFunctions functions ] 00087 //[-------------------------------------------------------] 00088 protected: 00089 virtual void OnMove(const PLMath::Vector2i &vPos) override; 00090 00091 00092 //[-------------------------------------------------------] 00093 //[ Protected functions ] 00094 //[-------------------------------------------------------] 00095 protected: 00096 /** 00097 * @brief 00098 * Try to unsnap the widget from it's current snap-targets 00099 * 00100 * @param[in] vPos 00101 * Position 00102 */ 00103 void TryUnsnap(const PLMath::Vector2i &vPos); 00104 00105 /** 00106 * @brief 00107 * Try to snap to a specific widget 00108 * 00109 * @param[in] vPos 00110 * Position 00111 * @param[in] pSnapWidget 00112 * Widget to snap to, can be either the parent or a sibling widget 00113 * @param[in] bParent 00114 * 'true', if pWidget is the parent window of this widget, else 'false' 00115 */ 00116 void TrySnap(const PLMath::Vector2i &vPos, Widget *pSnapWidget, bool bParent); 00117 00118 00119 //[-------------------------------------------------------] 00120 //[ Protected data ] 00121 //[-------------------------------------------------------] 00122 protected: 00123 // Event handlers 00124 PLCore::EventHandler<const PLMath::Vector2i&> EventHandlerMove; /**< Widget gets moved, new widget position as parameter */ 00125 00126 // State 00127 PLMath::Vector2i m_vPos; /**< Current position */ 00128 Widget *m_pSnappedLeft; /**< Widget to which we are currently snapped on our left side */ 00129 Widget *m_pSnappedRight; /**< Widget to which we are currently snapped on our right side */ 00130 Widget *m_pSnappedTop; /**< Widget to which we are currently snapped on our top side */ 00131 Widget *m_pSnappedBottom; /**< Widget to which we are currently snapped on our bottom side */ 00132 bool m_bPerformedSnap; /**< Widget has performed a snap in the last cycle */ 00133 00134 00135 }; 00136 00137 00138 //[-------------------------------------------------------] 00139 //[ Namespace ] 00140 //[-------------------------------------------------------] 00141 } // PLGui 00142 00143 00144 #endif // __PLGUI_MODSNAP_H__
|