parent
dd93f9508a
commit
33191714c1
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef TO_RECT_INCLUDED
|
||||||
|
#define TO_RECT_INCLUDED
|
||||||
|
|
||||||
|
#include <SDL2/SDL_rect.h>
|
||||||
|
#include "model/Coord.h"
|
||||||
|
|
||||||
|
SDL_Rect coordToRect(const SDL_Rect* boardRect, const Coord* coord);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //TO_RECT_INCLUDED
|
@ -1,37 +1,23 @@
|
|||||||
#include "view/PiecesDrawer.h"
|
#include "view/PiecesDrawer.h"
|
||||||
#include "model/Island.h"
|
#include "view/ToRect.h"
|
||||||
|
|
||||||
|
|
||||||
//Don't put this in model
|
|
||||||
SDL_Rect islandToRect(const SDL_Rect* boardRect, const Island* island) {
|
|
||||||
const int w = boardRect->w/9;
|
|
||||||
const int h = boardRect->h/9;
|
|
||||||
SDL_Rect r = {
|
|
||||||
.x = boardRect->x + w*(island->x*2),
|
|
||||||
.y = boardRect->y + h*(island->y*2),
|
|
||||||
.w = w,
|
|
||||||
.h = h
|
|
||||||
};
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Piece arrPieces[], const size_t nbPieces, const size_t numPlayer, SDL_Texture* piece) {
|
void drawPiecesPlayer(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Piece arrPieces[], const size_t nbPieces, const size_t numPlayer, SDL_Texture* piece) {
|
||||||
|
|
||||||
for (size_t i = 0; i < nbPieces; ++i)
|
for (size_t i = 0; i < nbPieces; ++i)
|
||||||
{
|
{
|
||||||
if (arrPieces[i].idJ == numPlayer) {
|
if (arrPieces[i].idJ == numPlayer) {
|
||||||
const SDL_Rect rDest = islandToRect(boardRect, &arrPieces[i].island);
|
Coord c = islandToCoord(&arrPieces[i].island);
|
||||||
|
const SDL_Rect rDest = coordToRect(boardRect, &c);
|
||||||
SDL_RenderCopy(renderer, piece, NULL, &rDest);
|
SDL_RenderCopy(renderer, piece, NULL, &rDest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Island* startMove, const Island* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture) {
|
void drawMovePiece(SDL_Renderer* renderer, const SDL_Rect* boardRect, const Coord* startMove, const Coord* endMove, SDL_Texture* pieceTexture, SDL_Texture* islandTexture) {
|
||||||
|
|
||||||
SDL_Rect rDest = islandToRect(boardRect, startMove);
|
SDL_Rect rDest = coordToRect(boardRect, startMove);
|
||||||
SDL_RenderCopy(renderer, islandTexture, NULL, &rDest);
|
SDL_RenderCopy(renderer, islandTexture, NULL, &rDest);
|
||||||
|
|
||||||
rDest = islandToRect(boardRect, endMove);
|
rDest = coordToRect(boardRect, endMove);
|
||||||
SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest);
|
SDL_RenderCopy(renderer, pieceTexture, NULL, &rDest);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
#include "view/ToRect.h"
|
||||||
|
|
||||||
|
SDL_Rect coordToRect(const SDL_Rect* boardRect, const Coord* coord) {
|
||||||
|
const int w = boardRect->w/9;
|
||||||
|
const int h = boardRect->h/9;
|
||||||
|
SDL_Rect r = {
|
||||||
|
.x = boardRect->x + w*coord->x,
|
||||||
|
.y = boardRect->y + h*coord->y,
|
||||||
|
.w = w,
|
||||||
|
.h = h
|
||||||
|
};
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
Loading…
Reference in new issue