Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

LayeredPicture Class Reference

Inheritance diagram for LayeredPicture:

Inheritance graph
[legend]
Collaboration diagram for LayeredPicture:

Collaboration graph
[legend]

Detailed Description

Picture with two layers and color mask.

Definition at line 11 of file LayeredPicture.h.

Public Member Functions

 LayeredPicture (const Path &bg_file, const V2 &loc, const Path &lowerLayer, const Path &colorMask)
 Create picture with two layers and color mask to select active areas.
 ~LayeredPicture ()
void setNoActive ()
void setActiveMask (Uint32 color)
Uint32 getMaskAtWorld (const V2 &worldLoc)
 Return pixel at worldLoc.
Uint32 getMaskAt (const V2 &loc)
 Return pixel at position from left top image corner.
Uint32 getNoMask () const
virtual void drawOn (SDL_Surface *screen)
 Blit entire surface to [x,y].


Constructor & Destructor Documentation

LayeredPicture::LayeredPicture const Path bg_file,
const V2 loc,
const Path lowerLayer,
const Path colorMask
 

Create picture with two layers and color mask to select active areas.

Exceptions:
ResourceException when lowerLayer and colorMask have different proportions

Definition at line 25 of file LayeredPicture.cpp.

00027 : Picture(bg_file, loc)
00028 {
00029     m_lowerLayer = ResImagePack::loadImage(lowerLayer);
00030     m_colorMask = ResImagePack::loadImage(colorMask);
00031     if (m_lowerLayer->w != m_colorMask->w
00032             || m_lowerLayer->h != m_colorMask->h) {
00033         SDL_FreeSurface(m_lowerLayer);
00034         SDL_FreeSurface(m_colorMask);
00035         SDL_FreeSurface(m_surface);
00036 
00037         throw ResourceException(ExInfo(
00038                     "lowerLayer and colorMask have different proportions")
00039                 .addInfo("lowerLayer", lowerLayer.getNative())
00040                 .addInfo("colorMask", colorMask.getNative()));
00041     }
00042 
00043     setNoActive();
00044 }

LayeredPicture::~LayeredPicture  ) 
 

Definition at line 46 of file LayeredPicture.cpp.

00047 {
00048     SDL_FreeSurface(m_lowerLayer);
00049     SDL_FreeSurface(m_colorMask);
00050 }


Member Function Documentation

void LayeredPicture::drawOn SDL_Surface *  screen  )  [virtual]
 

Blit entire surface to [x,y].

Reimplemented from Picture.

Definition at line 82 of file LayeredPicture.cpp.

00083 {
00084     Picture::drawOn(screen);
00085     if (m_activeColor == MASK_NO) {
00086         return;
00087     }
00088 
00089     SurfaceLock lock1(screen);
00090     SurfaceLock lock2(m_lowerLayer);
00091     SurfaceLock lock3(m_colorMask);
00092 
00093     //TODO: support alpha channels
00094     for (int py = 0; py < m_colorMask->h; ++py) {
00095         int world_y = m_loc.getY() + py;
00096         for (int px = 0; px < m_colorMask->w; ++px) {
00097             Uint32 sample = PixelTool::getPixel(m_colorMask, px, py);
00098 
00099             if (sample == m_activeColor) {
00100                 SDL_Color lower = PixelTool::getColor(m_lowerLayer, px, py);
00101                 if (lower.unused == 255) {
00102                     PixelTool::putColor(screen,
00103                             m_loc.getX() + px, world_y, lower);
00104                 }
00105             }
00106         }
00107     }
00108 }

Uint32 LayeredPicture::getMaskAt const V2 loc  ) 
 

Return pixel at position from left top image corner.

Definition at line 67 of file LayeredPicture.cpp.

00068 {
00069     Uint32 result = MASK_NO;
00070 
00071     if ((0 <= loc.getX() && loc.getX() < m_colorMask->w)
00072             && (0 <= loc.getY() && loc.getY() < m_colorMask->h))
00073     {
00074         SurfaceLock lock1(m_colorMask);
00075         result = PixelTool::getPixel(m_colorMask,
00076                 loc.getX(), loc.getY());
00077     }
00078     return result;
00079 }

Uint32 LayeredPicture::getMaskAtWorld const V2 worldLoc  ) 
 

Return pixel at worldLoc.

Translates world coordinates to local coordinates.

Definition at line 57 of file LayeredPicture.cpp.

00058 {
00059     V2 localLoc = worldLoc.minus(m_loc);
00060     return getMaskAt(localLoc);
00061 }

Uint32 LayeredPicture::getNoMask  )  const [inline]
 

Definition at line 27 of file LayeredPicture.h.

00027 { return MASK_NO; }

void LayeredPicture::setActiveMask Uint32  color  )  [inline]
 

Definition at line 23 of file LayeredPicture.h.

00023 { m_activeColor = color; }

void LayeredPicture::setNoActive  )  [inline]
 

Definition at line 22 of file LayeredPicture.h.

00022 { m_activeColor = MASK_NO; }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:55:33 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2