Implement parent component hover state handling.
This commit is contained in:
@@ -9,6 +9,10 @@ protected:
|
||||
std::vector<MenuComponent*>components;
|
||||
vf2d scrollOffset{};
|
||||
geom2d::rect<float>bounds;
|
||||
private:
|
||||
inline bool OnScreen(MenuComponent*component){
|
||||
return geom2d::overlaps(rect,geom2d::rect<float>{component->rect.pos+scrollOffset,component->rect.size});
|
||||
}
|
||||
public:
|
||||
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
|
||||
:MenuComponent(parent,rect,"",onClick,false){
|
||||
@@ -17,8 +21,18 @@ public:
|
||||
protected:
|
||||
virtual inline void Update(Crawler*game)override{
|
||||
MenuComponent::Update(game);
|
||||
|
||||
if(game->GetMouseWheel()!=0){
|
||||
if(game->GetMouseWheel()>0){
|
||||
scrollOffset.y-=4;
|
||||
}else{
|
||||
scrollOffset.y+=4;
|
||||
}
|
||||
}
|
||||
|
||||
for(MenuComponent*component:components){
|
||||
component->Update(game);
|
||||
component->disabled=!OnScreen(component);
|
||||
component->_Update(game);
|
||||
}
|
||||
}
|
||||
virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{
|
||||
@@ -27,7 +41,7 @@ protected:
|
||||
game->SetDrawTarget(r.Sprite());
|
||||
game->Clear(BLANK);
|
||||
for(MenuComponent*component:components){
|
||||
component->Draw(game,scrollOffset,focused);
|
||||
component->_Draw(game,scrollOffset,focused);
|
||||
}
|
||||
game->SetDrawTarget(prevDrawTarget);
|
||||
game->DrawSprite(parentPos,r.Sprite());
|
||||
@@ -36,13 +50,17 @@ protected:
|
||||
MenuComponent::DrawDecal(game,parentPos,focused);
|
||||
game->DrawRectDecal(parentPos,rect.size);
|
||||
for(MenuComponent*component:components){
|
||||
component->DrawDecal(game,parentPos+scrollOffset,focused);
|
||||
component->_DrawDecal(game,parentPos+scrollOffset,focused);
|
||||
}
|
||||
}
|
||||
virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{
|
||||
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+child->rect.pos+scrollOffset,child->rect.size},game->GetMousePos());
|
||||
}
|
||||
public:
|
||||
void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){
|
||||
components.push_back(button);
|
||||
button->renderInMain=false; //Now we are in control!
|
||||
button->parentComponent=this;
|
||||
|
||||
if(button->rect.pos.x<bounds.pos.x){
|
||||
float sizeIncrease=bounds.pos.x-button->rect.pos.x;
|
||||
|
||||
Reference in New Issue
Block a user