00001
00002 #ifndef jAPIdirectXH
00003 #define jAPIdirectXH
00004
00005
00006 #ifndef WIN32 // necessary for d3dtypes.h
00007 #define WIN32
00008 #endif
00009
00010 #include <mplayer.hpp>
00011
00012 #include <ddraw.h>
00013 #include <dsound.h>
00014 #include <map.h>
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 DDColorMatch(IDirectDrawSurface *pdds, COLORREF rgb);
00027
00028
00029
00030
00031
00032 class jDDraw
00033 {
00034 LPDIRECTDRAW lpDD;
00035 LPDIRECTDRAWSURFACE lpDDSPrimary;
00036 LPDIRECTDRAWSURFACE lpDDSBack;
00037 LPDIRECTDRAWPALETTE lpDDPal;
00038
00039 void * handle;
00040
00041 void __fastcall raz();
00042
00043 bool __fastcall create();
00044 bool __fastcall setCooperative(int mode);
00045 bool __fastcall createSurfaces();
00046 bool __fastcall setPalette(char * name);
00047 bool __fastcall copyBitmap(LPDIRECTDRAWSURFACE pdds, HBITMAP hbm, int x, int y, int dx, int dy, RECT * _rect = NULL);
00048 IDirectDrawPalette * __fastcall loadPalette(LPCSTR szBitmap);
00049
00050 public:
00051
00052 int width;
00053 int height;
00054
00055 bool __fastcall createSurface(LPDIRECTDRAWSURFACE * _surf, DWORD _type, int _width, int _height, DWORD flags, int nbBackBuffers=0);
00056
00057 bool __fastcall initialize(void * _handle, int width, int height, int color, int mode = DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN, char * palette = NULL);
00058 bool __fastcall release();
00059 bool __fastcall setDisplay(int width, int height, int color);
00060
00061 LPDIRECTDRAW __fastcall getDrawingContext() { return lpDD; }
00062 LPDIRECTDRAWSURFACE __fastcall loadSurface(LPCTSTR _fileName, RECT * _rect);
00063
00064 bool __fastcall textOut(int posX, int posY, AnsiString message, int bkColor, int txtColor, int mode = TRANSPARENT);
00065 bool __fastcall drawLine(LPDIRECTDRAWSURFACE src, int debX, int debY, int endX, int endY, int bkColor, int ftColor, int width);
00066 bool __fastcall fill(LPDIRECTDRAWSURFACE src = NULL, RECT * rect = NULL, int color = RGB(0, 0, 0));
00067 bool __fastcall drawRect(CONST RECT *lprc, int color);
00068 bool __fastcall clear(RECT * rect = NULL);
00069 bool __fastcall show();
00070 bool __fastcall draw(int posX, int posY, LPDIRECTDRAWSURFACE src, RECT * rc, int mode, bool wait = false);
00071
00072 jDDraw();
00073 jDDraw(void * handle, int width, int height, int color);
00074 ~jDDraw();
00075
00076 };
00077
00078
00079
00080
00081
00082 class jDsprite
00083 {
00084 jDDraw * lpDD;
00085
00086 public:
00087 LPDIRECTDRAWSURFACE surface;
00088 RECT rect;
00089
00090 int transpColor;
00091 bool transparent;
00092
00093 jDsprite(jDDraw * _lpDD);
00094 jDsprite(jDDraw * _lpDD, LPCTSTR _fileName);
00095 ~jDsprite();
00096
00097 bool __fastcall loadFromFile(LPCTSTR _fileName);
00098 bool __fastcall create(int _width, int _height);
00099 bool __fastcall drawLine(int debX, int debY, int endX, int endY, int bkColor, int ftColor, int width) { return (lpDD && lpDD->drawLine(surface, debX, debY, endX, endY, bkColor, ftColor, width)); }
00100 bool __fastcall draw(int posX, int posY) { return (lpDD && lpDD->draw(posX, posY, surface, &rect, transparent ? DDBLTFAST_SRCCOLORKEY : 0, false)); }
00101 bool __fastcall fill(int color) { return (lpDD && lpDD->fill(surface, &rect, color)); }
00102 bool __fastcall release();
00103 bool __fastcall setTransparent(bool _transparent, COLORREF _transpColor);
00104 };
00105
00106
00107
00108
00109
00110 class jDspriteCollection
00111 {
00112 jDDraw * lpDD;
00113 map<AnsiString, jDsprite *, less<AnsiString> > sprites;
00114
00115 public:
00116 int spriteWidth;
00117 int spriteHeight;
00118
00119 jDspriteCollection(jDDraw * _lpDD);
00120 ~jDspriteCollection();
00121
00122 bool __fastcall clear();
00123 bool __fastcall loadFromFiles(AnsiString location);
00124 bool __fastcall loadFromFiles(TStrings * sl);
00125
00126 jDsprite * __fastcall operator[] (unsigned int num);
00127 jDsprite * __fastcall at(unsigned int num);
00128 jDsprite * __fastcall at(AnsiString _key);
00129 unsigned int __fastcall count();
00130 };
00131
00132
00133
00134
00135
00136 class jDSound
00137 {
00138 LPDIRECTSOUND lpDS;
00139
00140 void * handle;
00141
00142 void __fastcall raz();
00143
00144 bool __fastcall create();
00145 bool __fastcall setCooperative(int mode);
00146
00147 public:
00148
00149 bool __fastcall createBuffer(LPDIRECTSOUNDBUFFER * _pdds, int _flags, LPWAVEFORMATEX _header, DWORD _size);
00150 bool __fastcall initialize(void * _handle, int mode = DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_STATIC);
00151 bool __fastcall release();
00152
00153 LPDIRECTSOUNDBUFFER __fastcall loadSound(LPCTSTR _fileName, LPBYTE & _start, LPWAVEFORMATEX & _header, LPBYTE & _data, DWORD & _size);
00154
00155 bool __fastcall play(LPDIRECTSOUNDBUFFER _src, int _mode);
00156 bool __fastcall stop(LPDIRECTSOUNDBUFFER _src);
00157
00158 jDSound();
00159 jDSound(void * _handle);
00160 ~jDSound();
00161
00162 };
00163
00164 class jDSoundBuffer
00165 {
00166 jDSound * lpDS;
00167
00168 LPBYTE start;
00169 LPWAVEFORMATEX header;
00170 LPBYTE data;
00171 DWORD size;
00172
00173 LPDIRECTSOUNDBUFFER buffer;
00174
00175 public:
00176
00177 bool __fastcall loadFromFile(LPCTSTR _fileName);
00178 bool __fastcall play(int _mode);
00179 bool __fastcall stop();
00180 };
00181
00182 #endif