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"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
using namespace hackrf::one;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2016-05-27 03:26:43 -04:00
|
|
|
void AlphanumView::paint(Painter& painter) {
|
2016-05-29 06:06:47 -04:00
|
|
|
(void)painter;
|
2016-05-27 03:26:43 -04:00
|
|
|
move_cursor();
|
|
|
|
}
|
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
AlphanumView::AlphanumView(
|
|
|
|
NavigationView& nav,
|
|
|
|
char txt[],
|
2016-12-09 12:21:47 -05:00
|
|
|
size_t max_length
|
|
|
|
) : _max_length(max_length)
|
|
|
|
{
|
2015-11-20 01:59:09 -05:00
|
|
|
_lowercase = false;
|
2016-07-28 22:52:51 -04:00
|
|
|
size_t n;
|
2015-11-20 01:59:09 -05:00
|
|
|
|
|
|
|
static constexpr Style style_alpha {
|
|
|
|
.font = font::fixed_8x16,
|
2016-12-08 20:35:50 -05:00
|
|
|
.background = Color::black(),
|
|
|
|
.foreground = Color(191,31,31)
|
2015-11-20 01:59:09 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr Style style_num {
|
|
|
|
.font = font::fixed_8x16,
|
2016-12-08 20:35:50 -05:00
|
|
|
.background = Color::black(),
|
|
|
|
.foreground = Color(191,191,31)
|
2015-11-20 01:59:09 -05:00
|
|
|
};
|
|
|
|
|
2016-05-27 03:26:43 -04:00
|
|
|
txtidx = strlen(txt);
|
2016-12-09 12:21:47 -05:00
|
|
|
memcpy(txtinput, txt, _max_length + 1);
|
2016-07-28 22:52:51 -04:00
|
|
|
n = txtidx;
|
|
|
|
while (n && (txtinput[n - 1] == ' ')) {
|
|
|
|
txtinput[--n] = 0;
|
|
|
|
txtidx--;
|
|
|
|
}
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
add_children({
|
2016-12-09 12:21:47 -05:00
|
|
|
&text_input,
|
|
|
|
&button_lowercase,
|
|
|
|
&raw_char,
|
|
|
|
&button_ok
|
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)),
|
|
|
|
static_cast<Coord>((n / 5) * 28 + 24),
|
|
|
|
240 / 5, 28
|
2015-11-20 01:59:09 -05:00
|
|
|
});
|
|
|
|
if ((n < 10) || (n == 39))
|
|
|
|
button.set_style(&style_num);
|
|
|
|
else
|
|
|
|
button.set_style(&style_alpha);
|
2016-07-27 18:08:05 -04:00
|
|
|
add_child(&button);
|
2015-11-20 01:59:09 -05:00
|
|
|
n++;
|
|
|
|
}
|
2016-12-09 12:21:47 -05:00
|
|
|
set_keys(keys_upper);
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
button_lowercase.on_select = [this, &nav](Button&) {
|
2015-11-20 01:59:09 -05:00
|
|
|
if (_lowercase == true) {
|
|
|
|
_lowercase = false;
|
|
|
|
button_lowercase.set_text("UC");
|
2016-12-09 12:21:47 -05:00
|
|
|
set_keys(keys_upper);
|
2015-11-20 01:59:09 -05:00
|
|
|
} else {
|
|
|
|
_lowercase = true;
|
|
|
|
button_lowercase.set_text("LC");
|
2016-12-09 12:21:47 -05:00
|
|
|
set_keys(keys_lower);
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
};
|
2016-07-25 10:21:27 -04:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
raw_char.set_value('0');
|
|
|
|
raw_char.on_select = [this, &nav](NumberField&) {
|
2016-07-25 10:21:27 -04:00
|
|
|
char_add(raw_char.value());
|
|
|
|
update_text();
|
2016-08-01 14:06:17 -04:00
|
|
|
};
|
2015-11-20 01:59:09 -05:00
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
button_ok.on_select = [this, &nav, txt, max_length](Button&) {
|
|
|
|
memcpy(txt, txtinput, max_length + 1);
|
2016-08-23 02:45:33 -04:00
|
|
|
if (on_changed) on_changed(this->value());
|
2015-11-20 01:59:09 -05:00
|
|
|
nav.pop();
|
|
|
|
};
|
|
|
|
|
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
|
2016-05-27 03:26:43 -04:00
|
|
|
void AlphanumView::move_cursor() {
|
|
|
|
Point cursor_pos;
|
|
|
|
|
2017-01-15 22:45:44 -05:00
|
|
|
cursor_pos = {text_input.screen_rect().location().x() + (txtidx * 8),
|
|
|
|
text_input.screen_rect().location().y() + 16};
|
2016-05-27 03:26:43 -04:00
|
|
|
|
|
|
|
portapack::display.fill_rectangle(
|
2017-01-15 22:45:44 -05:00
|
|
|
{{text_input.screen_rect().location().x(), cursor_pos.y()}, {text_input.screen_rect().size().width(), 4}},
|
2016-05-27 03:26:43 -04:00
|
|
|
Color::black()
|
|
|
|
);
|
|
|
|
portapack::display.fill_rectangle(
|
|
|
|
{cursor_pos, {8, 4}},
|
|
|
|
Color::white()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
void AlphanumView::set_keys(const char * const key_list) {
|
2015-11-20 01:59:09 -05:00
|
|
|
size_t n = 0;
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphanumView::focus() {
|
2016-12-09 12:21:47 -05:00
|
|
|
button_ok.focus();
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
char * AlphanumView::value() {
|
2016-05-27 03:26:43 -04:00
|
|
|
txtinput[txtidx] = 0;
|
2015-11-20 01:59:09 -05:00
|
|
|
return txtinput;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphanumView::on_button(Button& button) {
|
|
|
|
const auto s = button.text();
|
2016-12-09 12:21:47 -05:00
|
|
|
|
|
|
|
if (s == "<")
|
2015-11-20 01:59:09 -05:00
|
|
|
char_delete();
|
2016-12-09 12:21:47 -05:00
|
|
|
else
|
2015-11-20 01:59:09 -05:00
|
|
|
char_add(s[0]);
|
2016-12-09 12:21:47 -05:00
|
|
|
|
2015-11-20 01:59:09 -05:00
|
|
|
update_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphanumView::char_add(const char c) {
|
2016-12-09 12:21:47 -05:00
|
|
|
if (txtidx >= _max_length) return;
|
|
|
|
|
|
|
|
txtinput[txtidx] = c;
|
|
|
|
txtidx++;
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphanumView::char_delete() {
|
2016-12-09 12:21:47 -05:00
|
|
|
if (!txtidx) return;
|
|
|
|
|
|
|
|
txtidx--;
|
|
|
|
txtinput[txtidx] = 0;
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphanumView::update_text() {
|
2016-12-09 12:21:47 -05:00
|
|
|
text_input.set(std::string(txtinput) + std::string(_max_length - strlen(txtinput), ' '));
|
2016-05-27 03:26:43 -04:00
|
|
|
move_cursor();
|
2015-11-20 01:59:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|