windows: toolbar and draw samples fixed

master
Clyne 4 years ago
parent ab0f6acf4d
commit 4a0fb43d37

@ -55,7 +55,8 @@ enum Id {
MRunGenUpload, MRunGenUpload,
MRunGenStart, MRunGenStart,
MCodeCompile, MCodeCompile,
MCodeDisassemble MCodeDisassemble,
CompileOutput
}; };
MainFrame::MainFrame() : MainFrame::MainFrame() :
@ -67,7 +68,7 @@ MainFrame::MainFrame() :
auto panelCode = new wxPanel(mainSplitter, wxID_ANY); auto panelCode = new wxPanel(mainSplitter, wxID_ANY);
auto panelOutput = new wxPanel(mainSplitter, wxID_ANY); auto panelOutput = new wxPanel(mainSplitter, wxID_ANY);
// Additional panel for the toolbar // Additional panel for the toolbar
auto panelToolbar = new wxPanel(this, wxID_ANY); auto panelToolbar = new wxPanel(panelCode, wxID_ANY);
// Sizers for the controls // Sizers for the controls
auto sizerToolbar = new wxBoxSizer(wxHORIZONTAL); auto sizerToolbar = new wxBoxSizer(wxHORIZONTAL);
auto sizerCode = new wxBoxSizer(wxVERTICAL); auto sizerCode = new wxBoxSizer(wxVERTICAL);
@ -82,13 +83,13 @@ MainFrame::MainFrame() :
m_status_bar = new wxStatusBar(this); m_status_bar = new wxStatusBar(this);
m_text_editor = new wxStyledTextCtrl(panelCode, wxID_ANY, m_text_editor = new wxStyledTextCtrl(panelCode, wxID_ANY,
wxDefaultPosition, wxSize(620, 440)); wxDefaultPosition, wxSize(620, 440));
m_compile_output = new wxTextCtrl(panelOutput, wxID_ANY, m_compile_output = new wxTextCtrl(panelOutput, Id::CompileOutput,
wxEmptyString, wxEmptyString,
wxDefaultPosition, wxSize(620, 250), wxDefaultPosition, wxSize(620, 250),
wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_RICH2); wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_RICH2);
m_measure_timer = new wxTimer(this, Id::MeasureTimer); m_measure_timer = new wxTimer(this, Id::MeasureTimer);
m_menu_bar = new wxMenuBar; m_menu_bar = new wxMenuBar;
m_rate_select = new wxComboBox(this, wxID_ANY, m_rate_select = new wxComboBox(panelToolbar, wxID_ANY,
wxEmptyString, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
srateValues.size(), srateValues.data(), srateValues.size(), srateValues.data(),
@ -111,7 +112,7 @@ MainFrame::MainFrame() :
SetMenuBar(m_menu_bar); SetMenuBar(m_menu_bar);
// Toolbar initialization // Toolbar initialization
auto comp = new wxButton(this, wxID_ANY, "Compile"); auto comp = new wxButton(panelToolbar, wxID_ANY, "Compile");
sizerToolbar->Add(comp, 0, wxLEFT | wxTOP, 4); sizerToolbar->Add(comp, 0, wxLEFT | wxTOP, 4);
sizerToolbar->Add(m_rate_select, 0, wxLEFT | wxTOP, 4); sizerToolbar->Add(m_rate_select, 0, wxLEFT | wxTOP, 4);
panelToolbar->SetSizer(sizerToolbar); panelToolbar->SetSizer(sizerToolbar);
@ -144,7 +145,8 @@ MainFrame::MainFrame() :
// General // General
Bind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer); Bind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer);
Bind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY); Bind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY);
Bind(wxEVT_PAINT, &MainFrame::onPaint, this, wxID_ANY); m_compile_output->
Bind(wxEVT_PAINT, &MainFrame::onPaint, this, Id::CompileOutput);
// Toolbar actions // Toolbar actions
Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY, comp); Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY, comp);
@ -179,7 +181,6 @@ MainFrame::MainFrame() :
Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY, menuCode->Append(MCodeDisassemble, "Show &Disassembly")); Bind(wxEVT_MENU, &MainFrame::onCodeDisassemble, this, Id::MCodeDisassemble, wxID_ANY, menuCode->Append(MCodeDisassemble, "Show &Disassembly"));
updateMenuOptions(); updateMenuOptions();
comp->Raise();
} }
// Closes the window // Closes the window
@ -219,7 +220,7 @@ void MainFrame::onMeasureTimer(wxTimerEvent&)
if (m_run_draw_samples->IsChecked()) { if (m_run_draw_samples->IsChecked()) {
samples = m_device->continuous_read_input(); samples = m_device->continuous_read_input();
std::copy(samples.cbegin(), samples.cend(), m_device_samples_input); std::copy(samples.cbegin(), samples.cend(), m_device_samples_input);
this->Refresh(); m_compile_output->Refresh();
} }
} }
} }
@ -244,50 +245,42 @@ void MainFrame::onMeasureTimer(wxTimerEvent&)
void MainFrame::onPaint(wxPaintEvent&) void MainFrame::onPaint(wxPaintEvent&)
{ {
if (!m_is_running || !m_run_draw_samples->IsChecked()) { if (!m_is_running || !m_run_draw_samples->IsChecked())
if (!m_compile_output->IsShown())
m_compile_output->Show();
return; return;
} else if (m_compile_output->IsShown()) {
m_compile_output->Hide();
}
auto py = m_compile_output->GetScreenPosition().y - this->GetScreenPosition().y - 28; const auto& dim = m_compile_output->GetSize();
wxRect rect { wxRect rect {
0, py, 0, 0, dim.GetWidth(), dim.GetHeight()
this->GetSize().GetWidth(),
this->GetSize().GetHeight() - py - 60
}; };
auto *dc = new wxBufferedPaintDC(this); wxBufferedPaintDC dc (m_compile_output);
dc->SetBrush(*wxBLACK_BRUSH); dc.SetBrush(*wxBLACK_BRUSH);
dc->SetPen(*wxBLACK_PEN); dc.SetPen(*wxBLACK_PEN);
dc->DrawRectangle(rect); dc.DrawRectangle(rect);
auto stoy = [&](stmdsp::adcsample_t s) { auto stoy = [&](stmdsp::adcsample_t s) {
return static_cast<float>(py) + rect.GetHeight() - return static_cast<float>(rect.GetHeight()) -
(static_cast<float>(rect.GetHeight()) * s / 4095.f); (static_cast<float>(rect.GetHeight()) * s / 4095.f);
}; };
auto scount = m_device->get_buffer_size(); auto scount = m_device->get_buffer_size();
float dx = static_cast<float>(rect.GetWidth()) / scount; float dx = static_cast<float>(rect.GetWidth()) / scount;
float x = 0; float x = 0;
float lasty = stoy(2048); float lasty = stoy(2048);
dc->SetBrush(wxBrush(wxColour(0xFF, 0, 0, 0x80))); dc.SetBrush(wxBrush(wxColour(0xFF, 0, 0, 0x80)));
dc->SetPen(wxPen(wxColour(0xFF, 0, 0, 0x80))); dc.SetPen(wxPen(wxColour(0xFF, 0, 0, 0x80)));
for (decltype(scount) i = 0; i < scount; i++) { for (decltype(scount) i = 0; i < scount; i++) {
auto y = stoy(m_device_samples[i]); auto y = stoy(m_device_samples[i]);
dc->DrawLine(x, lasty, x + dx, y); dc.DrawLine(x, lasty, x + dx, y);
x += dx, lasty = y; x += dx, lasty = y;
} }
x = 0; x = 0;
lasty = stoy(2048); lasty = stoy(2048);
dc->SetBrush(wxBrush(wxColour(0, 0, 0xFF, 0x80))); dc.SetBrush(wxBrush(wxColour(0, 0, 0xFF, 0x80)));
dc->SetPen(wxPen(wxColour(0, 0, 0xFF, 0x80))); dc.SetPen(wxPen(wxColour(0, 0, 0xFF, 0x80)));
for (decltype(scount) i = 0; i < scount; i++) { for (decltype(scount) i = 0; i < scount; i++) {
auto y = stoy(m_device_samples_input[i]); auto y = stoy(m_device_samples_input[i]);
dc->DrawLine(x, lasty, x + dx, y); dc.DrawLine(x, lasty, x + dx, y);
x += dx, lasty = y; x += dx, lasty = y;
} }
delete dc;
} }
void MainFrame::prepareEditor() void MainFrame::prepareEditor()

Loading…
Cancel
Save