mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 15:02:56 +02:00
color: add function to get random color
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#include <gui/color.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <system/debug.h>
|
||||
|
||||
#include <driver/framebuffer.h>
|
||||
|
||||
@@ -258,3 +259,31 @@ void getItemColors(fb_pixel_t &t, fb_pixel_t &b, bool selected, bool marked, boo
|
||||
t = toggle_background ? (toggle_enlighten ? COL_MENUCONTENT_TEXT : COL_MENUCONTENTDARK_TEXT) : COL_MENUCONTENT_TEXT;
|
||||
b = toggle_background ? (toggle_enlighten ? COL_MENUCONTENT_PLUS_1 : COL_MENUCONTENTDARK_PLUS_0) : COL_MENUCONTENT_PLUS_0;
|
||||
}
|
||||
|
||||
fb_pixel_t getRandomColor(col_range_t range_r, col_range_t range_g, col_range_t range_b, uint8_t Alpha)
|
||||
{
|
||||
if (!range_r.min || !range_g.min || !range_b.min)
|
||||
{
|
||||
dprintf(DEBUG_NORMAL, "\033[31m[color.cpp] [Error:]\033[0m %s: color range min value < 1 in argument, allowed values are 1-255 [r: min%u/max%u] [g: min%u/max%u] [b: min%u/max%u]\n",__func__, range_r.min, range_r.max, range_g.min, range_g.max, range_b.min, range_b.max);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t seed[3];
|
||||
uint8_t r, g, b, a;
|
||||
|
||||
srand(range_r.min);
|
||||
r = rand_r(&seed[0]) % range_r.max;
|
||||
|
||||
srand(range_g.min);
|
||||
g = rand_r(&seed[1]) % range_g.max;
|
||||
|
||||
srand(range_b.min);
|
||||
b = rand_r(&seed[2]) % range_b.max;
|
||||
|
||||
a = Alpha;
|
||||
|
||||
int color = convertSetupColor2RGB(r, g, b);
|
||||
int alpha = a ? (convertSetupAlpha2Alpha(a)) : 0xFF;
|
||||
|
||||
return (((alpha << 24) & 0xFF000000) | color);
|
||||
}
|
||||
|
@@ -171,4 +171,13 @@ void Rgb2Hsv(RgbColor *rgb, HsvColor *hsv);
|
||||
|
||||
void getItemColors(fb_pixel_t &t, fb_pixel_t &b, bool selected = false, bool marked = false, bool toggle_background = false, bool toggle_enlighten = false);
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t min;
|
||||
uint8_t max;
|
||||
} col_range_t;
|
||||
|
||||
fb_pixel_t getRandomColor(col_range_t range_r = {1,255}, col_range_t range_g = {1,255}, col_range_t range_b = {1,255}, uint8_t Alpha = 0);
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -57,4 +57,6 @@
|
||||
#define COL_BLACK (CFrameBuffer::getInstance()->realcolor[0x11])
|
||||
#endif
|
||||
|
||||
#define COL_RANDOM (getRandomColor())
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user