[nexuiz-commits] r8402 - trunk/data/qcsrc/menu
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Dec 18 05:26:12 EST 2009
Author: div0
Date: 2009-12-18 05:26:12 -0500 (Fri, 18 Dec 2009)
New Revision: 8402
Modified:
trunk/data/qcsrc/menu/menu.qc
trunk/data/qcsrc/menu/skin-customizables.inc
trunk/data/qcsrc/menu/skin.qh
Log:
menu background: allow different aspect-fixing modes: letterbox, crop, width, height, stretch
Modified: trunk/data/qcsrc/menu/menu.qc
===================================================================
--- trunk/data/qcsrc/menu/menu.qc 2009-12-18 09:20:53 UTC (rev 8401)
+++ trunk/data/qcsrc/menu/menu.qc 2009-12-18 10:26:12 UTC (rev 8402)
@@ -226,62 +226,85 @@
if(key == K_SHIFT) menuShiftState |= S_SHIFT;
};
-void(string img, float a, float algn, float force1) drawBackground =
+void(string img, float a, string algn, float force1) drawBackground =
{
vector sz;
- vector isz;
- vector tl, ce, br;
+ float width_is_larger;
+ vector isz_w;
+ vector isz_h;
+ vector tl, ce, br, isz;
vector v;
string s;
- float i, f;
+ string mode;
+ float i, l;
+ string c;
sz = draw_PictureSize(img);
// keep aspect of image
- if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
- {
- // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
- // match up the height
- isz_y = 1;
- isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
- }
+ width_is_larger = (sz_x * draw_scale_y >= sz_y * draw_scale_x);
+
+ isz_w = '1 0 0' + '0 1 0' * ((sz_y / sz_x) * (draw_scale_x / draw_scale_y));
+ isz_h = '0 1 0' + '1 0 0' * ((sz_x / sz_y) * (draw_scale_y / draw_scale_x));
+
+ v_z = 0;
+
+ // mode "c"
+ if(width_is_larger)
+ isz = isz_h;
else
- {
- // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
- // match up the width
- isz_x = 1;
- isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
- }
- tl = '0 0 0';
- ce = '0.5 0.5 0' - 0.5 * isz;
- br = '1 1 0' - isz;
+ isz = isz_w;
- s = ftos(algn);
- v_z = 0;
- for(i = 0; i < strlen(s); ++i)
+ for(i = 0; i < strlen(algn); ++i)
{
- f = stof(substring(s, i, 1));
- switch(f)
+ br = '1 1 0' - isz;
+ tl = '0 0 0';
+ ce = 0.5 * (tl + br);
+ c = substring(algn, i, 1);
+ switch(c)
{
- case 1: case 4: case 7: v_x = tl_x; break;
- case 2: case 5: case 8: v_x = ce_x; break;
- case 3: case 6: case 9: v_x = br_x; break;
+ case "c": // crop
+ if(width_is_larger)
+ isz = isz_h;
+ else
+ isz = isz_w;
+ goto nopic;
+ case "l": // letterbox
+ if(width_is_larger)
+ isz = isz_w;
+ else
+ isz = isz_h;
+ goto nopic;
+ case "h": // height
+ isz = isz_h;
+ goto nopic;
+ case "w": // width
+ isz = isz_w;
+ goto nopic;
+ case "s": // stretch
+ isz = '1 1 0';
+ goto nopic;
+ case "1": case "4": case "7": v_x = tl_x; break;
+ case "2": case "5": case "8": v_x = ce_x; break;
+ case "3": case "6": case "9": v_x = br_x; break;
default: v_x = tl_x + (br_x - tl_x) * random(); break;
}
- switch(f)
+ switch(c)
{
- case 7: case 8: case 9: v_y = tl_y; break;
- case 4: case 5: case 6: v_y = ce_y; break;
- case 1: case 2: case 3: v_y = br_y; break;
+ case "7": case "8": case "9": v_y = tl_y; break;
+ case "4": case "5": case "6": v_y = ce_y; break;
+ case "1": case "2": case "3": v_y = br_y; break;
default: v_y = tl_y + (br_y - tl_y) * random(); break;
}
- if(i == 0)
+ if(l == 0)
draw_Picture(v, img, isz, '1 1 1', a);
else if(force1)
// force all secondary layers to use alpha 1. Prevents ugly issues
// with overlap. It's a flag because it cannot be used for the
// ingame background
- draw_Picture(v, strcat(img, "_l", ftos(i+1)), isz, '1 1 1', 1);
+ draw_Picture(v, strcat(img, "_l", ftos(l+1)), isz, '1 1 1', 1);
else
- draw_Picture(v, strcat(img, "_l", ftos(i+1)), isz, '1 1 1', a);
+ draw_Picture(v, strcat(img, "_l", ftos(l+1)), isz, '1 1 1', a);
+ ++l;
+:nopic
}
}
Modified: trunk/data/qcsrc/menu/skin-customizables.inc
===================================================================
--- trunk/data/qcsrc/menu/skin-customizables.inc 2009-12-18 09:20:53 UTC (rev 8401)
+++ trunk/data/qcsrc/menu/skin-customizables.inc 2009-12-18 10:26:12 UTC (rev 8402)
@@ -12,7 +12,8 @@
}
elsif(/^\s*SKINSTRING\(([A-Z_]+), "(.*)"\);$/)
{
- printf "// uses \"$2\" images\n";
+ # printf "// uses \"$2\" images\n";
+ printf "%-31s %s\n", $1, $2;
}
elsif(/^$/)
{
@@ -82,8 +83,9 @@
// general
SKINSTRING(GFX_BACKGROUND, "background");
SKINSTRING(GFX_BACKGROUND_INGAME, "background_ingame");
- SKINFLOAT(ALIGN_BACKGROUND, 5);
- SKINFLOAT(ALIGN_BACKGROUND_INGAME, 5);
+ // alignment string of num keys for orientations, or l = letterbox, c = crop, h = height, w = width, s = scale
+ SKINSTRING(ALIGN_BACKGROUND, "5");
+ SKINSTRING(ALIGN_BACKGROUND_INGAME, "5");
SKINFLOAT(ALPHA_BACKGROUND_INGAME, 0.7);
SKINFLOAT(ALPHA_DISABLED, 0.2);
SKINFLOAT(ALPHA_BEHIND, 0.5);
Modified: trunk/data/qcsrc/menu/skin.qh
===================================================================
--- trunk/data/qcsrc/menu/skin.qh 2009-12-18 09:20:53 UTC (rev 8401)
+++ trunk/data/qcsrc/menu/skin.qh 2009-12-18 10:26:12 UTC (rev 8402)
@@ -1,7 +1,8 @@
#define SKINBEGIN
#define SKINVECTOR(name,def) var vector SKIN##name = def
#define SKINFLOAT(name,def) var float SKIN##name = def
-#define SKINSTRING(name,def) const string SKIN##name = def
+//#define SKINSTRING(name,def) const string SKIN##name = def
+#define SKINSTRING(name,def) var string SKIN##name = def
#define SKINEND
#include "skin-customizables.inc"
#undef SKINEND
@@ -13,7 +14,9 @@
#define SKINBEGIN void Skin_ApplySetting(string key, string value) { switch(key) {
#define SKINVECTOR(name,def) case #name: SKIN##name = stov(value); break
#define SKINFLOAT(name,def) case #name: SKIN##name = stof(value); break
-#define SKINSTRING(name,def) case #name: break
+//#define SKINSTRING(name,def) case #name: break
+#define SKINSTRING(name,def) case #name: SKIN##name = strzone(value); break
+ // I know this leaks memory when skin is read multiple times. Screw it.
#define SKINEND case "": break; case "//": break; default: print("Invalid key in skin file: ", key, "\n"); } }
#include "skin-customizables.inc"
#undef SKINEND
More information about the nexuiz-commits
mailing list