| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include "nine_slice.h" |
| 30 |
|
| 31 |
#include "log.h" |
| 32 |
#include "texture.h" |
| 33 |
|
| 34 |
|
| 35 |
void Draw9Slice( |
| 36 |
GraphicsDevice *g, const Pic *pic, |
| 37 |
const Rect2i target, |
| 38 |
const int top, const int right, const int bottom, const int left, |
| 39 |
const bool repeat, const color_t mask, const SDL_RendererFlip flip) |
| 40 |
{ |
| 41 |
const int srcX[] = {0, left, pic->size.x - right}; |
| 42 |
const int srcY[] = {0, top, pic->size.y - bottom}; |
| 43 |
const int srcW[] = {left, pic->size.x - right - left, right}; |
| 44 |
const int srcH[] = {top, pic->size.y - bottom - top, bottom}; |
| 45 |
const int dstX[] = { |
| 46 |
target.Pos.x, |
| 47 |
target.Pos.x + left, |
| 48 |
target.Pos.x + target.Size.x - right, |
| 49 |
target.Pos.x + target.Size.x |
| 50 |
}; |
| 51 |
const int dstY[] = { |
| 52 |
target.Pos.y, |
| 53 |
target.Pos.y + top, |
| 54 |
target.Pos.y + target.Size.y - bottom, |
| 55 |
target.Pos.y + target.Size.y |
| 56 |
}; |
| 57 |
const int dstW[] = {left, target.Size.x - right - left, right}; |
| 58 |
const int dstH[] = {top, target.Size.y - bottom - top, bottom}; |
| 59 |
Rect2i src; |
| 60 |
Rect2i dst; |
| 61 |
for (int i = 0; i < 3; i++) |
| 62 |
{ |
| 63 |
src.Pos.x = srcX[i]; |
| 64 |
src.Size.x = srcW[i]; |
| 65 |
dst.Size.x = repeat ? srcW[i] : dstW[i]; |
| 66 |
for (dst.Pos.x = dstX[i]; |
| 67 |
dst.Pos.x < dstX[i + 1]; |
| 68 |
dst.Pos.x += dst.Size.x) |
| 69 |
{ |
| 70 |
if (dst.Pos.x + dst.Size.x > dstX[i + 1]) |
| 71 |
{ |
| 72 |
src.Size.x = dst.Size.x = dstX[i + 1] - dst.Pos.x; |
| 73 |
} |
| 74 |
for (int j = 0; j < 3; j++) |
| 75 |
{ |
| 76 |
src.Pos.y = srcY[j]; |
| 77 |
src.Size.y = srcH[j]; |
| 78 |
dst.Size.y = repeat ? srcH[j] : dstH[j]; |
| 79 |
for (dst.Pos.y = dstY[j]; |
| 80 |
dst.Pos.y < dstY[j + 1]; |
| 81 |
dst.Pos.y += dst.Size.y) |
| 82 |
{ |
| 83 |
if (dst.Pos.y + dst.Size.y > dstY[j + 1]) |
| 84 |
{ |
| 85 |
src.Size.y = dst.Size.y = dstY[j + 1] - dst.Pos.y; |
| 86 |
} |
| 87 |
TextureRender( |
| 88 |
pic->Tex, g->gameWindow.renderer, src, dst, mask, 0, |
| 89 |
flip); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |