#include "Image.h" namespace UI { Image::Image(Texture* texture, Size size) { focusable = false; padding = Thickness(0.0f, 0.0f); if (size.width > 0.0f || size.height > 0.0f) { minSize = size; maxSize = size; } source = texture; } void Image::RefreshPrimitives() { image = std::make_unique<::Image>(source, globalBounds.X, globalBounds.Y, globalBounds.Width, globalBounds.Height); } void Image::Measure(Size availableSpace) { Widget::Measure(availableSpace); if (minSize.width <= 0.0f && minSize.height <= 0.0f && source) { desiredSize.width = std::clamp((float)source->GetWidth() + margin.HorizontalTotal(), minSize.width, maxSize.width); desiredSize.height = std::clamp((float)source->GetHeight() + margin.VerticalTotal(), minSize.height, maxSize.height); } } void Image::Arrange(Rect finalBounds) { Rect oldGlobal = globalBounds; bool needsRefresh = IsDirty(DirtyFlags::Render | DirtyFlags::Layout); Widget::Arrange(finalBounds); if (needsRefresh || globalBounds != oldGlobal) { RefreshPrimitives(); } } void Image::Draw() { if (!visible) return; if (!image || IsDirty(DirtyFlags::Layout)) { RefreshPrimitives(); } if (image) { image->Render(); } Widget::Draw(); } }