Prepare framework with Draw and DrawDecal split.
This commit is contained in:
+62
-16
@@ -17,7 +17,8 @@ Menu::Menu(){}
|
||||
|
||||
Menu::Menu(vf2d pos,vf2d size)
|
||||
:pos(pos==CENTERED?WINDOW_SIZE/2-size/2:vi2d{pos}),size(size){
|
||||
|
||||
r.Create(size.x,size.y);
|
||||
overlay.Create(WINDOW_SIZE.x,WINDOW_SIZE.y);
|
||||
}
|
||||
|
||||
void Menu::InitializeMenus(){
|
||||
@@ -139,30 +140,65 @@ void Menu::Update(Crawler*game){
|
||||
};
|
||||
|
||||
void Menu::Draw(Crawler*game){
|
||||
|
||||
if(GetCurrentTheme().IsScaled()){
|
||||
DrawScaledWindow(game,pos);
|
||||
DrawScaledWindowBackground(game,pos);
|
||||
}else{
|
||||
DrawTiledWindow(game,pos);
|
||||
DrawTiledWindowBackground(game,pos);
|
||||
}
|
||||
|
||||
game->SetDrawTarget(r.Sprite());
|
||||
Pixel::Mode prevMode=game->GetPixelMode();
|
||||
game->SetPixelMode(Pixel::MASK);
|
||||
game->Clear(BLANK);
|
||||
for(auto&key:buttons){
|
||||
for(auto&button:key.second){
|
||||
button->Draw(game,pos,this==Menu::stack.back());
|
||||
button->Draw(game,{0,0},this==Menu::stack.back());
|
||||
}
|
||||
}
|
||||
for(auto&component:displayComponents){
|
||||
component->Draw(game,pos,this==Menu::stack.back());
|
||||
component->Draw(game,{0,0},this==Menu::stack.back());
|
||||
}
|
||||
game->SetPixelMode(prevMode);
|
||||
game->SetDrawTarget(nullptr);
|
||||
r.Decal()->Update();
|
||||
game->DrawDecal(pos,r.Decal());
|
||||
for(auto&key:buttons){
|
||||
for(auto&button:key.second){
|
||||
button->DrawDecal(game,{0,0},this==Menu::stack.back());
|
||||
}
|
||||
}
|
||||
for(auto&component:displayComponents){
|
||||
component->DrawDecal(game,{0,0},this==Menu::stack.back());
|
||||
}
|
||||
|
||||
if(GetCurrentTheme().IsScaled()){
|
||||
DrawScaledWindowBorder(game,pos);
|
||||
}else{
|
||||
DrawTiledWindowBorder(game,pos);
|
||||
}
|
||||
|
||||
if(draggingComponent!=nullptr){
|
||||
game->SetDrawTarget(overlay.Sprite());
|
||||
Pixel::Mode prevMode=game->GetPixelMode();
|
||||
game->SetPixelMode(Pixel::MASK);
|
||||
game->Clear(BLANK);
|
||||
vf2d offsetPos=draggingComponent->rect.pos;
|
||||
if(!MOUSE_NAVIGATION){
|
||||
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
||||
draggingComponent->Draw(game,pos+-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
|
||||
draggingComponent->Draw(game,pos-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
|
||||
}else{
|
||||
draggingComponent->Draw(game,-offsetPos+game->GetMousePos(),this==Menu::stack.back());
|
||||
}
|
||||
game->SetPixelMode(prevMode);
|
||||
game->SetDrawTarget(nullptr);
|
||||
overlay.Decal()->Update();
|
||||
game->DrawDecal({0,0},overlay.Decal());
|
||||
if(!MOUSE_NAVIGATION){
|
||||
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
||||
draggingComponent->DrawDecal(game,-offsetPos+selectedComponent->rect.pos+vi2d{1,-4},this==Menu::stack.back());
|
||||
}else{
|
||||
draggingComponent->DrawDecal(game,-pos-offsetPos+game->GetMousePos(),this==Menu::stack.back());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -299,7 +335,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::DrawScaledWindow(Crawler*game,vf2d menuPos){
|
||||
void Menu::DrawScaledWindowBorder(Crawler*game,vf2d menuPos){
|
||||
vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]};
|
||||
|
||||
//Upper-Left
|
||||
@@ -318,16 +354,9 @@ void Menu::DrawScaledWindow(Crawler*game,vf2d menuPos){
|
||||
game->DrawPartialDecal(menuPos+vf2d{size.x,0},vf2d{patchSize.x,size.y},GetPatchPart(2,1).Decal(),{patchSize.x*2,patchSize.y*1},patchSize,GetRenderColor());
|
||||
//Bottom
|
||||
game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GetPatchPart(1,2).Decal(),{patchSize.x*1,patchSize.y*2},patchSize,GetRenderColor());
|
||||
//Center
|
||||
if(GetCurrentTheme().HasBackground()){
|
||||
Decal*back=GetCurrentTheme().GetBackground();
|
||||
game->DrawPartialDecal(menuPos,size,back,{0,0},back->sprite->Size(),GetRenderColor());
|
||||
}else{
|
||||
game->DrawPartialDecal(menuPos,size,GetPatchPart(1,1).Decal(),{patchSize.x*1,patchSize.y*1},patchSize,GetRenderColor());
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::DrawTiledWindow(Crawler*game,vf2d menuPos){
|
||||
void Menu::DrawTiledWindowBorder(Crawler*game,vf2d menuPos){
|
||||
vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]};
|
||||
|
||||
//Upper-Left
|
||||
@@ -346,6 +375,23 @@ void Menu::DrawTiledWindow(Crawler*game,vf2d menuPos){
|
||||
game->DrawPartialDecal(menuPos+vf2d{size.x,0},vf2d{patchSize.x,size.y},GetPatchPart(2,1).Decal(),{0,0},vf2d{patchSize.x,size.y},GetRenderColor());
|
||||
//Bottom
|
||||
game->DrawPartialDecal(menuPos+vf2d{0,size.y},vf2d{size.x,patchSize.y},GetPatchPart(1,2).Decal(),{0,0},vf2d{size.x,patchSize.y},GetRenderColor());
|
||||
}
|
||||
|
||||
void Menu::DrawScaledWindowBackground(Crawler*game,vf2d menuPos){
|
||||
vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]};
|
||||
|
||||
//Center
|
||||
if(GetCurrentTheme().HasBackground()){
|
||||
Decal*back=GetCurrentTheme().GetBackground();
|
||||
game->DrawPartialDecal(menuPos,size,back,{0,0},back->sprite->Size(),GetRenderColor());
|
||||
}else{
|
||||
game->DrawPartialDecal(menuPos,size,GetPatchPart(1,1).Decal(),{patchSize.x*1,patchSize.y*1},patchSize,GetRenderColor());
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::DrawTiledWindowBackground(Crawler*game,vf2d menuPos){
|
||||
vf2d patchSize={"Interface.9PatchSize"_f[0],"Interface.9PatchSize"_f[1]};
|
||||
|
||||
//Center
|
||||
if(GetCurrentTheme().HasBackground()){
|
||||
Decal*back=GetCurrentTheme().GetBackground();
|
||||
|
||||
Reference in New Issue
Block a user