Allow PROP to set types from element name, fixes issue #48

This commit is contained in:
Simon Robertshaw 2012-08-03 12:52:07 +01:00
parent a3ebfb0ffd
commit 347c382e99
3 changed files with 58 additions and 7 deletions

View File

@ -49,11 +49,13 @@ position(position_)
ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit property"); ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit property");
messageLabel->SetTextColour(style::Colour::InformationTitle); messageLabel->SetTextColour(style::Colour::InformationTitle);
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop; messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
AddComponent(messageLabel); AddComponent(messageLabel);
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 17), "OK"); ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 17), "OK");
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom; okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200); okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
okayButton->SetActionCallback(new OkayAction(this)); okayButton->SetActionCallback(new OkayAction(this));
AddComponent(okayButton); AddComponent(okayButton);
@ -66,15 +68,16 @@ position(position_)
} }
property->SetOption(0); property->SetOption(0);
textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), ""); textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), "", "[value]");
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom; textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(textField); AddComponent(textField);
ui::Engine::Ref().ShowWindow(this); ui::Engine::Ref().ShowWindow(this);
} }
void PropertyWindow::SetProperty() void PropertyWindow::SetProperty()
{ {
if(property->GetOption().second!=-1) if(property->GetOption().second!=-1 && textField->GetText().length() > 0)
{ {
void * propValue; void * propValue;
int tempInt; int tempInt;
@ -102,8 +105,29 @@ void PropertyWindow::SetProperty()
} }
else else
{ {
istringstream(value) >> tempInt; if(properties[property->GetOption().second].Type == StructProperty::ParticleType)
{
int type = sim->GetParticleType(value);
if(type != -1)
{
#ifdef DEBUG
std::cout << "Got type from particle name" << std::endl;
#endif
tempInt = type;
}
else
{
stringstream(value) >> tempInt;
}
}
else
{
stringstream(value) >> tempInt;
}
} }
#ifdef DEBUG
std::cout << "Got int value " << tempInt << std::endl;
#endif
propValue = &tempInt; propValue = &tempInt;
break; break;
case StructProperty::UInteger: case StructProperty::UInteger:
@ -123,12 +147,18 @@ void PropertyWindow::SetProperty()
} }
else else
{ {
istringstream(value) >> tempUInt; stringstream(value) >> tempUInt;
} }
#ifdef DEBUG
std::cout << "Got uint value " << tempUInt << std::endl;
#endif
propValue = &tempUInt; propValue = &tempUInt;
break; break;
case StructProperty::Float: case StructProperty::Float:
istringstream(value) >> tempFloat; istringstream(value) >> tempFloat;
#ifdef DEBUG
std::cout << "Got float value " << tempFloat << std::endl;
#endif
propValue = &tempFloat; propValue = &tempFloat;
break; break;
default: default:
@ -146,6 +176,7 @@ void PropertyWindow::SetProperty()
} }
} }
} }
void PropertyWindow::OnDraw() void PropertyWindow::OnDraw()
{ {
Graphics * g = ui::Engine::Ref().g; Graphics * g = ui::Engine::Ref().g;

View File

@ -4294,6 +4294,24 @@ movedone:
} }
} }
int Simulation::GetParticleType(std::string type)
{
int i = -1;
char * txt = (char*)type.c_str();
// alternative names for some elements
if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
else if (strcasecmp(txt,"C5")==0) i = PT_C5;
else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
for (i=1; i<PT_NUM; i++) {
if (strcasecmp(txt, elements[i].Name)==0 && strlen(elements[i].Name) && elements[i].Enabled)
{
return i;
}
}
return -1;
}
void Simulation::update_particles()//doesn't update the particles themselves, but some other things void Simulation::update_particles()//doesn't update the particles themselves, but some other things
{ {
int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1; int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1;

View File

@ -183,6 +183,8 @@ public:
void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY); void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY);
int GetParticleType(std::string type);
void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate);
inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]); inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]);
inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]); inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]);