void DrawAxis(float size)
	{
		glLineWidth(5.0f);
		g_MVPMatrix->PushMatrix();

		SetUtilsColor(1.0f, 0.0f, 0.0f, 1.0f);
		DrawBegin(CL_LINES);
		clVertex3(0.0f, 0.0f, 0.0f);
		clVertex3(size, 0.0f, 0.0f);
		DrawEnd();

		SetUtilsColor(0.0f, 1.0f, 0.0f, 1.0f);
		DrawBegin(CL_LINES);
		clVertex3(0.0f, 0.0f, 0.0f);
		clVertex3(0.0f, size, 0.0f);
		DrawEnd();

		SetUtilsColor(0.0f, 0.0f, 1.0f, 1.0f);
		DrawBegin(CL_LINES);
		clVertex3(0.0f, 0.0f, 0.0f);
		clVertex3(0.0f, 0.0f, size);
		DrawEnd();

		g_MVPMatrix->PopMatrix();
		glLineWidth(1.0f);
	}
	void DrawLine(const Vector3Df& l1, const Vector3Df& l2)
	{
		DrawBegin(CL_LINES);
		clVertex3(l1.x, l1.y, l1.z);
		clVertex3(l2.x, l2.y, l2.z);
		DrawEnd();
	}
void AABoundingBox::DebugDraw() const
{
    SetUtilsColor(Color::White);
    GetCurrentProgram()->SetUniform("emissive", 1.0f);

    DrawBegin(CL_LINES);
    clVertex3(m_min.x, m_min.y, m_min.z);
    clVertex3(m_min.x, m_min.y, m_max.z);
    clVertex3(m_min.x, m_min.y, m_min.z);
    clVertex3(m_max.x, m_min.y, m_min.z);
    clVertex3(m_min.x, m_min.y, m_max.z);
    clVertex3(m_max.x, m_min.y, m_max.z);
    clVertex3(m_max.x, m_min.y, m_min.z);
    clVertex3(m_max.x, m_min.y, m_max.z);

    clVertex3(m_min.x, m_max.y, m_min.z);
    clVertex3(m_min.x, m_max.y, m_max.z);
    clVertex3(m_min.x, m_max.y, m_min.z);
    clVertex3(m_max.x, m_max.y, m_min.z);
    clVertex3(m_min.x, m_max.y, m_max.z);
    clVertex3(m_max.x, m_max.y, m_max.z);
    clVertex3(m_max.x, m_max.y, m_min.z);
    clVertex3(m_max.x, m_max.y, m_max.z);

    clVertex3(m_min.x, m_min.y, m_min.z);
    clVertex3(m_min.x, m_max.y, m_min.z);
    clVertex3(m_min.x, m_min.y, m_max.z);
    clVertex3(m_min.x, m_max.y, m_max.z);
    clVertex3(m_max.x, m_min.y, m_min.z);
    clVertex3(m_max.x, m_max.y, m_min.z);
    clVertex3(m_max.x, m_min.y, m_max.z);
    clVertex3(m_max.x, m_max.y, m_max.z);
    DrawEnd();
}
	void DeferredLight_Ambient::ApplyLight(const Vector3Df& cameraPos, GLTexture* renderTarget0, GLTexture* renderTarget1, GLTexture* renderTarget2)
	{
		UNUSED(cameraPos)
        UNUSED(renderTarget0)
        UNUSED(renderTarget1)
        UNUSED(renderTarget2)

		g_MVPMatrix->SetProjectionMode(CL_ORTHOGRAPHIC);

		g_MVPMatrix->PushMatrix();
		g_MVPMatrix->LoadIdentity();

		SetGLProgram(m_glProgram);

		SetUniform("lightColor", m_color);
		SetUniform("intensity", m_intensity);

		DrawBegin(CL_QUADS);
		{
			clVertex3(0.0f,			 0.0f,		     0.0f);
			clVertex3(WINDOW_WIDTHf, 0.0f,		     0.0f);
			clVertex3(WINDOW_WIDTHf, WINDOW_HEIGHTf, 0.0f);
			clVertex3(0.0f,		     WINDOW_HEIGHTf, 0.0f);
		}
		DrawEnd();

		SetGLProgram(NULL);

		g_MVPMatrix->SetProjectionMode(CL_PROJECTION);
		g_MVPMatrix->PopMatrix();
	}
Beispiel #5
0
extern "C" int rglGetScreenPitch()
{
    int pitch;
    DrawBegin();
    pitch = scrpitch;
    DrawEnd();
    return pitch;
}
	void DrawLineCircle(const Vector2Df& pos, float spaceing, float radius)
	{
		float radSpacing = DegreesToRadians(spaceing);

		DrawBegin(CL_LINES);
		for(float i = 0; i <= 2 * 3.1415f; i += radSpacing)
		{
			clVertex3(pos.x + cos(i) * radius,				pos.y + sin(i) * radius, 0.0f);
			clVertex3(pos.x + cos(i + radSpacing) * radius,	pos.y + sin(i + radSpacing) * radius, 0.0f);
		}
		DrawEnd();
	}
Beispiel #7
0
BOOL wbSetPixel(HANDLE handle, int xPos, int yPos, COLORREF color)
{
    BOOL bResult;

	if(!DrawStart(handle))
		return FALSE;

	bResult = (SetPixel(hdcMain, xPos, yPos, color) != (COLORREF)-1);

	if(!DrawEnd(handle))
		return FALSE;
	return bResult;
}
Beispiel #8
0
COLORREF wbGetPixel(HANDLE handle, int xPos, int yPos)
{
	COLORREF clResult;

	if(!DrawStart(handle))
		return CLR_INVALID;

	clResult = GetPixel(hdcMain, xPos, yPos);

	if(!DrawEnd(handle))
		return CLR_INVALID;
	return clResult;
}
	void DrawPlus(float x, float y, float z, float size)
	{
		DrawBegin(CL_LINES);
		clVertex3(x - size, y, z);
		clVertex3(x + size, y, z);

		clVertex3(x, y - size, z);
		clVertex3(x, y + size, z);

		clVertex3(x, y, z - size);
		clVertex3(x, y, z + size);
		DrawEnd();
	}
	void DrawArrow(const Vector3Df& from, const Vector3Df& to)
	{
		SetUtilsColor(1.0f, 1.0f, 1.0f, g_CurrentColor.a);

		DrawBegin(CL_LINES);
		clColor4(1.0f, 0.0f, 0.0f, g_CurrentColor.a);
		clVertex3(from.x, from.y, from.z);
		clColor4(0.0f, 1.0f, 0.0f, g_CurrentColor.a);
		clVertex3(to.x, to.y, to.z);
		DrawEnd();

		SetUtilsColor(0.0f, 1.0f, 0.0f, g_CurrentColor.a);
		DrawPlus(to, 0.1f);
	}
Beispiel #11
0
BOOL wbDrawBitmap(HANDLE handle, HBITMAP hbmBits, int xPos, int yPos, int nWidth, int nHeight, int xOffset, int yOffset, COLORREF clTransp)
{
	BOOL bRet;
	HDC hdcMem;
	HBITMAP hbmMask = NULL;

	if(!hbmBits)
		return FALSE;

	if(!DrawStart(handle))
		return FALSE;

	if(nWidth < 1 && nHeight < 1) {
		DWORD dwDim;

		dwDim = wbGetImageDimensions(hbmBits);
		nWidth = LOWORD(dwDim);
		nHeight = HIWORD(dwDim);
	}

	if(clTransp != CLR_INVALID)
		hbmMask = wbCreateMask(hbmBits, clTransp);

	hdcMem = CreateCompatibleDC(hdcMain);
	SelectObject(hdcMem, hbmBits);

	if(clTransp != CLR_INVALID) {

		bRet = MaskBlt(hdcMain,
			xPos, yPos, nWidth, nHeight,
			hdcMem,
			xOffset, yOffset,
			hbmMask,
			xOffset, yOffset,
			MAKEROP4(SRCPAINT, SRCCOPY));

	} else {
		bRet = BitBlt(hdcMain, xPos, yPos, nWidth, nHeight, hdcMem, xOffset, yOffset, SRCCOPY);
	}
	DeleteDC(hdcMem);

	if((clTransp != CLR_INVALID) && hbmMask)
		DeleteObject(hbmMask);

	if(!DrawEnd(handle))
		return FALSE;

	return bRet;
}
Beispiel #12
0
BOOL wbDrawEllipse(HANDLE handle, int xPos, int yPos, int nWidth, int nHeight, COLORREF cl, BOOL bFilled, UINT nLineWidth, UINT nLineStyle)
{
	if(cl == CLR_INVALID)
		return FALSE;

	if(!DrawStart(handle))
		return FALSE;

	if(bFilled) {

		HBRUSH hbr;
		HBRUSH hbrOld;

		hbr = CreateSolidBrush(cl);
		hbrOld = SelectObject(hdcMain, hbr);

		Ellipse(hdcMain, xPos, yPos, xPos + nWidth, yPos + nHeight);

		SelectObject(hdcMain, hbrOld);
		DeleteObject(hbr);

	} else {

		HPEN hpen;
		HBRUSH hbr;
		HPEN hpenOld;
		HBRUSH hbrOld;


		hbr = GetStockObject(NULL_BRUSH);
		hpen = CreatePenFromStyle(cl, nLineWidth, nLineStyle, PS_ENDCAP_ROUND | PS_JOIN_ROUND);
		hbrOld = SelectObject(hdcMain, hbr);
		hpenOld = SelectObject(hdcMain, hpen);

		Ellipse(hdcMain, xPos, yPos, xPos + nWidth, yPos + nHeight);

		SelectObject(hdcMain, hpenOld);
		SelectObject(hdcMain, hbrOld);
		DeleteObject(hpen);
		DeleteObject(hbr);
	}

	if(!DrawEnd(handle))
		return FALSE;
	return TRUE;
}
Beispiel #13
0
extern "C" void rglswDeleteWindow(GLint ihwnd)
{
    HWND hwnd = (HWND)ihwnd;

    DrawEnd();
    finiObjects(TRUE);

    if (scratch_buffer != NULL)
    {
        free(scratch_buffer);
        scratch_buffer = NULL;
    }
    if (scratch_buffer_2 != NULL)
    {
        free(scratch_buffer_2);
        scratch_buffer_2 = NULL;
    }
}
Beispiel #14
0
BOOL wbDrawRect(HANDLE handle, int xPos, int yPos, int nWidth, int nHeight, COLORREF cl, BOOL bFilled, UINT nLineWidth, UINT nLineStyle)
{
	HGDIOBJ hOldObj;

	if(cl == CLR_INVALID)
		return FALSE;

	if(!DrawStart(handle))
		return FALSE;

	if(bFilled) {

		HBRUSH hbr;

		hbr = CreateSolidBrush(cl);
		hOldObj = SelectObject(hdcMain, hbr);

		PatBlt(hdcMain, xPos, yPos, nWidth,	nHeight, PATCOPY); // Faster than FillRect()

		SelectObject(hdcMain, hOldObj);

		DeleteObject(hbr);

	} else {

		HPEN hpen;

		hpen = CreatePenFromStyle(cl, nLineWidth, nLineStyle, PS_ENDCAP_SQUARE | PS_JOIN_MITER);
		hOldObj = SelectObject(hdcMain, hpen);

		MoveToEx(hdcMain, xPos, yPos, NULL);
		LineTo(hdcMain, xPos + nWidth - 1, yPos);
		LineTo(hdcMain, xPos + nWidth - 1, yPos + nHeight - 1);
		LineTo(hdcMain, xPos, yPos + nHeight - 1);
		LineTo(hdcMain, xPos, yPos);

		SelectObject(hdcMain, hOldObj);
		DeleteObject(hpen);
	}

	if(!DrawEnd(handle))
		return FALSE;
	return TRUE;
}
Beispiel #15
0
static void rglCopyToScratchBuffer()
{
    BOOL bSave = bSaveFramebuffer;

    if (!useDirectDraw) return;

    bSaveFramebuffer = FALSE;

    if (!DrawBegin())
    {
        bSaveFramebuffer = bSave;
        return;
    }
    rglswPitchedCopy(scratch_buffer, scratch_pitch,
                     scrbuf, scrpitch,
                     SCRWIDTH, SCRHEIGHT);
    DrawEnd();

    bSaveFramebuffer = bSave;
}
	void FullScreenPass(int width, int height)
	{
		g_MVPMatrix->PushMatrix();
		g_MVPMatrix->LoadIdentity();
		g_MVPMatrix->SetProjectionMode(CL_ORTHOGRAPHIC);
		DrawBegin(CL_QUADS);
		{
			clVertex3(0.0f,  0.0f, 0.0f);
			clVertex3((float)width, 0.0f, 0.0f);
			clVertex3((float)width, (float)height, 0.0f);
			clVertex3(0.0f,  (float)height, 0.0f);

			clTexCoord(0, 0);
			clTexCoord(1, 0);
			clTexCoord(1, 1);
			clTexCoord(0, 1);
		}
		DrawEnd();
		g_MVPMatrix->SetProjectionMode(CL_PROJECTION);
		g_MVPMatrix->PopMatrix();
	}
Beispiel #17
0
// ////////////////////////////////////////////////////////////////////////////
BOOL runKeyMapEditor(void)
{
	UDWORD id;

	id = widgRunScreen(psWScreen);						// Run the current set of widgets 
	
	if(id == KM_RETURN)			// return
	{
		saveKeyMap();
		changeTitleMode(TITLE);
	}
	if(id == KM_DEFAULT)	
	{
		keyClearMappings();
		keyInitMappings(TRUE);
		widgDelete(psWScreen,FRONTEND_BACKDROP);// readd the widgets
		startKeyMapEditor(FALSE);
	}
	else if( id>=KM_START && id<=KM_END)
	{
		 pushedKeyMap(id);
	}
	
	if(selectedKeyMap)
	{
		id = scanKeyBoardForBinding();
		if(id)
		{
			pushedKeyCombo(id); 
		}
	}
	
	DrawBegin();
	StartCursorSnap(&InterfaceSnap);
	widgDisplayScreen(psWScreen);						// show the widgets currently running
	DrawEnd();

	return TRUE;
}
Beispiel #18
0
    void Draw()
    {
        DrawBegin();

        // Draw the background TODO: Fix glitches over the edge of the level?
        for (int x=0;x<=(320/16);x++)
        {
            for (int y=0;y<=(240/16);y++)
            {
                DrawTile(x*16-(xscroll/4)%16,y*16-(yscroll/4)%16,
                        (x+1)*16-(xscroll/4)%16,(y+1)*16-(yscroll/4)%16,17);
            }
        }

        // Draw each tile plane
        for (IPlane i = Planes.begin(); i != Planes.end(); i++) (*i)->Draw(-xscroll,-yscroll,rsb);

        // Draw each plumber
        for (IMover i = Movers.begin(); i != Movers.end(); i++) (*i)->Draw(-xscroll,-yscroll);

        // Draw each fallers
        for (IFaller i = Fallers.begin(); i != Fallers.end(); i++) (*i)->Draw(-xscroll,-yscroll);
        
        // Diagnostic information HUD
        if (PBACK->jumping)
          DrawTile(0,240-16,16,240,484);

        if (PBACK->jumpthrust>0)
          DrawTile(16,240-16,32,240,4*32+19);

        if (diagCollision)
          DrawTile(32,240-16,48,240,64*32+9);

        // Relinquish the GL
        DrawEnd();

        static unsigned int errstore=0;
        glError("Game::Draw()", &errstore);
    }
Beispiel #19
0
BOOL wbDrawLine(HANDLE handle, int x0, int y0, int x1, int y1, COLORREF cl, UINT nLineWidth, UINT nLineStyle)
{
	HPEN hpen;
	HGDIOBJ hOldObj;

	if(!DrawStart(handle))
		return FALSE;

	if(cl == CLR_INVALID)
		return FALSE;

	hpen = CreatePenFromStyle(cl, nLineWidth, nLineStyle, PS_ENDCAP_ROUND | PS_JOIN_ROUND);
	hOldObj = SelectObject(hdcMain, hpen);
	MoveToEx(hdcMain, x0, y0, NULL);
	LineTo(hdcMain, x1, y1);
	SelectObject(hdcMain, hOldObj);
	DeleteObject(hpen);

	if(!DrawEnd(handle))
		return FALSE;
	return TRUE;
}
	void DeferredLight_Directional::ApplyLight(const Vector3Df& cameraPos, GLTexture* renderTarget0, GLTexture* renderTarget1, GLTexture* renderTarget2)
	{
		UNUSED(cameraPos)

		g_MVPMatrix->SetProjectionMode(CL_ORTHOGRAPHIC);

		g_MVPMatrix->PushMatrix();
		g_MVPMatrix->LoadIdentity();

		SetGLProgram(m_glProgram);

        SetUtilsColor(m_color);

		SetTexture("renderTarget0", renderTarget0);
		SetTexture("renderTarget1", renderTarget1);
		SetTexture("renderTarget2", renderTarget2);

		SetUniform("intensity", m_intensity);
		SetUniform("lightDir", m_lightDir);

		DrawBegin(CL_QUADS);
		{
			clVertex3(0.0f,					0.0f,				 0.0f);
			clVertex3((float)WINDOW_WIDTH,	0.0f,				 0.0f);
			clVertex3((float)WINDOW_WIDTH, (float)WINDOW_HEIGHT, 0.0f);
			clVertex3(0.0f,				   (float)WINDOW_HEIGHT, 0.0f);

			clTexCoord(0, 0);
			clTexCoord(1, 0);
			clTexCoord(1, 1);
			clTexCoord(0, 1);
		}
		DrawEnd();

		SetGLProgram(NULL);

		g_MVPMatrix->SetProjectionMode(CL_PROJECTION);
		g_MVPMatrix->PopMatrix();
	}
Beispiel #21
0
void Game::Draw(Graphics* pGraph)
{
	Map::GetInstance()->Draw(pGraph);

	switch ( m_gsState )
	{
	case gsStart:
		DrawStart(pGraph);
		break;

	case gsNormal:
		DrawNormal(pGraph);
		break;

	case gsEnd:
		DrawEnd(pGraph);
		break;

	default:
		ASSERT(FALSE);
		break;
	}
}
Beispiel #22
0
BOOL wbDrawText(HANDLE handle, LPCTSTR pszString, int xPos, int yPos, int nWidth, int nHeight, int nFont, DWORD dwFlags)
{
	int nLen;
	BOOL bRet;
	COLORREF clOld;
	HFONT hfOld;
	RECT rc;
	PFONT pfont;
	DWORD dwWinFlags;

	if(!pszString || !*pszString)
		return FALSE;

	pfont = wbGetFont(nFont);
	if(!pfont)
		return FALSE;

	if(!DrawStart(handle))
		return FALSE;

	clOld = SetTextColor(hdcMain, pfont->color);
	SetBkMode(hdcMain, TRANSPARENT);
	hfOld = SelectObject(hdcMain, pfont->hFont);
	nLen = wcslen(pszString);

	if(nWidth > 0 && nHeight > 0) {
		rc.left = xPos;
		rc.right = xPos + nWidth;
		rc.top = yPos;
		rc.bottom = yPos + nHeight;

		// Text flags

		if(dwFlags == 0) {												// No flags: default font

			dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_VCENTER;

		} else if(BITTEST(dwFlags, WBC_MULTILINE)) {					// Multi-line

			dwWinFlags = DT_EDITCONTROL | DT_WORDBREAK;

		} else if(BITTEST(dwFlags, WBC_TOP)) {							// Top

			if(BITTEST(dwFlags, WBC_CENTER))
				dwWinFlags = DT_CENTER | DT_SINGLELINE | DT_TOP;
			else if(BITTEST(dwFlags, WBC_RIGHT))
				dwWinFlags = DT_RIGHT | DT_SINGLELINE | DT_TOP;
			else // WBC_LEFT == 0
				dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_TOP;

		} else if(BITTEST(dwFlags, WBC_BOTTOM)) {						// Bottom

			if(BITTEST(dwFlags, WBC_CENTER))
				dwWinFlags = DT_CENTER | DT_SINGLELINE | DT_BOTTOM;
			else if(BITTEST(dwFlags, WBC_RIGHT))
				dwWinFlags = DT_RIGHT | DT_SINGLELINE | DT_BOTTOM;
			else // WBC_LEFT == 0
				dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_BOTTOM;

		} else {														// Middle (WBC_MIDDLE == 0)

			if(BITTEST(dwFlags, WBC_CENTER))
				dwWinFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
			else if(BITTEST(dwFlags, WBC_RIGHT))
				dwWinFlags = DT_RIGHT | DT_SINGLELINE | DT_VCENTER;
			else // WBC_LEFT == 0
				dwWinFlags = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
		}

		if(BITTEST(dwFlags, WBC_ELLIPSIS))
			dwWinFlags |= DT_END_ELLIPSIS | DT_PATH_ELLIPSIS;

		bRet = DrawTextEx(hdcMain, (LPTSTR)pszString, nLen, &rc, dwWinFlags, NULL);
	} else {
		bRet = TextOut(hdcMain, xPos, yPos, (LPTSTR)pszString, nLen);
	}

	SelectObject(hdcMain, hfOld);
	SetBkMode(hdcMain, OPAQUE);
	SetTextColor(hdcMain, clOld);

	if(!DrawEnd(handle))
		return FALSE;

	return bRet;
}
	void DrawDebugBBox(const Vector3Df& pos, const Vector3Df& dimensions)
	{
		float vertices[] =
		{
			-1.0f,  1.0f,  1.0f,
			-1.0f, -1.0f,  1.0f,
			 1.0f, -1.0f,  1.0f,
			 1.0f,  1.0f,  1.0f,

			 1.0f,  1.0f, -1.0f,
			 1.0f, -1.0f, -1.0f,
			-1.0f, -1.0f, -1.0f,
			-1.0f,  1.0f, -1.0f,

			 1.0f, -1.0f,  1.0f,
			 1.0f, -1.0f, -1.0f,
			 1.0f,  1.0f, -1.0f,
			 1.0f,  1.0f,  1.0f,

			-1.0f,  1.0f,  1.0f,
			-1.0f,  1.0f, -1.0f,
			-1.0f, -1.0f, -1.0f,
			-1.0f, -1.0f,  1.0f,

			 1.0f,  1.0f,  1.0f, 
			 1.0f,  1.0f, -1.0f, 
			-1.0f, 1.0f, -1.0f, 
			-1.0f, 1.0f,  1.0f, 

			 1.0f, -1.0f, -1.0f,
			 1.0f, -1.0f,  1.0f,
			-1.0f, -1.0f,  1.0f,
			-1.0f, -1.0f, -1.0f,
		};

		const float hx = dimensions.x * 0.5f;
		const float hy = dimensions.y * 0.5f;
		const float hz = dimensions.z * 0.5f;

		for(int i = 0; i < 72; i += 3)
		{
			vertices[i] *= hx;
			vertices[i + 1] *= hy;
			vertices[i + 2] *= hz;

			vertices[i] += pos.x;
			vertices[i + 1] += pos.y;
			vertices[i + 2] += pos.z;
		}

		float currentAlpha = g_CurrentColor.a;

		glEnable(GL_BLEND);
		glDisable(GL_DEPTH_TEST);
		g_CurrentColor.a = .1f;
		DrawBegin(CL_LINES);
			for(int i = 0; i < 6; ++i)
			{
				const int ROW_INDEX = i * 12;
				for(int j = 0; j < 4; ++j)
				{
					const int index1 = ROW_INDEX + j * 3;
					const int index2 = ROW_INDEX + (j == 3 ? 0 : (j + 1) * 3);

					clVertex3(vertices[index1], vertices[index1 + 1], vertices[index1 + 2]);
					clVertex3(vertices[index2], vertices[index2 + 1], vertices[index2 + 2]);
				}
			}
		DrawEnd();

		glEnable(GL_DEPTH_TEST);
		g_CurrentColor.a = currentAlpha;
		DrawBegin(CL_LINES);
		for(int i = 0; i < 6; ++i)
		{
			const int ROW_INDEX = i * 12;
			for(int j = 0; j < 4; ++j)
			{
				const int index1 = ROW_INDEX + j * 3;
				const int index2 = ROW_INDEX + (j == 3 ? 0 : (j + 1) * 3);

				clVertex3(vertices[index1], vertices[index1 + 1], vertices[index1 + 2]);
				clVertex3(vertices[index2], vertices[index2 + 1], vertices[index2 + 2]);
			}
		}
		DrawEnd();

		g_CurrentColor.a = .05f;
		DrawBegin(CL_QUADS);
		for(int i = 0; i < 72; i += 3)
		{
			clVertex3(vertices[i], vertices[i+1], vertices[i+2]);
		}
		DrawEnd();
	}
Beispiel #24
0
extern "C" void UnlockBuffers()
{
    DrawEnd();
}
Beispiel #25
0
void gwinPutChar(GHandle gh, char c) {
	#define gcw		((GConsoleObject *)gh)
	uint8_t			width, fy;

	if (gh->vmt != &consoleVMT || !gh->font)
		return;

	fy = gdispGetFontMetric(gh->font, fontHeight);

	#if GWIN_CONSOLE_ESCSEQ
		/**
		 * Handle escape sequences
		 * 			ESC color		Change subsequent text color
		 * 							color:	"0" = black, "1" = red, "2" = green, "3" = yellow, "4" = blue,
		 * 									"5" = magenta, "6" = cyan, "7" = white
		 * 			ESC C			Revert subsequent text color to the window default
		 * 			ESC u			Turn on underline
		 * 			ESC U			Turn off underline
		 * 			ESC b			Turn on bold
		 * 			ESC B			Turn off bold
		 * 			ESC J			Clear the window
		 */
		switch (gcw->escstate) {
		case 1:
			gcw->escstate = 0;
			if (ESCtoAttr(c, &gcw->currattr)) {
				if (gcw->cx == 0 && gcw->cy == 0)
					gcw->startattr = gcw->currattr;
				else {
					putCharInBuffer(gcw, 27);
					putCharInBuffer(gcw, c);
				}
			} else {
				switch(c) {
				case 'J':
					// Clear the console and reset the cursor
					clearBuffer(gcw);
					if (DrawStart(gh)) {
						gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor);
						DrawEnd(gh);
					}
					gcw->cx = 0;
					gcw->cy = 0;
					gcw->startattr = gcw->currattr;
					break;
				}
			}
			return;
		}
	#endif

	/**
	 * Special Characters:
	 *
	 * Carriage returns and line feeds (\r & \n) are handled in unix terminal cooked mode; that is,
	 * line feeds perform both actions and carriage-returns are ignored.
	 *
	 * if GWIN_CONSOLE_ESCSEQ is turned on then ESC is trapped ready for the escape command.
	 *
	 * All other characters are treated as printable.
	 */
	switch (c) {
	case '\n':
		// clear to the end of the line
		#if GWIN_CONSOLE_USE_CLEAR_LINES
			if (gcw->cx == 0 && gcw->cy+fy < gh->height && DrawStart(gh)) {
				gdispGFillArea(gh->display, gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor);
				DrawEnd(gh);
			}
		#endif
		// update the cursor
		gcw->cx = 0;
		gcw->cy += fy;
		putCharInBuffer(gcw, '\n');
		// We use lazy scrolling here and only scroll when the next char arrives
		return;

	case '\r':
		// gcw->cx = 0;
		return;

	#if GWIN_CONSOLE_ESCSEQ
		case 27:		// ESC
			gcw->escstate = 1;
			return;
	#endif
	}

	// Characters with no width are ignored
	if (!(width = gdispGetCharWidth(c, gh->font)))
		return;

	// Allow space for (very crude) bold
	#if GWIN_CONSOLE_ESCSEQ
		if ((gcw->currattr & ESC_BOLD))
			width++;
	#endif

	// Do we need to go to the next line to fit this character?
	if (gcw->cx + width >= gh->width) {
		gcw->cx = 0;
		gcw->cy += fy;
		putCharInBuffer(gcw, '\n');
	}

	// Do we need to scroll to fit this character?
	if (gcw->cy + fy > gh->height) {
		#if GWIN_CONSOLE_USE_HISTORY && GWIN_CONSOLE_BUFFER_SCROLLING
			if (gcw->buffer) {
				// Scroll the buffer and then redraw using the buffer
				scrollBuffer(gcw);
				if (DrawStart(gh)) {
					HistoryuRedraw(gh);
					DrawEnd(gh);
				}
			} else
		#endif
		#if GDISP_NEED_SCROLL
			{
				// Scroll the console using hardware
				scrollBuffer(gcw);
				if (DrawStart(gh)) {
					gdispGVerticalScroll(gh->display, gh->x, gh->y, gh->width, gh->height, fy, gh->bgcolor);
					DrawEnd(gh);
				}

				// Set the cursor to the start of the last line
				gcw->cx = 0;
				gcw->cy = (((coord_t)(gh->height/fy))-1)*fy;
			}
		#else
			{
				// Clear the console and reset the cursor
				clearBuffer(gcw);
				if (DrawStart(gh)) {
					gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor);
					DrawEnd(gh);
				}
				gcw->cx = 0;
				gcw->cy = 0;
				#if GWIN_CONSOLE_ESCSEQ
					gcw->startattr = gcw->currattr;
				#endif
			}
		#endif
	}

	// Save the char
	putCharInBuffer(gcw, c);

	// Draw the character
	if (DrawStart(gh)) {

		// If we are at the beginning of a new line clear the line
		#if GWIN_CONSOLE_USE_CLEAR_LINES
			if (gcw->cx == 0)
				gdispGFillArea(gh->display, gh->x, gh->y + gcw->cy, gh->width, fy, gh->bgcolor);
		#endif

		#if GWIN_CONSOLE_USE_FILLED_CHARS
			gdispGFillChar(gh->display, gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw), gh->bgcolor);
		#else
			gdispGDrawChar(gh->display, gh->x + gcw->cx, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw));
		#endif

		#if GWIN_CONSOLE_ESCSEQ
			// Draw the underline
			if ((gcw->currattr & ESC_UNDERLINE))
				gdispGDrawLine(gh->display, gh->x + gcw->cx, gh->y + gcw->cy + fy - gdispGetFontMetric(gh->font, fontDescendersHeight),
											gh->x + gcw->cx + width + gdispGetFontMetric(gh->font, fontCharPadding), gh->y + gcw->cy + fy - gdispGetFontMetric(gh->font, fontDescendersHeight),
											ESCPrintColor(gcw));
			// Bold (very crude)
			if ((gcw->currattr & ESC_BOLD))
				gdispGDrawChar(gh->display, gh->x + gcw->cx + 1, gh->y + gcw->cy, c, gh->font, ESCPrintColor(gcw));
		#endif

		DrawEnd(gh);
	}

	// Update the cursor
	gcw->cx += width + gdispGetFontMetric(gh->font, fontCharPadding);

	#undef gcw
}