修复图片大小不正确
This commit is contained in:
parent
dc896d51f3
commit
de33e765d4
@ -31,8 +31,15 @@ int main(int argc, char* argv[]) {
|
||||
auto image = std::make_shared<mimage>();
|
||||
image->set_image(i);
|
||||
|
||||
auto hbox = std::make_shared<mh_box>();
|
||||
hbox->add_child()
|
||||
.auto_size()
|
||||
[
|
||||
image
|
||||
];
|
||||
|
||||
const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!");
|
||||
window->set_content(image);
|
||||
window->set_content(hbox);
|
||||
|
||||
mirage_app::get().run();
|
||||
return 0;
|
||||
|
@ -23,7 +23,9 @@ public:
|
||||
|
||||
[[nodiscard]] const auto& get_image() const { return image_; }
|
||||
[[nodiscard]] const auto& get_size() const { return size_; }
|
||||
[[nodiscard]] const auto& get_pixel_format() const { return pixel_format_; }
|
||||
private:
|
||||
sg_image image_{};
|
||||
sg_pixel_format pixel_format_{};
|
||||
Eigen::Vector2i size_{};
|
||||
};
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
* @param anisotropy 各向异性程度(1-16)
|
||||
* @return 具有各向异性过滤的采样器
|
||||
*/
|
||||
static texture_sampler_builder create_anisotropic(uint32_t anisotropy = 4);
|
||||
static texture_sampler_builder create_anisotropic(uint32_t anisotropy = 16);
|
||||
|
||||
/**
|
||||
* @brief 设置缩小过滤器
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
void texture2d::create(void* in_data, const Eigen::Vector2i& in_size, sg_pixel_format in_pixel_format) {
|
||||
auto format_info = sg_query_pixelformat(in_pixel_format);
|
||||
pixel_format_ = in_pixel_format;
|
||||
size_ = in_size;
|
||||
|
||||
sg_image_desc sg_desc{};
|
||||
sg_desc.type = SG_IMAGETYPE_2D;
|
||||
|
@ -12,11 +12,28 @@ void mimage::on_paint(mirage_paint_context& in_context) {
|
||||
in_context.geo().get_local_size(),
|
||||
in_context.geo(),
|
||||
image_->get_image(),
|
||||
sampler_type::default_,
|
||||
sampler_type::anisotropic,
|
||||
{ color_ }
|
||||
);
|
||||
}
|
||||
|
||||
void mimage::set_image(const std::shared_ptr<texture2d>& in_image) {
|
||||
image_ = in_image;
|
||||
auto image_format = image_->get_pixel_format();
|
||||
// 根据像素格式选择合适的过滤器
|
||||
if (image_format == sg_pixel_format::SG_PIXELFORMAT_BC1_RGBA ||
|
||||
image_format == sg_pixel_format::SG_PIXELFORMAT_BC2_RGBA ||
|
||||
image_format == sg_pixel_format::SG_PIXELFORMAT_BC3_RGBA ||
|
||||
image_format == sg_pixel_format::SG_PIXELFORMAT_BC4_R ||
|
||||
image_format == sg_pixel_format::SG_PIXELFORMAT_BC5_RG ||
|
||||
image_format == sg_pixel_format::SG_PIXELFORMAT_BC6H_RGBF ||
|
||||
image_format == sg_pixel_format::SG_PIXELFORMAT_BC7_RGBA) {
|
||||
filter_ = sg_filter::SG_FILTER_NEAREST;
|
||||
} else {
|
||||
filter_ = sg_filter::SG_FILTER_LINEAR;
|
||||
}
|
||||
}
|
||||
|
||||
Eigen::Vector2f mimage::compute_desired_size(float in_layout_scale_multiplier) const {
|
||||
if (image_) {
|
||||
return image_->get_size().cast<float>();
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
Eigen::Vector2f compute_desired_size(float in_layout_scale_multiplier) const override;
|
||||
|
||||
const auto& get_image() const { return image_; }
|
||||
void set_image(const std::shared_ptr<texture2d>& in_image) { image_ = in_image; }
|
||||
void set_image(const std::shared_ptr<texture2d>& in_image);
|
||||
|
||||
const auto& get_color() const { return color_; }
|
||||
void set_color(const linear_color& in_color) { color_ = in_color; }
|
||||
@ -18,4 +18,5 @@ private:
|
||||
std::shared_ptr<texture2d> image_;
|
||||
std::shared_ptr<texture_sampler> sampler_;
|
||||
linear_color color_ = { 1, 1, 1, 1 };
|
||||
sg_filter filter_{};
|
||||
};
|
||||
|
@ -72,14 +72,13 @@ public:
|
||||
*
|
||||
* 创建并添加一个新的子组件插槽到面板中。
|
||||
*/
|
||||
template<typename T>
|
||||
auto add_slot() -> SlotType& {
|
||||
auto& slot = slots_.emplace_back();
|
||||
slot.slot_owner = shared_from_this();
|
||||
invalidate(invalidate_reason::all);
|
||||
return slot;
|
||||
}
|
||||
template<typename T, typename... Args>
|
||||
template<typename... Args>
|
||||
auto add_child(Args&&... in_args) -> SlotType& {
|
||||
auto& slot = slots_.emplace_back(std::forward<Args>(in_args)...);
|
||||
slot.slot_owner = shared_from_this();
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user