The-Powder-Toy/src/simulation/Sign.cpp

70 lines
1.5 KiB
C++
Raw Normal View History

2012-06-25 07:57:23 -05:00
/*
* Sign.cpp
*
* Created on: Jun 25, 2012
* Author: Simon
*/
#include "Sign.h"
2012-07-06 10:06:26 -05:00
#include "graphics/Graphics.h"
#include "simulation/Simulation.h"
2012-06-25 07:57:23 -05:00
#include "Misc.h"
sign::sign(std::string text_, int x_, int y_, Justification justification_):
text(text_),
x(x_),
y(y_),
ju(justification_)
{
}
std::string sign::getText(Simulation *sim)
2012-06-25 07:57:23 -05:00
{
char buff[256];
char signText[256];
sprintf(signText, "%s", text.c_str());
if (!strcmp(signText,"{p}"))
2012-06-25 07:57:23 -05:00
{
float pressure = 0.0f;
if (x>=0 && x<XRES && y>=0 && y<YRES)
pressure = sim->pv[y/CELL][x/CELL];
sprintf(buff, "Pressure: %3.2f", pressure); //...pressure
2012-06-25 07:57:23 -05:00
}
else if (!strcmp(signText,"{t}"))
2012-06-25 07:57:23 -05:00
{
if (x>=0 && x<XRES && y>=0 && y<YRES && sim->pmap[y][x])
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[y][x]>>8].temp-273.15); //...temperature
else
sprintf(buff, "Temp: 0.00"); //...temperature
2012-06-25 07:57:23 -05:00
}
else if (sregexp(signText, "^{[c|t]:[0-9]*|.*}$")==0)
2012-06-25 07:57:23 -05:00
{
int sldr, startm;
memset(buff, 0, sizeof(buff));
for (sldr=3; signText[sldr-1] != '|'; sldr++)
2012-06-25 07:57:23 -05:00
startm = sldr + 1;
sldr = startm;
while (signText[sldr] != '}')
2012-06-25 07:57:23 -05:00
{
buff[sldr - startm] = signText[sldr];
2012-06-25 07:57:23 -05:00
sldr++;
}
}
else
{
sprintf(buff, "%s", signText);
2012-06-25 07:57:23 -05:00
}
return std::string(buff,256);
}
void sign::pos(std::string signText, int & x0, int & y0, int & w, int & h)
{
w = Graphics::textwidth(signText.c_str()) + 5;
h = 15;
2012-06-25 07:57:23 -05:00
x0 = (ju == 2) ? x - w :
(ju == 1) ? x - w/2 : x;
y0 = (y > 18) ? y - 18 : y + 4;
}