@ -0,0 +1,68 @@ |
|||||||
|
#pragma once |
||||||
|
#include "Menu.h" |
||||||
|
#include "MenuComponent.h" |
||||||
|
#include "Crawler.h" |
||||||
|
|
||||||
|
class ScrollableWindowComponent:public MenuComponent{ |
||||||
|
protected: |
||||||
|
Renderable r; |
||||||
|
std::vector<MenuComponent*>components; |
||||||
|
vf2d scrollOffset{}; |
||||||
|
geom2d::rect<float>bounds; |
||||||
|
public: |
||||||
|
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick) |
||||||
|
:MenuComponent(parent,rect,"",onClick,false){ |
||||||
|
r.Create(rect.size.x,rect.size.y); |
||||||
|
} |
||||||
|
protected: |
||||||
|
virtual inline void Update(Crawler*game)override{ |
||||||
|
MenuComponent::Update(game); |
||||||
|
for(MenuComponent*component:components){ |
||||||
|
component->Update(game); |
||||||
|
} |
||||||
|
} |
||||||
|
virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ |
||||||
|
MenuComponent::Draw(game,parentPos,focused); |
||||||
|
Sprite*prevDrawTarget=game->GetDrawTarget(); |
||||||
|
game->SetDrawTarget(r.Sprite()); |
||||||
|
game->Clear(BLANK); |
||||||
|
for(MenuComponent*component:components){ |
||||||
|
component->Draw(game,scrollOffset,focused); |
||||||
|
} |
||||||
|
game->SetDrawTarget(prevDrawTarget); |
||||||
|
game->DrawSprite(parentPos,r.Sprite()); |
||||||
|
} |
||||||
|
virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ |
||||||
|
MenuComponent::DrawDecal(game,parentPos,focused); |
||||||
|
game->DrawRectDecal(parentPos,rect.size); |
||||||
|
for(MenuComponent*component:components){ |
||||||
|
component->DrawDecal(game,parentPos+scrollOffset,focused); |
||||||
|
} |
||||||
|
} |
||||||
|
public: |
||||||
|
void inline AddComponent(Menu*parentMenu,std::string key,MenuComponent*button){ |
||||||
|
components.push_back(button); |
||||||
|
button->renderInMain=false; //Now we are in control!
|
||||||
|
|
||||||
|
if(button->rect.pos.x<bounds.pos.x){ |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
parentMenu->AddComponent(key,button); |
||||||
|
} |
||||||
|
}; |
After Width: | Height: | Size: 621 B |
After Width: | Height: | Size: 669 B |
After Width: | Height: | Size: 626 B |
After Width: | Height: | Size: 683 B |
After Width: | Height: | Size: 681 B |
After Width: | Height: | Size: 666 B |
After Width: | Height: | Size: 671 B |
After Width: | Height: | Size: 691 B |
After Width: | Height: | Size: 657 B |
After Width: | Height: | Size: 695 B |
After Width: | Height: | Size: 684 B |
After Width: | Height: | Size: 657 B |
After Width: | Height: | Size: 699 B |
After Width: | Height: | Size: 651 B |
After Width: | Height: | Size: 642 B |
After Width: | Height: | Size: 649 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 637 B |
After Width: | Height: | Size: 668 B |
After Width: | Height: | Size: 671 B |