Skip to content

Commit

Permalink
Add new parameters (proportion and offset) to the mouse Click. It wil…
Browse files Browse the repository at this point in the history
…l be possible to click e.g. sliderarea at certain positions.
  • Loading branch information
Sebastian Feustel committed Mar 11, 2024
1 parent 1508416 commit 6b24d6d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/include/Spix/TestServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class SPIX_EXPORT TestServer {
void wait(std::chrono::milliseconds waitTime);
void mouseClick(ItemPath path);
void mouseClick(ItemPath path, MouseButton mouseButton);
void mouseClick(ItemPath path, Point proportion);
void mouseClick(ItemPath path, Point proportion, Point offset);
void mouseBeginDrag(ItemPath path);
void mouseEndDrag(ItemPath path);
void mouseDropUrls(ItemPath path, const std::vector<std::string>& urls);
Expand Down
17 changes: 17 additions & 0 deletions lib/src/AnyRpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ AnyRpcServer::AnyRpcServer(int anyrpcPort)
"mouseButton)",
[this](std::string path, int mouseButton) { mouseClick(std::move(path), mouseButton); });

utils::AddFunctionToAnyRpc<void(std::string, double, double)>(methodManager, "mouseClickWithOffset",
"Click on the object at the given path with the given offset | mouseClickWithOffset(string path, float "
"offsetX, float offsetY)",
[this](std::string path, double offsetX, double offsetY) {
auto proportion = Point(0, 0);
auto offset = Point(offsetX, offsetY);
mouseClick(std::move(path), proportion, offset);
});

utils::AddFunctionToAnyRpc<void(std::string, double, double)>(methodManager, "mouseClickWithProportion",
"Click on the object at the given path with the given proportion | mouseClickWithProportion(string path, float "
"proportionX, float proportionY)",
[this](std::string path, double proportionX, double proportionY) {
auto proportion = Point(proportionX, proportionY);
mouseClick(std::move(path), proportion);
});

utils::AddFunctionToAnyRpc<void(std::string)>(methodManager, "mouseBeginDrag",
"Begin a drag with the mouse | mouseBeginDrag(string path)",
[this](std::string path) { mouseBeginDrag(std::move(path)); });
Expand Down
12 changes: 12 additions & 0 deletions lib/src/TestServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ void TestServer::mouseClick(ItemPath path)
m_cmdExec->enqueueCommand<cmd::ClickOnItem>(path, spix::MouseButtons::Left);
}

void TestServer::mouseClick(ItemPath path, Point proportion)
{
auto pathWithProportion = ItemPosition(path.string(), proportion);
m_cmdExec->enqueueCommand<cmd::ClickOnItem>(pathWithProportion, spix::MouseButtons::Left);
}

void TestServer::mouseClick(ItemPath path, Point proportion, Point offset)
{
auto pathWithOffset = ItemPosition(path.string(), proportion, offset);
m_cmdExec->enqueueCommand<cmd::ClickOnItem>(pathWithOffset, spix::MouseButtons::Left);
}

void TestServer::mouseClick(ItemPath path, MouseButton mouseButton)
{
m_cmdExec->enqueueCommand<cmd::ClickOnItem>(path, mouseButton);
Expand Down
11 changes: 11 additions & 0 deletions lib/src/Utils/AnyRpcFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ int unpackAnyRpcParam(anyrpc::Value& value)
return value.GetInt();
}


template <>
double unpackAnyRpcParam(anyrpc::Value& value)
{
if (!value.IsNumber()) {
throw anyrpc::AnyRpcException(anyrpc::AnyRpcErrorInvalidParams, "Invalid parameters. Expected double.");
}
return value.GetDouble();
}


template <>
unsigned unpackAnyRpcParam(anyrpc::Value& value)
{
Expand Down

0 comments on commit 6b24d6d

Please sign in to comment.