Move style into Component
This commit is contained in:
parent
45563e97e8
commit
136675b56a
@ -570,11 +570,11 @@ void Graphics::textsize(const char * s, int & width, int & height)
|
||||
if(!strlen(s))
|
||||
{
|
||||
width = 0;
|
||||
height = 0;
|
||||
height = FONT_H;
|
||||
return;
|
||||
}
|
||||
|
||||
int cHeight = FONT_H+2, cWidth = 0, lWidth = 0;
|
||||
int cHeight = FONT_H, cWidth = 0, lWidth = 0;
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (*s == '\n')
|
||||
|
10
src/Misc.h
10
src/Misc.h
@ -4,16 +4,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
enum HorizontalAlignment
|
||||
{
|
||||
AlignLeft, AlignCentre, AlignRight
|
||||
};
|
||||
|
||||
enum VerticalAlignment
|
||||
{
|
||||
AlignTop, AlignMiddle, AlignBottom
|
||||
};
|
||||
|
||||
#if defined(WIN32) && !defined(__GNUC__)
|
||||
#define x86_cpuid(func,af,bf,cf,df) \
|
||||
do {\
|
||||
|
@ -14,6 +14,8 @@ namespace style {
|
||||
ui::Colour Colour::WarningTitle = ui::Colour(255, 255, 50);
|
||||
ui::Colour Colour::ErrorTitle = ui::Colour(255, 20, 20);
|
||||
|
||||
ui::Colour Colour::ConfirmButton = ui::Colour(255, 255, 50);
|
||||
|
||||
ui::Colour Colour::ActiveBorder = ui::Colour(255, 255, 255);
|
||||
ui::Colour Colour::InactiveBorder = ui::Colour(180, 180, 180);
|
||||
|
||||
|
@ -18,6 +18,8 @@ namespace style
|
||||
static ui::Colour WarningTitle;
|
||||
static ui::Colour ErrorTitle;
|
||||
|
||||
static ui::Colour ConfirmButton;
|
||||
|
||||
static ui::Colour ActiveBorder;
|
||||
static ui::Colour InactiveBorder;
|
||||
|
||||
|
@ -370,7 +370,7 @@ unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
|
||||
{
|
||||
urlStream << "http://" << STATICSERVER << "/" << saveID << ".cps";
|
||||
}
|
||||
std::cout << urlStream.str() << std::endl;
|
||||
|
||||
data = (unsigned char *)http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
|
||||
if(data && dataStatus == 200)
|
||||
{
|
||||
|
@ -23,7 +23,8 @@ ConsoleView::ConsoleView():
|
||||
}
|
||||
};
|
||||
commandField = new ui::Textbox(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "");
|
||||
commandField->SetAlignment(AlignLeft, AlignBottom);
|
||||
commandField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
commandField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
commandField->SetActionCallback(new CommandHighlighter(this));
|
||||
AddComponent(commandField);
|
||||
FocusComponent(commandField);
|
||||
@ -67,11 +68,13 @@ void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender)
|
||||
if(currentY <= 0)
|
||||
break;
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(Size.X/2, currentY), ui::Point(Size.X/2, 16), commands[i].ReturnValue);
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
commandList.push_back(tempLabel);
|
||||
AddComponent(tempLabel);
|
||||
tempLabel = new ui::Label(ui::Point(0, currentY), ui::Point(Size.X/2, 16), commands[i].Command);
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
commandList.push_back(tempLabel);
|
||||
AddComponent(tempLabel);
|
||||
currentY-=16;
|
||||
|
@ -15,11 +15,13 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
|
||||
{
|
||||
ui::Label * titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), title);
|
||||
titleLabel->SetTextColour(ui::Colour(220, 220, 50));
|
||||
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(titleLabel);
|
||||
|
||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), message);
|
||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
AddComponent(messageLabel);
|
||||
|
||||
class CloseAction: public ui::ButtonAction
|
||||
@ -38,14 +40,16 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
|
||||
|
||||
|
||||
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-50, 16), "Cancel");
|
||||
cancelButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
cancelButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
||||
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
|
||||
AddComponent(cancelButton);
|
||||
|
||||
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-50, Size.Y-16), ui::Point(50, 16), "Continue");
|
||||
okayButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
okayButton->SetTextColour(ui::Colour(220, 220, 50));
|
||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
okayButton->Appearance.TextInactive = ui::Colour(220, 220, 50);
|
||||
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
|
||||
AddComponent(okayButton);
|
||||
|
||||
|
@ -14,11 +14,13 @@ ErrorMessage::ErrorMessage(std::string title, std::string message):
|
||||
{
|
||||
ui::Label * titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), title);
|
||||
titleLabel->SetTextColour(ui::Colour(200, 100, 50));
|
||||
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(titleLabel);
|
||||
|
||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), message);
|
||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
AddComponent(messageLabel);
|
||||
|
||||
class DismissAction: public ui::ButtonAction
|
||||
@ -34,8 +36,9 @@ ErrorMessage::ErrorMessage(std::string title, std::string message):
|
||||
};
|
||||
|
||||
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "Dismiss");
|
||||
okayButton->SetAlignment(AlignRight, AlignBottom);
|
||||
okayButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
|
||||
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
||||
okayButton->SetActionCallback(new DismissAction(this));
|
||||
AddComponent(okayButton);
|
||||
ui::Engine::Ref().ShowWindow(this);
|
||||
|
@ -30,27 +30,27 @@ TextPrompt::TextPrompt(std::string title, std::string message, bool multiline, T
|
||||
{
|
||||
ui::Label * titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), title);
|
||||
titleLabel->SetTextColour(ui::Colour(220, 220, 50));
|
||||
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(titleLabel);
|
||||
|
||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), message);
|
||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
AddComponent(messageLabel);
|
||||
|
||||
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-50, 16), "Cancel");
|
||||
cancelButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
cancelButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
||||
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
|
||||
AddComponent(cancelButton);
|
||||
|
||||
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-50, Size.Y-16), ui::Point(50, 16), "Okay");
|
||||
okayButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
okayButton->SetTextColour(ui::Colour(220, 220, 50));
|
||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
okayButton->Appearance.TextInactive = ui::Colour(220, 220, 50);
|
||||
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
|
||||
AddComponent(okayButton);
|
||||
|
||||
textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
|
||||
textField->SetAlignment(AlignLeft, AlignBottom);
|
||||
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(textField);
|
||||
|
||||
ui::Engine::Ref().ShowWindow(this);
|
||||
|
@ -125,7 +125,6 @@ GameModel::GameModel():
|
||||
toolList = menuList[SC_POWDERS]->GetToolList();
|
||||
|
||||
//Load last user
|
||||
std::cout << Client::Ref().GetAuthUser().Username << std::endl;
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
{
|
||||
currentUser = Client::Ref().GetAuthUser();
|
||||
|
@ -79,6 +79,7 @@ GameView::GameView():
|
||||
}
|
||||
};
|
||||
saveSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(150, 15));
|
||||
saveSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
saveSimulationButton->SetIcon(IconSave);
|
||||
currentX+=151;
|
||||
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
|
||||
@ -127,6 +128,7 @@ GameView::GameView():
|
||||
}
|
||||
};
|
||||
tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(250, 15));
|
||||
tagSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
tagSimulationButton->SetIcon(IconTag);
|
||||
currentX+=251;
|
||||
tagSimulationButton->SetActionCallback(new TagSimulationAction(this));
|
||||
@ -158,6 +160,7 @@ GameView::GameView():
|
||||
}
|
||||
};
|
||||
loginButton = new ui::Button(ui::Point(Size.X-141, Size.Y-16), ui::Point(92, 15), "Login");
|
||||
loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
loginButton->SetIcon(IconLogin);
|
||||
loginButton->SetActionCallback(new LoginAction(this));
|
||||
AddComponent(loginButton);
|
||||
@ -276,6 +279,7 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||
std::string tempString = "";
|
||||
tempString += menuList[i]->GetIcon();
|
||||
ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), tempString);
|
||||
tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2);
|
||||
tempButton->SetTogglable(true);
|
||||
tempButton->SetActionCallback(new MenuAction(this, menuList[i]));
|
||||
currentY+=16;
|
||||
@ -349,7 +353,7 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
||||
currentX -= 31;
|
||||
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
|
||||
|
||||
tempButton->SetBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
|
||||
tempButton->Appearance.BackgroundInactive = ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue);
|
||||
|
||||
if(sender->GetActiveTool(0) == toolList[i])
|
||||
{
|
||||
@ -364,7 +368,8 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
||||
tempButton->SetSelectionState(2); //Tertiary
|
||||
}
|
||||
|
||||
tempButton->SetAlignment(AlignCentre, AlignMiddle);
|
||||
tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
|
||||
tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempButton);
|
||||
toolButtons.push_back(tempButton);
|
||||
}
|
||||
@ -439,14 +444,14 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
reloadButton->Enabled = true;
|
||||
upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0);
|
||||
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1)
|
||||
upVoteButton->SetBackgroundColour(ui::Colour(0, 200, 40));
|
||||
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 200, 40));
|
||||
else
|
||||
upVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
||||
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
||||
downVoteButton->Enabled = upVoteButton->Enabled;
|
||||
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==-1)
|
||||
downVoteButton->SetBackgroundColour(ui::Colour(200, 40, 40));
|
||||
downVoteButton->Appearance.BackgroundInactive = (ui::Colour(200, 40, 40));
|
||||
else
|
||||
downVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
||||
downVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
||||
tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID);
|
||||
if(sender->GetSave()->GetID())
|
||||
{
|
||||
@ -466,9 +471,9 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
saveSimulationButton->SetText("");
|
||||
reloadButton->Enabled = false;
|
||||
upVoteButton->Enabled = false;
|
||||
upVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
||||
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
||||
downVoteButton->Enabled = false;
|
||||
upVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
||||
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
|
||||
tagSimulationButton->Enabled = false;
|
||||
tagSimulationButton->SetText("");
|
||||
}
|
||||
|
@ -49,12 +49,12 @@ position(position_)
|
||||
|
||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit property");
|
||||
messageLabel->SetTextColour(style::Colour::InformationTitle);
|
||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
AddComponent(messageLabel);
|
||||
|
||||
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 17), "OK");
|
||||
okayButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
okayButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
||||
okayButton->SetActionCallback(new OkayAction(this));
|
||||
AddComponent(okayButton);
|
||||
|
||||
@ -67,7 +67,7 @@ position(position_)
|
||||
property->SetOption(0);
|
||||
|
||||
textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), "");
|
||||
textField->SetAlignment(AlignLeft, AlignBottom);
|
||||
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(textField);
|
||||
|
||||
ui::Engine::Ref().ShowWindow(this);
|
||||
|
@ -50,12 +50,12 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
||||
{
|
||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "New sign");
|
||||
messageLabel->SetTextColour(style::Colour::InformationTitle);
|
||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
AddComponent(messageLabel);
|
||||
|
||||
ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "OK");
|
||||
okayButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
okayButton->SetBorderColour(ui::Colour(200, 200, 200));
|
||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
okayButton->Appearance.BorderInactive = (ui::Colour(200, 200, 200));
|
||||
okayButton->SetActionCallback(new OkayAction(this));
|
||||
AddComponent(okayButton);
|
||||
|
||||
@ -67,7 +67,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
||||
justification->SetOption(0);
|
||||
|
||||
textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 16), "");
|
||||
textField->SetAlignment(AlignLeft, AlignBottom);
|
||||
textField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; textField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(textField);
|
||||
|
||||
ui::Engine::Ref().ShowWindow(this);
|
||||
|
@ -12,7 +12,7 @@ ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_):
|
||||
ui::Button(position, size, text_)
|
||||
{
|
||||
SetSelectionState(-1);
|
||||
activeBorder = ui::Colour(255, 0, 0);
|
||||
Appearance.BorderActive = ui::Colour(255, 0, 0);
|
||||
}
|
||||
|
||||
void ToolButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
@ -38,17 +38,17 @@ void ToolButton::OnMouseUp(int x, int y, unsigned int button)
|
||||
void ToolButton::Draw(const ui::Point& screenPos)
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
int totalColour = background.Red + (3*background.Green) + (2*background.Blue);
|
||||
int totalColour = Appearance.BackgroundInactive.Red + (3*Appearance.BackgroundInactive.Green) + (2*Appearance.BackgroundInactive.Blue);
|
||||
|
||||
g->fillrect(screenPos.X+2, screenPos.Y+2, Size.X-4, Size.Y-4, background.Red, background.Green, background.Blue, background.Alpha);
|
||||
g->fillrect(screenPos.X+2, screenPos.Y+2, Size.X-4, Size.Y-4, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, Appearance.BackgroundInactive.Alpha);
|
||||
|
||||
if(isMouseInside && currentSelection == -1)
|
||||
{
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, activeBorder.Red, activeBorder.Green, activeBorder.Blue, activeBorder.Alpha);
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, Appearance.BorderActive.Alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, border.Alpha);
|
||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, Appearance.BorderInactive.Alpha);
|
||||
}
|
||||
|
||||
if (totalColour<544)
|
||||
@ -67,16 +67,16 @@ void ToolButton::SetSelectionState(int state)
|
||||
switch(state)
|
||||
{
|
||||
case 0:
|
||||
border = ui::Colour(255, 0, 0);
|
||||
Appearance.BorderInactive = ui::Colour(255, 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
border = ui::Colour(0, 0, 255);
|
||||
Appearance.BorderInactive = ui::Colour(0, 0, 255);
|
||||
break;
|
||||
case 2:
|
||||
border = ui::Colour(0, 255, 0);
|
||||
Appearance.BorderInactive = ui::Colour(0, 255, 0);
|
||||
break;
|
||||
default:
|
||||
border = ui::Colour(0, 0, 0);
|
||||
Appearance.BorderInactive = ui::Colour(0, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
32
src/interface/Appearance.cpp
Normal file
32
src/interface/Appearance.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// Appearance.cpp
|
||||
// The Powder Toy
|
||||
//
|
||||
// Created by Simon Robertshaw on 15/05/2012.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "Appearance.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
Appearance::Appearance():
|
||||
HorizontalAlign(AlignCentre),
|
||||
VerticalAlign(AlignMiddle),
|
||||
|
||||
BackgroundHover(30, 30, 30),
|
||||
BackgroundInactive(0, 0, 0),
|
||||
BackgroundActive(255, 255, 255),
|
||||
|
||||
TextHover(255, 255, 255),
|
||||
TextInactive(255, 255, 255),
|
||||
TextActive(0, 0, 0),
|
||||
|
||||
BorderHover(255, 255, 255),
|
||||
BorderInactive(200, 200, 200),
|
||||
BorderActive(255, 255, 255),
|
||||
Margin(1, 4),
|
||||
|
||||
icon(NoIcon)
|
||||
{};
|
||||
}
|
53
src/interface/Appearance.h
Normal file
53
src/interface/Appearance.h
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// Appearance.h
|
||||
// The Powder Toy
|
||||
//
|
||||
// Created by Simon Robertshaw on 15/05/2012.
|
||||
//
|
||||
|
||||
#ifndef The_Powder_Toy_Appearance_h
|
||||
#define The_Powder_Toy_Appearance_h
|
||||
|
||||
#include "Border.h"
|
||||
#include "Colour.h"
|
||||
#include "Graphics.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
class Appearance
|
||||
{
|
||||
public:
|
||||
enum HorizontalAlignment
|
||||
{
|
||||
AlignLeft, AlignCentre, AlignRight
|
||||
};
|
||||
|
||||
enum VerticalAlignment
|
||||
{
|
||||
AlignTop, AlignMiddle, AlignBottom
|
||||
};
|
||||
|
||||
VerticalAlignment VerticalAlign;
|
||||
HorizontalAlignment HorizontalAlign;
|
||||
|
||||
ui::Colour BackgroundHover;
|
||||
ui::Colour BackgroundInactive;
|
||||
ui::Colour BackgroundActive;
|
||||
|
||||
ui::Colour TextHover;
|
||||
ui::Colour TextInactive;
|
||||
ui::Colour TextActive;
|
||||
|
||||
ui::Colour BorderHover;
|
||||
ui::Colour BorderInactive;
|
||||
ui::Colour BorderActive;
|
||||
|
||||
ui::Border Margin;
|
||||
|
||||
Icon icon;
|
||||
|
||||
Appearance();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
64
src/interface/Border.h
Normal file
64
src/interface/Border.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include "Platform.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
|
||||
struct Border
|
||||
{
|
||||
#if ENABLE_FLOAT_UI
|
||||
# define BORDER_T float
|
||||
#else
|
||||
# define BORDER_T int
|
||||
#endif
|
||||
|
||||
BORDER_T Top;
|
||||
BORDER_T Right;
|
||||
BORDER_T Bottom;
|
||||
BORDER_T Left;
|
||||
|
||||
Border(BORDER_T all):
|
||||
Top(all),
|
||||
Right(all),
|
||||
Bottom(all),
|
||||
Left(all)
|
||||
{
|
||||
}
|
||||
|
||||
Border(BORDER_T v, BORDER_T h):
|
||||
Top(v),
|
||||
Right(h),
|
||||
Bottom(v),
|
||||
Left(h)
|
||||
{
|
||||
}
|
||||
|
||||
Border(BORDER_T top, BORDER_T right, BORDER_T bottom, BORDER_T left):
|
||||
Top(top),
|
||||
Right(right),
|
||||
Bottom(bottom),
|
||||
Left(left)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool operator == (const Border& v) const
|
||||
{
|
||||
return (Top == v.Top || Right == v.Right || Bottom == v.Bottom || Left == v.Left);
|
||||
}
|
||||
|
||||
inline bool operator != (const Border& v) const
|
||||
{
|
||||
return (Top != v.Top || Right != v.Right || Bottom != v.Bottom || Left != v.Left);
|
||||
}
|
||||
|
||||
inline void operator = (const Border& v)
|
||||
{
|
||||
Top = v.Top;
|
||||
Right = v.Right;
|
||||
Bottom = v.Bottom;
|
||||
Left = v.Left;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -21,15 +21,8 @@ Button::Button(Point position, Point size, std::string buttonText):
|
||||
isTogglable(false),
|
||||
toggle(false),
|
||||
actionCallback(NULL),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignLeft),
|
||||
Enabled(true),
|
||||
icon(NoIcon)
|
||||
Enabled(true)
|
||||
{
|
||||
activeText = background = Colour(0, 0, 0);
|
||||
text = activeBackground = border = activeBorder = Colour(255, 255, 255);
|
||||
|
||||
TextPosition();
|
||||
}
|
||||
|
||||
@ -38,63 +31,20 @@ void Button::TextPosition()
|
||||
buttonDisplayText = ButtonText;
|
||||
if(buttonDisplayText.length())
|
||||
{
|
||||
if(Graphics::textwidth((char *)buttonDisplayText.c_str()) > Size.X - (icon? 22 : 0))
|
||||
if(Graphics::textwidth((char *)buttonDisplayText.c_str()) > Size.X - (Appearance.icon? 22 : 0))
|
||||
{
|
||||
int position = Graphics::textwidthx((char *)buttonDisplayText.c_str(), Size.X - (icon? 38 : 22));
|
||||
int position = Graphics::textwidthx((char *)buttonDisplayText.c_str(), Size.X - (Appearance.icon? 38 : 22));
|
||||
buttonDisplayText = buttonDisplayText.erase(position, buttonDisplayText.length()-position);
|
||||
buttonDisplayText += "...";
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
if(icon)
|
||||
{
|
||||
switch(textHAlign)
|
||||
{
|
||||
case AlignLeft:
|
||||
textPosition.X = 3+17;
|
||||
break;
|
||||
case AlignCentre:
|
||||
textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)buttonDisplayText.c_str()))/2)+17;
|
||||
break;
|
||||
case AlignRight:
|
||||
textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)buttonDisplayText.c_str()))-2)+17;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(textHAlign)
|
||||
{
|
||||
case AlignLeft:
|
||||
textPosition.X = 3;
|
||||
break;
|
||||
case AlignCentre:
|
||||
textPosition.X = (Size.X-Graphics::textwidth((char *)buttonDisplayText.c_str()))/2;
|
||||
break;
|
||||
case AlignRight:
|
||||
textPosition.X = (Size.X-Graphics::textwidth((char *)buttonDisplayText.c_str()))-2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Component::TextPosition(buttonDisplayText);
|
||||
}
|
||||
|
||||
void Button::SetIcon(Icon icon)
|
||||
{
|
||||
this->icon = icon;
|
||||
Appearance.icon = icon;
|
||||
TextPosition();
|
||||
}
|
||||
|
||||
@ -127,31 +77,36 @@ inline void Button::SetToggleState(bool state)
|
||||
|
||||
void Button::Draw(const Point& screenPos)
|
||||
{
|
||||
if(!drawn)
|
||||
{
|
||||
TextPosition();
|
||||
drawn = true;
|
||||
}
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
Point Position = screenPos;
|
||||
if(Enabled)
|
||||
{
|
||||
if(isButtonDown || (isTogglable && toggle))
|
||||
{
|
||||
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);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, activeText.Red, activeText.Green, activeText.Blue, 255);
|
||||
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, Appearance.BackgroundActive.Red, Appearance.BackgroundActive.Green, Appearance.BackgroundActive.Blue, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, Appearance.TextActive.Red, Appearance.TextActive.Green, Appearance.TextActive.Blue, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, background.Red, background.Green, background.Blue, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, text.Red, text.Green, text.Blue, 255);
|
||||
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, Appearance.TextInactive.Red, Appearance.TextInactive.Green, Appearance.TextInactive.Blue, 255);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, background.Red, background.Green, background.Blue, 180);
|
||||
g->fillrect(Position.X+1, Position.Y+1, Size.X-2, Size.Y-2, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, 180);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 180, 180, 180, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, 180, 180, 180, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, buttonDisplayText, 180, 180, 180, 255);
|
||||
}
|
||||
if(icon)
|
||||
g->draw_icon(Position.X+3, Position.Y+textPosition.Y, icon);
|
||||
if(Appearance.icon)
|
||||
g->draw_icon(Position.X+iconPosition.X, Position.Y+iconPosition.Y, Appearance.icon);
|
||||
}
|
||||
|
||||
void Button::OnMouseUp(int x, int y, unsigned int button)
|
||||
|
@ -29,7 +29,6 @@ public:
|
||||
Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = "");
|
||||
virtual ~Button();
|
||||
|
||||
Icon icon;
|
||||
bool Toggleable;
|
||||
bool Enabled;
|
||||
|
||||
@ -42,6 +41,7 @@ public:
|
||||
|
||||
virtual void Draw(const Point& screenPos);
|
||||
|
||||
virtual void TextPosition();
|
||||
inline bool GetState() { return state; }
|
||||
virtual void DoAction(); //action of button what ever it may be
|
||||
void SetTogglable(bool isTogglable);
|
||||
@ -50,34 +50,15 @@ public:
|
||||
inline void SetToggleState(bool state);
|
||||
void SetActionCallback(ButtonAction * action);
|
||||
ButtonAction * GetActionCallback() { return actionCallback; }
|
||||
void TextPosition();
|
||||
void SetText(std::string buttonText);
|
||||
|
||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||
VerticalAlignment GetVAlignment() { return textVAlign; }
|
||||
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
||||
|
||||
void SetBackgroundColour(Colour background) { this->background = background; }
|
||||
void SetActiveBackgroundColour(Colour background) { this->activeBackground = background; }
|
||||
void SetBorderColour(Colour border) { this->border = border; }
|
||||
void SetActiveBorderColour(Colour border) { this->activeBorder = border; }
|
||||
void SetTextColour(Colour text) { this->text = text; }
|
||||
void SetActiveTextColour(Colour text) { this->activeText = text; }
|
||||
|
||||
void SetIcon(Icon icon);
|
||||
protected:
|
||||
Colour background, activeBackground;
|
||||
Colour border, activeBorder;
|
||||
Colour text, activeText;
|
||||
|
||||
std::string buttonDisplayText;
|
||||
std::string ButtonText;
|
||||
|
||||
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
|
||||
ButtonAction * actionCallback;
|
||||
ui::Point textPosition;
|
||||
HorizontalAlignment textHAlign;
|
||||
VerticalAlignment textVAlign;
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
//#include "Platform.h"
|
||||
#include <iostream>
|
||||
#include "interface/Component.h"
|
||||
#include "interface/Engine.h"
|
||||
#include "interface/Point.h"
|
||||
@ -13,18 +14,24 @@ Component::Component(Window* parent_state):
|
||||
Position(Point(0,0)),
|
||||
Size(Point(0,0)),
|
||||
Locked(false),
|
||||
Visible(true)
|
||||
Visible(true),
|
||||
textPosition(0, 0),
|
||||
iconPosition(0, 0),
|
||||
drawn(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Component::Component(Point position, Point size):
|
||||
parentstate_(NULL),
|
||||
parentstate_(0),
|
||||
_parent(NULL),
|
||||
Position(position),
|
||||
Size(size),
|
||||
Locked(false),
|
||||
Visible(true)
|
||||
Visible(true),
|
||||
textPosition(0, 0),
|
||||
iconPosition(0, 0),
|
||||
drawn(false)
|
||||
{
|
||||
|
||||
}
|
||||
@ -35,11 +42,68 @@ Component::Component():
|
||||
Position(Point(0,0)),
|
||||
Size(Point(0,0)),
|
||||
Locked(false),
|
||||
Visible(true)
|
||||
Visible(true),
|
||||
textPosition(0, 0),
|
||||
iconPosition(0, 0),
|
||||
drawn(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Component::Refresh()
|
||||
{
|
||||
drawn = false;
|
||||
}
|
||||
|
||||
void Component::TextPosition(std::string displayText)
|
||||
{
|
||||
|
||||
textPosition = ui::Point(0, 0);
|
||||
|
||||
int textWidth, textHeight = 10;
|
||||
Graphics::textsize((char*)displayText.c_str(), textWidth, textHeight);
|
||||
textHeight-=3;
|
||||
textWidth-=1;
|
||||
if(Appearance.icon)
|
||||
{
|
||||
textWidth += 15;
|
||||
}
|
||||
|
||||
int textAreaWidth = Size.X-(Appearance.Margin.Right+Appearance.Margin.Left);
|
||||
int textAreaHeight = Size.Y-(Appearance.Margin.Top+Appearance.Margin.Bottom);
|
||||
|
||||
switch(Appearance.VerticalAlign)
|
||||
{
|
||||
case ui::Appearance::AlignTop:
|
||||
textPosition.Y = Appearance.Margin.Top;
|
||||
break;
|
||||
case ui::Appearance::AlignMiddle:
|
||||
textPosition.Y = Appearance.Margin.Top+((textAreaHeight-textHeight)/2);
|
||||
break;
|
||||
case ui::Appearance::AlignBottom:
|
||||
textPosition.Y = Size.Y-(textHeight+Appearance.Margin.Bottom);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(Appearance.HorizontalAlign)
|
||||
{
|
||||
case ui::Appearance::AlignLeft:
|
||||
textPosition.X = Appearance.Margin.Left;
|
||||
break;
|
||||
case ui::Appearance::AlignCentre:
|
||||
textPosition.X = Appearance.Margin.Left+((textAreaWidth-textWidth)/2);
|
||||
break;
|
||||
case ui::Appearance::AlignRight:
|
||||
textPosition.X = Size.X-(textWidth+Appearance.Margin.Right);
|
||||
break;
|
||||
}
|
||||
if(Appearance.icon)
|
||||
{
|
||||
iconPosition = textPosition-ui::Point(0, 1);
|
||||
textPosition.X += 15;
|
||||
}
|
||||
}
|
||||
|
||||
bool Component::IsFocused() const
|
||||
{
|
||||
return parentstate_->IsFocused(this);
|
||||
@ -88,6 +152,7 @@ void Component::SetParent(Panel* new_parent)
|
||||
|
||||
void Component::Draw(const Point& screenPos)
|
||||
{
|
||||
drawn = true;
|
||||
}
|
||||
|
||||
void Component::Tick(float dt)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Appearance.h"
|
||||
#include "Point.h"
|
||||
#include "Window.h"
|
||||
#include "Platform.h"
|
||||
@ -16,6 +17,13 @@ namespace ui
|
||||
*/
|
||||
class Component
|
||||
{
|
||||
private:
|
||||
Window* parentstate_;
|
||||
Panel* _parent;
|
||||
protected:
|
||||
bool drawn;
|
||||
ui::Point textPosition;
|
||||
ui::Point iconPosition;
|
||||
public:
|
||||
Component(Window* parent_state);
|
||||
Component(Point position, Point size);
|
||||
@ -31,6 +39,13 @@ namespace ui
|
||||
bool Locked;
|
||||
bool Visible;
|
||||
|
||||
ui::Appearance Appearance;
|
||||
//virtual void SetAppearance(ui::Appearance);
|
||||
//ui::Appearance GetAppearance();
|
||||
virtual void TextPosition(std::string);
|
||||
|
||||
void Refresh();
|
||||
|
||||
/* See the parent of this component.
|
||||
* If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild)
|
||||
*/
|
||||
@ -196,9 +211,5 @@ namespace ui
|
||||
// alt: Alternate key is released.
|
||||
///
|
||||
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||
|
||||
private:
|
||||
Window* parentstate_;
|
||||
Panel* _parent;
|
||||
};
|
||||
}
|
||||
|
@ -15,9 +15,7 @@ namespace ui {
|
||||
class ItemSelectedAction;
|
||||
class DropDownWindow: public ui::Window {
|
||||
friend class ItemSelectedAction;
|
||||
Colour background, activeBackground;
|
||||
Colour border, activeBorder;
|
||||
Colour text, activeText;
|
||||
Appearance appearance;
|
||||
DropDown * dropDown;
|
||||
std::vector<Button> buttons;
|
||||
bool isMouseInside;
|
||||
@ -38,19 +36,13 @@ public:
|
||||
DropDownWindow(DropDown * dropDown):
|
||||
Window(ui::Point(dropDown->Position.X+dropDown->GetParentWindow()->Position.X-5, dropDown->Position.Y+dropDown->GetParentWindow()->Position.Y-3), ui::Point(dropDown->Size.X+10, 1+dropDown->options.size()*15)),
|
||||
dropDown(dropDown),
|
||||
background(dropDown->background),
|
||||
activeBackground(dropDown->activeBackground),
|
||||
border(dropDown->border),
|
||||
activeBorder(dropDown->activeBorder),
|
||||
text(dropDown->text),
|
||||
activeText(dropDown->activeText)
|
||||
appearance(dropDown->Appearance)
|
||||
{
|
||||
int currentY = 1;
|
||||
for(int i = 0; i < dropDown->options.size(); i++)
|
||||
{
|
||||
Button * tempButton = new Button(Point(1, currentY), Point(Size.X-2, 14), dropDown->options[i].first);
|
||||
tempButton->SetTextColour(dropDown->text);
|
||||
tempButton->SetBorderColour(dropDown->background);
|
||||
tempButton->Appearance = appearance;
|
||||
tempButton->SetActionCallback(new ItemSelectedAction(this, dropDown->options[i].first));
|
||||
AddComponent(tempButton);
|
||||
currentY += 15;
|
||||
@ -60,7 +52,7 @@ public:
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 100, 100, 100, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, border.Alpha);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, appearance.BackgroundInactive.Red, appearance.BackgroundInactive.Green, appearance.BackgroundInactive.Blue, appearance.BackgroundInactive.Alpha);
|
||||
}
|
||||
void setOption(std::string option)
|
||||
{
|
||||
@ -83,17 +75,8 @@ DropDown::DropDown(Point position, Point size):
|
||||
Component(position, size),
|
||||
isMouseInside(false),
|
||||
optionIndex(-1),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignLeft),
|
||||
callback(NULL)
|
||||
{
|
||||
activeText = text = Colour(255, 255, 255);
|
||||
|
||||
border = style::Colour::InactiveBorder;
|
||||
activeBorder = style::Colour::ActiveBorder;
|
||||
background = style::Colour::InactiveBackground;
|
||||
activeBackground = style::Colour::ActiveBackground;
|
||||
}
|
||||
|
||||
void DropDown::OnMouseClick(int x, int y, unsigned int button)
|
||||
@ -104,59 +87,31 @@ void DropDown::OnMouseClick(int x, int y, unsigned int button)
|
||||
|
||||
void DropDown::Draw(const Point& screenPos)
|
||||
{
|
||||
if(!drawn)
|
||||
{
|
||||
if(optionIndex!=-1)
|
||||
TextPosition(options[optionIndex].first);
|
||||
drawn = true;
|
||||
}
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
Point Position = screenPos;
|
||||
if(isMouseInside)
|
||||
{
|
||||
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);
|
||||
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, Appearance.BackgroundActive.Red, Appearance.BackgroundActive.Green, Appearance.BackgroundActive.Blue, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderActive.Red, Appearance.BorderActive.Green, Appearance.BorderActive.Blue, 255);
|
||||
if(optionIndex!=-1)
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, activeText.Red, activeText.Green, activeText.Blue, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, Appearance.TextActive.Red, Appearance.TextActive.Green, Appearance.TextActive.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);
|
||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BackgroundInactive.Red, Appearance.BackgroundInactive.Green, Appearance.BackgroundInactive.Blue, 255);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, Appearance.BorderInactive.Red, Appearance.BorderInactive.Green, Appearance.BorderInactive.Blue, 255);
|
||||
if(optionIndex!=-1)
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, text.Red, text.Green, text.Blue, 255);
|
||||
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, Appearance.TextInactive.Red, Appearance.TextInactive.Green, Appearance.TextInactive.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)
|
||||
@ -173,7 +128,7 @@ void DropDown::Draw(const Point& screenPos)
|
||||
if(options[i].first == option)
|
||||
{
|
||||
optionIndex = i;
|
||||
TextPosition();
|
||||
TextPosition(options[optionIndex].first);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -185,7 +140,7 @@ void DropDown::Draw(const Point& screenPos)
|
||||
if(options[i].second == option)
|
||||
{
|
||||
optionIndex = i;
|
||||
TextPosition();
|
||||
TextPosition(options[optionIndex].first);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -24,20 +24,13 @@ public:
|
||||
};
|
||||
class DropDown: public ui::Component {
|
||||
friend class DropDownWindow;
|
||||
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);
|
||||
|
@ -18,12 +18,8 @@ using namespace ui;
|
||||
Label::Label(Point position, Point size, std::string labelText):
|
||||
Component(position, size),
|
||||
text(labelText),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignCentre),
|
||||
textColour(255, 255, 255)
|
||||
{
|
||||
TextPosition();
|
||||
}
|
||||
|
||||
/*Label::Label(std::string labelText):
|
||||
@ -41,44 +37,24 @@ Label::~Label()
|
||||
|
||||
}
|
||||
|
||||
void Label::TextPosition()
|
||||
{
|
||||
//Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2
|
||||
switch(textVAlign)
|
||||
{
|
||||
case AlignTop:
|
||||
textPosition.Y = 3;
|
||||
break;
|
||||
case AlignMiddle:
|
||||
textPosition.Y = (Size.Y-10)/2;
|
||||
break;
|
||||
case AlignBottom:
|
||||
textPosition.Y = Size.Y-11;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(textHAlign)
|
||||
{
|
||||
case AlignLeft:
|
||||
textPosition.X = 3;
|
||||
break;
|
||||
case AlignCentre:
|
||||
textPosition.X = (Size.X-Graphics::textwidth((char *)text.c_str()))/2;
|
||||
break;
|
||||
case AlignRight:
|
||||
textPosition.X = (Size.X-Graphics::textwidth((char *)text.c_str()))-2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Label::SetText(std::string text)
|
||||
{
|
||||
this->text = text;
|
||||
TextPosition();
|
||||
TextPosition(text);
|
||||
}
|
||||
|
||||
std::string Label::GetText()
|
||||
{
|
||||
return this->text;
|
||||
}
|
||||
|
||||
void Label::Draw(const Point& screenPos)
|
||||
{
|
||||
if(!drawn)
|
||||
{
|
||||
TextPosition(text);
|
||||
drawn = true;
|
||||
}
|
||||
Graphics * g = Engine::Ref().g;
|
||||
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, text, textColour.Red, textColour.Green, textColour.Blue, 255);
|
||||
}
|
||||
|
@ -13,10 +13,6 @@ namespace ui
|
||||
{
|
||||
protected:
|
||||
std::string text;
|
||||
ui::Point textPosition;
|
||||
HorizontalAlignment textHAlign;
|
||||
VerticalAlignment textVAlign;
|
||||
|
||||
Colour textColour;
|
||||
public:
|
||||
//Label(Window* parent_state, std::string labelText);
|
||||
@ -24,11 +20,8 @@ namespace ui
|
||||
//Label(std::string labelText);
|
||||
virtual ~Label();
|
||||
|
||||
virtual void TextPosition();
|
||||
virtual void SetText(std::string text);
|
||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||
VerticalAlignment GetVAlignment() { return textVAlign; }
|
||||
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
||||
virtual std::string GetText();
|
||||
|
||||
void SetTextColour(Colour textColour) { this->textColour = textColour; }
|
||||
|
||||
|
@ -12,14 +12,11 @@ Textbox::Textbox(Point position, Point size, std::string textboxText):
|
||||
Component(position, size),
|
||||
text(textboxText),
|
||||
textPosition(ui::Point(0, 0)),
|
||||
textVAlign(AlignMiddle),
|
||||
textHAlign(AlignCentre),
|
||||
actionCallback(NULL),
|
||||
masked(false),
|
||||
border(true)
|
||||
{
|
||||
SetText(textboxText);
|
||||
TextPosition();
|
||||
cursor = text.length();
|
||||
}
|
||||
|
||||
@ -29,57 +26,19 @@ Textbox::~Textbox()
|
||||
delete actionCallback;
|
||||
}
|
||||
|
||||
void Textbox::TextPosition()
|
||||
{
|
||||
if(cursor)
|
||||
{
|
||||
cursorPosition = Graphics::textnwidth((char *)displayText.c_str(), cursor);
|
||||
}
|
||||
else
|
||||
{
|
||||
cursorPosition = 0;
|
||||
}
|
||||
//Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2
|
||||
switch(textVAlign)
|
||||
{
|
||||
case AlignTop:
|
||||
textPosition.Y = 3;
|
||||
break;
|
||||
case AlignMiddle:
|
||||
textPosition.Y = (Size.Y-10)/2;
|
||||
break;
|
||||
case AlignBottom:
|
||||
textPosition.Y = Size.Y-11;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void Textbox::SetText(std::string text)
|
||||
{
|
||||
cursor = text.length();
|
||||
this->text = text;
|
||||
this->displayText = text;
|
||||
TextPosition();
|
||||
TextPosition(displayText);
|
||||
}
|
||||
|
||||
|
||||
void Textbox::SetDisplayText(std::string text)
|
||||
{
|
||||
displayText = text;
|
||||
TextPosition();
|
||||
TextPosition(displayText);
|
||||
}
|
||||
|
||||
std::string Textbox::GetText()
|
||||
@ -140,7 +99,6 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
if(cursor == text.length())
|
||||
{
|
||||
text += character;
|
||||
//std::cout << key << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -171,11 +129,16 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
if(actionCallback)
|
||||
actionCallback->TextChangedCallback(this);
|
||||
}
|
||||
TextPosition();
|
||||
TextPosition(displayText);
|
||||
}
|
||||
|
||||
void Textbox::Draw(const Point& screenPos)
|
||||
{
|
||||
if(!drawn)
|
||||
{
|
||||
TextPosition(displayText);
|
||||
drawn = true;
|
||||
}
|
||||
Graphics * g = Engine::Ref().g;
|
||||
if(IsFocused())
|
||||
{
|
||||
|
@ -22,8 +22,6 @@ protected:
|
||||
std::string text;
|
||||
std::string displayText;
|
||||
ui::Point textPosition;
|
||||
HorizontalAlignment textHAlign;
|
||||
VerticalAlignment textVAlign;
|
||||
int cursor, cursorPosition;
|
||||
TextboxAction *actionCallback;
|
||||
bool masked;
|
||||
@ -32,13 +30,9 @@ public:
|
||||
Textbox(Point position, Point size, std::string textboxText);
|
||||
virtual ~Textbox();
|
||||
|
||||
virtual void TextPosition();
|
||||
virtual void SetText(std::string text);
|
||||
virtual void SetDisplayText(std::string text);
|
||||
std::string GetText();
|
||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||
VerticalAlignment GetVAlignment() { return textVAlign; }
|
||||
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
||||
void SetActionCallback(TextboxAction * action) { actionCallback = action; }
|
||||
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "LoginView.h"
|
||||
#include "Style.h"
|
||||
|
||||
class LoginView::LoginAction : public ui::ButtonAction
|
||||
{
|
||||
@ -30,28 +31,35 @@ public:
|
||||
};
|
||||
|
||||
LoginView::LoginView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 100)),
|
||||
loginButton(new ui::Button(ui::Point(200-50, 100-16), ui::Point(50, 16), "Login")),
|
||||
cancelButton(new ui::Button(ui::Point(0, 100-16), ui::Point(50, 16), "Cancel")),
|
||||
titleLabel(new ui::Label(ui::Point(4, 2), ui::Point(200-16, 16), "Server login")),
|
||||
usernameField(new ui::Textbox(ui::Point(8, 20), ui::Point(200-16, 16), "")),
|
||||
passwordField(new ui::Textbox(ui::Point(8, 40), ui::Point(200-16, 16), "")),
|
||||
infoLabel(new ui::Label(ui::Point(8, 60), ui::Point(200-16, 16), ""))
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 87)),
|
||||
loginButton(new ui::Button(ui::Point(200-100, 87-17), ui::Point(100, 17), "Sign in")),
|
||||
cancelButton(new ui::Button(ui::Point(0, 87-17), ui::Point(101, 17), "Cancel")),
|
||||
titleLabel(new ui::Label(ui::Point(4, 5), ui::Point(200-16, 16), "Server login")),
|
||||
usernameField(new ui::Textbox(ui::Point(8, 25), ui::Point(200-16, 17), Client::Ref().GetAuthUser().Username)),
|
||||
passwordField(new ui::Textbox(ui::Point(8, 46), ui::Point(200-16, 17), "")),
|
||||
infoLabel(new ui::Label(ui::Point(8, 67), ui::Point(200-16, 16), "")),
|
||||
targetSize(0, 0)
|
||||
{
|
||||
targetSize = Size;
|
||||
AddComponent(loginButton);
|
||||
loginButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
|
||||
loginButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
loginButton->Appearance.TextInactive = style::Colour::ConfirmButton;
|
||||
loginButton->SetActionCallback(new LoginAction(this));
|
||||
AddComponent(cancelButton);
|
||||
cancelButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
cancelButton->SetActionCallback(new CancelAction(this));
|
||||
AddComponent(titleLabel);
|
||||
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
|
||||
AddComponent(usernameField);
|
||||
usernameField->SetAlignment(AlignLeft, AlignBottom);
|
||||
usernameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; usernameField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(passwordField);
|
||||
passwordField->SetAlignment(AlignLeft, AlignBottom);
|
||||
passwordField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; passwordField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
passwordField->SetHidden(true);
|
||||
infoLabel->SetAlignment(AlignCentre, AlignBottom);
|
||||
infoLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; infoLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
infoLabel->Visible = false;
|
||||
AddComponent(infoLabel);
|
||||
}
|
||||
|
||||
@ -75,6 +83,11 @@ void LoginView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, boo
|
||||
|
||||
void LoginView::NotifyStatusChanged(LoginModel * sender)
|
||||
{
|
||||
if(!infoLabel->GetText().length() && sender->GetStatusText().length())
|
||||
{
|
||||
targetSize = Size+ui::Point(0, 18);
|
||||
infoLabel->Visible = true;
|
||||
}
|
||||
infoLabel->SetText(sender->GetStatusText());
|
||||
if(sender->GetStatus())
|
||||
{
|
||||
@ -82,6 +95,31 @@ void LoginView::NotifyStatusChanged(LoginModel * sender)
|
||||
}
|
||||
}
|
||||
|
||||
void LoginView::OnTick(float dt)
|
||||
{
|
||||
//if(targetSize != Size)
|
||||
{
|
||||
ui::Point difference = targetSize-Size;
|
||||
if(difference.X!=0)
|
||||
{
|
||||
int xdiff = difference.X/100;
|
||||
if(xdiff == 0)
|
||||
xdiff = 1*isign(difference.X);
|
||||
Size.X += xdiff;
|
||||
}
|
||||
if(difference.Y!=0)
|
||||
{
|
||||
int ydiff = difference.Y/100;
|
||||
if(ydiff == 0)
|
||||
ydiff = 1*isign(difference.Y);
|
||||
Size.Y += ydiff;
|
||||
}
|
||||
|
||||
loginButton->Position.Y = Size.Y-17;
|
||||
cancelButton->Position.Y = Size.Y-17;
|
||||
}
|
||||
}
|
||||
|
||||
void LoginView::OnDraw()
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
|
@ -19,6 +19,7 @@ class LoginController;
|
||||
class LoginMode;
|
||||
class LoginView: public ui::Window {
|
||||
LoginController * c;
|
||||
ui::Point targetSize;
|
||||
ui::Button * loginButton;
|
||||
ui::Button * cancelButton;
|
||||
ui::Label * titleLabel;
|
||||
@ -33,6 +34,7 @@ public:
|
||||
void AttachController(LoginController * c_) { c = c_; }
|
||||
void NotifyStatusChanged(LoginModel * sender);
|
||||
virtual void OnDraw();
|
||||
virtual void OnTick(float dt);
|
||||
virtual ~LoginView();
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ OptionsView::OptionsView():
|
||||
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options");
|
||||
tempLabel->SetTextColour(style::Colour::InformationTitle);
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class HeatSimulationAction: public ui::CheckboxAction
|
||||
@ -31,7 +31,7 @@ OptionsView::OptionsView():
|
||||
heatSimulation->SetActionCallback(new HeatSimulationAction(this));
|
||||
AddComponent(heatSimulation);
|
||||
tempLabel = new ui::Label(ui::Point(24, heatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with very old saves");
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class AmbientHeatSimulationAction: public ui::CheckboxAction
|
||||
@ -46,7 +46,7 @@ OptionsView::OptionsView():
|
||||
ambientHeatSimulation->SetActionCallback(new AmbientHeatSimulationAction(this));
|
||||
AddComponent(ambientHeatSimulation);
|
||||
tempLabel = new ui::Label(ui::Point(24, ambientHeatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with old saves");
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class NewtonianGravityAction: public ui::CheckboxAction
|
||||
@ -61,7 +61,7 @@ OptionsView::OptionsView():
|
||||
newtonianGravity->SetActionCallback(new NewtonianGravityAction(this));
|
||||
AddComponent(newtonianGravity);
|
||||
tempLabel = new ui::Label(ui::Point(24, newtonianGravity->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance on older computers");
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class WaterEqualisationAction: public ui::CheckboxAction
|
||||
@ -76,7 +76,7 @@ OptionsView::OptionsView():
|
||||
waterEqualisation->SetActionCallback(new WaterEqualisationAction(this));
|
||||
AddComponent(waterEqualisation);
|
||||
tempLabel = new ui::Label(ui::Point(24, waterEqualisation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance with a lot of water");
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class AirModeChanged: public ui::DropDownAction
|
||||
@ -96,7 +96,7 @@ OptionsView::OptionsView():
|
||||
airMode->SetActionCallback(new AirModeChanged(this));
|
||||
|
||||
tempLabel = new ui::Label(ui::Point(8, 146), ui::Point(Size.X-96, 16), "Air Simulation Mode");
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
class GravityModeChanged: public ui::DropDownAction
|
||||
@ -115,7 +115,7 @@ OptionsView::OptionsView():
|
||||
gravityMode->SetActionCallback(new GravityModeChanged(this));
|
||||
|
||||
tempLabel = new ui::Label(ui::Point(8, 166), ui::Point(Size.X-96, 16), "Gravity Simulation Mode");
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(tempLabel);
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ PreviewView::PreviewView():
|
||||
}
|
||||
};
|
||||
openButton = new ui::Button(ui::Point(0, Size.Y-19), ui::Point(51, 19), "Open");
|
||||
openButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||
openButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; openButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
openButton->SetIcon(IconOpen);
|
||||
openButton->SetActionCallback(new OpenAction(this));
|
||||
AddComponent(openButton);
|
||||
@ -45,7 +45,7 @@ PreviewView::PreviewView():
|
||||
};
|
||||
|
||||
favButton = new ui::Button(ui::Point(51, Size.Y-19), ui::Point(51, 19), "Fav.");
|
||||
favButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||
favButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; favButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
favButton->SetIcon(IconFavourite);
|
||||
favButton->SetActionCallback(new FavAction(this));
|
||||
AddComponent(favButton);
|
||||
@ -72,7 +72,7 @@ PreviewView::PreviewView():
|
||||
}
|
||||
};
|
||||
reportButton = new ui::Button(ui::Point(102, Size.Y-19), ui::Point(51, 19), "Report");
|
||||
reportButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||
reportButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; reportButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
reportButton->SetIcon(IconReport);
|
||||
reportButton->SetActionCallback(new ReportAction(this));
|
||||
AddComponent(reportButton);
|
||||
@ -89,22 +89,22 @@ PreviewView::PreviewView():
|
||||
};
|
||||
|
||||
browserOpenButton = new ui::Button(ui::Point((XRES/2)-108, Size.Y-19), ui::Point(108, 19), "Open in browser");
|
||||
browserOpenButton->SetAlignment(AlignLeft, AlignMiddle);
|
||||
browserOpenButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; browserOpenButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
browserOpenButton->SetIcon(IconOpen);
|
||||
browserOpenButton->SetActionCallback(new BrowserOpenAction(this));
|
||||
AddComponent(browserOpenButton);
|
||||
|
||||
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+15), ui::Point(100, 16), "");
|
||||
saveNameLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
saveNameLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveNameLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(saveNameLabel);
|
||||
|
||||
saveDescriptionTextblock = new ui::Textblock(ui::Point(5, (YRES/2)+15+14+17), ui::Point((XRES/2)-10, Size.Y-((YRES/2)+15+14+17)-21), "");
|
||||
saveDescriptionTextblock->SetAlignment(AlignLeft, AlignTop);
|
||||
saveDescriptionTextblock->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveDescriptionTextblock->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
saveDescriptionTextblock->SetTextColour(ui::Colour(180, 180, 180));
|
||||
AddComponent(saveDescriptionTextblock);
|
||||
|
||||
authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14), ui::Point(100, 16), "");
|
||||
authorDateLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
authorDateLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(authorDateLabel);
|
||||
}
|
||||
|
||||
@ -194,10 +194,10 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
||||
for(int i = 0; i < tempComments->size(); i++)
|
||||
{
|
||||
tempUsername = new ui::Label(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), 16), tempComments->at(i)->authorName);
|
||||
tempUsername->SetAlignment(AlignLeft, AlignBottom);
|
||||
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
currentY += 16;
|
||||
tempComment = new ui::Textblock(ui::Point((XRES/2) + 5, currentY+5), ui::Point(Size.X-((XRES/2) + 10), -1), tempComments->at(i)->comment);
|
||||
tempComment->SetAlignment(AlignLeft, AlignTop);
|
||||
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
||||
currentY += tempComment->Size.Y+4;
|
||||
|
||||
|
@ -13,7 +13,6 @@ Save::Save(Save & save) :
|
||||
save.date), Published(save.Published), id(save.id), votesUp(
|
||||
save.votesUp), votesDown(save.votesDown), data(NULL), vote(save.vote), tags(save.tags) {
|
||||
if (save.data) {
|
||||
std::cout << data << " " << save.data << std::endl;
|
||||
data = (unsigned char *) malloc(save.dataLength);
|
||||
memcpy(data, save.data, save.dataLength);
|
||||
dataLength = save.dataLength;
|
||||
|
@ -28,7 +28,7 @@ SearchView::SearchView():
|
||||
}
|
||||
};
|
||||
searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-226, 16), "");
|
||||
searchField->SetAlignment(AlignLeft, AlignBottom);
|
||||
searchField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; searchField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
searchField->SetActionCallback(new SearchAction(this));
|
||||
|
||||
class SortAction : public ui::ButtonAction
|
||||
@ -43,7 +43,7 @@ SearchView::SearchView():
|
||||
};
|
||||
sortButton = new ui::Button(ui::Point(XRES+BARSIZE-140, 10), ui::Point(60, 16), "Sort");
|
||||
sortButton->SetActionCallback(new SortAction(this));
|
||||
sortButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
sortButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; sortButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(sortButton);
|
||||
|
||||
class MyOwnAction : public ui::ButtonAction
|
||||
@ -61,7 +61,7 @@ SearchView::SearchView():
|
||||
ownButton->SetActionCallback(new MyOwnAction(this));
|
||||
if(!Client::Ref().GetAuthUser().ID)
|
||||
ownButton->Enabled = false;
|
||||
ownButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
ownButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; ownButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(ownButton);
|
||||
|
||||
class FavAction : public ui::ButtonAction
|
||||
@ -80,7 +80,7 @@ SearchView::SearchView():
|
||||
favButton->SetActionCallback(new FavAction(this));
|
||||
if(!Client::Ref().GetAuthUser().ID)
|
||||
favButton->Enabled = false;
|
||||
favButton->SetAlignment(AlignCentre, AlignBottom);
|
||||
favButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; favButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(favButton);
|
||||
|
||||
class NextPageAction : public ui::ButtonAction
|
||||
@ -94,7 +94,7 @@ SearchView::SearchView():
|
||||
}
|
||||
};
|
||||
nextButton->SetActionCallback(new NextPageAction(this));
|
||||
nextButton->SetAlignment(AlignRight, AlignBottom);
|
||||
nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight; nextButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
class PrevPageAction : public ui::ButtonAction
|
||||
{
|
||||
SearchView * v;
|
||||
@ -106,7 +106,7 @@ SearchView::SearchView():
|
||||
}
|
||||
};
|
||||
previousButton->SetActionCallback(new PrevPageAction(this));
|
||||
previousButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; previousButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(nextButton);
|
||||
AddComponent(previousButton);
|
||||
AddComponent(searchField);
|
||||
@ -116,7 +116,7 @@ SearchView::SearchView():
|
||||
AddComponent(loadingSpinner);
|
||||
|
||||
ui::Label * searchPrompt = new ui::Label(ui::Point(10, 10), ui::Point(50, 16), "Search:");
|
||||
searchPrompt->SetAlignment(AlignLeft, AlignBottom);
|
||||
searchPrompt->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; searchPrompt->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(searchPrompt);
|
||||
|
||||
class RemoveSelectedAction : public ui::ButtonAction
|
||||
|
@ -17,11 +17,11 @@ SSaveView::SSaveView():
|
||||
descriptionField(NULL)
|
||||
{
|
||||
titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), "Save to Server");
|
||||
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(titleLabel);
|
||||
|
||||
nameField = new ui::Textbox(ui::Point(4, 18), ui::Point(Size.X-8, 16), "");
|
||||
nameField->SetAlignment(AlignLeft, AlignBottom);
|
||||
nameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; nameField->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
AddComponent(nameField);
|
||||
|
||||
descriptionField = new ui::Textarea(ui::Point(4, 54), ui::Point(Size.X-8, Size.Y-26-54), "");
|
||||
|
@ -35,7 +35,7 @@ StampsView::StampsView():
|
||||
}
|
||||
};
|
||||
nextButton->SetActionCallback(new NextPageAction(this));
|
||||
nextButton->SetAlignment(AlignRight, AlignBottom);
|
||||
nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight; nextButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
|
||||
class PrevPageAction : public ui::ButtonAction
|
||||
{
|
||||
@ -48,7 +48,7 @@ StampsView::StampsView():
|
||||
}
|
||||
};
|
||||
previousButton->SetActionCallback(new PrevPageAction(this));
|
||||
previousButton->SetAlignment(AlignLeft, AlignBottom);
|
||||
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; previousButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
|
||||
class RemoveSelectedAction : public ui::ButtonAction
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ TagsView::TagsView():
|
||||
}
|
||||
};
|
||||
closeButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(195, 16), "Close");
|
||||
closeButton->SetAlignment(AlignLeft, AlignTop);
|
||||
closeButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; closeButton->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
closeButton->SetActionCallback(new CloseAction(this));
|
||||
AddComponent(closeButton);
|
||||
|
||||
@ -36,7 +36,7 @@ TagsView::TagsView():
|
||||
AddComponent(tagInput);
|
||||
|
||||
title = new ui::Label(ui::Point(5, 5), ui::Point(185, 16), "Manage tags:");
|
||||
title->SetAlignment(AlignLeft, AlignTop);
|
||||
title->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; title->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
AddComponent(title);
|
||||
}
|
||||
|
||||
@ -81,14 +81,14 @@ void TagsView::NotifyTagsChanged(TagsModel * sender)
|
||||
for(int i = 0; i < sender->GetSave()->GetTags().size(); i++)
|
||||
{
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(35, 35+(16*i)), ui::Point(120, 16), sender->GetSave()->GetTags()[i]);
|
||||
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
|
||||
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
tags.push_back(tempLabel);
|
||||
AddComponent(tempLabel);
|
||||
|
||||
if(sender->GetSave()->GetUserName()==Client::Ref().GetAuthUser().Username)
|
||||
{
|
||||
ui::Button * tempButton = new ui::Button(ui::Point(15, 35+(16*i)), ui::Point(14, 14), "x");
|
||||
tempButton->SetAlignment(AlignCentre, AlignMiddle);
|
||||
tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
tempButton->SetActionCallback(new DeleteTagAction(this, sender->GetSave()->GetTags()[i]));
|
||||
tags.push_back(tempButton);
|
||||
AddComponent(tempButton);
|
||||
|
Loading…
Reference in New Issue
Block a user