1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * Copyright (c) 2010 Ruslan Kabatsayev <b7.10110111@gmail.com> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or( at your option ) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #include "oxygenwindecobutton.h" 23 #include "oxygenrgba.h" 24 #include "oxygencairoutils.h" 25 #include "oxygencolorutils.h" 26 #include "oxygenqtsettings.h" 27 #include "oxygenstylehelper.h" 28 #include <cmath> 29 30 namespace Oxygen 31 { 32 33 //________________________________________________________________________________ render(cairo_t * context,gint x,gint y,gint w,gint h) const34 void WinDeco::Button::render( cairo_t* context, gint x, gint y, gint w, gint h ) const 35 { 36 if( _type==ButtonMenu ) 37 { 38 // menu button isn't drawn - an app icon should be drawn instead 39 return; 40 } 41 42 cairo_save( context ); 43 cairo_translate( context, x, y ); 44 45 const ColorUtils::Rgba base( settings().palette().color( _state == Disabled ? Palette::Disabled : Palette::Active, Palette::Window ) ); 46 ColorUtils::Rgba glow( settings().palette().color( Palette::WindowText ) ); 47 ColorUtils::Rgba icon(glow); 48 const double scale( (21.0*settings().buttonSize())/22.0 ); 49 50 // draw shadow 51 if(_state==Hovered||_state==Pressed) 52 { 53 glow=(_type==ButtonClose)? 54 ColorUtils::Rgba( settings().palette().color( Palette::NegativeText ) ): 55 ColorUtils::Rgba( settings().palette().color( Palette::Hover ) ); 56 icon=glow; 57 } else { 58 glow=ColorUtils::Rgba(0,0,0); 59 } 60 61 cairo_save(context); 62 cairo_scale(context,int(scale)/21.,int(scale)/21.); 63 cairo_translate(context,0,-1.4); 64 _helper.drawShadow(context,ColorUtils::shadowColor(base),21); 65 if(_state==Hovered||_state==Pressed) 66 _helper.drawOuterGlow(context,glow,21); 67 cairo_restore(context); 68 69 // draw button slab 70 const bool pressed( _state == Pressed || _type==ButtonUnstick || _type==ButtonUndoAbove || _type==ButtonUndoBelow ); 71 const Cairo::Surface& windecoButton( helper().windecoButton( base, pressed, int(scale) ) ); 72 cairo_set_source_surface( context, windecoButton, 0, 0 ); 73 cairo_rectangle( context, 0, 0, w, h ); 74 cairo_fill( context ); 75 76 // draw icon 77 cairo_set_line_width( context, 1.2 ); 78 cairo_set_line_cap( context, CAIRO_LINE_CAP_ROUND ); 79 cairo_set_line_join( context, CAIRO_LINE_JOIN_ROUND ); 80 81 cairo_scale( context, double(w)/22.0, double(h)/22.0 ); 82 Oxygen::cairo_set_source( context, ColorUtils::lightColor( base ) ); 83 drawIcon( context, w, h ); 84 85 cairo_translate( context, 0, -1.5 ); 86 87 if(_state==Disabled) 88 { 89 icon=ColorUtils::Rgba( settings().palette().color( Palette::Disabled, Palette::WindowText ) ); 90 } 91 cairo_set_source( context, icon ); 92 93 drawIcon( context, w, h ); 94 cairo_restore( context ); 95 96 } 97 98 //________________________________________________________________________________ drawIcon(cairo_t * context,int w,int h) const99 void WinDeco::Button::drawIcon( cairo_t* context, int w, int h ) const 100 { 101 102 switch( _type ) 103 { 104 case ButtonStick: 105 case ButtonUnstick: 106 cairo_move_to( context, 10.5, 10.5 ); 107 cairo_close_path( context ); 108 cairo_stroke( context ); 109 break; 110 111 case ButtonHelp: 112 cairo_save( context ); 113 cairo_translate( context, 1.5,1.5 ); 114 115 cairo_arc_qt( context, 7,5,4, 135.0*M_PI/180, -M_PI ); 116 cairo_stroke(context); 117 118 cairo_arc_qt( context, 9,8,4, 135*M_PI/180, M_PI/4 ); 119 cairo_stroke( context ); 120 cairo_move_to( context, 9,12 ); 121 cairo_close_path( context ); 122 cairo_stroke( context ); 123 124 cairo_restore( context ); 125 break; 126 127 case ButtonMin: 128 cairo_move_to( context, 7.5, 9.5 ); 129 cairo_line_to( context, 10.5, 12.5 ); 130 cairo_line_to( context, 13.5, 9.5 ); 131 cairo_stroke( context ); 132 break; 133 134 case ButtonMax: 135 cairo_move_to( context, 7.5, 11.5 ); 136 cairo_line_to( context, 10.5, 8.5 ); 137 cairo_line_to( context, 13.5, 11.5 ); 138 cairo_stroke( context ); 139 break; 140 141 case ButtonUnmax: 142 cairo_save( context ); 143 cairo_translate( context, 1.5,1.5 ); 144 cairo_move_to( context, 9, 6 ); 145 cairo_line_to( context, 12, 9 ); 146 cairo_line_to( context, 9, 12 ); 147 cairo_line_to( context, 6, 9 ); 148 cairo_line_to( context, 9, 6 ); 149 cairo_stroke( context ); 150 cairo_restore( context ); 151 break; 152 153 case ButtonClose: 154 cairo_move_to( context, 7.5, 7.5 ); cairo_line_to( context, 13.5, 13.5 ); 155 cairo_move_to( context, 13.5, 7.5 ); cairo_line_to( context, 7.5, 13.5 ); 156 cairo_stroke( context ); 157 break; 158 159 case ButtonAbove: 160 case ButtonUndoAbove: 161 cairo_move_to( context, 7.5, 14 ); 162 cairo_line_to( context, 10.5, 11 ); 163 cairo_line_to( context, 13.5, 14 ); 164 165 cairo_move_to( context, 7.5, 10 ); 166 cairo_line_to( context, 10.5, 7 ); 167 cairo_line_to( context, 13.5, 10 ); 168 cairo_stroke( context ); 169 break; 170 171 case ButtonBelow: 172 case ButtonUndoBelow: 173 cairo_move_to( context, 7.5, 11 ); 174 cairo_line_to( context, 10.5, 14 ); 175 cairo_line_to( context, 13.5, 11 ); 176 177 cairo_move_to( context, 7.5, 7 ); 178 cairo_line_to( context, 10.5, 10 ); 179 cairo_line_to( context, 13.5, 7 ); 180 cairo_stroke( context ); 181 break; 182 183 case ButtonShade: 184 cairo_move_to( context, 7.5, 7.5 ); 185 cairo_line_to( context, 10.5, 10.5 ); 186 cairo_line_to( context, 13.5, 7.5 ); 187 188 cairo_move_to( context, 7.5, 13.0 ); 189 cairo_line_to( context, 13.5, 13.0 ); 190 cairo_stroke( context ); 191 break; 192 193 case ButtonUnshade: 194 cairo_move_to( context, 7.5, 10.5 ); 195 cairo_line_to( context, 10.5, 7.5 ); 196 cairo_line_to( context, 13.5, 10.5 ); 197 198 cairo_move_to( context, 7.5, 13 ); 199 cairo_line_to( context, 13.5, 13 ); 200 cairo_stroke( context ); 201 break; 202 203 default: 204 break; 205 } 206 207 } 208 209 } 210