From f6881b3e40070f908e3399951d5810b7b97870ba Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Fri, 17 Jun 2022 08:58:56 -0500 Subject: [PATCH] switched char[] to string --- .editorconfig | 16 ++++++++++++++++ slangin.ino | 50 +++++++++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2944aeb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true + +# Tab indentation (no size specified) +[Makefile] +indent_style = tab + +[*.{ino,c,h,cpp,hpp}] +indent_size = 2 diff --git a/slangin.ino b/slangin.ino index 3be17ea..91e66c3 100644 --- a/slangin.ino +++ b/slangin.ino @@ -84,15 +84,20 @@ void loop() { if (!(arduboy.nextFrame())) return; + String menu[8]; + int menuLength = 0; + bool menuSmall = false; + if (!screenInitialized) { arduboy.clear(); switch (sGameState) { case STATE_TITLE: - drawTitle(" Slangin' v0.9"); - //char menu[3][19] = {{"New Game"}}; - //draw1ColMenu(1, menu); - char menu[5][19] = {{"Coney Island"},{"Central Park"},{"Manhatten"},{"Ghetto"},{"Brooklyn"}}; - draw2ColMenu(true, 5, menu); + drawTitle(F("Slangin'")); + menu[0] = F("New Game"); + menu[1] = F("Continue"); + menuLength = 2; + menuSmall = true; + draw1ColMenu(menuSmall, menuLength, menu); break; } arduboy.display(); @@ -102,46 +107,49 @@ void loop() { /***********************/ /* screen draw heplers */ /***********************/ -void drawTitle(const char title[]) { +void drawTitle(const String title) { arduboy.setCursor(6, 8); arduboy.print(title); } -void draw1ColMenu(const bool small, - const int itemCount, - const char items[][19]) { +void draw1ColMenu(const bool small, const int itemCount, const String items[]) { int colWidth = 0; for (int i = 0; i < itemCount; i++) { - if (strlen(items[i]) > colWidth) colWidth = strlen(items[i]); + const int newLen = items[i].length(); + if (newLen > colWidth) colWidth = newLen; } const int charWidth = small ? 5 : 6; - const int charHeight = small ? 7 : 10; - int x = 64 - round(colWidth * (charWidth / 2.0)); + const int charHeight = small ? 9 : 10; + int x = 66 - round(colWidth * (charWidth / 2.0)); int y = 18 - round(itemCount * (charHeight / 2.0)); for (int i = 0; i < itemCount; i++) { - arduboy.setCursor(x, i * charHeight + 22 + y); - arduboy.print(items[i]); + const int cy = i * charHeight + 22 + y; + if (small) { + font4x6.setCursor(x, cy); + font4x6.print(items[i]); + } else { + arduboy.setCursor(x, cy); + arduboy.print(items[i]); + } } } -void draw2ColMenu(const bool small, - const int itemCount, - const char items[][19]) { +void draw2ColMenu(const bool small, const int itemCount, const String items[]) { const int col1Count = round(itemCount / 2.0); const int col2Count = itemCount - col1Count; int col1Width = 0; int col2Width = 0; for (int i = 0; i < col1Count; i++) { - const int newLen = strlen(items[i]); + const int newLen = items[i].length(); if (newLen > col1Width) col1Width = newLen; } for (int i = 0; i < col2Count; i++) { - const int newLen = strlen(items[col1Count + i]); + const int newLen = items[i].length(); if (newLen > col2Width) col2Width = newLen; } const int charWidth = small ? 5 : 6; - const int charHeight = small ? 7 : 10; - int x = 64 - round((col1Width + col2Width + 2) * (charWidth / 2.0)); + const int charHeight = small ? 9 : 10; + int x = 66 - round((col1Width + col2Width + 2) * (charWidth / 2.0)); int y = 18 - round(col1Count * (charHeight / 2.0)); for (int i = 0; i < itemCount; i++) { const int cx = (i < col1Count)