To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / CollidoscopeApp / include / DrawInfo.h @ 4:ab6db404403a

History | View | Annotate | Download (3.23 KB)

1
#pragma once
2

    
3
#include "cinder/Area.h"
4

    
5
/**
6
 * The DrawInfo class holds size information for drawing the waves in the screen. 
7
 * Every time the screen is resized the draw info is updated with the new information about the window size.
8
 *
9
 * Every wave has its own drawInfo.
10
 *
11
 */ 
12
class DrawInfo
13
{
14
public:
15

    
16
    /**
17
     * Constructor. Takes the index of the wave as argument.
18
     */ 
19
    DrawInfo( size_t waveIndex ):
20
        mWaveIndex( waveIndex ),
21
        mWindowWidth(0),
22
        mWindowHeight(0),
23
        mSelectionBarHeight(0),
24
        mShrinkFactor(1)
25
    {}
26

    
27
    /**
28
     * Reset this DrawInfo using the new bounding area for the wave.  \a shrinkFactor 
29
     * makes the wave shrink on the y axis with respect to the area. A factor 1 makes the wave as big as the area, whereas a factor >1 makes it shrink.
30
     */ 
31
    void reset( const ci::Area &bounds, float shrinkFactor )
32
    {
33
        mWindowWidth = bounds.getWidth();
34
        mWindowHeight = bounds.getHeight();
35
        mSelectionBarHeight = mWindowHeight / NUM_WAVES;
36
        mShrinkFactor = shrinkFactor;
37
    }
38

    
39
    /**
40
     * Maps a value in the audio space [-1.0, 1.0] to a position on the y axis of this DrawInf's bounding area.
41
     *
42
     */ 
43
        float audioToHeigt(float audioSample) const {
44
        /* clip into range [-1.1] */
45
        if (audioSample < -1.0f) {
46
            audioSample = -1.0f;
47
        }
48
        else if ( audioSample > 1.0f ){
49
            audioSample = 1.0f;
50
        }
51

    
52
        /* map from [-1,1] to [0,1] */
53
                float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1) 
54

    
55
                /* get bottom and add the scaled height */
56
        return ratio * mSelectionBarHeight; //remove  bounds.getY1() bound only needed for size of tier
57
        }
58

    
59
    float getMaxChunkHeight() const 
60
    {
61
        return mSelectionBarHeight * mShrinkFactor;
62
    }
63

    
64
    float getSelectionBarHeight() const
65
    {
66
        return mSelectionBarHeight;
67
    }
68

    
69
    /**
70
     * Returns the center position on the y axis of this DrawInfo's the bounding area. 
71
     */ 
72
    int32_t getWaveCenterY() const
73
    {
74
        if ( mWaveIndex == 0 )
75
            return mWindowHeight * 0.75f + 1;
76
        else
77
            return mWindowHeight / (NUM_WAVES * 2);
78
    }
79

    
80
    /**
81
     * Flips y according to the index of the wave. It is needed because the second wave in collidoscope is upside down from the orientation oftthe screen.
82
     */ 
83
        int flipY(int y) const 
84
    {
85
        if ( mWaveIndex == 0)
86
                    return mWindowHeight - y;
87
        else
88
            return y;
89
        }
90

    
91
    /**
92
     * Returns x. not used at he moment.
93
     *
94
     */ 
95
        int flipX(int x) const
96
    {
97
        return x;
98
        }
99

    
100

    
101
    // how much the wave is shrunk on the y axis with respect to the wave's tier 
102
    float getShrinkFactor() const 
103
    {
104
        return mShrinkFactor;
105
    }
106

    
107
    int32_t getWindowWidth() const
108
    {
109
        return mWindowWidth;
110
    }
111

    
112
    int32_t getWindowHeight() const
113
    {
114
        return mWindowHeight;
115
    }
116

    
117
    /**
118
     * Draw infos cannot be copied and should be passed as const reference.
119
     */ 
120
    DrawInfo( const DrawInfo &original ) = delete;
121
    DrawInfo & operator=( const DrawInfo &original ) = delete;
122

    
123
private:
124
    const size_t mWaveIndex;
125

    
126
    int32_t mWindowHeight;
127
    int32_t mWindowWidth;
128
    int32_t mSelectionBarHeight;
129

    
130
    float mShrinkFactor;
131

    
132
};