From b8d53b5f7659f6b95f025a900d3b9982400dcc59 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 8 Feb 2013 17:59:13 -0500 Subject: [PATCH] fix sign box size, sign width with {t} and {p}, and zoom box size --- src/game/GameController.cpp | 2 +- src/game/SignTool.cpp | 67 ++++++++++++++++--------------------- src/graphics/Renderer.cpp | 63 ++++++---------------------------- src/simulation/Sign.cpp | 44 +++++++++++++++--------- src/simulation/Sign.h | 5 ++- 5 files changed, 73 insertions(+), 108 deletions(-) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 0b3568144..efe37c49d 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -543,7 +543,7 @@ bool GameController::MouseUp(int x, int y, unsigned button) for (std::vector::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) diff --git a/src/game/SignTool.cpp b/src/game/SignTool.cpp index af267af84..d2bba887f 100644 --- a/src/game/SignTool.cpp +++ b/src/game/SignTool.cpp @@ -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::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); + 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); - //Displaying special information - if (currentSign.text == "{p}") + 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++) { - float pressure = 0.0f; - if (currentSign.x>=0 && currentSign.x=0 && currentSign.ypv[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=0 && currentSign.ypmap[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); - } - else - { - 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; diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 50c9ba47a..e60f0f3a3 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -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; jsigns[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=0 && signs[i].ypv[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=0 && signs[i].ypmap[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); - } - else - { - drawtext(x+3, y+3, signs[i].text, 255, 255, 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, 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); diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 2caf6c3de..19261e4ab 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -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=0 && ypv[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=0 && ypmap[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; diff --git a/src/simulation/Sign.h b/src/simulation/Sign.h index 14b7dac34..1b45c25bc 100644 --- a/src/simulation/Sign.h +++ b/src/simulation/Sign.h @@ -11,6 +11,8 @@ #include +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