mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Fixed generation of upscaled spellbook
This commit is contained in:
		| @@ -35,9 +35,10 @@ void AssetGenerator::createAdventureOptionsCleanBackground() | ||||
| 		return; | ||||
| 	ResourcePath savePath(filename, EResType::IMAGE); | ||||
|  | ||||
| 	auto res = ImagePath::builtin("ADVOPTBK"); | ||||
| 	auto locator = ImageLocator(ImagePath::builtin("ADVOPTBK")); | ||||
| 	locator.scalingFactor = 1; | ||||
|  | ||||
| 	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE); | ||||
| 	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE); | ||||
|  | ||||
| 	Canvas canvas = Canvas(Point(575, 585), CanvasScalingPolicy::IGNORE); | ||||
| 	canvas.draw(img, Point(0, 0), Rect(0, 0, 575, 585)); | ||||
| @@ -64,9 +65,10 @@ void AssetGenerator::createBigSpellBook() | ||||
| 		return; | ||||
| 	ResourcePath savePath(filename, EResType::IMAGE); | ||||
|  | ||||
| 	auto res = ImagePath::builtin("SpelBack"); | ||||
| 	auto locator = ImageLocator(ImagePath::builtin("SpelBack")); | ||||
| 	locator.scalingFactor = 1; | ||||
|  | ||||
| 	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE); | ||||
| 	std::shared_ptr<IImage> img = GH.renderHandler().loadImage(locator, EImageBlitMode::OPAQUE); | ||||
| 	Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::IGNORE); | ||||
| 	// edges | ||||
| 	canvas.draw(img, Point(0, 0), Rect(15, 38, 90, 45)); | ||||
|   | ||||
| @@ -70,6 +70,7 @@ bool ImageLocator::empty() const | ||||
| ImageLocator ImageLocator::copyFile() const | ||||
| { | ||||
| 	ImageLocator result; | ||||
| 	result.scalingFactor = 1; | ||||
| 	result.image = image; | ||||
| 	result.defFile = defFile; | ||||
| 	result.defFrame = defFrame; | ||||
|   | ||||
| @@ -32,7 +32,7 @@ struct ImageLocator | ||||
|  | ||||
| 	bool verticalFlip = false; | ||||
| 	bool horizontalFlip = false; | ||||
| 	int8_t scalingFactor = 1; | ||||
| 	int8_t scalingFactor = 0; // 0 = auto / use default scaling | ||||
| 	EImageLayer layer = EImageLayer::ALL; | ||||
|  | ||||
| 	ImageLocator() = default; | ||||
|   | ||||
| @@ -28,7 +28,6 @@ ImageScaled::ImageScaled(const ImageLocator & inputLocator, const std::shared_pt | ||||
| 	, alphaValue(SDL_ALPHA_OPAQUE) | ||||
| 	, blitMode(mode) | ||||
| { | ||||
| 	locator.scalingFactor = GH.screenHandler().getScalingFactor(); | ||||
| 	setBodyEnabled(true); | ||||
| 	if (mode == EImageBlitMode::ALPHA) | ||||
| 		setShadowEnabled(true); | ||||
|   | ||||
| @@ -136,14 +136,6 @@ int RenderHandler::getScalingFactor() const | ||||
| 	return GH.screenHandler().getScalingFactor(); | ||||
| } | ||||
|  | ||||
| std::shared_ptr<IImage> RenderHandler::createImageReference(const ImageLocator & locator, std::shared_ptr<ISharedImage> input, EImageBlitMode mode) | ||||
| { | ||||
| 	if (getScalingFactor() == 1 || locator.scalingFactor != 1 || locator.empty()) | ||||
| 		return input->createImageReference(mode); | ||||
| 	else | ||||
| 		return std::make_shared<ImageScaled>(locator, input, mode); | ||||
| } | ||||
|  | ||||
| ImageLocator RenderHandler::getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group) | ||||
| { | ||||
| 	const auto & layout = getAnimationLayout(path); | ||||
| @@ -248,23 +240,46 @@ std::shared_ptr<ISharedImage> RenderHandler::scaleImage(const ImageLocator & loc | ||||
|  | ||||
| std::shared_ptr<IImage> RenderHandler::loadImage(const ImageLocator & locator, EImageBlitMode mode) | ||||
| { | ||||
| 	return createImageReference(locator, loadImageImpl(locator), mode); | ||||
| 	if (locator.scalingFactor == 0 && getScalingFactor() != 1 ) | ||||
| 	{ | ||||
| 		auto unscaledLocator = locator; | ||||
| 		auto scaledLocator = locator; | ||||
|  | ||||
| 		unscaledLocator.scalingFactor = 1; | ||||
| 		scaledLocator.scalingFactor = getScalingFactor(); | ||||
| 		auto unscaledImage = loadImageImpl(unscaledLocator); | ||||
|  | ||||
| 		return std::make_shared<ImageScaled>(scaledLocator, unscaledImage, mode); | ||||
| 	} | ||||
|  | ||||
| 	if (locator.scalingFactor == 0) | ||||
| 	{ | ||||
| 		auto scaledLocator = locator; | ||||
| 		scaledLocator.scalingFactor = getScalingFactor(); | ||||
|  | ||||
| 		return loadImageImpl(scaledLocator)->createImageReference(mode); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		return loadImageImpl(locator)->createImageReference(mode); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| std::shared_ptr<IImage> RenderHandler::loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) | ||||
| { | ||||
| 	auto locator = getLocatorForAnimationFrame(path, frame, group); | ||||
| 	ImageLocator locator = getLocatorForAnimationFrame(path, frame, group); | ||||
| 	return loadImage(locator, mode); | ||||
| } | ||||
|  | ||||
| std::shared_ptr<IImage> RenderHandler::loadImage(const ImagePath & path, EImageBlitMode mode) | ||||
| { | ||||
| 	return loadImage(ImageLocator(path), mode); | ||||
| 	ImageLocator locator(path); | ||||
| 	return loadImage(locator, mode); | ||||
| } | ||||
|  | ||||
| std::shared_ptr<IImage> RenderHandler::createImage(SDL_Surface * source) | ||||
| { | ||||
| 	return createImageReference(ImageLocator(), std::make_shared<SDLImageShared>(source), EImageBlitMode::ALPHA); | ||||
| 	return std::make_shared<SDLImageShared>(source)->createImageReference(EImageBlitMode::ALPHA); | ||||
| } | ||||
|  | ||||
| std::shared_ptr<CAnimation> RenderHandler::loadAnimation(const AnimationPath & path, EImageBlitMode mode) | ||||
|   | ||||
| @@ -46,7 +46,6 @@ class RenderHandler : public IRenderHandler | ||||
|  | ||||
| 	int getScalingFactor() const; | ||||
|  | ||||
| 	std::shared_ptr<IImage> createImageReference(const ImageLocator & locator, std::shared_ptr<ISharedImage> input, EImageBlitMode mode); | ||||
| public: | ||||
|  | ||||
| 	// IRenderHandler implementation | ||||
|   | ||||
		Reference in New Issue
	
	Block a user