diff --git a/src/data/action/set.cpp b/src/data/action/set.cpp index af68a0a0..0da4564c 100644 --- a/src/data/action/set.cpp +++ b/src/data/action/set.cpp @@ -80,6 +80,14 @@ void ReorderCardsAction::perform(bool to_undo) { // ----------------------------------------------------------------------------- : Change stylesheet +String DisplayChangeAction::getName(bool to_undo) const { + assert(false); + return _(""); +} +void DisplayChangeAction::perform(bool to_undo) { + assert(false); +} + String ChangeCardStyleAction::getName(bool to_undo) const { return _("Change style"); @@ -88,6 +96,7 @@ void ChangeCardStyleAction::perform(bool to_undo) { swap(card->stylesheet, stylesheet); } + String ChangeSetStyleAction::getName(bool to_undo) const { return _("Change style (all cards)"); } diff --git a/src/data/action/set.hpp b/src/data/action/set.hpp index 6b678135..73ec61d4 100644 --- a/src/data/action/set.hpp +++ b/src/data/action/set.hpp @@ -76,8 +76,15 @@ class ReorderCardsAction : public CardListAction { // ----------------------------------------------------------------------------- : Change stylesheet +/// An action that affects the rendering/display/look of a set or cards in the set +class DisplayChangeAction : public Action { + public: + virtual String getName(bool to_undo) const; + virtual void perform(bool to_undo); +}; + /// Changing the style of a a card -class ChangeCardStyleAction : public Action { +class ChangeCardStyleAction : public DisplayChangeAction { public: ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet) : card(card), stylesheet(stylesheet) {} @@ -91,7 +98,7 @@ class ChangeCardStyleAction : public Action { }; /// Changing the style of a set to that of a card -class ChangeSetStyleAction : public Action { +class ChangeSetStyleAction : public DisplayChangeAction { public: ChangeSetStyleAction(Set& set, const CardP& card) : set(set), card(card) {} diff --git a/src/data/format/image.cpp b/src/data/format/image.cpp index cf980799..0132e4bd 100644 --- a/src/data/format/image.cpp +++ b/src/data/format/image.cpp @@ -32,7 +32,7 @@ Bitmap export_bitmap(const SetP& set, const CardP& card) { // viewer.rotation.angle = 0; // viewer.rotation.zoom = 1.0; } - RealSize size = viewer.getRotation().getExternalRect().size(); + RealSize size = viewer.getRotation().getExternalSize(); // create bitmap & dc Bitmap bitmap(size.width, size.height); if (!bitmap.Ok()) throw InternalError(_("Unable to create bitmap")); diff --git a/src/gui/control/card_viewer.cpp b/src/gui/control/card_viewer.cpp index 2331ae2b..c1d88f70 100644 --- a/src/gui/control/card_viewer.cpp +++ b/src/gui/control/card_viewer.cpp @@ -20,10 +20,7 @@ CardViewer::CardViewer(Window* parent, int id, long style) wxSize CardViewer::DoGetBestSize() const { wxSize ws = GetSize(), cs = GetClientSize(); if (set) { - StyleSheetP stylesheet = set->stylesheetFor(card); - if (stylesheet) { - return wxSize(stylesheet->card_width, stylesheet->card_height) + ws - cs; - } + return (wxSize)getRotation().getExternalSize() + ws - cs; } return cs; } diff --git a/src/gui/control/native_look_editor.cpp b/src/gui/control/native_look_editor.cpp index 9eac6d61..e2c1ab1a 100644 --- a/src/gui/control/native_look_editor.cpp +++ b/src/gui/control/native_look_editor.cpp @@ -91,7 +91,7 @@ SetInfoEditor::SetInfoEditor(Window* parent, int id, long style) {} void SetInfoEditor::onChangeSet() { - setStyles(set->stylesheet->set_info_style); + setStyles(set->stylesheet, set->stylesheet->set_info_style); setData(set->data); } @@ -103,7 +103,7 @@ StylingEditor::StylingEditor(Window* parent, int id, long style) void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) { this->stylesheet = stylesheet; - setStyles(stylesheet->styling_style); + setStyles(set->stylesheet, stylesheet->styling_style); setData(set->stylingDataFor(*stylesheet)); } diff --git a/src/gui/control/text_ctrl.cpp b/src/gui/control/text_ctrl.cpp index da60410c..9e15f740 100644 --- a/src/gui/control/text_ctrl.cpp +++ b/src/gui/control/text_ctrl.cpp @@ -56,7 +56,7 @@ void TextCtrl::setValue(String* value) { // assign to this control IndexMap styles; styles.add(field, style); IndexMap values; values.add(field, value); - setStyles(styles); + setStyles(set->stylesheet, styles); setData(values); // determine required height viewers.front()->getEditor()->determineSize(); diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index 37069ca7..6fb7f884 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -175,7 +175,7 @@ void CardsPanel::onCommand(int id) { : id == ID_CARD_ROTATE_180 ? 180 : 270 ); - //onRenderSettingsChange(); + set->actions.tellListeners(DisplayChangeAction(),true); break; } case ID_SELECT_COLUMNS: { @@ -196,8 +196,13 @@ bool CardsPanel::wantsToHandle(const Action&, bool undone) const { return false; } -void CardsPanel::onAction(const Action& action, bool undo) { - // TODO +void CardsPanel::onAction(const Action& action, bool undone) { + TYPE_CASE_(action, DisplayChangeAction) { + // The style changed, maybe also the size of editor + Layout(); + //if (current_panel) current_panel->Layout(); + //fixMinWindowSize(); + } } void CardsPanel::onRenderSettingsChange() { @@ -224,4 +229,5 @@ void CardsPanel::selectCard(const CardP& card) { card_list->setCard(card); editor->setCard(card); notes->setValue(card ? &card->notes : nullptr); + Layout(); } diff --git a/src/gui/set/style_panel.cpp b/src/gui/set/style_panel.cpp index e095c5ee..59c7fc54 100644 --- a/src/gui/set/style_panel.cpp +++ b/src/gui/set/style_panel.cpp @@ -83,11 +83,13 @@ void StylePanel::onStyleSelect(wxCommandEvent&) { stylesheet = StyleSheetP(); } set->actions.add(new ChangeCardStyleAction(card, stylesheet)); + Layout(); } } void StylePanel::onUseForAll(wxCommandEvent&) { set->actions.add(new ChangeSetStyleAction(*set, card)); + Layout(); } BEGIN_EVENT_TABLE(StylePanel, wxPanel) diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index c52d08c1..0b89963b 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -27,6 +27,7 @@ #include #include #include +#include DECLARE_TYPEOF_COLLECTION(SetWindowPanel*); DECLARE_TYPEOF_COLLECTION(SetWindow*); @@ -231,11 +232,11 @@ void SetWindow::onChangeSet() { } void SetWindow::onAction(const Action& action, bool undone) { -// TYPE_CASE_(action, SetStyleChange) { -// // The style changed, maybe also the size of the viewer -// Layout(); -// fixMinWindowSize(); -// } + TYPE_CASE_(action, DisplayChangeAction) { + // The style changed, maybe also the size of card viewers + if (current_panel) current_panel->Layout(); + fixMinWindowSize(); + } } @@ -517,13 +518,10 @@ void SetWindow::onReplaceAll(wxFindDialogEvent&) { void SetWindow::onEditPreferences(wxCommandEvent&) { PreferencesWindow wnd(this); - wnd.ShowModal(); -// if (wnd.ShowModal() == wxID_OK) { -// // render settings may have changed, notify all windows -// FOR_EACH(m, setWindows) { -// m->onRenderSettingsChange(); -// } -// } + if (wnd.ShowModal() == wxID_OK) { + // render settings may have changed, notify all windows + set->actions.tellListeners(DisplayChangeAction(),true); + } } diff --git a/src/render/card/viewer.cpp b/src/render/card/viewer.cpp index 2965c2e0..d8ecf656 100644 --- a/src/render/card/viewer.cpp +++ b/src/render/card/viewer.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include // clearDC DECLARE_TYPEOF_COLLECTION(ValueViewerP); typedef IndexMap IndexMap_FieldP_StyleP; @@ -25,17 +27,14 @@ DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP); // ----------------------------------------------------------------------------- : Drawing void DataViewer::draw(DC& dc) { - StyleSheetP stylesheet = set->stylesheetFor(card); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); - RotatedDC rdc(dc, ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), ss.card_anti_alias() && !nativeLook()); - draw(rdc, set->stylesheet->card_background); + RotatedDC rdc(dc, ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), ss.card_anti_alias() && !nativeLook(), true); + draw(rdc, stylesheet->card_background); } void DataViewer::draw(RotatedDC& dc, const Color& background) { - if (!set) return; // no set specified, don't draw anything + if (!set) return; // no set specified, don't draw anything // fill with background color - dc.SetPen(*wxTRANSPARENT_PEN); - dc.SetBrush(background); - dc.DrawRectangle(dc.getInternalRect()); + clearDC(dc.getDC(), background); // update style scripts if (card) set->updateFor(card); // draw values @@ -59,9 +58,8 @@ ValueViewer* DataViewer::focusedViewer() const { return nullptr; } Context& DataViewer::getContext() const { return set->getContext(); } Rotation DataViewer::getRotation() const { - StyleSheetP stylesheet = set->stylesheetFor(card); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); - return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom()); + return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), true); } // ----------------------------------------------------------------------------- : Setting data @@ -70,7 +68,8 @@ void DataViewer::setCard(const CardP& card) { if (!card) return; // TODO: clear editor? assert(set); this->card = card; - setStyles(set->stylesheet->card_style); + stylesheet = set->stylesheetFor(card); + setStyles(stylesheet, stylesheet->card_style); setData(card->data); } @@ -82,11 +81,12 @@ struct CompareViewer { } }; -void DataViewer::setStyles(IndexMap& styles) { +void DataViewer::setStyles(const StyleSheetP& stylesheet, IndexMap& styles) { if (!viewers.empty() && styles.contains(viewers.front()->getStyle())) { // already using these styles return; } + this->stylesheet = stylesheet; // create viewers viewers.clear(); FOR_EACH(s, styles) { @@ -117,6 +117,11 @@ ValueViewerP DataViewer::makeViewer(const StyleP& style) { } void DataViewer::onAction(const Action& action, bool undone) { + TYPE_CASE_(action, DisplayChangeAction) { + // refresh + setCard(card); + return; + } TYPE_CASE(action, ValueAction) { FOR_EACH(v, viewers) { if (v->getValue() == action.valueP) { diff --git a/src/render/card/viewer.hpp b/src/render/card/viewer.hpp index 31aafe48..c9bfd6a9 100644 --- a/src/render/card/viewer.hpp +++ b/src/render/card/viewer.hpp @@ -21,10 +21,7 @@ class Context; /// 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; - + public: // --------------------------------------------------- : Drawing /// Draw the current (card/data) to the given dc @@ -63,7 +60,7 @@ class DataViewer : public SetView { // --------------------------------------------------- : The viewers protected: /// Set the styles for the data to be shown, recreating the viewers - void setStyles(IndexMap& styles); + void setStyles(const StyleSheetP& stylesheet, IndexMap& styles); /// Set the data to be shown in the viewers, refresh them void setData(IndexMap& values); @@ -82,6 +79,8 @@ class DataViewer : public SetView { vector viewers; ///< The viewers for the different values in the data CardP card; ///< The card that is currently displayed, if any + public: + StyleSheetP stylesheet; ///< Stylesheet being used }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/render/value/choice.cpp b/src/render/value/choice.cpp index a742475c..26202173 100644 --- a/src/render/value/choice.cpp +++ b/src/render/value/choice.cpp @@ -23,12 +23,12 @@ void ChoiceValueViewer::draw(RotatedDC& dc) { ScriptableImage& img = it->second; ScriptImageP i; if (nativeLook()) { - i = img.update(viewer.getContext(), *getSet().stylesheet, 16, 16, ASPECT_BORDER, false); + i = img.update(viewer.getContext(), *viewer.stylesheet, 16, 16, ASPECT_BORDER, false); } else if(style().render_style & RENDER_TEXT) { // also drawing text - i = img.update(viewer.getContext(), *getSet().stylesheet, 0, 0); + i = img.update(viewer.getContext(), *viewer.stylesheet, 0, 0); } else { - i = img.update(viewer.getContext(), *getSet().stylesheet, + i = img.update(viewer.getContext(), *viewer.stylesheet, dc.trS(style().width), dc.trS(style().height), style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT ); diff --git a/src/util/rotation.cpp b/src/util/rotation.cpp index 291d0a96..ffd7e32a 100644 --- a/src/util/rotation.cpp +++ b/src/util/rotation.cpp @@ -17,12 +17,15 @@ int constrain_angle(int angle) { return (a / 90) * 90; // multiple of 90 } -Rotation::Rotation(int angle, const RealRect& rect, double zoom) +Rotation::Rotation(int angle, const RealRect& rect, double zoom, bool is_internal) : angle(constrain_angle(angle)) , size(rect.size()) , origin(rect.position()) , zoom(zoom) { + if (is_internal) { + size = trNoNeg(size); + } // set origin if (revX()) origin.x += size.width; if (revY()) origin.y += size.height; @@ -108,12 +111,12 @@ Rotater::~Rotater() { // ----------------------------------------------------------------------------- : RotatedDC -RotatedDC::RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality) - : Rotation(angle, rect, zoom) +RotatedDC::RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality, bool is_internal) + : Rotation(angle, rect, zoom, is_internal) , dc(dc), high_quality(high_quality) {} -RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, bool high_quality = false) +RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, bool high_quality) : Rotation(rotation) , dc(dc), high_quality(high_quality&&false) {} diff --git a/src/util/rotation.hpp b/src/util/rotation.hpp index feb93e69..7c4e29f1 100644 --- a/src/util/rotation.hpp +++ b/src/util/rotation.hpp @@ -22,9 +22,11 @@ */ class Rotation { public: - /// Construct a rotation object with the given rectangle of external coordinates - /// and a given rotation angle and zoom factor - Rotation(int angle, const RealRect& rect, double zoom = 1.0); + /// Construct a rotation object + /** with the given rectangle of external coordinates and a given rotation angle and zoom factor. + * if is_internal then the rect gives the internal coordinates, its origin should be (0,0) + */ + Rotation(int angle, const RealRect& rect, double zoom = 1.0, bool is_internal = false); /// Change the zoom factor inline void setZoom(double z) { zoom = z; } @@ -34,6 +36,8 @@ class Rotation { inline RealSize getInternalSize() const { return trInvNoNeg(size); } /// The intarnal rectangle (origin at (0,0)) inline RealRect getInternalRect() const { return RealRect(RealPoint(0,0), getInternalSize()); } + /// The size of the external rectangle (as passed to the constructor) == trNoNeg(getInternalSize()) + inline RealSize getExternalSize() const { return size; } /// The external rectangle (as passed to the constructor) == trNoNeg(getInternalRect()) RealRect getExternalRect() const; @@ -120,7 +124,7 @@ class Rotater { */ class RotatedDC : public Rotation { public: - RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality); + RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality, bool is_internal = false); RotatedDC(DC& dc, const Rotation& rotation, bool high_quality); // --------------------------------------------------- : Drawing