fix aspect ratio, clicking, TODO: add setVisibleSize event, for uimap resizing

This commit is contained in:
Henrique 2011-11-23 02:27:58 -02:00
parent 6a33473a1a
commit 9208bf7b5a
3 changed files with 23 additions and 4 deletions

View File

@ -31,10 +31,15 @@
Map g_map;
Map::Map()
{
setVisibleSize(Size(MAP_VISIBLE_WIDTH, MAP_VISIBLE_HEIGHT) + Size(8, 2));
}
void Map::draw(const Rect& rect)
{
if(!m_framebuffer)
setVisibleSize(Size(MAP_VISIBLE_WIDTH, MAP_VISIBLE_HEIGHT));
m_framebuffer = FrameBufferPtr(new FrameBuffer(m_visibleSize.width() * NUM_TILE_PIXELS, m_visibleSize.height() * NUM_TILE_PIXELS));
g_graphics.bindColor(Fw::white);
m_framebuffer->bind();
@ -290,7 +295,8 @@ void Map::setVisibleSize(const Size& visibleSize)
m_centralOffset = Point(std::ceil(m_visibleSize.width() / 2.0), std::ceil(m_visibleSize.height() / 2.0));
m_size = m_visibleSize + Size(3, 3);
m_framebuffer = FrameBufferPtr(new FrameBuffer(m_visibleSize.width() * NUM_TILE_PIXELS, m_visibleSize.height() * NUM_TILE_PIXELS));
if(m_framebuffer)
m_framebuffer = FrameBufferPtr(new FrameBuffer(m_visibleSize.width() * NUM_TILE_PIXELS, m_visibleSize.height() * NUM_TILE_PIXELS));
}
Point Map::positionTo2D(const Position& position)

View File

@ -39,6 +39,8 @@ public:
NUM_TILE_PIXELS = 32
};
Map();
void draw(const Rect& rect);
void clean();
@ -65,6 +67,7 @@ public:
void removeCreatureById(uint32 id);
void setVisibleSize(const Size& visibleSize);
Size getVibibleSize() { return m_visibleSize; }
Point getCentralOffset() { return m_centralOffset; }
Point positionTo2D(const Position& position);

View File

@ -56,7 +56,7 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
if(m_mapRect.contains(mousePos)) {
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
Size mapSize(Map::MAP_VISIBLE_WIDTH * Map::NUM_TILE_PIXELS, Map::MAP_VISIBLE_HEIGHT * Map::NUM_TILE_PIXELS);
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor;
@ -75,8 +75,18 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
void UIMap::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
{
Rect mapRect = newRect.expanded(-m_mapMargin-1);
Size mapSize(Map::MAP_VISIBLE_WIDTH * Map::NUM_TILE_PIXELS, Map::MAP_VISIBLE_HEIGHT * Map::NUM_TILE_PIXELS);
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
/*bool useHeight = ((float)mapRect.width() / mapRect.height() < (float)mapSize.width() / mapSize.height());
if(useHeight) {
mapRect.setWidth(mapRect.height() * ((float)mapSize.width() / mapSize.height()));
}
else {
mapRect.setHeight(mapRect.width() * ((float)mapSize.width() / mapSize.height()));
}*/
m_mapRect.setSize(mapSize);
m_mapRect.moveCenter(newRect.center());
}