44 *
55 */
66
7+ #include < QLabel>
8+ #include < QDir>
79#include < QVBoxLayout>
10+ #include < QGraphicsView>
11+ #include < QGraphicsScene>
12+ #include < QGraphicsPixmapItem>
813#include < QScrollArea>
14+ #include < QPushButton>
15+ #include < QResizeEvent>
16+ #include < iostream>
17+ #include " Common/Cpp/Json/JsonObject.h"
918#include " Common/Cpp/Json/JsonValue.h"
1019#include " Common/Qt/CollapsibleGroupBox.h"
20+ #include " CommonFramework/VideoPipeline/VideoOverlayScopes.h"
21+ #include " NintendoSwitch/Framework/UI/NintendoSwitch_SwitchSystemWidget.h"
22+ #include " CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.h"
1123#include " ML_LabelImages.h"
1224#include " Pokemon/Pokemon_Strings.h"
25+ #include " Common/Qt/Options/ConfigWidget.h"
26+
27+
28+ using std::cout;
29+ using std::endl;
1330
1431namespace PokemonAutomation {
1532namespace ML {
1633
34+
35+ DrawnBoundingBox::DrawnBoundingBox (LabelImages& parent, VideoOverlay& overlay)
36+ : m_parent(parent)
37+ , m_overlay(overlay)
38+ , m_overlay_set(overlay)
39+ {
40+ m_parent.X .add_listener (*this );
41+ m_parent.Y .add_listener (*this );
42+ m_parent.WIDTH .add_listener (*this );
43+ m_parent.HEIGHT .add_listener (*this );
44+ overlay.add_listener (*this );
45+ }
46+
47+ DrawnBoundingBox::~DrawnBoundingBox (){
48+ detach ();
49+ }
50+
51+ void DrawnBoundingBox::on_config_value_changed (void * object){
52+ std::lock_guard<std::mutex> lg (m_lock);
53+ m_overlay_set.clear ();
54+ m_overlay_set.add (COLOR_RED, {m_parent.X , m_parent.Y , m_parent.WIDTH , m_parent.HEIGHT });
55+ }
56+ void DrawnBoundingBox::on_mouse_press (double x, double y){
57+ m_parent.WIDTH .set (0 );
58+ m_parent.HEIGHT .set (0 );
59+ m_parent.X .set (x);
60+ m_parent.Y .set (y);
61+ m_mouse_start.emplace ();
62+ m_mouse_start->first = x;
63+ m_mouse_start->second = y;
64+ }
65+ void DrawnBoundingBox::on_mouse_release (double x, double y){
66+ m_mouse_start.reset ();
67+ }
68+ void DrawnBoundingBox::on_mouse_move (double x, double y){
69+ if (!m_mouse_start){
70+ return ;
71+ }
72+
73+ double xl = m_mouse_start->first ;
74+ double xh = x;
75+ double yl = m_mouse_start->second ;
76+ double yh = y;
77+
78+ if (xl > xh){
79+ std::swap (xl, xh);
80+ }
81+ if (yl > yh){
82+ std::swap (yl, yh);
83+ }
84+
85+ m_parent.X .set (xl);
86+ m_parent.Y .set (yl);
87+ m_parent.WIDTH .set (xh - xl);
88+ m_parent.HEIGHT .set (yh - yl);
89+ }
90+
91+ void DrawnBoundingBox::detach (){
92+ m_overlay.remove_listener (*this );
93+ m_parent.X .remove_listener (*this );
94+ m_parent.Y .remove_listener (*this );
95+ m_parent.WIDTH .remove_listener (*this );
96+ m_parent.HEIGHT .remove_listener (*this );
97+ }
98+
99+
17100LabelImages_Descriptor::LabelImages_Descriptor ()
18101 : PanelDescriptor(
19102 Color (),
@@ -25,45 +108,55 @@ LabelImages_Descriptor::LabelImages_Descriptor()
25108{}
26109
27110
111+ #define ADD_OPTION (x ) m_options.add_option(x, #x)
28112
29113LabelImages::LabelImages (const LabelImages_Descriptor& descriptor)
30114 : PanelInstance(descriptor)
31- // , m_switch({}, false)
32- {}
115+ , m_switch_control_option({}, false )
116+ , m_options(LockMode::UNLOCK_WHILE_RUNNING)
117+ , X(" <b>X Coordinate:</b>" , LockMode::UNLOCK_WHILE_RUNNING, 0.3 , 0.0 , 1.0 )
118+ , Y(" <b>Y Coordinate:</b>" , LockMode::UNLOCK_WHILE_RUNNING, 0.3 , 0.0 , 1.0 )
119+ , WIDTH(" <b>Width:</b>" , LockMode::UNLOCK_WHILE_RUNNING, 0.4 , 0.0 , 1.0 )
120+ , HEIGHT(" <b>Height:</b>" , LockMode::UNLOCK_WHILE_RUNNING, 0.4 , 0.0 , 1.0 )
121+ {
122+ ADD_OPTION (X);
123+ ADD_OPTION (Y);
124+ ADD_OPTION (WIDTH);
125+ ADD_OPTION (HEIGHT);
126+ }
33127void LabelImages::from_json (const JsonValue& json){
34- // m_switch.load_json(json);
128+ const JsonObject* obj = json.to_object ();
129+ if (obj == nullptr ){
130+ return ;
131+ }
132+ const JsonValue* value = obj->get_value (" SwitchSetup" );
133+ if (value){
134+ m_switch_control_option.load_json (*value);
135+ }
136+ m_options.load_json (json);
35137}
36138JsonValue LabelImages::to_json () const {
37- return {};
38- // return m_switch.to_json();
139+ JsonObject obj = std::move (*m_options.to_json ().to_object ());
140+ obj[" SwitchSetup" ] = m_switch_control_option.to_json ();
141+ return obj;
39142}
40143QWidget* LabelImages::make_widget (QWidget& parent, PanelHolder& holder){
41- return LabelImages_Widget::make (parent, *this , holder);
144+ return new LabelImages_Widget (parent, *this , holder);
42145}
43146
44147
45-
46- LabelImages_Widget* LabelImages_Widget::make (
47- QWidget& parent,
48- LabelImages& instance,
49- PanelHolder& holder
50- ){
51- LabelImages_Widget* widget = new LabelImages_Widget (parent, instance, holder);
52- widget->construct ();
53- return widget;
54- }
55148LabelImages_Widget::~LabelImages_Widget (){
56- // delete m_switch ;
149+ delete m_switch_widget ;
57150}
58151LabelImages_Widget::LabelImages_Widget (
59152 QWidget& parent,
60153 LabelImages& instance,
61154 PanelHolder& holder
62155)
63156 : PanelWidget(parent, instance, holder)
64- // , m_session(instance.m_switch , 0, 0)
65- {}
66- void LabelImages_Widget::construct () {
157+ , m_session(instance.m_switch_control_option , 0 , 0 )
158+ , m_drawn_box(instance, m_session.overlay())
159+ {
67160 QVBoxLayout* layout = new QVBoxLayout (this );
68161 layout->setContentsMargins (0 , 0 , 0 , 0 );
69162 layout->addWidget (make_header (*this ));
@@ -77,10 +170,15 @@ void LabelImages_Widget::construct(){
77170 QVBoxLayout* scroll_layout = new QVBoxLayout (scroll_inner);
78171 scroll_layout->setAlignment (Qt::AlignTop);
79172
80- // m_switch = new SwitchSystemWidget(*this, m_session, 0);
81- // scroll_layout->addWidget(m_switch);
82- }
173+ m_switch_widget = new NintendoSwitch::SwitchSystemWidget (*this , m_session, 0 );
174+ scroll_layout->addWidget (m_switch_widget);
175+
176+ QPushButton* button = new QPushButton (" This is a button" , scroll_inner);
177+ scroll_layout->addWidget (button);
83178
179+ m_option_widget = instance.m_options .make_QtWidget (*scroll_inner);
180+ scroll_layout->addWidget (&m_option_widget->widget ());
181+ }
84182
85183
86184
0 commit comments