fix sign box size, sign width with {t} and {p}, and zoom box size

This commit is contained in:
jacob1 2013-02-08 17:59:13 -05:00
parent 7ce34ad732
commit b8d53b5f76
5 changed files with 73 additions and 108 deletions

View File

@ -543,7 +543,7 @@ bool GameController::MouseUp(int x, int y, unsigned button)
for (std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter)
{
int signx, signy, signw, signh;
(*iter).pos(signx, signy, signw, signh);
(*iter).pos((*iter).getText(sim), signx, signy, signw, signh);
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
{
if (sregexp((*iter).text.c_str(), "^{[c|t]:[0-9]*|.*}$")==0)

View File

@ -75,6 +75,7 @@ public:
if(prompt->signID!=-1)
{
prompt->sim->signs[prompt->signID].text = sender->GetText();
prompt->sim->signs[prompt->signID].ju = (sign::Justification)prompt->justification->GetOption().second;
}
}
};
@ -89,6 +90,7 @@ public:
if(prompt->signID!=-1)
{
prompt->movingSign = &prompt->sim->signs[prompt->signID];
prompt->sim->signs[prompt->signID].ju = (sign::Justification)prompt->justification->GetOption().second;
prompt->signMoving = true;
}
}
@ -175,48 +177,35 @@ void SignWindow::DoDraw()
for(std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter)
{
sign & currentSign = *iter;
int x, y, w, h;
int x, y, w, h, dx, dy;
Graphics * g = ui::Engine::Ref().g;
char buff[256]; //Buffer
currentSign.pos(x, y, w, h);
g->clearrect(x, y, w, h);
g->drawrect(x, y, w, h, 192, 192, 192, 255);
//Displaying special information
if (currentSign.text == "{p}")
{
float pressure = 0.0f;
if (currentSign.x>=0 && currentSign.x<XRES && currentSign.y>=0 && currentSign.y<YRES)
pressure = sim->pv[currentSign.y/CELL][currentSign.x/CELL];
sprintf(buff, "Pressure: %3.2f", pressure); //...pressure
g->drawtext(x+3, y+3, buff, 255, 255, 255, 255);
}
else if (currentSign.text == "{t}")
{
if (currentSign.x>=0 && currentSign.x<XRES && currentSign.y>=0 && currentSign.y<YRES && sim->pmap[currentSign.y][currentSign.x])
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[currentSign.y][currentSign.x]>>8].temp-273.15); //...temperature
else
sprintf(buff, "Temp: 0.00"); //...temperature
g->drawtext(x+3, y+3, buff, 255, 255, 255, 255);
}
else if (sregexp(currentSign.text.c_str(), "^{[c|t]:[0-9]*|.*}$")==0)
{
int sldr, startm;
memset(buff, 0, sizeof(buff));
for (sldr=3; currentSign.text[sldr-1] != '|'; sldr++)
startm = sldr + 1;
sldr = startm;
while (currentSign.text[sldr] != '}')
{
buff[sldr - startm] = currentSign.text[sldr];
sldr++;
}
g->drawtext(x+3, y+3, buff, 0, 191, 255, 255);
}
std::string text = currentSign.getText(sim);
currentSign.pos(text, x, y, w, h);
g->clearrect(x, y, w+1, h);
g->drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (sregexp(currentSign.text.c_str(), "^{[c|t]:[0-9]*|.*}$"))
g->drawtext(x+3, y+3, text, 255, 255, 255, 255);
else
g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
x = currentSign.x;
y = currentSign.y;
dx = 1 - currentSign.ju;
dy = (currentSign.y > 18) ? -1 : 1;
#ifdef OGLR
glBegin(GL_LINES);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex2i(x, y);
glVertex2i(x+(dx*4), y+(dy*4));
glEnd();
#else
for (int j=0; j<4; j++)
{
g->drawtext(x+3, y+3, currentSign.text, 255, 255, 255, 255);
g->blendpixel(x, y, 192, 192, 192, 255);
x+=dx;
y+=dy;
}
#endif
}
if(!signMoving)
{
@ -277,7 +266,7 @@ void SignTool::Click(Simulation * sim, Brush * brush, ui::Point position)
{
int signX, signY, signW, signH, signIndex = -1;
for(int i = 0; i < sim->signs.size(); i++){
sim->signs[i].pos(signX, signY, signW, signH);
sim->signs[i].pos(sim->signs[i].getText(sim), signX, signY, signW, signH);
if(position.X > signX && position.X < signX+signW && position.Y > signY && position.Y < signY+signH)
{
signIndex = i;

View File

@ -487,9 +487,9 @@ void Renderer::RenderZoom()
int x, y, i, j;
pixel pix;
pixel * img = vid;
clearrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2);
drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+4, zoomScopeSize*ZFACTOR+4, 192, 192, 192, 255);
drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 0, 0, 0, 255);
clearrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+1, zoomScopeSize*ZFACTOR+1);
drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+3, zoomScopeSize*ZFACTOR+3, 192, 192, 192, 255);
drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+1, zoomScopeSize*ZFACTOR+1, 0, 0, 0, 255);
for (j=0; j<zoomScopeSize; j++)
for (i=0; i<zoomScopeSize; i++)
{
@ -828,46 +828,14 @@ void Renderer::DrawSigns()
for (i=0; i < signs.size(); i++)
if (signs[i].text.length())
{
char buff[256]; //Buffer
sim->signs[i].pos(x, y, w, h);
clearrect(x, y, w, h);
drawrect(x, y, w, h, 192, 192, 192, 255);
//Displaying special information
if (signs[i].text == "{p}")
{
float pressure = 0.0f;
if (signs[i].x>=0 && signs[i].x<XRES && signs[i].y>=0 && signs[i].y<YRES)
pressure = sim->pv[signs[i].y/CELL][signs[i].x/CELL];
sprintf(buff, "Pressure: %3.2f", pressure); //...pressure
drawtext(x+3, y+3, buff, 255, 255, 255, 255);
}
else if (signs[i].text == "{t}")
{
if (signs[i].x>=0 && signs[i].x<XRES && signs[i].y>=0 && signs[i].y<YRES && sim->pmap[signs[i].y][signs[i].x])
sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[signs[i].y][signs[i].x]>>8].temp-273.15); //...temperature
else
sprintf(buff, "Temp: 0.00"); //...temperature
drawtext(x+3, y+3, buff, 255, 255, 255, 255);
}
else if (sregexp(signs[i].text.c_str(), "^{[c|t]:[0-9]*|.*}$")==0)
{
int sldr, startm;
memset(buff, 0, sizeof(buff));
for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
startm = sldr + 1;
sldr = startm;
while (signs[i].text[sldr] != '}')
{
buff[sldr - startm] = signs[i].text[sldr];
sldr++;
}
drawtext(x+3, y+3, buff, 0, 191, 255, 255);
}
std::string text = sim->signs[i].getText(sim);
sim->signs[i].pos(text, x, y, w, h);
clearrect(x, y, w+1, h);
drawrect(x, y, w+1, h, 192, 192, 192, 255);
if (sregexp(signs[i].text.c_str(), "^{[c|t]:[0-9]*|.*}$"))
drawtext(x+3, y+3, text, 255, 255, 255, 255);
else
{
drawtext(x+3, y+3, signs[i].text, 255, 255, 255, 255);
}
drawtext(x+3, y+3, text, 0, 191, 255, 255);
x = signs[i].x;
y = signs[i].y;
@ -887,15 +855,6 @@ void Renderer::DrawSigns()
y+=dy;
}
#endif
/*if (MSIGN==i)
{
bq = b;
b = SDL_GetMouseState(&mx, &my);
mx /= sdl_scale;
my /= sdl_scale;
signs[i].x = mx;
signs[i].y = my;
}*/
}
#ifdef OGLR
glTranslated(0, -MENUSIZE, 0);

View File

@ -7,6 +7,7 @@
#include "Sign.h"
#include "graphics/Graphics.h"
#include "simulation/Simulation.h"
#include "Misc.h"
sign::sign(std::string text_, int x_, int y_, Justification justification_):
@ -17,38 +18,51 @@ sign::sign(std::string text_, int x_, int y_, Justification justification_):
{
}
void sign::pos(int & x0, int & y0, int & w, int & h)
std::string sign::getText(Simulation *sim)
{
//Changing width if sign have special content
if (text == "{p}")
char buff[256];
char signText[256];
sprintf(signText, "%s", text.c_str());
if (!strcmp(signText,"{p}"))
{
w = Graphics::textwidth("Pressure: -000.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
}
else if (text == "{t}")
else if (!strcmp(signText,"{t}"))
{
w = Graphics::textwidth("Temp: 0000.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
}
else if (sregexp(text.c_str(), "^{[c|t]:[0-9]*|.*}$")==0)
else if (sregexp(signText, "^{[c|t]:[0-9]*|.*}$")==0)
{
int sldr, startm;
char buff[256];
memset(buff, 0, sizeof(buff));
for (sldr=3; text[sldr-1] != '|'; sldr++)
for (sldr=3; signText[sldr-1] != '|'; sldr++)
startm = sldr + 1;
sldr = startm;
while (text[sldr] != '}')
while (signText[sldr] != '}')
{
buff[sldr - startm] = text[sldr];
buff[sldr - startm] = signText[sldr];
sldr++;
}
w = Graphics::textwidth(buff) + 5;
}
else
{
w = Graphics::textwidth(text.c_str()) + 5;
sprintf(buff, "%s", signText);
}
h = 14;
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;
x0 = (ju == 2) ? x - w :
(ju == 1) ? x - w/2 : x;
y0 = (y > 18) ? y - 18 : y + 4;

View File

@ -11,6 +11,8 @@
#include <string>
class Simulation;
class sign
{
public:
@ -20,7 +22,8 @@ public:
Justification ju;
std::string text;
void pos(int & x0, int & y0, int & w, int & h);
std::string getText(Simulation *sim);
void pos(std::string signText, int & x0, int & y0, int & w, int & h);
};
#endif