Skip to main content
gamedev.net
🔒 Locked

Cannot rename function

Started by chophias Sep 7, 2011 at 8:02 PM 1 replies 950+ views
Original Post
chophias
chophias
Hello,

I'm using an class to load and draw images using SDL. There's one thing I dont understand. I cannot rename the LoadImage functions. If for instance i try to rename
"static SDL_Surface* LoadImage(const string& file)" int "static SDL_Surface* LoadImagefile(const string& file)" i get the folowing errors:

Graphics.cpp|9|error: no 'SDL_Surface* Graphics::LoadImagefile(const std::string&)' member function declared in class 'Graphics'|
Graphics.cpp|36|error: no 'SDL_Surface* Graphics::LoadImagefile(const std::string&, Color&)' member function declared in class 'Graphics'|

I just dont get it why i'm getting these errors, I just rename "LoadImage" to "LoadImagefile" in header and source file but when compiling i get these errors.
I'm sure there's a logical answer.



#ifndef GRAPHICS_H_INCLUDED
#define GRAPHICS_H_INCLUDED

#include "SDL.h"
#include "SDL_image.h"
#include <string>


using namespace std;

class Color;

class Graphics
{
public:
Graphics();

static SDL_Surface* LoadImage(const string& file);
static SDL_Surface* LoadImage(const string& file, Color& transparent);

static bool DrawImage(SDL_Surface* source, float x, float y);
static bool DrawImage(SDL_Surface* source, float x, float y, int sx, int sy, int w, int h); // Draws only part of the source image
static void DrawHorizontalLine(int x1, int x2, int y, int thickness, Color& color);
static void DrawVerticalLine(int y1, int y2, int x, int thickness, Color& color);

static bool SetTransparencyColor(SDL_Surface* source, Color& color);
static void SetTransparency(SDL_Surface* source, float alpha);
};

#endif // GRAPHICS_H_INCLUDED



#include "Graphics.h"
#include "Color.h"
#include "Screen.h"

Graphics::Graphics() {}

//============================================================================================================================

SDL_Surface* Graphics::LoadImage(const string& file)
{
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;

if((Surf_Temp = IMG_Load(file.c_str())) == NULL)
{
if(file.empty())
{
printf("Unable to load image: Empty string passed!\n");
}
else
{
printf("Unable to load image: %s\n", file.c_str());
}

return NULL;
}

Surf_Return = SDL_DisplayFormat(Surf_Temp);
SDL_FreeSurface(Surf_Temp);

return Surf_Return;
}

//============================================================================================================================

SDL_Surface* Graphics::LoadImage(const std::string& file, Color& transparent)
{
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;

if((Surf_Temp = IMG_Load(file.c_str())) == NULL)
{
if(file.empty())
{
printf("Unable to load image: Empty string passed!\n");
}
else
{
printf("Unable to load image: %s\n", file.c_str());
}

return NULL;
}

Surf_Return = SDL_DisplayFormat(Surf_Temp);
SDL_FreeSurface(Surf_Temp);
Graphics::SetTransparencyColor(Surf_Return, transparent);

return Surf_Return;
}

//============================================================================================================================

bool Graphics::DrawImage(SDL_Surface* source, float x, float y)
{
if(!source) {return false;}

bool locked = false;
SDL_Rect DestRect;

DestRect.x = (Sint16)x;
DestRect.y = (Sint16)y;

if(SDL_MUSTLOCK(source))
{
SDL_LockSurface(source);
locked = true;
}

SDL_BlitSurface(source, NULL, Screen::GetScreen().GetScreenSurface(), &DestRect);

if(locked)
{
SDL_UnlockSurface(source);
}

return true;
}

//============================================================================================================================

bool Graphics::DrawImage(SDL_Surface* source, float x, float y, int sx, int sy, int w, int h)
{
if(source == NULL) {return false;}

SDL_Rect DestRect;

DestRect.x = (Sint16)x;
DestRect.y = (Sint16)y;

SDL_Rect SourceRect;
SourceRect.x = sx;
SourceRect.y = sy;
SourceRect.w = w;
SourceRect.h = h;

SDL_BlitSurface(source, &SourceRect, Screen::GetScreen().GetScreenSurface(), &DestRect);

return true;
}

//============================================================================================================================

bool Graphics::SetTransparencyColor(SDL_Surface* source, Color& color)
{
if(source == NULL) {return false;}

SDL_SetColorKey(source, SDL_SRCCOLORKEY, SDL_MapRGB(source->format, color.GetR(), color.GetG(), color.GetB()));

return true;
}

//============================================================================================================================

void Graphics::SetTransparency(SDL_Surface* source, float alpha)
{
if(!source || (alpha < 0.f || alpha > 1.f))
return;

if(SDL_SetAlpha(source, SDL_SRCALPHA, (int)((1-alpha) * 255)) == -1) {return;}
}

//============================================================================================================================

void Graphics::DrawHorizontalLine(int x1, int x2, int y, int thickness, Color& color)
{
SDL_Rect DestRect;

DestRect.x = x1;
DestRect.y = y;
DestRect.h = thickness;
DestRect.w = x2 - x1;

SDL_FillRect(Screen::GetScreen().GetScreenSurface(), &DestRect, SDL_MapRGB(Screen::GetScreen().GetScreenSurface()->format, color.GetR(), color.GetG(), color.GetB()));
}

//=========================================================================================================================

void Graphics::DrawVerticalLine(int y1, int y2, int x, int thickness, Color& color)
{
SDL_Rect DestRect;

DestRect.x = x;
DestRect.y = y1;
DestRect.h = y2 - y1;
DestRect.w = thickness;

SDL_FillRect(Screen::GetScreen().GetScreenSurface(), &DestRect, SDL_MapRGB(Screen::GetScreen().GetScreenSurface()->format, color.GetR(), color.GetG(), color.GetB()));
}

//=========================================================================================================================

Nypyren
Nypyren
Possibilities in order of likelihood (high to low):

You may have accidentally capitalized the F in LoadImagefile (LoadImageFile) in the header.

You might have a copy of Graphics.h in a different folder that you're editing instead of the one being loaded by the compiler.

Your IDE may not be saving Graphics.h before starting the compile.

If there are precompiled headers enabled, they might not be set up correctly.

Your compiler might be buggy.
chophias
chophias

Possibilities in order of likelihood (high to low):

1. You may have accidentally capitalized the F in LoadImagefile (LoadImageFile) in the header.

2. You might have a copy of Graphics.h in a different folder that you're editing instead of the one being loaded by the compiler.

3. Your IDE may not be saving Graphics.h before starting the compile.

4. If there are precompiled headers enabled, they might not be set up correctly.

5. Your compiler might be buggy.


1. Checked
2. Checked
3. Checked
4. Not using precompiled headers
5. ok i'm checking this last possibility but i never had problems, using default Codeblocks setup mingw32

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.