Added custom title font

Adjusted text system to have multiple fonts
Added color escape to text
This commit is contained in:
MysterD 2021-06-21 21:18:27 -07:00
parent 7aec232450
commit dfef74e727
111 changed files with 848 additions and 199 deletions

View file

@ -193,6 +193,7 @@ SKY_FILES := $(patsubst %.png,%.inc.c,$(wildcard $(TEXTURE_DI
MACHINE_FILES := $(patsubst %.png,%.inc.c,$(wildcard $(TEXTURE_DIR)/machine/*.png))
MOUNTAIN_FILES := $(patsubst %.png,%.inc.c,$(wildcard $(TEXTURE_DIR)/mountain/*.png))
GRASS_FILES := $(patsubst %.png,%.inc.c,$(wildcard $(TEXTURE_DIR)/grass/*.png))
CUSTOM_FONT_TITLE_FILES := $(patsubst %.png,%.inc.c,$(wildcard $(TEXTURE_DIR)/custom_font_title/*.png))
# Texture Files
$(BUILD_DIR)/bin/segment2.o: $(addprefix $(BUILD_DIR)/,$(SEGMENT2_FILES))
@ -210,6 +211,7 @@ $(BUILD_DIR)/bin/sky.o: $(addprefix $(BUILD_DIR)/,$(SKY_FILES))
$(BUILD_DIR)/bin/machine.o: $(addprefix $(BUILD_DIR)/,$(MACHINE_FILES))
$(BUILD_DIR)/bin/mountain.o: $(addprefix $(BUILD_DIR)/,$(MOUNTAIN_FILES))
$(BUILD_DIR)/bin/grass.o: $(addprefix $(BUILD_DIR)/,$(GRASS_FILES))
$(BUILD_DIR)/bin/custom_font_title.o: $(addprefix $(BUILD_DIR)/,$(CUSTOM_FONT_TITLE_FILES))
# Others
$(BUILD_DIR)/bin/segment2.elf: SEGMENT_ADDRESS := 0x02000000
@ -228,6 +230,7 @@ $(BUILD_DIR)/bin/sky.elf: SEGMENT_ADDRESS := 0x09000000
$(BUILD_DIR)/bin/machine.elf: SEGMENT_ADDRESS := 0x09000000
$(BUILD_DIR)/bin/mountain.elf: SEGMENT_ADDRESS := 0x09000000
$(BUILD_DIR)/bin/grass.elf: SEGMENT_ADDRESS := 0x09000000
$(BUILD_DIR)/bin/custom_font_title.elf: SEGMENT_ADDRESS := 0x09000000
# EU segment 19 translations
$(BUILD_DIR)/bin/eu/translation_de.elf: SEGMENT_ADDRESS := 0x19000000

482
bin/custom_font_title.c Normal file
View file

@ -0,0 +1,482 @@
#include <ultra64.h>
#include "sm64.h"
#include "game/ingame_menu.h"
#include "make_const_nonconst.h"
ALIGNED8 static const u8 texture_font_title_char_01[] = {
#include "textures/custom_font_title/custom_font_title_01.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_02[] = {
#include "textures/custom_font_title/custom_font_title_02.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_03[] = {
#include "textures/custom_font_title/custom_font_title_03.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_04[] = {
#include "textures/custom_font_title/custom_font_title_04.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_05[] = {
#include "textures/custom_font_title/custom_font_title_05.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_06[] = {
#include "textures/custom_font_title/custom_font_title_06.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_07[] = {
#include "textures/custom_font_title/custom_font_title_07.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_08[] = {
#include "textures/custom_font_title/custom_font_title_08.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_09[] = {
#include "textures/custom_font_title/custom_font_title_09.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_10[] = {
#include "textures/custom_font_title/custom_font_title_10.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_11[] = {
#include "textures/custom_font_title/custom_font_title_11.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_12[] = {
#include "textures/custom_font_title/custom_font_title_12.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_13[] = {
#include "textures/custom_font_title/custom_font_title_13.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_14[] = {
#include "textures/custom_font_title/custom_font_title_14.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_15[] = {
#include "textures/custom_font_title/custom_font_title_15.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_16[] = {
#include "textures/custom_font_title/custom_font_title_16.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_17[] = {
#include "textures/custom_font_title/custom_font_title_17.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_18[] = {
#include "textures/custom_font_title/custom_font_title_18.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_19[] = {
#include "textures/custom_font_title/custom_font_title_19.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_20[] = {
#include "textures/custom_font_title/custom_font_title_20.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_21[] = {
#include "textures/custom_font_title/custom_font_title_21.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_22[] = {
#include "textures/custom_font_title/custom_font_title_22.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_23[] = {
#include "textures/custom_font_title/custom_font_title_23.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_24[] = {
#include "textures/custom_font_title/custom_font_title_24.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_25[] = {
#include "textures/custom_font_title/custom_font_title_25.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_26[] = {
#include "textures/custom_font_title/custom_font_title_26.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_27[] = {
#include "textures/custom_font_title/custom_font_title_27.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_28[] = {
#include "textures/custom_font_title/custom_font_title_28.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_29[] = {
#include "textures/custom_font_title/custom_font_title_29.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_30[] = {
#include "textures/custom_font_title/custom_font_title_30.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_31[] = {
#include "textures/custom_font_title/custom_font_title_31.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_32[] = {
#include "textures/custom_font_title/custom_font_title_32.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_33[] = {
#include "textures/custom_font_title/custom_font_title_33.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_34[] = {
#include "textures/custom_font_title/custom_font_title_34.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_35[] = {
#include "textures/custom_font_title/custom_font_title_35.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_36[] = {
#include "textures/custom_font_title/custom_font_title_36.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_37[] = {
#include "textures/custom_font_title/custom_font_title_37.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_38[] = {
#include "textures/custom_font_title/custom_font_title_38.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_39[] = {
#include "textures/custom_font_title/custom_font_title_39.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_40[] = {
#include "textures/custom_font_title/custom_font_title_40.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_41[] = {
#include "textures/custom_font_title/custom_font_title_41.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_42[] = {
#include "textures/custom_font_title/custom_font_title_42.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_43[] = {
#include "textures/custom_font_title/custom_font_title_43.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_44[] = {
#include "textures/custom_font_title/custom_font_title_44.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_45[] = {
#include "textures/custom_font_title/custom_font_title_45.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_46[] = {
#include "textures/custom_font_title/custom_font_title_46.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_47[] = {
#include "textures/custom_font_title/custom_font_title_47.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_48[] = {
#include "textures/custom_font_title/custom_font_title_48.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_49[] = {
#include "textures/custom_font_title/custom_font_title_49.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_50[] = {
#include "textures/custom_font_title/custom_font_title_50.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_51[] = {
#include "textures/custom_font_title/custom_font_title_51.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_52[] = {
#include "textures/custom_font_title/custom_font_title_52.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_53[] = {
#include "textures/custom_font_title/custom_font_title_53.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_54[] = {
#include "textures/custom_font_title/custom_font_title_54.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_55[] = {
#include "textures/custom_font_title/custom_font_title_55.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_56[] = {
#include "textures/custom_font_title/custom_font_title_56.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_57[] = {
#include "textures/custom_font_title/custom_font_title_57.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_58[] = {
#include "textures/custom_font_title/custom_font_title_58.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_59[] = {
#include "textures/custom_font_title/custom_font_title_59.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_60[] = {
#include "textures/custom_font_title/custom_font_title_60.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_61[] = {
#include "textures/custom_font_title/custom_font_title_61.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_62[] = {
#include "textures/custom_font_title/custom_font_title_62.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_63[] = {
#include "textures/custom_font_title/custom_font_title_63.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_64[] = {
#include "textures/custom_font_title/custom_font_title_64.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_65[] = {
#include "textures/custom_font_title/custom_font_title_65.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_66[] = {
#include "textures/custom_font_title/custom_font_title_66.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_67[] = {
#include "textures/custom_font_title/custom_font_title_67.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_68[] = {
#include "textures/custom_font_title/custom_font_title_68.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_69[] = {
#include "textures/custom_font_title/custom_font_title_69.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_70[] = {
#include "textures/custom_font_title/custom_font_title_70.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_71[] = {
#include "textures/custom_font_title/custom_font_title_71.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_72[] = {
#include "textures/custom_font_title/custom_font_title_72.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_73[] = {
#include "textures/custom_font_title/custom_font_title_73.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_74[] = {
#include "textures/custom_font_title/custom_font_title_74.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_75[] = {
#include "textures/custom_font_title/custom_font_title_75.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_76[] = {
#include "textures/custom_font_title/custom_font_title_76.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_77[] = {
#include "textures/custom_font_title/custom_font_title_77.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_78[] = {
#include "textures/custom_font_title/custom_font_title_78.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_79[] = {
#include "textures/custom_font_title/custom_font_title_79.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_80[] = {
#include "textures/custom_font_title/custom_font_title_80.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_81[] = {
#include "textures/custom_font_title/custom_font_title_81.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_82[] = {
#include "textures/custom_font_title/custom_font_title_82.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_83[] = {
#include "textures/custom_font_title/custom_font_title_83.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_84[] = {
#include "textures/custom_font_title/custom_font_title_84.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_85[] = {
#include "textures/custom_font_title/custom_font_title_85.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_86[] = {
#include "textures/custom_font_title/custom_font_title_86.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_87[] = {
#include "textures/custom_font_title/custom_font_title_87.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_88[] = {
#include "textures/custom_font_title/custom_font_title_88.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_89[] = {
#include "textures/custom_font_title/custom_font_title_89.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_90[] = {
#include "textures/custom_font_title/custom_font_title_90.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_91[] = {
#include "textures/custom_font_title/custom_font_title_91.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_92[] = {
#include "textures/custom_font_title/custom_font_title_92.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_93[] = {
#include "textures/custom_font_title/custom_font_title_93.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_94[] = {
#include "textures/custom_font_title/custom_font_title_94.rgba32.inc.c"
};
ALIGNED8 static const u8 texture_font_title_char_95[] = {
#include "textures/custom_font_title/custom_font_title_95.rgba32.inc.c"
};
const u8 *const font_title_chars[] = {
texture_font_title_char_01,
texture_font_title_char_02,
texture_font_title_char_03,
texture_font_title_char_04,
texture_font_title_char_05,
texture_font_title_char_06,
texture_font_title_char_07,
texture_font_title_char_08,
texture_font_title_char_09,
texture_font_title_char_10,
texture_font_title_char_11,
texture_font_title_char_12,
texture_font_title_char_13,
texture_font_title_char_14,
texture_font_title_char_15,
texture_font_title_char_16,
texture_font_title_char_17,
texture_font_title_char_18,
texture_font_title_char_19,
texture_font_title_char_20,
texture_font_title_char_21,
texture_font_title_char_22,
texture_font_title_char_23,
texture_font_title_char_24,
texture_font_title_char_25,
texture_font_title_char_26,
texture_font_title_char_27,
texture_font_title_char_28,
texture_font_title_char_29,
texture_font_title_char_30,
texture_font_title_char_31,
texture_font_title_char_32,
texture_font_title_char_33,
texture_font_title_char_34,
texture_font_title_char_35,
texture_font_title_char_36,
texture_font_title_char_37,
texture_font_title_char_38,
texture_font_title_char_39,
texture_font_title_char_40,
texture_font_title_char_41,
texture_font_title_char_42,
texture_font_title_char_43,
texture_font_title_char_44,
texture_font_title_char_45,
texture_font_title_char_46,
texture_font_title_char_47,
texture_font_title_char_48,
texture_font_title_char_49,
texture_font_title_char_50,
texture_font_title_char_51,
texture_font_title_char_52,
texture_font_title_char_53,
texture_font_title_char_54,
texture_font_title_char_55,
texture_font_title_char_56,
texture_font_title_char_57,
texture_font_title_char_58,
texture_font_title_char_59,
texture_font_title_char_60,
texture_font_title_char_61,
texture_font_title_char_62,
texture_font_title_char_63,
texture_font_title_char_64,
texture_font_title_char_65,
texture_font_title_char_66,
texture_font_title_char_67,
texture_font_title_char_68,
texture_font_title_char_69,
texture_font_title_char_70,
texture_font_title_char_71,
texture_font_title_char_72,
texture_font_title_char_73,
texture_font_title_char_74,
texture_font_title_char_75,
texture_font_title_char_76,
texture_font_title_char_77,
texture_font_title_char_78,
texture_font_title_char_79,
texture_font_title_char_80,
texture_font_title_char_81,
texture_font_title_char_82,
texture_font_title_char_83,
texture_font_title_char_84,
texture_font_title_char_85,
texture_font_title_char_86,
texture_font_title_char_87,
texture_font_title_char_88,
texture_font_title_char_89,
texture_font_title_char_90,
texture_font_title_char_91,
texture_font_title_char_92,
texture_font_title_char_93,
texture_font_title_char_94,
texture_font_title_char_95,
};

View file

@ -3945,9 +3945,11 @@
<ClCompile Include="..\src\pc\djui\djui_base.c" />
<ClCompile Include="..\src\pc\djui\djui_button.c" />
<ClCompile Include="..\src\pc\djui\djui_flow_layout.c" />
<ClCompile Include="..\src\pc\djui\djui_font.c" />
<ClCompile Include="..\src\pc\djui\djui_gfx.c" />
<ClCompile Include="..\src\pc\djui\djui_image.c" />
<ClCompile Include="..\src\pc\djui\djui_interactable.c" />
<ClCompile Include="..\src\pc\djui\djui_panel_debug.c" />
<ClCompile Include="..\src\pc\djui\djui_panel_main.c" />
<ClCompile Include="..\src\pc\djui\djui_panel_quit.c" />
<ClCompile Include="..\src\pc\djui\djui_rect.c" />
@ -4369,10 +4371,12 @@
<ClInclude Include="..\src\pc\djui\djui_base.h" />
<ClInclude Include="..\src\pc\djui\djui_button.h" />
<ClInclude Include="..\src\pc\djui\djui_flow_layout.h" />
<ClInclude Include="..\src\pc\djui\djui_font.h" />
<ClInclude Include="..\src\pc\djui\djui_gbi.h" />
<ClInclude Include="..\src\pc\djui\djui_gfx.h" />
<ClInclude Include="..\src\pc\djui\djui_image.h" />
<ClInclude Include="..\src\pc\djui\djui_interactable.h" />
<ClInclude Include="..\src\pc\djui\djui_panel_debug.h" />
<ClInclude Include="..\src\pc\djui\djui_panel_main.h" />
<ClInclude Include="..\src\pc\djui\djui_panel_quit.h" />
<ClInclude Include="..\src\pc\djui\djui_rect.h" />

View file

@ -15198,6 +15198,12 @@
<ClCompile Include="..\src\pc\utils\misc.c">
<Filter>Source Files\src\pc\utils</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_font.c">
<Filter>Source Files\src\pc\djui</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_panel_debug.c">
<Filter>Source Files\src\pc\djui\panel</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\actors\common0.h">
@ -16216,5 +16222,11 @@
<ClInclude Include="..\src\pc\utils\misc.h">
<Filter>Source Files\src\pc\utils</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_font.h">
<Filter>Source Files\src\pc\djui</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_panel_debug.h">
<Filter>Source Files\src\pc\djui\panel</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -4,14 +4,6 @@
#include "src/pc/controller/controller_sdl.h"
#include "src/pc/controller/controller_mouse.h"
ALIGNED8 static const u8 texture32x32[] = {
#include "actors/bubble/mr_i_bubble.rgba16.inc.c"
};
ALIGNED8 static const u8 texture16x16[] = {
#include "textures/segment2/custom_luigi_head.rgba16.inc.c"
};
ALIGNED8 static u8 texture_hand_open[] = {
#include "textures/intro_raw/hand_open.rgba16.inc.c"
};
@ -20,10 +12,6 @@ ALIGNED8 static u8 texture_hand_closed[] = {
#include "textures/intro_raw/hand_closed.rgba16.inc.c"
};
ALIGNED8 static u8 texture_title[] = {
#include "textures/segment2/custom_title.rgba32.inc.c"
};
static Gfx* sSavedDisplayListHead = NULL;
struct DjuiRoot* gDjuiRoot = NULL;
@ -38,61 +26,7 @@ static void djui_init(void) {
djui_base_set_size(&sMouseCursor->base, 64, 64);
djui_panel_main_create();
}
static void djui_debug_update(void) {
/*static struct DjuiImage* sDjuiImage = NULL;
static struct DjuiRect* sDjuiRect = NULL;;
static struct DjuiRect* sDjuiRect2 = NULL;;
static struct DjuiText* sDjuiText = NULL;;
if (sDjuiImage == NULL) {
struct DjuiRect* imageContainer = djui_rect_create(&gDjuiRoot->base);
djui_base_set_location(&imageContainer->base, 32, 32);
djui_base_set_size(&imageContainer->base, 128, 128);
djui_base_set_padding(&imageContainer->base, 48, 48, 48, 48);
sDjuiImage = djui_image_create(&imageContainer->base, texture16x16, 16, 16, 16);
djui_base_set_location(&sDjuiImage->base, 0, 0);
djui_base_set_size(&sDjuiImage->base, 32, 32);
djui_base_set_size_type(&sDjuiImage->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&sDjuiImage->base, 1.0f, 1.0f);
sDjuiRect = djui_rect_create(&gDjuiRoot->base);
djui_base_set_location(&sDjuiRect->base, 64, 64);
djui_base_set_size(&sDjuiRect->base, 188, 64);
djui_base_set_color(&sDjuiRect->base, 255, 255, 255, 200);
djui_base_set_alignment(&sDjuiRect->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_BOTTOM);
sDjuiRect2 = djui_rect_create(&sDjuiRect->base);
djui_base_set_location(&sDjuiRect2->base, 0, 0);
djui_base_set_size(&sDjuiRect2->base, 188 - 8, 64 - 8);
djui_base_set_alignment(&sDjuiRect2->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
sDjuiText = djui_text_create(&sDjuiRect2->base, "Host");
djui_base_set_location(&sDjuiText->base, 0, 0);
djui_base_set_size(&sDjuiText->base, 188 - 8, 64 - 8);
djui_base_set_color(&sDjuiText->base, 111, 111, 111, 255);
djui_text_set_font_size(sDjuiText, 2);
djui_text_set_alignment(sDjuiText, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
}*/
static u32 sTimer = 0;
sTimer++;
/*djui_base_set_size(&buttonContainer->base,
512.0f + cos((sTimer) / 20.0f) * 256.0f,
buttonContainer->base.height.value);*/
/*djui_base_set_location(&sDjuiImage->base,
0.0f + cos((sTimer) / 30.0f) * 128.0f,
0.0f + fabs(sin((sTimer) / 30.0f)) * 128.0f);*/
/*djui_base_set_color(&sDjuiImage->base,
127.0f + sin((sTimer) / 13.0f) * 127.0f,
127.0f + sin((sTimer) / 17.0f) * 127.0f,
127.0f + sin((sTimer) / 23.0f) * 127.0f,
255);
djui_base_set_location(&sDjuiRect2->base,
32.0f + cos((sTimer) / 10.0f) * 64.0f,
32.0f + sin((sTimer) / 31.0f) * 64.0f);*/
//djui_panel_debug_create();
}
static void djui_mouse_update(void) {
@ -127,7 +61,6 @@ void djui_render(void) {
create_dl_ortho_matrix();
djui_mouse_update();
djui_debug_update();
djui_base_render(&gDjuiRoot->base);
djui_base_render(&sMouseCursor->base);

View file

@ -8,6 +8,7 @@
#include "game/ingame_menu.h"
#include "djui_types.h"
#include "djui_font.h"
#include "djui_gfx.h"
#include "djui_base.h"
#include "djui_interactable.h"
@ -20,6 +21,7 @@
#include "djui_button.h"
#include "djui_flow_layout.h"
#include "djui_panel_debug.h"
#include "djui_panel_main.h"
#include "djui_panel_quit.h"

116
src/pc/djui/djui_font.c Normal file
View file

@ -0,0 +1,116 @@
#include "djui.h"
#include "game/segment2.h"
///////////////////////////////////
// font 0 (built-in normal font) //
///////////////////////////////////
static Vtx djui_font_normal_vertices[] = {
{{{ 0, -1, 0}, 0, { 0, 256}, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 0.5f, -1, 0}, 0, { 0, 0}, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 0.5f, 0, 0}, 0, { 512, 0}, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 0, 0, 0}, 0, { 512, 256}, { 0xff, 0xff, 0xff, 0xff }}},
};
static const Gfx djui_font_normal_text_begin[] = {
gsDPPipeSync(),
gsSPClearGeometryMode(G_LIGHTING),
gsDPSetCombineMode(G_CC_FADEA, G_CC_FADEA),
gsDPSetEnvColor(255, 255, 255, 255),
gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2),
gsDPSetTextureFilter(G_TF_POINT),
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON),
gsSPEndDisplayList(),
};
static const Gfx djui_font_normal_text_settings[] = {
gsDPSetTile(G_IM_FMT_IA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 3, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD),
gsDPLoadSync(),
gsDPLoadBlock(G_TX_LOADTILE, 0, 0, ((16 * 8 + G_IM_SIZ_4b_INCR) >> G_IM_SIZ_4b_SHIFT) - 1, CALC_DXT(16, G_IM_SIZ_4b_BYTES)),
gsDPSetTile(G_IM_FMT_IA, G_IM_SIZ_4b, 1, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 3, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD),
gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (8 - 1) << G_TEXTURE_IMAGE_FRAC),
gsSPVertex(djui_font_normal_vertices, 4, 0),
gsSPExecuteDjui(G_TEXCLIP_DJUI),
gsSP2Triangles(0, 1, 2, 0x0, 0, 2, 3, 0x0),
gsSPEndDisplayList(),
};
static void djui_font_normal_render_char(char c) {
void** fontLUT;
void* packedTexture;
u8 d = str_ascii_char_to_dialog(c);
fontLUT = segmented_to_virtual(main_font_lut);
packedTexture = segmented_to_virtual(fontLUT[d]);
gDPPipeSync(gDisplayListHead++);
gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, VIRTUAL_TO_PHYSICAL(packedTexture));
gSPDisplayList(gDisplayListHead++, djui_font_normal_text_settings);
}
static f32 djui_font_normal_char_width(char c) {
u8 d = str_ascii_char_to_dialog(c);
return gDialogCharWidths[d] / 16.0f;
}
static const struct DjuiFont sDjuiFontNormal = {
.charWidth = 0.5f,
.charHeight = 1.0f,
.lineHeight = 0.8f,
.defaultFontScale = 32.0f,
.rotatedUV = true,
.textBeginDisplayList = djui_font_normal_text_begin,
.render_char = djui_font_normal_render_char,
.char_width = djui_font_normal_char_width,
};
////////////////////////////////
// font 1 (custom title font) //
////////////////////////////////
static f32 sDjuiFontTitleCharWidths[] = {
/* ! " # $ % & ' ( ) * + , - . / */
0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f,
/* 0 1 2 3 4 5 6 7 8 9 */
0.45f, 0.35f, 0.45f, 0.45f, 0.45f, 0.45f, 0.45f, 0.45f, 0.45f, 0.45f,
/* : ; < = > ? @ */
0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f,
/* A B C D E F G H I J K L M N O P Q R S T U V W X Y Z */
0.55f, 0.50f, 0.50f, 0.50f, 0.45f, 0.45f, 0.50f, 0.55f, 0.28f, 0.60f, 0.50f, 0.45f, 0.55f, 0.50f, 0.50f, 0.45f, 0.50f, 0.50f, 0.55f, 0.50f, 0.50f, 0.50f, 0.60f, 0.52f, 0.60f, 0.45f,
/* [ \ ] ^ _ ` */
0.50f, 0.50f, 0.50f, 0.50f, 0.50f, 0.50f,
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */
0.45f, 0.45f, 0.40f, 0.40f, 0.45f, 0.37f, 0.40f, 0.40f, 0.20f, 0.45f, 0.40f, 0.30f, 0.50f, 0.40f, 0.40f, 0.40f, 0.45f, 0.40f, 0.50f, 0.45f, 0.50f, 0.40f, 0.50f, 0.50f, 0.45f, 0.45f,
/* { | } ~ ! */
0.50f, 0.50f, 0.50f, 0.50f, 0.50f,
};
static void djui_font_title_render_char(char c) {
extern const u8* const font_title_chars[];
djui_gfx_render_texture(font_title_chars[c - '!'], 64, 64, 32);
}
static f32 djui_font_title_char_width(char c) {
if (c == ' ') { return 0.30f; }
return sDjuiFontTitleCharWidths[c - '!'];
}
static const struct DjuiFont sDjuiFontTitle = {
.charWidth = 1.0f,
.charHeight = 1.0f,
.lineHeight = 0.7f,
.defaultFontScale = 64.0f,
.rotatedUV = false,
.textBeginDisplayList = NULL,
.render_char = djui_font_title_render_char,
.char_width = djui_font_title_char_width,
};
///////////////
// font list //
///////////////
struct DjuiFont gDjuiFonts[] = {
sDjuiFontNormal,
sDjuiFontTitle,
};

17
src/pc/djui/djui_font.h Normal file
View file

@ -0,0 +1,17 @@
#pragma once
#include "djui.h"
#pragma pack(1)
struct DjuiFont {
f32 charWidth;
f32 charHeight;
f32 lineHeight;
f32 defaultFontScale;
u8 textureBitSize;
bool rotatedUV;
const Gfx* textBeginDisplayList;
void (*render_char)(char);
f32 (*char_width)(char);
};
extern struct DjuiFont gDjuiFonts[];

View file

@ -26,55 +26,11 @@ const Gfx dl_djui_simple_rect[] = {
/////////////////////////////////////////////
static Vtx vertex_djui_ia_char[] = {
{{{ 0, -16, 0}, 0, { 0, 256}, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 8, -16, 0}, 0, { 0, 0}, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 8, 0, 0}, 0, { 512, 0}, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 0, 0, 0}, 0, { 512, 256}, { 0xff, 0xff, 0xff, 0xff }}},
};
const Gfx dl_djui_ia_text_begin[] = {
gsDPPipeSync(),
gsSPClearGeometryMode(G_LIGHTING),
gsDPSetCombineMode(G_CC_FADEA, G_CC_FADEA),
gsDPSetEnvColor(255, 255, 255, 255),
gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2),
gsDPSetTextureFilter(G_TF_POINT),
gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON),
gsSPEndDisplayList(),
};
const Gfx dl_djui_ia_text_settings[] = {
gsDPSetTile(G_IM_FMT_IA, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 3, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD),
gsDPLoadSync(),
gsDPLoadBlock(G_TX_LOADTILE, 0, 0, ((16 * 8 + G_IM_SIZ_4b_INCR) >> G_IM_SIZ_4b_SHIFT) - 1, CALC_DXT(16, G_IM_SIZ_4b_BYTES)),
gsDPSetTile(G_IM_FMT_IA, G_IM_SIZ_4b, 1, 0, G_TX_RENDERTILE, 0, G_TX_WRAP | G_TX_NOMIRROR, 3, G_TX_NOLOD, G_TX_WRAP | G_TX_NOMIRROR, 4, G_TX_NOLOD),
gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (8 - 1) << G_TEXTURE_IMAGE_FRAC),
gsSPVertex(vertex_djui_ia_char, 4, 0),
gsSPExecuteDjui(G_TEXCLIP_DJUI),
gsSP2Triangles(0, 1, 2, 0x0, 0, 2, 3, 0x0),
gsSPEndDisplayList(),
};
void djui_gfx_render_char(u8 c) {
void** fontLUT;
void* packedTexture;
fontLUT = segmented_to_virtual(main_font_lut);
packedTexture = segmented_to_virtual(fontLUT[c]);
gDPPipeSync(gDisplayListHead++);
gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, VIRTUAL_TO_PHYSICAL(packedTexture));
gSPDisplayList(gDisplayListHead++, dl_djui_ia_text_settings);
}
/////////////////////////////////////////////
static const Vtx vertex_djui_image[] = {
{{{ 0, -1, 0 }, 0, { 0, 512 }, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 1, -1, 0 }, 0, { 512, 512 }, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 1, -1, 0 }, 0, { 512, 512 }, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 1, 0, 0 }, 0, { 512, 0 }, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 0, 0, 0 }, 0, { 0, 0 }, { 0xff, 0xff, 0xff, 0xff }}},
{{{ 0, 0, 0 }, 0, { 0, 0 }, { 0xff, 0xff, 0xff, 0xff }}},
};
const Gfx dl_djui_image[] = {

View file

@ -6,11 +6,9 @@
#define DJUI_MTX_NOPUSH 2
extern const Gfx dl_djui_simple_rect[];
extern const Gfx dl_djui_ia_text_begin[];
extern const Gfx dl_djui_img_begin[];
extern const Gfx dl_djui_img_end[];
void djui_gfx_render_char(u8 c);
void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize);
void djui_gfx_position_translate(f32* x, f32* y);

View file

@ -0,0 +1,66 @@
#include "djui.h"
static struct DjuiRect* sDjuiRect = NULL;
static struct DjuiText* sDjuiText = NULL;
static struct DjuiRect* sDjuiRect2 = NULL;
static struct DjuiText* sDjuiText2 = NULL;
static void djui_panel_debug_render_pre(struct DjuiBase* base, bool* skipRender) {
static u32 sTimer = 0;
sTimer++;
if (sDjuiText != NULL) {
djui_base_set_location(&sDjuiText->base,
32.0f + cos(sTimer / 20.0f) * 100.0f,
32.0f + sin(sTimer / 62.0f) * 50.0f);
djui_text_set_font_scale(sDjuiText, 16.0f + sin((sTimer) / 72.0f) * 4.0f);
}
if (sDjuiText2 != NULL) {
djui_base_set_location(&sDjuiText2->base,
32.0f + cos(sTimer / 20.0f) * 100.0f,
32.0f + sin(sTimer / 62.0f) * 100.0f);
djui_text_set_font_scale(sDjuiText2, 64.0f + sin((sTimer) / 72.0f) * 8.0f);
}
}
void djui_panel_debug_create(void) {
sDjuiRect = djui_rect_create(&gDjuiRoot->base);
djui_base_set_location(&sDjuiRect->base, 64, 64);
djui_base_set_size(&sDjuiRect->base, 300, 100);
djui_base_set_color(&sDjuiRect->base, 0, 0, 0, 255);
djui_base_set_alignment(&sDjuiRect->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
sDjuiRect->base.on_render_pre = djui_panel_debug_render_pre;
sDjuiText = djui_text_create(&sDjuiRect->base, "hello\nworld");
djui_base_set_location(&sDjuiText->base, 0, 0);
djui_base_set_size(&sDjuiText->base, 300, 300);
djui_base_set_color(&sDjuiText->base, 255, 255, 255, 255);
djui_text_set_drop_shadow(sDjuiText, 255, 0, 0, 255);
djui_text_set_alignment(sDjuiText, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
sDjuiRect2 = djui_rect_create(&gDjuiRoot->base);
djui_base_set_location(&sDjuiRect2->base, 64, 64);
djui_base_set_size(&sDjuiRect2->base, 300, 100);
djui_base_set_color(&sDjuiRect2->base, 100, 100, 100, 255);
djui_base_set_alignment(&sDjuiRect2->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_BOTTOM);
sDjuiText2 = djui_text_create(&sDjuiRect2->base, "hello\nworld");
djui_base_set_location(&sDjuiText2->base, 0, 0);
djui_base_set_size(&sDjuiText2->base, 400, 400);
djui_base_set_color(&sDjuiText2->base, 255, 255, 255, 255);
djui_text_set_drop_shadow(sDjuiText2, 255, 0, 0, 255);
djui_text_set_alignment(sDjuiText2, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
djui_text_set_font(sDjuiText2, &gDjuiFonts[1]);
struct DjuiText* alphabet = djui_text_create(&gDjuiRoot->base, "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n01234567890\nthe quick brown fox jumps over the lazy dog\ngeqkbnfjsortelydg\nTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG\nGEQKBNFJSORTELYDG");
djui_base_set_location(&alphabet->base, 0, 0);
djui_base_set_size(&alphabet->base, 400, 400);
djui_base_set_size_type(&alphabet->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&alphabet->base, 1, 1);
djui_base_set_color(&alphabet->base, 255, 255, 255, 255);
djui_text_set_drop_shadow(alphabet, 255, 0, 0, 255);
djui_text_set_alignment(alphabet, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_text_set_font(alphabet, &gDjuiFonts[1]);
djui_text_set_font_scale(alphabet, 64);
}

View file

@ -0,0 +1,4 @@
#pragma once
#include "djui.h"
void djui_panel_debug_create(void);

View file

@ -5,19 +5,19 @@ ALIGNED8 static u8 texture_title[] = {
};
struct DjuiRect* gPanelMainMenu = NULL;
struct DjuiRect* sTitleContainer = NULL;
struct DjuiFlowLayout* sButtonContainer = NULL;
struct DjuiText* sTitleText = NULL;
struct DjuiText* sVersionText = NULL;
static void djui_panel_main_render_pre(struct DjuiBase* base, bool* skipRender) {
sTitleContainer->base.height.value = sButtonContainer->base.clip.y - gPanelMainMenu->base.comp.y;
sVersionText->base.height.value = sTitleContainer->base.height.value;
sTitleText->base.height.value = sButtonContainer->base.clip.y - gPanelMainMenu->base.comp.y;
sVersionText->base.height.value = sTitleText->base.height.value;
}
void djui_panel_main_create(void) {
gPanelMainMenu = djui_rect_create(&gDjuiRoot->base);
djui_base_set_size_type(&gPanelMainMenu->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE);
djui_base_set_size(&gPanelMainMenu->base, 512.0f + (16 * 2.0f), 1.0f);
djui_base_set_size(&gPanelMainMenu->base, 350.0f + (16 * 2.0f), 1.0f);
djui_base_set_color(&gPanelMainMenu->base, 0, 0, 0, 230);
djui_base_set_border_color(&gPanelMainMenu->base, 0, 0, 0, 200);
djui_base_set_border_width(&gPanelMainMenu->base, 8);
@ -49,18 +49,16 @@ void djui_panel_main_create(void) {
button4->base.interactable->on_click = djui_panel_quit_open;
}
sTitleContainer = djui_rect_create(&gPanelMainMenu->base);
djui_base_set_alignment(&sTitleContainer->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_TOP);
djui_base_set_size_type(&sTitleContainer->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&sTitleContainer->base, 1.0f, 1.0f);
djui_base_set_color(&sTitleContainer->base, 0, 0, 0, 0);
sTitleContainer->base.on_render_pre = djui_panel_main_render_pre;
{
struct DjuiImage* title = djui_image_create(&sTitleContainer->base, texture_title, 512, 128, 32);
djui_base_set_size(&title->base, 1.0f, 128.0f / 512.0f);
djui_base_set_size_type(&title->base, DJUI_SVT_RELATIVE, DJUI_SVT_ASPECT_RATIO);
djui_base_set_alignment(&title->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
}
//sTitleText = djui_text_create(&gPanelMainMenu->base, "SM64EX\nCOOP");
sTitleText = djui_text_create(&gPanelMainMenu->base, "\\#ff0800\\SM\\#1be700\\64\\#00b3ff\\EX\n\\#ffef00\\COOP");
djui_base_set_alignment(&sTitleText->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_TOP);
djui_base_set_size_type(&sTitleText->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&sTitleText->base, 1.0f, 1.0f);
djui_base_set_color(&sTitleText->base, 255, 8, 0, 255);
djui_text_set_alignment(sTitleText, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_text_set_font(sTitleText, &gDjuiFonts[1]);
djui_text_set_font_scale(sTitleText, gDjuiFonts[1].defaultFontScale);
sTitleText->base.on_render_pre = djui_panel_main_render_pre;
sVersionText = djui_text_create(&gPanelMainMenu->base, "version - unst 5");
djui_base_set_alignment(&sVersionText->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_BOTTOM);

View file

@ -48,7 +48,7 @@ static void djui_panel_quit_create(void) {
sClosing = false;
sPanelQuit = djui_rect_create(&gDjuiRoot->base);
djui_base_set_size_type(&sPanelQuit->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE);
djui_base_set_size(&sPanelQuit->base, 512.0f + (16 * 2.0f), 1.0f);
djui_base_set_size(&sPanelQuit->base, 350.0f + (16 * 2.0f), 1.0f);
djui_base_set_color(&sPanelQuit->base, 0, 0, 0, 230);
djui_base_set_border_color(&sPanelQuit->base, 0, 0, 0, 200);
djui_base_set_border_width(&sPanelQuit->base, 8);

View file

@ -2,6 +2,8 @@
#include "djui.h"
#include "game/segment2.h"
static u8 sSavedAlpha = 0;
////////////////
// properties //
////////////////
@ -18,8 +20,12 @@ void djui_text_set_text(struct DjuiText* text, const char* message) {
memcpy(text->message, message, sizeof(char) * (messageLen + 1));
}
void djui_text_set_font_size(struct DjuiText* text, f32 fontSize) {
text->fontSize = fontSize;
void djui_text_set_font(struct DjuiText* text, struct DjuiFont* font) {
text->font = font;
}
void djui_text_set_font_scale(struct DjuiText* text, f32 fontScale) {
text->fontScale = fontScale;
}
void djui_text_set_drop_shadow(struct DjuiText* text, f32 r, f32 g, f32 b, f32 a) {
@ -38,9 +44,6 @@ void djui_text_set_alignment(struct DjuiText* text, enum DjuiHAlign hAlign, enum
// rendering //
///////////////
#define DJUI_TEXT_CHAR_HEIGHT 16
#define DJUI_TEXT_CHAR_WIDTH 8
static f32 sTextRenderX = 0;
static f32 sTextRenderY = 0;
static f32 sTextRenderLastX = 0;
@ -51,84 +54,99 @@ static void djui_text_translate(f32 x, f32 y) {
sTextRenderY += y;
}
static void djui_text_render_single_char(struct DjuiText* text, u8 d) {
static void djui_text_render_single_char(struct DjuiText* text, char c) {
struct DjuiBaseRect* comp = &text->base.comp;
f32 dX = comp->x + sTextRenderX * text->fontSize;
f32 dY = comp->y + sTextRenderY * text->fontSize;
f32 dW = DJUI_TEXT_CHAR_WIDTH * text->fontSize;
f32 dH = DJUI_TEXT_CHAR_HEIGHT * text->fontSize;
f32 dX = comp->x + sTextRenderX * text->fontScale;
f32 dY = comp->y + sTextRenderY * text->fontScale;
f32 dW = text->font->charWidth * text->fontScale;
f32 dH = text->font->charHeight * text->fontScale;
if (djui_gfx_add_clipping_specific(&text->base, true, dX, dY, dW, dH)) {
if (djui_gfx_add_clipping_specific(&text->base, text->font->rotatedUV, dX, dY, dW, dH)) {
return;
}
create_dl_translation_matrix(DJUI_MTX_NOPUSH, sTextRenderX - sTextRenderLastX, (sTextRenderY - sTextRenderLastY) * -1.0f, 0);
djui_gfx_render_char(d);
text->font->render_char(c);
sTextRenderLastX = sTextRenderX;
sTextRenderLastY = sTextRenderY;
}
static void djui_text_render_char(struct DjuiText* text, u8 d) {
static void djui_text_render_char(struct DjuiText* text, char c) {
if (text->dropShadow.a > 0) {
// render drop shadow
struct DjuiBase* base = &text->base;
sTextRenderX += 0.5f;
sTextRenderY += 0.5f;
sTextRenderX += 1.0f / text->fontScale;
sTextRenderY += 1.0f / text->fontScale;
gDPSetEnvColor(gDisplayListHead++, text->dropShadow.r, text->dropShadow.g, text->dropShadow.b, text->dropShadow.a);
djui_text_render_single_char(text, d);
djui_text_render_single_char(text, c);
gDPSetEnvColor(gDisplayListHead++, base->color.r, base->color.g, base->color.b, base->color.a);
sTextRenderX -= 0.5f;
sTextRenderY -= 0.5f;
sTextRenderX -= 1.0f / text->fontScale;
sTextRenderY -= 1.0f / text->fontScale;
}
djui_text_render_single_char(text, d);
djui_text_render_single_char(text, c);
}
static f32 djui_text_measure_word_width(char* message) {
static f32 djui_text_measure_word_width(struct DjuiText* text, char* message) {
f32 width = 0;
bool skipping = false;
while (*message != '\0') {
u8 d = str_ascii_char_to_dialog(*message);
if (d == DIALOG_CHAR_SPACE) { return width; }
if (d == DIALOG_CHAR_NEWLINE) { return width; }
if (d == DIALOG_CHAR_TERMINATOR) { return width; }
width += gDialogCharWidths[d];
char c = *message;
if (c == ' ') { return width; }
if (c == '\n') { return width; }
if (c == '\0') { return width; }
if (c == '\\') { skipping = !skipping; }
if (!skipping) {
width += text->font->char_width(c);
}
message++;
}
return width;
}
static void djui_text_read_line(char* message, u16* index, f32* lineWidth, f32 maxLineWidth, bool onLastLine, bool* ellipses) {
static void djui_text_read_line(struct DjuiText* text, u16* index, f32* lineWidth, f32 maxLineWidth, bool onLastLine, bool* ellipses) {
char* message = text->message;
*lineWidth = 0;
u8 lastD = DIALOG_CHAR_TERMINATOR;
char lastC = '\0';
f32 ellipsesWidth = gDialogCharWidths[0x3F] * 3.0f;
u16 lastSafeEllipsesIndex = *index;
u16 lastSafeEllipsesLineWidth = *lineWidth + ellipsesWidth;
bool skipping = false;
while (message[*index] != '\0') {
u8 d = str_ascii_char_to_dialog(message[*index]);
char c = message[*index];
f32 charWidth = text->font->char_width(c);
// check for special escape sequences
if (c == '\\') { skipping = !skipping; }
if (skipping || c == '\\') {
*index = *index + 1;
lastC = c;
continue;
}
// check for newline
if (d == DIALOG_CHAR_NEWLINE) {
if (c == '\n') {
*index = *index + 1;
break;
}
// check to see if this character would exceed size
if (*lineWidth + gDialogCharWidths[d] >= maxLineWidth) {
if (*lineWidth + charWidth >= maxLineWidth) {
break;
}
// check to see if this word exceeds size
if (!onLastLine && lastD == DIALOG_CHAR_SPACE && d != DIALOG_CHAR_SPACE) {
f32 wordWidth = djui_text_measure_word_width(&message[*index]);
if (!onLastLine && lastC == ' ' && c != ' ') {
f32 wordWidth = djui_text_measure_word_width(text, &message[*index]);
if (*lineWidth + wordWidth >= maxLineWidth) {
return;
}
}
*lineWidth += gDialogCharWidths[d];
*lineWidth += charWidth;
// check for safe ellipses index
if (onLastLine && ((*lineWidth + ellipsesWidth) < maxLineWidth)) {
@ -137,7 +155,7 @@ static void djui_text_read_line(char* message, u16* index, f32* lineWidth, f32 m
}
*index = *index + 1;
lastD = d;
lastC = c;
}
// check to see if we should replace the end of the last line with ellipses
@ -148,6 +166,37 @@ static void djui_text_read_line(char* message, u16* index, f32* lineWidth, f32 m
}
}
static int djui_text_render_line_parse_escape(struct DjuiText* text, u16 startIndex, u16 endIndex) {
bool parsingColor = text->message[startIndex + 1] == '#';
u16 i = parsingColor ? (startIndex + 1) : startIndex;
u32 color = 0;
u8 colorPieces = 0;
while (++i < endIndex) {
char c = text->message[i];
if (c == '\\') { break; }
if (parsingColor) {
u8 colorPiece = 0;
if (c >= '0' && c <= '9') { colorPiece = c - '0'; }
else if (c >= 'a' && c <= 'f') { colorPiece = 10 + c - 'a'; }
else if (c >= 'A' && c <= 'F') { colorPiece = 10 + c - 'A'; }
color = (color << 4) | colorPiece;
colorPieces++;
}
}
if (parsingColor) {
if (colorPieces == 6) {
gDPSetEnvColor(gDisplayListHead++, ((color >> 16) & 0xFF), ((color >> 8) & 0xFF), ((color >> 0) & 0xFF), sSavedAlpha);
} else if (colorPieces == 8) {
gDPSetEnvColor(gDisplayListHead++, ((color >> 24) & 0xFF), ((color >> 16) & 0xFF), ((color >> 8) & 0xFF), ((color >> 0) & 0xFF));
sSavedAlpha = ((color << 0) & 0xFF);
}
}
return i;
}
static void djui_text_render_line(struct DjuiText* text, u16 startIndex, u16 endIndex, f32 lineWidth, bool ellipses) {
struct DjuiBase* base = &text->base;
struct DjuiBaseRect* comp = &base->comp;
@ -156,44 +205,47 @@ static void djui_text_render_line(struct DjuiText* text, u16 startIndex, u16 end
// horizontal alignment
if (text->textHAlign == DJUI_HALIGN_CENTER) {
// center text
f32 offset = (comp->width / text->fontSize) / 2.0f - lineWidth / 2.0f;
f32 offset = (comp->width / text->fontScale) / 2.0f - lineWidth / 2.0f;
djui_text_translate(offset, 0);
curWidth = offset;
} else if (text->textHAlign == DJUI_HALIGN_RIGHT) {
// right align text
f32 offset = (comp->width / text->fontSize) - lineWidth;
f32 offset = (comp->width / text->fontScale) - lineWidth;
djui_text_translate(offset, 0);
curWidth = offset;
}
// render the line
bool escapeCode = false;
for (int i = startIndex; i < endIndex; i++) {
u8 d = str_ascii_char_to_dialog(text->message[i]);
switch (d) {
case DIALOG_CHAR_SPACE:
break;
case DIALOG_CHAR_NEWLINE:
break;
default:
djui_text_render_char(text, d);
break;
char c = text->message[i];
if (c == '\\') {
i = djui_text_render_line_parse_escape(text, i, endIndex);
continue;
}
djui_text_translate(gDialogCharWidths[d], 0);
curWidth += gDialogCharWidths[d];
f32 charWidth = text->font->char_width(c);
if (c != '\n' && c != ' ') {
djui_text_render_char(text, c);
}
djui_text_translate(charWidth, 0);
curWidth += charWidth;
}
// render ellipses
if (ellipses) {
for (int i = 0; i < 3; i++) {
u8 d = str_ascii_char_to_dialog('.');
djui_text_render_char(text, d);
djui_text_translate(gDialogCharWidths[d], 0);
curWidth += gDialogCharWidths[d];
char c = '.';
f32 charWidth = text->font->char_width(c);
djui_text_render_char(text, c);
djui_text_translate(charWidth, 0);
curWidth += charWidth;
}
}
// reset translation matrix
djui_text_translate(-curWidth, DJUI_TEXT_CHAR_HEIGHT);
djui_text_translate(-curWidth, text->font->lineHeight);
}
////////////
@ -201,11 +253,13 @@ static void djui_text_render_line(struct DjuiText* text, u16 startIndex, u16 end
////////////
static void djui_text_render(struct DjuiBase* base) {
gSPDisplayList(gDisplayListHead++, dl_djui_ia_text_begin);
struct DjuiText* text = (struct DjuiText*)base;
struct DjuiBaseRect* comp = &base->comp;
if (text->font->textBeginDisplayList != NULL) {
gSPDisplayList(gDisplayListHead++, text->font->textBeginDisplayList);
}
// reset render location
sTextRenderX = 0;
sTextRenderY = 0;
@ -224,24 +278,25 @@ static void djui_text_render(struct DjuiBase* base) {
djui_gfx_scale_translate(&translatedWidth, &translatedHeight);
// compute font size
f32 translatedFontSize = text->fontSize;
f32 translatedFontSize = text->fontScale;
djui_gfx_size_translate(&translatedFontSize);
create_dl_scale_matrix(DJUI_MTX_NOPUSH, translatedFontSize, translatedFontSize, 1.0f);
// set color
gDPSetEnvColor(gDisplayListHead++, base->color.r, base->color.g, base->color.b, base->color.a);
sSavedAlpha = base->color.a;
// count lines
u16 startIndex = 0;
u16 endIndex = 0;
f32 maxLineWidth = comp->width / text->fontSize;
f32 maxLineWidth = comp->width / text->fontScale;
u16 lineCount = 0;
u16 maxLines = comp->height / ((f32)DJUI_TEXT_CHAR_HEIGHT * text->fontSize);
u16 maxLines = comp->height / ((f32)text->font->charHeight * text->fontScale);
while (text->message[startIndex] != '\0') {
bool onLastLine = lineCount + 1 >= maxLines;
f32 lineWidth;
bool ellipses;
djui_text_read_line(text->message, &endIndex, &lineWidth, maxLineWidth, onLastLine, &ellipses);
djui_text_read_line(text, &endIndex, &lineWidth, maxLineWidth, onLastLine, &ellipses);
startIndex = endIndex;
lineCount++;
if (onLastLine) { break; }
@ -250,11 +305,11 @@ static void djui_text_render(struct DjuiBase* base) {
// do vertical alignment
f32 vOffset = 0;
if (text->textVAlign == DJUI_VALIGN_CENTER) {
vOffset += (comp->height / text->fontSize) / 2.0f;
vOffset -= (lineCount * DJUI_TEXT_CHAR_HEIGHT) / 2.0f;
vOffset += (comp->height / text->fontScale) / 2.0f;
vOffset -= (lineCount * text->font->charHeight) / 2.0f;
} else if (text->textVAlign == DJUI_VALIGN_BOTTOM) {
vOffset += (comp->height / text->fontSize);
vOffset -= (lineCount * DJUI_TEXT_CHAR_HEIGHT);
vOffset += (comp->height / text->fontScale);
vOffset -= (lineCount * text->font->charHeight);
}
djui_text_translate(0, vOffset);
@ -266,7 +321,7 @@ static void djui_text_render(struct DjuiBase* base) {
bool ellipses = false;
while (text->message[startIndex] != '\0') {
bool onLastLine = lineIndex + 1 >= maxLines;
djui_text_read_line(text->message, &endIndex, &lineWidth, maxLineWidth, onLastLine, &ellipses);
djui_text_read_line(text, &endIndex, &lineWidth, maxLineWidth, onLastLine, &ellipses);
djui_text_render_line(text, startIndex, endIndex, lineWidth, ellipses);
startIndex = endIndex;
lineIndex++;
@ -290,8 +345,9 @@ struct DjuiText* djui_text_create(struct DjuiBase* parent, const char* message)
djui_base_init(parent, base, djui_text_render, djui_text_destroy);
text->message = NULL;
djui_text_set_font(text, &gDjuiFonts[0]);
djui_text_set_font_scale(text, text->font->defaultFontScale);
djui_text_set_text(text, message);
djui_text_set_font_size(text, 2.0f);
djui_text_set_alignment(text, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
return text;

View file

@ -5,14 +5,16 @@
struct DjuiText {
struct DjuiBase base;
char* message;
f32 fontSize;
struct DjuiFont* font;
f32 fontScale;
struct DjuiColor dropShadow;
enum DjuiHAlign textHAlign;
enum DjuiVAlign textVAlign;
};
void djui_text_set_text(struct DjuiText* text, const char* message);
void djui_text_set_font_size(struct DjuiText* text, f32 fontSize);
void djui_text_set_font(struct DjuiText* text, struct DjuiFont* font);
void djui_text_set_font_scale(struct DjuiText* text, f32 fontScale);
void djui_text_set_drop_shadow(struct DjuiText* text, f32 r, f32 g, f32 b, f32 a);
void djui_text_set_alignment(struct DjuiText* text, enum DjuiHAlign hAlign, enum DjuiVAlign vAlign);

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 973 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 992 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 722 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 690 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 847 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 835 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 757 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Some files were not shown because too many files have changed in this diff Show more