forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclip.cpp
More file actions
64 lines (49 loc) · 1.08 KB
/
clip.cpp
File metadata and controls
64 lines (49 loc) · 1.08 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Aseprite Gfx Library
// Copyright (c) 2001-2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gfx/clip.h"
namespace gfx {
bool Clip::clip(
int avail_dst_w,
int avail_dst_h,
int avail_src_w,
int avail_src_h)
{
// Clip srcBounds
if (src.x < 0) {
size.w += src.x;
dst.x -= src.x;
src.x = 0;
}
if (src.y < 0) {
size.h += src.y;
dst.y -= src.y;
src.y = 0;
}
if (src.x + size.w > avail_src_w)
size.w -= src.x + size.w - avail_src_w;
if (src.y + size.h > avail_src_h)
size.h -= src.y + size.h - avail_src_h;
// Clip dstBounds
if (dst.x < 0) {
size.w += dst.x;
src.x -= dst.x;
dst.x = 0;
}
if (dst.y < 0) {
size.h += dst.y;
src.y -= dst.y;
dst.y = 0;
}
if (dst.x + size.w > avail_dst_w)
size.w -= dst.x + size.w - avail_dst_w;
if (dst.y + size.h > avail_dst_h)
size.h -= dst.y + size.h - avail_dst_h;
return (size.w > 0 && size.h > 0);
}
} // namespace gfx