MCPcopy Create free account
hub / github.com/audacity/audacity / OnMove

Method OnMove

src/MovableControl.cpp:180–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180void MovableControl::OnMove(wxMouseEvent& evt)
181{
182 if(!mDragging)
183 return;
184
185 auto parent = GetParent();
186 if(!parent)
187 return;
188
189 wxPoint newPosition = wxGetMousePosition() - mInitialPosition;
190 Move(GetParent()->ScreenToClient(newPosition));
191
192 if(auto boxSizer = dynamic_cast<wxBoxSizer*>(parent->GetSizer()))
193 {
194 if(boxSizer->GetOrientation() == wxVERTICAL)
195 {
196 auto targetIndex = mSourceIndex;
197
198 //assuming that items are ordered from top to bottom (i > j <=> y(i) > y(j))
199 //compare wxSizerItem position with the current MovableControl position!
200 if(GetPosition().y < boxSizer->GetItem(mSourceIndex)->GetPosition().y)
201 {
202 //moving up
203 for(int i = 0; i < mSourceIndex; ++i)
204 {
205 const auto item = boxSizer->GetItem(i);
206
207 if(GetRect().GetTop() <= item->GetPosition().y + item->GetSize().y / 2)
208 {
209 targetIndex = i;
210 break;
211 }
212 }
213 }
214 else
215 {
216 //moving down
217 for(int i = static_cast<int>(boxSizer->GetItemCount()) - 1; i > mSourceIndex; --i)
218 {
219 const auto item = boxSizer->GetItem(i);
220 if(GetRect().GetBottom() >= item->GetPosition().y + item->GetSize().y / 2)
221 {
222 targetIndex = i;
223 break;
224 }
225 }
226 }
227
228 if(targetIndex != mTargetIndex)
229 {
230 mTargetIndex = targetIndex;
231 ProcessDragEvent(parent, EVT_MOVABLE_CONTROL_DRAG_POSITION);
232 }
233 }
234 }
235}

Callers

nothing calls this directly

Calls 5

GetParentFunction · 0.85
MoveFunction · 0.85
GetSizerMethod · 0.80
GetItemMethod · 0.80
GetSizeMethod · 0.45

Tested by

no test coverage detected