style::style(const std::string& aName, const i_style& aOther) : iName(aName), iMargins(aOther.margins()), iSpacing(aOther.spacing()), iColour(aOther.has_colour() ? aOther.colour() : optional_colour()), iBackgroundColour(aOther.has_background_colour() ? aOther.background_colour() : optional_colour()), iForegroundColour(aOther.has_foreground_colour() ? aOther.foreground_colour() : optional_colour()), iTextColour(aOther.has_text_colour() ? aOther.text_colour() : optional_colour()), iSelectionColour(aOther.has_selection_colour() ? aOther.selection_colour() : optional_colour()), iHoverColour(aOther.has_hover_colour() ? aOther.hover_colour() : optional_colour()), iFontInfo(aOther.font_info()) { }
void image_widget::paint(graphics_context& aGraphicsContext) const { if (iTexture.is_empty()) return; scoped_units su(*this, UnitsPixels); rect placementRect(point{}, iTexture.extents()); if (iAspectRatio == aspect_ratio::Stretch) { placementRect.cx = client_rect().width(); placementRect.cy = client_rect().height(); } else if (placementRect.width() >= placementRect.height()) { switch (iAspectRatio) { case aspect_ratio::Ignore: if (placementRect.width() > client_rect().width()) placementRect.cx = client_rect().width(); if (placementRect.height() > client_rect().height()) placementRect.cy = client_rect().height(); break; case aspect_ratio::Keep: if (placementRect.width() > client_rect().width()) { placementRect.cx = client_rect().width(); placementRect.cy = placementRect.cx * iTexture.extents().cy / iTexture.extents().cx; } if (placementRect.height() > client_rect().height()) { placementRect.cy = client_rect().height(); placementRect.cx = placementRect.cy * iTexture.extents().cx / iTexture.extents().cy; } break; case aspect_ratio::KeepExpanding: if (placementRect.height() > client_rect().height()) { placementRect.cy = client_rect().height(); placementRect.cx = placementRect.cy * iTexture.extents().cx / iTexture.extents().cy; } break; } } else { switch (iAspectRatio) { case aspect_ratio::Ignore: if (placementRect.width() > client_rect().width()) placementRect.cx = client_rect().width(); if (placementRect.height() > client_rect().height()) placementRect.cy = client_rect().height(); break; case aspect_ratio::Keep: if (placementRect.height() > client_rect().height()) { placementRect.cy = client_rect().height(); placementRect.cx = placementRect.cy * iTexture.extents().cx / iTexture.extents().cy; } if (placementRect.width() > client_rect().width()) { placementRect.cx = client_rect().width(); placementRect.cy = placementRect.cx * iTexture.extents().cy / iTexture.extents().cx; } break; case aspect_ratio::KeepExpanding: if (placementRect.width() > client_rect().width()) { placementRect.cx = client_rect().width(); placementRect.cy = placementRect.cx * iTexture.extents().cy / iTexture.extents().cx; } break; } } switch (iPlacement) { case cardinal_placement::NorthWest: placementRect.position() = point{}; break; case cardinal_placement::North: placementRect.position() = point{ std::floor((client_rect().width() - placementRect.cx) / 2.0), 0.0 }; break; case cardinal_placement::NorthEast: placementRect.position() = point{ client_rect().width() - placementRect.width(), 0.0 }; break; case cardinal_placement::West: placementRect.position() = point{ 0.0, std::floor((client_rect().height() - placementRect.cy) / 2.0) }; break; case cardinal_placement::Centre: placementRect.position() = point{ std::floor((client_rect().width() - placementRect.cx) / 2.0), std::floor((client_rect().height() - placementRect.cy) / 2.0) }; break; case cardinal_placement::East: placementRect.position() = point{ client_rect().width() - placementRect.width(), std::floor((client_rect().height() - placementRect.cy) / 2.0) }; break; case cardinal_placement::SouthWest: placementRect.position() = point{ 0.0, client_rect().height() - placementRect.height() }; break; case cardinal_placement::South: placementRect.position() = point{ std::floor((client_rect().width() - placementRect.cx) / 2.0), client_rect().height() - placementRect.height() }; break; case cardinal_placement::SouthEast: placementRect.position() = point{ client_rect().width() - placementRect.width(), client_rect().height() - placementRect.height() }; break; } if (effectively_disabled()) aGraphicsContext.set_monochrome(true); aGraphicsContext.draw_texture(placementRect, iTexture, effectively_disabled() ? colour(0xFF, 0xFF, 0xFF, 0x80) : optional_colour()); aGraphicsContext.set_monochrome(false); }