Optimize/simplify dialog shading slightly

- move creation to c'tor
 - apply position and size with one method instead of two
This commit is contained in:
Stephen Anthony 2020-11-14 22:35:05 -03:30
parent bda86befb4
commit 85d0c9227c
5 changed files with 80 additions and 48 deletions

View File

@ -104,41 +104,49 @@ const Common::Rect& FBSurfaceSDL2::dstRect() const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::setSrcPos(uInt32 x, uInt32 y)
{
if(x != static_cast<uInt32>(mySrcR.x) || y != static_cast<uInt32>(mySrcR.y))
{
setSrcPosInternal(x, y);
if(setSrcPosInternal(x, y))
reinitializeBlitter();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::setSrcSize(uInt32 w, uInt32 h)
{
if(w != static_cast<uInt32>(mySrcR.w) || h != static_cast<uInt32>(mySrcR.h))
{
setSrcSizeInternal(w, h);
if(setSrcSizeInternal(w, h))
reinitializeBlitter();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::setSrcRect(const Common::Rect& r)
{
const bool posChanged = setSrcPosInternal(r.x(), r.y()),
sizeChanged = setSrcSizeInternal(r.w(), r.h());
if(posChanged || sizeChanged)
reinitializeBlitter();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::setDstPos(uInt32 x, uInt32 y)
{
if(x != static_cast<uInt32>(myDstR.x) || y != static_cast<uInt32>(myDstR.y))
{
setDstPosInternal(x, y);
if(setDstPosInternal(x, y))
reinitializeBlitter();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::setDstSize(uInt32 w, uInt32 h)
{
if(w != static_cast<uInt32>(myDstR.w) || h != static_cast<uInt32>(myDstR.h))
{
setDstSizeInternal(w, h);
if(setDstSizeInternal(w, h))
reinitializeBlitter();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::setDstRect(const Common::Rect& r)
{
const bool posChanged = setDstPosInternal(r.x(), r.y()),
sizeChanged = setDstSizeInternal(r.w(), r.h());
if(posChanged || sizeChanged)
reinitializeBlitter();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -48,8 +48,11 @@ class FBSurfaceSDL2 : public FBSurface
const Common::Rect& dstRect() const override;
void setSrcPos(uInt32 x, uInt32 y) override;
void setSrcSize(uInt32 w, uInt32 h) override;
void setSrcRect(const Common::Rect& r) override;
void setDstPos(uInt32 x, uInt32 y) override;
void setDstSize(uInt32 w, uInt32 h) override;
void setDstRect(const Common::Rect& r) override;
void setVisible(bool visible) override;
void translateCoords(Int32& x, Int32& y) const override;
@ -67,21 +70,41 @@ class FBSurfaceSDL2 : public FBSurface
void applyAttributes() override;
private:
inline void setSrcPosInternal(uInt32 x, uInt32 y) {
mySrcR.x = x; mySrcR.y = y;
mySrcGUIR.moveTo(x, y);
inline bool setSrcPosInternal(uInt32 x, uInt32 y) {
if(x != static_cast<uInt32>(mySrcR.x) || y != static_cast<uInt32>(mySrcR.y))
{
mySrcR.x = x; mySrcR.y = y;
mySrcGUIR.moveTo(x, y);
return true;
}
return false;
}
inline void setSrcSizeInternal(uInt32 w, uInt32 h) {
mySrcR.w = w; mySrcR.h = h;
mySrcGUIR.setWidth(w); mySrcGUIR.setHeight(h);
inline bool setSrcSizeInternal(uInt32 w, uInt32 h) {
if(w != static_cast<uInt32>(mySrcR.w) || h != static_cast<uInt32>(mySrcR.h))
{
mySrcR.w = w; mySrcR.h = h;
mySrcGUIR.setWidth(w); mySrcGUIR.setHeight(h);
return true;
}
return false;
}
inline void setDstPosInternal(uInt32 x, uInt32 y) {
myDstR.x = x; myDstR.y = y;
myDstGUIR.moveTo(x, y);
inline bool setDstPosInternal(uInt32 x, uInt32 y) {
if(x != static_cast<uInt32>(myDstR.x) || y != static_cast<uInt32>(myDstR.y))
{
myDstR.x = x; myDstR.y = y;
myDstGUIR.moveTo(x, y);
return true;
}
return false;
}
inline void setDstSizeInternal(uInt32 w, uInt32 h) {
myDstR.w = w; myDstR.h = h;
myDstGUIR.setWidth(w); myDstGUIR.setHeight(h);
inline bool setDstSizeInternal(uInt32 w, uInt32 h) {
if(w != static_cast<uInt32>(myDstR.w) || h != static_cast<uInt32>(myDstR.h))
{
myDstR.w = w; myDstR.h = h;
myDstGUIR.setWidth(w); myDstGUIR.setHeight(h);
return true;
}
return false;
}
void createSurface(uInt32 width, uInt32 height, const uInt32* data);
@ -103,7 +126,7 @@ class FBSurfaceSDL2 : public FBSurface
{ScalingInterpolation::none};
SDL_Surface* mySurface{nullptr};
SDL_Rect mySrcR{0, 0, 0, 0}, myDstR{0, 0, 0, 0};
SDL_Rect mySrcR{-1, -1, -1, -1}, myDstR{-1, -1, -1, -1};
bool myIsVisible{true};
bool myIsStatic{false};

View File

@ -292,11 +292,14 @@ class FBSurface
These methods set the origin point and width/height for the
specified service. They are defined as separate x/y and w/h
methods since these items are sometimes set separately.
Other times they are set together, so we can use a Rect instead.
*/
virtual void setSrcPos(uInt32 x, uInt32 y) = 0;
virtual void setSrcSize(uInt32 w, uInt32 h) = 0;
virtual void setSrcRect(const Common::Rect& r) = 0;
virtual void setDstPos(uInt32 x, uInt32 y) = 0;
virtual void setDstSize(uInt32 w, uInt32 h) = 0;
virtual void setDstRect(const Common::Rect& r) = 0;
/**
This method should be called to enable/disable showing the surface

View File

@ -53,6 +53,18 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font
{
_flags = Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG;
setTitle(title);
// Create shading surface
uInt32 data = 0xff000000;
_shadeSurface = instance.frameBuffer().allocateSurface(
1, 1, ScalingInterpolation::sharp, &data);
FBSurface::Attributes& attr = _shadeSurface->attributes();
attr.blending = true;
attr.blendalpha = 25; // darken background dialogs by 25%
_shadeSurface->applyAttributes();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -223,7 +235,7 @@ void Dialog::redraw(bool force)
// Draw this dialog
setPosition();
drawDialog();
// full rendering is caused in dialog container
// full rendering is caused in dialog container
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -251,24 +263,7 @@ void Dialog::render()
{
cerr << " shade " << typeid(*this).name() << endl;
if(_shadeSurface == nullptr)
{
uInt32 data = 0xff000000;
_shadeSurface = instance().frameBuffer().allocateSurface(
1, 1, ScalingInterpolation::sharp, &data);
FBSurface::Attributes& attr = _shadeSurface->attributes();
attr.blending = true;
attr.blendalpha = 25; // darken background dialogs by 25%
_shadeSurface->applyAttributes();
}
const Common::Rect& rect = _surface->dstRect();
_shadeSurface->setDstPos(rect.x(), rect.y());
_shadeSurface->setDstSize(rect.w(), rect.h());
_shadeSurface->setDstRect(_surface->dstRect());
_shadeSurface->render();
}
}

View File

@ -44,8 +44,11 @@ class FBSurfaceLIBRETRO : public FBSurface
const Common::Rect& dstRect() const override { return myDstGUIR; }
void setSrcPos(uInt32 x, uInt32 y) override { }
void setSrcSize(uInt32 w, uInt32 h) override { }
void setSrcRect(const Common::Rect& r) override { }
void setDstPos(uInt32 x, uInt32 y) override { }
void setDstSize(uInt32 w, uInt32 h) override { }
void setDstRect(const Common::Rect& r) override { }
void setVisible(bool visible) override { }
void translateCoords(Int32& x, Int32& y) const override { }