X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fclient%2Fmiscfunctions.qh;h=0143d1a0134ac1720a49273a0bb87b408156ab54;hp=60048d0497bdd65279c9ec7f1e57c0551031bab2;hb=f8fe0e4aa8dad544f243ae997dfeb9cdccd55ee2;hpb=e9f30b97435c6afe3d6911f21e1f4fd1b97e93da diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index 60048d0497..0143d1a013 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -1,5 +1,4 @@ -#ifndef CLIENT_MISCFUNCTIONS_H -#define CLIENT_MISCFUNCTIONS_H +#pragma once entity players; entity teams; @@ -32,10 +31,11 @@ vector HUD_GetFontsize(string cvarname); float PreviewExists(string name); -vector rotate(vector v, float a); +vector Rotate(vector v, float a); -string ColorTranslateRGB(string s); +#define IS_DEAD(s) (((s).classname == "csqcmodel") ? (s).csqcmodel_isdead : (GetResourceAmount((s), RESOURCE_HEALTH) <= 0)) + // decolorizes and team colors the player name when needed string playername(string thename, float teamid); @@ -44,8 +44,9 @@ float cvar_or(string cv, float v); vector project_3d_to_2d(vector vec); -#define draw_beginBoldFont() do { drawfont = FONT_USER + 2; } while (0) -#define draw_endBoldFont() do { drawfont = FONT_USER + 1; } while (0) +vector drawfontscale; +#define draw_beginBoldFont() drawfont = FONT_USER + 2 +#define draw_endBoldFont() drawfont = FONT_USER + 1 float expandingbox_sizefactor_from_fadelerp(float fadelerp); @@ -55,6 +56,53 @@ void drawborderlines(float thickness, vector pos, vector dim, vector color, floa void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag); +void HUD_Scale_Disable(); +void HUD_Scale_Enable(); + +#define HUD_ScaleX(f) (f * hud_scale.x) +#define HUD_ScaleY(f) (f * hud_scale.y) +#define HUD_ShiftX(f) (f + hud_shift.x + hud_shift.z * (f - hud_scale_center.x)) +#define HUD_ShiftY(f) (f + hud_shift.y + hud_shift.z * (f - hud_scale_center.y)) +vector HUD_Scale(vector v); +vector HUD_Shift(vector v); + +// The following functions / macros must be called from within +// the panel HUD / scoreboard code so that pos and size are scaled +// when the hud_dynamic code is running. +// Make use of stringwidth_builtin and draw*_builtin everywhere else. + +float stringwidth(string text, float handleColors, vector sz); + +#define drawpic(position, pic, size, rgb, alpha, flag) \ + drawpic_builtin(HUD_Shift(position), pic, HUD_Scale(size), rgb, alpha, flag) + +#define drawcharacter(position, character, scale, rgb, alpha, flag) \ + drawcharacter_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag) + +#define drawstring(position, text, scale, rgb, alpha, flag) \ + drawstring_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag) + +#define drawcolorcodedstring(position, text, scale, alpha, flag) \ + drawcolorcodedstring_builtin(HUD_Shift(position), text, scale, alpha, flag) + +#define drawcolorcodedstring2(position, text, scale, rgb, alpha, flag) \ + drawcolorcodedstring2_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag) + +#define drawfill(position, size, rgb, alpha, flag) \ + drawfill_builtin(HUD_Shift(position), HUD_Scale(size), rgb, alpha, flag) + +#define drawsetcliparea(xposition, yposition, w, h) \ + drawsetcliparea_builtin(HUD_ShiftX(xposition), HUD_ShiftY(yposition), HUD_ScaleX(w), HUD_ScaleY(h)) + +// Since drawsubpic usually gets called multiple times from within an +// utility function, instead of scaling pos and size in every call +// we scale them once for all in the beginning of that utility function. +// That's why drawsubpic isn't remapped. +/* +#define drawsubpic(position, size, pic, srcPosition, srcSize, rgb, alpha, flag) \ + drawsubpic_builtin(HUD_Shift(position), HUD_Scale(size), pic, HUD_Shift(srcPosition), HUD_Scale(srcSize), rgb, alpha, flag) +*/ + // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box float _drawpic_imgaspect; vector _drawpic_imgsize; @@ -62,7 +110,7 @@ vector _drawpic_sz; float _drawpic_oldsz; string _drawpic_picpath; #define drawpic_aspect(pos,pic,mySize,color,theAlpha,drawflag)\ - do {\ + MACRO_BEGIN {\ _drawpic_imgsize = draw_getimagesize(pic);\ if(_drawpic_imgsize != '0 0 0') {\ _drawpic_imgaspect = _drawpic_imgsize.x/_drawpic_imgsize.y;\ @@ -71,45 +119,48 @@ string _drawpic_picpath; _drawpic_oldsz = _drawpic_sz.x;\ _drawpic_sz.x = _drawpic_sz.y * _drawpic_imgaspect;\ if(_drawpic_sz.x)\ - drawpic(pos + eX * (_drawpic_oldsz - _drawpic_sz.x) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\ + drawpic(pos + eX * 0.5 * (_drawpic_oldsz - _drawpic_sz.x), pic, _drawpic_sz, color, theAlpha, drawflag);\ } else {\ _drawpic_oldsz = _drawpic_sz.y;\ _drawpic_sz.y = _drawpic_sz.x / _drawpic_imgaspect;\ if(_drawpic_sz.y)\ - drawpic(pos + eY * (_drawpic_oldsz - _drawpic_sz.y) * 0.5, pic, _drawpic_sz, color, theAlpha, drawflag);\ + drawpic(pos + eY * 0.5 * (_drawpic_oldsz - _drawpic_sz.y), pic, _drawpic_sz, color, theAlpha, drawflag);\ }\ }\ - } while(0) + } MACRO_END // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga #define drawpic_aspect_skin(pos,pic,sz,color,theAlpha,drawflag)\ - do{\ + MACRO_BEGIN {\ _drawpic_picpath = strcat(hud_skin_path, "/", pic);\ if(precache_pic(_drawpic_picpath) == "") {\ _drawpic_picpath = strcat("gfx/hud/default/", pic);\ }\ drawpic_aspect(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\ _drawpic_picpath = string_null;\ - } while(0) + } MACRO_END // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga #define drawpic_skin(pos,pic,sz,color,theAlpha,drawflag)\ - do{\ + MACRO_BEGIN {\ _drawpic_picpath = strcat(hud_skin_path, "/", pic);\ if(precache_pic(_drawpic_picpath) == "") {\ _drawpic_picpath = strcat("gfx/hud/default/", pic);\ }\ drawpic(pos, _drawpic_picpath, sz, color, theAlpha, drawflag);\ _drawpic_picpath = string_null;\ - } while(0) + } MACRO_END void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp); void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp); -#define SET_POS_AND_SZ_Y_ASPECT(allow_colors) do { \ +#define SET_POS_AND_SZ_Y_ASPECT(allow_colors) MACRO_BEGIN { \ float textaspect, oldsz; \ + vector dfs = drawfontscale; \ + drawfontscale = '1 1 0'; \ textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y; \ + drawfontscale = dfs; \ if(sz.x/sz.y > textaspect) { \ oldsz = sz.x; \ sz.x = sz.y * textaspect; \ @@ -119,7 +170,7 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theSc sz.y = sz.x / textaspect; \ pos.y += (oldsz - sz.y) * 0.5; \ } \ -} while(0) +} MACRO_END // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag); @@ -127,7 +178,6 @@ void drawstring_aspect(vector pos, string text, vector sz, vector color, float t // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag); -vector drawfontscale; void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp); // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box @@ -137,21 +187,14 @@ void drawcolorcodedstring_expanding(vector position, string text, vector theScal void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp); +void update_mousepos(); + // this draws the triangles of a model DIRECTLY. Don't expect high performance, really... float PolyDrawModelSurface(entity e, float i_s); void PolyDrawModel(entity e); void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag); -const vector GETPLAYERORIGIN_ERROR = '1123581321 2357111317 3141592653'; // way out of bounds for anything on the map -vector getplayerorigin(int pl); - -float getplayeralpha(float pl); - -vector getcsqcplayercolor(float pl); - -float getplayerisdead(float pl); - const int MAX_ACCURACY_LEVELS = 10; float acc_lev[MAX_ACCURACY_LEVELS]; vector acc_col[MAX_ACCURACY_LEVELS]; @@ -163,5 +206,3 @@ void Accuracy_LoadLevels(); void Accuracy_LoadColors(); vector Accuracy_GetColor(float accuracy); - -#endif