Fix recent colours box in colour picker on Mac

Originally committed to SVN as r2260.
This commit is contained in:
Niels Martin Hansen 2008-07-16 01:29:36 +00:00
parent e8dffb60ec
commit 9c51d15a99
2 changed files with 42 additions and 17 deletions

View file

@ -52,6 +52,8 @@
#include "help_button.h" #include "help_button.h"
#include "utils.h" #include "utils.h"
#include <stdio.h>
#ifdef WIN32 #ifdef WIN32
#define STATIC_BORDER_FLAG wxSTATIC_BORDER #define STATIC_BORDER_FLAG wxSTATIC_BORDER
@ -168,6 +170,8 @@ ColorPickerRecent::ColorPickerRecent(wxWindow *parent, wxWindowID id, int _cols,
, cols(_cols) , cols(_cols)
, cellsize(_cellsize) , cellsize(_cellsize)
, internal_control_offset(0,0) , internal_control_offset(0,0)
, background_valid(false)
, background()
{ {
LoadFromString(wxEmptyString); LoadFromString(wxEmptyString);
SetClientSize(cols*cellsize, rows*cellsize); SetClientSize(cols*cellsize, rows*cellsize);
@ -183,12 +187,14 @@ void ColorPickerRecent::LoadFromString(const wxString &recent_string)
while (toker.HasMoreTokens()) { while (toker.HasMoreTokens()) {
AssColor color; AssColor color;
color.Parse(toker.NextToken()); color.Parse(toker.NextToken());
color.a = 0; color.a = wxALPHA_OPAQUE;
colors.push_back(color.GetWXColor()); colors.push_back(color.GetWXColor());
} }
while ((int)colors.size() < rows*cols) { while ((int)colors.size() < rows*cols) {
colors.push_back(*wxBLACK); colors.push_back(*wxBLACK);
} }
background_valid = false;
} }
wxString ColorPickerRecent::StoreToString() wxString ColorPickerRecent::StoreToString()
@ -210,7 +216,11 @@ void ColorPickerRecent::AddColor(wxColour color)
break; break;
} }
} }
colors.insert(colors.begin(), color); colors.insert(colors.begin(), color);
background_valid = false;
Refresh(false); Refresh(false);
} }
@ -240,30 +250,41 @@ void ColorPickerRecent::OnClick(wxMouseEvent &evt)
void ColorPickerRecent::OnPaint(wxPaintEvent &evt) void ColorPickerRecent::OnPaint(wxPaintEvent &evt)
{ {
wxPaintDC dc(this); wxPaintDC pdc(this);
wxBrush brush; PrepareDC(pdc);
wxSize cs = GetClientSize();
int i = 0; if (!background_valid) {
dc.SetPen(*wxTRANSPARENT_PEN); wxSize sz = pdc.GetSize();
for (int cy = 0; cy < rows; cy++) { background = wxBitmap(sz.x, sz.y);
for (int cx = 0; cx < cols; cx++) { wxMemoryDC dc(background);
int x, y;
x = cx * cellsize + internal_control_offset.x;
y = cy * cellsize + internal_control_offset.y;
dc.SetBrush(wxBrush(colors[i])); int i = 0;
dc.DrawRectangle(x, y, x+cellsize, y+cellsize); dc.SetPen(*wxTRANSPARENT_PEN);
i++; 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) void ColorPickerRecent::OnSize(wxSizeEvent &evt)
{ {
wxSize size = GetClientSize(); wxSize size = GetClientSize();
background_valid = false;
//internal_control_offset.x = (size.GetWidth() - cellsize * cols) / 2; //internal_control_offset.x = (size.GetWidth() - cellsize * cols) / 2;
//internal_control_offset.y = (size.GetHeight() - cellsize * rows) / 2; //internal_control_offset.y = (size.GetHeight() - cellsize * rows) / 2;
Refresh(); Refresh();

View file

@ -81,8 +81,12 @@ private:
int rows, cols; int rows, cols;
int cellsize; int cellsize;
wxPoint internal_control_offset; wxPoint internal_control_offset;
std::vector<wxColour> colors; std::vector<wxColour> colors;
bool background_valid;
wxBitmap background;
void OnClick(wxMouseEvent &evt); void OnClick(wxMouseEvent &evt);
void OnPaint(wxPaintEvent &evt); void OnPaint(wxPaintEvent &evt);
void OnSize(wxSizeEvent &evt); void OnSize(wxSizeEvent &evt);