summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui.cpp71
-rw-r--r--src/gui/gui.h2
-rw-r--r--src/gui/login.cpp90
-rw-r--r--src/gui/mw_button.cpp10
-rw-r--r--src/gui/mw_button.h4
-rw-r--r--src/gui/mw_checkbox.cpp65
-rw-r--r--src/gui/mw_checkbox.h36
7 files changed, 159 insertions, 119 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2a3631c2..22391550 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -509,22 +509,6 @@ void gui_shutdown(void) {
}
/*
- * 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) {
@@ -696,61 +680,6 @@ int tmw_slider_proc(int msg, DIALOG *d, int c) {
return ret;
}
-int tmw_check_proc(int msg, DIALOG *d, int c) {
- BITMAP *box = NULL;
- int x, y;
- int tx, ty, l;
- int rtm = 0;
- int col = 0;
- if (msg == MSG_DRAW) {
-// rectfill(gui_bitmap, d->x, d->y, d->x + d->w, d->y+d->h, d->bg);
- if (d->flags & D_SELECTED) {
- if (d->flags & D_DISABLED) {
- box = gui_skin.checkbox.disabled_checked;
- } else {
- box = gui_skin.checkbox.checked;
- }
- } else if (d->flags & D_DISABLED) {
- box = gui_skin.checkbox.disabled;
- } else {
- box = gui_skin.checkbox.normal;
- }
-
- if (d->flags & D_DISABLED) {
- col = gui_skin.checkbox.textcolor[1];
- } else {
- col = gui_skin.checkbox.textcolor[0];
- }
-
- if (d->dp != NULL) {
- l = gui_strlen((const char *)d->dp);
- } else {
- l = 0;
- }
-
- if (d->d1 != 0) {
- x = d->x;
- tx = x + box->w + box->w/2;
- } else {
- x = d->x + d->w - box->w;
- tx = x - box->w/2 - l;
- }
- y = d->y + (d->h - box->h)/ 2;
- ty = d->y + (d->h - alfont_text_height(gui_font)) / 2;
-
- masked_blit(box, gui_bitmap, 0, 0, x, y, box->w, box->h);
- if (d->dp != NULL) {
- rtm = alfont_text_mode(-1);
- gui_text(gui_bitmap, (const char *)d->dp, tx, ty, col, 0);
- alfont_text_mode(rtm);
- }
-
-
- } else {
- return d_check_proc(msg, d, c);
- }
- return D_O_K;
-}
int tmw_radio_proc(int msg, DIALOG *d, int c) {
BITMAP *box = NULL;
diff --git a/src/gui/gui.h b/src/gui/gui.h
index b6b134e1..99d302db 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -118,7 +118,6 @@ 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,
@@ -127,7 +126,6 @@ int gui_text(BITMAP *bmp, AL_CONST char *s,
// 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);
int tmw_radio_proc(int msg, DIALOG *d, int c);
int tmw_edit_proc(int msg, DIALOG *d, int c);
int tmw_password_proc(int msg, DIALOG *d, int c);
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 1b80ffc6..bae87745 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -24,6 +24,7 @@
#include "login.h"
#include "gui.h"
#include "mw_button.h"
+#include "mw_checkbox.h"
#include "../graphic/graphic.h"
// Dialog parts
@@ -74,7 +75,7 @@ void login() {
passLabel = new gcn::Label("Password:");
userField = new gcn::TextField("player");
passField = new gcn::TextField();
- keepCheck = new gcn::CheckBox("Keep", false);
+ keepCheck = new MWCheckBox("Keep", false);
okButton = new MWButton("OK");
cancelButton = new MWButton("Cancel");
@@ -111,7 +112,7 @@ void login() {
dialog->add(cancelButton);
guiTop->add(dialog);
-
+
if (get_config_int("login", "remember", 0)) {
if (get_config_string("login", "username", 0)) {
userField->setText(get_config_string("login", "username", ""));
@@ -149,14 +150,17 @@ void server_login(const std::string& user, const std::string& pass) {
int ret;
// Connect to login server
- ret = open_session(get_config_string("server", "host", 0), get_config_int("server", "port", 0));
+ ret = open_session(
+ get_config_string("server", "host", 0),
+ get_config_int("server", "port", 0));
+
if (ret == SOCKET_ERROR) {
state = LOGIN;
ok("Error", "Unable to connect to login server");
warning("Unable to connect to login server");
return;
}
-
+
// Send login infos
WFIFOW(0) = net_w_value(0x0064);
@@ -167,41 +171,49 @@ void server_login(const std::string& user, const std::string& pass) {
WFIFOB(54) = 0;
WFIFOSET(55);
- while((in_size<23)||(out_size>0))flush();
+ while ((in_size < 23) || (out_size > 0)) {
+ flush();
+ }
log("Network", "Packet ID: %x", RFIFOW(0));
log("Network", "Packet length: %d", get_packet_length(RFIFOW(0)));
-
- if(RFIFOW(0)==0x0069) {
- while(in_size<RFIFOW(2))flush();
- n_server = (RFIFOW(2)-47)/32;
- server_info = (SERVER_INFO *)malloc(sizeof(SERVER_INFO)*n_server);
- account_ID = RFIFOL(8);
- session_ID1 = RFIFOL(4);
- session_ID2 = RFIFOL(12);
- sex = RFIFOB(46);
- for(int i=0;i<n_server;i++) {
- server_info[i].address = RFIFOL(47+32*i);
- memcpy(server_info[i].name, RFIFOP(47+32*i+6), 20);
- server_info[i].online_users = RFIFOW(47+32*i+26);
- server_info[i].port = RFIFOW(47+32*i+4);
- state = CHAR_SERVER;
- }
- log("Network", "Server: %s (%s:%d)", server_info[0].name,
- iptostring(server_info[0].address),
- server_info[0].port);
- log("Network", "Users: %d", server_info[0].online_users);
- RFIFOSKIP(RFIFOW(2));
- } else if(RFIFOW(0)==0x006a) {
- switch(RFIFOB(2)) {
- case 0:
- ok("Error", "Unregistered ID");
- break;
- case 1:
- ok("Error", "Wrong password");
- break;
- }
- state = LOGIN;
- RFIFOSKIP(23);
- } else ok("Error", "Unknown error");
- // Todo: add other packets, also encrypted
+
+ if (RFIFOW(0) == 0x0069) {
+ while (in_size < RFIFOW(2)) {
+ flush();
+ }
+ n_server = (RFIFOW(2)-47)/32;
+ server_info = (SERVER_INFO*)malloc(sizeof(SERVER_INFO)*n_server);
+ account_ID = RFIFOL(8);
+ session_ID1 = RFIFOL(4);
+ session_ID2 = RFIFOL(12);
+ sex = RFIFOB(46);
+ for (int i = 0; i < n_server; i++) {
+ server_info[i].address = RFIFOL(47+32*i);
+ memcpy(server_info[i].name, RFIFOP(47+32*i+6), 20);
+ server_info[i].online_users = RFIFOW(47+32*i+26);
+ server_info[i].port = RFIFOW(47+32*i+4);
+ state = CHAR_SERVER;
+ }
+ log("Network", "Server: %s (%s:%d)", server_info[0].name,
+ iptostring(server_info[0].address),
+ server_info[0].port);
+ log("Network", "Users: %d", server_info[0].online_users);
+ RFIFOSKIP(RFIFOW(2));
+ }
+ else if (RFIFOW(0) == 0x006a) {
+ switch (RFIFOB(2)) {
+ case 0:
+ ok("Error", "Unregistered ID");
+ break;
+ case 1:
+ ok("Error", "Wrong password");
+ break;
+ }
+ state = LOGIN;
+ RFIFOSKIP(23);
+ }
+ else {
+ ok("Error", "Unknown error");
+ }
+ // Todo: add other packets, also encrypted
}
diff --git a/src/gui/mw_button.cpp b/src/gui/mw_button.cpp
index da767dec..f7a01176 100644
--- a/src/gui/mw_button.cpp
+++ b/src/gui/mw_button.cpp
@@ -29,10 +29,12 @@ MWButton::MWButton(const std::string& caption):
}
void MWButton::draw(gcn::Graphics* graphics) {
- gcn::Rectangle screenRect = getScreenDimension(this);
+ int x, y;
int mode;
int offset = 0;
+ getAbsolutePosition(x, y);
+
if (false /*disabled*/) {
mode = 3;
}
@@ -48,13 +50,11 @@ void MWButton::draw(gcn::Graphics* graphics) {
}
draw_skinned_rect(gui_bitmap, &gui_skin.button.background[mode],
- screenRect.x, screenRect.y,
- screenRect.width, screenRect.height);
+ x, y, getWidth(), getHeight());
int rtm = alfont_text_mode(-1);
gui_text(gui_bitmap, getCaption().c_str(),
- screenRect.x + 2 + offset,
- screenRect.y + 4 + offset,
+ x + 2 + offset, y + 4 + offset,
gui_skin.button.textcolor[mode], FALSE);
alfont_text_mode(rtm);
}
diff --git a/src/gui/mw_button.h b/src/gui/mw_button.h
index 1d63c2b3..31c7bd44 100644
--- a/src/gui/mw_button.h
+++ b/src/gui/mw_button.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _TMW_WIDGETS_H
-#define _TMW_WIDGETS_H
+#ifndef _TMW_BUTTON_H
+#define _TMW_BUTTON_H
#include "gui.h"
diff --git a/src/gui/mw_checkbox.cpp b/src/gui/mw_checkbox.cpp
new file mode 100644
index 00000000..a2b02e6e
--- /dev/null
+++ b/src/gui/mw_checkbox.cpp
@@ -0,0 +1,65 @@
+/*
+ * 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_checkbox.h"
+
+MWCheckBox::MWCheckBox(const std::string& caption, bool marked):
+ gcn::CheckBox(caption, marked)
+{
+}
+
+void MWCheckBox::draw(gcn::Graphics* graphics) {
+ BITMAP *box = NULL;
+ int x, y;
+ int tx, ty;
+ int col = 0;
+
+ getAbsolutePosition(x, y);
+
+ if (mMarked) {
+ if (false /*disabled*/) {
+ box = gui_skin.checkbox.disabled_checked;
+ } else {
+ box = gui_skin.checkbox.checked;
+ }
+ } else if (false /*disabled*/) {
+ box = gui_skin.checkbox.disabled;
+ } else {
+ box = gui_skin.checkbox.normal;
+ }
+
+ if (false /*disabled*/) {
+ col = gui_skin.checkbox.textcolor[1];
+ } else {
+ col = gui_skin.checkbox.textcolor[0];
+ }
+
+ x += 2;
+ y += 2;
+ tx = x + box->w + 2;
+ ty = y - 2;
+
+ masked_blit(box, gui_bitmap, 0, 0, x, y, box->w, box->h);
+
+ int rtm = alfont_text_mode(-1);
+ gui_text(gui_bitmap, getCaption().c_str(), tx, ty, col, 0);
+ alfont_text_mode(rtm);
+}
diff --git a/src/gui/mw_checkbox.h b/src/gui/mw_checkbox.h
new file mode 100644
index 00000000..427d943a
--- /dev/null
+++ b/src/gui/mw_checkbox.h
@@ -0,0 +1,36 @@
+/*
+ * 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_CHECKBOX_H
+#define _TMW_CHECKBOX_H
+
+#include "gui.h"
+
+class MWCheckBox : public gcn::CheckBox {
+ public:
+ MWCheckBox(const std::string& caption, bool marked = false);
+
+ // Inherited from Widget
+
+ void draw(gcn::Graphics* graphics);
+};
+
+#endif