forked from Phobos-developers/YRpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawing.h
171 lines (135 loc) · 4.12 KB
/
Drawing.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
Drawing related static class.
This provides access to the game's Surfaces, color value conversion
and text aligning helpers.
*/
#pragma once
#include <GeneralDefinitions.h>
#include "ColorScheme.h"
#include <Surface.h>
#include <Helpers/CompileTime.h>
struct DirtyAreaStruct
{
RectangleStruct Rect;
bool alphabool10;
bool operator==(const DirtyAreaStruct& another) const {
return
Rect.X == another.Rect.X &&
Rect.Y == another.Rect.Y &&
Rect.Width == another.Rect.Width &&
Rect.Height == another.Rect.Height &&
alphabool10 == another.alphabool10;
};
};
class Drawing
{
public:
constexpr static reference<DynamicVectorClass<DirtyAreaStruct>, 0xB0CE78> DirtyAreas{};
static RectangleStruct &SurfaceDimensions_Hidden;
static ColorStruct &TooltipColor;
//TextBox dimensions for tooltip-style boxes
static RectangleStruct GetTextBox(const wchar_t* pText, int nX, int nY, DWORD flags, int nMarginX, int nMarginY)
{
RectangleStruct box;
RectangleStruct* p_box=&box;
PUSH_VAR32(nMarginY); //X Margin
PUSH_VAR32(nMarginX); //Y Margin - should add 2, because X margin adds to 2 internally!
PUSH_VAR32(flags);
PUSH_VAR32(nY);
PUSH_VAR32(nX);
SET_REG32(edx,pText);
SET_REG32(ecx,p_box);
CALL(0x4A59E0);
return box;
}
static RectangleStruct GetTextBox(const wchar_t* pText, int nX, int nY, int nMargin)
{ return GetTextBox(pText, nX, nY, 0, nMargin + 2, nMargin); }
static RectangleStruct GetTextBox(const wchar_t* pText, int nX, int nY)
{ return GetTextBox(pText, nX, nY, 2); }
static RectangleStruct GetTextBox(const wchar_t* pText, Point2D* pPoint)
{ return GetTextBox(pText, pPoint->X, pPoint->Y, 2); }
static RectangleStruct GetTextBox(const wchar_t* pText, Point2D* pPoint, int nMargin)
{ return GetTextBox(pText, pPoint->X, pPoint->Y, nMargin); }
//TextDimensions for text aligning
static RectangleStruct GetTextDimensions(const wchar_t* pText)
{
RectangleStruct dim=GetTextBox(pText,0,0,0);
dim.X=0;
dim.Y=0;
dim.Width-=4;
dim.Height-=2;
return dim;
}
// Rectangles
static RectangleStruct Intersect(RectangleStruct* rect1, RectangleStruct* rect2, int* delta_left, int* delta_top)
{
RectangleStruct box;
RectangleStruct* p_box=&box;
PUSH_VAR32(delta_top);
PUSH_VAR32(delta_left);
PUSH_VAR32(rect2);
SET_REG32(edx,rect1);
SET_REG32(ecx,p_box);
CALL(0x421B60);
return box;
}
//Stuff
// Converts an RGB color to a 16bit color value.
static WORD Color16bit(const ColorStruct& color) {
return static_cast<WORD>((color.B >> 3) | ((color.G >> 2) << 5) | ((color.R >> 3) << 11));
}
static DWORD __fastcall RGB2DWORD(int red, int green, int blue)
{ JMP_STD(0x4355D0); }
static DWORD RGB2DWORD(const ColorStruct Color) {
return RGB2DWORD(Color.R, Color.G, Color.B);
}
// Converts a 16bit color to an RGB color.
static ColorStruct WordColor(WORD bits) {
ColorStruct color;
color.R = static_cast<BYTE>(((bits & 0xF800) >> 11) << 3);
color.G = static_cast<BYTE>(((bits & 0x07E0) >> 5) << 2);
color.B = static_cast<BYTE>((bits & 0x001F) << 3);
return color;
}
/** Message is a vswprintf format specifier, ... is for any arguments needed */
static Point2D * __cdecl PrintUnicode(Point2D *Position1, wchar_t *Message, Surface *a3, RectangleStruct *Rect, Point2D *Position2,
ColorScheme *a6, int a7, int a8, ...)
{ JMP_STD(0x4A61C0); };
};
//A few preset 16bit colors.
#define COLOR_BLACK 0x0000
#define COLOR_WHITE 0xFFFF
#define COLOR_RED 0xF800
#define COLOR_GREEN 0x07E0
#define COLOR_BLUE 0x001F
#define COLOR_PURPLE (COLOR_RED | COLOR_BLUE)
class ABufferClass {
public:
static ABufferClass* &ABuffer;
ABufferClass(RectangleStruct rect)
{ JMP_THIS(0x410CE0); }
RectangleStruct rect;
int field_10;
BSurface *Surface;
byte* BufferStart;
byte* BufferEndpoint;
int BufferSize;
int field_24;
int W;
int H;
};
class ZBufferClass {
public:
static ZBufferClass* &ZBuffer;
ZBufferClass(RectangleStruct rect)
{ JMP_THIS(0x7BC970); }
RectangleStruct rect;
int field_10;
BSurface *Surface;
byte* BufferStart;
byte* BufferEndpoint;
int BufferSize;
int field_24;
int W;
int H;
};