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
|
#include "Image.h"
#include "Graphics.h"
using namespace Sexy;
Image::Image()
{
mWidth = 0;
mHeight = 0;
mNumRows = 1;
mNumCols = 1;
mAnimInfo = NULL;
mDrawn = false;
}
Image::Image(const Image& theImage) :
mWidth(theImage.mWidth),
mHeight(theImage.mHeight),
mNumRows(theImage.mNumRows),
mNumCols(theImage.mNumCols)
{
mDrawn = false;
if (theImage.mAnimInfo != NULL)
mAnimInfo = new AnimInfo(*theImage.mAnimInfo);
else
mAnimInfo = NULL;
}
Image::~Image()
{
delete mAnimInfo;
}
int Image::GetWidth()
{
return mWidth;
}
int Image::GetHeight()
{
return mHeight;
}
int Image::GetCelHeight()
{
return mHeight / mNumRows;
}
int Image::GetCelWidth()
{
return mWidth / mNumCols;
}
Rect Image::GetCelRect(int theCel)
{
int h = GetCelHeight();
int w = GetCelWidth();
int x = (theCel % mNumCols) * w;
int y = (theCel / mNumCols) * h;
return Rect(x, y, w, h);
}
Rect Image::GetCelRect(int theCol, int theRow)
{
int h = GetCelHeight();
int w = GetCelWidth();
int x = theCol * w;
int y = theRow * h;
return Rect(x, y, w, h);
}
AnimInfo::AnimInfo()
{
mAnimType = AnimType_None;
mFrameDelay = 1;
mNumCels = 1;
}
void AnimInfo::SetPerFrameDelay(int theFrame, int theTime)
{
if ((int)mPerFrameDelay.size()<=theFrame)
mPerFrameDelay.resize(theFrame+1);
mPerFrameDelay[theFrame] = theTime;
}
void AnimInfo::Compute(int theNumCels, int theBeginFrameTime, int theEndFrameTime)
{
int i;
mNumCels = theNumCels;
if (mNumCels<=0)
mNumCels = 1;
if (mFrameDelay<=0)
mFrameDelay = 1;
if (mAnimType==AnimType_PingPong && mNumCels>1)
{
mFrameMap.resize(theNumCels*2-2);
int index = 0;
for (i=0; i<theNumCels; i++)
mFrameMap[index++] = i;
for (i=theNumCels-2; i>=1; i--)
mFrameMap[index++] = i;
}
if (!mFrameMap.empty())
mNumCels = (int)mFrameMap.size();
if (theBeginFrameTime>0)
SetPerFrameDelay(0,theBeginFrameTime);
if (theEndFrameTime>0)
SetPerFrameDelay(mNumCels-1,theEndFrameTime);
if (!mPerFrameDelay.empty())
{
mTotalAnimTime = 0;
mPerFrameDelay.resize(mNumCels);
for (i=0; i<mNumCels; i++)
{
if (mPerFrameDelay[i]<=0)
mPerFrameDelay[i] = mFrameDelay;
mTotalAnimTime += mPerFrameDelay[i];
}
}
else
mTotalAnimTime = mFrameDelay*mNumCels;
if (!mFrameMap.empty())
mFrameMap.resize(mNumCels);
}
int AnimInfo::GetPerFrameCel(int theTime)
{
for (int i=0; i<mNumCels; i++)
{
theTime -= mPerFrameDelay[i];
if (theTime<0)
return i;
}
return mNumCels-1;
}
int AnimInfo::GetCel(int theTime)
{
if (mAnimType==AnimType_Once && theTime>=mTotalAnimTime)
{
if (!mFrameMap.empty())
return mFrameMap[mFrameMap.size()-1];
else
return mNumCels-1;
}
theTime = theTime%mTotalAnimTime;
int aFrame;
if (!mPerFrameDelay.empty())
aFrame = GetPerFrameCel(theTime);
else
aFrame = (theTime/mFrameDelay)%mNumCels;
if (mFrameMap.empty())
return aFrame;
else
return mFrameMap[aFrame];
}
int Image::GetAnimCel(int theTime)
{
if (mAnimInfo==NULL)
return 0;
else
return mAnimInfo->GetCel(theTime);
}
Rect Image::GetAnimCelRect(int theTime)
{
Rect aRect;
int aCel = GetAnimCel(theTime);
int aCelWidth = GetCelWidth();
int aCelHeight = GetCelHeight();
if (mNumCols>1)
return Rect(aCel*aCelWidth,0,aCelWidth,mHeight);
else
return Rect(0,aCel*aCelHeight,mWidth,aCelHeight);
}
void Image::CopyAttributes(Image *from)
{
mNumCols = from->mNumCols;
mNumRows = from->mNumRows;
delete mAnimInfo;
mAnimInfo = NULL;
if (from->mAnimInfo != NULL)
mAnimInfo = new AnimInfo(*from->mAnimInfo);
}
Graphics* Image::GetGraphics()
{
Graphics* g = new Graphics(this);
return g;
}
void Image::FillRect(const Rect& theRect, const Color& theColor, int theDrawMode)
{
}
void Image::ClearRect(const Rect& theRect)
{
}
void Image::DrawRect(const Rect& theRect, const Color& theColor, int theDrawMode)
{
FillRect(Rect(theRect.mX, theRect.mY, theRect.mWidth + 1, 1), theColor, theDrawMode);
FillRect(Rect(theRect.mX, theRect.mY + theRect.mHeight, theRect.mWidth + 1, 1), theColor, theDrawMode);
FillRect(Rect(theRect.mX, theRect.mY + 1, 1, theRect.mHeight - 1), theColor, theDrawMode);
FillRect(Rect(theRect.mX + theRect.mWidth, theRect.mY + 1, 1, theRect.mHeight - 1), theColor, theDrawMode);
}
void Image::DrawLine(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
{
}
void Image::DrawLineAA(double theStartX, double theStartY, double theEndX, double theEndY, const Color& theColor, int theDrawMode)
{
}
void Image::FillScanLines(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode)
{
for (int i = 0; i < theSpanCount; i++)
{
Span* aSpan = &theSpans[i];
FillRect(Rect(aSpan->mX, aSpan->mY, aSpan->mWidth, 1), theColor, theDrawMode);
}
}
void Image::FillScanLinesWithCoverage(Span* theSpans, int theSpanCount, const Color& theColor, int theDrawMode, const unsigned char* theCoverage, int theCoverX, int theCoverY, int theCoverWidth, int theCoverHeight)
{
}
bool Image::PolyFill3D(const Point theVertices[], int theNumVertices, const Rect *theClipRect, const Color &theColor, int theDrawMode, int tx, int ty, bool convex)
{
return false;
}
void Image::Blt(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
{
}
void Image::BltF(Image* theImage, float theX, float theY, const Rect& theSrcRect, const Rect &theClipRect, const Color& theColor, int theDrawMode)
{
}
void Image::BltRotated(Image* theImage, float theX, float theY, const Rect &theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, double theRot, float theRotCenterX, float theRotCenterY)
{
}
void Image::StretchBlt(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
{
}
void Image::BltMatrix(Image* theImage, float x, float y, const SexyMatrix3 &theMatrix, const Rect& theClipRect, const Color& theColor, int theDrawMode, const Rect &theSrcRect, bool blend)
{
}
void Image::BltTrianglesTex(Image *theTexture, const TriVertex theVertices[][3], int theNumTriangles, const Rect& theClipRect, const Color &theColor, int theDrawMode, float tx, float ty, bool blend)
{
}
void Image::BltMirror(Image* theImage, int theX, int theY, const Rect& theSrcRect, const Color& theColor, int theDrawMode)
{
}
void Image::StretchBltMirror(Image* theImage, const Rect& theDestRect, const Rect& theSrcRect, const Rect& theClipRect, const Color& theColor, int theDrawMode, bool fastStretch)
{
}
|