master
Avril 4 years ago
parent 9c7591b0c5
commit 7d76317add
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -165,3 +165,18 @@ blockquote {
font-style:normal; font-style:normal;
margin-right:3px; margin-right:3px;
} }
.filebar {
margin: auto;
margin-top: 5px;
border-radius:5px;
height: 25px;
width: 90%;
}
#bars {
width: 100%;
display: block;
margin-top: 10px;
}

@ -10,6 +10,7 @@
<script src='js/stage.js'></script> <script src='js/stage.js'></script>
<script src='js/util.js'></script> <script src='js/util.js'></script>
<script src='js/bars.js'></script>
<script src='js/osu.js'></script> <script src='js/osu.js'></script>
<script src='js/client.js'></script> <script src='js/client.js'></script>
</head> </head>
@ -111,6 +112,10 @@
</div> </div>
</div> </div>
</div> </div>
<div style='margin: auto; margin-top: 5px; border-radius:5px; background: linear-gradient(90deg, green 25%, 25%, blue 50%, 50%, red 75%); height: 25px; width: 90%;'></div> <hr></hr>
<div id='bars'>
</div>
<!-- <div style='margin: auto; margin-top: 5px; border-radius:5px; background: linear-gradient(90deg, green 25%, 25%, blue 50%, 50%, red 75%); height: 25px; width: 90%;'></div> -->
</body> </body>
</html> </html>

@ -0,0 +1,59 @@
const clamp = (p, s, e) => {
s = s || 0;
e = e || p;
return p < s ? s : (p > e ? e : p);
};
const spectrum = (p) => {
return {
r: clamp(1.0 - (p*2), 0, 1),
g: p < 0.5 ? p / 0.5 : (p-0.5),
b: clamp(p, 0.5, 1),
toBytes: function() {
var bytes = {
r: floor(this.r * 255),
g: floor(this.g * 255),
b: floor(this.b * 255),
toString: function() {
return "#"+bytes.r.toString(16)+bytes.g.toString(16)+bytes.b.toString(16);
}
};
return bytes;
}
};
};
const genrgb = (r,g,b) =>{ return {r: r, g: g, b: b}; };
function ColouredBar(par, bars) {
const elem = document.createElement("div");
var str = "";
var pct = 0;
for(let i=0;i<bars.length;i++) {
const bar = bars[i];
pct += bar.frag;
str +=","+ bar.colour+" "+(pct*100)+"%"+ ((i<bars.length-1)? ", "+(pct*100)+"%":"");
}
elem.setAttribute("class", "filebar");
if(bars.length<1)
elem.style.background = "grey";
else
elem.style.background = 'linear-gradient(90deg '+str+')';
this.frags = bars;
this.element = elem;
this.parent = par;
par.appendChild(elem);
}
var BAR = ColouredBar.prototype;
BAR.remove = function() {
this.element.remove();
};

@ -300,3 +300,44 @@ global.hook("FILE_REMOVE", function(arg) {
else setWarn(document.getElementById(OSUFILE_DOM_PRE+i), false); else setWarn(document.getElementById(OSUFILE_DOM_PRE+i), false);
} }
}); });
/// --- bars --- ///
function osu_bar(others, osu) {
const part = (colour, frag) => { return {colour: colour, frag: frag}; };
var bars = [];
//TODO: Check for overlaps
return bars;
}
var OSU_BARS = {};
global.hook("FILE_ADD", function(arg) {
const osu = arg.osu;
const id = arg.id;
const bar_id = "_bar_"+id;
const par = document.getElementById("bars");
OSU_BARS[bar_id] = new ColouredBar(par, osu_bar(OSU_FILES.where(x=> x && x!=osu), osu)); //[{colour: "red", frag: 0.5}, {colour: "green", frag: 0.5}]);
OSU_BARS[bar_id].element.setAttribute("id", bar_id);
//OSU_BARS[bar_id].element.innerText = osu.Shortname();
});
global.hook("FILE_REMOVE", function(arg) {
const osu = arg.osu;
const id = arg.id;
const bar_id = "_bar_"+id;
if(OSU_BARS[bar_id])
{
OSU_BARS[bar_id].remove();
OSU_BARS[bar_id] = undefined;
}
});

Loading…
Cancel
Save