Move zarch_zui_push_quad and zarch_zui_snow to menu_display
This commit is contained in:
parent
1d1b868103
commit
c761b14eb4
|
@ -55,7 +55,6 @@
|
|||
|
||||
#define ZUI_FG_NORMAL (~0)
|
||||
#define ZUI_ITEM_SIZE_PX 54
|
||||
#define NPARTICLES 100
|
||||
|
||||
enum zarch_zui_input_state
|
||||
{
|
||||
|
@ -168,13 +167,6 @@ struct zui_tabbed
|
|||
bool inited;
|
||||
};
|
||||
|
||||
struct zui_part
|
||||
{
|
||||
float x, y;
|
||||
float xspeed, yspeed;
|
||||
float alpha;
|
||||
bool alive;
|
||||
};
|
||||
|
||||
static enum zarch_layout_type zarch_layout;
|
||||
|
||||
|
@ -320,133 +312,6 @@ static void zarch_zui_draw_text(zui_t *zui,
|
|||
video_driver_set_osd_msg(text, ¶ms, zui->fb_buf);
|
||||
}
|
||||
|
||||
static void zarch_zui_push_quad(unsigned width, unsigned height,
|
||||
const float *colors, gfx_coord_array_t *ca, int x1, int y1,
|
||||
int x2, int y2)
|
||||
{
|
||||
menu_display_ctx_coord_draw_t coord_draw;
|
||||
gfx_coords_t coords;
|
||||
float vertex[8];
|
||||
|
||||
vertex[0] = x1 / (float)width;
|
||||
vertex[1] = y1 / (float)height;
|
||||
vertex[2] = x2 / (float)width;
|
||||
vertex[3] = y1 / (float)height;
|
||||
vertex[4] = x1 / (float)width;
|
||||
vertex[5] = y2 / (float)height;
|
||||
vertex[6] = x2 / (float)width;
|
||||
vertex[7] = y2 / (float)height;
|
||||
|
||||
coord_draw.ptr = NULL;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_TEX_COORDS_GET, &coord_draw);
|
||||
|
||||
coords.color = colors;
|
||||
coords.vertex = vertex;
|
||||
coords.tex_coord = coord_draw.ptr;
|
||||
coords.lut_tex_coord = coord_draw.ptr;
|
||||
coords.vertices = 3;
|
||||
|
||||
gfx_coord_array_append(ca, &coords, 3);
|
||||
|
||||
coords.color += 4;
|
||||
coords.vertex += 2;
|
||||
coords.tex_coord += 2;
|
||||
coords.lut_tex_coord += 2;
|
||||
|
||||
gfx_coord_array_append(ca, &coords, 3);
|
||||
}
|
||||
|
||||
static float zarch_zui_randf(float min, float max)
|
||||
{
|
||||
return (rand() * ((max - min) / RAND_MAX)) + min;
|
||||
}
|
||||
|
||||
static float zarch_zui_scalef(float val,
|
||||
float oldmin, float oldmax, float newmin, float newmax)
|
||||
{
|
||||
return (((val - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
|
||||
}
|
||||
|
||||
static void zarch_zui_snow(zui_t *zui, gfx_coord_array_t *ca,
|
||||
int width, int height)
|
||||
{
|
||||
static struct zui_part particles[NPARTICLES];
|
||||
static bool initialized = false;
|
||||
static int timeout = 0;
|
||||
unsigned i, max_gen = 2;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
memset(particles, 0, sizeof(particles));
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
for (i = 0; i < NPARTICLES; ++i)
|
||||
{
|
||||
struct zui_part *p = (struct zui_part*)&particles[i];
|
||||
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
if (p->alive)
|
||||
{
|
||||
int16_t mouse_x = zarch_zui_input_state(zui, MENU_ZARCH_MOUSE_X);
|
||||
|
||||
p->y += p->yspeed;
|
||||
p->x += zarch_zui_scalef(mouse_x, 0, width, -0.3, 0.3);
|
||||
p->x += p->xspeed;
|
||||
|
||||
p->alive = p->y >= 0 && p->y < height
|
||||
&& p->x >= 0 && p->x < width;
|
||||
}
|
||||
else if (max_gen > 0 && timeout <= 0)
|
||||
{
|
||||
p->xspeed = zarch_zui_randf(-0.2, 0.2);
|
||||
p->yspeed = zarch_zui_randf(1, 2);
|
||||
p->y = 0;
|
||||
p->x = rand() % width;
|
||||
p->alpha = (float)rand() / (float)RAND_MAX;
|
||||
p->alive = true;
|
||||
|
||||
max_gen--;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_gen == 0)
|
||||
timeout = 3;
|
||||
else
|
||||
timeout--;
|
||||
|
||||
for (i = 0; i < NPARTICLES; ++i)
|
||||
{
|
||||
unsigned j;
|
||||
float alpha;
|
||||
float colors[16];
|
||||
struct zui_part *p = &particles[i];
|
||||
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
if (!p->alive)
|
||||
continue;
|
||||
|
||||
alpha = zarch_zui_randf(0, 100) > 90 ? p->alpha/2 : p->alpha;
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
colors[j] = 1;
|
||||
if (j == 3 || j == 7 || j == 11 || j == 15)
|
||||
colors[j] = alpha;
|
||||
}
|
||||
|
||||
zarch_zui_push_quad(width, height,
|
||||
colors, ca, p->x-2, p->y-2, p->x+2, p->y+2);
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
static bool zarch_zui_button_full(zui_t *zui,
|
||||
int x1, int y1, int x2, int y2, const char *label)
|
||||
{
|
||||
|
@ -457,7 +322,7 @@ static bool zarch_zui_button_full(zui_t *zui,
|
|||
if (zui->item.active == id || zui->item.hot == id)
|
||||
bg = zui_bg_hilite;
|
||||
|
||||
zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2);
|
||||
menu_display_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2);
|
||||
zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x1+12, y1 + 41, label);
|
||||
|
||||
return active;
|
||||
|
@ -513,7 +378,7 @@ static bool zarch_zui_list_item(zui_t *zui, struct zui_tabbed *tab, int x1, int
|
|||
|
||||
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
|
||||
|
||||
zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2);
|
||||
menu_display_push_quad(zui->width, zui->height, bg, &zui->ca, x1, y1, x2, y2);
|
||||
zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 12, y1 + 35, title_buf);
|
||||
|
||||
if (entry)
|
||||
|
@ -572,7 +437,7 @@ static bool zarch_zui_tab(zui_t *zui, struct zui_tabbed *tab,
|
|||
else if (selected)
|
||||
bg = zui_bg_pad_hilite;
|
||||
|
||||
zarch_zui_push_quad(zui->width, zui->height, bg, &zui->ca, x1+0, y1+0, x2, y2);
|
||||
menu_display_push_quad(zui->width, zui->height, bg, &zui->ca, x1+0, y1+0, x2, y2);
|
||||
zarch_zui_draw_text(zui, ZUI_FG_NORMAL, x1+12, y1 + 41, label);
|
||||
|
||||
if (tab->vertical)
|
||||
|
@ -897,7 +762,7 @@ static int zarch_zui_render_lay_root(zui_t *zui)
|
|||
zarch_zui_draw_text(zui, ZUI_FG_NORMAL, 1600 +12, 300 + 111, item);
|
||||
#endif
|
||||
|
||||
zarch_zui_push_quad(zui->width, zui->height,
|
||||
menu_display_push_quad(zui->width, zui->height,
|
||||
zui_bg_hilite, &zui->ca, 0, 60, zui->width - 290 - 40, 60+4);
|
||||
|
||||
return 0;
|
||||
|
@ -1042,9 +907,9 @@ static void zarch_frame(void *data)
|
|||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_BIND_BLOCK, &zui->tmp_block);
|
||||
|
||||
zarch_zui_push_quad(zui->width, zui->height, zui_bg_screen,
|
||||
menu_display_push_quad(zui->width, zui->height, zui_bg_screen,
|
||||
&zui->ca, 0, 0, zui->width, zui->height);
|
||||
zarch_zui_snow(zui, &zui->ca, zui->width, zui->height);
|
||||
menu_display_snow(&zui->ca, zui->width, zui->height);
|
||||
|
||||
switch (zarch_layout)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "../gfx/video_thread_wrapper.h"
|
||||
#endif
|
||||
|
||||
|
||||
uintptr_t menu_display_white_texture;
|
||||
|
||||
static menu_display_ctx_driver_t *menu_display_ctx_drivers[] = {
|
||||
|
@ -590,3 +591,139 @@ void menu_display_allocate_white_texture(void)
|
|||
video_driver_texture_load(&ti,
|
||||
TEXTURE_FILTER_NEAREST, &menu_display_white_texture);
|
||||
}
|
||||
|
||||
static INLINE float menu_display_scalef(float val,
|
||||
float oldmin, float oldmax, float newmin, float newmax)
|
||||
{
|
||||
return (((val - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
|
||||
}
|
||||
|
||||
static INLINE float menu_display_randf(float min, float max)
|
||||
{
|
||||
return (rand() * ((max - min) / RAND_MAX)) + min;
|
||||
}
|
||||
|
||||
|
||||
void menu_display_push_quad(unsigned width, unsigned height,
|
||||
const float *colors, gfx_coord_array_t *ca, int x1, int y1,
|
||||
int x2, int y2)
|
||||
{
|
||||
menu_display_ctx_coord_draw_t coord_draw;
|
||||
gfx_coords_t coords;
|
||||
float vertex[8];
|
||||
|
||||
vertex[0] = x1 / (float)width;
|
||||
vertex[1] = y1 / (float)height;
|
||||
vertex[2] = x2 / (float)width;
|
||||
vertex[3] = y1 / (float)height;
|
||||
vertex[4] = x1 / (float)width;
|
||||
vertex[5] = y2 / (float)height;
|
||||
vertex[6] = x2 / (float)width;
|
||||
vertex[7] = y2 / (float)height;
|
||||
|
||||
coord_draw.ptr = NULL;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_TEX_COORDS_GET, &coord_draw);
|
||||
|
||||
coords.color = colors;
|
||||
coords.vertex = vertex;
|
||||
coords.tex_coord = coord_draw.ptr;
|
||||
coords.lut_tex_coord = coord_draw.ptr;
|
||||
coords.vertices = 3;
|
||||
|
||||
gfx_coord_array_append(ca, &coords, 3);
|
||||
|
||||
coords.color += 4;
|
||||
coords.vertex += 2;
|
||||
coords.tex_coord += 2;
|
||||
coords.lut_tex_coord += 2;
|
||||
|
||||
gfx_coord_array_append(ca, &coords, 3);
|
||||
}
|
||||
|
||||
#define PARTICLES_COUNT 100
|
||||
|
||||
void menu_display_snow(gfx_coord_array_t *ca, int width, int height)
|
||||
{
|
||||
struct display_particle
|
||||
{
|
||||
float x, y;
|
||||
float xspeed, yspeed;
|
||||
float alpha;
|
||||
bool alive;
|
||||
};
|
||||
static struct display_particle particles[PARTICLES_COUNT];
|
||||
static bool initialized = false;
|
||||
static int timeout = 0;
|
||||
unsigned i, max_gen = 2;
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
memset(particles, 0, sizeof(particles));
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
for (i = 0; i < PARTICLES_COUNT; ++i)
|
||||
{
|
||||
struct display_particle *p = (struct display_particle*)&particles[i];
|
||||
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
if (p->alive)
|
||||
{
|
||||
int16_t mouse_x = menu_input_mouse_state(MENU_MOUSE_X_AXIS);
|
||||
|
||||
p->y += p->yspeed;
|
||||
p->x += menu_display_scalef(mouse_x, 0, width, -0.3, 0.3);
|
||||
p->x += p->xspeed;
|
||||
|
||||
p->alive = p->y >= 0 && p->y < height
|
||||
&& p->x >= 0 && p->x < width;
|
||||
}
|
||||
else if (max_gen > 0 && timeout <= 0)
|
||||
{
|
||||
p->xspeed = menu_display_randf(-0.2, 0.2);
|
||||
p->yspeed = menu_display_randf(1, 2);
|
||||
p->y = 0;
|
||||
p->x = rand() % width;
|
||||
p->alpha = (float)rand() / (float)RAND_MAX;
|
||||
p->alive = true;
|
||||
|
||||
max_gen--;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_gen == 0)
|
||||
timeout = 3;
|
||||
else
|
||||
timeout--;
|
||||
|
||||
for (i = 0; i < PARTICLES_COUNT; ++i)
|
||||
{
|
||||
unsigned j;
|
||||
float alpha;
|
||||
float colors[16];
|
||||
struct display_particle *p = &particles[i];
|
||||
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
if (!p->alive)
|
||||
continue;
|
||||
|
||||
alpha = menu_display_randf(0, 100) > 90 ? p->alpha/2 : p->alpha;
|
||||
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
colors[j] = 1;
|
||||
if (j == 3 || j == 7 || j == 11 || j == 15)
|
||||
colors[j] = alpha;
|
||||
}
|
||||
|
||||
menu_display_push_quad(width, height,
|
||||
colors, ca, p->x-2, p->y-2, p->x+2, p->y+2);
|
||||
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,6 +174,12 @@ bool menu_display_ctl(enum menu_display_ctl_state state, void *data);
|
|||
void menu_display_handle_wallpaper_upload(void *task_data,
|
||||
void *user_data, const char *err);
|
||||
|
||||
void menu_display_push_quad(unsigned width, unsigned height,
|
||||
const float *colors, gfx_coord_array_t *ca, int x1, int y1,
|
||||
int x2, int y2);
|
||||
|
||||
void menu_display_snow(gfx_coord_array_t *ca, int width, int height);
|
||||
|
||||
extern uintptr_t menu_display_white_texture;
|
||||
void menu_display_allocate_white_texture();
|
||||
|
||||
|
|
Loading…
Reference in New Issue