diff --git a/src/driver/colorgradient.cpp b/src/driver/colorgradient.cpp index 3fc8c41b7..57e9d71d5 100644 --- a/src/driver/colorgradient.cpp +++ b/src/driver/colorgradient.cpp @@ -92,7 +92,7 @@ fb_pixel_t* CColorGradient::gradientColorToTransparent(fb_pixel_t col, fb_pixel_ return gradientBuf; } -fb_pixel_t* CColorGradient::gradientOneColor(fb_pixel_t col, fb_pixel_t *gradientBuf, int bSize, int mode, int intensity) +fb_pixel_t* CColorGradient::gradientOneColor(fb_pixel_t col, fb_pixel_t *gradientBuf, int bSize, int mode, int intensity, uint8_t v_min, uint8_t v_max, uint8_t s) { if (gradientBuf == NULL) { @@ -105,25 +105,30 @@ fb_pixel_t* CColorGradient::gradientOneColor(fb_pixel_t col, fb_pixel_t *gradien memset((void*)gradientBuf, '\0', bSize * sizeof(fb_pixel_t)); HsvColor hsv; - uint8_t min_v=0, max_v=0, min_s=0, max_s=0; - uint8_t start_v=0 , end_v=0, start_s=0, end_s=0; + uint8_t min_v=0, max_v=0, col_s=0; + uint8_t start_v=0 , end_v=0; uint8_t tr = SysColor2Hsv(col, &hsv); bool noSaturation = (hsv.s <= (float)0.05); - switch (intensity) { - case light: - min_v = limitChar((int)(hsv.v * 255 - hsv.v * 255/30)); - max_v = 0xE0; - min_s = limitChar((int)((hsv.s * 255) / 1.5)); - max_s = 0xE0; - break; - case normal: - min_v = limitChar((int)(hsv.v * 255 - hsv.v * 255/3)); - max_v = 0xFF; - min_s = limitChar((int)((hsv.s * 255) / 2.5)); - max_s = 0xFF; - break; + if (intensity == extended) { + min_v = v_min; + max_v = v_max; + col_s = s; + } + else { + switch (intensity) { + case light: + min_v = 0x40; + max_v = 0xE0; + col_s = (noSaturation) ? 0 : 0xC0; + break; + case normal: + min_v = 0x00; + max_v = 0xFF; + col_s = (noSaturation) ? 0 : 0xC0; + break; + } } switch (mode) { @@ -131,15 +136,11 @@ fb_pixel_t* CColorGradient::gradientOneColor(fb_pixel_t col, fb_pixel_t *gradien case gradientDark2Light2Dark: start_v = min_v; end_v = max_v; - start_s = max_s; - end_s = min_s; break; case gradientLight2Dark: case gradientLight2Dark2Light: start_v = max_v; end_v = min_v; - start_s = min_s; - end_s = max_s; break; default: return 0; @@ -149,16 +150,11 @@ fb_pixel_t* CColorGradient::gradientOneColor(fb_pixel_t col, fb_pixel_t *gradien int v = start_v; int v_ = v; float factor_v = ((float)end_v - (float)v) / (float)bSize1; - int s = start_s; int s_ = s; - float factor_s = ((float)end_s - (float)s) / (float)bSize1; for (int i = 0; i < bSize1; i++) { v = v_ + (int)(factor_v * (float)i); hsv.v = (float)limitChar(v) / (float)255; - if (!noSaturation) { - s = s_ + (int)(factor_s * (float)i); - hsv.s = (float)limitChar(s) / (float)255; - } + hsv.s = (float)col_s / (float)255; gradientBuf[i] = Hsv2SysColor(&hsv, tr); } @@ -167,10 +163,7 @@ fb_pixel_t* CColorGradient::gradientOneColor(fb_pixel_t col, fb_pixel_t *gradien for (int i = 0; i < bSize1; i++) { v = v_ + (int)(factor_v * (float)i); hsv.v = (float)limitChar(v) / (float)255; - if (!noSaturation) { - s = s_ + (int)(factor_s * (float)i); - hsv.s = (float)limitChar(s) / (float)255; - } + hsv.s = (float)col_s / (float)255; gradientBuf[bSize-i-1] = Hsv2SysColor(&hsv, tr); } } diff --git a/src/driver/colorgradient.h b/src/driver/colorgradient.h index 51d7de79e..41e26f518 100644 --- a/src/driver/colorgradient.h +++ b/src/driver/colorgradient.h @@ -44,14 +44,15 @@ class CColorGradient ///intensity enum { light, - normal + normal, + extended }; CColorGradient(); ~CColorGradient(); // static CColorGradient* getInstance(); - fb_pixel_t* gradientOneColor(fb_pixel_t col, fb_pixel_t *gradientBuf, int bSize, int mode, int intensity=normal); + fb_pixel_t* gradientOneColor(fb_pixel_t col, fb_pixel_t *gradientBuf, int bSize, int mode, int intensity=normal, uint8_t v_min=0x40, uint8_t v_max=0xE0, uint8_t s=0xC0); fb_pixel_t* gradientColorToTransparent(fb_pixel_t col, fb_pixel_t *gradientBuf, int bSize, int mode, int intensity=normal); }; diff --git a/src/gui/components/cc_base.h b/src/gui/components/cc_base.h index d884198ec..caeaec0a2 100644 --- a/src/gui/components/cc_base.h +++ b/src/gui/components/cc_base.h @@ -89,6 +89,12 @@ class CComponents : public CComponentsSignals, public COSDFader int cc_body_gradient_mode; ///property: background gradient intensity int cc_body_gradient_intensity; + ///property: background gradient intensity value min + uint8_t cc_body_gradient_intensity_v_min; + ///property: background gradient intensity value max + uint8_t cc_body_gradient_intensity_v_max; + ///property: background gradient saturation + uint8_t cc_body_gradient_saturation; ///property: background gradient direction int cc_body_gradient_direction; @@ -196,10 +202,13 @@ class CComponents : public CComponentsSignals, public COSDFader ///set color gradient on/off virtual void enableColBodyGradient(bool do_paint_gradient); ///set color gradient properties, possible parameter values for mode and intensity to find in CColorGradient, in driver/framebuffer.h> - virtual void setColBodyGradient(const int& mode, const int& direction, const int& intensity = CColorGradient::normal) + virtual void setColBodyGradient(const int& mode, const int& direction, const int& intensity = CColorGradient::normal, uint8_t v_min=0x40, uint8_t v_max=0xE0, uint8_t s=0xC0) { cc_body_gradient_mode = mode; cc_body_gradient_direction = direction; - cc_body_gradient_intensity=intensity;}; + cc_body_gradient_intensity=intensity; + cc_body_gradient_intensity_v_min=v_min; + cc_body_gradient_intensity_v_max=v_max; + cc_body_gradient_saturation=s; }; ///get frame color inline virtual fb_pixel_t getColorFrame(){return col_frame;}; diff --git a/src/gui/components/cc_item.cpp b/src/gui/components/cc_item.cpp index 4f594984c..4f61cd47a 100644 --- a/src/gui/components/cc_item.cpp +++ b/src/gui/components/cc_item.cpp @@ -54,6 +54,9 @@ CComponentsItem::CComponentsItem(CComponentsForm* parent) cc_gradientData.gradientBuf = NULL; cc_body_gradient_mode = CColorGradient::gradientLight2Dark; cc_body_gradient_intensity = CColorGradient::light; + cc_body_gradient_intensity_v_min = 0x40; + cc_body_gradient_intensity_v_max = 0xE0; + cc_body_gradient_saturation = 0xC0; cc_body_gradient_direction = CFrameBuffer::gradientVertical; initParent(parent); } @@ -243,7 +246,7 @@ void CComponentsItem::initBodyGradient() if (cc_body_gradientBuf == NULL) { CColorGradient ccGradient; int gsize = cc_body_gradient_direction == CFrameBuffer::gradientVertical ? height : width; - cc_body_gradientBuf = ccGradient.gradientOneColor(col_body, NULL, gsize, cc_body_gradient_mode, cc_body_gradient_intensity); + cc_body_gradientBuf = ccGradient.gradientOneColor(col_body, NULL, gsize, cc_body_gradient_mode, cc_body_gradient_intensity, cc_body_gradient_intensity_v_min, cc_body_gradient_intensity_v_max, cc_body_gradient_saturation); } cc_gradientData.gradientBuf = cc_body_gradientBuf; cc_gradientData.direction = cc_body_gradient_direction;