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 37 of file imageset.h.

Member Typedef Documentation

◆ size_type

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

Definition at line 68 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 34 of file imageset.cpp.

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

References Image::getHeight(), Image::getSubImage(), Image::getWidth(), mImages, Resource::mNotCount, x, and y.

Referenced by calcMemoryLocal().

◆ ~ImageSet()

ImageSet::~ImageSet ( )

Destructor.

Definition at line 61 of file imageset.cpp.

62 {
64 }

References delete_all(), and mImages.

Member Function Documentation

◆ calcMemoryLocal()

int ImageSet::calcMemoryLocal ( ) const
virtual

Reimplemented from MemoryCounter.

Reimplemented in Tileset.

Definition at line 77 of file imageset.cpp.

78 {
79  return static_cast<int>(sizeof(ImageSet)) +
81  static_cast<int>(mImages.capacity() * sizeof(Image));
82 }

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

Referenced by Tileset::calcMemoryLocal().

◆ get()

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

◆ getHeight()

int ImageSet::getHeight ( ) const
inline

Returns the height of the images in the image set.

Definition at line 65 of file imageset.h.

66  { 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 87 of file imageset.h.

88  { return mImages; }

References mImages.

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

◆ getOffsetX()

int ImageSet::getOffsetX ( ) const
inline

Definition at line 75 of file imageset.h.

76  { return mOffsetX; }

References mOffsetX.

Referenced by SpriteDef::loadAnimation().

◆ getOffsetY()

int ImageSet::getOffsetY ( ) const
inline

Definition at line 81 of file imageset.h.

82  { 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 59 of file imageset.h.

60  { return mWidth; }

References mWidth.

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

◆ setOffsetX()

void ImageSet::setOffsetX ( const int  n)
inline

Definition at line 78 of file imageset.h.

79  { mOffsetX = n; }

References mOffsetX.

Referenced by SpriteDef::loadImageSet().

◆ setOffsetY()

void ImageSet::setOffsetY ( const int  n)
inline

Definition at line 84 of file imageset.h.

85  { 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 96 of file imageset.h.

Referenced by getHeight().

◆ mImages

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

Definition at line 93 of file imageset.h.

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

◆ mOffsetX

int ImageSet::mOffsetX
private

Definition at line 97 of file imageset.h.

Referenced by getOffsetX(), and setOffsetX().

◆ mOffsetY

int ImageSet::mOffsetY
private

Definition at line 98 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 95 of file imageset.h.

Referenced by getWidth().


The documentation for this class was generated from the following files:
Image::getHeight
int getHeight() const A_INLINE
Definition: image.h:128
ImageSet::mHeight
int mHeight
Definition: imageset.h:96
ImageSet::mImages
std::vector< Image * > mImages
Definition: imageset.h:93
ImageSet::mOffsetX
int mOffsetX
Definition: imageset.h:97
Resource::mNotCount
bool mNotCount
Definition: resource.h:88
ImageSet::mWidth
int mWidth
Definition: imageset.h:95
Image
Definition: image.h:67
logger
Logger * logger
Definition: logger.cpp:88
ImageSet::mOffsetY
int mOffsetY
Definition: imageset.h:98
Image::getSubImage
virtual Image * getSubImage(const int x, const int y, const int width, const int height)
Definition: image.cpp:466
ParticleType::Image
@ Image
Definition: particletype.h:30
x
x
Definition: graphics_calcImageRect.hpp:72
ImageSet::ImageSet
ImageSet(Image *const img, const int w, const int h, const int margin, const int spacing)
Definition: imageset.cpp:34
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
Resource::Resource
Resource()
Definition: resource.h:39
CAST_S32
#define CAST_S32
Definition: cast.h:29
Resource::calcMemoryLocal
int calcMemoryLocal() const
Definition: resource.cpp:75
y
y
Definition: graphics_calcImageRect.hpp:72
Image::getWidth
int getWidth() const A_INLINE
Definition: image.h:122
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268