1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

More CCursorHandler style tweaks

# Conflicts:
#	AI/FuzzyLite
This commit is contained in:
AlexVinS 2016-10-28 14:03:26 +03:00
parent 9423555015
commit 69c6643893
2 changed files with 22 additions and 25 deletions

View File

@ -23,7 +23,16 @@ void CCursorHandler::initCursor()
xpos = ypos = 0;
type = ECursor::DEFAULT;
dndObject = nullptr;
currentCursor = nullptr;
cursors =
{
make_unique<CAnimImage>("CRADVNTR", 0),
make_unique<CAnimImage>("CRCOMBAT", 0),
make_unique<CAnimImage>("CRDEFLT", 0),
make_unique<CAnimImage>("CRSPELL", 0)
};
currentCursor = cursors.at(int(ECursor::DEFAULT)).get();
help = CSDL_Ext::newSurface(40,40);
//No blending. Ensure, that we are copying pixels during "screen restore draw"
@ -35,22 +44,16 @@ void CCursorHandler::initCursor()
void CCursorHandler::changeGraphic(ECursor::ECursorTypes type, int index)
{
std::string cursorDefs[4] = { "CRADVNTR.DEF", "CRCOMBAT.DEF", "CRDEFLT.DEF", "CRSPELL.DEF" };
if (type != this->type)
if(type != this->type)
{
BLOCK_CAPTURING; // not used here
this->type = type;
this->frame = index;
delete currentCursor;
currentCursor = new CAnimImage(cursorDefs[int(type)], index);
currentCursor = cursors.at(int(type)).get();
currentCursor->setFrame(index);
}
if (frame != index)
else if(index != this->frame)
{
frame = index;
this->frame = index;
currentCursor->setFrame(index);
}
}
@ -98,13 +101,6 @@ void CCursorHandler::drawRestored()
SDL_Rect temp_rect = genRect(40, 40, x, y);
SDL_BlitSurface(help, nullptr, screen, &temp_rect);
//blitAt(help,x,y);
}
void CCursorHandler::draw(SDL_Surface *to)
{
currentCursor->moveTo(Point(xpos, ypos));
currentCursor->showAll(screen);
}
void CCursorHandler::shiftPos( int &x, int &y )
@ -230,10 +226,10 @@ void CCursorHandler::render()
drawRestored();
}
CCursorHandler::CCursorHandler() = default;
CCursorHandler::~CCursorHandler()
{
if(help)
SDL_FreeSurface(help);
delete currentCursor;
}

View File

@ -24,21 +24,21 @@ namespace ECursor
}
/// handles mouse cursor
class CCursorHandler
class CCursorHandler final
{
SDL_Surface * help;
CAnimImage * currentCursor;
std::unique_ptr<CAnimImage> dndObject; //if set, overrides currentCursor
std::array<std::unique_ptr<CAnimImage>, 4> cursors;
bool showing;
/// Draw cursor preserving original image below cursor
void drawWithScreenRestore();
/// Restore original image below cursor
void drawRestored();
/// Simple draw cursor
void draw(SDL_Surface *to);
public:
/// position of cursor
int xpos, ypos;
@ -72,5 +72,6 @@ public:
/// Move cursor to screen center
void centerCursor();
CCursorHandler();
~CCursorHandler();
};