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 = 0x00,
60 EVENT_RESULT_HANDLED = 0x01,
61 EVENT_RESULT_PAN_HORIZONTAL = 0x02,
62 EVENT_RESULT_PAN_VERTICAL = 0x04,
63 EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA = 0x08,
64 EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA = 0x10,
65 EVENT_RESULT_ROTATE = 0x20,
66 EVENT_RESULT_ZOOM = 0x40,
67 EVENT_RESULT_SWIPE = 0x80
72 \brief Base class for controls
78 CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height);
79 virtual ~CGUIControl(void);
80 virtual CGUIControl *Clone() const=0;
82 virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions);
83 virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
84 virtual void DoRender();
85 virtual void Render() {};
87 /*! \brief Returns whether or not we have processed */
88 bool HasProcessed() const { return m_hasProcessed; };
90 // OnAction() is called by our window when we are the focused control.
91 // We should process any control-specific actions in the derived classes,
92 // and return true if we have taken care of the action. Returning false
93 // indicates that the message may be handed down to the window or application
94 // levels. This base class implementation handles basic movement, and should
95 // be called from the derived classes when the action has not been handled.
96 // Return true to indicate that the action has been dealt with.
97 virtual bool OnAction(const CAction &action);
99 // Common actions to make the code easier to read (no ugly switch statements in derived controls)
101 virtual void OnDown();
102 virtual void OnLeft();
103 virtual void OnRight();
104 virtual bool OnBack();
105 virtual void OnNextControl();
106 virtual void OnPrevControl();
107 virtual void OnFocus() {};
108 virtual void OnUnFocus() {};
110 /*! \brief React to a mouse event
112 Mouse events are sent from the window to all controls, and each control can react based on the event
113 and location of the event.
115 \param point the location in transformed skin coordinates from the upper left corner of the parent control.
116 \param event the mouse event to perform
117 \return EVENT_RESULT corresponding to whether the control handles this event
118 \sa HitTest, CanFocusFromPoint, CMouseEvent, EVENT_RESULT
120 virtual EVENT_RESULT SendMouseEvent(const CPoint &point, const CMouseEvent &event);
122 /*! \brief Perform a mouse action
124 Mouse actions are sent from the window to all controls, and each control can react based on the event
125 and location of the actions.
127 \param point the location in transformed skin coordinates from the upper left corner of the parent control.
128 \param event the mouse event to perform
129 \return EVENT_RESULT corresponding to whether the control handles this event
130 \sa SendMouseEvent, HitTest, CanFocusFromPoint, CMouseEvent
132 virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) { return EVENT_RESULT_UNHANDLED; };
134 /*! \brief Unfocus the control if the given point on screen is not within it's boundary
135 \param point the location in transformed skin coordinates from the upper left corner of the parent control.
136 \sa CanFocusFromPoint
138 virtual void UnfocusFromPoint(const CPoint &point);
140 /*! \brief Used to test whether the point is inside a control.
141 \param point location to test
142 \return true if the point is inside the bounds of this control.
145 virtual bool HitTest(const CPoint &point) const;
147 virtual bool OnMessage(CGUIMessage& message);
148 virtual int GetID(void) const;
149 virtual void SetID(int id) { m_controlID = id; };
150 virtual bool HasID(int id) const;
151 virtual bool HasVisibleID(int id) const;
152 int GetParentID() const;
153 virtual bool HasFocus() const;
154 virtual void AllocResources();
155 virtual void FreeResources(bool immediately = false);
156 virtual void DynamicResourceAlloc(bool bOnOff);
157 virtual bool IsDynamicallyAllocated() { return false; };
158 virtual bool CanFocus() const;
159 virtual bool IsVisible() const;
160 bool IsVisibleFromSkin() const { return m_visibleFromSkinCondition; };
161 virtual bool IsDisabled() const;
162 virtual void SetPosition(float posX, float posY);
163 virtual void SetHitRect(const CRect &rect);
164 virtual void SetCamera(const CPoint &camera);
165 bool SetColorDiffuse(const CGUIInfoColor &color);
166 CPoint GetRenderPosition() const;
167 virtual float GetXPosition() const;
168 virtual float GetYPosition() const;
169 virtual float GetWidth() const;
170 virtual float GetHeight() const;
172 void MarkDirtyRegion();
174 /*! \brief return the render region in screen coordinates of this control
176 const CRect &GetRenderRegion() const { return m_renderRegion; };
177 /*! \brief calculate the render region in parentcontrol coordinates of this control
178 Called during process to update m_renderRegion
180 virtual CRect CalcRenderRegion() const;
182 virtual void SetNavigation(int up, int down, int left, int right, int back = 0);
183 virtual void SetTabNavigation(int next, int prev);
185 /*! \brief Set actions to perform on navigation
186 Navigations are set if replace is true or if there is no previously set action
187 \param up CGUIAction to execute on up
188 \param down CGUIAction to execute on down
189 \param left CGUIAction to execute on left
190 \param right CGUIAction to execute on right
191 \param back CGUIAction to execute on back
192 \param replace Actions are set only if replace is true or there is no previously set action. Defaults to true
195 virtual void SetNavigationActions(const CGUIAction &up, const CGUIAction &down,
196 const CGUIAction &left, const CGUIAction &right,
197 const CGUIAction &back, bool replace = true);
198 void SetNavigationAction(int direction, const CGUIAction &action, bool replace = true);
199 int GetControlIdUp() const { return m_actionUp.GetNavigation(); };
200 int GetControlIdDown() const { return m_actionDown.GetNavigation(); };
201 int GetControlIdLeft() const { return m_actionLeft.GetNavigation(); };
202 int GetControlIdRight() const { return m_actionRight.GetNavigation(); };
203 int GetControlIdBack() const { return m_actionBack.GetNavigation(); };
204 bool GetNavigationAction(int direction, CGUIAction& action) const;
205 /*! \brief Start navigating in given direction.
207 bool Navigate(int direction) const;
208 virtual void SetFocus(bool focus);
209 virtual void SetWidth(float width);
210 virtual void SetHeight(float height);
211 virtual void SetVisible(bool bVisible, bool setVisState = false);
212 void SetVisibleCondition(const CStdString &expression, const CStdString &allowHiddenFocus = "");
213 bool HasVisibleCondition() const { return m_visibleCondition; };
214 void SetEnableCondition(const CStdString &expression);
215 virtual void UpdateVisibility(const CGUIListItem *item = NULL);
216 virtual void SetInitialVisibility();
217 virtual void SetEnabled(bool bEnable);
218 virtual void SetInvalid() { m_bInvalidated = true; };
219 virtual void SetPulseOnSelect(bool pulse) { m_pulseOnSelect = pulse; };
220 virtual CStdString GetDescription() const { return ""; };
222 void SetAnimations(const std::vector<CAnimation> &animations);
223 const std::vector<CAnimation> &GetAnimations() const { return m_animations; };
225 virtual void QueueAnimation(ANIMATION_TYPE anim);
226 virtual bool IsAnimating(ANIMATION_TYPE anim);
227 virtual bool HasAnimation(ANIMATION_TYPE anim);
228 CAnimation *GetAnimation(ANIMATION_TYPE type, bool checkConditions = true);
229 virtual void ResetAnimation(ANIMATION_TYPE type);
230 virtual void ResetAnimations();
232 // push information updates
233 virtual void UpdateInfo(const CGUIListItem *item = NULL) {};
234 virtual void SetPushUpdates(bool pushUpdates) { m_pushedUpdates = pushUpdates; };
236 virtual bool IsGroup() const { return false; };
237 virtual bool IsContainer() const { return false; };
238 virtual bool GetCondition(int condition, int data) const { return false; };
240 void SetParentControl(CGUIControl *control) { m_parentControl = control; };
241 CGUIControl *GetParentControl(void) const { return m_parentControl; };
242 virtual void SaveStates(std::vector<CControlState> &states);
244 enum GUICONTROLTYPES {
247 GUICONTROL_CHECKMARK,
248 GUICONTROL_FADELABEL,
250 GUICONTROL_BORDEREDIMAGE,
251 GUICONTROL_LARGE_IMAGE,
253 GUICONTROL_LISTGROUP,
257 GUICONTROL_SELECTBUTTON,
259 GUICONTROL_SETTINGS_SLIDER,
263 GUICONTROL_TOGGLEBUTTON,
268 GUICONTROL_VISUALISATION,
269 GUICONTROL_RENDERADDON,
270 GUICONTROL_MULTI_IMAGE,
272 GUICONTROL_GROUPLIST,
273 GUICONTROL_SCROLLBAR,
274 GUICONTROL_LISTLABEL,
275 GUICONTROL_MULTISELECT,
277 GUICONTAINER_WRAPLIST,
278 GUICONTAINER_FIXEDLIST,
279 GUICONTAINER_EPGGRID,
282 GUICONTROLTYPES GetControlType() const { return ControlType; }
284 enum GUIVISIBLE { HIDDEN = 0, DELAYED, VISIBLE };
287 virtual void DumpTextureUse() {};
291 \brief Return the coordinates of the top left of the control, in the control's parent coordinates
292 \return The top left coordinates of the control
294 virtual CPoint GetPosition() const { return CPoint(GetXPosition(), GetYPosition()); };
296 /*! \brief Called when the mouse is over the control.
297 Default implementation selects the control.
298 \param point location of the mouse in transformed skin coordinates
299 \return true if handled, false otherwise.
301 virtual bool OnMouseOver(const CPoint &point);
303 /*! \brief Test whether we can focus a control from a point on screen
304 \param point the location in vanilla skin coordinates from the upper left corner of the parent control.
305 \return true if the control can be focused from this location
306 \sa UnfocusFromPoint, HitRect
308 virtual bool CanFocusFromPoint(const CPoint &point) const;
310 virtual bool UpdateColors();
311 virtual bool Animate(unsigned int currentTime);
312 virtual bool CheckAnimation(ANIMATION_TYPE animType);
313 void UpdateStates(ANIMATION_TYPE type, ANIMATION_PROCESS currentProcess, ANIMATION_STATE currentState);
314 bool SendWindowMessage(CGUIMessage &message) const;
316 // navigation and actions
317 CGUIAction m_actionLeft;
318 CGUIAction m_actionRight;
319 CGUIAction m_actionUp;
320 CGUIAction m_actionDown;
321 CGUIAction m_actionBack;
322 CGUIAction m_actionNext;
323 CGUIAction m_actionPrev;
330 CGUIInfoColor m_diffuseColor;
336 bool m_pulseOnSelect;
337 GUICONTROLTYPES ControlType;
339 CGUIControl *m_parentControl; // our parent control if we're part of a group
341 // visibility condition/state
342 INFO::InfoPtr m_visibleCondition;
343 GUIVISIBLE m_visible;
344 bool m_visibleFromSkinCondition;
345 bool m_forceHidden; // set from the code when a hidden operation is given - overrides m_visible
346 CGUIInfoBool m_allowHiddenFocus;
348 // enable/disable state
349 INFO::InfoPtr m_enableCondition;
352 bool m_pushedUpdates;
355 std::vector<CAnimation> m_animations;
358 TransformMatrix m_transform;
359 TransformMatrix m_cachedTransform; // Contains the absolute transform the control
361 bool m_controlIsDirty;
362 CRect m_renderRegion; // In screen coordinates