Textbox bounds checking
This commit is contained in:
parent
03cd07f6b8
commit
c5a85c7fcd
@ -52,11 +52,22 @@ void Textbox::Update(PixelGameEngine*pge){
|
||||
|
||||
void Textbox::Draw(PixelGameEngine*pge,Resources&resources){
|
||||
if(visible){
|
||||
vf2d finalPos=pos;
|
||||
geom2d::rect<float>boxRect={pos-vf2d{2,2},maxSize+vf2d{4,4}};
|
||||
pge->FillRectDecal(pos-vf2d{2,2},maxSize+vf2d{4,4},VERY_DARK_GREEN);
|
||||
pge->DrawRectDecal(pos-vf2d{1,1},maxSize+vf2d{3,3},WHITE);
|
||||
pge->DrawShadowStringPropDecal(pos+vf2d{1,1},displayText,{220,220,220});
|
||||
if(boxRect.bottom().start.y>=pge->ScreenHeight()){
|
||||
boxRect.pos-={0,boxRect.bottom().start.y-pge->ScreenHeight()};
|
||||
}
|
||||
if(boxRect.right().start.x>=pge->ScreenWidth()){
|
||||
boxRect.pos-={boxRect.right().start.x-pge->ScreenWidth(),0};
|
||||
}
|
||||
if(boxRect.top().start.y<0){
|
||||
boxRect.pos+={0,-boxRect.top().start.y};
|
||||
}
|
||||
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->DrawShadowStringPropDecal(boxRect.pos+vf2d{3,3},displayText,{220,220,220});
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,4 +90,8 @@ void Textbox::UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources){
|
||||
UpdatePosition(pos);
|
||||
Update(pge);
|
||||
Draw(pge,resources);
|
||||
}
|
||||
|
||||
vf2d Textbox::GetSize(){
|
||||
return maxSize;
|
||||
}
|
||||
@ -24,6 +24,7 @@ public:
|
||||
void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources);
|
||||
std::string&GetCurrentString();
|
||||
void SetVisible(bool visible);
|
||||
vf2d GetSize();
|
||||
private:
|
||||
void Update(PixelGameEngine*pge);
|
||||
void UpdatePosition(vf2d newPos);
|
||||
|
||||
@ -61,6 +61,7 @@ bool VirusAttack::OnUserCreate(){
|
||||
unitCreationBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",
|
||||
{});
|
||||
unitCreationBox.SetVisible(false);
|
||||
testBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",{});
|
||||
|
||||
IMAGES[MINIMAP_OUTLINE]=std::make_unique<Renderable>();
|
||||
IMAGES[MINIMAP_OUTLINE]->Create(64,64);
|
||||
@ -534,6 +535,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
|
||||
DrawMinimap();
|
||||
|
||||
unitCreationBox.UpdateAndDraw(GetMousePos(),this,player_resources);
|
||||
testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources);
|
||||
|
||||
std::sort(units.begin(),units.end(),[&](auto&u1,auto&u2){
|
||||
float dist1=geom2d::line<float>(u1->GetGhostPos(),GetWorldMousePos()).length();
|
||||
|
||||
@ -38,7 +38,7 @@ private:
|
||||
|
||||
TileTransformedView game;
|
||||
|
||||
Textbox unitCreationBox;
|
||||
Textbox unitCreationBox,testBox;
|
||||
|
||||
QuickGUI::Manager unitCreationList;
|
||||
QuickGUI::ImageButton*leftShifterButton;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user