forked from FWGS/mainui_cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Scissor.cpp
89 lines (69 loc) · 1.74 KB
/
Scissor.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "BaseMenu.h"
#include "Scissor.h"
#define MAX_SCISSORS 16
static class CScissorState
{
public:
CScissorState() : iDepth( 0 ) { }
int iDepth;
Point coordStack[MAX_SCISSORS];
Size sizeStack[MAX_SCISSORS];
} scissor;
void CropByPreviousScissors( Point pt, Size sz, int &x, int &y, int &w, int &h )
{
int inRight = pt.x + sz.w;
int inBottom = pt.y + sz.h;
int outLeft = x, outRight = x + w;
int outTop = y, outBottom = y + h;
if( outLeft < pt.x )
outLeft = pt.x;
if( outTop < pt.y )
outTop = pt.y;
if( outRight > inRight )
outRight = inRight;
if( outBottom > inBottom )
outBottom = inBottom;
x = outLeft;
y = outTop;
w = outRight - outLeft;
h = outBottom - outTop;
}
void UI::Scissor::PushScissor(int x, int y, int w, int h)
{
if( scissor.iDepth + 1 > MAX_SCISSORS )
{
Con_DPrintf( "UI::PushScissor: Scissor stack limit exceeded" );
return;
}
// have active scissors. Disable current
if( scissor.iDepth > 0 )
{
EngFuncs::PIC_DisableScissor();
CropByPreviousScissors( scissor.coordStack[scissor.iDepth - 1 ], scissor.sizeStack[scissor.iDepth - 1],
x, y, w, h );
}
scissor.coordStack[scissor.iDepth].x = x;
scissor.coordStack[scissor.iDepth].y = y;
scissor.sizeStack[scissor.iDepth].w = w;
scissor.sizeStack[scissor.iDepth].h = h;
EngFuncs::PIC_EnableScissor( x, y, w, h );
scissor.iDepth++;
}
void UI::Scissor::PopScissor()
{
if( scissor.iDepth <= 0 )
{
Con_DPrintf( "UI::PopScissor: no stack" );
return;
}
EngFuncs::PIC_DisableScissor();
scissor.iDepth--;
if( scissor.iDepth > 0 )
{
EngFuncs::PIC_EnableScissor(
scissor.coordStack[scissor.iDepth - 1].x,
scissor.coordStack[scissor.iDepth - 1].y,
scissor.sizeStack[scissor.iDepth - 1].w,
scissor.sizeStack[scissor.iDepth - 1].h );
}
}