From 86e10f867bc0531cdc2007524aa7757d7d594e7d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 19 Dec 2004 12:41:27 +0000 Subject: More refining of windows. --- src/gui/char_server.cpp | 15 +++++---------- src/gui/char_server.h | 7 +------ src/gui/login.cpp | 41 ++++++++++++++++------------------------- src/gui/login.h | 14 ++++++++------ src/gui/window.cpp | 24 +++++++++++++++--------- src/gui/window.h | 2 +- 6 files changed, 46 insertions(+), 57 deletions(-) diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 342836e4..6664be84 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -30,8 +30,8 @@ char server[30]; int showServerList = 1; -ServerSelectDialog::ServerSelectDialog(): - Window("Select Server") +ServerSelectDialog::ServerSelectDialog(gcn::Container *parent): + Window(parent, "Select Server") { serverListModel = new ServerListModel(); serverList = new gcn::ListBox(serverListModel); @@ -63,6 +63,8 @@ ServerSelectDialog::ServerSelectDialog(): // Select first server serverList->setSelected(1); } + + setLocationRelativeTo(getParent()); } ServerSelectDialog::~ServerSelectDialog() @@ -74,11 +76,6 @@ ServerSelectDialog::~ServerSelectDialog() delete cancelButton; } -void ServerSelectDialog::init() -{ - setLocationRelativeTo(getParent()); -} - void ServerSelectDialog::action(const std::string& eventId) { if (eventId == "ok") { @@ -103,9 +100,7 @@ std::string ServerListModel::getElementAt(int i) { void char_server() { - ServerSelectDialog *dialog = new ServerSelectDialog(); - guiTop->add(dialog); - dialog->init(); + ServerSelectDialog *dialog = new ServerSelectDialog(guiTop); state = LOGIN; diff --git a/src/gui/char_server.h b/src/gui/char_server.h index 6a11c589..66ea52bf 100644 --- a/src/gui/char_server.h +++ b/src/gui/char_server.h @@ -52,14 +52,9 @@ class ServerListModel : public gcn::ListModel { */ class ServerSelectDialog : public Window, public gcn::ActionListener { public: - ServerSelectDialog(); + ServerSelectDialog(gcn::Container *parent); ~ServerSelectDialog(); - /** - * Initializes the dialog. Should be called after adding it to the GUI. - */ - void init(); - /** * Called when receiving actions from the widgets. */ diff --git a/src/gui/login.cpp b/src/gui/login.cpp index cd74e850..3748106b 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -28,8 +28,8 @@ #include "../graphic/graphic.h" -LoginDialog::LoginDialog(): - Window("Login") +LoginDialog::LoginDialog(gcn::Container *parent): + Window(parent, "Login") { userLabel = new gcn::Label("Name:"); passLabel = new gcn::Label("Password:"); @@ -69,21 +69,7 @@ LoginDialog::LoginDialog(): add(keepCheck); add(okButton); add(cancelButton); -} - -LoginDialog::~LoginDialog() -{ - delete userLabel; - delete passLabel; - delete userField; - delete passField; - delete keepCheck; - delete okButton; - delete cancelButton; -} -void LoginDialog::init() -{ setLocationRelativeTo(getParent()); userField->requestFocus(); userField->setCaretPosition(userField->getText().length()); @@ -96,6 +82,17 @@ void LoginDialog::init() } } +LoginDialog::~LoginDialog() +{ + delete userLabel; + delete passLabel; + delete userField; + delete passField; + delete keepCheck; + delete okButton; + delete cancelButton; +} + void LoginDialog::action(const std::string& eventId) { if (eventId == "ok") { @@ -124,13 +121,9 @@ void LoginDialog::action(const std::string& eventId) } } -/** - * Display login dialog - */ + void login() { - LoginDialog *dialog = new LoginDialog(); - guiTop->add(dialog); - dialog->init(); + LoginDialog *dialog = new LoginDialog(guiTop); while (state == LOGIN) { clear_bitmap(buffer); @@ -145,9 +138,7 @@ void login() { delete dialog; } -/** - * Attempt to login to login server - */ + void server_login(const std::string& user, const std::string& pass) { strncpy(username, user.c_str(), LEN_USERNAME); strncpy(password, pass.c_str(), LEN_PASSWORD); diff --git a/src/gui/login.h b/src/gui/login.h index 725e578c..46c12d08 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -43,14 +43,9 @@ */ class LoginDialog : public Window, public gcn::ActionListener { public: - LoginDialog(); + LoginDialog(gcn::Container *parent); ~LoginDialog(); - /** - * Initializes the dialog. Should be called after adding it to the GUI. - */ - void init(); - /** * Called when receiving actions from the widgets. */ @@ -66,7 +61,14 @@ class LoginDialog : public Window, public gcn::ActionListener { gcn::Button *cancelButton; }; +/** + * Display login dialog + */ void login(); + +/** + * Attempt to login to login server + */ void server_login(const std::string& user, const std::string& pass); #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index a75dd242..eb886538 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -23,7 +23,7 @@ #include "gui.h" #include -Window::Window(std::string text) : +Window::Window(gcn::Container *parent, std::string text) : caption(text), mousePX(0), mousePY(0), @@ -31,9 +31,9 @@ Window::Window(std::string text) : mouseDown(false), titlebarHeight(20) { - titlebarColor.r = 32; - titlebarColor.g = 32; - titlebarColor.b = 128; + titlebarColor.r = 203; + titlebarColor.g = 203; + titlebarColor.b = 203; setBaseColor(gcn::Color(255, 255, 255)); @@ -50,6 +50,9 @@ Window::Window(std::string text) : chrome->setOpaque(false); chrome->setY(titlebarHeight); gcn::Container::add(chrome); + + // Add this window to the parent container + parent->add(this); } Window::~Window() @@ -72,6 +75,10 @@ void Window::draw(gcn::Graphics* graphics) getDimension().height - titlebarHeight)); } + // Draw line around window + graphics->setColor(titlebarColor); + graphics->drawRectangle(gcn::Rectangle(0, titlebarHeight - 1, + getWidth(), getHeight() - titlebarHeight + 1)); // Skinned dialog render if (typeid(*graphics) == typeid(gcn::AllegroGraphics)) @@ -95,7 +102,7 @@ void Window::draw(gcn::Graphics* graphics) // Plain title bar graphics->setColor(titlebarColor); graphics->fillRectangle(gcn::Rectangle(0, 0, - getDimension().width, titlebarHeight)); + getWidth(), titlebarHeight)); } // Draw title @@ -173,7 +180,6 @@ void Window::mouseRelease(int mx, int my, int button) mouseDown = false; } -//window move void Window::mouseMotion(int mx, int my) { if (mouseDown) @@ -186,17 +192,17 @@ void Window::mouseMotion(int mx, int my) x = x - (mousePX - mx); y = y - (mousePY - my); - //keep guichan window inside window + // Keep guichan window inside window if (x < 0) x = 0; if (y < 0) y = 0; if (x + winWidth > 799) x = 799 - winWidth; - if (y + winWidth > 599) + if (y + winHeight > 599) y = 599 - winHeight; - //snap window to edges + // Snap window to edges if (x < snapSize) x = 0; if (y < snapSize) diff --git a/src/gui/window.h b/src/gui/window.h index a51a150c..3fa3f58f 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -49,7 +49,7 @@ class Window : public gcn::Container, public gcn::MouseListener BITMAP *dRight; /**< Right side of title bar */ public: - Window(std::string text = "Window"); + Window(gcn::Container *parent, std::string text = "Window"); ~Window(); /** -- cgit v1.2.3-70-g09d2