From 7192361c36d5ffb866dde10bceaaf6548ea7aa53 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 27 Oct 2006 22:10:09 +0000 Subject: [PATCH] Implemented ImageValueViewer, and more of the related classes git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@54 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/card.cpp | 1 + src/data/field.hpp | 4 ++ src/data/field/boolean.hpp | 2 + src/data/field/choice.hpp | 2 + src/data/field/color.hpp | 2 + src/data/field/image.hpp | 2 + src/data/field/multiple_choice.hpp | 2 + src/data/field/symbol.hpp | 2 + src/data/field/text.hpp | 2 + src/gui/control/card_list.cpp | 16 +++-- src/gui/control/card_list.hpp | 9 ++- src/gui/set/cards_panel.cpp | 2 +- src/gui/set/panel.hpp | 2 +- src/gui/set/window.cpp | 15 ++-- src/gui/set/window.hpp | 4 +- src/gui/util.cpp | 21 ++++++ src/gui/util.hpp | 6 ++ src/render/card/viewer.cpp | 41 ++++++++++- src/render/card/viewer.hpp | 7 +- src/render/value/boolean.cpp | 11 +++ src/render/value/boolean.hpp | 18 +++++ src/render/value/choice.cpp | 11 +++ src/render/value/choice.hpp | 18 +++++ src/render/value/color.cpp | 11 +++ src/render/value/color.hpp | 18 +++++ src/render/value/image.cpp | 104 +++++++++++++++++++++++++++ src/render/value/image.hpp | 42 +++++++++++ src/render/value/multiple_choice.cpp | 11 +++ src/render/value/multiple_choice.hpp | 18 +++++ src/render/value/symbol.cpp | 11 +++ src/render/value/symbol.hpp | 18 +++++ src/render/value/text.cpp | 11 +++ src/render/value/text.hpp | 18 +++++ src/render/value/viewer.cpp | 41 ++++++++++- src/render/value/viewer.hpp | 19 +++-- 35 files changed, 485 insertions(+), 37 deletions(-) create mode 100644 src/render/value/boolean.cpp create mode 100644 src/render/value/boolean.hpp create mode 100644 src/render/value/choice.cpp create mode 100644 src/render/value/choice.hpp create mode 100644 src/render/value/color.cpp create mode 100644 src/render/value/color.hpp create mode 100644 src/render/value/image.cpp create mode 100644 src/render/value/image.hpp create mode 100644 src/render/value/multiple_choice.cpp create mode 100644 src/render/value/multiple_choice.hpp create mode 100644 src/render/value/symbol.cpp create mode 100644 src/render/value/symbol.hpp create mode 100644 src/render/value/text.cpp create mode 100644 src/render/value/text.hpp diff --git a/src/data/card.cpp b/src/data/card.cpp index 80f13d95..d68e707c 100644 --- a/src/data/card.cpp +++ b/src/data/card.cpp @@ -32,6 +32,7 @@ String Card::identification() const { } IMPLEMENT_REFLECTION(Card) { + REFLECT(stylesheet); REFLECT(notes); REFLECT_NAMELESS(data); } diff --git a/src/data/field.hpp b/src/data/field.hpp index 35990c73..acf919ea 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -79,6 +79,10 @@ class Style { Scriptable width, height; ///< Position of this field Scriptable visible; ///< Is this field visible? + inline RealPoint getPos() const { return RealPoint(left, top ); } + inline RealSize getSize() const { return RealSize ( width, height); } + inline RealRect getRect() const { return RealRect (left, top, width, height); } + /// 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; diff --git a/src/data/field/boolean.hpp b/src/data/field/boolean.hpp index 0c27818d..0d92aabc 100644 --- a/src/data/field/boolean.hpp +++ b/src/data/field/boolean.hpp @@ -15,6 +15,8 @@ // ----------------------------------------------------------------------------- : BooleanField DECLARE_POINTER_TYPE(BooleanField); +DECLARE_POINTER_TYPE(BooleanStyle); +DECLARE_POINTER_TYPE(BooleanValue); /// A field whos value is either true or false class BooleanField : public ChoiceField { diff --git a/src/data/field/choice.hpp b/src/data/field/choice.hpp index 12ac11d0..e54f011d 100644 --- a/src/data/field/choice.hpp +++ b/src/data/field/choice.hpp @@ -18,6 +18,8 @@ // ----------------------------------------------------------------------------- : ChoiceField DECLARE_POINTER_TYPE(ChoiceField); +DECLARE_POINTER_TYPE(ChoiceStyle); +DECLARE_POINTER_TYPE(ChoiceValue); /// A field that contains a list of choices class ChoiceField : public Field { diff --git a/src/data/field/color.hpp b/src/data/field/color.hpp index 7ab246e9..f3f78f09 100644 --- a/src/data/field/color.hpp +++ b/src/data/field/color.hpp @@ -17,6 +17,8 @@ // ----------------------------------------------------------------------------- : ColorField DECLARE_POINTER_TYPE(ColorField); +DECLARE_POINTER_TYPE(ColorStyle); +DECLARE_POINTER_TYPE(ColorValue); /// A field for color values, it contains a list of choices for colors class ColorField : public Field { diff --git a/src/data/field/image.hpp b/src/data/field/image.hpp index 817b980c..a0285d51 100644 --- a/src/data/field/image.hpp +++ b/src/data/field/image.hpp @@ -16,6 +16,8 @@ // ----------------------------------------------------------------------------- : ImageField DECLARE_POINTER_TYPE(ImageField); +DECLARE_POINTER_TYPE(ImageStyle); +DECLARE_POINTER_TYPE(ImageValue); /// A field for image values class ImageField : public Field { diff --git a/src/data/field/multiple_choice.hpp b/src/data/field/multiple_choice.hpp index 4d396991..7778362f 100644 --- a/src/data/field/multiple_choice.hpp +++ b/src/data/field/multiple_choice.hpp @@ -15,6 +15,8 @@ // ----------------------------------------------------------------------------- : MultipleChoiceField DECLARE_POINTER_TYPE(MultipleChoiceField); +DECLARE_POINTER_TYPE(MultipleChoiceStyle); +DECLARE_POINTER_TYPE(MultipleChoiceValue); /// A ChoiceField where multiple choices can be selected simultaniously class MultipleChoiceField : public ChoiceField { diff --git a/src/data/field/symbol.hpp b/src/data/field/symbol.hpp index baee7454..abf49039 100644 --- a/src/data/field/symbol.hpp +++ b/src/data/field/symbol.hpp @@ -18,6 +18,8 @@ DECLARE_POINTER_TYPE(SymbolFilter); // ----------------------------------------------------------------------------- : SymbolField DECLARE_POINTER_TYPE(SymbolField); +DECLARE_POINTER_TYPE(SymbolStyle); +DECLARE_POINTER_TYPE(SymbolValue); /// A field for image values class SymbolField : public Field { diff --git a/src/data/field/text.hpp b/src/data/field/text.hpp index c11af8ce..9fc1e533 100644 --- a/src/data/field/text.hpp +++ b/src/data/field/text.hpp @@ -17,6 +17,8 @@ // ----------------------------------------------------------------------------- : TextField DECLARE_POINTER_TYPE(TextField); +DECLARE_POINTER_TYPE(TextStyle); +DECLARE_POINTER_TYPE(TextValue); /// A field for values containing tagged text class TextField : public Field { diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index bd0d9944..3a268e69 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -56,14 +56,14 @@ void CardListBase::onAction(const Action& action, bool undone) { selectCardPos((long)sorted_card_list.size() - 1, true); } else { // select the new card - selectCard(action.card, false /*list will be refreshed anyway*/); + selectCard(action.card, false /*list will be refreshed anyway*/, true); refreshList(); } } TYPE_CASE(action, RemoveCardAction) { if (undone) { // select the re-added card - selectCard(action.card, false /*list will be refreshed anyway*/); + selectCard(action.card, false /*list will be refreshed anyway*/, true); refreshList(); } else { long pos = selected_card_pos; @@ -116,10 +116,12 @@ void CardListBase::selectNext() { // ----------------------------------------------------------------------------- : CardListBase : Selection (private) -void CardListBase::selectCard(const CardP& card, bool focus) { +void CardListBase::selectCard(const CardP& card, bool focus, bool event) { selected_card = card; - CardSelectEvent ev(card); - ProcessEvent(ev); + if (event) { + CardSelectEvent ev(card); + ProcessEvent(ev); + } if (focus) { findSelectedCardPos(); selectCurrentCard(); @@ -130,9 +132,9 @@ void CardListBase::selectCardPos(long pos, bool focus) { if (selected_card_pos == pos && !focus) return; // this card is already selected if ((size_t)pos < sorted_card_list.size()) { // only if there is something to select - selectCard(sorted_card_list[pos], false); + selectCard(sorted_card_list[pos], false, true); } else { - selectCard(CardP(), false); + selectCard(CardP(), false, true); } selected_card_pos = pos; if (focus) selectCurrentCard(); diff --git a/src/gui/control/card_list.hpp b/src/gui/control/card_list.hpp index 876f8d67..7b58ac04 100644 --- a/src/gui/control/card_list.hpp +++ b/src/gui/control/card_list.hpp @@ -20,7 +20,10 @@ DECLARE_POINTER_TYPE(Field); DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, ) /// Handle CardSelectEvents -#define EVT_CARD_SELECT(id, handler) EVT_COMMAND(id, EVENT_CARD_SELECT, handler) +#define EVT_CARD_SELECT(id, handler) \ + DECLARE_EVENT_TABLE_ENTRY(EVENT_CARD_SELECT, id, -1, \ + (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \ + (void (wxEvtHandler::*)(CardSelectEvent&)) (&handler), (wxObject*) NULL), /// The event of selecting a card struct CardSelectEvent : public wxCommandEvent { @@ -50,7 +53,7 @@ class CardListBase : public wxListView, public SetView { // --------------------------------------------------- : Selection inline CardP getCard() const { return selected_card; } - inline void setCard(const CardP& card) { selectCard(card, true); } + inline void setCard(const CardP& card) { selectCard(card, true, false); } /// Is there a previous card to select? bool canSelectPrevious() const; @@ -113,7 +116,7 @@ class CardListBase : public wxListView, public SetView { /** If focus then the card is also focused and selected in the actual control. * This should abviously not be done when the card is selected because it was selected (leading to a loop). */ - void selectCard(const CardP& card, bool focus); + void selectCard(const CardP& card, bool focus, bool event); /// Select a card at the specified position void selectCardPos(long pos, bool focus); /// Find the position for the selected_card diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index 9d73042a..fbdb66d9 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -211,4 +211,4 @@ CardP CardsPanel::selectedCard() const { void CardsPanel::selectCard(const CardP& card) { card_list->setCard(card); editor->setCard(*card); -} \ No newline at end of file +} diff --git a/src/gui/set/panel.hpp b/src/gui/set/panel.hpp index 07570f12..4c23215d 100644 --- a/src/gui/set/panel.hpp +++ b/src/gui/set/panel.hpp @@ -68,7 +68,7 @@ class SetWindowPanel : public wxPanel, public SetView { // --------------------------------------------------- : Selection virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP() - virtual void selectCard(CardP card) {} ///< Switch the view to another card + virtual void selectCard(const CardP& card) {} ///< Switch the view to another card protected: // --------------------------------------------------- : Helper functions for UI diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 146d9fe8..f1477181 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -246,11 +246,10 @@ void SetWindow::onAction(const Action& action, bool undone) { } -void SetWindow::onCardSelect(wxCommandEvent& ev) { -// CardP card = static_cast(ev).card; -// FOR_EACH(p, panels) { -// p->selectCard(card); -// } +void SetWindow::onCardSelect(CardSelectEvent& ev) { + FOR_EACH(p, panels) { + p->selectCard(ev.card); + } fixMinWindowSize(); } @@ -547,12 +546,6 @@ void SetWindow::onChildMenu(wxCommandEvent& ev) { current_panel->onCommand(ev.GetId()); } -void SetWindow::onCardSelect(CardSelectEvent& ev) { - FOR_EACH(p, panels) { - p->selectCard(ev.card); - } -} - // ----------------------------------------------------------------------------- : Event table BEGIN_EVENT_TABLE(SetWindow, wxFrame) diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index 17fe4e53..ddb089ff 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -85,7 +85,7 @@ class SetWindow : public wxFrame, public SetView { private: /// A different card has been selected - void onCardSelect(wxCommandEvent&); + void onCardSelect(CardSelectEvent&); /// Render settings have changed (because of editing of preferences) void onRenderSettingsChange(); @@ -154,8 +154,6 @@ class SetWindow : public wxFrame, public SetView { // --------------------------------------------------- : Window events - other void onChildMenu (wxCommandEvent&); - - void onCardSelect (CardSelectEvent&); }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/gui/util.cpp b/src/gui/util.cpp index ed51da01..6b7224c4 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -8,6 +8,7 @@ #include #include +#include #include // ----------------------------------------------------------------------------- : DC related @@ -20,6 +21,26 @@ void clearDC(DC& dc, const wxBrush& brush) { dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight()); } +void draw_checker(RotatedDC& dc, const RealRect& rect) { + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(*wxWHITE_BRUSH); + dc.DrawRectangle(rect); + dc.SetBrush(Color(235,235,235)); + const double checker_size = 10; + int odd = 0; + for (double y = 0 ; y < rect.size.height ; y += checker_size) { + for (double x = odd * checker_size ; x < rect.size.width ; x += checker_size * 2) { + dc.DrawRectangle(RealRect( + rect.position.x + x, + rect.position.y + y, + min(checker_size, rect.size.width - x), + min(checker_size, rect.size.height - y) + )); + } + odd = 1 - odd; + } +} + // ----------------------------------------------------------------------------- : Image related Image load_resource_image(String name) { diff --git a/src/gui/util.hpp b/src/gui/util.hpp index 7a2ca66d..5baf07a4 100644 --- a/src/gui/util.hpp +++ b/src/gui/util.hpp @@ -15,11 +15,17 @@ #include +class RotatedDC; +class RealRect; + // ----------------------------------------------------------------------------- : DC related /// Fill a DC with a single color void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH); +/// Draw a checkerboard pattern +void draw_checker(RotatedDC& dc, const RealRect&); + // ----------------------------------------------------------------------------- : Resource related /// Load an image from a resource diff --git a/src/render/card/viewer.cpp b/src/render/card/viewer.cpp index 5055a868..e939c4f8 100644 --- a/src/render/card/viewer.cpp +++ b/src/render/card/viewer.cpp @@ -14,6 +14,8 @@ #include DECLARE_TYPEOF_COLLECTION(ValueViewerP); +typedef IndexMap IndexMap_FieldP_StyleP; +DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP); // ----------------------------------------------------------------------------- : DataViewer @@ -21,16 +23,31 @@ DECLARE_TYPEOF_COLLECTION(ValueViewerP); // ----------------------------------------------------------------------------- : Drawing void DataViewer::draw(DC& dc) { +// RotatedDC rdc(dc, rotation, settings.styleSettingsFor(*style).cardAntiAlias && !nativeLook()) + RotatedDC rdc(dc, 0, RealRect(0,0,400,400), 1.0, false); + draw(rdc); } void DataViewer::draw(RotatedDC& dc) { + if (!set) return; // no set specified, don't draw anything + // fill with background color + dc.SetPen(*wxTRANSPARENT_PEN); + dc.SetBrush(set->stylesheet->card_background); + dc.DrawRectangle(dc.getInternalRect()); + // draw values + FOR_EACH(v, viewers) { // draw low z index fields first + if (v->getStyle()->visible) {// visible + v->draw(dc); + } + } } // ----------------------------------------------------------------------------- : Utility for ValueViewers bool DataViewer::nativeLook() const { return false; } bool DataViewer::drawBorders() const { return false; } +bool DataViewer::drawEditing() const { return false; } wxPen DataViewer::borderPen(bool) const { return wxPen(); } -Value* DataViewer::focusedValue() const { return nullptr; } +ValueViewer* DataViewer::focusedViewer() const { return nullptr; } // ----------------------------------------------------------------------------- : Setting data @@ -42,7 +59,29 @@ void DataViewer::setCard(Card& card) { // ----------------------------------------------------------------------------- : Viewers +struct CompareViewer { + bool operator() (const ValueViewerP& a, const ValueViewerP& b) { + return a->getStyle()->z_index < b->getStyle()->z_index; + } +}; + void DataViewer::setStyles(IndexMap& styles) { + if (!viewers.empty() && styles.contains(viewers.front()->getStyle())) { + // already using these styles + return; + } + // create viewers + viewers.clear(); + FOR_EACH(s, styles) { + if (s->visible || s->visible.isScripted()) { + // no need to make a viewer for things that are always invisible + viewers.push_back(makeViewer(s)); + // REMOVEME //TODO //%%% + if (!viewers.back()) viewers.pop_back(); + } + } + // sort viewers by z-index of style + stable_sort(viewers.begin(), viewers.end(), CompareViewer()); } void DataViewer::setData(IndexMap& values) { diff --git a/src/render/card/viewer.hpp b/src/render/card/viewer.hpp index f5be98a6..ce880941 100644 --- a/src/render/card/viewer.hpp +++ b/src/render/card/viewer.hpp @@ -39,11 +39,14 @@ class DataViewer : public SetView { /// Should field borders be drawn? /** false by default, can be overloaded */ virtual bool drawBorders() const; + /// Should editing specific things be drawn? + /** false by default, can be overloaded */ + virtual bool drawEditing() 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 + /// The viewer that is currently focused, may be null /** null by default, can be overloaded */ - virtual Value* focusedValue() const; + virtual ValueViewer* focusedViewer() const; // --------------------------------------------------- : Setting data diff --git a/src/render/value/boolean.cpp b/src/render/value/boolean.cpp new file mode 100644 index 00000000..9c8c6903 --- /dev/null +++ b/src/render/value/boolean.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/render/value/boolean.hpp b/src/render/value/boolean.hpp new file mode 100644 index 00000000..89a13e98 --- /dev/null +++ b/src/render/value/boolean.hpp @@ -0,0 +1,18 @@ +//+----------------------------------------------------------------------------+ +//| 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_BOOLEAN +#define HEADER_RENDER_VALUE_BOOLEAN + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/choice.cpp b/src/render/value/choice.cpp new file mode 100644 index 00000000..7fd92a59 --- /dev/null +++ b/src/render/value/choice.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/render/value/choice.hpp b/src/render/value/choice.hpp new file mode 100644 index 00000000..ddf726b0 --- /dev/null +++ b/src/render/value/choice.hpp @@ -0,0 +1,18 @@ +//+----------------------------------------------------------------------------+ +//| 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_CHOICE +#define HEADER_RENDER_VALUE_CHOICE + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/color.cpp b/src/render/value/color.cpp new file mode 100644 index 00000000..d63471b5 --- /dev/null +++ b/src/render/value/color.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/render/value/color.hpp b/src/render/value/color.hpp new file mode 100644 index 00000000..38e9cedc --- /dev/null +++ b/src/render/value/color.hpp @@ -0,0 +1,18 @@ +//+----------------------------------------------------------------------------+ +//| 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_COLOR +#define HEADER_RENDER_VALUE_COLOR + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/image.cpp b/src/render/value/image.cpp new file mode 100644 index 00000000..5938e820 --- /dev/null +++ b/src/render/value/image.cpp @@ -0,0 +1,104 @@ +//+----------------------------------------------------------------------------+ +//| 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 +#include + +// ----------------------------------------------------------------------------- : ImageValueViewer + +void ImageValueViewer::draw(RotatedDC& dc) { + drawFieldBorder(dc); + // try to load image + if (!bitmap.Ok() && !value().filename.empty()) { + try { + InputStreamP image_file = getSet().openIn(value().filename); + Image image; + if (image.LoadFile(*image_file)) { + image.Rescale(dc.trS(style().width), dc.trS(style().height)); + // apply mask to image +/* loadMask(dc); + if (alpha_mask) alpha_mask->setAlpha(image); +*/ bitmap = Bitmap(image); + } + } catch (Error e) { + handle_error(e, false, false); // don't handle now, we are in onPaint + } + } + // if there is no image, generate a placeholder, only if there is enough room for it + if (!bitmap.Ok() && style().width > 40) { + bitmap = imagePlaceholder(dc, dc.trS(style().width), dc.trS(style().height), viewer.drawEditing()); +/* loadMask(dc); + if (alpha_mask) alpha_mask->setAlpha(bitmap); +/* if (alphaMask) { + // convert to image and apply alpha + Image image = bmp.ConvertToImage(); + alpha_mask->setAlpha(image); + bitmap = image; + } +*/ } + // draw image, if any + if (bitmap.Ok()) { + dc.DrawBitmap(bitmap, style().getPos()); + } +} + +bool ImageValueViewer::containsPoint(const RealPoint& p) const { + int x = p.x - style().left; + int y = p.y - style().top; + if (x < 0 || y < 0 || x >= (int)style().width || y >= (int)style().height) { + return false; // outside rectangle + } +/* // check against mask + if (!style->maskFilename.value.empty()) { + RotatedObject rot(viewer.getRotation()); + loadMask(rot); + return !alphaMask->isTransparent(x, y); + } else { + return true; + }*/ + return true; +} + +void ImageValueViewer::onValueChange() { + bitmap = Bitmap(); +} + +void ImageValueViewer::onStyleChange() { + bitmap = Bitmap(); +// alpha_mask = AlphaMaskP(); +} + +Bitmap ImageValueViewer::imagePlaceholder(const Rotation& rot, UInt w, UInt h, bool editing) { + // Bitmap and memory dc + Bitmap bmp(w, h, 24); + wxMemoryDC mdc; + mdc.SelectObject(bmp); + RealRect rect(0,0,w,h); + RotatedDC dc(mdc, 0, rect, 1.0, true); + // Draw checker background + draw_checker(dc, rect); + // Draw text + if (editing) { + // only when in editor mode + for (UInt size = 12 ; size > 2 ; --size) { + dc.SetFont(wxFont(size, wxSWISS, wxNORMAL, wxNORMAL)); + RealSize rs = dc.GetTextExtent(_("double click to load image")); + if (rs.width <= w - 10 && rs.height < h - 10) { + // text fits + dc.SetTextForeground(*wxBLACK); + dc.DrawText(_("double click to load image"), align_in_rect(ALIGN_MIDDLE_CENTER, rs, rect)); + break; + } + } + } + // Done + mdc.SelectObject(wxNullBitmap); + return bmp; +} diff --git a/src/render/value/image.hpp b/src/render/value/image.hpp new file mode 100644 index 00000000..b394318c --- /dev/null +++ b/src/render/value/image.hpp @@ -0,0 +1,42 @@ +//+----------------------------------------------------------------------------+ +//| 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_IMAGE +#define HEADER_RENDER_VALUE_IMAGE + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include + +// ----------------------------------------------------------------------------- : ImageValueViewer + +/// Viewer that displays an image value +class ImageValueViewer : public ValueViewer { + public: + DECLARE_VALUE_VIEWER(Image) : ValueViewer(parent,style) {} + + void draw(RotatedDC& dc); + + bool containsPoint(const RealPoint& p) const; + + void onValueChange(); + void onStyleChange(); + + private: + Bitmap bitmap; +// mutable AlphaMaskP alpha_mask; + +// void loadMask(const RotatedObject& rot) const; + + /// Generate a placeholder image + static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, bool editing); +}; + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/multiple_choice.cpp b/src/render/value/multiple_choice.cpp new file mode 100644 index 00000000..fb8ae96a --- /dev/null +++ b/src/render/value/multiple_choice.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/render/value/multiple_choice.hpp b/src/render/value/multiple_choice.hpp new file mode 100644 index 00000000..2892cc8b --- /dev/null +++ b/src/render/value/multiple_choice.hpp @@ -0,0 +1,18 @@ +//+----------------------------------------------------------------------------+ +//| 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_MULTIPLE_CHOICE +#define HEADER_RENDER_VALUE_MULTIPLE_CHOICE + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/symbol.cpp b/src/render/value/symbol.cpp new file mode 100644 index 00000000..462d1918 --- /dev/null +++ b/src/render/value/symbol.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/render/value/symbol.hpp b/src/render/value/symbol.hpp new file mode 100644 index 00000000..01860d4a --- /dev/null +++ b/src/render/value/symbol.hpp @@ -0,0 +1,18 @@ +//+----------------------------------------------------------------------------+ +//| 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_SYMBOL +#define HEADER_RENDER_VALUE_SYMBOL + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/text.cpp b/src/render/value/text.cpp new file mode 100644 index 00000000..5f66da1a --- /dev/null +++ b/src/render/value/text.cpp @@ -0,0 +1,11 @@ +//+----------------------------------------------------------------------------+ +//| 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 + +// ----------------------------------------------------------------------------- : diff --git a/src/render/value/text.hpp b/src/render/value/text.hpp new file mode 100644 index 00000000..31245314 --- /dev/null +++ b/src/render/value/text.hpp @@ -0,0 +1,18 @@ +//+----------------------------------------------------------------------------+ +//| 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_TEXT +#define HEADER_RENDER_VALUE_TEXT + +// ----------------------------------------------------------------------------- : Includes + +#include + +// ----------------------------------------------------------------------------- : + + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/render/value/viewer.cpp b/src/render/value/viewer.cpp index a6bc3dd9..8c2927ec 100644 --- a/src/render/value/viewer.cpp +++ b/src/render/value/viewer.cpp @@ -7,15 +7,47 @@ // ----------------------------------------------------------------------------- : Includes #include +#include +#include +#include +#include +#include +#include +#include +#include // ----------------------------------------------------------------------------- : ValueViewer +ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style) + : viewer(parent), styleP(style) +{} + +Set& ValueViewer::getSet() const { return *viewer.getSet(); } + void ValueViewer::setValue(const ValueP& value) { assert(value->fieldP == styleP->fieldP); // matching field valueP = value; onValueChange(); } +bool ValueViewer::containsPoint(const RealPoint& p) const { + return p.x >= styleP->left + && p.y >= styleP->top + && p.x < styleP->left + (int)(styleP->width) + && p.y < styleP->top + (int)(styleP->height); +} +RealRect ValueViewer::boundingBox() const { + return styleP->getRect().grow(1); +} + +void ValueViewer::drawFieldBorder(RotatedDC& dc) { + if (viewer.drawBorders() && getField()->editable) { + dc.SetPen(viewer.borderPen(viewer.focusedViewer() == this)); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(styleP->getRect().grow(dc.trInvS(1))); + } +} + // ----------------------------------------------------------------------------- : Development/debug #ifdef _DEBUG @@ -31,11 +63,18 @@ void ValueViewer::setValue(const ValueP& value) { #include #include +#define IMPLEMENT_MAKE_VIEWER(Type) \ + ValueViewerP Type##Style::makeViewer(DataViewer& parent, const StyleP& thisP) { \ + assert(thisP.get() == this); \ + return ValueViewerP(new Type##ValueViewer(parent, static_pointer_cast(thisP))); \ + } + 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 ImageStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } +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/render/value/viewer.hpp b/src/render/value/viewer.hpp index 5841a013..fdba2fe7 100644 --- a/src/render/value/viewer.hpp +++ b/src/render/value/viewer.hpp @@ -14,6 +14,7 @@ #include #include +class Set; class DataViewer; class ValueAction; DECLARE_POINTER_TYPE(Style); @@ -33,6 +34,8 @@ class ValueViewer { void setValue(const ValueP&); /// Return the associated field inline const FieldP& getField() const { return styleP->fieldP; } + /// Return the associated style + inline const StyleP& getStyle() const { return styleP; } // Draw this value virtual void draw(RotatedDC& dc) = 0; @@ -65,17 +68,19 @@ class ValueViewer { /// Draws a border around the field void drawFieldBorder(RotatedDC& dc); + + Set& getSet() const; }; // ----------------------------------------------------------------------------- : Utility -#define VALUE_VIEWER(Base, Type) \ - public: \ - Type(DataViewer& parent, const Type ## StyleP& style) \ - private: \ - inline Type##Style& style() const { return *styleP; } \ - inline Type##Value& value() const { return *valueP; } \ - inline Type##Field& field() const { return styleP->field(); } +#define DECLARE_VALUE_VIEWER(Type) \ + private: \ + inline const Type##Style& style() const { return static_cast(*styleP); } \ + inline const Type##Value& value() const { return static_cast(*valueP); } \ + inline const Type##Field& field() const { return style().field(); } \ + public: \ + Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style) // ----------------------------------------------------------------------------- : EOF