DJUI: Created main menu panel

Added ability to make a DjuiBase keep its aspect ration
Added on_render_pre callback
Added ability to display 32b images
Added DjuiFlowLayout
Added logo
This commit is contained in:
MysterD 2021-06-20 23:34:14 -07:00
parent 5e6eb8e833
commit c0b093b11f
20 changed files with 331 additions and 121 deletions

View file

@ -3944,6 +3944,7 @@
<ClCompile Include="..\src\pc\djui\djui.c" />
<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_gfx.c" />
<ClCompile Include="..\src\pc\djui\djui_image.c" />
<ClCompile Include="..\src\pc\djui\djui_interactable.c" />
@ -4364,6 +4365,7 @@
<ClInclude Include="..\src\pc\djui\djui.h" />
<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_gbi.h" />
<ClInclude Include="..\src\pc\djui\djui_gfx.h" />
<ClInclude Include="..\src\pc\djui\djui_image.h" />

View file

@ -3448,9 +3448,15 @@
<Filter Include="Source Files\src\pc\djui">
<UniqueIdentifier>{0e1e4798-796e-4801-be6e-69d0c3b05ad7}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\src\pc\djui\components">
<Filter Include="Source Files\src\pc\djui\panel">
<UniqueIdentifier>{2401a619-ee3f-4637-9926-a619a5e65bcb}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\src\pc\djui\component">
<UniqueIdentifier>{471ac819-ed6b-4a33-8952-50a8e0d2d839}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\src\pc\djui\component\compound">
<UniqueIdentifier>{a7515004-4574-4bc0-9288-f716100c8a43}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\actors\amp\anims\anim_0800401C.inc.c">
@ -15154,22 +15160,19 @@
<Filter>Source Files\src\pc\djui</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_image.c">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_rect.c">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_text.c">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_base.c">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_root.c">
<Filter>Source Files\src\pc\djui\components</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_button.c">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\controller\controller_sdl1.c">
<Filter>Source Files\src\pc\controller</Filter>
@ -15178,7 +15181,13 @@
<Filter>Source Files\src\pc\controller</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_interactable.c">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_flow_layout.c">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_button.c">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@ -16166,25 +16175,28 @@
<Filter>Source Files\src\pc\djui</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_image.h">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_rect.h">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_text.h">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_base.h">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_root.h">
<Filter>Source Files\src\pc\djui\components</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_button.h">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_interactable.h">
<Filter>Source Files\src\pc\djui\components</Filter>
<Filter>Source Files\src\pc\djui\component</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_flow_layout.h">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_button.h">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -12,48 +12,51 @@ ALIGNED8 static const u8 texture16x16[] = {
#include "textures/segment2/custom_luigi_head.rgba16.inc.c"
};
ALIGNED8 u8 texture_hand_open[] = {
ALIGNED8 static u8 texture_hand_open[] = {
#include "textures/intro_raw/hand_open.rgba16.inc.c"
};
ALIGNED8 u8 texture_hand_closed[] = {
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;
static struct DjuiImage* sMouseCursor = NULL;
// v REMOVE ME v
static struct DjuiRect* sDjuiRect = NULL;
static struct DjuiRect* sDjuiRect2 = NULL;
static struct DjuiText* sDjuiText = NULL;
static struct DjuiImage* sDjuiImage = NULL;
// ^ REMOVE ME ^
struct DjuiFlowLayout* buttonContainer;
static void djui_init(void) {
gDjuiRoot = djui_root_create();
sMouseCursor = djui_image_create(NULL, texture_hand_open, 32, 32);
sMouseCursor = djui_image_create(NULL, texture_hand_open, 32, 32, 16);
djui_base_set_location(&sMouseCursor->base, 0, 0);
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);
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);
@ -71,33 +74,17 @@ static void djui_init(void) {
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);
struct DjuiRect* buttonContainer = djui_rect_create(&gDjuiRoot->base);
djui_base_set_alignment(&buttonContainer->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_BOTTOM);
djui_base_set_location(&buttonContainer->base, 64, 64);
djui_base_set_size(&buttonContainer->base, 200 + 16, (64 + 16) * 2.0f + 16);
djui_base_set_color(&buttonContainer->base, 0, 0, 0, 64);
djui_base_set_padding(&buttonContainer->base, 16, 16, 16, 16);
struct DjuiButton* button1 = djui_button_create(&buttonContainer->base, "one");
djui_base_set_location(&button1->base, 0, 0);
djui_base_set_size_type(&button1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button1->base, 1.0f, 64);
struct DjuiButton* button2 = djui_button_create(&buttonContainer->base, "two");
djui_base_set_location(&button2->base, 0, 64 + 16);
djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button2->base, 1.0f, 64);
}
static void djui_debug_update(void) {
}*/
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,
/*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,
@ -105,7 +92,7 @@ static void djui_debug_update(void) {
djui_base_set_location(&sDjuiRect2->base,
32.0f + cos((sTimer) / 10.0f) * 64.0f,
32.0f + sin((sTimer) / 31.0f) * 64.0f);
32.0f + sin((sTimer) / 31.0f) * 64.0f);*/
}
static void djui_mouse_update(void) {
@ -118,9 +105,9 @@ static void djui_mouse_update(void) {
djui_base_set_location(&sMouseCursor->base, mouse_window_x - 13, mouse_window_y - 13);
if (mouse_window_buttons & 0b0001) {
djui_image_set_image(sMouseCursor, texture_hand_closed, 32, 32);
djui_image_set_image(sMouseCursor, texture_hand_closed, 32, 32, 16);
} else {
djui_image_set_image(sMouseCursor, texture_hand_open, 32, 32);
djui_image_set_image(sMouseCursor, texture_hand_open, 32, 32, 16);
}
#endif
}

View file

@ -4,6 +4,8 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "game/game_init.h"
#include "game/ingame_menu.h"
#include "djui_types.h"
#include "djui_gfx.h"
@ -16,9 +18,9 @@
#include "djui_image.h"
#include "djui_button.h"
#include "djui_flow_layout.h"
#include "game/game_init.h"
#include "game/ingame_menu.h"
#include "djui_panel_main.h"
extern struct DjuiRoot* gDjuiRoot;

View file

@ -1,7 +1,7 @@
#include <string.h>
#include "djui.h"
////////////////
////////////////
// properties //
////////////////
@ -121,6 +121,9 @@ void djui_base_compute(struct DjuiBase* base) {
f32 width = (base->width.type == DJUI_SVT_RELATIVE) ? parent->comp.width * base->width.value : base->width.value;
f32 height = (base->height.type == DJUI_SVT_RELATIVE) ? parent->comp.height * base->height.value : base->height.value;
width = (base->width.type == DJUI_SVT_ASPECT_RATIO) ? height * base->width.value : width;
height = (base->height.type == DJUI_SVT_ASPECT_RATIO) ? width * base->height.value : height;
// horizontal alignment
if (base->hAlign == DJUI_HALIGN_CENTER) {
x += (parent->comp.width - width) / 2.0f;
@ -252,6 +255,10 @@ static void djui_base_render_border(struct DjuiBase* base) {
void djui_base_render(struct DjuiBase* base) {
if (!base->visible) { return; }
if (base->on_render_pre != NULL) {
base->on_render_pre(base);
}
struct DjuiBaseRect* comp = &base->comp;
struct DjuiBaseRect* clip = &base->clip;
@ -277,6 +284,11 @@ void djui_base_render(struct DjuiBase* base) {
struct DjuiBaseChild* child = base->child;
while (child != NULL) {
djui_base_render(child->base);
if (base->on_child_render != NULL) {
base->on_child_render(base, child->base);
}
child = child->next;
}
}

View file

@ -41,6 +41,8 @@ struct DjuiBase {
struct DjuiBaseRect comp;
struct DjuiBaseRect clip;
struct DjuiInteractable* interactable;
void (*on_child_render)(struct DjuiBase*, struct DjuiBase*);
void (*on_render_pre)(struct DjuiBase*);
void (*render)(struct DjuiBase*);
void (*destroy)(struct DjuiBase*);
};

View file

@ -0,0 +1,61 @@
#include "djui.h"
#include <stdio.h>
////////////////
// properties //
////////////////
void djui_flow_layout_set_flow_direction(struct DjuiFlowLayout* layout, enum DjuiFlowDirection flowDirection) {
layout->flowDirection = flowDirection;
}
void djui_flow_layout_set_margin(struct DjuiFlowLayout* layout, f32 margin) {
layout->margin.value = margin;
}
void djui_flow_layout_set_margin_type(struct DjuiFlowLayout* layout, enum DjuiScreenValueType marginType) {
layout->margin.type = marginType;
}
////////////
// events //
////////////
static void djui_flow_layout_on_child_render(struct DjuiBase* base, struct DjuiBase* child) {
struct DjuiFlowLayout* layout = (struct DjuiFlowLayout*)base;
switch (layout->flowDirection) {
case DJUI_FLOW_DIR_DOWN:
base->comp.y += (child->comp.height + layout->margin.value);
base->comp.height -= (child->comp.height + layout->margin.value);
break;
case DJUI_FLOW_DIR_UP:
base->comp.height -= (child->comp.height + layout->margin.value);
break;
case DJUI_FLOW_DIR_RIGHT:
base->comp.x += (child->comp.width + layout->margin.value);
base->comp.width -= (child->comp.width + layout->margin.value);
break;
case DJUI_FLOW_DIR_LEFT:
base->comp.width -= (child->comp.width + layout->margin.value);
break;
}
}
static void djui_flow_layout_destroy(struct DjuiBase* base) {
struct DjuiFlowLayout* layout = (struct DjuiFlowLayout*)base;
free(layout);
}
struct DjuiFlowLayout* djui_flow_layout_create(struct DjuiBase* parent) {
struct DjuiFlowLayout* layout = malloc(sizeof(struct DjuiFlowLayout));
struct DjuiBase* base = &layout->base;
djui_base_init(parent, base, djui_rect_render, djui_flow_layout_destroy);
djui_base_set_size(base, 256, 512);
djui_flow_layout_set_flow_direction(layout, DJUI_FLOW_DIR_DOWN);
djui_flow_layout_set_margin(layout, 8);
layout->base.on_child_render = djui_flow_layout_on_child_render;
return layout;
}

View file

@ -0,0 +1,15 @@
#pragma once
#include "djui.h"
#pragma pack(1)
struct DjuiFlowLayout {
struct DjuiBase base;
enum DjuiFlowDirection flowDirection;
struct DjuiScreenValue margin;
};
void djui_flow_layout_set_flow_direction(struct DjuiFlowLayout* layout, enum DjuiFlowDirection flowDirection);
void djui_flow_layout_set_margin(struct DjuiFlowLayout* layout, f32 margin);
void djui_flow_layout_set_margin_type(struct DjuiFlowLayout* layout, enum DjuiScreenValueType marginType);
struct DjuiFlowLayout* djui_flow_layout_create(struct DjuiBase* parent);

View file

@ -12,11 +12,11 @@
_g->words.w1 = _SHIFTL(x2, 16, 8) | _SHIFTL(y2, 8, 8); \
}
#define gSetOverrideDjui(pkt, cmd, texture, w, h) \
#define gSetOverrideDjui(pkt, cmd, texture, w, h, bitSize) \
{ \
Gfx *_g = (Gfx *)(pkt); \
_g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(w, 16, 8) | \
_SHIFTL(h, 8, 8); \
_SHIFTL(h, 8, 8) | _SHIFTL(bitSize, 0, 8); \
_g->words.w1 = (uintptr_t)(texture); \
}
@ -26,4 +26,4 @@
}}
#define gDPSetTextureClippingDjui(pkt, rot, x1, y1, x2, y2) gSetClippingDjui(pkt, G_TEXCLIP_DJUI, rot, x1, y1, x2, y2)
#define gDPSetTextureOverrideDjui(pkt, texture, w, h) gSetOverrideDjui(pkt, G_TEXOVERRIDE_DJUI, texture, w, h)
#define gDPSetTextureOverrideDjui(pkt, texture, w, h, bitSize) gSetOverrideDjui(pkt, G_TEXOVERRIDE_DJUI, texture, w, h, bitSize)

View file

@ -94,8 +94,24 @@ const Gfx dl_djui_image[] = {
gsSPEndDisplayList(),
};
void djui_gfx_render_texture(const u8* texture, u16 w, u16 h) {
gDPSetTextureOverrideDjui(gDisplayListHead++, texture, w, h);
static u8 djui_gfx_power_of_two(u32 value) {
switch (value) {
case 2: return 1;
case 4: return 2;
case 8: return 3;
case 16: return 4;
case 32: return 5;
case 64: return 6;
case 128: return 7;
case 256: return 8;
case 512: return 9;
case 1024: return 10;
default: return 11;
}
}
void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize) {
gDPSetTextureOverrideDjui(gDisplayListHead++, texture, djui_gfx_power_of_two(w), djui_gfx_power_of_two(h), bitSize);
gSPDisplayList(gDisplayListHead++, dl_djui_image);
}

View file

@ -11,7 +11,7 @@ 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, u16 w, u16 h);
void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize);
void djui_gfx_position_translate(f32* x, f32* y);
void djui_gfx_scale_translate(f32* width, f32* height);

View file

@ -6,10 +6,11 @@
// properties //
////////////////
void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textureWidth, u16 textureHeight) {
void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) {
image->texture = texture;
image->textureWidth = textureWidth;
image->textureHeight = textureHeight;
image->textureBitSize = textureBitSize;
}
////////////
@ -36,7 +37,7 @@ static void djui_image_render(struct DjuiBase* base) {
// render
if (!djui_gfx_add_clipping(base)) {
gDPSetEnvColor(gDisplayListHead++, base->color.r, base->color.g, base->color.b, base->color.a);
djui_gfx_render_texture(image->texture, image->textureWidth, image->textureHeight);
djui_gfx_render_texture(image->texture, image->textureWidth, image->textureHeight, image->textureBitSize);
}
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
@ -47,13 +48,13 @@ static void djui_image_destroy(struct DjuiBase* base) {
free(image);
}
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight) {
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize) {
struct DjuiImage* image = malloc(sizeof(struct DjuiImage));
struct DjuiBase* base = &image->base;
djui_base_init(parent, base, djui_image_render, djui_image_destroy);
djui_image_set_image(image, texture, textureWidth, textureHeight);
djui_image_set_image(image, texture, textureWidth, textureHeight, textureBitSize);
return image;
}

View file

@ -7,8 +7,9 @@ struct DjuiImage {
const u8* texture;
u16 textureWidth;
u16 textureHeight;
u16 textureBitSize;
};
void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textureWidth, u16 textureHeight);
void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize);
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight);
struct DjuiImage* djui_image_create(struct DjuiBase* parent, const u8* texture, u16 textureWidth, u16 textureHeight, u16 textureBitSize);

View file

@ -0,0 +1,70 @@
#include "djui.h"
ALIGNED8 static u8 texture_title[] = {
#include "textures/segment2/custom_title.rgba32.inc.c"
};
struct DjuiRect* sTitleContainer = NULL;
struct DjuiFlowLayout* sButtonContainer = NULL;
struct DjuiText* sVersionText = NULL;
static void djui_panel_main_render_pre(struct DjuiBase* base) {
sTitleContainer->base.height.value = sButtonContainer->base.clip.y - sTitleContainer->base.clip.y;
sVersionText->base.height.value = sTitleContainer->base.height.value;
}
void djui_panel_main_create(void) {
struct DjuiRect* menuContainer = djui_rect_create(&gDjuiRoot->base);
djui_base_set_size_type(&menuContainer->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE);
djui_base_set_size(&menuContainer->base, 512.0f + (16 * 2.0f), 1.0f);
djui_base_set_color(&menuContainer->base, 0, 0, 0, 230);
djui_base_set_border_color(&menuContainer->base, 0, 0, 0, 200);
djui_base_set_border_width(&menuContainer->base, 8);
djui_base_set_padding(&menuContainer->base, 16, 16, 16, 16);
{
sButtonContainer = djui_flow_layout_create(&menuContainer->base);
djui_base_set_alignment(&sButtonContainer->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_base_set_size_type(&sButtonContainer->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&sButtonContainer->base, 1.0f, 292);
djui_base_set_color(&sButtonContainer->base, 0, 0, 0, 0);
djui_flow_layout_set_margin(sButtonContainer, 16);
djui_flow_layout_set_flow_direction(sButtonContainer, DJUI_FLOW_DIR_DOWN);
{
struct DjuiButton* button1 = djui_button_create(&sButtonContainer->base, "Host");
djui_base_set_size_type(&button1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button1->base, 1.0f, 64);
struct DjuiButton* button2 = djui_button_create(&sButtonContainer->base, "Join");
djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button2->base, 1.0f, 64);
struct DjuiButton* button3 = djui_button_create(&sButtonContainer->base, "Options");
djui_base_set_size_type(&button3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button3->base, 1.0f, 64);
struct DjuiButton* button4 = djui_button_create(&sButtonContainer->base, "Quit");
djui_base_set_size_type(&button4->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button4->base, 1.0f, 64);
}
sTitleContainer = djui_rect_create(&menuContainer->base);
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);
}
sVersionText = djui_text_create(&menuContainer->base, "version - unst 5");
djui_base_set_alignment(&sVersionText->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_BOTTOM);
djui_base_set_size_type(&sVersionText->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&sVersionText->base, 1.0f, 1.0f);
djui_base_set_color(&sVersionText->base, 50, 50, 50, 255);
djui_text_set_alignment(sVersionText, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
}
}

View file

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

View file

@ -4,7 +4,7 @@
// events //
////////////
static void djui_rect_render(struct DjuiBase* base) {
void djui_rect_render(struct DjuiBase* base) {
struct DjuiBaseRect* clip = &base->clip;
// translate position

View file

@ -6,4 +6,5 @@ struct DjuiRect {
struct DjuiBase base;
};
void djui_rect_render(struct DjuiBase* base);
struct DjuiRect* djui_rect_create(struct DjuiBase* parent);

View file

@ -9,7 +9,8 @@ struct DjuiColor {
u8 a;
};
enum DjuiScreenValueType { DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE };
enum DjuiScreenValueType { DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE, DJUI_SVT_ASPECT_RATIO };
enum DjuiFlowDirection { DJUI_FLOW_DIR_DOWN, DJUI_FLOW_DIR_UP, DJUI_FLOW_DIR_RIGHT, DJUI_FLOW_DIR_LEFT };
#pragma pack(1)
struct DjuiScreenValue {

View file

@ -1862,17 +1862,9 @@ static uint8_t sDjuiClipY2 = 0;
static bool sDjuiOverride = false;
static void* sDjuiOverrideTexture = NULL;
static uint8_t sDjuiOverrideW = 0;
static uint8_t sDjuiOverrideH = 0;
static void djui_gfx_dp_set_clipping(bool rotatedUV, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2) {
sDjuiClipRotatedUV = rotatedUV;
sDjuiClipX1 = x1;
sDjuiClipY1 = y1;
sDjuiClipX2 = x2;
sDjuiClipY2 = y2;
sDjuiClip = true;
}
static uint32_t sDjuiOverrideW = 0;
static uint32_t sDjuiOverrideH = 0;
static uint32_t sDjuiOverrideB = 0;
static void djui_gfx_dp_execute_clipping(void) {
if (!sDjuiClip) { return; }
@ -1949,23 +1941,37 @@ static void djui_gfx_dp_execute_clipping(void) {
}
}
static void djui_gfx_dp_set_override(void* texture, uint8_t w, uint8_t h) {
sDjuiOverrideTexture = texture;
sDjuiOverrideW = w;
sDjuiOverrideH = h;
sDjuiOverride = (texture != NULL);
}
static void djui_gfx_dp_execute_override(void) {
if (!sDjuiOverride) { return; }
sDjuiOverride = false;
// gsDPSetTextureImage
uint8_t sizeLoadBlock = (sDjuiOverrideB == 32) ? 3 : 2;
rdp.texture_to_load.addr = sDjuiOverrideTexture;
rdp.texture_to_load.siz = sizeLoadBlock;
// gsDPSetTile
rdp.texture_tile.siz = sizeLoadBlock;
// gsDPLoadBlock
uint32_t wordSizeShift = (sDjuiOverrideB == 32) ? 2 : 1;
uint32_t lrs = (sDjuiOverrideW * sDjuiOverrideH) - 1;
uint32_t sizeBytes = (lrs + 1) << wordSizeShift;
rdp.loaded_texture[rdp.texture_to_load.tile_number].size_bytes = sizeBytes;
rdp.loaded_texture[rdp.texture_to_load.tile_number].addr = rdp.texture_to_load.addr;
rdp.textures_changed[rdp.texture_to_load.tile_number] = true;
// gsDPSetTile
uint32_t line = (((sDjuiOverrideW * 2) + 7) >> 3);
rdp.texture_tile.line_size_bytes = line * 8;
uint32_t lrs = (sDjuiOverrideW * sDjuiOverrideH) - 1;
rdp.loaded_texture[rdp.texture_to_load.tile_number].size_bytes = (lrs + 1) << 1;
// gsDPSetTileSize
/*rdp.texture_tile.uls = 0;
rdp.texture_tile.ult = 0;
rdp.texture_tile.lrs = (sDjuiOverrideW - 1) << G_TEXTURE_IMAGE_FRAC;
rdp.texture_tile.lrt = (sDjuiOverrideH - 1) << G_TEXTURE_IMAGE_FRAC;*/
rdp.textures_changed[0] = true;
rdp.textures_changed[1] = true;
}
static void djui_gfx_dp_execute_djui(uint32_t opcode) {
@ -1975,6 +1981,23 @@ static void djui_gfx_dp_execute_djui(uint32_t opcode) {
}
}
static void djui_gfx_dp_set_clipping(bool rotatedUV, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2) {
sDjuiClipRotatedUV = rotatedUV;
sDjuiClipX1 = x1;
sDjuiClipY1 = y1;
sDjuiClipX2 = x2;
sDjuiClipY2 = y2;
sDjuiClip = true;
}
static void djui_gfx_dp_set_override(void* texture, uint32_t w, uint32_t h, uint32_t b) {
sDjuiOverrideTexture = texture;
sDjuiOverrideW = w;
sDjuiOverrideH = h;
sDjuiOverrideB = b;
sDjuiOverride = (texture != NULL);
}
void djui_gfx_run_dl(Gfx* cmd) {
uint32_t opcode = cmd->words.w0 >> 24;
switch (opcode) {
@ -1982,7 +2005,7 @@ void djui_gfx_run_dl(Gfx* cmd) {
djui_gfx_dp_set_clipping(C0(0, 8), C0(16, 8), C0(8, 8), C1(16, 8), C1(8, 8));
break;
case G_TEXOVERRIDE_DJUI:
djui_gfx_dp_set_override(seg_addr(cmd->words.w1), C0(16, 8), C0(8, 8));
djui_gfx_dp_set_override(seg_addr(cmd->words.w1), 1 << C0(16, 8), 1 << C0(8, 8), C0(0, 8));
break;
case G_EXECUTE_DJUI:
djui_gfx_dp_execute_djui(cmd->words.w1);

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB