mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
feat: add background support for Label
This commit is contained in:
@@ -44,7 +44,7 @@ void UIRenderer::renderUI(const UIRenderData& uiRenderData) {
|
|||||||
|
|
||||||
void UIRenderer::renderButton(const ButtonData& buttonData) {
|
void UIRenderer::renderButton(const ButtonData& buttonData) {
|
||||||
//SDL_Log("render button\n");
|
//SDL_Log("render button\n");
|
||||||
renderButtonBackground(buttonData);
|
renderBackground<ButtonData>(buttonData);
|
||||||
|
|
||||||
renderButtonBorder(buttonData);
|
renderButtonBorder(buttonData);
|
||||||
renderText<ButtonData>(buttonData);
|
renderText<ButtonData>(buttonData);
|
||||||
@@ -52,12 +52,13 @@ void UIRenderer::renderButton(const ButtonData& buttonData) {
|
|||||||
|
|
||||||
void UIRenderer::renderLabel(const LabelData& labelData) {
|
void UIRenderer::renderLabel(const LabelData& labelData) {
|
||||||
//SDL_Log("start render label\n");
|
//SDL_Log("start render label\n");
|
||||||
|
renderBackground<LabelData>(labelData);
|
||||||
renderText<LabelData>(labelData);
|
renderText<LabelData>(labelData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
void UIRenderer::renderButtonBackground(const ButtonData& buttonData) {
|
void UIRenderer::renderBackground(const Type& data) {
|
||||||
// 设置绘制颜色
|
// 设置绘制颜色
|
||||||
if (!m_renderer) {
|
if (!m_renderer) {
|
||||||
SDL_Log("renderer is null\n");
|
SDL_Log("renderer is null\n");
|
||||||
@@ -65,9 +66,11 @@ void UIRenderer::renderButtonBackground(const ButtonData& buttonData) {
|
|||||||
// SDL_Log("renderButtonBackground called for rect (%d,%d,%d,%d)",
|
// SDL_Log("renderButtonBackground called for rect (%d,%d,%d,%d)",
|
||||||
// buttonData.rect.x, buttonData.rect.y, buttonData.rect.w, buttonData.rect.h);
|
// buttonData.rect.x, buttonData.rect.y, buttonData.rect.w, buttonData.rect.h);
|
||||||
//SDL_Log("start render background\n");
|
//SDL_Log("start render background\n");
|
||||||
auto m_backgroundColor = buttonData.backgroundColor;
|
auto m_backgroundColor = data.backgroundColor;
|
||||||
auto m_rect = buttonData.rect;
|
auto m_rect = data.rect;
|
||||||
|
if (data.backgroundColor.a == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
SDL_SetRenderDrawColor(m_renderer, m_backgroundColor.r, m_backgroundColor.g, m_backgroundColor.b, m_backgroundColor.a);
|
SDL_SetRenderDrawColor(m_renderer, m_backgroundColor.r, m_backgroundColor.g, m_backgroundColor.b, m_backgroundColor.a);
|
||||||
//auto [width, height] = m_textRenderer->getLogicalTextSize(buttonData.text, buttonData.textstytle);
|
//auto [width, height] = m_textRenderer->getLogicalTextSize(buttonData.text, buttonData.textstytle);
|
||||||
auto viewport = m_textRenderer->getViewport();
|
auto viewport = m_textRenderer->getViewport();
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 渲染按钮背景
|
* @brief 渲染背景
|
||||||
* @param renderer SDL渲染器
|
* @param renderer SDL渲染器
|
||||||
*/
|
*/
|
||||||
void renderButtonBackground(const ButtonData& buttonData);
|
template <typename Type>
|
||||||
|
void renderBackground(const Type& data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 渲染按钮边框
|
* @brief 渲染按钮边框
|
||||||
|
|||||||
Reference in New Issue
Block a user