21 Image(
const std::string& texName,
26 const bool& bCrop =
false )
38 if (
auto tex = ga::textureCache().get(
textureName ) ) {
39 if ( tex->isAllocated() ) {
40 ga::vec2 texDims { tex->getWidth(), tex->getHeight() };
42 auto texSize = texDims * texScale;
47 tex->draw( texPos, texSize.x, texSize.y );
51 auto cropPtB = glm::min(
bounds2D.
max(), texPos + texSize );
52 auto cropSz = cropPtB - cropPtA;
53 auto subPtA = ( cropPtA - texPos ) / texScale;
54 auto subPtB = ( cropPtB - texPos ) / texScale;
55 auto subSz = subPtB - subPtA;
56 tex->drawSubsection( cropPtA.x, cropPtA.y, cropSz.x, cropSz.y, subPtA.x, subPtA.y, subSz.x, subSz.y );
72 if (
auto img = ga::textureCache().get(
textureName ) ) {
73 if ( img->isAllocated() ) {
74 ga::vec2 texDims { img->getWidth(), img->getHeight() };
76 auto texSize = texDims * texScale;
80 drawBounds =
ga::Rect { texPos, texPos + texSize };
Definition: component.h:11
Definition: image_component.h:10
ga::Rect bounds2D
Definition: image_component.h:13
VertAlign vertAlign
Definition: image_component.h:16
std::string textureName
Definition: image_component.h:12
Image(const std::string &texName, const ga::Rect &bounds, const ga::FitMode &fit, const HorzAlign &hAlign=HorzAlign::LEFT, const VertAlign &vAlign=VertAlign::TOP, const bool &bCrop=false)
Definition: image_component.h:21
void draw()
Definition: image_component.h:36
ga::FitMode fitMode
Definition: image_component.h:14
ga::Rect getDrawBounds()
Definition: image_component.h:69
bool crop
Definition: image_component.h:17
HorzAlign horzAlign
Definition: image_component.h:15
vec3 calcScaleToFit(const vec3 &sourceSize, const vec3 &containerSize, const FitMode &fitMode)
Definition: layout.h:55
FitMode
Definition: layout.h:45
VertAlign
Definition: layout.h:12
HorzAlign
Definition: layout.h:6
vec2 anchor(HorzAlign h, VertAlign v)
Definition: layout.h:19
A 2D axis-aligned rectangle, with x,y (float) position and w,h (float) size components.
Definition: math.h:64
vec2 position() const
Definition: math.h:93
vec2 max() const
Definition: math.h:97
vec2 size() const
Definition: math.h:94
vec2 min() const
Definition: math.h:96