summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-16 19:26:59 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-07-16 19:26:59 +0000
commita6db4d8004da5ad985a5ff26c0c01976a5618449 (patch)
tree5ed3dea6a28222de87840a4d1966338098123993 /src/gui
parentf4aedad02e8994f89a4137d175dba2666a7005bc (diff)
downloadmana-client-a6db4d8004da5ad985a5ff26c0c01976a5618449.tar.gz
mana-client-a6db4d8004da5ad985a5ff26c0c01976a5618449.tar.bz2
mana-client-a6db4d8004da5ad985a5ff26c0c01976a5618449.tar.xz
mana-client-a6db4d8004da5ad985a5ff26c0c01976a5618449.zip
Updated changelog, got rid of remaining extern SDL_Surface *screen cases,
fixed double free and cleaned up a bit.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/popupmenu.cpp26
-rw-r--r--src/gui/popupmenu.h9
-rw-r--r--src/gui/setup.cpp11
-rw-r--r--src/gui/updatewindow.cpp50
-rw-r--r--src/gui/updatewindow.h16
-rw-r--r--src/gui/window.cpp16
6 files changed, 53 insertions, 75 deletions
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index ea8034d8..dbaa1e70 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -22,6 +22,7 @@
*/
#include "popupmenu.h"
+#include "gui.h"
#include "../graphics.h"
#include "../game.h"
#include "../engine.h"
@@ -29,9 +30,6 @@
#include "../resources/itemmanager.h"
#include <iostream>
-// TODO Remove this once setVisible doesn't need it anymore
-extern SDL_Surface *screen;
-
PopupMenu::PopupMenu():
Window()
{
@@ -58,20 +56,6 @@ PopupMenu::~PopupMenu()
delete floorItem;
}
-void PopupMenu::setVisible(bool visible)
-{
- if (visible == false)
- {
- if (hasFocus())
- {
- mFocusHandler->focusNone();
- }
- setPosition(screen->w, screen->h);
- }
-
- mVisible = visible;
-}
-
void PopupMenu::showPopup(int mx, int my)
{
being = findNode(mx, my);
@@ -108,7 +92,7 @@ void PopupMenu::showPopup(int mx, int my)
// If there is nothing of interest, don't display menu.
return;
}
-
+
//browserBox->addRow("@@look|Look To@@");
browserBox->addRow("##3---");
browserBox->addRow("@@cancel|Cancel@@");
@@ -116,9 +100,9 @@ void PopupMenu::showPopup(int mx, int my)
setContentSize(browserBox->getWidth() + 8, browserBox->getHeight() + 8);
mx = (mx - camera_x) * 32 + 25;
my = (my - camera_y) * 32 + 25;
- if (screen->w < (mx + getWidth() + 5))
+ if (guiGraphics->getWidth() < (mx + getWidth() + 5))
mx -= (getWidth() + 50);
- if (screen->h < (my + getHeight() + 5))
+ if (guiGraphics->getHeight() < (my + getHeight() + 5))
my -= (getHeight() + 50);
setPosition(mx, my);
setVisible(true);
@@ -149,7 +133,7 @@ void PopupMenu::handleLink(const std::string& link)
else if (link == "follow")
{
}*/
-
+
/*
// Add Buddy action
else if ((link == "buddy") && being && being->isPlayer())
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index bb68852b..cfafc739 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -48,11 +48,6 @@ class PopupMenu : public Window, public LinkHandler
~PopupMenu();
/**
- * Sets the visibility of popup
- */
- void setVisible(bool visible);
-
- /**
* Shows the related popup menu specifies by the mouse click coords.
*/
void showPopup(int mx, int my);
@@ -61,11 +56,11 @@ class PopupMenu : public Window, public LinkHandler
* Handles link action.
*/
void handleLink(const std::string& link);
-
+
private:
BrowserBox* browserBox;
int mX, mY;
-
+
Being* being;
FloorItem* floorItem;
};
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index eb9121bc..cda9ae31 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -22,6 +22,7 @@
*/
#include "setup.h"
+#include "gui.h"
#include "button.h"
#include "checkbox.h"
#include "scrollarea.h"
@@ -34,8 +35,6 @@
#define SETUP_WIDTH 240
-extern SDL_Surface *screen;
-
ModeListModel::ModeListModel()
{
SDL_Rect **modes;
@@ -236,14 +235,18 @@ void Setup::action(const std::string &eventId)
//displayFlags |= SDL_OPENGL;
//SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
}
-
- screen = SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags);
+
+ SDL_Surface *screen =
+ SDL_SetVideoMode(screenW, screenH, bitDepth, displayFlags);
+
if (screen == NULL) {
std::cerr << "Couldn't set " << screenW << "x" <<
screenH << "x" << bitDepth << " video mode: " <<
SDL_GetError() << std::endl;
exit(1);
}
+
+ guiGraphics->setScreen(screen);
}
// Sound settings
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 66839451..64f99dd0 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -43,15 +43,15 @@ std::string basePath = "";
bool memoryTransfer = true;
int downloadedBytes = 0;
char *memoryBuffer = NULL;
-int fileIndex = 0;
+unsigned int fileIndex = 0;
-UpdaterWindow::UpdaterWindow()
- : Window("Updating...")
+UpdaterWindow::UpdaterWindow():
+ Window("Updating...")
{
int h = 300;
int w = 320;
setContentSize(w, h);
-
+
browserBox = new BrowserBox();
browserBox->setOpaque(false);
scrollArea = new ScrollArea(browserBox);
@@ -69,13 +69,13 @@ UpdaterWindow::UpdaterWindow()
playButton->setEventId("play");
playButton->setEnabled(false);
playButton->addActionListener(this);
-
+
add(scrollArea);
add(label);
add(progressBar);
add(cancelButton);
add(playButton);
-
+
cancelButton->requestFocus();
setLocationRelativeTo(getParent());
}
@@ -105,11 +105,6 @@ void UpdaterWindow::enable()
playButton->requestFocus();
}
-void UpdaterWindow::draw(gcn::Graphics *graphics)
-{
- Window::draw(graphics);
-}
-
void UpdaterWindow::action(const std::string& eventId)
{
if (eventId == "cancel") {
@@ -141,7 +136,7 @@ void UpdaterWindow::loadNews()
// Reallocate and include terminating 0 character
fileContents = (char*)realloc(fileContents, contentsLength + 1);
fileContents[contentsLength] = '\0';
-
+
browserBox->clearRows();
// Tokenize and add each line separately
@@ -152,16 +147,16 @@ void UpdaterWindow::loadNews()
line = strtok(NULL, "\n");
}
- free(fileContents);
+ //free(fileContents);
scrollArea->setVerticalScrollAmount(0);
setVisible(true);
}
-void UpdaterWindow::setText(std::string row) {
+void UpdaterWindow::addRow(const std::string &row)
+{
browserBox->addRow(row);
- scrollArea->setVerticalScrollAmount(
- scrollArea->getVerticalMaxScroll());
+ scrollArea->setVerticalScrollAmount(scrollArea->getVerticalMaxScroll());
}
int updateProgress(void *ptr, double dt, double dn, double ut, double un)
@@ -259,7 +254,8 @@ void download()
}
}
-void checkFile(std::ifstream &in) {
+void checkFile(std::ifstream &in)
+{
// Check for XML tag (if it is XML tag it is error)
// WARNING: this way we can't use an XML file for resources listing
if (!in.eof())
@@ -284,13 +280,13 @@ void updateData()
updaterWindow = new UpdaterWindow();
state = UPDATE;
-
+
updateHost = config.getValue("updatehost", "themanaworld.org/files");
basePath = config.getValue("homeDir", ".");
-
+
// Try to download the updates list
download();
-
+
while (state == UPDATE)
{
// Handle SDL events
@@ -308,17 +304,17 @@ void updateData()
}
break;
}
-
+
guiInput->pushInput(event);
}
-
+
switch (downloadStatus) {
case UPDATE_ERROR:
SDL_WaitThread(thread, NULL);
- updaterWindow->setText("");
- updaterWindow->setText("##1 The update process is incomplete.");
- updaterWindow->setText("##1 It is strongly recommended that");
- updaterWindow->setText("##1 you try again later");
+ updaterWindow->addRow("");
+ updaterWindow->addRow("##1 The update process is incomplete.");
+ updaterWindow->addRow("##1 It is strongly recommended that");
+ updaterWindow->addRow("##1 you try again later");
downloadStatus = UPDATE_COMPLETE;
break;
case UPDATE_NEWS:
@@ -395,7 +391,7 @@ void updateData()
gui->draw();
guiGraphics->updateScreen();
}
-
+
free(memoryBuffer);
in.close();
// Remove downloaded files
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index f1d460a2..062dc191 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -77,25 +77,27 @@ class UpdaterWindow : public Window, public gcn::ActionListener
* Set's label above progress
*/
void setLabel(const std::string &);
-
+
/**
* Enables play button
*/
void enable();
-
+
/**
* Loads and display news
*/
void loadNews();
-
+
void action(const std::string& eventId);
- void draw(gcn::Graphics *);
-
- void setText(std:: string row);
-
+ /**
+ * Add a row to the message field.
+ */
+ void addRow(const std::string &row);
+
int updateState;
};
void updateData();
+
#endif
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index e6a55ea0..158e9272 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -22,13 +22,11 @@
*/
#include "window.h"
+#include "gui.h"
#include "../resources/resourcemanager.h"
#include "../log.h"
#include "../main.h"
-// TODO Check if we can get rid of this
-extern SDL_Surface *screen;
-
WindowContainer *Window::windowContainer = NULL;
int Window::instances = 0;
ImageRect Window::border;
@@ -302,26 +300,26 @@ void Window::mouseMotion(int x, int y)
newDim.y = 0;
}
- if (newDim.x + newDim.width > screen->w)
+ if (newDim.x + newDim.width > guiGraphics->getWidth())
{
if (mMouseResize)
{
- newDim.width = screen->w - newDim.x;
+ newDim.width = guiGraphics->getWidth() - newDim.x;
}
else
{
- newDim.x = screen->w - newDim.width;
+ newDim.x = guiGraphics->getWidth() - newDim.width;
}
}
- if (newDim.y + newDim.height > screen->h)
+ if (newDim.y + newDim.height > guiGraphics->getHeight())
{
if (mMouseResize)
{
- newDim.height = screen->h - newDim.y;
+ newDim.height = guiGraphics->getHeight() - newDim.y;
}
else
{
- newDim.y = screen->h - newDim.height;
+ newDim.y = guiGraphics->getHeight() - newDim.height;
}
}