6 #ifndef GUILIB_GUICONTROL_H
7 #define GUILIB_GUICONTROL_H
11 * Copyright (C) 2005-2013 Team XBMC
14 * This Program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This Program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with XBMC; see the file COPYING. If not, see
26 * <http://www.gnu.org/licenses/>.
30 #include "GraphicContext.h" // needed by any rendering operation (all controls)
31 #include "GUIMessage.h" // needed by practically all controls
32 #include "VisibleEffect.h" // needed for the CAnimation members
33 #include "GUIInfoTypes.h" // needed for CGUIInfoColor to handle infolabel'ed colors
34 #include "DirtyRegion.h"
35 #include "GUIAction.h"
37 class CGUIListItem; // forward
41 enum ORIENTATION { HORIZONTAL = 0, VERTICAL };
46 CControlState(int id, int data)
56 \brief Results of OnMouseEvent()
57 Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was handled.
59 enum EVENT_RESULT { EVENT_RESULT_UNHANDLED = 0,
61 EVENT_RESULT_PAN_HORIZONTAL,
62 EVENT_RESULT_PAN_VERTICAL,
63 EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA,
64 EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA,
70 \brief Base class for controls
76 CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height);
77 virtual ~CGUIControl(void);
78 virtual CGUIControl *Clone() const=0;
80 virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions);
81 virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
82 virtual void DoRender();
83 virtual void Render();
85 bool HasRendered() const { return m_hasRendered; };
87 // OnAction() is called by our window when we are the focused control.
88 // We should process any control-specific actions in the derived classes,
89 // and return true if we have taken care of the action. Returning false
90 // indicates that the message may be handed down to the window or application
91 // levels. This base class implementation handles basic movement, and should
92 // be called from the derived classes when the action has not been handled.
93 // Return true to indicate that the action has been dealt with.
94 virtual bool OnAction(const CAction &action);
96 // Common actions to make the code easier to read (no ugly switch statements in derived controls)
98 virtual void OnDown();
99 virtual void OnLeft();
100 virtual void OnRight();
101 virtual bool OnBack();
102 virtual void OnNextControl();
103 virtual void OnPrevControl();
104 virtual void OnFocus() {};
105 virtual void OnUnFocus() {};
107 /*! \brief React to a mouse event
109 Mouse events are sent from the window to all controls, and each control can react based on the event
110 and location of the event.
112 \param point the location in transformed skin coordinates from the upper left corner of the parent control.
113 \param event the mouse event to perform
114 \return EVENT_RESULT corresponding to whether the control handles this event
115 \sa HitTest, CanFocusFromPoint, CMouseEvent, EVENT_RESULT
117 virtual EVENT_RESULT SendMouseEvent(const CPoint &point, const CMouseEvent &event);
119 /*! \brief Perform a mouse action
121 Mouse actions are sent from the window to all controls, and each control can react based on the event
122 and location of the actions.
124 \param point the location in transformed skin coordinates from the upper left corner of the parent control.
125 \param event the mouse event to perform
126 \return EVENT_RESULT corresponding to whether the control handles this event
127 \sa SendMouseEvent, HitTest, CanFocusFromPoint, CMouseEvent
129 virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) { return EVENT_RESULT_UNHANDLED; };
131 /*! \brief Unfocus the control if the given point on screen is not within it's boundary
132 \param point the location in transformed skin coordinates from the upper left corner of the parent control.
133 \sa CanFocusFromPoint
135 virtual void UnfocusFromPoint(const CPoint &point);
137 /*! \brief Used to test whether the point is inside a control.
138 \param point location to test
139 \return true if the point is inside the bounds of this control.
142 virtual bool HitTest(const CPoint &point) const;
144 virtual bool OnMessage(CGUIMessage& message);
145 virtual int GetID(void) const;
146 virtual void SetID(int id) { m_controlID = id; };
147 virtual bool HasID(int id) const;
148 virtual bool HasVisibleID(int id) const;
149 int GetParentID() const;
150 virtual bool HasFocus() const;
151 virtual void AllocResources();
152 virtual void FreeResources(bool immediately = false);
153 virtual void DynamicResourceAlloc(bool bOnOff);
154 virtual bool IsDynamicallyAllocated() { return false; };
155 virtual bool CanFocus() const;
156 virtual bool IsVisible() const;
157 bool IsVisibleFromSkin() const { return m_visibleFromSkinCondition; };
158 virtual bool IsDisabled() const;
159 virtual void SetPosition(float posX, float posY);
160 virtual void SetHitRect(const CRect &rect);
161 virtual void SetCamera(const CPoint &camera);
162 bool SetColorDiffuse(const CGUIInfoColor &color);
163 CPoint GetRenderPosition() const;
164 virtual float GetXPosition() const;
165 virtual float GetYPosition() const;
166 virtual float GetWidth() const;
167 virtual float GetHeight() const;
169 void MarkDirtyRegion();
171 /*! \brief return the render region in screen coordinates of this control
173 const CRect &GetRenderRegion() const { return m_renderRegion; };
174 /*! \brief calculate the render region in parentcontrol coordinates of this control
175 Called during process to update m_renderRegion
177 virtual CRect CalcRenderRegion() const;
179 virtual void SetNavigation(int up, int down, int left, int right, int back = 0);
180 virtual void SetTabNavigation(int next, int prev);
182 /*! \brief Set actions to perform on navigation
183 Navigations are set if replace is true or if there is no previously set action
184 \param up CGUIAction to execute on up
185 \param down CGUIAction to execute on down
186 \param left CGUIAction to execute on left
187 \param right CGUIAction to execute on right
188 \param back CGUIAction to execute on back
189 \param replace Actions are set only if replace is true or there is no previously set action. Defaults to true
192 virtual void SetNavigationActions(const CGUIAction &up, const CGUIAction &down,
193 const CGUIAction &left, const CGUIAction &right,
194 const CGUIAction &back, bool replace = true);
195 void SetNavigationAction(int direction, const CGUIAction &action, bool replace = true);
196 int GetControlIdUp() const { return m_actionUp.GetNavigation(); };
197 int GetControlIdDown() const { return m_actionDown.GetNavigation(); };
198 int GetControlIdLeft() const { return m_actionLeft.GetNavigation(); };
199 int GetControlIdRight() const { return m_actionRight.GetNavigation(); };
200 int GetControlIdBack() const { return m_actionBack.GetNavigation(); };
201 bool GetNavigationAction(int direction, CGUIAction& action) const;
202 /*! \brief Start navigating in given direction.
204 bool Navigate(int direction);
205 virtual void SetFocus(bool focus);
206 virtual void SetWidth(float width);
207 virtual void SetHeight(float height);
208 virtual void SetVisible(bool bVisible, bool setVisState = false);
209 void SetVisibleCondition(const CStdString &expression, const CStdString &allowHiddenFocus = "");
210 unsigned int GetVisibleCondition() const { return m_visibleCondition; };
211 void SetEnableCondition(const CStdString &expression);
212 virtual void UpdateVisibility(const CGUIListItem *item = NULL);
213 virtual void SetInitialVisibility();
214 virtual void SetEnabled(bool bEnable);
215 virtual void SetInvalid() { m_bInvalidated = true; };
216 virtual void SetPulseOnSelect(bool pulse) { m_pulseOnSelect = pulse; };
217 virtual CStdString GetDescription() const { return ""; };
219 void SetAnimations(const std::vector<CAnimation> &animations);
220 const std::vector<CAnimation> &GetAnimations() const { return m_animations; };
222 virtual void QueueAnimation(ANIMATION_TYPE anim);
223 virtual bool IsAnimating(ANIMATION_TYPE anim);
224 virtual bool HasAnimation(ANIMATION_TYPE anim);
225 CAnimation *GetAnimation(ANIMATION_TYPE type, bool checkConditions = true);
226 virtual void ResetAnimation(ANIMATION_TYPE type);
227 virtual void ResetAnimations();
229 // push information updates
230 virtual void UpdateInfo(const CGUIListItem *item = NULL) {};
231 virtual void SetPushUpdates(bool pushUpdates) { m_pushedUpdates = pushUpdates; };
233 virtual bool IsGroup() const { return false; };
234 virtual bool IsContainer() const { return false; };
235 virtual bool GetCondition(int condition, int data) const { return false; };
237 void SetParentControl(CGUIControl *control) { m_parentControl = control; };
238 CGUIControl *GetParentControl(void) const { return m_parentControl; };
239 virtual void SaveStates(std::vector<CControlState> &states);
241 enum GUICONTROLTYPES {
244 GUICONTROL_CHECKMARK,
245 GUICONTROL_FADELABEL,
247 GUICONTROL_BORDEREDIMAGE,
248 GUICONTROL_LARGE_IMAGE,
250 GUICONTROL_LISTGROUP,
254 GUICONTROL_SELECTBUTTON,
256 GUICONTROL_SETTINGS_SLIDER,
260 GUICONTROL_TOGGLEBUTTON,
265 GUICONTROL_VISUALISATION,
266 GUICONTROL_RENDERADDON,
267 GUICONTROL_MULTI_IMAGE,
269 GUICONTROL_GROUPLIST,
270 GUICONTROL_SCROLLBAR,
271 GUICONTROL_LISTLABEL,
272 GUICONTROL_MULTISELECT,
274 GUICONTAINER_WRAPLIST,
275 GUICONTAINER_FIXEDLIST,
276 GUICONTAINER_EPGGRID,
279 GUICONTROLTYPES GetControlType() const { return ControlType; }
281 enum GUIVISIBLE { HIDDEN = 0, DELAYED, VISIBLE };
284 virtual void DumpTextureUse() {};
288 \brief Return the coordinates of the top left of the control, in the control's parent coordinates
289 \return The top left coordinates of the control
291 virtual CPoint GetPosition() const { return CPoint(GetXPosition(), GetYPosition()); };
293 /*! \brief Called when the mouse is over the control.
294 Default implementation selects the control.
295 \param point location of the mouse in transformed skin coordinates
296 \return true if handled, false otherwise.
298 virtual bool OnMouseOver(const CPoint &point);
300 /*! \brief Test whether we can focus a control from a point on screen
301 \param point the location in vanilla skin coordinates from the upper left corner of the parent control.
302 \return true if the control can be focused from this location
303 \sa UnfocusFromPoint, HitRect
305 virtual bool CanFocusFromPoint(const CPoint &point) const;
307 virtual bool UpdateColors();
308 virtual bool Animate(unsigned int currentTime);
309 virtual bool CheckAnimation(ANIMATION_TYPE animType);
310 void UpdateStates(ANIMATION_TYPE type, ANIMATION_PROCESS currentProcess, ANIMATION_STATE currentState);
311 bool SendWindowMessage(CGUIMessage &message);
313 // navigation and actions
314 CGUIAction m_actionLeft;
315 CGUIAction m_actionRight;
316 CGUIAction m_actionUp;
317 CGUIAction m_actionDown;
318 CGUIAction m_actionBack;
319 CGUIAction m_actionNext;
320 CGUIAction m_actionPrev;
327 CGUIInfoColor m_diffuseColor;
333 bool m_pulseOnSelect;
334 GUICONTROLTYPES ControlType;
336 CGUIControl *m_parentControl; // our parent control if we're part of a group
338 // visibility condition/state
339 unsigned int m_visibleCondition;
340 GUIVISIBLE m_visible;
341 bool m_visibleFromSkinCondition;
342 bool m_forceHidden; // set from the code when a hidden operation is given - overrides m_visible
343 CGUIInfoBool m_allowHiddenFocus;
345 // enable/disable state
346 unsigned int m_enableCondition;
349 bool m_pushedUpdates;
352 std::vector<CAnimation> m_animations;
355 TransformMatrix m_transform;
356 TransformMatrix m_cachedTransform; // Contains the absolute transform the control
358 bool m_controlIsDirty;
359 CRect m_renderRegion; // In screen coordinates