void Console::Draw(void) { static DWORD count = GetTickCount(); EnterCriticalSection(&Vars.cConsoleSection); if (IsVisible()) { POINT size = GetScreenSize(); int xsize = size.x; int ysize = size.y; size = CalculateTextLen("@", Vars.dwConsoleFont); int charwidth = size.x; int charheight = max(12, size.y / 2 + 2); // the default console height is 30% of the screen size int height = ((int)(((double)ysize) * .3) / charheight) * charheight + charheight; lineWidth = xsize - (2 * charwidth); lineCount = height / charheight; int cmdsize = 0; int cmdlines = 0; std::list<std::wstring> cmdsplit; if (IsEnabled()) { std::wstring cmdstr = cmd.str(); if (cmdstr.length() > 0) { SplitLines(cmdstr, Console::MaxWidth(), L' ', cmdsplit); cmdsize = CalculateTextLen(cmdsplit.back().c_str(), Vars.dwConsoleFont).x; cmdlines += cmdsplit.size() - 1; } } Console::height = height + (cmdlines * charheight) + 6; // draw the box large enough to hold the whole thing D2GFX_DrawRectangle(0, 0, xsize, Console::height, 0xdf, 0); std::deque<std::wstring>::reverse_iterator it = lines.rbegin(); if (scrollIndex == 0 && lines.size() == lineCount && IsEnabled()) // handle index 0, top of console it++; for (int i = lineCount - (int)IsEnabled(); i > 0 && it != lines.rend(); i--, it++) myDrawText(it->c_str(), charwidth, 4 + (i * charheight), 0, Vars.dwConsoleFont); if (IsEnabled()) { if (cmdsplit.size() > 0) { int dy = height + 3; for (std::list<std::wstring>::iterator it2 = cmdsplit.begin(); it2 != cmdsplit.end(); it2++, dy += charheight) myDrawText(it2->c_str(), charwidth, dy, 0, Vars.dwConsoleFont); } myDrawText(L">", 1, Console::height - 3, 0, Vars.dwConsoleFont); DWORD tick = GetTickCount(); if ((tick - count) < 600) { int lx = cmdsize + charwidth, ly = Console::height - (charheight / 3); D2GFX_DrawRectangle(lx, ly, lx + ((charwidth * 2) / 3), ly + 2, 0xFF, 0x07); } else if ((tick - count) > 1100) count = tick; } } LeaveCriticalSection(&Vars.cConsoleSection); }
void Console::Draw(void) { // update the hooks to their necessary values static DWORD count = 0; if(!IsReady()) Initialize(); if(IsVisible()) { if(count % 15 == 0 && IsEnabled()) cursor->SetIsVisible(!cursor->GetIsVisible()); // TODO: make this respect wrapping char* t = const_cast<char*>(text->GetText()); uint width = GetScreenSize().x; POINT textlen = CalculateTextLen(t, 0); int newsize = textlen.x + text->GetX(); cursor->SetX(newsize); cursor->SetX2(newsize); if(box->GetXSize() != width) { // screen resolution reset, time to adjust all coordinates as necessary // TODO: fix up the lines when the screen resizes box->SetXSize(width); } } count++; }
void Console::Initialize(void) { if(!initialized) { EnterCriticalSection(&Vars.cConsoleSection); POINT size = GetScreenSize(); int xsize = size.x; int ysize = size.y; // the console height is 30% of the screen size int height = (int)(((double)ysize)*.3); size = CalculateTextLen(">", 0); int charsize = size.x; int charheight = size.y-10; int cx = charsize+9; box = new BoxHook(NULL, 0, 0, xsize, height, 0xdf, 0); prompt = new TextHook(NULL, ">", 1, height, 0, 0); text = new TextHook(NULL, "", charsize+5, height, 0, 0); // the cursor's height is basically hand-crafted, if you change // the font, make sure to double check the char height cursor = new LineHook(NULL, cx, height-charheight, cx, height-2, 0xff); for(unsigned int i = 0; i < lineCount; i++) { lineBuffers[i] = new TextHook(NULL, "", 2+charheight, 2+charheight+(i*charheight), 0, 0); lineBuffers[i]->SetIsVisible(false); } box->SetIsVisible(false); prompt->SetIsVisible(false); text->SetIsVisible(false); cursor->SetIsVisible(false); initialized = true; LeaveCriticalSection(&Vars.cConsoleSection); } }
void Console::Draw(void) { static DWORD count = 0; EnterCriticalSection(&Vars.cConsoleSection); if(IsVisible()) { POINT size = GetScreenSize(); int xsize = size.x; int ysize = size.y; // the default console height is 30% of the screen size int height = (int)(((double)ysize)*.3); size = CalculateTextLen(">", 0); int charsize = size.x; int charheight = size.y-10; int cx = charsize+9; int linelen = 115; Console::height = height; int cmdsize = CalculateTextLen(cmd.str().c_str(), 0).x; if((cmdsize/xsize) > 0) Console::height += (cmdsize/xsize)*charheight + 1; // draw the box large enough to hold the whole thing D2GFX_DrawRectangle(0, 0, xsize, Console::height, 0xdf, 0); std::deque<std::string>::reverse_iterator it = lines.rbegin(); for(int i = lineCount-1; i >= 0 && it != lines.rend(); i--, it++) { if(CalculateTextLen(it->c_str(), 0).x > (xsize - (2+charheight)*2)) { std::list<std::string> buf; SplitLines(*it, linelen, ' ', buf); for(std::list<std::string>::iterator it = buf.begin(); it != buf.end(); it++) myDrawText(it->c_str(), 2+charheight, 2+charheight+((i--)*charheight), 0, 0); } else myDrawText(it->c_str(), 2+charheight, 2+charheight+(i*charheight), 0, 0); } if(IsEnabled()) { myDrawText(">", 1, height, 0, 0); int lx = cx + cmdsize - charsize + 5, ly = height-charheight; if(count % 30) D2GFX_DrawLine(lx, ly, lx, height-2, 0xFF, 0xFF); std::string cmdstr = cmd.str(); if(cmdstr.length() > 0) { if((cmdsize/xsize) > 0) { std::list<std::string> lines; SplitLines(cmdstr, linelen, ' ', lines); int i = 0; for(std::list<std::string>::iterator it = lines.begin(); it != lines.end(); it++, i++) myDrawText(it->c_str(), charsize+5, height+(charheight*i)+1, 0, 0); } else myDrawText(cmdstr.c_str(), charsize+5, height+1, 0, 0); } } } LeaveCriticalSection(&Vars.cConsoleSection); count++; }