summaryrefslogtreecommitdiff
path: root/Source/++DFB/include/++dfb.h
blob: fc7b8634c4cc969b296df0c0dbc9ec0fddac227a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
   (c) Copyright 2000-2002  convergence integrated media GmbH.
   All rights reserved.

   Written by Denis Oliver Kropp <dok@convergence.de>,
              Andreas Hundt <andi@convergence.de> and
              Sven Neumann <sven@convergence.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#ifndef DFBPP_H
#define DFBPP_H

#ifdef __DIRECTFB_H__
#error Please include '++dfb.h' before 'directfb.h'.
#endif

#include <iostream>

#define IDirectFB              IDirectFB_C
#define IDirectFBScreen        IDirectFBScreen_C
#define IDirectFBDisplayLayer  IDirectFBDisplayLayer_C
#define IDirectFBSurface       IDirectFBSurface_C
#define IDirectFBPalette       IDirectFBPalette_C
#define IDirectFBWindow        IDirectFBWindow_C
#define IDirectFBInputDevice   IDirectFBInputDevice_C
#define IDirectFBEventBuffer   IDirectFBEventBuffer_C
#define IDirectFBFont          IDirectFBFont_C
#define IDirectFBImageProvider IDirectFBImageProvider_C
#define IDirectFBVideoProvider IDirectFBVideoProvider_C
#define IDirectFBDataBuffer    IDirectFBDataBuffer_C

#define DFBPoint     DFBPoint_C
#define DFBDimension DFBDimension_C
#define DFBRectangle DFBRectangle_C
#define DFBRegion    DFBRegion_C


extern "C" {
#include <directfb.h>
#include <directfb_strings.h>
#include <directfb_util.h>
}

#undef IDirectFB
#undef IDirectFBScreen
#undef IDirectFBDisplayLayer
#undef IDirectFBSurface
#undef IDirectFBPalette
#undef IDirectFBWindow
#undef IDirectFBInputDevice
#undef IDirectFBEventBuffer
#undef IDirectFBFont
#undef IDirectFBImageProvider
#undef IDirectFBVideoProvider
#undef IDirectFBDataBuffer

#undef DFBPoint
#undef DFBDimension
#undef DFBRectangle
#undef DFBRegion



class DFBPoint : public DFBPoint_C {
public:
     DFBPoint() {
          x = 0;
          y = 0;
     }

     DFBPoint( const int &_x, const int &_y ) {
          x = _x;
          y = _y;
     }

     DFBPoint( const DFBPoint_C &point ) {
          x = point.x;
          y = point.y;
     }

     DFBPoint( const DFBRectangle_C &rectangle ) {
          x = rectangle.x;
          y = rectangle.y;
     }

     DFBPoint( const DFBRegion_C &region ) {
          x = region.x1;
          y = region.y1;
     }

     bool operator== ( const DFBPoint &ref ) const {
          return ref.x == x && ref.y == y;
     }

     DFBPoint operator +( const DFBPoint &offset ) const {
          DFBPoint p( *this );
          p.x += offset.x;
          p.y += offset.y;
          return p;
     }

     DFBPoint& operator +=( const DFBPoint& offset ) {
          x += offset.x;
          y += offset.y;
          return *this;
     }
};

class DFBDimension : public DFBDimension_C {
public:
     DFBDimension() {
          w = 0;
          h = 0;
     }

     DFBDimension( const int &_w, const int &_h ) {
          w = _w;
          h = _h;
     }

     DFBDimension( const DFBDimension_C &dimension ) {
          w = dimension.w;
          h = dimension.h;
     }

     DFBDimension( const DFBPoint_C &point ) {
          w = point.x;
          h = point.y;
     }

     DFBDimension( const DFBRectangle_C &rectangle ) {
          w = rectangle.w;
          h = rectangle.h;
     }

     DFBDimension( const DFBRegion_C &region ) {
          w = region.x2 - region.x1 + 1;
          h = region.y2 - region.y1 + 1;
     }

     bool operator== ( const DFBDimension &ref ) const {
          return ref.w == w && ref.h == h;
     }

	bool contains( const DFBRegion_C &region ) const {
		if (region.x1 < 0 || region.y1 < 0)
			return false;

		if (region.x2 >= w || region.y2 >= h)
			return false;

		return true;
	}
};



class DFBRectangle : public DFBRectangle_C {
public:
     DFBRectangle() {
          x = 0;
          y = 0;
          w = 0;
          h = 0;
     }

     DFBRectangle( const int &_x, const int &_y, const int &_w, const int &_h ) {
          x = _x;
          y = _y;
          w = _w;
          h = _h;
     }

     DFBRectangle( const DFBRectangle_C &rectangle ) {
          x = rectangle.x;
          y = rectangle.y;
          w = rectangle.w;
          h = rectangle.h;
     }

     DFBRectangle( const DFBRegion_C &region ) {
          x = region.x1;
          y = region.y1;
          w = region.x2 - region.x1 + 1;
          h = region.y2 - region.y1 + 1;
     }

     DFBRectangle( const DFBDimension_C &dimension ) {
          x = 0;
          y = 0;
          w = dimension.w;
          h = dimension.h;
     }

     DFBRectangle( const DFBPoint_C &point, const DFBDimension_C &dimension ) {
          x = point.x;
          y = point.y;
          w = dimension.w;
          h = dimension.h;
     }

     bool operator== ( const DFBRectangle &ref ) const {
          return ref.x == x && ref.y == y && ref.w == w && ref.h == h;
     }

     DFBRectangle& operator-= ( const DFBPoint &sub ) {
          x -= sub.x;
          y -= sub.y;

          return *this;
     }

     DFBRectangle operator -( const DFBPoint &sub ) const {
          return DFBRectangle( x - sub.x, y - sub.y, w, h );
     }

     DFBRectangle operator +( const DFBPoint &offset ) const {
          DFBRectangle r( *this );
          r.x += offset.x;
          r.y += offset.y;
          return r;
     }
};


class DFBRegion : public DFBRegion_C {
public:
     DFBRegion() {
          x1 = 0;
          y1 = 0;
          x2 = 0;
          y2 = 0;
     }

     DFBRegion( const int &_x1, const int &_y1, const int &_x2, const int &_y2 ) {
          x1 = _x1;
          y1 = _y1;
          x2 = _x2;
          y2 = _y2;
     }

     DFBRegion( const DFBRegion_C &region ) {
          x1 = region.x1;
          y1 = region.y1;
          x2 = region.x2;
          y2 = region.y2;
     }

     DFBRegion( const DFBRectangle_C &rectangle ) {
          x1 = rectangle.x;
          y1 = rectangle.y;
          x2 = x1 + rectangle.w - 1;
          y2 = y1 + rectangle.h - 1;
     }

     DFBRegion( const DFBDimension_C &dimension ) {
          x1 = 0;
          y1 = 0;
          x2 = dimension.w - 1;
          y2 = dimension.h - 1;
     }

     DFBRegion( const DFBPoint_C &point, const DFBDimension_C &dimension ) {
          x1 = point.x;
          y1 = point.y;
          x2 = x1 + dimension.w - 1;
          y2 = y1 + dimension.h - 1;
     }

     bool operator== ( const DFBRegion &ref ) const {
          return ref.x1 == x1 && ref.y1 == y1 && ref.x2 == x2 && ref.y2 == y2;
     }

     DFBRegion& operator-= ( const DFBPoint &sub ) {
          x1 -= sub.x;
          y1 -= sub.y;
          x2 -= sub.x;
          y2 -= sub.y;

          return *this;
     }

     DFBRegion operator- ( const DFBPoint &sub ) const {
          return DFBRegion( x1 - sub.x, y1 - sub.y, x2 - sub.x, y2 - sub.y );
     }

     DFBRegion& operator|= ( const DFBRegion &r ) {
          if (r.x1 < x1)
               x1 = r.x1;

          if (r.y1 < y1)
               y1 = r.y1;

          if (r.x2 > x2)
               x2 = r.x2;

          if (r.y2 > y2)
               y2 = r.y2;

          return *this;
     }

     void unionWith ( const DFBRegion &r ) {
          if (r.x1 < x1)
               x1 = r.x1;

          if (r.y1 < y1)
               y1 = r.y1;

          if (r.x2 > x2)
               x2 = r.x2;

          if (r.y2 > y2)
               y2 = r.y2;
     }
};



template <class IMPLEMENTINGCLASS, class IPPAny_C>
class IPPAny
{
	protected:
		IPPAny(IPPAny_C *iface) {
			this->iface = iface;
		}
		inline IPPAny_C *get_iface() { return iface; }
		inline IPPAny_C *get_iface() const { return iface; }

	public:
		IPPAny_C* iface;
	public:
		IPPAny(){
			iface = NULL;
		}

		IPPAny(const IPPAny &other) {
			IPPAny_C *other_iface = other.iface;
			if (other_iface)
				other_iface->AddRef( other_iface );
			iface = other_iface;
		}

		virtual ~IPPAny() {
			if (iface)
				iface->Release( iface );
		}
		inline operator IMPLEMENTINGCLASS*() {
			return dynamic_cast<IMPLEMENTINGCLASS*>(this);
		}
		inline operator IMPLEMENTINGCLASS*() const{
 			return dynamic_cast<IMPLEMENTINGCLASS*> (this);
 		}
		inline operator bool() {
			return iface != NULL;
		}
		inline IMPLEMENTINGCLASS &operator = (const IMPLEMENTINGCLASS &other) {
			IPPAny_C *other_iface = other.iface;

			if (other_iface)
				other_iface->AddRef( other_iface );
			if (iface)
				iface->Release( iface );
			iface = other_iface;
			return dynamic_cast<IMPLEMENTINGCLASS&>(*this);
		}
		inline IMPLEMENTINGCLASS &operator = (IPPAny_C *other_iface) {
			if (other_iface)
				other_iface->AddRef( other_iface );
			if (iface)
				iface->Release( iface );
			iface = other_iface;
			return dynamic_cast<IMPLEMENTINGCLASS&>(*this);
		}
};




class DirectFB;
class IDirectFB;
class IDirectFBScreen;
class IDirectFBDisplayLayer;
class IDirectFBSurface;
class IDirectFBPalette;
class IDirectFBWindow;
class IDirectFBInputDevice;
class IDirectFBEventBuffer;
class IDirectFBFont;
class IDirectFBImageProvider;
class IDirectFBVideoProvider;
class IDirectFBDataBuffer;


#include "idirectfb.h"
#include "idirectfbscreen.h"
#include "idirectfbdisplaylayer.h"
#include "idirectfbsurface.h"
#include "idirectfbpalette.h"
#include "idirectfbwindow.h"
#include "idirectfbinputdevice.h"
#include "idirectfbeventbuffer.h"
#include "idirectfbfont.h"
#include "idirectfbimageprovider.h"
#include "idirectfbvideoprovider.h"
#include "idirectfbdatabuffer.h"


#define DFB_ADD_SURFACE_DESC(d,f)   (d) = static_cast<DFBSurfaceDescriptionFlags>  ((d) | (f))
#define DFB_ADD_SURFACE_CAPS(c,f)   (c) = static_cast<DFBSurfaceCapabilities>      ((c) | (f))
#define DFB_ADD_DRAWING_FLAG(d,f)   (d) = static_cast<DFBSurfaceDrawingFlags>      ((d) | (f))
#define DFB_ADD_BLITTING_FLAG(b,f)  (b) = static_cast<DFBSurfaceBlittingFlags>     ((b) | (f))


class DirectFB {
public:
     static void      Init   (int *argc = NULL, char *(*argv[]) = NULL);
     static IDirectFB Create ();
};

class DFBException {
public:
     DFBException (const char *action, DFBResult result_code);

     const char *GetAction() const;
     const char *GetResult() const;
     DFBResult   GetResultCode() const;

     friend std::ostream &operator << (std::ostream &stream, DFBException *ex);

private:
     const char *action;
     DFBResult   result_code;
};



#endif