From 027ec204499aa85da30b83c3d1f2ead33a3191ed Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 30 Aug 2023 18:19:54 -0500 Subject: [PATCH] Padding and auto-expanding height. --- olcCodeJam2023Entry/Textbox.cpp | 7 ++++--- olcCodeJam2023Entry/Textbox.h | 2 +- olcCodeJam2023Entry/VirusAttack.cpp | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/olcCodeJam2023Entry/Textbox.cpp b/olcCodeJam2023Entry/Textbox.cpp index e8f41e8..f57bd7a 100644 --- a/olcCodeJam2023Entry/Textbox.cpp +++ b/olcCodeJam2023Entry/Textbox.cpp @@ -44,6 +44,7 @@ void Textbox::Update(PixelGameEngine*pge){ } displayText+=text[textboxMarker+1]; textboxMarker++; + maxSize.y=std::max(maxSize.y,float(pge->GetTextSizeProp(tempText).y)); } lastLetterTime=letterDisplayDelay; } @@ -52,7 +53,7 @@ void Textbox::Update(PixelGameEngine*pge){ void Textbox::Draw(PixelGameEngine*pge,Resources&resources){ if(visible){ - geom2d::rectboxRect={pos-vf2d{2,2},maxSize+vf2d{4,4}}; + geom2d::rectboxRect={pos-vf2d{3,3},maxSize+vf2d{6,6}}; if(boxRect.bottom().start.y>=pge->ScreenHeight()){ boxRect.pos-={0,boxRect.bottom().start.y-pge->ScreenHeight()}; } @@ -65,8 +66,8 @@ void Textbox::Draw(PixelGameEngine*pge,Resources&resources){ if(boxRect.left().start.x<0){ boxRect.pos+={-boxRect.left().start.x,0}; } - pge->FillRectDecal(boxRect.pos,maxSize+vf2d{4,4},VERY_DARK_GREEN); - pge->DrawRectDecal(boxRect.pos+vf2d{1,1},maxSize+vf2d{3,3},WHITE); + pge->FillRectDecal(boxRect.pos,maxSize+vf2d{6,6},VERY_DARK_GREEN); + pge->DrawRectDecal(boxRect.pos+vf2d{1,1},maxSize+vf2d{4,4},WHITE); pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3,3},displayText,{220,220,220}); } } diff --git a/olcCodeJam2023Entry/Textbox.h b/olcCodeJam2023Entry/Textbox.h index d83138f..acf7608 100644 --- a/olcCodeJam2023Entry/Textbox.h +++ b/olcCodeJam2023Entry/Textbox.h @@ -19,7 +19,7 @@ class Textbox{ bool visible=true; public: Textbox(); - void Initialize(std::string text,vf2d pos,std::string headerText="",vf2d maxSize={120,64},std::vectorresourceCost={},float letterDisplayDelay=0.01); + void Initialize(std::string text,vf2d pos={},std::string headerText="",vf2d maxSize={120,1},std::vectorresourceCost={},float letterDisplayDelay=0.01); void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources); std::string&GetCurrentString(); diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index e281943..9539602 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -62,6 +62,7 @@ bool VirusAttack::OnUserCreate(){ {}); unitCreationBox.SetVisible(false); testBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",{}); + testBox.SetVisible(false); IMAGES[MINIMAP_OUTLINE]=std::make_unique(); IMAGES[MINIMAP_OUTLINE]->Create(64,64);