00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "ui_main.h"
00026 #include "ui_font.h"
00027 #include "ui_render.h"
00028 #include "../cl_video.h"
00029 #include "../renderer/r_draw.h"
00030 #include "../renderer/r_misc.h"
00031
00035 void UI_DrawFill (int x, int y, int w, int h, const vec4_t color)
00036 {
00037 R_DrawFill(x, y, w, h, color);
00038 }
00039
00051 void UI_Transform (const vec3_t transform, const vec3_t rotate, const vec3_t scale)
00052 {
00053 vec3_t pos;
00054
00055 if (transform != NULL) {
00056 R_PushMatrix();
00057 VectorCopy(transform, pos);
00058 pos[0] *= viddef.rx;
00059 pos[1] *= viddef.ry;
00060
00061 R_Transform(pos, rotate, scale);
00062 } else {
00063 R_PopMatrix();
00064 }
00065 }
00066
00074 const struct image_s *UI_LoadImage (const char *name)
00075 {
00076 const struct image_s *image = R_FindImage(va("pics/%s", name), it_pic);
00077 if (image == r_noTexture)
00078 return NULL;
00079 return image;
00080 }
00081
00082 void UI_DrawNormImage (float x, float y, float w, float h, float sh, float th, float sl, float tl, const image_t *image)
00083 {
00084 float nw, nh, x1, x2, x3, x4, y1, y2, y3, y4;
00085
00086 if (!image)
00087 return;
00088
00089
00090 x1 = x * viddef.rx;
00091 y1 = y * viddef.ry;
00092
00093
00094 if (w)
00095 nw = w * viddef.rx;
00096 else
00097 nw = 0;
00098
00099 if (h)
00100 nh = h * viddef.ry;
00101 else
00102 nh = 0;
00103
00104
00105 if (sh) {
00106 if (!w)
00107 nw = (sh - sl) * viddef.rx;
00108 sh /= image->width;
00109 } else {
00110 if (!w)
00111 nw = ((float)image->width - sl) * viddef.rx;
00112 sh = 1.0f;
00113 }
00114 sl /= image->width;
00115
00116
00117 if (th) {
00118 if (!h)
00119 nh = (th - tl) * viddef.ry;
00120 th /= image->height;
00121 } else {
00122 if (!h)
00123 nh = ((float)image->height - tl) * viddef.ry;
00124 th = 1.0f;
00125 }
00126 tl /= image->height;
00127
00128
00129 x4 = x1;
00130 x3 = x2 = x1 + nw;
00131 y2 = y1;
00132 y4 = y3 = y1 + nh;
00133
00134 {
00135 const vec2_t imageTexcoords[4] = {{sl, tl}, {sh, tl}, {sh, th}, {sl, th}};
00136 const vec2_t imageVerts[4] = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}};
00137 R_DrawImageArray(imageTexcoords, imageVerts, image);
00138 }
00139 }
00140
00156 const image_t *UI_DrawNormImageByName (float x, float y, float w, float h, float sh, float th, float sl, float tl, const char *name)
00157 {
00158 const struct image_s *image;
00159
00160 image = UI_LoadImage(name);
00161 if (!image) {
00162 Com_Printf("Can't find pic: %s\n", name);
00163 return NULL;
00164 }
00165
00166 UI_DrawNormImage(x, y, w, h, sh, th, sl, tl, image);
00167 return image;
00168 }
00169
00183 void UI_DrawPanel (const vec2_t pos, const vec2_t size, const char *texture, int texX, int texY, const int panelDef[6])
00184 {
00185 const int leftWidth = panelDef[0];
00186 const int midWidth = panelDef[1];
00187 const int rightWidth = panelDef[2];
00188 const int topHeight = panelDef[3];
00189 const int midHeight = panelDef[4];
00190 const int bottomHeight = panelDef[5];
00191 const int marge = panelDef[6];
00192
00194 const int firstPos = 0;
00195 const int secondPos = firstPos + leftWidth + marge;
00196 const int thirdPos = secondPos + midWidth + marge;
00197 const int firstPosY = 0;
00198 const int secondPosY = firstPosY + topHeight + marge;
00199 const int thirdPosY = secondPosY + midHeight + marge;
00200
00201 int y, h;
00202
00203 const image_t *image = UI_LoadImage(texture);
00204 if (!image)
00205 return;
00206
00207
00208 UI_DrawNormImage(pos[0], pos[1], leftWidth, topHeight, texX + firstPos + leftWidth, texY + firstPosY + topHeight,
00209 texX + firstPos, texY + firstPosY, image);
00210 UI_DrawNormImage(pos[0] + leftWidth, pos[1], size[0] - leftWidth - rightWidth, topHeight, texX + secondPos + midWidth, texY + firstPosY + topHeight,
00211 texX + secondPos, texY + firstPosY, image);
00212 UI_DrawNormImage(pos[0] + size[0] - rightWidth, pos[1], rightWidth, topHeight, texX + thirdPos + rightWidth, texY + firstPosY + topHeight,
00213 texX + thirdPos, texY + firstPosY, image);
00214
00215
00216 y = pos[1] + topHeight;
00217 h = size[1] - topHeight - bottomHeight;
00218 UI_DrawNormImage(pos[0], y, leftWidth, h, texX + firstPos + leftWidth, texY + secondPosY + midHeight,
00219 texX + firstPos, texY + secondPosY, image);
00220 UI_DrawNormImage(pos[0] + leftWidth, y, size[0] - leftWidth - rightWidth, h, texX + secondPos + midWidth, texY + secondPosY + midHeight,
00221 texX + secondPos, texY + secondPosY, image);
00222 UI_DrawNormImage(pos[0] + size[0] - rightWidth, y, rightWidth, h, texX + thirdPos + rightWidth, texY + secondPosY + midHeight,
00223 texX + thirdPos, texY + secondPosY, image);
00224
00225
00226 y = pos[1] + size[1] - bottomHeight;
00227 UI_DrawNormImage(pos[0], y, leftWidth, bottomHeight, texX + firstPos + leftWidth, texY + thirdPosY + bottomHeight,
00228 texX + firstPos, texY + thirdPosY, image);
00229 UI_DrawNormImage(pos[0] + leftWidth, y, size[0] - leftWidth - rightWidth, bottomHeight, texX + secondPos + midWidth, texY + thirdPosY + bottomHeight,
00230 texX + secondPos, texY + thirdPosY, image);
00231 UI_DrawNormImage(pos[0] + size[0] - bottomHeight, y, rightWidth, bottomHeight, texX + thirdPos + rightWidth, texY + thirdPosY + bottomHeight,
00232 texX + thirdPos, texY + thirdPosY, image);
00233 }
00234
00252 int UI_DrawStringInBox (const char *fontID, align_t align, int x, int y, int width, int height, const char *text, longlines_t method)
00253 {
00254 const align_t horizontalAlign = align % 3;
00255 const align_t verticalAlign = align / 3;
00256
00257
00258 const int xx = x + ((width * horizontalAlign) >> 1);
00259 const int yy = y + ((height * verticalAlign) >> 1);
00260
00261 return UI_DrawString(fontID, align, xx, yy, xx, width, 0, text, 0, 0, NULL, qfalse, method);
00262 }
00263
00264 int UI_DrawString (const char *fontID, align_t align, int x, int y, int absX, int maxWidth,
00265 int lineHeight, const char *c, int boxHeight, int scrollPos, int *curLine, qboolean increaseLine, longlines_t method)
00266 {
00267 const uiFont_t *font = UI_GetFontByID(fontID);
00268 const align_t verticalAlign = align / 3;
00269 int lines;
00270
00271 if (!font)
00272 Com_Error(ERR_FATAL, "Could not find font with id: '%s'", fontID);
00273
00274 if (lineHeight <= 0)
00275 lineHeight = UI_FontGetHeight(font->name);
00276
00277
00278
00279
00280 if (verticalAlign == 1)
00281 y += -(lineHeight / 2);
00282 else if (verticalAlign == 2)
00283 y += -lineHeight;
00284
00285 lines = R_FontDrawString(fontID, align, x, y, absX, maxWidth, lineHeight,
00286 c, boxHeight, scrollPos, curLine, method);
00287
00288 if (curLine && increaseLine)
00289 *curLine += lines;
00290
00291 return lines * lineHeight;
00292 }
00293