X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fdraw.qc;h=0b29572bee644865b70ebc3ddc6815bdc3806fa0;hp=05e7af227adccb9040870bc7e690e405a7b1d400;hb=HEAD;hpb=99facb38338832f539cec7022c414f7a6de458c3 diff --git a/qcsrc/menu/draw.qc b/qcsrc/menu/draw.qc index 05e7af227a..2bfb955c57 100644 --- a/qcsrc/menu/draw.qc +++ b/qcsrc/menu/draw.qc @@ -1,7 +1,6 @@ -#if defined(CSQC) -#elif defined(MENUQC) -#elif defined(SVQC) -#endif +#include "draw.qh" +#include +#include string draw_mousepointer; vector draw_mousepointer_offset; @@ -28,16 +27,6 @@ void draw_reset(float cw, float ch, float ox, float oy) draw_endBoldFont(); } -void draw_beginBoldFont() -{ - drawfont = FONT_USER+3; -} - -void draw_endBoldFont() -{ - drawfont = FONT_USER+0; -} - vector globalToBox(vector v, vector theOrigin, vector theScale) { v -= theOrigin; @@ -94,6 +83,17 @@ vector draw_PictureSize(string pic) return drawgetimagesize(pic); } +bool draw_PictureExists(string pic) +{ + pic = draw_UseSkinFor(pic); + if (fexists(strcat(pic, ".tga"))) return true; + if (fexists(strcat(pic, ".png"))) return true; + if (fexists(strcat(pic, ".jpg"))) return true; + if (fexists(strcat(pic, ".pcx"))) return true; + + return false; +} + void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha) { drawfill(boxToGlobal(theOrigin, draw_shift, draw_scale), boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0); @@ -282,7 +282,7 @@ void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector the void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz) { if(theSize.x <= 0 || theSize.y <= 0) { - dprint("Drawing zero size text?\n"); + LOG_TRACE("Drawing zero size text?"); return; } @@ -323,32 +323,55 @@ float draw_CondensedFontFactor(string theText, float ICanHasKallerz, vector Size return 1.0; } -float draw_clipSet; +IntrusiveList draw_clip; +STATIC_INIT(draw_clip) { draw_clip = IL_NEW(); } +CLASS(ClipFrame, Object) + ATTRIB(ClipFrame, clip_shift, vector, '0 0 0'); + ATTRIB(ClipFrame, clip_scale, vector, '0 0 0'); +ENDCLASS(ClipFrame) + +void _draw_SetClip(vector o, vector s) +{ + ClipFrame prev = IL_PEEK(draw_clip); + if (prev) { + o.x = bound(prev.clip_shift.x, o.x, prev.clip_shift.x + prev.clip_scale.x); + o.y = bound(prev.clip_shift.y, o.y, prev.clip_shift.y + prev.clip_scale.y); + s.x = bound(0, s.x, prev.clip_scale.x - (o.x - prev.clip_shift.x)); + s.y = bound(0, s.y, prev.clip_scale.y - (o.y - prev.clip_shift.y)); + } + ClipFrame e = NEW(ClipFrame); + e.clip_shift = o; + e.clip_scale = s; + IL_PUSH(draw_clip, e); + drawsetcliparea(o.x, o.y, s.x, s.y); +} + void draw_SetClip() { - if(draw_clipSet) - error("Already clipping, no stack implemented here, sorry"); - drawsetcliparea(draw_shift.x, draw_shift.y, draw_scale.x, draw_scale.y); - draw_clipSet = 1; + _draw_SetClip(draw_shift, draw_scale); } void draw_SetClipRect(vector theOrigin, vector theScale) { - vector o, s; - if(draw_clipSet) - error("Already clipping, no stack implemented here, sorry"); - o = boxToGlobal(theOrigin, draw_shift, draw_scale); - s = boxToGlobalSize(theScale, draw_scale); - drawsetcliparea(o.x, o.y, s.x, s.y); - draw_clipSet = 1; + _draw_SetClip( + boxToGlobal(theOrigin, draw_shift, draw_scale), + boxToGlobalSize(theScale, draw_scale) + ); } void draw_ClearClip() { - if(!draw_clipSet) - error("Not clipping, can't clear it then"); + if (IL_EMPTY(draw_clip)) { + LOG_FATAL("Not clipping, can't clear it then"); + } + entity currentSettings = IL_PEEK(draw_clip); + IL_REMOVE(draw_clip, currentSettings); + delete(currentSettings); drawresetcliparea(); - draw_clipSet = 0; + ClipFrame e = IL_PEEK(draw_clip); + if (e) { + drawsetcliparea(e.clip_shift.x, e.clip_shift.y, e.clip_scale.x, e.clip_scale.y); + } } string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)