Sign tool can now edit existing signs
This commit is contained in:
parent
04b007b36f
commit
ab8f382acc
@ -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<sign> 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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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));
|
||||
AddComponent(justification);
|
||||
justification->AddOption(std::pair<std::string, int>("Left", (int)sign::Left));
|
||||
justification->AddOption(std::pair<std::string, int>("Centre", (int)sign::Centre));
|
||||
justification->AddOption(std::pair<std::string, int>("Right", (int)sign::Right));
|
||||
justification->SetOption(0);
|
||||
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);
|
||||
|
||||
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;
|
||||
justification = new ui::DropDown(ui::Point(52, 48), ui::Point(50, 16));
|
||||
AddComponent(justification);
|
||||
justification->AddOption(std::pair<std::string, int>("\x9D Left", (int)sign::Left));
|
||||
justification->AddOption(std::pair<std::string, int>("\x9E Centre", (int)sign::Centre));
|
||||
justification->AddOption(std::pair<std::string, int>("\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, 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);
|
||||
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);
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
|
55
src/simulation/Sign.cpp
Normal file
55
src/simulation/Sign.cpp
Normal file
@ -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;
|
||||
}
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user