From 86c7003d6dca3dbea013bcc3b68c6d6189888d41 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 26 Dec 2010 22:19:09 +0100 Subject: [PATCH] Commit CairoUtil class forgotten in commit 60ccdd. --- src/gui/util/cairo-util.cpp | 81 +++++++++++++++++++++++++++++++++++++ src/gui/util/cairo-util.hpp | 73 +++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/gui/util/cairo-util.cpp create mode 100644 src/gui/util/cairo-util.hpp diff --git a/src/gui/util/cairo-util.cpp b/src/gui/util/cairo-util.cpp new file mode 100644 index 000000000..d9559cd82 --- /dev/null +++ b/src/gui/util/cairo-util.cpp @@ -0,0 +1,81 @@ +/* + cairo-util.cpp - Defines utility functions for Cairo + + Copyright (C) Lumiera.org + 2010, Stefan Kangas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +#include "cairo-util.hpp" + +namespace gui { +namespace util { + + RefPtr + CairoUtil::pattern_set_red (const RefPtr color, double red) + { + double old_red; + double blue; + double green; + double alpha; + + color->get_rgba (old_red, blue, green, alpha); + + return Cairo::SolidPattern::create_rgba (red, blue, green, alpha); + } + + RefPtr + CairoUtil::pattern_set_green (const RefPtr color, double blue) + { + double red; + double old_blue; + double green; + double alpha; + + color->get_rgba (red, old_blue, green, alpha); + + return Cairo::SolidPattern::create_rgba (red, blue, green, alpha); + } + + RefPtr + CairoUtil::pattern_set_blue (const RefPtr color, double green) + { + double red; + double blue; + double old_green; + double alpha; + + color->get_rgba (red, blue, old_green, alpha); + + return Cairo::SolidPattern::create_rgba (red, blue, green, alpha); + } + + RefPtr + CairoUtil::pattern_set_alpha (const RefPtr color, double alpha) + { + double red; + double blue; + double green; + double old_alpha; + + color->get_rgba (red, blue, green, old_alpha); + + return Cairo::SolidPattern::create_rgba (red, blue, green, alpha); + } + +} // namespace util +} // namespace gui diff --git a/src/gui/util/cairo-util.hpp b/src/gui/util/cairo-util.hpp new file mode 100644 index 000000000..999e728ea --- /dev/null +++ b/src/gui/util/cairo-util.hpp @@ -0,0 +1,73 @@ +/* + cairo-util.hpp - Declares utility functions for Cairo + + Copyright (C) Lumiera.org + 2010, Stefan Kangas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +#include + +#ifndef UTIL_CAIRO_HPP +#define UTIL_CAIRO_HPP + +using Cairo::RefPtr; +using Cairo::SolidPattern; + +namespace gui { +namespace util { + + class CairoUtil + { + public: + /** + * Make a new SolidPattern from an old one, changing the red component of the color. + * @param The new value for the red component of the color. + * @return The new pattern. + */ + static RefPtr + pattern_set_red (const RefPtr color, double red); + + /** + * Make a new SolidPattern from an old one, changing the green component of the color. + * @param The new value for the green component of the color. + * @return The new pattern. + */ + static RefPtr + pattern_set_green (const RefPtr, double green); + + /** + * Make a new SolidPattern from an old one, changing the blue component of the color. + * @param The new value for the blue component of the color. + * @return The new pattern. + */ + static RefPtr + pattern_set_blue (const RefPtr, double blue); + + /** + * Make a new SolidPattern from an old one, changing the alpha component of the color. + * @param The new value for the alpha component of the color. + * @return The new pattern. + */ + static RefPtr + pattern_set_alpha (const RefPtr, double alpha); + }; + +} // namespace util +} // namespace gui + +#endif