| 85 | } |
| 86 | |
| 87 | cairo_surface_t*decoration_theme_t::get_button_surface(button_type_t button, |
| 88 | const button_state_t& state) const |
| 89 | { |
| 90 | cairo_surface_t *button_surface = cairo_image_surface_create( |
| 91 | CAIRO_FORMAT_ARGB32, state.width, state.height); |
| 92 | |
| 93 | auto cr = cairo_create(button_surface); |
| 94 | cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST); |
| 95 | |
| 96 | /* Clear the button background */ |
| 97 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
| 98 | cairo_set_source_rgba(cr, 0, 0, 0, 0); |
| 99 | cairo_rectangle(cr, 0, 0, state.width, state.height); |
| 100 | cairo_fill(cr); |
| 101 | |
| 102 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
| 103 | |
| 104 | /** A gray that looks good on light and dark themes */ |
| 105 | color_t base = {0.60, 0.60, 0.63, 0.36}; |
| 106 | |
| 107 | /** |
| 108 | * We just need the alpha component. |
| 109 | * r == g == b == 0.0 will be directly set |
| 110 | */ |
| 111 | double line = 0.27; |
| 112 | double hover = 0.27; |
| 113 | |
| 114 | /** Coloured base on hover/press. Don't compare float to 0 */ |
| 115 | if (fabs(state.hover_progress) > 1e-3) |
| 116 | { |
| 117 | switch (button) |
| 118 | { |
| 119 | case BUTTON_CLOSE: |
| 120 | base = {242.0 / 255.0, 80.0 / 255.0, 86.0 / 255.0, 0.63}; |
| 121 | break; |
| 122 | |
| 123 | case BUTTON_TOGGLE_MAXIMIZE: |
| 124 | base = {57.0 / 255.0, 234.0 / 255.0, 73.0 / 255.0, 0.63}; |
| 125 | break; |
| 126 | |
| 127 | case BUTTON_MINIMIZE: |
| 128 | base = {250.0 / 255.0, 198.0 / 255.0, 54.0 / 255.0, 0.63}; |
| 129 | break; |
| 130 | |
| 131 | default: |
| 132 | assert(false); |
| 133 | } |
| 134 | |
| 135 | line *= 2.0; |
| 136 | } |
| 137 | |
| 138 | /** Draw the base */ |
| 139 | cairo_set_source_rgba(cr, |
| 140 | base.r + 0.0 * state.hover_progress, |
| 141 | base.g + 0.0 * state.hover_progress, |
| 142 | base.b + 0.0 * state.hover_progress, |
| 143 | base.a + hover * state.hover_progress); |
| 144 | cairo_arc(cr, state.width / 2, state.height / 2, |