summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/tabs/TabCurve.java
blob: 0b6a30d7a05b7cc7b41de80296ebd67dfd543136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.tabs;

import android.graphics.Path;

/**
 * Utility methods to draws Firefox's tab curve shape.
 */
public class TabCurve {

    public enum Direction {
        LEFT(-1),
        RIGHT(1);

        private final int value;

        private Direction(int value) {
            this.value = value;
        }
    }

    // Curve's aspect ratio
    private static final float ASPECT_RATIO = 0.729f;

    // Width multipliers
    private static final float W_M1 = 0.343f;
    private static final float W_M2 = 0.514f;
    private static final float W_M3 = 0.49f;
    private static final float W_M4 = 0.545f;
    private static final float W_M5 = 0.723f;

    // Height multipliers
    private static final float H_M1 = 0.25f;
    private static final float H_M2 = 0.5f;
    private static final float H_M3 = 0.72f;
    private static final float H_M4 = 0.961f;

    private TabCurve() {
    }

    public static float getWidthForHeight(float height) {
        return (int) (height * ASPECT_RATIO);
    }

    public static void drawFromTop(Path path, float from, float height, Direction dir) {
        final float width = getWidthForHeight(height);

        path.cubicTo(from + width * W_M1 * dir.value, 0.0f,
                     from + width * W_M3 * dir.value, height * H_M1,
                     from + width * W_M2 * dir.value, height * H_M2);
        path.cubicTo(from + width * W_M4 * dir.value, height * H_M3,
                     from + width * W_M5 * dir.value, height * H_M4,
                     from + width * dir.value, height);
    }

    public static void drawFromBottom(Path path, float from, float height, Direction dir) {
        final float width = getWidthForHeight(height);

        path.cubicTo(from + width * (1f - W_M5) * dir.value, height * H_M4,
                     from + width * (1f - W_M4) * dir.value, height * H_M3,
                     from + width * (1f - W_M2) * dir.value, height * H_M2);
        path.cubicTo(from + width * (1f - W_M3) * dir.value, height * H_M1,
                     from + width * (1f - W_M1) * dir.value, 0.0f,
                     from + width * dir.value, 0.0f);
    }
}