ManaPlus
Public Member Functions | Private Attributes | Friends
MapItem Class Reference

#include <mapitem.h>

Public Member Functions

 MapItem ()
 
 MapItem (const int type)
 
 MapItem (const int type, const std::string &comment)
 
 MapItem (const int type, const std::string &comment, const int x, const int y)
 
 ~MapItem ()
 
int getType () const
 
void setType (const int type)
 
void setPos (const int x, const int y)
 
int getX () const
 
int getY () const
 
const std::string & getComment () const
 
void setComment (const std::string &comment)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
void draw (Graphics *const graphics, const int x, const int y, const int dx, const int dy) const
 

Private Attributes

ImagemImage
 
std::string mComment
 
std::string mName
 
int mType
 
int mX
 
int mY
 

Friends

class Map
 
class MapLayer
 
class SpecialLayer
 

Detailed Description

Definition at line 32 of file mapitem.h.

Constructor & Destructor Documentation

◆ MapItem() [1/4]

MapItem::MapItem ( )

Definition at line 39 of file mapitem.cpp.

39  :
40  mImage(nullptr),
41  mComment(),
42  mName(),
44  mX(-1),
45  mY(-1)
46 {
48 }
int mX
Definition: mapitem.h:89
std::string mName
Definition: mapitem.h:87
Image * mImage
Definition: mapitem.h:85
int mType
Definition: mapitem.h:88
std::string mComment
Definition: mapitem.h:86
void setType(const int type)
Definition: mapitem.cpp:96
int mY
Definition: mapitem.h:90

References MapItemType::EMPTY, and setType().

◆ MapItem() [2/4]

MapItem::MapItem ( const int  type)
explicit

Definition at line 50 of file mapitem.cpp.

50  :
51  mImage(nullptr),
52  mComment(),
53  mName(),
54  mType(type),
55  mX(-1),
56  mY(-1)
57 {
58  setType(type);
59 }

References setType().

◆ MapItem() [3/4]

MapItem::MapItem ( const int  type,
const std::string &  comment 
)

Definition at line 61 of file mapitem.cpp.

62  :
63  mImage(nullptr),
64  mComment(comment),
65  mName(),
66  mType(type),
67  mX(-1),
68  mY(-1)
69 {
70  setType(type);
71 }

References setType().

◆ MapItem() [4/4]

MapItem::MapItem ( const int  type,
const std::string &  comment,
const int  x,
const int  y 
)

Definition at line 73 of file mapitem.cpp.

76  :
77  mImage(nullptr),
78  mComment(comment),
79  mName(),
80  mType(type),
81  mX(x),
82  mY(y)
83 {
84  setType(type);
85 }

References setType().

◆ ~MapItem()

MapItem::~MapItem ( )

Definition at line 87 of file mapitem.cpp.

88 {
89  if (mImage != nullptr)
90  {
91  mImage->decRef();
92  mImage = nullptr;
93  }
94 }

References mImage.

Member Function Documentation

◆ draw()

void MapItem::draw ( Graphics *const  graphics,
const int  x,
const int  y,
const int  dx,
const int  dy 
) const

Definition at line 133 of file mapitem.cpp.

135 {
136  BLOCK_START("MapItem::draw")
137  if (mImage != nullptr)
138  graphics->drawImage(mImage, x, y);
139 
140  switch (mType)
141  {
142  case MapItemType::ROAD:
143  case MapItemType::CROSS:
146  graphics->fillRectangle(Rect(x + dx / 3, y + dy / 3,
147  dx / 3, dy / 3));
148  break;
149  case MapItemType::HOME:
150  {
153  graphics->fillRectangle(Rect(x, y, dx, dy));
156  graphics->drawRectangle(Rect(x, y, dx, dy));
157  break;
158  }
159  default:
160  break;
161  }
162  if (!mName.empty()
165  {
166  Font *const font = gui->getFont();
167  const Color &color = userPalette->getColor(UserColorId::BEING, 255U);
168  font->drawString(graphics,
169  color,
170  color,
171  mName,
172  x, y);
173  }
174  BLOCK_END("MapItem::draw")
175 }
Definition: color.h:76
Definition: font.h:90
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawRectangle(const Rect &rectangle)=0
Font * getFont() const
Definition: gui.h:160
Definition: rect.h:74
const Color & getColor(UserColorIdT type, const unsigned int alpha)
Definition: userpalette.h:160
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:200
if(!vert) return
void drawImage(const Image *restrict const image, int dstX, int dstY) restrict2 override final
Gui * gui
Definition: gui.cpp:111
@ HOME_PLACE_BORDER
Definition: usercolorid.h:95
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
UserPalette * userPalette
Definition: userpalette.cpp:34

References UserColorId::BEING, BLOCK_END, BLOCK_START, MapItemType::CROSS, Graphics::drawImage(), Graphics::drawRectangle(), Font::drawString(), MapItemType::EMPTY, Graphics::fillRectangle(), UserPalette::getColor(), UserPalette::getColorWithAlpha(), Gui::getFont(), gui, MapItemType::HOME, UserColorId::HOME_PLACE, UserColorId::HOME_PLACE_BORDER, mImage, mName, mType, MapItemType::PORTAL, MapItemType::ROAD, UserColorId::ROAD_POINT, Graphics::setColor(), userPalette, x, and y.

Referenced by SpecialLayer::draw(), and MapLayer::drawSpecialLayer().

◆ getComment()

const std::string& MapItem::getComment ( ) const
inline

◆ getName()

const std::string& MapItem::getName ( ) const
inline

Definition at line 74 of file mapitem.h.

75  { return mName; }

References mName.

◆ getType()

int MapItem::getType ( ) const
inline

◆ getX()

int MapItem::getX ( ) const
inline

◆ getY()

int MapItem::getY ( ) const
inline

◆ setComment()

void MapItem::setComment ( const std::string &  comment)
inline

Definition at line 71 of file mapitem.h.

72  { mComment = comment; }

References mComment.

Referenced by RenameListener::action().

◆ setName()

void MapItem::setName ( const std::string &  name)
inline

Definition at line 77 of file mapitem.h.

78  { mName = name; }

References mName.

Referenced by LocalPlayer::setHome(), and SocialNavigationTab::updateList().

◆ setPos()

void MapItem::setPos ( const int  x,
const int  y 
)

Definition at line 127 of file mapitem.cpp.

128 {
129  mX = x;
130  mY = y;
131 }

References mX, mY, x, and y.

Referenced by SpecialLayer::setTile().

◆ setType()

void MapItem::setType ( const int  type)

Definition at line 96 of file mapitem.cpp.

97 {
98  std::string name;
99  mType = type;
100  if (mImage != nullptr)
101  mImage->decRef();
102 
103  switch (type)
104  {
106  name = "graphics/sprites/arrow_up.png";
107  break;
109  name = "graphics/sprites/arrow_down.png";
110  break;
112  name = "graphics/sprites/arrow_left.png";
113  break;
115  name = "graphics/sprites/arrow_right.png";
116  break;
117  default:
118  break;
119  }
120 
121  if (!name.empty())
122  mImage = Loader::getImage(name);
123  else
124  mImage = nullptr;
125 }
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:86

References MapItemType::ARROW_DOWN, MapItemType::ARROW_LEFT, MapItemType::ARROW_RIGHT, MapItemType::ARROW_UP, Loader::getImage(), mImage, and mType.

Referenced by SpecialLayer::addRoad(), SpecialLayer::clean(), MapItem(), and SpecialLayer::setTile().

Friends And Related Function Documentation

◆ Map

friend class Map
friend

Definition at line 35 of file mapitem.h.

◆ MapLayer

friend class MapLayer
friend

Definition at line 36 of file mapitem.h.

◆ SpecialLayer

friend class SpecialLayer
friend

Definition at line 37 of file mapitem.h.

Field Documentation

◆ mComment

std::string MapItem::mComment
private

Definition at line 86 of file mapitem.h.

Referenced by getComment(), and setComment().

◆ mImage

Image* MapItem::mImage
private

Definition at line 85 of file mapitem.h.

Referenced by draw(), setType(), and ~MapItem().

◆ mName

std::string MapItem::mName
private

Definition at line 87 of file mapitem.h.

Referenced by draw(), getName(), and setName().

◆ mType

int MapItem::mType
private

◆ mX

int MapItem::mX
private

Definition at line 89 of file mapitem.h.

Referenced by getX(), and setPos().

◆ mY

int MapItem::mY
private

Definition at line 90 of file mapitem.h.

Referenced by getY(), and setPos().


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