[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / guilib / GUIControl.h
1 /*!
2 \file GUIControl.h
3 \brief
4 */
5
6 #ifndef GUILIB_GUICONTROL_H
7 #define GUILIB_GUICONTROL_H
8 #pragma once
9
10 /*
11  *      Copyright (C) 2005-2013 Team XBMC
12  *      http://www.xbmc.org
13  *
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)
17  *  any later version.
18  *
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.
23  *
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/>.
27  *
28  */
29
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"
36
37 class CGUIListItem; // forward
38 class CAction;
39 class CMouseEvent;
40
41 enum ORIENTATION { HORIZONTAL = 0, VERTICAL };
42
43 class CControlState
44 {
45 public:
46   CControlState(int id, int data)
47   {
48     m_id = id;
49     m_data = data;
50   }
51   int m_id;
52   int m_data;
53 };
54
55 /*!
56  \brief Results of OnMouseEvent()
57  Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was handled.
58  */
59 enum EVENT_RESULT { EVENT_RESULT_UNHANDLED = 0,
60                     EVENT_RESULT_HANDLED,
61                     EVENT_RESULT_PAN_HORIZONTAL,
62                     EVENT_RESULT_PAN_VERTICAL,
63                     EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA,
64                     EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA,                    
65                     EVENT_RESULT_ROTATE,
66                     EVENT_RESULT_ZOOM };
67
68 /*!
69  \ingroup controls
70  \brief Base class for controls
71  */
72 class CGUIControl
73 {
74 public:
75   CGUIControl();
76   CGUIControl(int parentID, int controlID, float posX, float posY, float width, float height);
77   virtual ~CGUIControl(void);
78   virtual CGUIControl *Clone() const=0;
79
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();
84
85   bool HasRendered() const { return m_hasRendered; };
86
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);
95
96   // Common actions to make the code easier to read (no ugly switch statements in derived controls)
97   virtual void OnUp();
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() {};
106
107   /*! \brief React to a mouse event
108
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.
111
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
116    */
117   virtual EVENT_RESULT SendMouseEvent(const CPoint &point, const CMouseEvent &event);
118
119   /*! \brief Perform a mouse action
120
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.
123
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
128    */
129   virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) { return EVENT_RESULT_UNHANDLED; };
130
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
134    */
135   virtual void UnfocusFromPoint(const CPoint &point);
136
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.
140    \sa SetHitRect
141    */
142   virtual bool HitTest(const CPoint &point) const;
143
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;
168
169   void MarkDirtyRegion();
170
171   /*! \brief return the render region in screen coordinates of this control
172    */
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
176    */
177   virtual CRect CalcRenderRegion() const;
178
179   virtual void SetNavigation(int up, int down, int left, int right, int back = 0);
180   virtual void SetTabNavigation(int next, int prev);
181
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
190    \sa SetNavigation
191    */
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.
203    */
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 ""; };
218
219   void SetAnimations(const std::vector<CAnimation> &animations);
220   const std::vector<CAnimation> &GetAnimations() const { return m_animations; };
221
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();
228
229   // push information updates
230   virtual void UpdateInfo(const CGUIListItem *item = NULL) {};
231   virtual void SetPushUpdates(bool pushUpdates) { m_pushedUpdates = pushUpdates; };
232
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; };
236
237   void SetParentControl(CGUIControl *control) { m_parentControl = control; };
238   CGUIControl *GetParentControl(void) const { return m_parentControl; };
239   virtual void SaveStates(std::vector<CControlState> &states);
240
241   enum GUICONTROLTYPES {
242     GUICONTROL_UNKNOWN,
243     GUICONTROL_BUTTON,
244     GUICONTROL_CHECKMARK,
245     GUICONTROL_FADELABEL,
246     GUICONTROL_IMAGE,
247     GUICONTROL_BORDEREDIMAGE,
248     GUICONTROL_LARGE_IMAGE,
249     GUICONTROL_LABEL,
250     GUICONTROL_LISTGROUP,
251     GUICONTROL_PROGRESS,
252     GUICONTROL_RADIO,
253     GUICONTROL_RSS,
254     GUICONTROL_SELECTBUTTON,
255     GUICONTROL_SLIDER,
256     GUICONTROL_SETTINGS_SLIDER,
257     GUICONTROL_SPIN,
258     GUICONTROL_SPINEX,
259     GUICONTROL_TEXTBOX,
260     GUICONTROL_TOGGLEBUTTON,
261     GUICONTROL_VIDEO,
262     GUICONTROL_MOVER,
263     GUICONTROL_RESIZE,
264     GUICONTROL_EDIT,
265     GUICONTROL_VISUALISATION,
266     GUICONTROL_RENDERADDON,
267     GUICONTROL_MULTI_IMAGE,
268     GUICONTROL_GROUP,
269     GUICONTROL_GROUPLIST,
270     GUICONTROL_SCROLLBAR,
271     GUICONTROL_LISTLABEL,
272     GUICONTROL_MULTISELECT,
273     GUICONTAINER_LIST,
274     GUICONTAINER_WRAPLIST,
275     GUICONTAINER_FIXEDLIST,
276     GUICONTAINER_EPGGRID,
277     GUICONTAINER_PANEL
278   };
279   GUICONTROLTYPES GetControlType() const { return ControlType; }
280
281   enum GUIVISIBLE { HIDDEN = 0, DELAYED, VISIBLE };
282
283 #ifdef _DEBUG
284   virtual void DumpTextureUse() {};
285 #endif
286 protected:
287   /*!
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
290    */
291   virtual CPoint GetPosition() const { return CPoint(GetXPosition(), GetYPosition()); };
292
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.
297    */
298   virtual bool OnMouseOver(const CPoint &point);
299
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
304    */
305   virtual bool CanFocusFromPoint(const CPoint &point) const;
306
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);
312
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;
321
322   float m_posX;
323   float m_posY;
324   float m_height;
325   float m_width;
326   CRect m_hitRect;
327   CGUIInfoColor m_diffuseColor;
328   int m_controlID;
329   int m_parentID;
330   bool m_bHasFocus;
331   bool m_bInvalidated;
332   bool m_bAllocated;
333   bool m_pulseOnSelect;
334   GUICONTROLTYPES ControlType;
335
336   CGUIControl *m_parentControl;   // our parent control if we're part of a group
337
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;
344   bool m_hasRendered;
345   // enable/disable state
346   unsigned int m_enableCondition;
347   bool m_enabled;
348
349   bool m_pushedUpdates;
350
351   // animation effects
352   std::vector<CAnimation> m_animations;
353   CPoint m_camera;
354   bool m_hasCamera;
355   TransformMatrix m_transform;
356   TransformMatrix m_cachedTransform; // Contains the absolute transform the control
357
358   bool  m_controlIsDirty;
359   CRect m_renderRegion;         // In screen coordinates
360 };
361
362 #endif