mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Changes to Canvas class according to review:
- renamed CCanvas -> Canvas.cpp - replaced shared_ptr<Canvas> with Canvas& - removed getSurface method
This commit is contained in:
parent
c855823528
commit
7f5e5259c8
@ -17,7 +17,7 @@ set(client_SRCS
|
|||||||
battle/CreatureAnimation.cpp
|
battle/CreatureAnimation.cpp
|
||||||
|
|
||||||
gui/CAnimation.cpp
|
gui/CAnimation.cpp
|
||||||
gui/CCanvas.cpp
|
gui/Canvas.cpp
|
||||||
gui/CCursorHandler.cpp
|
gui/CCursorHandler.cpp
|
||||||
gui/CGuiHandler.cpp
|
gui/CGuiHandler.cpp
|
||||||
gui/CIntObject.cpp
|
gui/CIntObject.cpp
|
||||||
@ -100,7 +100,7 @@ set(client_HEADERS
|
|||||||
battle/CreatureAnimation.h
|
battle/CreatureAnimation.h
|
||||||
|
|
||||||
gui/CAnimation.h
|
gui/CAnimation.h
|
||||||
gui/CCanvas.h
|
gui/Canvas.h
|
||||||
gui/CCursorHandler.h
|
gui/CCursorHandler.h
|
||||||
gui/CGuiHandler.h
|
gui/CGuiHandler.h
|
||||||
gui/CIntObject.h
|
gui/CIntObject.h
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
|
|
||||||
#include "../../CCallback.h"
|
#include "../../CCallback.h"
|
||||||
#include "../../lib/battle/BattleAction.h"
|
#include "../../lib/battle/BattleAction.h"
|
||||||
@ -134,7 +134,7 @@ void BattleEffectsController::collectRenderableObjects(BattleRenderer & renderer
|
|||||||
|
|
||||||
auto img = elem.animation->getImage(currentFrame);
|
auto img = elem.animation->getImage(currentFrame);
|
||||||
|
|
||||||
canvas->draw(img, Point(elem.x, elem.y));
|
canvas.draw(img, Point(elem.x, elem.y));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
|
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
class CAnimation;
|
class CAnimation;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
class BattleRenderer;
|
class BattleRenderer;
|
||||||
class CPointEffectAnimation;
|
class CPointEffectAnimation;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/CCursorHandler.h"
|
#include "../gui/CCursorHandler.h"
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ BattleFieldController::BattleFieldController(BattleInterface * owner):
|
|||||||
}
|
}
|
||||||
|
|
||||||
//preparing graphic with cell borders
|
//preparing graphic with cell borders
|
||||||
cellBorders = std::make_shared<CCanvas>(Point(background->width(), background->height()));
|
cellBorders = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
||||||
|
|
||||||
for (int i=0; i<GameConstants::BFIELD_SIZE; ++i)
|
for (int i=0; i<GameConstants::BFIELD_SIZE; ++i)
|
||||||
{
|
{
|
||||||
@ -73,7 +73,7 @@ BattleFieldController::BattleFieldController(BattleInterface * owner):
|
|||||||
cellBorders->draw(cellBorder, hexPositionLocal(i).topLeft());
|
cellBorders->draw(cellBorder, hexPositionLocal(i).topLeft());
|
||||||
}
|
}
|
||||||
|
|
||||||
backgroundWithHexes = std::make_shared<CCanvas>(Point(background->width(), background->height()));
|
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
||||||
|
|
||||||
for (int h = 0; h < GameConstants::BFIELD_SIZE; ++h)
|
for (int h = 0; h < GameConstants::BFIELD_SIZE; ++h)
|
||||||
{
|
{
|
||||||
@ -89,7 +89,7 @@ BattleFieldController::BattleFieldController(BattleInterface * owner):
|
|||||||
stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE);
|
stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::renderBattlefield(std::shared_ptr<CCanvas> canvas)
|
void BattleFieldController::renderBattlefield(Canvas & canvas)
|
||||||
{
|
{
|
||||||
showBackground(canvas);
|
showBackground(canvas);
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ void BattleFieldController::renderBattlefield(std::shared_ptr<CCanvas> canvas)
|
|||||||
owner->projectilesController->showProjectiles(canvas);
|
owner->projectilesController->showProjectiles(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::showBackground(std::shared_ptr<CCanvas> canvas)
|
void BattleFieldController::showBackground(Canvas & canvas)
|
||||||
{
|
{
|
||||||
if (owner->stacksController->getActiveStack() != nullptr ) //&& creAnims[stacksController->getActiveStack()->ID]->isIdle() //show everything with range
|
if (owner->stacksController->getActiveStack() != nullptr ) //&& creAnims[stacksController->getActiveStack()->ID]->isIdle() //show everything with range
|
||||||
showBackgroundImageWithHexes(canvas);
|
showBackgroundImageWithHexes(canvas);
|
||||||
@ -111,21 +111,21 @@ void BattleFieldController::showBackground(std::shared_ptr<CCanvas> canvas)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::showBackgroundImage(std::shared_ptr<CCanvas> canvas)
|
void BattleFieldController::showBackgroundImage(Canvas & canvas)
|
||||||
{
|
{
|
||||||
canvas->draw(background, owner->pos.topLeft());
|
canvas.draw(background, owner->pos.topLeft());
|
||||||
|
|
||||||
owner->obstacleController->showAbsoluteObstacles(canvas, pos.topLeft());
|
owner->obstacleController->showAbsoluteObstacles(canvas, pos.topLeft());
|
||||||
if ( owner->siegeController )
|
if ( owner->siegeController )
|
||||||
owner->siegeController->showAbsoluteObstacles(canvas, pos.topLeft());
|
owner->siegeController->showAbsoluteObstacles(canvas, pos.topLeft());
|
||||||
|
|
||||||
if (settings["battle"]["cellBorders"].Bool())
|
if (settings["battle"]["cellBorders"].Bool())
|
||||||
canvas->draw(cellBorders, owner->pos.topLeft());
|
canvas.draw(*cellBorders, owner->pos.topLeft());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::showBackgroundImageWithHexes(std::shared_ptr<CCanvas> canvas)
|
void BattleFieldController::showBackgroundImageWithHexes(Canvas & canvas)
|
||||||
{
|
{
|
||||||
canvas->draw(backgroundWithHexes, owner->pos.topLeft());
|
canvas.draw(*backgroundWithHexes.get(), owner->pos.topLeft());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::redrawBackgroundWithHexes()
|
void BattleFieldController::redrawBackgroundWithHexes()
|
||||||
@ -142,9 +142,9 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
|||||||
|
|
||||||
//prepare background graphic with hexes and shaded hexes
|
//prepare background graphic with hexes and shaded hexes
|
||||||
backgroundWithHexes->draw(background, Point(0,0));
|
backgroundWithHexes->draw(background, Point(0,0));
|
||||||
owner->obstacleController->showAbsoluteObstacles(backgroundWithHexes, Point(0,0));
|
owner->obstacleController->showAbsoluteObstacles(*backgroundWithHexes, Point(0,0));
|
||||||
if ( owner->siegeController )
|
if ( owner->siegeController )
|
||||||
owner->siegeController->showAbsoluteObstacles(backgroundWithHexes, Point(0,0));
|
owner->siegeController->showAbsoluteObstacles(*backgroundWithHexes, Point(0,0));
|
||||||
|
|
||||||
if (settings["battle"]["stackRange"].Bool())
|
if (settings["battle"]["stackRange"].Bool())
|
||||||
{
|
{
|
||||||
@ -157,16 +157,16 @@ void BattleFieldController::redrawBackgroundWithHexes()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(settings["battle"]["cellBorders"].Bool())
|
if(settings["battle"]["cellBorders"].Bool())
|
||||||
backgroundWithHexes->draw(cellBorders, Point(0, 0));
|
backgroundWithHexes->draw(*cellBorders, Point(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::showHighlightedHex(std::shared_ptr<CCanvas> to, BattleHex hex, bool darkBorder)
|
void BattleFieldController::showHighlightedHex(Canvas & canvas, BattleHex hex, bool darkBorder)
|
||||||
{
|
{
|
||||||
Point hexPos = hexPosition(hex).topLeft();
|
Point hexPos = hexPosition(hex).topLeft();
|
||||||
|
|
||||||
to->draw(cellShade, hexPos);
|
canvas.draw(cellShade, hexPos);
|
||||||
if(!darkBorder && settings["battle"]["cellBorders"].Bool())
|
if(!darkBorder && settings["battle"]["cellBorders"].Bool())
|
||||||
to->draw(cellBorder, hexPos);
|
canvas.draw(cellBorder, hexPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<BattleHex> BattleFieldController::getHighlightedHexesStackRange()
|
std::set<BattleHex> BattleFieldController::getHighlightedHexesStackRange()
|
||||||
@ -242,7 +242,7 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesSpellRange()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleFieldController::showHighlightedHexes(std::shared_ptr<CCanvas> canvas)
|
void BattleFieldController::showHighlightedHexes(Canvas & canvas)
|
||||||
{
|
{
|
||||||
std::set<BattleHex> hoveredStack = getHighlightedHexesStackRange();
|
std::set<BattleHex> hoveredStack = getHighlightedHexesStackRange();
|
||||||
std::set<BattleHex> hoveredMouse = getHighlightedHexesSpellRange();
|
std::set<BattleHex> hoveredMouse = getHighlightedHexesSpellRange();
|
||||||
|
@ -23,7 +23,7 @@ struct Rect;
|
|||||||
struct Point;
|
struct Point;
|
||||||
|
|
||||||
class ClickableHex;
|
class ClickableHex;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class IImage;
|
class IImage;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
|
|
||||||
@ -35,10 +35,10 @@ class BattleFieldController : public CIntObject
|
|||||||
std::shared_ptr<IImage> cellBorder;
|
std::shared_ptr<IImage> cellBorder;
|
||||||
std::shared_ptr<IImage> cellShade;
|
std::shared_ptr<IImage> cellShade;
|
||||||
|
|
||||||
std::shared_ptr<CCanvas> cellBorders;
|
std::unique_ptr<Canvas> cellBorders;
|
||||||
|
|
||||||
/// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
|
/// Canvas that contains background, hex grid (if enabled), absolute obstacles and movement range of active stack
|
||||||
std::shared_ptr<CCanvas> backgroundWithHexes;
|
std::unique_ptr<Canvas> backgroundWithHexes;
|
||||||
|
|
||||||
//BattleHex previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
|
//BattleHex previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
|
||||||
//BattleHex currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
|
//BattleHex currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
|
||||||
@ -49,21 +49,21 @@ class BattleFieldController : public CIntObject
|
|||||||
|
|
||||||
std::vector<std::shared_ptr<ClickableHex>> bfield; //11 lines, 17 hexes on each
|
std::vector<std::shared_ptr<ClickableHex>> bfield; //11 lines, 17 hexes on each
|
||||||
|
|
||||||
void showHighlightedHex(std::shared_ptr<CCanvas> to, BattleHex hex, bool darkBorder);
|
void showHighlightedHex(Canvas & to, BattleHex hex, bool darkBorder);
|
||||||
|
|
||||||
std::set<BattleHex> getHighlightedHexesStackRange();
|
std::set<BattleHex> getHighlightedHexesStackRange();
|
||||||
std::set<BattleHex> getHighlightedHexesSpellRange();
|
std::set<BattleHex> getHighlightedHexesSpellRange();
|
||||||
|
|
||||||
void showBackground(std::shared_ptr<CCanvas> canvas);
|
void showBackground(Canvas & canvas);
|
||||||
void showBackgroundImage(std::shared_ptr<CCanvas> canvas);
|
void showBackgroundImage(Canvas & canvas);
|
||||||
void showBackgroundImageWithHexes(std::shared_ptr<CCanvas> canvas);
|
void showBackgroundImageWithHexes(Canvas & canvas);
|
||||||
void showHighlightedHexes(std::shared_ptr<CCanvas> canvas);
|
void showHighlightedHexes(Canvas & canvas);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BattleFieldController(BattleInterface * owner);
|
BattleFieldController(BattleInterface * owner);
|
||||||
|
|
||||||
void redrawBackgroundWithHexes();
|
void redrawBackgroundWithHexes();
|
||||||
void renderBattlefield(std::shared_ptr<CCanvas> canvas);
|
void renderBattlefield(Canvas & canvas);
|
||||||
|
|
||||||
Rect hexPositionLocal(BattleHex hex) const;
|
Rect hexPositionLocal(BattleHex hex) const;
|
||||||
Rect hexPosition(BattleHex hex) const;
|
Rect hexPosition(BattleHex hex) const;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "../CMessage.h"
|
#include "../CMessage.h"
|
||||||
#include "../CMusicHandler.h"
|
#include "../CMusicHandler.h"
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
#include "../gui/CCursorHandler.h"
|
#include "../gui/CCursorHandler.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../windows/CAdvmapInterface.h"
|
#include "../windows/CAdvmapInterface.h"
|
||||||
@ -891,7 +891,7 @@ void BattleInterface::showAll(SDL_Surface *to)
|
|||||||
|
|
||||||
void BattleInterface::show(SDL_Surface *to)
|
void BattleInterface::show(SDL_Surface *to)
|
||||||
{
|
{
|
||||||
auto canvas = std::make_shared<CCanvas>(to);
|
Canvas canvas(to);
|
||||||
assert(to);
|
assert(to);
|
||||||
|
|
||||||
SDL_Rect buf;
|
SDL_Rect buf;
|
||||||
@ -907,7 +907,7 @@ void BattleInterface::show(SDL_Surface *to)
|
|||||||
|
|
||||||
SDL_SetClipRect(to, &buf); //restoring previous clip_rect
|
SDL_SetClipRect(to, &buf); //restoring previous clip_rect
|
||||||
|
|
||||||
showInterface(canvas);
|
showInterface(to);
|
||||||
|
|
||||||
//activation of next stack, if any
|
//activation of next stack, if any
|
||||||
//TODO: should be moved to the very start of this method?
|
//TODO: should be moved to the very start of this method?
|
||||||
@ -920,23 +920,23 @@ void BattleInterface::collectRenderableObjects(BattleRenderer & renderer)
|
|||||||
{
|
{
|
||||||
renderer.insert(EBattleFieldLayer::HEROES, BattleHex(0),[this](BattleRenderer::RendererPtr canvas)
|
renderer.insert(EBattleFieldLayer::HEROES, BattleHex(0),[this](BattleRenderer::RendererPtr canvas)
|
||||||
{
|
{
|
||||||
attackingHero->show(canvas->getSurface());
|
attackingHero->render(canvas);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (defendingHero)
|
if (defendingHero)
|
||||||
{
|
{
|
||||||
renderer.insert(EBattleFieldLayer::HEROES, BattleHex(GameConstants::BFIELD_WIDTH-1),[this](BattleRenderer::RendererPtr canvas)
|
renderer.insert(EBattleFieldLayer::HEROES, BattleHex(GameConstants::BFIELD_WIDTH-1),[this](BattleRenderer::RendererPtr canvas)
|
||||||
{
|
{
|
||||||
defendingHero->show(canvas->getSurface());
|
defendingHero->render(canvas);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleInterface::showInterface(std::shared_ptr<CCanvas> canvas)
|
void BattleInterface::showInterface(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
//showing in-game console
|
//showing in-game console
|
||||||
LOCPLINT->cingconsole->show(canvas->getSurface());
|
LOCPLINT->cingconsole->show(to);
|
||||||
controlPanel->showAll(canvas->getSurface());
|
controlPanel->showAll(to);
|
||||||
|
|
||||||
Rect posWithQueue = Rect(pos.x, pos.y, 800, 600);
|
Rect posWithQueue = Rect(pos.x, pos.y, 800, 600);
|
||||||
|
|
||||||
@ -948,13 +948,13 @@ void BattleInterface::showInterface(std::shared_ptr<CCanvas> canvas)
|
|||||||
posWithQueue.h += queue->pos.h;
|
posWithQueue.h += queue->pos.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue->showAll(canvas->getSurface());
|
queue->showAll(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printing border around interface
|
//printing border around interface
|
||||||
if (screen->w != 800 || screen->h !=600)
|
if (screen->w != 800 || screen->h !=600)
|
||||||
{
|
{
|
||||||
CMessage::drawBorder(curInt->playerID,canvas->getSurface(),posWithQueue.w + 28, posWithQueue.h + 28, posWithQueue.x-14, posWithQueue.y-15);
|
CMessage::drawBorder(curInt->playerID,to,posWithQueue.w + 28, posWithQueue.h + 28, posWithQueue.x-14, posWithQueue.y-15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ struct CustomEffectInfo;
|
|||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
class BattleHero;
|
class BattleHero;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class BattleResultWindow;
|
class BattleResultWindow;
|
||||||
class StackQueue;
|
class StackQueue;
|
||||||
class CPlayerInterface;
|
class CPlayerInterface;
|
||||||
@ -98,7 +98,7 @@ private:
|
|||||||
|
|
||||||
const CGHeroInstance *getActiveHero(); //returns hero that can currently cast a spell
|
const CGHeroInstance *getActiveHero(); //returns hero that can currently cast a spell
|
||||||
|
|
||||||
void showInterface(std::shared_ptr<CCanvas> canvas);
|
void showInterface(SDL_Surface * to);
|
||||||
|
|
||||||
void setHeroAnimation(ui8 side, int phase);
|
void setHeroAnimation(ui8 side, int phase);
|
||||||
public:
|
public:
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "../CVideoHandler.h"
|
#include "../CVideoHandler.h"
|
||||||
#include "../Graphics.h"
|
#include "../Graphics.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
|
#include "../gui/Canvas.h"
|
||||||
#include "../gui/CCursorHandler.h"
|
#include "../gui/CCursorHandler.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../widgets/Buttons.h"
|
#include "../widgets/Buttons.h"
|
||||||
@ -126,7 +127,7 @@ void BattleConsole::lock(bool shouldLock)
|
|||||||
// no-op?
|
// no-op?
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleHero::show(SDL_Surface * to)
|
void BattleHero::render(Canvas & canvas)
|
||||||
{
|
{
|
||||||
auto flagFrame = flagAnimation->getImage(flagAnim, 0, true);
|
auto flagFrame = flagAnimation->getImage(flagAnim, 0, true);
|
||||||
|
|
||||||
@ -134,35 +135,18 @@ void BattleHero::show(SDL_Surface * to)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//animation of flag
|
//animation of flag
|
||||||
SDL_Rect temp_rect;
|
Point flagPosition = pos.topLeft();
|
||||||
|
|
||||||
if(flip)
|
if(flip)
|
||||||
{
|
flagPosition += Point(61, 39);
|
||||||
temp_rect = genRect(
|
|
||||||
flagFrame->height(),
|
|
||||||
flagFrame->width(),
|
|
||||||
pos.x + 61,
|
|
||||||
pos.y + 39);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
flagPosition += Point(72, 39);
|
||||||
temp_rect = genRect(
|
|
||||||
flagFrame->height(),
|
|
||||||
flagFrame->width(),
|
|
||||||
pos.x + 72,
|
|
||||||
pos.y + 39);
|
|
||||||
}
|
|
||||||
|
|
||||||
flagFrame->draw(screen, &temp_rect, nullptr); //FIXME: why screen?
|
|
||||||
|
|
||||||
//animation of hero
|
|
||||||
SDL_Rect rect = pos;
|
|
||||||
|
|
||||||
auto heroFrame = animation->getImage(currentFrame, phase, true);
|
auto heroFrame = animation->getImage(currentFrame, phase, true);
|
||||||
if(!heroFrame)
|
|
||||||
return;
|
|
||||||
|
|
||||||
heroFrame->draw(to, &rect, nullptr);
|
canvas.draw(flagFrame, flagPosition);
|
||||||
|
canvas.draw(heroFrame, pos.topLeft());
|
||||||
|
|
||||||
if(++animCount >= 4)
|
if(++animCount >= 4)
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
class CGHeroInstance;
|
class CGHeroInstance;
|
||||||
struct BattleResult;
|
struct BattleResult;
|
||||||
class CStack;
|
class CStack;
|
||||||
|
class Canvas;
|
||||||
|
|
||||||
namespace battle
|
namespace battle
|
||||||
{
|
{
|
||||||
@ -79,7 +80,7 @@ public:
|
|||||||
|
|
||||||
size_t flagAnim;
|
size_t flagAnim;
|
||||||
ui8 animCount; //for flag animation
|
ui8 animCount; //for flag animation
|
||||||
void show(SDL_Surface * to) override; //prints next frame of animation to to
|
void render(Canvas & canvas); //prints next frame of animation to to
|
||||||
void setPhase(int newPhase); //sets phase of hero animation
|
void setPhase(int newPhase); //sets phase of hero animation
|
||||||
void hover(bool on) override;
|
void hover(bool on) override;
|
||||||
void clickLeft(tribool down, bool previousState) override; //call-in
|
void clickLeft(tribool down, bool previousState) override; //call-in
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
|
|
||||||
#include "../../CCallback.h"
|
#include "../../CCallback.h"
|
||||||
#include "../../lib/battle/CObstacleInstance.h"
|
#include "../../lib/battle/CObstacleInstance.h"
|
||||||
@ -113,7 +113,7 @@ void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleObstacleController::showAbsoluteObstacles(std::shared_ptr<CCanvas> canvas, const Point & offset)
|
void BattleObstacleController::showAbsoluteObstacles(Canvas & canvas, const Point & offset)
|
||||||
{
|
{
|
||||||
//Blit absolute obstacles
|
//Blit absolute obstacles
|
||||||
for(auto & oi : owner->curInt->cb->battleGetAllObstacles())
|
for(auto & oi : owner->curInt->cb->battleGetAllObstacles())
|
||||||
@ -122,7 +122,7 @@ void BattleObstacleController::showAbsoluteObstacles(std::shared_ptr<CCanvas> ca
|
|||||||
{
|
{
|
||||||
auto img = getObstacleImage(*oi);
|
auto img = getObstacleImage(*oi);
|
||||||
if(img)
|
if(img)
|
||||||
canvas->draw(img, Point(offset.x + oi->getInfo().width, offset.y + oi->getInfo().height));
|
canvas.draw(img, Point(offset.x + oi->getInfo().width, offset.y + oi->getInfo().height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ void BattleObstacleController::collectRenderableObjects(BattleRenderer & rendere
|
|||||||
if(img)
|
if(img)
|
||||||
{
|
{
|
||||||
Point p = getObstaclePosition(img, *obstacle);
|
Point p = getObstaclePosition(img, *obstacle);
|
||||||
canvas->draw(img, p);
|
canvas.draw(img, p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
|
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
class IImage;
|
class IImage;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class CAnimation;
|
class CAnimation;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
class BattleRenderer;
|
class BattleRenderer;
|
||||||
@ -46,7 +46,7 @@ public:
|
|||||||
|
|
||||||
void obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & oi);
|
void obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & oi);
|
||||||
void showObstacles(SDL_Surface *to, std::vector<std::shared_ptr<const CObstacleInstance>> &obstacles);
|
void showObstacles(SDL_Surface *to, std::vector<std::shared_ptr<const CObstacleInstance>> &obstacles);
|
||||||
void showAbsoluteObstacles(std::shared_ptr<CCanvas> canvas, const Point & offset);
|
void showAbsoluteObstacles(Canvas & canvas, const Point & offset);
|
||||||
|
|
||||||
void collectRenderableObjects(BattleRenderer & renderer);
|
void collectRenderableObjects(BattleRenderer & renderer);
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "../gui/Geometries.h"
|
#include "../gui/Geometries.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ static double calculateCatapultParabolaY(const Point & from, const Point & dest,
|
|||||||
return facA *pow(x, 2.0) + facB *x + facC;
|
return facA *pow(x, 2.0) + facB *x + facC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectileMissile::show(std::shared_ptr<CCanvas> canvas)
|
void ProjectileMissile::show(Canvas & canvas)
|
||||||
{
|
{
|
||||||
logAnim->info("Projectile rendering, %d / %d", step, steps);
|
logAnim->info("Projectile rendering, %d / %d", step, steps);
|
||||||
size_t group = reverse ? 1 : 0;
|
size_t group = reverse ? 1 : 0;
|
||||||
@ -61,12 +61,12 @@ void ProjectileMissile::show(std::shared_ptr<CCanvas> canvas)
|
|||||||
CSDL_Ext::lerp(from.y, dest.y, progress) - image->height() / 2,
|
CSDL_Ext::lerp(from.y, dest.y, progress) - image->height() / 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
canvas->draw(image, pos);
|
canvas.draw(image, pos);
|
||||||
}
|
}
|
||||||
++step;
|
++step;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectileAnimatedMissile::show(std::shared_ptr<CCanvas> canvas)
|
void ProjectileAnimatedMissile::show(Canvas & canvas)
|
||||||
{
|
{
|
||||||
ProjectileMissile::show(canvas);
|
ProjectileMissile::show(canvas);
|
||||||
frameProgress += AnimationControls::getSpellEffectSpeed() * GH.mainFPSmng->getElapsedMilliseconds() / 1000;
|
frameProgress += AnimationControls::getSpellEffectSpeed() * GH.mainFPSmng->getElapsedMilliseconds() / 1000;
|
||||||
@ -77,7 +77,7 @@ void ProjectileAnimatedMissile::show(std::shared_ptr<CCanvas> canvas)
|
|||||||
frameNum = std::floor(frameProgress);
|
frameNum = std::floor(frameProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectileCatapult::show(std::shared_ptr<CCanvas> canvas)
|
void ProjectileCatapult::show(Canvas & canvas)
|
||||||
{
|
{
|
||||||
auto image = animation->getImage(frameNum, 0, true);
|
auto image = animation->getImage(frameNum, 0, true);
|
||||||
|
|
||||||
@ -89,14 +89,14 @@ void ProjectileCatapult::show(std::shared_ptr<CCanvas> canvas)
|
|||||||
int posY = calculateCatapultParabolaY(from, dest, posX);
|
int posY = calculateCatapultParabolaY(from, dest, posX);
|
||||||
Point pos(posX, posY);
|
Point pos(posX, posY);
|
||||||
|
|
||||||
canvas->draw(image, pos);
|
canvas.draw(image, pos);
|
||||||
|
|
||||||
frameNum = (frameNum + 1) % animation->size(0);
|
frameNum = (frameNum + 1) % animation->size(0);
|
||||||
}
|
}
|
||||||
++step;
|
++step;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectileRay::show(std::shared_ptr<CCanvas> canvas)
|
void ProjectileRay::show(Canvas & canvas)
|
||||||
{
|
{
|
||||||
float progress = float(step) / steps;
|
float progress = float(step) / steps;
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ void ProjectileRay::show(std::shared_ptr<CCanvas> canvas)
|
|||||||
SDL_Color beginColor{ ray.r1, ray.g1, ray.b1, ray.a1};
|
SDL_Color beginColor{ ray.r1, ray.g1, ray.b1, ray.a1};
|
||||||
SDL_Color endColor { ray.r2, ray.g2, ray.b2, ray.a2};
|
SDL_Color endColor { ray.r2, ray.g2, ray.b2, ray.a2};
|
||||||
|
|
||||||
canvas->drawLine(Point(x1, y1 + i), Point(x2, y2+i), beginColor, endColor);
|
canvas.drawLine(Point(x1, y1 + i), Point(x2, y2+i), beginColor, endColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // draw in vertical axis
|
else // draw in vertical axis
|
||||||
@ -140,7 +140,7 @@ void ProjectileRay::show(std::shared_ptr<CCanvas> canvas)
|
|||||||
SDL_Color beginColor{ ray.r1, ray.g1, ray.b1, ray.a1};
|
SDL_Color beginColor{ ray.r1, ray.g1, ray.b1, ray.a1};
|
||||||
SDL_Color endColor { ray.r2, ray.g2, ray.b2, ray.a2};
|
SDL_Color endColor { ray.r2, ray.g2, ray.b2, ray.a2};
|
||||||
|
|
||||||
canvas->drawLine(Point(x1 + i, y1), Point(x2 + i, y2), beginColor, endColor);
|
canvas.drawLine(Point(x1 + i, y1), Point(x2 + i, y2), beginColor, endColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++step;
|
++step;
|
||||||
@ -223,7 +223,7 @@ void BattleProjectileController::emitStackProjectile(const CStack * stack)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleProjectileController::showProjectiles(std::shared_ptr<CCanvas> canvas)
|
void BattleProjectileController::showProjectiles(Canvas & canvas)
|
||||||
{
|
{
|
||||||
for ( auto it = projectiles.begin(); it != projectiles.end();)
|
for ( auto it = projectiles.begin(); it != projectiles.end();)
|
||||||
{
|
{
|
||||||
|
@ -22,14 +22,14 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
struct Point;
|
struct Point;
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
class CAnimation;
|
class CAnimation;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
|
|
||||||
/// Small struct which contains information about the position and the velocity of a projectile
|
/// Small struct which contains information about the position and the velocity of a projectile
|
||||||
struct ProjectileBase
|
struct ProjectileBase
|
||||||
{
|
{
|
||||||
virtual ~ProjectileBase() = default;
|
virtual ~ProjectileBase() = default;
|
||||||
virtual void show(std::shared_ptr<CCanvas> canvas) = 0;
|
virtual void show(Canvas & canvas) = 0;
|
||||||
|
|
||||||
Point from; // initial position on the screen
|
Point from; // initial position on the screen
|
||||||
Point dest; // target position on the screen
|
Point dest; // target position on the screen
|
||||||
@ -42,7 +42,7 @@ struct ProjectileBase
|
|||||||
|
|
||||||
struct ProjectileMissile : ProjectileBase
|
struct ProjectileMissile : ProjectileBase
|
||||||
{
|
{
|
||||||
void show(std::shared_ptr<CCanvas> canvas) override;
|
void show(Canvas & canvas) override;
|
||||||
|
|
||||||
std::shared_ptr<CAnimation> animation;
|
std::shared_ptr<CAnimation> animation;
|
||||||
int frameNum; // frame to display from projectile animation
|
int frameNum; // frame to display from projectile animation
|
||||||
@ -51,13 +51,13 @@ struct ProjectileMissile : ProjectileBase
|
|||||||
|
|
||||||
struct ProjectileAnimatedMissile : ProjectileMissile
|
struct ProjectileAnimatedMissile : ProjectileMissile
|
||||||
{
|
{
|
||||||
void show(std::shared_ptr<CCanvas> canvas) override;
|
void show(Canvas & canvas) override;
|
||||||
float frameProgress;
|
float frameProgress;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProjectileCatapult : ProjectileBase
|
struct ProjectileCatapult : ProjectileBase
|
||||||
{
|
{
|
||||||
void show(std::shared_ptr<CCanvas> canvas) override;
|
void show(Canvas & canvas) override;
|
||||||
|
|
||||||
std::shared_ptr<CAnimation> animation;
|
std::shared_ptr<CAnimation> animation;
|
||||||
int frameNum; // frame to display from projectile animation
|
int frameNum; // frame to display from projectile animation
|
||||||
@ -65,7 +65,7 @@ struct ProjectileCatapult : ProjectileBase
|
|||||||
|
|
||||||
struct ProjectileRay : ProjectileBase
|
struct ProjectileRay : ProjectileBase
|
||||||
{
|
{
|
||||||
void show(std::shared_ptr<CCanvas> canvas) override;
|
void show(Canvas & canvas) override;
|
||||||
|
|
||||||
std::vector<CCreature::CreatureAnimation::RayColor> rayConfig;
|
std::vector<CCreature::CreatureAnimation::RayColor> rayConfig;
|
||||||
};
|
};
|
||||||
@ -90,7 +90,7 @@ class BattleProjectileController
|
|||||||
bool stackUsesRayProjectile(const CStack * stack);
|
bool stackUsesRayProjectile(const CStack * stack);
|
||||||
bool stackUsesMissileProjectile(const CStack * stack);
|
bool stackUsesMissileProjectile(const CStack * stack);
|
||||||
|
|
||||||
void showProjectile(std::shared_ptr<CCanvas> canvas, std::shared_ptr<ProjectileBase> projectile);
|
void showProjectile(Canvas & canvas, std::shared_ptr<ProjectileBase> projectile);
|
||||||
|
|
||||||
const CCreature * getShooter(const CStack * stack);
|
const CCreature * getShooter(const CStack * stack);
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ class BattleProjectileController
|
|||||||
public:
|
public:
|
||||||
BattleProjectileController(BattleInterface * owner);
|
BattleProjectileController(BattleInterface * owner);
|
||||||
|
|
||||||
void showProjectiles(std::shared_ptr<CCanvas> canvas);
|
void showProjectiles(Canvas & canvas);
|
||||||
|
|
||||||
bool hasActiveProjectile(const CStack * stack);
|
bool hasActiveProjectile(const CStack * stack);
|
||||||
void emitStackProjectile(const CStack * stack);
|
void emitStackProjectile(const CStack * stack);
|
||||||
|
@ -22,7 +22,7 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
//struct Point;
|
//struct Point;
|
||||||
//
|
//
|
||||||
//class CClickableHex;
|
//class CClickableHex;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
//class IImage;
|
//class IImage;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ enum class EBattleFieldLayer {
|
|||||||
class BattleRenderer
|
class BattleRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using RendererPtr = std::shared_ptr<CCanvas>;
|
using RendererPtr = Canvas &;
|
||||||
using RenderFunctor = std::function<void(RendererPtr)>;
|
using RenderFunctor = std::function<void(RendererPtr)>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
|
|
||||||
#include "../../CCallback.h"
|
#include "../../CCallback.h"
|
||||||
#include "../../lib/NetPacks.h"
|
#include "../../lib/NetPacks.h"
|
||||||
@ -106,13 +106,13 @@ std::string BattleSiegeController::getWallPieceImageName(EWallVisual::EWallVisua
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleSiegeController::showWallPiece(std::shared_ptr<CCanvas> canvas, EWallVisual::EWallVisual what, const Point & offset)
|
void BattleSiegeController::showWallPiece(Canvas & canvas, EWallVisual::EWallVisual what, const Point & offset)
|
||||||
{
|
{
|
||||||
auto & ci = town->town->clientInfo;
|
auto & ci = town->town->clientInfo;
|
||||||
auto const & pos = ci.siegePositions[what];
|
auto const & pos = ci.siegePositions[what];
|
||||||
|
|
||||||
if ( wallPieceImages[what])
|
if ( wallPieceImages[what])
|
||||||
canvas->draw(wallPieceImages[what], offset + Point(pos.x, pos.y));
|
canvas.draw(wallPieceImages[what], offset + Point(pos.x, pos.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BattleSiegeController::getBattleBackgroundName() const
|
std::string BattleSiegeController::getBattleBackgroundName() const
|
||||||
@ -249,7 +249,7 @@ void BattleSiegeController::gateStateChanged(const EGateState state)
|
|||||||
CCS->soundh->playSound(soundBase::DRAWBRG);
|
CCS->soundh->playSound(soundBase::DRAWBRG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleSiegeController::showAbsoluteObstacles(std::shared_ptr<CCanvas> canvas, const Point & offset)
|
void BattleSiegeController::showAbsoluteObstacles(Canvas & canvas, const Point & offset)
|
||||||
{
|
{
|
||||||
if (getWallPieceExistance(EWallVisual::MOAT))
|
if (getWallPieceExistance(EWallVisual::MOAT))
|
||||||
showWallPiece(canvas, EWallVisual::MOAT, offset);
|
showWallPiece(canvas, EWallVisual::MOAT, offset);
|
||||||
|
@ -23,7 +23,7 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
|
|
||||||
struct Point;
|
struct Point;
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
class BattleRenderer;
|
class BattleRenderer;
|
||||||
class IImage;
|
class IImage;
|
||||||
@ -85,7 +85,7 @@ class BattleSiegeController
|
|||||||
/// returns true if chosen wall piece should be present in current battle
|
/// returns true if chosen wall piece should be present in current battle
|
||||||
bool getWallPieceExistance(EWallVisual::EWallVisual what) const;
|
bool getWallPieceExistance(EWallVisual::EWallVisual what) const;
|
||||||
|
|
||||||
void showWallPiece(std::shared_ptr<CCanvas> canvas, EWallVisual::EWallVisual what, const Point & offset);
|
void showWallPiece(Canvas & canvas, EWallVisual::EWallVisual what, const Point & offset);
|
||||||
|
|
||||||
BattleHex getTurretBattleHex(EWallVisual::EWallVisual wallPiece) const;
|
BattleHex getTurretBattleHex(EWallVisual::EWallVisual wallPiece) const;
|
||||||
const CStack * getTurretStack(EWallVisual::EWallVisual wallPiece) const;
|
const CStack * getTurretStack(EWallVisual::EWallVisual wallPiece) const;
|
||||||
@ -98,7 +98,7 @@ public:
|
|||||||
void stackIsCatapulting(const CatapultAttack & ca);
|
void stackIsCatapulting(const CatapultAttack & ca);
|
||||||
|
|
||||||
/// call-ins from other battle controllers
|
/// call-ins from other battle controllers
|
||||||
void showAbsoluteObstacles(std::shared_ptr<CCanvas> canvas, const Point & offset);
|
void showAbsoluteObstacles(Canvas & canvas, const Point & offset);
|
||||||
void collectRenderableObjects(BattleRenderer & renderer);
|
void collectRenderableObjects(BattleRenderer & renderer);
|
||||||
|
|
||||||
/// queries from other battle controllers
|
/// queries from other battle controllers
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../gui/CAnimation.h"
|
#include "../gui/CAnimation.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
|
|
||||||
#include "../../CCallback.h"
|
#include "../../CCallback.h"
|
||||||
#include "../../lib/battle/BattleHex.h"
|
#include "../../lib/battle/BattleHex.h"
|
||||||
@ -302,7 +302,7 @@ std::shared_ptr<IImage> BattleStacksController::getStackAmountBox(const CStack *
|
|||||||
return amountEffNeutral;
|
return amountEffNeutral;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleStacksController::showStackAmountBox(std::shared_ptr<CCanvas> canvas, const CStack * stack)
|
void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack * stack)
|
||||||
{
|
{
|
||||||
//blitting amount background box
|
//blitting amount background box
|
||||||
auto amountBG = getStackAmountBox(stack);
|
auto amountBG = getStackAmountBox(stack);
|
||||||
@ -318,15 +318,15 @@ void BattleStacksController::showStackAmountBox(std::shared_ptr<CCanvas> canvas,
|
|||||||
(moveInside ? amountBG->width() + 10 : 0) * reverseSideShift;
|
(moveInside ? amountBG->width() + 10 : 0) * reverseSideShift;
|
||||||
int yAdd = 260 + ((stack->side == BattleSide::ATTACKER || moveInside) ? 0 : -15);
|
int yAdd = 260 + ((stack->side == BattleSide::ATTACKER || moveInside) ? 0 : -15);
|
||||||
|
|
||||||
canvas->draw(amountBG, stackAnimation[stack->ID]->pos.topLeft() + Point(xAdd, yAdd));
|
canvas.draw(amountBG, stackAnimation[stack->ID]->pos.topLeft() + Point(xAdd, yAdd));
|
||||||
|
|
||||||
//blitting amount
|
//blitting amount
|
||||||
Point textPos = stackAnimation[stack->ID]->pos.topLeft() + amountBG->dimensions()/2 + Point(xAdd, yAdd);
|
Point textPos = stackAnimation[stack->ID]->pos.topLeft() + amountBG->dimensions()/2 + Point(xAdd, yAdd);
|
||||||
|
|
||||||
canvas->drawText(textPos, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, makeNumberShort(stack->getCount()));
|
canvas.drawText(textPos, EFonts::FONT_TINY, Colors::WHITE, ETextAlignment::CENTER, makeNumberShort(stack->getCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BattleStacksController::showStack(std::shared_ptr<CCanvas> canvas, const CStack * stack)
|
void BattleStacksController::showStack(Canvas & canvas, const CStack * stack)
|
||||||
{
|
{
|
||||||
stackAnimation[stack->ID]->nextFrame(canvas, facingRight(stack)); // do actual blit
|
stackAnimation[stack->ID]->nextFrame(canvas, facingRight(stack)); // do actual blit
|
||||||
stackAnimation[stack->ID]->incrementFrame(float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000);
|
stackAnimation[stack->ID]->incrementFrame(float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000);
|
||||||
|
@ -23,7 +23,7 @@ VCMI_LIB_NAMESPACE_END
|
|||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
struct StackAttackedInfo;
|
struct StackAttackedInfo;
|
||||||
|
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
class BattleInterface;
|
class BattleInterface;
|
||||||
class CBattleAnimation;
|
class CBattleAnimation;
|
||||||
class CreatureAnimation;
|
class CreatureAnimation;
|
||||||
@ -55,7 +55,7 @@ class BattleStacksController
|
|||||||
ui32 animIDhelper; //for giving IDs for animations
|
ui32 animIDhelper; //for giving IDs for animations
|
||||||
|
|
||||||
bool stackNeedsAmountBox(const CStack * stack);
|
bool stackNeedsAmountBox(const CStack * stack);
|
||||||
void showStackAmountBox(std::shared_ptr<CCanvas> canvas, const CStack * stack);
|
void showStackAmountBox(Canvas & canvas, const CStack * stack);
|
||||||
BattleHex getStackCurrentPosition(const CStack * stack);
|
BattleHex getStackCurrentPosition(const CStack * stack);
|
||||||
|
|
||||||
std::shared_ptr<IImage> getStackAmountBox(const CStack * stack);
|
std::shared_ptr<IImage> getStackAmountBox(const CStack * stack);
|
||||||
@ -86,8 +86,8 @@ public:
|
|||||||
void setHoveredStack(const CStack *stack);
|
void setHoveredStack(const CStack *stack);
|
||||||
void setSelectedStack(const CStack *stack);
|
void setSelectedStack(const CStack *stack);
|
||||||
|
|
||||||
void showAliveStack(std::shared_ptr<CCanvas> canvas, const CStack * stack);
|
void showAliveStack(Canvas & canvas, const CStack * stack);
|
||||||
void showStack(std::shared_ptr<CCanvas> canvas, const CStack * stack);
|
void showStack(Canvas & canvas, const CStack * stack);
|
||||||
|
|
||||||
void collectRenderableObjects(BattleRenderer & renderer);
|
void collectRenderableObjects(BattleRenderer & renderer);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/CCreatureHandler.h"
|
#include "../../lib/CCreatureHandler.h"
|
||||||
|
|
||||||
#include "../gui/CCanvas.h"
|
#include "../gui/Canvas.h"
|
||||||
|
|
||||||
static const SDL_Color creatureBlueBorder = { 0, 255, 255, 255 };
|
static const SDL_Color creatureBlueBorder = { 0, 255, 255, 255 };
|
||||||
static const SDL_Color creatureGoldBorder = { 255, 255, 0, 255 };
|
static const SDL_Color creatureGoldBorder = { 255, 255, 0, 255 };
|
||||||
@ -301,7 +301,7 @@ void CreatureAnimation::genBorderPalette(IImage::BorderPallete & target)
|
|||||||
target[2] = addColors(genShadow(64), genBorderColor(getBorderStrength(elapsedTime), border));
|
target[2] = addColors(genShadow(64), genBorderColor(getBorderStrength(elapsedTime), border));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatureAnimation::nextFrame(std::shared_ptr<CCanvas> canvas, bool facingRight)
|
void CreatureAnimation::nextFrame(Canvas & canvas, bool facingRight)
|
||||||
{
|
{
|
||||||
size_t frame = static_cast<size_t>(floor(currentFrame));
|
size_t frame = static_cast<size_t>(floor(currentFrame));
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ void CreatureAnimation::nextFrame(std::shared_ptr<CCanvas> canvas, bool facingRi
|
|||||||
|
|
||||||
image->setBorderPallete(borderPallete);
|
image->setBorderPallete(borderPallete);
|
||||||
|
|
||||||
canvas->draw(image, pos.topLeft(), Rect(0, 0, pos.w, pos.h));
|
canvas.draw(image, pos.topLeft(), Rect(0, 0, pos.w, pos.h));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
class CIntObject;
|
class CIntObject;
|
||||||
class CreatureAnimation;
|
class CreatureAnimation;
|
||||||
class CCanvas;
|
class Canvas;
|
||||||
|
|
||||||
/// Namespace for some common controls of animations
|
/// Namespace for some common controls of animations
|
||||||
namespace AnimationControls
|
namespace AnimationControls
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
|
void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
|
||||||
CCreatureAnim::EAnimType getType() const; //returns type of animation
|
CCreatureAnim::EAnimType getType() const; //returns type of animation
|
||||||
|
|
||||||
void nextFrame(std::shared_ptr<CCanvas> canvas, bool facingRight);
|
void nextFrame(Canvas & canvas, bool facingRight);
|
||||||
|
|
||||||
// should be called every frame, return true when animation was reset to beginning
|
// should be called every frame, return true when animation was reset to beginning
|
||||||
bool incrementFrame(float timePassed);
|
bool incrementFrame(float timePassed);
|
||||||
|
@ -100,8 +100,6 @@ public:
|
|||||||
void setFlagColor(PlayerColor player) override;
|
void setFlagColor(PlayerColor player) override;
|
||||||
bool isTransparent(const Point & coords) const override;
|
bool isTransparent(const Point & coords) const override;
|
||||||
Point dimensions() const override;
|
Point dimensions() const override;
|
||||||
int width() const override;
|
|
||||||
int height() const override;
|
|
||||||
|
|
||||||
void horizontalFlip() override;
|
void horizontalFlip() override;
|
||||||
void verticalFlip() override;
|
void verticalFlip() override;
|
||||||
@ -561,6 +559,15 @@ SDLImageLoader::~SDLImageLoader()
|
|||||||
IImage::IImage() = default;
|
IImage::IImage() = default;
|
||||||
IImage::~IImage() = default;
|
IImage::~IImage() = default;
|
||||||
|
|
||||||
|
int IImage::width() const
|
||||||
|
{
|
||||||
|
return dimensions().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int IImage::height() const
|
||||||
|
{
|
||||||
|
return dimensions().y;
|
||||||
|
}
|
||||||
|
|
||||||
SDLImage::SDLImage(CDefFile * data, size_t frame, size_t group)
|
SDLImage::SDLImage(CDefFile * data, size_t frame, size_t group)
|
||||||
: surf(nullptr),
|
: surf(nullptr),
|
||||||
@ -737,16 +744,6 @@ void SDLImage::setFlagColor(PlayerColor player)
|
|||||||
CSDL_Ext::setPlayerColor(surf, player);
|
CSDL_Ext::setPlayerColor(surf, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDLImage::width() const
|
|
||||||
{
|
|
||||||
return fullSize.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SDLImage::height() const
|
|
||||||
{
|
|
||||||
return fullSize.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SDLImage::isTransparent(const Point & coords) const
|
bool SDLImage::isTransparent(const Point & coords) const
|
||||||
{
|
{
|
||||||
return CSDL_Ext::isTransparent(surf, coords.x, coords.y);
|
return CSDL_Ext::isTransparent(surf, coords.x, coords.y);
|
||||||
|
@ -57,8 +57,8 @@ public:
|
|||||||
virtual bool isTransparent(const Point & coords) const = 0;
|
virtual bool isTransparent(const Point & coords) const = 0;
|
||||||
|
|
||||||
virtual Point dimensions() const = 0;
|
virtual Point dimensions() const = 0;
|
||||||
virtual int width() const=0;
|
int width() const;
|
||||||
virtual int height() const=0;
|
int height() const;
|
||||||
|
|
||||||
//only indexed bitmaps, 16 colors maximum
|
//only indexed bitmaps, 16 colors maximum
|
||||||
virtual void shiftPalette(int from, int howMany) = 0;
|
virtual void shiftPalette(int from, int howMany) = 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* CCanvas.cpp, part of VCMI engine
|
* Canvas.cpp, part of VCMI engine
|
||||||
*
|
*
|
||||||
* Authors: listed in file AUTHORS in main folder
|
* Authors: listed in file AUTHORS in main folder
|
||||||
*
|
*
|
||||||
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CCanvas.h"
|
#include "Canvas.h"
|
||||||
|
|
||||||
#include "SDL_Extensions.h"
|
#include "SDL_Extensions.h"
|
||||||
#include "Geometries.h"
|
#include "Geometries.h"
|
||||||
@ -16,43 +16,53 @@
|
|||||||
|
|
||||||
#include "../Graphics.h"
|
#include "../Graphics.h"
|
||||||
|
|
||||||
CCanvas::CCanvas(SDL_Surface * surface):
|
Canvas::Canvas(SDL_Surface * surface):
|
||||||
surface(surface)
|
surface(surface)
|
||||||
{
|
{
|
||||||
surface->refcount++;
|
surface->refcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCanvas::CCanvas(const Point & size)
|
Canvas::Canvas(Canvas & other):
|
||||||
|
surface(other.surface)
|
||||||
|
{
|
||||||
|
surface->refcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Canvas::Canvas(const Point & size)
|
||||||
{
|
{
|
||||||
surface = CSDL_Ext::newSurface(size.x, size.y);
|
surface = CSDL_Ext::newSurface(size.x, size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCanvas::~CCanvas()
|
Canvas::~Canvas()
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(surface);
|
SDL_FreeSurface(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCanvas::draw(std::shared_ptr<IImage> image, const Point & pos)
|
void Canvas::draw(std::shared_ptr<IImage> image, const Point & pos)
|
||||||
{
|
{
|
||||||
image->draw(surface, pos.x, pos.y);
|
assert(image);
|
||||||
|
if (image)
|
||||||
|
image->draw(surface, pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCanvas::draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect)
|
void Canvas::draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect)
|
||||||
{
|
{
|
||||||
image->draw(surface, pos.x, pos.y, &sourceRect);
|
assert(image);
|
||||||
|
if (image)
|
||||||
|
image->draw(surface, pos.x, pos.y, &sourceRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCanvas::draw(std::shared_ptr<CCanvas> image, const Point & pos)
|
void Canvas::draw(Canvas & image, const Point & pos)
|
||||||
{
|
{
|
||||||
blitAt(image->surface, pos.x, pos.y, surface);
|
blitAt(image.surface, pos.x, pos.y, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCanvas::drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest)
|
void Canvas::drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest)
|
||||||
{
|
{
|
||||||
CSDL_Ext::drawLine(surface, from.x, from.y, dest.x, dest.y, colorFrom, colorDest);
|
CSDL_Ext::drawLine(surface, from.x, from.y, dest.x, dest.y, colorFrom, colorDest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCanvas::drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text )
|
void Canvas::drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text )
|
||||||
{
|
{
|
||||||
switch (alignment)
|
switch (alignment)
|
||||||
{
|
{
|
||||||
@ -62,7 +72,7 @@ void CCanvas::drawText(const Point & position, const EFonts & font, const SDL_Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCanvas::drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text )
|
void Canvas::drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text )
|
||||||
{
|
{
|
||||||
switch (alignment)
|
switch (alignment)
|
||||||
{
|
{
|
||||||
@ -72,7 +82,3 @@ void CCanvas::drawText(const Point & position, const EFonts & font, const SDL_Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * CCanvas::getSurface()
|
|
||||||
{
|
|
||||||
return surface;
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* CCanvas.h, part of VCMI engine
|
* Canvas.h, part of VCMI engine
|
||||||
*
|
*
|
||||||
* Authors: listed in file AUTHORS in main folder
|
* Authors: listed in file AUTHORS in main folder
|
||||||
*
|
*
|
||||||
@ -17,18 +17,23 @@ class IImage;
|
|||||||
enum EFonts : int;
|
enum EFonts : int;
|
||||||
|
|
||||||
/// Class that represents surface for drawing on
|
/// Class that represents surface for drawing on
|
||||||
class CCanvas
|
class Canvas
|
||||||
{
|
{
|
||||||
SDL_Surface * surface;
|
SDL_Surface * surface;
|
||||||
|
|
||||||
|
Canvas & operator = (Canvas & other) = delete;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// constructs canvas using existing surface. Caller maintains ownership on the surface
|
/// constructs canvas using existing surface. Caller maintains ownership on the surface
|
||||||
CCanvas(SDL_Surface * surface);
|
Canvas(SDL_Surface * surface);
|
||||||
|
|
||||||
|
/// copy contructor
|
||||||
|
Canvas(Canvas & other);
|
||||||
|
|
||||||
/// constructs canvas of specified size
|
/// constructs canvas of specified size
|
||||||
CCanvas(const Point & size);
|
Canvas(const Point & size);
|
||||||
|
|
||||||
~CCanvas();
|
~Canvas();
|
||||||
|
|
||||||
/// renders image onto this canvas at specified position
|
/// renders image onto this canvas at specified position
|
||||||
void draw(std::shared_ptr<IImage> image, const Point & pos);
|
void draw(std::shared_ptr<IImage> image, const Point & pos);
|
||||||
@ -37,7 +42,7 @@ public:
|
|||||||
void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect);
|
void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect);
|
||||||
|
|
||||||
/// renders another canvas onto this canvas
|
/// renders another canvas onto this canvas
|
||||||
void draw(std::shared_ptr<CCanvas> image, const Point & pos);
|
void draw(Canvas & image, const Point & pos);
|
||||||
|
|
||||||
/// renders continuous, 1-pixel wide line with color gradient
|
/// renders continuous, 1-pixel wide line with color gradient
|
||||||
void drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest);
|
void drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest);
|
||||||
@ -47,7 +52,4 @@ public:
|
|||||||
|
|
||||||
/// renders multiple lines of text with specified parameters
|
/// renders multiple lines of text with specified parameters
|
||||||
void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
|
void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
|
||||||
|
|
||||||
/// for compatibility, returns pointer to internal SDL surface
|
|
||||||
SDL_Surface * getSurface();
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user