diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-25 12:57:23 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-06-25 12:57:23 (GMT) |
| commit | ab8f382acc863d8d71ddb75b3161629cf5dd8d64 (patch) | |
| tree | 18744659d28c8fd3556a8c8bb3e17b308aeadc75 /src/simulation | |
| parent | 04b007b36f3341d0906b64f8f59eab36ba58988a (diff) | |
| download | powder-ab8f382acc863d8d71ddb75b3161629cf5dd8d64.zip powder-ab8f382acc863d8d71ddb75b3161629cf5dd8d64.tar.gz | |
Sign tool can now edit existing signs
Diffstat (limited to 'src/simulation')
| -rw-r--r-- | src/simulation/Sign.cpp | 55 | ||||
| -rw-r--r-- | src/simulation/Sign.h | 11 | ||||
| -rw-r--r-- | src/simulation/Simulation.h | 1 |
3 files changed, 61 insertions, 6 deletions
diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp new file mode 100644 index 0000000..1ce471f --- /dev/null +++ b/src/simulation/Sign.cpp @@ -0,0 +1,55 @@ +/* + * Sign.cpp + * + * Created on: Jun 25, 2012 + * Author: Simon + */ + +#include "Sign.h" +#include "Graphics.h" +#include "Misc.h" + +sign::sign(std::string text_, int x_, int y_, Justification justification_): + text(text_), + x(x_), + y(y_), + ju(justification_) +{ +} + +void sign::pos(int & x0, int & y0, int & w, int & h) +{ + //Changing width if sign have special content + if (text == "{p}") + { + w = Graphics::textwidth("Pressure: -000.00"); + } + else if (text == "{t}") + { + w = Graphics::textwidth("Temp: 0000.00"); + } + else if (sregexp(text.c_str(), "^{c:[0-9]*|.*}$")==0) + { + int sldr, startm; + char buff[256]; + memset(buff, 0, sizeof(buff)); + for (sldr=3; text[sldr-1] != '|'; sldr++) + startm = sldr + 1; + + sldr = startm; + while (text[sldr] != '}') + { + buff[sldr - startm] = text[sldr]; + sldr++; + } + w = Graphics::textwidth(buff) + 5; + } + else + { + w = Graphics::textwidth(text.c_str()) + 5; + } + h = 14; + 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 1b8a68c..14b7dac 100644 --- a/src/simulation/Sign.h +++ b/src/simulation/Sign.h @@ -9,19 +9,18 @@ #ifndef The_Powder_Toy_Sign_h #define The_Powder_Toy_Sign_h +#include <string> + class sign { public: enum Justification { Left = 0, Centre = 1, Right = 2 }; - sign(std::string text_, int x_, int y_, Justification justification_): - text(text_), - x(x_), - y(y_), - ju(justification_) - {} + sign(std::string text_, int x_, int y_, Justification justification_); int x, y; Justification ju; std::string text; + + void pos(int & x0, int & y0, int & w, int & h); }; #endif diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 8e25daa..b9cc6bb 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -141,6 +141,7 @@ public: //int get_brush_flags(); inline int create_part(int p, int x, int y, int t); inline void delete_part(int x, int y, int flags); + void get_sign_pos(int i, int *x0, int *y0, int *w, int *h); inline int is_wire(int x, int y); inline int is_wire_off(int x, int y); inline void set_emap(int x, int y); |
