#include <CSPicture.h>
Example:<!ELEMENT PICTURE (ID,(X,Y,WIDTH,HEIGHT)?,BITMAP)> <!ELEMENT ID (#PCDATA)> <!ELEMENT X (#PCDATA)> <!ELEMENT Y (#PCDATA)> <!ELEMENT WIDTH (#PCDATA)> <!ELEMENT HEIGHT (#PCDATA)> <!ELEMENT BITMAP (#PCDATA)>
<PICTURE> <ID>PacManUp1</ID> <X>0</X> <Y>96</Y> <WIDTH>37</WIDTH> <HEIGHT>31</HEIGHT> <BITMAP>bitmap\\pac_pix.xml</BITMAP> </PICTURE>
ID - supposed a unique identifier X, Y - position of "picture" on the bitmap WIDTH, HEIGHT - Width and Hight (size) of the "picture" on the bitmap BITMAP - File to be loaded for the bitmap.
CSPicture are singletons in the sense, that two "loaded" CSPicture of the same "ini" file ARE the same instances. (Bitmaps are loaded only once - by there respective loader entity)
these methods can be used:
unsigned int getMaxX() // get width of the pciture unsigned int getMaxY() // get height of the picture void setSolid(bool b) // enable/disable transparency bool isSolid() // has picture a transparent color SDL_Surface *getSurface() // for the font lib only
(SDLMain::addUpdateRect(mUpdateRegion) - is called after displaying, so at some stage - later (main-loop) void SDLMain::updateScreen() must be called.)Class that holds and can display a picture. The picture class has no instance relevant data (state independant) for example: as position
Definition at line 143 of file CSPicture.h.
Public Member Functions | |
CSPicture (const CSPicture &picture) | |
copy constructor | |
virtual | ~CSPicture () |
destructor | |
virtual std::string | getType () |
void | getRGB (int &r, int &b, int &g) |
virtual void | display (CSDisplayParams *mDisplayParams) |
display this picture on the srceen | |
virtual void | display (int x, int y) |
display this picture on the srceen | |
virtual void | display (SDL_Surface *destination, int x, int y) |
display this picture on the srceen | |
unsigned int | getMaxX () |
get width of the pciture | |
unsigned int | getMaxY () |
get height of the picture | |
unsigned int | getWidth () |
get width of the pciture | |
unsigned int | getHeight () |
get height of the picture | |
void | setSolid (bool b) |
enable/disable transparency | |
bool | isSolid () |
has picture a transparent color | |
void | setAlpha (int alpha) |
int | getColorKey () |
get current transparent color | |
SDL_Surface * | getSurface () |
for the font lib only | |
unsigned char ** | getProjection () |
for collision detection | |
unsigned int | getPixelProjectionCount () |
void | scale (int width, int divideX, int height, int divideY) |
SDL_Surface * | getScaledPicture (double factor) |
SDL_Surface * | getScaledPicture (int w, int h) |
Get a scaled version of this CSPicture. | |
bool | isTransparent (int x, int y) |
Static Public Member Functions | |
void | resetSurfaces () |
CSPicture * | createScaledPicture (CSPicture *picture, double factor) |
Static Public Attributes | |
const char * | CLASS = "CSPicture" |
|
copy constructor
Definition at line 222 of file CSPicture.cpp. References SDLMain::freeSurface(), SDLMain::getScreen(), LOG_ENTER, LOG_EXIT, mAlpha, mB, mColorKey, mFactor, mFileName, mG, mId, mIsCreatedAsScaled, mIsDirectLoad, mIsSolid, mLoadName, mPictureRegion, mPixelPictureRegion, mPixelProjectionCount, mProjection, mR, mRLEAccelleration, mRLEUse, mStartPixelsX, mStartPixelsY, and mUpdateRegion. Referenced by createScaledPicture().
00223 { 00224 static char *functionName="CSPicture"; 00225 LOG_ENTER 00226 mFactor = 0; 00227 mScaledWidth = 0; 00228 mScaledHeight = 0; 00229 mScaledPicture = 0; 00230 mPicture = 0; 00231 mProjection = 0; 00232 mUpdateRegion = picture.mUpdateRegion; 00233 mPictureRegion = picture.mPictureRegion; 00234 mRLEUse = picture.mRLEUse; 00235 mAlpha = picture.mAlpha; 00236 mIsCreatedAsScaled = picture.mIsCreatedAsScaled; 00237 mLoadName = picture.mLoadName; 00238 mIsDirectLoad = picture.mIsDirectLoad; 00239 00240 mPixelPictureRegion = picture.mPixelPictureRegion; 00241 mStartPixelsX = picture.mStartPixelsX; 00242 mStartPixelsY = picture.mStartPixelsY; 00243 00244 mPixelProjectionCount = picture.mPixelProjectionCount; 00245 mRLEAccelleration = picture.mRLEAccelleration; 00246 if (picture.mId) 00247 { 00248 mId = strdup(picture.mId); 00249 } 00250 else 00251 { 00252 mId = 0; 00253 } 00254 mFileName = strdup(picture.mFileName); 00255 mIsSolid = picture.mIsSolid; 00256 mColorKey = picture.mColorKey; 00257 mR = picture.mR; 00258 mG = picture.mG; 00259 mB = picture.mB; 00260 mFactor = picture.mFactor; 00261 00262 if (mIsDirectLoad) 00263 { 00264 mPicture = convertToCurrentScreen(CSBitmapDirectLoader::INSTANCE.load(mLoadName), mPictureRegion); 00265 } 00266 else 00267 { 00268 mPicture = convertToCurrentScreen(CSBitmapLoader::INSTANCE.load(mFileName), mPictureRegion); 00269 } 00270 if (mIsSolid) 00271 { 00272 SDL_SetColorKey(mPicture, mRLEAccelleration, mColorKey+11); 00273 SDL_Surface *h = mPicture; 00274 mPicture = SDL_DisplayFormat(h); 00275 SDLMain::freeSurface(h); 00276 } 00277 else 00278 { 00279 SDL_Surface *h = mPicture; 00280 // software surface needs befor 00281 if (!(SDLMain::getScreen()->flags & SDL_HWSURFACE)) 00282 { 00283 SDL_SetColorKey(mPicture, SDL_SRCCOLORKEY| mRLEAccelleration, mColorKey); 00284 } 00285 mPicture = SDL_DisplayFormat(h); 00286 00287 // hardware surface needs after 00288 if (SDLMain::getScreen()->flags & SDL_HWSURFACE) 00289 { 00290 SDL_SetColorKey(mPicture, SDL_SRCCOLORKEY| mRLEAccelleration, mColorKey); 00291 } 00292 buildOptimizeData(); 00293 SDLMain::freeSurface(h); 00294 } 00295 00296 int x,y; 00297 if (picture.mProjection != 0) 00298 { 00299 mProjection = (unsigned char **) new void *[mUpdateRegion.h]; 00300 for (y = 0; y<mUpdateRegion.h; y++) 00301 { 00302 mProjection[y] = (unsigned char *) new unsigned char[mUpdateRegion.w]; 00303 } 00304 for (y = 0; y<mUpdateRegion.h; y++) 00305 { 00306 for (x = 0; x<mUpdateRegion.w; x++) 00307 { 00308 mProjection[y][x] = picture.mProjection[y][x]; 00309 } 00310 } 00311 } 00312 addPicture(this); 00313 LOG_EXIT 00314 } |
Here is the call graph for this function:
|
destructor
Definition at line 316 of file CSPicture.cpp. References SDLMain::freeSurface(), SDLMain::isInitialized(), LOG_ENTER, and LOG_EXIT.
00317 { 00318 static char *functionName="~CSPicture"; 00319 LOG_ENTER 00320 removePicture(this); 00321 if (mId) 00322 { 00323 free(mId); 00324 mId = 0; 00325 } 00326 if (mFileName) 00327 { 00328 free(mFileName); 00329 mFileName = 0; 00330 } 00331 if (mProjection != 0) 00332 { 00333 for (int y = 0; y<mPictureRegion.h; y++) 00334 { 00335 delete[] mProjection[y]; 00336 } 00337 delete[] mProjection; 00338 mProjection = 0; 00339 } 00340 if (mScaledPicture != 0) 00341 { 00342 if (SDLMain::isInitialized()) 00343 { 00344 SDLMain::freeSurface(mScaledPicture); 00345 } 00346 mScaledPicture = 0; 00347 } 00348 LOG_EXIT 00349 } |
Here is the call graph for this function:
|
Definition at line 225 of file CSPicture.h. References CLASS.
00225 {return (std::string) CLASS;} |
|
Definition at line 935 of file CSPicture.cpp.
00936 { 00937 static char *functionName="getRGB"; 00938 r = mR; 00939 g = mG; 00940 b = mB; 00941 } |
|
display this picture on the srceen
Definition at line 444 of file CSPicture.cpp. References SDLMain::addUpdateRect(), CSDisplayParams::mXDisplayStart, CSDisplayParams::mXPos, CSDisplayParams::mXWorldStart, CSDisplayParams::mYDisplayStart, CSDisplayParams::mYPos, CSDisplayParams::mYWorldStart, and SDLMain::shutdown(). Referenced by CSAnimation::display(), CSWindow::paint(), CSMouseCursor::paint(), CSPictureIcon::paint(), and CSPictureArea::paint().
00445 { 00446 static char *functionName="display"; 00447 if ((!mIsSolid) && (mPixelProjectionCount == 0)) 00448 { 00449 return; 00450 } 00451 00452 // optimize - perhaps have some part of below as 00453 // constants - uses less indirections... 00454 mUpdateRegion.x = mStartPixelsX + displayParams->mXDisplayStart + displayParams->mXPos - displayParams->mXWorldStart; 00455 mUpdateRegion.y = mStartPixelsY + displayParams->mYDisplayStart + displayParams->mYPos - displayParams->mYWorldStart; 00456 00457 /* Blit onto the screen surface */ 00458 if (SDL_BlitSurface(mPicture, &mPixelPictureRegion, SDLMain::getScreen(), &mUpdateRegion)< 0) 00459 { 00460 SDLMain::shutdown((std::string)"BlitSurface error: " + SDL_GetError(), 1); 00461 } 00462 00463 SDLMain::addUpdateRect(mUpdateRegion); 00464 } |
Here is the call graph for this function:
|
display this picture on the srceen
Definition at line 425 of file CSPicture.cpp. References SDLMain::addUpdateRect(), and SDLMain::shutdown().
00426 { 00427 static char *functionName="display"; 00428 if ((!mIsSolid) && (mPixelProjectionCount == 0)) 00429 { 00430 return; 00431 } 00432 00433 mUpdateRegion.x = mStartPixelsX + x; 00434 mUpdateRegion.y = mStartPixelsY + y; 00435 /* Blit onto the screen surface */ 00436 if (SDL_BlitSurface(mPicture, &mPixelPictureRegion, SDLMain::getScreen(), &mUpdateRegion)< 0) 00437 { 00438 SDLMain::shutdown((std::string)"BlitSurface error: " + SDL_GetError(), 1); 00439 } 00440 00441 SDLMain::addUpdateRect(mUpdateRegion); 00442 } |
Here is the call graph for this function:
|
display this picture on the srceen
Definition at line 408 of file CSPicture.cpp. References SDLMain::shutdown().
00409 { 00410 static char *functionName="display"; 00411 if ((!mIsSolid) && (mPixelProjectionCount == 0)) 00412 { 00413 return; 00414 } 00415 00416 mUpdateRegion.x = mStartPixelsX + x; 00417 mUpdateRegion.y = mStartPixelsY + y; 00418 00419 if (SDL_BlitSurface(mPicture, &mPixelPictureRegion, destination, &mUpdateRegion)< 0) 00420 { 00421 SDLMain::shutdown((std::string)"BlitSurface error: " + SDL_GetError(), 1); 00422 } 00423 } |
Here is the call graph for this function:
|
get width of the pciture
Definition at line 231 of file CSPicture.h. Referenced by CSSprite::checkCollision(), CSSprite::checkCollisionPixels(), CSWindow::CSWindow(), CSSprite::getCollidingTiles(), and CSAnimation::getMaxX(). |
|
get height of the picture
Definition at line 232 of file CSPicture.h. Referenced by CSSprite::checkCollision(), CSSprite::checkCollisionPixels(), CSWindow::CSWindow(), CSSprite::getCollidingTiles(), and CSAnimation::getMaxY(). |
|
get width of the pciture
Definition at line 233 of file CSPicture.h. Referenced by CSPictureIcon::initIcon(), CSPictureIcon::layoutSetupPictureIcon(), and CSPictureArea::paint(). |
|
get height of the picture
Definition at line 234 of file CSPicture.h. Referenced by CSPictureIcon::initIcon(), CSPictureIcon::layoutSetupPictureIcon(), and CSPictureArea::paint(). |
|
enable/disable transparency
Definition at line 351 of file CSPicture.cpp. References SDLMain::freeSurface(), and SDLMain::getScreen(). Referenced by CSFont::setSolid(), and CSAnimation::setSolid().
00352 { 00353 static char *functionName="setSolid"; 00354 if (b == mIsSolid) 00355 { 00356 return; 00357 } 00358 00359 SDL_Surface *h = mPicture; 00360 mIsSolid = b; 00361 if (mIsSolid) 00362 { 00363 SDL_SetColorKey(mPicture, mRLEAccelleration, mColorKey+11); 00364 mPicture = SDL_DisplayFormat(h); 00365 mPixelPictureRegion = mPictureRegion; 00366 mPixelPictureRegion.x = 0; 00367 mPixelPictureRegion.y = 0; 00368 mStartPixelsX = 0; 00369 mStartPixelsY = 0; 00370 mUpdateRegion.h = mPictureRegion.h; 00371 mUpdateRegion.w = mPictureRegion.w; 00372 } 00373 else 00374 { 00375 // software surface needs befor 00376 if (!(SDLMain::getScreen()->flags & SDL_HWSURFACE)) 00377 { 00378 SDL_SetColorKey(mPicture, SDL_SRCCOLORKEY| mRLEAccelleration, mColorKey); 00379 } 00380 mPicture = SDL_DisplayFormat(h); 00381 00382 // hardware surface needs after 00383 if (SDLMain::getScreen()->flags & SDL_HWSURFACE) 00384 { 00385 SDL_SetColorKey(mPicture, SDL_SRCCOLORKEY| mRLEAccelleration, mColorKey); 00386 } 00387 buildOptimizeData(); 00388 } 00389 SDLMain::freeSurface(h); 00390 } |
Here is the call graph for this function:
|
has picture a transparent color
Definition at line 236 of file CSPicture.h. Referenced by CSTileMap::getScaledMap(), getScaledPicture(), and CSFont::putString(). |
|
Definition at line 392 of file CSPicture.cpp. References LOG_ENTER, and LOG_EXIT. Referenced by CSAnimation::setAlpha().
00393 { 00394 static char *functionName="setAlpha"; 00395 LOG_ENTER 00396 if (alpha < 0) 00397 { 00398 mAlpha = -1; 00399 SDL_SetAlpha(mPicture, mRLEAccelleration, 0); 00400 LOG_EXIT 00401 return; 00402 } 00403 mAlpha = alpha; 00404 SDL_SetAlpha(mPicture, mRLEAccelleration | SDL_SRCALPHA, alpha); 00405 LOG_EXIT 00406 } |
|
get current transparent color
Definition at line 238 of file CSPicture.h. Referenced by CSFont::putString(). |
|
for the font lib only
Definition at line 239 of file CSPicture.h. Referenced by CSFont::inputText(), and CSFont::putString(). |
|
for collision detection
Definition at line 240 of file CSPicture.h. Referenced by CSSprite::checkCollision(), and CSSprite::checkCollisionPixels(). |
|
Definition at line 241 of file CSPicture.h. Referenced by CSSprite::checkCollision(), and CSSprite::checkCollisionPixels().
00242 {return mPixelProjectionCount;}
|
|
resets all surfaces loaded via the CSPictureLoader (all!) Definition at line 615 of file CSPicture.cpp. References LOG_ENTER, and LOG_EXIT.
|
|
This function scales the current picture "deeply", each following reference, even to the buffered Bitmap will produce a scaled version of the picture. Only way to get rid of scaling is unload from the Loader!
Definition at line 889 of file CSPicture.cpp. References SDLMain::getInstance(), Loadable< CSBitmap >::load(), CSBitmapLoader::scale(), SDLMain::scaleX(), and SDLMain::scaleY(). Referenced by CSAnimation::scale().
00890 { 00891 static char *functionName="scale"; 00892 if (mIsDirectLoad) 00893 { 00894 CSBitmapDirectLoader::INSTANCE.scale((char *) mLoadName.c_str(), width, divideX*mUpdateRegion.w, height, divideY*mUpdateRegion.h); 00895 } 00896 else 00897 { 00898 CSBitmapLoader::INSTANCE.scale(mFileName, width, divideX*mUpdateRegion.w, height, divideY*mUpdateRegion.h); 00899 } 00900 00901 if (mProjection != 0) 00902 { 00903 for (int y = 0; y<mPictureRegion.h; y++) 00904 { 00905 delete[] mProjection[y]; 00906 } 00907 delete[] mProjection; 00908 mProjection = 0; 00909 } 00910 00911 mUpdateRegion.x = mPictureRegion.x = SDLMain::getInstance()->scaleX(width, divideX*mUpdateRegion.w, mUpdateRegion.x); 00912 mUpdateRegion.y = mPictureRegion.y = SDLMain::getInstance()->scaleY(height, divideY*mUpdateRegion.h, mUpdateRegion.y); 00913 mUpdateRegion.w = mPictureRegion.w = SDLMain::getInstance()->scaleX(width, divideX*mUpdateRegion.w, mUpdateRegion.w); 00914 mUpdateRegion.h = mPictureRegion.h = SDLMain::getInstance()->scaleY(height, divideY*mUpdateRegion.h, mUpdateRegion.h); 00915 00916 resetSurface(); 00917 00918 CSBitmap *image = 0; 00919 if (mIsDirectLoad) 00920 { 00921 image = CSBitmapDirectLoader::INSTANCE.load(mLoadName); 00922 } 00923 else 00924 { 00925 image = CSBitmapLoader::INSTANCE.load(mFileName); 00926 } 00927 buildPixelProjection(image, mUpdateRegion); 00928 mPixelPictureRegion = mPictureRegion; 00929 mPixelPictureRegion.x = 0; 00930 mPixelPictureRegion.y = 0; 00931 buildOptimizeData(); 00932 checkRLEAccelleration(); 00933 } |
Here is the call graph for this function:
|
This function scales the current picture with a factor. The scaled result is a part of this picture! Both the scaled and unscaled picture can be got with functions. The scaled picture is "buffered" by CSPicture and can be got "fast!" again and again Definition at line 950 of file CSPicture.cpp. References SDLMain::freeSurface(), SDLMain::getInstance(), isSolid(), and SDLMain::scale(). Referenced by CSAnimation::getScaledAnimation(), and CSPictureArea::paint().
00951 { 00952 static char *functionName="getScaledPicture"; 00953 if ((mFactor == factor) && (mScaledPicture != 0)) 00954 { 00955 return mScaledPicture; 00956 } 00957 mFactor = factor; 00958 if (mScaledPicture != 0) 00959 { 00960 SDLMain::freeSurface(mScaledPicture); 00961 mScaledPicture = 0; 00962 } 00963 00964 mScaledPicture = SDLMain::getInstance()->scale(mPicture, factor); 00965 if (!isSolid()) 00966 { 00967 int key; 00968 key = SDL_MapRGB(mScaledPicture->format, mR, mG, mB); 00969 SDL_SetColorKey(mScaledPicture, SDL_SRCCOLORKEY, key); 00970 } 00971 return mScaledPicture; 00972 } |
Here is the call graph for this function:
|
Get a scaled version of this CSPicture. This function scales the current picture with a factor. The scaled result is a part of this picture! Both the scaled and unscaled picture can be got with functions. The scaled picture is "buffered" by CSPicture and can be got "fast!" again and again
Definition at line 981 of file CSPicture.cpp. References SDLMain::freeSurface(), SDLMain::getInstance(), isSolid(), and SDLMain::scale().
00982 { 00983 static char *functionName="getScaledPicture"; 00984 00985 if ((mScaledWidth == h) && (mScaledHeight == h) && (mScaledPicture != 0)) 00986 { 00987 return mScaledPicture; 00988 } 00989 mScaledWidth = w; 00990 mScaledHeight = h; 00991 if (mScaledPicture != 0) 00992 { 00993 SDLMain::freeSurface(mScaledPicture); 00994 mScaledPicture = 0; 00995 } 00996 00997 mScaledPicture = SDLMain::getInstance()->scale(mPicture, w,h); 00998 if (!isSolid()) 00999 { 01000 int key; 01001 key = SDL_MapRGB(mScaledPicture->format, mR, mG, mB); 01002 SDL_SetColorKey(mScaledPicture, SDL_SRCCOLORKEY, key); 01003 } 01004 return mScaledPicture; 01005 } |
Here is the call graph for this function:
|
Definition at line 1007 of file CSPicture.cpp. References SDLMain::getPixel(), LOG_ENTER, and LOG_EXIT. Referenced by CSWindow::isTransparent().
01008 { 01009 static char *functionName="isTransparent"; 01010 LOG_ENTER 01011 if (SDL_MUSTLOCK(mPicture)) 01012 { 01013 SDL_LockSurface(mPicture); 01014 } 01015 bool val = mColorKey == SDLMain::getPixel(mPicture, x, y); 01016 if (SDL_MUSTLOCK(mPicture)) 01017 { 01018 SDL_UnlockSurface(mPicture); 01019 } 01020 LOG_EXIT 01021 return val; 01022 } |
Here is the call graph for this function:
|
This function duplicates the current picture, that is builds a new pciture, which is scaled to the factor given! Definition at line 1028 of file CSPicture.cpp. References buildOptimizeData(), checkRLEAccelleration(), CSPicture(), mFactor, mIsCreatedAsScaled, mPixelPictureRegion, mUpdateRegion, and resetSurface().
01029 { 01030 CSPicture *newPicture = new CSPicture(*picture); 01031 newPicture->mIsCreatedAsScaled = true; 01032 newPicture->mFactor = factor; 01033 newPicture->resetSurface(); 01034 01035 newPicture->mUpdateRegion.x = newPicture->mUpdateRegion.x * newPicture->mFactor; 01036 newPicture->mUpdateRegion.y = newPicture->mUpdateRegion.y * newPicture->mFactor; 01037 newPicture->mUpdateRegion.w = newPicture->mUpdateRegion.w * newPicture->mFactor; 01038 newPicture->mUpdateRegion.h = newPicture->mUpdateRegion.h * newPicture->mFactor; 01039 newPicture->mPixelPictureRegion = newPicture->mUpdateRegion; 01040 newPicture->mPixelPictureRegion.x = 0; 01041 newPicture->mPixelPictureRegion.y = 0; 01042 01043 01044 // following is not done yet for copied scaled pictures 01045 // CSBitmap *image = CSBitmapLoader::INSTANCE.load(mFileName); 01046 // buildPixelProjection(image, mUpdateRegion); 01047 newPicture->buildOptimizeData(); 01048 newPicture->checkRLEAccelleration(); 01049 01050 return newPicture; 01051 } |
Here is the call graph for this function:
|
Definition at line 10 of file CSPicture.cpp. Referenced by getType(). |