Skip to content

Commit

Permalink
Improve Font Rendering & Set Working Directory
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Jan 13, 2025
1 parent 74ed6c5 commit 636b54d
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions system/ui/raylib/util.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "system/ui/raylib/util.h"

#include <array>
#include <filesystem>

#undef GREEN
#undef RED
Expand All @@ -9,20 +10,23 @@
#include "system/hardware/hw.h"

constexpr std::array<const char *, static_cast<int>(FontWeight::Count)> FONT_FILE_PATHS = {
"../../assets/fonts/Inter-Black.ttf",
"../../assets/fonts/Inter-Bold.ttf",
"../../assets/fonts/Inter-ExtraBold.ttf",
"../../assets/fonts/Inter-ExtraLight.ttf",
"../../assets/fonts/Inter-Medium.ttf",
"../../assets/fonts/Inter-Regular.ttf",
"../../assets/fonts/Inter-SemiBold.ttf",
"../../assets/fonts/Inter-Thin.ttf",
"../../selfdrive/assets/fonts/Inter-Black.ttf",
"../../selfdrive/assets/fonts/Inter-Bold.ttf",
"../../selfdrive/assets/fonts/Inter-ExtraBold.ttf",
"../../selfdrive/assets/fonts/Inter-ExtraLight.ttf",
"../../selfdrive/assets/fonts/Inter-Medium.ttf",
"../../selfdrive/assets/fonts/Inter-Regular.ttf",
"../../selfdrive/assets/fonts/Inter-SemiBold.ttf",
"../../selfdrive/assets/fonts/Inter-Thin.ttf",
};

struct FontManager {
FontManager() {
for (int i = 0; i < fonts.size(); ++i) {
fonts[i] = LoadFontEx(FONT_FILE_PATHS[i], 120, nullptr, 250);
fonts[i] = LoadFontEx(FONT_FILE_PATHS[i], 120, nullptr, 0);
// Enable anti-aliasing for the custom font
GenTextureMipmaps(&fonts[i].texture);
SetTextureFilter(fonts[i].texture, TEXTURE_FILTER_TRILINEAR);
}
}

Expand All @@ -46,9 +50,15 @@ Texture2D LoadTextureResized(const char *fileName, int size) {
}

void initApp(const char *title, int fps) {
// ensure the current dir matches the exectuable's directory
auto self_path = util::readlink("/proc/self/exe");
auto exe_dir = std::filesystem::path(self_path).parent_path();
chdir(exe_dir.c_str());

Hardware::set_display_power(true);
Hardware::set_brightness(65);

// SetTraceLogLevel(LOG_NONE);
InitWindow(2160, 1080, title);
InitWindow(0, 0, title);
SetTargetFPS(fps);
}

0 comments on commit 636b54d

Please sign in to comment.