mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-07-31 21:50:18 +02:00
Username, password icons for Login window
This commit is contained in:
@@ -639,8 +639,13 @@ void Graphics::draw_icon(int x, int y, Icon icon)
|
|||||||
case IconReport:
|
case IconReport:
|
||||||
drawchar(x, y, 0xE3, 255, 255, 0, 255);
|
drawchar(x, y, 0xE3, 255, 255, 0, 255);
|
||||||
break;
|
break;
|
||||||
case IconFavourite:
|
case IconUsername:
|
||||||
drawchar(x, y, 0xCC, 192, 160, 64, 255);
|
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;
|
break;
|
||||||
case IconVoteSort:
|
case IconVoteSort:
|
||||||
case IconDateSort:
|
case IconDateSort:
|
||||||
|
@@ -87,7 +87,9 @@ enum Icon
|
|||||||
IconFolder,
|
IconFolder,
|
||||||
IconSearch,
|
IconSearch,
|
||||||
IconDelete,
|
IconDelete,
|
||||||
IconReport
|
IconReport,
|
||||||
|
IconUsername,
|
||||||
|
IconPassword
|
||||||
};
|
};
|
||||||
|
|
||||||
//"Graphics lite" - slightly lower performance due to variable size,
|
//"Graphics lite" - slightly lower performance due to variable size,
|
||||||
|
@@ -11,7 +11,6 @@ using namespace ui;
|
|||||||
Textbox::Textbox(Point position, Point size, std::string textboxText):
|
Textbox::Textbox(Point position, Point size, std::string textboxText):
|
||||||
Component(position, size),
|
Component(position, size),
|
||||||
text(textboxText),
|
text(textboxText),
|
||||||
textPosition(ui::Point(0, 0)),
|
|
||||||
actionCallback(NULL),
|
actionCallback(NULL),
|
||||||
masked(false),
|
masked(false),
|
||||||
border(true)
|
border(true)
|
||||||
@@ -26,19 +25,32 @@ Textbox::~Textbox()
|
|||||||
delete actionCallback;
|
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)
|
void Textbox::SetText(std::string text)
|
||||||
{
|
{
|
||||||
cursor = text.length();
|
cursor = text.length();
|
||||||
this->text = text;
|
this->text = text;
|
||||||
this->displayText = text;
|
this->displayText = text;
|
||||||
TextPosition(displayText);
|
TextPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Textbox::SetDisplayText(std::string text)
|
void Textbox::SetDisplayText(std::string text)
|
||||||
{
|
{
|
||||||
displayText = text;
|
displayText = text;
|
||||||
TextPosition(displayText);
|
TextPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Textbox::GetText()
|
std::string Textbox::GetText()
|
||||||
@@ -129,14 +141,14 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
if(actionCallback)
|
if(actionCallback)
|
||||||
actionCallback->TextChangedCallback(this);
|
actionCallback->TextChangedCallback(this);
|
||||||
}
|
}
|
||||||
TextPosition(displayText);
|
TextPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textbox::Draw(const Point& screenPos)
|
void Textbox::Draw(const Point& screenPos)
|
||||||
{
|
{
|
||||||
if(!drawn)
|
if(!drawn)
|
||||||
{
|
{
|
||||||
TextPosition(displayText);
|
TextPosition();
|
||||||
drawn = true;
|
drawn = true;
|
||||||
}
|
}
|
||||||
Graphics * g = Engine::Ref().g;
|
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);
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,6 @@ class Textbox : public Component
|
|||||||
protected:
|
protected:
|
||||||
std::string text;
|
std::string text;
|
||||||
std::string displayText;
|
std::string displayText;
|
||||||
ui::Point textPosition;
|
|
||||||
int cursor, cursorPosition;
|
int cursor, cursorPosition;
|
||||||
TextboxAction *actionCallback;
|
TextboxAction *actionCallback;
|
||||||
bool masked;
|
bool masked;
|
||||||
@@ -40,6 +39,8 @@ public:
|
|||||||
bool GetHidden() { return masked; }
|
bool GetHidden() { return masked; }
|
||||||
|
|
||||||
void SetBorder(bool border) {this->border = border;}
|
void SetBorder(bool border) {this->border = border;}
|
||||||
|
|
||||||
|
void TextPosition();
|
||||||
|
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
};
|
};
|
||||||
|
@@ -41,6 +41,11 @@ LoginView::LoginView():
|
|||||||
targetSize(0, 0)
|
targetSize(0, 0)
|
||||||
{
|
{
|
||||||
targetSize = Size;
|
targetSize = Size;
|
||||||
|
|
||||||
|
infoLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; infoLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
|
infoLabel->Visible = false;
|
||||||
|
AddComponent(infoLabel);
|
||||||
|
|
||||||
AddComponent(loginButton);
|
AddComponent(loginButton);
|
||||||
loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
|
loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
|
||||||
loginButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
loginButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
@@ -54,13 +59,12 @@ LoginView::LoginView():
|
|||||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||||
|
|
||||||
AddComponent(usernameField);
|
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);
|
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);
|
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)
|
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;
|
ui::Point difference = targetSize-Size;
|
||||||
if(difference.X!=0)
|
if(difference.X!=0)
|
||||||
{
|
{
|
||||||
int xdiff = difference.X/100;
|
int xdiff = difference.X/5;
|
||||||
if(xdiff == 0)
|
if(xdiff == 0)
|
||||||
xdiff = 1*isign(difference.X);
|
xdiff = 1*isign(difference.X);
|
||||||
Size.X += xdiff;
|
Size.X += xdiff;
|
||||||
}
|
}
|
||||||
if(difference.Y!=0)
|
if(difference.Y!=0)
|
||||||
{
|
{
|
||||||
int ydiff = difference.Y/100;
|
int ydiff = difference.Y/5;
|
||||||
if(ydiff == 0)
|
if(ydiff == 0)
|
||||||
ydiff = 1*isign(difference.Y);
|
ydiff = 1*isign(difference.Y);
|
||||||
Size.Y += ydiff;
|
Size.Y += ydiff;
|
||||||
|
Reference in New Issue
Block a user