From c5c829357dfc66e44f23ed1d9f8624b6dfa3afb0 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 2 Feb 2012 20:50:56 +0000 Subject: [PATCH] Use wxAutoBufferedPaintDC for ToggleButton Originally committed to SVN as r6437. --- aegisub/src/toggle_bitmap.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/aegisub/src/toggle_bitmap.cpp b/aegisub/src/toggle_bitmap.cpp index 63c1fa375..ac8acf1dc 100644 --- a/aegisub/src/toggle_bitmap.cpp +++ b/aegisub/src/toggle_bitmap.cpp @@ -37,7 +37,7 @@ #include "config.h" #ifndef AGI_PRE -#include +#include #include #include #endif @@ -60,6 +60,8 @@ ToggleBitmap::ToggleBitmap(wxWindow *parent, agi::Context *context, const char * GetSize(&w, &h); SetSizeHints(w, h, w, h); + SetBackgroundStyle(wxBG_STYLE_PAINT); + ToolTipManager::Bind(this, command->StrHelp(), ht_ctx, cmd_name); Bind(wxEVT_PAINT, &ToggleBitmap::OnPaint, this); Bind(wxEVT_LEFT_DOWN, &ToggleBitmap::OnMouseEvent, this); @@ -71,9 +73,7 @@ void ToggleBitmap::OnMouseEvent(wxMouseEvent &) { } void ToggleBitmap::OnPaint(wxPaintEvent &) { - wxPaintDC dc(this); - int w,h; - GetClientSize(&w,&h); + wxAutoBufferedPaintDC dc(this); // Get background color wxColour bgColor = command->IsActive(context) ? wxColour(0,255,0) : wxColour(255,0,0); @@ -85,7 +85,8 @@ void ToggleBitmap::OnPaint(wxPaintEvent &) { dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(wxBrush(bgColor)); - dc.DrawRectangle(0, 0, w, h); + dc.DrawRectangle(wxPoint(0, 0), GetClientSize()); - dc.DrawBitmap(img, (w - img.GetWidth()) / 2, (h - img.GetHeight()) / 2, true); + wxSize excess = (GetClientSize() - img.GetSize()) / 2; + dc.DrawBitmap(img, excess.GetX(), excess.GetY(), true); }