#include "stdafx.h"
#include "ChromaSDKImpl.h"
#ifdef _WIN64
#define CHROMASDKDLL _T("RzChromaSDK64.dll")
#else
#define CHROMASDKDLL _T("RzChromaSDK.dll")
#endif
using namespace ChromaSDK;
using namespace ChromaSDK::Keyboard;
using namespace ChromaSDK::Keypad;
using namespace ChromaSDK::Mouse;
using namespace ChromaSDK::Mousepad;
using namespace ChromaSDK::Headset;
typedef RZRESULT (*REGISTEREVENTNOTIFICATION)(HWND hWnd);
typedef RZRESULT (*UNREGISTEREVENTNOTIFICATION)(void);
DWORD WINAPI Thread_LoadingAnimationOnKeyboard(LPVOID lpParameter)
{
{
{
for(UINT c=0; c<3; c++)
{
Effect.
Color[r][c] = ORANGE;
}
}
{
for(UINT c=0; c<6; c++)
{
Effect.
Color[r][c] = ORANGE;
}
}
{
for(UINT c=0; c<9; c++)
{
Effect.
Color[r][c] = ORANGE;
}
}
{
for(UINT c=0; c<12; c++)
{
Effect.
Color[r][c] = ORANGE;
}
}
{
for(UINT c=0; c<15; c++)
{
Effect.
Color[r][c] = ORANGE;
}
}
{
for(UINT c=0; c<18; c++)
{
Effect.
Color[r][c] = ORANGE;
}
}
Sleep(500);
Sleep(100);
Sleep(100);
Sleep(100);
Sleep(100);
Sleep(100);
Sleep(100);
StaticEffect.
Color = ORANGE;
}
{
}
return 0;
}
DWORD WINAPI Thread_LoadingAnimationOnMousepad(LPVOID lpParameter)
{
{
Sleep(500);
{
CustomEffect.
Color[i] = ORANGE;
Sleep(50);
}
}
return 0;
}
DWORD WINAPI Thread_LoadingAnimationOnMice(LPVOID lpParameter)
{
{
Sleep(500);
{
{
CustomEffect.
Color[row][col] = ORANGE;
}
Sleep(50);
}
}
return 0;
}
DWORD WINAPI Thread_LoadingAnimationOnKeypad(LPVOID lpParameter)
{
PTSTR szDevice = (PTSTR)lpParameter;
if(_tcsicmp(szDevice, _T("Orbweaver")) == 0)
{
DeviceId = ORBWEAVER_CHROMA;
}
else if(_tcsicmp(szDevice, _T("Tartarus")) == 0)
{
DeviceId = TARTARUS_CHROMA;
}
{
if(DeviceId == ORBWEAVER_CHROMA)
{
for(UINT i=0; i<1; i++)
{
{
Effect.
Color[j][i] = ORANGE;
}
}
for(UINT i=0; i<2; i++)
{
{
Effect.
Color[j][i] = ORANGE;
}
}
for(UINT i=0; i<3; i++)
{
{
Effect.
Color[j][i] = ORANGE;
}
}
for(UINT i=0; i<4; i++)
{
{
Effect.
Color[j][i] = ORANGE;
}
}
for(UINT i=0; i<5; i++)
{
{
Effect.
Color[j][i] = ORANGE;
}
}
}
else if(DeviceId == TARTARUS_CHROMA)
{
Effect.
Color[0][0] = RGB((255.0/100.0*0.2),((165.0/100.0)*0.2),00);
Effect.
Color[0][0] = RGB((255.0/100.0*0.4),((165.0/100.0)*0.4),00);
Effect.
Color[0][0] = RGB((255.0/100.0*0.6),((165.0/100.0)*0.6),00);
Effect.
Color[0][0] = RGB((255.0/100.0*0.8),((165.0/100.0)*0.8),00);
Effect.
Color[0][0] = ORANGE;
}
Sleep(500);
Sleep(100);
Sleep(100);
Sleep(100);
Sleep(100);
}
{
}
return 0;
}
struct _ActiveKeysData
{
UINT numKeys;
UINT Key[20];
COLORREF Color;
} ActiveKeysData;
DWORD WINAPI Thread_AnimateActiveKeysOnKeyboard(LPVOID lpParameter)
{
for(UINT i=0; i<ActiveKeysData.numKeys; i++)
{
COLORREF Color = 0x01000000 | ActiveKeysData.Color;
switch(ActiveKeysData.Key[i])
{
}
}
Sleep(50);
{
{
{
if((i == row) && (i < Keyboard::MAX_ROW))
{
Effect.
Color[row][col] = RGB(GetRValue(ORANGE),
GetGValue(ORANGE),
GetBValue(ORANGE));
}
if((i-1) == row)
{
Effect.
Color[row][col] = RGB(0.3 * GetRValue(ORANGE),
0.3 * GetGValue(ORANGE),
0.3 * GetBValue(ORANGE));
}
if((i-2) == row)
{
Effect.
Color[row][col] = RGB(0.1 * GetRValue(ORANGE),
0.1 * GetGValue(ORANGE),
0.1 * GetBValue(ORANGE));
}
}
}
Sleep(50);
}
return 0;
}
CChromaSDKImpl::CChromaSDKImpl():m_ChromaSDKModule(NULL)
{
}
CChromaSDKImpl::~CChromaSDKImpl()
{
}
BOOL CChromaSDKImpl::Initialize()
{
if(m_ChromaSDKModule == NULL)
{
m_ChromaSDKModule = LoadLibrary(CHROMASDKDLL);
if(m_ChromaSDKModule == NULL)
{
ASSERT(GetLastError() == ERROR_SUCCESS);
return FALSE;
}
}
{
Init = (INIT)GetProcAddress(m_ChromaSDKModule,
"Init");
{
{
CreateEffect = (CREATEEFFECT)GetProcAddress(m_ChromaSDKModule,
"CreateEffect");
CreateKeyboardEffect = (CREATEKEYBOARDEFFECT)GetProcAddress(m_ChromaSDKModule,
"CreateKeyboardEffect");
CreateMouseEffect = (CREATEMOUSEEFFECT)GetProcAddress(m_ChromaSDKModule,
"CreateMouseEffect");
CreateHeadsetEffect = (CREATEHEADSETEFFECT)GetProcAddress(m_ChromaSDKModule,
"CreateHeadsetEffect");
CreateMousepadEffect = (CREATEMOUSEPADEFFECT)GetProcAddress(m_ChromaSDKModule,
"CreateMousepadEffect");
CreateKeypadEffect = (CREATEKEYPADEFFECT)GetProcAddress(m_ChromaSDKModule,
"CreateKeypadEffect");
SetEffect = (SETEFFECT)GetProcAddress(m_ChromaSDKModule,
"SetEffect");
DeleteEffect = (DELETEEFFECT)GetProcAddress(m_ChromaSDKModule,
"DeleteEffect");
QueryDevice = (QUERYDEVICE)GetProcAddress(m_ChromaSDKModule,
"QueryDevice");
{
return TRUE;
}
else
{
return FALSE;
}
}
}
}
return TRUE;
}
BOOL CChromaSDKImpl::UnInitialize()
{
if(m_ChromaSDKModule != NULL)
{
UNINIT
UnInit = (UNINIT)GetProcAddress(m_ChromaSDKModule,
"UnInit");
if(UnInit)
{
}
FreeLibrary(m_ChromaSDKModule);
m_ChromaSDKModule = NULL;
return TRUE;
}
return FALSE;
}
void CChromaSDKImpl::PlayLoadingAnimation(UINT DeviceType)
{
HANDLE hWorkerThread = NULL;
switch(DeviceType)
{
case 1:
hWorkerThread = CreateThread(NULL, 0, Thread_LoadingAnimationOnKeyboard, this, 0, NULL);
CloseHandle(hWorkerThread);
break;
case 2:
hWorkerThread = CreateThread(NULL, 0, Thread_LoadingAnimationOnMousepad, this, 0, NULL);
CloseHandle(hWorkerThread);
break;
case 3:
hWorkerThread = CreateThread(NULL, 0, Thread_LoadingAnimationOnMice, this, 0, NULL);
CloseHandle(hWorkerThread);
break;
case 4:
break;
case 5:
hWorkerThread = CreateThread(NULL, 0, Thread_LoadingAnimationOnKeypad, _T("Orbweaver"), 0, NULL);
CloseHandle(hWorkerThread);
hWorkerThread = CreateThread(NULL, 0, Thread_LoadingAnimationOnKeypad, _T("Tartarus"), 0, NULL);
CloseHandle(hWorkerThread);
break;
}
}
void CChromaSDKImpl::ShowKeys(UINT DeviceType, UINT NumKeys, UINT VKey[], COLORREF Color, BOOL Animate)
{
switch(DeviceType)
{
case 1:
{
ActiveKeysData.numKeys = NumKeys;
ActiveKeysData.Color = Color;
memcpy_s(ActiveKeysData.Key,
sizeof(ActiveKeysData.Key),
VKey,
(sizeof(VKey) * NumKeys));
if(Animate == TRUE)
{
HANDLE hThread = CreateThread(NULL, 0, Thread_AnimateActiveKeysOnKeyboard, NULL, 0, NULL);
if(WaitForSingleObject(hThread, 5000) == WAIT_OBJECT_0)
{
CloseHandle(hThread);
}
}
else
{
for(UINT i=0; i<ActiveKeysData.numKeys; i++)
{
COLORREF Color = 0x01000000 | ActiveKeysData.Color;
switch(ActiveKeysData.Key[i])
{
}
}
}
}
break;
case 5:
{
for(UINT i=0; i<NumKeys; i++)
{
switch(VKey[i])
{
case 0x41: Effect.
Color[2][1] = Color;
break;
case 0x44: Effect.
Color[2][3] = Color;
break;
case 0x53: Effect.
Color[2][2] = Color;
break;
case 0x57: Effect.
Color[1][2] = Color;
break;
}
}
}
break;
}
}
void CChromaSDKImpl::ShowLevel(UINT DeviceType, UINT Hp, UINT Ammo)
{
switch(DeviceType)
{
case 1:
{
UINT RemainingHealth = UINT(Hp/100.0 * 12.0);
COLORREF HpColor = RGB((((12-RemainingHealth)/12.0)*255), ((RemainingHealth/12.0)*255), 0);
for(UINT i=0; i<RemainingHealth; i++)
{
Effect.
Key[HIBYTE(HpLevel+i)][LOBYTE(HpLevel+i)] = 0x01000000 | HpColor;
}
UINT RemainingAmmo = UINT(Ammo/100.0 * 10.0);
for(UINT i=0; i<RemainingAmmo; i++)
{
Effect.
Key[HIBYTE(AmmoLevel+i)][LOBYTE(AmmoLevel+i)] = 0x01000000 | YELLOW;
}
}
break;
case 2:
{
FLOAT RemainingHealth = FLOAT((FLOAT)Hp/100.0 * 5.0);
COLORREF HpColor;
if(RemainingHealth == 0.0)
{
HpColor = RED;
Effect.
Color[10] = HpColor;
Effect.
Color[11] = HpColor;
Effect.
Color[12] = HpColor;
Effect.
Color[13] = HpColor;
Effect.
Color[14] = HpColor;
}
else
{
HpColor = RGB((((5-RemainingHealth)/5.0)*255), ((RemainingHealth/5.0)*255), 0);
for(UINT i=0; i<RemainingHealth; i++)
{
Effect.
Color[10+i] = HpColor;
}
}
UINT RemainingAmmo = UINT(Ammo/100.0 * 5.0);
for(UINT i=0; i<RemainingAmmo; i++)
{
Effect.
Color[4-i] = YELLOW;
}
}
break;
case 3:
{
UINT RemainingHealth = UINT(Hp/100.0 * 7.0);
COLORREF HpColor = RGB((((5-RemainingHealth)/5.0)*255), ((RemainingHealth/5.0)*255), 0);
for(UINT i=0; i<RemainingHealth; i++)
{
}
UINT RemainingAmmo = UINT(Ammo/100.0 * 7.0);
for(UINT i=0; i<RemainingAmmo; i++)
{
}
}
break;
case 4:
{
Effect.
Color = RGB((255 - ((Hp/100.0) * 255.0)), ((Hp/100.0) * 255.0), 0);
}
break;
case 5:
{
FLOAT RemainingHealth = FLOAT((FLOAT)Hp/100.0 * 5.0);
COLORREF HpColor = RGB((((5-RemainingHealth)/5.0)*255), ((RemainingHealth/5.0)*255), 0);
for(UINT i=0; i<RemainingHealth; i++)
{
Effect.
Color[0][i] = HpColor;
}
UINT RemainingAmmo = UINT(Ammo/100.0 * 5.0);
for(UINT i=0; i<RemainingAmmo; i++)
{
Effect.
Color[3][i] = YELLOW;
}
}
break;
}
}
void CChromaSDKImpl::ShowAlert(UINT DeviceType, COLORREF Color)
{
switch(DeviceType)
{
case 1:
{
{
{
Effect.
Color[row][col] = Color;
}
}
for(UINT t=0; t<3; t++)
{
Sleep(200);
Sleep(200);
}
}
break;
case 2:
{
StaticEffect.
Color = Color;
for(UINT t=0; t<3; t++)
{
Sleep(200);
Sleep(200);
}
}
break;
case 3:
{
for(int i=0; i<Mouse::MAX_ROW; i++)
{
for(int j=0; j<Mouse::MAX_COLUMN; j++)
{
CustomEffect.
Color[i][j] = Color;
}
}
for(UINT t=0; t<3; t++)
{
Sleep(200);
Sleep(200);
}
}
break;
case 4:
{
for(UINT t=0; t<3; t++)
{
Sleep(200);
Sleep(200);
}
}
break;
case 5:
{
{
{
Effect.
Color[i][j] = Color;
}
}
for(UINT t=0; t<3; t++)
{
Sleep(200);
Sleep(200);
}
}
break;
}
}
void CChromaSDKImpl::ShowGauge(UINT DeviceType, UINT Level)
{
switch(DeviceType)
{
case 1:
{
UINT Gauge = UINT(Level/100.0 * 18.0);
switch(Gauge)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
case 13:
break;
case 14:
break;
case 15:
break;
case 16:
break;
case 17:
break;
case 18:
break;
}
}
break;
case 2:
{
UINT Gauge = UINT(Level/100.0 * 15.0);
for(UINT i=0; i<Gauge; i++)
{
}
}
break;
case 5:
{
UINT Gauge = UINT(Level/100.0 * 14.0);
switch(Gauge)
{
case 1:
Effect.
Color[0][0] = YELLOW;
break;
case 2:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
break;
case 3:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
break;
case 4:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
break;
case 5:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
break;
case 6:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
break;
case 7:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
break;
case 8:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
break;
case 9:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
Effect.
Color[3][3] = YELLOW;
break;
case 10:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
Effect.
Color[3][3] = YELLOW;
Effect.
Color[3][2] = YELLOW;
break;
case 11:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
Effect.
Color[3][3] = YELLOW;
Effect.
Color[3][2] = YELLOW;
Effect.
Color[3][1] = YELLOW;
break;
case 12:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
Effect.
Color[3][3] = YELLOW;
Effect.
Color[3][2] = YELLOW;
Effect.
Color[3][1] = YELLOW;
Effect.
Color[3][0] = YELLOW;
break;
case 13:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
Effect.
Color[3][3] = YELLOW;
Effect.
Color[3][2] = YELLOW;
Effect.
Color[3][1] = YELLOW;
Effect.
Color[3][0] = YELLOW;
Effect.
Color[2][0] = YELLOW;
break;
case 14:
Effect.
Color[0][0] = YELLOW;
Effect.
Color[0][1] = YELLOW;
Effect.
Color[0][2] = YELLOW;
Effect.
Color[0][3] = YELLOW;
Effect.
Color[0][4] = YELLOW;
Effect.
Color[1][4] = YELLOW;
Effect.
Color[2][4] = YELLOW;
Effect.
Color[3][4] = YELLOW;
Effect.
Color[3][3] = YELLOW;
Effect.
Color[3][2] = YELLOW;
Effect.
Color[3][1] = YELLOW;
Effect.
Color[3][0] = YELLOW;
Effect.
Color[2][0] = YELLOW;
Effect.
Color[1][0] = YELLOW;
break;
}
}
break;
}
}
void CChromaSDKImpl::ShowBitmap(UINT DeviceType, HBITMAP hBitmap)
{
HWND hDesktopWin = GetDesktopWindow();
HDC hDesktopDC = ::GetDC(hDesktopWin);
if(hDesktopDC)
{
HDC hDestDC = ::CreateCompatibleDC(hDesktopDC);
::SelectObject(hDestDC, hBitmap);
BITMAP bm;
::GetObject(hBitmap, sizeof(bm), &bm);
BITMAPINFOHEADER bmi = {0};
bmi.biSize = sizeof(BITMAPINFOHEADER);
bmi.biPlanes = bm.bmPlanes;
bmi.biBitCount = bm.bmBitsPixel;
if(DeviceType == 1)
{
}
else if(DeviceType == 5)
{
}
bmi.biCompression = BI_RGB;
bmi.biSizeImage = 0;
BYTE *pBits = NULL;
pBits = (BYTE*)malloc(4 * bmi.biWidth * bmi.biHeight);
ZeroMemory(pBits, (4 * bmi.biWidth * bmi.biHeight));
{
{
::GetDIBits(hDestDC, hBitmap, i, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
COLORREF *pColor = (COLORREF*)pBits;
{
Effect.
Color[i][j] = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
pColor++;
}
}
}
{
{
::GetDIBits(hDestDC, hBitmap, i, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
COLORREF *pColor = (COLORREF*)pBits;
{
Effect.
Color[i][j] = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
pColor++;
}
}
}
free(pBits);
::DeleteDC(hDestDC);
::ReleaseDC(hDesktopWin, hDesktopDC);
}
}
void CChromaSDKImpl::ShowDamageEffect(UINT DeviceType)
{
switch(DeviceType)
{
case 1:
{
Sleep(50);
}
break;
case 2:
{
Sleep(50);
}
break;
case 3:
{
for(int i=0; i<Mouse::MAX_ROW; i++)
{
for(int j=0; j<Mouse::MAX_COLUMN; j++)
{
Effect.
Color[i][j] = RED;
}
}
Sleep(50);
}
break;
case 4:
{
Sleep(50);
}
break;
}
}
void CChromaSDKImpl::ShowColor(UINT DeviceType, COLORREF Color)
{
switch(DeviceType)
{
case 1:
{
{
{
Effect.
Color[row][col] = Color;
}
}
}
break;
case 4:
{
}
break;
case 5:
{
{
{
Effect.
Color[i][j] = Color;
}
}
}
break;
}
}
void CChromaSDKImpl::ResetEffects(UINT DeviceType)
{
switch(DeviceType)
{
case 0:
{
}
{
}
{
}
{
}
{
}
break;
case 1:
{
}
break;
case 2:
{
}
break;
case 3:
{
}
break;
case 4:
{
}
break;
case 5:
{
}
break;
}
}
BOOL CChromaSDKImpl::IsDeviceConnected(
RZDEVICEID DeviceId)
{
{
}
return FALSE;
}