mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
redrawing of editors (for drop down lists)
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@155 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <gui/control/card_viewer.hpp>
|
#include <gui/control/card_viewer.hpp>
|
||||||
#include <data/stylesheet.hpp>
|
#include <data/stylesheet.hpp>
|
||||||
|
#include <render/value/viewer.hpp>
|
||||||
#include <wx/dcbuffer.h>
|
#include <wx/dcbuffer.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Events
|
// ----------------------------------------------------------------------------- : Events
|
||||||
@@ -29,9 +30,14 @@ wxSize CardViewer::DoGetBestSize() const {
|
|||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardViewer::onChange() {
|
void CardViewer::redraw(const ValueViewer& v) {
|
||||||
Refresh(false);
|
|
||||||
up_to_date = false;
|
up_to_date = false;
|
||||||
|
RefreshRect(v.boundingBox(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardViewer::onChange() {
|
||||||
|
up_to_date = false;
|
||||||
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardViewer::onChangeSize() {
|
void CardViewer::onChangeSize() {
|
||||||
@@ -43,7 +49,6 @@ void CardViewer::onChangeSize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
DECLARE_DYNAMIC_ARG(bool, inOnPaint);
|
DECLARE_DYNAMIC_ARG(bool, inOnPaint);
|
||||||
IMPLEMENT_DYNAMIC_ARG(bool, inOnPaint, false);
|
IMPLEMENT_DYNAMIC_ARG(bool, inOnPaint, false);
|
||||||
@@ -61,6 +66,7 @@ void CardViewer::onPaint(wxPaintEvent&) {
|
|||||||
up_to_date = false;
|
up_to_date = false;
|
||||||
}
|
}
|
||||||
wxBufferedPaintDC dc(this, buffer);
|
wxBufferedPaintDC dc(this, buffer);
|
||||||
|
dc.SetClippingRegion(GetUpdateRegion());
|
||||||
if (!up_to_date) {
|
if (!up_to_date) {
|
||||||
up_to_date = true;
|
up_to_date = true;
|
||||||
dc.BeginDrawing();
|
dc.BeginDrawing();
|
||||||
@@ -69,6 +75,14 @@ void CardViewer::onPaint(wxPaintEvent&) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||||
|
if (shouldDraw(v)) v.draw(dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CardViewer::shouldDraw(const ValueViewer& v) const {
|
||||||
|
return GetUpdateRegion().Contains((wxRect)v.boundingBox()) != wxOutRegion;
|
||||||
|
}
|
||||||
|
|
||||||
// helper class for overdrawDC()
|
// helper class for overdrawDC()
|
||||||
class CardViewer::OverdrawDC : private wxClientDC, public wxBufferedDC {
|
class CardViewer::OverdrawDC : private wxClientDC, public wxBufferedDC {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ class CardViewer : public wxControl, public DataViewer {
|
|||||||
/** May NOT be called while in onPaint/draw */
|
/** May NOT be called while in onPaint/draw */
|
||||||
shared_ptr<DC> overdrawDC();
|
shared_ptr<DC> overdrawDC();
|
||||||
|
|
||||||
|
/// Invalidate and redraw (the area of) a single value viewer
|
||||||
|
void redraw(const ValueViewer&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Return the desired size of control
|
/// Return the desired size of control
|
||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
@@ -37,6 +40,11 @@ class CardViewer : public wxControl, public DataViewer {
|
|||||||
virtual void onChange();
|
virtual void onChange();
|
||||||
virtual void onChangeSize();
|
virtual void onChangeSize();
|
||||||
|
|
||||||
|
/// Should the given viewer be drawn?
|
||||||
|
bool shouldDraw(const ValueViewer&) const;
|
||||||
|
|
||||||
|
virtual void drawViewer(RotatedDC& dc, ValueViewer& v);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_EVENT_TABLE();
|
DECLARE_EVENT_TABLE();
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ void NativeLookEditor::draw(DC& dc) {
|
|||||||
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
|
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
|
||||||
}
|
}
|
||||||
void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||||
|
if (!shouldDraw(v)) return;
|
||||||
// draw background
|
// draw background
|
||||||
Style& s = *v.getStyle();
|
Style& s = *v.getStyle();
|
||||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
|||||||
@@ -29,10 +29,6 @@ void TextCtrl::draw(DC& dc) {
|
|||||||
RotatedDC rdc(dc, getRotation(), false);
|
RotatedDC rdc(dc, getRotation(), false);
|
||||||
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||||
}
|
}
|
||||||
void TextCtrl::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
|
||||||
// draw viewer
|
|
||||||
v.draw(dc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TextCtrl::setValue(String* value) {
|
void TextCtrl::setValue(String* value) {
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class TextCtrl : public DataEditor {
|
|||||||
virtual Rotation getRotation() const;
|
virtual Rotation getRotation() const;
|
||||||
|
|
||||||
virtual void draw(DC& dc);
|
virtual void draw(DC& dc);
|
||||||
virtual void drawViewer(RotatedDC& dc, ValueViewer& v);
|
|
||||||
|
|
||||||
/// When an action is received, change the underlying value
|
/// When an action is received, change the underlying value
|
||||||
virtual void onAction(const Action&, bool undone);
|
virtual void onAction(const Action&, bool undone);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <gui/util.hpp>
|
#include <gui/util.hpp>
|
||||||
#include <render/value/viewer.hpp>
|
#include <render/value/viewer.hpp>
|
||||||
#include <render/card/viewer.hpp>
|
#include <render/card/viewer.hpp>
|
||||||
|
#include <gui/value/editor.hpp>
|
||||||
#include <util/rotation.hpp>
|
#include <util/rotation.hpp>
|
||||||
#include <gfx/gfx.hpp>
|
#include <gfx/gfx.hpp>
|
||||||
#include <wx/dcbuffer.h>
|
#include <wx/dcbuffer.h>
|
||||||
@@ -208,7 +209,8 @@ int DropDownList::itemPosition(size_t item) const {
|
|||||||
|
|
||||||
void DropDownList::redrawArrowOnParent() {
|
void DropDownList::redrawArrowOnParent() {
|
||||||
if (viewer) {
|
if (viewer) {
|
||||||
// TODO
|
ValueEditor* e = viewer->getEditor();
|
||||||
|
if (e) e->redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ class ValueEditor {
|
|||||||
virtual void determineSize(bool force_fit = false) {}
|
virtual void determineSize(bool force_fit = false) {}
|
||||||
/// The editor is shown or hidden
|
/// The editor is shown or hidden
|
||||||
virtual void onShow(bool) {}
|
virtual void onShow(bool) {}
|
||||||
|
|
||||||
|
/// Redraw this viewer
|
||||||
|
virtual void redraw() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Utility
|
// ----------------------------------------------------------------------------- : Utility
|
||||||
@@ -106,6 +109,7 @@ class ValueEditor {
|
|||||||
#define DECLARE_VALUE_EDITOR(Type) \
|
#define DECLARE_VALUE_EDITOR(Type) \
|
||||||
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \
|
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \
|
||||||
virtual ValueEditor* getEditor() { return this; } \
|
virtual ValueEditor* getEditor() { return this; } \
|
||||||
|
virtual void redraw(); \
|
||||||
private: \
|
private: \
|
||||||
inline DataEditor& editor() const { \
|
inline DataEditor& editor() const { \
|
||||||
return static_cast<DataEditor&>(viewer); \
|
return static_cast<DataEditor&>(viewer); \
|
||||||
@@ -113,6 +117,9 @@ class ValueEditor {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
#define IMPLEMENT_VALUE_EDITOR(Type) \
|
#define IMPLEMENT_VALUE_EDITOR(Type) \
|
||||||
|
void Type##ValueEditor::redraw() { \
|
||||||
|
editor().redraw(*this); \
|
||||||
|
} \
|
||||||
Type##ValueEditor::Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
|
Type##ValueEditor::Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
|
||||||
: Type##ValueViewer(parent, style)
|
: Type##ValueViewer(parent, style)
|
||||||
|
|
||||||
|
|||||||
@@ -506,7 +506,7 @@ void TextValueEditor::moveSelection(IndexType t, size_t new_end, bool also_move_
|
|||||||
if (ensureCaretVisible()) {
|
if (ensureCaretVisible()) {
|
||||||
// we can't redraw just the selection because we must scroll
|
// we can't redraw just the selection because we must scroll
|
||||||
updateScrollbar();
|
updateScrollbar();
|
||||||
// editor.refreshEditor();
|
redraw();
|
||||||
} else {
|
} else {
|
||||||
// draw new selection
|
// draw new selection
|
||||||
v.drawSelection(rdc, style(), selection_start_i, selection_end_i);
|
v.drawSelection(rdc, style(), selection_start_i, selection_end_i);
|
||||||
@@ -605,7 +605,7 @@ void TextValueEditor::determineSize(bool force_fit) {
|
|||||||
style().top - 1,
|
style().top - 1,
|
||||||
sbw,
|
sbw,
|
||||||
style().height + 2);
|
style().height + 2);
|
||||||
// r.reset();
|
v.reset();
|
||||||
} else {
|
} else {
|
||||||
// Height depends on font
|
// Height depends on font
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
@@ -637,7 +637,7 @@ void TextValueEditor::scrollTo(int pos) {
|
|||||||
v.scrollTo(pos);
|
v.scrollTo(pos);
|
||||||
// move the cursor if needed
|
// move the cursor if needed
|
||||||
// refresh
|
// refresh
|
||||||
// viewer.onChange();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextValueEditor::ensureCaretVisible() {
|
bool TextValueEditor::ensureCaretVisible() {
|
||||||
|
|||||||
Reference in New Issue
Block a user