00001 #ifndef ZSURFACE_H
00002 #define ZSURFACE_H
00003
00004 #include <qimage.h>
00005 #include <qpixmap.h>
00006 #include <qstring.h>
00007 #include <qdirectpainter_qws.h>
00008 #include <qgfx_qws.h>
00009
00010
00011
00012
00013
00014
00015 class ZFont;
00017
00063 class ZSurface
00064 {
00065
00066
00067 public:
00068
00069 enum ZROTATION
00070 {
00071 Z0,
00072 Z90,
00073 Z270
00074 };
00075
00079 ZSurface();
00083 ZSurface(int w, int h, bool alpha=false);
00089 ZSurface(const QImage &img, bool alpha=false);
00094 ZSurface(const QPixmap &pix, bool alpha=false);
00098 ZSurface(const ZSurface &);
00102 virtual ~ZSurface();
00103
00107 ZSurface & operator=(const ZSurface &z);
00108
00116 virtual bool create(const QImage &, bool alpha=false);
00120 virtual bool create(const QPixmap &, bool alpha=false);
00129 virtual bool create(int width, int height, bool alpha=false);
00130
00134 void fill(QColor clr);
00135
00139 bool drawLine(int x1, int y1, int x2, int y2, QColor clr);
00144 bool drawLineBlend(int x1, int y1, int x2, int y2, QColor clr, int opacity);
00145
00146
00147
00148
00149 static ZROTATION rotation()
00150 {
00151 return zrot;
00152 }
00153
00154 static void setRotation(ZROTATION zr )
00155 {
00156 zrot=zr;
00157 }
00158
00168 static bool bitBlit(QDirectPainter *dst, const ZSurface *src,ZROTATION r);
00169
00178 static bool bitBlit(ZSurface *dst, int dx, int dy, const ZSurface *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
00179
00191 static bool bitBlitBlend(int opacity, ZSurface *dst, int dx, int dy, const ZSurface *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
00203 static bool bitBlitAlpha(ZSurface *dst, int dx, int dy, const ZSurface *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
00214 static bool bitBlitKeyed(ZSurface *dst, int dx, int dy,const QColor &key, const ZSurface *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
00215
00227 static bool bitBlitKeyedBlend(int opacity, ZSurface *dst, int dx, int dy,const QColor &key, const ZSurface *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
00228
00240 static bool fillBlitKeyed(ZSurface *dst, int dx, int dy,const QColor &key,const QColor &fillColor, const ZSurface *src, int sx=0, int sy=0, int sw=-1, int sh=-1);
00241
00255 static bool fillBlitKeyedBlend(int opacity,ZSurface *dst, int dx, int dy,const QColor &key,const QColor &fillColor, const ZSurface *src,
00256 int sx=0, int sy=0, int sw=-1, int sh=-1);
00257
00264 static bool fillRect(ZSurface *dst, int dx, int dy,int rw, int rh,const QColor &clr);
00265
00272 static bool fillRectBlend(int opacity,ZSurface *dst, int dx, int dy,int rw, int rh,const QColor &clr);
00273
00279 int ZSurface::drawText(int dx, int ny,const QString &s, ZFont *f, int opacity=32);
00280
00286 int ZSurface::drawText(int dx, int ny,const QString &s, ZFont *f,QColor c, int opacity=32);
00287
00291 inline bool isValid() const
00292 {
00293 return (bool) data;
00294 }
00295
00300 inline bool hasAlpha() const
00301 {
00302 return (bool) adata;
00303 }
00304
00308 inline int width() const
00309 {
00310 return iW;
00311 }
00312
00317 inline int size() const
00318 {
00319 return iTW*iH*iD;
00320 }
00321
00328 inline int scanlineWidth() const
00329 {
00330 return iTW;
00331 }
00332
00337 inline int height() const
00338 {
00339 return iH;
00340 }
00341
00345 inline int depth() const
00346 {
00347 return iD*8;
00348 }
00349
00350
00355 inline void setPixel(int x, int y, const QColor &c)
00356 {
00357 if ( (x>=0 && x <iW) && (y>=0 && y<iH) )
00358 {
00359 *((ushort*)data+(y*iTW)+x)=qt_convRgbTo16(c.rgb());
00360 }
00361 }
00362
00367 inline void getPixel(int x, int y, QColor &c)
00368 {
00369 if ( (x>=0 && x <iW) && (y>=0 && y<iH) )
00370 {
00371 c.setRgb(qt_conv16ToRgb((unsigned short)*((ushort*)data+(y*iTW)+x)));
00372 }
00373 }
00377 inline unsigned short* bits()
00378 {
00379 return (unsigned short*)data;
00380 }
00381
00386 inline unsigned short* alpha()
00387 {
00388 return (unsigned short*)adata;
00389 }
00390
00391
00392 protected:
00393
00394 void initFromImage(const QImage &i);
00395
00396
00397 private:
00398
00399 typedef struct BLIT_PARAMETERS
00400 {
00401 unsigned char *dst;
00402 unsigned char *src;
00403 unsigned int sw;
00404 unsigned int sh;
00405 unsigned int ss;
00406 unsigned int ds;
00407 unsigned int key;
00408 unsigned int color;
00409 unsigned int alpha;
00410 unsigned char *asrc;
00411 unsigned int depth;
00412 } BLIT_PARS;
00413
00414 enum
00415 {
00416 TOP = 0x1, BOTTOM = 0x2, RIGHT = 0x4, LEFT = 0x8
00417 };
00418
00419 bool clipLine (int &x0, int &y0, int &x1, int &y1, QRect clip);
00420 unsigned int ZSurface::getCode (int x, int y, QRect r);
00421
00422
00423
00424
00425 static bool ZSurface::computeBlitPars( BLIT_PARS *bpar,ZSurface *dst, int dx, int dy, const ZSurface *src, int sx, int sy, int sw, int sh);
00426 static bool ZSurface::computeBlitPars( BLIT_PARS *bpar,ZSurface *dst, int dx, int dy,int sw, int sh);
00427
00428
00429 void initSurface();
00430 void copySurface(const ZSurface&);
00431
00432 int iW;
00433 int iTW;
00434 int iH;
00435 int iD;
00436
00437 unsigned char *data;
00438 unsigned char *adata;
00439
00440
00441 static ZROTATION zrot;
00442 };
00443
00444 #endif // INPUT_DIALOG_H
00445