mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Make button sprites (scrollbar arrows) DPI-aware (#14772)
This commit is contained in:
parent
fb6ceb2664
commit
4c001bd248
9 changed files with 67 additions and 61 deletions
|
@ -75,12 +75,11 @@ void CGUIButton::setSpriteBank(IGUISpriteBank *sprites)
|
|||
SpriteBank = sprites;
|
||||
}
|
||||
|
||||
void CGUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop, bool scale)
|
||||
void CGUIButton::setSprite(EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop)
|
||||
{
|
||||
ButtonSprites[(u32)state].Index = index;
|
||||
ButtonSprites[(u32)state].Color = color;
|
||||
ButtonSprites[(u32)state].Loop = loop;
|
||||
ButtonSprites[(u32)state].Scale = scale;
|
||||
}
|
||||
|
||||
//! Get the sprite-index for the given state or -1 when no sprite is set
|
||||
|
@ -101,12 +100,6 @@ bool CGUIButton::getSpriteLoop(EGUI_BUTTON_STATE state) const
|
|||
return ButtonSprites[(u32)state].Loop;
|
||||
}
|
||||
|
||||
//! Returns if the sprite in the given state is scaled
|
||||
bool CGUIButton::getSpriteScale(EGUI_BUTTON_STATE state) const
|
||||
{
|
||||
return ButtonSprites[(u32)state].Scale;
|
||||
}
|
||||
|
||||
//! called if an event happened.
|
||||
bool CGUIButton::OnEvent(const SEvent &event)
|
||||
{
|
||||
|
@ -294,19 +287,26 @@ void CGUIButton::draw()
|
|||
void CGUIButton::drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di ¢er)
|
||||
{
|
||||
u32 stateIdx = (u32)state;
|
||||
s32 spriteIdx = ButtonSprites[stateIdx].Index;
|
||||
if (spriteIdx == -1)
|
||||
return;
|
||||
|
||||
if (ButtonSprites[stateIdx].Index != -1) {
|
||||
if (ButtonSprites[stateIdx].Scale) {
|
||||
const video::SColor colors[] = {ButtonSprites[stateIdx].Color, ButtonSprites[stateIdx].Color, ButtonSprites[stateIdx].Color, ButtonSprites[stateIdx].Color};
|
||||
SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, AbsoluteRect,
|
||||
&AbsoluteClippingRect, colors,
|
||||
os::Timer::getTime() - startTime, ButtonSprites[stateIdx].Loop);
|
||||
} else {
|
||||
SpriteBank->draw2DSprite(ButtonSprites[stateIdx].Index, center,
|
||||
&AbsoluteClippingRect, ButtonSprites[stateIdx].Color, startTime, os::Timer::getTime(),
|
||||
ButtonSprites[stateIdx].Loop, true);
|
||||
}
|
||||
}
|
||||
u32 rectIdx = SpriteBank->getSprites()[spriteIdx].Frames[0].rectNumber;
|
||||
core::rect<s32> srcRect = SpriteBank->getPositions()[rectIdx];
|
||||
|
||||
IGUISkin *skin = Environment->getSkin();
|
||||
s32 scale = std::max(std::floor(skin->getScale()), 1.0f);
|
||||
core::rect<s32> rect(center, srcRect.getSize() * scale);
|
||||
rect -= rect.getSize() / 2;
|
||||
|
||||
const video::SColor colors[] = {
|
||||
ButtonSprites[stateIdx].Color,
|
||||
ButtonSprites[stateIdx].Color,
|
||||
ButtonSprites[stateIdx].Color,
|
||||
ButtonSprites[stateIdx].Color,
|
||||
};
|
||||
SpriteBank->draw2DSprite(spriteIdx, rect, &AbsoluteClippingRect, colors,
|
||||
os::Timer::getTime() - startTime, ButtonSprites[stateIdx].Loop);
|
||||
}
|
||||
|
||||
EGUI_BUTTON_IMAGE_STATE CGUIButton::getImageState(bool pressed) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue