| 4287 | } |
| 4288 | |
| 4289 | void PixelGameEngine::UpdateConsole() |
| 4290 | { |
| 4291 | if (GetKey(keyConsoleExit).bPressed) |
| 4292 | { |
| 4293 | TextEntryEnable(false); |
| 4294 | bConsoleSuspendTime = false; |
| 4295 | bConsoleShow = false; |
| 4296 | return; |
| 4297 | } |
| 4298 | |
| 4299 | // Keep Console sizes based in real screen dimensions |
| 4300 | vConsoleCharacterScale = olc::vf2d(1.0f, 2.0f) / (olc::vf2d(vViewSize) * vInvScreenSize); |
| 4301 | vConsoleSize = (vViewSize / olc::vi2d(8, 16)) - olc::vi2d(2, 4); |
| 4302 | |
| 4303 | // If console has changed size, simply reset it |
| 4304 | if (vConsoleSize.y != sConsoleLines.size()) |
| 4305 | { |
| 4306 | vConsoleCursor = { 0,0 }; |
| 4307 | sConsoleLines.clear(); |
| 4308 | sConsoleLines.resize(vConsoleSize.y); |
| 4309 | } |
| 4310 | |
| 4311 | auto TypeCharacter = [&](const char c) |
| 4312 | { |
| 4313 | if (c >= 32 && c < 127) |
| 4314 | { |
| 4315 | sConsoleLines[vConsoleCursor.y].append(1, c); |
| 4316 | vConsoleCursor.x++; |
| 4317 | } |
| 4318 | |
| 4319 | if (c == '\n' || vConsoleCursor.x >= vConsoleSize.x) |
| 4320 | { |
| 4321 | vConsoleCursor.y++; vConsoleCursor.x = 0; |
| 4322 | } |
| 4323 | |
| 4324 | if (vConsoleCursor.y >= vConsoleSize.y) |
| 4325 | { |
| 4326 | vConsoleCursor.y = vConsoleSize.y - 1; |
| 4327 | for (int i = 1; i < vConsoleSize.y; i++) |
| 4328 | sConsoleLines[i - 1] = sConsoleLines[i]; |
| 4329 | sConsoleLines[vConsoleCursor.y].clear(); |
| 4330 | } |
| 4331 | }; |
| 4332 | |
| 4333 | // Empty out "std::cout", parsing as we go |
| 4334 | while (ssConsoleOutput.rdbuf()->sgetc() != -1) |
| 4335 | { |
| 4336 | char c = ssConsoleOutput.rdbuf()->sbumpc(); |
| 4337 | TypeCharacter(c); |
| 4338 | } |
| 4339 | |
| 4340 | // Draw Shadow |
| 4341 | GradientFillRectDecal({ 0,0 }, olc::vf2d(vScreenSize), olc::PixelF(0, 0, 0.5f, 0.5f), olc::PixelF(0, 0, 0.25f, 0.5f), olc::PixelF(0, 0, 0.25f, 0.5f), olc::PixelF(0, 0, 0.25f, 0.5f)); |
| 4342 | |
| 4343 | // Draw the console buffer |
| 4344 | SetDecalMode(olc::DecalMode::NORMAL); |
| 4345 | for (int32_t nLine = 0; nLine < vConsoleSize.y; nLine++) |
| 4346 | DrawStringDecal(olc::vf2d(1, 1 + float(nLine)) * vConsoleCharacterScale * 8.0f, sConsoleLines[nLine], olc::WHITE, vConsoleCharacterScale); |
nothing calls this directly
no test coverage detected