From 296dacb0237503216b4f2b62081bd8eafa7e5628 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Wed, 19 Feb 2003 03:55:51 +0000 Subject: [PATCH] Added the much sought after horizontal gradient --- otk/rendercontrol.cc | 33 +++++++++++++++++++++++++++++++++ otk/rendercontrol.hh | 1 + 2 files changed, 34 insertions(+) diff --git a/otk/rendercontrol.cc b/otk/rendercontrol.cc index 6aefb8d5..6386b035 100644 --- a/otk/rendercontrol.cc +++ b/otk/rendercontrol.cc @@ -232,6 +232,9 @@ void RenderControl::drawGradientBackground( case RenderTexture::Vertical: verticalGradient(sf, texture); break; + case RenderTexture::Horizontal: + horizontalGradient(sf, texture); + break; case RenderTexture::Diagonal: diagonalGradient(sf, texture); break; @@ -321,6 +324,36 @@ void RenderControl::verticalGradient(Surface &sf, } } +void RenderControl::horizontalGradient(Surface &sf, + const RenderTexture &texture) const +{ + pixel32 *data = sf.pixelData(); + pixel32 current; + float dr, dg, db; + unsigned int r,g,b; + int w = sf.size().width(), h = sf.size().height(); + + dr = (float)(texture.secondary_color().red() - texture.color().red()); + dr/= (float)w; + + dg = (float)(texture.secondary_color().green() - texture.color().green()); + dg/= (float)w; + + db = (float)(texture.secondary_color().blue() - texture.color().blue()); + db/= (float)w; + + for (int x = 0; x < w; ++x, ++data) { + r = texture.color().red() + (int)(dr * x); + g = texture.color().green() + (int)(dg * x); + b = texture.color().blue() + (int)(db * x); + current = (r << default_red_shift) + + (g << default_green_shift) + + (b << default_blue_shift); + for (int y = 0; y < h; ++y) + *(data + y*w) = current; + } +} + void RenderControl::diagonalGradient(Surface &sf, const RenderTexture &texture) const { diff --git a/otk/rendercontrol.hh b/otk/rendercontrol.hh index fa07cf51..9e140db0 100644 --- a/otk/rendercontrol.hh +++ b/otk/rendercontrol.hh @@ -28,6 +28,7 @@ protected: inline void highlight(pixel32 *x, pixel32 *y, bool raised) const; void verticalGradient(Surface &sf, const RenderTexture &texture) const; + void horizontalGradient(Surface &sf, const RenderTexture &texture) const; void diagonalGradient(Surface &sf, const RenderTexture &texture) const; void crossDiagonalGradient(Surface &sf, const RenderTexture &texture) const; virtual void drawGradientBackground(Surface &sf, -- 2.45.2