mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-30 15:18:42 +02:00
Various cleanups of label track code, no changes of behavior...
... this includes eliminating one indirection in accessing them
This commit is contained in:
commit
adb4ba3f04
1126
src/LabelTrack.cpp
1126
src/LabelTrack.cpp
File diff suppressed because it is too large
Load Diff
@ -41,21 +41,18 @@ class ZoomInfo;
|
||||
|
||||
class LabelStruct
|
||||
{
|
||||
// disallow copy
|
||||
private:
|
||||
LabelStruct(const LabelStruct&);
|
||||
LabelStruct& operator= (const LabelStruct&);
|
||||
public:
|
||||
// Copies region
|
||||
LabelStruct(const SelectedRegion& region, const wxString &aTitle);
|
||||
// Copies region but then overwrites other times
|
||||
LabelStruct(const SelectedRegion& region, double t0, double t1,
|
||||
const wxString &aTitle);
|
||||
void DrawLines( wxDC & dc, const wxRect & r);
|
||||
void DrawGlyphs( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight);
|
||||
void DrawText( wxDC & dc, const wxRect & r);
|
||||
void DrawTextBox( wxDC & dc, const wxRect & r);
|
||||
void DrawHighlight( wxDC & dc, int xPos1, int xPos2, int charHeight);
|
||||
void DrawLines( wxDC & dc, const wxRect & r) const;
|
||||
void DrawGlyphs
|
||||
( wxDC & dc, const wxRect & r, int GlyphLeft, int GlyphRight) const;
|
||||
void DrawText( wxDC & dc, const wxRect & r) const;
|
||||
void DrawTextBox( wxDC & dc, const wxRect & r) const;
|
||||
void DrawHighlight( wxDC & dc, int xPos1, int xPos2, int charHeight) const;
|
||||
void getXPos( wxDC & dc, int * xPos1, int cursorPos) const;
|
||||
const SelectedRegion &getSelectedRegion() const { return selectedRegion; }
|
||||
double getDuration() const { return selectedRegion.duration(); }
|
||||
@ -81,27 +78,25 @@ public:
|
||||
/// and end of parent to be within a region that borders them (this makes
|
||||
/// it possible to DELETE capture all labels with a Select All).
|
||||
TimeRelations RegionRelation(double reg_t0, double reg_t1,
|
||||
const LabelTrack *parent = NULL);
|
||||
const LabelTrack *parent = NULL) const;
|
||||
|
||||
public:
|
||||
SelectedRegion selectedRegion;
|
||||
wxString title; /// Text of the label.
|
||||
int width; /// width of the text in pixels.
|
||||
mutable int width; /// width of the text in pixels.
|
||||
|
||||
// Working storage for on-screen layout.
|
||||
int x; /// Pixel position of left hand glyph
|
||||
int x1; /// Pixel position of right hand glyph
|
||||
int xText; /// Pixel position of left hand side of text box
|
||||
int y; /// Pixel position of label.
|
||||
mutable int x; /// Pixel position of left hand glyph
|
||||
mutable int x1; /// Pixel position of right hand glyph
|
||||
mutable int xText; /// Pixel position of left hand side of text box
|
||||
mutable int y; /// Pixel position of label.
|
||||
|
||||
bool highlighted; /// if the text is highlighted
|
||||
bool changeInitialMouseXPos; /// flag to change initial mouse X pos
|
||||
mutable bool highlighted; /// if the text is highlighted
|
||||
mutable bool changeInitialMouseXPos; /// flag to change initial mouse X pos
|
||||
bool updated; /// flag to tell if the label times were updated
|
||||
};
|
||||
|
||||
//You can't stick AUDACITY_DLL_API in front of the WX_DEFINE_ARRAY() macro, you
|
||||
//have to use the below macro instead to avoid a warning
|
||||
WX_DEFINE_USER_EXPORTED_ARRAY(LabelStruct *, LabelArray, class AUDACITY_DLL_API);
|
||||
using LabelArray = std::vector<LabelStruct>;
|
||||
|
||||
const int NUM_GLYPH_CONFIGS = 3;
|
||||
const int NUM_GLYPH_HIGHLIGHTS = 4;
|
||||
@ -181,11 +176,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
|
||||
static bool IsTextClipSupported();
|
||||
|
||||
// methods to set flags
|
||||
void SetDragXPos(const int d) { mDragXPos = d; }
|
||||
void SetInBox(bool inTextBox) { mInBox = inTextBox; }
|
||||
void SetResetCursorPos(bool resetFlag) { mResetCursorPos = resetFlag; }
|
||||
void SetWrongDragging(bool rightFlag) { mRightDragging = rightFlag; }
|
||||
void SetDrawCursor(bool drawCursorFlag) { mDrawCursor = drawCursorFlag; }
|
||||
|
||||
void HandleClick(const wxMouseEvent & evt, const wxRect & r, const ZoomInfo &zoomInfo,
|
||||
SelectedRegion *newSel);
|
||||
@ -198,7 +189,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
|
||||
bool OnChar(SelectedRegion &sel, wxKeyEvent & event);
|
||||
|
||||
void Import(wxTextFile & f);
|
||||
void Export(wxTextFile & f);
|
||||
void Export(wxTextFile & f) const;
|
||||
|
||||
void Unselect();
|
||||
|
||||
@ -216,9 +207,11 @@ class AUDACITY_DLL_API LabelTrack final : public Track
|
||||
//This deletes the label at given index.
|
||||
void DeleteLabel(int index);
|
||||
|
||||
//get current cursor position
|
||||
bool CalcCursorX(wxWindow * parent, int * x);
|
||||
int getCurrentCursorPosition() const { return mCurrentCursorPos; }
|
||||
//get current cursor position,
|
||||
// relative to the left edge of the track panel
|
||||
bool CalcCursorX(int * x) const;
|
||||
|
||||
void CalcHighlightXs(int *x1, int *x2) const;
|
||||
|
||||
void MayAdjustLabel( int iLabel, int iEdge, bool bAllowSwapping, double fNewTime);
|
||||
void MayMoveLabel( int iLabel, int iEdge, double fNewTime);
|
||||
@ -237,7 +230,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
|
||||
void WarpLabels(const TimeWarper &warper);
|
||||
|
||||
// Returns tab-separated text of all labels completely within given region
|
||||
wxString GetTextOfLabels(double t0, double t1);
|
||||
wxString GetTextOfLabels(double t0, double t1) const;
|
||||
|
||||
public:
|
||||
void SortLabels();
|
||||
@ -262,28 +255,28 @@ class AUDACITY_DLL_API LabelTrack final : public Track
|
||||
static bool mbGlyphsReady;
|
||||
static wxBitmap mBoundaryGlyphs[NUM_GLYPH_CONFIGS * NUM_GLYPH_HIGHLIGHTS];
|
||||
|
||||
mutable int xUsed[MAX_NUM_ROWS];
|
||||
|
||||
static int mFontHeight;
|
||||
mutable int mXPos1; /// left X pos of highlighted area
|
||||
mutable int mXPos2; /// right X pos of highlighted area
|
||||
mutable int mCurrentCursorPos; /// current cursor position
|
||||
mutable int mInitialCursorPos; /// initial cursor position
|
||||
mutable double mMouseXPos; /// mouse X pos
|
||||
int mDragXPos; /// end X pos of dragging
|
||||
bool mInBox; /// flag to tell if the mouse is in text box
|
||||
mutable bool mResetCursorPos; /// flag to reset cursor position(used in the dragging the glygh)
|
||||
bool mRightDragging; /// flag to tell if it's a valid dragging
|
||||
mutable bool mDrawCursor; /// flag to tell if drawing the cursor or not
|
||||
int mRestoreFocus; /// Restore focus to this track when done editing
|
||||
int mCurrentCursorPos; /// current cursor position
|
||||
int mInitialCursorPos; /// initial cursor position
|
||||
int mDragXPos; /// end X pos of dragging
|
||||
/// in text box
|
||||
|
||||
bool mRightDragging; /// flag to tell if it's a valid dragging
|
||||
bool mDrawCursor; /// flag to tell if drawing the
|
||||
/// cursor or not
|
||||
int mRestoreFocus; /// Restore focus to this track
|
||||
/// when done editing
|
||||
|
||||
// Set in copied label tracks
|
||||
double mClipLen;
|
||||
|
||||
void ComputeLayout(const wxRect & r, const ZoomInfo &zoomInfo) const;
|
||||
void ComputeTextPosition(const wxRect & r, int index) const;
|
||||
void SetCurrentCursorPosition(wxDC & dc, int xPos) const;
|
||||
|
||||
public:
|
||||
void SetCurrentCursorPosition(int xPos);
|
||||
|
||||
private:
|
||||
void calculateFontHeight(wxDC & dc) const;
|
||||
void RemoveSelectedText();
|
||||
|
||||
|
@ -4322,7 +4322,7 @@ bool AudacityProject::HandlePasteText()
|
||||
|
||||
// Make sure caret is in view
|
||||
int x;
|
||||
if (pLabelTrack->CalcCursorX(this, &x)) {
|
||||
if (pLabelTrack->CalcCursorX(&x)) {
|
||||
mTrackPanel->ScrollIntoView(x);
|
||||
}
|
||||
|
||||
|
@ -5887,7 +5887,7 @@ void TrackPanel::OnKeyDown(wxKeyEvent & event)
|
||||
|
||||
// Make sure caret is in view
|
||||
int x;
|
||||
if (lt->CalcCursorX(this, &x)) {
|
||||
if (lt->CalcCursorX(&x)) {
|
||||
ScrollIntoView(x);
|
||||
}
|
||||
|
||||
@ -6313,17 +6313,8 @@ bool TrackPanel::HandleLabelTrackClick(LabelTrack * lTrack, wxRect &rect, wxMous
|
||||
|
||||
if(mCapturedTrack == NULL)
|
||||
SetCapturedTrack(lTrack, IsSelectingLabelText);
|
||||
// handle shift+mouse left button
|
||||
if (event.ShiftDown() && event.ButtonDown()) {
|
||||
// if the mouse is clicked in text box, set flags
|
||||
if (lTrack->OverTextBox(lTrack->GetLabel(lTrack->getSelectedIndex()), event.m_x, event.m_y)) {
|
||||
lTrack->SetInBox(true);
|
||||
lTrack->SetDragXPos(event.m_x);
|
||||
lTrack->SetResetCursorPos(true);
|
||||
RefreshTrack(lTrack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
RefreshTrack(lTrack);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user