Deluge Firmware 1.3.0
Build date: 2025.11.26
Loading...
Searching...
No Matches
amount.h
1/*
2 * Copyright (c) 2014-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "gui/menu_item/integer.h"
20#include "hid/display/oled.h"
21
22namespace deluge::gui::menu_item::delay {
23
24using namespace hid::display;
25
26class Amount final : public patched_param::Integer {
27public:
28 using Integer::Integer;
29
30 float normalize(int32_t value) override {
31 const int32_t clamped = std::clamp<int32_t>(value, 0, max_value_in_horizontal_menu);
32 return clamped / static_cast<float>(max_value_in_horizontal_menu);
33 }
34
35 void renderInHorizontalMenu(const SlotPosition& slot) override {
36 drawBar(slot);
37
38 if (getValue() > max_value_in_horizontal_menu) {
39 // Draw exclamation mark
40 oled_canvas::Canvas& image = OLED::main;
41 constexpr uint8_t excl_mark_width = 3;
42 constexpr uint8_t excl_mark_height = 11;
43 const uint8_t center_x = slot.start_x + slot.width / 2;
44 const uint8_t excl_mark_start_y = slot.start_y + kHorizontalMenuSlotYOffset - 1;
45 const uint8_t excl_mark_end_y = excl_mark_start_y + excl_mark_height - 1;
46 const uint8_t excl_mark_start_x = center_x - 1;
47
48 // Fill the mark area
49 for (uint8_t x = center_x - 2; x <= center_x + 2; x++) {
50 for (uint8_t y = excl_mark_start_y - 1; y <= excl_mark_end_y + 1; y++) {
51 image.drawPixel(x, y);
52 }
53 }
54
55 image.invertArea(excl_mark_start_x, excl_mark_width, excl_mark_start_y, excl_mark_start_y + 6);
56 image.invertArea(excl_mark_start_x, excl_mark_width, excl_mark_start_y + 8, excl_mark_start_y + 10);
57 }
58 }
59
60 void getColumnLabel(StringBuf& label) override { label.append(l10n::get(l10n::String::STRING_FOR_AMOUNT_SHORT)); }
61
62private:
63 constexpr static int32_t max_value_in_horizontal_menu = 24;
64};
65} // namespace deluge::gui::menu_item::delay
Definition d_stringbuf.h:16
Definition menu_item.h:33