// Drawing mixins

// generic drawing of more complex things

// function to convert px to em
@function to_em($input, $base: 16px) {
  // multiplied and divided by 1000 to make up for round() shortcoming
  $em_value: ($input / $base) * 1.091 * 1000;
  @return round($em_value) / 1000 * 1em;
}

// Mixin to convert provided font size in pt to em units
@mixin fontsize($size, $base: 16px, $unit: pt) {
  // if pt, convert into unitless value with the assumption: 1pt = 1.091px
  $adjusted_size: if($unit ==pt, $size * 1.091, $size) * 1000;
  $rounded_size: round($adjusted_size / $base) / 1000;
  font-size: $rounded_size * 1em;
  // font-size: round($size) + pt;
}

// Entries

@mixin entry($t, $dark:false) {
//
// Entries drawing function
//
  //@extend %reset_style;

  @if $t==normal {
    color: $text_color;
    background-color: $entry_bg;
    border: 1px solid $entry_border;
    box-shadow: inset 0 2px 4px transparentize($entry_bg, 0.95);
  }

  @if $t==focus {
    color: $fg_color;
    background-color: $entry_bg;
    border: 1px solid $selected_bg_color;
    box-shadow: inset 0 2px 4px transparentize($entry_bg, 0.95);
  }

  @if $t==insensitive {
    color: $insensitive_fg_color;
    background-color: mix($entry_bg, $bg_color, 55%);
    border-color: 1px solid mix($entry_border, $bg_color, 55%);
    box-shadow: inset 0 2px 4px transparentize(mix($entry_bg, $bg_color, 55%), 0.95);
  }

  @if $t==osd {
    color: $osd_fg_color;
    background-color: $osd_entry_bg;
    border: 1px solid $osd_entry_border;
    box-shadow: inset 0 2px 4px transparentize(black, 0.95);
  }

  @if $t==osd-focus {
    color: $selected_fg_color;
    background-color: $selected_bg_color;
    border: 1px solid $selected_bg_color;
    box-shadow: inset 0 2px 4px transparentize(black, 0.95);
  }

  @if $t==osd-insensitive {
    color: transparentize($osd_fg_color, 0.45);
    background-color: transparentize($osd_entry_bg, 0.15);
    border: 1px solid $osd_entry_border;
    box-shadow: inset 0 2px 4px transparentize(black, 0.95);
  }
}

// Buttons

@mixin button($t, $c: $button_bg, $style: null) {
//
// Button drawing function
//
  //@extend %reset_style;

  text-shadow: none;
  $button_border: $borders_color;
  $button_focus_border: $selected_bg_color;
  $button_active_bg_color: $selected_bg_color;
  $button_active_fg_color: $selected_fg_color;

  @if $style == 'default' {
    $button_border: lighten($c, 6%);
    $button_focus_border: lighten($c, 10%);
    $button_active_bg_color: lighten($c, 20%);
    $button_active_fg_color: $fg_color;
  }

  @if $style == 'flat' {
    $button_border: transparent;
    $button_focus_border: transparent;
  }

  @if $t==normal {
  //
  // normal button
  //
    color: $fg_color;
    background-color: $c;
    border: 1px solid $button_border;
    box-shadow: none;

    @if $style == 'flat' {
      background-color: transparent;
    }
  }

  @else if $t==focus {
  //
  // focused button
  //
    color: $fg_color;
    background-color: $c;
    border: 1px solid $button_focus_border;
    box-shadow: none;
  }

  @else if $t==focus-hover {
  //
  // focused button
  //
    color: $fg_color;
    background-color: $c;
    border: 1px solid $button_focus_border;
    box-shadow: none;
  }

  @else if $t==hover {
  //
  // hovered button
  //
    color: $fg_color;
    background-color: lighten($c, 5%);
    border: 1px solid $button_border;
    box-shadow: none;
  }

  @else if $t==active {
  //
  // pushed button
  //
    color: $button_active_fg_color;
    background-color: $button_active_bg_color;
    border: 1px solid $button_active_bg_color;
    box-shadow: none;
  }

  @else if $t==checked {
  //
  // checked button
  //
    color: $button_active_fg_color;
    background-color: $button_active_bg_color;
    border: 1px solid $button_active_bg_color;
    box-shadow: none;
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    color: $insensitive_fg_color;
    border: 1px solid transparentize($button_border, 0.45);
    background-color: transparentize($c, 0.45);
    box-shadow: none;
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    color: $osd_fg_color;
    border: 1px solid $osd_button_border;
    background-color: $osd_button_bg;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    color: $osd_fg_color;
    border: 1px solid $osd_button_border;
    background-color: opacify(lighten($osd_button_bg, 7%), 0.1);
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    color: $selected_fg_color;
    border: 1px solid $selected_bg_color;
    background-color: $selected_bg_color;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    color: $osd_insensitive_fg_color;
    border: 1px solid $osd_button_border;
    background-color: transparentize($osd_button_bg, 0.15);
  }
}
