Sequencer - Scroll bars

This commit is contained in:
Emmanuel BENOîT 2017-11-27 13:54:06 +01:00
parent 8d2aac85b3
commit 56416abdb8
2 changed files with 43 additions and 15 deletions

2
TODO
View file

@ -32,7 +32,7 @@ Sync / inputs:
* Support for overrides * Support for overrides
* Fix the various remaining issues * Fix the various remaining issues
* Zooming issues on the right side * Zooming issues on the right side
* Scrollbars * Mouse wheel
* Add curve display * Add curve display
Misc: Misc:

View file

@ -282,6 +282,8 @@ struct T_SyncViewImpl_
T_StringBuilder stringBuffer; // XXX damn this shit to fucking hell T_StringBuilder stringBuffer; // XXX damn this shit to fucking hell
// Computed metrics // Computed metrics
bool checkLockMode{ false };
float vScroll{ 0 };
float barWidth; float barWidth;
float cursorPos; float cursorPos;
uint32_t startBar; uint32_t startBar;
@ -297,7 +299,6 @@ struct T_SyncViewImpl_
// Zoom area selection // Zoom area selection
bool zoomInProgress{ false }; bool zoomInProgress{ false };
bool justZoomed{ false };
float firstZoomPixel; float firstZoomPixel;
float curZoomPixel; float curZoomPixel;
@ -550,16 +551,25 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
using namespace ImGui; using namespace ImGui;
const auto width{ CalcItemWidth( ) }; const auto width{ CalcItemWidth( ) };
auto* const win( GetCurrentWindow( ) ); auto* const win{ GetCurrentWindow( ) };
const auto seqId{ win->GetID( "##sequencer" ) }; const auto seqId{ win->GetID( "##sequencer" ) };
const ImVec2 cPos( win->DC.CursorPos ); const ImVec2 cPos{ win->DC.CursorPos };
const ImVec2 ws( GetWindowContentRegionMax( ) ); const ImVec2 ws{ GetWindowContentRegionMax( ) };
auto& style( ImGui::GetStyle( ) ); auto& style( ImGui::GetStyle( ) );
const ImRect bbHeader{ cPos , cPos + ImVec2( width , SeqHeaderHeight ) }; const float widgetWidth{ width - style.ScrollbarSize };
const ImRect bbDisplay{ ImVec2{ cPos.x , bbHeader.Max.y } , const ImRect bbHeader{
ImVec2{ cPos.x + width , GetWindowPos( ).y + ws.y - style.FramePadding.y * 2 } }; cPos ,
cPos + ImVec2( widgetWidth , SeqHeaderHeight )
};
const ImRect bbDisplay{
ImVec2{ cPos.x , bbHeader.Max.y } ,
ImVec2{ cPos.x + widgetWidth ,
GetWindowPos( ).y + ws.y
- style.FramePadding.y * 2
- style.ScrollbarSize }
};
const ImRect bbAll{ bbHeader.Min , bbDisplay.Max }; const ImRect bbAll{ bbHeader.Min , bbDisplay.Max };
ItemSize( bbAll , style.FramePadding.y ); ItemSize( bbAll , style.FramePadding.y );
@ -567,12 +577,13 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
return; return;
} }
const bool hovered{ ItemHoverable( bbAll , seqId ) }; const bool hovered{ ItemHoverable( bbAll , seqId ) };
computeMetrics( std::max( 0.f , width - 2.f ) ); computeMetrics( std::max( 0.f , widgetWidth - 2.f ) );
BeginGroup( ); BeginGroup( );
const auto hdrId{ win->GetID( "##header" ) }; const auto hdrId{ win->GetID( "##header" ) };
const auto dspId{ win->GetID( "##display" ) }; const auto dspId{ win->GetID( "##display" ) };
PushID( seqId ); PushID( seqId );
if ( ItemAdd( bbHeader , hdrId ) ) { if ( ItemAdd( bbHeader , hdrId ) ) {
PushID( hdrId ); PushID( hdrId );
sequencerHeader( bbHeader ); sequencerHeader( bbHeader );
@ -583,6 +594,25 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
sequencerBody( bbDisplay ); sequencerBody( bbDisplay );
PopID( ); PopID( );
} }
// Vertical scrollbar - tracks
const float totalHeight{ sCurves.size( ) * ( TrackHeight + TrackPadding * 2.f ) };
if ( vScroll > totalHeight - bbDisplay.GetHeight( ) ) {
vScroll = ImMax( 0.f , totalHeight - bbDisplay.GetHeight( ) );
}
// FIXME overrides
UserScrollbar( false , totalHeight , bbDisplay.GetHeight( ) , &vScroll ,
bbHeader.GetTR( ) , bbAll.GetHeight( ) );
// Horizontal scrollbar - time
auto& sync( Common::Sync( ) );
float rsPos = startPixel;
if ( UserScrollbar( true , totalPixels , widgetWidth , &rsPos ,
bbDisplay.GetBL( ) , bbDisplay.GetWidth( ) ) ) {
startPos = sync.durationUnits( ) * rsPos / totalPixels;
checkLockMode = true;
}
PopID( ); PopID( );
EndGroup( ); EndGroup( );
@ -593,7 +623,6 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
} }
const bool active( GetCurrentContext( )->ActiveId == seqId ); const bool active( GetCurrentContext( )->ActiveId == seqId );
auto& sync( Common::Sync( ) );
const float mPixels{ io.MousePos.x - bbAll.Min.x + startPixel }; const float mPixels{ io.MousePos.x - bbAll.Min.x + startPixel };
const float mTime{ mPixels * sync.duration( ) / totalPixels }; const float mTime{ mPixels * sync.duration( ) / totalPixels };
@ -612,7 +641,7 @@ void T_SyncViewImpl_::sequencerWidget( ) noexcept
if ( zoomInProgress && !io.MouseDown[ 1 ] ) { if ( zoomInProgress && !io.MouseDown[ 1 ] ) {
zoomInProgress = false; zoomInProgress = false;
justZoomed = true; checkLockMode = true;
const auto zMin{ std::min( firstZoomPixel , curZoomPixel ) } , const auto zMin{ std::min( firstZoomPixel , curZoomPixel ) } ,
zMax{ std::max( firstZoomPixel , curZoomPixel ) } , zMax{ std::max( firstZoomPixel , curZoomPixel ) } ,
diff{ zMax - zMin }; diff{ zMax - zMin };
@ -715,7 +744,7 @@ void T_SyncViewImpl_::computeMetrics(
const float spp{ startPos * totalPixels / units }; const float spp{ startPos * totalPixels / units };
const float epp{ endPos * totalPixels / units }; const float epp{ endPos * totalPixels / units };
if ( absCursorPos < spp || absCursorPos > epp ) { if ( absCursorPos < spp || absCursorPos > epp ) {
if ( justZoomed ) { if ( checkLockMode ) {
followTime = false; followTime = false;
} else { } else {
startPos = std::max( 0.f , sync.time( ) / uSize - unitsPerBar * .5f ); startPos = std::max( 0.f , sync.time( ) / uSize - unitsPerBar * .5f );
@ -738,7 +767,7 @@ void T_SyncViewImpl_::computeMetrics(
assert( startBarPos <= 0 ); assert( startBarPos <= 0 );
assert( totalPixels >= innerWidth ); assert( totalPixels >= innerWidth );
justZoomed = false; checkLockMode = false;
} }
void T_SyncViewImpl_::sequencerHeader( void T_SyncViewImpl_::sequencerHeader(
@ -819,8 +848,7 @@ void T_SyncViewImpl_::sequencerBody(
if ( sCurves.size( ) != 0 ) { if ( sCurves.size( ) != 0 ) {
ImRect subBb{ inner }; ImRect subBb{ inner };
// FIXME scroll subBb.Min.y += TrackPadding - vScroll;
subBb.Min.y += TrackPadding;
subBb.Max.y = subBb.Min.y + TrackHeight; subBb.Max.y = subBb.Min.y + TrackHeight;
float hue{ 0.12f }; float hue{ 0.12f };