第八课:SDL的简单封装——实现一个图片旋转

SDL2本身并没有对Window进行封装,这样的好处可以给使用者更大的灵活性,但是我们在写程序的时候,基本上都是面向对象的,所以做这种封装是很有必要的,一下是原作者对其进行的一个封装。

window07.h

/*
    SDL Window的一个封装
*/
class Window07 {
public:
    /*
        初始化SDL,并且设置标题
	*/
	static void Init(std::string title = "Window");
	///Quit SDL and destroy the window and renderer
	static void Quit();
    /**
        绘制,可以进行角度控制。
    */
    static void Draw(SDL_Texture *tex, SDL_Rect &dstRect, SDL_Rect *clip = NULL,
                     float angle = 0.0, int xPivot = 0, int yPivot = 0,
                     SDL_RendererFlip flip = SDL_FLIP_NONE);
    /**
        图片文件创建一个SDL_Texture
     */
    static SDL_Texture* LoadImage(const std::string &file);
    /**
        TTF文件创建一个SDL_Texture
    */
    static SDL_Texture* RenderText(const std::string &message, const std::string &fontFile, SDL_Color color, int fontSize);
    ///Clear the renderer
    static void Clear();
    ///更新Render
    static void Present();
    ///获取Render大小
    static SDL_Rect Box();

private:
    //unique_ptr是C++中智能指针,定义了一个window,一个SDL_Renderer
    static std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> mWindow;
    static std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer*)> mRenderer;
    static SDL_Rect mBox;
};

window07.cpp

#include <string>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值