Commit 3e0ee813 authored by twanvl's avatar twanvl

Reduce coupling between ValueEditors/Viewers and Set and StyleSheet.

 - Adding of actions is done with an addAction function
 - Files are read from
     - getStylePackage for styling stuff (this is stylesheet)
     - getLocalPackage for symbol and image values (this was the set)
parent 52281e68
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <data/field/symbol.hpp> #include <data/field/symbol.hpp>
#include <data/field/package_choice.hpp> #include <data/field/package_choice.hpp>
#include <util/tagged_string.hpp> #include <util/tagged_string.hpp>
#include <data/set.hpp> // for ValueActionPerformer
// ----------------------------------------------------------------------------- : ValueAction // ----------------------------------------------------------------------------- : ValueAction
...@@ -24,6 +25,10 @@ String ValueAction::getName(bool to_undo) const { ...@@ -24,6 +25,10 @@ String ValueAction::getName(bool to_undo) const {
return _ACTION_1_("change", valueP->fieldP->name); return _ACTION_1_("change", valueP->fieldP->name);
} }
void ValueAction::isOnCard(Card* card) {
const_cast<ValueAction*>(this)->card = card;
}
// ----------------------------------------------------------------------------- : Simple // ----------------------------------------------------------------------------- : Simple
/// Swap the value in a Value object with a new one /// Swap the value in a Value object with a new one
...@@ -42,8 +47,8 @@ inline void swap_value(MultipleChoiceValue& a, MultipleChoiceValue::ValueType& b ...@@ -42,8 +47,8 @@ inline void swap_value(MultipleChoiceValue& a, MultipleChoiceValue::ValueType& b
template <typename T, bool ALLOW_MERGE> template <typename T, bool ALLOW_MERGE>
class SimpleValueAction : public ValueAction { class SimpleValueAction : public ValueAction {
public: public:
inline SimpleValueAction(const Card* card, const intrusive_ptr<T>& value, const typename T::ValueType& new_value) inline SimpleValueAction(const intrusive_ptr<T>& value, const typename T::ValueType& new_value)
: ValueAction(card, value), new_value(new_value) : ValueAction(value), new_value(new_value)
{} {}
virtual void perform(bool to_undo) { virtual void perform(bool to_undo) {
...@@ -67,21 +72,21 @@ class SimpleValueAction : public ValueAction { ...@@ -67,21 +72,21 @@ class SimpleValueAction : public ValueAction {
typename T::ValueType new_value; typename T::ValueType new_value;
}; };
ValueAction* value_action(const Card* card, const ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, true> (card, value, new_value); } ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, true> (value, new_value); }
ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, true> (card, value, new_value); } ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, true> (value, new_value); }
ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, false>(card, value, new_value); } ValueAction* value_action(const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, false>(value, new_value); }
ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, false>(card, value, new_value); } ValueAction* value_action(const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, false>(value, new_value); }
ValueAction* value_action(const Card* card, const PackageChoiceValueP& value, const String& new_value) { return new SimpleValueAction<PackageChoiceValue, false>(card, value, new_value); } ValueAction* value_action(const PackageChoiceValueP& value, const String& new_value) { return new SimpleValueAction<PackageChoiceValue, false>(value, new_value); }
ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change) { ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change) {
MultipleChoiceValue::ValueType v = { new_value, last_change }; MultipleChoiceValue::ValueType v = { new_value, last_change };
return new SimpleValueAction<MultipleChoiceValue, false>(card, value, v); return new SimpleValueAction<MultipleChoiceValue, false>(value, v);
} }
// ----------------------------------------------------------------------------- : Text // ----------------------------------------------------------------------------- : Text
TextValueAction::TextValueAction(const Card* card, const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name) TextValueAction::TextValueAction(const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name)
: ValueAction(card, value) : ValueAction(value)
, selection_start(start), selection_end(end), new_selection_end(new_end) , selection_start(start), selection_end(end), new_selection_end(new_end)
, new_value(new_value) , new_value(new_value)
, name(name) , name(name)
...@@ -111,7 +116,7 @@ TextValue& TextValueAction::value() const { ...@@ -111,7 +116,7 @@ TextValue& TextValueAction::value() const {
} }
TextValueAction* toggle_format_action(const Card* card, const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name) { TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name) {
if (start > end) { if (start > end) {
swap(start, end); swap(start, end);
swap(start_i, end_i); swap(start_i, end_i);
...@@ -144,11 +149,11 @@ TextValueAction* toggle_format_action(const Card* card, const TextValueP& value, ...@@ -144,11 +149,11 @@ TextValueAction* toggle_format_action(const Card* card, const TextValueP& value,
if (value->value() == new_value) { if (value->value() == new_value) {
return nullptr; // no changes return nullptr; // no changes
} else { } else {
return new TextValueAction(card, value, start, end, end, new_value, action_name); return new TextValueAction(value, start, end, end, new_value, action_name);
} }
} }
TextValueAction* typing_action(const Card* card, const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name) { TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name) {
bool reverse = start > end; bool reverse = start > end;
if (reverse) { if (reverse) {
swap(start, end); swap(start, end);
...@@ -160,17 +165,17 @@ TextValueAction* typing_action(const Card* card, const TextValueP& value, size_t ...@@ -160,17 +165,17 @@ TextValueAction* typing_action(const Card* card, const TextValueP& value, size_t
return nullptr; return nullptr;
} else { } else {
if (reverse) { if (reverse) {
return new TextValueAction(card, value, end, start, start+untag(replacement).size(), new_value, action_name); return new TextValueAction(value, end, start, start+untag(replacement).size(), new_value, action_name);
} else { } else {
return new TextValueAction(card, value, start, end, start+untag(replacement).size(), new_value, action_name); return new TextValueAction(value, start, end, start+untag(replacement).size(), new_value, action_name);
} }
} }
} }
// ----------------------------------------------------------------------------- : Reminder text // ----------------------------------------------------------------------------- : Reminder text
TextToggleReminderAction::TextToggleReminderAction(const Card* card, const TextValueP& value, size_t pos_in) TextToggleReminderAction::TextToggleReminderAction(const TextValueP& value, size_t pos_in)
: ValueAction(card, value) : ValueAction(value)
{ {
pos = in_tag(value->value(), _("<kw-"), pos_in, pos_in); pos = in_tag(value->value(), _("<kw-"), pos_in, pos_in);
if (pos == String::npos) { if (pos == String::npos) {
...@@ -217,3 +222,19 @@ String ScriptStyleEvent::getName(bool) const { ...@@ -217,3 +222,19 @@ String ScriptStyleEvent::getName(bool) const {
void ScriptStyleEvent::perform(bool) { void ScriptStyleEvent::perform(bool) {
assert(false); // this action is just an event, it should not be performed assert(false); // this action is just an event, it should not be performed
} }
// ----------------------------------------------------------------------------- : Action performer
ValueActionPerformer::ValueActionPerformer(const ValueP& value, Card* card, const SetP& set)
: value(value), card(card), set(set)
{}
ValueActionPerformer::~ValueActionPerformer() {}
void ValueActionPerformer::addAction(ValueAction* action) {
action->isOnCard(card);
set->actions.addAction(action);
}
Package& ValueActionPerformer::getLocalPackage() {
return *set;
}
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
class Card; class Card;
class StyleSheet; class StyleSheet;
DECLARE_POINTER_TYPE(Set);
DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Style);
DECLARE_POINTER_TYPE(TextValue); DECLARE_POINTER_TYPE(TextValue);
...@@ -35,10 +36,13 @@ DECLARE_POINTER_TYPE(PackageChoiceValue); ...@@ -35,10 +36,13 @@ DECLARE_POINTER_TYPE(PackageChoiceValue);
/// An Action the changes a Value /// An Action the changes a Value
class ValueAction : public Action { class ValueAction : public Action {
public: public:
inline ValueAction(const Card* card, const ValueP& value) : valueP(value), card(card) {} inline ValueAction(const ValueP& value) : valueP(value), card(nullptr) {}
virtual String getName(bool to_undo) const; virtual String getName(bool to_undo) const;
/// We know that the value is on the given card, add that information
void isOnCard(Card* card);
const ValueP valueP; ///< The modified value const ValueP valueP; ///< The modified value
const Card* card; ///< The card the value is on, or null if it is not a card value const Card* card; ///< The card the value is on, or null if it is not a card value
}; };
...@@ -46,19 +50,19 @@ class ValueAction : public Action { ...@@ -46,19 +50,19 @@ class ValueAction : public Action {
// ----------------------------------------------------------------------------- : Simple // ----------------------------------------------------------------------------- : Simple
/// Action that updates a Value to a new value /// Action that updates a Value to a new value
ValueAction* value_action(const Card* card, const ChoiceValueP& value, const Defaultable<String>& new_value); ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value);
ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change); ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change);
ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable<Color>& new_value); ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value);
ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value); ValueAction* value_action(const ImageValueP& value, const FileName& new_value);
ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value); ValueAction* value_action(const SymbolValueP& value, const FileName& new_value);
ValueAction* value_action(const Card* card, const PackageChoiceValueP& value, const String& new_value); ValueAction* value_action(const PackageChoiceValueP& value, const String& new_value);
// ----------------------------------------------------------------------------- : Text // ----------------------------------------------------------------------------- : Text
/// An action that changes a TextValue /// An action that changes a TextValue
class TextValueAction : public ValueAction { class TextValueAction : public ValueAction {
public: public:
TextValueAction(const Card* card, const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name); TextValueAction(const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name);
virtual String getName(bool to_undo) const; virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
...@@ -77,18 +81,18 @@ class TextValueAction : public ValueAction { ...@@ -77,18 +81,18 @@ class TextValueAction : public ValueAction {
}; };
/// Action for toggling some formating tag on or off in some range /// Action for toggling some formating tag on or off in some range
TextValueAction* toggle_format_action(const Card* card, const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name); TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name);
/// Typing in a TextValue, replace the selection [start...end) with replacement /// Typing in a TextValue, replace the selection [start...end) with replacement
/** start and end are cursor positions, start_i and end_i are indices*/ /** start and end are cursor positions, start_i and end_i are indices*/
TextValueAction* typing_action(const Card* card, const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name); TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name);
// ----------------------------------------------------------------------------- : Reminder text // ----------------------------------------------------------------------------- : Reminder text
/// Toggle reminder text for a keyword on or off /// Toggle reminder text for a keyword on or off
class TextToggleReminderAction : public ValueAction { class TextToggleReminderAction : public ValueAction {
public: public:
TextToggleReminderAction(const Card* card, const TextValueP& value, size_t pos); TextToggleReminderAction(const TextValueP& value, size_t pos);
virtual String getName(bool to_undo) const; virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
...@@ -150,5 +154,24 @@ class ScriptStyleEvent : public Action { ...@@ -150,5 +154,24 @@ class ScriptStyleEvent : public Action {
const Style* style; ///< The modified style const Style* style; ///< The modified style
}; };
// ----------------------------------------------------------------------------- : Action performer
/// A loose object for performing ValueActions on a certain value.
/** Used to reduce coupling */
class ValueActionPerformer {
public:
ValueActionPerformer(const ValueP& value, Card* card, const SetP& set);
~ValueActionPerformer();
/// Perform an action. The performer takes ownerwhip of the action.
void addAction(ValueAction* action);
const ValueP value; ///< The value
Package& getLocalPackage();
private:
Card* card; ///< Card the value is on (if any)
SetP set; ///< Set for the actions
};
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -96,6 +96,7 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def) { ...@@ -96,6 +96,7 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def) {
return loc->tr(subcat, key, def); \ return loc->tr(subcat, key, def); \
} }
IMPLEMENT_TR_TYPE(Package, game_translations) //%% TODO!
IMPLEMENT_TR_TYPE(Game, game_translations) IMPLEMENT_TR_TYPE(Game, game_translations)
IMPLEMENT_TR_TYPE(StyleSheet, stylesheet_translations) IMPLEMENT_TR_TYPE(StyleSheet, stylesheet_translations)
IMPLEMENT_TR_TYPE(SymbolFont, symbol_font_translations) IMPLEMENT_TR_TYPE(SymbolFont, symbol_font_translations)
......
...@@ -149,7 +149,7 @@ class SetView : public ActionListener { ...@@ -149,7 +149,7 @@ class SetView : public ActionListener {
~SetView(); ~SetView();
/// Get the set that is currently being viewed /// Get the set that is currently being viewed
inline SetP getSet() { return set; } //inline SetP getSet() const { return set; }
/// Change the set that is being viewed /// Change the set that is being viewed
void setSet(const SetP& set); void setSet(const SetP& set);
......
...@@ -60,6 +60,10 @@ ValueViewer* DataEditor::focusedViewer() const { ...@@ -60,6 +60,10 @@ ValueViewer* DataEditor::focusedViewer() const {
return FindFocus() == this ? current_viewer : nullptr; return FindFocus() == this ? current_viewer : nullptr;
} }
void DataEditor::addAction(Action* action) {
set->actions.addAction(action);
}
// ----------------------------------------------------------------------------- : Selection // ----------------------------------------------------------------------------- : Selection
bool DataEditor::AcceptsFocus() const { bool DataEditor::AcceptsFocus() const {
......
...@@ -22,7 +22,7 @@ class DataEditor : public CardViewer { ...@@ -22,7 +22,7 @@ class DataEditor : public CardViewer {
public: public:
DataEditor(Window* parent, int id, long style = 0); DataEditor(Window* parent, int id, long style = 0);
// --------------------------------------------------- : Utility for ValueViewers // --------------------------------------------------- : Utility for ValueViewers/Editors
virtual bool drawBorders() const; virtual bool drawBorders() const;
virtual bool drawEditing() const; virtual bool drawEditing() const;
...@@ -30,6 +30,9 @@ class DataEditor : public CardViewer { ...@@ -30,6 +30,9 @@ class DataEditor : public CardViewer {
virtual wxPen borderPen(bool active) const; virtual wxPen borderPen(bool active) const;
virtual ValueViewer* focusedViewer() const; virtual ValueViewer* focusedViewer() const;
virtual void addAction(Action* action);
inline SetP getSetForActions() { return set; }
// --------------------------------------------------- : Selection // --------------------------------------------------- : Selection
/// Select the given viewer, sends focus events /// Select the given viewer, sends focus events
......
...@@ -162,7 +162,7 @@ bool CardListBase::doPaste() { ...@@ -162,7 +162,7 @@ bool CardListBase::doPaste() {
ok = data.getCards(set, new_cards); ok = data.getCards(set, new_cards);
if (!ok) return false; if (!ok) return false;
// add card to set // add card to set
set->actions.add(new AddCardAction(ADD, *set, new_cards)); set->actions.addAction(new AddCardAction(ADD, *set, new_cards));
return true; return true;
} }
bool CardListBase::doDelete() { bool CardListBase::doDelete() {
...@@ -176,7 +176,7 @@ bool CardListBase::doDelete() { ...@@ -176,7 +176,7 @@ bool CardListBase::doDelete() {
} }
if (cards_to_delete.empty()) return false; if (cards_to_delete.empty()) return false;
// delete cards // delete cards
set->actions.add(new AddCardAction(REMOVE, *set, cards_to_delete)); set->actions.addAction(new AddCardAction(REMOVE, *set, cards_to_delete));
return true; return true;
} }
...@@ -345,7 +345,7 @@ void CardListBase::onDrag(wxMouseEvent& ev) { ...@@ -345,7 +345,7 @@ void CardListBase::onDrag(wxMouseEvent& ev) {
findSelectedItemPos(); findSelectedItemPos();
if (item != selected_item_pos) { if (item != selected_item_pos) {
// move card in the set // move card in the set
set->actions.add(new ReorderCardsAction(*set, item, selected_item_pos)); set->actions.addAction(new ReorderCardsAction(*set, item, selected_item_pos));
} }
} }
} }
......
...@@ -96,9 +96,9 @@ void KeywordList::updateUsageStatistics() { ...@@ -96,9 +96,9 @@ void KeywordList::updateUsageStatistics() {
// ----------------------------------------------------------------------------- : Clipboard // ----------------------------------------------------------------------------- : Clipboard
bool KeywordList::canCopy() const { return !!selected_item; } bool KeywordList::canDelete() const { return !getKeyword()->fixed; }
bool KeywordList::canCut() const { return canCopy() && !getKeyword()->fixed; } bool KeywordList::canCopy() const { return !!selected_item; }
bool KeywordList::canPaste() const { bool KeywordList::canPaste() const {
return wxTheClipboard->IsSupported(KeywordDataObject::format); return wxTheClipboard->IsSupported(KeywordDataObject::format);
} }
...@@ -127,14 +127,14 @@ bool KeywordList::doPaste() { ...@@ -127,14 +127,14 @@ bool KeywordList::doPaste() {
// add keyword to set // add keyword to set
KeywordP keyword = data.getKeyword(set); KeywordP keyword = data.getKeyword(set);
if (keyword) { if (keyword) {
set->actions.add(new AddKeywordAction(ADD, *set, keyword)); set->actions.addAction(new AddKeywordAction(ADD, *set, keyword));
return true; return true;
} else { } else {
return false; return false;
} }
} }
bool KeywordList::doDelete() { bool KeywordList::doDelete() {
set->actions.add(new AddKeywordAction(REMOVE, *set, getKeyword())); set->actions.addAction(new AddKeywordAction(REMOVE, *set, getKeyword()));
return true; return true;
} }
......
...@@ -53,9 +53,9 @@ class KeywordList : public ItemList, public SetView { ...@@ -53,9 +53,9 @@ class KeywordList : public ItemList, public SetView {
// --------------------------------------------------- : Clipboard // --------------------------------------------------- : Clipboard
bool canCut() const; bool canDelete() const;
bool canCopy() const; bool canCopy() const;
bool canPaste() const; bool canPaste() const;
// Try to perform a clipboard operation, return success // Try to perform a clipboard operation, return success
bool doCut(); bool doCut();
bool doCopy(); bool doCopy();
......
...@@ -205,6 +205,12 @@ void SetInfoEditor::onChangeSet() { ...@@ -205,6 +205,12 @@ void SetInfoEditor::onChangeSet() {
setData(set->data); setData(set->data);
} }
Package& SetInfoEditor::getStylePackage() const {
return DataEditor::getStylePackage();
// TODO: Use the game
//return getGame();
}
// ----------------------------------------------------------------------------- : StylingEditor // ----------------------------------------------------------------------------- : StylingEditor
StylingEditor::StylingEditor(Window* parent, int id, long style) StylingEditor::StylingEditor(Window* parent, int id, long style)
...@@ -232,7 +238,11 @@ ExportOptionsEditor::ExportOptionsEditor(Window* parent, int id, long style) ...@@ -232,7 +238,11 @@ ExportOptionsEditor::ExportOptionsEditor(Window* parent, int id, long style)
{} {}
void ExportOptionsEditor::showExport(const ExportTemplateP& export_template) { void ExportOptionsEditor::showExport(const ExportTemplateP& export_template) {
this->export_template = export_template;
setStyles(set->stylesheet, export_template->option_style); setStyles(set->stylesheet, export_template->option_style);
setData(settings.exportOptionsFor(*export_template)); setData(settings.exportOptionsFor(*export_template));
} }
Package& ExportOptionsEditor::getStylePackage() const {
return *export_template;
}
...@@ -58,6 +58,8 @@ class NativeLookEditor : public DataEditor { ...@@ -58,6 +58,8 @@ class NativeLookEditor : public DataEditor {
class SetInfoEditor : public NativeLookEditor { class SetInfoEditor : public NativeLookEditor {
public: public:
SetInfoEditor(Window* parent, int id, long style = 0); SetInfoEditor(Window* parent, int id, long style = 0);
virtual Package& getStylePackage() const;
protected: protected:
virtual void onChangeSet(); virtual void onChangeSet();
}; };
...@@ -73,7 +75,6 @@ class StylingEditor : public NativeLookEditor { ...@@ -73,7 +75,6 @@ class StylingEditor : public NativeLookEditor {
void showStylesheet(const StyleSheetP& stylesheet); void showStylesheet(const StyleSheetP& stylesheet);
/// Show the styling for given card /// Show the styling for given card
void showCard(const CardP& card); void showCard(const CardP& card);
protected: protected:
virtual void onChangeSet(); virtual void onChangeSet();
}; };
...@@ -87,6 +88,10 @@ class ExportOptionsEditor : public NativeLookEditor { ...@@ -87,6 +88,10 @@ class ExportOptionsEditor : public NativeLookEditor {
/// Show the options for given export template /// Show the options for given export template
void showExport(const ExportTemplateP& export_template); void showExport(const ExportTemplateP& export_template);
virtual Package& getStylePackage() const;
private:
ExportTemplateP export_template;
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -207,7 +207,7 @@ void CardsPanel::onCommand(int id) { ...@@ -207,7 +207,7 @@ void CardsPanel::onCommand(int id) {
card_list->selectNext(); card_list->selectNext();
break; break;
case ID_CARD_ADD: case ID_CARD_ADD:
set->actions.add(new AddCardAction(*set)); set->actions.addAction(new AddCardAction(*set));
break; break;
case ID_CARD_REMOVE: case ID_CARD_REMOVE:
card_list->doDelete(); card_list->doDelete();
......
...@@ -154,12 +154,12 @@ void KeywordsPanel::onCommand(int id) { ...@@ -154,12 +154,12 @@ void KeywordsPanel::onCommand(int id) {
list->selectNext(); list->selectNext();
break; break;
case ID_KEYWORD_ADD: case ID_KEYWORD_ADD:
set->actions.add(new AddKeywordAction(*set)); set->actions.addAction(new AddKeywordAction(*set));
break; break;
case ID_KEYWORD_REMOVE: case ID_KEYWORD_REMOVE:
if (!list->getKeyword()->fixed) { if (list->canDelete()) {
// only remove set keywords // only remove set keywords
set->actions.add(new AddKeywordAction(REMOVE, *set, list->getKeyword())); list->doDelete();
} }
break; break;
case ID_KEYWORD_ADD_PARAM: { case ID_KEYWORD_ADD_PARAM: {
...@@ -336,7 +336,7 @@ void KeywordsPanel::onModeChange(wxCommandEvent& ev) { ...@@ -336,7 +336,7 @@ void KeywordsPanel::onModeChange(wxCommandEvent& ev) {
if (!list->getKeyword()) return; if (!list->getKeyword()) return;
int sel = mode->GetSelection(); int sel = mode->GetSelection();
if (sel >= 0 && (size_t)sel < set->game->keyword_modes.size()) { if (sel >= 0 && (size_t)sel < set->game->keyword_modes.size()) {
set->actions.add(new ChangeKeywordModeAction(*list->getKeyword(), set->game->keyword_modes[sel]->name)); set->actions.addAction(new ChangeKeywordModeAction(*list->getKeyword(), set->game->keyword_modes[sel]->name));
} }
} }
......
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2008 Twan van Laarhoven and "coppro" |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/random_pack_panel.hpp>
#include <gui/control/card_viewer.hpp>
#include <gui/control/filtered_card_list.hpp>
// ----------------------------------------------------------------------------- : RandomPackPanel
RandomPackPanel::RandomPackPanel(Window* parent, int id)
: SetWindowPanel(parent, id)
{
// init controls
preview = new CardViewer(this, wxID_ANY);
card_list = new FilteredCardList(this, wxID_ANY);
// init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(preview, 0, wxRIGHT, 2);
wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(card_list, 1, wxEXPAND | wxTOP, 4);
s->Add(s2, 1, wxEXPAND, 8);
s->SetSizeHints(this);
SetSizer(s);
}
void RandomPackPanel::onChangeSet() {
preview ->setSet(set);
card_list->setSet(set);
}
// ----------------------------------------------------------------------------- : UI
void RandomPackPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
// ?
}
void RandomPackPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
// ?
}
void RandomPackPanel::onUpdateUI(wxUpdateUIEvent& ev) {
// ?
}
void RandomPackPanel::onCommand(int id) {
// ?
}
// ----------------------------------------------------------------------------- : Clipboard
bool RandomPackPanel::canCopy() const { return card_list->canCopy(); }
void RandomPackPanel::doCopy() { card_list->doCopy(); }
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2008 Twan van Laarhoven and "coppro" |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_GUI_SET_RANDOM_PACK_PANEL
#define HEADER_GUI_SET_RANDOM_PACK_PANEL
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/set/panel.hpp>
class CardViewer;
class FilteredCardList;
// ----------------------------------------------------------------------------- : RandomPackPanel
/// A SetWindowPanel for creating random booster packs
class RandomPackPanel : public SetWindowPanel {
public:
RandomPackPanel(Window* parent, int id);
// --------------------------------------------------- : UI
virtual void onChangeSet();
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
virtual void onUpdateUI(wxUpdateUIEvent&);
virtual void onCommand(int id);
// --------------------------------------------------- : Clipboard
virtual bool canCopy() const;
virtual void doCopy();
private:
CardViewer* preview; ///< Card preview
FilteredCardList* card_list; ///< The list of cards
};
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -131,18 +131,18 @@ void StylePanel::onStyleSelect(wxCommandEvent&) { ...@@ -131,18 +131,18 @@ void StylePanel::onStyleSelect(wxCommandEvent&) {
// select no special style when selecting the same style as the set default // select no special style when selecting the same style as the set default
stylesheet = StyleSheetP(); stylesheet = StyleSheetP();
} }
set->actions.add(new ChangeCardStyleAction(card, stylesheet)); set->actions.addAction(new ChangeCardStyleAction(card, stylesheet));
Layout(); Layout();
} }
} }
void StylePanel::onUseForAll(wxCommandEvent&) { void StylePanel::onUseForAll(wxCommandEvent&) {
set->actions.add(new ChangeSetStyleAction(*set, card)); set->actions.addAction(new ChangeSetStyleAction(*set, card));
Layout(); Layout();
} }
void StylePanel::onUseCustom(wxCommandEvent&) { void StylePanel::onUseCustom(wxCommandEvent&) {
set->actions.add(new ChangeCardHasStylingAction(*set, card)); set->actions.addAction(new ChangeCardHasStylingAction(*set, card));
} }
BEGIN_EVENT_TABLE(StylePanel, wxPanel) BEGIN_EVENT_TABLE(StylePanel, wxPanel)
......
...@@ -100,7 +100,7 @@ void SymbolBasicShapeEditor::onLeftDown (const Vector2D& pos, wxMouseEvent& ev ...@@ -100,7 +100,7 @@ void SymbolBasicShapeEditor::onLeftDown (const Vector2D& pos, wxMouseEvent& ev
void SymbolBasicShapeEditor::onLeftUp (const Vector2D& pos, wxMouseEvent& ev) { void SymbolBasicShapeEditor::onLeftUp (const Vector2D& pos, wxMouseEvent& ev) {
if (drawing && shape) { if (drawing && shape) {
// Finalize the shape // Finalize the shape
getSymbol()->actions.add(new AddSymbolPartAction(*getSymbol(), shape)); addAction(new AddSymbolPartAction(*getSymbol(), shape));
// Select the part // Select the part
control.selectPart(shape); control.selectPart(shape);
// no need to clean up, this editor is replaced // no need to clean up, this editor is replaced
......
...@@ -15,3 +15,7 @@ ...@@ -15,3 +15,7 @@
void SymbolEditorBase::SetStatusText(const String& text) { void SymbolEditorBase::SetStatusText(const String& text) {
control.parent->SetStatusText(text); control.parent->SetStatusText(text);
} }
void SymbolEditorBase::addAction(Action* action, bool allow_merge) {
getSymbol()->actions.addAction(action, allow_merge);
}
...@@ -28,6 +28,10 @@ class SymbolEditorBase : public IntrusivePtrVirtualBase { ...@@ -28,6 +28,10 @@ class SymbolEditorBase : public IntrusivePtrVirtualBase {
SymbolControl& control; SymbolControl& control;
inline SymbolP getSymbol() { return control.getSymbol(); } inline SymbolP getSymbol() { return control.getSymbol(); }
/// Perform an action
void addAction(Action* action, bool allow_merge = true);
void SetStatusText(const String& text); void SetStatusText(const String& text);
public: public:
......
...@@ -166,9 +166,9 @@ void SymbolPartList::onLeftUp(wxMouseEvent& ev) { ...@@ -166,9 +166,9 @@ void SymbolPartList::onLeftUp(wxMouseEvent& ev) {
if (par != drop_parent && par->parts.size() == 1 && !par->isSymbolSymmetry()) { if (par != drop_parent && par->parts.size() == 1 && !par->isSymbolSymmetry()) {
// this leaves a group without elements, remove it // this leaves a group without elements, remove it
findParent(*par, par, drag_position); // parent of the group findParent(*par, par, drag_position); // parent of the group
symbol->actions.add(new UngroupReorderSymbolPartsAction(*par, drag_position, *drop_parent, drop_position)); symbol->actions.addAction(new UngroupReorderSymbolPartsAction(*par, drag_position, *drop_parent, drop_position));
} else { } else {
symbol->actions.add(new ReorderSymbolPartsAction(*par, drag_position, *drop_parent, drop_position)); symbol->actions.addAction(new ReorderSymbolPartsAction(*par, drag_position, *drop_parent, drop_position));
} }
} else { } else {
Refresh(false); Refresh(false);
...@@ -253,14 +253,14 @@ void SymbolPartList::onChar(wxKeyEvent& ev) { ...@@ -253,14 +253,14 @@ void SymbolPartList::onChar(wxKeyEvent& ev) {
if (cursor > 0 && cursor <= typing_in->name.size()) { if (cursor > 0 && cursor <= typing_in->name.size()) {
String new_name = typing_in->name; String new_name = typing_in->name;
new_name.erase(cursor - 1, 1); new_name.erase(cursor - 1, 1);
symbol->actions.add(new SymbolPartNameAction(typing_in, new_name, cursor, cursor - 1)); symbol->actions.addAction(new SymbolPartNameAction(typing_in, new_name, cursor, cursor - 1));
} }
break; break;
case WXK_DELETE: case WXK_DELETE:
if (cursor < typing_in->name.size()) { if (cursor < typing_in->name.size()) {
String new_name = typing_in->name; String new_name = typing_in->name;
new_name.erase(cursor, 1); new_name.erase(cursor, 1);
symbol->actions.add(new SymbolPartNameAction(typing_in, new_name, cursor, cursor)); symbol->actions.addAction(new SymbolPartNameAction(typing_in, new_name, cursor, cursor));
} }
break; break;
default: default:
...@@ -277,7 +277,7 @@ void SymbolPartList::onChar(wxKeyEvent& ev) { ...@@ -277,7 +277,7 @@ void SymbolPartList::onChar(wxKeyEvent& ev) {
#endif #endif
String new_name = typing_in->name; String new_name = typing_in->name;
new_name.insert(cursor, 1, key); new_name.insert(cursor, 1, key);
symbol->actions.add(new SymbolPartNameAction(typing_in, new_name, cursor, cursor + 1)); symbol->actions.addAction(new SymbolPartNameAction(typing_in, new_name, cursor, cursor + 1));
} }
} }
} }
......
...@@ -254,7 +254,7 @@ void SymbolPointEditor::onLeftDClick(const Vector2D& pos, wxMouseEvent& ev) { ...@@ -254,7 +254,7 @@ void SymbolPointEditor::onLeftDClick(const Vector2D& pos, wxMouseEvent& ev) {
if (hovering == SELECTED_NEW_POINT) { if (hovering == SELECTED_NEW_POINT) {
// Add point // Add point
ControlPointAddAction* act = new ControlPointAddAction(part, hover_line_1_idx, hover_line_t); ControlPointAddAction* act = new ControlPointAddAction(part, hover_line_1_idx, hover_line_t);
getSymbol()->actions.add(act); addAction(act);
// select the new point // select the new point
selectPoint(act->getNewPoint(), false); selectPoint(act->getNewPoint(), false);
selection = SELECTED_POINTS; selection = SELECTED_POINTS;
...@@ -262,7 +262,7 @@ void SymbolPointEditor::onLeftDClick(const Vector2D& pos, wxMouseEvent& ev) { ...@@ -262,7 +262,7 @@ void SymbolPointEditor::onLeftDClick(const Vector2D& pos, wxMouseEvent& ev) {
// Delete point // Delete point
selected_points.clear(); selected_points.clear();
selectPoint(hover_handle.point, false); selectPoint(hover_handle.point, false);
getSymbol()->actions.add(control_point_remove_action(part, selected_points)); addAction(control_point_remove_action(part, selected_points));
selected_points.clear(); selected_points.clear();
selection = SELECTED_NONE; selection = SELECTED_NONE;
} }
...@@ -288,7 +288,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx ...@@ -288,7 +288,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
if (controlPointMoveAction) controlPointMoveAction = 0; if (controlPointMoveAction) controlPointMoveAction = 0;
if (!curveDragAction) { if (!curveDragAction) {
curveDragAction = new CurveDragAction(selected_line1, selected_line2); curveDragAction = new CurveDragAction(selected_line1, selected_line2);
getSymbol()->actions.add(curveDragAction); addAction(curveDragAction);
} }
curveDragAction->move(delta, selected_line_t); curveDragAction->move(delta, selected_line_t);
control.Refresh(false); control.Refresh(false);
...@@ -298,7 +298,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx ...@@ -298,7 +298,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
if (!controlPointMoveAction) { if (!controlPointMoveAction) {
// create action we can add this movement to // create action we can add this movement to
controlPointMoveAction = new ControlPointMoveAction(selected_points); controlPointMoveAction = new ControlPointMoveAction(selected_points);
getSymbol()->actions.add(controlPointMoveAction); addAction(controlPointMoveAction);
} }
controlPointMoveAction->constrain = ev.ControlDown(); // ctrl constrains controlPointMoveAction->constrain = ev.ControlDown(); // ctrl constrains
controlPointMoveAction->snap = snap(ev); controlPointMoveAction->snap = snap(ev);
...@@ -309,7 +309,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx ...@@ -309,7 +309,7 @@ void SymbolPointEditor::onMouseDrag(const Vector2D& from, const Vector2D& to, wx
// Move the selected handle // Move the selected handle
if (!handleMoveAction) { if (!handleMoveAction) {
handleMoveAction = new HandleMoveAction(selected_handle); handleMoveAction = new HandleMoveAction(selected_handle);
getSymbol()->actions.add(handleMoveAction); addAction(handleMoveAction);
} }
handleMoveAction->constrain = ev.ControlDown(); // ctrl constrains handleMoveAction->constrain = ev.ControlDown(); // ctrl constrains
handleMoveAction->snap = snap(ev); handleMoveAction->snap = snap(ev);
...@@ -368,14 +368,14 @@ void SymbolPointEditor::onChar(wxKeyEvent& ev) { ...@@ -368,14 +368,14 @@ void SymbolPointEditor::onChar(wxKeyEvent& ev) {
if (selection == SELECTED_POINTS || selection == SELECTED_LINE) { if (selection == SELECTED_POINTS || selection == SELECTED_LINE) {
// Move all selected points // Move all selected points
controlPointMoveAction = new ControlPointMoveAction(selected_points); controlPointMoveAction = new ControlPointMoveAction(selected_points);
getSymbol()->actions.add(controlPointMoveAction); addAction(controlPointMoveAction);
controlPointMoveAction->move(delta); controlPointMoveAction->move(delta);
new_point += delta; new_point += delta;
control.Refresh(false); control.Refresh(false);
} else if (selection == SELECTED_HANDLE) { } else if (selection == SELECTED_HANDLE) {
// Move the selected handle // Move the selected handle
handleMoveAction = new HandleMoveAction(selected_handle); handleMoveAction = new HandleMoveAction(selected_handle);
getSymbol()->actions.add(handleMoveAction); addAction(handleMoveAction);
handleMoveAction->move(delta); handleMoveAction->move(delta);
control.Refresh(false); control.Refresh(false);
} }
...@@ -466,7 +466,7 @@ void SymbolPointEditor::resetActions() { ...@@ -466,7 +466,7 @@ void SymbolPointEditor::resetActions() {
void SymbolPointEditor::deleteSelection() { void SymbolPointEditor::deleteSelection() {
if (!selected_points.empty()) { if (!selected_points.empty()) {
getSymbol()->actions.add(control_point_remove_action(part, selected_points)); addAction(control_point_remove_action(part, selected_points));
selected_points.clear(); selected_points.clear();
resetActions(); resetActions();
control.Refresh(false); control.Refresh(false);
...@@ -477,12 +477,12 @@ void SymbolPointEditor::onChangeSegment(SegmentMode mode) { ...@@ -477,12 +477,12 @@ void SymbolPointEditor::onChangeSegment(SegmentMode mode) {
assert(selected_line1); assert(selected_line1);
assert(selected_line2); assert(selected_line2);
if (selected_line1->segment_after == mode) return; if (selected_line1->segment_after == mode) return;
getSymbol()->actions.add(new SegmentModeAction(selected_line1, selected_line2, mode)); addAction(new SegmentModeAction(selected_line1, selected_line2, mode));
control.Refresh(false); control.Refresh(false);
} }
void SymbolPointEditor::onChangeLock(LockMode mode) { void SymbolPointEditor::onChangeLock(LockMode mode) {
getSymbol()->actions.add(new LockModeAction(*selected_points.begin(), mode)); addAction(new LockModeAction(*selected_points.begin(), mode));
control.Refresh(false); control.Refresh(false);
} }
......
...@@ -173,22 +173,22 @@ void SymbolSelectEditor::onUpdateUI(wxUpdateUIEvent& ev) { ...@@ -173,22 +173,22 @@ void SymbolSelectEditor::onUpdateUI(wxUpdateUIEvent& ev) {
void SymbolSelectEditor::onCommand(int id) { void SymbolSelectEditor::onCommand(int id) {
if (id >= ID_SYMBOL_COMBINE && id < ID_SYMBOL_COMBINE_MAX) { if (id >= ID_SYMBOL_COMBINE && id < ID_SYMBOL_COMBINE_MAX) {
// change combine mode // change combine mode
getSymbol()->actions.add(new CombiningModeAction( addAction(new CombiningModeAction(
control.selected_parts.get(), control.selected_parts.get(),
static_cast<SymbolShapeCombine>(id - ID_SYMBOL_COMBINE) static_cast<SymbolShapeCombine>(id - ID_SYMBOL_COMBINE)
)); ));
control.Refresh(false); control.Refresh(false);
} else if (id == ID_EDIT_DUPLICATE && !isEditing()) { } else if (id == ID_EDIT_DUPLICATE && !isEditing()) {
// duplicate selection, not when dragging // duplicate selection, not when dragging
getSymbol()->actions.add(new DuplicateSymbolPartsAction(*getSymbol(), control.selected_parts.get())); addAction(new DuplicateSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
control.Refresh(false); control.Refresh(false);
} else if (id == ID_EDIT_GROUP && !isEditing()) { } else if (id == ID_EDIT_GROUP && !isEditing()) {
// group selection, not when dragging // group selection, not when dragging
getSymbol()->actions.add(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), new_intrusive<SymbolGroup>())); addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), new_intrusive<SymbolGroup>()));
control.Refresh(false); control.Refresh(false);
} else if (id == ID_EDIT_UNGROUP && !isEditing()) { } else if (id == ID_EDIT_UNGROUP && !isEditing()) {
// ungroup selection, not when dragging // ungroup selection, not when dragging
getSymbol()->actions.add(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get())); addAction(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
control.Refresh(false); control.Refresh(false);
} }
} }
...@@ -313,23 +313,23 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to, ...@@ -313,23 +313,23 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
if (scaleX == 0 || scaleY == 0) { if (scaleX == 0 || scaleY == 0) {
// shear, center/fixed point on the opposite side // shear, center/fixed point on the opposite side
shearAction = new SymbolPartShearAction(control.selected_parts.get(), handlePos(-scaleX, -scaleY)); shearAction = new SymbolPartShearAction(control.selected_parts.get(), handlePos(-scaleX, -scaleY));
getSymbol()->actions.add(shearAction); addAction(shearAction);
} else { } else {
// rotate // rotate
rotateAction = new SymbolPartRotateAction(control.selected_parts.get(), center); rotateAction = new SymbolPartRotateAction(control.selected_parts.get(), center);
getSymbol()->actions.add(rotateAction); addAction(rotateAction);
startAngle = angleTo(to); startAngle = angleTo(to);
} }
} else { } else {
// we are on a handle; start scaling // we are on a handle; start scaling
scaleAction = new SymbolPartScaleAction(control.selected_parts.get(), scaleX, scaleY); scaleAction = new SymbolPartScaleAction(control.selected_parts.get(), scaleX, scaleY);
getSymbol()->actions.add(scaleAction); addAction(scaleAction);
} }
} else { } else {
// move // move
click_mode = CLICK_MOVE; click_mode = CLICK_MOVE;
moveAction = new SymbolPartMoveAction(control.selected_parts.get()); moveAction = new SymbolPartMoveAction(control.selected_parts.get());
getSymbol()->actions.add(moveAction); addAction(moveAction);
} }
} }
...@@ -399,7 +399,7 @@ void SymbolSelectEditor::onKeyChange (wxKeyEvent& ev) { ...@@ -399,7 +399,7 @@ void SymbolSelectEditor::onKeyChange (wxKeyEvent& ev) {
void SymbolSelectEditor::onChar(wxKeyEvent& ev) { void SymbolSelectEditor::onChar(wxKeyEvent& ev) {
if (ev.GetKeyCode() == WXK_DELETE) { if (ev.GetKeyCode() == WXK_DELETE) {
// delete selected parts // delete selected parts
getSymbol()->actions.add(new RemoveSymbolPartsAction(*getSymbol(), control.selected_parts.get())); addAction(new RemoveSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
if (control.selected_parts.selected(highlightPart)) highlightPart = SymbolPartP(); // deleted it if (control.selected_parts.selected(highlightPart)) highlightPart = SymbolPartP(); // deleted it
control.selected_parts.clear(); control.selected_parts.clear();
resetActions(); resetActions();
...@@ -416,7 +416,7 @@ void SymbolSelectEditor::onChar(wxKeyEvent& ev) { ...@@ -416,7 +416,7 @@ void SymbolSelectEditor::onChar(wxKeyEvent& ev) {
ev.Skip(); ev.Skip();
return; return;
} }
getSymbol()->actions.add(new SymbolPartMoveAction(control.selected_parts.get(), delta)); addAction(new SymbolPartMoveAction(control.selected_parts.get(), delta));
} }
} }
......
...@@ -107,13 +107,13 @@ void SymbolSymmetryEditor::onCommand(int id) { ...@@ -107,13 +107,13 @@ void SymbolSymmetryEditor::onCommand(int id) {
if (id >= ID_SYMMETRY && id < ID_SYMMETRY_MAX) { if (id >= ID_SYMMETRY && id < ID_SYMMETRY_MAX) {
SymbolSymmetryType kind = id == ID_SYMMETRY_ROTATION ? SYMMETRY_ROTATION : SYMMETRY_REFLECTION; SymbolSymmetryType kind = id == ID_SYMMETRY_ROTATION ? SYMMETRY_ROTATION : SYMMETRY_REFLECTION;
if (symmetry && symmetry->kind != kind) { if (symmetry && symmetry->kind != kind) {
getSymbol()->actions.add(new SymmetryTypeAction(*symmetry, kind)); addAction(new SymmetryTypeAction(*symmetry, kind));
control.Refresh(false); control.Refresh(false);
} }
resetActions(); resetActions();
} else if (id == ID_COPIES) { } else if (id == ID_COPIES) {
if (symmetry && symmetry->copies != copies->GetValue()) { if (symmetry && symmetry->copies != copies->GetValue()) {
getSymbol()->actions.add(new SymmetryCopiesAction(*symmetry, copies->GetValue())); addAction(new SymmetryCopiesAction(*symmetry, copies->GetValue()));
control.Refresh(false); control.Refresh(false);
} }
resetActions(); resetActions();
...@@ -124,11 +124,11 @@ void SymbolSymmetryEditor::onCommand(int id) { ...@@ -124,11 +124,11 @@ void SymbolSymmetryEditor::onCommand(int id) {
symmetry->center = Vector2D(0.5,0.5); symmetry->center = Vector2D(0.5,0.5);
symmetry->handle = Vector2D(0.2,0); symmetry->handle = Vector2D(0.2,0);
symmetry->name = symmetry->expectedName(); symmetry->name = symmetry->expectedName();
getSymbol()->actions.add(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), symmetry)); addAction(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), symmetry));
control.selected_parts.select(symmetry); control.selected_parts.select(symmetry);
control.Refresh(false); control.Refresh(false);
} else if (id == ID_REMOVE_SYMMETRY) { } else if (id == ID_REMOVE_SYMMETRY) {
getSymbol()->actions.add(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get())); addAction(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
symmetry = SymbolSymmetryP(); symmetry = SymbolSymmetryP();
control.Refresh(false); control.Refresh(false);
} }
...@@ -158,7 +158,7 @@ void SymbolSymmetryEditor::onMouseDrag (const Vector2D& from, const Vector2D& t ...@@ -158,7 +158,7 @@ void SymbolSymmetryEditor::onMouseDrag (const Vector2D& from, const Vector2D& t
symmetryMoveAction = new SymmetryMoveAction(*symmetry, selection == SELECTION_HANDLE); symmetryMoveAction = new SymmetryMoveAction(*symmetry, selection == SELECTION_HANDLE);
symmetryMoveAction->constrain = ev.ControlDown(); symmetryMoveAction->constrain = ev.ControlDown();
symmetryMoveAction->snap = ev.ShiftDown() != settings.symbol_grid_snap ? settings.symbol_grid_size : 0; symmetryMoveAction->snap = ev.ShiftDown() != settings.symbol_grid_snap ? settings.symbol_grid_size : 0;
getSymbol()->actions.add(symmetryMoveAction); addAction(symmetryMoveAction);
} }
symmetryMoveAction->move(to - from); symmetryMoveAction->move(to - from);
control.Refresh(false); control.Refresh(false);
......
...@@ -12,23 +12,28 @@ ...@@ -12,23 +12,28 @@
#include <gui/symbol/part_list.hpp> #include <gui/symbol/part_list.hpp>
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <data/set.hpp>
#include <data/field/symbol.hpp> #include <data/field/symbol.hpp>
#include <data/format/image_to_symbol.hpp> #include <data/format/image_to_symbol.hpp>
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <data/set.hpp> // :(
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <util/io/reader.hpp> #include <util/io/reader.hpp>
#include <util/io/package.hpp>
#include <util/error.hpp> #include <util/error.hpp>
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/wfstream.h> #include <wx/wfstream.h>
// ----------------------------------------------------------------------------- : Constructor // ----------------------------------------------------------------------------- : Constructor
SymbolWindow::SymbolWindow(Window* parent) { SymbolWindow::SymbolWindow(Window* parent)
: performer(nullptr)
{
init(parent, default_symbol()); init(parent, default_symbol());
} }
SymbolWindow::SymbolWindow(Window* parent, const String& filename) { SymbolWindow::SymbolWindow(Window* parent, const String& filename)
: performer(nullptr)
{
// open file // open file
Reader reader(new_shared1<wxFileInputStream>(filename), nullptr, filename); Reader reader(new_shared1<wxFileInputStream>(filename), nullptr, filename);
SymbolP symbol; SymbolP symbol;
...@@ -36,15 +41,17 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename) { ...@@ -36,15 +41,17 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename) {
init(parent, symbol); init(parent, symbol);
} }
SymbolWindow::SymbolWindow(Window* parent, const SetP& set, const Card* card, const SymbolValueP& value) SymbolWindow::SymbolWindow(Window* parent, ValueActionPerformer* performer)
: value(value), card(card), set(set) : performer(performer)
{ {
// attempt to load symbol // attempt to load symbol
SymbolP symbol; SymbolP symbol;
SymbolValueP value = static_pointer_cast<SymbolValue>(performer->value);
if (!value->filename.empty()) { if (!value->filename.empty()) {
try { try {
// load symbol // load symbol
symbol = set->readFile<SymbolP>(value->filename); Package& package = performer->getLocalPackage();
symbol = package.readFile<SymbolP>(value->filename);
} catch (const Error& e) { } catch (const Error& e) {
handle_error(e); handle_error(e);
} }
...@@ -52,6 +59,9 @@ SymbolWindow::SymbolWindow(Window* parent, const SetP& set, const Card* card, co ...@@ -52,6 +59,9 @@ SymbolWindow::SymbolWindow(Window* parent, const SetP& set, const Card* card, co
if (!symbol) symbol = default_symbol(); if (!symbol) symbol = default_symbol();
init(parent, symbol); init(parent, symbol);
} }
SymbolWindow::~SymbolWindow() {
delete performer;
}
void SymbolWindow::init(Window* parent, SymbolP symbol) { void SymbolWindow::init(Window* parent, SymbolP symbol) {
Create(parent, wxID_ANY, _TITLE_("symbol editor"), wxDefaultPosition, wxSize(650,600), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE); Create(parent, wxID_ANY, _TITLE_("symbol editor"), wxDefaultPosition, wxSize(650,600), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
...@@ -233,11 +243,13 @@ void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) { ...@@ -233,11 +243,13 @@ void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
} }
void SymbolWindow::onFileStore(wxCommandEvent& ev) { void SymbolWindow::onFileStore(wxCommandEvent& ev) {
if (value) { if (performer) {
FileName new_filename = set->newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package SymbolValueP value = static_pointer_cast<SymbolValue>(performer->value);
Writer writer(set->openOut(new_filename)); Package& package = performer->getLocalPackage();
FileName new_filename = package.newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
Writer writer(package.openOut(new_filename));
writer.handle(control->getSymbol()); writer.handle(control->getSymbol());
set->actions.add(value_action(card, value, new_filename)); performer->addAction(value_action(value, new_filename));
} }
} }
...@@ -273,7 +285,7 @@ void SymbolWindow::onUpdateUI(wxUpdateUIEvent& ev) { ...@@ -273,7 +285,7 @@ void SymbolWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch(ev.GetId()) { switch(ev.GetId()) {
// file menu // file menu
case ID_FILE_STORE: { case ID_FILE_STORE: {
ev.Enable(value); ev.Enable(performer);
break; break;
// undo/redo // undo/redo
} case ID_EDIT_UNDO: { } case ID_EDIT_UNDO: {
......
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
class SymbolControl; class SymbolControl;
class SymbolPartList; class SymbolPartList;
class Card; DECLARE_POINTER_TYPE(ValueActionPerformer);
DECLARE_POINTER_TYPE(SymbolValue);
DECLARE_POINTER_TYPE(Set);
// ----------------------------------------------------------------------------- : SymbolWindow // ----------------------------------------------------------------------------- : SymbolWindow
...@@ -29,7 +27,8 @@ class SymbolWindow : public Frame { ...@@ -29,7 +27,8 @@ class SymbolWindow : public Frame {
/// Construct a SymbolWindow showing a symbol from a file /// Construct a SymbolWindow showing a symbol from a file
SymbolWindow(Window* parent, const String& filename); SymbolWindow(Window* parent, const String& filename);
/// Construct a SymbolWindow showing a symbol value in a set /// Construct a SymbolWindow showing a symbol value in a set
SymbolWindow(Window* parent, const SetP& set, const Card* card, const SymbolValueP& value); SymbolWindow(Window* parent, ValueActionPerformer* performer);
~SymbolWindow();
private: private:
// --------------------------------------------------- : Children // --------------------------------------------------- : Children
...@@ -41,9 +40,7 @@ class SymbolWindow : public Frame { ...@@ -41,9 +40,7 @@ class SymbolWindow : public Frame {
SymbolPartList* parts; ///< A list of parts in the symbol SymbolPartList* parts; ///< A list of parts in the symbol
// when editing a symbol field // when editing a symbol field
SymbolValueP value; ValueActionPerformer* performer;
const Card* card;
SetP set;
// --------------------------------------------------- : Event handling // --------------------------------------------------- : Event handling
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <gui/util.hpp> #include <gui/util.hpp>
#include <gui/thumbnail_thread.hpp> #include <gui/thumbnail_thread.hpp>
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <data/stylesheet.hpp>
#include <script/image.hpp> #include <script/image.hpp>
#include <wx/imaglist.h> #include <wx/imaglist.h>
...@@ -28,7 +27,6 @@ class ChoiceThumbnailRequest : public ThumbnailRequest { ...@@ -28,7 +27,6 @@ class ChoiceThumbnailRequest : public ThumbnailRequest {
bool isThreadSafe; bool isThreadSafe;
virtual bool threadSafe() const {return isThreadSafe;} virtual bool threadSafe() const {return isThreadSafe;}
private: private:
StyleSheetP stylesheet;
int id; int id;
inline ChoiceStyle& style() { return *static_cast<ChoiceStyle*>(viewer().getStyle().get()); } inline ChoiceStyle& style() { return *static_cast<ChoiceStyle*>(viewer().getStyle().get()); }
...@@ -38,12 +36,11 @@ class ChoiceThumbnailRequest : public ThumbnailRequest { ...@@ -38,12 +36,11 @@ class ChoiceThumbnailRequest : public ThumbnailRequest {
ChoiceThumbnailRequest::ChoiceThumbnailRequest(ValueViewer* viewer, int id, bool from_disk, bool thread_safe) ChoiceThumbnailRequest::ChoiceThumbnailRequest(ValueViewer* viewer, int id, bool from_disk, bool thread_safe)
: ThumbnailRequest( : ThumbnailRequest(
static_cast<void*>(viewer), static_cast<void*>(viewer),
viewer->viewer.stylesheet->name() + _("/") + viewer->getField()->name + _("/") << id, viewer->getStylePackage().name() + _("/") + viewer->getField()->name + _("/") << id,
from_disk ? viewer->viewer.stylesheet->lastModified() from_disk ? viewer->getStylePackage().lastModified()
: wxDateTime::Now() : wxDateTime::Now()
) )
, isThreadSafe(thread_safe) , isThreadSafe(thread_safe)
, stylesheet(viewer->viewer.stylesheet)
, id(id) , id(id)
{} {}
...@@ -52,7 +49,7 @@ Image ChoiceThumbnailRequest::generate() { ...@@ -52,7 +49,7 @@ Image ChoiceThumbnailRequest::generate() {
String name = cannocial_name_form(s.field().choices->choiceName(id)); String name = cannocial_name_form(s.field().choices->choiceName(id));
ScriptableImage& img = s.choice_images[name]; ScriptableImage& img = s.choice_images[name];
return img.isReady() return img.isReady()
? img.generate(GeneratedImage::Options(16,16, stylesheet.get(), viewer().viewer.getSet().get(), ASPECT_BORDER, true)) ? img.generate(GeneratedImage::Options(16,16, &viewer().getStylePackage(), &viewer().getLocalPackage(), ASPECT_BORDER, true))
: wxImage(); : wxImage();
} }
...@@ -308,5 +305,5 @@ void ChoiceValueEditor::determineSize(bool) { ...@@ -308,5 +305,5 @@ void ChoiceValueEditor::determineSize(bool) {
} }
void ChoiceValueEditor::change(const Defaultable<String>& c) { void ChoiceValueEditor::change(const Defaultable<String>& c) {
perform(value_action(card(), valueP(), c)); addAction(value_action(valueP(), c));
} }
...@@ -36,7 +36,6 @@ class ChoiceValueEditor : public ChoiceValueViewer, public ValueEditor { ...@@ -36,7 +36,6 @@ class ChoiceValueEditor : public ChoiceValueViewer, public ValueEditor {
private: private:
DropDownListP drop_down; DropDownListP drop_down;
friend class DropDownChoiceList; friend class DropDownChoiceList;
friend class ChoiceThumbnailRequest;
/// Change the choice /// Change the choice
void change(const Defaultable<String>& c); void change(const Defaultable<String>& c);
}; };
......
...@@ -150,7 +150,7 @@ void ColorValueEditor::determineSize(bool) { ...@@ -150,7 +150,7 @@ void ColorValueEditor::determineSize(bool) {
} }
void ColorValueEditor::change(const Defaultable<Color>& c) { void ColorValueEditor::change(const Defaultable<Color>& c) {
perform(value_action(card(), valueP(), c)); addAction(value_action(valueP(), c));
} }
void ColorValueEditor::changeCustom() { void ColorValueEditor::changeCustom() {
Color c = wxGetColourFromUser(0, value().value()); Color c = wxGetColourFromUser(0, value().value());
......
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp> #include <util/prec.hpp>
//#include <gui/value/editor.hpp> #include <gui/value/editor.hpp>
#include <data/action/value.hpp>
// ----------------------------------------------------------------------------- : ValueEditor // ----------------------------------------------------------------------------- : ValueEditor
void ValueEditor::addAction(ValueAction* a) {
a->isOnCard(editor().getCard().get());
editor().addAction(a);
}
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <render/value/viewer.hpp> #include <render/value/viewer.hpp>
class IconMenu; class IconMenu;
class ValueAction;
DECLARE_POINTER_TYPE(ValueActionPerformer);
// ----------------------------------------------------------------------------- : ValueEditor // ----------------------------------------------------------------------------- : ValueEditor
...@@ -122,8 +124,13 @@ class ValueEditor { ...@@ -122,8 +124,13 @@ class ValueEditor {
/// The editor is shown or hidden /// The editor is shown or hidden
virtual void onShow(bool) {} virtual void onShow(bool) {}
/// Redraw this viewer // --------------------------------------------------- : Helpers
virtual void redraw() = 0; protected:
/// Retrieve the parent editor object
virtual DataEditor& editor() const = 0;
/// Perform an action
void addAction(ValueAction* a);
}; };
// ----------------------------------------------------------------------------- : Utility // ----------------------------------------------------------------------------- : Utility
...@@ -131,22 +138,14 @@ class ValueEditor { ...@@ -131,22 +138,14 @@ class ValueEditor {
#define DECLARE_VALUE_EDITOR(Type) \ #define DECLARE_VALUE_EDITOR(Type) \
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \ Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \
virtual ValueEditor* getEditor() { return this; } \ virtual ValueEditor* getEditor() { return this; } \
virtual void redraw(); \
private: \ private: \
/** Retrieve the parent editor object */ \ /** Retrieve the parent editor object */ \
inline DataEditor& editor() const { \ inline DataEditor& editor() const { \
return static_cast<DataEditor&>(viewer); \ return static_cast<DataEditor&>(viewer); \
} \ } \
/** Card this editor is on, or nullptr */ \
inline const Card* card() const { return viewer.getCard().get(); } \
/** Perform an action */ \
void perform(Action* a) { getSet().actions.add(a); } \
public: public:
#define IMPLEMENT_VALUE_EDITOR(Type) \ #define IMPLEMENT_VALUE_EDITOR(Type) \
void Type##ValueEditor::redraw() { \
editor().redraw(*this); \
} \
ValueViewerP Type##Style::makeEditor(DataEditor& parent, const StyleP& thisP) { \ ValueViewerP Type##Style::makeEditor(DataEditor& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \ assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueEditor(parent, static_pointer_cast<Type##Style>(thisP))); \ return ValueViewerP(new Type##ValueEditor(parent, static_pointer_cast<Type##Style>(thisP))); \
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <gui/image_slice_window.hpp> #include <gui/image_slice_window.hpp>
#include <data/format/clipboard.hpp> #include <data/format/clipboard.hpp>
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <data/stylesheet.hpp>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
// ----------------------------------------------------------------------------- : ImageValueEditor // ----------------------------------------------------------------------------- : ImageValueEditor
...@@ -34,7 +33,7 @@ void ImageValueEditor::sliceImage(const Image& image) { ...@@ -34,7 +33,7 @@ void ImageValueEditor::sliceImage(const Image& image) {
AlphaMaskP mask; AlphaMaskP mask;
if (!style().mask_filename().empty()) { if (!style().mask_filename().empty()) {
Image mask_image; Image mask_image;
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename); InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
if (mask_image.LoadFile(*image_file)) { if (mask_image.LoadFile(*image_file)) {
Image resampled(style().width, style().height); Image resampled(style().width, style().height);
resample(mask_image, resampled); resample(mask_image, resampled);
...@@ -46,10 +45,10 @@ void ImageValueEditor::sliceImage(const Image& image) { ...@@ -46,10 +45,10 @@ void ImageValueEditor::sliceImage(const Image& image) {
// clicked ok? // clicked ok?
if (s.ShowModal() == wxID_OK) { if (s.ShowModal() == wxID_OK) {
// store the image into the set // store the image into the set
FileName new_image_file = getSet().newFileName(field().name,_("")); // a new unique name in the package FileName new_image_file = getLocalPackage().newFileName(field().name,_("")); // a new unique name in the package
Image img = s.getImage(); Image img = s.getImage();
img.SaveFile(getSet().nameOut(new_image_file), img.HasAlpha() ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG); img.SaveFile(getLocalPackage().nameOut(new_image_file), img.HasAlpha() ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG);
perform(value_action(card(), valueP(), new_image_file)); addAction(value_action(valueP(), new_image_file));
} }
} }
...@@ -66,7 +65,7 @@ bool ImageValueEditor::canPaste() const { ...@@ -66,7 +65,7 @@ bool ImageValueEditor::canPaste() const {
bool ImageValueEditor::doCopy() { bool ImageValueEditor::doCopy() {
// load image // load image
InputStreamP image_file = getSet().openIn(value().filename); InputStreamP image_file = getLocalPackage().openIn(value().filename);
Image image; Image image;
if (!image.LoadFile(*image_file)) return false; if (!image.LoadFile(*image_file)) return false;
// set data // set data
...@@ -89,7 +88,7 @@ bool ImageValueEditor::doPaste() { ...@@ -89,7 +88,7 @@ bool ImageValueEditor::doPaste() {
} }
bool ImageValueEditor::doDelete() { bool ImageValueEditor::doDelete() {
perform(value_action(card(), valueP(), FileName())); addAction(value_action(valueP(), FileName()));
return true; return true;
} }
......
...@@ -174,9 +174,9 @@ void MultipleChoiceValueEditor::toggle(int id) { ...@@ -174,9 +174,9 @@ void MultipleChoiceValueEditor::toggle(int id) {
if (i == id) toggled_choice = choice; if (i == id) toggled_choice = choice;
} }
// store value // store value
perform(value_action(card(), valueP(), new_value, toggled_choice)); addAction(value_action(valueP(), new_value, toggled_choice));
} }
void MultipleChoiceValueEditor::toggleDefault() { void MultipleChoiceValueEditor::toggleDefault() {
perform(value_action(card(), valueP(), Defaultable<String>(value().value(), !value().value.isDefault()), _(""))); addAction(value_action(valueP(), Defaultable<String>(value().value(), !value().value.isDefault()), _("")));
} }
...@@ -111,7 +111,7 @@ void PackageChoiceValueEditor::determineSize(bool) { ...@@ -111,7 +111,7 @@ void PackageChoiceValueEditor::determineSize(bool) {
} }
void PackageChoiceValueEditor::change(const String& c) { void PackageChoiceValueEditor::change(const String& c) {
perform(value_action(card(), valueP(), c)); addAction(value_action(valueP(), c));
} }
void PackageChoiceValueEditor::initDropDown() { void PackageChoiceValueEditor::initDropDown() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <gui/value/symbol.hpp> #include <gui/value/symbol.hpp>
#include <gui/symbol/window.hpp> #include <gui/symbol/window.hpp>
#include <data/action/value.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
// ----------------------------------------------------------------------------- : SymbolValueEditor // ----------------------------------------------------------------------------- : SymbolValueEditor
...@@ -93,8 +94,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) { ...@@ -93,8 +94,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
// edit // edit
button_down = -2; button_down = -2;
viewer.redraw(*this); viewer.redraw(*this);
SymbolWindow* wnd = new SymbolWindow(nullptr, viewer.getSet(), card(), valueP()); editSymbol();
wnd->Show();
return true; return true;
} else if (button_down == 1) { } else if (button_down == 1) {
// gallery // gallery
...@@ -110,11 +110,20 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) { ...@@ -110,11 +110,20 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) { bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
// Use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes // Use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
SymbolWindow* wnd = new SymbolWindow(nullptr, viewer.getSet(), card(), valueP()); editSymbol();
wnd->Show();
return true; return true;
} }
void SymbolValueEditor::determineSize(bool) { void SymbolValueEditor::determineSize(bool) {
style().height = 50; style().height = 50;
} }
void SymbolValueEditor::editSymbol() {
SymbolWindow* wnd = new SymbolWindow(nullptr, getActionPerformer());
wnd->Show();
}
ValueActionPerformer* SymbolValueEditor::getActionPerformer() {
return new ValueActionPerformer(valueP(), editor().getCard().get(), editor().getSetForActions());
}
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <gui/value/editor.hpp> #include <gui/value/editor.hpp>
#include <render/value/symbol.hpp> #include <render/value/symbol.hpp>
class ValueActionPerformer;
// ----------------------------------------------------------------------------- : SymbolValueEditor // ----------------------------------------------------------------------------- : SymbolValueEditor
/// An editor 'control' for editing SymbolValues /// An editor 'control' for editing SymbolValues
...@@ -31,6 +33,10 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor { ...@@ -31,6 +33,10 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
void drawButton(RotatedDC& dc, int button, const String& text); void drawButton(RotatedDC& dc, int button, const String& text);
/// Is there a button at the given position? returns the button index, or -1 if there is no button /// Is there a button at the given position? returns the button index, or -1 if there is no button
int findButton(const RealPoint& pos); int findButton(const RealPoint& pos);
/// Show the symbol editor
void editSymbol();
/// Get an object to perform actions for us
ValueActionPerformer* getActionPerformer();
// button, or -1 for mouse down, but not on button, or -2 for mouse not down // button, or -1 for mouse down, but not on button, or -2 for mouse not down
int button_down; int button_down;
......
...@@ -69,7 +69,6 @@ BEGIN_EVENT_TABLE(TextValueEditorScrollBar, wxEvtHandler) ...@@ -69,7 +69,6 @@ BEGIN_EVENT_TABLE(TextValueEditorScrollBar, wxEvtHandler)
END_EVENT_TABLE () END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : WordListPos // ----------------------------------------------------------------------------- : WordListPos
class WordListPos : public IntrusivePtrBase<WordListPos> { class WordListPos : public IntrusivePtrBase<WordListPos> {
...@@ -770,19 +769,19 @@ void TextValueEditor::doFormat(int type) { ...@@ -770,19 +769,19 @@ void TextValueEditor::doFormat(int type) {
size_t ss = selection_start, se = selection_end; size_t ss = selection_start, se = selection_end;
switch (type) { switch (type) {
case ID_FORMAT_BOLD: { case ID_FORMAT_BOLD: {
perform(toggle_format_action(card(), valueP(), _("b"), selection_start_i, selection_end_i, selection_start, selection_end, _("Bold"))); addAction(toggle_format_action(valueP(), _("b"), selection_start_i, selection_end_i, selection_start, selection_end, _("Bold")));
break; break;
} }
case ID_FORMAT_ITALIC: { case ID_FORMAT_ITALIC: {
perform(toggle_format_action(card(), valueP(), _("i"), selection_start_i, selection_end_i, selection_start, selection_end, _("Italic"))); addAction(toggle_format_action(valueP(), _("i"), selection_start_i, selection_end_i, selection_start, selection_end, _("Italic")));
break; break;
} }
case ID_FORMAT_SYMBOL: { case ID_FORMAT_SYMBOL: {
perform(toggle_format_action(card(), valueP(), _("sym"), selection_start_i, selection_end_i, selection_start, selection_end, _("Symbols"))); addAction(toggle_format_action(valueP(), _("sym"), selection_start_i, selection_end_i, selection_start, selection_end, _("Symbols")));
break; break;
} }
case ID_FORMAT_REMINDER: { case ID_FORMAT_REMINDER: {
perform(new TextToggleReminderAction(card(), valueP(), selection_start_i)); addAction(new TextToggleReminderAction(valueP(), selection_start_i));
break; break;
} }
} }
...@@ -907,7 +906,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String& ...@@ -907,7 +906,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
fixSelection(); fixSelection();
// execute the action before adding it to the stack, // execute the action before adding it to the stack,
// because we want to run scripts before action listeners see the action // because we want to run scripts before action listeners see the action
TextValueAction* action = typing_action(card(), valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name); TextValueAction* action = typing_action(valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
if (!action) { if (!action) {
// nothing changes, but move the selection anyway // nothing changes, but move the selection anyway
moveSelection(TYPE_CURSOR, selection_end); moveSelection(TYPE_CURSOR, selection_end);
...@@ -918,7 +917,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String& ...@@ -918,7 +917,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
size_t expected_cursor = min(selection_start, selection_end) + untag(replacement).size(); size_t expected_cursor = min(selection_start, selection_end) + untag(replacement).size();
// perform the action // perform the action
// NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text // NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text
perform(action); addAction(action);
// move cursor // move cursor
{ {
String real_value = untag_for_cursor(value().value()); String real_value = untag_for_cursor(value().value());
...@@ -964,7 +963,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String& ...@@ -964,7 +963,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
void TextValueEditor::tryAutoReplace() { void TextValueEditor::tryAutoReplace() {
size_t end = selection_start_i; size_t end = selection_start_i;
GameSettings& gs = settings.gameSettingsFor(*getSet().game); GameSettings& gs = settings.gameSettingsFor(viewer.getGame());
if (!gs.use_auto_replace) return; if (!gs.use_auto_replace) return;
FOR_EACH(ar, gs.auto_replaces) { FOR_EACH(ar, gs.auto_replaces) {
if (ar->enabled && ar->match.size() <= end) { if (ar->enabled && ar->match.size() <= end) {
...@@ -1279,7 +1278,7 @@ void TextValueEditor::findWordLists() { ...@@ -1279,7 +1278,7 @@ void TextValueEditor::findWordLists() {
String name = str.substr(pos + 11, type_end - pos - 11); String name = str.substr(pos + 11, type_end - pos - 11);
WordListP word_list; WordListP word_list;
// find word list type // find word list type
FOR_EACH(wl, getSet().game->word_lists) { FOR_EACH(wl, viewer.getGame().word_lists) {
if (wl->name == name) { if (wl->name == name) {
word_list = wl; word_list = wl;
break; break;
......
...@@ -110,6 +110,16 @@ Rotation DataViewer::getRotation() const { ...@@ -110,6 +110,16 @@ Rotation DataViewer::getRotation() const {
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT); return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
} }
Package& DataViewer::getStylePackage() const {
return *stylesheet;
}
Package& DataViewer::getLocalPackage() const {
return *set;
}
Game& DataViewer::getGame() const {
return *set->game;
}
// ----------------------------------------------------------------------------- : Setting data // ----------------------------------------------------------------------------- : Setting data
void DataViewer::setCard(const CardP& card, bool refresh) { void DataViewer::setCard(const CardP& card, bool refresh) {
......
...@@ -62,6 +62,13 @@ class DataViewer : public SetView { ...@@ -62,6 +62,13 @@ class DataViewer : public SetView {
/// Invalidate and redraw (the area of) a single value viewer /// Invalidate and redraw (the area of) a single value viewer
virtual void redraw(const ValueViewer&) {} virtual void redraw(const ValueViewer&) {}
/// The package containing style stuff like images
virtual Package& getStylePackage() const;
/// The local package for loading/saving files
Package& getLocalPackage() const;
/// Return the game to use for information
Game& getGame() const;
// --------------------------------------------------- : Setting data // --------------------------------------------------- : Setting data
/// Display a card in this viewer /// Display a card in this viewer
...@@ -100,7 +107,6 @@ class DataViewer : public SetView { ...@@ -100,7 +107,6 @@ class DataViewer : public SetView {
vector<ValueViewerP> viewers; ///< The viewers for the different values in the data vector<ValueViewerP> viewers; ///< The viewers for the different values in the data
CardP card; ///< The card that is currently displayed, if any CardP card; ///< The card that is currently displayed, if any
bool drawing; ///< Are we currently drawing? bool drawing; ///< Are we currently drawing?
public:
mutable StyleSheetP stylesheet; ///< Stylesheet being used mutable StyleSheetP stylesheet; ///< Stylesheet being used
}; };
......
...@@ -9,28 +9,27 @@ ...@@ -9,28 +9,27 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <render/value/choice.hpp> #include <render/value/choice.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
#include <data/stylesheet.hpp>
// ----------------------------------------------------------------------------- : ChoiceValueViewer // ----------------------------------------------------------------------------- : ChoiceValueViewer
IMPLEMENT_VALUE_VIEWER(Choice); IMPLEMENT_VALUE_VIEWER(Choice);
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts); void get_options(Rotation& rot, ValueViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts);
bool ChoiceValueViewer::prepare(RotatedDC& dc) { bool ChoiceValueViewer::prepare(RotatedDC& dc) {
return prepare_choice_viewer(dc, viewer, style(), value().value()); return prepare_choice_viewer(dc, *this, style(), value().value());
} }
void ChoiceValueViewer::draw(RotatedDC& dc) { void ChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc); drawFieldBorder(dc);
if (style().render_style & RENDER_HIDDEN) return; if (style().render_style & RENDER_HIDDEN) return;
draw_choice_viewer(dc, viewer, style(), value().value()); draw_choice_viewer(dc, *this, style(), value().value());
} }
bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) { bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value) {
if (style.render_style & RENDER_IMAGE) { if (style.render_style & RENDER_IMAGE) {
style.initImage(); style.initImage();
CachedScriptableImage& img = style.image; CachedScriptableImage& img = style.image;
Context& ctx = viewer.getContext(); Context& ctx = viewer.viewer.getContext();
ctx.setVariable(SCRIPT_VAR_input, to_script(value)); ctx.setVariable(SCRIPT_VAR_input, to_script(value));
// generate to determine the size // generate to determine the size
if (img.update(ctx) && img.isReady()) { if (img.update(ctx) && img.isReady()) {
...@@ -39,7 +38,7 @@ bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style ...@@ -39,7 +38,7 @@ bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style
// Generate image/bitmap (whichever is available) // Generate image/bitmap (whichever is available)
// don't worry, we cache the image // don't worry, we cache the image
ImageCombine combine = style.combine; ImageCombine combine = style.combine;
style.loadMask(*viewer.stylesheet); style.loadMask(viewer.getStylePackage());
Bitmap bitmap; Image image; Bitmap bitmap; Image image;
RealSize size; RealSize size;
img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size); img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
...@@ -54,7 +53,7 @@ bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style ...@@ -54,7 +53,7 @@ bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style
return false; return false;
} }
void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value) { void draw_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value) {
if (value.empty()) return; if (value.empty()) return;
double margin = 0; double margin = 0;
if (style.render_style & RENDER_IMAGE) { if (style.render_style & RENDER_IMAGE) {
...@@ -65,7 +64,7 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c ...@@ -65,7 +64,7 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
get_options(dc, viewer, style, img_options); get_options(dc, viewer, style, img_options);
// Generate image/bitmap // Generate image/bitmap
ImageCombine combine = style.combine; ImageCombine combine = style.combine;
style.loadMask(*viewer.stylesheet); style.loadMask(viewer.getStylePackage());
Bitmap bitmap; Image image; Bitmap bitmap; Image image;
RealSize size; RealSize size;
img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size); img.generateCached(img_options, &style.mask, &combine, &bitmap, &image, &size);
...@@ -85,16 +84,16 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c ...@@ -85,16 +84,16 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
} }
} }
if (style.render_style & RENDER_TEXT) { if (style.render_style & RENDER_TEXT) {
String text = tr(*viewer.stylesheet, value, capitalize_sentence); String text = tr(viewer.getStylePackage(), value, capitalize_sentence);
dc.SetFont(style.font, 1.0); dc.SetFont(style.font, 1.0);
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0); RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0);
dc.DrawTextWithShadow(text, style.font, pos); dc.DrawTextWithShadow(text, style.font, pos);
} }
} }
void get_options(Rotation& rot, DataViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts) { void get_options(Rotation& rot, ValueViewer& viewer, const ChoiceStyle& style, GeneratedImage::Options& opts) {
opts.package = viewer.stylesheet.get(); opts.package = &viewer.getStylePackage();
opts.local_package = viewer.getSet().get(); opts.local_package = &viewer.getLocalPackage();
opts.angle = rot.trAngle(0); opts.angle = rot.trAngle(0);
if (viewer.nativeLook()) { if (viewer.nativeLook()) {
opts.width = opts.height = 16; opts.width = opts.height = 16;
......
...@@ -25,8 +25,8 @@ class ChoiceValueViewer : public ValueViewer { ...@@ -25,8 +25,8 @@ class ChoiceValueViewer : public ValueViewer {
virtual void onStyleChange(int); virtual void onStyleChange(int);
}; };
bool prepare_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value); bool prepare_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value);
void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, const String& value); void draw_choice_viewer(RotatedDC& dc, ValueViewer& viewer, ChoiceStyle& style, const String& value);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <render/value/color.hpp> #include <render/value/color.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
#include <data/stylesheet.hpp>
DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP); DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP);
...@@ -100,7 +99,7 @@ void ColorValueViewer::loadMask(const Rotation& rot) const { ...@@ -100,7 +99,7 @@ void ColorValueViewer::loadMask(const Rotation& rot) const {
if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size
// (re) load the mask // (re) load the mask
Image image; Image image;
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename); InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
if (image.LoadFile(*image_file)) { if (image.LoadFile(*image_file)) {
Image resampled(w,h); Image resampled(w,h);
resample(image, resampled); resample(image, resampled);
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <render/value/image.hpp> #include <render/value/image.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
#include <data/set.hpp>
#include <data/stylesheet.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
DECLARE_TYPEOF_COLLECTION(wxPoint); DECLARE_TYPEOF_COLLECTION(wxPoint);
...@@ -35,7 +33,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -35,7 +33,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
// load from file // load from file
if (!value().filename.empty()) { if (!value().filename.empty()) {
try { try {
InputStreamP image_file = getSet().openIn(value().filename); InputStreamP image_file = getLocalPackage().openIn(value().filename);
if (image.LoadFile(*image_file)) { if (image.LoadFile(*image_file)) {
image.Rescale(w, h); image.Rescale(w, h);
} }
...@@ -45,7 +43,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -45,7 +43,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
} }
// nice placeholder // nice placeholder
if (!image.Ok() && style().default_image.isReady()) { if (!image.Ok() && style().default_image.isReady()) {
image = style().default_image.generate(GeneratedImage::Options(w, h, viewer.stylesheet.get(), &getSet())); image = style().default_image.generate(GeneratedImage::Options(w, h, &getStylePackage(), &getLocalPackage()));
is_default = true; is_default = true;
if (viewer.drawEditing()) { if (viewer.drawEditing()) {
bitmap = imagePlaceholder(dc, w, h, image, viewer.drawEditing()); bitmap = imagePlaceholder(dc, w, h, image, viewer.drawEditing());
...@@ -127,7 +125,7 @@ void ImageValueViewer::loadMask(const Rotation& rot) const { ...@@ -127,7 +125,7 @@ void ImageValueViewer::loadMask(const Rotation& rot) const {
if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size if (alpha_mask && alpha_mask->size == wxSize(w,h)) return; // mask loaded and right size
// (re) load the mask // (re) load the mask
Image image; Image image;
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename); InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
if (image.LoadFile(*image_file)) { if (image.LoadFile(*image_file)) {
alpha_mask = new_intrusive1<AlphaMask>(resample(image,w,h)); alpha_mask = new_intrusive1<AlphaMask>(resample(image,w,h));
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <render/value/multiple_choice.hpp> #include <render/value/multiple_choice.hpp>
#include <render/value/choice.hpp> #include <render/value/choice.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
#include <data/stylesheet.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
DECLARE_TYPEOF_COLLECTION(String); DECLARE_TYPEOF_COLLECTION(String);
...@@ -21,7 +20,7 @@ IMPLEMENT_VALUE_VIEWER(MultipleChoice); ...@@ -21,7 +20,7 @@ IMPLEMENT_VALUE_VIEWER(MultipleChoice);
bool MultipleChoiceValueViewer::prepare(RotatedDC& dc) { bool MultipleChoiceValueViewer::prepare(RotatedDC& dc) {
if (style().render_style & (RENDER_CHECKLIST | RENDER_LIST)) return false; if (style().render_style & (RENDER_CHECKLIST | RENDER_LIST)) return false;
return prepare_choice_viewer(dc, viewer, style(), value().value()); return prepare_choice_viewer(dc, *this, style(), value().value());
} }
void MultipleChoiceValueViewer::draw(RotatedDC& dc) { void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
...@@ -47,7 +46,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) { ...@@ -47,7 +46,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
drawChoice(dc, pos, choice); drawChoice(dc, pos, choice);
} }
} else { } else {
draw_choice_viewer(dc, viewer, style(), value().value()); draw_choice_viewer(dc, *this, style(), value().value());
} }
} }
...@@ -62,7 +61,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const ...@@ -62,7 +61,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice)); map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice));
if (it != style().choice_images.end() && it->second.isReady()) { if (it != style().choice_images.end() && it->second.isReady()) {
// TODO: caching // TODO: caching
GeneratedImage::Options options(0,0, viewer.stylesheet.get(),&getSet()); GeneratedImage::Options options(0,0, &getStylePackage(), &getLocalPackage());
options.zoom = dc.getZoom(); options.zoom = dc.getZoom();
options.angle = dc.trAngle(style().angle); options.angle = dc.trAngle(style().angle);
Image image = it->second.generate(options); Image image = it->second.generate(options);
...@@ -74,7 +73,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const ...@@ -74,7 +73,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
} }
if (style().render_style & RENDER_TEXT) { if (style().render_style & RENDER_TEXT) {
// draw text // draw text
String text = tr(*viewer.stylesheet, choice, capitalize_sentence); String text = tr(getStylePackage(), choice, capitalize_sentence);
RealSize text_size = dc.GetTextExtent(text); RealSize text_size = dc.GetTextExtent(text);
dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size, dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size,
RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height)))); RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height))));
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/io/package.hpp>
#include <render/value/symbol.hpp> #include <render/value/symbol.hpp>
#include <render/symbol/filter.hpp> #include <render/symbol/filter.hpp>
#include <data/set.hpp>
#include <data/symbol.hpp> #include <data/symbol.hpp>
#include <gui/util.hpp> // draw_checker #include <gui/util.hpp> // draw_checker
#include <util/error.hpp> #include <util/error.hpp>
...@@ -29,7 +29,7 @@ void SymbolValueViewer::draw(RotatedDC& dc) { ...@@ -29,7 +29,7 @@ void SymbolValueViewer::draw(RotatedDC& dc) {
if (symbols.empty() && !value().filename.empty()) { if (symbols.empty() && !value().filename.empty()) {
try { try {
// load symbol // load symbol
SymbolP symbol = getSet().readFile<SymbolP>(value().filename); SymbolP symbol = getLocalPackage().readFile<SymbolP>(value().filename);
// aspect ratio // aspect ratio
double ar = symbol->aspectRatio(); double ar = symbol->aspectRatio();
ar = min(style().max_aspect_ratio, max(style().min_aspect_ratio, ar)); ar = min(style().max_aspect_ratio, max(style().min_aspect_ratio, ar));
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <render/value/text.hpp> #include <render/value/text.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
#include <data/stylesheet.hpp>
// ----------------------------------------------------------------------------- : TextValueViewer // ----------------------------------------------------------------------------- : TextValueViewer
...@@ -19,7 +18,7 @@ bool TextValueViewer::prepare(RotatedDC& dc) { ...@@ -19,7 +18,7 @@ bool TextValueViewer::prepare(RotatedDC& dc) {
if (!style().mask_filename.empty() && !style().mask.ok()) { if (!style().mask_filename.empty() && !style().mask.ok()) {
// load contour mask // load contour mask
Image image; Image image;
InputStreamP image_file = viewer.stylesheet->openIn(style().mask_filename); InputStreamP image_file = getStylePackage().openIn(style().mask_filename);
if (image.LoadFile(*image_file)) { if (image.LoadFile(*image_file)) {
style().mask.load(image); style().mask.load(image);
} }
......
...@@ -16,7 +16,8 @@ ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style) ...@@ -16,7 +16,8 @@ ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
: StyleListener(style), viewer(parent) : StyleListener(style), viewer(parent)
{} {}
Set& ValueViewer::getSet() const { return *viewer.getSet(); } Package& ValueViewer::getStylePackage() const { return viewer.getStylePackage(); }
Package& ValueViewer::getLocalPackage() const { return viewer.getLocalPackage(); }
void ValueViewer::setValue(const ValueP& value) { void ValueViewer::setValue(const ValueP& value) {
assert(value->fieldP == styleP->fieldP); // matching field assert(value->fieldP == styleP->fieldP); // matching field
...@@ -47,6 +48,10 @@ void ValueViewer::drawFieldBorder(RotatedDC& dc) { ...@@ -47,6 +48,10 @@ void ValueViewer::drawFieldBorder(RotatedDC& dc) {
} }
} }
void ValueViewer::redraw() {
viewer.redraw(*this);
}
bool ValueViewer::nativeLook() const { bool ValueViewer::nativeLook() const {
return viewer.nativeLook(); return viewer.nativeLook();
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <data/field.hpp> #include <data/field.hpp>
class Set; class Set;
class Package;
class DataViewer; class DataViewer;
class Action; class Action;
DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Style);
...@@ -74,16 +75,23 @@ class ValueViewer : public StyleListener { ...@@ -74,16 +75,23 @@ class ValueViewer : public StyleListener {
protected: protected:
ValueP valueP; ///< The value we are currently viewing ValueP valueP; ///< The value we are currently viewing
/// Draws a border around the field
void drawFieldBorder(RotatedDC& dc);
/// Redraw this viewer
void redraw();
public:
/// Should this viewer render using a platform native look? /// Should this viewer render using a platform native look?
bool nativeLook() const; bool nativeLook() const;
/// Is this the currently selected viewer? /// Is this the currently selected viewer?
/** Usually only the editor allows selection of viewers */ /** Usually only the editor allows selection of viewers */
bool isCurrent() const; bool isCurrent() const;
/// Draws a border around the field /// The package containing style stuff like images
void drawFieldBorder(RotatedDC& dc); Package& getStylePackage() const;
/// The local package for loading/saving files
Set& getSet() const; Package& getLocalPackage() const;
}; };
// ----------------------------------------------------------------------------- : Utility // ----------------------------------------------------------------------------- : Utility
......
...@@ -26,7 +26,7 @@ ActionStack::~ActionStack() { ...@@ -26,7 +26,7 @@ ActionStack::~ActionStack() {
FOR_EACH(a, redo_actions) delete a; FOR_EACH(a, redo_actions) delete a;
} }
void ActionStack::add(Action* action, bool allow_merge) { void ActionStack::addAction(Action* action, bool allow_merge) {
if (!action) return; // no action if (!action) return; // no action
action->perform(false); // TODO: delete action if perform throws action->perform(false); // TODO: delete action if perform throws
tellListeners(*action, false); tellListeners(*action, false);
......
...@@ -67,9 +67,11 @@ class ActionStack { ...@@ -67,9 +67,11 @@ class ActionStack {
~ActionStack(); ~ActionStack();
/// Add an action to the stack, and perform that action. /// Add an action to the stack, and perform that action.
/// Tells all listeners about the action. /** Tells all listeners about the action.
/// The ActionStack takes ownership of the action * The ActionStack takes ownership of the action.
void add(Action* action, bool allowMerge = true); * If allow_merge == true then we attempt to merge this action with previous ones
*/
void addAction(Action* action, bool allow_merge = true);
/// Undoes the last action that was (re)done /// Undoes the last action that was (re)done
/** @pre canUndo() */ /** @pre canUndo() */
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/string.hpp> #include <util/string.hpp>
class Package;
class Game; class Game;
class StyleSheet; class StyleSheet;
class SymbolFont; class SymbolFont;
...@@ -46,6 +47,8 @@ String warn_and_identity(const String&); ...@@ -46,6 +47,8 @@ String warn_and_identity(const String&);
/// Translate 'key' in the category 'cat' using the current locale /// Translate 'key' in the category 'cat' using the current locale
String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity); String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity);
/// Translate 'key' in the for a Package using the current locale
String tr(const Package&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Game using the current locale /// Translate 'key' in the for a Game using the current locale
String tr(const Game&, const String& key, DefaultLocaleFun def); String tr(const Game&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a StyleSheet using the current locale /// Translate 'key' in the for a StyleSheet using the current locale
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment