1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-06 23:29:24 +02:00

Public functions get, set highlight boundaries, hit-test on text

This commit is contained in:
Paul Licameli 2018-11-09 08:56:05 -05:00
parent 6af9187003
commit bbc465920b
2 changed files with 20 additions and 8 deletions

View File

@ -983,7 +983,7 @@ void LabelTrackView::SetSelectedIndex( int index )
/// uses GetTextExtent to find the character position
/// corresponding to the x pixel position.
int LabelTrackView::FindCurrentCursorPosition(int xPos)
int LabelTrackView::FindCursorPosition(wxCoord xPos)
{
int result = -1;
wxMemoryDC dc;
@ -1032,10 +1032,17 @@ int LabelTrackView::FindCurrentCursorPosition(int xPos)
return result;
}
/// Set the cursor position according to x position of mouse
void LabelTrackView::SetCurrentCursorPosition(int xPos)
void LabelTrackView::SetCurrentCursorPosition(int pos)
{
mCurrentCursorPos = FindCurrentCursorPosition(xPos);
mCurrentCursorPos = pos;
}
void LabelTrackView::SetTextHighlight(
int initialPosition, int currentPosition )
{
mInitialCursorPos = initialPosition;
mCurrentCursorPos = currentPosition;
mDrawCursor = true;
}
void LabelTrackView::calculateFontHeight(wxDC & dc)
@ -1683,7 +1690,7 @@ void LabelTrackView::HandleTextDragRelease(const wxMouseEvent & evt)
{
if (!mRightDragging)
// Update drag end
SetCurrentCursorPosition(evt.m_x);
SetCurrentCursorPosition(FindCursorPosition(evt.m_x));
return;
}
@ -1778,7 +1785,7 @@ void LabelTrackView::HandleTextClick(const wxMouseEvent & evt,
if (evt.LeftDown()) {
// Find the NEW drag end
auto position = FindCurrentCursorPosition(evt.m_x);
auto position = FindCursorPosition(evt.m_x);
// Anchor shift-drag at the farther end of the previous highlight
// that is farther from the click, on Mac, for consistency with

View File

@ -192,8 +192,13 @@ private:
static void DrawHighlight(
wxDC & dc, const LabelStruct &ls, int xPos1, int xPos2, int charHeight);
int FindCurrentCursorPosition(int xPos);
void SetCurrentCursorPosition(int xPos);
public:
/// convert pixel coordinate to character position in text box
int FindCursorPosition(wxCoord xPos);
int GetCurrentCursorPosition() const { return mCurrentCursorPos; }
void SetCurrentCursorPosition(int pos);
int GetInitialCursorPosition() const { return mInitialCursorPos; }
void SetTextHighlight( int initialPosition, int currentPosition );
static void calculateFontHeight(wxDC & dc);
bool HasSelection() const;