summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-06 21:31:43 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-06 21:31:43 +0000
commitfef7a7fb89b529bb3695bbff14d964f4da49ab64 (patch)
treea5a3c3f43d81fa71d3437ad1ac3ab6385961b813
parent16d1701920597d0a9636e30d57ebf399395233d9 (diff)
downloadmana-fef7a7fb89b529bb3695bbff14d964f4da49ab64.tar.gz
mana-fef7a7fb89b529bb3695bbff14d964f4da49ab64.tar.bz2
mana-fef7a7fb89b529bb3695bbff14d964f4da49ab64.tar.xz
mana-fef7a7fb89b529bb3695bbff14d964f4da49ab64.zip
Moved some GUI code into a class.
-rwxr-xr-x.cvsignore3
-rw-r--r--src/being.cpp6
-rw-r--r--src/graphic/graphic.cpp22
-rw-r--r--src/gui/char_select.cpp4
-rw-r--r--src/gui/char_server.cpp2
-rw-r--r--src/gui/gui.cpp164
-rw-r--r--src/gui/gui.h35
-rw-r--r--src/gui/login.cpp2
-rw-r--r--src/main.cpp2
9 files changed, 135 insertions, 105 deletions
diff --git a/.cvsignore b/.cvsignore
index 016843da..251fd14c 100755
--- a/.cvsignore
+++ b/.cvsignore
@@ -1,3 +1,4 @@
The_Mana_World_private.h
The_Mana_World_private.rc
-Makefile.win \ No newline at end of file
+Makefile.win
+tmw
diff --git a/src/being.cpp b/src/being.cpp
index 66d7cea0..41fa46fe 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -164,7 +164,7 @@ Being::Being() {
}
Being::~Being() {
- if(path) {
+ if (path) {
PATH_NODE *temp = path;
PATH_NODE *next;
while (temp) {
@@ -174,7 +174,7 @@ Being::~Being() {
}
path = NULL;
}
- if(speech) {
+ if (speech) {
free(speech);
}
-} \ No newline at end of file
+}
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index aa2d3407..3b9e1e1e 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -194,21 +194,21 @@ GraphicEngine::GraphicEngine() {
// Initialize the gui bitmap to the page that will be drawn first
gui_bitmap = this->buffer;
-
- BITMAP *npcbmp = load_bitmap("data/graphic/npcset.bmp", NULL);
- if (!npcbmp) error("Unable to load npcset.bmp");
- npcset = new Spriteset(npcbmp, 50, 80, 0, 0);
+ // Load the sprite sets
+ BITMAP *npcbmp = load_bitmap("data/graphic/npcset.bmp", NULL);
BITMAP *emotionbmp = load_bitmap("data/graphic/emotionset.bmp", NULL);
- if (!emotionbmp) error("Unable to load emotionset.bmp");
- emotionset = new Spriteset(emotionbmp, 19, 19, 0, 0);
-
BITMAP *tilesetbmp = load_bitmap("data/graphic/tileset.bmp", NULL);
- if (!tilesetbmp) error("Unable to load tileset.bmp");
- tileset = new Spriteset(tilesetbmp, 32, 32, 0, 0);
-
BITMAP *monsterbitmap = load_bitmap("data/graphic/monsterset.bmp", NULL);
+
+ if (!npcbmp) error("Unable to load npcset.bmp");
+ if (!emotionbmp) error("Unable to load emotionset.bmp");
+ if (!tilesetbmp) error("Unable to load tileset.bmp");
if (!monsterbitmap) error("Unable to load monsterset.bmp");
+
+ npcset = new Spriteset(npcbmp, 50, 80, 0, 0);
+ emotionset = new Spriteset(emotionbmp, 19, 19, 0, 0);
+ tileset = new Spriteset(tilesetbmp, 32, 32, 0, 0);
monsterset = new Spriteset(monsterbitmap, 60, 60, 30, 40);
}
@@ -486,7 +486,7 @@ void GraphicEngine::refresh() {
// Update GUI
guiGraphics->setTarget(buffer);
- gui_update(NULL);
+ gui->update();
textprintf_ex(buffer, font, 0, 0, makecol(255, 255, 255), -1,
"[%i fps] %i,%i", fps,
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 0bc49084..537a33ad 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -228,7 +228,7 @@ void charSelect()
// Draw background
blit(login_wallpaper, buffer, 0, 0, 0, 0, 800, 600);
- gui_update(NULL);
+ gui->update();
// Draw character
const int pX = 8, pY = 16;
@@ -315,7 +315,7 @@ void charCreate()
// Draw background
blit(login_wallpaper, buffer, 0, 0, 0, 0, 800, 600);
- gui_update(NULL);
+ gui->update();
// Draw character
const int pX = 96, pY = 40;
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index ea28d849..4543a829 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -117,7 +117,7 @@ void char_server() {
showServerList = 1;
while (showServerList) {
blit(login_wallpaper, buffer, 0, 0, 0, 0, 800, 600);
- gui_update(NULL);
+ gui->update();
blit(buffer, screen, 0, 0, 0, 0, 800, 600);
}
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 52b4bc85..da8c3651 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -48,72 +48,74 @@ static BITMAP *gui__repository[GUI_BMP_COUNT];
/* The currently active skin */
LexSkin gui_skin;
BITMAP *gui_bitmap;
-bool drag;
DATAFILE *gui_gfx;
// Guichan Allegro stuff
-gcn::AllegroInput* guiInput; // Input driver
gcn::AllegroGraphics* guiGraphics; // Graphics driver
-gcn::AllegroImageLoader* imageLoader; // For loading images
// Guichan stuff
-gcn::Gui* gui; // A Gui object - binds it all together
+Gui* gui;
gcn::Container* guiTop; // The top container
-gcn::ImageFont* guiFont; // A font
+Gui::Gui(BITMAP *screen)
+{
+ gui = new gcn::Gui();
-
-/** Initialize gui system */
-void init_gui(BITMAP *bitmap, const char *skin) {
- imageLoader = new gcn::AllegroImageLoader();
- gcn::Image::setImageLoader(imageLoader);
-
+ // Set graphics
guiGraphics = new gcn::AllegroGraphics();
- guiGraphics->setTarget(bitmap);
+ guiGraphics->setTarget(screen);
+ gui->setGraphics(guiGraphics);
+ // Set input
guiInput = new AllegroInput();
+ gui->setInput(guiInput);
+
+ // Set image loader
+ imageLoader = new gcn::AllegroImageLoader();
+ gcn::Image::setImageLoader(imageLoader);
+ // Initialize top GUI widget
guiTop = new gcn::Container();
guiTop->setDimension(gcn::Rectangle(0, 0, SCREEN_W, SCREEN_H));
guiTop->setOpaque(false);
-
- gui = new gcn::Gui();
- gui->setGraphics(guiGraphics);
- gui->setInput(guiInput);
gui->setTop(guiTop);
+
+ // Set global font
guiFont = new gcn::ImageFont("./data/graphic/fixedfont.bmp",
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:@"
"!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`"
);
gcn::Widget::setGlobalFont(guiFont);
-
-
- gui_bitmap = bitmap;
- gui_load_skin(skin);
- drag = false;
- show_mouse(NULL);
}
-int gui_update(DIALOG_PLAYER *player) {
- int ret = 0;
+Gui::~Gui()
+{
+ delete guiFont;
+ delete guiTop;
+ delete imageLoader;
+ delete guiInput;
+ delete guiGraphics;
+ delete gui;
+}
- if (player) {
- // Update Allegro dialog (to be replaced)
- dialog_message(player->dialog, MSG_DRAW, 0, 0);
- ret = update_dialog(player);
- }
- else {
- // Update new GUI system using Guichan
- gui->logic();
- gui->draw();
- }
+void Gui::update()
+{
+ gui->logic();
+ gui->draw();
// Draw the mouse
draw_sprite(gui_bitmap, mouse_sprite, mouse_x, mouse_y);
+}
- return ret;
+
+void init_gui(BITMAP *bitmap, const char *skin) {
+ gui = new Gui(bitmap);
+
+ gui_bitmap = bitmap;
+ gui_load_skin(skin);
+ show_mouse(NULL);
}
@@ -134,17 +136,17 @@ void loadButtonSkin() {
gridy[a] = atoi(tokens[a]);
}
- tokens = get_config_argv("button", "textcol_norm", &tokenCount);
+ tokens = get_config_argv("button", "textcol_norm", &tokenCount);
gui_skin.button.textcolor[0] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("button", "textcol_hilite", &tokenCount);
+ tokens = get_config_argv("button", "textcol_hilite", &tokenCount);
gui_skin.button.textcolor[1] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("button", "textcol_pressed", &tokenCount);
+ tokens = get_config_argv("button", "textcol_pressed", &tokenCount);
gui_skin.button.textcolor[2] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("button", "textcol_disabled", &tokenCount);
+ tokens = get_config_argv("button", "textcol_disabled", &tokenCount);
gui_skin.button.textcolor[3] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
gui__repository[GUI_BMP_OFS_BUTTON + 0] = (BITMAP *)gui_gfx[0].dat;
- gui__repository[GUI_BMP_OFS_BUTTON + 1] = (BITMAP *)gui_gfx[2].dat;
+ gui__repository[GUI_BMP_OFS_BUTTON + 1] = (BITMAP *)gui_gfx[2].dat;
gui__repository[GUI_BMP_OFS_BUTTON + 2] = (BITMAP *)gui_gfx[3].dat;
gui__repository[GUI_BMP_OFS_BUTTON + 3] = (BITMAP *)gui_gfx[1].dat;
@@ -153,10 +155,10 @@ void loadButtonSkin() {
for (y = 0; y < 3; y++) {
for (x = 0; x < 3; x++) {
gui_skin.button.background[mode].grid[a] = create_sub_bitmap(
- gui__repository[GUI_BMP_OFS_BUTTON + mode],
- gridx[x] , gridy[y],
- gridx[x+1]-gridx[x]+1, gridy[y+1]-gridy[y]+1
- );
+ gui__repository[GUI_BMP_OFS_BUTTON + mode],
+ gridx[x], gridy[y],
+ gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y]+1
+ );
a++;
}
}
@@ -168,8 +170,8 @@ void loadSliderSkin() {
char **tokens;
int tokenCount;
- gui__repository[GUI_BMP_OFS_SLIDER] = (BITMAP *)gui_gfx[8].dat;
- if(!gui__repository[GUI_BMP_OFS_SLIDER])alert("","","","","",0,0);
+ gui__repository[GUI_BMP_OFS_SLIDER] = (BITMAP *)gui_gfx[8].dat;
+ if (!gui__repository[GUI_BMP_OFS_SLIDER])alert("","","","","",0,0);
tokens = get_config_argv("slider", "slider_h", &tokenCount);
x = atoi(tokens[0]); y = atoi(tokens[1]);
@@ -178,8 +180,8 @@ void loadSliderSkin() {
tokens = get_config_argv("slider", "slider_h_ofs", &tokenCount);
o1 = atoi(tokens[0]); o2 = atoi(tokens[1]);
- gui_skin.slider.hSlider[0] = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], x , y, o1-x , h);
- gui_skin.slider.hSlider[1] = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], o1, y, o2-o1 , h);
+ gui_skin.slider.hSlider[0] = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], x , y, o1-x, h);
+ gui_skin.slider.hSlider[1] = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], o1, y, o2-o1, h);
gui_skin.slider.hSlider[2] = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], o2, y, w-(o2-x), h);
tokens = get_config_argv("slider", "slider_v", &tokenCount);
@@ -196,20 +198,20 @@ void loadSliderSkin() {
tokens = get_config_argv("slider", "handle_v", &tokenCount);
x = atoi(tokens[0]); y = atoi(tokens[1]);
w = atoi(tokens[2]); h = atoi(tokens[3]);
- gui_skin.slider.vGrip = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], x, y, w, h);
+ gui_skin.slider.vGrip = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], x, y, w, h);
tokens = get_config_argv("slider", "handle_h", &tokenCount);
x = atoi(tokens[0]); y = atoi(tokens[1]);
w = atoi(tokens[2]); h = atoi(tokens[3]);
- gui_skin.slider.hGrip = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], x, y, w, h);
+ gui_skin.slider.hGrip = create_sub_bitmap(gui__repository[GUI_BMP_OFS_SLIDER], x, y, w, h);
}
void loadCheckboxSkin() {
- int x, y, w,h;
+ int x, y, w,h;
char **tokens;
- int tokenCount;
+ int tokenCount;
- gui__repository[GUI_BMP_OFS_CHECKBOX] = (BITMAP *)gui_gfx[4].dat;
+ gui__repository[GUI_BMP_OFS_CHECKBOX] = (BITMAP *)gui_gfx[4].dat;
tokens = get_config_argv("checkbox", "normal", &tokenCount);
@@ -232,9 +234,9 @@ void loadCheckboxSkin() {
w = atoi(tokens[2]); h = atoi(tokens[3]);
gui_skin.checkbox.disabled_checked = create_sub_bitmap(gui__repository[GUI_BMP_OFS_CHECKBOX], x , y, w, h);
- tokens = get_config_argv("button", "textcol_norm", &tokenCount);
+ tokens = get_config_argv("button", "textcol_norm", &tokenCount);
gui_skin.checkbox.textcolor[0] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("button", "textcol_disabled", &tokenCount);
+ tokens = get_config_argv("button", "textcol_disabled", &tokenCount);
gui_skin.checkbox.textcolor[1] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
}
@@ -255,21 +257,21 @@ void loadTextboxSkin() {
gridy[a] = atoi(tokens[a]);
}
- tokens = get_config_argv("textbox", "textcol_norm", &tokenCount);
+ tokens = get_config_argv("textbox", "textcol_norm", &tokenCount);
gui_skin.textbox.textcolor[0] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("textbox", "textcol_disabled", &tokenCount);
+ tokens = get_config_argv("textbox", "textcol_disabled", &tokenCount);
gui_skin.textbox.textcolor[1] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- gui__repository[GUI_BMP_OFS_TEXTBOX] = (BITMAP *)gui_gfx[9].dat;
+ gui__repository[GUI_BMP_OFS_TEXTBOX] = (BITMAP *)gui_gfx[9].dat;
a = 0;
for (y = 0; y < 3; y++) {
for (x = 0; x < 3; x++) {
gui_skin.textbox.bg.grid[a] = create_sub_bitmap(
- gui__repository[GUI_BMP_OFS_TEXTBOX],
- gridx[x] , gridy[y],
- gridx[x+1]-gridx[x]+1, gridy[y+1]-gridy[y]+1
- );
+ gui__repository[GUI_BMP_OFS_TEXTBOX],
+ gridx[x], gridy[y],
+ gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1
+ );
a++;
}
}
@@ -292,26 +294,26 @@ void loadListboxSkin() {
gridy[a] = atoi(tokens[a]);
}
- tokens = get_config_argv("listbox", "textcol_norm", &tokenCount);
+ tokens = get_config_argv("listbox", "textcol_norm", &tokenCount);
gui_skin.listbox.textcolor[0] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("listbox", "textcol_selected", &tokenCount);
+ tokens = get_config_argv("listbox", "textcol_selected", &tokenCount);
gui_skin.listbox.textcolor[1] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("listbox", "textbg_selected", &tokenCount);
+ tokens = get_config_argv("listbox", "textbg_selected", &tokenCount);
gui_skin.listbox.textcolor[2] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- tokens = get_config_argv("listbox", "textcol_disabled", &tokenCount);
+ tokens = get_config_argv("listbox", "textcol_disabled", &tokenCount);
gui_skin.listbox.textcolor[3] = makecol(atoi(tokens[0]),atoi(tokens[1]),atoi(tokens[2]));
- gui__repository[GUI_BMP_OFS_LISTBOX + 0] = (BITMAP*)gui_gfx[6].dat;
- gui__repository[GUI_BMP_OFS_LISTBOX + 1] = (BITMAP*)gui_gfx[10].dat;
+ gui__repository[GUI_BMP_OFS_LISTBOX + 0] = (BITMAP*)gui_gfx[6].dat;
+ gui__repository[GUI_BMP_OFS_LISTBOX + 1] = (BITMAP*)gui_gfx[10].dat;
a = 0;
for (y = 0; y < 3; y++) {
for (x = 0; x < 3; x++) {
gui_skin.listbox.bg.grid[a] = create_sub_bitmap(
- gui__repository[GUI_BMP_OFS_LISTBOX],
- gridx[x] , gridy[y],
- gridx[x+1]-gridx[x]+1, gridy[y+1]-gridy[y]+1
- );
+ gui__repository[GUI_BMP_OFS_LISTBOX],
+ gridx[x], gridy[y],
+ gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1
+ );
a++;
}
}
@@ -328,10 +330,10 @@ void loadListboxSkin() {
for (y = 0; y < 3; y++) {
for (x = 0; x < 3; x++) {
gui_skin.listbox.vscroll.grid[a] = create_sub_bitmap(
- gui__repository[GUI_BMP_OFS_LISTBOX+1],
- gridx[x] , gridy[y],
- gridx[x+1]-gridx[x]+1, gridy[y+1]-gridy[y]+1
- );
+ gui__repository[GUI_BMP_OFS_LISTBOX+1],
+ gridx[x], gridy[y],
+ gridx[x + 1] - gridx[x] + 1, gridy[y + 1] - gridy[y] + 1
+ );
a++;
}
}
@@ -390,7 +392,7 @@ void loadDialogSkin() {
gridy[a] = atoi(tokens[a]);
}
- gui__repository[GUI_BMP_OFS_DIALOG] = (BITMAP *)gui_gfx[5].dat;
+ gui__repository[GUI_BMP_OFS_DIALOG] = (BITMAP *)gui_gfx[5].dat;
a = 0;
for (y = 0; y < 3; y++) {
@@ -464,14 +466,8 @@ int gui_load_skin(const char* skinname) {
}
void gui_exit() {
- delete guiFont;
- delete guiTop;
delete gui;
- delete guiInput;
- delete guiGraphics;
- delete imageLoader;
-
gui_shutdown();
}
@@ -637,7 +633,7 @@ int tmw_dialog_proc(int msg, DIALOG *d, int c) {
d->x, d->y, d->w, d->h);
textprintf_centre_ex(gui_bitmap, font,
- d->x + d->w/2,
+ d->x + d->w / 2,
d->y + (gui_skin.dialog.bg.grid[1]->h - text_height(font)) / 2,
d->fg, -1, "%s", (char*)d->dp);
diff --git a/src/gui/gui.h b/src/gui/gui.h
index f1556898..ada04a55 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -37,6 +37,36 @@
* \defgroup GUI GUI related classes
*/
+/**
+ * Main GUI class.
+ *
+ * \ingroup GUI
+ */
+class Gui
+{
+ public:
+ /**
+ * Constructor.
+ */
+ Gui(BITMAP *screen);
+
+ /**
+ * Destructor.
+ */
+ virtual ~Gui();
+
+ /**
+ * Performs GUI logic and drawing.
+ */
+ void update();
+
+ private:
+ gcn::Gui* gui; /**< The GUI system */
+ gcn::Input* guiInput; /**< Input driver */
+ gcn::ImageLoader* imageLoader; /**< For loading images */
+ gcn::ImageFont* guiFont; /**< The global GUI font */
+};
+
typedef struct {
BITMAP *grid[9];
} LexSkinnedRect;
@@ -107,13 +137,14 @@ typedef struct {
extern LexSkin gui_skin;
extern BITMAP *gui_bitmap;
+extern Gui* gui;
extern gcn::Container* guiTop; // The top container
extern gcn::AllegroGraphics* guiGraphics; // Graphics driver
-extern gcn::ImageFont* guiFont; // The gui font
+/** Initialize gui system */
void init_gui(BITMAP *dest_bitmap, const char *skin);
+
void gui_exit();
-int gui_update(DIALOG_PLAYER *player);
int gui_load_skin(const char* skinname);
void gui_shutdown(void);
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 52325105..00797917 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -133,7 +133,7 @@ void login() {
while (state == LOGIN) {
blit(login_wallpaper, buffer, 0, 0, 0, 0, 800, 600);
- gui_update(NULL);
+ gui->update();
blit(buffer, screen, 0, 0, 0, 0, 800, 600);
if (key[KEY_ESC]) {
state = EXIT;
diff --git a/src/main.cpp b/src/main.cpp
index 3dc7862c..a955ea01 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -279,6 +279,7 @@ void init_engine() {
0, 0, playerbitmap->w, playerbitmap->h,
0, 0, playerbitmap2->w, playerbitmap2->h);
playerset = new Spriteset(playerbitmap2, 160, 120, 0, 0);
+ destroy_bitmap(playerbitmap);
BITMAP *hairbitmap = load_bitmap("data/graphic/hairset.bmp", NULL);
if (!hairbitmap) error("Couldn't load hairset.bmp");
@@ -288,6 +289,7 @@ void init_engine() {
0, 0, hairbitmap->w, hairbitmap->h,
0, 0, hairbitmap2->w, hairbitmap2->h);
hairset = new Spriteset(hairbitmap2, 40, 40, 0, 0);
+ destroy_bitmap(hairbitmap);
// TODO: Remove Allegro config file usage from GUI look
init_gui(buffer, "data/Skin/aqua.skin");