Skip to content

Commit

Permalink
Make border drawing outside of window by set a negative border width
Browse files Browse the repository at this point in the history
  • Loading branch information
yilozt committed Sep 14, 2022
1 parent 78e5ed6 commit 662aee1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
22 changes: 0 additions & 22 deletions .vscode/settings.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
<default>false</default>
</key>

<key name="border-width" type="u">
<key name="border-width" type="i">
<summary>Border width for rounded corners window</summary>
<range min="-40" max="40"/>
<default>0</default>
</key>

Expand Down
21 changes: 16 additions & 5 deletions src/effect/shader/rounded_corners.frag
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,22 @@ void main() {
vec2 texture_coord = cogl_tex_coord0_in.xy / pixel_step;

float outer_alpha = rounded_rect_coverage(texture_coord, bounds, radius, exponent);
if(border_width > 0.1) {
float inner_alpha = rounded_rect_coverage(texture_coord, inner_bounds, inner_radius, exponent);
float border_alpha = clamp(outer_alpha - inner_alpha, 0.0, 1.0) * cogl_color_out.a;

cogl_color_out = mix(cogl_color_out, vec4(border_color.rgb, 1.0), border_alpha * border_color.a);
// Clip window corners first
cogl_color_out.a *= outer_alpha;

// Draw border later
if(border_width > 0.9 || border_width < -0.9) {
float inner_alpha = rounded_rect_coverage(texture_coord, inner_bounds, inner_radius, exponent);
float border_alpha = clamp(abs(outer_alpha - inner_alpha), 0.0, 1.0);

if (border_width > 0.9) {
// If border is drawing inside window, mix color of window
cogl_color_out = mix(cogl_color_out, vec4(border_color.rgb, 1.0), border_alpha * border_color.a);
cogl_color_out.a *= outer_alpha;
} else {
// If border is drawing outside window, just draw border
cogl_color_out = mix(cogl_color_out, border_color, border_alpha);
}
}
cogl_color_out.a *= outer_alpha;
}
4 changes: 2 additions & 2 deletions src/preferences/pages/general.ui
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@
</template>

<object class="GtkAdjustment" id="border_width_ajustment">
<property name="lower">0</property>
<property name="upper">40</property>
<property name="lower">-20</property>
<property name="upper">20</property>
<property name="page-increment">1</property>
<property name="step-increment">1</property>
</object>
Expand Down

0 comments on commit 662aee1

Please sign in to comment.