Skip to content

Commit af98f30

Browse files
committed
BoxDraw: add custom text box for ImageFloatBox coordinates.
1 parent 4c94f6a commit af98f30

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/BoxDraw.cpp

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
99
#include "BoxDraw.h"
1010

11-
//#include <iostream>
12-
//using std::cout;
13-
//using std::endl;
11+
#include <iostream>
12+
using std::cout;
13+
using std::endl;
1414

1515
namespace PokemonAutomation{
1616
namespace NintendoSwitch{
@@ -33,11 +33,13 @@ BoxDraw::BoxDraw()
3333
, Y("<b>Y Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.3, 0.0, 1.0)
3434
, WIDTH("<b>Width:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.4, 0.0, 1.0)
3535
, HEIGHT("<b>Height:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.4, 0.0, 1.0)
36+
, BOX_COORDINATES(false, "ImageFloatBox coordinates", LockMode::LOCK_WHILE_RUNNING, "0.3, 0.3, 0.4, 0.4", "0.3, 0.3, 0.4, 0.4")
3637
{
3738
PA_ADD_OPTION(X);
3839
PA_ADD_OPTION(Y);
3940
PA_ADD_OPTION(WIDTH);
4041
PA_ADD_OPTION(HEIGHT);
42+
PA_ADD_OPTION(BOX_COORDINATES);
4143
}
4244

4345
class BoxDraw::DrawnBox : public ConfigOption::Listener, public VideoOverlay::MouseListener{
@@ -57,6 +59,7 @@ class BoxDraw::DrawnBox : public ConfigOption::Listener, public VideoOverlay::Mo
5759
m_parent.Y.add_listener(*this);
5860
m_parent.WIDTH.add_listener(*this);
5961
m_parent.HEIGHT.add_listener(*this);
62+
// m_parent.BOX_COORDINATES.add_listener(*this);
6063
overlay.add_listener(*this);
6164
}catch (...){
6265
detach();
@@ -67,6 +70,14 @@ class BoxDraw::DrawnBox : public ConfigOption::Listener, public VideoOverlay::Mo
6770
std::lock_guard<std::mutex> lg(m_lock);
6871
m_overlay_set.clear();
6972
m_overlay_set.add(COLOR_RED, {m_parent.X, m_parent.Y, m_parent.WIDTH, m_parent.HEIGHT});
73+
if (object == &m_parent.X || object == &m_parent.Y || object == &m_parent.WIDTH || object == &m_parent.HEIGHT){
74+
m_parent.update_box_coordinates();
75+
}
76+
// else if(object == &m_parent.BOX_COORDINATES){
77+
// // m_parent.update_individual_coordinates();
78+
// }
79+
80+
7081
}
7182
virtual void on_mouse_press(double x, double y) override{
7283
// m_parent.WIDTH.set(0);
@@ -101,6 +112,7 @@ class BoxDraw::DrawnBox : public ConfigOption::Listener, public VideoOverlay::Mo
101112
m_parent.Y.set(yl);
102113
m_parent.WIDTH.set(xh - xl);
103114
m_parent.HEIGHT.set(yh - yl);
115+
m_parent.update_box_coordinates();
104116
}
105117

106118
private:
@@ -121,7 +133,57 @@ class BoxDraw::DrawnBox : public ConfigOption::Listener, public VideoOverlay::Mo
121133
std::optional<std::pair<double, double>> m_mouse_start;
122134
};
123135

136+
void BoxDraw::update_box_coordinates(){
137+
BOX_COORDINATES.set(std::to_string(X) + ", " + std::to_string(Y) + ", " + std::to_string(WIDTH) + ", " + std::to_string(HEIGHT));
138+
}
139+
140+
std::vector<std::string> split(const std::string& str, const std::string& delimiter) {
141+
std::vector<std::string> tokens;
142+
size_t start = 0;
143+
size_t end = str.find(delimiter);
144+
145+
while (end != std::string::npos) {
146+
tokens.push_back(str.substr(start, end - start));
147+
start = end + delimiter.length();
148+
end = str.find(delimiter, start);
149+
}
150+
151+
tokens.push_back(str.substr(start));
152+
return tokens;
153+
}
154+
155+
156+
void BoxDraw::update_individual_coordinates(){
157+
std::string box_coord_string = BOX_COORDINATES;
158+
std::vector<std::string> all_coords = split(box_coord_string, ", ");
159+
160+
std::string x_string = all_coords[0];
161+
std::string y_string = all_coords[1];
162+
std::string width_string = all_coords[2];
163+
std::string height_string = all_coords[3];
164+
165+
double x_coord = std::stod(x_string);
166+
double y_coord = std::stod(y_string);
167+
double width_coord = std::stod(width_string);
168+
double height_coord = std::stod(height_string);
169+
170+
cout << box_coord_string << endl;
171+
cout << std::to_string(x_coord) << endl;
172+
cout << std::to_string(y_coord) << endl;
173+
cout << std::to_string(width_coord) << endl;
174+
cout << std::to_string(height_coord) << endl;
175+
176+
X.set(x_coord);
177+
Y.set(y_coord);
178+
WIDTH.set(width_coord);
179+
HEIGHT.set(height_coord);
180+
181+
// double x_coord1 = std::stod("0a.4aasdf");
182+
// cout << std::to_string(x_coord1) << endl;
183+
}
184+
124185
void BoxDraw::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
186+
update_individual_coordinates();
125187
DrawnBox drawn_box(*this, env.console.overlay());
126188
drawn_box.on_config_value_changed(this);
127189
context.wait_until_cancel();

SerialPrograms/Source/NintendoSwitch/DevPrograms/BoxDraw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PokemonAutomation_NintendoSwitch_BoxDraw_H
99

1010
#include "Common/Cpp/Options/FloatingPointOption.h"
11+
#include "Common/Cpp/Options/StringOption.h"
1112
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1213

1314
namespace PokemonAutomation{
@@ -26,6 +27,9 @@ class BoxDraw : public SingleSwitchProgramInstance{
2627
public:
2728
BoxDraw();
2829

30+
void update_box_coordinates();
31+
void update_individual_coordinates();
32+
2933
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
3034

3135
private:
@@ -36,6 +40,7 @@ class BoxDraw : public SingleSwitchProgramInstance{
3640
FloatingPointOption Y;
3741
FloatingPointOption WIDTH;
3842
FloatingPointOption HEIGHT;
43+
StringOption BOX_COORDINATES;
3944
};
4045

4146

0 commit comments

Comments
 (0)