Переглянути джерело

Basic version of scaling for view world

Ivan Savenko 2 роки тому
батько
коміт
40413ee6be

+ 6 - 2
client/adventureMap/CAdvMapInt.cpp

@@ -1483,7 +1483,6 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, int tileSize)
 			infoBar->activate();
 
 			worldViewOptions.clear();
-			terrain->setTileSize(32);
 
 			break;
 		case EAdvMapMode::WORLD_VIEW:
@@ -1496,12 +1495,17 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, int tileSize)
 			heroList->deactivate();
 			infoBar->showSelection(); // to prevent new day animation interfering world view mode
 			infoBar->deactivate();
-			terrain->setTileSize(tileSize);
+
 
 			break;
 		}
 		redraw();
 	}
+
+	if(mode == EAdvMapMode::NORMAL)
+		terrain->setTileSize(32);
+	if(mode == EAdvMapMode::WORLD_VIEW)
+		terrain->setTileSize(tileSize);
 }
 
 CAdvMapInt::WorldViewOptions::WorldViewOptions()

+ 11 - 2
client/adventureMap/MapView.cpp

@@ -33,6 +33,7 @@ MapViewCache::~MapViewCache() = default;
 MapViewCache::MapViewCache(const std::shared_ptr<MapViewModel> & model)
 	: model(model)
 	, mapRenderer(new MapRenderer())
+	, intermediate(new Canvas(Point(32,32)))
 	, terrain(new Canvas(model->getCacheDimensionsPixels()))
 {
 }
@@ -46,7 +47,15 @@ void MapViewCache::updateTile(const std::shared_ptr<MapRendererContext> & contex
 {
 	Canvas target = getTile(coordinates);
 
-	mapRenderer->renderTile(*context, target, coordinates);
+	if(model->getSingleTileSize() == Point(32, 32))
+	{
+		mapRenderer->renderTile(*context, target, coordinates);
+	}
+	else
+	{
+		mapRenderer->renderTile(*context, *intermediate, coordinates);
+		target.drawScaled(*intermediate, Point(0, 0), model->getSingleTileSize());
+	}
 }
 
 void MapViewCache::update(const std::shared_ptr<MapRendererContext> & context)
@@ -541,7 +550,7 @@ void MapViewController::update(uint32_t timeDelta)
 	}
 
 	context->animationTime += timeDelta;
-	context->tileSize = model->getSingleTileSize();
+	context->tileSize = Point(32,32); //model->getSingleTileSize();
 }
 
 void MapViewController::onObjectFadeIn(const CGObjectInstance * obj)

+ 3 - 1
client/adventureMap/MapView.h

@@ -124,11 +124,13 @@ public:
 class MapViewCache
 {
 	std::shared_ptr<MapViewModel> model;
-	std::shared_ptr<IImage> mapTransition; //TODO
 
 	std::unique_ptr<Canvas> terrain;
+	std::unique_ptr<Canvas> terrainTransition;
+	std::unique_ptr<Canvas> intermediate;
 	std::unique_ptr<MapRenderer> mapRenderer;
 
+
 	Canvas getTile(const int3 & coordinates);
 	void updateTile(const std::shared_ptr<MapRendererContext> & context, const int3 & coordinates);
 

+ 0 - 17
client/adventureMap/mapHandler.cpp

@@ -11,32 +11,15 @@
 #include "StdInc.h"
 #include "mapHandler.h"
 #include "MapRendererContext.h"
-#include "MapView.h"
 
-#include "../render/CAnimation.h"
-#include "../render/Colors.h"
-#include "../gui/CGuiHandler.h"
-#include "../renderSDL/SDL_Extensions.h"
 #include "../CGameInfo.h"
-#include "../render/Graphics.h"
-#include "../render/IImage.h"
-#include "../render/Canvas.h"
-#include "../CMusicHandler.h"
 #include "../CPlayerInterface.h"
 
-#include "../../CCallback.h"
-
 #include "../../lib/UnlockGuard.h"
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CObjectClassesHandler.h"
 #include "../../lib/mapping/CMap.h"
-#include "../../lib/Color.h"
-#include "../../lib/CConfigHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
-#include "../../lib/CStopWatch.h"
-#include "../../lib/CRandomGenerator.h"
-#include "../../lib/RoadHandler.h"
-#include "../../lib/RiverHandler.h"
 #include "../../lib/TerrainHandler.h"
 
 /*

+ 10 - 2
client/render/Canvas.cpp

@@ -40,6 +40,7 @@ Canvas::Canvas(const Point & size):
 	renderArea(Point(0,0), size),
 	surface(CSDL_Ext::newSurface(size.x, size.y))
 {
+	SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
 }
 
 Canvas::~Canvas()
@@ -66,10 +67,17 @@ void Canvas::draw(const Canvas & image, const Point & pos)
 	CSDL_Ext::blitSurface(image.surface, image.renderArea, surface, renderArea.topLeft() + pos);
 }
 
+void Canvas::drawTransparent(const Canvas & image, const Point & pos, double transparency)
+{
+	SDL_SetSurfaceAlphaMod(image.surface, 255 * transparency);
+	CSDL_Ext::blitSurface(image.surface, image.renderArea, surface, renderArea.topLeft() + pos);
+	SDL_SetSurfaceAlphaMod(image.surface, 255);
+}
+
 void Canvas::drawScaled(const Canvas & image, const Point & pos, const Point & targetSize)
 {
-	SDL_Rect targetRect = CSDL_Ext::toSDL(Rect(pos, targetSize));
-	SDL_BlitScaled(image.surface, nullptr, surface, &targetRect );
+	SDL_Rect targetRect = CSDL_Ext::toSDL(Rect(pos + renderArea.topLeft(), targetSize));
+	SDL_BlitScaled(image.surface, nullptr, surface, &targetRect);
 }
 
 void Canvas::drawPoint(const Point & dest, const ColorRGBA & color)

+ 4 - 1
client/render/Canvas.h

@@ -27,8 +27,8 @@ class Canvas
 	/// Current rendering area, all rendering operations will be moved into selected area
 	Rect renderArea;
 
-	Canvas & operator = (const Canvas & other) = delete;
 public:
+	Canvas & operator = (const Canvas & other) = delete;
 
 	/// constructs canvas using existing surface. Caller maintains ownership on the surface
 	explicit Canvas(SDL_Surface * surface);
@@ -53,6 +53,9 @@ public:
 	/// renders another canvas onto this canvas
 	void draw(const Canvas &image, const Point & pos);
 
+	/// renders another canvas onto this canvas with transparency
+	void drawTransparent(const Canvas & image, const Point & pos, double transparency);
+
 	/// renders another canvas onto this canvas with scaling
 	void drawScaled(const Canvas &image, const Point & pos, const Point & targetSize);