summaryrefslogtreecommitdiff
path: root/source/q_uis.c
blob: 4862ac22e085290a689b6e89f0324cddf70f66cf (plain)
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
/*
Copyright (C) 2003-2006 Andrey Nazarov

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.

*/

//
// ui_shared.c - basic UI support for client modules
//

#include "config.h"
#include "q_shared.h"
#include "com_public.h"
#include "ref_public.h"
#include "q_uis.h"

/*
===============================================================================

STRING DRAWING

===============================================================================
*/


/*
==============
UIS_DrawStringEx
==============
*/
void UIS_DrawStringEx( int x, int y, uint32 flags, int maxChars,
        const char *string, qhandle_t hFont )
{
	char	*p;
	int		length;
	int		xx;
    int     cw, ch;

	if( maxChars < 1 ) {
		maxChars = MAX_STRING_CHARS;
	}

    ref.DrawGetFontSize( &cw, &ch, hFont );

	if( !( flags & UI_MULTILINE ) ) {
		if( ( flags & UI_CENTER ) == UI_CENTER ) {
			x -= Q_DrawStrlenTo( string, maxChars ) * cw / 2;
		} else if( flags & UI_RIGHT ) {
			x -= Q_DrawStrlenTo( string, maxChars ) * cw;
		}

		ref.DrawString( x, y, flags, maxChars, string, hFont );
		return;
	}

	while( *string ) {
		if( ( p = strchr( string, '\n' ) ) != NULL && p - string < maxChars ) {
			length = p - string;
		} else {
			length = maxChars;
		}

		xx = x;
		if( ( flags & UI_CENTER ) == UI_CENTER ) {
			xx -= Q_DrawStrlenTo( string, length ) * cw / 2;
		} else if( flags & UI_RIGHT ) {
			xx -= Q_DrawStrlenTo( string, length ) * cw;
		}

		ref.DrawString( xx, y, flags, length, string, hFont );

		if( !p ) {
			break;
		}

		y += ch;
		string = p + 1;
	}

	// TODO: UI_AUTOWRAP support
	
}

/*
===============================================================================

DRAWING

===============================================================================
*/


/*
==============
UIS_DrawStretchPicByName
==============
*/
void UIS_DrawStretchPicByName( int x, int y, int w, int h, const char *pic ) {	
	ref.DrawStretchPic( x, y, w, h, ref.RegisterPic( pic ) );
}

/*
==============
UIS_DrawPicByName
==============
*/
void UIS_DrawPicByName( int x, int y, const char *pic )	{
	ref.DrawPic( x, y, ref.RegisterPic( pic ) );
}

/*
================
UIS_DrawRect
================
*/
void UIS_DrawRect( const vrect_t *rect, int width, int color ) {
	int x, y, w, h;

	// TODO: remove this
	x = rect->x;
	y = rect->y;
	w = rect->width;
	h = rect->height;

	ref.DrawFill( x, y, width, h, color ); // left
	ref.DrawFill( x + w - width, y, width, h, color ); // right
	ref.DrawFill( x + width, y, w - width * 2, width, color ); // top
	ref.DrawFill( x + width, y + h - width, w - width * 2, width, color ); // bottom
}

/*
================
UIS_DrawRectEx
================
*/
void UIS_DrawRectEx( const vrect_t *rect, int width, const color_t color ) {
	int x, y, w, h;

	// TODO: remove this
	x = rect->x;
	y = rect->y;
	w = rect->width;
	h = rect->height;

	ref.DrawFillEx( x, y, width, h, color ); // left
	ref.DrawFillEx( x + w - width, y, width, h, color ); // right
	ref.DrawFillEx( x + width, y, w - width * 2, width, color ); // top
	ref.DrawFillEx( x + width, y + h - width, w - width * 2, width, color ); // bottom
}