mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
added overdrawDC for drawing selection
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@107 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
CardViewer::CardViewer(Window* parent, int id, long style)
|
||||
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, style)
|
||||
, up_to_date(false)
|
||||
{}
|
||||
|
||||
wxSize CardViewer::DoGetBestSize() const {
|
||||
@@ -29,17 +30,54 @@ wxSize CardViewer::DoGetBestSize() const {
|
||||
|
||||
void CardViewer::onChange() {
|
||||
Refresh(false);
|
||||
up_to_date = false;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
DECLARE_DYNAMIC_ARG(bool, inOnPaint);
|
||||
IMPLEMENT_DYNAMIC_ARG(bool, inOnPaint, false);
|
||||
#endif
|
||||
|
||||
void CardViewer::onPaint(wxPaintEvent&) {
|
||||
#ifdef _DEBUG
|
||||
// we don't want recursion
|
||||
assert(!inOnPaint());
|
||||
WITH_DYNAMIC_ARG(inOnPaint, true);
|
||||
#endif
|
||||
wxSize cs = GetClientSize();
|
||||
if (!buffer.Ok() || buffer.GetWidth() != cs.GetWidth() || buffer.GetHeight() != cs.GetHeight()) {
|
||||
buffer = Bitmap(cs.GetWidth(), cs.GetHeight());
|
||||
up_to_date = false;
|
||||
}
|
||||
wxBufferedPaintDC dc(this, buffer);
|
||||
dc.BeginDrawing();
|
||||
draw(dc);
|
||||
dc.EndDrawing();
|
||||
if (!up_to_date) {
|
||||
up_to_date = true;
|
||||
dc.BeginDrawing();
|
||||
draw(dc);
|
||||
dc.EndDrawing();
|
||||
}
|
||||
}
|
||||
|
||||
// helper class for overdrawDC()
|
||||
class CardViewer::OverdrawDC : private wxClientDC, public wxBufferedDC {
|
||||
public:
|
||||
OverdrawDC(CardViewer* window)
|
||||
: wxClientDC(window)
|
||||
{
|
||||
wxBufferedDC::Init((wxClientDC*)this, window->buffer);
|
||||
wxBufferedDC::BeginDrawing();
|
||||
}
|
||||
~OverdrawDC() {
|
||||
wxBufferedDC::EndDrawing();
|
||||
}
|
||||
};
|
||||
|
||||
shared_ptr<DC> CardViewer::overdrawDC() {
|
||||
#ifdef _DEBUG
|
||||
// don't call from onPaint
|
||||
assert(!inOnPaint());
|
||||
#endif
|
||||
return shared_ptr<DC>((wxBufferedDC*)(new OverdrawDC(this)));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
@@ -19,6 +19,10 @@ class CardViewer : public wxControl, public DataViewer {
|
||||
public:
|
||||
CardViewer(Window* parent, int id, long style = 0);
|
||||
|
||||
/// Get a dc to draw on the card outside onPaint
|
||||
/** May NOT be called while in onPaint/draw */
|
||||
shared_ptr<DC> overdrawDC();
|
||||
|
||||
protected:
|
||||
/// Return the desired size of control
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
@@ -30,7 +34,10 @@ class CardViewer : public wxControl, public DataViewer {
|
||||
|
||||
void onPaint(wxPaintEvent&);
|
||||
|
||||
Bitmap buffer; /// < Off-screen buffer we draw to
|
||||
Bitmap buffer; ///< Off-screen buffer we draw to
|
||||
bool up_to_date; ///< Is the buffer up to date?
|
||||
|
||||
class OverdrawDC;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
Reference in New Issue
Block a user