float DrawButton2(float x, float y, float w, char * t, int select) { int len = strlen(t); u32 rgba = 0xffffffff, brgba = 0x0000c080; if(w < (len + 2) * 10) w = (len + 2) * 10; SetFontAutoCenter(0); SetCurrentFont(FONT_BUTTON); SetFontSize(10, 32); if(select == 2) {rgba = 0xffffffff; brgba = 0xc01000ff;} else if(select == 1) {rgba = 0xffffffff; brgba = 0x00c000ff;} else if(select == -1) {rgba = 0xffffff6f; brgba = 0x00c0006f;} SetFontColor(rgba, 0x0); DrawBox(x, y, 0.0f, w, 40, brgba); DrawLineBox(x, y, 0.0f, w, 40, 0xc0c0c0ff); DrawString(x + (w - len * 10) / 2, y + 4, t); return x + w; }
void CScene::Draw(HDC hDC) { RECT rcWorldSize; RECT rcLocalSize; GetClientRect(m_hWnd, &rcWorldSize); rcLocalSize = rcWorldSize; rcLocalSize.right -= rcLocalSize.left; rcLocalSize.bottom -= rcLocalSize.top; rcLocalSize.left = rcLocalSize.top = 0; RECT rcValidArea = rcLocalSize; rcValidArea.left = 10; rcValidArea.right = 360; rcValidArea.top += m_ulspDownlist; rcValidArea.bottom = rcValidArea.top + CLIENT_HEIGHT - m_ulspDownlist * 3; RECT rcTitle = SizeDown(rcLocalSize, 2); rcTitle.bottom = rcTitle.top + m_ulspDownlist; DrawLineBox(hDC, SizeDown(rcLocalSize, 2), RGB(255, 255, 255), RGB(155, 155, 155), 2, DL_FRAME); DrawLineBox(hDC, SizeDown(rcTitle, 5), RGB(255, 255, 255), RGB(155, 155, 155), 2, DL_FRAME); HFONT mainFont = CreateFont(24, FontSet_Arial_B); HFONT origFont = (HFONT)SelectObject(hDC, mainFont); SetTextColor(hDC, RGB(55, 55, 55)); DrawText(hDC, TEXT("Service File List"), -1, &rcTitle, DT_CENTER | DT_SINGLELINE | DT_VCENTER); SelectObject(hDC, origFont); DeleteObject(mainFont); m_Scroll.Draw(hDC, rcLocalSize, RGB(0, 0, 0)); for (auto &p : m_vPageList) { float fLength = m_Scroll.GetNowSrcPosition(); p->GetAdvanceInfo(1, &fLength); p->OnDraw(hDC); } SetDCBrushColor(hDC, RGB(55, 55, 55)); FrameRect(hDC, &rcValidArea, (HBRUSH)GetStockObject(DC_BRUSH)); HDC hdcIcon = CreateCompatibleDC(hDC); if (m_hIcon) DrawIcon(hDC, 10, 550, m_hIcon); else if (m_cImage) { SelectObject(hdcIcon, m_cImage); BLENDFUNCTION bf; bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = 0xff; bf.AlphaFormat = AC_SRC_ALPHA; ::AlphaBlend(hDC, 10, 550, 64, 64, hdcIcon, 0, 0, 64, 64, bf); } // TCHAR strView[80]; // CImage cimg; // if (m_vffFileList.size() > 0) // { // for (size_t i = 0; i < m_vffFileList.size(); ++i) // { // SetBkMode(hDC, TRANSPARENT); // // SelectObject(hdcIcon, m_vffFileList[i].second.GetHBitmap()); // // BLENDFUNCTION bf; // // bf.BlendOp = AC_SRC_OVER; // bf.BlendFlags = 0; // bf.SourceConstantAlpha = 0xff; // bf.AlphaFormat = AC_SRC_ALPHA; // ::AlphaBlend(hDC, 10, 10 + i * 35, 32, 32, hdcIcon, 0, 0, 32, 32, bf); // // lstrcpy(strView, m_vffFileList[i].first.c_str()); // PathCompactPath(hDC, strView, 250); // TextOut(hDC, 50, 10 + i * 35, strView, lstrlen(strView)); // } // } // cimg.Destroy(); DeleteDC(hdcIcon); }
int main(int argc, char **argv) { #ifdef DXPORTLIB SetUseCharSet(DX_CHARSET_EXT_UTF8); #endif SetWindowText(_T("DxPortLib Test App")); SetWindowSizeChangeEnableFlag(TRUE); SetGraphMode(640, 480, 32); ChangeWindowMode(TRUE); if (DxLib_Init() == -1) { return -1; } SRand(0); InitBounceThings(); int isWindowed = TRUE; int wasPressed = 0; int timerDelta = 0; int timeLast = GetNowCount(); int screenshotWasPressed = 0; int drawScreen = MakeScreen(640, 480, FALSE); while (ProcessMessage() == 0 #ifndef DX_NON_INPUT && CheckHitKey(KEY_INPUT_ESCAPE) == 0 #endif ) { /* If Alt+Enter is pressed, flip to fullscreen mode. */ if (CheckHitKey(KEY_INPUT_RETURN) && (CheckHitKey(KEY_INPUT_LALT) || CheckHitKey(KEY_INPUT_RALT)) ) { if (wasPressed == 0) { isWindowed = 1 - isWindowed; ChangeWindowMode(isWindowed); } wasPressed = 1; } else { wasPressed = 0; } /* Game logic here */ MoveBounceThings(); /* Draw logic here */ SetDrawScreen(drawScreen); SetDrawBright(255, 255, 255); SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 255); DrawFillBox(0, 0, 640, 480, 0xFF000000); DrawLineBox(10, 10, 630, 470, 0xFFFFFFFF); SetDrawBlendMode(DX_BLENDMODE_ALPHA, 128); DrawFillBox(20, 20, 620, 460, GetColor(0x90, 0x80, 0x70)); DrawBounceThings(); if (CheckHitKey(KEY_INPUT_S)) { if (screenshotWasPressed == 0) { SaveDrawScreenToPNG(0, 0, 640, 480, _T("test_draw_screenshot.png")); screenshotWasPressed = 1; } } else { screenshotWasPressed = 0; } SetDrawScreen(DX_SCREEN_BACK); DrawGraph(0, 0, drawScreen, FALSE); ScreenFlip(); /* Time to next frame automatically... */ int newTime = GetNowCount(); timerDelta += newTime - timeLast; timeLast = newTime; int n = timerDelta; if (n > 16) { n = 16; } timerDelta -= n; WaitTimer(16 - n); } DxLib_End(); return 0; }