|
10 | 10 | #include "ExamplePlugin.hpp" |
11 | 11 | #include <cstring> // For C-style string manipulation functions like strncpy_s, strcpy_s, strcmp, strstr. |
12 | 12 |
|
| 13 | +// --- Custom Fonts --- |
| 14 | +#include "font\DRKrapkaSquare.h" |
| 15 | + |
13 | 16 | namespace ExamplePlugin { |
14 | 17 |
|
15 | 18 | // ================================================================================================= |
@@ -426,7 +429,11 @@ void OnActivated(const SPF_Core_API* core_api) { |
426 | 429 | // The actual SPF_Font_Handle should be retrieved later during rendering using UI_GetFont("ExamplePlugin_CustomFont"). |
427 | 430 | g_ctx.uiAPI->UI_LoadFontFromFile("ExamplePlugin_CustomFont", fontPath, &config); |
428 | 431 |
|
429 | | - g_ctx.coreAPI->logger->Log(logger, SPF_LOG_INFO, "Dynamic Font Management: Requested custom font Rushon Ground.ttf. It will be available in the next frame."); |
| 432 | + // --- Demo: Load Font from Memory (DRKrapkaSquare) --- |
| 433 | + // We use the compressed data from the generated .h file. |
| 434 | + g_ctx.uiAPI->UI_LoadFontFromMemory("ExamplePlugin_MemoryFont", Font_DRKrapkaSquare_compressed_data, Font_DRKrapkaSquare_compressed_size, &config); |
| 435 | + |
| 436 | + g_ctx.coreAPI->logger->Log(logger, SPF_LOG_INFO, "Dynamic Font Management: Requested fonts from file and memory. They will be available in the next frame."); |
430 | 437 | } |
431 | 438 | } |
432 | 439 |
|
@@ -1862,16 +1869,36 @@ void RenderStylingTab(SPF_UI_API* ui, void* user_data) { |
1862 | 1869 |
|
1863 | 1870 | ui->UI_Spacing(); |
1864 | 1871 | ui->UI_TextStyled(separator_style, ICON_FA_FONT " Dynamic Font Rendering"); |
1865 | | - ui->UI_TextWrapped("Demonstrating UI_LoadFontFromFile. Below is text rendered with 'Rushon Ground.ttf' loaded from the plugin's data folder."); |
| 1872 | + ui->UI_TextWrapped("Demonstrating UI_LoadFontFromFile and UI_LoadFontFromMemory."); |
| 1873 | + |
| 1874 | + // --- File Font Demo --- |
1866 | 1875 | if (!g_ctx.pluginFont) { |
1867 | | - ui->UI_TextColored(1.0f, 0.5f, 0.0f, 1.0f, "Custom font not loaded yet (queued for next frame or missing file)."); |
1868 | 1876 | g_ctx.pluginFont = ui->UI_GetFont("ExamplePlugin_CustomFont"); |
1869 | 1877 | } |
1870 | | - else{ |
| 1878 | + |
| 1879 | + if (g_ctx.pluginFont) { |
1871 | 1880 | ui->UI_PushFont(g_ctx.pluginFont); |
1872 | | - ui->UI_TextColored(0.4f, 0.7f, 1.0f, 1.0f, "This text uses a custom plugin font!"); |
| 1881 | + ui->UI_TextColored(0.4f, 0.7f, 1.0f, 1.0f, "This text uses a custom font loaded from FILE (Rushon Ground.ttf)!"); |
| 1882 | + ui->UI_Text("Sample: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789"); |
| 1883 | + ui->UI_PopFont(); |
| 1884 | + } else { |
| 1885 | + ui->UI_TextColored(1.0f, 0.5f, 0.0f, 1.0f, "File font not loaded yet (queued for next frame or missing file)."); |
| 1886 | + } |
| 1887 | + |
| 1888 | + ui->UI_Spacing(); |
| 1889 | + |
| 1890 | + // --- Memory Font Demo --- |
| 1891 | + if (!g_ctx.memoryFont) { |
| 1892 | + g_ctx.memoryFont = ui->UI_GetFont("ExamplePlugin_MemoryFont"); |
| 1893 | + } |
| 1894 | + |
| 1895 | + if (g_ctx.memoryFont) { |
| 1896 | + ui->UI_PushFont(g_ctx.memoryFont); |
| 1897 | + ui->UI_TextColored(0.7f, 1.0f, 0.4f, 1.0f, "This text uses a custom font loaded from MEMORY (DRKrapkaSquare)!"); |
1873 | 1898 | ui->UI_Text("Sample: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789"); |
1874 | 1899 | ui->UI_PopFont(); |
| 1900 | + } else { |
| 1901 | + ui->UI_TextColored(1.0f, 0.5f, 0.0f, 1.0f, "Memory font not loaded yet (queued for next frame)."); |
1875 | 1902 | } |
1876 | 1903 |
|
1877 | 1904 | ui->UI_Spacing(); |
|
0 commit comments