From 9c51d15a99c8aef0b206f5d058b1f3360c6d2165 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Wed, 16 Jul 2008 01:29:36 +0000 Subject: [PATCH] Fix recent colours box in colour picker on Mac Originally committed to SVN as r2260. --- aegisub/dialog_colorpicker.cpp | 55 +++++++++++++++++++++++----------- aegisub/dialog_colorpicker.h | 4 +++ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/aegisub/dialog_colorpicker.cpp b/aegisub/dialog_colorpicker.cpp index 3dfae42b9..fd1bfb263 100644 --- a/aegisub/dialog_colorpicker.cpp +++ b/aegisub/dialog_colorpicker.cpp @@ -52,6 +52,8 @@ #include "help_button.h" #include "utils.h" +#include + #ifdef WIN32 #define STATIC_BORDER_FLAG wxSTATIC_BORDER @@ -168,6 +170,8 @@ ColorPickerRecent::ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols, , cols(_cols) , cellsize(_cellsize) , internal_control_offset(0,0) +, background_valid(false) +, background() { LoadFromString(wxEmptyString); SetClientSize(cols*cellsize, rows*cellsize); @@ -183,12 +187,14 @@ void ColorPickerRecent::LoadFromString(const wxString &recent_string) while (toker.HasMoreTokens()) { AssColor color; color.Parse(toker.NextToken()); - color.a = 0; + color.a = wxALPHA_OPAQUE; colors.push_back(color.GetWXColor()); } while ((int)colors.size() < rows*cols) { colors.push_back(*wxBLACK); } + + background_valid = false; } wxString ColorPickerRecent::StoreToString() @@ -210,7 +216,11 @@ void ColorPickerRecent::AddColor(wxColour color) break; } } + colors.insert(colors.begin(), color); + + background_valid = false; + Refresh(false); } @@ -240,30 +250,41 @@ void ColorPickerRecent::OnClick(wxMouseEvent &evt) void ColorPickerRecent::OnPaint(wxPaintEvent &evt) { - wxPaintDC dc(this); - wxBrush brush; - wxSize cs = GetClientSize(); + wxPaintDC pdc(this); + PrepareDC(pdc); - int i = 0; - dc.SetPen(*wxTRANSPARENT_PEN); - - for (int cy = 0; cy < rows; cy++) { - for (int cx = 0; cx < cols; cx++) { - int x, y; - x = cx * cellsize + internal_control_offset.x; - y = cy * cellsize + internal_control_offset.y; - - dc.SetBrush(wxBrush(colors[i])); - dc.DrawRectangle(x, y, x+cellsize, y+cellsize); - - i++; + if (!background_valid) { + wxSize sz = pdc.GetSize(); + + background = wxBitmap(sz.x, sz.y); + wxMemoryDC dc(background); + + int i = 0; + dc.SetPen(*wxTRANSPARENT_PEN); + + for (int cy = 0; cy < rows; cy++) { + for (int cx = 0; cx < cols; cx++) { + int x, y; + x = cx * cellsize + internal_control_offset.x; + y = cy * cellsize + internal_control_offset.y; + + dc.SetBrush(wxBrush(colors[i])); + dc.DrawRectangle(x, y, x+cellsize, y+cellsize); + + i++; + } } + + background_valid = true; } + + pdc.DrawBitmap(background, 0, 0, false); } void ColorPickerRecent::OnSize(wxSizeEvent &evt) { wxSize size = GetClientSize(); + background_valid = false; //internal_control_offset.x = (size.GetWidth() - cellsize * cols) / 2; //internal_control_offset.y = (size.GetHeight() - cellsize * rows) / 2; Refresh(); diff --git a/aegisub/dialog_colorpicker.h b/aegisub/dialog_colorpicker.h index 9261c8197..00b02420f 100644 --- a/aegisub/dialog_colorpicker.h +++ b/aegisub/dialog_colorpicker.h @@ -81,7 +81,11 @@ private: int rows, cols; int cellsize; wxPoint internal_control_offset; + std::vector colors; + + bool background_valid; + wxBitmap background; void OnClick(wxMouseEvent &evt); void OnPaint(wxPaintEvent &evt);