浏览代码

More CCursorHandler style tweaks

# Conflicts:
#	AI/FuzzyLite
AlexVinS 9 年之前
父节点
当前提交
69c6643893
共有 2 个文件被更改,包括 22 次插入25 次删除
  1. 17 21
      client/gui/CCursorHandler.cpp
  2. 5 4
      client/gui/CCursorHandler.h

+ 17 - 21
client/gui/CCursorHandler.cpp

@@ -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;
 }

+ 5 - 4
client/gui/CCursorHandler.h

@@ -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();
 };