123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /**
- * Copyright (c) 2011 Nokia Corporation.
- *
- * CAUTION: This class is in early, experimental state.
- *
- */
- #ifndef __SPRITEBATCH__
- #define __SPRITEBATCH__
- #include <memory.h>
- struct SpriteDrawInfo
- {
- SpriteDrawInfo() {
- sourcex = 0;
- sourcey = 0;
- sourceWidth = 1;
- sourceHeight = 1;
- r = 1;
- g = 1;
- b = 1;
- a = 1;
- posx = 0;
- posy = 0;
- angle = 0;
- sourceAngle = 0;
- scaleX = 1.0f;
- scaleY = 1.0f;
- manualTransformActive = false;
- }
- // Setter helpers
- void setTargetPos( float xi, float yi ) {
- posx = xi;
- posy = yi;
- }
- void setColor( float ri, float gi, float bi, float ai ) {
- r = ri; g = gi; b = bi; a = ai;
- }
- void setColor( float *col ) {
- r = col[0]; g = col[1]; b = col[2]; a = col[3];
- }
- void setSourceRect( float x=0.0f, float y=0.0f, float w=1.0f, float h=1.0f) {
- sourcex = x;
- sourcey = y;
- sourceWidth = w;
- sourceHeight = h;
- }
- void setSourceRect( float *rec ) {
- sourcex = rec[0];
- sourcey = rec[1];
- sourceWidth = rec[2];
- sourceHeight = rec[3];
- }
- void setScale( float scale ) {
- scaleX = scale;
- scaleY = scale;
- }
- void setScale( float scaleXi, float scaleYi ) {
- scaleX = scaleXi;
- scaleY = scaleYi;
- }
- void manualTransform( float xvx, float xvy, float yvx, float yvy ) {
- manualTransformMatrix[0][0] = xvx;
- manualTransformMatrix[0][1] = xvy;
- manualTransformMatrix[1][0] = yvx;
- manualTransformMatrix[1][1] = yvy;
- manualTransformActive = true;
- }
- void disableManualTransform() { manualTransformActive = false; }
- // Texture handle
- unsigned int textureHandle;
- // Target position
- float posx;
- float posy;
- // Source rectangle.
- float sourcex;
- float sourcey;
- float sourceWidth;
- float sourceHeight;
- // Blit color. NOTE, these must be in this order r,g,b,a must be next to eachother in structures memory
- float r,g,b,a;
- // source angle
- float sourceAngle;
- // Scale
- bool manualTransformActive;
- float manualTransformMatrix[2][2];
- float scaleX, scaleY;
- float angle;
- // For now, TODO, thinkAbout.
- // Effects ignored.
- // Layer depth ignored.
- };
- class SpriteBatch
- {
- public:
- enum TransformMode { ePIXELSPACE, eCUSTOMPROJECTION };
- enum BlendMode { eALPHA, eADDITIVE };
- SpriteBatch(int tWidth, int tHeight) {
- setTargetSize(tWidth, tHeight);
- }
- virtual ~SpriteBatch() {}
- virtual void begin( BlendMode bmode = eALPHA, TransformMode dTransform = ePIXELSPACE, float *customProjectionMatrix = 0) {}
- virtual void end() {}
- virtual void draw ( SpriteDrawInfo *sdi, int spriteCount=1 ) = 0;
- // Helper draws
- void draw( int texture, float x, float y, float w, float h, float angle = 0.0f );
- void draw( int texture, float x, float y, float w, float h, float *col );
- void draw( int texture, float x, float y, float w, float h, float *col, float angle );
- virtual void flushSprites(bool useTable=true) = 0; // Force flush,..
- inline int getTargetWidth() { return targetWidth; }
- inline int getTargetHeight() { return targetHeight; }
- inline void setTargetSize( int w, int h ) {
- #ifdef Q_WS_MAEMO_6_removed_as_firecup_is_landscape_app
- targetWidth = h;
- targetHeight = w;
- #else
- targetWidth = w;
- targetHeight = h;
- #endif
- }
- protected:
- int targetWidth;
- int targetHeight;
- };
- #endif
|