Recoloured and added waves
This commit is contained in:
parent
e843cc598f
commit
233d70c22c
@ -10,7 +10,7 @@ endef
|
||||
test : pc_main/main.cpp pc_main/pc_launch.c \
|
||||
common/menu.c common/font.c common/language.c common/launch.c \
|
||||
common/menu-entry.c common/menu-list.c common/text.c \
|
||||
common/nanojpeg.c common/ui.c \
|
||||
common/nanojpeg.c common/ui.c common/math.c \
|
||||
build_pc/tahoma24.o build_pc/tahoma12.o build_pc/switchicon_questionmark.bin.o build_pc/folder_icon.bin.o
|
||||
gcc -Wall -O2 -g0 $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ -I. -Ibuild_pc -o $@
|
||||
|
||||
|
@ -37,6 +37,7 @@ typedef union {
|
||||
#include "launch.h"
|
||||
#include "nro.h"
|
||||
#include "nanojpeg.h"
|
||||
#include "math.h"
|
||||
|
||||
void menuStartup();
|
||||
void menuLoop();
|
||||
@ -80,6 +81,11 @@ static inline void DrawPixelRaw(uint32_t x, uint32_t y, color_t clr)
|
||||
g_framebuf[off] = clr.b; off++;
|
||||
g_framebuf[off] = 0xff;
|
||||
}
|
||||
static inline color_t FetchPixelColor(uint32_t x, uint32_t y)
|
||||
{
|
||||
u32 off = (y * g_framebuf_width + x)*4;
|
||||
return MakeColor(g_framebuf[off], g_framebuf[++off], g_framebuf[++off], 255);
|
||||
}
|
||||
#else
|
||||
extern color_t pixels[720][1280];
|
||||
static inline void DrawPixel(uint32_t x, uint32_t y, color_t clr)
|
||||
@ -100,6 +106,10 @@ static inline void DrawPixelRaw(uint32_t x, uint32_t y, color_t clr)
|
||||
pixels[y][x].b = clr.b;
|
||||
pixels[y][x].a = 0xff;
|
||||
}
|
||||
static inline color_t FetchPixelColor(uint32_t x, uint32_t y)
|
||||
{
|
||||
return pixels[y][x];
|
||||
}
|
||||
#endif
|
||||
|
||||
void DrawPixel(uint32_t x, uint32_t y, color_t clr);
|
||||
|
22
common/math.c
Normal file
22
common/math.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include "math.h"
|
||||
|
||||
// Low precision, adapted from http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/
|
||||
float approxSin(float x) {
|
||||
float ret;
|
||||
|
||||
// always wrap input angle to -PI..PI
|
||||
while (x<-3.14159265 || x>3.14159265) {
|
||||
if (x<-3.14159265)
|
||||
x += 6.28318531;
|
||||
else if (x >3.14159265)
|
||||
x -= 6.28318531;
|
||||
}
|
||||
|
||||
// compute sine
|
||||
if (x<0)
|
||||
ret = 1.27323954 * x + .405284735 * x * x;
|
||||
else
|
||||
ret = 1.27323954 * x - 0.405284735 * x * x;
|
||||
|
||||
return ret;
|
||||
}
|
9
common/math.h
Normal file
9
common/math.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
float approxSin(float x);
|
||||
|
||||
inline float clamp(float x, float min, float max) {
|
||||
return x<min ? min : x>max ? max : x;
|
||||
}
|
@ -28,7 +28,7 @@ static void drawImage(int x, int y, int width, int height, const uint8_t *image)
|
||||
|
||||
static void drawEntry(menuEntry_s* me, int n, int is_active) {
|
||||
int x, y;
|
||||
int start_y = 96 + 304 - 32;//*(n % 2);
|
||||
int start_y = 96 + 108 - 32;//*(n % 2);
|
||||
int end_y = start_y + 288;
|
||||
int start_x = 64 + (256+16)*n;//(n / 2);
|
||||
int end_x = /*1280 - 64*/start_x + 256;
|
||||
@ -44,26 +44,61 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) {
|
||||
}
|
||||
|
||||
//{
|
||||
for (x=(start_x-3); x<(end_x+3); x++) {
|
||||
for (x=(start_x-5); x<(end_x+5); x++) {
|
||||
if (!is_active) {
|
||||
if (x < start_x-3)
|
||||
continue;
|
||||
else if (x >= end_x+3)
|
||||
break;
|
||||
}
|
||||
|
||||
//DrawPixelRaw(x, start_y , border_color0);
|
||||
//DrawPixelRaw(x, end_y , border_color0);
|
||||
DrawPixelRaw(x, end_y , border_color0);
|
||||
DrawPixelRaw(x, start_y-1, border_color0);
|
||||
DrawPixelRaw(x, end_y +1, border_color0);
|
||||
DrawPixelRaw(x, start_y-2, border_color0);
|
||||
DrawPixelRaw(x, end_y +2, border_color0);
|
||||
DrawPixelRaw(x, start_y-3, border_color1);
|
||||
DrawPixelRaw(x, end_y +3, border_color1);
|
||||
|
||||
if (is_active) {
|
||||
DrawPixelRaw(x, start_y-3, border_color0);
|
||||
DrawPixelRaw(x, end_y +3, border_color0);
|
||||
DrawPixelRaw(x, start_y-4, border_color0);
|
||||
DrawPixelRaw(x, end_y +4, border_color0);
|
||||
DrawPixelRaw(x, start_y-5, border_color1);
|
||||
DrawPixelRaw(x, end_y +5, border_color1);
|
||||
}
|
||||
else {
|
||||
DrawPixelRaw(x, start_y-3, border_color1);
|
||||
DrawPixelRaw(x, end_y +3, border_color1);
|
||||
}
|
||||
}
|
||||
|
||||
for (y=(start_y-3); y<(end_y+3); y++) {
|
||||
for (y=(start_y-5); y<(end_y+5); y++) {
|
||||
if (!is_active) {
|
||||
if (y < start_y-3)
|
||||
continue;
|
||||
else if (y >= end_y+3)
|
||||
break;
|
||||
}
|
||||
|
||||
DrawPixelRaw(start_x , y, border_color0);
|
||||
DrawPixelRaw(end_x , y, border_color0);
|
||||
DrawPixelRaw(start_x-1, y, border_color0);
|
||||
DrawPixelRaw(end_x +1, y, border_color0);
|
||||
DrawPixelRaw(start_x-2, y, border_color0);
|
||||
DrawPixelRaw(end_x +2, y, border_color0);
|
||||
DrawPixelRaw(start_x-3, y, border_color1);
|
||||
//DrawPixelRaw(end_x +3, y, border_color1);
|
||||
|
||||
if (is_active) {
|
||||
DrawPixelRaw(start_x-3, y, border_color0);
|
||||
DrawPixelRaw(end_x +3, y, border_color0);
|
||||
DrawPixelRaw(start_x-4, y, border_color0);
|
||||
DrawPixelRaw(end_x +4, y, border_color0);
|
||||
DrawPixelRaw(start_x-5, y, border_color1);
|
||||
}
|
||||
else {
|
||||
DrawPixelRaw(start_x-3, y, border_color1);
|
||||
//DrawPixelRaw(end_x +3, y, border_color1);
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
@ -86,11 +121,11 @@ static void drawEntry(menuEntry_s* me, int n, int is_active) {
|
||||
|
||||
if (is_active) {
|
||||
start_x = 64;
|
||||
start_y = 96 + 32;
|
||||
start_y = 96 + 32 + 288 + 64;
|
||||
|
||||
memset(tmpstr, 0, sizeof(tmpstr));
|
||||
snprintf(tmpstr, sizeof(tmpstr)-1, "Name: %s\nAuthor: %s\nVersion: %s", me->name, me->author, me->version);
|
||||
DrawText(tahoma12, start_x, start_y, MakeColor(64, 64, 64, 255), tmpstr);
|
||||
DrawText(tahoma12, start_x, start_y, MakeColor(255, 255, 255, 255), tmpstr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,6 +141,33 @@ void menuStartup() {
|
||||
menuScan(path);
|
||||
}
|
||||
|
||||
color_t waveBlendAdd(color_t a, color_t b, float alpha) {
|
||||
return MakeColor(a.r+(b.r*alpha), a.g+b.g*alpha, a.b + b.b*alpha, 255);
|
||||
}
|
||||
|
||||
const int ENABLE_WAVE_BLENDING = 1;
|
||||
double timer;
|
||||
|
||||
void drawWave(float timer, color_t color, float height, float phase, float speed) {
|
||||
int x, y;
|
||||
double wave_top_y, alpha;
|
||||
color_t existing_color, new_color;
|
||||
|
||||
height = 720 - height;
|
||||
|
||||
for (x=0; x<1280; x++) {
|
||||
wave_top_y = approxSin(x*speed/1280.0+timer+phase) * 10.0 + height;
|
||||
|
||||
for (y=wave_top_y; y<720; y++) {
|
||||
alpha = clamp(y-wave_top_y, 0.0, 1.0) * 0.3;
|
||||
existing_color = FetchPixelColor(x, y);
|
||||
new_color = ENABLE_WAVE_BLENDING ? waveBlendAdd(existing_color, color, alpha) : color;
|
||||
|
||||
DrawPixelRaw(x, y, new_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void menuLoop() {
|
||||
menuEntry_s* me;
|
||||
menu_s* menu = menuGetCurrent();
|
||||
@ -114,14 +176,19 @@ void menuLoop() {
|
||||
int x, y;
|
||||
|
||||
for (x=0; x<1280; x++) {
|
||||
for (y=0; y<122; y++) {
|
||||
DrawPixelRaw(x, y, MakeColor(237+8, 237+8, 237+8, 237+8));
|
||||
for (y=0; y<720; y++) {
|
||||
DrawPixelRaw(x, y, MakeColor(45, 55, 66, 255));
|
||||
}
|
||||
}
|
||||
|
||||
DrawText(tahoma24, 64, 64, MakeColor(64, 64, 64, 255), "The Homebrew Launcher");
|
||||
DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16, MakeColor(64, 64, 64, 255), "v1.0.0");
|
||||
DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16 + 16, MakeColor(64, 64, 64, 255), menu->dirname);
|
||||
DrawText(tahoma24, 64, 64, MakeColor(255, 255, 255, 255), "The Homebrew Launcher");
|
||||
DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16, MakeColor(255, 255, 255, 255), "v1.0.0");
|
||||
DrawText(tahoma12, 64 + 256 + 128 + 128, 64 + 16 + 16, MakeColor(255, 255, 255, 255), menu->dirname);
|
||||
|
||||
drawWave(timer, MakeColor(73, 103, 169, 255), 160.0, 0.0, 3.0);
|
||||
drawWave(timer, MakeColor(66, 154, 159, 255), 150.0, 2.0, 3.5);
|
||||
drawWave(timer, MakeColor(96, 204, 204, 255), 140.0, 4.0, -2.5);
|
||||
timer += 0.025;
|
||||
|
||||
if (menu->nEntries==0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user