From c8080cb0251890b3a9513756e2438ca0f03ffbd6 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 14 Aug 2012 19:18:59 +0100 Subject: [PATCH] Photon wavlength info for HUD, fixes #111 --- src/game/GameView.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 13cac1aad..45addebf1 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1839,6 +1839,7 @@ void GameView::OnDraw() if(showHud && !introText) { //Draw info about simulation under cursor + int wavelengthGfx = 0; std::stringstream sampleInfo; sampleInfo.precision(2); if(sample.particle.type) @@ -1860,6 +1861,8 @@ void GameView::OnDraw() sampleInfo << c->ElementResolve(sample.particle.type) << ", Pressure: " << std::fixed << sample.AirPressure; sampleInfo << ", Temp: " << std::fixed << sample.particle.temp -273.15f; } + if(sample.particle.type == PT_PHOT) + wavelengthGfx = sample.particle.ctype; } else { @@ -1870,6 +1873,43 @@ void GameView::OnDraw() g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5); g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255*0.75); +#ifndef OGLI + if(wavelengthGfx) + { + int i, cr, cg, cb, j, h = 3, x = XRES-19-textWidth, y = 10; + int tmp; + g->fillrect(x, y, 30, h, 64, 64, 64, 255); // coords -1 size +1 to work around bug in fillrect - TODO: fix fillrect + for (i = 0; i < 30; i++) + { + if ((wavelengthGfx >> i)&1) + { + // Need a spread of wavelengths to get a smooth spectrum, 5 bits seems to work reasonably well + if (i>2) tmp = 0x1F << (i-2); + else tmp = 0x1F >> (2-i); + + cg = 0; + cb = 0; + cr = 0; + + for (j=0; j<12; j++) + { + cr += (tmp >> (j+18)) & 1; + cb += (tmp >> j) & 1; + } + for (j=0; j<13; j++) + cg += (tmp >> (j+9)) & 1; + + tmp = 624/(cr+cg+cb+1); + cr *= tmp; + cg *= tmp; + cb *= tmp; + for (j=0; jblendpixel(x+29-i,y+j,cr>255?255:cr,cg>255?255:cg,cb>255?255:cb,255); + } + } + } +#endif + if(showDebug) { sampleInfo.str(std::string());