Пример #1
0
void drawText(int x, int y, char* text, int sizeInPts, color backgroundColor, color textColor)
{
	int h = -MulDiv(sizeInPts, GetDeviceCaps(_paintDC, LOGPIXELSY), 72);

	HFONT font = CreateFont(h,0,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
									CLIP_DEFAULT_PRECIS,NONANTIALIASED_QUALITY, VARIABLE_PITCH,TEXT("Terminal"));
    
	HFONT oldFont = (HFONT)SelectObject(_paintDC, font);

	SetBkColor(_paintDC, backgroundColor);
	SetTextColor(_paintDC, textColor);

	RECT measureRect;
	DrawTextEx(_paintDC, text, strlen(text), &measureRect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE, NULL);


	RECT drawRect;
	drawRect.left = x;
	drawRect.top = y - (measureRect.bottom - measureRect.top);
	drawRect.right = x + (measureRect.right - measureRect.left);
	drawRect.bottom = y;

	DrawTextEx(_paintDC, text, strlen(text), &drawRect, DT_LEFT | DT_SINGLELINE, NULL);

	SelectObject(_paintDC, oldFont);
	DeleteObject(font);

}
Пример #2
0
// Ending Screen Draw logic
void DrawEndingScreen(void)
{
    DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), DARKGRAY);

    DrawTextEx(font, "CONGRATULATIONS!", (Vector2){ 50, 160 }, font.baseSize*3, 2, Fade(WHITE, alpha));
    DrawTextEx(font, "SKULLY ESCAPED!", (Vector2){ 100, 300 }, font.baseSize*3, 2, Fade(WHITE, alpha));
    
    if ((framesCounter > 180) && ((framesCounter/40)%2)) DrawText("PRESS ENTER or CLICK", 380, 545, 40, BLACK);
}
Пример #3
0
void SimpleCanvas::drawString(int x0, int y0, const TCHAR* str)
{
	int bkMode = SetBkMode(offScreenDC(), TRANSPARENT);
	RECT r = { x0, y0, x0, y0 };
	DrawTextEx(offScreenDC(), const_cast<TCHAR*>(str), -1, &r, DT_LEFT | DT_TOP | DT_CALCRECT, 0);
	DrawTextEx(offScreenDC(), const_cast<TCHAR*>(str), -1, &r, DT_LEFT | DT_TOP, 0);
	SetBkMode(offScreenDC(), bkMode);
	InvalidateRect(handle(), &r, FALSE);
}
Пример #4
0
// Gameplay Screen Draw logic
void DrawAisle01Screen(void)
{
    DrawTexture(background, -scroll, 0, WHITE);
    
    // Draw monsters
	DrawMonster(lamp, scroll);
    DrawMonster(picture, scroll);
    
    // Draw door
    Vector2 doorScrollPos = { doorCenter.position.x - scroll, doorCenter.position.y };
    if (doorCenter.selected) DrawTextureRec(doors, doorCenter.frameRec, doorScrollPos, GREEN);
    else DrawTextureRec(doors, doorCenter.frameRec, doorScrollPos, WHITE);
    
    doorScrollPos = (Vector2){ doorLeft.position.x - scroll, doorLeft.position.y };
    if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, GREEN);
    else DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, WHITE);
    
    doorScrollPos = (Vector2){ doorRight.position.x - scroll, doorRight.position.y };
    if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorScrollPos, GREEN);
    else DrawTextureRec(doors, doorRight.frameRec, doorScrollPos, WHITE);
    
    // Draw messsages
    if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f));
    else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f));

    if (msgState == 0) 
    {
        DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.baseSize, 2, WHITE);
    }
    else if (msgState == 1)
    {
        DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.baseSize, 2, WHITE);
        
        if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK);
    }
    else if (msgState == 2)
    {
        if ((msgCounter/30)%2)
        {
            DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.baseSize*2, 2, WHITE);
            
            DrawRectangleRec(lamp.bounds, Fade(RED, 0.6f));
            DrawRectangleRec(picture.bounds, Fade(RED, 0.6f));
        }
    }
    else
    {
        if ((monsterHover) && ((msgCounter/30)%2))
        {
            DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f));
            DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK);
        }
    }

    DrawPlayer();       // NOTE: Also draws mouse pointer!
}
Пример #5
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading");

    const char msgBm[64] = "THIS IS AN AngelCode SPRITE FONT";
    const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF";

    // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
    SpriteFont fontBm = LoadSpriteFont("resources/fonts/bmfont.fnt");       // BMFont (AngelCode)
    SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf");  // TTF font

    Vector2 fontPosition;

    fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2;
    fontPosition.y = screenHeight/2 - fontBm.size/2 - 80;

    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update variables here...
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON);
            DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadSpriteFont(fontBm);     // AngelCode SpriteFont unloading
    UnloadSpriteFont(fontTtf);    // TTF SpriteFont unloading

    CloseWindow();                // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
Пример #6
0
// Ending Screen Draw logic
void DrawEndingScreen(void)
{
    // TODO: Draw ENDING screen here!
    DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE);
    DrawTextEx(font, "ENDING SCREEN", (Vector2){ 20, 10 }, font.baseSize*3, 4, DARKBLUE);
    DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE);
}
Пример #7
0
// Mission Screen Draw logic
void DrawMissionScreen(void)
{
    // Draw MISSION screen here!
    DrawTexture(texBackground, 0,0, WHITE);
    DrawTexturePro(texBackline, sourceRecBackLine, destRecBackLine, (Vector2){0,0},0, Fade(WHITE, fadeBackLine));

    if (writeNumber) DrawTextEx(fontMission, FormatText("Filtración #%02i ", currentMission + 1), numberPosition, missionSize + 10, 0, numberColor);
    DrawTextEx(fontMission, TextSubtext(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor);
    if (writeKeyword && blinkKeyWord) DrawTextEx(fontMission, FormatText("Keyword: %s", missions[currentMission].key), keywordPosition, missionSize + 10, 0, keywordColor);

    if (showButton)
    {
        if (!writeEnd) DrawButton("saltar");
        else DrawButton("codificar");
    }
}
Пример #8
0
void CFilePreviewCtrl::DoPaintEmpty(HDC hDC)
{
    RECT rcClient;
    GetClientRect(&rcClient);

    HFONT hOldFont = (HFONT)SelectObject(hDC, m_hFont);

    FillRect(hDC, &rcClient, (HBRUSH)GetStockObject(WHITE_BRUSH));

    CRect rcText;
    DrawTextEx(hDC, m_sEmptyMsg.GetBuffer(0), -1, &rcText, DT_CALCRECT, NULL);

    rcText.MoveToX(rcClient.right/2-rcText.right/2);
    DrawTextEx(hDC, m_sEmptyMsg.GetBuffer(0), -1, &rcText, DT_LEFT, NULL);

    SelectObject(hDC, hOldFont);
}
Пример #9
0
void CIVInfoLabel::DrawLabel(CDC & dcTarget)
{
	CRect rc;
	GetClientRect (&rc);

	CDC dc;	
	dc.CreateCompatibleDC (&dcTarget);

	CBitmap bmp;
	bmp.CreateCompatibleBitmap (&dcTarget, rc.Width(), rc.Height());
	
	dc.SelectObject (&bmp);
	
	CBrush brush;
	brush.CreateSysColorBrush (COLOR_3DFACE);

	dc.SelectObject (&brush);
	dc.PatBlt (0,0, rc.Width(), rc.Height(), PATCOPY);
	

	CFont font;
	font.CreateStockObject (DEFAULT_GUI_FONT);
	dc.SelectObject (&font);

	dc.SetBkColor ( GetSysColor (COLOR_3DFACE));
	dc.SetTextColor ( GetSysColor (COLOR_WINDOWTEXT));

	CRect rcCalc = rc;
	
	LPTSTR szStr =  (LPTSTR) (LPCTSTR) m_strText;

	DrawTextEx (dc, szStr, -1, &rcCalc,  DT_CALCRECT | DT_CENTER | DT_WORDBREAK, NULL);
	
	int nOffset = rcCalc.Height() < rc.Height() 
		? ( rc.Height() - rcCalc.Height() ) / 2 : 0;

	rcCalc = rc;
	rcCalc.top += nOffset;

	DrawTextEx (dc, szStr, -1, &rcCalc,  DT_CENTER | DT_WORDBREAK, NULL);
	
	dcTarget.BitBlt(rc.left,rc.top,rc.Width(),rc.Height(),&dc,0,0,SRCCOPY);
}
Пример #10
0
void DrawHeader(HDC hdc, TCHAR *s, int y, int width) {

	SelectObject(hdc, hfontSegoe);

	TEXTMETRIC tm;
	GetTextMetrics(hdc, &tm);

	RECT r = {8, y, width, y + tm.tmHeight*3/2};

	SetBkMode(hdc, TRANSPARENT);
	SetTextColor(hdc, RGB(0, 51, 153));
	DrawTextEx(hdc, s, -1, &r, DT_LEFT | DT_VCENTER | DT_SINGLELINE, NULL);

	DrawTextEx(hdc, s, -1, &r, DT_LEFT | DT_CALCRECT | DT_VCENTER | DT_SINGLELINE, NULL);
	SelectObject(hdc, GetStockObject(DC_PEN));
	SetDCPenColor(hdc, RGB(176, 191, 222));
	MoveToEx(hdc, r.right + tm.tmAveCharWidth/2, (r.bottom - r.top)/2 + 1, NULL);
	LineTo(hdc, width - 28, (r.bottom - r.top)/2 + 1);
}
Пример #11
0
// Draw text (using default font)
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used
// NOTE: chars spacing is proportional to fontSize
void DrawText(const char* text, int posX, int posY, int fontSize, Color color)
{
    Vector2 position = { (float)posX, (float)posY };
       
    int defaultFontSize = 10;   // Default Font chars height in pixel
    
    if (fontSize < defaultFontSize) fontSize = defaultFontSize;
    
    int spacing = fontSize / defaultFontSize;
    
    DrawTextEx(defaultFont, text, position, fontSize, spacing, color);
}
Пример #12
0
void OnScreenDisplayWnd::paint(HDC hdc)
{
   RECT rect;
   HFONT  defFont;

   GetClientRect(m_hWnd, &rect);

   defFont = (HFONT)SelectObject(hdc, m_font);
   SetTextColor(hdc, m_fgColor);
   SetBkMode(hdc, TRANSPARENT);
   DrawTextEx(hdc, m_text, -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_NOPREFIX, NULL);
   SelectObject(hdc, defFont);
}
Пример #13
0
// Draw text (using default font)
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used
// NOTE: chars spacing is proportional to fontSize
void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
{
    // Check if default font has been loaded
    if (defaultFont.texture.id != 0)
    {
        Vector2 position = { (float)posX, (float)posY };

        int defaultFontSize = 10;   // Default Font chars height in pixel
        if (fontSize < defaultFontSize) fontSize = defaultFontSize;
        int spacing = fontSize/defaultFontSize;

        DrawTextEx(GetDefaultFont(), text, position, (float)fontSize, spacing, color);
    }
}
Пример #14
0
void CLCDText::DrawText(CLCDGfx &rGfx)
{
    // draw the text
    RECT rBoundary = { 0, 0,0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 
    DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rBoundary, m_nTextFormat, &m_dtp);
    
//    LCDUITRACE(_T("Drawing %s at (%d,%d)-(%d-%d) lmargin=%d, rmargin=%d\n"),
//         m_sText.c_str(), m_Origin.x, m_Origin.y, GetWidth(), GetHeight(),
//         m_dtp.iLeftMargin, m_dtp.iRightMargin);

    if (m_bInverted)
    {
        InvertRect(rGfx.GetHDC(), &rBoundary);
    }
}
Пример #15
0
void CLCDText::DrawText(CLCDGfx &rGfx)
{
    // draw the text
    RECT rBoundary = { 0, 0,0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 
    DrawTextEx(rGfx.GetHDC(), m_szText, m_nTextLength, &rBoundary, m_nTextFormat, &m_dtp);
    
//    Printf(_T("Drawing %s at (%d,%d)-(%d-%d) lmargin=%d, rmargin=%d\n"),
//         m_szText, m_Origin.x, m_Origin.y, GetWidth(), GetHeight(),
//         m_dtp.iLeftMargin, m_dtp.iRightMargin);

    if (m_bInverted)
    {
        InvertRect(rGfx.GetHDC(), &rBoundary);
    }
}
Пример #16
0
//************************************************************************
// CLCDGfx::DrawText
//************************************************************************
void CLCDGfx::DrawText(int nX, int nY, LPCTSTR sText)
{
	// map mode text, with transparency
	int nOldMapMode = SetMapMode(m_hDC, MM_TEXT);
	int nOldBkMode = SetBkMode(m_hDC, TRANSPARENT); 

	DRAWTEXTPARAMS dtp;
	memset(&dtp, 0, sizeof(DRAWTEXTPARAMS));
	dtp.cbSize = sizeof(DRAWTEXTPARAMS);

	RECT rBounds = {nX,nY,GetClipWidth(),GetClipHeight()};
	DrawTextEx(m_hDC, (LPTSTR)sText, (int)mir_tstrlen(sText), &rBounds, (DT_LEFT | DT_NOPREFIX), &dtp);

	// restores
	SetMapMode(m_hDC, nOldMapMode);
	SetBkMode(m_hDC, nOldBkMode);
}
Пример #17
0
//************************************************************************
// draws the label
//************************************************************************
bool CLCDLabel::Draw(CLCDGfx *pGfx)
{
	if(!CLCDTextObject::Draw(pGfx))
		return false;

	SelectObject(pGfx->GetHDC(),m_hFont);

	int iTop = (int)(GetHeight()-(m_vLines.size()*m_iFontHeight))/2;///2;//()/2;
	RECT rBoundary = {0,iTop,GetWidth(), GetHeight()-iTop}; 

	vector<tstring>::iterator iter = m_vLines.begin();
	while(!m_vLines.empty() && iter != m_vLines.end())
	{
		DrawTextEx(pGfx->GetHDC(), (LPTSTR)(*iter).c_str(), (*iter).length(), &rBoundary, m_iTextFormat, &m_dtp);
		rBoundary.top += m_iFontHeight;
		iter++;
	}
	return true;
}
/**   paint text in window   **/
void paintText(HDC hdc, LPCTSTR tsText){

    /**   write character string to location x, y   **/

    /* TODO: This code needs work, our exact needs for text display is
             not completely defined yet                                  */
    int width = 150;
    int height = 60;

    /**   like everything we draw to the screen   **/
    /**   create the text rectangle               **/
    textRect.left = (mwinRect.right - width) / 2 ;
    textRect.top = 60;
    textRect.right = textRect.left + width;
    textRect.bottom = textRect.top + height;

    /**   draw the text using rectangle   **/
    DrawTextEx(hdc, (LPSTR)tsText, _tcslen(tsText), &textRect, DT_CENTER, 0);

}
Пример #19
0
/*
 * tooltip_draw_text - ツールチップの描画
 */
static void tooltip_draw_text(const TOOLTIP_INFO *ti, const HDC hdc, RECT *rect)
{
	DRAWTEXTPARAMS dtp;
	HBRUSH hbrush;
	HFONT hRetFont;
#ifdef TOOLTIP_COLOR
	DWORD color_infoback = (*option.tooltip_color_back.color_str != TEXT('\0')) ?
		option.tooltip_color_back.color : GetSysColor(COLOR_INFOBK);
	DWORD color_infotext = (*option.tooltip_color_text.color_str != TEXT('\0')) ?
		option.tooltip_color_text.color : GetSysColor(COLOR_INFOTEXT);
#else	// TOOLTIP_COLOR
	DWORD color_infoback = GetSysColor(COLOR_INFOBK);
	DWORD color_infotext = GetSysColor(COLOR_INFOTEXT);
#endif	// TOOLTIP_COLOR

	// 背景の塗りつぶし
	hbrush = CreateSolidBrush(color_infoback);
	FillRect(hdc, rect, hbrush);
	DeleteObject(hbrush);

	if (ti->buf != NULL) {
		// テキストの描画
		hRetFont = SelectObject(hdc, (ti->hfont != NULL) ? ti->hfont : GetStockObject(DEFAULT_GUI_FONT));
		SetRect(rect,
			rect->left + option.tooltip_margin_x,
			rect->top + option.tooltip_margin_y,
			rect->right - option.tooltip_margin_x,
			rect->bottom - option.tooltip_margin_y);

		SetTextColor(hdc, color_infotext);
		SetBkColor(hdc, color_infoback);
		SetBkMode(hdc, TRANSPARENT);

		ZeroMemory(&dtp, sizeof(DRAWTEXTPARAMS));
		dtp.cbSize = sizeof(DRAWTEXTPARAMS);
		dtp.iTabLength = option.tooltip_tab_length;
		DrawTextEx(hdc, ti->buf, lstrlen(ti->buf),
			rect, DT_EDITCONTROL | DT_NOCLIP | DT_EXPANDTABS | DT_TABSTOP | DT_NOPREFIX, &dtp);
		SelectObject(hdc, hRetFont);
	}
}
Пример #20
0
void notify(const char* ctitle, const char* ctext) {
    WCHAR btitle[1024];
    WCHAR btext[1024];
    MultiByteToWideChar(CP_UTF8,0,ctitle,-1,btitle,1024);
    MultiByteToWideChar(CP_UTF8,0,ctext,-1,btext,1024);

    LPWSTR content = (LPWSTR) malloc(2048);
    swprintf(content, L"%s\n%s", btitle, btext);
    SetWindowText(label, content);

    HDC dc = GetDC(label);

    lRect->right = 290;
    DrawTextEx(dc, content,(int) wcslen(content),lRect, DT_CALCRECT | DT_WORDBREAK ,NULL);

    ShowWindow(hWnd,SW_SHOW);
    SetWindowPos(label,NULL, 0, 0, lRect->right - lRect->left, lRect->bottom - lRect->top, SWP_NOMOVE|SWP_NOZORDER);
    SetWindowPos(hWnd,HWND_TOPMOST, x_pos, y_pos, lRect->right - lRect->left, lRect->bottom - lRect->top, SWP_SHOWWINDOW); //|SWP_NOMOVE
    SetTimer(hWnd,TIMER_HIDE,5500,NULL);
    free(content);
}
Пример #21
0
void BottomAlignStatic(HWND hStatic)
{
    HWND hParent;
    RECT rc;
    RECT rcStatic;
    int cyText;
    HDC hdc;
    TCHAR szText[512];

    hParent = GetParent(hStatic);
    GetWindowText(hStatic, szText, ARRAYSIZE(szText));

    GetWindowRect(hStatic, &rcStatic);
    MapWindowRect(HWND_DESKTOP, hParent, &rc);

    hdc = GetDC(hStatic);

    // We need to bottom align the prompt text
    SelectObject(hdc, GetWindowFont(hStatic));

    // Ask DrawText for the right cx and cy
    rc.left     = 0;
    rc.top      = 0;
    rc.right    = rcStatic.right - rcStatic.left;
    rc.bottom   = rcStatic.bottom - rcStatic.top;
    cyText = DrawTextEx(hdc, szText, -1, &rc,
            DT_CALCRECT | DT_WORDBREAK | DT_EXPANDTABS |
            DT_NOPREFIX | DT_EXTERNALLEADING, NULL);

    // This should automatically deselect the font
    ReleaseDC(hStatic, hdc);

    if (cyText < rcStatic.bottom-rcStatic.top)
    {
        rcStatic.top = rcStatic.bottom - cyText;
        SetWindowPos(hStatic, NULL, rcStatic.left, rcStatic.top,
                rcStatic.right-rcStatic.left, cyText, SWP_NOZORDER);
    }
}
Пример #22
0
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage");

    const char msg1[50] = "THIS IS A custom SPRITE FONT...";
    const char msg2[50] = "...and this is ANOTHER CUSTOM font...";
    const char msg3[50] = "...and a THIRD one! GREAT! :D";

    // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
    Font font1 = LoadFont("resources/custom_mecha.png");          // Font loading
    Font font2 = LoadFont("resources/custom_alagard.png");        // Font loading
    Font font3 = LoadFont("resources/custom_jupiter_crash.png");  // Font loading

    Vector2 fontPosition1 = { screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2,
                              screenHeight/2 - font1.baseSize/2 - 80 };

    Vector2 fontPosition2 = { screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2,
                              screenHeight/2 - font2.baseSize/2 - 10 };

    Vector2 fontPosition3 = { screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2,
                              screenHeight/2 - font3.baseSize/2 + 50 };

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update variables here...
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE);
            DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE);
            DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadFont(font1);      // Font unloading
    UnloadFont(font2);      // Font unloading
    UnloadFont(font3);      // Font unloading

    CloseWindow();                // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
Пример #23
0
//************************************************************************
// CLCDInput::Draw
//************************************************************************
bool CLCDInput::Draw(CLCDGfx *pGfx)
{
	if(!CLCDTextObject::Draw(pGfx))
		return false;
	
	
	SelectObject(pGfx->GetHDC(),m_hFont);
				
	RECT rBoundary = { 0, 0,0 + GetWidth(), 0 + GetHeight() }; 
	int iLine = m_iLinePosition;
	int iEndLine = m_iLinePosition + m_iLineCount;
	int iLen = 0;
	TCHAR *pcOffset = NULL;
	while(iLine <  iEndLine && iLine < m_vLineOffsets.size())
	{
		// Calculate the text length
		if(iLine < m_vLineOffsets.size() -1)
		{
			iLen = m_vLineOffsets[iLine+1].iOffset - m_vLineOffsets[iLine].iOffset;
			// Draw the linebreak marker
			if(m_bShowSymbols && m_vLineOffsets[iLine+1].bLineBreak)
				pGfx->DrawFilledRect(m_vLineOffsets[iLine].iWidth+1,rBoundary.top+m_iFontHeight/3,m_iFontHeight/3,m_iFontHeight/3);
		}
		else iLen = (int)m_strText.length() - m_vLineOffsets[iLine].iOffset;
		
		// Draw the text
		pcOffset = (TCHAR*)m_strText.c_str() + m_vLineOffsets[iLine].iOffset;
		DrawTextEx(pGfx->GetHDC(),
					(LPTSTR)pcOffset,
					iLen,
					&rBoundary,
					m_iTextFormat,
					&m_dtp);

		// Draw the input cursor
		if(m_pInput && m_bShowMarker && m_Marker[0].iLine == iLine)
		{
			// insert-mode cursor
			if(m_bInsert ||m_Marker[0].iXWidth == 1)
			{
				pGfx->DrawFilledRect(m_Marker[0].iXLine,
				m_iFontHeight*(iLine-m_iLinePosition),
				1,
				m_iFontHeight);
			}
			// replace-mode cursor
			else
			{
				RECT rMarker = {m_Marker[0].iXLine,
								m_iFontHeight*(iLine-m_iLinePosition),
								m_Marker[0].iXLine+m_Marker[0].iXWidth,
								m_iFontHeight*(iLine-m_iLinePosition+1)};
				InvertRect(pGfx->GetHDC(),&rMarker);
			}
		}

		rBoundary.top += m_iFontHeight;
		rBoundary.bottom += m_iFontHeight;

		iLine++;
	}
	return true;
}
Пример #24
0
void _draw_listview(
		LPDRAWITEMSTRUCT itst
	)
{
	DRAWTEXTPARAMS dtp         = { sizeof(dtp) };
	LVCOLUMN       lvc         = { sizeof(lvc) };
	wchar_t        s_text[200] = { 0 };
	int            cx, cy, k   = 0;
	int            offset      = 0;
	int            icon;
	BOOL           is_root;
	int            col_cnt     = Header_GetItemCount( ListView_GetHeader( itst->hwndItem ) );
	LVITEM         lvitem      = { LVIF_TEXT | LVIF_PARAM, itst->itemID, 0, 0, 0, s_text, countof(s_text) };
	COLORREF       bgcolor     = ListView_GetBkColor( itst->hwndItem );

	ListView_GetItem( itst->hwndItem, &lvitem );
	is_root = _is_root_item( lvitem.lParam );

	{
		void *user_data = wnd_get_long( __lists[HMAIN_DRIVES], GWL_USERDATA );
		if (user_data != NULL)
		{
			MessageBox( __dlg, s_text, NULL, 0 );
		}
	}

	if ( ( itst->itemState & ODS_SELECTED ) && IsWindowEnabled( itst->hwndItem ) /*&& ( lvitem.lParam != NULL )*/ ) 
	{
		if ( GetFocus( ) == itst->hwndItem )
		{
			bgcolor = CL_WHITE;
		} else {
			bgcolor = _cl( COLOR_BTNFACE, 80 );
		}
	}
	if ( is_root ) 
	{
		bgcolor = _cl( COLOR_BTNSHADOW, 60 );
	}
	if ( _is_marked_item(lvitem.lParam) ) 
	{
		bgcolor = _cl( COLOR_BTNSHADOW, 35 );
	}
	
	_fill( itst->hDC, &itst->rcItem, bgcolor );

	for ( ; k < col_cnt; k++ )
	{
		lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_IMAGE;
		ListView_GetColumn( itst->hwndItem, k, &lvc );

		itst->rcItem.left  = k ? itst->rcItem.right : 0;
		itst->rcItem.right = itst->rcItem.left + lvc.cx;

		lvitem.iItem       = itst->itemID; 
		lvitem.iSubItem    = k;

		ListView_GetItem( itst->hwndItem, &lvitem );
		dtp.iLeftMargin = dtp.iRightMargin = 5;		

		if ( (!itst->rcItem.left) && _is_icon_show( itst->hwndItem, k ) )
		{
			ImageList_GetIconSize( __dsk_img, &cx, &cy );
			offset = lvitem.lParam && !is_root ? 25 : 3;

			itst->rcItem.left += offset + cy + ( lvitem.lParam && !is_root ? 8 : 4 );
			icon = 0;

			if (! is_root ) 
			{
				if ( _is_splited_item(lvitem.lParam) ) icon = 1;
				if ( _is_cdrom_item(lvitem.lParam) )   icon = 2;
			}

			ImageList_Draw(
				__dsk_img, icon, itst->hDC, offset, itst->rcItem.top + 3, ILD_TRANSPARENT
				);
		} else 
		{
			offset = 0;
		}
		if ( offset && is_root )
		{
			DrawState(
				itst->hDC, 0, NULL, (LPARAM)s_text, 0, 
				itst->rcItem.left+5, itst->rcItem.top, 0, 0, DST_PREFIXTEXT | DSS_MONO
				);
		} else 
		{
			if ( wcslen(s_text) != 0 ) 
			{
				COLORREF text_color = GetSysColor( COLOR_WINDOWTEXT );

				if ( !_is_active_item(lvitem.lParam) )
				{
					text_color = GetSysColor( COLOR_GRAYTEXT );
				}
				SetTextColor( itst->hDC, text_color );

				if ( k >= 4 )
				{
					SelectObject( itst->hDC, __font_bold );
				}
				if ( !IsWindowEnabled( itst->hwndItem ) )
				{
					SetTextColor( itst->hDC, GetSysColor(COLOR_GRAYTEXT) );

					DrawTextEx(
						itst->hDC, s_text, -1, &itst->rcItem,
						DT_END_ELLIPSIS | ((lvc.fmt & LVCFMT_RIGHT) ? DT_RIGHT : FALSE), &dtp
						);
				} else 
				{
					DrawTextEx(
						itst->hDC, s_text, -1, &itst->rcItem,
						DT_END_ELLIPSIS | ((lvc.fmt & LVCFMT_RIGHT) ? DT_RIGHT : FALSE), &dtp
						);
					/*
					if ( GetFocus( ) == itst->hwndItem )
					{
						DrawFocusRect( itst->hDC, &itst->rcItem );
					}
					*/
				}
			}
		}
	}							
}
Пример #25
0
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 1280;
    const int screenHeight = 720;
    
    // Init window
    ShowLogo();
    InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
    
    // Initialize audio device
    InitAudioDevice();      
    
    // Load game resources: textures
    Texture2D sky = LoadTexture("resources/sky.png");
    Texture2D mountains = LoadTexture("resources/mountains.png");
    Texture2D sea = LoadTexture("resources/sea.png");
    Texture2D title = LoadTexture("resources/title.png");
    Texture2D turtle = LoadTexture("resources/turtle.png");
    Texture2D gamera = LoadTexture("resources/gamera.png");
    Texture2D shark = LoadTexture("resources/shark.png");
    Texture2D orca = LoadTexture("resources/orca.png");
    Texture2D swhale = LoadTexture("resources/swhale.png");
    Texture2D fish = LoadTexture("resources/fish.png");
    Texture2D gframe = LoadTexture("resources/gframe.png");
    
    // Load game resources: fonts
    SpriteFont font = LoadSpriteFont("resources/komika.png");
    
    // Load game resources: sounds
    Sound eat = LoadSound("resources/eat.wav");
    Sound die = LoadSound("resources/die.wav");
    Sound growl = LoadSound("resources/gamera.wav");
    
    // Start playing streaming music
    PlayMusicStream("resources/speeding.ogg");

    // Define scrolling variables
    int backScrolling = 0;
    int seaScrolling = 0;
    
    // Define current screen
    GameScreen currentScreen = TITLE;
    
    // Define player variables
    int playerRail = 1;
    Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
    bool gameraMode = false;
    
    // Define enemies variables
    Rectangle enemyBounds[MAX_ENEMIES];
    int enemyRail[MAX_ENEMIES];
    int enemyType[MAX_ENEMIES];
    bool enemyActive[MAX_ENEMIES];
    float enemySpeed = 10;
    
    // Init enemies variables
    for (int i = 0; i < MAX_ENEMIES; i++)
    {
        // Define enemy type (all same probability)
        //enemyType[i] = GetRandomValue(0, 3);
    
        // Probability system for enemies type
        int enemyProb = GetRandomValue(0, 100);
        
        if (enemyProb < 30) enemyType[i] = 0;
        else if (enemyProb < 60) enemyType[i] = 1;
        else if (enemyProb < 90) enemyType[i] = 2;
        else enemyType[i] = 3;

        // define enemy rail
        enemyRail[i] = GetRandomValue(0, 4);

        // Make sure not two consecutive enemies in the same row
        if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
        
        enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
        enemyActive[i] = false;
    }
    
    // Define additional game variables
    int score = 0;
    float distance = 0.0f;
    int hiscore = 0;
    float hidistance = 0.0f;
    int foodBar = 0;
    int framesCounter = 0;
    
    unsigned char blue = 200;
    float timeCounter = 0;
    
    SetTargetFPS(60);       // Setup game frames per second
    //--------------------------------------------------------------------------------------
    
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        framesCounter++;
        
        // Sea color tint effect
        blue = 210 + 25 * sin(timeCounter);
        timeCounter += 0.01;

        // Game screens management
        switch (currentScreen)
        {
            case TITLE:
            {
                // Sea scrolling
                seaScrolling -= 2;
                if (seaScrolling <= -screenWidth) seaScrolling = 0; 
            
                // Press enter to change to gameplay screen
                if (IsKeyPressed(KEY_ENTER))
                {
                    currentScreen = GAMEPLAY;
                    framesCounter = 0;
                }
                
            } break;
            case GAMEPLAY:
            {
                // Background scrolling logic
                backScrolling--;
                if (backScrolling <= -screenWidth) backScrolling = 0; 
                
                // Sea scrolling logic
                seaScrolling -= (enemySpeed - 2);
                if (seaScrolling <= -screenWidth) seaScrolling = 0; 
            
                // Player movement logic
                if (IsKeyPressed(KEY_DOWN)) playerRail++;
                else if (IsKeyPressed(KEY_UP)) playerRail--;
                
                // Check player not out of rails
                if (playerRail > 4) playerRail = 4;
                else if (playerRail < 0) playerRail = 0;
            
                // Update player bounds
                playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
                
                // Enemies activation logic (every 40 frames)        
                if (framesCounter > 40)
                {
                    for (int i = 0; i < MAX_ENEMIES; i++)
                    {
                        if (enemyActive[i] == false)
                        {
                            enemyActive[i] = true;
                            i = MAX_ENEMIES;
                        }
                    }
                    
                    framesCounter = 0;
                }
                
                // Enemies logic
                for (int i = 0; i < MAX_ENEMIES; i++)
                {
                    if (enemyActive[i])
                    {
                        enemyBounds[i].x -= enemySpeed;
                    }
                    
                    // Check enemies out of screen
                    if (enemyBounds[i].x <= 0 - 128)
                    {
                        enemyActive[i] = false;
                        enemyType[i] = GetRandomValue(0, 3);
                        enemyRail[i] = GetRandomValue(0, 4);
                        
                        // Make sure not two consecutive enemies in the same row
                        if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
                        
                        enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
                    }
                }
                
                if (!gameraMode) enemySpeed += 0.005;
                
                // Check collision player vs enemies
                for (int i = 0; i < MAX_ENEMIES; i++)
                {
                    if (enemyActive[i])
                    {
                        if (CheckCollisionRecs(playerBounds, enemyBounds[i]))
                        {                       
                            if (enemyType[i] < 3)   // Bad enemies
                            {
                                if (gameraMode)
                                {
                                    if (enemyType[i] == 0) score += 50;
                                    else if (enemyType[i] == 1) score += 150;
                                    else if (enemyType[i] == 2) score += 300;
                                    
                                    foodBar += 15;
                                
                                    enemyActive[i] = false;
                                    
                                    // After enemy deactivation, reset enemy parameters to be reused
                                    enemyType[i] = GetRandomValue(0, 3);
                                    enemyRail[i] = GetRandomValue(0, 4);
                                    
                                    // Make sure not two consecutive enemies in the same row
                                    if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
                                    
                                    enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
                                    
                                    PlaySound(eat);
                                }
                                else
                                {
                                    // Player die logic
                                    PlaySound(die);
                                
                                    currentScreen = ENDING;
                                    framesCounter = 0;
                                    
                                    // Save hiscore and hidistance for next game
                                    if (score > hiscore) hiscore = score;
                                    if (distance > hidistance) hidistance = distance;
                                }
                            }
                            else    // Sweet fish
                            {
                                enemyActive[i] = false;
                                enemyType[i] = GetRandomValue(0, 3);
                                enemyRail[i] = GetRandomValue(0, 4);
                                
                                // Make sure not two consecutive enemies in the same row
                                if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
                                
                                enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
                                
                                if (!gameraMode) foodBar += 80;
                                else foodBar += 25;
                                
                                score += 10;
                                
                                if (foodBar == 400)
                                {
                                    gameraMode = true;
                                    
                                    PlaySound(growl);
                                }
                                
                                PlaySound(eat);
                            }
                        }
                    }
                }
                
                // Gamera mode logic
                if (gameraMode)
                {
                    foodBar--;
                    
                    if (foodBar <= 0) 
                    {
                        gameraMode = false;
                        enemySpeed -= 2;
                        if (enemySpeed < 10) enemySpeed = 10;
                    }
                }
        
                // Update distance counter
                distance += 0.5f;
            
            } break;
            case ENDING:
            {
                // Press enter to play again
                if (IsKeyPressed(KEY_ENTER))
                {
                    currentScreen = GAMEPLAY;
                    
                    // Reset player
                    playerRail = 1;
                    playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
                    gameraMode = false;
                    
                    // Reset enemies data
                    for (int i = 0; i < MAX_ENEMIES; i++)
                    {
                        int enemyProb = GetRandomValue(0, 100);
                        
                        if (enemyProb < 30) enemyType[i] = 0;
                        else if (enemyProb < 60) enemyType[i] = 1;
                        else if (enemyProb < 90) enemyType[i] = 2;
                        else enemyType[i] = 3;
                        
                        //enemyType[i] = GetRandomValue(0, 3);
                        enemyRail[i] = GetRandomValue(0, 4);

                        // Make sure not two consecutive enemies in the same row
                        if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
                        
                        enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
                        enemyActive[i] = false;
                    }
                    
                    enemySpeed = 10;
                    
                    // Reset game variables
                    score = 0;
                    distance = 0.0;
                    foodBar = 0;
                    framesCounter = 0;
                }
      
            } break;
            default: break;
        }
        //----------------------------------------------------------------------------------
        
        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();
        
            ClearBackground(RAYWHITE);
            
            // Draw background (common to all screens)
            DrawTexture(sky, 0, 0, WHITE);
            
            DrawTexture(mountains, backScrolling, 0, WHITE);
            DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
            
            if (!gameraMode)
            {
                DrawTexture(sea, seaScrolling, 0, (Color){ 16, 189, blue, 255});
                DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 16, 189, blue, 255});
            }
            else
            {
                DrawTexture(sea, seaScrolling, 0, (Color){ 255, 113, 66, 255});
                DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 255, 113, 66, 255});
            }
            
            switch (currentScreen)
            {
                case TITLE:
                {
                    // Draw title
                    DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
                    
                    // Draw blinking text
                    if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER", (Vector2){ screenWidth/2 - 150, 480 }, GetFontBaseSize(font), 0, WHITE);
                
                } break;
                case GAMEPLAY:
                {
                    // Draw water lines
                    for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f));
                    
                    // Draw player
                    if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
                    else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
                    
                    // Draw player bounding box
                    //if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f));
                    //else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f));
                    
                    // Draw enemies
                    for (int i = 0; i < MAX_ENEMIES; i++)
                    {
                        if (enemyActive[i]) 
                        {
                            // Draw enemies
                            switch(enemyType[i])
                            {
                                case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
                                case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
                                case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
                                case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
                                default: break;
                            }
                            
                            // Draw enemies bounding boxes
                            /*
                            switch(enemyType[i])
                            {
                                case 0: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
                                case 1: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
                                case 2: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
                                case 3: DrawRectangleRec(enemyBounds[i], Fade(GREEN, 0.5f)); break;
                                default: break;
                            }
                            */
                        }
                    }
                    
                    // Draw gameplay interface
                    DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f));
                    DrawRectangle(20, 20, foodBar, 40, ORANGE);
                    DrawRectangleLines(20, 20, 400, 40, BLACK);
                    
                    DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ screenWidth - 300, 20 }, GetFontBaseSize(font), -2, ORANGE);
                    DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 550, 20 }, GetFontBaseSize(font), -2, ORANGE);
                    
                    if (gameraMode)
                    {
                        DrawText("GAMERA MODE", 60, 22, 40, GRAY);
                        DrawTexture(gframe, 0, 0, Fade(WHITE, 0.5f));
                    }
            
                } break;
                case ENDING:
                {
                    // Draw a transparent black rectangle that covers all screen
                    DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
                
                    DrawTextEx(font, "GAME OVER", (Vector2){ 300, 160 }, GetFontBaseSize(font)*3, -2, MAROON);
                    
                    DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ 680, 350 }, GetFontBaseSize(font), -2, GOLD);
                    DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 290, 350 }, GetFontBaseSize(font), -2, GOLD);
                    DrawTextEx(font, FormatText("HISCORE: %04i", hiscore), (Vector2){ 665, 400 }, GetFontBaseSize(font), -2, ORANGE);
                    DrawTextEx(font, FormatText("HIDISTANCE: %04i", (int)hidistance), (Vector2){ 270, 400 }, GetFontBaseSize(font), -2, ORANGE);
                    
                    // Draw blinking text
                    if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER to REPLAY", (Vector2){ screenWidth/2 - 250, 520 }, GetFontBaseSize(font), -2, LIGHTGRAY);
                    
                } break;
                default: break;
            }

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    
    // Unload textures
    UnloadTexture(sky);
    UnloadTexture(mountains);
    UnloadTexture(sea);
    UnloadTexture(gframe);
    UnloadTexture(title);
    UnloadTexture(turtle);
    UnloadTexture(shark);
    UnloadTexture(orca);
    UnloadTexture(swhale);
    UnloadTexture(fish);
    UnloadTexture(gamera);
    
    // Unload font texture
    UnloadSpriteFont(font);
    
    // Unload sounds
    UnloadSound(eat);
    UnloadSound(die);
    UnloadSound(growl);
    
    StopMusicStream();      // Stop music
    CloseAudioDevice();     // Close audio device
    
    CloseWindow();          // Close window and OpenGL context
    //--------------------------------------------------------------------------------------
    
    return 0;
}
Пример #26
0
void CLCDColorText::OnDraw(CLCDGfxBase &rGfx)
{
    if(GetBackgroundMode() == OPAQUE)
    {
        HBRUSH backbrush = CreateSolidBrush(m_backColor);

        // clear the clipped area
        RECT rcClp = { 0, 0, m_Size.cx, m_Size.cy };
        FillRect(rGfx.GetHDC(), &rcClp, backbrush);

        // clear the logical area
        RECT rcLog = { 0, 0, m_sizeLogical.cx, m_sizeLogical.cy };
        FillRect(rGfx.GetHDC(), &rcLog, backbrush);

        DeleteObject(backbrush);
    }

    if(m_nTextLength)
    {

        // map mode text, with transparency
        int nOldMapMode = SetMapMode(rGfx.GetHDC(), MM_TEXT);

        int nOldBkMode = SetBkMode(rGfx.GetHDC(), TRANSPARENT);

        // select current font
        HFONT hOldFont = (HFONT)SelectObject(rGfx.GetHDC(), m_hFont);

        // select color
        COLORREF crOldTextColor = SetTextColor(rGfx.GetHDC(), m_crForegroundColor);

        if (m_bRecalcExtent)
        {
            int nTextFormat;

            RECT rExtent;
            // calculate vertical extent with word wrap
            nTextFormat = (m_nTextFormat | DT_WORDBREAK | DT_CALCRECT);
            rExtent.left = rExtent.top = 0;
            rExtent.right = GetWidth();
            rExtent.bottom = GetHeight();
            DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rExtent, nTextFormat, &m_dtp);
            m_sizeVExtent.cx = rExtent.right;
            m_sizeVExtent.cy = rExtent.bottom;

            // calculate horizontal extent w/o word wrap
            nTextFormat = (m_nTextFormat | DT_CALCRECT);
            rExtent.left = rExtent.top = 0;
            rExtent.right = GetWidth();
            rExtent.bottom = GetHeight();
            DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rExtent, nTextFormat, &m_dtp);
            m_sizeHExtent.cx = rExtent.right;
            m_sizeHExtent.cy = rExtent.bottom;

            m_bRecalcExtent = FALSE;

            //For scrolling
            m_PixelLength = m_sizeHExtent.cx;
            m_StartX = 0;

            if( m_bAutoScroll )
            {
                if( m_PixelLength > GetWidth() )
                {
                    m_ScrollRate = -1*GetHeight();
                }
                else
                {
                    m_ScrollRate = 0;
                }
            }

            if( m_ScrollRate > 0 )
            {
                if( GetWidth() > m_PixelLength + m_ScrollBuffer )
                {
                    m_JumpDistance = -1 * GetWidth();
                }
                else
                {
                    m_JumpDistance = -1 * (m_PixelLength + m_ScrollBuffer);
                }
            }
            else if( m_ScrollRate < 0 )
            {
                if( GetWidth() > m_PixelLength + m_ScrollBuffer )
                {
                    m_JumpDistance = GetWidth();
                }
                else
                {
                    m_JumpDistance = m_PixelLength + m_ScrollBuffer;
                }
            }

            m_LoopX = m_JumpDistance;
        }

        if( IsVisible() )
        {
            if( m_ScrollRate == 0 )
            {
                RECT rBoundary = { 0, 0, 0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 
                DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rBoundary, m_nTextFormat, &m_dtp);
            }
            else
            {
                RECT rBoundaryFirst = { m_StartX, 0, 0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 
                RECT rBoundarySecond = { m_LoopX, 0, 0 + GetLogicalSize().cx, 0 + GetLogicalSize().cy }; 

                DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), 
                    &rBoundaryFirst, m_nTextFormat, &m_dtp);
                DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), 
                    &rBoundarySecond, m_nTextFormat, &m_dtp);
            }
        }

        // restores
        SetMapMode(rGfx.GetHDC(), nOldMapMode);
        SetTextColor(rGfx.GetHDC(), crOldTextColor);
        SetBkMode(rGfx.GetHDC(), nOldBkMode);
        SelectObject(rGfx.GetHDC(), hOldFont);
    }
}
Пример #27
0
void CLCDText::OnDraw(CLCDGfx &rGfx)
{

    if (GetBackgroundMode() == OPAQUE)
    {
        // clear the clipped area
        RECT rcClp = { 0, 0, m_Size.cx, m_Size.cy };
        FillRect(rGfx.GetHDC(), &rcClp, (HBRUSH) GetStockObject(BLACK_BRUSH));
    
        // clear the logical area
        RECT rcLog = { 0, 0, m_sizeLogical.cx, m_sizeLogical.cy };
        FillRect(rGfx.GetHDC(), &rcLog, (HBRUSH) GetStockObject(BLACK_BRUSH));
    }
    
    if (m_nTextLength)
    {

        // map mode text, with transparency
        int nOldMapMode = SetMapMode(rGfx.GetHDC(), MM_TEXT);
        int nOldBkMode = SetBkMode(rGfx.GetHDC(), GetBackgroundMode()); 

        // select current font
        HFONT hOldFont = (HFONT)SelectObject(rGfx.GetHDC(), m_hFont);   

        // select color
        COLORREF crOldTextColor = SetTextColor(rGfx.GetHDC(), m_crColor);
        
        if (m_bRecalcExtent)
        {
            int nTextFormat;

            RECT rExtent;
            // calculate vertical extent with word wrap
            nTextFormat = (m_nTextFormat | DT_WORDBREAK | DT_CALCRECT);
            rExtent.left = rExtent.top = 0;
            rExtent.right = GetWidth();
            rExtent.bottom = GetHeight();
            DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rExtent, nTextFormat, &m_dtp);
            m_sizeVExtent.cx = rExtent.right;
            m_sizeVExtent.cy = rExtent.bottom;

            // calculate horizontal extent w/o word wrap
            nTextFormat = (m_nTextFormat | DT_CALCRECT);
            rExtent.left = rExtent.top = 0;
            rExtent.right = GetWidth();
            rExtent.bottom = GetHeight();
            DrawTextEx(rGfx.GetHDC(), (LPTSTR)m_sText.c_str(), static_cast<int>(m_nTextLength), &rExtent, nTextFormat, &m_dtp);
            m_sizeHExtent.cx = rExtent.right;
            m_sizeHExtent.cy = rExtent.bottom;

            m_bRecalcExtent = FALSE;
        }

        if (IsVisible())
        {
            DrawText(rGfx);
        }

        // restores
        SetMapMode(rGfx.GetHDC(), nOldMapMode);
        SetTextColor(rGfx.GetHDC(), crOldTextColor);
        SetBkMode(rGfx.GetHDC(), nOldBkMode);
        SelectObject(rGfx.GetHDC(), hOldFont);
    }
}
Пример #28
0
void _draw_static(
		LPDRAWITEMSTRUCT itst
	)
{
	UINT edge   = BDR_RAISEDINNER;
	UINT state  = DSS_NORMAL;
	UINT border = BF_RECT;

	DRAWTEXTPARAMS tp = { sizeof(tp) };
	WINDOWINFO wi;
	RECT rc;

	_wnd_data *gwl;
	_tab_data *tab;

	wchar_t data[MAX_PATH];
	int x = 6, y = 3;
	char curr;	

	if ( !itst ) return;
	switch ( itst->CtlType )
	{
		case ODT_LISTVIEW: _draw_listview(itst); break;
		case ODT_COMBOBOX: _draw_combobox(itst); break;
		case ODT_TAB:      _draw_tabs(itst);     break;

		case ODT_BUTTON:

        if ( itst->itemState & ODS_DISABLED ) state = DSS_DISABLED;
        if ( itst->itemState & ODS_SELECTED )
		{
			edge = BDR_SUNKENOUTER;
			x++; y++;
        }
		itst->rcItem.top++;

		GetWindowText( itst->hwndItem, data, MAX_PATH );
		GetClientRect( itst->hwndItem, &rc );

		gwl = wnd_get_long( itst->hwndItem, GWL_USERDATA );
		tab = wnd_get_long( GetParent(itst->hwndItem), GWL_USERDATA );

		curr = tab && ( tab->h_curr == itst->hwndItem );

		if ( gwl )
		{
			if ( !gwl->dlg[0] )
			{
				itst->rcItem.right  = itst->rcItem.left + 13;
				itst->rcItem.bottom = itst->rcItem.top  + 13;

				_fill( itst->hDC, &rc, _cl(COLOR_BTNFACE, FALSE) );
				_fill( itst->hDC, &itst->rcItem, /* (itst->itemState & ODS_FOCUS) ? _cl(COLOR_BTNFACE, FALSE) : */ _cl(COLOR_BTNFACE, LGHT_CLR) );

				GetWindowText(itst->hwndItem, data, MAX_PATH);
				if ( gwl->state )
				{
					ImageList_DrawEx(
						__img, 0, itst->hDC, itst->rcItem.right - 11, 2, 0, 0, CLR_NONE, GetSysColor(COLOR_BTNSHADOW), ILD_BLEND
					);
				}
				DrawEdge(
					itst->hDC, &itst->rcItem, BDR_SUNKENOUTER, border
					);
				DrawState(
					itst->hDC, NULL, NULL, (LPARAM)data, 0, itst->rcItem.right+4, 0, 0, 0, DST_PREFIXTEXT | state
					);

				if ( itst->itemState & ODS_FOCUS )
				{
					rc.bottom  = itst->rcItem.bottom - itst->rcItem.top + 2;					
					rc.left   += itst->rcItem.right + 2;

					DrawFocusRect( itst->hDC, &rc );
				}
				return;
			} else 
			{ 
				if ( curr )
				{							
					edge = BDR_SUNKENOUTER;
					x++; y++;
				} else {
					border = BF_FLAT;
				}
			}
		}

		_fill( itst->hDC, &itst->rcItem, (itst->itemState & ODS_FOCUS ) ?
			_cl( COLOR_BTNFACE, DARK_CLR ) :
			_cl( COLOR_BTNFACE, FALSE ) );

		DrawState( itst->hDC, NULL, NULL, (LPARAM)data, 0, x, y, 0, 0, DST_PREFIXTEXT | state );
		if ( itst->itemState & ODS_FOCUS )
		{
			modify_rect( rc, 1, 2, -2, -2 );
			if ( itst->itemState & ODS_SELECTED )
			{
				modify_rect( rc, 1, 1, 1, 1 );
			}
			DrawFocusRect( itst->hDC, &rc );
		}

		case ODT_STATIC:
		{
			GetWindowInfo(itst->hwndItem, &wi);
			GetWindowText(itst->hwndItem, data, MAX_PATH);

			if ( data[0] == L'#' )
			{
				GetWindowRect(GetParent(GetParent(itst->hwndItem)), &rc);

				itst->rcItem.right = rc.right - rc.left - 3;
				itst->rcItem.top = itst->rcItem.left = 1;

				_fill(itst->hDC, &itst->rcItem, _cl(COLOR_BTNSHADOW, DARK_CLR - 7));

				tp.iLeftMargin   += 10;
				itst->rcItem.top += 1;

				DrawTextEx(itst->hDC, data + 1, -1, &itst->rcItem, DT_END_ELLIPSIS, &tp);					
			}
			else 
			{
				if ( (wi.dwStyle & SS_SUNKEN) == 0 )
				{
					DrawEdge(itst->hDC, &itst->rcItem, edge, border);				
				}
			}
		}
		break;
	}
}
Пример #29
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;
}
Пример #30
0
void CExpensiveGiftCtrl::OnPaint() 
{
	CPaintDC dc(this);

	CRect ClientRect;
	GetClientRect(&ClientRect);
	
	CDC MemDC;
	CBitmap MemBitMap;
	BOOL  bOverOut = FALSE;
	
	//创建一个与dc兼容的内存内存设备环境
	MemDC.CreateCompatibleDC(&dc);
	//创建一个与dc兼容的位图,大小为整个客户区
	MemBitMap.CreateCompatibleBitmap(&dc,ClientRect.Width(),ClientRect.Height());
	CBitmap *pOldBitMap = MemDC.SelectObject(&MemBitMap);
	MemDC.FillSolidRect(&ClientRect,RGB(232,243,255));

	CDC FontMenDC;  //用来放文字
	CBitmap FontMenBM;
	FontMenDC.CreateCompatibleDC(&MemDC);
	FontMenBM.CreateCompatibleBitmap(&MemDC,ClientRect.Width(),ClientRect.Height());
	CBitmap *pOldFontBM=FontMenDC.SelectObject(&FontMenBM);
	FontMenDC.FillSolidRect(&ClientRect,RGB(232,243,255));
	if(m_pNowInfo!=NULL)
	{
		CString sTmp;
		int nSize=0;   //计算长度
		int nPos=m_nPos; //保存后面计算长度
		///////////////////////////////////////////绘图/////////////////////////////////
	    ERRORRETURN(DrawGif(&MemDC,nSize,nPos),Result);

		
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,m_pNowInfo->sFromUserName,&m_font[0],RGB(232,7,108),10,nSize,nPos),Result);
		if (m_pNowInfo->nFromUserID != "0")	
		{
			sTmp.Format("(%s)",m_pNowInfo->nFromUserID);		
			ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[1],RGB(80,0 ,36),26,nSize,nPos),Result);
			sTmp="送给";
		}
		else
		{
			ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[1],RGB(80,0 ,36),26,nSize,nPos),Result);
			sTmp="悄悄的送给";
		}
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[0],RGB(80,0 ,36),10,nSize,nPos),Result);
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,m_pNowInfo->sToUserName,&m_font[0],RGB(232,7,108),10,nSize,nPos),Result);
		sTmp.Format("(%s)",m_pNowInfo->nToUserID);
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[1],RGB(80,0,36),26,nSize,nPos),Result);
		sTmp.Format("%d",m_pNowInfo->nItemNum);
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[0],RGB(80,0,36),10,nSize,nPos),Result);
		sTmp.Format("%s",m_pNowInfo->sUnitName);
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[0],RGB(80,0,36),10,nSize,nPos),Result);
		sTmp.Format("%s",m_pNowInfo->sItemName);
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[0],RGB(255,0,0),10,nSize,nPos),Result);
		sTmp.Format("%s",m_pNowInfo->sTip); // 赠言
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[1],RGB(255,0,0),26,nSize,nPos),Result);
		sTmp.Format(" (%s)",m_pNowInfo->sSendTime);
		ERRORRETURN(DrawTextEx(&MemDC,&FontMenDC,sTmp,&m_font[1],RGB(80,0,36),26,nSize,nPos),Result);
		if(nPos > ClientRect.Width())
		{
			m_nPos=0;
			bOverOut=TRUE;
		}
	}
Result:
#ifdef KTV
	   MemDC.Draw3dRect(ClientRect,RGB(185,213,255), RGB(185,213,255));
#else
	   MemDC.Draw3dRect(ClientRect,RGB(95,154,214), RGB(95,154,214));
#endif
	dc.BitBlt(0,0,ClientRect.Width(),ClientRect.Height(),&MemDC, 0, 0,SRCCOPY);

	FontMenDC.SelectObject(pOldFontBM);
   	FontMenBM.DeleteObject();
   	FontMenDC.DeleteDC();


	MemDC.SelectObject(pOldBitMap);
	MemBitMap.DeleteObject();
	MemDC.DeleteDC(); 

	
	if(m_bAddSpeed && bOverOut)
		OnUpNewRoadItem();	
}