Add fade-in / fade-out

This commit is contained in:
Adam Bieńkowski 2019-08-05 23:04:14 +02:00
parent bd347ef9ef
commit 3f843fa8c4
2 changed files with 43 additions and 4 deletions

View File

@ -545,7 +545,7 @@ namespace Gala
get_parent ().remove_child (this); get_parent ().remove_child (this);
unowned WorkspaceInsertThumb inserter = (WorkspaceInsertThumb) destination; unowned WorkspaceInsertThumb inserter = (WorkspaceInsertThumb) destination;
workspace.get_screen ().reorder_workspace (workspace, inserter.workspace_index); // workspace.get_screen ().reorder_workspace (workspace, inserter.workspace_index);
restore_group (); restore_group ();
} else { } else {

View File

@ -327,6 +327,9 @@ namespace Gala
return false; return false;
} }
float greyscale_opacity = 0.0f;
uint fade_in_id = 0U;
uint fade_out_id = 0U;
void toggle_greyscale () void toggle_greyscale ()
{ {
if (greyscale_effect == null) { if (greyscale_effect == null) {
@ -334,22 +337,58 @@ namespace Gala
greyscale_effect.set_name ("greyscale"); greyscale_effect.set_name ("greyscale");
greyscale_effect.set_shader_source (""" greyscale_effect.set_shader_source ("""
uniform sampler2D texture; uniform sampler2D texture;
uniform float opacity;
void main () { void main () {
vec4 color = texture2D (texture, cogl_tex_coord0_in.xy); vec4 color = texture2D (texture, cogl_tex_coord0_in.xy);
float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114)); float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
cogl_color_out = vec4(vec3(gray), 1.0); cogl_color_out = mix (color, vec4(vec3(gray), 1.0), opacity);
} }
"""); """);
greyscale_effect.set_uniform_value ("texture", 0); greyscale_effect.set_uniform_value ("texture", 0);
greyscale_effect.set_uniform_value ("opacity", 0.0f);
} }
const uint FADE_TIMEOUT = 300 / 100;
if (AppearanceSettings.get_default ().greyscale) { if (AppearanceSettings.get_default ().greyscale) {
if (ui_group.get_effect ("greyscale") == null) { bool animates_out = fade_out_id > 0U;
if (ui_group.get_effect ("greyscale") == null || animates_out) {
ui_group.add_effect (greyscale_effect); ui_group.add_effect (greyscale_effect);
if (animates_out) {
Source.remove (fade_out_id);
}
fade_in_id = Timeout.add (FADE_TIMEOUT, () => {
greyscale_effect.set_uniform_value ("opacity", greyscale_opacity);
greyscale_opacity += 0.01f;
bool stop = greyscale_opacity > 1.0f;
if (stop) {
fade_in_id = 0U;
}
return !stop;
});
} }
} else { } else {
if (ui_group.get_effect ("greyscale") != null) { if (ui_group.get_effect ("greyscale") != null) {
ui_group.remove_effect (greyscale_effect); if (fade_in_id > 0U) {
Source.remove (fade_in_id);
}
fade_out_id = Timeout.add (FADE_TIMEOUT, () => {
greyscale_opacity -= 0.01f;
greyscale_effect.set_uniform_value ("opacity", greyscale_opacity);
bool stop = greyscale_opacity <= 0.0f;
if (stop) {
ui_group.remove_effect (greyscale_effect);
fade_out_id = 0U;
}
return !stop;
});
} }
} }
} }