diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-23 14:36:51 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-23 14:36:51 +0000 |
commit | 3a9ae4770fcfec80c660fd9351ecea8c3c9bc913 (patch) | |
tree | 2f084acc77ac30724641fda88989fbb003b352e0 /src | |
parent | db4fd250723ad6121059a71f1cac0e87eb91e695 (diff) | |
download | mana-3a9ae4770fcfec80c660fd9351ecea8c3c9bc913.tar.gz mana-3a9ae4770fcfec80c660fd9351ecea8c3c9bc913.tar.bz2 mana-3a9ae4770fcfec80c660fd9351ecea8c3c9bc913.tar.xz mana-3a9ae4770fcfec80c660fd9351ecea8c3c9bc913.zip |
Skinned our beautiful text field back!
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 11 | ||||
-rw-r--r-- | src/gui/button.h | 8 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 3 | ||||
-rw-r--r-- | src/gui/gui.cpp | 3 | ||||
-rw-r--r-- | src/gui/login.cpp | 5 | ||||
-rw-r--r-- | src/gui/progressbar.cpp | 2 | ||||
-rw-r--r-- | src/gui/progressbar.h | 14 | ||||
-rw-r--r-- | src/gui/textfield.cpp | 61 | ||||
-rw-r--r-- | src/gui/textfield.h | 51 | ||||
-rw-r--r-- | src/gui/window.h | 12 |
11 files changed, 157 insertions, 14 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 13b290ce..ffc5023a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,6 +16,7 @@ tmw_SOURCES = sound/sound.cpp \ gui/shop.cpp \ gui/skill.cpp \ gui/stats.cpp \ + gui/textfield.cpp \ gui/window.cpp \ net/network.cpp \ net/protocol.cpp \ diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index 7ce2e93f..7b59f89a 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -25,6 +25,7 @@ #include "2xsai.h" #include "../gui/gui.h" #include "../gui/stats.h" +#include "../gui/textfield.h" #define TILESET_W 480 #define TILESET_H 320 @@ -215,14 +216,16 @@ void init_graphic() { clear_bitmap(screen); chat_background = create_bitmap(592, 100); - clear_to_color(chat_background, makecol(0,0,0)); + clear_to_color(chat_background, makecol(0, 0, 0)); // Initialize gui // Create chat input field - chatInput = new gcn::TextField(); - chatInput->setPosition(0, SCREEN_H - chatInput->getHeight()); - chatInput->setWidth(592); + chatInput = new TextField(); + chatInput->setPosition( + chatInput->getBorderSize(), + SCREEN_H - chatInput->getHeight() - chatInput->getBorderSize() -1); + chatInput->setWidth(592 - 2 * chatInput->getBorderSize()); ChatListener *chatListener = new ChatListener(); chatInput->setEventId("chatinput"); diff --git a/src/gui/button.h b/src/gui/button.h index b7d48929..0c45b133 100644 --- a/src/gui/button.h +++ b/src/gui/button.h @@ -31,10 +31,14 @@ */ class Button : public gcn::Button { public: + /** + * Constructor, sets the caption of the button to the given string. + */ Button(const std::string& caption); - // Inherited from Widget - + /** + * Draws the button. + */ void draw(gcn::Graphics* graphics); }; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index c88839f0..9084c6e9 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -20,6 +20,7 @@ */ #include "char_select.h" +#include "textfield.h" #include "../graphic/graphic.h" #include "../graphic/2xsai.h" @@ -112,7 +113,7 @@ std::string curName; CharCreateDialog::CharCreateDialog(gcn::Container *parent) : Window(parent, "Create Character") { - nameField = new gcn::TextField(""); + nameField = new TextField(""); nameLabel = new gcn::Label("Name:"); nextHairColorButton = new Button(">"); prevHairColorButton = new Button("<"); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ced9758b..714f114f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -728,7 +728,6 @@ int tmw_radio_proc(int msg, DIALOG *d, int c) { } int tmw_edit_proc(int msg, DIALOG *d, int c) { -// BITMAP *box = NULL; int x; int tx, ty, l; int rtm = 0; @@ -769,7 +768,7 @@ int tmw_edit_proc(int msg, DIALOG *d, int c) { cr=gui_bitmap->w; cb=gui_bitmap->h; } - set_clip_rect(gui_bitmap, tx, ty, d->x+d->w-rb, ty + text_height(font)); // set_clip() is deprecated use set_clip_rect() instead + set_clip_rect(gui_bitmap, tx, ty, d->x+d->w-rb, ty + text_height(font)); hack = text[d->d2]; text[d->d2] = '\0'; l = text_length(font, text); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 628d50e5..4ba0fe67 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -25,6 +25,7 @@ #include "gui.h" #include "button.h" #include "checkbox.h" +#include "textfield.h" #include "../graphic/graphic.h" @@ -33,8 +34,8 @@ LoginDialog::LoginDialog(gcn::Container *parent): { userLabel = new gcn::Label("Name:"); passLabel = new gcn::Label("Password:"); - userField = new gcn::TextField("player"); - passField = new gcn::TextField(); + userField = new TextField("player"); + passField = new TextField(); keepCheck = new CheckBox("Keep", false); okButton = new Button("OK"); cancelButton = new Button("Cancel"); diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 28151de3..4b754b77 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -17,8 +17,6 @@ * You should have received a copy of the GNU General Public License * along with The Mana World; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * By ElvenProgrammer aka Eugenio Favalli (umperio@users.sourceforge.net) */ #include "progressbar.h" diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h index beab9b7f..d5bde55d 100644 --- a/src/gui/progressbar.h +++ b/src/gui/progressbar.h @@ -22,7 +22,6 @@ #ifndef __PROGRESSBAR_H__ #define __PROGRESSBAR_H__ -#include <iostream> #include <allegro.h> #include <guichan.hpp> @@ -33,11 +32,24 @@ */ class ProgressBar : public gcn::Widget { public: + /** + * Constructor, initializes the progress with the given value. + */ ProgressBar(float progress = 0.0f); + /** + * Draws the progress bar. + */ void draw(gcn::Graphics *graphics); + /** + * Sets the current progress. + */ void setProgress(float progress); + + /** + * Returns the current progress. + */ float getProgress(); private: diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp new file mode 100644 index 00000000..3b838126 --- /dev/null +++ b/src/gui/textfield.cpp @@ -0,0 +1,61 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "textfield.h" +#include "gui.h" + + +TextField::TextField(const std::string& text): + gcn::TextField(text) +{ + setBorderSize(2); +} + +void TextField::draw(gcn::Graphics *graphics) +{ + int x, y, w, h, col; + getAbsolutePosition(x, y); + w = getWidth(); + h = getHeight(); + + if (hasFocus()) { + drawCaret(graphics, + getFont()->getWidth(mText.substr(0, mCaretPosition)) - + mXScroll); + } + + graphics->setColor(getForegroundColor()); + graphics->setFont(getFont()); + graphics->drawText(mText, 1 - mXScroll, 1); +} + +void TextField::drawBorder(gcn::Graphics *graphics) +{ + int x, y, w, h, bs; + getAbsolutePosition(x, y); + bs = getBorderSize(); + w = getWidth() + bs * 2; + h = getHeight() + bs * 2; + x -= bs; + y -= bs; + + draw_skinned_rect(gui_bitmap, &gui_skin.textbox.bg, x, y, w, h); +} diff --git a/src/gui/textfield.h b/src/gui/textfield.h new file mode 100644 index 00000000..c401e416 --- /dev/null +++ b/src/gui/textfield.h @@ -0,0 +1,51 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __TEXTFIELD_H__ +#define __TEXTFIELD_H__ + +#include <allegro.h> +#include <guichan.hpp> + +/** + * A text field. + * + * \ingroup GUI + */ +class TextField : public gcn::TextField { + public: + /** + * Constructor, initializes the text field with the given string. + */ + TextField(const std::string& text = ""); + + /** + * Draws the text field. + */ + void draw(gcn::Graphics *graphics); + + /** + * Draws the background and border. + */ + void drawBorder(gcn::Graphics *graphics); +}; + +#endif diff --git a/src/gui/window.h b/src/gui/window.h index 92fe0313..c7fd6956 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -49,7 +49,19 @@ class Window : public gcn::Container, public gcn::MouseListener BITMAP *dRight; /**< Right side of title bar */ public: + /** + * Constructor. Initializes the title to the given text and hooks + * itself into the given parent. + * + * @param parent The parent container to which this window will add + * itself. + * @param text The initial window title, "Window" by default. + */ Window(gcn::Container *parent, const std::string& text = "Window"); + + /** + * Destructor. + */ ~Window(); /** |