[Fix] Fixed system_info_view's misalignment.

This commit is contained in:
Allanis 2018-01-15 23:31:40 +00:00
parent 1e1bcb88c5
commit ab7d16613a
3 changed files with 15 additions and 11 deletions

View File

@ -506,7 +506,6 @@ StarSystem::StarSystem(int sector_x, int sector_y, int system_idx) {
centGrav2->name = s.m_systems[system_idx].name; centGrav2->name = s.m_systems[system_idx].name;
centGrav2->orbMax = 0; centGrav2->orbMax = 0;
StarSystem::BodyType type = s.m_systems[system_idx].primaryStarClass;
star[2] = new SBody; star[2] = new SBody;
star[2]->name = s.m_systems[system_idx].name+" C"; star[2]->name = s.m_systems[system_idx].name+" C";
star[2]->parent = centGrav2; star[2]->parent = centGrav2;

View File

@ -55,7 +55,8 @@ void SystemInfoView::OnBodySelected(StarSystem::SBody* b) {
m_infoText->SetText(desc); m_infoText->SetText(desc);
} }
void SystemInfoView::PutBodies(StarSystem::SBody* body, int dir, float pos[2], int& majorBodies) { void SystemInfoView::PutBodies(StarSystem::SBody* body, int dir, float pos[2],
int& majorBodies, float prevSize) {
float size[2]; float size[2];
float myPos[2]; float myPos[2];
myPos[0] = pos[0]; myPos[0] = pos[0];
@ -64,20 +65,24 @@ void SystemInfoView::PutBodies(StarSystem::SBody* body, int dir, float pos[2], i
Gui::ImageButton* ib = new Gui::ImageButton(body->GetIcon()); Gui::ImageButton* ib = new Gui::ImageButton(body->GetIcon());
ib->GetSize(size); ib->GetSize(size);
size[1] = -size[1]; size[1] = -size[1];
pos[dir] += size[dir]; if(prevSize == -1) prevSize = size[!dir];
myPos[dir] += size[dir];
ib->onClick.connect(sigc::bind(sigc::mem_fun(this, &SystemInfoView::OnBodySelected), body)); ib->onClick.connect(sigc::bind(sigc::mem_fun(this, &SystemInfoView::OnBodySelected), body));
Add(ib, pos[0], pos[1]+0.5*size[1]); myPos[0] += (dir ? prevSize*0.5 - size[0]*0.5 : 0);
myPos[1] += (!dir ? prevSize*0.5 - size[1]*0.5 : 0);
Add(ib, myPos[0], myPos[1]+size[1]);
majorBodies++; majorBodies++;
pos[dir] += size[dir];
dir = !dir; dir = !dir;
myPos[dir] += 0.5*size[dir]; myPos[dir] += size[dir];
} else { } else {
size[0] = -1;
size[1] = -1;
pos[!dir] += 320; pos[!dir] += 320;
} }
for(std::vector<StarSystem::SBody*>::iterator i = body->children.begin(); for(std::vector<StarSystem::SBody*>::iterator i = body->children.begin();
i != body->children.end(); ++i) { i != body->children.end(); ++i) {
PutBodies(*i, dir, myPos, majorBodies); PutBodies(*i, dir, myPos, majorBodies, size[!dir]);
} }
} }
@ -88,10 +93,10 @@ void SystemInfoView::SystemChanged(StarSystem* s) {
GetSize(csize); GetSize(csize);
float pos[2]; float pos[2];
pos[0] = 50; pos[0] = 0;
pos[1] = csize[1]+40; pos[1] = csize[1];
PutBodies(s->rootBody, 1, pos, majorBodies); PutBodies(s->rootBody, 1, pos, majorBodies, -1);
char buf[512]; char buf[512];
snprintf(buf, sizeof(buf), "Stable system with %d major bodies", majorBodies); snprintf(buf, sizeof(buf), "Stable system with %d major bodies", majorBodies);

View File

@ -13,7 +13,7 @@ public:
private: private:
void SystemChanged(StarSystem* s); void SystemChanged(StarSystem* s);
void OnBodySelected(StarSystem::SBody* b); void OnBodySelected(StarSystem::SBody* b);
void PutBodies(StarSystem::SBody* body, int dir, float pos[2], int& majorBodies); void PutBodies(StarSystem::SBody* body, int dir, float pos[2], int& majorBodies, float prevSize);
StarSystem::SBody* m_bodySelected; StarSystem::SBody* m_bodySelected;
Gui::Label* m_infoText; Gui::Label* m_infoText;
}; };