Another take on menu's. This uses the hosting menu scroll view container as a menuba...
[chromium-blink-merge.git] / app / multi_animation.h
blob77f5f4c3fec80907c0dc5dff9223eb17b1406bb6
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef APP_MULTI_ANIMATION_H_
6 #define APP_MULTI_ANIMATION_H_
7 #pragma once
9 #include <vector>
11 #include "app/animation.h"
12 #include "app/tween.h"
14 // MultiAnimation is an animation that consists of a number of sub animations.
15 // To create a MultiAnimation pass in the parts, invoke Start() and the delegate
16 // is notified as the animation progresses. MultiAnimation runs until Stop is
17 // invoked.
18 class MultiAnimation : public Animation {
19 public:
20 // Defines part of the animation. Each part consists of the following:
22 // time_ms: the time of the part.
23 // start_time_ms: the amount of time to offset this part by when calculating
24 // the percented completed.
25 // end_time_ms: the end time used to calculate the percentange completed.
27 // In most cases |start_time_ms| = 0 and |end_time_ms| = |time_ms|. But you
28 // can adjust the start/end for different effects. For example, to run a part
29 // for 200ms with a % between .25 and .75 use the following three values: 200,
30 // 100, 400.
31 struct Part {
32 Part() : time_ms(0), start_time_ms(0), end_time_ms(0), type(Tween::ZERO) {}
33 Part(int time_ms, Tween::Type type)
34 : time_ms(time_ms),
35 start_time_ms(0),
36 end_time_ms(time_ms),
37 type(type) {}
39 int time_ms;
40 int start_time_ms;
41 int end_time_ms;
42 Tween::Type type;
45 typedef std::vector<Part> Parts;
47 explicit MultiAnimation(const Parts& parts);
49 // Returns the current value. The current value for a MultiAnimation is
50 // determined from the tween type of the current part.
51 virtual double GetCurrentValue() const { return current_value_; }
53 // Returns the index of the current part.
54 size_t current_part_index() const { return current_part_index_; }
56 protected:
57 // Animation overrides.
58 virtual void Step(base::TimeTicks time_now);
60 private:
61 // Returns the part containing the specified time. |time_ms| is reset to be
62 // relative to the part containing the time and |part_index| the index of the
63 // part.
64 const Part& GetPart(int* time_ms, size_t* part_index);
66 // The parts that make up the animation.
67 const Parts parts_;
69 // Total time of all the parts.
70 const int cycle_time_ms_;
72 // Current value for the animation.
73 double current_value_;
75 // Index of the current part.
76 size_t current_part_index_;
78 DISALLOW_COPY_AND_ASSIGN(MultiAnimation);
81 #endif // APP_MULTI_ANIMATION_H_