2009-05-20 13:08:56 +03:00
|
|
|
#include "../stdafx.h"
|
2007-08-21 16:48:18 +03:00
|
|
|
#include "CCursorHandler.h"
|
|
|
|
#include "SDL.h"
|
2008-08-01 21:13:33 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2007-08-21 16:48:18 +03:00
|
|
|
#include "CGameInfo.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CDefHandler.h"
|
2007-08-21 16:48:18 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CCursorHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-08-21 16:48:18 +03:00
|
|
|
extern SDL_Surface * screen;
|
|
|
|
|
|
|
|
void CCursorHandler::initCursor()
|
|
|
|
{
|
2008-08-01 21:13:33 +03:00
|
|
|
mode = number = xpos = ypos = 0;
|
2009-11-28 21:55:40 +02:00
|
|
|
dndImage = NULL;
|
2009-08-30 15:47:40 +03:00
|
|
|
help = CSDL_Ext::newSurface(40,40);
|
2008-08-01 21:13:33 +03:00
|
|
|
cursors.push_back(CDefHandler::giveDef("CRADVNTR.DEF"));
|
|
|
|
cursors.push_back(CDefHandler::giveDef("CRCOMBAT.DEF"));
|
|
|
|
cursors.push_back(CDefHandler::giveDef("CRDEFLT.DEF"));
|
|
|
|
cursors.push_back(CDefHandler::giveDef("CRSPELL.DEF"));
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2007-08-21 16:48:18 +03:00
|
|
|
}
|
|
|
|
|
2008-09-25 17:09:31 +03:00
|
|
|
void CCursorHandler::changeGraphic(const int & type, const int & no)
|
2007-08-21 16:48:18 +03:00
|
|
|
{
|
2008-08-01 21:13:33 +03:00
|
|
|
mode = type;
|
|
|
|
number = no;
|
2007-08-21 16:48:18 +03:00
|
|
|
}
|
|
|
|
|
2009-11-28 21:55:40 +02:00
|
|
|
/**
|
|
|
|
* Replaces the cursor with a custom image.
|
|
|
|
*
|
|
|
|
* @param image Image to replace cursor with or NULL to use the normal
|
|
|
|
* cursor.
|
|
|
|
*/
|
|
|
|
void CCursorHandler::dragAndDropCursor(SDL_Surface* image)
|
|
|
|
{
|
|
|
|
dndImage = image;
|
|
|
|
}
|
|
|
|
|
2008-09-25 17:09:31 +03:00
|
|
|
void CCursorHandler::cursorMove(const int & x, const int & y)
|
2007-08-21 16:48:18 +03:00
|
|
|
{
|
2008-08-01 21:13:33 +03:00
|
|
|
xpos = x;
|
|
|
|
ypos = y;
|
2007-08-21 16:48:18 +03:00
|
|
|
}
|
2008-08-01 21:13:33 +03:00
|
|
|
void CCursorHandler::draw1()
|
2007-08-21 16:48:18 +03:00
|
|
|
{
|
2008-08-07 03:38:44 +03:00
|
|
|
if(!Show) return;
|
2008-08-28 20:36:34 +03:00
|
|
|
int x = xpos, y = ypos;
|
2009-08-30 15:47:40 +03:00
|
|
|
shiftPos(x, y);
|
|
|
|
SDL_BlitSurface(screen, &genRect(40,40,x,y), help, &genRect(40,40,0,0));
|
2010-08-23 18:16:40 +03:00
|
|
|
// if (dndImage)
|
|
|
|
// blitAt(dndImage, x - dndImage->w/2, y - dndImage->h/2);
|
|
|
|
// else
|
|
|
|
// blitAt(cursors[mode]->ourImages[number].bitmap,x,y);
|
|
|
|
|
2009-11-28 21:55:40 +02:00
|
|
|
if (dndImage)
|
2010-08-23 18:16:40 +03:00
|
|
|
SDL_BlitSurface(dndImage, NULL, screen, &genRect(40, 40, x - dndImage->w/2, y - dndImage->h/2));
|
2009-11-28 21:55:40 +02:00
|
|
|
else
|
2010-08-23 18:16:40 +03:00
|
|
|
SDL_BlitSurface(cursors[mode]->ourImages[number].bitmap, NULL, screen, &genRect(40,40,x,y));
|
2007-08-21 16:48:18 +03:00
|
|
|
}
|
2008-08-01 21:13:33 +03:00
|
|
|
void CCursorHandler::draw2()
|
2007-08-21 16:48:18 +03:00
|
|
|
{
|
2008-08-07 03:38:44 +03:00
|
|
|
if(!Show) return;
|
2008-08-28 20:36:34 +03:00
|
|
|
int x = xpos, y = ypos;
|
2009-08-30 15:47:40 +03:00
|
|
|
shiftPos(x, y);
|
2010-08-23 18:16:40 +03:00
|
|
|
SDL_BlitSurface(help, NULL, screen, &genRect(40, 40, x, y));
|
|
|
|
//blitAt(help,x,y);
|
2009-08-30 15:47:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCursorHandler::shiftPos( int &x, int &y )
|
|
|
|
{
|
|
|
|
if((mode==1 && number!=6) || mode ==3)
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
|
|
|
x-=16;
|
|
|
|
y-=16;
|
2009-08-30 15:47:40 +03:00
|
|
|
|
|
|
|
// Properly align the melee attack cursors.
|
|
|
|
if (mode == 1)
|
|
|
|
{
|
|
|
|
switch (number)
|
|
|
|
{
|
|
|
|
case 7: // Bottom left
|
|
|
|
x -= 6;
|
|
|
|
y += 16;
|
|
|
|
break;
|
|
|
|
case 8: // Left
|
|
|
|
x -= 16;
|
|
|
|
y += 10;
|
|
|
|
break;
|
|
|
|
case 9: // Top left
|
|
|
|
x -= 6;
|
|
|
|
y -= 6;
|
|
|
|
break;
|
|
|
|
case 10: // Top right
|
|
|
|
x += 16;
|
|
|
|
y -= 6;
|
|
|
|
break;
|
|
|
|
case 11: // Right
|
|
|
|
x += 16;
|
|
|
|
y += 11;
|
|
|
|
break;
|
|
|
|
case 12: // Bottom right
|
|
|
|
x += 16;
|
|
|
|
y += 16;
|
|
|
|
break;
|
|
|
|
case 13: // Below
|
|
|
|
x += 9;
|
|
|
|
y += 16;
|
|
|
|
break;
|
|
|
|
case 14: // Above
|
|
|
|
x += 9;
|
|
|
|
y -= 15;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
2009-08-30 15:47:40 +03:00
|
|
|
else if(mode==0)
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
2009-08-30 15:47:40 +03:00
|
|
|
if(number == 0); //to exclude
|
|
|
|
else if(number == 2)
|
|
|
|
{
|
|
|
|
x -= 12;
|
|
|
|
y -= 10;
|
|
|
|
}
|
|
|
|
else if(number == 3)
|
|
|
|
{
|
|
|
|
x -= 12;
|
|
|
|
y -= 12;
|
|
|
|
}
|
|
|
|
else if(number < 27)
|
|
|
|
{
|
|
|
|
int hlpNum = (number - 4)%6;
|
|
|
|
if(hlpNum == 0)
|
|
|
|
{
|
|
|
|
x -= 15;
|
|
|
|
y -= 13;
|
|
|
|
}
|
|
|
|
else if(hlpNum == 1)
|
|
|
|
{
|
|
|
|
x -= 13;
|
|
|
|
y -= 13;
|
|
|
|
}
|
|
|
|
else if(hlpNum == 2)
|
|
|
|
{
|
|
|
|
x -= 20;
|
|
|
|
y -= 20;
|
|
|
|
}
|
|
|
|
else if(hlpNum == 3)
|
|
|
|
{
|
|
|
|
x -= 13;
|
|
|
|
y -= 16;
|
|
|
|
}
|
|
|
|
else if(hlpNum == 4)
|
|
|
|
{
|
|
|
|
x -= 8;
|
|
|
|
y -= 9;
|
|
|
|
}
|
|
|
|
else if(hlpNum == 5)
|
|
|
|
{
|
|
|
|
x -= 14;
|
|
|
|
y -= 16;
|
|
|
|
}
|
|
|
|
}
|
2010-03-21 00:17:19 +02:00
|
|
|
else if(number == 41)
|
|
|
|
{
|
|
|
|
x -= 14;
|
|
|
|
y -= 16;
|
|
|
|
}
|
|
|
|
else if(number < 31 || number == 42)
|
2009-08-30 15:47:40 +03:00
|
|
|
{
|
|
|
|
x -= 20;
|
|
|
|
y -= 20;
|
|
|
|
}
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
2009-10-25 16:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CCursorHandler::~CCursorHandler()
|
|
|
|
{
|
|
|
|
if(help)
|
|
|
|
SDL_FreeSurface(help);
|
|
|
|
|
|
|
|
for(int g=0; g<cursors.size(); ++g)
|
|
|
|
delete cursors[g];
|
|
|
|
}
|