forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeDialog.cpp
126 lines (101 loc) · 2.64 KB
/
TimeDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**********************************************************************
Sneedacity: A Digital Audio Editor
TimeDialog.cpp
Dominic Mazzoni
*******************************************************************//**
\class TimeDialog
\brief Dialog used to request a time value.
*//*******************************************************************/
#include "TimeDialog.h"
#include <wx/defs.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/string.h>
#include "ShuttleGui.h"
#include "widgets/NumericTextCtrl.h"
BEGIN_EVENT_TABLE(TimeDialog, wxDialogWrapper)
EVT_COMMAND(wxID_ANY, EVT_TIMETEXTCTRL_UPDATED, TimeDialog::OnUpdate)
END_EVENT_TABLE()
TimeDialog::TimeDialog(wxWindow *parent,
const TranslatableString &title,
const NumericFormatSymbol &format,
double rate,
double time,
const TranslatableString &prompt)
: wxDialogWrapper(parent, wxID_ANY, title),
mPrompt(prompt),
mFormat(format),
mRate(rate),
mTime(time),
mTimeCtrl(NULL)
{
SetName();
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
}
void TimeDialog::PopulateOrExchange(ShuttleGui &S)
{
S.SetBorder(5);
S.StartVerticalLay(true);
{
S.StartStatic(mPrompt, true);
{
mTimeCtrl = safenew
NumericTextCtrl(
S.GetParent(), wxID_ANY,
NumericConverter::TIME,
mFormat,
mTime,
mRate,
NumericTextCtrl::Options{}
.AutoPos(true));
S.AddWindow(mTimeCtrl);
}
S.EndStatic();
}
S.EndVerticalLay();
S.AddStandardButtons();
TransferDataToWindow();
Layout();
Fit();
SetMinSize(GetSize());
Center();
}
bool TimeDialog::TransferDataToWindow()
{
mTimeCtrl->SetFormatString(mTimeCtrl->GetBuiltinFormat(mFormat));
mTimeCtrl->SetSampleRate(mRate);
mTimeCtrl->SetValue(mTime);
mTimeCtrl->SetFocus();
return true;
}
bool TimeDialog::TransferDataFromWindow()
{
mTime = mTimeCtrl->GetValue();
return true;
}
const double TimeDialog::GetTimeValue()
{
return mTime;
}
void TimeDialog::SetFormatString(const NumericFormatSymbol &formatString)
{
mFormat = formatString;
TransferDataToWindow();
}
void TimeDialog::SetSampleRate(double sampleRate)
{
mRate = sampleRate;
TransferDataToWindow();
}
void TimeDialog::SetTimeValue(double newTime)
{
mTime = newTime;
TransferDataToWindow();
}
void TimeDialog::OnUpdate(wxCommandEvent &event)
{
Layout();
Refresh();
event.Skip(false);
}