annotate CollidoscopeApp/include/DrawInfo.h @ 3:7fb593d53361

added comments
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 12 Jul 2016 18:29:38 +0200
parents 02467299402e
children 75b744078d66
rev   line source
f@0 1 #pragma once
f@0 2
f@0 3 #include "cinder/Area.h"
f@0 4
f@3 5 /**
f@3 6 * The DrawInfo class holds size information for drawing the waves in the screen.
f@3 7 * Every time the screen is resized the draw info is updated with the new information about the window size.
f@3 8 *
f@3 9 * Every wave has its own drawInfo.
f@3 10 *
f@3 11 */
f@0 12 class DrawInfo
f@0 13 {
f@0 14 public:
f@0 15
f@3 16 /**
f@3 17 * Constructor. Takes the index of the wave as argument.
f@3 18 */
f@0 19 DrawInfo( size_t waveIndex ):
f@0 20 mWaveIndex( waveIndex ),
f@0 21 mWindowWidth(0),
f@0 22 mWindowHeight(0),
f@0 23 mSelectionBarHeight(0),
f@0 24 mShrinkFactor(1)
f@0 25 {}
f@0 26
f@3 27 /**
f@3 28 * Reset this DrawInfo using the new bounding area for the wave. \a shrinkFactor
f@3 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.
f@3 30 */
f@0 31 void reset( const ci::Area &bounds, float shrinkFactor )
f@0 32 {
f@0 33 mWindowWidth = bounds.getWidth();
f@0 34 mWindowHeight = bounds.getHeight();
f@0 35 mSelectionBarHeight = mWindowHeight / NUM_WAVES;
f@0 36 mShrinkFactor = shrinkFactor;
f@0 37 }
f@0 38
f@3 39 /**
f@3 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.
f@3 41 *
f@3 42 */
f@0 43 float audioToHeigt(float audioSample) const {
f@0 44 /* clip into range [-1.1] */
f@0 45 if (audioSample < -1.0f) {
f@0 46 audioSample = -1.0f;
f@0 47 }
f@0 48 else if ( audioSample > 1.0f ){
f@0 49 audioSample = 1.0f;
f@0 50 }
f@0 51
f@0 52 /* map from [-1,1] to [0,1] */
f@0 53 float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1)
f@0 54
f@0 55 /* get bottom and add the scaled height */
f@0 56 return ratio * mSelectionBarHeight; //remove bounds.getY1() bound only needed for size of tier
f@0 57 }
f@0 58
f@0 59 float getMaxChunkHeight() const
f@0 60 {
f@0 61 return mSelectionBarHeight * mShrinkFactor;
f@0 62 }
f@0 63
f@0 64 float getSelectionBarHeight() const
f@0 65 {
f@0 66 return mSelectionBarHeight;
f@0 67 }
f@0 68
f@3 69 /**
f@3 70 * Returns the center position on the y axis of this DrawInfo's the bounding area.
f@3 71 */
f@0 72 int32_t getWaveCenterY() const
f@0 73 {
f@0 74 if ( mWaveIndex == 0 )
f@0 75 return mWindowHeight * 0.75f + 1;
f@0 76 else
f@0 77 return mWindowHeight / (NUM_WAVES * 2);
f@0 78 }
f@0 79
f@3 80 /**
f@3 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.
f@3 82 */
f@0 83 int flipY(int y) const
f@0 84 {
f@0 85 if ( mWaveIndex == 0)
f@3 86 return mWindowHeight - y;
f@0 87 else
f@3 88 return y;
f@0 89 }
f@0 90
f@3 91 /**
f@3 92 * Returns x. not used at he moment.
f@3 93 *
f@3 94 */
f@0 95 int flipX(int x) const
f@0 96 {
f@0 97 return x;
f@0 98 }
f@0 99
f@0 100
f@0 101 // how much the wave is shrunk on the y axis with respect to the wave's tier
f@0 102 float getShrinkFactor() const
f@0 103 {
f@0 104 return mShrinkFactor;
f@0 105 }
f@0 106
f@0 107 int32_t getWindowWidth() const
f@0 108 {
f@0 109 return mWindowWidth;
f@0 110 }
f@0 111
f@0 112 int32_t getWindowHeight() const
f@0 113 {
f@0 114 return mWindowHeight;
f@0 115 }
f@0 116
f@3 117 /**
f@3 118 * Draw infos cannot be copied and should be passed as const reference.
f@3 119 */
f@0 120 DrawInfo( const DrawInfo &original ) = delete;
f@0 121 DrawInfo & operator=( const DrawInfo &original ) = delete;
f@0 122
f@0 123 private:
f@0 124 const size_t mWaveIndex;
f@0 125
f@0 126 int32_t mWindowHeight;
f@0 127 int32_t mWindowWidth;
f@0 128 int32_t mSelectionBarHeight;
f@0 129
f@0 130 float mShrinkFactor;
f@0 131
f@0 132 };