X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fdraw.qc;h=ae6967e367565fc02c38f08f57c77ac0ccca706d;hb=04d7768d6a7d13490d9530a164703f1919c204e4;hp=7596c0c3a1c47c3b3920303dd18136da131cc712;hpb=6c4f62990980e74d4a0963b7179c7c964f535398;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/draw.qc b/qcsrc/menu/draw.qc index 7596c0c3a..ae6967e36 100644 --- a/qcsrc/menu/draw.qc +++ b/qcsrc/menu/draw.qc @@ -1,3 +1,7 @@ +#include "draw.qh" +#include "../common/util.qh" +#include "../common/constants.qh" + string draw_mousepointer; vector draw_mousepointer_offset; vector draw_mousepointer_size; @@ -23,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; @@ -77,7 +71,7 @@ string draw_PreloadPictureWithFlags(string pic, float f) void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha) { - if(theSize_x == 0 || theSize.y <= 0) // no default sizing please + if(theSize.x == 0 || theSize.y <= 0) // no default sizing please return; pic = draw_UseSkinFor(pic); drawpic(boxToGlobal(theOrigin, draw_shift, draw_scale), pic, boxToGlobalSize(theSize, draw_scale), theColor, theAlpha * draw_alpha, 0); @@ -277,7 +271,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; } @@ -303,7 +297,7 @@ float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye) vector v; v = '0 0 0'; //float r; - v_x = stringwidth(theText, ICanHasKallerz, globalToBoxSize(boxToGlobalSize(SizeThxBye, draw_scale), draw_fontscale)); + v.x = stringwidth(theText, ICanHasKallerz, globalToBoxSize(boxToGlobalSize(SizeThxBye, draw_scale), draw_fontscale)); v = globalToBoxSize(v, draw_scale); return v.x; } @@ -318,32 +312,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) @@ -362,12 +379,12 @@ string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKall float draw_TextWidth_WithColors(string s, vector theFontSize) { - return draw_TextWidth(s, TRUE, theFontSize); + return draw_TextWidth(s, true, theFontSize); } float draw_TextWidth_WithoutColors(string s, vector theFontSize) { - return draw_TextWidth(s, FALSE, theFontSize); + return draw_TextWidth(s, false, theFontSize); } float draw_TextLengthUpToWidth(string theText, float maxWidth, float allowColorCodes, vector theFontSize)