Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
#ifndef __GRAPHICS_H__
2
#define __GRAPHICS_H__
3
 
4
#include "Common.h"
5
#include "Rect.h"
6
#include "Color.h"
7
#include "Image.h"
8
#include "TriVertex.h"
9
 
10
namespace Sexy
11
{
12
 
13
class Font;
14
class SexyMatrix3;
15
class Transform;
16
 
17
const int MAX_TEMP_SPANS = 8192;
18
 
19
struct Edge
20
{
21
    double mX;
22
    double mDX;
23
    int i;
24
        double b;
25
};
26
 
27
class Graphics;
28
 
29
class GraphicsState
30
{
31
public:
32
        static Image                    mStaticImage;
33
        Image*                                  mDestImage;
34
        float                                   mTransX;
35
        float                                   mTransY;
36
        float                                   mScaleX;
37
        float                                   mScaleY;
38
        float                                   mScaleOrigX;
39
        float                                   mScaleOrigY;
40
        Rect                                    mClipRect;
41
        Color                                   mColor;
42
        Font*                                   mFont;
43
        int                                             mDrawMode;
44
        bool                                    mColorizeImages;
45
        bool                                    mFastStretch;
46
        bool                                    mWriteColoredString;
47
        bool                                    mLinearBlend;
48
        bool                                    mIs3D;
49
 
50
public:
51
        void                                    CopyStateFrom(const GraphicsState* theState);
52
};
53
 
54
typedef std::list<GraphicsState> GraphicsStateList;
55
 
56
class Graphics : public GraphicsState
57
{
58
public:
59
        enum
60
        {
61
                DRAWMODE_NORMAL,
62
                DRAWMODE_ADDITIVE
63
        };
64
 
65
        Edge*                                   mPFActiveEdgeList;
66
        int                                             mPFNumActiveEdges;
67
        static const Point*             mPFPoints;
68
        int                                             mPFNumVertices;
69
 
70
        GraphicsStateList               mStateStack;
71
 
72
protected:     
73
        static int                              PFCompareInd(const void* u, const void* v);
74
        static int                              PFCompareActive(const void* u, const void* v);
75
        void                                    PFDelete(int i);
76
        void                                    PFInsert(int i, int y);
77
 
78
        void                                    DrawImageTransformHelper(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x, float y, bool useFloat);
79
 
80
public:
81
        Graphics(const Graphics& theGraphics);
82
        Graphics(Image* theDestImage = NULL);
83
        virtual ~Graphics();   
84
 
85
        void                                    PushState();
86
        void                                    PopState();
87
 
88
        Graphics*                               Create();
89
 
90
        void                                    SetFont(Font* theFont);
91
        Font*                                   GetFont();
92
 
93
        void                                    SetColor(const Color& theColor);
94
        const Color&                    GetColor();
95
 
96
        void                                    SetDrawMode(int theDrawMode);
97
        int                                             GetDrawMode();
98
 
99
        void                                    SetColorizeImages(bool colorizeImages);
100
        bool                                    GetColorizeImages();
101
 
102
        void                                    SetFastStretch(bool fastStretch);
103
        bool                                    GetFastStretch();
104
 
105
        void                                    SetLinearBlend(bool linear); // for DrawImageMatrix, DrawImageTransform, etc...
106
        bool                                    GetLinearBlend();
107
 
108
        void                                    FillRect(int theX, int theY, int theWidth, int theHeight);
109
        void                                    FillRect(const Rect& theRect);
110
        void                                    DrawRect(int theX, int theY, int theWidth, int theHeight);     
111
        void                                    DrawRect(const Rect& theRect);
112
        void                                    ClearRect(int theX, int theY, int theWidth, int theHeight);    
113
        void                                    ClearRect(const Rect& theRect);
114
        void                                    DrawString(const SexyString& theString, int theX, int theY);
115
 
116
private:
117
        bool                                    DrawLineClipHelper(double* theStartX, double* theStartY, double *theEndX, double* theEndY);
118
public:
119
        void                                    DrawLine(int theStartX, int theStartY, int theEndX, int theEndY);
120
        void                                    DrawLineAA(int theStartX, int theStartY, int theEndX, int theEndY);
121
        void                                    PolyFill(const Point *theVertexList, int theNumVertices, bool convex = false);
122
        void                                    PolyFillAA(const Point *theVertexList, int theNumVertices, bool convex = false);
123
 
124
        void                                    DrawImage(Image* theImage, int theX, int theY);
125
        void                                    DrawImage(Image* theImage, int theX, int theY, const Rect& theSrcRect);
126
        void                                    DrawImage(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect);
127
        void                                    DrawImage(Image* theImage, int theX, int theY, int theStretchedWidth, int theStretchedHeight);
128
        void                                    DrawImageF(Image* theImage, float theX, float theY);
129
        void                                    DrawImageF(Image* theImage, float theX, float theY, const Rect& theSrcRect);
130
 
131
        void                                    DrawImageMirror(Image* theImage, int theX, int theY, bool mirror = true);
132
        void                                    DrawImageMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, bool mirror = true);
133
        void                                    DrawImageMirror(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, bool mirror = true);
134
 
135
        void                                    DrawImageRotated(Image* theImage, int theX, int theY, double theRot, const Rect *theSrcRect = NULL);
136
        void                                    DrawImageRotated(Image* theImage, int theX, int theY, double theRot, int theRotCenterX, int theRotCenterY, const Rect *theSrcRect = NULL);
137
        void                                    DrawImageRotatedF(Image* theImage, float theX, float theY, double theRot, const Rect *theSrcRect = NULL);
138
        void                                    DrawImageRotatedF(Image* theImage, float theX, float theY, double theRot, float theRotCenterX, float theRotCenterY, const Rect *theSrcRect = NULL);
139
 
140
        void                                    DrawImageMatrix(Image* theImage, const SexyMatrix3 &theMatrix, float x = 0, float y = 0);
141
        void                                    DrawImageMatrix(Image* theImage, const SexyMatrix3 &theMatrix, const Rect &theSrcRect, float x = 0, float y = 0);
142
        void                                    DrawImageTransform(Image* theImage, const Transform &theTransform, float x = 0, float y = 0);
143
        void                                    DrawImageTransform(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x = 0, float y = 0);
144
        void                                    DrawImageTransformF(Image* theImage, const Transform &theTransform, float x = 0, float y = 0);
145
        void                                    DrawImageTransformF(Image* theImage, const Transform &theTransform, const Rect &theSrcRect, float x = 0, float y = 0);
146
        void                                    DrawTriangleTex(Image *theTexture, const TriVertex &v1, const TriVertex &v2, const TriVertex &v3);
147
        void                                    DrawTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles);
148
 
149
        void                                    DrawImageCel(Image* theImageStrip, int theX, int theY, int theCel);
150
        void                                    DrawImageCel(Image* theImageStrip, const Rect& theDestRect, int theCel);
151
        void                                    DrawImageCel(Image* theImageStrip, int theX, int theY, int theCelCol, int theCelRow);
152
        void                                    DrawImageCel(Image* theImageStrip, const Rect& theDestRect, int theCelCol, int theCelRow);
153
 
154
        void                                    DrawImageAnim(Image* theImageAnim, int theX, int theY, int theTime);
155
 
156
        void                                    ClearClipRect();
157
        void                                    SetClipRect(int theX, int theY, int theWidth, int theHeight);
158
        void                                    SetClipRect(const Rect& theRect);
159
        void                                    ClipRect(int theX, int theY, int theWidth, int theHeight);
160
        void                                    ClipRect(const Rect& theRect);
161
        void                                    Translate(int theTransX, int theTransY);
162
        void                                    TranslateF(float theTransX, float theTransY);
163
 
164
        // In progress: Only affects DrawImage
165
        void                                    SetScale(float theScaleX, float theScaleY, float theOrigX, float theOrigY);
166
 
167
        int                                             StringWidth(const SexyString& theString);
168
        void                                    DrawImageBox(const Rect& theDest, Image* theComponentImage);
169
        void                                    DrawImageBox(const Rect& theSrc, const Rect& theDest, Image* theComponentImage);
170
 
171
        int                                             WriteString(const SexyString& theString, int theX, int theY, int theWidth = -1, int theJustification = 0, bool drawString = true, int theOffset = 0, int theLength = -1, int theOldColor = -1);
172
        int                                             WriteWordWrapped(const Rect& theRect, const SexyString& theLine, int theLineSpacing = -1, int theJustification = -1, int *theMaxWidth = NULL, int theMaxChars = -1, int* theLastWidth = NULL);
173
        int                                             DrawStringColor(const SexyString& theString, int theX, int theY, int theOldColor = -1); //works like DrawString but can have color tags like ^ff0000^.
174
        int                                             DrawStringWordWrapped(const SexyString& theLine, int theX, int theY, int theWrapWidth = 10000000, int theLineSpacing = -1, int theJustification = -1, int *theMaxWidth = NULL); //works like DrawString but also word wraps
175
        int                                             GetWordWrappedHeight(int theWidth, const SexyString& theLine, int theLineSpacing = -1, int *theMaxWidth = NULL);
176
 
177
        bool                                    Is3D() { return mIs3D; }
178
};
179
 
180
class GraphicsAutoState
181
{
182
public:
183
        Graphics*                               mG;
184
 
185
public:
186
 
187
        GraphicsAutoState(Graphics* theG) : mG(theG)
188
        {
189
                mG->PushState();
190
        }
191
 
192
        ~GraphicsAutoState()
193
        {
194
                mG->PopState();
195
        }
196
};
197
 
198
}
199
 
200
#endif //__GRAPHICS_H__