forked from mia/Aegisub
Use wxStaticBitmap for ColorPickerRecent
This commit is contained in:
parent
0e58e3b09f
commit
7a3b221847
1 changed files with 18 additions and 38 deletions
|
@ -249,7 +249,7 @@ wxDEFINE_EVENT(EVT_RECENT_SELECT, wxThreadEvent);
|
||||||
|
|
||||||
/// @class ColorPickerRecent
|
/// @class ColorPickerRecent
|
||||||
/// @brief A grid of recently used colors which can be selected by clicking on them
|
/// @brief A grid of recently used colors which can be selected by clicking on them
|
||||||
class ColorPickerRecent : public wxControl {
|
class ColorPickerRecent : public wxStaticBitmap {
|
||||||
int rows; ///< Number of rows of colors
|
int rows; ///< Number of rows of colors
|
||||||
int cols; ///< Number of cols of colors
|
int cols; ///< Number of cols of colors
|
||||||
int cellsize; ///< Width/Height of each cell
|
int cellsize; ///< Width/Height of each cell
|
||||||
|
@ -257,12 +257,6 @@ class ColorPickerRecent : public wxControl {
|
||||||
/// The colors currently displayed in the control
|
/// The colors currently displayed in the control
|
||||||
std::vector<agi::Color> colors;
|
std::vector<agi::Color> colors;
|
||||||
|
|
||||||
/// Does the background need to be regenerated?
|
|
||||||
bool background_valid;
|
|
||||||
|
|
||||||
/// Bitmap storing the cached background
|
|
||||||
wxBitmap background;
|
|
||||||
|
|
||||||
void OnClick(wxMouseEvent &evt) {
|
void OnClick(wxMouseEvent &evt) {
|
||||||
wxSize cs = GetClientSize();
|
wxSize cs = GetClientSize();
|
||||||
int cx = evt.GetX() * cols / cs.x;
|
int cx = evt.GetX() * cols / cs.x;
|
||||||
|
@ -277,14 +271,10 @@ class ColorPickerRecent : public wxControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPaint(wxPaintEvent &evt) {
|
void UpdateBitmap() {
|
||||||
wxPaintDC pdc(this);
|
wxSize sz = GetClientSize();
|
||||||
PrepareDC(pdc);
|
|
||||||
|
|
||||||
if (!background_valid) {
|
wxBitmap background(sz.x, sz.y);
|
||||||
wxSize sz = pdc.GetSize();
|
|
||||||
|
|
||||||
background = wxBitmap(sz.x, sz.y);
|
|
||||||
wxMemoryDC dc(background);
|
wxMemoryDC dc(background);
|
||||||
|
|
||||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
@ -299,26 +289,18 @@ class ColorPickerRecent : public wxControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
background_valid = true;
|
SetBitmap(background);
|
||||||
}
|
Refresh(false);
|
||||||
|
|
||||||
pdc.DrawBitmap(background, 0, 0, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnSize(wxSizeEvent &evt) {
|
|
||||||
background_valid = false;
|
|
||||||
Refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AcceptsFocusFromKeyboard() const { return false; }
|
bool AcceptsFocusFromKeyboard() const { return false; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ColorPickerRecent(wxWindow *parent, int cols, int rows, int cellsize)
|
ColorPickerRecent(wxWindow *parent, int cols, int rows, int cellsize)
|
||||||
: wxControl(parent, -1, wxDefaultPosition, wxDefaultSize, STATIC_BORDER_FLAG)
|
: wxStaticBitmap(parent, -1, wxBitmap(), wxDefaultPosition, wxDefaultSize, STATIC_BORDER_FLAG)
|
||||||
, rows(rows)
|
, rows(rows)
|
||||||
, cols(cols)
|
, cols(cols)
|
||||||
, cellsize(cellsize)
|
, cellsize(cellsize)
|
||||||
, background_valid(false)
|
|
||||||
{
|
{
|
||||||
colors.resize(rows * cols);
|
colors.resize(rows * cols);
|
||||||
SetClientSize(cols*cellsize, rows*cellsize);
|
SetClientSize(cols*cellsize, rows*cellsize);
|
||||||
|
@ -326,15 +308,15 @@ public:
|
||||||
SetMaxSize(GetSize());
|
SetMaxSize(GetSize());
|
||||||
SetCursor(*wxCROSS_CURSOR);
|
SetCursor(*wxCROSS_CURSOR);
|
||||||
|
|
||||||
Bind(wxEVT_PAINT, &ColorPickerRecent::OnPaint, this);
|
|
||||||
Bind(wxEVT_LEFT_DOWN, &ColorPickerRecent::OnClick, this);
|
Bind(wxEVT_LEFT_DOWN, &ColorPickerRecent::OnClick, this);
|
||||||
Bind(wxEVT_SIZE, &ColorPickerRecent::OnSize, this);
|
Bind(wxEVT_SIZE, [=](wxSizeEvent&) { UpdateBitmap(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load the colors to show
|
/// Load the colors to show
|
||||||
void Load(std::vector<agi::Color> const& recent_colors) {
|
void Load(std::vector<agi::Color> const& recent_colors) {
|
||||||
colors = recent_colors;
|
colors = recent_colors;
|
||||||
colors.resize(rows * cols);
|
colors.resize(rows * cols);
|
||||||
|
UpdateBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the list of recent colors
|
/// Get the list of recent colors
|
||||||
|
@ -350,9 +332,7 @@ public:
|
||||||
colors.pop_back();
|
colors.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
background_valid = false;
|
UpdateBitmap();
|
||||||
|
|
||||||
Refresh(false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue