ManaPlus
Public Member Functions | Data Fields | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | Friends
Viewport Class Reference

#include <viewport.h>

Inheritance diagram for Viewport:
WindowContainer MouseListener ConfigListener WindowContainer MouseListener ConfigListener Container Container BasicContainer2 BasicContainer2 BasicContainer BasicContainer Widget WidgetDeathListener Widget WidgetDeathListener Widget2 Widget2

Public Member Functions

 Viewport ()
 
 ~Viewport ()
 
void setMap (Map *const map)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void logic ()
 
void toggleMapDrawType ()
 
void toggleCameraMode ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void optionChanged (const std::string &name)
 
int getCameraX () const
 
int getCameraY () const
 
void scrollBy (const int x, const int y)
 
void cleanHoverItems ()
 
MapgetMap () const
 
void moveCamera (const int dx, const int dy)
 
int getCameraRelativeX () const
 
int getCameraRelativeY () const
 
void setCameraRelativeX (const int n)
 
void setCameraRelativeY (const int n)
 
void videoResized ()
 
 Viewport ()
 
 ~Viewport ()
 
void setMap (Map *const map)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void logic ()
 
void toggleMapDrawType ()
 
void toggleCameraMode ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void optionChanged (const std::string &name)
 
int getCameraX () const
 
int getCameraY () const
 
void scrollBy (const int x, const int y)
 
void cleanHoverItems ()
 
MapgetMap () const
 
void moveCamera (const int dx, const int dy)
 
int getCameraRelativeX () const
 
int getCameraRelativeY () const
 
void setCameraRelativeX (const int n)
 
void setCameraRelativeY (const int n)
 
void moveCameraToActor (const BeingId actorId, const int x, const int y)
 
void moveCameraToPosition (const int x, const int y)
 
void moveCameraRelative (const int x, const int y)
 
void returnCamera ()
 
void getMouseTile (int &destX, int &destY) const
 
void videoResized ()
 
- Public Member Functions inherited from WindowContainer
 WindowContainer (const Widget2 *const widget)
 
void slowLogic ()
 
void scheduleDelete (Widget *const widget)
 
void adjustAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
void moveWidgetAfter (Widget *const before, Widget *const widget)
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 

Data Fields

int mMouseX
 
int mMouseY
 
- Data Fields inherited from Widget
Visible mVisible
 

Protected Member Functions

void clearHover (const ActorSprite *const actor)
 Clears any matching hovers. More...
 
void updateMidVars ()
 
void updateMaxVars ()
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 

Static Protected Member Functions

static void validateSpeed ()
 

Private Member Functions

void drawDebugPath (Graphics *const graphics)
 
void drawPath (Graphics *const graphics, const Path &path, const Color &color) const
 
bool leftMouseAction ()
 
bool openContextMenu (const MouseEvent &event)
 
void walkByMouse (const MouseEvent &event)
 
void followMouse ()
 
void drawDebugPath (Graphics *const graphics)
 
void drawPath (Graphics *const graphics, const Path &path, const Color &color) const
 
bool leftMouseAction ()
 
bool openContextMenu (const MouseEvent &event)
 
void walkByMouse (const MouseEvent &event)
 
void getMouseTile (const int x, const int y, int &destX, int &destY) const
 
void followMouse ()
 

Private Attributes

MapmMap
 
BeingmHoverBeing
 
FloorItemmHoverItem
 
MapItemmHoverSign
 
int mScrollRadius
 
int mScrollLaziness
 
int mScrollCenterOffsetX
 
int mScrollCenterOffsetY
 
int mMousePressX
 
int mMousePressY
 
int mPixelViewX
 
int mPixelViewY
 
int mLocalWalkTime
 
int mCameraRelativeX
 
int mCameraRelativeY
 
bool mShowBeingPopup
 
bool mSelfMouseHeal
 
bool mEnableLazyScrolling
 
bool mMouseDirectionMove
 
bool mLongMouseClick
 
bool mMouseClicked
 
bool mPlayerFollowMouse
 
int mMidTileX
 
int mMidTileY
 
int mViewXmax
 
int mViewYmax
 
time_t mLocalWalkTime
 
bool mAllowMoveByMouse
 

Friends

class ActorManager
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

The viewport on the map. Displays the current map and handles mouse input and the popup menu.

Definition at line 44 of file viewport.h.

Constructor & Destructor Documentation

◆ Viewport() [1/2]

Viewport::Viewport ( )

Constructor.

Definition at line 40 of file viewport.cpp.

40  :
41  WindowContainer(nullptr),
42  MouseListener(),
44  mMouseX(0),
45  mMouseY(0),
46  mMap(nullptr),
47  mHoverBeing(nullptr),
48  mHoverItem(nullptr),
49  mHoverSign(nullptr),
50  mScrollRadius(config.getIntValue("ScrollRadius")),
51  mScrollLaziness(config.getIntValue("ScrollLaziness")),
52  mScrollCenterOffsetX(config.getIntValue("ScrollCenterOffsetX")),
53  mScrollCenterOffsetY(config.getIntValue("ScrollCenterOffsetY")),
54  mMousePressX(0),
55  mMousePressY(0),
56  mPixelViewX(0),
57  mPixelViewY(0),
58  mLocalWalkTime(-1),
61  mShowBeingPopup(config.getBoolValue("showBeingPopup")),
62  mSelfMouseHeal(config.getBoolValue("selfMouseHeal")),
63  mEnableLazyScrolling(config.getBoolValue("enableLazyScrolling")),
64  mMouseDirectionMove(config.getBoolValue("mouseDirectionMove")),
65  mLongMouseClick(config.getBoolValue("longmouseclick")),
66  mMouseClicked(false),
67  mPlayerFollowMouse(false)
68 {
70  addMouseListener(this);
71 
72  config.addListener("ScrollLaziness", this);
73  config.addListener("ScrollRadius", this);
74  config.addListener("showBeingPopup", this);
75  config.addListener("selfMouseHeal", this);
76  config.addListener("enableLazyScrolling", this);
77  config.addListener("mouseDirectionMove", this);
78  config.addListener("longmouseclick", this);
79 
80  setFocusable(true);
81 }
void setOpaque(Opaque opaque)
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
int getIntValue(const std::string &key) const
int mMouseX
Definition: viewport.h:154
Being * mHoverBeing
Definition: viewport.h:185
int mScrollLaziness
Definition: viewport.h:190
int mMousePressX
Definition: viewport.h:193
Map * mMap
Definition: viewport.h:183
int mCameraRelativeY
Definition: viewport.h:201
int mPixelViewX
Definition: viewport.h:195
bool mLongMouseClick
Definition: viewport.h:207
bool mMouseClicked
Definition: viewport.h:208
bool mPlayerFollowMouse
Definition: viewport.h:209
int mScrollCenterOffsetX
Definition: viewport.h:191
bool mEnableLazyScrolling
Definition: viewport.h:205
bool mShowBeingPopup
Definition: viewport.h:203
int mLocalWalkTime
Definition: viewport.h:198
FloorItem * mHoverItem
Definition: viewport.h:186
bool mMouseDirectionMove
Definition: viewport.h:206
bool mSelfMouseHeal
Definition: viewport.h:204
int mCameraRelativeX
Definition: viewport.h:200
MapItem * mHoverSign
Definition: viewport.h:187
int mPixelViewY
Definition: viewport.h:196
int mScrollRadius
Definition: viewport.h:189
int mScrollCenterOffsetY
Definition: viewport.h:192
int mMouseY
Definition: viewport.h:155
int mMousePressY
Definition: viewport.h:194
void setFocusable(const bool focusable)
Definition: widget.cpp:192
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
WindowContainer(const Widget2 *const widget)
Configuration config
const bool Opaque_false
Definition: opaque.h:30

References Configuration::addListener(), Widget::addMouseListener(), config, Opaque_false, Widget::setFocusable(), and BasicContainer2::setOpaque().

◆ ~Viewport() [1/2]

Viewport::~Viewport ( )

Destructor.

Definition at line 83 of file viewport.cpp.

84 {
85  config.removeListeners(this);
87 }
void removeListeners(ConfigListener *const listener)
#define CHECKLISTENERS
Definition: localconsts.h:277

References CHECKLISTENERS, config, and Configuration::removeListeners().

◆ Viewport() [2/2]

Viewport::Viewport ( )

Constructor.

◆ ~Viewport() [2/2]

Viewport::~Viewport ( )

Destructor.

Member Function Documentation

◆ cleanHoverItems() [1/2]

void Viewport::cleanHoverItems ( )

Clear all hover item, being etc

Definition at line 259 of file viewport.cpp.

260 {
261  mHoverBeing = nullptr;
262  mHoverItem = nullptr;
263  mHoverSign = nullptr;
264 }

References mHoverBeing, mHoverItem, and mHoverSign.

Referenced by Game::changeMap().

◆ cleanHoverItems() [2/2]

void Viewport::cleanHoverItems ( )

Clear all hover item, being etc

◆ clearHover()

void Viewport::clearHover ( const ActorSprite *const  actor)
protected

Clears any matching hovers.

Definition at line 1054 of file viewport.cpp.

1055 {
1056  if (mHoverBeing == actor)
1057  mHoverBeing = nullptr;
1058 
1059  if (mHoverItem == actor)
1060  mHoverItem = nullptr;
1061 }

References mHoverBeing, and mHoverItem.

Referenced by ActorManager::logic().

◆ draw() [1/2]

void Viewport::draw ( Graphics *const  graphics)
virtual

Draws the viewport.

Reimplemented from BasicContainer2.

Definition at line 93 of file viewport.cpp.

94 {
95  BLOCK_START("Viewport::draw 1")
96  static int lastTick = tick_time;
97 
98  graphics->setColor(Color(64, 64, 64, 255));
99  graphics->fillRectangle(
100  Rect(0, 0, getWidth(), getHeight()));
101 
102  // Avoid freaking out when tick_time overflows
103  if (tick_time < lastTick)
104  lastTick = tick_time;
105 
106  // Draw contained widgets
107  WindowContainer::draw(graphics);
108  BLOCK_END("Viewport::draw 1")
109 }
Definition: color.h:76
Definition: rect.h:74
void draw(Graphics *const graphics)
Definition: viewport.cpp:93
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
volatile int tick_time
Definition: timer.cpp:53
if(!vert) return
void fillRectangle(const Rect &restrict rect) restrict2 override final
void setColor(const Color &restrict color) override final
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, BasicContainer2::draw(), Graphics::fillRectangle(), Widget::getHeight(), Widget::getWidth(), Graphics::setColor(), and tick_time.

Referenced by safeDraw().

◆ draw() [2/2]

void Viewport::draw ( Graphics *const  graphics)
virtual

Draws the viewport.

Reimplemented from BasicContainer2.

◆ drawDebugPath() [1/2]

void Viewport::drawDebugPath ( Graphics *const  graphics)
private

Finds a path from the player to the mouse, and draws it. This is for debug purposes.

Definition at line 129 of file viewport.cpp.

130 {
131 }

◆ drawDebugPath() [2/2]

void Viewport::drawDebugPath ( Graphics *const  graphics)
private

Finds a path from the player to the mouse, and draws it. This is for debug purposes.

◆ drawPath() [1/2]

void Viewport::drawPath ( Graphics *const  graphics,
const Path path,
const Color color 
) const
private

Draws the given path.

Definition at line 354 of file viewport.cpp.

357 {
358  graphics->setColor(color);
359  Font *const font = getFont();
360 
361  int cnt = 1;
362  FOR_EACH (Path::const_iterator, i, path)
363  {
364  const int squareX = i->x * mapTileSize - mPixelViewX + 12;
365  const int squareY = i->y * mapTileSize - mPixelViewY + 12;
366 
367  graphics->fillRectangle(Rect(squareX, squareY, 8, 8));
368  if (mMap != nullptr)
369  {
370  const std::string str = toString(cnt);
371  font->drawString(graphics,
372  color, color,
373  str,
374  squareX + 4 - font->getWidth(str) / 2,
375  squareY + 12);
376  }
377  cnt ++;
378  }
379 }
Definition: font.h:90
int getWidth(const std::string &text) const
Definition: font.cpp:334
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
Font * getFont() const
Definition: widget.cpp:331
static const int mapTileSize
Definition: map.h:27
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References Font::drawString(), Graphics::fillRectangle(), FOR_EACH, Widget::getFont(), Font::getWidth(), mapTileSize, mMap, mPixelViewX, mPixelViewY, Graphics::setColor(), and Catch::toString().

◆ drawPath() [2/2]

void Viewport::drawPath ( Graphics *const  graphics,
const Path path,
const Color color 
) const
private

Draws the given path.

◆ followMouse() [1/2]

void Viewport::followMouse ( )
private

Make the player go to the mouse position.

Definition at line 125 of file viewport.cpp.

126 {
127 }

◆ followMouse() [2/2]

void Viewport::followMouse ( )
private

Make the player go to the mouse position.

◆ getCameraRelativeX() [1/2]

int Viewport::getCameraRelativeX ( ) const
inline

Definition at line 140 of file viewport.h.

141  { return mCameraRelativeX; }

References mCameraRelativeX.

Referenced by Minimap::draw2(), and NpcDialog::saveCamera().

◆ getCameraRelativeX() [2/2]

int Viewport::getCameraRelativeX ( ) const
inline

Definition at line 142 of file viewport.h.

143  { return mCameraRelativeX; }

References mCameraRelativeX.

◆ getCameraRelativeY() [1/2]

int Viewport::getCameraRelativeY ( ) const
inline

Definition at line 143 of file viewport.h.

144  { return mCameraRelativeY; }

References mCameraRelativeY.

Referenced by Minimap::draw2(), and NpcDialog::saveCamera().

◆ getCameraRelativeY() [2/2]

int Viewport::getCameraRelativeY ( ) const
inline

Definition at line 145 of file viewport.h.

146  { return mCameraRelativeY; }

References mCameraRelativeY.

◆ getCameraX() [1/2]

int Viewport::getCameraX ( ) const
inline

Returns camera x offset in pixels.

Definition at line 115 of file viewport.h.

116  { return mPixelViewX; }

References mPixelViewX.

Referenced by MapDebugTab::logic(), and ParticleEngine::update().

◆ getCameraX() [2/2]

int Viewport::getCameraX ( ) const
inline

Returns camera x offset in pixels.

Definition at line 117 of file viewport.h.

118  { return mPixelViewX; }

References mPixelViewX.

◆ getCameraY() [1/2]

int Viewport::getCameraY ( ) const
inline

Returns camera y offset in pixels.

Definition at line 121 of file viewport.h.

122  { return mPixelViewY; }

References mPixelViewY.

Referenced by MapDebugTab::logic(), and ParticleEngine::update().

◆ getCameraY() [2/2]

int Viewport::getCameraY ( ) const
inline

Returns camera y offset in pixels.

Definition at line 123 of file viewport.h.

124  { return mPixelViewY; }

References mPixelViewY.

◆ getMap() [1/2]

Map* Viewport::getMap ( ) const
inline

◆ getMap() [2/2]

Map* Viewport::getMap ( ) const
inline

Definition at line 137 of file viewport.h.

138  { return mMap; }

References mMap.

◆ getMouseTile() [1/2]

void Viewport::getMouseTile ( const int  x,
const int  y,
int &  destX,
int &  destY 
) const
private

Definition at line 619 of file viewport.cpp.

621 {
622  if (mMap == nullptr)
623  return;
624  const int tw = mMap->getTileWidth();
625  const int th = mMap->getTileHeight();
626  destX = CAST_S32(x + mPixelViewX)
627  / static_cast<float>(tw);
628 
629  if (mMap->isHeightsPresent())
630  {
631  const int th2 = th / 2;
632  const int clickY = y + mPixelViewY - th2;
633  destY = y + mPixelViewY;
634  int newDiffY = 1000000;
635  const int heightTiles = mainGraphics->mHeight / th;
636  const int tileViewY = mPixelViewY / th;
637  for (int f = tileViewY; f < tileViewY + heightTiles; f ++)
638  {
639  if (!mMap->getWalk(destX,
640  f,
645  {
646  continue;
647  }
648 
649  const int offset = mMap->getHeightOffset(
650  destX, f) * th2;
651  const int pixelF = f * th;
652  const int diff = abs(clickY + offset - pixelF);
653  if (diff < newDiffY)
654  {
655  destY = pixelF;
656  newDiffY = diff;
657  }
658  }
659  destY /= 32;
660  }
661  else
662  {
663  destY = CAST_S32((y + mPixelViewY) / static_cast<float>(th));
664  }
665 }
#define CAST_S32
Definition: cast.h:30
int mHeight
Definition: graphics.h:485
uint8_t getHeightOffset(const int x, const int y) const
Definition: map.cpp:1631
bool isHeightsPresent() const
Definition: map.h:362
int getTileHeight() const
Definition: map.h:184
bool getWalk(const int x, const int y, const unsigned char blockWalkMask) const
Definition: map.cpp:785
int getTileWidth() const
Definition: map.h:178
Graphics * mainGraphics
Definition: graphics.cpp:109
@ PLAYERWALL
Definition: blockmask.h:36

References BlockMask::AIR, CAST_S32, Map::getHeightOffset(), Map::getTileHeight(), Map::getTileWidth(), Map::getWalk(), Map::isHeightsPresent(), mainGraphics, Graphics::mHeight, mMap, mPixelViewX, mPixelViewY, BlockMask::PLAYERWALL, BlockMask::WALL, BlockMask::WATER, x, and y.

◆ getMouseTile() [2/2]

void Viewport::getMouseTile ( int &  destX,
int &  destY 
) const

Definition at line 614 of file viewport.cpp.

615 {
616  getMouseTile(mMouseX, mMouseY, destX, destY);
617 }
void getMouseTile(int &destX, int &destY) const
Definition: viewport.cpp:614

References mMouseX, and mMouseY.

Referenced by SkillDialog::useSkill(), and SkillDialog::useSkillDefault().

◆ leftMouseAction() [1/2]

bool Viewport::leftMouseAction ( )
private

Definition at line 266 of file viewport.cpp.

267 {
268  return false;
269 }

Referenced by mousePressed(), and mouseReleased().

◆ leftMouseAction() [2/2]

bool Viewport::leftMouseAction ( )
private

◆ logic() [1/2]

void Viewport::logic ( )
virtual

Implements player to keep following mouse.

Reimplemented from BasicContainer.

Definition at line 116 of file viewport.cpp.

117 {
118  BLOCK_START("Viewport::logic")
119  // Make the player follow the mouse position
120  // if the mouse is dragged elsewhere than in a window.
121  Gui::getMouseState(mMouseX, mMouseY);
123 }
Definition: gui.h:117
void logic()
Definition: viewport.cpp:116

References BLOCK_END, BLOCK_START, Gui::getMouseState(), mMouseX, and mMouseY.

◆ logic() [2/2]

void Viewport::logic ( )
virtual

Implements player to keep following mouse.

Reimplemented from BasicContainer.

◆ mouseDragged() [1/2]

void Viewport::mouseDragged ( MouseEvent event)
virtual

Handles mouse move on map

Reimplemented from MouseListener.

Definition at line 179 of file viewport.cpp.

180 {
181  if (event.getSource() != this || event.isConsumed())
182  {
183  mPlayerFollowMouse = false;
184  return;
185  }
186  if (mMouseClicked)
187  {
188  if (abs(event.getX() - mMousePressX) > 32
189  || abs(event.getY() - mMousePressY) > 32)
190  {
191  mPlayerFollowMouse = true;
192  }
193  }
194 
195  walkByMouse(event);
196 }
Widget * getSource() const
Definition: event.h:104
bool isConsumed() const
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
void walkByMouse(const MouseEvent &event)
Definition: viewport.cpp:175

References Event::getSource(), MouseEvent::getX(), MouseEvent::getY(), InputGuiEvent::isConsumed(), mMouseClicked, mMousePressX, mMousePressY, mPlayerFollowMouse, and walkByMouse().

◆ mouseDragged() [2/2]

void Viewport::mouseDragged ( MouseEvent event)
virtual

Handles mouse move on map

Reimplemented from MouseListener.

◆ mouseMoved() [1/2]

void Viewport::mouseMoved ( MouseEvent event)
virtual

Handles mouse move on map.

Reimplemented from MouseListener.

Definition at line 247 of file viewport.cpp.

248 {
249 }

◆ mouseMoved() [2/2]

void Viewport::mouseMoved ( MouseEvent event)
virtual

Handles mouse move on map.

Reimplemented from MouseListener.

◆ mousePressed() [1/2]

void Viewport::mousePressed ( MouseEvent event)
virtual

Handles mouse press on map.

Reimplemented from MouseListener.

Definition at line 138 of file viewport.cpp.

139 {
140  if (event.getSource() != this || event.isConsumed())
141  return;
142 
143  mMouseClicked = true;
144 
145  mMousePressX = event.getX();
146  mMousePressY = event.getY();
147  const MouseButtonT eventButton = event.getButton();
148 
149  // Right click might open a popup
150  if (eventButton == MouseButton::RIGHT)
151  {
152  if (openContextMenu(event))
153  return;
154  }
155 
156  // If a popup is active, just remove it
158  {
159  mPlayerFollowMouse = false;
161  return;
162  }
163 
164  // Left click can cause different actions
165  if (!mLongMouseClick && eventButton == MouseButton::LEFT)
166  {
167  if (leftMouseAction())
168  {
169  mPlayerFollowMouse = false;
170  return;
171  }
172  }
173 }
static void hidePopupMenu()
static bool isPopupMenuVisible()
bool openContextMenu(const MouseEvent &event)
Definition: viewport.cpp:133
bool leftMouseAction()
Definition: viewport.cpp:266
MouseButton ::T MouseButtonT
Definition: mousebutton.h:78

References Event::getSource(), PopupManager::hidePopupMenu(), InputGuiEvent::isConsumed(), PopupManager::isPopupMenuVisible(), MouseButton::LEFT, leftMouseAction(), mLongMouseClick, mMouseClicked, mMousePressX, mMousePressY, mPlayerFollowMouse, openContextMenu(), and MouseButton::RIGHT.

◆ mousePressed() [2/2]

void Viewport::mousePressed ( MouseEvent event)
virtual

Handles mouse press on map.

Reimplemented from MouseListener.

◆ mouseReleased() [1/2]

void Viewport::mouseReleased ( MouseEvent event)
virtual

Handles mouse button release on map.

Reimplemented from MouseListener.

Definition at line 198 of file viewport.cpp.

199 {
200  mPlayerFollowMouse = false;
201  mLocalWalkTime = -1;
203  {
204  mMouseClicked = false;
205  if (event.getSource() != this || event.isConsumed())
206  return;
207  const MouseButtonT eventButton = event.getButton();
208  if (eventButton == MouseButton::LEFT)
209  {
210  // long button press
211  if ((gui != nullptr) && gui->isLongPress())
212  {
213  if (openContextMenu(event))
214  {
215  gui->resetClickCount();
216  return;
217  }
218  }
219  else
220  {
221  if (leftMouseAction())
222  return;
223  }
224  walkByMouse(event);
225  }
226  }
227 }
bool isLongPress() const
Definition: gui.h:309
void resetClickCount()
Definition: gui.cpp:980
Gui * gui
Definition: gui.cpp:111

References Event::getSource(), gui, InputGuiEvent::isConsumed(), Gui::isLongPress(), MouseButton::LEFT, leftMouseAction(), mLocalWalkTime, mLongMouseClick, mMouseClicked, mPlayerFollowMouse, openContextMenu(), Gui::resetClickCount(), and walkByMouse().

◆ mouseReleased() [2/2]

void Viewport::mouseReleased ( MouseEvent event)
virtual

Handles mouse button release on map.

Reimplemented from MouseListener.

◆ moveCamera() [1/2]

void Viewport::moveCamera ( const int  dx,
const int  dy 
)

Definition at line 1070 of file viewport.cpp.

1071 {
1072  mCameraRelativeX += dx;
1073  mCameraRelativeY += dy;
1074  updateMidVars();
1075 }
void updateMidVars()
Definition: viewport.cpp:1129

References mCameraRelativeX, mCameraRelativeY, and updateMidVars().

Referenced by Game::moveInDirection().

◆ moveCamera() [2/2]

void Viewport::moveCamera ( const int  dx,
const int  dy 
)

◆ moveCameraRelative()

void Viewport::moveCameraRelative ( const int  x,
const int  y 
)

Definition at line 1103 of file viewport.cpp.

1104 {
1105  settings.cameraMode = 1;
1106  mCameraRelativeX += x;
1107  mCameraRelativeY += y;
1108  updateMidVars();
1109 }
unsigned int cameraMode
Definition: settings.h:144
Settings settings
Definition: settings.cpp:32

References Settings::cameraMode, mCameraRelativeX, mCameraRelativeY, settings, updateMidVars(), x, and y.

Referenced by Ea::NpcRecv::processNpcCommand().

◆ moveCameraToActor()

void Viewport::moveCameraToActor ( const BeingId  actorId,
const int  x,
const int  y 
)

Definition at line 1077 of file viewport.cpp.

1079 {
1080  if ((localPlayer == nullptr) || (actorManager == nullptr))
1081  return;
1082 
1083  const Actor *const actor = actorManager->findBeing(actorId);
1084  if (actor == nullptr)
1085  return;
1086  settings.cameraMode = 1;
1089  updateMidVars();
1090 }
ActorManager * actorManager
Being * findBeing(const BeingId id) const
Definition: actor.h:42
int mPixelX
Definition: actor.h:133
int mPixelY
Definition: actor.h:134
LocalPlayer * localPlayer

References actorManager, Settings::cameraMode, ActorManager::findBeing(), localPlayer, mCameraRelativeX, mCameraRelativeY, Actor::mPixelX, Actor::mPixelY, settings, updateMidVars(), x, and y.

Referenced by Ea::NpcRecv::processNpcCommand().

◆ moveCameraToPosition()

void Viewport::moveCameraToPosition ( const int  x,
const int  y 
)

Definition at line 1092 of file viewport.cpp.

1093 {
1094  if (localPlayer == nullptr)
1095  return;
1096 
1097  settings.cameraMode = 1;
1100  updateMidVars();
1101 }

References Settings::cameraMode, localPlayer, mCameraRelativeX, mCameraRelativeY, Actor::mPixelX, Actor::mPixelY, settings, updateMidVars(), x, and y.

Referenced by Ea::NpcRecv::processNpcCommand().

◆ openContextMenu() [1/2]

bool Viewport::openContextMenu ( const MouseEvent event)
private

Definition at line 133 of file viewport.cpp.

134 {
135  return false;
136 }

Referenced by mousePressed(), and mouseReleased().

◆ openContextMenu() [2/2]

bool Viewport::openContextMenu ( const MouseEvent event)
private

◆ optionChanged() [1/2]

void Viewport::optionChanged ( const std::string &  name)
virtual

A relevant config option changed.

Implements ConfigListener.

Definition at line 229 of file viewport.cpp.

230 {
231  if (name == "ScrollLaziness")
232  mScrollLaziness = config.getIntValue("ScrollLaziness");
233  else if (name == "ScrollRadius")
234  mScrollRadius = config.getIntValue("ScrollRadius");
235  else if (name == "showBeingPopup")
236  mShowBeingPopup = config.getBoolValue("showBeingPopup");
237  else if (name == "selfMouseHeal")
238  mSelfMouseHeal = config.getBoolValue("selfMouseHeal");
239  else if (name == "enableLazyScrolling")
240  mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling");
241  else if (name == "mouseDirectionMove")
242  mMouseDirectionMove = config.getBoolValue("mouseDirectionMove");
243  else if (name == "longmouseclick")
244  mLongMouseClick = config.getBoolValue("longmouseclick");
245 }

References config, Configuration::getBoolValue(), Configuration::getIntValue(), mEnableLazyScrolling, mLongMouseClick, mMouseDirectionMove, mScrollLaziness, mScrollRadius, mSelfMouseHeal, and mShowBeingPopup.

◆ optionChanged() [2/2]

void Viewport::optionChanged ( const std::string &  name)
virtual

A relevant config option changed.

Implements ConfigListener.

◆ returnCamera()

void Viewport::returnCamera ( )

◆ safeDraw() [1/2]

void Viewport::safeDraw ( Graphics *const  graphics)
virtual

Reimplemented from BasicContainer2.

Definition at line 111 of file viewport.cpp.

112 {
113  Viewport::draw(graphics);
114 }

References draw().

◆ safeDraw() [2/2]

void Viewport::safeDraw ( Graphics *const  graphics)
virtual

Reimplemented from BasicContainer2.

◆ scrollBy() [1/2]

void Viewport::scrollBy ( const int  x,
const int  y 
)
inline

Changes viewpoint by relative pixel coordinates.

Definition at line 127 of file viewport.h.

128  { mPixelViewX += x; mPixelViewY += y; }

References mPixelViewX, mPixelViewY, x, and y.

Referenced by Ea::PlayerRecv::processPlayerWarp().

◆ scrollBy() [2/2]

void Viewport::scrollBy ( const int  x,
const int  y 
)
inline

Changes viewpoint by relative pixel coordinates.

Definition at line 129 of file viewport.h.

130  { mPixelViewX += x; mPixelViewY += y; }

References mPixelViewX, mPixelViewY, x, and y.

◆ setCameraRelativeX() [1/2]

void Viewport::setCameraRelativeX ( const int  n)
inline

Definition at line 146 of file viewport.h.

147  { mCameraRelativeX = n; }

References mCameraRelativeX.

Referenced by NpcDialog::restoreCamera().

◆ setCameraRelativeX() [2/2]

void Viewport::setCameraRelativeX ( const int  n)
inline

Definition at line 148 of file viewport.h.

149  { mCameraRelativeX = n; updateMidVars(); }

References mCameraRelativeX, and updateMidVars().

◆ setCameraRelativeY() [1/2]

void Viewport::setCameraRelativeY ( const int  n)
inline

Definition at line 149 of file viewport.h.

150  { mCameraRelativeY = n; }

References mCameraRelativeY.

Referenced by NpcDialog::restoreCamera().

◆ setCameraRelativeY() [2/2]

void Viewport::setCameraRelativeY ( const int  n)
inline

Definition at line 151 of file viewport.h.

152  { mCameraRelativeY = n; updateMidVars(); }

References mCameraRelativeY, and updateMidVars().

◆ setMap() [1/2]

void Viewport::setMap ( Map *const  map)

Sets the map displayed by the viewport.

Definition at line 89 of file viewport.cpp.

90 {
91 }

Referenced by Game::changeMap().

◆ setMap() [2/2]

void Viewport::setMap ( Map *const  map)

Sets the map displayed by the viewport.

◆ toggleCameraMode() [1/2]

void Viewport::toggleCameraMode ( )

◆ toggleCameraMode() [2/2]

void Viewport::toggleCameraMode ( )

◆ toggleMapDrawType() [1/2]

void Viewport::toggleMapDrawType ( )

Toggles whether the path debug graphics are shown. normal, debug with all images and grid, debug with out big images and with out grid.

Definition at line 251 of file viewport.cpp.

252 {
253 }

Referenced by GameModifiers::changeMapDrawType().

◆ toggleMapDrawType() [2/2]

void Viewport::toggleMapDrawType ( )

Toggles whether the path debug graphics are shown. normal, debug with all images and grid, debug with out big images and with out grid.

◆ updateMaxVars()

void Viewport::updateMaxVars ( )
protected

Definition at line 1137 of file viewport.cpp.

1138 {
1139  if (mMap == nullptr)
1140  return;
1142  - mainGraphics->mWidth;
1144  - mainGraphics->mHeight;
1145 }
int mWidth
Definition: graphics.h:484
int getHeight() const
Definition: map.h:172
int getWidth() const
Definition: map.h:166
int mViewXmax
Definition: viewport.h:230
int mViewYmax
Definition: viewport.h:231

References Map::getHeight(), Map::getTileHeight(), Map::getTileWidth(), Map::getWidth(), mainGraphics, Graphics::mHeight, mMap, mViewXmax, mViewYmax, and Graphics::mWidth.

◆ updateMidVars()

void Viewport::updateMidVars ( )
protected

◆ validateSpeed()

void Viewport::validateSpeed ( )
staticprotected

Definition at line 1119 of file viewport.cpp.

1120 {
1123  {
1124  if (Game::instance() != nullptr)
1126  }
1127 }
static Game * instance()
Definition: game.h:82
void setValidSpeed()
Definition: game.cpp:1273
bool isActionActive(const InputActionT index) const
InputManager inputManager

References InputAction::ATTACK, inputManager, Game::instance(), InputManager::isActionActive(), Game::setValidSpeed(), and InputAction::TARGET_ATTACK.

◆ videoResized() [1/2]

void Viewport::videoResized ( )

Definition at line 271 of file viewport.cpp.

272 {
273 }

Referenced by Gui::videoResized().

◆ videoResized() [2/2]

void Viewport::videoResized ( )

◆ walkByMouse() [1/2]

void Viewport::walkByMouse ( const MouseEvent event)
private

Definition at line 175 of file viewport.cpp.

176 {
177 }

Referenced by mouseDragged(), and mouseReleased().

◆ walkByMouse() [2/2]

void Viewport::walkByMouse ( const MouseEvent event)
private

Friends And Related Function Documentation

◆ ActorManager

friend class ActorManager
friend

Definition at line 172 of file viewport.h.

Field Documentation

◆ mAllowMoveByMouse

bool Viewport::mAllowMoveByMouse
private

Definition at line 243 of file viewport.h.

◆ mCameraRelativeX

int Viewport::mCameraRelativeX
private

◆ mCameraRelativeY

int Viewport::mCameraRelativeY
private

◆ mEnableLazyScrolling

bool Viewport::mEnableLazyScrolling
private

Definition at line 205 of file viewport.h.

Referenced by optionChanged().

◆ mHoverBeing

Being * Viewport::mHoverBeing
private

Being mouse is currently over.

Definition at line 185 of file viewport.h.

Referenced by cleanHoverItems(), and clearHover().

◆ mHoverItem

FloorItem * Viewport::mHoverItem
private

FloorItem mouse is currently over.

Definition at line 186 of file viewport.h.

Referenced by cleanHoverItems(), and clearHover().

◆ mHoverSign

MapItem * Viewport::mHoverSign
private

Map sign mouse is currently over.

Definition at line 187 of file viewport.h.

Referenced by cleanHoverItems().

◆ mLocalWalkTime [1/2]

int Viewport::mLocalWalkTime
private

Timestamp before the next walk can be sent.

Definition at line 198 of file viewport.h.

Referenced by mouseReleased().

◆ mLocalWalkTime [2/2]

time_t Viewport::mLocalWalkTime
private

Definition at line 233 of file viewport.h.

◆ mLongMouseClick

bool Viewport::mLongMouseClick
private

Definition at line 207 of file viewport.h.

Referenced by mousePressed(), mouseReleased(), and optionChanged().

◆ mMap

Map * Viewport::mMap
private

The current map.

Definition at line 183 of file viewport.h.

Referenced by drawPath(), getMap(), getMouseTile(), and updateMaxVars().

◆ mMidTileX

int Viewport::mMidTileX
private

Definition at line 228 of file viewport.h.

Referenced by updateMidVars().

◆ mMidTileY

int Viewport::mMidTileY
private

Definition at line 229 of file viewport.h.

Referenced by updateMidVars().

◆ mMouseClicked

bool Viewport::mMouseClicked
private

Definition at line 208 of file viewport.h.

Referenced by mouseDragged(), mousePressed(), and mouseReleased().

◆ mMouseDirectionMove

bool Viewport::mMouseDirectionMove
private

Definition at line 206 of file viewport.h.

Referenced by optionChanged().

◆ mMousePressX

int Viewport::mMousePressX
private

Definition at line 193 of file viewport.h.

Referenced by mouseDragged(), and mousePressed().

◆ mMousePressY

int Viewport::mMousePressY
private

Definition at line 194 of file viewport.h.

Referenced by mouseDragged(), and mousePressed().

◆ mMouseX

int Viewport::mMouseX

◆ mMouseY

int Viewport::mMouseY

◆ mPixelViewX

int Viewport::mPixelViewX
private

Current viewpoint in pixels.

Definition at line 195 of file viewport.h.

Referenced by drawPath(), getCameraX(), getMouseTile(), and scrollBy().

◆ mPixelViewY

int Viewport::mPixelViewY
private

Current viewpoint in pixels.

Definition at line 196 of file viewport.h.

Referenced by drawPath(), getCameraY(), getMouseTile(), and scrollBy().

◆ mPlayerFollowMouse

bool Viewport::mPlayerFollowMouse
private

Definition at line 209 of file viewport.h.

Referenced by mouseDragged(), mousePressed(), and mouseReleased().

◆ mScrollCenterOffsetX

int Viewport::mScrollCenterOffsetX
private

Definition at line 191 of file viewport.h.

Referenced by updateMidVars().

◆ mScrollCenterOffsetY

int Viewport::mScrollCenterOffsetY
private

Definition at line 192 of file viewport.h.

Referenced by updateMidVars().

◆ mScrollLaziness

int Viewport::mScrollLaziness
private

Definition at line 190 of file viewport.h.

Referenced by optionChanged().

◆ mScrollRadius

int Viewport::mScrollRadius
private

Definition at line 189 of file viewport.h.

Referenced by optionChanged().

◆ mSelfMouseHeal

bool Viewport::mSelfMouseHeal
private

Definition at line 204 of file viewport.h.

Referenced by optionChanged().

◆ mShowBeingPopup

bool Viewport::mShowBeingPopup
private

Definition at line 203 of file viewport.h.

Referenced by optionChanged().

◆ mViewXmax

int Viewport::mViewXmax
private

Definition at line 230 of file viewport.h.

Referenced by updateMaxVars().

◆ mViewYmax

int Viewport::mViewYmax
private

Definition at line 231 of file viewport.h.

Referenced by updateMaxVars().


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