Chat rendering optimizations
This commit is contained in:
parent
951d8e6fe7
commit
68fe7af455
|
@ -295,7 +295,9 @@ bool djui_base_render(struct DjuiBase* base) {
|
|||
if (clip->width < 0 || clip->height <= 0) { return false; }
|
||||
|
||||
if (base->render != NULL) {
|
||||
base->render(base);
|
||||
if (!base->render(base)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
djui_base_add_padding(base);
|
||||
|
@ -371,7 +373,7 @@ void djui_base_destroy(struct DjuiBase* base) {
|
|||
base->destroy(base);
|
||||
}
|
||||
|
||||
void djui_base_init(struct DjuiBase* parent, struct DjuiBase* base, void(*render)(struct DjuiBase*), void (*destroy)(struct DjuiBase*)) {
|
||||
void djui_base_init(struct DjuiBase* parent, struct DjuiBase* base, bool (*render)(struct DjuiBase*), void (*destroy)(struct DjuiBase*)) {
|
||||
memset(base, 0, sizeof(struct DjuiBase));
|
||||
base->parent = parent;
|
||||
djui_base_set_visible(base, true);
|
||||
|
|
|
@ -49,7 +49,7 @@ struct DjuiBase {
|
|||
void (*get_cursor_hover_location)(struct DjuiBase*, f32* x, f32* y);
|
||||
void (*on_child_render)(struct DjuiBase*, struct DjuiBase*);
|
||||
void (*on_render_pre)(struct DjuiBase*, bool*);
|
||||
void (*render)(struct DjuiBase*);
|
||||
bool (*render)(struct DjuiBase*);
|
||||
void (*destroy)(struct DjuiBase*);
|
||||
};
|
||||
|
||||
|
@ -71,4 +71,4 @@ void djui_base_compute(struct DjuiBase* base);
|
|||
|
||||
bool djui_base_render(struct DjuiBase* base);
|
||||
void djui_base_destroy(struct DjuiBase* base);
|
||||
void djui_base_init(struct DjuiBase* parent, struct DjuiBase* base, void (*render)(struct DjuiBase*), void (*destroy)(struct DjuiBase*));
|
||||
void djui_base_init(struct DjuiBase* parent, struct DjuiBase* base, bool (*render)(struct DjuiBase*), void (*destroy)(struct DjuiBase*));
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
struct DjuiChatBox* gDjuiChatBox = NULL;
|
||||
bool gDjuiChatBoxFocus = false;
|
||||
|
||||
void djui_chat_box_render(struct DjuiBase* base) {
|
||||
bool djui_chat_box_render(struct DjuiBase* base) {
|
||||
struct DjuiChatBox* chatBox = (struct DjuiChatBox*)base;
|
||||
struct DjuiBase* ccBase = &chatBox->chatContainer->base;
|
||||
djui_base_set_size(ccBase, 1.0f, chatBox->base.comp.height - 32 - 8);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_chat_box_destroy(struct DjuiBase* base) {
|
||||
|
@ -58,19 +59,19 @@ static bool djui_chat_box_input_on_key_down(struct DjuiBase* base, int scancode)
|
|||
switch (scancode) {
|
||||
case SCANCODE_UP:
|
||||
gDjuiChatBox->scrolling = true;
|
||||
if (canScrollUp) { *yValue = fmax(*yValue - 15, yMax); }
|
||||
if (canScrollDown) { *yValue = fmin(*yValue + 15, 0); }
|
||||
return true;
|
||||
case SCANCODE_DOWN:
|
||||
gDjuiChatBox->scrolling = true;
|
||||
if (canScrollDown) { *yValue = fmin(*yValue + 15, 0); }
|
||||
if (canScrollUp) { *yValue = fmax(*yValue - 15, yMax); }
|
||||
return true;
|
||||
case SCANCODE_PAGE_UP:
|
||||
gDjuiChatBox->scrolling = true;
|
||||
if (canScrollUp) { *yValue = fmax(*yValue - pageAmount, yMax); }
|
||||
if (canScrollDown) { *yValue = fmin(*yValue + pageAmount, 0); }
|
||||
return true;
|
||||
case SCANCODE_PAGE_DOWN:
|
||||
gDjuiChatBox->scrolling = true;
|
||||
if (canScrollDown) { *yValue = fmin(*yValue + pageAmount, 0); }
|
||||
if (canScrollUp) { *yValue = fmax(*yValue - pageAmount, yMax); }
|
||||
return true;
|
||||
case SCANCODE_ENTER: djui_chat_box_input_enter(gDjuiChatBox->chatInput); return true;
|
||||
case SCANCODE_ESCAPE: djui_chat_box_input_escape(gDjuiChatBox->chatInput); return true;
|
||||
|
@ -96,9 +97,9 @@ struct DjuiChatBox* djui_chat_box_create(void) {
|
|||
struct DjuiBase* base = &chatBox->base;
|
||||
|
||||
djui_base_init(&gDjuiRoot->base, base, djui_chat_box_render, djui_chat_box_destroy);
|
||||
djui_base_set_size_type(base, DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE);
|
||||
djui_base_set_size(base, 600, 1.0f);
|
||||
djui_base_set_alignment(base, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
djui_base_set_size_type(base, DJUI_SVT_ABSOLUTE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(base, 600, 400);
|
||||
djui_base_set_alignment(base, DJUI_HALIGN_LEFT, DJUI_VALIGN_BOTTOM);
|
||||
djui_base_set_color(base, 0, 0, 0, 0);
|
||||
djui_base_set_padding(base, 0, 8, 8, 8);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#define DJUI_CHAT_LIFE_TIME 10.0f
|
||||
|
||||
static void djui_chat_message_render(struct DjuiBase* base) {
|
||||
static bool djui_chat_message_render(struct DjuiBase* base) {
|
||||
struct DjuiChatMessage* chatMessage = (struct DjuiChatMessage*)base;
|
||||
struct DjuiBase* ctBase = &chatMessage->message->base;
|
||||
|
||||
|
@ -21,20 +21,21 @@ static void djui_chat_message_render(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
if (gDjuiChatBoxFocus) {
|
||||
djui_base_set_color(base, 0, 0, 0, 64);
|
||||
djui_base_set_color(base, 0, 0, 0, 120);
|
||||
djui_base_set_color(ctBase, 255, 255, 255, 255);
|
||||
djui_text_set_drop_shadow(chatMessage->message, 0, 0, 0, 200);
|
||||
djui_base_set_size_type(base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(base, 1.0f, chatMessage->base.height.value);
|
||||
} else if (f <= 0.1f) {
|
||||
return false;
|
||||
} else {
|
||||
djui_base_set_color(base, 0, 0, 0, 150 * f);
|
||||
djui_base_set_color(base, 0, 0, 0, 180 * f);
|
||||
djui_base_set_color(ctBase, 255, 255, 255, 255 * f);
|
||||
djui_text_set_drop_shadow(chatMessage->message, 0, 0, 0, 200 * f);
|
||||
djui_base_set_size_type(base, DJUI_SVT_ABSOLUTE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(base, chatMessage->messageWidth, chatMessage->base.height.value);
|
||||
}
|
||||
|
||||
djui_rect_render(base);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_chat_message_destroy(struct DjuiBase* base) {
|
||||
|
@ -71,7 +72,6 @@ struct DjuiChatMessage* djui_chat_message_create(char* message) {
|
|||
djui_base_set_color(ctBase, 255, 255, 255, 255);
|
||||
djui_base_set_location(ctBase, 0, 0);
|
||||
djui_text_set_alignment(chatText, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP);
|
||||
djui_text_set_drop_shadow(chatText, 0, 0, 0, 200);
|
||||
chatMessage->message = chatText;
|
||||
chatMessage->createTime = clock_elapsed();
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ void djui_image_set_image(struct DjuiImage* image, const u8* texture, u16 textur
|
|||
// events //
|
||||
////////////
|
||||
|
||||
static void djui_image_render(struct DjuiBase* base) {
|
||||
static bool djui_image_render(struct DjuiBase* base) {
|
||||
struct DjuiImage* image = (struct DjuiImage*)base;
|
||||
struct DjuiBaseRect* comp = &base->comp;
|
||||
struct DjuiBaseRect* clip = &base->clip;
|
||||
|
@ -41,6 +41,7 @@ static void djui_image_render(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_image_destroy(struct DjuiBase* base) {
|
||||
|
|
|
@ -465,7 +465,7 @@ static void djui_inputbox_keep_selection_in_view(struct DjuiInputbox* inputbox)
|
|||
}
|
||||
}
|
||||
|
||||
static void djui_inputbox_render(struct DjuiBase* base) {
|
||||
static bool djui_inputbox_render(struct DjuiBase* base) {
|
||||
struct DjuiInputbox* inputbox = (struct DjuiInputbox*)base;
|
||||
struct DjuiBaseRect* comp = &base->comp;
|
||||
const struct DjuiFont* font = gDjuiFonts[0];
|
||||
|
@ -524,6 +524,7 @@ static void djui_inputbox_render(struct DjuiBase* base) {
|
|||
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
gSPDisplayList(gDisplayListHead++, dl_ia_text_end);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_inputbox_destroy(struct DjuiBase* base) {
|
||||
|
|
|
@ -23,8 +23,9 @@ static void djui_popup_add_to_list(struct DjuiPopup* popup) {
|
|||
sPopupListHead = node;
|
||||
}
|
||||
|
||||
static void djui_popup_render(struct DjuiBase* base) {
|
||||
static bool djui_popup_render(struct DjuiBase* base) {
|
||||
djui_rect_render(base);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_popup_destroy(struct DjuiBase* base) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// events //
|
||||
////////////
|
||||
|
||||
void djui_rect_render(struct DjuiBase* base) {
|
||||
bool djui_rect_render(struct DjuiBase* base) {
|
||||
struct DjuiBaseRect* clip = &base->clip;
|
||||
|
||||
// translate position
|
||||
|
@ -24,6 +24,7 @@ void djui_rect_render(struct DjuiBase* base) {
|
|||
gSPDisplayList(gDisplayListHead++, dl_djui_simple_rect);
|
||||
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_rect_destroy(struct DjuiBase* base) {
|
||||
|
|
|
@ -6,5 +6,5 @@ struct DjuiRect {
|
|||
struct DjuiBase base;
|
||||
};
|
||||
|
||||
void djui_rect_render(struct DjuiBase* base);
|
||||
bool djui_rect_render(struct DjuiBase* base);
|
||||
struct DjuiRect* djui_rect_create(struct DjuiBase* parent);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "src/pc/pc_main.h"
|
||||
#include "src/pc/gfx/gfx_window_manager_api.h"
|
||||
|
||||
static void djui_root_render(struct DjuiBase* base) {
|
||||
static bool djui_root_render(struct DjuiBase* base) {
|
||||
// grab window height
|
||||
u32 windowWidth, windowHeight;
|
||||
wm_api->get_dimensions(&windowWidth, &windowHeight);
|
||||
|
@ -13,6 +13,7 @@ static void djui_root_render(struct DjuiBase* base) {
|
|||
|
||||
// compute base
|
||||
djui_base_compute(base);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_root_destroy(struct DjuiBase* base) {
|
||||
|
|
|
@ -300,7 +300,7 @@ static void djui_text_render_line(struct DjuiText* text, u16 startIndex, u16 end
|
|||
// events //
|
||||
////////////
|
||||
|
||||
static void djui_text_render(struct DjuiBase* base) {
|
||||
static bool djui_text_render(struct DjuiBase* base) {
|
||||
struct DjuiText* text = (struct DjuiText*)base;
|
||||
struct DjuiBaseRect* comp = &base->comp;
|
||||
|
||||
|
@ -370,6 +370,7 @@ static void djui_text_render(struct DjuiBase* base) {
|
|||
|
||||
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
|
||||
gSPDisplayList(gDisplayListHead++, dl_ia_text_end);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_text_destroy(struct DjuiBase* base) {
|
||||
|
|
|
@ -61,7 +61,7 @@ void djui_three_panel_set_min_footer_size(struct DjuiThreePanel* threePanel, f32
|
|||
// events //
|
||||
////////////
|
||||
|
||||
void djui_three_panel_render(struct DjuiBase* base) {
|
||||
bool djui_three_panel_render(struct DjuiBase* base) {
|
||||
struct DjuiThreePanel* threePanel = (struct DjuiThreePanel*)base;
|
||||
|
||||
struct DjuiBase* children[3] = { NULL };
|
||||
|
@ -76,7 +76,7 @@ void djui_three_panel_render(struct DjuiBase* base) {
|
|||
struct DjuiBase* body = children[1];
|
||||
struct DjuiBase* foot = children[2];
|
||||
|
||||
if (body == NULL) { return; }
|
||||
if (body == NULL) { return false; }
|
||||
|
||||
struct DjuiBaseRect* parentComp = &base->comp;
|
||||
f32 tPad = (base->padding.top.type == DJUI_SVT_RELATIVE) ? parentComp->height * base->padding.top.value : base->padding.top.value;
|
||||
|
@ -133,6 +133,7 @@ void djui_three_panel_render(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
djui_rect_render(base);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void djui_three_panel_destroy(struct DjuiBase* base) {
|
||||
|
|
Loading…
Reference in New Issue