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 31 of file mapitem.h.

Constructor & Destructor Documentation

◆ MapItem() [1/4]

MapItem::MapItem ( )

Definition at line 38 of file mapitem.cpp.

38  :
39  mImage(nullptr),
40  mComment(),
41  mName(),
43  mX(-1),
44  mY(-1)
45 {
47 }

References MapItemType::EMPTY, and setType().

◆ MapItem() [2/4]

MapItem::MapItem ( const int  type)
explicit

Definition at line 49 of file mapitem.cpp.

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

References setType().

◆ MapItem() [3/4]

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

Definition at line 60 of file mapitem.cpp.

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

References setType().

◆ MapItem() [4/4]

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

Definition at line 72 of file mapitem.cpp.

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

References setType().

◆ ~MapItem()

MapItem::~MapItem ( )

Definition at line 86 of file mapitem.cpp.

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

References Image::decRef(), and 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 132 of file mapitem.cpp.

134 {
135  BLOCK_START("MapItem::draw")
136  if (mImage != nullptr)
137  graphics->drawImage(mImage, x, y);
138 
139  switch (mType)
140  {
141  case MapItemType::ROAD:
142  case MapItemType::CROSS:
145  graphics->fillRectangle(Rect(x + dx / 3, y + dy / 3,
146  dx / 3, dy / 3));
147  break;
148  case MapItemType::HOME:
149  {
152  graphics->fillRectangle(Rect(x, y, dx, dy));
155  graphics->drawRectangle(Rect(x, y, dx, dy));
156  break;
157  }
158  default:
159  break;
160  }
161  if (!mName.empty()
164  {
165  Font *const font = gui->getFont();
166  const Color &color = userPalette->getColor(UserColorId::BEING, 255U);
167  font->drawString(graphics,
168  color,
169  color,
170  mName,
171  x, y);
172  }
173  BLOCK_END("MapItem::draw")
174 }

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 73 of file mapitem.h.

74  { 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 70 of file mapitem.h.

71  { mComment = comment; }

References mComment.

Referenced by RenameListener::action().

◆ setName()

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

Definition at line 76 of file mapitem.h.

77  { mName = name; }

References mName.

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

◆ setPos()

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

Definition at line 126 of file mapitem.cpp.

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

References mX, mY, x, and y.

Referenced by SpecialLayer::setTile().

◆ setType()

void MapItem::setType ( const int  type)

Definition at line 95 of file mapitem.cpp.

96 {
97  std::string name;
98  mType = type;
99  if (mImage != nullptr)
100  mImage->decRef();
101 
102  switch (type)
103  {
105  name = "graphics/sprites/arrow_up.png";
106  break;
108  name = "graphics/sprites/arrow_down.png";
109  break;
111  name = "graphics/sprites/arrow_left.png";
112  break;
114  name = "graphics/sprites/arrow_right.png";
115  break;
116  default:
117  break;
118  }
119 
120  if (!name.empty())
121  mImage = Loader::getImage(name);
122  else
123  mImage = nullptr;
124 }

References MapItemType::ARROW_DOWN, MapItemType::ARROW_LEFT, MapItemType::ARROW_RIGHT, MapItemType::ARROW_UP, Image::decRef(), 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 34 of file mapitem.h.

◆ MapLayer

friend class MapLayer
friend

Definition at line 35 of file mapitem.h.

◆ SpecialLayer

friend class SpecialLayer
friend

Definition at line 36 of file mapitem.h.

Field Documentation

◆ mComment

std::string MapItem::mComment
private

Definition at line 85 of file mapitem.h.

Referenced by getComment(), and setComment().

◆ mImage

Image* MapItem::mImage
private

Definition at line 84 of file mapitem.h.

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

◆ mName

std::string MapItem::mName
private

Definition at line 86 of file mapitem.h.

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

◆ mType

int MapItem::mType
private

◆ mX

int MapItem::mX
private

Definition at line 88 of file mapitem.h.

Referenced by getX(), and setPos().

◆ mY

int MapItem::mY
private

Definition at line 89 of file mapitem.h.

Referenced by getY(), and setPos().


The documentation for this class was generated from the following files:
Graphics::drawRectangle
virtual void drawRectangle(const Rect &rectangle)=0
MapItemType::ARROW_DOWN
@ ARROW_DOWN
Definition: mapitemtype.h:33
UserColorId::HOME_PLACE_BORDER
@ HOME_PLACE_BORDER
Definition: usercolorid.h:94
MapItemType::ARROW_UP
@ ARROW_UP
Definition: mapitemtype.h:32
UserPalette::getColorWithAlpha
const Color & getColorWithAlpha(const UserColorIdT type)
Definition: userpalette.h:199
MapItemType::ARROW_LEFT
@ ARROW_LEFT
Definition: mapitemtype.h:34
MapItem::mType
int mType
Definition: mapitem.h:87
MapItem::mY
int mY
Definition: mapitem.h:89
MapItemType::ARROW_RIGHT
@ ARROW_RIGHT
Definition: mapitemtype.h:35
userPalette
UserPalette * userPalette
Definition: userpalette.cpp:33
Gui::getFont
Font * getFont() const
Definition: gui.h:159
UserColorId::ROAD_POINT
@ ROAD_POINT
Definition: usercolorid.h:95
if
if(!vert) return
drawImage
void drawImage(const Image *restrict const image, int dstX, int dstY) restrict2 override final
Font::drawString
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
MapItem::mName
std::string mName
Definition: mapitem.h:86
UserColorId::HOME_PLACE
@ HOME_PLACE
Definition: usercolorid.h:93
MapItemType::ROAD
@ ROAD
Definition: mapitemtype.h:30
gui
Gui * gui
Definition: gui.cpp:110
Loader::getImage
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
MapItemType::HOME
@ HOME
Definition: mapitemtype.h:29
MapItem::setType
void setType(const int type)
Definition: mapitem.cpp:95
MapItemType::CROSS
@ CROSS
Definition: mapitemtype.h:31
x
x
Definition: graphics_calcImageRect.hpp:72
MapItem::mX
int mX
Definition: mapitem.h:88
Font
Definition: font.h:88
MapItemType::EMPTY
@ EMPTY
Definition: mapitemtype.h:28
Graphics::setColor
virtual void setColor(const Color &color)
Definition: graphics.h:319
Rect
Definition: rect.h:72
MapItem::mComment
std::string mComment
Definition: mapitem.h:85
MapItemType::PORTAL
@ PORTAL
Definition: mapitemtype.h:36
UserPalette::getColor
const Color & getColor(UserColorIdT type, const unsigned int alpha)
Definition: userpalette.h:159
BLOCK_START
#define BLOCK_START(name)
Definition: perfomance.h:78
BLOCK_END
#define BLOCK_END(name)
Definition: perfomance.h:79
Graphics::fillRectangle
virtual void fillRectangle(const Rect &rectangle)=0
Color
Definition: color.h:74
MapItem::mImage
Image * mImage
Definition: mapitem.h:84
y
y
Definition: graphics_calcImageRect.hpp:72
Image::decRef
void decRef()
Definition: image.cpp:522
UserColorId::BEING
@ BEING
Definition: usercolorid.h:33