HandleMouseButtonDown either finds an existing control point or adds a NEW one which is then recorded as the point to drag. This is slightly complicated by there possibly being four control points for a given time value: We have an upper and lower envelope line. Also we may be showing an inner envelope (at 0.5 the range).
| 156 | /// We have an upper and lower envelope line. |
| 157 | /// Also we may be showing an inner envelope (at 0.5 the range). |
| 158 | bool EnvelopeEditor::HandleMouseButtonDown(const wxMouseEvent & event, wxRect & r, |
| 159 | const ZoomInfo &zoomInfo, |
| 160 | bool dB, double dBRange, |
| 161 | float zoomMin, float zoomMax) |
| 162 | { |
| 163 | int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin)); |
| 164 | bool upper = !mMirrored || (zoomMin >= 0.0) || (event.m_y - r.y < ctr); |
| 165 | |
| 166 | int clip_y = event.m_y - r.y; |
| 167 | if(clip_y < 0) clip_y = 0; //keeps point in rect r, even if mouse isn't |
| 168 | if(clip_y > r.GetBottom()) clip_y = r.GetBottom(); |
| 169 | |
| 170 | int bestNum = -1; |
| 171 | int bestDistSqr = 100; // Must be within 10 pixel radius. |
| 172 | |
| 173 | // Member variables hold state that will be needed in dragging. |
| 174 | mButton = event.GetButton(); |
| 175 | mContourOffset = false; |
| 176 | |
| 177 | // wxLogDebug(wxT("Y:%i Height:%i Offset:%i"), y, height, mContourOffset ); |
| 178 | int len = mEnvelope.GetNumberOfPoints(); |
| 179 | |
| 180 | // TODO: extract this into a function FindNearestControlPoint() |
| 181 | // TODO: also fix it so that we can drag the last point on an envelope. |
| 182 | for (int i = 0; i < len; i++) { //search for control point nearest click |
| 183 | const double time = mEnvelope[i].GetT() + mEnvelope.GetOffset(); |
| 184 | const wxInt64 position = zoomInfo.TimeToPosition(time); |
| 185 | if (position >= 0 && position < r.width) { |
| 186 | |
| 187 | int x = (int)(position); |
| 188 | int y[4]; |
| 189 | int numControlPoints; |
| 190 | |
| 191 | // Outer control points |
| 192 | double value = mEnvelope[i].GetVal(); |
| 193 | y[0] = GetWaveYPos(value, zoomMin, zoomMax, r.height, |
| 194 | dB, true, dBRange, false); |
| 195 | y[1] = GetWaveYPos(-value, zoomMin, zoomMax, r.height, |
| 196 | dB, true, dBRange, false); |
| 197 | |
| 198 | // Inner control points(contour) |
| 199 | y[2] = GetWaveYPos(value, zoomMin, zoomMax, r.height, |
| 200 | dB, false, dBRange, false); |
| 201 | y[3] = GetWaveYPos(-value -.00000001, zoomMin, zoomMax, |
| 202 | r.height, dB, false, dBRange, false); |
| 203 | |
| 204 | numControlPoints = 4; |
| 205 | |
| 206 | if (y[2] > y[3]) |
| 207 | numControlPoints = 2; |
| 208 | |
| 209 | if (!mMirrored) |
| 210 | numControlPoints = 1; |
| 211 | |
| 212 | const int deltaXSquared = SQR(x - (event.m_x - r.x)); |
| 213 | for(int j=0; j<numControlPoints; j++){ |
| 214 | |
| 215 | const int dSqr = deltaXSquared + SQR(y[j] - (event.m_y - r.y)); |
nothing calls this directly
no test coverage detected