ManaPlus
Public Types | Public Member Functions | Private Attributes
ImageSet Class Reference

#include <imageset.h>

Inheritance diagram for ImageSet:
Resource MemoryCounter Tileset

Public Types

typedef std::vector< Image * >::size_type size_type
 

Public Member Functions

 ImageSet (Image *const img, const int w, const int h, const int margin, const int spacing)
 
 ~ImageSet ()
 
int getWidth () const
 
int getHeight () const
 
Imageget (const size_type i) const
 
size_type size () const
 
int getOffsetX () const
 
void setOffsetX (const int n)
 
int getOffsetY () const
 
void setOffsetY (const int n)
 
const std::vector< Image * > & getImages () const
 
int calcMemoryLocal () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
 ~Resource ()
 
virtual void incRef ()
 
virtual void decRef ()
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
virtual int calcMemoryChilds (const int level) const
 

Private Attributes

std::vector< Image * > mImages
 
int mWidth
 
int mHeight
 
int mOffsetX
 
int mOffsetY
 

Additional Inherited Members

- Data Fields inherited from Resource
time_t mTimeStamp
 
std::string mIdPath
 
std::string mSource
 
unsigned int mRefCount
 
bool mProtected
 
bool mNotCount
 

Detailed Description

Stores a set of subimages originating from a single image.

Definition at line 38 of file imageset.h.

Member Typedef Documentation

◆ size_type

typedef std::vector<Image*>::size_type ImageSet::size_type

Definition at line 69 of file imageset.h.

Constructor & Destructor Documentation

◆ ImageSet()

ImageSet::ImageSet ( Image *const  img,
const int  w,
const int  h,
const int  margin,
const int  spacing 
)

Cuts the passed image in a grid of sub images.

Definition at line 35 of file imageset.cpp.

36  :
37  Resource(),
38  mImages(),
39  mWidth(width),
40  mHeight(height),
41  mOffsetX(0),
42  mOffsetY(0)
43 {
44  if (img != nullptr)
45  {
46  const int hAdd = height + spacing;
47  const int wAdd = width + spacing;
48  for (int y = margin; y + height <= img->getHeight() - margin;
49  y += hAdd)
50  {
51  for (int x = margin; x + width <= img->getWidth() - margin;
52  x += wAdd)
53  {
54  Image *const image = img->getSubImage(x, y, width, height);
55  image->mNotCount = true;
56  mImages.push_back(image);
57  }
58  }
59  }
60 }
std::vector< Image * > mImages
Definition: imageset.h:94
int mOffsetY
Definition: imageset.h:99
int mWidth
Definition: imageset.h:96
int mOffsetX
Definition: imageset.h:98
int mHeight
Definition: imageset.h:97
Resource()
Definition: resource.h:40

References mImages, x, and y.

Referenced by calcMemoryLocal().

◆ ~ImageSet()

ImageSet::~ImageSet ( )

Destructor.

Definition at line 62 of file imageset.cpp.

63 {
65 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), and mImages.

Member Function Documentation

◆ calcMemoryLocal()

int ImageSet::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Reimplemented in Tileset.

Definition at line 78 of file imageset.cpp.

79 {
80  return static_cast<int>(sizeof(ImageSet)) +
82  static_cast<int>(mImages.capacity() * sizeof(Image));
83 }
ImageSet(Image *const img, const int w, const int h, const int margin, const int spacing)
Definition: imageset.cpp:35
int calcMemoryLocal() const
Definition: resource.cpp:76

References Resource::calcMemoryLocal(), ParticleType::Image, ImageSet(), and mImages.

Referenced by Tileset::calcMemoryLocal().

◆ get()

Image * ImageSet::get ( const size_type  i) const

Definition at line 67 of file imageset.cpp.

68 {
69  if (i >= mImages.size())
70  {
71  logger->log("Warning: No sprite %d in this image set",
72  CAST_S32(i));
73  return nullptr;
74  }
75  return mImages[i];
76 }
#define CAST_S32
Definition: cast.h:30
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References CAST_S32, Logger::log(), logger, and mImages.

Referenced by EquipmentWindow::addBox(), WindowMenu::addButton(), SpriteDef::addSequence(), BrowserBox::calcHeight(), Gui::draw(), SimpleAnimation::initializeAnimation(), SpriteDef::loadAnimation(), Button::loadImageSet(), EquipmentWindow::loadSlot(), ParticleEmitter::ParticleEmitter(), EmoteWindow::postInit(), ProgressIndicator::ProgressIndicator(), MapReader::readTileset(), setTile(), and StaticBrowserBox::updateHeight().

◆ getHeight()

int ImageSet::getHeight ( ) const
inline

Returns the height of the images in the image set.

Definition at line 66 of file imageset.h.

67  { return mHeight; }

References mHeight.

Referenced by SimpleAnimation::initializeAnimation(), SpriteDef::loadAnimation(), and ParticleEmitter::ParticleEmitter().

◆ getImages()

const std::vector<Image*>& ImageSet::getImages ( ) const
inline

Definition at line 88 of file imageset.h.

89  { return mImages; }

References mImages.

Referenced by EmotePage::draw(), and EmotePage::safeDraw().

◆ getOffsetX()

int ImageSet::getOffsetX ( ) const
inline

Definition at line 76 of file imageset.h.

77  { return mOffsetX; }

References mOffsetX.

Referenced by SpriteDef::loadAnimation().

◆ getOffsetY()

int ImageSet::getOffsetY ( ) const
inline

Definition at line 82 of file imageset.h.

83  { return mOffsetY; }

References mOffsetY.

Referenced by SpriteDef::loadAnimation().

◆ getWidth()

int ImageSet::getWidth ( ) const
inline

Returns the width of the images in the image set.

Definition at line 60 of file imageset.h.

61  { return mWidth; }

References mWidth.

Referenced by SimpleAnimation::initializeAnimation(), SpriteDef::loadAnimation(), and ParticleEmitter::ParticleEmitter().

◆ setOffsetX()

void ImageSet::setOffsetX ( const int  n)
inline

Definition at line 79 of file imageset.h.

80  { mOffsetX = n; }

References mOffsetX.

Referenced by SpriteDef::loadImageSet().

◆ setOffsetY()

void ImageSet::setOffsetY ( const int  n)
inline

Definition at line 85 of file imageset.h.

86  { mOffsetY = n; }

References mOffsetY.

Referenced by SpriteDef::loadImageSet().

◆ size()

size_type ImageSet::size ( ) const
inline

Field Documentation

◆ mHeight

int ImageSet::mHeight
private

Height of the images in the image set.

Definition at line 97 of file imageset.h.

Referenced by getHeight().

◆ mImages

std::vector<Image*> ImageSet::mImages
private

Definition at line 94 of file imageset.h.

Referenced by calcMemoryLocal(), get(), getImages(), ImageSet(), size(), and ~ImageSet().

◆ mOffsetX

int ImageSet::mOffsetX
private

Definition at line 98 of file imageset.h.

Referenced by getOffsetX(), and setOffsetX().

◆ mOffsetY

int ImageSet::mOffsetY
private

Definition at line 99 of file imageset.h.

Referenced by getOffsetY(), and setOffsetY().

◆ mWidth

int ImageSet::mWidth
private

Width of the images in the image set.

Definition at line 96 of file imageset.h.

Referenced by getWidth().


The documentation for this class was generated from the following files: