diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-17 23:21:20 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-17 23:21:20 +0000 |
commit | 11e9c220d8b989d9ee9abb27c8d0acc41fe3d7f4 (patch) | |
tree | 304bebd799fcb1052f1b452e8f9da255cd718242 | |
parent | bc4c1e72374a44595e8b1ea0cd16e182139b2cb7 (diff) | |
download | mana-11e9c220d8b989d9ee9abb27c8d0acc41fe3d7f4.tar.gz mana-11e9c220d8b989d9ee9abb27c8d0acc41fe3d7f4.tar.bz2 mana-11e9c220d8b989d9ee9abb27c8d0acc41fe3d7f4.tar.xz mana-11e9c220d8b989d9ee9abb27c8d0acc41fe3d7f4.zip |
Made some fixes to the window widget and made server selection use it too.
WARNING: From now on we need Guichan 0.2.0, the 0.1.0 version will NOT work!
-rw-r--r-- | src/gui/button.cpp | 3 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 3 | ||||
-rw-r--r-- | src/gui/login.cpp | 9 | ||||
-rw-r--r-- | src/gui/window.cpp | 64 | ||||
-rw-r--r-- | src/gui/window.h | 59 |
5 files changed, 86 insertions, 52 deletions
diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 02a77984..030dd9de 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -26,6 +26,7 @@ Button::Button(const std::string& caption): { mouseDown = false; keyDown = false; + setBorderSize(0); } void Button::draw(gcn::Graphics* graphics) { @@ -35,6 +36,8 @@ void Button::draw(gcn::Graphics* graphics) { getAbsolutePosition(x, y); + //printf("draw - %d,%d\n", x, y); + if (false /*disabled*/) { mode = 3; } diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 0bd431a5..df88adc6 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -24,6 +24,7 @@ #include "char_server.h" #include "../graphic/graphic.h" #include "button.h" +#include "window.h" char server[30]; int showServerList = 1; @@ -62,7 +63,7 @@ void char_server() { gcn::ScrollArea *scrollArea; serverListModel = new ServerListModel(); - dialog = new gcn::Container(); + dialog = new Window("Select Server"); serverList = new gcn::ListBox(serverListModel); scrollArea = new gcn::ScrollArea(serverList); okButton = new Button("OK"); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 0a8c19a7..2250f59b 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -71,7 +71,7 @@ void LoginActionListener::action(const std::string& eventId) */ void login() { // Create dialog - dialog = new WindowContainer(); + dialog = new Window("Login"); userLabel = new gcn::Label("Name:"); passLabel = new gcn::Label("Password:"); userField = new gcn::TextField("player"); @@ -114,15 +114,16 @@ void login() { guiTop->add(dialog); + userField->requestFocus(); + userField->setCaretPosition(userField->getText().length()); + if (get_config_int("login", "remember", 0)) { if (get_config_string("login", "username", 0)) { userField->setText(get_config_string("login", "username", "")); + passField->requestFocus(); } } - userField->requestFocus(); - userField->setCaretPosition(userField->getText().length()); - while (state == LOGIN) { clear_bitmap(buffer); blit((BITMAP *)graphic[LOGIN_BMP].dat, buffer, 0, 0, 0, 0, 800, 600); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0e1ca828..507f9ffb 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -23,13 +23,13 @@ #include "gui.h" #include <guichan/allegro.hpp> -WindowContainer::WindowContainer(std::string text) : +Window::Window(std::string text) : caption(text), mousePX(0), mousePY(0), snapSize(8), mouseDown(false), - titlebarHeight(48) + titlebarHeight(24) { titlebarColor.r = 32; titlebarColor.g = 32; @@ -50,9 +50,14 @@ WindowContainer::WindowContainer(std::string text) : //register mouse listener addMouseListener(this); + + // Add chrome + chrome = new gcn::Container(); + chrome->setOpaque(false); + gcn::Container::add(chrome); } -WindowContainer::~WindowContainer() +Window::~Window() { //delete captionLabel; @@ -60,17 +65,23 @@ WindowContainer::~WindowContainer() release_bitmap(dLeft); release_bitmap(dMid); release_bitmap(dRight); + + delete chrome; } -void WindowContainer::draw(gcn::Graphics* graphics) +void Window::draw(gcn::Graphics* graphics) { + int x, y; + getAbsolutePosition(x, y); + //draw container background //Container::draw(graphics); if (mOpaque) { graphics->setColor(getBaseColor()); - graphics->fillRectangle(gcn::Rectangle(0, 24, - getDimension().width, getDimension().height)); + graphics->fillRectangle(gcn::Rectangle(0, titlebarHeight, + getDimension().width, + getDimension().height - titlebarHeight)); } @@ -103,33 +114,34 @@ void WindowContainer::draw(gcn::Graphics* graphics) getDimension().width, titlebarHeight)); } - drawChildren(graphics); } -//set dimension -void WindowContainer::setDimension(const gcn::Rectangle &dimension) +void Window::setDimension(const gcn::Rectangle &dimension) { - gcn::Widget::setDimension(gcn::Rectangle(dimension.x, dimension.y, - dimension.width, dimension.height + titlebarHeight)); + gcn::Container::setDimension(gcn::Rectangle( + dimension.x, + dimension.y - titlebarHeight, + dimension.width, + dimension.height + titlebarHeight)); + chrome->setDimension(gcn::Rectangle(0, titlebarHeight, + dimension.width, dimension.height)); } -//adding new widget -void WindowContainer::add(gcn::Widget *w) +void Window::add(gcn::Widget *w) { - w->setPosition(w->getDimension().x, w->getDimension().y + titlebarHeight); - gcn::Container::add(w); + chrome->add(w); } -void WindowContainer::add(Widget *w, int x, int y) + +void Window::add(Widget *w, int x, int y) { - w->setPosition(x, y + titlebarHeight); - gcn::Container::add(w); + chrome->add(w, x, y); } -void WindowContainer::mousePress(int mx, int my, int button) +void Window::mousePress(int mx, int my, int button) { - x = this->getDimension().x; - y = this->getDimension().y; + int x = this->getDimension().x; + int y = this->getDimension().y; mouseDown = true; @@ -137,20 +149,20 @@ void WindowContainer::mousePress(int mx, int my, int button) mousePY = my; } -void WindowContainer::mouseRelease(int mx, int my, int button) +void Window::mouseRelease(int mx, int my, int button) { mouseDown = false; } //window move -void WindowContainer::mouseMotion(int mx, int my) +void Window::mouseMotion(int mx, int my) { if (mouseDown) { int winWidth = this->getDimension().width; int winHeight = this->getDimension().height; - x = this->getDimension().x; - y = this->getDimension().y; + int x = this->getDimension().x; + int y = this->getDimension().y; x = x - (mousePX - mx); y = y - (mousePY - my); @@ -179,7 +191,7 @@ void WindowContainer::mouseMotion(int mx, int my) } } -void WindowContainer::mouseOut() +void Window::mouseOut() { mouseDown = false; } diff --git a/src/gui/window.h b/src/gui/window.h index 99ebfdec..492b679e 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -26,38 +26,55 @@ #include <allegro.h> #include <guichan.hpp> -class WindowContainer : public gcn::Container, public gcn::MouseListener +/** + * A window. This window can be dragged around and has a title bar. + * + * \ingroup GUI + */ +class Window : public gcn::Container, public gcn::MouseListener { private: - std::string caption; //title bar caption - gcn::Label* captionLabel; //TItle bar caption - int x, y; //x and y positions of the window - int z; //z position of window - int mousePX, mousePY; //Mouse down location relative to 0,0 of window - int snapSize; //Snap to window edge - bool mouseDown; //mouse button state - gcn::Color titlebarColor; //title bar color + gcn::Container *chrome; /**< Contained container */ + std::string caption; /**< Title bar caption */ + gcn::Label* captionLabel; /**< Title bar caption label */ + int z; /**< Z position of the window */ + int mousePX; /**< Mouse down location */ + int mousePY; /**< Mouse down location */ + int snapSize; /**< Snap distance to window edge */ + bool mouseDown; /**< Mouse button state */ + gcn::Color titlebarColor; /**< Title bar color */ + int titlebarHeight; /**< Height of title bar */ - BITMAP *dLeft, *dMid, *dRight; + BITMAP *dLeft; /**< Left side of title bar */ + BITMAP *dMid; /**< Middle of title bar */ + BITMAP *dRight; /**< Right side of title bar */ public: - int titlebarHeight; //height of title bar - - //constructor - WindowContainer(std::string text = "Window"); - ~WindowContainer(); + Window(std::string text = "Window"); + ~Window(); - //draw window + /** + * Draws the window. + */ void draw(gcn::Graphics* graphics); - //add to stop compiler complaining - void add(Widget *w); - //new add - void add(Widget *w, int x, int y); + /** + * Adds a widget to the window. + */ + void add(gcn::Widget *w); + /** + * Adds a widget to the window and also specifices its position. + */ + void add(gcn::Widget *w, int x, int y); + + /** + * Set the dimension of the window contents. + */ void setDimension(const gcn::Rectangle& dimension); - //Mouse handling + // Mouse handling + void mousePress(int mx, int my, int button); void mouseRelease(int mx, int my, int button); void mouseMotion(int mx, int my); |