Removed the allowUpscale option for ImageComponent::setResize.

Added ImageComponent::setMaxSize(size).
Added "maxSize" theming option for ImageComponent.
This commit is contained in:
Aloshi 2014-01-10 17:45:47 -06:00
parent 92a6678736
commit b35d365dc8
9 changed files with 78 additions and 63 deletions

View file

@ -222,6 +222,7 @@ Reference
#### image
* `pos` - type: NORMALIZED_PAIR.
* `size` - type: NORMALIZED_PAIR.
* `maxSize` - type: NORMALIZED_PAIR.
* `origin` - type: NORMALIZED_PAIR.
* `path` - type: PATH.
* `tile` - type: BOOLEAN.

View file

@ -14,6 +14,7 @@ std::map< std::string, std::map<std::string, ThemeData::ElementPropertyType> > T
("image", boost::assign::map_list_of
("pos", NORMALIZED_PAIR)
("size", NORMALIZED_PAIR)
("maxSize", NORMALIZED_PAIR)
("origin", NORMALIZED_PAIR)
("path", PATH)
("tile", BOOLEAN))

View file

@ -63,8 +63,8 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), &mResultInfo, false, ComponentListComponent::AlignLeft);
mResultThumbnail.setOrigin(0.5f, 0.5f);
mResultThumbnail.setResize(colWidth, mResultInfo.getSize().y(), false);
mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mResultThumbnail, false, ComponentListComponent::AlignCenter);
mResultThumbnail.setMaxSize(colWidth, mResultInfo.getSize().y() + mResultName.getSize().y());
mList.setEntry(Vector2i(1, 1), Vector2i(1, 2), &mResultThumbnail, false, ComponentListComponent::AlignCenter);
//y = 3 is a spacer row

View file

@ -20,10 +20,10 @@ Eigen::Vector2f ImageComponent::getCenter() const
mPosition.y() - (getSize().y() * mOrigin.y()) + getSize().y() / 2);
}
ImageComponent::ImageComponent(Window* window, float offsetX, float offsetY, std::string path, float targetWidth, float targetHeight, bool allowUpscale) : GuiComponent(window),
mTiled(false), mAllowUpscale(allowUpscale), mFlipX(false), mFlipY(false), mOrigin(0.0, 0.0), mTargetSize(targetWidth, targetHeight), mColorShift(0xFFFFFFFF)
ImageComponent::ImageComponent(Window* window, const Eigen::Vector2f& pos, const std::string& path) : GuiComponent(window),
mTiled(false), mTargetIsMax(false), mFlipX(false), mFlipY(false), mOrigin(0.0, 0.0), mTargetSize(0, 0), mColorShift(0xFFFFFFFF)
{
setPosition(offsetX, offsetY);
setPosition(pos.x(), pos.y());
if(!path.empty())
setImage(path);
@ -38,35 +38,44 @@ void ImageComponent::resize()
if(!mTexture)
return;
mSize << (float)getTextureSize().x(), (float)getTextureSize().y();
//(we don't resize tiled images)
if(!mTiled && (mTargetSize.x() || mTargetSize.y()))
{
Eigen::Vector2f resizeScale(Eigen::Vector2f::Zero());
if(mTargetSize.x() && (mAllowUpscale || mSize.x() > mTargetSize.x()))
{
resizeScale[0] = mTargetSize.x() / mSize.x();
}
if(mTargetSize.y() && (mAllowUpscale || mSize.y() > mTargetSize.y()))
{
resizeScale[1] = mTargetSize.y() / mSize.y();
}
if(resizeScale.x() && !resizeScale.y())
resizeScale[1] = resizeScale.x();
if(resizeScale[1] && !resizeScale.x())
resizeScale[0] = resizeScale.y();
if(resizeScale.x())
mSize[0] = (mSize.x() * resizeScale.x());
if(resizeScale.y())
mSize[1] = (mSize.y() * resizeScale.y());
}
const Eigen::Vector2f textureSize((float)getTextureSize().x(), (float)getTextureSize().y());
if(mTiled)
{
mSize = mTargetSize;
}else{
if(mTargetIsMax)
{
mSize = textureSize;
Eigen::Vector2f resizeScale((mTargetSize.x() / mSize.x()), (mTargetSize.y() / mSize.y()));
if(resizeScale.x() < resizeScale.y())
{
mSize[0] *= resizeScale.x();
mSize[1] *= resizeScale.x();
}else{
mSize[0] *= resizeScale.y();
mSize[1] *= resizeScale.y();
}
}else{
// if both components are set, we just stretch
// if no components are set, we don't resize at all
mSize = mTargetSize.isZero() ? textureSize : mTargetSize;
// if only one component is set, we resize in a way that maintains aspect ratio
if(!mTargetSize.x() && mTargetSize.y())
{
mSize[0] = (mTargetSize.y() / mSize.y()) * mSize.x();
mSize[1] = mTargetSize.y();
}else if(mTargetSize.x() && !mTargetSize.y())
{
mSize[0] = mTargetSize.x();
mSize[1] = (mTargetSize.x() / mSize.x()) * mSize.y();
}
}
}
}
void ImageComponent::setImage(std::string path)
@ -104,16 +113,20 @@ void ImageComponent::setTiling(bool tile)
{
mTiled = tile;
if(mTiled)
mAllowUpscale = false;
resize();
}
void ImageComponent::setResize(float width, float height, bool allowUpscale)
void ImageComponent::setResize(float width, float height)
{
mTargetSize << width, height;
mAllowUpscale = allowUpscale;
mTargetIsMax = false;
resize();
}
void ImageComponent::setMaxSize(float width, float height)
{
mTargetSize << width, height;
mTargetIsMax = true;
resize();
}
@ -266,8 +279,13 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
setPosition(Eigen::Vector3f(denormalized.x(), denormalized.y(), 0));
}
if(properties & ThemeFlags::SIZE && elem->has("size"))
setResize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale), true);
if(properties & ThemeFlags::SIZE)
{
if(elem->has("size"))
setResize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale));
else if(elem->has("maxSize"))
setMaxSize(elem->get<Eigen::Vector2f>("maxSize").cwiseProduct(scale));
}
// position + size also implies origin
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))

View file

@ -15,7 +15,7 @@ public:
//Creates a new GuiImage at the given location. If given an image, it will be loaded. If maxWidth and/or maxHeight are nonzero, the image will be
//resized to fit. If only one axis is specified, the other will be set in accordance with the image's aspect ratio. If allowUpscale is false,
//the image will only be downscaled, never upscaled (the image's size must surpass at least one nonzero bound).
ImageComponent(Window* window, float offsetX = 0.0f, float offsetY = 0.0f, std::string path = "", float maxWidth = 0, float maxHeight = 0, bool allowUpscale = false);
ImageComponent(Window* window, const Eigen::Vector2f& pos = Eigen::Vector2f::Zero(), const std::string& path = "");
virtual ~ImageComponent();
void copyScreen(); //Copy the entire screen into a texture for us to use.
@ -25,8 +25,10 @@ public:
void setOrigin(float originX, float originY); //Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center)
inline void setOrigin(Eigen::Vector2f origin) { setOrigin(origin.x(), origin.y()); }
void setTiling(bool tile); //Enables or disables tiling. Must be called before loading an image or resizing will be weird.
void setResize(float width, float height, bool allowUpscale);
inline void setResize(Eigen::Vector2f size, bool allowUpscale) { setResize(size.x(), size.y(), allowUpscale); }
void setResize(float width, float height);
inline void setResize(const Eigen::Vector2f& size) { setResize(size.x(), size.y()); }
void setMaxSize(float width, float height);
inline void setMaxSize(const Eigen::Vector2f& size) { setMaxSize(size.x(), size.y()); }
void setColorShift(unsigned int color);
void setFlipX(bool flip);
@ -47,7 +49,7 @@ private:
Eigen::Vector2f mTargetSize;
Eigen::Vector2f mOrigin;
bool mAllowUpscale, mTiled, mFlipX, mFlipY;
bool mTiled, mFlipX, mFlipY, mTargetIsMax;
void resize();
void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs, float percentageX = 1, float percentageY = 1); //writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position

View file

@ -317,7 +317,7 @@ void ImageGridComponent<T>::buildImages()
image.setPosition((squareSize.x() + padding.x()) * (x + 0.5f) + offset.x(), (squareSize.y() + padding.y()) * (y + 0.5f) + offset.y());
image.setOrigin(0.5f, 0.5f);
image.setResize(squareSize.x(), squareSize.y(), true);
image.setResize(squareSize.x(), squareSize.y());
image.setImage("");
}
}
@ -357,10 +357,10 @@ void ImageGridComponent<T>::updateImages()
if(i == mCursor)
{
image.setColorShift(0xFFFFFFFF);
image.setResize(squareSize.x() + getPadding().x() * 0.95f, squareSize.y() + getPadding().y() * 0.95f, true);
image.setResize(squareSize.x() + getPadding().x() * 0.95f, squareSize.y() + getPadding().y() * 0.95f);
}else{
image.setColorShift(0xAAAAAABB);
image.setResize(squareSize.x(), squareSize.y(), true);
image.setResize(squareSize.x(), squareSize.y());
}
image.setImage(mEntries.at(i).texture);

View file

@ -17,7 +17,7 @@ SystemView::SystemView(Window* window, SystemData* system) : GuiComponent(window
mHeaderImage.setOrigin(0.5f, 0.0f);
mHeaderImage.setPosition(mSize.x() / 2, 0);
mHeaderImage.setResize(0, mSize.y() * 0.2f, true);
mHeaderImage.setResize(0, mSize.y() * 0.2f);
mHeaderText.setPosition(0, 6);
mHeaderText.setSize(mSize.x(), 0);
@ -25,7 +25,7 @@ SystemView::SystemView(Window* window, SystemData* system) : GuiComponent(window
mImage.setOrigin(0.5f, 0.5f);
mImage.setPosition(mSize.x() / 2, mSize.y() * 0.6f);
mImage.setResize(0, mSize.y() * 0.8f, false);
mImage.setResize(0, mSize.y() * 0.8f);
addChild(&mExtras);
addChild(&mImage);

View file

@ -16,13 +16,13 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
mList.setCentered(false);
mList.setCursorChangedCallback([&](TextListComponent<FileData*>::CursorState state) { updateInfoPanel(); });
mImage.setOrigin(0.5f, 0.0f);
mImage.setPosition(mSize.x() * 0.25f, mList.getPosition().y());
mImage.setResize(mSize.x() * (0.50f - 2*padding), 0, false);
mImage.setOrigin(0.5f, 0.5f);
mImage.setPosition(mSize.x() * 0.25f, mList.getPosition().y() + mSize.y() * 0.2125f);
mImage.setMaxSize(mSize.x() * (0.50f - 2*padding), mSize.y() * 0.425f);
addChild(&mImage);
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.2f);
mDescContainer.setSize(mSize.x() * (0.50f - 2*padding), 0);
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f);
mDescContainer.setSize(mSize.x() * (0.50f - 2*padding), mSize.y() - mDescContainer.getPosition().y());
mDescContainer.setAutoScroll((int)(1600 + mDescContainer.getSize().x()), 0.025f);
addChild(&mDescContainer);
@ -35,12 +35,8 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
{
mHeaderImage.setResize(mSize.x() * 0.5f, 0, true);
BasicGameListView::onThemeChanged(theme);
//if(mHeaderImage.getPosition().y() + mHeaderImage.getSize().y() > mImage.getPosition().y())
// mHeaderImage.setResize(0, mSize.y() * 0.185f, true);
using namespace ThemeFlags;
mImage.applyTheme(theme, getName(), "gameimage", POSITION | ThemeFlags::SIZE);
mDescContainer.applyTheme(theme, getName(), "infoPanel", POSITION | ThemeFlags::SIZE);
@ -57,12 +53,9 @@ void DetailedGameListView::updateInfoPanel()
mDescription.setText("");
}else{
mImage.setImage(file->metadata.get("image"));
mDescContainer.setPosition(mDescContainer.getPosition().x(), mImage.getPosition().y() + mImage.getSize().y() * 1.02f);
mDescContainer.setSize(mDescContainer.getSize().x(), mSize.y() - mDescContainer.getPosition().y());
mDescContainer.resetAutoScrollTimer();
mDescription.setText(file->metadata.get("desc"));
mDescContainer.resetAutoScrollTimer();
}
}

View file

@ -12,11 +12,11 @@ ISimpleGameListView::ISimpleGameListView(Window* window, FileData* root) : IGame
mHeaderText.setPosition(0, 0);
mHeaderText.setCentered(true);
mHeaderImage.setResize(0, mSize.y() * 0.185f, false);
mHeaderImage.setResize(0, mSize.y() * 0.185f);
mHeaderImage.setOrigin(0.5f, 0.0f);
mHeaderImage.setPosition(mSize.x() / 2, 0);
mBackground.setResize(mSize.x(), mSize.y(), true);
mBackground.setResize(mSize.x(), mSize.y());
addChild(&mHeaderText);
addChild(&mBackground);