Skip to content

Commit

Permalink
llib: make icons const
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Feb 8, 2024
1 parent a65453f commit f8cb271
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 10 deletions.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
4 changes: 2 additions & 2 deletions firmware-demo/src/demo_letris.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <lilka.h>

#include "letris.h"
#include "letris_splash.h"

#define BLOCK_SIZE 10
#define FIELD_COLS 10
Expand Down Expand Up @@ -141,7 +141,7 @@ void demo_letris() {
for (uint16_t y = 0; y < 64; y++) {
int16_t xShift = sin(time * 5 + y / 4.0) * 8;
for (uint16_t x = 0; x < 128; x++) {
canvas.drawPixel(x + xShift, y, letris[y * LILKA_DISPLAY_WIDTH + x]);
canvas.drawPixel(x + xShift, y, letris_splash[y * LILKA_DISPLAY_WIDTH + x]);
}
}
lilka::display.renderCanvas(canvas);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// This file was generated automatically. Do not edit.
// clang-format off
const uint16_t letris[] = {
#include <stdint.h>
const uint16_t letris_splash_width = 240;
const uint16_t letris_splash_height = 64;
const uint16_t letris_splash[] = {
0x0015,
0x0015,
0x0015,
Expand Down
2 changes: 1 addition & 1 deletion firmware-demo/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void sd_browser_menu(String path) {
}

String filenames[32];
menu_icon_t *icons[32];
const menu_icon_t *icons[32];
for (int i = 0; i < numEntries; i++) {
filenames[i] = entries[i].name;
icons[i] = entries[i].type == lilka::EntryType::DIRECTORY ? &folder : (entries[i].name.endsWith(".rom") || entries[i].name.endsWith(".nes")) ? &nes : &file;
Expand Down
6 changes: 5 additions & 1 deletion lib/lilka/src/lilka/icons/file.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// This file was generated automatically. Do not edit.
// clang-format off
uint16_t file[] = {
#include <stdint.h>
const uint16_t file_width = 24;
const uint16_t file_height = 24;
const uint16_t file[] = {
0x0000,
0x0000,
0x0000,
Expand Down
6 changes: 5 additions & 1 deletion lib/lilka/src/lilka/icons/folder.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// This file was generated automatically. Do not edit.
// clang-format off
uint16_t folder[] = {
#include <stdint.h>
const uint16_t folder_width = 24;
const uint16_t folder_height = 24;
const uint16_t folder[] = {
0x0000,
0x0000,
0x0000,
Expand Down
6 changes: 5 additions & 1 deletion lib/lilka/src/lilka/icons/nes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// This file was generated automatically. Do not edit.
// clang-format off
uint16_t nes[] = {
#include <stdint.h>
const uint16_t nes_width = 24;
const uint16_t nes_height = 24;
const uint16_t nes[] = {
0x0000,
0x0000,
0x0000,
Expand Down
4 changes: 4 additions & 0 deletions lib/lilka/src/lilka/splash.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// This file was generated automatically. Do not edit.
// clang-format off
#include <stdint.h>
const uint16_t splash_width = 240;
const uint16_t splash_height = 280;
const uint16_t splash[] = {
0x00eb,
0x00eb,
Expand Down
4 changes: 2 additions & 2 deletions lib/lilka/src/lilka/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace lilka {

int ui_menu(String title, String menu[], int menu_size, int cursor, menu_icon_t *icons[]) {
int ui_menu(String title, String menu[], int menu_size, int cursor, const menu_icon_t *icons[]) {
display.fillScreen(display.color565(0, 0, 0));
controller.resetState();
while (1) {
Expand All @@ -21,7 +21,7 @@ int ui_menu(String title, String menu[], int menu_size, int cursor, menu_icon_t
for (int i = 0; i < menu_size; i++) {
display.fillRect(0, 96 + i * 24 - 20, LILKA_DISPLAY_WIDTH, 24, i == cursor ? display.color565(255, 0, 0) : display.color565(0, 0, 0));
if (icons != NULL && icons[i] != NULL) {
display.draw16bitRGBBitmapWithTranColor(0, 96 + i * 24 - 20, *icons[i], display.color565(0, 0, 0), 24, 24);
display.draw16bitRGBBitmap(0, 96 + i * 24 - 20, *icons[i], 24, 24);
}
display.setCursor(32, 96 + i * 24);
display.setTextColor(display.color565(255, 255, 255));
Expand Down
2 changes: 1 addition & 1 deletion lib/lilka/src/lilka/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace lilka {

int ui_menu(String title, String menu[], int menu_size, int cursor, menu_icon_t *icons[] = 0);
int ui_menu(String title, String menu[], int menu_size, int cursor, const menu_icon_t *icons[] = 0);
void ui_alert(String title, String message);

} // namespace lilka
Expand Down
4 changes: 4 additions & 0 deletions tools/image2code/image2code.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@

with open(out, "w") as f:
print(f"Записуємо {len(pixels)} пікселів у {out}... ", end="")
print("// This file was generated automatically. Do not edit.", file=f)
print("// clang-format off", file=f)
print(f"#include <stdint.h>", file=f)
print(f"const uint16_t {var_name}_width = {img.width};", file=f)
print(f"const uint16_t {var_name}_height = {img.height};", file=f)
print(f"const uint16_t {var_name}[] = {{", file=f)
for pixel in pixels:
print(f" 0x{pixel:04x},", file=f)
Expand Down

0 comments on commit f8cb271

Please sign in to comment.