02_C++精灵库之aboutwindow.h头文件源代码(2026年1月15日版)

// aboutwindow.h
#ifndef ABOUTWINDOW_H
#define ABOUTWINDOW_H

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <string>

class AboutWindow {
public:
    AboutWindow();
    ~AboutWindow();
    
    // 初始化关于窗口
    bool initialize();
    
    // 显示关于窗口
    void show();
    
    // 隐藏关于窗口
    void hide();
    
    // 处理事件
    void handleEvent(SDL_Event* event); 
    
    // 渲染关于窗口
    void render();
    
    // 检查窗口是否可见
    bool isVisible() const { return m_visible; }
    
    // 设置图片路径
    void setLogoPath(const std::string& path) { m_logoPath = path; }
    void setQrCodePath(const std::string& path) { m_qrCodePath = path; }
    
    // 设置信息文本
    void setInfoText(const std::string& text) { m_infoText = text; }

private:
    // 创建纹理
    SDL_Texture* loadTexture(const std::string& path);
    
    // 字体渲染相关方法
    SDL_Texture* createTextTexture(const std::string& text, SDL_Color color, TTF_Font* font);
    void renderText(const std::string& text, SDL_Color color, TTF_Font* font, int x, int y, bool center = true);
    void renderMultilineText(const std::string& text, SDL_Color color, TTF_Font* font, int x, int y, int lineHeight);
    
    // 加载字体
    TTF_Font* loadFont(const std::string& path, int size);
    
    // 清理资源
    void cleanup();

    bool m_visible;
    SDL_Window* m_window;
    SDL_Renderer* m_renderer;
    
    // 纹理
    SDL_Texture* m_logoTexture;
    SDL_Texture* m_qrCodeTexture;
    
    // 字体
    TTF_Font* m_titleFont;
    TTF_Font* m_textFont;
    TTF_Font* m_smallFont;
    
    // 路径
    std::string m_logoPath;
    std::string m_qrCodePath;
    std::string m_infoText;
    std::string m_windir;
    
    // 窗口尺寸
    static const int WINDOW_WIDTH = 400;
    static const int WINDOW_HEIGHT = 600;
    
    // 颜色常量
    const SDL_Color BG_COLOR = {245, 245, 245, 255};
    const SDL_Color TEXT_COLOR = {50, 50, 50, 255};
    const SDL_Color TITLE_COLOR = {30, 30, 30, 255};
    const SDL_Color ACCENT_COLOR = {70, 130, 180, 255};
};

#endif // ABOUTWINDOW_H

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在C++分类目录。将固定链接加入收藏夹。

发表回复