mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
implemented ColorValueViewer
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@56 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -8,4 +8,60 @@
|
||||
|
||||
#include <render/value/color.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
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
|
||||
}
|
||||
|
||||
@@ -10,8 +10,19 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <render/value/viewer.hpp>
|
||||
#include <data/field/color.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
// ----------------------------------------------------------------------------- : 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user