Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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++;
}