-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuicore_Import.cpp
More file actions
185 lines (153 loc) · 5.79 KB
/
uicore_Import.cpp
File metadata and controls
185 lines (153 loc) · 5.79 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright (C) 2007 Benjamin Litzelmann
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "uicore_Global.h"
#include "../gameshared/q_shared.h"
#include "../gameshared/q_math.h"
#include "../gameshared/q_cvar.h"
#include "../gameshared/q_dynvar.h"
#include "../gameshared/gs_ref.h"
#include "../gameshared/q_keycodes.h"
#include "uiwsw_Utils.h"
#include "uicore_Import.h"
using namespace UIWsw;
#define D_ROUND(x) round(x)
#define R_ROUND(r) { r.x = D_ROUND(r.x); r.y = D_ROUND(r.y); r.w = D_ROUND(r.w); r.h = D_ROUND(r.h); }
namespace UICore
{
void* Importer::newFunc( unsigned int size )
{
return UIMem::Malloc( size );
}
void Importer::deleteFunc( void *p )
{
UIMem::Free( p );
}
void Importer::FixRect( Rect &rect )
{
// !! IMPORTANT !! - prevent rounding errors
rect.w = round( (rect.w + rect.x) * Local::getScaleX() ) - round(rect.x * Local::getScaleX());
rect.h = round( (rect.h + rect.y) * Local::getScaleY() ) - round(rect.y * Local::getScaleY());
rect.x = round(rect.x * Local::getScaleX());
rect.y = round(rect.y * Local::getScaleY());
}
void Importer::DrawImage( Image img, const Rect &src, const Rect &dest, const Color &color, const float angle )
{
Rect pos;
pos.x = dest.x + src.x;
pos.y = dest.y + src.y;
pos.w = max( 0, src.w );
pos.h = max( 0, src.h );
FixRect(pos);
if( fabs( angle ) < 0.001 ) {
Trap::R_DrawStretchPic( (int)pos.x, (int)pos.y, (int)pos.w, (int)pos.h, 0, 0, 1, 1, (float*)(&color), img );
} else {
Trap::R_DrawRotatedStretchPic( (int)pos.x, (int)pos.y, (int)pos.w, (int)pos.h, 0, 0, 1, 1, angle, (float*)(&color), img );
}
}
void Importer::FillRect( const Rect &rect, const Color &color )
{
Rect pos;
pos.x = rect.x;
pos.y = rect.y;
pos.w = max( 0, rect.w );
pos.h = max( 0, rect.h );
FixRect(pos);
Trap::R_DrawStretchPic( (int)pos.x, (int)pos.y, (int)pos.w, (int)pos.h, 0, 0, 1, 1, (float*)(&color), Local::getWhiteShader() );
}
float Importer::StringWidth( const char *text, const Font font, int maxlen )
{
struct qfontface_s *ft;
if( !font )
ft = Local::getFontSmall();
else
ft = (struct qfontface_s *)font;
return Trap::SCR_strWidth( text, ft, maxlen ) / Local::getScaleX();
}
float Importer::StringHeight( const Font font )
{
struct qfontface_s *ft;
if( !font )
ft = Local::getFontSmall();
else
ft = (struct qfontface_s *)font;
return Trap::SCR_strHeight( ft ) / Local::getScaleY();
}
void Importer::DrawString( const Rect &src, const Rect &dest, const char *text, const Font font, const Color &color )
{
// the src argument is the part of the image generated from the font that must be displayed.
// when the text is fully displayed, src.x = 0 and src.w = stringWidth.
// otherwise, it depends of the aligment of the font (eg: if centered, src.x = stringWidth - src.w)
// Alignment offsets are already calculated at this point
vec4_t clr;
struct qfontface_s *ft;
Rect pos;
if ( src.w <= 0 || src.h <= 0 )
return;
color.get( clr[0], clr[1], clr[2], clr[3] );
if( !font )
ft = Local::getFontSmall();
else
ft = (struct qfontface_s *)font;
pos.x = (dest.x + src.x);
pos.y = (dest.y + src.y);
pos.w = (dest.w);
pos.h = (dest.h);
FixRect(pos);
if( src.w < dest.w || src.h < dest.h ) {
Trap::SCR_DrawClampString( (int)pos.x, (int)pos.y, text, (int)pos.x, (int)pos.y,
(int)round( (dest.x + src.x + src.w) * Local::getScaleX() ),
(int)round( (dest.y + src.y + src.h) * Local::getScaleY() ),
ft, clr );
/*
Trap::SCR_DrawClampString( x, y, text, x, y,
x + (int)round( pos.x ),
y + (int)round( pos.y ),
ft, clr );
*/
} else {
Trap::SCR_DrawString( (int)pos.x, (int)pos.y, ALIGN_TOP_LEFT, text, ft, clr );
}
}
const int Importer::clickButton = K_MOUSE1;
const int Importer::mouseWheelUp = K_MWHEELUP;
const int Importer::mouseWheelDown = K_MWHEELDOWN;
const int Importer::keyLeft = K_LEFTARROW;
const int Importer::keyRight = K_RIGHTARROW;
const int Importer::keyUp = K_UPARROW;
const int Importer::keyDown = K_DOWNARROW;
const int Importer::keyBackspace = K_BACKSPACE;
const int Importer::keyDelete = K_DEL;
const int Importer::keyInsert = K_INS;
const int Importer::keyEnter = K_ENTER;
const int Importer::keySpace = K_SPACE;
const int Importer::keyPgUp = K_PGUP;
const int Importer::keyPgDn = K_PGDN;
const int Importer::keyPadLeft = KP_LEFTARROW;
const int Importer::keyPadRight = KP_RIGHTARROW;
const int Importer::keyPadUp = KP_UPARROW;
const int Importer::keyPadDown = KP_DOWNARROW;
const int Importer::keyPadDelete = KP_DEL;
const int Importer::keyPadInsert = KP_INS;
const int Importer::keyPadEnter = KP_ENTER;
const int Importer::keyPadPgUp = KP_PGUP;
const int Importer::keyPadPgDn = KP_PGDN;
const int Importer::keyTab = K_TAB;
const int Importer::keyLShift = K_LSHIFT;
const int Importer::keyLCtrl = K_LCTRL;
const int Importer::keyLAlt = K_LALT;
const int Importer::keyRShift = K_RSHIFT;
const int Importer::keyRCtrl = K_RCTRL;
const int Importer::keyRAlt = K_RALT;
}