mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
refactor(render): replace UI shaders with image shaders and Image widget
This commit is contained in:
27
src/ui/image.cpp
Normal file
27
src/ui/image.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "Cubed/ui/image.hpp"
|
||||
|
||||
#include "Cubed/render/renderer.hpp"
|
||||
#include "Cubed/tools/shader_tools.hpp"
|
||||
|
||||
namespace Cubed {
|
||||
Image::Image() : m_texture(TextureType::TEXTURE_2D) {}
|
||||
void Image::update(float dt) { (void)dt; }
|
||||
void Image::render(Renderer& renderer) { renderer.render_image(*this); }
|
||||
|
||||
Image& Image::set_image(std::filesystem::path path) {
|
||||
auto data = Tools::load_image_data(path);
|
||||
m_texture.tex_image_2d(RGBA, RGBA, GL_UNSIGNED_BYTE, data.data, data.width,
|
||||
data.height);
|
||||
m_height = data.height;
|
||||
m_width = data.width;
|
||||
m_texture.set_nearest();
|
||||
return *this;
|
||||
}
|
||||
|
||||
float Image::height() const { return m_height; }
|
||||
|
||||
float Image::width() const { return m_width; }
|
||||
|
||||
const Texture& Image::texture() const { return m_texture; }
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -11,21 +11,6 @@ Label& Label::set_text(std::string_view text) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Label& Label::set_position(const glm::vec2& pos) {
|
||||
return set_position(pos.x, pos.y);
|
||||
}
|
||||
|
||||
Label& Label::set_position(float x, float y) {
|
||||
m_pos.x = x;
|
||||
m_pos.y = y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Label& Label::set_scale(float scale) {
|
||||
m_scale = scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Label& Label::set_color(Color color) {
|
||||
m_text.color = color;
|
||||
return *this;
|
||||
@@ -52,7 +37,6 @@ void Label::update_vertices() {
|
||||
}
|
||||
|
||||
const UIVertexData& Label::data() const { return m_data; }
|
||||
const glm::vec2& Label::pos() const { return m_pos; }
|
||||
const TextStyle& Label::text_style() const { return m_text; }
|
||||
float Label::scale() const { return m_scale; }
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -21,6 +21,22 @@ void Widget::render(Renderer& renderer) {
|
||||
void Widget::on_update(float dt) {}
|
||||
void Widget::on_render(Renderer& renderer) {}
|
||||
|
||||
Widget& Widget::set_position(const glm::vec2& pos) {
|
||||
return set_position(pos.x, pos.y);
|
||||
}
|
||||
|
||||
Widget& Widget::set_position(float x, float y) {
|
||||
m_pos.x = x;
|
||||
m_pos.y = y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Widget& Widget::set_scale(float scale) {
|
||||
m_scale = scale;
|
||||
return *this;
|
||||
}
|
||||
const glm::vec2& Widget::pos() const { return m_pos; }
|
||||
float Widget::scale() const { return m_scale; }
|
||||
const std::string& Widget::id() const { return m_id; }
|
||||
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user