00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef VIEWPORT_H 00023 #define VIEWPORT_H 00024 00025 #include "gui/widgets/windowcontainer.h" 00026 00027 #include "configlistener.h" 00028 #include "position.h" 00029 00030 #include <guichan/mouselistener.hpp> 00031 00032 class Being; 00033 class FloorItem; 00034 class Graphics; 00035 class ImageSet; 00036 class Item; 00037 class Map; 00038 class PopupMenu; 00039 00041 const int walkingMouseDelay = 500; 00042 00051 class Viewport : public WindowContainer, public gcn::MouseListener, 00052 public ConfigListener 00053 { 00054 public: 00058 Viewport(); 00059 00063 ~Viewport(); 00064 00068 void setMap(Map *map); 00069 00073 void draw(gcn::Graphics *graphics); 00074 00078 void logic(); 00079 00083 void toggleDebugPath() { mShowDebugPath = !mShowDebugPath; } 00084 00088 void mousePressed(gcn::MouseEvent &event); 00089 00093 void mouseDragged(gcn::MouseEvent &event); 00094 00098 void mouseReleased(gcn::MouseEvent &event); 00099 00103 void mouseMoved(gcn::MouseEvent &event); 00104 00109 void showPopup(int x, int y, Item *item); 00110 00115 void closePopupMenu(); 00116 00120 void optionChanged(const std::string &name); 00121 00125 int getCameraX() const { return (int) mPixelViewX; } 00126 00130 int getCameraY() const { return (int) mPixelViewY; } 00131 00135 int getMouseX() const { return mMouseX; } 00136 00140 int getMouseY() const { return mMouseY; } 00141 00145 void scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; } 00146 00147 private: 00152 void drawDebugPath(Graphics *graphics); 00153 00157 void drawPath(Graphics *graphics, const Path &path); 00158 00159 Map *mMap; 00161 int mScrollRadius; 00162 int mScrollLaziness; 00163 int mScrollCenterOffsetX; 00164 int mScrollCenterOffsetY; 00165 int mMouseX; 00166 int mMouseY; 00167 float mPixelViewX; 00168 float mPixelViewY; 00169 int mTileViewX; 00170 int mTileViewY; 00171 bool mShowDebugPath; 00172 bool mVisibleNames; 00174 bool mPlayerFollowMouse; 00175 #ifdef TMWSERV_SUPPORT 00176 int mLocalWalkTime; 00177 #else 00178 int mWalkTime; 00179 #endif 00180 00181 PopupMenu *mPopupMenu; 00182 Being *mSelectedBeing; 00183 }; 00184 00185 extern Viewport *viewport; 00187 #endif