File indexing completed on 2024-04-28 05:32:18

0001 #ifndef oxygenstylehelper_h
0002 #define oxygenstylehelper_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "oxygencachekey.h"
0011 #include "oxygencairosurface.h"
0012 #include "oxygencairosurfacecache.h"
0013 #include "oxygentileset.h"
0014 #include "oxygentilesetcache.h"
0015 
0016 #include <gtk/gtk.h>
0017 
0018 namespace Oxygen
0019 {
0020     // forward declaration
0021     namespace Cairo
0022     { class Context; }
0023 
0024     namespace ColorUtils
0025     { class Rgba; }
0026 
0027     class StyleHelper
0028     {
0029 
0030         public:
0031 
0032         //! constructor
0033         StyleHelper( void );
0034 
0035         //! destructor
0036         virtual ~StyleHelper( void );
0037 
0038         //! initialize ref surface
0039         void initializeRefSurface( void );
0040 
0041         //! separators
0042         void drawSeparator( Cairo::Context&, const ColorUtils::Rgba& color, int x, int y, int w, int h, bool vertical );
0043 
0044         //! clear caches
0045         void clearCaches( void )
0046         {
0047             _separatorCache.clear();
0048             _slabCache.clear();
0049             _slopeCache.clear();
0050             _slabSunkenCache.clear();
0051             _holeFocusedCache.clear();
0052             _holeFlatCache.clear();
0053             _scrollHoleCache.clear();
0054             _scrollHandleCache.clear();
0055             _slitFocusedCache.clear();
0056             _dockFrameCache.clear();
0057             _grooveCache.clear();
0058             _selectionCache.clear();
0059             _roundSlabCache.clear();
0060             _sliderSlabCache.clear();
0061             _progressBarIndicatorCache.clear();
0062             _windecoButtonCache.clear();
0063             _windecoButtonGlowCache.clear();
0064             _windowShadowCache.clear();
0065             _verticalGradientCache.clear();
0066             _radialGradientCache.clear();
0067             _windecoLeftBorderCache.clear();
0068             _windecoRightBorderCache.clear();
0069             _windecoTopBorderCache.clear();
0070             _windecoBottomBorderCache.clear();
0071         }
0072 
0073         //! create surface from reference for given width and height
0074         Cairo::Surface createSurface( int w, int h ) const
0075         {
0076             if( w <= 0 || h <= 0 ) return 0L;
0077             else return cairo_surface_create_similar( _refSurface, CAIRO_CONTENT_COLOR_ALPHA, w, h );
0078         }
0079 
0080         //!@name decoration specific helper functions
0081         //@{
0082         const Cairo::Surface& windecoButton(const ColorUtils::Rgba &color, bool pressed, int size = 21);
0083         const Cairo::Surface& windecoButtonGlow(const ColorUtils::Rgba &color, int size = 21);
0084         //@}
0085 
0086         //!@name window background cache
0087         //@{
0088         const Cairo::Surface& verticalGradient( const ColorUtils::Rgba&, int );
0089         const Cairo::Surface& radialGradient( const ColorUtils::Rgba&, int );
0090         //@}
0091 
0092         //!@name slabs
0093         //@{
0094 
0095         const TileSet& slab( const ColorUtils::Rgba& color, double shade = 0, int size = 7 )
0096         { return slab( color, ColorUtils::Rgba(), shade, size ); }
0097 
0098         const TileSet& slab( const ColorUtils::Rgba&, const ColorUtils::Rgba&, double shade = 0, int size = 7 );
0099 
0100         const TileSet& slabSunken( const ColorUtils::Rgba&, int size = 7 );
0101 
0102         const Cairo::Surface& roundSlab( const ColorUtils::Rgba& color, double shade, int size = 7 )
0103         { return roundSlab( color, ColorUtils::Rgba(), shade, size ); }
0104 
0105         const Cairo::Surface& roundSlab( const ColorUtils::Rgba&, const ColorUtils::Rgba& glow, double shade, int size = 7 );
0106 
0107         // slider slab
0108         const Cairo::Surface& sliderSlab( const ColorUtils::Rgba&, const ColorUtils::Rgba& glowColor, bool sunken, double shade, int size = 7 );
0109 
0110         //! groupbox background
0111         const TileSet& slope( const ColorUtils::Rgba&, double shade, int size = 7 );
0112 
0113         void fillSlab( cairo_t* context, int x, int y, int w, int h, const TileSet::Tiles& = TileSet::Ring ) const;
0114 
0115         //@}
0116 
0117         //! rounded mask
0118         /*! used for non-composited tooltips and menus */
0119         GdkPixmap* roundMask( int w, int h, int radius = 6 ) const;
0120 
0121         //!@name holes
0122         //@{
0123 
0124         const TileSet& hole( const ColorUtils::Rgba& base, const ColorUtils::Rgba& fill, int size = 7, bool contrast = false )
0125         { return holeFocused( base, fill, ColorUtils::Rgba(), size, contrast ); }
0126 
0127         const TileSet& hole( const ColorUtils::Rgba& base, int size = 7, bool contrast = false)
0128         { return holeFocused( base, ColorUtils::Rgba(), ColorUtils::Rgba(), size, contrast ); }
0129 
0130         const TileSet& holeFocused( const ColorUtils::Rgba& base, const ColorUtils::Rgba &glow, int size = 7, bool contrast = false )
0131         { return holeFocused( base, ColorUtils::Rgba(), glow, size, contrast ); }
0132 
0133         const TileSet& holeFocused( const ColorUtils::Rgba&, const ColorUtils::Rgba& fill, const ColorUtils::Rgba &glow, int size = 7, bool contrast = false );
0134 
0135         const TileSet& holeFlat( const  ColorUtils::Rgba&, double, bool = true, int size = 7 );
0136 
0137         //@}
0138 
0139         //!@name scrollbar elements
0140         //@{
0141         const TileSet& scrollHole( const ColorUtils::Rgba&, bool vertical, bool smallShadow = false );
0142         const TileSet& scrollHandle( const ColorUtils::Rgba&, const ColorUtils::Rgba&, int size = 7 );
0143 
0144         //! 'slit' (for hovered/focused flat buttons )
0145         const TileSet& slitFocused( const ColorUtils::Rgba& );
0146 
0147         //! dock frame
0148         const TileSet& dockFrame( const ColorUtils::Rgba&, const ColorUtils::Rgba& );
0149 
0150         //! progressbar indicator
0151         const Cairo::Surface& progressBarIndicator( const ColorUtils::Rgba&, const ColorUtils::Rgba& glow, int w, int h );
0152 
0153         //! slider groove
0154         const TileSet& groove( const ColorUtils::Rgba&, int size = 7 );
0155 
0156         //! selection
0157         const TileSet& selection( const ColorUtils::Rgba&, int, bool custom );
0158 
0159         //! dots
0160         void renderDot( cairo_t*, const ColorUtils::Rgba&, int x, int y ) const;
0161 
0162         //!@name windeco caches
0163         //@{
0164 
0165         /*! needed to oxygenwindowshadow and drawWindowDecoration() */
0166         TileSetCache<WindowShadowKey>& windowShadowCache( void )
0167         { return _windowShadowCache; }
0168 
0169         CairoSurfaceCache<WindecoLeftBorderKey>& windecoLeftBorderCache( void )
0170         { return _windecoLeftBorderCache; }
0171 
0172         CairoSurfaceCache<WindecoRightBorderKey>& windecoRightBorderCache( void )
0173         { return _windecoRightBorderCache; }
0174 
0175         CairoSurfaceCache<WindecoTopBorderKey>& windecoTopBorderCache( void )
0176         { return _windecoTopBorderCache; }
0177 
0178         CairoSurfaceCache<WindecoBottomBorderKey>& windecoBottomBorderCache( void )
0179         { return _windecoBottomBorderCache; }
0180 
0181         //! shadow rendering
0182         virtual void drawShadow( cairo_t*, const ColorUtils::Rgba&, int size ) const;
0183 
0184         //! highlight glow
0185         virtual void drawOuterGlow( cairo_t*, const ColorUtils::Rgba&, int size) const;
0186 
0187         //@}
0188 
0189         //@}
0190 
0191         //! window decorations button for MDI windows from oxygen-qt, used as tab close button in oxygen-gtk
0192         const Cairo::Surface& dockWidgetButton(const ColorUtils::Rgba& base, bool pressed, int size);
0193 
0194         protected:
0195 
0196         //! access reference surface
0197         const Cairo::Surface& refSurface( void ) const
0198         { return _refSurface; }
0199 
0200         // separator
0201         const Cairo::Surface& separator(const ColorUtils::Rgba &color, bool vertical, int size );
0202 
0203         //! slab rendering
0204         virtual void drawSlab( Cairo::Context&, const ColorUtils::Rgba&, double shade) const;
0205 
0206         //! inverse shadow (for sunken slabs)
0207         void drawInverseShadow( Cairo::Context&, const ColorUtils::Rgba&, int pad, int size, double fuzz ) const;
0208 
0209         //! inverse glow (for sunken slabs)
0210         void drawInverseGlow( Cairo::Context&, const ColorUtils::Rgba&, int pad, int size, int rsize ) const;
0211 
0212         //! round slab
0213         void drawRoundSlab( Cairo::Context&, const ColorUtils::Rgba&, double ) const;
0214 
0215         //! slider slab
0216         void drawSliderSlab( Cairo::Context&, const ColorUtils::Rgba&, bool sunken, double ) const;
0217 
0218         //! inverse shadow gradient
0219         cairo_pattern_t* inverseShadowGradient( const ColorUtils::Rgba&, int pad, int size, double fuzz ) const;
0220 
0221         private:
0222 
0223         //!@name some constants for drawing
0224         //@{
0225         static const double _slabThickness;
0226         static const double _shadowGain;
0227         static const double _glowBias;
0228         //@}
0229 
0230         //! reference surface for all later surface creations
0231         Cairo::Surface _refSurface;
0232 
0233         //!@name caches
0234         //@{
0235 
0236         //! round slabs
0237         CairoSurfaceCache<SeparatorKey> _separatorCache;
0238 
0239         //! slabs
0240         TileSetCache<SlabKey> _slabCache;
0241 
0242         //! slabs
0243         TileSetCache<SlabKey> _slopeCache;
0244 
0245         //! slabs
0246         TileSetCache<SlabKey> _slabSunkenCache;
0247 
0248         //! holes
0249         TileSetCache<HoleFocusedKey> _holeFocusedCache;
0250 
0251         //! holes
0252         TileSetCache<HoleFlatKey> _holeFlatCache;
0253 
0254         //! scroll hole
0255         TileSetCache<ScrollHoleKey> _scrollHoleCache;
0256 
0257         //! scrollbar handle
0258         TileSetCache<ScrollHandleKey> _scrollHandleCache;
0259 
0260         //! slit
0261         TileSetCache<SlitFocusedKey> _slitFocusedCache;
0262 
0263         //! docks
0264         TileSetCache<DockFrameKey> _dockFrameCache;
0265 
0266         //! groove
0267         TileSetCache<GrooveKey> _grooveCache;
0268 
0269         //! selection
0270         TileSetCache<SelectionKey> _selectionCache;
0271 
0272         //! round slabs
0273         CairoSurfaceCache<SlabKey> _roundSlabCache;
0274 
0275         //! slider slabs
0276         CairoSurfaceCache<SliderSlabKey> _sliderSlabCache;
0277 
0278         //! progressbar indicators
0279         CairoSurfaceCache<ProgressBarIndicatorKey> _progressBarIndicatorCache;
0280 
0281         //! decoration button
0282         CairoSurfaceCache<WindecoButtonKey> _windecoButtonCache;
0283 
0284         //! decoration glow
0285         CairoSurfaceCache<WindecoButtonGlowKey> _windecoButtonGlowCache;
0286 
0287         //! decoration shadow
0288         TileSetCache<WindowShadowKey> _windowShadowCache;
0289 
0290         //! window backgound vertical gradient
0291         CairoSurfaceCache<VerticalGradientKey> _verticalGradientCache;
0292 
0293         //! window backgound radial gradient
0294         CairoSurfaceCache<RadialGradientKey> _radialGradientCache;
0295 
0296         //! dock widget button
0297         CairoSurfaceCache<DockWidgetButtonKey> _dockWidgetButtonCache;
0298 
0299         //@}
0300 
0301         //!@name windeco borders
0302         //@{
0303 
0304         CairoSurfaceCache<WindecoLeftBorderKey> _windecoLeftBorderCache;
0305         CairoSurfaceCache<WindecoRightBorderKey> _windecoRightBorderCache;
0306         CairoSurfaceCache<WindecoTopBorderKey> _windecoTopBorderCache;
0307         CairoSurfaceCache<WindecoBottomBorderKey> _windecoBottomBorderCache;
0308 
0309         //@}
0310 
0311     };
0312 
0313 }
0314 
0315 #endif