annotate CollidoscopeApp/include/DrawInfo.h @ 5:75b744078d66

added license
author Fiore Martin <f.martin@qmul.ac.uk>
date Wed, 13 Jul 2016 16:06:46 +0200
parents 7fb593d53361
children a4a336624f5a
rev   line source
f@5 1 /*
f@5 2
f@5 3 Copyright (C) 2016 Queen Mary University of London
f@5 4 Author: Fiore Martin
f@5 5
f@5 6 This file is part of Collidoscope.
f@5 7
f@5 8 Collidoscope is free software: you can redistribute it and/or modify
f@5 9 it under the terms of the GNU General Public License as published by
f@5 10 the Free Software Foundation, either version 3 of the License, or
f@5 11 (at your option) any later version.
f@5 12
f@5 13 This program is distributed in the hope that it will be useful,
f@5 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
f@5 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@5 16 GNU General Public License for more details.
f@5 17
f@5 18 You should have received a copy of the GNU General Public License
f@5 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
f@5 20 */
f@5 21
f@0 22 #pragma once
f@0 23
f@0 24 #include "cinder/Area.h"
f@0 25
f@3 26 /**
f@3 27 * The DrawInfo class holds size information for drawing the waves in the screen.
f@3 28 * Every time the screen is resized the draw info is updated with the new information about the window size.
f@3 29 *
f@3 30 * Every wave has its own drawInfo.
f@3 31 *
f@3 32 */
f@0 33 class DrawInfo
f@0 34 {
f@0 35 public:
f@0 36
f@3 37 /**
f@3 38 * Constructor. Takes the index of the wave as argument.
f@3 39 */
f@0 40 DrawInfo( size_t waveIndex ):
f@0 41 mWaveIndex( waveIndex ),
f@0 42 mWindowWidth(0),
f@0 43 mWindowHeight(0),
f@0 44 mSelectionBarHeight(0),
f@0 45 mShrinkFactor(1)
f@0 46 {}
f@0 47
f@3 48 /**
f@3 49 * Reset this DrawInfo using the new bounding area for the wave. \a shrinkFactor
f@3 50 * 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 51 */
f@0 52 void reset( const ci::Area &bounds, float shrinkFactor )
f@0 53 {
f@0 54 mWindowWidth = bounds.getWidth();
f@0 55 mWindowHeight = bounds.getHeight();
f@0 56 mSelectionBarHeight = mWindowHeight / NUM_WAVES;
f@0 57 mShrinkFactor = shrinkFactor;
f@0 58 }
f@0 59
f@3 60 /**
f@3 61 * 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 62 *
f@3 63 */
f@5 64 float audioToHeigt(float audioSample) const {
f@0 65 /* clip into range [-1.1] */
f@0 66 if (audioSample < -1.0f) {
f@0 67 audioSample = -1.0f;
f@0 68 }
f@0 69 else if ( audioSample > 1.0f ){
f@0 70 audioSample = 1.0f;
f@0 71 }
f@0 72
f@0 73 /* map from [-1,1] to [0,1] */
f@5 74 float ratio = (audioSample - (-1.0f)) * 0.5f; // 2 = 1 - (-1)
f@0 75
f@5 76 /* get bottom and add the scaled height */
f@0 77 return ratio * mSelectionBarHeight; //remove bounds.getY1() bound only needed for size of tier
f@5 78 }
f@0 79
f@0 80 float getMaxChunkHeight() const
f@0 81 {
f@0 82 return mSelectionBarHeight * mShrinkFactor;
f@0 83 }
f@0 84
f@0 85 float getSelectionBarHeight() const
f@0 86 {
f@0 87 return mSelectionBarHeight;
f@0 88 }
f@0 89
f@3 90 /**
f@3 91 * Returns the center position on the y axis of this DrawInfo's the bounding area.
f@3 92 */
f@0 93 int32_t getWaveCenterY() const
f@0 94 {
f@0 95 if ( mWaveIndex == 0 )
f@0 96 return mWindowHeight * 0.75f + 1;
f@0 97 else
f@0 98 return mWindowHeight / (NUM_WAVES * 2);
f@0 99 }
f@0 100
f@3 101 /**
f@3 102 * 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 103 */
f@5 104 int flipY(int y) const
f@0 105 {
f@0 106 if ( mWaveIndex == 0)
f@5 107 return mWindowHeight - y;
f@0 108 else
f@3 109 return y;
f@5 110 }
f@0 111
f@3 112 /**
f@3 113 * Returns x. not used at he moment.
f@3 114 *
f@3 115 */
f@5 116 int flipX(int x) const
f@0 117 {
f@0 118 return x;
f@5 119 }
f@0 120
f@0 121
f@0 122 // how much the wave is shrunk on the y axis with respect to the wave's tier
f@0 123 float getShrinkFactor() const
f@0 124 {
f@0 125 return mShrinkFactor;
f@0 126 }
f@0 127
f@0 128 int32_t getWindowWidth() const
f@0 129 {
f@0 130 return mWindowWidth;
f@0 131 }
f@0 132
f@0 133 int32_t getWindowHeight() const
f@0 134 {
f@0 135 return mWindowHeight;
f@0 136 }
f@0 137
f@3 138 /**
f@3 139 * Draw infos cannot be copied and should be passed as const reference.
f@3 140 */
f@0 141 DrawInfo( const DrawInfo &original ) = delete;
f@0 142 DrawInfo & operator=( const DrawInfo &original ) = delete;
f@0 143
f@0 144 private:
f@0 145 const size_t mWaveIndex;
f@0 146
f@0 147 int32_t mWindowHeight;
f@0 148 int32_t mWindowWidth;
f@0 149 int32_t mSelectionBarHeight;
f@0 150
f@0 151 float mShrinkFactor;
f@0 152
f@0 153 };