2017-07-04 15:39:32 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
TrackPanelResizeHandle.cpp
|
|
|
|
|
|
|
|
Paul Licameli split from TrackPanel.cpp
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2017-07-04 15:39:32 +00:00
|
|
|
#include "TrackPanelResizerCell.h"
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
|
2018-11-03 04:34:49 +00:00
|
|
|
#include "AColor.h"
|
|
|
|
#include "Track.h"
|
|
|
|
#include "TrackArtist.h"
|
|
|
|
#include "TrackPanelDrawingContext.h"
|
2017-07-04 15:39:32 +00:00
|
|
|
#include "TrackPanelResizeHandle.h"
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
#include "TrackPanelMouseEvent.h"
|
2017-07-04 15:39:32 +00:00
|
|
|
#include "HitTestResult.h"
|
2018-11-03 04:34:49 +00:00
|
|
|
#include "ViewInfo.h"
|
2019-07-13 20:08:29 +00:00
|
|
|
#include "widgets/OverlayPanel.h"
|
2017-07-04 15:39:32 +00:00
|
|
|
|
2018-11-03 04:34:49 +00:00
|
|
|
#include <wx/dc.h>
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
#include <wx/mousestate.h>
|
|
|
|
|
2019-06-17 18:11:31 +00:00
|
|
|
TrackPanelResizerCell::TrackPanelResizerCell(
|
2019-07-09 18:45:42 +00:00
|
|
|
const std::shared_ptr<Track> &pTrack )
|
|
|
|
: mwTrack{ pTrack }
|
2017-07-04 15:39:32 +00:00
|
|
|
{}
|
|
|
|
|
2017-06-29 14:34:57 +00:00
|
|
|
std::vector<UIHandlePtr> TrackPanelResizerCell::HitTest
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
(const TrackPanelMouseState &st, const AudacityProject *pProject)
|
2017-07-04 15:39:32 +00:00
|
|
|
{
|
2018-10-10 18:09:10 +00:00
|
|
|
(void)pProject;// Compiler food
|
2017-06-29 14:34:57 +00:00
|
|
|
std::vector<UIHandlePtr> results;
|
2019-06-18 03:23:44 +00:00
|
|
|
auto pTrack = FindTrack();
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
if (pTrack) {
|
|
|
|
auto result = std::make_shared<TrackPanelResizeHandle>(
|
2017-01-11 19:00:31 +00:00
|
|
|
pTrack, st.state.m_y );
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
result = AssignUIHandlePtr(mResizeHandle, result);
|
2017-06-29 14:34:57 +00:00
|
|
|
results.push_back(result);
|
Changed lifetime management of UIHandle objects, no singletons...
... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)
This also fixes bug 1677 by other means and avoids similar problems.
A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.
And the objects will surely be destroyed after drag-release, or ESC key.
For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
2017-07-05 20:45:55 +00:00
|
|
|
}
|
2017-06-29 14:34:57 +00:00
|
|
|
return results;
|
2017-07-04 15:39:32 +00:00
|
|
|
}
|
2019-06-18 03:23:44 +00:00
|
|
|
|
|
|
|
std::shared_ptr<Track> TrackPanelResizerCell::DoFindTrack()
|
|
|
|
{
|
2019-07-09 18:45:42 +00:00
|
|
|
return mwTrack.lock();
|
2019-06-18 03:23:44 +00:00
|
|
|
}
|
2018-11-03 04:34:49 +00:00
|
|
|
|
|
|
|
void TrackPanelResizerCell::Draw(
|
|
|
|
TrackPanelDrawingContext &context,
|
|
|
|
const wxRect &rect, unsigned iPass )
|
|
|
|
{
|
|
|
|
if ( iPass == TrackArtist::PassMargins ) {
|
|
|
|
auto pTrack = FindTrack();
|
|
|
|
if ( pTrack ) {
|
|
|
|
auto dc = &context.dc;
|
|
|
|
const bool last =
|
|
|
|
pTrack.get() == *TrackList::Channels( pTrack.get() ).rbegin();
|
|
|
|
if ( last ) {
|
|
|
|
// Fill in separator area below a track
|
|
|
|
AColor::TrackPanelBackground( dc, false );
|
|
|
|
dc->DrawRectangle( rect );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Area between channels of a group
|
|
|
|
// Paint the channel separator over (what would be) the lower border
|
|
|
|
// of this channel, down to and including the upper border of the
|
|
|
|
// next channel
|
|
|
|
|
|
|
|
ADCChanger cleanup{ dc };
|
|
|
|
|
|
|
|
// Paint the left part of the background
|
|
|
|
const auto artist = TrackArtist::Get( context );
|
|
|
|
auto labelw = artist->pZoomInfo->GetLabelWidth();
|
|
|
|
AColor::MediumTrackInfo( dc, pTrack->GetSelected() );
|
|
|
|
dc->DrawRectangle(
|
|
|
|
rect.GetX(), rect.GetY(), labelw, rect.GetHeight() );
|
|
|
|
|
|
|
|
// Stroke the left border
|
|
|
|
dc->SetPen(*wxBLACK_PEN);
|
|
|
|
{
|
|
|
|
const auto left = rect.GetLeft();
|
|
|
|
AColor::Line( *dc, left, rect.GetTop(), left, rect.GetBottom() );
|
|
|
|
}
|
|
|
|
|
|
|
|
AColor::TrackPanelBackground(dc, false);
|
|
|
|
|
|
|
|
wxRect rec{ rect };
|
|
|
|
rec.width -= labelw - rec.x;
|
|
|
|
rec.x = labelw;
|
|
|
|
|
|
|
|
dc->DrawRectangle( wxRect( rec ).Inflate( 0, -kBorderThickness ) );
|
|
|
|
|
|
|
|
// These lines stroke over what is otherwise "border" of each
|
|
|
|
// channel
|
|
|
|
dc->SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
dc->SetPen(*wxBLACK_PEN);
|
|
|
|
const auto left = rec.GetLeft();
|
|
|
|
const auto right = rec.GetRight();
|
|
|
|
const auto top = rec.GetTop();
|
|
|
|
const auto bottom = rec.GetBottom();
|
|
|
|
AColor::Line( *dc, left, top, right, top );
|
|
|
|
AColor::Line( *dc, left, bottom, right, bottom );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-09 18:45:42 +00:00
|
|
|
|
|
|
|
static const AttachedTrackObjects::RegisteredFactory key{
|
|
|
|
[]( Track &track ){
|
|
|
|
return std::make_shared<TrackPanelResizerCell>(
|
|
|
|
track.shared_from_this() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TrackPanelResizerCell &TrackPanelResizerCell::Get( Track &track )
|
|
|
|
{
|
|
|
|
return track.AttachedObjects::Get< TrackPanelResizerCell >( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
const TrackPanelResizerCell &TrackPanelResizerCell::Get( const Track &track )
|
|
|
|
{
|
|
|
|
return Get( const_cast< Track & >( track ) );
|
|
|
|
}
|