Console UI, open in browser button, tab and enter shortcut for Login UI, various

This commit is contained in:
Simon Robertshaw 2012-02-01 18:45:59 +00:00
parent 857b0cc1fc
commit 038da72c61
27 changed files with 565 additions and 31 deletions

View File

@ -57,6 +57,8 @@
#define BARSIZE 0
#else
#define MENUSIZE 40
//#define MENUSIZE 20
//#define BARSIZE 50
#define BARSIZE 17
#endif
#define XRES 612

View File

@ -993,6 +993,11 @@ int Graphics::textnwidth(char *s, int n)
{
if (!n)
break;
if(((char)*s)=='\b')
{
s++;
continue;
}
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
n--;
}
@ -1035,6 +1040,11 @@ int Graphics::textwidthx(char *s, int w)
int x=0,n=0,cw;
for (; *s; s++)
{
if((char)*s == '\b')
{
s++;
continue;
}
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
if (x+(cw/2) >= w)
break;

View File

@ -621,6 +621,29 @@ void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255(0-360 for
*b += m;
}
void OpenURI(std::string uri) {
#ifdef WIN32
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
#elif MACOSX
char *cmd = malloc(7+uri.length());
strcpy(cmd, "open ");
strappend(cmd, uri.c_str());
system(cmd);
#elif LIN32
char *cmd = malloc(11+uri.length());
strcpy(cmd, "xdg-open ");
strappend(cmd, uri.c_str());
system(cmd);
#elif LIN64
char *cmd = malloc(11+uri.length());
strcpy(cmd, "xdg-open ");
strappend(cmd, uri.c_str());
system(cmd);
#else
printf("Cannot open browser\n");
#endif
}
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB values to 0-255(0-360 for H) HSV
{
float rr, gg, bb, a,x,c,d;

View File

@ -2,6 +2,7 @@
#define UTILS_H
#include <stdio.h>
#include <stdlib.h>
#include <string>
enum HorizontalAlignment
{
@ -86,6 +87,8 @@ void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b);
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
void OpenURI(std::string uri);
void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
// a b
// c d

View File

@ -0,0 +1,25 @@
/*
* ConsoleCommand.h
*
* Created on: Feb 1, 2012
* Author: Simon
*/
#ifndef CONSOLECOMMAND_H_
#define CONSOLECOMMAND_H_
class ConsoleCommand
{
public:
ConsoleCommand(std::string command, int returnStatus, std::string returnValue):
Command(command), ReturnStatus(returnStatus), ReturnValue(returnValue)
{
}
std::string Command;
int ReturnStatus;
std::string ReturnValue;
};
#endif /* CONSOLECOMMAND_H_ */

View File

@ -0,0 +1,102 @@
/*
* ConsoleController.cpp
*
* Created on: Jan 31, 2012
* Author: Simon
*/
#include <stack>
#include "ConsoleController.h"
ConsoleController::ConsoleController(ControllerCallback * callback):
HasDone(false)
{
consoleModel = new ConsoleModel();
consoleView = new ConsoleView();
consoleView->AttachController(this);
consoleModel->AddObserver(consoleView);
this->callback = callback;
}
void ConsoleController::EvaluateCommand(std::string command)
{
if(command.length())
consoleModel->AddLastCommand(ConsoleCommand(command, -1, "Syntax error"));
else
if(ui::Engine::Ref().GetWindow() == consoleView)
ui::Engine::Ref().CloseWindow();
}
std::string ConsoleController::FormatCommand(std::string command)
{
char * rawText = (char*)command.c_str();
char * outputData = (char *)calloc(command.length()*6, 1);
int rawTextLoc = 0;
int outputDataLoc = 0;
std::stack<char> pstack;
while(rawText[rawTextLoc])
{
switch(rawText[rawTextLoc])
{
case '\\':
outputData[outputDataLoc++] = rawText[rawTextLoc++];
if(rawText[rawTextLoc])
outputData[outputDataLoc++] = rawText[rawTextLoc++];
break;
case '"':
if(pstack.size() && pstack.top() == '"')
{
pstack.pop();
outputData[outputDataLoc++] = rawText[rawTextLoc++];
outputData[outputDataLoc++] = '\b';
outputData[outputDataLoc++] = 'w';
}
else
{
pstack.push('"');
outputData[outputDataLoc++] = '\b';
outputData[outputDataLoc++] = 'o';
outputData[outputDataLoc++] = rawText[rawTextLoc++];
}
break;
default:
outputData[outputDataLoc++] = rawText[rawTextLoc++];
break;
}
}
return outputData;
}
void ConsoleController::NextCommand()
{
int cIndex = consoleModel->GetCurrentCommandIndex();
if(cIndex < consoleModel->GetPreviousCommands().size())
consoleModel->SetCurrentCommandIndex(cIndex+1);
}
void ConsoleController::PreviousCommand()
{
int cIndex = consoleModel->GetCurrentCommandIndex();
if(cIndex > 0)
consoleModel->SetCurrentCommandIndex(cIndex-1);
}
void ConsoleController::Exit()
{
if(ui::Engine::Ref().GetWindow() == consoleView)
ui::Engine::Ref().CloseWindow();
if(callback)
callback->ControllerExit();
HasDone = true;
}
ConsoleView * ConsoleController::GetView()
{
return consoleView;
}
ConsoleController::~ConsoleController() {
// TODO Auto-generated destructor stub
}

View File

@ -0,0 +1,35 @@
/*
* ConsoleController.h
*
* Created on: Jan 31, 2012
* Author: Simon
*/
#ifndef CONSOLECONTROLLER_H_
#define CONSOLECONTROLLER_H_
#include <string>
#include "Controller.h"
#include "ConsoleView.h"
#include "ConsoleModel.h"
#include "ConsoleCommand.h"
class ConsoleModel;
class ConsoleView;
class ConsoleController {
ControllerCallback * callback;
ConsoleView * consoleView;
ConsoleModel * consoleModel;
public:
bool HasDone;
ConsoleController(ControllerCallback * callback);
std::string FormatCommand(std::string command);
void EvaluateCommand(std::string command);
void NextCommand();
void PreviousCommand();
void Exit();
ConsoleView * GetView();
virtual ~ConsoleController();
};
#endif /* CONSOLECONTROLLER_H_ */

View File

@ -0,0 +1,72 @@
/*
* ConsoleModel.cpp
*
* Created on: Feb 1, 2012
* Author: Simon
*/
#include "ConsoleModel.h"
ConsoleModel::ConsoleModel() {
}
void ConsoleModel::AddObserver(ConsoleView * observer)
{
observers.push_back(observer);
}
int ConsoleModel::GetCurrentCommandIndex()
{
return currentCommandIndex;
}
void ConsoleModel::SetCurrentCommandIndex(int index)
{
currentCommandIndex = index;
notifyCurrentCommandChanged();
}
ConsoleCommand ConsoleModel::GetCurrentCommand()
{
if(currentCommandIndex < 0 || currentCommandIndex >= previousCommands.size())
{
return ConsoleCommand("", 0, "");
}
return previousCommands[currentCommandIndex];
}
void ConsoleModel::AddLastCommand(ConsoleCommand command)
{
previousCommands.push_back(command);
if(previousCommands.size()>25)
previousCommands.pop_front();
currentCommandIndex = previousCommands.size();
notifyPreviousCommandsChanged();
}
std::deque<ConsoleCommand> ConsoleModel::GetPreviousCommands()
{
return previousCommands;
}
void ConsoleModel::notifyPreviousCommandsChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyPreviousCommandsChanged(this);
}
}
void ConsoleModel::notifyCurrentCommandChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyCurrentCommandChanged(this);
}
}
ConsoleModel::~ConsoleModel() {
}

View File

@ -0,0 +1,35 @@
/*
* ConsoleModel.h
*
* Created on: Feb 1, 2012
* Author: Simon
*/
#ifndef CONSOLEMODEL_H_
#define CONSOLEMODEL_H_
#include <vector>
#include <deque>
#include "ConsoleView.h"
#include "ConsoleCommand.h"
class ConsoleView;
class ConsoleModel {
int currentCommandIndex;
std::vector<ConsoleView*> observers;
std::deque<ConsoleCommand> previousCommands;
void notifyPreviousCommandsChanged();
void notifyCurrentCommandChanged();
public:
int GetCurrentCommandIndex();
void SetCurrentCommandIndex(int index);
ConsoleCommand GetCurrentCommand();
std::deque<ConsoleCommand> GetPreviousCommands();
ConsoleModel();
void AddObserver(ConsoleView * observer);
void AddLastCommand(ConsoleCommand command);
virtual ~ConsoleModel();
};
#endif /* CONSOLEMODEL_H_ */

View File

@ -0,0 +1,90 @@
/*
* ConsoleView.cpp
*
* Created on: Jan 31, 2012
* Author: Simon
*/
#include "ConsoleView.h"
#include "interface/Keys.h"
ConsoleView::ConsoleView():
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, 150)),
commandField(NULL)
{
class CommandHighlighter: public ui::TextboxAction
{
ConsoleView * v;
public:
CommandHighlighter(ConsoleView * v_) { v = v_; }
void TextChangedCallback(ui::Textbox * sender)
{
sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
}
};
commandField = new ui::Textbox(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "");
commandField->SetAlignment(AlignLeft, AlignBottom);
commandField->SetActionCallback(new CommandHighlighter(this));
AddComponent(commandField);
FocusComponent(commandField);
commandField->SetBorder(false);
}
void ConsoleView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
switch(key)
{
case KEY_RETURN:
case KEY_ENTER:
c->EvaluateCommand(commandField->GetText());
commandField->SetText("");
break;
case KEY_DOWN:
c->NextCommand();
break;
case KEY_UP:
c->PreviousCommand();
break;
}
}
void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender)
{
for(int i = 0; i < commandList.size(); i++)
{
RemoveComponent(commandList[i]);
delete commandList[i];
}
commandList.clear();
std::deque<ConsoleCommand> commands = sender->GetPreviousCommands();
int currentY = Size.Y - 32;
if(commands.size())
for(int i = commands.size()-1; i >= 0; i--)
{
if(currentY <= 0)
break;
ui::Label * tempLabel = new ui::Label(ui::Point(0, currentY), ui::Point(Size.X, 16), commands[i].Command);
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
commandList.push_back(tempLabel);
AddComponent(tempLabel);
currentY-=16;
}
}
void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)
{
commandField->SetText(sender->GetCurrentCommand().Command);
}
void ConsoleView::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 0, 0, 0, 110);
g->blend_line(Position.X, Position.Y+Size.Y-16, Position.X+Size.X, Position.Y+Size.Y-16, 255, 255, 255, 160);
g->blend_line(Position.X, Position.Y+Size.Y, Position.X+Size.X, Position.Y+Size.Y, 255, 255, 255, 200);
}
ConsoleView::~ConsoleView() {
}

37
src/console/ConsoleView.h Normal file
View File

@ -0,0 +1,37 @@
/*
* ConsoleView.h
*
* Created on: Jan 31, 2012
* Author: Simon
*/
#ifndef CONSOLEVIEW_H_
#define CONSOLEVIEW_H_
#include <vector>
#include <queue>
#include "interface/Label.h"
#include "interface/Window.h"
#include "ConsoleController.h"
#include "ConsoleModel.h"
#include "interface/Textbox.h"
#include "ConsoleCommand.h"
class ConsoleController;
class ConsoleModel;
class ConsoleView: public ui::Window {
ConsoleController * c;
ui::Textbox * commandField;
std::vector<ui::Label*> commandList;
public:
ConsoleView();
virtual void OnDraw();
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
void AttachController(ConsoleController * c_) { c = c_; }
void NotifyPreviousCommandsChanged(ConsoleModel * sender);
void NotifyCurrentCommandChanged(ConsoleModel * sender);
virtual ~ConsoleView();
};
#endif /* CONSOLEVIEW_H_ */

View File

@ -95,6 +95,10 @@ GameController::~GameController()
{
delete loginWindow;
}
if(console)
{
delete console;
}
if(ui::Engine::Ref().GetWindow() == gameView)
{
ui::Engine::Ref().CloseWindow();
@ -301,6 +305,12 @@ void GameController::OpenDisplayOptions()
//TODO: Implement
}
void GameController::ShowConsole()
{
console = new ConsoleController(NULL);
ui::Engine::Ref().ShowWindow(console->GetView());
}
void GameController::OpenRenderOptions()
{
renderOptions = new RenderController(gameModel->GetRenderer(), new RenderCallback(this));

View File

@ -10,6 +10,7 @@
#include "render/RenderController.h"
#include "login/LoginController.h"
#include "ssave/SSaveController.h"
#include "console/ConsoleController.h"
#include "Menu.h"
using namespace std;
@ -26,6 +27,7 @@ private:
RenderController * renderOptions;
LoginController * loginWindow;
SSaveController * ssave;
ConsoleController * console;
public:
class LoginCallback;
class SearchCallback;
@ -57,6 +59,7 @@ public:
void ReloadSim();
void Vote(int direction);
void ChangeBrush();
void ShowConsole();
ui::Point PointTranslate(ui::Point point);
};

View File

@ -41,12 +41,19 @@ GameModel::GameModel():
//sim->wtypes[i]
}
//Set default brush palette
brushList.push_back(new Brush(ui::Point(4, 4)));
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
activeTools[0] = new ElementTool(1, "TURD", 0, 0, 0);
activeTools[1] = new ElementTool(0, "TURD", 0, 0, 0);
//activeTool[1] = new ElementTool(0, "TURD", 0, 0, 0);
//Set default tools
activeTools[0] = menuList[SC_POWDERS]->GetToolList()[0];
activeTools[1] = menuList[SC_SPECIAL]->GetToolList()[0];
//Set default menu
activeMenu = menuList[SC_POWDERS];
toolList = menuList[SC_POWDERS]->GetToolList();
//Load last user
std::cout << Client::Ref().GetAuthUser().Username << std::endl;
if(Client::Ref().GetAuthUser().ID)
{

View File

@ -277,6 +277,7 @@ void GameView::NotifyActiveToolsChanged(GameModel * sender)
void GameView::NotifyToolListChanged(GameModel * sender)
{
//int currentY = YRES+MENUSIZE-36;
int currentX = XRES+BARSIZE-56;
int totalColour;
for(int i = 0; i < menuButtons.size(); i++)
@ -299,8 +300,10 @@ void GameView::NotifyToolListChanged(GameModel * sender)
vector<Tool*> toolList = sender->GetToolList();
for(int i = 0; i < toolList.size(); i++)
{
ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES), ui::Point(32, 16), toolList[i]->GetName());
currentX -= 36;
//ToolButton * tempButton = new ToolButton(ui::Point(XRES+1, currentY), ui::Point(28, 15), toolList[i]->GetName());
ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(28, 15), toolList[i]->GetName());
//currentY -= 17;
currentX -= 32;
tempButton->SetActionCallback(new ToolAction(this, toolList[i]));
tempButton->SetBackgroundColour(ui::Colour(toolList[i]->colRed, toolList[i]->colGreen, toolList[i]->colBlue));
@ -507,6 +510,9 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
zoomCursorFixed = false;
c->SetZoomEnabled(true);
break;
case '`':
c->ShowConsole();
break;
}
}

View File

@ -43,11 +43,11 @@ void ToolButton::Draw(const ui::Point& screenPos)
if (totalColour<544)
{
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, ButtonText.c_str(), 255, 255, 255, 255);
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText.c_str(), 255, 255, 255, 255);
}
else
{
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, ButtonText.c_str(), 0, 0, 0, 255);
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, buttonDisplayText.c_str(), 0, 0, 0, 255);
}
if(currentSelection!=-1)
{

View File

@ -25,7 +25,7 @@ Button::Button(Point position, Point size, std::string buttonText):
actionCallback(NULL),
textPosition(ui::Point(0, 0)),
textVAlign(AlignMiddle),
textHAlign(AlignCentre),
textHAlign(AlignLeft),
Enabled(true),
icon(NoIcon)
{
@ -36,6 +36,16 @@ Button::Button(Point position, Point size, std::string buttonText):
void Button::TextPosition()
{
buttonDisplayText = ButtonText;
if(buttonDisplayText.length())
{
if(Graphics::textwidth((char *)buttonDisplayText.c_str()) > Size.X - (icon? 22 : 0))
{
int position = Graphics::textwidthx((char *)buttonDisplayText.c_str(), Size.X - (icon? 38 : 22));
buttonDisplayText = buttonDisplayText.erase(position, buttonDisplayText.length()-position);
buttonDisplayText += "...";
}
}
switch(textVAlign)
{
case AlignTop:
@ -45,7 +55,7 @@ void Button::TextPosition()
textPosition.Y = (Size.Y-10)/2;
break;
case AlignBottom:
textPosition.Y = Size.Y-11;
textPosition.Y = Size.Y-12;
break;
}
@ -57,10 +67,10 @@ void Button::TextPosition()
textPosition.X = 3+17;
break;
case AlignCentre:
textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)ButtonText.c_str()))/2)+17;
textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)buttonDisplayText.c_str()))/2)+17;
break;
case AlignRight:
textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)ButtonText.c_str()))-2)+17;
textPosition.X = (((Size.X-14)-Graphics::textwidth((char *)buttonDisplayText.c_str()))-2)+17;
break;
}
}
@ -72,10 +82,10 @@ void Button::TextPosition()
textPosition.X = 3;
break;
case AlignCentre:
textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2;
textPosition.X = (Size.X-Graphics::textwidth((char *)buttonDisplayText.c_str()))/2;
break;
case AlignRight:
textPosition.X = (Size.X-Graphics::textwidth((char *)ButtonText.c_str()))-2;
textPosition.X = (Size.X-Graphics::textwidth((char *)buttonDisplayText.c_str()))-2;
break;
}
}
@ -124,20 +134,20 @@ void Button::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);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, activeText.Red, activeText.Green, activeText.Blue, 255);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, 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);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, ButtonText, text.Red, text.Green, text.Blue, 255);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, text.Red, text.Green, text.Blue, 255);
}
}
else
{
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.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, ButtonText, 180, 180, 180, 255);
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, buttonDisplayText, 180, 180, 180, 255);
}
if(icon)
g->draw_icon(Position.X+3, Position.Y+textPosition.Y, icon);

View File

@ -33,8 +33,6 @@ public:
bool Toggleable;
bool Enabled;
std::string ButtonText;
virtual void OnMouseClick(int x, int y, unsigned int button);
virtual void OnMouseUp(int x, int y, unsigned int button);
//virtual void OnMouseUp(int x, int y, unsigned int button);
@ -72,6 +70,9 @@ protected:
Colour border, activeBorder;
Colour text, activeText;
std::string buttonDisplayText;
std::string ButtonText;
bool isButtonDown, state, isMouseInside, isTogglable, toggle;
ButtonAction * actionCallback;
ui::Point textPosition;

View File

@ -7,6 +7,8 @@
#define KEY_BACKSPACE SDLK_BACKSPACE
#define KEY_DELETE SDLK_DELETE
#define KEY_TAB SDLK_TAB
#define KEY_RETURN SDLK_RETURN
#define KEY_ENTER SDLK_KP_ENTER
#define KEY_CTRL SDLK_LCTRL
#define KEY_ALT SDLK_LALT

View File

@ -16,7 +16,8 @@ Textbox::Textbox(Point position, Point size, std::string textboxText):
textVAlign(AlignMiddle),
textHAlign(AlignCentre),
actionCallback(NULL),
masked(false)
masked(false),
border(true)
{
SetText(textboxText);
TextPosition();
@ -31,11 +32,9 @@ Textbox::~Textbox()
void Textbox::TextPosition()
{
std::string tempText = displayText;
if(tempText.length() && cursor)
if(cursor)
{
tempText.erase(cursor, tempText.length()-cursor);
cursorPosition = Graphics::textwidth((char *)tempText.c_str());
cursorPosition = Graphics::textnwidth((char *)displayText.c_str(), cursor);
}
else
{
@ -71,6 +70,7 @@ void Textbox::TextPosition()
void Textbox::SetText(std::string text)
{
cursor = text.length();
if(masked)
{
char tempText[text.length()];
@ -86,6 +86,13 @@ void Textbox::SetText(std::string text)
TextPosition();
}
void Textbox::SetDisplayText(std::string text)
{
displayText = text;
TextPosition();
}
std::string Textbox::GetText()
{
return text;
@ -153,17 +160,18 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
cursor++;
changed = true;
}
if(changed && actionCallback)
{
actionCallback->TextChangedCallback(this);
}
}
catch(std::out_of_range &e)
{
cursor = 0;
text = "";
}
if(changed)
{
SetText(text);
if(actionCallback)
actionCallback->TextChangedCallback(this);
}
TextPosition();
}
@ -172,12 +180,12 @@ void Textbox::Draw(const Point& screenPos)
Graphics * g = Engine::Ref().g;
if(IsFocused())
{
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
g->draw_line(screenPos.X+textPosition.X+cursorPosition, screenPos.Y+3, screenPos.X+textPosition.X+cursorPosition, screenPos.Y+12, 255, 255, 255, XRES+BARSIZE);
}
else
{
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);
}

View File

@ -17,6 +17,7 @@ public:
};
class Textbox : public Component
{
friend class TextboxAction;
protected:
std::string text;
std::string displayText;
@ -26,12 +27,14 @@ protected:
int cursor, cursorPosition;
TextboxAction *actionCallback;
bool masked;
bool border;
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; }
@ -42,6 +45,8 @@ public:
void SetHidden(bool hidden) { masked = hidden; }
bool GetHidden() { return masked; }
void SetBorder(bool border) {this->border = border;}
virtual void Draw(const Point& screenPos);
};
}

View File

@ -55,6 +55,24 @@ LoginView::LoginView():
AddComponent(infoLabel);
}
void LoginView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
switch(key)
{
case KEY_TAB:
if(IsFocused(usernameField))
FocusComponent(passwordField);
else
FocusComponent(usernameField);
break;
case KEY_ENTER:
case KEY_RETURN:
if(IsFocused(passwordField))
loginButton->DoAction();
break;
}
}
void LoginView::NotifyStatusChanged(LoginModel * sender)
{
infoLabel->SetText(sender->GetStatusText());

View File

@ -29,6 +29,7 @@ public:
class LoginAction;
class CancelAction;
LoginView();
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
void AttachController(LoginController * c_) { c = c_; }
void NotifyStatusChanged(LoginModel * sender);
virtual void OnDraw();

View File

@ -5,6 +5,7 @@
* Author: Simon
*/
#include <sstream>
#include "PreviewController.h"
#include "PreviewView.h"
#include "PreviewModel.h"
@ -43,6 +44,16 @@ void PreviewController::DoOpen()
previewModel->SetDoOpen(true);
}
void PreviewController::OpenInBrowser()
{
if(previewModel->GetSave())
{
std::stringstream uriStream;
uriStream << "http://" << SERVER << "/Browse/View.html?ID=" << previewModel->GetSave()->id;
OpenURI(uriStream.str());
}
}
void PreviewController::Exit()
{
if(ui::Engine::Ref().GetWindow() == previewView)

View File

@ -24,6 +24,7 @@ public:
PreviewController(int saveID, ControllerCallback * callback);
void Exit();
void DoOpen();
void OpenInBrowser();
bool GetDoOpen();
Save * GetSave();
PreviewView * GetView() { return previewView; }

View File

@ -25,12 +25,28 @@ PreviewView::PreviewView():
v->c->Exit();
}
};
openButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(75, 16), "Open");
openButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(50, 16), "Open");
openButton->SetAlignment(AlignLeft, AlignMiddle);
openButton->SetIcon(IconOpen);
openButton->SetActionCallback(new OpenAction(this));
AddComponent(openButton);
class BrowserOpenAction: public ui::ButtonAction
{
PreviewView * v;
public:
BrowserOpenAction(PreviewView * v_){ v = v_; }
virtual void ActionCallback(ui::Button * sender)
{
v->c->OpenInBrowser();
}
};
browserOpenButton = new ui::Button(ui::Point((XRES/2)-90, Size.Y-16), ui::Point(90, 16), "Open in browser");
browserOpenButton->SetAlignment(AlignLeft, 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);
AddComponent(saveNameLabel);

View File

@ -20,6 +20,7 @@ class PreviewView: public ui::Window {
PreviewController * c;
Thumbnail * savePreview;
ui::Button * openButton;
ui::Button * browserOpenButton;
ui::Label * saveNameLabel;
ui::Label * authorDateLabel;
int votesUp;