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

0001 /*
0002     this file is part of the oxygen gtk engine
0003     SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0004     SPDX-FileCopyrightText: 2010 Ruslan Kabatsayev <b7.10110111@gmail.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "oxygenwindecobutton.h"
0010 #include "oxygenrgba.h"
0011 #include "oxygencairoutils.h"
0012 #include "oxygencolorutils.h"
0013 #include "oxygenqtsettings.h"
0014 #include "oxygenstylehelper.h"
0015 #include <cmath>
0016 
0017 namespace Oxygen
0018 {
0019 
0020     //________________________________________________________________________________
0021     void WinDeco::Button::render( cairo_t* context, gint x, gint y, gint w, gint h ) const
0022     {
0023         if( _type==ButtonMenu )
0024         {
0025             // menu button isn't drawn - an app icon should be drawn instead
0026             return;
0027         }
0028 
0029         cairo_save( context );
0030         cairo_translate( context, x, y );
0031 
0032         const ColorUtils::Rgba base( settings().palette().color( _state == Disabled ? Palette::Disabled : Palette::Active, Palette::Window ) );
0033         ColorUtils::Rgba glow( settings().palette().color( Palette::WindowText ) );
0034         ColorUtils::Rgba icon(glow);
0035         const double scale( (21.0*settings().buttonSize())/22.0 );
0036 
0037         // draw shadow
0038         if(_state==Hovered||_state==Pressed)
0039         {
0040             glow=(_type==ButtonClose)?
0041                 ColorUtils::Rgba( settings().palette().color( Palette::NegativeText ) ):
0042                 ColorUtils::Rgba( settings().palette().color( Palette::Hover ) );
0043             icon=glow;
0044         } else {
0045             glow=ColorUtils::Rgba(0,0,0);
0046         }
0047 
0048         cairo_save(context);
0049         cairo_scale(context,int(scale)/21.,int(scale)/21.);
0050         cairo_translate(context,0,-1.4);
0051         _helper.drawShadow(context,ColorUtils::shadowColor(base),21);
0052         if(_state==Hovered||_state==Pressed)
0053             _helper.drawOuterGlow(context,glow,21);
0054         cairo_restore(context);
0055 
0056         // draw button slab
0057         const bool pressed( _state == Pressed || _type==ButtonUnstick || _type==ButtonUndoAbove || _type==ButtonUndoBelow );
0058         const Cairo::Surface& windecoButton( helper().windecoButton( base, pressed, int(scale) ) );
0059         cairo_set_source_surface( context, windecoButton, 0, 0 );
0060         cairo_rectangle( context, 0, 0, w, h );
0061         cairo_fill( context );
0062 
0063         // draw icon
0064         cairo_set_line_width( context, 1.2 );
0065         cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND );
0066         cairo_set_line_join( context, CAIRO_LINE_JOIN_ROUND );
0067 
0068         cairo_scale( context, double(w)/22.0, double(h)/22.0 );
0069         Oxygen::cairo_set_source( context, ColorUtils::lightColor( base ) );
0070         drawIcon( context, w, h );
0071 
0072         cairo_translate( context, 0, -1.5 );
0073 
0074         if(_state==Disabled)
0075         {
0076             icon=ColorUtils::Rgba( settings().palette().color( Palette::Disabled, Palette::WindowText ) );
0077         }
0078         cairo_set_source( context, icon );
0079 
0080         drawIcon( context, w, h );
0081         cairo_restore( context );
0082 
0083     }
0084 
0085     //________________________________________________________________________________
0086     void WinDeco::Button::drawIcon( cairo_t* context, int w, int h ) const
0087     {
0088 
0089         switch( _type )
0090         {
0091             case ButtonStick:
0092             case ButtonUnstick:
0093             cairo_move_to( context, 10.5, 10.5 );
0094             cairo_close_path( context );
0095             cairo_stroke( context );
0096             break;
0097 
0098             case ButtonHelp:
0099             cairo_save( context );
0100             cairo_translate( context, 1.5,1.5 );
0101 
0102             cairo_arc_qt( context, 7,5,4, 135.0*M_PI/180, -M_PI );
0103             cairo_stroke(context);
0104 
0105             cairo_arc_qt( context, 9,8,4, 135*M_PI/180, M_PI/4 );
0106             cairo_stroke( context );
0107             cairo_move_to( context, 9,12 );
0108             cairo_close_path( context );
0109             cairo_stroke( context );
0110 
0111             cairo_restore( context );
0112             break;
0113 
0114             case ButtonMin:
0115             cairo_move_to( context, 7.5, 9.5 );
0116             cairo_line_to( context, 10.5, 12.5 );
0117             cairo_line_to( context, 13.5, 9.5 );
0118             cairo_stroke( context );
0119             break;
0120 
0121             case ButtonMax:
0122             cairo_move_to( context, 7.5, 11.5 );
0123             cairo_line_to( context, 10.5, 8.5 );
0124             cairo_line_to( context, 13.5, 11.5 );
0125             cairo_stroke( context );
0126             break;
0127 
0128             case ButtonUnmax:
0129             cairo_save( context );
0130             cairo_translate( context, 1.5,1.5 );
0131             cairo_move_to( context, 9, 6 );
0132             cairo_line_to( context, 12, 9 );
0133             cairo_line_to( context, 9, 12 );
0134             cairo_line_to( context, 6, 9 );
0135             cairo_line_to( context, 9, 6 );
0136             cairo_stroke( context );
0137             cairo_restore( context );
0138             break;
0139 
0140             case ButtonClose:
0141             cairo_move_to( context, 7.5, 7.5 ); cairo_line_to( context, 13.5, 13.5 );
0142             cairo_move_to( context, 13.5, 7.5 ); cairo_line_to( context, 7.5, 13.5 );
0143             cairo_stroke( context );
0144             break;
0145 
0146             case ButtonAbove:
0147             case ButtonUndoAbove:
0148             cairo_move_to( context, 7.5, 14 );
0149             cairo_line_to( context, 10.5, 11 );
0150             cairo_line_to( context, 13.5, 14 );
0151 
0152             cairo_move_to( context, 7.5, 10 );
0153             cairo_line_to( context, 10.5, 7 );
0154             cairo_line_to( context, 13.5, 10 );
0155             cairo_stroke( context );
0156             break;
0157 
0158             case ButtonBelow:
0159             case ButtonUndoBelow:
0160             cairo_move_to( context, 7.5, 11 );
0161             cairo_line_to( context, 10.5, 14 );
0162             cairo_line_to( context, 13.5, 11 );
0163 
0164             cairo_move_to( context, 7.5, 7 );
0165             cairo_line_to( context, 10.5, 10 );
0166             cairo_line_to( context, 13.5, 7 );
0167             cairo_stroke( context );
0168             break;
0169 
0170             case ButtonShade:
0171             cairo_move_to( context, 7.5, 7.5 );
0172             cairo_line_to( context, 10.5, 10.5 );
0173             cairo_line_to( context, 13.5, 7.5 );
0174 
0175             cairo_move_to( context, 7.5, 13.0 );
0176             cairo_line_to( context, 13.5, 13.0 );
0177             cairo_stroke( context );
0178             break;
0179 
0180             case ButtonUnshade:
0181             cairo_move_to( context, 7.5, 10.5 );
0182             cairo_line_to( context, 10.5, 7.5 );
0183             cairo_line_to( context, 13.5, 10.5 );
0184 
0185             cairo_move_to( context, 7.5, 13 );
0186             cairo_line_to( context, 13.5, 13 );
0187             cairo_stroke( context );
0188             break;
0189 
0190             default:
0191             break;
0192         }
0193 
0194     }
0195 
0196 }