Ginga  0.13.6
 All Classes Namespaces Functions Variables
SDLWindow.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef SDLWINDOW_H_
51 #define SDLWINDOW_H_
52 
53 #include "util/Color.h"
54 using namespace ::br::pucrio::telemidia::util;
55 
56 #include "mb/interface/IWindow.h"
57 
58 #include "SDL.h"
59 
60 typedef uint32_t Uint32;
61 typedef Uint32 SDL_WindowID;
62 
63 #include <iostream>
64 #include <vector>
65 using namespace std;
66 
67 namespace br {
68 namespace pucrio {
69 namespace telemidia {
70 namespace ginga {
71 namespace core {
72 namespace mb {
73 
74  typedef struct DrawData {
75  int coord1;
76  int coord2;
77  int coord3;
78  int coord4;
79  short dataType;
80  int r;
81  int g;
82  int b;
83  int a;
84  } DrawData;
85 
86  class SDLWindow : public IWindow {
87  public:
88  static const short DDT_LINE = 0;
89  static const short DDT_RECT = 1;
90  static const short DDT_FILL_RECT = 2;
91 
92  private:
93  SDL_Texture* texture;
94  SDL_Surface* curSur;
95 
96  ISurface* winISur;
97 
98  bool textureUpdate;
99  bool textureOwner;
100 
101  int borderWidth;
102  IColor* bgColor;
103  IColor* borderColor;
104  IColor* winColor;
105  IColor* colorKey;
106 
107  GingaScreenID myScreen;
108  GingaWindowID windowId;
109  GingaWindowID parentId;
110 
111  SDL_Rect rect;
112 
113  float z;
114  int transparencyValue;
115  bool visible;
116  bool ghost;
117 
118  ISurface* childSurface;
119  bool fit;
120  bool stretch;
121  int caps;
122 
123  pthread_mutex_t mutex; //external mutex
124  pthread_mutex_t mutexC; //childs mutex
125  pthread_mutex_t texMutex; //texture mutex
126  pthread_mutex_t surMutex; //underlying surface mutex
127 
128  bool isWaiting;
129  pthread_mutex_t rMutex; //render mutex
130  pthread_mutex_t cMutex; //condition mutex
131  pthread_cond_t cond;
132 
133  public:
134  SDLWindow(
135  GingaWindowID underlyingWindowID,
136  GingaWindowID parentWindowID,
137  GingaScreenID screenId,
138  int x, int y, int width, int height,
139  float z);
140 
141  virtual ~SDLWindow();
142 
143  private:
144  void initialize(
145  GingaWindowID underlyingWindowID,
146  GingaWindowID parentWindowID,
147  GingaScreenID screenId,
148  int x, int y, int width, int height,
149  float z);
150 
151  void releaseWinISur();
152  void releaseBGColor();
153  void releaseWinColor();
154  void releaseColorKey();
155  void releaseBorderColor();
156 
157  public:
158  void setBgColor(int r, int g, int b, int alpha);
159  IColor* getBgColor();
160  void setColorKey(int r, int g, int b);
161  IColor* getColorKey();
162  void setWindowColor(int r, int g, int b, int alpha);
163  IColor* getWindowColor();
164  void setBorder(int r, int g, int b, int alpha=255, int bWidth=0);
165  void getBorder(int* r, int* g, int* b, int* alpha, int* bWidth);
166 
167  GingaScreenID getScreen();
168  void revertContent();
169  void setChildSurface(ISurface* iSur);
170  int getCap(string cap);
171  void setCaps(int caps);
172  void addCaps(int capability);
173  int getCaps();
174 
175  void draw();
176  void setBounds(int x, int y, int width, int height);
177  void moveTo(int x, int y);
178  void resize(int width, int height);
179  void raiseToTop();
180  void lowerToBottom();
181  void setCurrentTransparency(int alpha);
182  int getTransparencyValue();
183  GingaWindowID getId();
184  void show();
185  void hide();
186 
187  int getX();
188  int getY();
189  int getW();
190  int getH();
191  float getZ();
192 
193  void setX(int x);
194  void setY(int y);
195  void setW(int w);
196  void setH(int h);
197  void setZ(float z);
198 
199  bool isGhostWindow();
200  void setGhostWindow(bool ghost);
201  bool isVisible();
202  void validate();
203 
204  private:
205  void unprotectedValidate();
206 
207  public:
208  vector<DrawData*>* createDrawDataList();
209  void setStretch(bool stretchTo);
210  bool getStretch();
211  void setFit(bool fitTo);
212  bool getFit();
213  void clearContent();
214  void setRenderedSurface(SDL_Surface* uSur);
215  void* getContent();
216  void setTexture(SDL_Texture* texture);
217  SDL_Texture* getTexture(SDL_Renderer* renderer);
218  bool isTextureOwner(SDL_Texture* texture);
219 
220  private:
221  bool isMine(ISurface* surface);
222 
223  public:
224  void renderImgFile(string serializedImageUrl);
225  void renderFrom(ISurface* s);
226 
227  void blit(IWindow* src);
228  void stretchBlit(IWindow* src);
229  string getDumpFileUri(int quality, int dumpW, int dumpH);
230 
231  void lock();
232  void unlock();
233 
234  void lockChilds();
235  void unlockChilds();
236 
237  bool rendered();
238 
239  private:
240  void waitRenderer();
241 
242  void lockTexture();
243  void unlockTexture();
244 
245  void lockSurface();
246  void unlockSurface();
247  };
248 }
249 }
250 }
251 }
252 }
253 }
254 
255 #endif /*SDLWINDOW_H_*/
Definition: IColor.h:64