summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-13 20:11:02 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-13 20:11:02 (GMT)
commit4bb90d0d79d983c2f6d16af4575661b845a3d72f (patch)
treefd5b17495cb5169defa6095adcc816f18486afcd /src
parent41e1d28c56b6e4b9b380022e9220161c57612006 (diff)
downloadpowder-4bb90d0d79d983c2f6d16af4575661b845a3d72f.zip
powder-4bb90d0d79d983c2f6d16af4575661b845a3d72f.tar.gz
Text alignment for dropdown, make sign UI nice
Diffstat (limited to 'src')
-rw-r--r--src/game/SignTool.cpp6
-rw-r--r--src/interface/DropDown.cpp47
-rw-r--r--src/interface/DropDown.h4
3 files changed, 50 insertions, 7 deletions
diff --git a/src/game/SignTool.cpp b/src/game/SignTool.cpp
index 7f28b5e..b382019 100644
--- a/src/game/SignTool.cpp
+++ b/src/game/SignTool.cpp
@@ -48,7 +48,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
sim(sim_),
signPosition(position_)
{
- ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), "New sign");
+ ui::Label * messageLabel = new ui::Label(ui::Point(4, 2), ui::Point(Size.X-8, 14), "New sign");
messageLabel->SetAlignment(AlignLeft, AlignTop);
AddComponent(messageLabel);
@@ -58,14 +58,14 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
okayButton->SetActionCallback(new OkayAction(this));
AddComponent(okayButton);
- justification = new ui::DropDown(ui::Point(4, 18), ui::Point(50, 16));
+ justification = new ui::DropDown(ui::Point(8, 38), 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);
- textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
+ textField = new ui::Textbox(ui::Point(8, 17), ui::Point(Size.X-16, 16), "");
textField->SetAlignment(AlignLeft, AlignBottom);
AddComponent(textField);
diff --git a/src/interface/DropDown.cpp b/src/interface/DropDown.cpp
index d5af4c4..8b9c976 100644
--- a/src/interface/DropDown.cpp
+++ b/src/interface/DropDown.cpp
@@ -80,6 +80,9 @@ DropDown::DropDown(Point position, Point size):
Component(position, size),
isMouseInside(false),
optionIndex(-1),
+ textPosition(ui::Point(0, 0)),
+ textVAlign(AlignMiddle),
+ textHAlign(AlignLeft),
callback(NULL)
{
background = activeBackground = Colour(0, 0, 0);
@@ -101,20 +104,52 @@ void DropDown::Draw(const Point& screenPos)
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, activeBackground.Red, activeBackground.Green, activeBackground.Blue, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, activeBorder.Red, activeBorder.Green, activeBorder.Blue, 255);
if(optionIndex!=-1)
- g->drawtext(Position.X, Position.Y+1, options[optionIndex].first, activeText.Red, activeText.Green, activeText.Blue, 255);
- //g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, displayText, activeText.Red, activeText.Green, activeText.Blue, 255);
+ g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, activeText.Red, activeText.Green, activeText.Blue, 255);
}
else
{
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255);
if(optionIndex!=-1)
- g->drawtext(Position.X, Position.Y+1, options[optionIndex].first, text.Red, text.Green, text.Blue, 255);
- //g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, displayText, text.Red, text.Green, text.Blue, 255);
+ g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, text.Red, text.Green, text.Blue, 255);
}
}
+ void DropDown::TextPosition()
+ {
+ std::string displayText;
+ if(optionIndex!=-1)
+ displayText = options[optionIndex].first;
+
+ // Values 3 and 10 are for vertical padding of 3 pixels, middle uses 7 as that's the height of a capital
+ switch(textVAlign)
+ {
+ case AlignTop:
+ textPosition.Y = 3;
+ break;
+ case AlignMiddle:
+ textPosition.Y = (Size.Y-10)/2;
+ break;
+ case AlignBottom:
+ textPosition.Y = Size.Y-10;
+ break;
+ }
+
+ switch(textHAlign)
+ {
+ case AlignLeft:
+ textPosition.X = 3;
+ break;
+ case AlignCentre:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))/2;
+ break;
+ case AlignRight:
+ textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))-2;
+ break;
+ }
+ }
+
std::pair<std::string, int> DropDown::GetOption()
{
if(optionIndex!=-1)
@@ -131,6 +166,7 @@ void DropDown::Draw(const Point& screenPos)
if(options[i].first == option)
{
optionIndex = i;
+ TextPosition();
return;
}
}
@@ -142,6 +178,7 @@ void DropDown::Draw(const Point& screenPos)
if(options[i].second == option)
{
optionIndex = i;
+ TextPosition();
return;
}
}
@@ -162,6 +199,8 @@ void DropDown::Draw(const Point& screenPos)
{
if(options[i].first == option)
{
+ if(i == optionIndex)
+ optionIndex = -1;
options.erase(options.begin()+i);
goto start;
}
diff --git a/src/interface/DropDown.h b/src/interface/DropDown.h
index 40fac68..dabd4ec 100644
--- a/src/interface/DropDown.h
+++ b/src/interface/DropDown.h
@@ -27,13 +27,17 @@ class DropDown: public ui::Component {
Colour background, activeBackground;
Colour border, activeBorder;
Colour text, activeText;
+ Point textPosition;
bool isMouseInside;
int optionIndex;
DropDownAction * callback;
std::vector<std::pair<std::string, int> > options;
+ HorizontalAlignment textHAlign;
+ VerticalAlignment textVAlign;
public:
DropDown(Point position, Point size);
std::pair<std::string, int> GetOption();
+ void TextPosition();
void SetOption(int option);
void SetOption(std::string option);
void AddOption(std::pair<std::string, int> option);