Skip to content

Commit 9d9519a

Browse files
author
Gin
committed
add more image display UI
1 parent 4caa014 commit 9d9519a

11 files changed

+629
-60
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,12 @@ file(GLOB MAIN_SOURCES
894894
Source/ML/ML_Panels.h
895895
Source/ML/Programs/ML_LabelImages.cpp
896896
Source/ML/Programs/ML_LabelImages.h
897+
Source/ML/UI/ML_ImageDisplayCommandRow.cpp
898+
Source/ML/UI/ML_ImageDisplayCommandRow.h
899+
Source/ML/UI/ML_ImageDisplayOption.cpp
900+
Source/ML/UI/ML_ImageDisplayOption.h
901+
Source/ML/UI/ML_ImageDisplaySession.cpp
902+
Source/ML/UI/ML_ImageDisplaySession.h
897903
Source/ML/UI/ML_ImageDisplayWidget.cpp
898904
Source/ML/UI/ML_ImageDisplayWidget.h
899905
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp

SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ LabelImages_Descriptor::LabelImages_Descriptor()
195195

196196
LabelImages::LabelImages(const LabelImages_Descriptor& descriptor)
197197
: PanelInstance(descriptor)
198-
, m_switch_control_option({}, false)
199198
, m_options(LockMode::UNLOCK_WHILE_RUNNING)
200199
, X("<b>X Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.3, 0.0, 1.0)
201200
, Y("<b>Y Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, 0.3, 0.0, 1.0)
@@ -413,12 +412,12 @@ LabelImages_Widget::~LabelImages_Widget(){
413412
}
414413
LabelImages_Widget::LabelImages_Widget(
415414
QWidget& parent,
416-
LabelImages& instance,
415+
LabelImages& program,
417416
PanelHolder& holder
418417
)
419-
: PanelWidget(parent, instance, holder)
420-
, m_program(instance)
421-
, m_session(instance.m_switch_control_option, 0, 0)
418+
: PanelWidget(parent, program, holder)
419+
, m_program(program)
420+
, m_session(program.m_switch_control_option, 0, 0)
422421
, m_overlay_set(m_session.overlay())
423422
, m_drawn_box(*this, m_session.overlay())
424423
{
@@ -453,10 +452,10 @@ LabelImages_Widget::LabelImages_Widget(
453452
program.update_rendered_objects(this->m_overlay_set);
454453
});
455454

456-
m_option_widget = instance.m_options.make_QtWidget(*scroll_inner);
455+
m_option_widget = program.m_options.make_QtWidget(*scroll_inner);
457456
scroll_layout->addWidget(&m_option_widget->widget());
458457

459-
const VideoSourceDescriptor* video_source_desc = instance.m_switch_control_option.m_video.descriptor().get();
458+
const VideoSourceDescriptor* video_source_desc = program.m_switch_control_option.m_video.descriptor().get();
460459
auto image_source_desc = dynamic_cast<const VideoSourceDescriptor_StillImage*>(video_source_desc);
461460
if (image_source_desc != nullptr){
462461
const std::string image_path = image_source_desc->path();

SerialPrograms/Source/ML/Programs/ML_LabelImages.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
2121
#include <QGraphicsScene>
2222
#include "ML/DataLabeling/SegmentAnythingModel.h"
23+
#include "ML/UI/ML_ImageDisplayOption.h"
24+
#include "ML/UI/ML_ImageDisplaySession.h"
2325

2426
class QGraphicsView;
2527
class QGraphicsPixmapItem;
@@ -78,9 +80,8 @@ class LabelImages : public PanelInstance{
7880
private:
7981
friend class LabelImages_Widget;
8082
friend class DrawnBoundingBox;
81-
// switch control options like what micro-controller
82-
// and what video source to use
83-
NintendoSwitch::SwitchSystemOption m_switch_control_option;
83+
// image display options like what image file is loaded
84+
ImageDisplayOption m_switch_control_option;
8485
// the group option that holds rest of the options defined below:
8586
BatchOption m_options;
8687

@@ -143,7 +144,7 @@ class LabelImages_Widget : public PanelWidget, public ConfigOption::Listener{
143144

144145
private:
145146
LabelImages& m_program;
146-
NintendoSwitch::SwitchSystemSession m_session;
147+
ImageDisplaySession m_session;
147148
ImageDisplayWidget* m_switch_widget;
148149
VideoOverlaySet m_overlay_set;
149150
DrawnBoundingBox m_drawn_box;
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
/* Command Row
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include <QHBoxLayout>
8+
#include "Common/Qt/Options/ConfigWidget.h"
9+
#include "CommonFramework/GlobalSettingsPanel.h"
10+
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
11+
#include "CommonFramework/Recording/StreamHistoryOption.h"
12+
#include "ML_ImageDisplayCommandRow.h"
13+
14+
//#include <iostream>
15+
//using std::cout;
16+
//using std::endl;
17+
18+
namespace PokemonAutomation{
19+
namespace ML{
20+
21+
22+
ImageDisplayCommandRow::~ImageDisplayCommandRow(){
23+
m_session.remove_listener(*this);
24+
}
25+
ImageDisplayCommandRow::ImageDisplayCommandRow(
26+
QWidget& parent,
27+
VideoOverlaySession& session
28+
)
29+
: QWidget(&parent)
30+
, m_session(session)
31+
, m_last_known_focus(false)
32+
, m_last_known_state(ProgramState::STOPPED)
33+
{
34+
QHBoxLayout* command_row = new QHBoxLayout(this);
35+
command_row->setContentsMargins(0, 0, 0, 0);
36+
37+
command_row->addWidget(new QLabel("<b>Console Type:</b>", this), 2);
38+
command_row->addSpacing(5);
39+
40+
QHBoxLayout* row = new QHBoxLayout();
41+
command_row->addLayout(row, 12);
42+
43+
44+
#if 0
45+
row->addWidget(new QLabel("<b>Keyboard Input:</b>", this), 2);
46+
row->addSpacing(5);
47+
#endif
48+
49+
row->addStretch(100);
50+
51+
m_status = new QLabel(this);
52+
// m_status->setVisible(false);
53+
row->addWidget(m_status);
54+
row->addSpacing(5);
55+
56+
// row->addWidget(new QLabel("<b>Overlays:<b>", this));
57+
58+
m_overlay_boxes = new QCheckBox("Boxes", this);
59+
m_overlay_boxes->setChecked(session.enabled_boxes());
60+
row->addWidget(m_overlay_boxes);
61+
62+
m_overlay_text = new QCheckBox("Text", this);
63+
m_overlay_text->setHidden(true); // Nothing uses text overlay yet.
64+
m_overlay_text->setChecked(session.enabled_text());
65+
row->addWidget(m_overlay_text);
66+
67+
if (PreloadSettings::instance().DEVELOPER_MODE){
68+
m_overlay_images = new QCheckBox("Masks", this);
69+
m_overlay_images->setChecked(session.enabled_images());
70+
row->addWidget(m_overlay_images);
71+
}
72+
73+
m_overlay_log = new QCheckBox("Log", this);
74+
m_overlay_log->setChecked(session.enabled_log());
75+
row->addWidget(m_overlay_log);
76+
77+
m_overlay_stats = new QCheckBox("Stats", this);
78+
m_overlay_stats->setChecked(session.enabled_stats());
79+
row->addWidget(m_overlay_stats);
80+
81+
row->addSpacing(5);
82+
83+
m_load_profile_button = new QPushButton("Load Profile", this);
84+
row->addWidget(m_load_profile_button, 2);
85+
86+
m_save_profile_button = new QPushButton("Save Profile", this);
87+
row->addWidget(m_save_profile_button, 2);
88+
89+
m_screenshot_button = new QPushButton("Screenshot", this);
90+
// m_screenshot_button->setToolTip("Take a screenshot of the console and save to disk.");
91+
row->addWidget(m_screenshot_button, 2);
92+
93+
94+
// m_test_button = new QPushButton("Test Button", this);
95+
// row->addWidget(m_test_button, 3);
96+
97+
update_ui();
98+
99+
connect(
100+
m_overlay_boxes, &QCheckBox::clicked,
101+
this, [this](bool checked){ m_session.set_enabled_boxes(checked); }
102+
);
103+
#if QT_VERSION < 0x060700
104+
connect(
105+
m_overlay_text, &QCheckBox::stateChanged,
106+
this, [this](bool checked){ m_session.set_enabled_text(checked); }
107+
);
108+
connect(
109+
m_overlay_images, &QCheckBox::stateChanged,
110+
this, [this](bool checked){ m_session.set_enabled_images(checked); }
111+
);
112+
connect(
113+
m_overlay_log, &QCheckBox::stateChanged,
114+
this, [this](bool checked){ m_session.set_enabled_log(checked); }
115+
);
116+
connect(
117+
m_overlay_stats, &QCheckBox::stateChanged,
118+
this, [this](bool checked){ m_session.set_enabled_stats(checked); }
119+
);
120+
#else
121+
connect(
122+
m_overlay_text, &QCheckBox::checkStateChanged,
123+
this, [this](Qt::CheckState state){ m_session.set_enabled_text(state == Qt::Checked); }
124+
);
125+
if (PreloadSettings::instance().DEVELOPER_MODE){
126+
connect(
127+
m_overlay_images, &QCheckBox::checkStateChanged,
128+
this, [this](Qt::CheckState state){ m_session.set_enabled_images(state == Qt::Checked); }
129+
);
130+
}
131+
connect(
132+
m_overlay_log, &QCheckBox::checkStateChanged,
133+
this, [this](Qt::CheckState state){ m_session.set_enabled_log(state == Qt::Checked); }
134+
);
135+
connect(
136+
m_overlay_stats, &QCheckBox::checkStateChanged,
137+
this, [this](Qt::CheckState state){ m_session.set_enabled_stats(state == Qt::Checked); }
138+
);
139+
#endif
140+
connect(
141+
m_load_profile_button, &QPushButton::clicked,
142+
this, [this](bool) { emit load_profile(); }
143+
);
144+
connect(
145+
m_save_profile_button, &QPushButton::clicked,
146+
this, [this](bool) { emit save_profile(); }
147+
);
148+
connect(
149+
m_screenshot_button, &QPushButton::clicked,
150+
this, [this](bool){ emit screenshot_requested(); }
151+
);
152+
153+
#if (QT_VERSION_MAJOR == 6) && (QT_VERSION_MINOR >= 8)
154+
if (IS_BETA_VERSION || PreloadSettings::instance().DEVELOPER_MODE){
155+
m_video_button = new QPushButton("Video Capture", this);
156+
command_row->addWidget(m_video_button, 2);
157+
if (GlobalSettings::instance().STREAM_HISTORY->enabled()){
158+
connect(
159+
m_video_button, &QPushButton::clicked,
160+
this, [this](bool){ emit video_requested(); }
161+
);
162+
}else{
163+
m_video_button->setEnabled(false);
164+
m_video_button->setToolTip("Please turn on Stream History to enable video capture.");
165+
}
166+
}
167+
#endif
168+
169+
m_session.add_listener(*this);
170+
}
171+
172+
void ImageDisplayCommandRow::on_key_press(const QKeyEvent& key){
173+
if (!m_last_known_focus){
174+
m_session.add_log("Keyboard Command Suppressed: Not in focus.", COLOR_RED);
175+
return;
176+
}
177+
}
178+
void ImageDisplayCommandRow::on_key_release(const QKeyEvent& key){}
179+
180+
void ImageDisplayCommandRow::set_focus(bool focused){
181+
if (m_last_known_focus == focused){
182+
return;
183+
}
184+
m_last_known_focus = focused;
185+
update_ui();
186+
}
187+
188+
void ImageDisplayCommandRow::update_ui(){
189+
// cout << "ImageDisplayCommandRow::update_ui(): focus = " << m_last_known_focus << endl;
190+
191+
bool stopped = m_last_known_state == ProgramState::STOPPED;
192+
m_load_profile_button->setEnabled(stopped);
193+
194+
if (!m_last_known_focus){
195+
m_status->setText(
196+
QString::fromStdString(
197+
"Keyboard: " + html_color_text("&#x2b24;", COLOR_PURPLE)
198+
)
199+
);
200+
return;
201+
}
202+
203+
m_status->setText(
204+
QString::fromStdString(
205+
"Keyboard: " + html_color_text("&#x2b24;", COLOR_DARKGREEN)
206+
)
207+
);
208+
}
209+
210+
void ImageDisplayCommandRow::on_state_changed(ProgramState state){
211+
m_last_known_state = state;
212+
update_ui();
213+
}
214+
215+
216+
void ImageDisplayCommandRow::on_overlay_enabled_boxes(bool enabled){
217+
QMetaObject::invokeMethod(this, [this, enabled]{
218+
this->m_overlay_boxes->setChecked(enabled);
219+
}, Qt::QueuedConnection);
220+
}
221+
void ImageDisplayCommandRow::on_overlay_enabled_text(bool enabled){
222+
QMetaObject::invokeMethod(this, [this, enabled]{
223+
this->m_overlay_text->setChecked(enabled);
224+
}, Qt::QueuedConnection);
225+
}
226+
void ImageDisplayCommandRow::on_overlay_enabled_images(bool enabled){
227+
QMetaObject::invokeMethod(this, [this, enabled]{
228+
this->m_overlay_images->setChecked(enabled);
229+
}, Qt::QueuedConnection);
230+
}
231+
void ImageDisplayCommandRow::on_overlay_enabled_log(bool enabled){
232+
QMetaObject::invokeMethod(this, [this, enabled]{
233+
this->m_overlay_log->setChecked(enabled);
234+
}, Qt::QueuedConnection);
235+
}
236+
void ImageDisplayCommandRow::on_overlay_enabled_stats(bool enabled){
237+
QMetaObject::invokeMethod(this, [this, enabled]{
238+
this->m_overlay_stats->setChecked(enabled);
239+
}, Qt::QueuedConnection);
240+
}
241+
void ImageDisplayCommandRow::ready_changed(bool ready){
242+
// cout << "ImageDisplayCommandRow::ready_changed(): " << ready << endl;
243+
QMetaObject::invokeMethod(this, [this]{
244+
update_ui();
245+
}, Qt::QueuedConnection);
246+
}
247+
248+
249+
250+
251+
}
252+
}
253+
254+
255+
256+
257+
258+
259+
260+
261+
262+
263+
264+

0 commit comments

Comments
 (0)