Skip to content

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Feb 19, 2023
1 parent 2139547 commit d5ffc17
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
26 changes: 26 additions & 0 deletions VortexTestingFramework/EditorPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,41 @@ bool EditorPipe::init()
return true;
}

BOOL CALLBACK EditorPipe::findEditorWindow(HWND hwnd, LPARAM lParam)
{
char text[256] = {0};
if (!GetWindowText(hwnd, text, sizeof(text) - 1) || !text[0]) {
return true;
}
// try to find the word editor in the window so we don't send the message
// to the color picker or something
if (!strstr(text, "Editor")) {
return true;
}
// success
*(HWND *)lParam = hwnd;
return false;
}

bool EditorPipe::connect()
{
if (m_serialConnected) {
return true;
}
// create a global pipe
if (!ConnectNamedPipe(hPipe, NULL)) {
int err = GetLastError();
if (err != ERROR_PIPE_CONNECTED && err != ERROR_PIPE_LISTENING) {
return false;
}
}
HWND editor_hwnd = NULL;
EnumWindows(findEditorWindow, (LPARAM)&editor_hwnd);
HWND hwnd = FindWindow("VWINDOW", NULL);
if (hwnd != NULL) {
// send it a message to tell it the test framework is here
PostMessage(hwnd, WM_USER + 1, 0, 0);
}
m_serialConnected = true;
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions VortexTestingFramework/EditorPipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class EditorPipe
static bool isConnected() { return m_serialConnected; }

private:
// callback to find the editor window
static BOOL CALLBACK findEditorWindow(HWND hwnd, LPARAM lParam);

static HANDLE hPipe;
static bool m_serialConnected;
};
14 changes: 7 additions & 7 deletions VortexTestingFramework/GUI/VWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ VWindow::VWindow() :

VWindow::VWindow(HINSTANCE hinstance, const string &title,
COLORREF backcol, uint32_t width, uint32_t height,
void *callbackArg) :
void *callbackArg, const string &className) :
VWindow()
{
init(hinstance, title, backcol, width, height, callbackArg);
init(hinstance, title, backcol, width, height, callbackArg, className);
}

VWindow::~VWindow()
Expand All @@ -46,7 +46,7 @@ VWindow::~VWindow()

void VWindow::init(HINSTANCE hInstance, const string &title,
COLORREF backcol, uint32_t width, uint32_t height,
void *callbackArg)
void *callbackArg, const string &className)
{
// store callback
m_callbackArg = callbackArg;
Expand All @@ -57,14 +57,14 @@ void VWindow::init(HINSTANCE hInstance, const string &title,
m_foreEnabled = true;

// register a window class for the window if not done yet
registerWindowClass(hInstance, backcol);
registerWindowClass(hInstance, backcol, className);

// get desktop rect so we can center the window
RECT desktop;
GetClientRect(GetDesktopWindow(), &desktop);

// create the window
m_hwnd = CreateWindow(WC_VWINDOW, title.c_str(),
m_hwnd = CreateWindow(className.c_str(), title.c_str(),
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,
(desktop.right / 2) - (width / 2), (desktop.bottom / 2) - (height / 2),
width, height, nullptr, nullptr, hInstance, nullptr);
Expand Down Expand Up @@ -358,7 +358,7 @@ LRESULT CALLBACK VWindow::window_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

void VWindow::registerWindowClass(HINSTANCE hInstance, COLORREF backcol)
void VWindow::registerWindowClass(HINSTANCE hInstance, COLORREF backcol, const string &className)
{
if (m_wc.lpfnWndProc == VWindow::window_proc) {
// alredy registered
Expand All @@ -367,7 +367,7 @@ void VWindow::registerWindowClass(HINSTANCE hInstance, COLORREF backcol)
// class registration
m_wc.lpfnWndProc = VWindow::window_proc;
m_wc.hInstance = hInstance;
m_wc.lpszClassName = WC_VWINDOW;
m_wc.lpszClassName = className.c_str();
m_wc.hbrBackground = CreateSolidBrush(backcol);
RegisterClass(&m_wc);
}
9 changes: 3 additions & 6 deletions VortexTestingFramework/GUI/VWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <map>
#include <string>

// The window class
#define WC_VWINDOW "VWINDOW"

// The VWindow is the main window, there's only really supposed to be one
// if you want child windows that is a separate class. This is also the base
// class of all other GUI objects
Expand All @@ -23,12 +20,12 @@ class VWindow
VWindow();
VWindow(HINSTANCE hinstance, const std::string &title,
COLORREF backcol, uint32_t width, uint32_t height,
void *callbackArg);
void *callbackArg, const std::string &className);
virtual ~VWindow();

virtual void init(HINSTANCE hinstance, const std::string &title,
COLORREF backcol, uint32_t width, uint32_t height,
void *callbackArg);
void *callbackArg, const std::string &className);
virtual void cleanup();

virtual bool process(MSG &msg);
Expand Down Expand Up @@ -116,7 +113,7 @@ class VWindow

private:
static LRESULT CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void registerWindowClass(HINSTANCE hInstance, COLORREF backcol);
static void registerWindowClass(HINSTANCE hInstance, COLORREF backcol, const std::string &className);
static WNDCLASS m_wc;
};

6 changes: 3 additions & 3 deletions VortexTestingFramework/TestFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool TestFramework::init(HINSTANCE hInstance)
}

// load the main window
m_window.init(m_hInst, "Vortex Glove Emulator", BACK_COL, width, height, this);
m_window.init(m_hInst, "Vortex Glove Emulator", BACK_COL, width, height, this, "VortexTestFramework");

// load the icon and background image
m_hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_ICON1));
Expand Down Expand Up @@ -324,7 +324,7 @@ void TestFramework::setBrightness(int brightness)
// when the glove framework calls 'FastLED.show'
void TestFramework::show()
{
if (!m_initialized) {
if (!m_initialized || !m_ledList) {
return;
}
// update the colors with the colors in the led list
Expand All @@ -338,7 +338,7 @@ void TestFramework::show()

bool TestFramework::handlePatternChange(bool force)
{
if (!Modes::curMode()) {
if (!VortexEngine::curMode() || !m_ledList) {
return false;
}
// don't want to create a callback mechanism just for the test framework to be
Expand Down
2 changes: 1 addition & 1 deletion VortexTestingFramework/VortexEngine

0 comments on commit d5ffc17

Please sign in to comment.