// Drawing mixins

// generic drawing of more complex things



@mixin headerbar_fill($c:$headerbar_bg_color, $ov: none) {
//
// headerbar fill
//
// $c:  base color
// $ov: a background layer for background shorthand (hence no commas!)
//
  @if $ov != none { background: $c $ov; }
  @else { background: $c; }

}

@mixin overshoot($p, $t:normal, $c:$selected_bg_color) {
//
// overshoot
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  $_small_gradient_length: 3%;
  $_big_gradient_length: 50%;

  $_small_gradient_size: 100% $_small_gradient_length;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==right or $p==left {
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  $_small_gradient_color: $c;
  $_big_gradient_color: transparentize($c, 0.93);

  @if $c==$fg_color {
    $_small_gradient_color: darken($borders_color, 10%);
    $_big_gradient_color: transparentize($fg_color, 0.93);

    @if $t==backdrop { $_small_gradient_color: $backdrop_borders_color; }
  }

  $_small_gradient: radial-gradient(farthest-side at $p,
                                    $_small_gradient_color 85%,
                                    transparentize($_small_gradient_color, 1));

  $_big_gradient: radial-gradient(farthest-side at $p,
                                  $_big_gradient_color,
                                  transparentize($_big_gradient_color, 1));

  @if $t==normal {
    background-image: $_small_gradient, $_big_gradient;
    background-size: $_small_gradient_size, $_big_gradient_size;
  }

  @else if $t==backdrop {
    background-image: $_small_gradient;
    background-size: $_small_gradient_size;
  }

  background-repeat: no-repeat;
  background-position: $p;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}

/***************************
 * Check and Radio buttons *
 ***************************/

 @mixin check($t, $c:$checkradio_bg_color, $tc:$checkradio_fg_color, $checked: false) {
  // Check/Radio drawing function
  //
  // $t:        check/radio type,
  // $c:        base button color for colored* types
  // $tc:       optional text color for colored* types
  // $checked:  bool to chose between checked/unchecked
  //
  // possible $t values:
  // normal, hover, active, insensitive, backdrop, backdrop-insensitive, menu

  $_border_color: if($c==$checkradio_bg_color, $checkradio_bg_color, transparentize($fg_color, 0.2));
  $_dim_border_color: transparentize($_border_color, if($variant == 'light', 0.3, 0.7));

  @if $t==normal  {
    background-clip: border-box;
    background-image: image($c);
    border-color: transparent;
    box-shadow: 0 0 0 2px $_border_color;
    color: $tc;
  }

  @if $t==hover {
    background-image: image($c);
  }

  @if $t==active {
    box-shadow: 0 0 0 2px $_border_color;
    background-image: image($c);
  }

  @if $t==insensitive {
    box-shadow: 0 0 0 2px transparentize($color: $_border_color, $amount: 0.5);
    background-image: image(transparentize($c, 0.5));
    color: transparentize($tc, 0.5);
  }

  @if $t==backdrop {
    background-image: image(transparentize($c, 0.3));
    box-shadow: 0 0 0 2px transparentize($color: $_border_color, $amount: 0.3);
    color: $tc;
  }

  @if $t==backdrop-insensitive {
    box-shadow: 0 0 0 2px transparentize($color: $_border_color, $amount: 0.7);
    background-image: image(transparentize($c, 0.7));
    color: transparentize($tc, 0.5);
  }

  @if $t==menu {
   transform: scale(0.8);
   border-width: 1.2px;
   border-color: transparent;
   box-shadow: none;
   background-image: image(transparent);
   color: $tc;
  }

  @if $t==menu-active {
   transform: scale(0.8);
   border-width: 1.2px;
   color: $tc;
   box-shadow: none;
   background-image: image(transparent);
  }
}

// Helper for drawing circular buttons
@mixin draw_circle($c, $size:24px) {
  $button_size: $size + 2px * 2;
  $circle_size: 20px / $button_size / 2;

  background-image: -gtk-gradient(radial,
                                  center center, 0,
                                  center center, $circle_size,
                                  to($c),
                                  to(transparent));

  &:hover {
    $_bg: if($c!=$selected_bg_color, transparentize(white, 0.8), lighten($c, 3%));
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, $circle_size,
                                    to($_bg),
                                    to(transparent));

    &:backdrop {
      $_bg: transparentize(white, 0.9);
      background-image: -gtk-gradient(radial,
                                      center center, 0,
                                      center center, $circle_size,
                                      to($_bg),
                                      to(transparent));
    }
  }

  &:active {
    $_bg: if($c!=$selected_bg_color, transparentize(white, 0.9), darken($c, 2%));
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, $circle_size,
                                    to($_bg),
                                    to(transparent));
  }
}

// buttons

@function _border_color($c, $darker: false) {
  @if $darker == true { @return darken($c, 20%); }
  @else { @return darken($c, 15%); }
}

$_default_button_c: lighten($bg_color, 2%);
@mixin button($t, $c:$_default_button_c, $tc:$fg_color) {
//
// Button drawing function
//
// $t:    button type,
// $c:    base button color for colored* types
// $tc:   optional text color for colored* types
//
// possible $t values:
// normal, hover, active, checked-hover, checked-active, insensitive, insensitive-active,
// backdrop, backdrop-active, backdrop-insensitive, backdrop-insensitive-active,
// osd, osd-hover, osd-active, osd-insensitive, osd-backdrop, undecorated
//
  $_button_shadow: 0 1px 2px transparentize($shadow_color, 0.03);

  @if $t==normal {
  //
  // normal button
  //
    transition: $button_transition;
    color: $tc;
    outline-color: if($c != $_default_button_c, $alt_focus_border_color, $focus_border_color);
    border-color: if($c!=$_default_button_c, _border_color($c, true), $borders_color); //tint if not default button color
    background-image: image($c);
    @include _shadows($_button_shadow);
  }

  @else if $t==hover {
  //
  // hovered button
  //
    transition: $button_transition;
    color: $tc;
    $_hover_border_color: if($c != $_default_button_c, _border_color($c), $borders_color);
    border-color: lighten($_hover_border_color, 5%);
    border-top-color: lighten($color: $_hover_border_color, $amount: 10%);
    border-bottom-color: $_hover_border_color;
    @if $variant == 'light' {
      background-image: image($c);
      @include _shadows($_button_shadow);
    }
    @else {
      background-image: image($c);
      @include _shadows($_button_shadow);
    }
  }

  @else if $t==active {
  //
  // pushed button
  //
    transition: $button_transition;
    color: $tc;
    border-color: if($c != $_default_button_c, _border_color($c), $borders_color);
    background-image: if($variant == 'light', image(darken($c, 14%)), image(darken($c, 9%)));
    box-shadow: none;
  }

  @else if $t==checked-hover {
  //
  // pushed togglebutton hover
  //
    transition: $button_transition;
    color: $tc;
    border-color: if($c != $_default_button_c, _border_color($c), $borders_color);
    background-image: if($variant == 'light', image(darken($c, 18%)), image(darken($c, 12%)));
    box-shadow: none;
  }

  @else if $t==checked-active {
  //
  // pushed togglebutton pushed further :)
  //
    transition: $button_transition;
    color: $tc;
    border-color: if($c != $_default_button_c, _border_color($c), $borders_color);
    background-image: if($variant == 'light', image(darken($c, 22%)), image(darken($c, 14%)));
    box-shadow: none;
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    transition: $button_transition;
    $_bg: if($c != $_default_button_c, mix($c, $base_color, 85%), $insensitive_bg_color);

    color: if($tc != $fg_color, mix($tc, $_bg, 50%), $insensitive_fg_color);
    border-color: if($c != $_default_button_c, _border_color($c), $insensitive_borders_color);
    background-image: image($_bg);
  }

  @else if $t==insensitive-active {
  //
  // insensitive pushed button
  //
    transition: $button_transition;
    $_bg: if($variant == 'light', darken(mix($c, $base_color, 85%), 8%), darken(mix($c, $base_color, 85%), 6%));
    $_bc: if($c != $_default_button_c, _border_color($c), $insensitive_borders_color);

    color: if($c != $_default_button_c, mix($tc, $_bg, 60%), $insensitive_fg_color);
    border-color: $_bc;
    background-image: image($_bg);
    box-shadow: none;
  }

  @else if $t==backdrop {
  //
  // backdrop button
  //
    transition: $button_transition;
    $_bg: if($c != $_default_button_c, $c, $backdrop_bg_color);
    $_bc: if($variant == 'light', $c, _border_color($c));

    color: if($tc != $fg_color, mix($tc, $_bg, 80%), $backdrop_fg_color);
    border-color: if($c != $_default_button_c, $_bc, $backdrop_borders_color);
    background-image: image($_bg);
    box-shadow: none;
  }

  @else if $t==backdrop-active {
  //
  // backdrop pushed button
  //
    transition: $button_transition;
    $_bg: if($variant == 'light', darken(mix($c, $base_color, 85%), 8%), darken(mix($c, $base_color, 85%), 4%));
    $_bc: if($variant == 'light', $_bg ,_border_color($c));

    color: if($tc != $fg_color, mix($tc, $_bg, 80%), $backdrop_fg_color);
    border-color: if($c != $_default_button_c, $_bc, $backdrop_borders_color);
    background-image: image($_bg);
    box-shadow: none;
  }

  @else if $t==backdrop-insensitive {
  //
  // backdrop insensitive button
  //
    transition: $button_transition;

    $_bg: if($c != $_default_button_c, mix($c, $base_color, 85%), $insensitive_bg_color);
    $_bc: if($variant == 'light', $_bg,_border_color($c));

    color: if($c != $_default_button_c, mix($tc, $_bg, 35%), $backdrop_insensitive_color);
    border-color: if($c != $_default_button_c, $_bc, $backdrop_borders_color);
    background-image: image($_bg);
    box-shadow: none;
  }

  @else if $t==backdrop-insensitive-active {
  //
  // backdrop insensitive pushed button
  //
    transition: $button_transition;

    $_bg: if($variant == 'light', darken(mix($c, $base_color, 85%), 8%), darken(mix($c, $base_color, 85%), 4%));
    $_bc: if($variant == 'light', $_bg, _border_color($c));

    color: if($c != $_default_button_c, mix($tc, $_bg, 35%), $backdrop_insensitive_color);
    border-color: if($c != $_default_button_c, $_bc, $backdrop_borders_color);
    background-image: image($_bg);
    box-shadow: none;
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    transition: $button_transition;
    $_bg: if($c != $_default_button_c, transparentize($c, 0.5), $osd_bg_color);

    color: $osd_fg_color;
    outline-color: if($c != $_default_button_c, $alt_focus_border_color, $focus_border_color);
    border-color: $osd_borders_color;
    background-color: transparent;
    background-image: image($_bg);
    background-clip: padding-box;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    transition: $button_transition;
    $_bg: if($c != $_default_button_c, transparentize($c, 0.3), darken($osd_bg_color, 10%));

    color: white;
    border-color: $osd_borders_color;
    background-color: transparent;
    background-image: image($_bg);
    background-clip: padding-box;
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    transition: $button_transition;
    $_bg: if($c != $_default_button_c, $c, darken($osd_bg_color, 20%));

    color: white;
    border-color: $osd_borders_color;
    background-color: transparent;
    background-image: image($_bg);
    background-clip: padding-box;
    box-shadow: none;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    transition: $button_transition;
    color: $osd_insensitive_fg_color;
    border-color: $osd_borders_color;
    background-color: transparent;
    background-image: image($osd_insensitive_bg_color);
    background-clip: padding-box;
  }

  @else if $t==osd-backdrop {
  //
  // backdrop osd button
  //
    transition: $button_transition;
    $_bg: if($c != $_default_button_c, transparentize($c, 0.5), $osd_bg_color);

    color: $osd_fg_color;
    border-color: $osd_borders_color;
    background-color: transparent;
    background-image: image($_bg);
    background-clip: padding-box;
  }

  @else if $t==undecorated {
  //
  // reset
  //
    border-color: transparent;
    background-color: transparent;
    background-image: none;
    box-shadow: none;
  }
  @else if $t==undecorated-hover {
    border-color: transparent;
    background-image: none;
    box-shadow: none;
    @if $variant == 'light' {
      background-color: darken($c,14%);
    } @else {
      background-color: darken($c,1%);
    }
  }
  @else if $t==undecorated-active {
    border-color: transparent;
    background-image: none;
    box-shadow: none;
    @if $variant == 'light' {
      background-color: darken($c,20%);
    }
    @else {
      background-color: darken($c,5%);
    }
  }
}
