mirror of
https://github.com/elementary/gala.git
synced 2024-09-11 15:15:39 +03:00
IconGroup: Improve animation (#1653)
This commit is contained in:
parent
66477d16af
commit
7af203c820
@ -15,7 +15,7 @@ namespace Gala {
|
||||
|
||||
private const int PLUS_SIZE = 8;
|
||||
private const int PLUS_WIDTH = 24;
|
||||
|
||||
private const int BACKDROP_ABSOLUTE_OPACITY = 40;
|
||||
private const int CLOSE_BUTTON_SIZE = 36;
|
||||
private const int SHOW_CLOSE_BUTTON_DELAY = 200;
|
||||
|
||||
@ -25,11 +25,11 @@ namespace Gala {
|
||||
*/
|
||||
public signal void selected ();
|
||||
|
||||
private uint8 _backdrop_opacity = 0;
|
||||
private float _backdrop_opacity = 0.0f;
|
||||
/**
|
||||
* The opacity of the backdrop/highlight. Set by the active property setter.
|
||||
* The opacity of the backdrop/highlight.
|
||||
*/
|
||||
protected uint8 backdrop_opacity {
|
||||
public float backdrop_opacity {
|
||||
get {
|
||||
return _backdrop_opacity;
|
||||
}
|
||||
@ -39,41 +39,6 @@ namespace Gala {
|
||||
}
|
||||
}
|
||||
|
||||
private bool _active = false;
|
||||
/**
|
||||
* Fades in/out the backdrop/highlight
|
||||
*/
|
||||
public bool active {
|
||||
get {
|
||||
return _active;
|
||||
}
|
||||
set {
|
||||
if (_active == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
_active = value;
|
||||
|
||||
if (get_stage () == null) {
|
||||
backdrop_opacity = 40;
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_transition ("backdrop-opacity") != null) {
|
||||
remove_transition ("backdrop-opacity");
|
||||
}
|
||||
|
||||
var transition = new Clutter.PropertyTransition ("backdrop-opacity") {
|
||||
duration = 300,
|
||||
remove_on_complete = true
|
||||
};
|
||||
transition.set_from_value (_active ? 0 : 40);
|
||||
transition.set_to_value (_active ? 40 : 0);
|
||||
|
||||
add_transition ("backdrop-opacity", transition);
|
||||
}
|
||||
}
|
||||
|
||||
private DragDropAction drag_action;
|
||||
|
||||
public WindowManager wm { get; construct; }
|
||||
@ -226,7 +191,7 @@ namespace Gala {
|
||||
* Override the paint handler to draw our backdrop if necessary
|
||||
*/
|
||||
public override void paint (Clutter.PaintContext context) {
|
||||
if (backdrop_opacity < 1 || drag_action.dragging) {
|
||||
if (backdrop_opacity == 0.0 || drag_action.dragging) {
|
||||
base.paint (context);
|
||||
return;
|
||||
}
|
||||
@ -235,11 +200,12 @@ namespace Gala {
|
||||
var x = (InternalUtils.scale_to_int (SIZE, scale_factor) - width) / 2;
|
||||
var y = -10;
|
||||
var height = InternalUtils.scale_to_int (WorkspaceClone.BOTTOM_OFFSET, scale_factor);
|
||||
var backdrop_opacity_int = (uint8) (BACKDROP_ABSOLUTE_OPACITY * backdrop_opacity);
|
||||
|
||||
Cogl.VertexP2T2C4 vertices[4];
|
||||
vertices[0] = { x, y + height, 0, 1, backdrop_opacity, backdrop_opacity, backdrop_opacity, backdrop_opacity };
|
||||
vertices[0] = { x, y + height, 0, 1, backdrop_opacity_int, backdrop_opacity_int, backdrop_opacity_int, backdrop_opacity_int };
|
||||
vertices[1] = { x, y, 0, 0, 0, 0, 0, 0 };
|
||||
vertices[2] = { x + width, y + height, 1, 1, backdrop_opacity, backdrop_opacity, backdrop_opacity, backdrop_opacity };
|
||||
vertices[2] = { x + width, y + height, 1, 1, backdrop_opacity_int, backdrop_opacity_int, backdrop_opacity_int, backdrop_opacity_int };
|
||||
vertices[3] = { x + width, y, 1, 0, 0, 0, 0, 0 };
|
||||
|
||||
var primitive = new Cogl.Primitive.p2t2c4 (context.get_framebuffer ().get_context (), Cogl.VerticesMode.TRIANGLE_STRIP, vertices);
|
||||
|
@ -291,20 +291,33 @@ namespace Gala {
|
||||
var scale = display.get_monitor_scale (display.get_primary_monitor ());
|
||||
var nudge_gap = InternalUtils.scale_to_int ((int)WindowManagerGala.NUDGE_GAP, scale);
|
||||
|
||||
unowned IconGroup active_icon_group = null;
|
||||
unowned IconGroup target_icon_group = null;
|
||||
|
||||
if (is_nudge_animation) {
|
||||
var workspaces_geometry = InternalUtils.get_workspaces_geometry (display);
|
||||
target_x = initial_x + (workspaces_geometry.width * -relative_dir);
|
||||
} else {
|
||||
foreach (var child in workspaces.get_children ()) {
|
||||
unowned WorkspaceClone workspace_clone = (WorkspaceClone) child;
|
||||
foreach (unowned var child in workspaces.get_children ()) {
|
||||
unowned var workspace_clone = (WorkspaceClone) child;
|
||||
var index = workspace_clone.workspace.index ();
|
||||
|
||||
if (index == target_workspace_index) {
|
||||
target_icon_group = workspace_clone.icon_group;
|
||||
target_x = -workspace_clone.multitasking_view_x ();
|
||||
break;
|
||||
} else if (index == active_workspace_index) {
|
||||
active_icon_group = workspace_clone.icon_group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (active_icon_group.get_transition ("backdrop-opacity") != null) {
|
||||
active_icon_group.remove_transition ("backdrop-opacity");
|
||||
}
|
||||
if (target_icon_group.get_transition ("backdrop-opacity") != null) {
|
||||
target_icon_group.remove_transition ("backdrop-opacity");
|
||||
}
|
||||
|
||||
debug ("Starting MultitaskingView switch workspace animation:");
|
||||
debug ("Active workspace index: %d", active_workspace_index);
|
||||
debug ("Target workspace index: %d", target_workspace_index);
|
||||
@ -315,12 +328,18 @@ namespace Gala {
|
||||
|
||||
GestureTracker.OnUpdate on_animation_update = (percentage) => {
|
||||
var x = GestureTracker.animation_value (initial_x, target_x, percentage, true);
|
||||
var icon_group_opacity = GestureTracker.animation_value (0.0f, 1.0f, percentage, false);
|
||||
|
||||
if (is_nudge_animation) {
|
||||
x = x.clamp (initial_x - nudge_gap, initial_x + nudge_gap);
|
||||
}
|
||||
|
||||
workspaces.x = x;
|
||||
|
||||
if (!is_nudge_animation) {
|
||||
active_icon_group.backdrop_opacity = 1.0f - icon_group_opacity;
|
||||
target_icon_group.backdrop_opacity = icon_group_opacity;
|
||||
}
|
||||
};
|
||||
|
||||
GestureTracker.OnEnd on_animation_end = (percentage, cancel_action, calculated_duration) => {
|
||||
@ -335,6 +354,25 @@ namespace Gala {
|
||||
workspaces.x = (is_nudge_animation || cancel_action) ? initial_x : target_x;
|
||||
workspaces.restore_easing_state ();
|
||||
|
||||
if (!is_nudge_animation) {
|
||||
var active_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
|
||||
duration = calculated_duration,
|
||||
remove_on_complete = true
|
||||
};
|
||||
active_transition.set_from_value (active_icon_group.backdrop_opacity);
|
||||
active_transition.set_to_value (0.0f);
|
||||
active_icon_group.add_transition ("backdrop-opacity", active_transition);
|
||||
|
||||
var target_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
|
||||
duration = calculated_duration,
|
||||
remove_on_complete = true
|
||||
};
|
||||
target_transition.set_from_value (target_icon_group.backdrop_opacity);
|
||||
target_transition.set_to_value (1.0f);
|
||||
target_icon_group.add_transition ("backdrop-opacity", target_transition);
|
||||
}
|
||||
|
||||
|
||||
workspaces.get_transition ("x").completed.connect (() => {
|
||||
workspace_gesture_tracker.enabled = true;
|
||||
|
||||
@ -364,16 +402,16 @@ namespace Gala {
|
||||
var active_index = manager.get_active_workspace ().index ();
|
||||
var active_x = 0.0f;
|
||||
|
||||
foreach (var child in workspaces.get_children ()) {
|
||||
unowned WorkspaceClone workspace_clone = (WorkspaceClone) child;
|
||||
foreach (unowned var child in workspaces.get_children ()) {
|
||||
unowned var workspace_clone = (WorkspaceClone) child;
|
||||
var index = workspace_clone.workspace.index ();
|
||||
var dest_x = workspace_clone.multitasking_view_x ();
|
||||
|
||||
if (index == active_index) {
|
||||
active_x = dest_x;
|
||||
workspace_clone.active = true;
|
||||
workspace_clone.icon_group.backdrop_opacity = 1.0f;
|
||||
} else {
|
||||
workspace_clone.active = false;
|
||||
workspace_clone.icon_group.backdrop_opacity = 0.0f;
|
||||
}
|
||||
|
||||
workspace_clone.save_easing_state ();
|
||||
|
@ -142,21 +142,6 @@ namespace Gala {
|
||||
public IconGroup icon_group { get; private set; }
|
||||
public WindowCloneContainer window_container { get; private set; }
|
||||
|
||||
private bool _active = false;
|
||||
/**
|
||||
* If this WorkspaceClone is currently the active one. Also sets the active
|
||||
* state on its IconGroup.
|
||||
*/
|
||||
public bool active {
|
||||
get {
|
||||
return _active;
|
||||
}
|
||||
set {
|
||||
_active = value;
|
||||
icon_group.active = value;
|
||||
}
|
||||
}
|
||||
|
||||
private float _scale_factor = 1.0f;
|
||||
public float scale_factor {
|
||||
get {
|
||||
|
Loading…
Reference in New Issue
Block a user