#include "windows.h" #include "CCMap.h" #include "math.h" /****** DRAW FUNCTIONS *******/ inline void AddBWColor(s32 *buff, u32 Color) { *buff += Color; if (*buff > 1023) *buff = 1023; } void DrawLineAddBW(MAP *MapDST,s32 X1,s32 Y1,s32 X2,s32 Y2, u32 Color) { s32 DX,DY,ADY,Inc,Inc2,Counter; u32 IThresh,ITCurrent,ITAdd; s32 *B0,Pitch; if (X1 < 0) X1 = 0; if (Y1 < 0) Y1 = 0; if (X1 > (s32)MapDST->SX) X1 = MapDST->SX; if (Y1 > (s32)MapDST->SY) Y1 = MapDST->SY; if (X2 < 0) X2 = 0; if (Y2 < 0) Y2 = 0; if (X2 > (s32)MapDST->SX) X2 = MapDST->SX; if (Y2 > (s32)MapDST->SY) Y2 = MapDST->SY; AddBWColor(MapDST->GetBase() + X1 + Y1 * MapDST->PITCH, Color); AddBWColor(MapDST->GetBase() + X2 + Y2 * MapDST->PITCH, Color); if (X2 < X1) { /* Swap */ DX = X1; X1 = X2; X2 = DX; DY = Y1; Y1 = Y2; Y2 = DY; } B0 = MapDST->GetBase(); Pitch = MapDST->PITCH; B0 += Y1 * Pitch + X1; DX = X2 - X1; DY = Y2 - Y1; if (DX == 0) { if (DY < 0) {DY = -DY;while (DY--) AddBWColor(B0 - DY * Pitch, Color); } else { while (DY--) AddBWColor(B0 + DY * Pitch, Color); } return; } if (DY == 0) { while (DX--) AddBWColor(B0++, Color); return; } ADY = abs(DY); Inc2 = DY > 0 ? Pitch : -Pitch; if (ADY > DX) {Inc = Inc2;Inc2 = 1;IThresh = ADY;ITAdd = DX;} else {Inc = 1;IThresh = DX;ITAdd = ADY; }; ITCurrent = 0; if (ADY > DX) Counter = ADY; else Counter = DX; while (Counter--) { AddBWColor(B0, Color); ITCurrent += ITAdd; if (IThresh <= ITCurrent) { B0 += Inc2; // *B0 = Color; ITCurrent -= IThresh; } B0 += Inc; } } void DrawCross(MAP *image, POINT p, u32 color, int len, char orient) { // pas d'optimisation pour les tests :P if (p.x < 0 || p.x >= image->SX) return; if (p.y < 0 || p.y >= image->SY) return; if (orient & 1) for (int x=p.x-len; x <= p.x+len; x++) { if (x < 0 || x > image->SX) continue; *(image->GetBase() + x + p.y*image->PITCH) = color; } if (orient & 2) for (int y=p.y-len; y <= p.y+len; y++) { if (y < 0 || y > image->SY) continue; *(image->GetBase() + p.x + y*image->PITCH) = color; } } void DrawRect(MAP *image, RECT r, u32 color) { if (r.left < 0 || r.right > image->SX) return; if (r.top < 0 || r.bottom > image->SY) return; for (int x=r.left; x<=r.right; x++) { *(image->GetBase() + x + r.top*image->PITCH) = color; *(image->GetBase() + x + r.bottom*image->PITCH) = color; } for (int y=r.top; y<=r.bottom; y++) { *(image->GetBase() + r.left + y*image->PITCH) = color; *(image->GetBase() + r.right + y*image->PITCH) = color; } }