diff --git a/src/Renderer.cpp b/src/Renderer.cpp index cb6691195..51be5c2ed 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -58,6 +58,9 @@ void Renderer::clearScreen(float alpha) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); #endif +#ifdef OGLI + std::fill(vid, vid+(VIDXRES*VIDYRES), 0); +#endif } #ifdef OGLR void Renderer::checkShader(GLuint shader, char * shname) @@ -478,44 +481,6 @@ void Renderer::DrawWalls() #endif } -void Renderer::get_sign_pos(int i, int *x0, int *y0, int *w, int *h) -{ - std::vector signs = sim->signs; - //Changing width if sign have special content - if (signs[i].text == "{p}") - { - *w = Graphics::textwidth("Pressure: -000.00"); - } - else if (signs[i].text == "{t}") - { - *w = Graphics::textwidth("Temp: 0000.00"); - } - else if (sregexp(signs[i].text.c_str(), "^{c:[0-9]*|.*}$")==0) - { - int sldr, startm; - char buff[256]; - 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++; - } - *w = Graphics::textwidth(buff) + 5; - } - else - { - *w = Graphics::textwidth(signs[i].text.c_str()) + 5; - } - *h = 14; - *x0 = (signs[i].ju == 2) ? signs[i].x - *w : - (signs[i].ju == 1) ? signs[i].x - *w/2 : signs[i].x; - *y0 = (signs[i].y > 18) ? signs[i].y - 18 : signs[i].y + 4; -} - void Renderer::DrawSigns() { int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq; @@ -528,7 +493,7 @@ void Renderer::DrawSigns() if (signs[i].text.length()) { char buff[256]; //Buffer - get_sign_pos(i, &x, &y, &w, &h); + sim->signs[i].pos(x, y, w, h); clearrect(x, y, w, h); drawrect(x, y, w, h, 192, 192, 192, 255); diff --git a/src/Renderer.h b/src/Renderer.h index 88e379a55..b414fe4af 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -103,8 +103,6 @@ public: void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb); //... - void get_sign_pos(int i, int *x0, int *y0, int *w, int *h); - //Display mode modifiers void CompileDisplayMode(); void CompileRenderMode(); diff --git a/src/game/SignTool.cpp b/src/game/SignTool.cpp index a01ba77a0..35f802d53 100644 --- a/src/game/SignTool.cpp +++ b/src/game/SignTool.cpp @@ -32,13 +32,28 @@ public: { prompt->sim->signs.push_back(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, (sign::Justification)prompt->justification->GetOption().second)); } - else if(prompt->textField->GetText().length()) + else if(prompt->signID!=-1 && prompt->textField->GetText().length()) { prompt->sim->signs[prompt->signID] = sign(sign(prompt->textField->GetText(), prompt->signPosition.X, prompt->signPosition.Y, (sign::Justification)prompt->justification->GetOption().second)); } prompt->SelfDestruct(); } }; + class DeleteAction: public ui::ButtonAction + { + public: + SignWindow * prompt; + DeleteAction(SignWindow * prompt_) { prompt = prompt_; } + void ActionCallback(ui::Button * sender) + { + ui::Engine::Ref().CloseWindow(); + if(prompt->signID!=-1) + { + prompt->sim->signs.erase(prompt->sim->signs.begin()+prompt->signID); + } + prompt->SelfDestruct(); + } + }; }; SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_): @@ -48,28 +63,51 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi sim(sim_), signPosition(position_) { - ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "New sign"); + ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), "New sign"); 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::AlignMiddle; AddComponent(messageLabel); - + ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "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->SetActionCallback(new OkayAction(this)); AddComponent(okayButton); - justification = new ui::DropDown(ui::Point(8, 46), ui::Point(50, 16)); + ui::Label * tempLabel = new ui::Label(ui::Point(8, 48), ui::Point(40, 15), "Justify:"); + okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + AddComponent(tempLabel); + + justification = new ui::DropDown(ui::Point(52, 48), ui::Point(50, 16)); AddComponent(justification); - justification->AddOption(std::pair("Left", (int)sign::Left)); - justification->AddOption(std::pair("Centre", (int)sign::Centre)); - justification->AddOption(std::pair("Right", (int)sign::Right)); + justification->AddOption(std::pair("\x9D Left", (int)sign::Left)); + justification->AddOption(std::pair("\x9E Centre", (int)sign::Centre)); + justification->AddOption(std::pair("\x9F Right", (int)sign::Right)); justification->SetOption(0); + justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; - textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 16), ""); - textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom; + textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 17), ""); + textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + textField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(textField); + if(signID!=-1) + { + messageLabel->SetText("Edit sign"); + + textField->SetText(sim->signs[signID].text); + justification->SetOption(sim->signs[signID].ju); + + ui::Point position = ui::Point(justification->Position.X+justification->Size.X+3, 48); + ui::Button * deleteButton = new ui::Button(position, ui::Point(Size.X-position.X-8, 16), "Delete"); + deleteButton->SetIcon(IconDelete); + deleteButton->SetActionCallback(new DeleteAction(this)); + AddComponent(deleteButton); + } + ui::Engine::Ref().ShowWindow(this); } void SignWindow::OnDraw() @@ -82,5 +120,14 @@ void SignWindow::OnDraw() void SignTool::Click(Simulation * sim, Brush * brush, ui::Point position) { - new SignWindow(this, sim, -1, position); -} \ No newline at end of file + int signX, signY, signW, signH, signIndex = -1; + for(int i = 0; i < sim->signs.size(); i++){ + sim->signs[i].pos(signX, signY, signW, signH); + if(position.X > signX && position.X < signX+signW && position.Y > signY && position.Y < signY+signH) + { + signIndex = i; + break; + } + } + new SignWindow(this, sim, signIndex, position); +} diff --git a/src/interface/Slider.cpp b/src/interface/Slider.cpp index 3b188b4e5..b4ae0630e 100644 --- a/src/interface/Slider.cpp +++ b/src/interface/Slider.cpp @@ -109,7 +109,7 @@ void Slider::Draw(const Point& screenPos) for (int i = 3; i < Size.X-6; i++) g->blendpixel(screenPos.X+i+2, screenPos.Y+j+2, bgGradient[(i-3)*3], bgGradient[(i-3)*3+1], bgGradient[(i-3)*3+2], 255); #else - g->gradientrect(screenPos.X+3, screenPos.Y+3, Size.X-6, Size.Y-6, col1.Red, col1.Green, col1.Blue, col1.Alpha, col2.Red, col2.Green, col2.Blue, col2.Alpha); + g->gradientrect(screenPos.X+5, screenPos.Y+5, Size.X-10, Size.Y-10, col1.Red, col1.Green, col1.Blue, col1.Alpha, col2.Red, col2.Green, col2.Blue, col2.Alpha); #endif } diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp new file mode 100644 index 000000000..1ce471f84 --- /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 1b8a68c26..14b7dac34 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 + 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 8e25daad0..b9cc6bbd9 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);