From ba5efb101e30c75e9d1a639a717f48767785982d Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 15 May 2012 18:55:36 +0100 Subject: [PATCH] Username, password icons for Login window --- src/Graphics.cpp | 9 +++++++-- src/Graphics.h | 4 +++- src/interface/Textbox.cpp | 24 +++++++++++++++++++----- src/interface/Textbox.h | 3 ++- src/login/LoginView.cpp | 18 +++++++++++------- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/Graphics.cpp b/src/Graphics.cpp index c7d8ba233..4f1d68ee0 100644 --- a/src/Graphics.cpp +++ b/src/Graphics.cpp @@ -639,8 +639,13 @@ void Graphics::draw_icon(int x, int y, Icon icon) case IconReport: drawchar(x, y, 0xE3, 255, 255, 0, 255); break; - case IconFavourite: - drawchar(x, y, 0xCC, 192, 160, 64, 255); + case IconUsername: + drawchar(x, y, 0x8B, 32, 64, 128, 255); + drawchar(x, y, 0x8A, 255, 255, 255, 255); + break; + case IconPassword: + drawchar(x, y, 0x8C, 160, 144, 32, 255); + drawchar(x, y, 0x84, 255, 255, 255, 255); break; case IconVoteSort: case IconDateSort: diff --git a/src/Graphics.h b/src/Graphics.h index 9b917015d..5e43417e0 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -87,7 +87,9 @@ enum Icon IconFolder, IconSearch, IconDelete, - IconReport + IconReport, + IconUsername, + IconPassword }; //"Graphics lite" - slightly lower performance due to variable size, diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 8657e8e1b..9db4dc650 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -11,7 +11,6 @@ using namespace ui; Textbox::Textbox(Point position, Point size, std::string textboxText): Component(position, size), text(textboxText), - textPosition(ui::Point(0, 0)), actionCallback(NULL), masked(false), border(true) @@ -26,19 +25,32 @@ Textbox::~Textbox() delete actionCallback; } +void Textbox::TextPosition() +{ + if(cursor) + { + cursorPosition = Graphics::textnwidth((char *)displayText.c_str(), cursor); + } + else + { + cursorPosition = 0; + } + Component::TextPosition(displayText); +} + void Textbox::SetText(std::string text) { cursor = text.length(); this->text = text; this->displayText = text; - TextPosition(displayText); + TextPosition(); } void Textbox::SetDisplayText(std::string text) { displayText = text; - TextPosition(displayText); + TextPosition(); } std::string Textbox::GetText() @@ -129,14 +141,14 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool if(actionCallback) actionCallback->TextChangedCallback(this); } - TextPosition(displayText); + TextPosition(); } void Textbox::Draw(const Point& screenPos) { if(!drawn) { - TextPosition(displayText); + TextPosition(); drawn = true; } Graphics * g = Engine::Ref().g; @@ -150,4 +162,6 @@ void Textbox::Draw(const Point& screenPos) if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255); } g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, displayText, 255, 255, 255, 255); + if(Appearance.icon) + g->draw_icon(screenPos.X+iconPosition.X, screenPos.Y+iconPosition.Y, Appearance.icon); } diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index e5027687a..551ff5437 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -21,7 +21,6 @@ class Textbox : public Component protected: std::string text; std::string displayText; - ui::Point textPosition; int cursor, cursorPosition; TextboxAction *actionCallback; bool masked; @@ -40,6 +39,8 @@ public: bool GetHidden() { return masked; } void SetBorder(bool border) {this->border = border;} + + void TextPosition(); virtual void Draw(const Point& screenPos); }; diff --git a/src/login/LoginView.cpp b/src/login/LoginView.cpp index e9f8090d3..561e694a6 100644 --- a/src/login/LoginView.cpp +++ b/src/login/LoginView.cpp @@ -41,6 +41,11 @@ LoginView::LoginView(): targetSize(0, 0) { targetSize = Size; + + infoLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; infoLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + infoLabel->Visible = false; + AddComponent(infoLabel); + AddComponent(loginButton); loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight; loginButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; @@ -54,13 +59,12 @@ LoginView::LoginView(): titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; AddComponent(usernameField); - usernameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; usernameField->Appearance.VerticalAlign = ui::Appearance::AlignBottom; + usernameField->Appearance.icon = IconUsername; + usernameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; usernameField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(passwordField); - passwordField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; passwordField->Appearance.VerticalAlign = ui::Appearance::AlignBottom; + passwordField->Appearance.icon = IconPassword; + passwordField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; passwordField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; passwordField->SetHidden(true); - infoLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; infoLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom; - infoLabel->Visible = false; - AddComponent(infoLabel); } void LoginView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) @@ -102,14 +106,14 @@ void LoginView::OnTick(float dt) ui::Point difference = targetSize-Size; if(difference.X!=0) { - int xdiff = difference.X/100; + int xdiff = difference.X/5; if(xdiff == 0) xdiff = 1*isign(difference.X); Size.X += xdiff; } if(difference.Y!=0) { - int ydiff = difference.Y/100; + int ydiff = difference.Y/5; if(ydiff == 0) ydiff = 1*isign(difference.Y); Size.Y += ydiff;