@ -54,7 +54,8 @@ protected:
float scrollBarTop = 0 ;
bool scrollBarSelected = false ;
float scrollBarHoverTime = 0 ;
vf2d scrollOffset ;
vf2d scrollOffset { } ;
vf2d targetScrollOffset { } ;
protected :
inline bool OnScreen ( std : : weak_ptr < MenuComponent > component ) {
return geom2d : : overlaps ( geom2d : : rect < float > { { } , rect . size } , geom2d : : rect < float > { component . lock ( ) - > rect . pos + vf2d { 2 , 2 } , component . lock ( ) - > rect . size - vf2d { 2 , 2 } } ) ;
@ -86,13 +87,14 @@ public:
CalculateBounds ( ) ;
}
virtual inline void SetScrollAmount ( vf2d scrollOffset ) {
this - > scrollOffset = scrollOffset ;
for ( std : : weak_ptr < MenuComponent > component : components ) {
component . lock ( ) - > rect . pos = component . lock ( ) - > originalPos + scrollOffset ;
}
this - > targetScrollOffset = scrollOffset ;
}
virtual inline vf2d GetScrollAmount ( ) {
return scrollOffset ;
return targetScrollOffset ;
}
virtual bool GetHoverState ( AiL * game , MenuComponent * child ) override {
return geom2d : : overlaps ( geom2d : : rect < float > { Menu : : menus [ parentMenu ] - > pos + rect . pos , rect . size } , game - > GetMousePos ( ) ) & & //Make sure the mouse is inside the parent window component first....
geom2d : : overlaps ( geom2d : : rect < float > { Menu : : menus [ parentMenu ] - > pos + rect . pos + child - > rect . pos , child - > rect . size } , game - > GetMousePos ( ) ) ;
}
protected :
virtual inline void AfterCreate ( ) override {
@ -141,6 +143,10 @@ protected:
scrollBarHoverTime = std : : max ( scrollBarHoverTime - game - > GetElapsedTime ( ) , 0.f ) ;
}
for ( std : : weak_ptr < MenuComponent > component : components ) {
component . lock ( ) - > rect . pos = component . lock ( ) - > originalPos + targetScrollOffset ;
}
if ( game - > GetMouseWheel ( ) ! = 0 ) {
if ( game - > GetMouseWheel ( ) > 0 ) {
SetScrollAmount ( GetScrollAmount ( ) + vf2d { 0 , " ThemeGlobal.MenuScrollWheelSpeed " _F } ) ;
@ -150,8 +156,10 @@ protected:
}
if ( bounds . size . y - rect . size . y > 0 ) {
scrollOffset . y = std : : clamp ( GetScrollAmount ( ) . y , - ( bounds . size . y - rect . size . y ) , 0.f ) ;
SetScrollAmount ( { GetScrollAmount ( ) . x , std : : clamp ( GetScrollAmount ( ) . y , - ( bounds . size . y - rect . size . y ) , 0.f ) } ) ;
} else {
scrollOffset . y = 0 ;
SetScrollAmount ( { GetScrollAmount ( ) . x , 0 } ) ;
}
@ -195,10 +203,6 @@ protected:
DrawScrollbar ( window , { } , focused ) ;
}
}
virtual bool GetHoverState ( AiL * game , MenuComponent * child ) override {
return geom2d : : overlaps ( geom2d : : rect < float > { Menu : : menus [ parentMenu ] - > pos + rect . pos , rect . size } , game - > GetMousePos ( ) ) & & //Make sure the mouse is inside the parent window component first....
geom2d : : overlaps ( geom2d : : rect < float > { Menu : : menus [ parentMenu ] - > pos + rect . pos + child - > rect . pos , child - > rect . size } , game - > GetMousePos ( ) ) ;
}
//Calculates the bounds of all components.
inline void CalculateBounds ( ) {
bounds = { } ;
@ -228,7 +232,7 @@ public:
std : : shared_ptr < T > _AddComponent ( std : : string key , std : : shared_ptr < T > button ) {
components . push_back ( button ) ;
button - > renderInMain = false ; //Now we are in control!
button - > parentComponent = Menu : : menus [ parentMenu ] - > components [ this - > GetName ( ) ] ;
button - > parentComponent = DYNAMIC_POINTER_CAST < ScrollableWindowComponent > ( Menu : : menus [ parentMenu ] - > components [ this - > GetName ( ) ] ) ;
button - > disabled = disabled ;
CalculateBounds ( ) ;
@ -244,7 +248,7 @@ public:
}
virtual inline bool HandleOutsideDisabledButtonSelection ( std : : weak_ptr < MenuComponent > disabledButton ) override {
//Set the offset so the center is highlighted by this button.
SetScrollAmount ( vf2d { GetScrollAmount ( ) . x , - disabledButton . lock ( ) - > rect . pos . y + disabledButton . lock ( ) - > rect . size . y } ) ;
SetScrollAmount ( vf2d { GetScrollAmount ( ) . x , GetScrollAmount ( ) . y - disabledButton . lock ( ) - > rect . pos . y + disabledButton . lock ( ) - > rect . size . y } ) ;
return true ;
} ;
virtual void Cleanup ( ) override { }