Skip to content

Commit

Permalink
[FairyGUI] Use content scale factor to correctly set up a scale 9 spr…
Browse files Browse the repository at this point in the history
…ite (#1884)

* Ensure that the content scale factor is used to correctly set up a scale 9 sprite

* Insets defined in FairyGUI editor should be scaled too, which simplifies the fix.

* Update copyright for Axmol related modifications
  • Loading branch information
rh101 authored May 6, 2024
1 parent 1d8233d commit 5ee1c8e
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions extensions/fairygui/src/fairygui/GImage.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/****************************************************************************
Copyright (c) 2015 fairygui.com
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
****************************************************************************/

#include "GImage.h"
#include "PackageItem.h"
#include "display/FUISprite.h"
Expand Down Expand Up @@ -126,16 +150,25 @@ void GImage::setProp(ObjectPropID propId, const ax::Value& value)
void GImage::constructFromResource()
{
PackageItem* contentItem = _packageItem->getBranch();
sourceSize.width = contentItem->width;
sourceSize.height = contentItem->height;
initSize = sourceSize;
sourceSize.width = contentItem->width;
sourceSize.height = contentItem->height;
initSize = sourceSize;

contentItem = contentItem->getHighResolution();
contentItem->load();

_content->setSpriteFrame(contentItem->spriteFrame);
if (contentItem->scale9Grid)
((FUISprite*)_content)->setScale9Grid(contentItem->scale9Grid);
{
const auto contentScaleFactor = AX_CONTENT_SCALE_FACTOR();

auto scaledInsets = *contentItem->scale9Grid;

scaledInsets.setRect(scaledInsets.origin.x / contentScaleFactor, scaledInsets.origin.y / contentScaleFactor,
scaledInsets.size.x / contentScaleFactor, scaledInsets.size.y / contentScaleFactor);

((FUISprite*)_content)->setScale9Grid(&scaledInsets);
}
else if (contentItem->scaleByTile)
((FUISprite*)_content)->setScaleByTile(true);

Expand All @@ -161,4 +194,4 @@ void GImage::setup_beforeAdd(ByteBuffer* buffer, int beginPos)
}
}

NS_FGUI_END
NS_FGUI_END

0 comments on commit 5ee1c8e

Please sign in to comment.