Permalink
Browse files

Merge pull request #10182 from unknownbrackets/ui-text

UI: Avoid drawing dirty pixels from old text strings on Windows
  • Loading branch information...
hrydgard committed Nov 23, 2017
2 parents c04ead1 + 03ac79c commit 31c1b5a41f639f351ee02034041c29f6f19be858
Showing with 16 additions and 20 deletions.
  1. +2 −2 UI/PauseScreen.cpp
  2. +2 −6 UI/PauseScreen.h
  3. +12 −12 ext/native/gfx_es2/draw_text_win.cpp
@@ -172,8 +172,8 @@ class SaveSlotView : public UI::LinearLayout {
UI::EventReturn OnSaveState(UI::EventParams &e);
UI::EventReturn OnLoadState(UI::EventParams &e);
UI::Button *saveStateButton_;
UI::Button *loadStateButton_;
UI::Button *saveStateButton_ = nullptr;
UI::Button *loadStateButton_ = nullptr;
int slot_;
std::string gamePath_;
@@ -27,7 +27,7 @@
class GamePauseScreen : public UIDialogScreenWithGameBackground {
public:
GamePauseScreen(const std::string &filename) : UIDialogScreenWithGameBackground(filename), finishNextFrame_(false), gamePath_(filename) {}
GamePauseScreen(const std::string &filename) : UIDialogScreenWithGameBackground(filename), gamePath_(filename) {}
virtual ~GamePauseScreen();
virtual void dialogFinished(const Screen *dialog, DialogResult dr) override;
@@ -39,7 +39,6 @@ class GamePauseScreen : public UIDialogScreenWithGameBackground {
void CallbackDeleteConfig(bool yes);
private:
UI::EventReturn OnMainSettings(UI::EventParams &e);
UI::EventReturn OnGameSettings(UI::EventParams &e);
UI::EventReturn OnExitToMenu(UI::EventParams &e);
UI::EventReturn OnReportFeedback(UI::EventParams &e);
@@ -55,11 +54,8 @@ class GamePauseScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnSwitchUMD(UI::EventParams &e);
UI::EventReturn OnState(UI::EventParams &e);
UI::Choice *saveStateButton_;
UI::Choice *loadStateButton_;
// hack
bool finishNextFrame_;
bool finishNextFrame_ = false;
std::string gamePath_;
};
@@ -227,14 +227,6 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f
size.cx = textRect.right;
size.cy = textRect.bottom;
// GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);
RECT rc = { 0 };
rc.right = size.cx + 4;
rc.bottom = size.cy + 4;
FillRect(ctx_->hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
//ExtTextOut(ctx_->hDC, 0, 0, ETO_OPAQUE | ETO_CLIPPED, NULL, wstr.c_str(), (int)wstr.size(), NULL);
DrawTextExW(ctx_->hDC, (LPWSTR)wstr.c_str(), (int)wstr.size(), &rc, DT_HIDEPREFIX | DT_TOP | dtAlign, 0);
if (size.cx > MAX_TEXT_WIDTH)
size.cx = MAX_TEXT_WIDTH;
if (size.cy > MAX_TEXT_HEIGHT)
@@ -247,6 +239,12 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f
entry->bmHeight = (size.cy + 3) & ~3;
entry->lastUsedFrame = frameCount_;
RECT rc = { 0 };
rc.right = entry->bmWidth;
rc.bottom = entry->bmHeight;
FillRect(ctx_->hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
DrawTextExW(ctx_->hDC, (LPWSTR)wstr.c_str(), (int)wstr.size(), &rc, DT_HIDEPREFIX | DT_TOP | dtAlign, 0);
DataFormat texFormat;
// For our purposes these are equivalent, so just choose the supported one. D3D can emulate them.
if (draw_->GetDataFormatSupport(Draw::DataFormat::A4R4G4B4_UNORM_PACK16) & FMT_TEXTURE)
@@ -307,10 +305,12 @@ void TextDrawerWin32::DrawString(DrawBuffer &target, const char *str, float x, f
draw_->BindTexture(0, entry->texture);
// Okay, the texture is bound, let's draw.
float w = entry->bmWidth * fontScaleX_ * dpiScale_;
float h = entry->bmHeight * fontScaleY_ * dpiScale_;
float w = entry->width * fontScaleX_ * dpiScale_;
float h = entry->height * fontScaleY_ * dpiScale_;
float u = entry->width / (float)entry->bmWidth;
float v = entry->height / (float)entry->bmHeight;
DrawBuffer::DoAlign(align, &x, &y, &w, &h);
target.DrawTexRect(x, y, x + w, y + h, 0.0f, 0.0f, 1.0f, 1.0f, color);
target.DrawTexRect(x, y, x + w, y + h, 0.0f, 0.0f, u, v, color);
target.Flush(true);
}
@@ -385,4 +385,4 @@ void TextDrawerWin32::OncePerFrame() {
}
}
#endif
#endif

0 comments on commit 31c1b5a

Please sign in to comment.