@ -71,8 +71,8 @@ public:
}
}
}
}
virtual inline void RemoveButton ( MenuComponent * button ) {
virtual inline void RemoveButton ( MenuComponent * button ) {
std : : vector < MenuComponent * > & buttonList = Menu : : menus [ button - > parentMenu ] - > buttons . at ( int ( button - > GetPos ( ) . y ) ) ;
std : : vector < MenuComponent * > & buttonList = Menu : : menus [ button - > parentMenu ] - > buttons . at ( int ( button - > originalPos . y ) ) ;
std : : vector < MenuComponent * > & keyboardButtonList = Menu : : menus [ button - > parentMenu ] - > keyboardButtons . at ( int ( button - > GetPos ( ) . y ) ) ;
std : : vector < MenuComponent * > & keyboardButtonList = Menu : : menus [ button - > parentMenu ] - > keyboardButtons . at ( int ( button - > originalPos . y ) ) ;
size_t removedCount = 0 ;
size_t removedCount = 0 ;
removedCount + = std : : erase ( buttonList , button ) ;
removedCount + = std : : erase ( buttonList , button ) ;
removedCount + = std : : erase ( keyboardButtonList , button ) ;
removedCount + = std : : erase ( keyboardButtonList , button ) ;
@ -80,19 +80,20 @@ public:
std : : cout < < " WARNING! Attempted to remove buttons from button listing, but not found! " ;
std : : cout < < " WARNING! Attempted to remove buttons from button listing, but not found! " ;
}
}
if ( buttonList . size ( ) = = 0 ) {
if ( buttonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > buttons . erase ( int ( button - > GetPos ( ) . y ) ) ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > buttons . erase ( int ( button - > originalPos . y ) ) ) {
ERR ( " WARNING! Attempted to erase key " < < button - > GetPos ( ) . y < < " from button map, but the list still exists! " )
ERR ( " WARNING! Attempted to erase key " < < button - > originalPos . y < < " from button map, but the list still exists! " )
}
}
}
}
if ( keyboardButtonList . size ( ) = = 0 ) {
if ( keyboardButtonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > keyboardButtons . erase ( int ( button - > GetPos ( ) . y ) ) ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > keyboardButtons . erase ( int ( button - > originalPos . y ) ) ) {
ERR ( " WARNING! Attempted to erase key " < < button - > GetPos ( ) . y < < " from button map, but the list still exists! " )
ERR ( " WARNING! Attempted to erase key " < < button - > originalPos . y < < " from button map, but the list still exists! " )
}
}
}
}
Menu : : menus [ button - > parentMenu ] - > components . erase ( button - > GetName ( ) ) ;
Menu : : menus [ button - > parentMenu ] - > components . erase ( button - > GetName ( ) ) ;
components . erase ( std : : find ( components . begin ( ) , components . end ( ) , button ) ) ;
components . erase ( std : : find ( components . begin ( ) , components . end ( ) , button ) ) ;
Menu : : menus [ button - > parentMenu ] - > RecalculateComponentCount ( ) ;
Menu : : menus [ button - > parentMenu ] - > RecalculateComponentCount ( ) ;
delete button ;
delete button ;
CalculateBounds ( ) ;
}
}
virtual inline void SetScrollAmount ( vf2d scrollOffset ) {
virtual inline void SetScrollAmount ( vf2d scrollOffset ) {
this - > scrollOffset = scrollOffset ;
this - > scrollOffset = scrollOffset ;
@ -106,8 +107,8 @@ public:
protected :
protected :
virtual inline void AfterCreate ( ) override {
virtual inline void AfterCreate ( ) override {
//Let's use the internal name of this component to add unique names for sub-components.
//Let's use the internal name of this component to add unique names for sub-components.
upButton = Menu : : menus [ parentMenu ] - > ADD ( name + vf2d ( rect . pos + vf2d { rect . size . x - 12 , 0 } ) . str ( ) + " _ " + vf2d ( 12 , 12 ) . str ( ) , MenuComponent ) ( { rect . pos + vf2d { rect . size . x - 12 , 0 } , { 12 , 12 } } , " ^ " , [ & ] ( MenuFuncData dat ) { SetScrollAmount ( GetScrollAmount ( ) + vf2d { 0 , " ThemeGlobal.MenuButtonScrollSpeed " _F } ) ; return true ; } , ButtonAttr : : UNSELECTABLE_VIA_KEYBOARD ) DEPTH - 1 END ;
upButton = Menu : : menus [ parentMenu ] - > ADD ( name + vf2d ( rect . pos + vf2d { rect . size . x - 12 , 0 } ) . str ( ) + " _ " + vf2d ( 12 , 12 ) . str ( ) , MenuComponent ) ( { rect . pos + vf2d { rect . size . x - 12 , 0 } , { 12 , 12 } } , " ^ " , [ & ] ( MenuFuncData dat ) { SetScrollAmount ( GetScrollAmount ( ) + vf2d { 0 , " ThemeGlobal.MenuButtonScrollSpeed " _F } ) ; return true ; } , ButtonAttr : : UNSELECTABLE_VIA_KEYBOARD ) DEPTH depth - 1 END ;
downButton = Menu : : menus [ parentMenu ] - > ADD ( name + vf2d ( rect . pos + rect . size - vf2d { 12 , 12 } ) . str ( ) + " _ " + vf2d ( 12 , 12 ) . str ( ) , MenuComponent ) ( { rect . pos + rect . size - vf2d { 12 , 12 } , { 12 , 12 } } , " v " , [ & ] ( MenuFuncData dat ) { SetScrollAmount ( GetScrollAmount ( ) - vf2d { 0 , " ThemeGlobal.MenuButtonScrollSpeed " _F } ) ; return true ; } , ButtonAttr : : UNSELECTABLE_VIA_KEYBOARD ) DEPTH - 1 END ;
downButton = Menu : : menus [ parentMenu ] - > ADD ( name + vf2d ( rect . pos + rect . size - vf2d { 12 , 12 } ) . str ( ) + " _ " + vf2d ( 12 , 12 ) . str ( ) , MenuComponent ) ( { rect . pos + rect . size - vf2d { 12 , 12 } , { 12 , 12 } } , " v " , [ & ] ( MenuFuncData dat ) { SetScrollAmount ( GetScrollAmount ( ) - vf2d { 0 , " ThemeGlobal.MenuButtonScrollSpeed " _F } ) ; return true ; } , ButtonAttr : : UNSELECTABLE_VIA_KEYBOARD ) DEPTH depth - 1 END ;
subWindow = ViewPort : : rectViewPort ( { } , rect . size , Menu : : menus [ parentMenu ] - > pos + rect . pos ) ;
subWindow = ViewPort : : rectViewPort ( { } , rect . size , Menu : : menus [ parentMenu ] - > pos + rect . pos ) ;
if ( upButton ) { upButton - > Enable ( ! disabled ) ; }
if ( upButton ) { upButton - > Enable ( ! disabled ) ; }
if ( downButton ) { downButton - > Enable ( ! disabled ) ; }
if ( downButton ) { downButton - > Enable ( ! disabled ) ; }
@ -137,7 +138,6 @@ protected:
float spaceBetweenTopAndBottomArrows = rect . size . y - 24 ;
float spaceBetweenTopAndBottomArrows = rect . size . y - 24 ;
float viewHeight = rect . size . y ;
float viewHeight = rect . size . y ;
float totalContentHeight = bounds . size . y ;
float totalContentHeight = bounds . size . y ;
if ( totalContentHeight = = 0 ) totalContentHeight = 1 ;
if ( totalContentHeight = = 0 ) totalContentHeight = 1 ;
float scrollBarScale = ( spaceBetweenTopAndBottomArrows / totalContentHeight ) ;
float scrollBarScale = ( spaceBetweenTopAndBottomArrows / totalContentHeight ) ;
@ -205,8 +205,8 @@ protected:
return geom2d : : overlaps ( geom2d : : rect < float > { Menu : : menus [ parentMenu ] - > pos + rect . pos + child - > rect . pos , child - > rect . size } , game - > GetMousePos ( ) ) ;
return 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.
//Calculates the bounds of all components.
geom2d : : rect < float > inline CalculateBounds ( ) {
inline void CalculateBounds ( ) {
geom2d : : rect < float > bounds ;
bounds = { } ;
for ( MenuComponent * component : components ) {
for ( MenuComponent * component : components ) {
if ( component - > rect . pos . x < bounds . pos . x ) {
if ( component - > rect . pos . x < bounds . pos . x ) {
float sizeIncrease = bounds . pos . x - component - > rect . pos . x ;
float sizeIncrease = bounds . pos . x - component - > rect . pos . x ;
@ -227,7 +227,6 @@ protected:
bounds . size . y + = sizeIncrease ;
bounds . size . y + = sizeIncrease ;
}
}
}
}
return bounds ;
}
}
public :
public :
template < class T >
template < class T >
@ -236,24 +235,7 @@ public:
button - > renderInMain = false ; //Now we are in control!
button - > renderInMain = false ; //Now we are in control!
button - > parentComponent = this ;
button - > parentComponent = this ;
if ( button - > rect . pos . x < bounds . pos . x ) {
CalculateBounds ( ) ;
float sizeIncrease = bounds . pos . x - button - > rect . pos . x ;
bounds . size . x + = sizeIncrease ;
bounds . pos . x = button - > rect . pos . x ;
}
if ( button - > rect . right ( ) . start . x > bounds . right ( ) . start . x ) {
float sizeIncrease = button - > rect . right ( ) . start . x - bounds . right ( ) . start . x ;
bounds . size . x + = sizeIncrease ;
}
if ( button - > rect . pos . y < bounds . pos . y ) {
float sizeIncrease = bounds . pos . y - button - > rect . pos . y ;
bounds . size . y + = sizeIncrease ;
bounds . pos . y = button - > rect . pos . y ;
}
if ( button - > rect . bottom ( ) . start . y > bounds . bottom ( ) . start . y ) {
float sizeIncrease = button - > rect . bottom ( ) . start . y - bounds . bottom ( ) . start . y ;
bounds . size . y + = sizeIncrease ;
}
Menu : : menus [ parentMenu ] - > _AddComponent ( key , button ) ;
Menu : : menus [ parentMenu ] - > _AddComponent ( key , button ) ;
return button ;
return button ;