summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-01 00:07:47 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-03-01 00:07:47 +0000
commit17de81fb71b4f91d2e0897f802a36df5630f1eaa (patch)
treea8d6444c8f4da24918228eb7566204aa5dded4a9 /src
parente9a413d772c608f4ceba2953fabea643a02e0266 (diff)
downloadmana-17de81fb71b4f91d2e0897f802a36df5630f1eaa.tar.gz
mana-17de81fb71b4f91d2e0897f802a36df5630f1eaa.tar.bz2
mana-17de81fb71b4f91d2e0897f802a36df5630f1eaa.tar.xz
mana-17de81fb71b4f91d2e0897f802a36df5630f1eaa.zip
Changed around recent additions to Image class a bit and fixed OpenGL compile.
Diffstat (limited to 'src')
-rw-r--r--src/gui/chat.cpp36
-rw-r--r--src/gui/progressbar.cpp21
-rw-r--r--src/gui/setup.cpp11
-rw-r--r--src/resources/image.cpp42
-rw-r--r--src/resources/image.h40
-rw-r--r--src/resources/resourcemanager.cpp4
6 files changed, 85 insertions, 69 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 278f36c3..34b49571 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -31,10 +31,11 @@ ChatBox::ChatBox(const char *logfile, int item_num)
items = 0;
items_keep = item_num;
- chatBoxBackground = new Image();
- chatBoxBackground->create(200, 200);
- chatBoxBackground->fillWithColor(255, 255, 255);
- chatBoxBackground->setAlpha(0.7f);
+ chatBoxBackground = Image::create(200, 200);
+ if (chatBoxBackground) {
+ chatBoxBackground->fillWithColor(255, 255, 255);
+ chatBoxBackground->setAlpha(0.7f);
+ }
}
ChatBox::~ChatBox()
@@ -128,16 +129,25 @@ void ChatBox::draw(gcn::Graphics *graphics)
graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
getAbsolutePosition(x, y);
-
- if ( (chatBoxBackground->getWidth() != getWidth()) || (chatBoxBackground->getHeight() != getHeight()) )
- {
- chatBoxBackground->unload();
- chatBoxBackground->create(getWidth(), getHeight());
- chatBoxBackground->fillWithColor(255, 255, 255);
- chatBoxBackground->setAlpha(0.7f);
+
+ // Potentially recreate background with new size
+ if (chatBoxBackground) {
+ if ((chatBoxBackground->getWidth() != getWidth()) ||
+ (chatBoxBackground->getHeight() != getHeight()))
+ {
+ delete chatBoxBackground;
+ chatBoxBackground = Image::create(getWidth(), getHeight());
+ if (chatBoxBackground) {
+ chatBoxBackground->fillWithColor(255, 255, 255);
+ chatBoxBackground->setAlpha(0.7f);
+ }
+ }
+ }
+
+ // Draw background image
+ if (chatBoxBackground) {
+ chatBoxBackground->draw(screen, x, y);
}
-
- chatBoxBackground->draw(screen, x, y);
for (iter = chatlog.begin(); iter != chatlog.end(); iter++) {
line = *iter;
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp
index 5ef5e03f..178f7d30 100644
--- a/src/gui/progressbar.cpp
+++ b/src/gui/progressbar.cpp
@@ -63,17 +63,18 @@ ProgressBar::ProgressBar(float progress, int x, int y, int width, int height,
dBottomLeftBorder->setAlpha(1.0f);
dBottomRightBorder->setAlpha(1.0f);
- colorBar = new Image();
- colorBar->create(getWidth() - 8, getHeight() - 8);
- colorBar->fillWithColor(red, green, blue);
- colorBar->setAlpha(0.7f);
+ colorBar = Image::create(getWidth() - 8, getHeight() - 8);
+ if (colorBar) {
+ colorBar->fillWithColor(red, green, blue);
+ colorBar->setAlpha(0.7f);
+ }
}
ProgressBar::~ProgressBar()
{
- #ifndef USE_OPENGL
- //SDL_FreeSurface(ColorBar);
- #endif
+ if (colorBar) {
+ delete colorBar;
+ }
}
void ProgressBar::draw(gcn::Graphics *graphics)
@@ -102,8 +103,10 @@ void ProgressBar::draw(gcn::Graphics *graphics)
dRightBorder->drawPattern(screen, absx + getWidth() - 4, absy + 4,
4, getHeight() - 8);
- colorBar->draw(screen, 0, 0, absx + 4, absy + 4,
- (int)(progress * float(getWidth() - 4)), getHeight() - 8);
+ if (colorBar) {
+ colorBar->draw(screen, 0, 0, absx + 4, absy + 4,
+ (int)(progress * float(getWidth() - 4)), getHeight() - 8);
+ }
}
void ProgressBar::setProgress(float progress)
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index b43a469c..4f71e94d 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -50,12 +50,12 @@ ModeListModel::ModeListModel()
// Check if any modes available
if (modes == (SDL_Rect**)0) {
nmode = 0;
- puts("No modes");
+ log("No modes");
}
// Check if modes restricted
- if (modes == (SDL_Rect**) - 1) {
- puts("Modes restricted");
+ if (modes == (SDL_Rect**)-1) {
+ log("Modes unrestricted");
}
for (nmode = 0; modes[nmode]; ++nmode);
@@ -65,8 +65,9 @@ ModeListModel::ModeListModel()
for (i = 0; modes[i]; ++i) {
char *temp = (char*)malloc(20 * sizeof(char));
mode[i] = temp;
- if (sprintf(mode[i], "%d x %d", modes[i]->w, modes[i]->h) == -1)
- puts("Cannot allocate mode list");
+ if (sprintf(mode[i], "%d x %d", modes[i]->w, modes[i]->h) == -1) {
+ log("Cannot allocate mode list");
+ }
}
}
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index cefb9d88..314de573 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -44,11 +44,6 @@ Image::Image(GLuint image, int width, int height, int texWidth, int texHeight):
alpha = 1.0f;
}
-Image::Image():image(image)
-{
- alpha = 1.0f;
-}
-
Image::~Image()
{
unload();
@@ -225,6 +220,24 @@ Image* Image::load(const char* buffer, unsigned int bufferSize)
#endif
}
+Image *Image::create(int width, int height)
+{
+#ifndef USE_OPENGL
+ SDL_Surface *surf =
+ SDL_AllocSurface(SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
+
+ if (surf) {
+ return new Image(surf);
+ }
+ else {
+ return NULL;
+ }
+#else
+ return NULL;
+#endif
+}
+
+
void Image::unload()
{
// Free the image surface.
@@ -366,26 +379,19 @@ float Image::getAlpha()
return alpha;
}
-bool Image::create(int width, int height)
+void Image::fillWithColor(
+ unsigned char red, unsigned char green, unsigned blue)
{
- image = SDL_AllocSurface(SDL_SWSURFACE, width, height, 32, 0, 0, 0, 0);
- if ( image )
- return true;
- else
- return false;
-}
-
-void Image::fillWithColor(unsigned char red, unsigned char green, unsigned blue)
-{
- Uint32 boxColor = SDL_MapRGB(SDL_GetVideoSurface()->format, red, green, blue);
- if ( image )
- {
+#ifndef USE_OPENGL
+ if (image) {
+ Uint32 boxColor = SDL_MapRGB(image->format, red, green, blue);
SDL_Rect sourceRect;
sourceRect.x = sourceRect.y = 0;
sourceRect.w = image->w;
sourceRect.h = image->h;
SDL_FillRect(image, &sourceRect, boxColor);
}
+#endif
}
//============================================================================
diff --git a/src/resources/image.h b/src/resources/image.h
index 084bb211..f5869167 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -47,22 +47,6 @@ class Image : public Resource
{
public:
/**
- * Constructor.
- */
-#ifdef USE_OPENGL
- Image(GLuint image,
- int width, int height,
- int texWidth, int texHeight);
-#else
- Image(SDL_Surface *image);
-#endif
-
- /**
- * Two time intialization Contructor. For now : Only to be used with create.
- */
- Image();
-
- /**
* Destructor.
*/
virtual ~Image();
@@ -92,6 +76,11 @@ class Image : public Resource
static Image *load(const char* buffer, unsigned int bufferSize);
/**
+ * Creates a new empty image with given height and width.
+ */
+ static Image *create(int width, int height);
+
+ /**
* Frees the resources created by SDL.
*/
virtual void unload();
@@ -149,17 +138,24 @@ class Image : public Resource
float getAlpha();
/**
- * Creates a new empty image with given height and width.
- */
- bool create(int width, int height);
-
- /**
* Fills the image with given color.
*/
- void fillWithColor(unsigned char red, unsigned char green, unsigned blue);
+ void fillWithColor(
+ unsigned char red, unsigned char green, unsigned blue);
protected:
+ /**
+ * Constructor.
+ */
+#ifdef USE_OPENGL
+ Image(GLuint image,
+ int width, int height,
+ int texWidth, int texHeight);
+#else
+ Image(SDL_Surface *image);
+#endif
+
#ifdef USE_OPENGL
GLuint image;
int width, height;
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 13cbc4d6..e40aa723 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -201,7 +201,7 @@ void ResourceManager::searchAndAddZipFiles()
std::string filePath = std::string("data/") +
std::string(findFileInfo.name);
- std::cout << "Adding to PhysicsFS: " << findFileInfo.name << std::endl;
+ log("Adding to PhysicsFS: %s", findFileInfo.name);
// Add the zip file to our PhysicsFS search path
PHYSFS_addToSearchPath(filePath.c_str(), 1);
@@ -234,7 +234,7 @@ void ResourceManager::searchAndAddZipFiles()
std::string filePath = std::string(programPath) +
std::string("/") + std::string(direntry->d_name);
- std::cout << "Adding to PhysicsFS: " << filePath << std::endl;
+ log("Adding to PhysicsFS: %s", filePath.c_str());
// Add the zip file to our PhysicsFS search path
PHYSFS_addToSearchPath(filePath.c_str(), 1);