📄 surfaceclass.h
字号:
//UVi Soft (2008)
//Long Fei (lf426), E-mail: zbln426@163.com
//FileName: SurfaceClass.h
#ifndef SURFACE_CLASS_H
#define SURFACE_CLASS_H
#include <iostream>
#include <string>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
class ScreenSurface
{
private:
static int screenNum;
int width;
int height;
int bpp;
Uint32 flags;
SDL_Surface* pScreen;
std::string windowName;
public:
ScreenSurface();
ScreenSurface(int w, int h, const std::string& window_name = "NULL", int b = 0, Uint32 f = 0);
~ScreenSurface();
SDL_Surface* point() const;
void flip() const;
void fillColor(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0) const;
};
class DisplaySurface
{
private:
std::string fileName;
SDL_Surface* pSurface;
SDL_Surface* pScreen;
//for TextSurafce
static int textNum;
TTF_Font* pFont;
public:
DisplaySurface(const std::string& file_name, const ScreenSurface& screen);
~DisplaySurface();
SDL_Surface* point() const;
void blit() const;
void blit(int at_x, int at_y) const;
void blit(int at_x, int at_y,
int from_x, int from_y, int w, int h,
int delta_x = 0, int delta_y = 0) const;
void colorKey(Uint8 r = 0, Uint8 g = 0xFF, Uint8 b = 0xFF, Uint32 flag = SDL_SRCCOLORKEY);
protected:
//for TextSurface
DisplaySurface(const std::string& msg_name, const std::string& message, const ScreenSurface& screen,
Uint8 r, Uint8 g, Uint8 b,
int ttf_size, const std::string& ttf_fileName);
int tellTextNum() const;
void reduceTextNum();
void deleteFontPoint();
};
class TextSurface: public DisplaySurface
{
public:
TextSurface(const std::string& msg_name, const std::string& message, const ScreenSurface& screen,
Uint8 r = 0xFF, Uint8 g = 0xFF, Uint8 b = 0xFF,
int ttf_size = 28, const std::string& ttf_fileName = "../Fonts/gkai00mp.ttf");
~TextSurface();
};
class ErrorInfo
{
private:
std::string info;
public:
ErrorInfo():info("Unknown ERROR!")
{}
ErrorInfo(const char* c_str)
{
info = std::string(c_str);
}
ErrorInfo(const std::string& str):info(str)
{}
void show() const
{
std::cerr << info << std::endl;
}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -