Commit 8e590ab3 authored by twanvl's avatar twanvl

Cleaned up handling of what things should be drawn by using the DrawWhat enumeration type.

parent 2a0933a1
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2008 Twan van Laarhoven and "coppro" |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_DRAW_WHAT
#define HEADER_DATA_DRAW_WHAT
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- : DrawWhat
/// What should be drawn?
enum DrawWhat
{ DRAW_NOTHING = 0x00
, DRAW_NORMAL = 0x01 // draw normal things, like the text
, DRAW_BORDERS = 0x10 // draw editor stuff, such as borders/lines, can be disabled.
, DRAW_BOXES = 0x20 // draw editor stuff, such as borders/lines, can be disabled.
, DRAW_EDITING = 0x40 // draw other editor stuff, can be disabled.
, DRAW_ERRORS = 0x80 // draw error indicators, can't be disabled
, DRAW_ACTIVE = 0x100 // draw active editor stuff, such as hidden separators and atom highlights
, DRAW_NATIVELOOK = 0x200 // use a native look
};
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -39,26 +39,24 @@ ValueViewerP DataEditor::makeViewer(const StyleP& style) { ...@@ -39,26 +39,24 @@ ValueViewerP DataEditor::makeViewer(const StyleP& style) {
// ----------------------------------------------------------------------------- : Utility for ValueViewers // ----------------------------------------------------------------------------- : Utility for ValueViewers
bool DataEditor::drawBorders() const { DrawWhat DataEditor::drawWhat(const ValueViewer* viewer) const {
return !nativeLook() && int what = DRAW_NORMAL
settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_borders(); | DRAW_ACTIVE * viewerIsCurrent(viewer);
} if (nativeLook()) {
bool DataEditor::drawEditing() const { what |= DRAW_BOXES | DRAW_EDITING | DRAW_NATIVELOOK;
return nativeLook() || } else {
settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_draw_editing(); StyleSheetSettings& ss = settings.stylesheetSettingsFor(set->stylesheetFor(card));
} what |= DRAW_BORDERS * ss.card_borders()
bool DataEditor::drawFocus() const { | (DRAW_BOXES | DRAW_EDITING) * ss.card_draw_editing()
return FindFocus() == this; | DRAW_ERRORS;
}
return (DrawWhat)what;
} }
wxPen DataEditor::borderPen(bool active) const { bool DataEditor::viewerIsCurrent(const ValueViewer* viewer) const {
return active ? wxPen(Color(0,128,255), 1, wxSOLID) return viewer == current_viewer && FindFocus() == this;
: wxPen(Color(128,128,128), 1, wxDOT);
} }
ValueViewer* DataEditor::focusedViewer() const {
return FindFocus() == this ? current_viewer : nullptr;
}
void DataEditor::addAction(Action* action) { void DataEditor::addAction(Action* action) {
set->actions.addAction(action); set->actions.addAction(action);
......
...@@ -24,11 +24,8 @@ class DataEditor : public CardViewer { ...@@ -24,11 +24,8 @@ class DataEditor : public CardViewer {
// --------------------------------------------------- : Utility for ValueViewers/Editors // --------------------------------------------------- : Utility for ValueViewers/Editors
virtual bool drawBorders() const; virtual DrawWhat drawWhat(const ValueViewer*) const;
virtual bool drawEditing() const; virtual bool viewerIsCurrent(const ValueViewer*) const;
virtual bool drawFocus() const;
virtual wxPen borderPen(bool active) const;
virtual ValueViewer* focusedViewer() const;
virtual void addAction(Action* action); virtual void addAction(Action* action);
inline SetP getSetForActions() { return set; } inline SetP getSetForActions() { return set; }
......
...@@ -23,7 +23,6 @@ class NativeLookEditor : public DataEditor { ...@@ -23,7 +23,6 @@ class NativeLookEditor : public DataEditor {
/// Uses a native look /// Uses a native look
virtual bool nativeLook() const { return true; } virtual bool nativeLook() const { return true; }
virtual bool drawBorders() const { return false; }
virtual Rotation getRotation() const; virtual Rotation getRotation() const;
virtual void draw(DC& dc); virtual void draw(DC& dc);
......
...@@ -50,7 +50,6 @@ class TextCtrl : public DataEditor { ...@@ -50,7 +50,6 @@ class TextCtrl : public DataEditor {
/// Uses a native look /// Uses a native look
virtual bool nativeLook() const { return true; } virtual bool nativeLook() const { return true; }
virtual bool drawBorders() const { return false; }
virtual Rotation getRotation() const; virtual Rotation getRotation() const;
virtual void draw(DC& dc); virtual void draw(DC& dc);
......
...@@ -1318,7 +1318,8 @@ void TextValueEditor::redrawWordListIndicators(bool toggling_dropdown) { ...@@ -1318,7 +1318,8 @@ void TextValueEditor::redrawWordListIndicators(bool toggling_dropdown) {
void TextValueEditor::drawWordListIndicators(RotatedDC& dc, bool redrawing) { void TextValueEditor::drawWordListIndicators(RotatedDC& dc, bool redrawing) {
if (word_lists.empty()) return; if (word_lists.empty()) return;
bool current = isCurrent(); DrawWhat what = viewer.drawWhat(this);
bool current = what & DRAW_ACTIVE;
// Draw lines around fields // Draw lines around fields
FOR_EACH(wl, word_lists) { FOR_EACH(wl, word_lists) {
RealRect& r = wl->rect; RealRect& r = wl->rect;
...@@ -1345,7 +1346,7 @@ void TextValueEditor::drawWordListIndicators(RotatedDC& dc, bool redrawing) { ...@@ -1345,7 +1346,7 @@ void TextValueEditor::drawWordListIndicators(RotatedDC& dc, bool redrawing) {
if (!redrawing) { if (!redrawing) {
wl->behind = dc.GetBackground(RealRect(r.right(), r.top() - 1, 10, r.height + 3)); wl->behind = dc.GetBackground(RealRect(r.right(), r.top() - 1, 10, r.height + 3));
} }
if (current || viewer.drawEditing()) { if (what & (DRAW_ACTIVE | DRAW_BOXES)) {
// draw rectangle around value // draw rectangle around value
dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(r.move(-1,-1,2,2)); dc.DrawRectangle(r.move(-1,-1,2,2));
...@@ -1368,7 +1369,7 @@ void TextValueEditor::drawWordListIndicators(RotatedDC& dc, bool redrawing) { ...@@ -1368,7 +1369,7 @@ void TextValueEditor::drawWordListIndicators(RotatedDC& dc, bool redrawing) {
small = (wl.get() != hovered_words); small = (wl.get() != hovered_words);
} }
if (small) { if (small) {
if (viewer.drawEditing()) { if (what & DRAW_BOXES) {
dc.DrawRectangle(RealRect(r.right(), r.top() - 1, 2, r.height + 2)); dc.DrawRectangle(RealRect(r.right(), r.top() - 1, 2, r.height + 2));
} }
} else { } else {
......
...@@ -1853,6 +1853,9 @@ ...@@ -1853,6 +1853,9 @@
<Filter <Filter
Name="aux" Name="aux"
Filter=""> Filter="">
<File
RelativePath=".\data\draw_what.hpp">
</File>
<File <File
RelativePath=".\data\export_template.cpp"> RelativePath=".\data\export_template.cpp">
</File> </File>
......
...@@ -96,13 +96,21 @@ void DataViewer::updateStyles(bool only_content_dependent) { ...@@ -96,13 +96,21 @@ void DataViewer::updateStyles(bool only_content_dependent) {
// ----------------------------------------------------------------------------- : Utility for ValueViewers // ----------------------------------------------------------------------------- : Utility for ValueViewers
bool DataViewer::nativeLook() const { return false; } bool DataViewer::nativeLook() const {
bool DataViewer::drawBorders() const { return false; } return false;
bool DataViewer::drawEditing() const { return false; } }
bool DataViewer::drawFocus() const { return false; }
wxPen DataViewer::borderPen(bool) const { return wxPen(); } DrawWhat DataViewer::drawWhat(const ValueViewer*) const {
ValueViewer* DataViewer::focusedViewer() const { return nullptr; } return (DrawWhat)(DRAW_NORMAL | nativeLook() * DRAW_NATIVELOOK);
Context& DataViewer::getContext() const { return set->getContext(card); } }
bool DataViewer::viewerIsCurrent(const ValueViewer*) const {
return false;
}
Context& DataViewer::getContext() const {
return set->getContext(card);
}
Rotation DataViewer::getRotation() const { Rotation DataViewer::getRotation() const {
if (!stylesheet) stylesheet = set->stylesheet; if (!stylesheet) stylesheet = set->stylesheet;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/rotation.hpp> #include <util/rotation.hpp>
#include <data/set.hpp> #include <data/set.hpp>
#include <data/draw_what.hpp>
DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Style);
DECLARE_POINTER_TYPE(ValueViewer); DECLARE_POINTER_TYPE(ValueViewer);
...@@ -39,20 +40,11 @@ class DataViewer : public SetView { ...@@ -39,20 +40,11 @@ class DataViewer : public SetView {
/// Should the ValueViewers use a platform native look and feel? /// Should the ValueViewers use a platform native look and feel?
/** false by default, can be overloaded */ /** false by default, can be overloaded */
virtual bool nativeLook() const; virtual bool nativeLook() const;
/// Should field borders be drawn? /// Which things should be drawn for the given viewer?
/** false by default, can be overloaded */ /** can be overloaded */
virtual bool drawBorders() const; virtual DrawWhat drawWhat(const ValueViewer*) const;
/// Should editing specific things be drawn? /// Is the given viewer currently selected?
/** false by default, can be overloaded */ virtual bool viewerIsCurrent(const ValueViewer*) const;
virtual bool drawEditing() const;
/// Should focus only editing specific things be drawn?
/** false by default, can be overloaded */
virtual bool drawFocus() const;
/// Pens for drawing field borders (only called if drawBorders())
virtual wxPen borderPen(bool active) const;
/// The viewer that is currently focused, may be null
/** null by default, can be overloaded */
virtual ValueViewer* focusedViewer() const;
/// Get a script context to use for scripts in the viewers /// Get a script context to use for scripts in the viewers
Context& getContext() const; Context& getContext() const;
/// The rotation to use /// The rotation to use
......
...@@ -39,17 +39,19 @@ void AtomTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, co ...@@ -39,17 +39,19 @@ void AtomTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, co
void ErrorTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { void ErrorTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const {
// Draw wavy underline // Draw wavy underline
dc.SetPen(*wxRED_PEN); if (what & DRAW_ERRORS) {
RealPoint pos = rect.bottomLeft() - dc.trInvS(RealSize(0,2)); dc.SetPen(*wxRED_PEN);
RealSize dx(dc.trInvS(2), 0), dy(0, dc.trInvS(1)); RealPoint pos = rect.bottomLeft() - dc.trInvS(RealSize(0,2));
while (pos.x + 1 < rect.right()) { RealSize dx(dc.trInvS(2), 0), dy(0, dc.trInvS(1));
dc.DrawLine(pos - dy, pos + dx + dy); while (pos.x + 1 < rect.right()) {
pos += dx; dc.DrawLine(pos - dy, pos + dx + dy);
dy = -dy; pos += dx;
} dy = -dy;
if (pos.x < rect.right()) { }
// final piece if (pos.x < rect.right()) {
dc.DrawLine(pos - dy, pos + dx / 2); // final piece
dc.DrawLine(pos - dy, pos + dx / 2);
}
} }
// Draw the contents // Draw the contents
CompoundTextElement::draw(dc, scale, rect, xs, what, start, end); CompoundTextElement::draw(dc, scale, rect, xs, what, start, end);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <util/rotation.hpp> #include <util/rotation.hpp>
#include <util/real_point.hpp> #include <util/real_point.hpp>
#include <data/font.hpp> #include <data/font.hpp>
#include <data/draw_what.hpp>
DECLARE_POINTER_TYPE(TextElement); DECLARE_POINTER_TYPE(TextElement);
DECLARE_POINTER_TYPE(Font); DECLARE_POINTER_TYPE(Font);
...@@ -22,14 +23,6 @@ class SymbolFontRef; ...@@ -22,14 +23,6 @@ class SymbolFontRef;
// ----------------------------------------------------------------------------- : TextElement // ----------------------------------------------------------------------------- : TextElement
/// What should be drawn?
enum DrawWhat
{ DRAW_NOTHING = 0x00
, DRAW_NORMAL = 0x01 // draw normal things, like the text
, DRAW_BORDERS = 0x02 // draw editor stuff, such as borders/lines
, DRAW_ACTIVE = 0x04 // draw active editor stuff, such as hidden separators and atom highlights
};
/// Information on a linebreak /// Information on a linebreak
enum LineBreak enum LineBreak
{ BREAK_NO // no line break ever { BREAK_NO // no line break ever
......
...@@ -70,6 +70,8 @@ TextViewer::~TextViewer() {} ...@@ -70,6 +70,8 @@ TextViewer::~TextViewer() {}
void TextViewer::draw(RotatedDC& dc, const TextStyle& style, DrawWhat what) { void TextViewer::draw(RotatedDC& dc, const TextStyle& style, DrawWhat what) {
assert(!lines.empty()); assert(!lines.empty());
// draw anything?
if (what == DRAW_NOTHING) return;
// separator lines? // separator lines?
// do this first, so pen is still set from drawing the field border // do this first, so pen is still set from drawing the field border
if (what & DRAW_BORDERS) { if (what & DRAW_BORDERS) {
......
...@@ -18,6 +18,7 @@ DECLARE_TYPEOF_COLLECTION(wxPoint); ...@@ -18,6 +18,7 @@ DECLARE_TYPEOF_COLLECTION(wxPoint);
IMPLEMENT_VALUE_VIEWER(Image); IMPLEMENT_VALUE_VIEWER(Image);
void ImageValueViewer::draw(RotatedDC& dc) { void ImageValueViewer::draw(RotatedDC& dc) {
DrawWhat what = viewer.drawWhat(this);
// reset? // reset?
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height)); int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
int a = dc.trAngle(0); //% TODO : Add getAngle()? int a = dc.trAngle(0); //% TODO : Add getAngle()?
...@@ -45,8 +46,8 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -45,8 +46,8 @@ void ImageValueViewer::draw(RotatedDC& dc) {
if (!image.Ok() && style().default_image.isReady()) { if (!image.Ok() && style().default_image.isReady()) {
image = style().default_image.generate(GeneratedImage::Options(w, h, &getStylePackage(), &getLocalPackage())); image = style().default_image.generate(GeneratedImage::Options(w, h, &getStylePackage(), &getLocalPackage()));
is_default = true; is_default = true;
if (viewer.drawEditing()) { if (what & DRAW_EDITING) {
bitmap = imagePlaceholder(dc, w, h, image, viewer.drawEditing()); bitmap = imagePlaceholder(dc, w, h, image, what & DRAW_EDITING);
if (alpha_mask || a) { if (alpha_mask || a) {
image = bitmap.ConvertToImage(); // we need to convert back to an image image = bitmap.ConvertToImage(); // we need to convert back to an image
} else { } else {
...@@ -57,7 +58,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -57,7 +58,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
// checkerboard placeholder // checkerboard placeholder
if (!image.Ok() && !bitmap.Ok() && style().width > 40) { if (!image.Ok() && !bitmap.Ok() && style().width > 40) {
// placeholder bitmap // placeholder bitmap
bitmap = imagePlaceholder(dc, w, h, wxNullImage, viewer.drawEditing()); bitmap = imagePlaceholder(dc, w, h, wxNullImage, what & DRAW_EDITING);
if (alpha_mask || a) { if (alpha_mask || a) {
// we need to convert back to an image // we need to convert back to an image
image = bitmap.ConvertToImage(); image = bitmap.ConvertToImage();
...@@ -83,8 +84,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -83,8 +84,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
void ImageValueViewer::drawFieldBorder(RotatedDC& dc) { void ImageValueViewer::drawFieldBorder(RotatedDC& dc) {
if (!alpha_mask) { if (!alpha_mask) {
ValueViewer::drawFieldBorder(dc); ValueViewer::drawFieldBorder(dc);
} else if (viewer.drawBorders() && field().editable) { } else if (setFieldBorderPen(dc)) {
dc.SetPen(viewer.borderPen(isCurrent()));
dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxTRANSPARENT_BRUSH);
vector<wxPoint> points; vector<wxPoint> points;
alpha_mask->convexHull(points); alpha_mask->convexHull(points);
......
...@@ -32,14 +32,10 @@ void TextValueViewer::draw(RotatedDC& dc) { ...@@ -32,14 +32,10 @@ void TextValueViewer::draw(RotatedDC& dc) {
v.prepare(dc, value().value(), style(), viewer.getContext()); v.prepare(dc, value().value(), style(), viewer.getContext());
dc.setStretch(getStretch()); dc.setStretch(getStretch());
} }
if (viewer.drawFocus() && isCurrent()) { DrawWhat what = viewer.drawWhat(this);
v.draw(dc, style(), DRAW_ACTIVE); v.draw(dc, style(), (DrawWhat)(what & DRAW_ACTIVE));
} setFieldBorderPen(dc);
if (viewer.drawBorders()) dc.SetPen(viewer.borderPen(isCurrent())); v.draw(dc, style(), (DrawWhat)(what & ~DRAW_ACTIVE));
v.draw(dc, style(), (DrawWhat)(
DRAW_NORMAL
| (viewer.drawBorders() ? DRAW_BORDERS : 0)
));
} }
void TextValueViewer::onValueChange() { void TextValueViewer::onValueChange() {
......
...@@ -40,9 +40,19 @@ Rotation ValueViewer::getRotation() const { ...@@ -40,9 +40,19 @@ Rotation ValueViewer::getRotation() const {
return Rotation(getStyle()->angle, getStyle()->getExternalRect(), 1.0, getStretch()); return Rotation(getStyle()->angle, getStyle()->getExternalRect(), 1.0, getStretch());
} }
bool ValueViewer::setFieldBorderPen(RotatedDC& dc) {
if (!getField()->editable) return false;
DrawWhat what = viewer.drawWhat(this);
if (!(what & DRAW_BORDERS)) return false;
dc.SetPen( (what & DRAW_ACTIVE)
? wxPen(Color(0,128,255), 1, wxSOLID)
: wxPen(Color(128,128,128), 1, wxDOT)
);
return true;
}
void ValueViewer::drawFieldBorder(RotatedDC& dc) { void ValueViewer::drawFieldBorder(RotatedDC& dc) {
if (viewer.drawBorders() && getField()->editable) { if (setFieldBorderPen(dc)) {
dc.SetPen(viewer.borderPen(isCurrent()));
dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(dc.getInternalRect().grow(dc.trInvS(1))); dc.DrawRectangle(dc.getInternalRect().grow(dc.trInvS(1)));
} }
...@@ -56,7 +66,7 @@ bool ValueViewer::nativeLook() const { ...@@ -56,7 +66,7 @@ bool ValueViewer::nativeLook() const {
return viewer.nativeLook(); return viewer.nativeLook();
} }
bool ValueViewer::isCurrent() const { bool ValueViewer::isCurrent() const {
return viewer.focusedViewer() == this; return viewer.viewerIsCurrent(this);
} }
void ValueViewer::onStyleChange(int changes) { void ValueViewer::onStyleChange(int changes) {
......
...@@ -75,6 +75,8 @@ class ValueViewer : public StyleListener { ...@@ -75,6 +75,8 @@ class ValueViewer : public StyleListener {
protected: protected:
ValueP valueP; ///< The value we are currently viewing ValueP valueP; ///< The value we are currently viewing
/// Set the pen for drawing the border, returns true if a border needs to be drawn
bool setFieldBorderPen(RotatedDC& dc);
/// Draws a border around the field /// Draws a border around the field
void drawFieldBorder(RotatedDC& dc); void drawFieldBorder(RotatedDC& dc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment