2015-11-20 01:59:09 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2016-12-05 06:56:41 -05:00
|
|
|
* Copyright (C) 2016 Furrtek
|
2015-11-20 01:59:09 -05:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ui_alphanum.hpp"
|
|
|
|
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "hackrf_hal.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
|
2017-06-10 21:53:06 -04:00
|
|
|
#include <algorithm>
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
namespace ui {
|
2017-02-07 17:12:20 -05:00
|
|
|
|
|
|
|
void AlphanumView::paint(Painter&) {
|
2017-06-10 21:53:06 -04:00
|
|
|
draw_cursor();
|
2016-05-27 03:26:43 -04:00
|
|
|
}
|
2017-06-10 21:53:06 -04:00
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
AlphanumView::AlphanumView(
|
|
|
|
NavigationView& nav,
|
2017-06-10 21:53:06 -04:00
|
|
|
std::string * str,
|
2016-12-09 12:21:47 -05:00
|
|
|
size_t max_length
|
2017-06-20 22:25:27 -04:00
|
|
|
) : TextEntryView(nav, str, max_length)
|
2016-12-09 12:21:47 -05:00
|
|
|
{
|
2016-07-28 22:52:51 -04:00
|
|
|
size_t n;
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2017-02-07 17:12:20 -05:00
|
|
|
&button_mode,
|
|
|
|
&text_raw,
|
2017-06-20 22:25:27 -04:00
|
|
|
&field_raw
|
2017-01-15 22:45:44 -05:00
|
|
|
});
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
const auto button_fn = [this](Button& button) {
|
|
|
|
this->on_button(button);
|
|
|
|
};
|
|
|
|
|
2016-07-28 22:52:51 -04:00
|
|
|
n = 0;
|
2016-12-05 06:56:41 -05:00
|
|
|
for (auto& button : buttons) {
|
2015-11-20 01:59:09 -05:00
|
|
|
button.on_select = button_fn;
|
|
|
|
button.set_parent_rect({
|
2016-12-09 12:21:47 -05:00
|
|
|
static_cast<Coord>((n % 5) * (240 / 5)),
|
2017-02-07 17:12:20 -05:00
|
|
|
static_cast<Coord>((n / 5) * 38 + 24),
|
|
|
|
240 / 5, 38
|
2015-11-20 01:59:09 -05:00
|
|
|
});
|
2016-07-27 18:08:05 -04:00
|
|
|
add_child(&button);
|
2015-11-20 01:59:09 -05:00
|
|
|
n++;
|
|
|
|
}
|
2017-06-10 21:53:06 -04:00
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
set_mode(mode);
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-06-10 21:53:06 -04:00
|
|
|
button_mode.on_select = [this](Button&) {
|
2017-02-07 17:12:20 -05:00
|
|
|
set_mode(mode + 1);
|
2015-11-20 01:59:09 -05:00
|
|
|
};
|
2016-07-25 10:21:27 -04:00
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
field_raw.set_value('0');
|
2017-06-10 21:53:06 -04:00
|
|
|
field_raw.on_select = [this](NumberField&) {
|
2017-02-07 17:12:20 -05:00
|
|
|
char_add(field_raw.value());
|
2016-07-25 10:21:27 -04:00
|
|
|
update_text();
|
2016-08-01 14:06:17 -04:00
|
|
|
};
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-06-10 21:53:06 -04:00
|
|
|
button_ok.on_select = [this, &nav](Button&) {
|
|
|
|
if (on_changed)
|
|
|
|
on_changed(_str);
|
2015-11-20 01:59:09 -05:00
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
void AlphanumView::set_mode(const uint32_t new_mode) {
|
2015-11-20 01:59:09 -05:00
|
|
|
size_t n = 0;
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2017-02-07 17:12:20 -05:00
|
|
|
if (new_mode < 3)
|
|
|
|
mode = new_mode;
|
|
|
|
else
|
|
|
|
mode = 0;
|
|
|
|
|
2017-06-10 21:53:06 -04:00
|
|
|
const char * key_list = key_sets[mode].second;
|
2017-02-07 17:12:20 -05:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
for (auto& button : buttons) {
|
2015-11-20 01:59:09 -05:00
|
|
|
const std::string label {
|
2016-12-09 12:21:47 -05:00
|
|
|
key_list[n]
|
2015-11-20 01:59:09 -05:00
|
|
|
};
|
|
|
|
button.set_text(label);
|
|
|
|
n++;
|
|
|
|
}
|
2017-02-07 17:12:20 -05:00
|
|
|
|
|
|
|
if (mode < 2)
|
2017-06-10 21:53:06 -04:00
|
|
|
button_mode.set_text(key_sets[mode + 1].first);
|
2017-02-07 17:12:20 -05:00
|
|
|
else
|
2017-06-10 21:53:06 -04:00
|
|
|
button_mode.set_text(key_sets[0].first);
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphanumView::on_button(Button& button) {
|
2017-06-10 21:53:06 -04:00
|
|
|
const auto c = button.text()[0];
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2017-06-10 21:53:06 -04:00
|
|
|
if (c == '<')
|
2015-11-20 01:59:09 -05:00
|
|
|
char_delete();
|
2016-12-09 12:21:47 -05:00
|
|
|
else
|
2017-06-10 21:53:06 -04:00
|
|
|
char_add(c);
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|