summaryrefslogtreecommitdiff
path: root/plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-12 13:43:31 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-12 13:43:31 +0300
commit8dd4143614ffa1a309f07f0b1a19921955f9c3f5 (patch)
treec99f5116020adb618d020fe4df7283fb5268d9ab /plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp
parent6312425c1ad093cad87a688497728fdb12e24385 (diff)
MirandaG15: warning fixes + massive code cleaning
Diffstat (limited to 'plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp')
-rw-r--r--plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp141
1 files changed, 65 insertions, 76 deletions
diff --git a/plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp b/plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp
index 53cd59b701..1694707897 100644
--- a/plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp
+++ b/plugins/MirandaG15/src/LCDFramework/CLCDOutputManager.cpp
@@ -14,9 +14,7 @@ CLCDOutputManager *CLCDOutputManager::m_pInstance = nullptr;
//************************************************************************
// Constructor
//************************************************************************
-CLCDOutputManager::CLCDOutputManager() : m_dwButtonRepeatDelay(300), m_pGfx(nullptr),
- m_pdwButtonRepeatTimers(nullptr), m_pdwButtonRepeatStarts(nullptr), m_pbButtonStates(nullptr),
- m_pLcdConnection(nullptr), m_bInitialized(false), m_dwLastUpdate(0), m_pActiveScreen(nullptr)
+CLCDOutputManager::CLCDOutputManager()
{
ASSERT(m_pInstance == nullptr);
@@ -62,21 +60,21 @@ CLCDScreen *CLCDOutputManager::GetActiveScreen()
//************************************************************************
// Initializes the OutputManager
//************************************************************************
-bool CLCDOutputManager::Initialize(tstring strAppletName,bool bAutostart, bool bConfigDialog)
+bool CLCDOutputManager::Initialize(tstring strAppletName, bool bAutostart, bool bConfigDialog)
{
- srand ( time(0) );
+ srand(time(0));
InitDebug();
m_strAppletName = strAppletName;
-
+
m_pGfx = new CLCDGfx();
m_pLcdConnection = new CLCDConnectionLogitech();
- if(!m_pLcdConnection->Initialize(m_strAppletName,bAutostart,bConfigDialog))
+ if (!m_pLcdConnection->Initialize(m_strAppletName, bAutostart, bConfigDialog))
return false;
-
-
+
+
m_bInitialized = true;
m_dwLastUpdate = GetTickCount();
@@ -101,15 +99,14 @@ bool CLCDOutputManager::Shutdown()
// Shutdown all screens
vector<CLCDScreen*>::iterator iter = m_Screens.begin();
- while(iter != m_Screens.end())
- {
+ while (iter != m_Screens.end()) {
(*(iter))->Shutdown();
iter++;
}
m_pLcdConnection->Shutdown();
-
-
+
+
delete m_pLcdConnection;
UnInitDebug();
@@ -120,7 +117,8 @@ bool CLCDOutputManager::Shutdown()
//************************************************************************
// called by CLCDConnection when connected to a device
//************************************************************************
-void CLCDOutputManager::OnDeviceConnected() {
+void CLCDOutputManager::OnDeviceConnected()
+{
InitializeGfxObject();
OnConnectionChanged(CONNECTED);
}
@@ -128,7 +126,8 @@ void CLCDOutputManager::OnDeviceConnected() {
//************************************************************************
// called by CLCDConnection when disconnected from a device
//************************************************************************
-void CLCDOutputManager::OnDeviceDisconnected() {
+void CLCDOutputManager::OnDeviceDisconnected()
+{
DeinitializeGfxObject();
OnConnectionChanged(DISCONNECTED);
}
@@ -136,23 +135,23 @@ void CLCDOutputManager::OnDeviceDisconnected() {
//************************************************************************
// Initializes the CGfx Object
//************************************************************************
-void CLCDOutputManager::InitializeGfxObject() {
- if(m_pGfx->IsInitialized())
+void CLCDOutputManager::InitializeGfxObject()
+{
+ if (m_pGfx->IsInitialized())
return;
TRACE(L"CLCDOutputManager::UpdateGfxObject(): initializing CLCDGfx\n");
SIZE size;
size = m_pLcdConnection->GetDisplaySize();
-
- m_pGfx->Initialize(size.cx,size.cy,m_pLcdConnection->GetColorCount(), m_pLcdConnection->GetPixelBuffer());
+
+ m_pGfx->Initialize(size.cx, size.cy, m_pLcdConnection->GetColorCount(), m_pLcdConnection->GetPixelBuffer());
int iButtonCount = m_pLcdConnection->GetButtonCount();
m_pbButtonStates = (bool*)malloc(sizeof(bool)*iButtonCount);
m_pdwButtonRepeatTimers = (DWORD*)malloc(sizeof(DWORD)*iButtonCount);
m_pdwButtonRepeatStarts = (DWORD*)malloc(sizeof(DWORD)*iButtonCount);
- for(int i=0;i<iButtonCount;i++)
- {
+ for (int i = 0; i < iButtonCount; i++) {
m_pbButtonStates[i] = false;
m_pdwButtonRepeatTimers[i] = 0;
m_pdwButtonRepeatStarts[i] = 0;
@@ -160,8 +159,7 @@ void CLCDOutputManager::InitializeGfxObject() {
// Update all screens sizes
vector<CLCDScreen*>::iterator iter = m_Screens.begin();
- while(iter != m_Screens.end())
- {
+ while (iter != m_Screens.end()) {
(*(iter))->OnSizeChanged();
iter++;
}
@@ -172,10 +170,11 @@ void CLCDOutputManager::InitializeGfxObject() {
//************************************************************************
// Deinitializes the CGfx Object
//************************************************************************
-void CLCDOutputManager::DeinitializeGfxObject() {
- if(!m_pGfx->IsInitialized())
+void CLCDOutputManager::DeinitializeGfxObject()
+{
+ if (!m_pGfx->IsInitialized())
return;
-
+
TRACE(L"CLCDOutputManager::UpdateGfxObject(): shutting down CLCDGfx\n");
m_pGfx->Shutdown();
@@ -194,56 +193,52 @@ bool CLCDOutputManager::Update()
ASSERT(m_bInitialized);
// Update the active screen
- if(m_pActiveScreen != nullptr)
- {
+ if (m_pActiveScreen != nullptr) {
m_pActiveScreen->Update();
// Check if the active screen has expired
- if(m_pActiveScreen->HasExpired())
- {
+ if (m_pActiveScreen->HasExpired()) {
// Call event handlers
DeactivateScreen();
return true;
}
}
- if(!m_pLcdConnection)
+ if (!m_pLcdConnection)
return true;
// Update
m_pLcdConnection->Update();
-
+
// skip button checking and drawing if there is no connection to a device
- if(m_pLcdConnection->GetConnectionState() != CONNECTED)
+ if (m_pLcdConnection->GetConnectionState() != CONNECTED)
return true;
-
+
// Handle buttons
bool bState = false;
int iId = 0;
- for(int i = 0; i < m_pLcdConnection->GetButtonCount(); i ++)
- {
+ for (int i = 0; i < m_pLcdConnection->GetButtonCount(); i++) {
// get current state
bState = m_pLcdConnection->GetButtonState(i);
// handle input event
- if(bState != m_pbButtonStates[i])
- {
+ if (bState != m_pbButtonStates[i]) {
iId = m_pLcdConnection->GetButtonId(i);
- if(bState) {
+ if (bState) {
OnLCDButtonDown(iId);
- } else {
+ }
+ else {
OnLCDButtonUp(iId);
}
m_pdwButtonRepeatStarts[i] = GetTickCount();
m_pdwButtonRepeatTimers[i] = m_pdwButtonRepeatStarts[i] + m_dwButtonRepeatDelay;
}
// check if repeat event should be sent
- else if(bState && m_pdwButtonRepeatTimers[i] <= GetTickCount())
- {
+ else if (bState && m_pdwButtonRepeatTimers[i] <= GetTickCount()) {
iId = m_pLcdConnection->GetButtonId(i);
-
+
// reduce the delay by 5% per second
DWORD dwNewDelay = m_dwButtonRepeatDelay - ((float)m_dwButtonRepeatDelay * 0.05 * (GetTickCount() - m_pdwButtonRepeatStarts[i]) / 250);
// delay may not be less than 25% of the original value
- if(dwNewDelay < m_dwButtonRepeatDelay * 0.25)
+ if (dwNewDelay < m_dwButtonRepeatDelay * 0.25)
dwNewDelay = m_dwButtonRepeatDelay * 0.25;
m_pdwButtonRepeatTimers[i] = GetTickCount() + dwNewDelay;
@@ -253,11 +248,10 @@ bool CLCDOutputManager::Update()
// save the current state
m_pbButtonStates[i] = bState;
}
-
+
// Draw
-
- if(m_pActiveScreen != nullptr && m_pGfx->IsInitialized())
- {
+
+ if (m_pActiveScreen != nullptr && m_pGfx->IsInitialized()) {
m_pGfx->BeginDraw();
m_pGfx->ClearScreen();
m_pActiveScreen->Draw(m_pGfx);
@@ -278,22 +272,20 @@ bool CLCDOutputManager::Update()
//************************************************************************
bool CLCDOutputManager::DeactivateScreen()
{
- if(m_pActiveScreen == nullptr)
+ if (m_pActiveScreen == nullptr)
return false;
CLCDScreen *pActiveScreen = m_pActiveScreen;
m_pActiveScreen = nullptr;
- if(pActiveScreen->HasExpired())
- {
+ if (pActiveScreen->HasExpired()) {
pActiveScreen->OnExpiration();
OnScreenExpired(pActiveScreen);
}
- else
- {
+ else {
OnScreenDeactivated(pActiveScreen);
pActiveScreen->OnDeactivation();
- }
+ }
return true;
}
@@ -301,12 +293,12 @@ bool CLCDOutputManager::DeactivateScreen()
// Activates the specified screen
//************************************************************************
bool CLCDOutputManager::ActivateScreen(CLCDScreen *pScreen)
-{
- if(m_pActiveScreen == pScreen)
+{
+ if (m_pActiveScreen == pScreen)
return false;
-
+
// If another screen is currently active, deactivate it
- if(m_pActiveScreen != nullptr)
+ if (m_pActiveScreen != nullptr)
DeactivateScreen();
m_pActiveScreen = pScreen;
@@ -321,13 +313,12 @@ bool CLCDOutputManager::AddScreen(CLCDScreen *pScreen)
{
// Check if the screen is already managed
vector<CLCDScreen*>::iterator iter = m_Screens.begin();
- while(iter != m_Screens.end())
- {
- if(*(iter) == pScreen)
+ while (iter != m_Screens.end()) {
+ if (*(iter) == pScreen)
return false;
iter++;
}
-
+
m_Screens.push_back(pScreen);
return true;
}
@@ -337,15 +328,13 @@ bool CLCDOutputManager::AddScreen(CLCDScreen *pScreen)
//************************************************************************
bool CLCDOutputManager::RemoveScreen(CLCDScreen *pScreen)
{
- if(m_Screens.empty())
+ if (m_Screens.empty())
return false;
// Find the screen and remove it from the list of managed screens
vector<CLCDScreen*>::iterator iter = m_Screens.begin();
- while(iter != m_Screens.end())
- {
- if(*(iter) == pScreen)
- {
+ while (iter != m_Screens.end()) {
+ if (*(iter) == pScreen) {
m_Screens.erase(iter);
return true;
}
@@ -357,9 +346,9 @@ bool CLCDOutputManager::RemoveScreen(CLCDScreen *pScreen)
//************************************************************************
// starts a screen transition
//************************************************************************
-void CLCDOutputManager::StartTransition(ETransitionType eTransition,LPRECT rect)
+void CLCDOutputManager::StartTransition(ETransitionType eTransition, LPRECT rect)
{
- m_pGfx->StartTransition(eTransition,rect);
+ m_pGfx->StartTransition(eTransition, rect);
}
//************************************************************************
@@ -374,14 +363,14 @@ void CLCDOutputManager::SetButtonRepeatDelay(DWORD dwDelay)
// Called when a screen has been deactivated
//************************************************************************
void CLCDOutputManager::OnScreenDeactivated(CLCDScreen*)
-{
+{
}
//************************************************************************
// Called when a screen has expired
//************************************************************************
void CLCDOutputManager::OnScreenExpired(CLCDScreen*)
-{
+{
}
//************************************************************************
@@ -389,7 +378,7 @@ void CLCDOutputManager::OnScreenExpired(CLCDScreen*)
//************************************************************************
void CLCDOutputManager::OnLCDButtonRepeated(int iButton)
{
- if(m_pActiveScreen) {
+ if (m_pActiveScreen) {
m_pActiveScreen->OnLCDButtonRepeated(iButton);
}
}
@@ -399,7 +388,7 @@ void CLCDOutputManager::OnLCDButtonRepeated(int iButton)
//************************************************************************
void CLCDOutputManager::OnLCDButtonDown(int iButton)
{
- if(m_pActiveScreen)
+ if (m_pActiveScreen)
m_pActiveScreen->OnLCDButtonDown(iButton);
}
@@ -408,7 +397,7 @@ void CLCDOutputManager::OnLCDButtonDown(int iButton)
//************************************************************************
void CLCDOutputManager::OnLCDButtonUp(int iButton)
{
- if(m_pActiveScreen)
+ if (m_pActiveScreen)
m_pActiveScreen->OnLCDButtonUp(iButton);
}
@@ -436,7 +425,7 @@ void CLCDOutputManager::OnLCDDisconnected()
//************************************************************************
// Called by the LCDManager to open a config dialog
//************************************************************************
-DWORD WINAPI CLCDOutputManager::configDialogCallback(IN int connection,IN const PVOID pContext)
+DWORD WINAPI CLCDOutputManager::configDialogCallback(IN int connection, IN const PVOID pContext)
{
return CLCDOutputManager::GetInstance()->OnConfigDialogRequest(connection, pContext);
}
@@ -447,4 +436,4 @@ DWORD WINAPI CLCDOutputManager::configDialogCallback(IN int connection,IN const
DWORD CLCDOutputManager::OnConfigDialogRequest(int, const PVOID)
{
return 0;
-} \ No newline at end of file
+}