summaryrefslogtreecommitdiff
path: root/plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp')
-rw-r--r--plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp398
1 files changed, 184 insertions, 214 deletions
diff --git a/plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp b/plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp
index 8dfc6c98e3..7712cf1d36 100644
--- a/plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp
+++ b/plugins/MirandaG15/src/LCDFramework/CLCDGfx.cpp
@@ -19,7 +19,7 @@
//************************************************************************
// CLCDGfx::CLCDGfx
//************************************************************************
-CLCDGfx::CLCDGfx(void)
+CLCDGfx::CLCDGfx(void)
{
m_nWidth = 0;
m_nHeight = 0;
@@ -53,22 +53,20 @@ bool CLCDGfx::Initialize(int nWidth, int nHeight, int nBPP, PBYTE pLcdBitmapBits
{
m_pLcdBitmapBits = pLcdBitmapBits;
- m_nWidth = nWidth;
- m_nHeight = nHeight;
- m_nBPP = nBPP;
+ m_nWidth = nWidth;
+ m_nHeight = nHeight;
+ m_nBPP = nBPP;
m_hDC = CreateCompatibleDC(nullptr);
- if(nullptr == m_hDC)
- {
+ if (nullptr == m_hDC) {
TRACE(L"CLCDGfx::Initialize(): failed to create compatible DC.\n");
Shutdown();
return false;
}
int nBMISize = sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD);
- m_pBitmapInfo = (BITMAPINFO *) new BYTE [nBMISize];
- if(nullptr == m_pBitmapInfo)
- {
+ m_pBitmapInfo = (BITMAPINFO *) new BYTE[nBMISize];
+ if (nullptr == m_pBitmapInfo) {
TRACE(L"CLCDGfx::Initialize(): failed to allocate bitmap info.\n");
Shutdown();
return false;
@@ -79,7 +77,7 @@ bool CLCDGfx::Initialize(int nWidth, int nHeight, int nBPP, PBYTE pLcdBitmapBits
m_pBitmapInfo->bmiHeader.biWidth = m_nWidth;
m_pBitmapInfo->bmiHeader.biHeight = -m_nHeight;
m_pBitmapInfo->bmiHeader.biPlanes = 1;
- m_pBitmapInfo->bmiHeader.biBitCount = 8*m_nBPP;
+ m_pBitmapInfo->bmiHeader.biBitCount = 8 * m_nBPP;
m_pBitmapInfo->bmiHeader.biCompression = BI_RGB;
m_pBitmapInfo->bmiHeader.biSizeImage = m_pBitmapInfo->bmiHeader.biWidth * m_pBitmapInfo->bmiHeader.biHeight * m_nBPP;
m_pBitmapInfo->bmiHeader.biXPelsPerMeter = 3200;
@@ -87,9 +85,8 @@ bool CLCDGfx::Initialize(int nWidth, int nHeight, int nBPP, PBYTE pLcdBitmapBits
m_pBitmapInfo->bmiHeader.biClrUsed = 256;
m_pBitmapInfo->bmiHeader.biClrImportant = 256;
- if(m_nBPP == 1) {
- for(int nColor = 0; nColor < 256; ++nColor)
- {
+ if (m_nBPP == 1) {
+ for (int nColor = 0; nColor < 256; ++nColor) {
m_pBitmapInfo->bmiColors[nColor].rgbRed = (BYTE)((nColor > 128) ? 255 : 0);
m_pBitmapInfo->bmiColors[nColor].rgbGreen = (BYTE)((nColor > 128) ? 255 : 0);
m_pBitmapInfo->bmiColors[nColor].rgbBlue = (BYTE)((nColor > 128) ? 255 : 0);
@@ -97,9 +94,8 @@ bool CLCDGfx::Initialize(int nWidth, int nHeight, int nBPP, PBYTE pLcdBitmapBits
}
}
- m_hBitmap = CreateDIBSection(m_hDC, m_pBitmapInfo, DIB_RGB_COLORS, (PVOID *) &m_pBitmapBits, nullptr, 0);
- if(nullptr == m_hBitmap)
- {
+ m_hBitmap = CreateDIBSection(m_hDC, m_pBitmapInfo, DIB_RGB_COLORS, (PVOID *)&m_pBitmapBits, nullptr, 0);
+ if (nullptr == m_hBitmap) {
TRACE(L"CLCDGfx::Initialize(): failed to create bitmap.\n");
Shutdown();
return false;
@@ -125,8 +121,7 @@ bool CLCDGfx::Shutdown(void)
{
EndTransition();
- if(nullptr != m_hBitmap)
- {
+ if (nullptr != m_hBitmap) {
DeleteObject(m_hBitmap);
m_hBitmap = nullptr;
m_pBitmapBits = nullptr;
@@ -135,14 +130,12 @@ bool CLCDGfx::Shutdown(void)
ASSERT(nullptr == m_hPrevBitmap);
m_hPrevBitmap = nullptr;
- if(nullptr != m_pBitmapInfo)
- {
- delete [] m_pBitmapInfo;
+ if (nullptr != m_pBitmapInfo) {
+ delete[] m_pBitmapInfo;
m_pBitmapInfo = nullptr;
}
- if(nullptr != m_hDC)
- {
+ if (nullptr != m_hDC) {
DeleteDC(m_hDC);
m_hDC = nullptr;
}
@@ -157,16 +150,16 @@ bool CLCDGfx::Shutdown(void)
//************************************************************************
// CLCDGfx::SetClipRegion
//************************************************************************
-void CLCDGfx::SetClipRegion(int iX,int iY,int iWidth,int iHeight)
+void CLCDGfx::SetClipRegion(int iX, int iY, int iWidth, int iHeight)
{
ASSERT(nullptr != m_hPrevBitmap);
m_rClipRegion.left = iX;
- m_rClipRegion.right = iX+iWidth;
+ m_rClipRegion.right = iX + iWidth;
m_rClipRegion.top = iY;
- m_rClipRegion.bottom = iY+iHeight;
+ m_rClipRegion.bottom = iY + iHeight;
- HRGN hRgn = CreateRectRgn(iX,iY,iX+iWidth,iY+iHeight);
+ HRGN hRgn = CreateRectRgn(iX, iY, iX + iWidth, iY + iHeight);
SelectClipRgn(GetHDC(), hRgn);
DeleteObject(hRgn);
}
@@ -185,12 +178,11 @@ RECT CLCDGfx::GetClipRegion()
void CLCDGfx::BeginDraw(void)
{
ASSERT(nullptr != m_hBitmap);
- if(m_hPrevBitmap != nullptr)
+ if (m_hPrevBitmap != nullptr)
Sleep(1);
ASSERT(nullptr == m_hPrevBitmap);
- if(nullptr == m_hPrevBitmap)
- {
- m_hPrevBitmap = (HBITMAP) SelectObject(m_hDC, m_hBitmap);
+ if (nullptr == m_hPrevBitmap) {
+ m_hPrevBitmap = (HBITMAP)SelectObject(m_hDC, m_hBitmap);
SetTextColor(m_hDC, RGB(255, 255, 255));
SetBkColor(m_hDC, RGB(0, 0, 0));
}
@@ -203,21 +195,23 @@ void CLCDGfx::ClearScreen(void)
{
// this means, we're inside BeginDraw()/EndDraw()
ASSERT(nullptr != m_hPrevBitmap);
- RECT rc = { 0, 0, m_nWidth, m_nHeight };
- FillRect(m_hDC, &rc, (HBRUSH) GetStockObject(BLACK_BRUSH));
+ RECT rc = {0, 0, m_nWidth, m_nHeight};
+ FillRect(m_hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
}
//************************************************************************
// CLCDGfx::GetPixel
//************************************************************************
-COLORREF CLCDGfx::GetPixel(int nX, int nY) {
- return ::GetPixel(m_hDC,nX,nY);
+COLORREF CLCDGfx::GetPixel(int nX, int nY)
+{
+ return ::GetPixel(m_hDC, nX, nY);
}
//************************************************************************
// CLCDGfx::SetPixel
//************************************************************************
-void CLCDGfx::SetPixel(int nX, int nY, COLORREF color) {
+void CLCDGfx::SetPixel(int nX, int nY, COLORREF color)
+{
// this means, we're inside BeginDraw()/EndDraw()
ASSERT(nullptr != m_hPrevBitmap);
::SetPixel(m_hDC, nX, nY, color);
@@ -226,12 +220,13 @@ void CLCDGfx::SetPixel(int nX, int nY, COLORREF color) {
void CLCDGfx::SetPixel(int nX, int nY, BYTE r, BYTE g, BYTE b)
{
COLORREF ref;
- if(m_nBPP==1) {
+ if (m_nBPP == 1) {
ref = (r || g || b) ? RGB(255, 255, 255) : RGB(0, 0, 0);
- } else {
- ref = RGB(r,g,b);
}
- SetPixel(nX,nY,ref);
+ else {
+ ref = RGB(r, g, b);
+ }
+ SetPixel(nX, nY, ref);
}
@@ -243,7 +238,7 @@ void CLCDGfx::DrawLine(int nX1, int nY1, int nX2, int nY2)
// this means, we're inside BeginDraw()/EndDraw()
ASSERT(nullptr != m_hPrevBitmap);
- HPEN hPrevPen = (HPEN) SelectObject(m_hDC, GetStockObject(WHITE_PEN));
+ HPEN hPrevPen = (HPEN)SelectObject(m_hDC, GetStockObject(WHITE_PEN));
::MoveToEx(m_hDC, nX1, nY1, nullptr);
::LineTo(m_hDC, nX2, nY2);
SelectObject(m_hDC, hPrevPen);
@@ -260,8 +255,8 @@ void CLCDGfx::DrawFilledRect(int nX, int nY, int nWidth, int nHeight)
// this means, we're inside BeginDraw()/EndDraw()
ASSERT(nullptr != m_hPrevBitmap);
- HBRUSH hPrevBrush = (HBRUSH) SelectObject(m_hDC, GetStockObject(WHITE_BRUSH));
- RECT r = { nX, nY, nX + nWidth, nY + nHeight };
+ HBRUSH hPrevBrush = (HBRUSH)SelectObject(m_hDC, GetStockObject(WHITE_BRUSH));
+ RECT r = {nX, nY, nX + nWidth, nY + nHeight};
::FillRect(m_hDC, &r, hPrevBrush);
SelectObject(m_hDC, hPrevBrush);
}
@@ -274,16 +269,16 @@ void CLCDGfx::DrawRect(int iX, int iY, int iWidth, int iHeight)
// this means, we're inside BeginDraw()/EndDraw()
ASSERT(nullptr != m_hPrevBitmap);
- HBRUSH hPrevBrush = (HBRUSH) SelectObject(m_hDC, GetStockObject(WHITE_BRUSH));
+ HBRUSH hPrevBrush = (HBRUSH)SelectObject(m_hDC, GetStockObject(WHITE_BRUSH));
// top line
- DrawLine(iX+1,iY,iX+iWidth-1,iY);
+ DrawLine(iX + 1, iY, iX + iWidth - 1, iY);
// bottom line
- DrawLine(iX+1,iY+iHeight-1,iX+iWidth-1,iY+iHeight-1);
+ DrawLine(iX + 1, iY + iHeight - 1, iX + iWidth - 1, iY + iHeight - 1);
// left line
- DrawLine(iX,iY,iX,iY+iHeight);
+ DrawLine(iX, iY, iX, iY + iHeight);
// right line
- DrawLine(iX+iWidth-1,iY,iX+iWidth-1,iY+iHeight);
+ DrawLine(iX + iWidth - 1, iY, iX + iWidth - 1, iY + iHeight);
SelectObject(m_hDC, hPrevBrush);
}
@@ -295,7 +290,7 @@ 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);
+ int nOldBkMode = SetBkMode(m_hDC, TRANSPARENT);
DRAWTEXTPARAMS dtp;
memset(&dtp, 0, sizeof(DRAWTEXTPARAMS));
@@ -312,33 +307,33 @@ void CLCDGfx::DrawText(int nX, int nY, LPCTSTR sText)
//************************************************************************
// CLCDGfx::DrawText
//************************************************************************
-void CLCDGfx::DrawText(int nX,int nY,int nWidth,tstring strText)
+void CLCDGfx::DrawText(int nX, int nY, int nWidth, tstring strText)
{
- SIZE sizeLine = {0, 0};
+ SIZE sizeLine = {0, 0};
SIZE sizeCutOff = {0, 0};
- GetTextExtentPoint(GetHDC(),L"...",3,&sizeCutOff);
+ GetTextExtentPoint(GetHDC(), L"...", 3, &sizeCutOff);
int *piWidths = new int[strText.length()];
int iMaxChars = 0;
GetTextExtentExPoint(GetHDC(), strText.c_str(), (int)strText.length(), nWidth, &iMaxChars, piWidths, &sizeLine);
- if(iMaxChars < strText.length()) {
- for(iMaxChars--;iMaxChars>0;iMaxChars--)
- if(piWidths[iMaxChars] + sizeCutOff.cx <= nWidth)
+ if (iMaxChars < strText.length()) {
+ for (iMaxChars--; iMaxChars > 0; iMaxChars--)
+ if (piWidths[iMaxChars] + sizeCutOff.cx <= nWidth)
break;
- DrawText(nX,nY,(strText.substr(0,iMaxChars) + L"...").c_str());
+ DrawText(nX, nY, (strText.substr(0, iMaxChars) + L"...").c_str());
}
- else DrawText(nX,nY,strText.c_str());
+ else DrawText(nX, nY, strText.c_str());
delete[] piWidths;
}
//************************************************************************
// CLCDGfx::DrawBitmap
//************************************************************************
-void CLCDGfx::DrawBitmap(int nX, int nY,int nWidth, int nHeight, HBITMAP hBitmap)
+void CLCDGfx::DrawBitmap(int nX, int nY, int nWidth, int nHeight, HBITMAP hBitmap)
{
HDC hCompatibleDC = CreateCompatibleDC(GetHDC());
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hCompatibleDC, hBitmap);
@@ -356,19 +351,17 @@ void CLCDGfx::DrawBitmap(int nX, int nY,int nWidth, int nHeight, HBITMAP hBitmap
void CLCDGfx::EndDraw(void)
{
ASSERT(nullptr != m_hPrevBitmap);
- if(nullptr != m_hPrevBitmap)
- {
+ if (nullptr != m_hPrevBitmap) {
GdiFlush();
- m_hPrevBitmap = (HBITMAP) SelectObject(m_hDC, m_hPrevBitmap);
+ m_hPrevBitmap = (HBITMAP)SelectObject(m_hDC, m_hPrevBitmap);
ASSERT(m_hPrevBitmap == m_hBitmap);
m_hPrevBitmap = nullptr;
}
- if(m_nBPP != 1 || !m_bTransition)
+ if (m_nBPP != 1 || !m_bTransition)
memcpy(m_pLcdBitmapBits, m_pBitmapBits, m_nWidth * m_nHeight * m_nBPP);
- else
- {
- if(m_dwTransitionStart == 0) {
+ else {
+ if (m_dwTransitionStart == 0) {
Cache();
}
@@ -420,117 +413,109 @@ void CLCDGfx::EndDraw(void)
memcpy(m_pLcdBitmapBits+(i*m_nWidth)+(m_nWidth-iCols),pScreen2+(i*m_nWidth),iCols);
}
}
- else*/ if(m_eTransition == TRANSITION_HLINES)
- {
- int iCols = ((float)dwTimeElapsed/(float)TRANSITION_DURATION)*m_nHeight;
- if(iCols%2 == 1)
+ else*/ if (m_eTransition == TRANSITION_HLINES) {
+ int iCols = ((float)dwTimeElapsed / (float)TRANSITION_DURATION)*m_nHeight;
+ if (iCols % 2 == 1)
iCols--;
- if(iCols > m_nHeight)
+ if (iCols > m_nHeight)
iCols = m_nHeight;
- if(iCols < 2)
+ if (iCols < 2)
iCols = 2;
- memcpy(m_pLcdBitmapBits,pScreen1,m_nHeight*m_nWidth);
- for(int i=0;i<m_nHeight;i += m_nHeight/iCols)
- memcpy(m_pLcdBitmapBits+(i*m_nWidth),pScreen2+(i*m_nWidth),m_nWidth);
+ memcpy(m_pLcdBitmapBits, pScreen1, m_nHeight*m_nWidth);
+ for (int i = 0; i < m_nHeight; i += m_nHeight / iCols)
+ memcpy(m_pLcdBitmapBits + (i*m_nWidth), pScreen2 + (i*m_nWidth), m_nWidth);
}
- else if(m_eTransition == TRANSITION_VLINES)
- {
- int iCols = ((float)dwTimeElapsed/(float)TRANSITION_DURATION)*m_nWidth;
- if(iCols%2 == 1)
+ else if (m_eTransition == TRANSITION_VLINES) {
+ int iCols = ((float)dwTimeElapsed / (float)TRANSITION_DURATION)*m_nWidth;
+ if (iCols % 2 == 1)
iCols--;
- if(iCols > m_nWidth)
+ if (iCols > m_nWidth)
iCols = m_nWidth;
- if(iCols < 2)
+ if (iCols < 2)
iCols = 2;
- memcpy(m_pLcdBitmapBits,pScreen1,m_nHeight*m_nWidth);
- for(int i=0;i<m_nHeight;i++)
- {
- for(int j=0;j<m_nWidth;j+=m_nWidth/iCols)
- memcpy(m_pLcdBitmapBits+(i*m_nWidth)+j,pScreen2+(i*m_nWidth)+j,1);
+ memcpy(m_pLcdBitmapBits, pScreen1, m_nHeight*m_nWidth);
+ for (int i = 0; i < m_nHeight; i++) {
+ for (int j = 0; j < m_nWidth; j += m_nWidth / iCols)
+ memcpy(m_pLcdBitmapBits + (i*m_nWidth) + j, pScreen2 + (i*m_nWidth) + j, 1);
}
}
- else if(m_eTransition == TRANSITION_FADE)
- {
- int iCols = ((float)dwTimeElapsed/(float)TRANSITION_DURATION)*m_nHeight;
- if(iCols%2 == 1)
+ else if (m_eTransition == TRANSITION_FADE) {
+ int iCols = ((float)dwTimeElapsed / (float)TRANSITION_DURATION)*m_nHeight;
+ if (iCols % 2 == 1)
iCols--;
- if(iCols > m_nHeight)
+ if (iCols > m_nHeight)
iCols = m_nHeight;
- if(iCols < 2)
+ if (iCols < 2)
iCols = 2;
- int iCols2 = ((float)dwTimeElapsed/(float)TRANSITION_DURATION)*m_nWidth;
- if(iCols2%2 == 1)
+ int iCols2 = ((float)dwTimeElapsed / (float)TRANSITION_DURATION)*m_nWidth;
+ if (iCols2 % 2 == 1)
iCols2--;
- if(iCols2 > m_nWidth)
+ if (iCols2 > m_nWidth)
iCols2 = m_nWidth;
- if(iCols2 < 2)
+ if (iCols2 < 2)
iCols2 = 2;
- memcpy(m_pLcdBitmapBits,pScreen1,m_nHeight*m_nWidth);
- for(int i=0;i<m_nHeight;i += m_nHeight/iCols)
- {
- for(int j=0;j<m_nWidth;j+=m_nWidth/iCols2)
- memcpy(m_pLcdBitmapBits+(i*m_nWidth)+j,pScreen2+(i*m_nWidth)+j,1);
+ memcpy(m_pLcdBitmapBits, pScreen1, m_nHeight*m_nWidth);
+ for (int i = 0; i < m_nHeight; i += m_nHeight / iCols) {
+ for (int j = 0; j < m_nWidth; j += m_nWidth / iCols2)
+ memcpy(m_pLcdBitmapBits + (i*m_nWidth) + j, pScreen2 + (i*m_nWidth) + j, 1);
}
}
- else if(m_eTransition == TRANSITION_MORPH)
- {
- double dPercent = ((float)dwTimeElapsed/(float)TRANSITION_DURATION);
+ else if (m_eTransition == TRANSITION_MORPH) {
+ double dPercent = ((float)dwTimeElapsed / (float)TRANSITION_DURATION);
double dPixelPercent = dPercent;
- memset(m_pLcdBitmapBits,0x00,m_nHeight * m_nWidth);
+ memset(m_pLcdBitmapBits, 0x00, m_nHeight * m_nWidth);
SLCDPixel *pPixel = nullptr;
vector<SLCDPixel*>::iterator iter = m_LMovingPixels.begin();
- int iIndex = 0,iMoved = 0;
+ int iIndex = 0, iMoved = 0;
- while(iter != m_LMovingPixels.end())
- {
+ while (iter != m_LMovingPixels.end()) {
pPixel = *iter;
- if(pPixel->Position.x != pPixel->Destination.x ||pPixel->Position.y != pPixel->Destination.y) {
+ if (pPixel->Position.x != pPixel->Destination.x || pPixel->Position.y != pPixel->Destination.y) {
iMoved++;
dPixelPercent = dPercent * pPixel->dSpeed;
- if(dPixelPercent > 1.0f)
+ if (dPixelPercent > 1.0f)
dPixelPercent = 1.0f;
- if(pPixel->Start.x < pPixel->Destination.x)
- pPixel->Position.x = pPixel->Start.x + dPixelPercent*(pPixel->Destination.x-pPixel->Start.x);
- else if(pPixel->Start.x > pPixel->Destination.x)
- pPixel->Position.x = pPixel->Start.x - dPixelPercent*(pPixel->Start.x-pPixel->Destination.x);
+ if (pPixel->Start.x < pPixel->Destination.x)
+ pPixel->Position.x = pPixel->Start.x + dPixelPercent * (pPixel->Destination.x - pPixel->Start.x);
+ else if (pPixel->Start.x > pPixel->Destination.x)
+ pPixel->Position.x = pPixel->Start.x - dPixelPercent * (pPixel->Start.x - pPixel->Destination.x);
- if(pPixel->Start.y < pPixel->Destination.y)
- pPixel->Position.y = pPixel->Start.y + dPixelPercent*(pPixel->Destination.y-pPixel->Start.y);
- else if(pPixel->Start.y > pPixel->Destination.y)
- pPixel->Position.y = pPixel->Start.y - dPixelPercent*(pPixel->Start.y-pPixel->Destination.y);
+ if (pPixel->Start.y < pPixel->Destination.y)
+ pPixel->Position.y = pPixel->Start.y + dPixelPercent * (pPixel->Destination.y - pPixel->Start.y);
+ else if (pPixel->Start.y > pPixel->Destination.y)
+ pPixel->Position.y = pPixel->Start.y - dPixelPercent * (pPixel->Start.y - pPixel->Destination.y);
}
iIndex = pPixel->Position.y*m_nWidth + pPixel->Position.x;
- if(iIndex >= 0 && iIndex < m_nHeight * m_nWidth)
+ if (iIndex >= 0 && iIndex < m_nHeight * m_nWidth)
m_pLcdBitmapBits[iIndex] = pPixel->cValue;
iter++;
}
iter = m_LStaticPixels.begin();
- while(iter != m_LStaticPixels.end())
- {
+ while (iter != m_LStaticPixels.end()) {
pPixel = *iter;
iIndex = pPixel->Position.y*m_nWidth + pPixel->Position.x;
m_pLcdBitmapBits[iIndex] = pPixel->cValue;
iter++;
}
- if(iMoved == 0)
+ if (iMoved == 0)
EndTransition();
}
- if(m_eTransition != TRANSITION_MORPH && dwTimeElapsed > TRANSITION_DURATION) {
+ if (m_eTransition != TRANSITION_MORPH && dwTimeElapsed > TRANSITION_DURATION) {
EndTransition();
}
}
@@ -565,36 +550,34 @@ HBITMAP CLCDGfx::GetHBITMAP(void)
return m_hBitmap;
}
-int CLCDGfx::findNearestMatch(PBYTE targetArray,int iSourceIndex) {
- int startY = iSourceIndex/m_nWidth;
- int startX = iSourceIndex - (iSourceIndex/m_nWidth)*m_nWidth;
+int CLCDGfx::findNearestMatch(PBYTE targetArray, int iSourceIndex)
+{
+ int startY = iSourceIndex / m_nWidth;
+ int startX = iSourceIndex - (iSourceIndex / m_nWidth)*m_nWidth;
int iIndex;
- int iY=0,iX=0;
- for(int iPass=1;iPass<m_nWidth;iPass++)
- {
- for(iY = startY-iPass;iY<=startY+iPass;iY+=iPass*2)
- for(iX=startX-iPass;iX<startX+iPass;iX++)
- {
+ int iY = 0, iX = 0;
+ for (int iPass = 1; iPass < m_nWidth; iPass++) {
+ for (iY = startY - iPass; iY <= startY + iPass; iY += iPass * 2)
+ for (iX = startX - iPass; iX < startX + iPass; iX++) {
// skip illegal coordinates
- if(iY < 0 || iY >= m_nHeight || iX <0 || iX >= m_nWidth)
+ if (iY < 0 || iY >= m_nHeight || iX < 0 || iX >= m_nWidth)
continue;
- iIndex = iY*m_nWidth + iX;
- if(targetArray[iIndex] != 0)
+ iIndex = iY * m_nWidth + iX;
+ if (targetArray[iIndex] != 0)
+ return iIndex;
+ }
+ for (iX = startX - iPass; iX <= startX + iPass; iX += iPass * 2)
+ for (iY = startY - iPass; iY < startY + iPass; iY++) {
+ // skip illegal coordinates
+ if (iY < 0 || iY >= m_nHeight || iX < 0 || iX >= m_nWidth)
+ continue;
+
+ iIndex = iY * m_nWidth + iX;
+ if (targetArray[iIndex] != 0)
return iIndex;
}
- for(iX = startX-iPass;iX<=startX+iPass;iX+=iPass*2)
- for(iY=startY-iPass;iY<startY+iPass;iY++)
- {
- // skip illegal coordinates
- if(iY < 0 || iY >= m_nHeight || iX <0 || iX >= m_nWidth)
- continue;
-
- iIndex = iY*m_nWidth + iX;
- if(targetArray[iIndex] != 0)
- return iIndex;
- }
}
return -1;
}
@@ -607,8 +590,7 @@ void CLCDGfx::Cache()
DWORD dwStart = GetTickCount();
// Initialize pixels
- if(m_eTransition == TRANSITION_MORPH)
- {
+ if (m_eTransition == TRANSITION_MORPH) {
SLCDPixel *pPixel = nullptr;
SLCDPixel *pSource = nullptr;
@@ -619,22 +601,20 @@ void CLCDGfx::Cache()
int iTransitionPixels = 0;
POINT pt;
- for(int j=0;j<2;j++)
- {
+ for (int j = 0; j < 2; j++) {
iIndex = 0;
- for(int i=0;i<m_nHeight * m_nWidth;i++)
- {
- pt.y = i/m_nWidth;
- pt.x = i - (i/m_nWidth)*m_nWidth;
- if((j==0 && !PtInRect(&m_rTransitionRegion,pt)) || (m_pSavedBitmapBits[i] != 0x00 && (j==1 || m_pBitmapBits[i] != 0x00)))
- {
+ for (int i = 0; i < m_nHeight * m_nWidth; i++) {
+ pt.y = i / m_nWidth;
+ pt.x = i - (i / m_nWidth)*m_nWidth;
+ if ((j == 0 && !PtInRect(&m_rTransitionRegion, pt)) || (m_pSavedBitmapBits[i] != 0x00 && (j == 1 || m_pBitmapBits[i] != 0x00))) {
iIndex = i;
pPixel = new SLCDPixel();
pPixel->dSpeed = GetRandomDouble()*0.5 + 1;
- if(!PtInRect(&m_rTransitionRegion,pt)) {
+ if (!PtInRect(&m_rTransitionRegion, pt)) {
pPixel->cValue = m_pBitmapBits[i];
- } else {
+ }
+ else {
pPixel->cValue = m_pSavedBitmapBits[i];
}
pPixel->Start.y = pt.y;
@@ -642,78 +622,70 @@ void CLCDGfx::Cache()
pPixel->Position = pPixel->Start;
bBreak = false;
- if(j==1 && bSearch)
- {
+ if (j == 1 && bSearch) {
// search for a pixel in circles with increasing radius around the location
- iIndex = findNearestMatch(m_pBitmapBits,i);
- if(iIndex < 0) {
+ iIndex = findNearestMatch(m_pBitmapBits, i);
+ if (iIndex < 0) {
iIndex = i;
- } else {
+ }
+ else {
bBreak = true;
}
}
- if(j==0 || bBreak)
- {
- pPixel->Destination.y = iIndex/m_nWidth;
- pPixel->Destination.x = iIndex - (iIndex/m_nWidth)*m_nWidth;
+ if (j == 0 || bBreak) {
+ pPixel->Destination.y = iIndex / m_nWidth;
+ pPixel->Destination.x = iIndex - (iIndex / m_nWidth)*m_nWidth;
m_pBitmapBits[iIndex] = 0;
m_pSavedBitmapBits[i] = 0;
- if(bBreak)
+ if (bBreak)
iTransitionPixels++;
}
- else
- {
- if(m_LMovingPixels.size() > 0 && iTransitionPixels > 0)
- {
- pSource = m_LMovingPixels[GetRandomInt(0, (int)m_LMovingPixels.size()-1)];
+ else {
+ if (m_LMovingPixels.size() > 0 && iTransitionPixels > 0) {
+ pSource = m_LMovingPixels[GetRandomInt(0, (int)m_LMovingPixels.size() - 1)];
pPixel->Destination = pSource->Destination;
}
- else
- {
- pPixel->Destination.x = GetRandomInt(0,m_nWidth-1);
- pPixel->Destination.y = GetRandomInt(0,1)==1?-1:m_nHeight+1;
+ else {
+ pPixel->Destination.x = GetRandomInt(0, m_nWidth - 1);
+ pPixel->Destination.y = GetRandomInt(0, 1) == 1 ? -1 : m_nHeight + 1;
}
bSearch = false;
}
- if(j == 0)
+ if (j == 0)
m_LStaticPixels.push_back(pPixel);
- else {
+ else
m_LMovingPixels.push_back(pPixel);
- }
}
}
}
+
bool bRandom = false;
- if(m_LMovingPixels.size() <= 0)
+ if (m_LMovingPixels.size() <= 0)
bRandom = true;
- for(iIndex=0;iIndex<m_nHeight * m_nWidth;iIndex++)
- {
- if(m_pBitmapBits[iIndex] == 0)
+ for (iIndex = 0; iIndex < m_nHeight * m_nWidth; iIndex++) {
+ if (m_pBitmapBits[iIndex] == 0)
continue;
pPixel = new SLCDPixel();
pPixel->dSpeed = GetRandomDouble()*0.5 + 1;
pPixel->cValue = m_pBitmapBits[iIndex];
- if(!bRandom)
- {
- pSource = m_LMovingPixels[GetRandomInt(0, (int)m_LMovingPixels.size()-1)];
+ if (!bRandom) {
+ pSource = m_LMovingPixels[GetRandomInt(0, (int)m_LMovingPixels.size() - 1)];
pPixel->Start = pSource->Start;
}
- else
- {
- pPixel->Start.x = GetRandomInt(0,m_nWidth-1);
- pPixel->Start.y = GetRandomInt(0,1)==1?-1:m_nHeight+1;
+ else {
+ pPixel->Start.x = GetRandomInt(0, m_nWidth - 1);
+ pPixel->Start.y = GetRandomInt(0, 1) == 1 ? -1 : m_nHeight + 1;
}
pPixel->Position = pPixel->Start;
-
- pPixel->Destination.y = iIndex/m_nWidth;
- pPixel->Destination.x = iIndex - (iIndex/m_nWidth)*m_nWidth;
+ pPixel->Destination.y = iIndex / m_nWidth;
+ pPixel->Destination.x = iIndex - (iIndex / m_nWidth)*m_nWidth;
m_LMovingPixels.push_back(pPixel);
}
@@ -721,66 +693,64 @@ void CLCDGfx::Cache()
m_dwTransitionStart = GetTickCount();
- TRACE(L"Textmorphing: time consumed: %0.2f\n",(double)(m_dwTransitionStart-dwStart)/(double)1000);
+ TRACE(L"Textmorphing: time consumed: %0.2f\n", (double)(m_dwTransitionStart - dwStart) / (double)1000);
}
//************************************************************************
// CLCDGfx::StartTransition
//************************************************************************
-void CLCDGfx::StartTransition(ETransitionType eType,LPRECT rect)
+void CLCDGfx::StartTransition(ETransitionType eType, LPRECT rect)
{
- if(!m_bInitialized)
+ if (!m_bInitialized)
return;
- if(rect != nullptr) {
+ if (rect != nullptr) {
m_rTransitionRegion.left = rect->left;
m_rTransitionRegion.right = rect->right;
m_rTransitionRegion.top = rect->top;
m_rTransitionRegion.bottom = rect->bottom;
- } else {
- SetRect(&m_rTransitionRegion,0,0,m_nWidth,m_nHeight);
+ }
+ else {
+ SetRect(&m_rTransitionRegion, 0, 0, m_nWidth, m_nHeight);
}
- if(eType == TRANSITION_RANDOM)
- m_eTransition = static_cast<ETransitionType>(GetRandomInt(0,2));
+ if (eType == TRANSITION_RANDOM)
+ m_eTransition = static_cast<ETransitionType>(GetRandomInt(0, 2));
else
m_eTransition = eType;
- if(m_bTransition) {
+ if (m_bTransition) {
EndTransition();
- memcpy(m_pBitmapBits,m_pLcdBitmapBits,sizeof(BYTE)*m_nWidth*m_nHeight*m_nBPP);
+ memcpy(m_pBitmapBits, m_pLcdBitmapBits, sizeof(BYTE)*m_nWidth*m_nHeight*m_nBPP);
}
- if(m_pSavedBitmapBits == nullptr)
+ if (m_pSavedBitmapBits == nullptr)
m_pSavedBitmapBits = (BYTE*)malloc(sizeof(BYTE)*m_nWidth*m_nHeight*m_nBPP);
- memcpy(m_pSavedBitmapBits, m_pBitmapBits,sizeof(BYTE)* m_nWidth * m_nHeight * m_nBPP);
+ memcpy(m_pSavedBitmapBits, m_pBitmapBits, sizeof(BYTE)* m_nWidth * m_nHeight * m_nBPP);
m_dwTransitionStart = 0;
- m_bTransition = true;
+ m_bTransition = true;
}
void CLCDGfx::EndTransition()
{
- if(m_pSavedBitmapBits != nullptr)
+ if (m_pSavedBitmapBits != nullptr)
free(m_pSavedBitmapBits);
m_pSavedBitmapBits = nullptr;
- if(!m_LMovingPixels.empty())
- {
+ if (!m_LMovingPixels.empty()) {
vector<SLCDPixel*>::iterator iter = m_LMovingPixels.begin();
- while(iter != m_LMovingPixels.end())
- {
+ while (iter != m_LMovingPixels.end()) {
delete *iter;
iter++;
}
m_LMovingPixels.clear();
iter = m_LStaticPixels.begin();
- while(iter != m_LStaticPixels.end())
- {
+ while (iter != m_LStaticPixels.end()) {
delete *iter;
iter++;
}
@@ -788,4 +758,4 @@ void CLCDGfx::EndTransition()
}
m_bTransition = false;
-} \ No newline at end of file
+}