Fix textbox

This commit is contained in:
Simon Robertshaw
2012-01-24 23:33:32 +00:00
parent 04e4a2346d
commit 35858ef607
9 changed files with 51 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ SDL_Surface * SDLOpen()
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError()); fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
return 0; return 0;
} }
SDL_EnableUNICODE(1);
#if defined(WIN32) && defined(WINCONSOLE) #if defined(WIN32) && defined(WINCONSOLE)
//On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console //On Windows, SDL redirects stdout to stdout.txt, which can be annoying when debugging, here we redirect back to the console
if (console) if (console)
@@ -84,7 +85,7 @@ int main(int argc, char * argv[])
engine->Exit(); engine->Exit();
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
engine->onKeyPress(event.key.keysym.sym, false, false, false); engine->onKeyPress(event.key.keysym.unicode, false, false, false);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
break; break;
@@ -133,7 +134,14 @@ int main(int argc, char * argv[])
fps = (((float)currentFrame)/((float)elapsedTime))*1000.0f; fps = (((float)currentFrame)/((float)elapsedTime))*1000.0f;
currentFrame = 0; currentFrame = 0;
lastTime = currentTime; lastTime = currentTime;
delta = 60.0f/fps; if(ui::Engine::Ref().FpsLimit > 2.0f)
{
delta = ui::Engine::Ref().FpsLimit/fps;
}
else
{
delta = 1.0f;
}
} }
} }
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();

View File

@@ -20,7 +20,7 @@
Client::Client() Client::Client()
{ {
int i = 0; int i = 0;
http_init("wwwcache.lancs.ac.uk:8080"); http_init(NULL);
for(i = 0; i < THUMB_CACHE_SIZE; i++) for(i = 0; i < THUMB_CACHE_SIZE; i++)
{ {
thumbnailCache[i] = NULL; thumbnailCache[i] = NULL;

View File

@@ -28,14 +28,22 @@ GameController::~GameController()
{ {
if(search) if(search)
{ {
if(ui::Engine::Ref().GetWindow() == search->GetView())
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
delete search; delete search;
} }
if(renderOptions) if(renderOptions)
{ {
if(ui::Engine::Ref().GetWindow() == renderOptions->GetView())
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
delete renderOptions; delete renderOptions;
} }
if(loginWindow)
{
if(ui::Engine::Ref().GetWindow() == loginWindow->GetView())
ui::Engine::Ref().CloseWindow();
delete loginWindow;
}
delete gameView; delete gameView;
delete gameModel; delete gameModel;
} }

View File

@@ -144,7 +144,7 @@ void Engine::Tick(float dt)
{ {
state_->Position.Y += windowTargetPosition.Y/20; state_->Position.Y += windowTargetPosition.Y/20;
}*/ }*/
windowOpenState += 0.05f*dt; windowOpenState += 0.05f;//*dt;
} }
/*if(statequeued_ != NULL) /*if(statequeued_ != NULL)

View File

@@ -1,4 +1,5 @@
#include <string> #include <string>
#include <iostream>
#include <stdexcept> #include <stdexcept>
#include "Config.h" #include "Config.h"
#include "Global.h" #include "Global.h"
@@ -157,6 +158,7 @@ void Textbox::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
if(cursor == text.length()) if(cursor == text.length())
{ {
text += key; text += key;
//std::cout << key << std::endl;
} }
else else
{ {

View File

@@ -22,7 +22,18 @@ void LoginController::Login(string username, string password)
loginModel->Login(username, password); loginModel->Login(username, password);
} }
LoginController::~LoginController() { void LoginController::Exit()
// TODO Auto-generated destructor stub {
if(ui::Engine::Ref().GetWindow() == loginView)
{
ui::Engine::Ref().CloseWindow();
loginView = NULL;
}
}
LoginController::~LoginController() {
if(loginView)
delete loginView;
delete loginModel;
} }

View File

@@ -22,6 +22,7 @@ class LoginController {
public: public:
LoginController(); LoginController();
void Login(string username, string password); void Login(string username, string password);
void Exit();
LoginView * GetView() { return loginView; } LoginView * GetView() { return loginView; }
virtual ~LoginController(); virtual ~LoginController();

View File

@@ -18,6 +18,17 @@ public:
} }
}; };
class LoginView::CancelAction : public ui::ButtonAction
{
LoginView * v;
public:
CancelAction(LoginView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
v->c->Exit();
}
};
LoginView::LoginView(): LoginView::LoginView():
ui::Window(ui::Point(-1, -1), ui::Point(200, 100)), 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")), loginButton(new ui::Button(ui::Point(200-50, 100-16), ui::Point(50, 16), "Login")),
@@ -32,6 +43,7 @@ LoginView::LoginView():
loginButton->SetActionCallback(new LoginAction(this)); loginButton->SetActionCallback(new LoginAction(this));
AddComponent(cancelButton); AddComponent(cancelButton);
cancelButton->SetAlignment(AlignCentre, AlignBottom); cancelButton->SetAlignment(AlignCentre, AlignBottom);
cancelButton->SetActionCallback(new CancelAction(this));
AddComponent(titleLabel); AddComponent(titleLabel);
titleLabel->SetAlignment(AlignLeft, AlignBottom); titleLabel->SetAlignment(AlignLeft, AlignBottom);
AddComponent(usernameField); AddComponent(usernameField);

View File

@@ -27,6 +27,7 @@ class LoginView: public ui::Window {
ui::Textbox * passwordField; ui::Textbox * passwordField;
public: public:
class LoginAction; class LoginAction;
class CancelAction;
LoginView(); LoginView();
void AttachController(LoginController * c_) { c = c_; } void AttachController(LoginController * c_) { c = c_; }
void NotifyStatusChanged(LoginModel * sender); void NotifyStatusChanged(LoginModel * sender);