mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[client] splash: pre-calculate & cache the radial gradient vectors
This commit is contained in:
parent
1770defea2
commit
1e660fb7e1
@ -24,40 +24,39 @@
|
|||||||
#include "../overlays.h"
|
#include "../overlays.h"
|
||||||
#include "../main.h"
|
#include "../main.h"
|
||||||
#include "overlay_utils.h"
|
#include "overlay_utils.h"
|
||||||
|
#include "common/array.h"
|
||||||
|
|
||||||
#include "resources/lg-logo.svg.h"
|
#include "resources/lg-logo.svg.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
|
#define SEGMENTS 12
|
||||||
|
|
||||||
static bool l_show;
|
static bool l_show;
|
||||||
static bool l_fadeDone;
|
static bool l_fadeDone;
|
||||||
static float l_alpha;
|
static float l_alpha;
|
||||||
static OverlayImage l_logo;
|
static OverlayImage l_logo;
|
||||||
|
static float l_vectors[SEGMENTS][2];
|
||||||
|
|
||||||
static bool splash_init(void ** udata, const void * params)
|
static void calcRadialVectors(float vectors[][2], int segments)
|
||||||
{
|
{
|
||||||
l_show = true;
|
for (unsigned int i = 0; i < segments; ++i)
|
||||||
l_fadeDone = false;
|
{
|
||||||
l_alpha = 1.0f;
|
float angle = (i / (float)(segments - 1)) * M_PI * 2.0f;
|
||||||
|
vectors[i][0] = cos(angle);
|
||||||
overlayLoadSVG(b_lg_logo_svg, b_lg_logo_svg_size, &l_logo, 200, 200);
|
vectors[i][1] = sin(angle);
|
||||||
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void splash_free(void * udata)
|
|
||||||
{
|
|
||||||
overlayFreeImage(&l_logo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawRadialGradient(ImDrawList * list, int x, int y, int w, int h,
|
static void drawRadialGradient(ImDrawList * list, int x, int y, int w, int h,
|
||||||
int steps, ImU32 innerColor, ImU32 outerColor)
|
ImU32 innerColor, ImU32 outerColor,
|
||||||
|
float vectors[0][2], int segments)
|
||||||
{
|
{
|
||||||
const ImVec2 uv = list->_Data->TexUvWhitePixel;
|
const ImVec2 uv = list->_Data->TexUvWhitePixel;
|
||||||
|
|
||||||
ImDrawList_PrimReserve(list, steps * 3, steps + 2);
|
ImDrawList_PrimReserve(list, (segments - 1) * 3, segments + 1);
|
||||||
for(int i = 0; i < steps; ++i)
|
for(int i = 0; i < segments - 1; ++i)
|
||||||
{
|
{
|
||||||
ImDrawList_PrimWriteIdx(list, list->_VtxCurrentIdx);
|
ImDrawList_PrimWriteIdx(list, list->_VtxCurrentIdx);
|
||||||
ImDrawList_PrimWriteIdx(list, list->_VtxCurrentIdx + i + 1);
|
ImDrawList_PrimWriteIdx(list, list->_VtxCurrentIdx + i + 1);
|
||||||
@ -69,17 +68,30 @@ static void drawRadialGradient(ImDrawList * list, int x, int y, int w, int h,
|
|||||||
uv,
|
uv,
|
||||||
innerColor);
|
innerColor);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < steps + 1; ++i)
|
for (unsigned int i = 0; i < segments; ++i)
|
||||||
{
|
|
||||||
float angle = (i / (float)steps) * M_PI * 2.0f;
|
|
||||||
ImDrawList_PrimWriteVtx(list,
|
ImDrawList_PrimWriteVtx(list,
|
||||||
(ImVec2){
|
(ImVec2){
|
||||||
x + cos(angle) * w,
|
x + vectors[i][0] * w,
|
||||||
y + sin(angle) * h
|
y + vectors[i][1] * h
|
||||||
},
|
},
|
||||||
uv,
|
uv,
|
||||||
outerColor);
|
outerColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool splash_init(void ** udata, const void * params)
|
||||||
|
{
|
||||||
|
l_show = true;
|
||||||
|
l_fadeDone = false;
|
||||||
|
l_alpha = 1.0f;
|
||||||
|
|
||||||
|
overlayLoadSVG(b_lg_logo_svg, b_lg_logo_svg_size, &l_logo, 200, 200);
|
||||||
|
calcRadialVectors(l_vectors, ARRAY_LENGTH(l_vectors));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void splash_free(void * udata)
|
||||||
|
{
|
||||||
|
overlayFreeImage(&l_logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int splash_render(void * udata, bool interactive, struct Rect * windowRects,
|
static int splash_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||||
@ -116,9 +128,10 @@ static int splash_render(void * udata, bool interactive, struct Rect * windowRec
|
|||||||
drawRadialGradient(list,
|
drawRadialGradient(list,
|
||||||
screen->x / 2, screen->y / 2,
|
screen->x / 2, screen->y / 2,
|
||||||
screen->x , screen->y ,
|
screen->x , screen->y ,
|
||||||
12,
|
|
||||||
innerColor,
|
innerColor,
|
||||||
outerColor);
|
outerColor,
|
||||||
|
l_vectors,
|
||||||
|
ARRAY_LENGTH(l_vectors));
|
||||||
|
|
||||||
ImDrawList_AddImage(
|
ImDrawList_AddImage(
|
||||||
list,
|
list,
|
||||||
|
Loading…
Reference in New Issue
Block a user