summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--file.list1
-rw-r--r--src/gui/char_server.cpp5
-rw-r--r--src/gui/gui.cpp21
-rw-r--r--src/gui/gui.h12
-rw-r--r--src/gui/login.cpp5
-rw-r--r--src/gui/mw_button.cpp96
-rw-r--r--src/gui/mw_button.h50
7 files changed, 183 insertions, 7 deletions
diff --git a/file.list b/file.list
index d3f1e749..1b8b012f 100644
--- a/file.list
+++ b/file.list
@@ -9,6 +9,7 @@ MODULES = src/sound/sound.cpp \
src/gui/setup.cpp \
src/gui/gui.cpp \
src/gui/login.cpp \
+ src/gui/mw_button.cpp \
src/gui/char_server.cpp \
src/gui/char_select.cpp \
src/gui/inventory.cpp \
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index caf02eed..bd02f51a 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -23,6 +23,7 @@
#include "char_server.h"
#include "../graphic/graphic.h"
+#include "mw_button.h"
char server[30];
int showServerList = 1;
@@ -64,8 +65,8 @@ void char_server() {
dialog = new gcn::Container();
serverList = new gcn::ListBox(serverListModel);
scrollArea = new gcn::ScrollArea(serverList);
- okButton = new gcn::Button("OK");
- cancelButton = new gcn::Button("Cancel");
+ okButton = new MWButton("OK");
+ cancelButton = new MWButton("Cancel");
dialog->setDimension(gcn::Rectangle(300, 200, 200, 100));
scrollArea->setDimension(gcn::Rectangle(4, 4, 192, 55));
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 6b574b45..2a3631c2 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -404,7 +404,6 @@ void loadDialogSkin() {
}
void draw_skinned_rect(BITMAP*dst, LexSkinnedRect *skin, int x, int y,int w, int h) {
-
BITMAP **grid = skin->grid;
int w0 = grid[0]->w;
@@ -509,7 +508,25 @@ void gui_shutdown(void) {
}
}
-/** Draw text for gui widgets */
+/*
+ * Find out the screen area of a Guichan widget
+ */
+gcn::Rectangle getScreenDimension(gcn::Widget *widget) {
+ gcn::Rectangle rect = gcn::Rectangle(widget->getDimension());
+ gcn::BasicContainer *parent = widget->getParent();
+
+ while (parent != NULL) {
+ rect.x += parent->getX();
+ rect.y += parent->getY();
+ parent = parent->getParent();
+ }
+
+ return rect;
+}
+
+/*
+ * Draw text for gui widgets
+ */
int gui_text(BITMAP *bmp, AL_CONST char *s, int x, int y, int color, int centre) {
char tmp[1024];
int hline_pos = -1;
diff --git a/src/gui/gui.h b/src/gui/gui.h
index af83ccac..b6b134e1 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -105,8 +105,9 @@ extern ALFONT_FONT *gui_font;
extern gcn::Container* guiTop; // The top container
extern gcn::AllegroGraphics* guiGraphics; // Graphics driver
+extern gcn::ImageFont* guiFont; // The gui font
-/* Definition of the callback function prototypes */
+// Definition of the callback function prototypes
typedef int (*gui_buttonCallback)(int id);
typedef char *(*getfuncptr)(int, int *);
@@ -116,6 +117,14 @@ int gui_update(DIALOG_PLAYER *player);
int gui_load_skin(const char* skinname);
void gui_shutdown(void);
+// Helper procedures used for GUI drawing
+gcn::Rectangle getScreenDimension(gcn::Widget *widget);
+void draw_skinned_rect(BITMAP*dst, LexSkinnedRect *skin,
+ int x, int y, int w, int h);
+int gui_text(BITMAP *bmp, AL_CONST char *s,
+ int x, int y, int color, int centre);
+
+// Old Allegro GUI procs
int tmw_button_proc(int msg, DIALOG *d, int c);
int tmw_slider_proc(int msg, DIALOG *d, int c);
int tmw_check_proc(int msg, DIALOG *d, int c);
@@ -134,4 +143,5 @@ int tmw_plus_proc(int msg, DIALOG *d, int c);
void ok(const char *title, const char *message);
unsigned int yes_no(const char *title, const char *message);
+
#endif
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 2f07090f..1b80ffc6 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -23,6 +23,7 @@
#include "login.h"
#include "gui.h"
+#include "mw_button.h"
#include "../graphic/graphic.h"
// Dialog parts
@@ -74,8 +75,8 @@ void login() {
userField = new gcn::TextField("player");
passField = new gcn::TextField();
keepCheck = new gcn::CheckBox("Keep", false);
- okButton = new gcn::Button("OK");
- cancelButton = new gcn::Button("Cancel");
+ okButton = new MWButton("OK");
+ cancelButton = new MWButton("Cancel");
dialog->setDimension(gcn::Rectangle(300, 250, 200, 80));
userLabel->setPosition(4, 14);
diff --git a/src/gui/mw_button.cpp b/src/gui/mw_button.cpp
new file mode 100644
index 00000000..da767dec
--- /dev/null
+++ b/src/gui/mw_button.cpp
@@ -0,0 +1,96 @@
+/*
+ * 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 "mw_button.h"
+
+MWButton::MWButton(const std::string& caption):
+ gcn::Button(caption)
+{
+ mouseDown = false;
+ keyDown = false;
+}
+
+void MWButton::draw(gcn::Graphics* graphics) {
+ gcn::Rectangle screenRect = getScreenDimension(this);
+ int mode;
+ int offset = 0;
+
+ if (false /*disabled*/) {
+ mode = 3;
+ }
+ else if (hasMouse() && mouseDown || keyDown) {
+ mode = 2;
+ offset = 1;
+ }
+ else if (hasMouse()) {
+ mode = 1;
+ }
+ else {
+ mode = 0;
+ }
+
+ draw_skinned_rect(gui_bitmap, &gui_skin.button.background[mode],
+ screenRect.x, screenRect.y,
+ screenRect.width, screenRect.height);
+
+ int rtm = alfont_text_mode(-1);
+ gui_text(gui_bitmap, getCaption().c_str(),
+ screenRect.x + 2 + offset,
+ screenRect.y + 4 + offset,
+ gui_skin.button.textcolor[mode], FALSE);
+ alfont_text_mode(rtm);
+}
+
+void MWButton::lostFocus() {
+ mouseDown = false;
+ keyDown = false;
+}
+
+void MWButton::mousePress(int x, int y, int button) {
+ if (button == gcn::MouseInput::LEFT && hasMouse()) {
+ mouseDown = true;
+ }
+}
+
+void MWButton::mouseRelease(int x, int y, int button) {
+ if (button == gcn::MouseInput::LEFT) {
+ mouseDown = false;
+ }
+}
+
+void MWButton::keyPress(const gcn::Key& key) {
+ if (key.getValue() == gcn::Key::ENTER ||
+ key.getValue() == gcn::Key::SPACE)
+ {
+ keyDown = true;
+ }
+ mouseDown = false;
+}
+
+void MWButton::keyRelease(const gcn::Key& key) {
+ if ((key.getValue() == gcn::Key::ENTER ||
+ key.getValue() == gcn::Key::SPACE) && keyDown)
+ {
+ keyDown = false;
+ generateAction();
+ }
+}
+
diff --git a/src/gui/mw_button.h b/src/gui/mw_button.h
new file mode 100644
index 00000000..1d63c2b3
--- /dev/null
+++ b/src/gui/mw_button.h
@@ -0,0 +1,50 @@
+/*
+ * 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 _TMW_WIDGETS_H
+#define _TMW_WIDGETS_H
+
+#include "gui.h"
+
+class MWButton : public gcn::Button {
+ public:
+ MWButton(const std::string& caption);
+
+ // Inherited from Widget
+
+ void draw(gcn::Graphics* graphics);
+ void lostFocus();
+
+ // Inherited from MouseListener
+
+ void mousePress(int x, int y, int button);
+ void mouseRelease(int x, int y, int button);
+
+ // Inherited from KeyListener
+
+ void keyPress(const gcn::Key& key);
+ void keyRelease(const gcn::Key& key);
+
+ private:
+ bool mouseDown, keyDown;
+};
+
+#endif