<2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(六)——Widgets
<2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(六)——Widgets
- Button
Button
namespace OvUI::Widgets::Buttons
{class AButton : public AWidget{protected:void _Draw_Impl() override = 0;public:OvTools::Eventing::Event<> ClickedEvent;};
}
定义按钮小部件的基类
OvUI::Widgets::Buttons::Button::Button(const std::string& p_label, const OvMaths::FVector2& p_size, bool p_disabled) :label(p_label), size(p_size), disabled(p_disabled)
{auto& style = ImGui::GetStyle();idleBackgroundColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_Button]);hoveredBackgroundColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_ButtonHovered]);clickedBackgroundColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_ButtonActive]);textColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_Text]);
}void OvUI::Widgets::Buttons::Button::_Draw_Impl()
{auto& style = ImGui::GetStyle();auto defaultIdleColor = style.Colors[ImGuiCol_Button];auto defaultHoveredColor = style.Colors[ImGuiCol_ButtonHovered];auto defaultClickedColor = style.Colors[ImGuiCol_ButtonActive];auto defaultTextColor = style.Colors[ImGuiCol_Text];style.Colors[ImGuiCol_Button] = OvUI::Internal::Converter::ToImVec4(idleBackgroundColor);style.Colors[ImGuiCol_ButtonHovered] = OvUI::Internal::Converter::ToImVec4(hoveredBackgroundColor);style.Colors[ImGuiCol_ButtonActive] = OvUI::Internal::Converter::ToImVec4(clickedBackgroundColor);style.Colors[ImGuiCol_Text] = OvUI::Internal::Converter::ToImVec4(textColor);if (ImGui::ButtonEx((label + m_widgetID).c_str(), Internal::Converter::ToImVec2(size), disabled ? ImGuiButtonFlags_Disabled : 0))ClickedEvent.Invoke();style.Colors[ImGuiCol_Button] = defaultIdleColor;style.Colors[ImGuiCol_ButtonHovered] = defaultHoveredColor;style.Colors[ImGuiCol_ButtonActive] = defaultClickedColor;style.Colors[ImGuiCol_Text] = defaultTextColor;
}
这是一个简单按钮小部件的实现。
OvUI::Widgets::Buttons::ButtonArrow::ButtonArrow(ImGuiDir p_direction) :direction(p_direction)
{}void OvUI::Widgets::Buttons::ButtonArrow::_Draw_Impl()
{if (ImGui::ArrowButton(m_widgetID.c_str(), direction))ClickedEvent.Invoke();
}
带有箭头的按钮小部件的实现,需要使用ImGui库中的箭头按钮。
OvUI::Widgets::Buttons::ButtonColored::ButtonColored(const std::string & p_label, const Types::Color& p_color, const OvMaths::FVector2& p_size, bool p_enableAlpha) :label(p_label), color(p_color), size(p_size), enableAlpha(p_enableAlpha)
{}void OvUI::Widgets::Buttons::ButtonColored::_Draw_Impl()
{ImVec4 imColor = Internal::Converter::ToImVec4(color);if (ImGui::ColorButton((label + m_widgetID).c_str(), imColor, !enableAlpha ? ImGuiColorEditFlags_NoAlpha : 0, Internal::Converter::ToImVec2(size)))ClickedEvent.Invoke();color = Internal::Converter::ToColor(imColor);
}
这是一个单一颜色的按钮小部件的实现,需要使用调色板元素。
OvUI::Widgets::Buttons::ButtonImage::ButtonImage(uint32_t p_textureID, const OvMaths::FVector2 & p_size) :textureID{ p_textureID }, size(p_size)
{}void OvUI::Widgets::Buttons::ButtonImage::_Draw_Impl()
{ImVec4 bg = Internal::Converter::ToImVec4(background);ImVec4 tn = Internal::Converter::ToImVec4(tint);if (ImGui::ImageButton(textureID.raw, Internal::Converter::ToImVec2(size), ImVec2(0.f, 1.f), ImVec2(1.f, 0.f), -1, bg, tn, disabled ? ImGuiButtonFlags_Disabled : 0))ClickedEvent.Invoke();
}
带有图像的按钮小部件
OvUI::Widgets::Buttons::ButtonSmall::ButtonSmall(const std::string& p_label) :label(p_label)
{auto& style = ImGui::GetStyle();idleBackgroundColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_Button]);hoveredBackgroundColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_ButtonHovered]);clickedBackgroundColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_ButtonActive]);textColor = Internal::Converter::ToColor(style.Colors[ImGuiCol_Text]);
}void OvUI::Widgets::Buttons::ButtonSmall::_Draw_Impl()
{auto& style = ImGui::GetStyle();auto defaultIdleColor = style.Colors[ImGuiCol_Button];auto defaultHoveredColor = style.Colors[ImGuiCol_ButtonHovered];auto defaultClickedColor = style.Colors[ImGuiCol_ButtonActive];auto defaultTextColor = style.Colors[ImGuiCol_Text];style.Colors[ImGuiCol_Button] = OvUI::Internal::Converter::ToImVec4(idleBackgroundColor);style.Colors[ImGuiCol_ButtonHovered] = OvUI::Internal::Converter::ToImVec4(hoveredBackgroundColor);style.Colors[ImGuiCol_ButtonActive] = OvUI::Internal::Converter::ToImVec4(clickedBackgroundColor);style.Colors[ImGuiCol_Text] = OvUI::Internal::Converter::ToImVec4(textColor);if (ImGui::SmallButton((label + m_widgetID).c_str()))ClickedEvent.Invoke();style.Colors[ImGuiCol_Button] = defaultIdleColor;style.Colors[ImGuiCol_ButtonHovered] = defaultHoveredColor;style.Colors[ImGuiCol_ButtonActive] = defaultClickedColor;style.Colors[ImGuiCol_Text] = defaultTextColor;
}
小按钮小部件
<2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(六)——Widgets相关推荐
- <2021SC@SDUSC>【Overload游戏引擎】源码模块简介及项目分工
<2021SC@SDUSC>[Overload游戏引擎]源码模块简介及项目分工 模块简介 Overload SDK Overload 应用程序 项目分工 模块简介 Overload 由12 ...
- <2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(五)——Plugins
<2021SC@SDUSC>[Overload游戏引擎]OvUI源码模块分析(五)--Plugins 前言 DataDispatcher DDSource DDTarget IPlugin ...
- <2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(三)——Internal
<2021SC@SDUSC>[Overload游戏引擎]OvUI源码模块分析(三)--Internal 前言 Internal 1.Converter 2.EMemoryMode 3.Wi ...
- <2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(二)——ImGui
<2021SC@SDUSC>[Overload游戏引擎]OvUI源码模块分析(二) 前言 案例分析 程序框架 1.基本案例 2.实现定制绑定/定制引擎 渲染函数 总结 前言 本篇我们来分析 ...
- <2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(四)——ModulesPanels
<2021SC@SDUSC>[Overload游戏引擎]OvUI源码模块分析(四)--Modules&Panels 前言 Modules Canvas Panels APanel ...
- <2021SC@SDUSC>【Overload游戏引擎】OvUI源码模块分析(一)——Core
<2021SC@SDUSC>[Overload游戏引擎]OvUI源码模块分析(一) 文章目录 前言 OvUI的模块结构 源码分析 1.Core模块 (1)UIManger的构造函数和析构函 ...
- 【Overload游戏引擎】源码分析之十三:OvRendering函数库(十一)
2021SC@SDUSC 目录 1.Driver 1.1构造函数 1.2InitGlew 1.3GLDebugMessageCallback 2.Renderer 2.1Draw 2.2FetchGL ...
- 【Overload游戏引擎】源码分析之五:OvRendering函数库(三)
2021SC@SDUSC 目录 IMesh.h与Mesh.h 1.CreateBuffers 2.ComputeBoundingSphere 3.其他函数 回顾一下前几篇文章,我们讲到了有关图形学三维 ...
- 【Overload游戏引擎】源码分析之六:OvRendering函数库(四)
2021SC@SDUSC 目录 1.Uniform 1.1UniformType 1.2UniformInfo 2.Shader 2.1SetUniform和GetUniform 2.2GetUnif ...
最新文章
- egret发布的HTML5项目怎么打开,Egret引擎开发指南之发布项目
- mac terminal常用命令接触
- Exchange 2013恢复已禁用用户邮箱
- 简单粗暴, 包邮送 30 本 Python 新书。
- python 单元测试 unittest
- jQuery 对HTML的操作(二)
- [SpringBoot2]welcomefavicon
- [C++11]基于范围的for循环
- ieee39节点系统介绍_Java秒杀系统实战系列-基于ZooKeeper的分布式锁优化秒杀逻辑...
- 微服务应用实现无损上下线实践
- cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第八部---怪物出场
- Gartner:CIO需破解建立数字化领导力的四大障碍
- 不要主动进行垃圾回收
- 使用 Apache 工具类 HttpClients 进行 GET、POST请求
- Xampp的apache无法启动时的解决办法
- Java宠物管理系统(运用接口简易版)
- Windows API串口编程详解
- Android Netty的使用-入门指南
- SELinux/SEAndroid -- 基础知识介绍
- 无需打开软件排版设计海报的在线工具!
热门文章
- matlab 浮雕,基于MATLAB根据图片快速制作陶瓷浮雕的方法与流程
- 爆照!!!以及不吃月饼的5大理由。
- 四川师范大学计算机学院冯林,李晓宁(四川师范大学计算机科学学院副教授)_百度百科...
- android提醒程序,设置Android闹钟 - 提醒应用程序
- Go语言下载网络图片或文件
- python:输出内容对不齐怎么办?这篇文章解决大家的数据输出对不齐,不好看的问题
- ECSHOP农行支付接口开发(含手机端)
- 365天英语口语学习_08,饮料
- 基于SSM的智能车库管理系统的设计与实现
- duang!京东瞬间成了一只受伤的狗!