示例#1
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;
}
示例#2
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;
}
示例#3
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;
}
示例#4
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;
}
示例#5
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;
}
示例#6
0
void PasPlay::Draw(){
// 描画処理
	mBackground->Draw();					// 背景
	mUnitAdmin->Draw();						// ゲームオブジェクト
	DrawPlayerStatusBar(200);				// ステータスバー

	if(flgWarning)	{ DrawWarning();	}	// ワーニング

	BoardStatus tmpBoard;
	mScoreBoard->Draw(GetBoardStatus(&tmpBoard));	// スコアボード

	/*==  ================*/
	if(flgStart)	{ DrawStart();		}	// ミッションスタート
	if(flgClear)	{ DrawClear();		}	// ミッションクリア
	if(flgGameOver)	{ DrawGameOver();	}	// ゲームオーバー
	if(flgResult)	{ DrawResult();		}	// リザルト

//	DrawDebug();
}
示例#7
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;
}
示例#8
0
文件: Game.cpp 项目: yangzhiming/popo
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;
	}
}
示例#9
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;
}
示例#10
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
}