diff --git a/src/data/field.hpp b/src/data/field.hpp index 9ee7d282..35990c73 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -18,6 +18,11 @@ DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Value); +// for DataViewer/editor +class DataViewer; class DataEditor; +DECLARE_POINTER_TYPE(ValueViewer); +DECLARE_POINTER_TYPE(ValueEditor); + // ----------------------------------------------------------------------------- : Field /// Information on how to store a value @@ -74,6 +79,13 @@ class Style { Scriptable width, height; ///< Position of this field Scriptable visible; ///< Is this field visible? + /// Make a viewer object for values using this style + /** thisP is a smart pointer to this */ + virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP) = 0; + /// Make an editor object for values using this style + /** thisP is a smart pointer to this */ + virtual ValueEditorP makeEditor(DataEditor& parent, const StyleP& thisP) = 0; + private: DECLARE_REFLECTION_VIRTUAL(); }; @@ -107,8 +119,13 @@ template <> ValueP read_new(Reader&); // ----------------------------------------------------------------------------- : Utilities +#define DECLARE_FIELD_TYPE(Type) \ + virtual ValueP newValue(const FieldP& thisP) const; \ + virtual StyleP newStyle(const FieldP& thisP) const; \ + virtual String typeName() const + // implement newStyle and newValue -#define FIELD_TYPE(Type) \ +#define IMPLEMENT_FIELD_TYPE(Type) \ StyleP Type ## Field::newStyle(const FieldP& thisP) const { \ assert(thisP.get() == this); \ return new_shared1(static_pointer_cast(thisP)); \ @@ -118,8 +135,13 @@ template <> ValueP read_new(Reader&); return new_shared1(static_pointer_cast(thisP)); \ } +#define DECLARE_STYLE_TYPE(Type) \ + DECLARE_HAS_FIELD(Type) \ + virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP); \ + virtual ValueEditorP makeEditor(DataEditor& parent, const StyleP& thisP) + // implement field() which returns a field with the right (derived) type -#define HAS_FIELD(Type) \ +#define DECLARE_HAS_FIELD(Type) \ inline Type ## Field& field() const { \ return *static_cast(fieldP.get()); \ } diff --git a/src/data/field/boolean.cpp b/src/data/field/boolean.cpp index 83bcf223..a3a1efab 100644 --- a/src/data/field/boolean.cpp +++ b/src/data/field/boolean.cpp @@ -16,7 +16,7 @@ BooleanField::BooleanField() { choices->initIds(); } -FIELD_TYPE(Boolean) +IMPLEMENT_FIELD_TYPE(Boolean) String BooleanField::typeName() const { return _("boolean"); diff --git a/src/data/field/boolean.hpp b/src/data/field/boolean.hpp index 75bb24d2..0c27818d 100644 --- a/src/data/field/boolean.hpp +++ b/src/data/field/boolean.hpp @@ -20,13 +20,10 @@ DECLARE_POINTER_TYPE(BooleanField); class BooleanField : public ChoiceField { public: BooleanField(); + DECLARE_FIELD_TYPE(Boolean); // no extra data - - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; - + private: DECLARE_REFLECTION(); }; @@ -37,7 +34,7 @@ class BooleanField : public ChoiceField { class BooleanStyle : public ChoiceStyle { public: inline BooleanStyle(const ChoiceFieldP& field) : ChoiceStyle(field) {} - HAS_FIELD(Boolean) + DECLARE_STYLE_TYPE(Boolean); // no extra data @@ -51,7 +48,7 @@ class BooleanStyle : public ChoiceStyle { class BooleanValue : public ChoiceValue { public: inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {} - HAS_FIELD(Boolean) + DECLARE_HAS_FIELD(Boolean); // no extra data diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 8b7417ec..76776466 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -17,7 +17,7 @@ ChoiceField::ChoiceField() , default_name(_("Default")) {} -FIELD_TYPE(Choice) +IMPLEMENT_FIELD_TYPE(Choice) String ChoiceField::typeName() const { return _("choice"); diff --git a/src/data/field/choice.hpp b/src/data/field/choice.hpp index c4b5ed5a..12ac11d0 100644 --- a/src/data/field/choice.hpp +++ b/src/data/field/choice.hpp @@ -23,6 +23,7 @@ DECLARE_POINTER_TYPE(ChoiceField); class ChoiceField : public Field { public: ChoiceField(); + DECLARE_FIELD_TYPE(Choice); class Choice; typedef shared_ptr ChoiceP; @@ -32,11 +33,7 @@ class ChoiceField : public Field { OptionalScript default_script; ///< Script that generates the default value String initial; ///< Initial choice of a new value, or "" String default_name; ///< Name of "default" value - - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; - + private: DECLARE_REFLECTION(); }; @@ -111,7 +108,7 @@ enum ChoiceRenderStyle class ChoiceStyle : public Style { public: ChoiceStyle(const ChoiceFieldP& field); - HAS_FIELD(Choice) + DECLARE_STYLE_TYPE(Choice); ChoicePopupStyle popup_style; ///< Style of popups/menus ChoiceRenderStyle render_style; ///< Style of rendering @@ -133,7 +130,7 @@ class ChoiceStyle : public Style { class ChoiceValue : public Value { public: inline ChoiceValue(const ChoiceFieldP& field) : Value(field) {} - HAS_FIELD(Choice) + DECLARE_HAS_FIELD(Choice) Defaultable value; /// The name of the selected choice diff --git a/src/data/field/color.cpp b/src/data/field/color.cpp index 5ac5e027..9c60da91 100644 --- a/src/data/field/color.cpp +++ b/src/data/field/color.cpp @@ -17,7 +17,7 @@ ColorField::ColorField() , allow_custom(true) {} -FIELD_TYPE(Color) +IMPLEMENT_FIELD_TYPE(Color) String ColorField::typeName() const { return _("color"); diff --git a/src/data/field/color.hpp b/src/data/field/color.hpp index 44d279d2..7ab246e9 100644 --- a/src/data/field/color.hpp +++ b/src/data/field/color.hpp @@ -22,6 +22,7 @@ DECLARE_POINTER_TYPE(ColorField); class ColorField : public Field { public: ColorField(); + DECLARE_FIELD_TYPE(Color); class Choice; typedef shared_ptr ChoiceP; @@ -31,11 +32,7 @@ class ColorField : public Field { vector choices; ///< Color choices available bool allow_custom; ///< Are colors not in the list of choices allowed? String default_name; ///< Name of "default" value - - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; - + private: DECLARE_REFLECTION(); }; @@ -55,7 +52,7 @@ class ColorField::Choice { class ColorStyle : public Style { public: ColorStyle(const ColorFieldP& field); - HAS_FIELD(Color) + DECLARE_STYLE_TYPE(Color); int radius; ///< Radius of round corners UInt left_width; ///< Width of the colored region on the left side @@ -73,7 +70,7 @@ class ColorStyle : public Style { class ColorValue : public Value { public: inline ColorValue(const ColorFieldP& field) : Value(field) {} - HAS_FIELD(Color) + DECLARE_HAS_FIELD(Color) Defaultable value; ///< The value diff --git a/src/data/field/image.cpp b/src/data/field/image.cpp index edfdac70..1f31e998 100644 --- a/src/data/field/image.cpp +++ b/src/data/field/image.cpp @@ -10,7 +10,7 @@ // ----------------------------------------------------------------------------- : ImageField -FIELD_TYPE(Image) +IMPLEMENT_FIELD_TYPE(Image) String ImageField::typeName() const { return _("image"); diff --git a/src/data/field/image.hpp b/src/data/field/image.hpp index 15e4420a..817b980c 100644 --- a/src/data/field/image.hpp +++ b/src/data/field/image.hpp @@ -21,10 +21,7 @@ DECLARE_POINTER_TYPE(ImageField); class ImageField : public Field { public: // no extra data - - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; + DECLARE_FIELD_TYPE(Image); private: DECLARE_REFLECTION(); @@ -36,6 +33,7 @@ class ImageField : public Field { class ImageStyle : public Style { public: inline ImageStyle(const ImageFieldP& field) : Style(field) {} + DECLARE_STYLE_TYPE(Image); Scriptable mask_filename; ///< Filename for a mask image diff --git a/src/data/field/multiple_choice.cpp b/src/data/field/multiple_choice.cpp index 699e37f2..1b2590f5 100644 --- a/src/data/field/multiple_choice.cpp +++ b/src/data/field/multiple_choice.cpp @@ -15,7 +15,7 @@ MultipleChoiceField::MultipleChoiceField() , maximum_selection(1000000) {} -FIELD_TYPE(MultipleChoice) +IMPLEMENT_FIELD_TYPE(MultipleChoice) String MultipleChoiceField::typeName() const { return _("multiple choice"); diff --git a/src/data/field/multiple_choice.hpp b/src/data/field/multiple_choice.hpp index 1d5d1a3d..4d396991 100644 --- a/src/data/field/multiple_choice.hpp +++ b/src/data/field/multiple_choice.hpp @@ -20,13 +20,10 @@ DECLARE_POINTER_TYPE(MultipleChoiceField); class MultipleChoiceField : public ChoiceField { public: MultipleChoiceField(); + DECLARE_FIELD_TYPE(MultipleChoiceField); UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously? - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; - private: DECLARE_REFLECTION(); }; @@ -41,7 +38,7 @@ enum Direction { class MultipleChoiceStyle : public ChoiceStyle { public: MultipleChoiceStyle(const MultipleChoiceFieldP& field); - HAS_FIELD(MultipleChoice) + DECLARE_STYLE_TYPE(MultipleChoice); Direction direction; ///< In what direction are choices layed out? double spacing; ///< Spacing between choices (images) in pixels @@ -59,7 +56,7 @@ class MultipleChoiceStyle : public ChoiceStyle { class MultipleChoiceValue : public ChoiceValue { public: inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field) {} - HAS_FIELD(MultipleChoice) + DECLARE_HAS_FIELD(MultipleChoice); // no extra data diff --git a/src/data/field/symbol.cpp b/src/data/field/symbol.cpp index d2fc0901..07c39dbe 100644 --- a/src/data/field/symbol.cpp +++ b/src/data/field/symbol.cpp @@ -10,7 +10,7 @@ // ----------------------------------------------------------------------------- : SymbolField -FIELD_TYPE(Symbol) +IMPLEMENT_FIELD_TYPE(Symbol) String SymbolField::typeName() const { return _("symbol"); diff --git a/src/data/field/symbol.hpp b/src/data/field/symbol.hpp index c212aae6..baee7454 100644 --- a/src/data/field/symbol.hpp +++ b/src/data/field/symbol.hpp @@ -23,10 +23,7 @@ DECLARE_POINTER_TYPE(SymbolField); class SymbolField : public Field { public: // no extra data - - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; + DECLARE_FIELD_TYPE(Symbol); private: DECLARE_REFLECTION(); @@ -38,7 +35,7 @@ class SymbolField : public Field { class SymbolStyle : public Style { public: inline SymbolStyle(const SymbolFieldP& field) : Style(field) {} - HAS_FIELD(Symbol) + DECLARE_STYLE_TYPE(Symbol); class Variation; typedef shared_ptr VariationP; @@ -64,7 +61,7 @@ class SymbolStyle::Variation { class SymbolValue : public Value { public: inline SymbolValue(const SymbolFieldP& field) : Value(field) {} - HAS_FIELD(Symbol) + DECLARE_HAS_FIELD(Symbol) String filename; ///< Filename of the symbol (in the current package) diff --git a/src/data/field/text.cpp b/src/data/field/text.cpp index 8f48d3f4..2f5272c2 100644 --- a/src/data/field/text.cpp +++ b/src/data/field/text.cpp @@ -16,7 +16,7 @@ TextField::TextField() , default_name(_("Default")) {} -FIELD_TYPE(Text) +IMPLEMENT_FIELD_TYPE(Text) String TextField::typeName() const { return _("text"); diff --git a/src/data/field/text.hpp b/src/data/field/text.hpp index d236f7ac..c11af8ce 100644 --- a/src/data/field/text.hpp +++ b/src/data/field/text.hpp @@ -22,17 +22,14 @@ DECLARE_POINTER_TYPE(TextField); class TextField : public Field { public: TextField(); + DECLARE_FIELD_TYPE(Text); OptionalScript script; ///< Script to apply to all values OptionalScript default_script; ///< Script that generates the default value bool multi_line; ///< Are newlines allowed in the text? bool move_cursor_with_sort; ///< When the text is reordered by a script should the cursor position be updated? String default_name; ///< Name of "default" value - - virtual ValueP newValue(const FieldP& thisP) const; - virtual StyleP newStyle(const FieldP& thisP) const; - virtual String typeName() const; - + private: DECLARE_REFLECTION(); }; @@ -43,7 +40,7 @@ class TextField : public Field { class TextStyle : public Style { public: TextStyle(const TextFieldP&); - HAS_FIELD(Text) + DECLARE_STYLE_TYPE(Text); // FontInfo font; ///< Font to use for the text // SymbolFontInfo symbol_font; ///< Symbol font for symbols in the text @@ -70,7 +67,7 @@ class TextStyle : public Style { class TextValue : public Value { public: inline TextValue(const TextFieldP& field) : Value(field) {} - HAS_FIELD(Text) + DECLARE_HAS_FIELD(Text) Defaultable value; ///< The text of this value diff --git a/src/data/stylesheet.hpp b/src/data/stylesheet.hpp index 78cb096c..9766eec5 100644 --- a/src/data/stylesheet.hpp +++ b/src/data/stylesheet.hpp @@ -20,6 +20,8 @@ DECLARE_POINTER_TYPE(Game); class StyleSheet : public Packaged { public: GameP game; + double card_width; ///< The width of a card in pixels + double card_height; ///< The height of a card in pixels static String typeNameStatic(); virtual String typeName() const; diff --git a/src/gui/control/card_viewer.cpp b/src/gui/control/card_viewer.cpp new file mode 100644 index 00000000..09ac115f --- /dev/null +++ b/src/gui/control/card_viewer.cpp @@ -0,0 +1,35 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include + +// ----------------------------------------------------------------------------- : CardViewer + +CardViewer::CardViewer(Window* parent, int id, int style) + : wxControl(parent, id, wxDefaultPosition, wxDefaultSize, style) +{} + +wxSize CardViewer::DoGetBestSize() const { + wxSize ws = GetSize(), cs = GetClientSize(); + return wxSize(set->stylesheet->card_width, set->stylesheet->card_height) + ws - cs; +} + +void CardViewer::onPaint(wxPaintEvent&) { + wxBufferedPaintDC dc(this); + dc.BeginDrawing(); + draw(dc); + dc.EndDrawing(); +} + +// ----------------------------------------------------------------------------- : Event table + +BEGIN_EVENT_TABLE(CardViewer, wxControl) + EVT_PAINT (CardViewer::onPaint) +END_EVENT_TABLE () diff --git a/src/gui/control/card_viewer.hpp b/src/gui/control/card_viewer.hpp new file mode 100644 index 00000000..f9c0b24d --- /dev/null +++ b/src/gui/control/card_viewer.hpp @@ -0,0 +1,36 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_GUI_CONTROL_CARD_VIEWER +#define HEADER_GUI_CONTROL_CARD_VIEWER + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +// ----------------------------------------------------------------------------- : CardViewer + +/// A control to view a single card +class CardViewer : public wxControl, public DataViewer { + public: + CardViewer(Window* parent, int id, int style); + + protected: + /// Return the desired size of control + virtual wxSize DoGetBestSize() const; + + private: + DECLARE_EVENT_TABLE(); + + void onPaint(wxPaintEvent&); + void onSize(wxSizeEvent&); + + Bitmap buffer; /// < Off-screen buffer we draw to +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/main.cpp b/src/main.cpp index 3620a7e2..5cbac4d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,10 +42,10 @@ bool MSE::OnInit() { settings.read(); //Window* wnd = new SymbolWindow(nullptr); //GameP g = Game::byName(_("magic")) - //SetP s = new_shared(); - //s->open(_("test.mse-set")); - //Window* wnd = new SetWindow(nullptr, s); - Window* wnd = new WelcomeWindow(); + SetP s = new_shared(); + s->open(_("test.mse-set")); + Window* wnd = new SetWindow(nullptr, s); + //Window* wnd = new WelcomeWindow(); wnd->Show(); return true; diff --git a/src/mse.vcproj b/src/mse.vcproj index f08a1896..591fbc22 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -368,6 +368,12 @@ + + + + @@ -567,6 +573,58 @@ RelativePath=".\gui\welcome_window.hpp"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#include + +// ----------------------------------------------------------------------------- : DataViewer + + +// ----------------------------------------------------------------------------- : Drawing + +void DataViewer::draw(DC& dc) { +} +void DataViewer::draw(RotatedDC& dc) { +} + +// ----------------------------------------------------------------------------- : Utility for ValueViewers + +bool DataViewer::nativeLook() const { return false; } +bool DataViewer::drawBorders() const { return false; } +wxPen DataViewer::borderPen(bool) const { return wxPen(); } +Value* DataViewer::focusedValue() const { return nullptr; } + +// ----------------------------------------------------------------------------- : Setting data + + +// ----------------------------------------------------------------------------- : Viewers + +ValueViewerP DataViewer::makeViewer(const StyleP& style) { + return style->makeViewer(*this, style); +} + +void DataViewer::onAction(const Action&, bool undone) { + // TODO +} diff --git a/src/render/card/viewer.hpp b/src/render/card/viewer.hpp new file mode 100644 index 00000000..f5be98a6 --- /dev/null +++ b/src/render/card/viewer.hpp @@ -0,0 +1,72 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_RENDER_CARD_VIEWER +#define HEADER_RENDER_CARD_VIEWER + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include + +DECLARE_POINTER_TYPE(Style); +DECLARE_POINTER_TYPE(ValueViewer); + +// ----------------------------------------------------------------------------- : DataViewer + +/// A viewer can generate an image of some values, usually a card. +class DataViewer : public SetView { + public: + /// Rotation and zoom to use when drawing +// Rotation rotation; + + // --------------------------------------------------- : Drawing + + /// Draw the current (card/data) to the given dc + void draw(DC& dc); + /// Draw the current (card/data) to the given dc + virtual void draw(RotatedDC& dc); + + // --------------------------------------------------- : Utility for ValueViewers + + /// Should the ValueViewers use a platform native look and feel? + /** false by default, can be overloaded */ + virtual bool nativeLook() const; + /// Should field borders be drawn? + /** false by default, can be overloaded */ + virtual bool drawBorders() const; + /// Pens for drawing field borders (only called if drawBorders()) + virtual wxPen borderPen(bool active) const; + /// The value of the field that is currently focused, may be null + /** null by default, can be overloaded */ + virtual Value* focusedValue() const; + + // --------------------------------------------------- : Setting data + + /// Display a card in this viewer + void setCard(Card& card); + + // --------------------------------------------------- : The viewers + protected: + /// Set the styles for the data to be shown, recreating the viewers + void setStyles(IndexMap& styles); + /// Set the data to be shown in the viewers, refresh them + void setData(IndexMap& values); + + /// Create a viewer for the given style. + /** Can be overloaded to create a ValueEditor instead */ + virtual ValueViewerP makeViewer(const StyleP&); + + /// Update the viewers and forward actions + virtual void onAction(const Action&, bool undone); + + private: + vector viewers; ///< The viewers for the different values in the data +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/viewer.cpp b/src/render/value/viewer.cpp new file mode 100644 index 00000000..337e9348 --- /dev/null +++ b/src/render/value/viewer.cpp @@ -0,0 +1,45 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : ValueViewer + + +// ----------------------------------------------------------------------------- : Development/debug + +#ifdef _DEBUG + +// REMOVEME + +#include +#include +#include +#include +#include +#include +#include +#include + +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 ImageStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } +ValueViewerP SymbolStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } +ValueViewerP TextStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } + +ValueEditorP ChoiceStyle ::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } +ValueEditorP BooleanStyle ::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } +ValueEditorP MultipleChoiceStyle::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } +ValueEditorP ColorStyle ::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } +ValueEditorP ImageStyle ::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } +ValueEditorP SymbolStyle ::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } +ValueEditorP TextStyle ::makeEditor(DataEditor& parent, const StyleP& thisP) { return ValueEditorP(); } + +#endif \ No newline at end of file diff --git a/src/render/value/viewer.hpp b/src/render/value/viewer.hpp new file mode 100644 index 00000000..b38456f1 --- /dev/null +++ b/src/render/value/viewer.hpp @@ -0,0 +1,78 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2006 Twan van Laarhoven | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_RENDER_VALUE_VIEWER +#define HEADER_RENDER_VALUE_VIEWER + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include + +class DataViewer; +class ValueAction; +DECLARE_POINTER_TYPE(Style); +DECLARE_POINTER_TYPE(Value); + +// ----------------------------------------------------------------------------- : ValueViewer + +/// The virtual viewer control for a single field on a card (or in the set data) +/** A viewer can only display a value, not edit it, ValueEditor is used for that */ +class ValueViewer { + public: + /// Construct a ValueViewer, set the value at a later time + ValueViewer(DataViewer& parent, const StyleP& style); + virtual ~ValueViewer(); + + // Draw this value + virtual void draw(RotatedDC& dc) = 0; + + /// Does this field contian the given point? + virtual bool containsPoint(const RealPoint& p) const; + /// Get a bounding rectangle for this field (including any border it may have) + virtual RealRect boundingBox() const; + + /// Called when the associated value is changed + /** Both when we are associated with another value, + * and by default when the value itself changes (called from onAction) + */ + virtual void onValueChange() {} + /// Called when a (scripted) property of the associated style has changed + virtual void onStyleChange() {} + /// Called when an action is performed on the associated value + virtual void onAction(const ValueAction&, bool undone) { onValueChange(); } + + /// Change the associated value + void setValue(const ValueP&); + + protected: + DataViewer& viewer; ///< Our parent object + StyleP style_; ///< The style of this viewer + ValueP value_; ///< The value we are currently viewing + + /// Should this viewer render using a platform native look? + bool nativeLook() const; + /// Is this the currently selected viewer? + /** Usually only the editor allows selection of viewers */ + bool isCurrent() const; + + /// Draws a border around the field + void drawFieldBorder(RotatedDC& dc); +}; + +// ----------------------------------------------------------------------------- : Utility + +#define VALUE_VIEWER(Base, Type) \ + public: \ + Type(DataViewer& parent, const Type ## StyleP& style) \ + private: \ + inline Type##Style style() const { return *value_; } \ + inline Type##Value value() const { return *value_; } + + +// ----------------------------------------------------------------------------- : EOF +#endif