Merge remote branch 'mine/ext-python'
[vuplus_xbmc] / xbmc / interfaces / python / xbmcmodule / control.h
1 /*
2  *      Copyright (C) 2005-2008 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include <Python.h>
23
24 #include "../XBPythonDll.h"
25 #include "listitem.h"
26 #include "guilib/GUIColorManager.h"
27
28 #pragma once
29
30 class CGUIControl;
31
32 // python type checking
33 #define Control_Check(op) PyObject_TypeCheck(op, &Control_Type)
34 #define Control_CheckExact(op) ((op)->ob_type == &Control_Type)
35
36 #define ControlButton_Check(op) PyObject_TypeCheck(op, &ControlButton_Type)
37 #define ControlButton_CheckExact(op) ((op)->ob_type == &ControlButton_Type)
38
39 #define ControlCheckMark_Check(op) PyObject_TypeCheck(op, &ControlCheckMark_Type)
40 #define ControlCheckMark_CheckExact(op) ((op)->ob_type == &ControlCheckMark_Type)
41
42 #define ControlProgress_Check(op) PyObject_TypeCheck(op, &ControlProgress_Type)
43 #define ControlProgress__CheckExact(op) ((op)->ob_type == &ControlProgress_Type)
44
45 #define ControlList_Check(op) PyObject_TypeCheck(op, &ControlList_Type)
46 #define ControlList_CheckExact(op) ((op)->ob_type == &ControlList_Type)
47
48 #define ControlSpin_Check(op) PyObject_TypeCheck(op, &ControlSpin_Type)
49 #define ControlSpin_CheckExact(op) ((op)->ob_type == &ControlSpin_Type)
50
51 #define ControlLabel_Check(op) PyObject_TypeCheck(op, &ControlLabel_Type)
52 #define ControlLabel_CheckExact(op) ((op)->ob_type == &ControlLabel_Type)
53
54 #define ControlFadeLabel_Check(op) PyObject_TypeCheck(op, &ControlFadeLabel_Type)
55 #define ControlFadeLabel_CheckExact(op) ((op)->ob_type == &ControlFadeLabel_Type)
56
57 #define ControlTextBox_Check(op) PyObject_TypeCheck(op, &ControlTextBox_Type)
58 #define ControlTextBox_CheckExact(op) ((op)->ob_type == &ControlTextBox_Type)
59
60 #define ControlImage_Check(op) PyObject_TypeCheck(op, &ControlImage_Type)
61 #define ControlImage_CheckExact(op) ((op)->ob_type == &ControlImage_Type)
62
63 #define ControlGroup_Check(op) PyObject_TypeCheck(op, &ControlGroup_Type)
64 #define ControlGroup_CheckExact(op) ((op)->ob_type == &ControlGroup_Type)
65
66 #define ControlRadioButton_Check(op) PyObject_TypeCheck(op, &ControlRadioButton_Type)
67 #define ControlRadioButton_CheckExact(op) ((op)->ob_type == &ControlRadioButton_Type)
68
69 #define ControlSlider_Check(op) PyObject_TypeCheck(op, &ControlSlider_Type)
70 #define ControlSlider_CheckExact(op) ((op)->ob_type == &ControlSlider_Type)
71
72 // -----------------
73
74 // hardcoded offsets for button controls (and controls that use button controls)
75 // ideally they should be dynamically read in as with all the other properties.
76 #define CONTROL_TEXT_OFFSET_X 10
77 #define CONTROL_TEXT_OFFSET_Y 2
78
79 #define PyObject_HEAD_XBMC_CONTROL  \
80     PyObject_HEAD                   \
81     int iControlId;                 \
82     int iParentId;                  \
83     int dwPosX;                     \
84     int dwPosY;                     \
85     int dwWidth;                    \
86     int dwHeight;                   \
87     int iControlUp;                 \
88     int iControlDown;               \
89     int iControlLeft;               \
90     int iControlRight;              \
91     CGUIControl* pGUIControl;
92
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96
97 namespace PYXBMC
98 {
99   typedef struct {
100     PyObject_HEAD_XBMC_CONTROL
101   } Control;
102
103   typedef struct {
104     PyObject_HEAD_XBMC_CONTROL
105     color_t color;
106     std::string strTextureUp;
107     std::string strTextureDown;
108     std::string strTextureUpFocus;
109     std::string strTextureDownFocus;
110   } ControlSpin;
111
112   typedef struct {
113     PyObject_HEAD_XBMC_CONTROL
114     std::string strFont;
115     std::string strText;
116     color_t textColor;
117     color_t disabledColor;
118     uint32_t align;
119     bool bHasPath;
120     int iAngle;
121   } ControlLabel;
122
123
124   typedef struct {
125     PyObject_HEAD_XBMC_CONTROL
126     std::string strFont;
127     color_t textColor;
128     std::vector<std::string> vecLabels;
129     uint32_t align;
130   } ControlFadeLabel;
131
132   typedef struct {
133     PyObject_HEAD_XBMC_CONTROL
134     std::string strFont;
135     color_t textColor;
136   } ControlTextBox;
137
138   typedef struct {
139     PyObject_HEAD_XBMC_CONTROL
140     std::string strFileName;
141     int aspectRatio;
142     color_t colorDiffuse;
143   } ControlImage;
144
145   typedef struct {
146   PyObject_HEAD_XBMC_CONTROL
147     std::string strTextureLeft;
148     std::string strTextureMid;
149     std::string strTextureRight;
150     std::string strTextureBg;
151     std::string strTextureOverlay;
152     int aspectRatio;
153     color_t colorDiffuse;
154   } ControlProgress;
155
156   typedef struct {
157     PyObject_HEAD_XBMC_CONTROL
158     std::string strFont;
159     std::string strText;
160     std::string strText2;
161     std::string strTextureFocus;
162     std::string strTextureNoFocus;
163     color_t textColor;
164     color_t disabledColor;
165     int textOffsetX;
166     int textOffsetY;
167     color_t align;
168     int iAngle;
169     int shadowColor;
170     int focusedColor;
171   } ControlButton;
172
173   typedef struct {
174     PyObject_HEAD_XBMC_CONTROL
175     std::string strFont;
176     std::string strText;
177     std::string strTextureFocus;
178     std::string strTextureNoFocus;
179     color_t textColor;
180     color_t disabledColor;
181     int checkWidth;
182     int checkHeight;
183     uint32_t align;
184   } ControlCheckMark;
185
186   typedef struct {
187     PyObject_HEAD_XBMC_CONTROL
188     std::vector<PYXBMC::ListItem*> vecItems;
189     std::string strFont;
190     ControlSpin* pControlSpin;
191
192     color_t textColor;
193     color_t selectedColor;
194     std::string strTextureButton;
195     std::string strTextureButtonFocus;
196
197     int imageHeight;
198     int imageWidth;
199     int itemHeight;
200     int space;
201
202     int itemTextOffsetX;
203     int itemTextOffsetY;
204     uint32_t alignmentY;
205   } ControlList;
206
207   typedef struct {
208     PyObject_HEAD_XBMC_CONTROL
209   } ControlGroup;
210
211   typedef struct {
212     PyObject_HEAD_XBMC_CONTROL
213     std::string strFont;
214     std::string strText;
215     std::string strTextureFocus;
216     std::string strTextureNoFocus;
217     std::string strTextureRadioFocus;
218     std::string strTextureRadioNoFocus;
219     color_t textColor;
220     color_t disabledColor;
221     int textOffsetX;
222     int textOffsetY;
223     uint32_t align;
224     int iAngle;
225     color_t shadowColor;
226     color_t focusedColor;
227   } ControlRadioButton;
228         
229   typedef struct {
230     PyObject_HEAD_XBMC_CONTROL
231     std::string strTextureBack;
232     std::string strTexture;
233     std::string strTextureFoc;    
234   } ControlSlider;      
235
236   extern void Control_Dealloc(Control* self);
237
238   extern PyMethodDef Control_methods[];
239
240   extern PyTypeObject Control_Type;
241   extern PyTypeObject ControlSpin_Type;
242   extern PyTypeObject ControlLabel_Type;
243   extern PyTypeObject ControlFadeLabel_Type;
244   extern PyTypeObject ControlTextBox_Type;
245   extern PyTypeObject ControlImage_Type;
246   extern PyTypeObject ControlGroup_Type;
247   extern PyTypeObject ControlButton_Type;
248   extern PyTypeObject ControlCheckMark_Type;
249   extern PyTypeObject ControlList_Type;
250   extern PyTypeObject ControlProgress_Type;
251   extern PyTypeObject ControlRadioButton_Type;
252   extern PyTypeObject ControlSlider_Type;
253
254   CGUIControl* ControlLabel_Create(ControlLabel* pControl);
255   CGUIControl* ControlFadeLabel_Create(ControlFadeLabel* pControl);
256   CGUIControl* ControlTextBox_Create(ControlTextBox* pControl);
257   CGUIControl* ControlButton_Create(ControlButton* pControl);
258   CGUIControl* ControlCheckMark_Create(ControlCheckMark* pControl);
259   CGUIControl* ControlImage_Create(ControlImage* pControl);
260   CGUIControl* ControlGroup_Create(ControlGroup* pControl);
261   CGUIControl* ControlList_Create(ControlList* pControl);
262   CGUIControl* ControlProgress_Create(ControlProgress* pControl);
263   CGUIControl* ControlRadioButton_Create(ControlRadioButton* pControl);
264   CGUIControl* ControlSlider_Create(ControlSlider* pControl);
265
266   void initControl_Type();
267   void initControlSpin_Type();
268   void initControlLabel_Type();
269   void initControlFadeLabel_Type();
270   void initControlTextBox_Type();
271   void initControlButton_Type();
272   void initControlCheckMark_Type();
273   void initControlList_Type();
274   void initControlImage_Type();
275   void initControlGroup_Type();
276   void initControlProgress_Type();
277   void initControlRadioButton_Type();
278   void initControlSlider_Type();
279 }
280
281 #ifdef __cplusplus
282 }
283 #endif