Просмотр исходного кода

Piano: Use the return key emoji in the key labels

The new way labels are stored unfortunately makes it *slightly* less
convenient to update the lists of white key and black key labels.
Grant Yap 4 лет назад
Родитель
Сommit
ca9101e5f0
1 измененных файлов с 29 добавлено и 27 удалено
  1. 29 27
      Userland/Applications/Piano/KeysWidget.cpp

+ 29 - 27
Userland/Applications/Piano/KeysWidget.cpp

@@ -7,6 +7,8 @@
 
 #include "KeysWidget.h"
 #include "TrackManager.h"
+#include <AK/Array.h>
+#include <AK/StringView.h>
 #include <LibGUI/Painter.h>
 
 KeysWidget::KeysWidget(TrackManager& track_manager)
@@ -107,33 +109,33 @@ constexpr int black_key_width = 16;
 constexpr int black_key_x_offset = black_key_width / 2;
 constexpr int black_key_height = 60;
 
-constexpr char white_key_labels[] = {
-    'A',
-    'S',
-    'D',
-    'F',
-    'G',
-    'H',
-    'J',
-    'K',
-    'L',
-    ';',
-    '\'',
-    'r',
+constexpr int white_key_labels_count = 12;
+constexpr Array<StringView, white_key_labels_count> white_key_labels = {
+    "A",
+    "S",
+    "D",
+    "F",
+    "G",
+    "H",
+    "J",
+    "K",
+    "L",
+    ";",
+    "\'",
+    "\u23CE", // Return key symbol
 };
-constexpr int white_key_labels_count = sizeof(white_key_labels) / sizeof(char);
-
-constexpr char black_key_labels[] = {
-    'W',
-    'E',
-    'T',
-    'Y',
-    'U',
-    'O',
-    'P',
-    ']',
+
+constexpr int black_key_labels_count = 8;
+constexpr Array<StringView, black_key_labels_count> black_key_labels = {
+    "W",
+    "E",
+    "T",
+    "Y",
+    "U",
+    "O",
+    "P",
+    "]",
 };
-constexpr int black_key_labels_count = sizeof(black_key_labels) / sizeof(char);
 
 constexpr int black_key_offsets[] = {
     white_key_width,
@@ -175,7 +177,7 @@ void KeysWidget::paint_event(GUI::PaintEvent& event)
         painter.draw_rect(rect, Color::Black);
         if (i < white_key_labels_count) {
             rect.set_height(rect.height() * 1.5);
-            painter.draw_text(rect, StringView(&white_key_labels[i], 1), Gfx::TextAlignment::Center, Color::Black);
+            painter.draw_text(rect, white_key_labels[i], Gfx::TextAlignment::Center, Color::Black);
         }
 
         note += white_key_note_accumulator[i % white_keys_per_octave];
@@ -197,7 +199,7 @@ void KeysWidget::paint_event(GUI::PaintEvent& event)
         painter.draw_rect(rect, Color::Black);
         if (i < black_key_labels_count) {
             rect.set_height(rect.height() * 1.5);
-            painter.draw_text(rect, StringView(&black_key_labels[i], 1), Gfx::TextAlignment::Center, Color::White);
+            painter.draw_text(rect, black_key_labels[i], Gfx::TextAlignment::Center, Color::White);
         }
 
         note += black_key_note_accumulator[i % black_keys_per_octave];