diff --git a/src/mse.vcproj b/src/mse.vcproj index 5a4eba23..5c81bd9c 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -1144,6 +1144,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -// ----------------------------------------------------------------------------- : +DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP); + +// ----------------------------------------------------------------------------- : ColorValueViewer + +void ColorValueViewer::draw(RotatedDC& dc) { + // draw in the value color + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(value().value.get()); + if (nativeLook()) { + // native look + // find name of color + String color_name = _("Custom"); + if (field().default_script && value().value.isDefault()) { + color_name = field().default_name; + } else { + FOR_EACH_CONST(c, field().choices) { + if (value().value.get() == c->color) { + color_name = capitalize(c->name); + break; + } + } + } + // draw name and color + dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); + dc.DrawRectangle(RealRect(style().left, style().top, 40, style().height)); + dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + dc.SetPen(*wxTRANSPARENT_PEN); + dc.DrawRectangle(style().getRect() + RealRect(40, 0, -40, 0)); + dc.DrawText(color_name, style().getPos() + RealSize(43, 3)); + } else { + // do we need clipping? + bool clip = style().left_width < style().width && style().right_width < style().width && + style().top_width < style().height && style().bottom_width < style().height; + if (clip) { + // clip away the inside of the rectangle + wxRegion r = dc.tr(style().getRect()); + r.Subtract(dc.tr(RealRect( + style().left + style().left_width, + style().top + style().top_width, + style().width - style().left_width - style().right_width, + style().height - style().top_width - style().bottom_width + ))); + dc.getDC().SetClippingRegion(r); + } + dc.DrawRoundedRectangle(style().getRect(), style().radius); + if (clip) dc.getDC().DestroyClippingRegion(); + } +} + +bool ColorValueViewer::containsPoint(const RealPoint& p) const { + // distance to each side + double left = p.x - style().left, right = style().left + style().width - p.x - 1; + double top = p.y - style().top, bottom = style().top + style().height - p.y - 1; + return left >= 0 && right >= 0 && top >= 0 && bottom >= 0 && // inside bounding box + (left < style().left_width || right < style().right_width || // inside horizontal border + top < style().top_width || bottom < style().bottom_width); // inside vertical border +} diff --git a/src/render/value/color.hpp b/src/render/value/color.hpp index 38e9cedc..2c7c6bbf 100644 --- a/src/render/value/color.hpp +++ b/src/render/value/color.hpp @@ -10,8 +10,19 @@ // ----------------------------------------------------------------------------- : Includes #include +#include +#include -// ----------------------------------------------------------------------------- : +// ----------------------------------------------------------------------------- : ColorValueViewer + +/// Viewer that displays an color value +class ColorValueViewer : public ValueViewer { + public: + DECLARE_VALUE_VIEWER(Color) : ValueViewer(parent,style) {} + + virtual void draw(RotatedDC& dc); + virtual bool containsPoint(const RealPoint& p) const; +}; // ----------------------------------------------------------------------------- : EOF diff --git a/src/render/value/image.hpp b/src/render/value/image.hpp index b394318c..bcb89d97 100644 --- a/src/render/value/image.hpp +++ b/src/render/value/image.hpp @@ -20,12 +20,12 @@ class ImageValueViewer : public ValueViewer { public: DECLARE_VALUE_VIEWER(Image) : ValueViewer(parent,style) {} - void draw(RotatedDC& dc); + virtual void draw(RotatedDC& dc); - bool containsPoint(const RealPoint& p) const; + virtual bool containsPoint(const RealPoint& p) const; - void onValueChange(); - void onStyleChange(); + virtual void onValueChange(); + virtual void onStyleChange(); private: Bitmap bitmap; diff --git a/src/render/value/viewer.cpp b/src/render/value/viewer.cpp index 8c2927ec..ac44db89 100644 --- a/src/render/value/viewer.cpp +++ b/src/render/value/viewer.cpp @@ -48,6 +48,10 @@ void ValueViewer::drawFieldBorder(RotatedDC& dc) { } } +bool ValueViewer::nativeLook() const { + return viewer.nativeLook(); +} + // ----------------------------------------------------------------------------- : Development/debug #ifdef _DEBUG @@ -72,8 +76,9 @@ void ValueViewer::drawFieldBorder(RotatedDC& dc) { ValueViewerP ChoiceStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP BooleanStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP MultipleChoiceStyle::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } -ValueViewerP ColorStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } +//ValueViewerP ColorStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } //ValueViewerP ImageStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } +IMPLEMENT_MAKE_VIEWER(Color); IMPLEMENT_MAKE_VIEWER(Image); ValueViewerP SymbolStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP TextStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } diff --git a/src/util/defaultable.hpp b/src/util/defaultable.hpp index 43baa8ef..944c007f 100644 --- a/src/util/defaultable.hpp +++ b/src/util/defaultable.hpp @@ -31,6 +31,7 @@ class Defaultable { /// Get access to the value inline const T& operator () () const { return value; } + inline const T& get () const { return value; } /// Is this value in the default state? inline bool isDefault() const { return is_default; } diff --git a/src/util/real_point.hpp b/src/util/real_point.hpp index 2655c5b7..f1265ef8 100644 --- a/src/util/real_point.hpp +++ b/src/util/real_point.hpp @@ -93,6 +93,9 @@ class RealRect { /// Size of the rectangle RealSize size; + inline RealRect(const wxRect& rect) + : position(rect.x, rect.y), size(rect.width, rect.height) + {} inline RealRect(const RealPoint& position, const RealSize& size) : position(position), size(size) {} @@ -107,6 +110,10 @@ class RealRect { inline RealRect grow(double amount) { return RealRect(position.x - amount, position.y - amount, size.width + 2 * amount, size.height + 2 * amount); } + + inline RealRect operator + (const RealRect& r) const { + return RealRect(position + r.position, size + r.size); + } }; // ----------------------------------------------------------------------------- : Operators diff --git a/src/util/rotation.hpp b/src/util/rotation.hpp index 0d564554..22a02743 100644 --- a/src/util/rotation.hpp +++ b/src/util/rotation.hpp @@ -136,6 +136,8 @@ class RotatedDC : public Rotation { RealSize GetTextExtent(const String& text); + inline wxDC& getDC() { return dc; } + private: wxDC& dc; ///< The actual dc bool high_quality; ///< Drawing using our own anti aliassing?