Mana
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Viewport Class Reference

The viewport on the map. More...

#include <viewport.h>

Inheritance diagram for Viewport:
WindowContainer EventListener Container

Classes

struct  ShakeEffect
 

Public Member Functions

 Viewport ()
 
 ~Viewport () override
 
void setMap (Map *map)
 Sets the map displayed by the viewport.
 
void draw (gcn::Graphics *graphics) override
 Draws the viewport.
 
void logic () override
 Implements player to keep following mouse.
 
void setDebugFlags (int debugFlags)
 Sets which debug flags (see Map::DebugFlags) should be enabled.
 
void mousePressed (gcn::MouseEvent &event) override
 Handles mouse press on map.
 
void mouseDragged (gcn::MouseEvent &event) override
 Handles mouse move on map.
 
void mouseReleased (gcn::MouseEvent &event) override
 Handles mouse button release on map.
 
void mouseMoved (gcn::MouseEvent &event) override
 Handles mouse move on map.
 
void showPopup (Window *parent, int x, int y, Item *item, bool isInventory=true, bool canDrop=true)
 Shows a popup for an item.
 
void closePopupMenu ()
 Closes the popup menu.
 
int getCameraX () const
 Returns camera x offset in pixels.
 
int getCameraY () const
 Returns camera y offset in pixels.
 
int getMouseX () const
 Returns mouse x in pixels.
 
int getMouseY () const
 Returns mouse y in pixels.
 
void scrollBy (float x, float y)
 Changes viewpoint by relative pixel coordinates.
 
MapgetCurrentMap () const
 Returns the current map object.
 
void hideBeingPopup ()
 Hides the BeingPopup.
 
void shakeScreen (int intensity)
 Makes the screen shake in a random direction.
 
void shakeScreen (float x, float y, float decay=0.95f, unsigned duration=0)
 Makes the screen shake in a specific direction.
 
void shakeScreenStop ()
 Stops all active screen shake effects.
 
void event (Event::Channel channel, const Event &event) override
 
- Public Member Functions inherited from WindowContainer
void logic () override
 Do GUI logic.
 
void draw (gcn::Graphics *graphics) override
 Adds debug drawing.
 
void scheduleDelete (gcn::Widget *widget)
 Schedule a widget for deletion.
 
void adjustAfterResize (int oldScreenWidth, int oldScreenHeight)
 Ensures that all visible windows are on the screen after the screen has been resized.
 
- Public Member Functions inherited from Container
 Container ()
 
 ~Container () override
 
void drawFrame (gcn::Graphics *graphics) override
 
- Public Member Functions inherited from EventListener
virtual ~EventListener ()
 
void listen (Event::Channel channel)
 
void ignore (Event::Channel channel)
 

Private Member Functions

void _drawDebugPath (Graphics *graphics)
 Finds a path from the player to the mouse, and draws it.
 
void _drawPath (Graphics *graphics, const Path &path, gcn::Color color=gcn::Color(255, 0, 0))
 Draws the given path.
 
void _followMouse ()
 Make the player go to the mouse position.
 
void updateCursorType ()
 Updates the cursor type.
 

Private Attributes

MapmMap = nullptr
 The current map.
 
int mMouseX = 0
 Current mouse position in pixels.
 
int mMouseY = 0
 Current mouse position in pixels.
 
float mPixelViewX = 0.0f
 Current viewpoint in pixels.
 
float mPixelViewY = 0.0f
 Current viewpoint in pixels.
 
int mDebugFlags = 0
 Flags for showing debug graphics.
 
std::list< ShakeEffectmShakeEffects
 
bool mPlayerFollowMouse = false
 
Timer mLocalWalkTimer
 Timer for sending walk messages.
 
PopupMenumPopupMenu
 Popup menu.
 
BeingmHoverBeing = nullptr
 Being mouse is currently over.
 
FloorItemmHoverItem = nullptr
 FloorItem mouse is currently over.
 
BeingPopupmBeingPopup
 Being information popup.
 

Additional Inherited Members

- Protected Member Functions inherited from Container
LayoutgetLayout ()
 Gets the layout handler for this container.
 
LayoutCellplace (int x, int y, gcn::Widget *wg, int w=1, int h=1)
 Adds a widget to the container and sets it at given cell.
 
ContainerPlacer getPlacer (int x, int y)
 Returns a proxy for adding widgets in an inner table of the layout.
 

Detailed Description

The viewport on the map.

Displays the current map and handles mouse input and the popup menu.

TODO: This class is planned to be extended to allow floating widgets on top of it such as NPC messages, which are positioned using map pixel coordinates.

Definition at line 57 of file viewport.h.

Constructor & Destructor Documentation

◆ Viewport()

Viewport::Viewport ( )

Definition at line 46 of file viewport.cpp.

◆ ~Viewport()

Viewport::~Viewport ( )
override

Definition at line 60 of file viewport.cpp.

Member Function Documentation

◆ _drawDebugPath()

void Viewport::_drawDebugPath ( Graphics graphics)
private

Finds a path from the player to the mouse, and draws it.

This is for debug purposes.

Definition at line 300 of file viewport.cpp.

◆ _drawPath()

void Viewport::_drawPath ( Graphics graphics,
const Path path,
gcn::Color  color = gcn::Color(255, 0, 0) 
)
private

Draws the given path.

Definition at line 392 of file viewport.cpp.

◆ _followMouse()

void Viewport::_followMouse ( )
private

Make the player go to the mouse position.

Definition at line 271 of file viewport.cpp.

◆ closePopupMenu()

void Viewport::closePopupMenu ( )

Closes the popup menu.

Needed for when the player dies or switching maps.

Definition at line 544 of file viewport.cpp.

◆ draw()

void Viewport::draw ( gcn::Graphics *  graphics)
override

Draws the viewport.

Definition at line 75 of file viewport.cpp.

◆ event()

void Viewport::event ( Event::Channel  channel,
const Event event 
)
overridevirtual

Implements EventListener.

Definition at line 605 of file viewport.cpp.

◆ getCameraX()

int Viewport::getCameraX ( ) const
inline

Returns camera x offset in pixels.

Definition at line 121 of file viewport.h.

◆ getCameraY()

int Viewport::getCameraY ( ) const
inline

Returns camera y offset in pixels.

Definition at line 126 of file viewport.h.

◆ getCurrentMap()

Map * Viewport::getCurrentMap ( ) const
inline

Returns the current map object.

Definition at line 146 of file viewport.h.

◆ getMouseX()

int Viewport::getMouseX ( ) const
inline

Returns mouse x in pixels.

Definition at line 131 of file viewport.h.

◆ getMouseY()

int Viewport::getMouseY ( ) const
inline

Returns mouse y in pixels.

Definition at line 136 of file viewport.h.

◆ hideBeingPopup()

void Viewport::hideBeingPopup ( )

Hides the BeingPopup.

Definition at line 600 of file viewport.cpp.

◆ logic()

void Viewport::logic ( )
override

Implements player to keep following mouse.

Definition at line 262 of file viewport.cpp.

◆ mouseDragged()

void Viewport::mouseDragged ( gcn::MouseEvent &  event)
override

Handles mouse move on map.

Definition at line 516 of file viewport.cpp.

◆ mouseMoved()

void Viewport::mouseMoved ( gcn::MouseEvent &  event)
override

Handles mouse move on map.

Definition at line 549 of file viewport.cpp.

◆ mousePressed()

void Viewport::mousePressed ( gcn::MouseEvent &  event)
override

Handles mouse press on map.

Definition at line 411 of file viewport.cpp.

◆ mouseReleased()

void Viewport::mouseReleased ( gcn::MouseEvent &  event)
override

Handles mouse button release on map.

Definition at line 533 of file viewport.cpp.

◆ scrollBy()

void Viewport::scrollBy ( float  x,
float  y 
)
inline

Changes viewpoint by relative pixel coordinates.

Definition at line 141 of file viewport.h.

◆ setDebugFlags()

void Viewport::setDebugFlags ( int  debugFlags)

Sets which debug flags (see Map::DebugFlags) should be enabled.

Definition at line 593 of file viewport.cpp.

◆ setMap()

void Viewport::setMap ( Map map)

Sets the map displayed by the viewport.

Definition at line 66 of file viewport.cpp.

◆ shakeScreen() [1/2]

void Viewport::shakeScreen ( float  x,
float  y,
float  decay = 0.95f,
unsigned  duration = 0 
)

Makes the screen shake in a specific direction.

Definition at line 251 of file viewport.cpp.

◆ shakeScreen() [2/2]

void Viewport::shakeScreen ( int  intensity)

Makes the screen shake in a random direction.

Definition at line 243 of file viewport.cpp.

◆ shakeScreenStop()

void Viewport::shakeScreenStop ( )
inline

Stops all active screen shake effects.

Definition at line 166 of file viewport.h.

◆ showPopup()

void Viewport::showPopup ( Window parent,
int  x,
int  y,
Item item,
bool  isInventory = true,
bool  canDrop = true 
)

Shows a popup for an item.

TODO Find some way to get rid of Item here

Definition at line 538 of file viewport.cpp.

◆ updateCursorType()

void Viewport::updateCursorType ( )
private

Updates the cursor type.

Definition at line 567 of file viewport.cpp.

Member Data Documentation

◆ mBeingPopup

BeingPopup* Viewport::mBeingPopup
private

Being information popup.

Definition at line 219 of file viewport.h.

◆ mDebugFlags

int Viewport::mDebugFlags = 0
private

Flags for showing debug graphics.

Definition at line 200 of file viewport.h.

◆ mHoverBeing

Being* Viewport::mHoverBeing = nullptr
private

Being mouse is currently over.

Definition at line 217 of file viewport.h.

◆ mHoverItem

FloorItem* Viewport::mHoverItem = nullptr
private

FloorItem mouse is currently over.

Definition at line 218 of file viewport.h.

◆ mLocalWalkTimer

Timer Viewport::mLocalWalkTimer
private

Timer for sending walk messages.

Definition at line 214 of file viewport.h.

◆ mMap

Map* Viewport::mMap = nullptr
private

The current map.

Definition at line 194 of file viewport.h.

◆ mMouseX

int Viewport::mMouseX = 0
private

Current mouse position in pixels.

Definition at line 196 of file viewport.h.

◆ mMouseY

int Viewport::mMouseY = 0
private

Current mouse position in pixels.

Definition at line 197 of file viewport.h.

◆ mPixelViewX

float Viewport::mPixelViewX = 0.0f
private

Current viewpoint in pixels.

Definition at line 198 of file viewport.h.

◆ mPixelViewY

float Viewport::mPixelViewY = 0.0f
private

Current viewpoint in pixels.

Definition at line 199 of file viewport.h.

◆ mPlayerFollowMouse

bool Viewport::mPlayerFollowMouse = false
private

Definition at line 212 of file viewport.h.

◆ mPopupMenu

PopupMenu* Viewport::mPopupMenu
private

Popup menu.

Definition at line 216 of file viewport.h.

◆ mShakeEffects

std::list<ShakeEffect> Viewport::mShakeEffects
private

Definition at line 210 of file viewport.h.


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