Skip to content

Commit 50ad93c

Browse files
committed
changed all ScopedPointer to std::unique_ptr
1 parent f2cc21c commit 50ad93c

File tree

5 files changed

+153
-111
lines changed

5 files changed

+153
-111
lines changed

PosTracker/PosTrackerEditor.cpp

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,141 +14,160 @@ PosTrackerEditor::PosTrackerEditor(GenericProcessor * parentNode, bool useDefaul
1414
m_proc = (PosTracker*)getProcessor();
1515

1616
// Video source stuff
17-
addAndMakeVisible(sourceCombo = new ComboBox("sourceCombo"));
17+
sourceCombo = std::make_unique<ComboBox>("sourceCombo");
1818
sourceCombo->setBounds(5, 30, 120, 20); // x,y,w,h
1919
sourceCombo->setTooltip("The video device (e.g. /dev/video0)");
2020
sourceCombo->setEditableText(false);
2121
sourceCombo->setJustificationType(Justification::centredLeft);
2222
sourceCombo->setTextWhenNothingSelected("Device");
2323
sourceCombo->setTextWhenNoChoicesAvailable("Device");
24+
addAndMakeVisible(sourceCombo.get());
2425

2526
auto video_devices = m_proc->getDeviceList();
2627
for (int i = 0; i < video_devices.size(); ++i)
2728
sourceCombo->addItem(video_devices.at(i), i+1);
2829

2930
sourceCombo->addListener(this);
3031

31-
addAndMakeVisible(resolution = new ComboBox ("resolutionMenu"));
32+
resolution = std::make_unique<ComboBox>("resolutionMenu");
3233
resolution->setBounds(5, 55, 120, 20);
3334
resolution->setTooltip (("The size and frame rate of the video output (e.g. 640 x 480, 30fps)"));
3435
resolution->setEditableText (false);
3536
resolution->setJustificationType (Justification::centredLeft);
3637
resolution->setTextWhenNothingSelected (("Resolution/ fps"));
3738
resolution->setTextWhenNoChoicesAvailable (("Resolution / fps"));
3839
resolution->addListener(this);
40+
addAndMakeVisible(resolution.get());
3941

40-
addAndMakeVisible(refreshBtn = new UtilityButton("Refresh", Font ("Small Text", 10, Font::plain)));
42+
refreshBtn = std::make_unique<UtilityButton>("Refresh", Font ("Small Text", 10, Font::plain));
4143
refreshBtn->setBounds(5, 80, 60, 20);
4244
refreshBtn->setTooltip("Refresh the list of devices");
4345
refreshBtn->addListener(this);
46+
addAndMakeVisible(refreshBtn.get());
4447

45-
addAndMakeVisible(showVideo = new ToggleButton("Show video"));
48+
showVideo = std::make_unique<ToggleButton>("Show video");
4649
showVideo->setBounds(5, 105, 100, 20);
4750
showVideo->setTooltip("Show the video stream");
4851
showVideo->addListener(this);
4952
showVideo->setEnabled(false);
53+
addAndMakeVisible(showVideo.get());
5054

5155
font.setHeight(8);
5256

5357
// autoexposure button
54-
addAndMakeVisible(autoExposure = new ToggleButton("Auto exposure"));
58+
autoExposure = std::make_unique<ToggleButton>("Auto exposure");
5559
autoExposure->setBounds(345, 72, 60, 40); // smaller than this and the JUCE graphics_context goes mental
5660
autoExposure->setTooltip("Turn auto exposure on or off");
5761
autoExposure->setToggleState(true, dontSendNotification);
5862
autoExposure->addListener(this);
63+
addAndMakeVisible(autoExposure.get());
5964

6065
// overlaypath button
61-
addAndMakeVisible(overlayPath = new ToggleButton("Path overlay"));
66+
overlayPath = std::make_unique<ToggleButton>("Path overlay");
6267
overlayPath->setBounds(345, 92, 60, 40); // smaller than this and the JUCE graphics_context goes mental
6368
overlayPath->setTooltip("Overlay path on video");
6469
overlayPath->setToggleState(false, dontSendNotification);
6570
overlayPath->addListener(this);
71+
addAndMakeVisible(overlayPath.get());
6672

6773
// Values used for control ranges & step
6874
__s32 min, max, step;
6975
// Brightness slider and label
70-
addAndMakeVisible(brightnessSldr = new CameraControlSlider(font));
76+
brightnessSldr = std::make_unique<CameraControlSlider>(font);
7177
brightnessSldr->setBounds(210, 30, 50,50);
7278
brightnessSldr->setActive(false);
7379
brightnessSldr->addListener(this);
80+
addAndMakeVisible(brightnessSldr.get());
7481

75-
addAndMakeVisible(brightLbl = new Label("Brightness", "Brightness"));
82+
brightLbl = std::make_unique<Label>("Brightness", "Brightness");
7683
brightLbl->setBounds(200, 18, 70, 20);
7784
brightLbl->setFont(font);
7885
brightLbl->setEditable (false, false, false);
7986
brightLbl->setJustificationType(Justification::centred);
8087
brightLbl->setColour (TextEditor::textColourId, Colours::grey);
88+
addAndMakeVisible(brightLbl.get());
8189

8290
// Contrast slider and label
83-
addAndMakeVisible(contrastSldr = new CameraControlSlider(font));
91+
contrastSldr = std::make_unique<CameraControlSlider>(font);
8492
contrastSldr->setBounds(295, 30, 50,50);
8593
contrastSldr->setActive(false);
8694
contrastSldr->addListener(this);
95+
addAndMakeVisible(contrastSldr.get());
8796

88-
addAndMakeVisible(contrLbl = new Label("Contrast", "Contrast"));
97+
contrLbl = std::make_unique<Label>("Contrast", "Contrast");
8998
contrLbl->setBounds(285, 18, 70, 20);
9099
contrLbl->setFont(font);
91100
contrLbl->setEditable (false, false, false);
92101
contrLbl->setJustificationType(Justification::centred);
93102
contrLbl->setColour (TextEditor::textColourId, Colours::grey);
103+
addAndMakeVisible(contrLbl.get());
94104

95105
// Exposure slider and label
96-
addAndMakeVisible(exposureSldr = new CameraControlSlider(font));
106+
exposureSldr = std::make_unique<CameraControlSlider>(font);
97107
exposureSldr->setBounds(370, 30, 50,50);
98108
exposureSldr->setActive(false);
99109
exposureSldr->addListener(this);
110+
addAndMakeVisible(exposureSldr.get());
100111

101-
addAndMakeVisible(exposureLbl = new Label("Exposure", "Exposure"));
112+
exposureLbl = std::make_unique<Label>("Exposure", "Exposure");
102113
exposureLbl->setBounds(360, 18, 70, 20);
103114
exposureLbl->setFont(font);
104115
exposureLbl->setEditable(false, false, false);
105116
exposureLbl->setJustificationType(Justification::centred);
106117
exposureLbl->setColour(TextEditor::textColourId, Colours::grey);
118+
addAndMakeVisible(exposureLbl.get());
107119

108120
std::pair<int,int> resolution = m_proc->getResolution();
109121
int width = resolution.first;
110122
int height = resolution.second;
111123

112124
// LEFT-RIGHT BOUNDING BOX
113-
addAndMakeVisible(leftRightSlider = new FrameControlSlider(m_proc, font));
125+
leftRightSlider = std::make_unique<FrameControlSlider>(m_proc, font);
114126
leftRightSlider->setBounds(195, 80, 140, 25);
115127
leftRightSlider->setRange(0, width, 1);
116128
leftRightSlider->setMinValue(0);
117129
leftRightSlider->setMaxValue(width);
118130
leftRightSlider->setActive(false);
119131
leftRightSlider->addListener(this);
132+
addAndMakeVisible(leftRightSlider.get());
120133

121-
addAndMakeVisible(leftRightLbl = new Label("leftRightLbl", "Left-Right"));
134+
leftRightLbl = std::make_unique<Label>("leftRightLbl", "Left-Right");
122135
leftRightLbl->setBounds(130, 80, 70, 20);
123136
leftRightLbl->setFont(font);
124137
leftRightLbl->setEditable (false, false, false);
125138
leftRightLbl->setJustificationType(Justification::centred);
126139
leftRightLbl->setColour (TextEditor::textColourId, Colours::grey);
140+
addAndMakeVisible(leftRightLbl.get());
127141

128142
// TOP-BOTTOM BOUNDING BOX
129-
addAndMakeVisible(topBottomSlider = new FrameControlSlider(m_proc, font));
143+
topBottomSlider = std::make_unique<FrameControlSlider>(m_proc, font);
130144
topBottomSlider->setBounds(195, 110, 140, 25);
131145
topBottomSlider->setRange(0, height, 1);
132146
topBottomSlider->setMinValue(0);
133147
topBottomSlider->setMaxValue(height);
134148
topBottomSlider->setActive(false);
135149
topBottomSlider->addListener(this);
150+
addAndMakeVisible(topBottomSlider.get());
136151

137-
addAndMakeVisible(topBottomLbl = new Label("topBottomLbl", "Top-Bottom"));
152+
topBottomLbl = std::make_unique<Label>("topBottomLbl", "Top-Bottom");
138153
topBottomLbl->setBounds(130, 110, 70, 20);
139154
topBottomLbl->setFont(font);
140155
topBottomLbl->setEditable (false, false, false);
141156
topBottomLbl->setJustificationType(Justification::centred);
142157
topBottomLbl->setColour (TextEditor::textColourId, Colours::grey);
158+
addAndMakeVisible(topBottomLbl.get());
143159

144-
addAndMakeVisible(fpslabel = new InfoLabel(m_proc, font, String("FPS")));
160+
fpslabel = std::make_unique<InfoLabel>(m_proc, font, String("FPS"));
145161
fpslabel->setBounds(125, 30, 100, 40);
162+
addAndMakeVisible(fpslabel.get());
146163

147-
addAndMakeVisible(xPoslabel = new InfoLabel(m_proc, font, String("X")));
164+
xPoslabel = std::make_unique<InfoLabel>(m_proc, font, String("X"));
148165
xPoslabel->setBounds(125, 40, 100, 40);
166+
addAndMakeVisible(xPoslabel.get());
149167

150-
addAndMakeVisible(yPoslabel = new InfoLabel(m_proc, font, String("Y")));
168+
yPoslabel = std::make_unique<InfoLabel>(m_proc, font, String("Y"));
151169
yPoslabel->setBounds(125, 50, 100, 40);
170+
addAndMakeVisible(yPoslabel.get());
152171

153172

154173
}
@@ -180,35 +199,35 @@ void PosTrackerEditor::setInfoValue(InfoLabelType type, double val)
180199

181200
void PosTrackerEditor::sliderValueChanged(Slider * sliderChanged)
182201
{
183-
if ( sliderChanged == leftRightSlider )
202+
if ( sliderChanged == leftRightSlider.get() )
184203
{
185204
auto min = sliderChanged->getMinValue();
186205
m_proc->adjustVideoMask(BORDER::LEFT, min);
187206
auto max = sliderChanged->getMaxValue();
188207
m_proc->adjustVideoMask(BORDER::RIGHT, max);
189208
m_proc->makeVideoMask();
190209
}
191-
if ( sliderChanged == topBottomSlider )
210+
if ( sliderChanged == topBottomSlider.get() )
192211
{
193212
auto min = sliderChanged->getMinValue();
194213
m_proc->adjustVideoMask(BORDER::TOP, min);
195214
auto max = sliderChanged->getMaxValue();
196215
m_proc->adjustVideoMask(BORDER::BOTTOM, max);
197216
m_proc->makeVideoMask();
198217
}
199-
if ( sliderChanged == contrastSldr )
218+
if ( sliderChanged == contrastSldr.get() )
200219
{
201220
auto val = sliderChanged->getValue();
202221
if ( m_proc->isCamReady() )
203222
m_proc->adjustContrast(val);
204223
}
205-
if ( sliderChanged == brightnessSldr )
224+
if ( sliderChanged == brightnessSldr.get() )
206225
{
207226
auto val = sliderChanged->getValue();
208227
if ( m_proc->isCamReady() )
209228
m_proc->adjustBrightness(val);
210229
}
211-
if ( sliderChanged == exposureSldr )
230+
if ( sliderChanged == exposureSldr.get() )
212231
{
213232
if ( autoExposure->getToggleState() == false )
214233
{
@@ -221,7 +240,7 @@ void PosTrackerEditor::sliderValueChanged(Slider * sliderChanged)
221240

222241
void PosTrackerEditor::buttonEvent(Button* button)
223242
{
224-
if (button == refreshBtn)
243+
if ( button == refreshBtn.get() )
225244
{
226245
if ( sourceCombo->getNumItems() > 0 )
227246
{
@@ -232,7 +251,7 @@ void PosTrackerEditor::buttonEvent(Button* button)
232251
sourceCombo->addItem(video_devices.at(i), i+1);
233252
}
234253
}
235-
if ( button == showVideo )
254+
if ( button == showVideo.get() )
236255
{
237256
if ( showVideo->getToggleState() == true )
238257
{
@@ -261,7 +280,7 @@ void PosTrackerEditor::buttonEvent(Button* button)
261280
m_proc->showLiveStream(false);
262281
}
263282
}
264-
if ( button == autoExposure )
283+
if ( button == autoExposure.get() )
265284
{
266285
if ( autoExposure->getToggleState() == true )
267286
{
@@ -274,7 +293,7 @@ void PosTrackerEditor::buttonEvent(Button* button)
274293
}
275294
}
276295

277-
if ( button == overlayPath )
296+
if ( button == overlayPath.get() )
278297
{
279298
if ( overlayPath->getToggleState() == true )
280299
m_proc->overlayPath(true);
@@ -286,7 +305,7 @@ void PosTrackerEditor::buttonEvent(Button* button)
286305
void PosTrackerEditor::comboBoxChanged(ComboBox* cb)
287306
{
288307

289-
if (cb == sourceCombo)
308+
if ( cb == sourceCombo.get() )
290309
{
291310
if ( resolution->getNumItems() > 0 )
292311
resolution->clear();
@@ -298,7 +317,7 @@ void PosTrackerEditor::comboBoxChanged(ComboBox* cb)
298317
for (int i = 0; i < fmts.size(); ++i)
299318
resolution->addItem(fmts[i], i+1);
300319
}
301-
else if (cb == resolution)
320+
else if ( cb == resolution.get() )
302321
{
303322
int idx = cb->getSelectedId();
304323
auto formatId = cb->getItemText(idx-1).toStdString();
@@ -442,22 +461,24 @@ CameraControlSlider::CameraControlSlider(Font f) : Slider("name"), font(f)
442461
setValues(v);
443462
setVelocityBasedMode(true);
444463

445-
addAndMakeVisible(upButton = new TriangleButton(1));
464+
upButton = std::make_unique<TriangleButton>(1);
446465
upButton->addListener(this);
447466
upButton->setBounds(16, 21, 10, 8);
467+
addAndMakeVisible(upButton.get());
448468

449-
addAndMakeVisible(downButton = new TriangleButton(2));
469+
downButton = std::make_unique<TriangleButton>(2);
450470
downButton->addListener(this);
451471
downButton->setBounds(24, 21, 10, 8);
472+
addAndMakeVisible(downButton.get());
452473
}
453474

454475
void CameraControlSlider::buttonClicked(Button * btn) {
455-
if ( btn == upButton ) {
476+
if ( btn == upButton.get() ) {
456477
auto val = getValue();
457478
auto inc = getInterval();
458479
setValue(val + inc);
459480
}
460-
if ( btn == downButton ) {
481+
if ( btn == downButton.get() ) {
461482
auto val = getValue();
462483
auto inc = getInterval();
463484
setValue(val - inc);
@@ -547,24 +568,24 @@ FrameControlSlider::FrameControlSlider(PosTracker * proc, Font f) : Slider("name
547568
setMaxValue(100);
548569
setTextBoxStyle(Slider::NoTextBox, false, 40, 20);
549570

550-
Label * l = new Label("min");
571+
auto l = std::make_unique<Label>("min");
551572
l->setBounds(0, getHeight()+12, 40, 10);
552573
font.setHeight(9.0);
553574
l->setFont(f);
554575
l->setEditable(true);
555576
l->addListener(this);
556577
l->setText(String("0000"), dontSendNotification);
557-
addAndMakeVisible(l);
558-
borderlbl[0] = l;
578+
addAndMakeVisible(l.get());
579+
borderlbl.push_back(std::move(l));
559580

560-
l = new Label("max");
581+
l = std::make_unique<Label>("max");
561582
l->setBounds(110, getHeight()+12, 40, 10);
562583
l->setFont(f);
563584
l->setEditable(true);
564585
l->addListener(this);
565586
l->setText(String("9999"), dontSendNotification);
566-
addAndMakeVisible(l);
567-
borderlbl[1] = l;
587+
addAndMakeVisible(l.get());
588+
borderlbl.push_back(std::move(l));
568589

569590
setValue(0, 0);
570591
setValue(1, 1);
@@ -693,18 +714,20 @@ void FrameControlSlider::setValue(int idx, int val)
693714
InfoLabel::InfoLabel(PosTracker * proc, Font f, String name)
694715
: m_proc(proc), m_font(f)
695716
{
696-
addAndMakeVisible(lbl = new Label(name, name));
717+
lbl = std::make_unique<Label>(name, name);
697718
lbl->setBounds(0, 5, 30, 20);
698719
lbl->setEditable(false);
699720
lbl->setFont(m_font);
700721
lbl->setColour(TextEditor::textColourId, Colours::grey);
701722
lbl->setJustificationType(Justification::right);
723+
addAndMakeVisible(lbl.get());
702724

703-
addAndMakeVisible(lblvalue = new Label("value"));
725+
lblvalue = std::make_unique<Label>("value");
704726
lblvalue->setBounds(30, 5, 50, 20);
705727
lblvalue->setEditable(false);
706728
lblvalue->setFont(m_font);
707729
setInfo(0.0);
730+
addAndMakeVisible(lblvalue.get());
708731
}
709732

710733
void InfoLabel::handleAsyncUpdate()

0 commit comments

Comments
 (0)