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