Skip to content

Commit

Permalink
UI: Fixed fade in/out effect on HUD messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed Nov 20, 2024
1 parent bde9ad3 commit 919e14f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Core/Shared/Video/DebugHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void DebugHud::DrawRectangle(int x, int y, int width, int height, int color, boo
AddCommand(unique_ptr<DrawCommand>(new DrawRectangleCommand(x, y, width, height, color, fill, frameCount, startFrame)));
}

void DebugHud::DrawString(int x, int y, string text, int color, int backColor, int frameCount, int startFrame, int maxWidth)
void DebugHud::DrawString(int x, int y, string text, int color, int backColor, int frameCount, int startFrame, int maxWidth, bool overwritePixels)
{
AddCommand(unique_ptr<DrawCommand>(new DrawStringCommand(x, y, text, color, backColor, frameCount, startFrame, maxWidth)));
AddCommand(unique_ptr<DrawCommand>(new DrawStringCommand(x, y, text, color, backColor, frameCount, startFrame, maxWidth, overwritePixels)));
}
2 changes: 1 addition & 1 deletion Core/Shared/Video/DebugHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DebugHud
void DrawPixel(int x, int y, int color, int frameCount, int startFrame = -1);
void DrawLine(int x, int y, int x2, int y2, int color, int frameCount, int startFrame = -1);
void DrawRectangle(int x, int y, int width, int height, int color, bool fill, int frameCount, int startFrame = -1);
void DrawString(int x, int y, string text, int color, int backColor, int frameCount, int startFrame = -1, int maxWidth = 0);
void DrawString(int x, int y, string text, int color, int backColor, int frameCount, int startFrame = -1, int maxWidth = 0, bool overwritePixels = false);

__forceinline void AddCommand(unique_ptr<DrawCommand> cmd)
{
Expand Down
9 changes: 7 additions & 2 deletions Core/Shared/Video/DrawCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DrawCommand
FrameInfo _frameInfo = {};
OverscanDimensions _overscan = {};
bool _useIntegerScaling = false;
bool _overwritePixels = false;
float _xScale = 1;
int _yScale = 1;

Expand All @@ -24,10 +25,10 @@ class DrawCommand
if(_drawnPixels) {
//Log modified pixels
if(alpha != 0xFF000000) {
if(_drawnPixels->find(offset) == _drawnPixels->end()) {
if(_drawnPixels->find(offset) == _drawnPixels->end() || _overwritePixels) {
//When drawing on an empty background, premultiply channels & preserve alpha value
//This is needed for hardware blending between the HUD and the game screen
(*_drawnPixels)[offset] = color;
(*_drawnPixels)[offset] = 0;
BlendColors((uint8_t*)&(*_drawnPixels)[offset], (uint8_t*)&color, true);
} else {
BlendColors((uint8_t*)&(*_drawnPixels)[offset], (uint8_t*)&color);
Expand All @@ -38,6 +39,10 @@ class DrawCommand
} else {
//Draw pixels directly to the buffer
if(alpha != 0xFF000000) {
if(_overwritePixels) {
_argbBuffer[offset] = 0;
}

if(_argbBuffer[offset] == 0) {
//When drawing on an empty background, premultiply channels & preserve alpha value
//This is needed for hardware blending between the HUD and the game screen
Expand Down
3 changes: 2 additions & 1 deletion Core/Shared/Video/DrawStringCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@ class DrawStringCommand : public DrawCommand
}

public:
DrawStringCommand(int x, int y, string text, int color, int backColor, int frameCount, int startFrame, int maxWidth = 0) :
DrawStringCommand(int x, int y, string text, int color, int backColor, int frameCount, int startFrame, int maxWidth = 0, bool overwritePixels = false) :
DrawCommand(startFrame, frameCount, true), _x(x), _y(y), _color(color), _backColor(backColor), _maxWidth(maxWidth), _text(text)
{
//Invert alpha byte - 0 = opaque, 255 = transparent (this way, no need to specifiy alpha channel all the time)
_overwritePixels = overwritePixels;
_color = (~color & 0xFF000000) | (color & 0xFFFFFF);
_backColor = (~backColor & 0xFF000000) | (backColor & 0xFFFFFF);
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Shared/Video/SystemHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ void SystemHud::DrawString(DebugHud* hud, uint32_t screenWidth, string text, int
opacity = 255 - opacity;
for(int i = -1; i <= 1; i++) {
for(int j = -1; j <= 1; j++) {
hud->DrawString(x + i, y + j, text, 0 | (opacity << 24), 0xFF000000, 1, -1, maxWidth);
hud->DrawString(x + i, y + j, text, 0 | (opacity << 24), 0xFF000000, 1, -1, maxWidth, true);
}
}
hud->DrawString(x, y, text, 0xFFFFFF | (opacity << 24), 0xFF000000, 1, -1, maxWidth);
hud->DrawString(x, y, text, 0xFFFFFF | (opacity << 24), 0xFF000000, 1, -1, maxWidth, true);
}

void SystemHud::ShowFpsCounter(DebugHud* hud, uint32_t screenWidth, int lineNumber) const
Expand Down
4 changes: 2 additions & 2 deletions Core/Shared/Video/SystemHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class MessageInfo
float GetOpacity()
{
uint64_t currentTime = GetCurrentTime();
if(currentTime - _startTime < 200) {
return (currentTime - _startTime) * 5.0f / 1000.0f;
if(currentTime - _startTime < 100) {
return (currentTime - _startTime) * 10.0f / 1000.0f;
} else if(_endTime - currentTime < 200) {
return (_endTime - currentTime) * 5.0f / 1000.0f;
} else if(currentTime >= _endTime) {
Expand Down

0 comments on commit 919e14f

Please sign in to comment.