2011-08-29 05:04:23 +02:00
|
|
|
/*
|
2012-01-02 17:58:37 +01:00
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
2011-08-29 05:04:23 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "uimap.h"
|
2011-12-30 19:14:50 +01:00
|
|
|
#include <otclient/core/game.h>
|
2011-08-29 05:04:23 +02:00
|
|
|
#include <otclient/core/map.h>
|
2012-01-30 01:00:12 +01:00
|
|
|
#include <otclient/core/mapview.h>
|
2011-11-03 10:59:11 +01:00
|
|
|
#include <framework/otml/otml.h>
|
|
|
|
#include <framework/graphics/graphics.h>
|
2012-01-07 23:24:29 +01:00
|
|
|
#include <otclient/core/localplayer.h>
|
2011-08-29 05:04:23 +02:00
|
|
|
|
2012-01-20 03:33:11 +01:00
|
|
|
UIMap::UIMap()
|
|
|
|
{
|
|
|
|
m_dragable = true;
|
2012-01-30 01:00:12 +01:00
|
|
|
m_mapView = MapViewPtr(new MapView);
|
|
|
|
g_map.addMapView(m_mapView);
|
|
|
|
m_mapView->followCreature(g_game.getLocalPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
UIMap::~UIMap()
|
|
|
|
{
|
|
|
|
g_map.removeMapView(m_mapView);
|
2012-01-20 03:33:11 +01:00
|
|
|
}
|
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
void UIMap::draw()
|
2011-08-29 05:04:23 +02:00
|
|
|
{
|
2012-01-10 23:13:40 +01:00
|
|
|
drawSelf();
|
2011-08-29 05:04:23 +02:00
|
|
|
|
2012-02-03 05:18:54 +01:00
|
|
|
// draw map border
|
2011-12-07 01:31:55 +01:00
|
|
|
g_painter.setColor(Fw::black);
|
|
|
|
g_painter.drawBoundingRect(m_mapRect.expanded(1));
|
2012-01-30 01:00:12 +01:00
|
|
|
|
|
|
|
m_mapView->draw(m_mapRect);
|
2011-11-03 10:59:11 +01:00
|
|
|
|
2012-01-10 23:13:40 +01:00
|
|
|
drawChildren();
|
2011-08-29 05:04:23 +02:00
|
|
|
}
|
|
|
|
|
2012-01-30 01:00:12 +01:00
|
|
|
void UIMap::zoomIn()
|
|
|
|
{
|
2012-01-31 05:12:54 +01:00
|
|
|
int dimensionHeight = m_mapView->getVisibleDimension().height() * 0.99;
|
|
|
|
if(dimensionHeight == m_mapView->getVisibleDimension().height())
|
|
|
|
dimensionHeight -= 1;
|
|
|
|
if(dimensionHeight % 2 == 0)
|
|
|
|
dimensionHeight -= 1;
|
|
|
|
int dimensionWidth = dimensionHeight * getSize().ratio();
|
|
|
|
if(dimensionWidth % 2 == 0)
|
|
|
|
dimensionWidth -= 1;
|
|
|
|
|
|
|
|
m_mapView->setVisibleDimension(Size(dimensionWidth, dimensionHeight));
|
2012-01-30 01:00:12 +01:00
|
|
|
|
|
|
|
Rect mapRect = getChildrenRect().expanded(-1);
|
|
|
|
Size mapSize = m_mapView->getVisibleSize();
|
|
|
|
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
|
|
|
|
|
|
|
m_mapRect.resize(mapSize);
|
|
|
|
m_mapRect.moveCenter(m_rect.center());
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIMap::zoomOut()
|
|
|
|
{
|
2012-01-31 05:12:54 +01:00
|
|
|
int dimensionHeight = m_mapView->getVisibleDimension().height() * 1.01;
|
|
|
|
if(dimensionHeight == m_mapView->getVisibleDimension().height())
|
|
|
|
dimensionHeight += 1;
|
|
|
|
if(dimensionHeight % 2 == 0)
|
|
|
|
dimensionHeight += 1;
|
|
|
|
int dimensionWidth = dimensionHeight * getSize().ratio();
|
|
|
|
if(dimensionWidth % 2 == 0)
|
|
|
|
dimensionWidth += 1;
|
|
|
|
|
|
|
|
m_mapView->setVisibleDimension(Size(dimensionWidth, dimensionHeight));
|
2012-01-30 01:00:12 +01:00
|
|
|
|
|
|
|
Rect mapRect = getChildrenRect().expanded(-1);
|
|
|
|
Size mapSize = m_mapView->getVisibleSize();
|
|
|
|
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
|
|
|
|
|
|
|
m_mapRect.resize(mapSize);
|
|
|
|
m_mapRect.moveCenter(m_rect.center());
|
|
|
|
}
|
|
|
|
|
2012-01-31 21:50:35 +01:00
|
|
|
void UIMap::setCameraPosition(const Position& pos)
|
|
|
|
{
|
|
|
|
m_mapView->setCameraPosition(pos);
|
|
|
|
}
|
|
|
|
|
2012-01-21 02:01:11 +01:00
|
|
|
TilePtr UIMap::getTile(const Point& mousePos)
|
2011-08-29 05:04:23 +02:00
|
|
|
{
|
2012-01-02 20:01:48 +01:00
|
|
|
if(!m_mapRect.contains(mousePos))
|
2012-01-21 02:01:11 +01:00
|
|
|
return nullptr;
|
2012-01-02 20:01:48 +01:00
|
|
|
|
2012-02-07 02:35:46 +01:00
|
|
|
//TODO: move MapView code to UIMap and rework this shit
|
|
|
|
return m_mapView->getTile(mousePos, m_mapRect);
|
2011-08-29 05:04:23 +02:00
|
|
|
}
|
2011-08-30 17:12:57 +02:00
|
|
|
|
2012-01-05 03:42:17 +01:00
|
|
|
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
2011-08-30 17:12:57 +02:00
|
|
|
{
|
2012-01-10 23:13:40 +01:00
|
|
|
Rect mapRect = getChildrenRect().expanded(-1);
|
2012-01-30 01:00:12 +01:00
|
|
|
Size mapSize = m_mapView->getVisibleSize();
|
2011-08-30 17:12:57 +02:00
|
|
|
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
2011-11-23 05:27:58 +01:00
|
|
|
|
2011-12-07 01:31:55 +01:00
|
|
|
m_mapRect.resize(mapSize);
|
2011-11-03 10:59:11 +01:00
|
|
|
m_mapRect.moveCenter(newRect.center());
|
2011-08-30 17:12:57 +02:00
|
|
|
}
|