void OsuManiaRenderer::RenderHitTimings(Window& _win)
{
	const int KEYS = play->beatmap->getMods().getCS();

	Analyzer* analyzer = AnalysisStruct::beatmapAnalysis.getAnalyzer("Tap Deviation (ms)");
	if (analyzer == nullptr) return;

	for (osu::TIMING timing : *(analyzer->getData()))
	{
		if (BTWN(getStartTime(), timing.time + timing.data, getEndTime())) // hits
		{
			int hitXpos = timing.key * (this->width / KEYS) + (this->absXpos - this->width / 2);
			int width = ((this->width) / KEYS) - (2 * KEYS);

			int hitPos = (*viewTime) - timing.time - timing.data;
			int hitYpos = hitPos*zoom + height;

			_win.driver->draw2DRectangle(SColor(255, 255, 0, 255), rect<s32>(absXpos + hitXpos, absYpos + hitYpos, absXpos + hitXpos + width, absYpos + hitYpos + 2));
		}
		else if (BTWN(getStartTime(), timing.time, getEndTime())) // misses
		{
			if (timing.data == INT_MAX)
			{
				int hitXpos = timing.key * (this->width / KEYS) + (this->absXpos - this->width / 2);
				int width = ((this->width) / KEYS) - (2 * KEYS);

				int hitPos = (*viewTime) - timing.time;
				int hitYpos = hitPos*zoom + height;

				_win.driver->draw2DRectangle(SColor(255, 200, 0, 0), rect<s32>(absXpos + hitXpos, absYpos + hitYpos, absXpos + hitXpos + width, absYpos + hitYpos + 3));
			}	
		}
	}
}
void HitTimingGraph::genStdBins()
{
	setBinTable(
	{ 
		0.000,
		4.500,
		10.000,
		20.000,
		40.000,
		80.500,
		160.000,
		320.000 
	});

	bins.resize(binTable.size() + 1);
	for (int& bin : bins)
		bin = 0;

	Analyzer* analyzer = AnalysisStruct::beatmapAnalysis.getAnalyzer("Tap Deviation (ms)");
	if (analyzer == nullptr) return;

	for (auto& timing : *(analyzer->getData()))
	{
		for (int i = 0; i < binTable.size() - 1; i++)
		{
			// miss
			if (timing.data > binTable[binTable.size() - 1])
			{
				bins[binTable.size()]++;
				break;
			}

			// hit
			if (BTWN(binTable[i], abs(timing.data), binTable[i + 1]))
			{
				bins[i]++;
				break;
			}
		}
	}

	textBins.resize(binTable.size() + 1);
	for (int i = 0; i < binTable.size(); i++)
		textBins[i] = (std::to_string((int)binTable[i])/* + " - " + std::to_string((int)binTable[i + 1])*/).data();
	textBins[binTable.size()] = "MISSES";
}