Commit 88919557 authored by twanvl's avatar twanvl

Switched to a new coding style, which plays nicely with the Reader/Writer....

Switched to a new coding style, which plays nicely with the Reader/Writer. This new style allows REFLECT to be used instead of REFLECT_N in most places.
parent 3fd47ec7
......@@ -23,15 +23,15 @@ SymbolPartMoveAction::SymbolPartMoveAction(const set<SymbolPartP>& parts)
, constrain(false)
{}
String SymbolPartMoveAction::getName(bool toUndo) const {
String SymbolPartMoveAction::getName(bool to_undo) const {
return parts.size() == 1 ? _("Move shape") : _("Move shapes");
}
void SymbolPartMoveAction::perform(bool toUndo) {
void SymbolPartMoveAction::perform(bool to_undo) {
// move the points back
FOR_EACH(p, parts) {
p->minPos -= moved;
p->maxPos -= moved;
p->min_pos -= moved;
p->max_pos -= moved;
FOR_EACH(pnt, p->points) {
pnt->pos -= moved;
}
......@@ -45,8 +45,8 @@ void SymbolPartMoveAction::move(const Vector2D& deltaDelta) {
Vector2D d = constrainVector(delta, constrain);
Vector2D dd = d - moved;
FOR_EACH(p, parts) {
p->minPos += dd;
p->maxPos += dd;
p->min_pos += dd;
p->max_pos += dd;
FOR_EACH(pnt, p->points) {
pnt->pos += dd;
}
......@@ -66,8 +66,8 @@ void SymbolPartMatrixAction::transform(const Vector2D& mx, const Vector2D& my) {
FOR_EACH(p, parts) {
FOR_EACH(pnt, p->points) {
pnt->pos = (pnt->pos - center).mul(mx,my) + center;
pnt->deltaBefore = pnt->deltaBefore.mul(mx,my);
pnt->deltaAfter = pnt->deltaAfter .mul(mx,my);
pnt->delta_before = pnt->delta_before.mul(mx,my);
pnt->delta_after = pnt->delta_after .mul(mx,my);
}
// bounds change after transforming
p->calculateBounds();
......@@ -81,11 +81,11 @@ SymbolPartRotateAction::SymbolPartRotateAction(const set<SymbolPartP>& parts, co
, angle(0)
{}
String SymbolPartRotateAction::getName(bool toUndo) const {
String SymbolPartRotateAction::getName(bool to_undo) const {
return parts.size() == 1 ? _("Rotate shape") : _("Rotate shapes");
}
void SymbolPartRotateAction::perform(bool toUndo) {
void SymbolPartRotateAction::perform(bool to_undo) {
// move the points back
rotateBy(-angle);
angle = -angle;
......@@ -119,11 +119,11 @@ SymbolPartShearAction::SymbolPartShearAction(const set<SymbolPartP>& parts, cons
, constrain(false)
{}
String SymbolPartShearAction::getName(bool toUndo) const {
String SymbolPartShearAction::getName(bool to_undo) const {
return parts.size() == 1 ? _("Shear shape") : _("Shear shapes");
}
void SymbolPartShearAction::perform(bool toUndo) {
void SymbolPartShearAction::perform(bool to_undo) {
// move the points back
// the vector shear = (x,y) is used as:
// <1 x>
......@@ -161,19 +161,19 @@ SymbolPartScaleAction::SymbolPartScaleAction(const set<SymbolPartP>& parts, int
oldMin = Vector2D::infinity();
Vector2D oldMax = -Vector2D::infinity();
FOR_EACH(p, parts) {
oldMin = piecewise_min(oldMin, p->minPos);
oldMax = piecewise_max(oldMax, p->maxPos);
oldMin = piecewise_min(oldMin, p->min_pos);
oldMax = piecewise_max(oldMax, p->max_pos);
}
// new == old
newMin = newRealMin = oldMin;
newSize = newRealSize = oldSize = oldMax - oldMin;
}
String SymbolPartScaleAction::getName(bool toUndo) const {
String SymbolPartScaleAction::getName(bool to_undo) const {
return parts.size() == 1 ? _("Scale shape") : _("Scale shapes");
}
void SymbolPartScaleAction::perform(bool toUndo) {
void SymbolPartScaleAction::perform(bool to_undo) {
swap(oldMin, newMin);
swap(oldSize, newSize);
transformAll();
......@@ -207,17 +207,17 @@ void SymbolPartScaleAction::update() {
void SymbolPartScaleAction::transformAll() {
Vector2D scale = newSize.div(oldSize);
FOR_EACH(p, parts) {
p->minPos = transform(p->minPos);
p->maxPos = transform(p->maxPos);
p->min_pos = transform(p->min_pos);
p->max_pos = transform(p->max_pos);
// make sure that max >= min
if (p->minPos.x > p->maxPos.x) swap(p->minPos.x, p->maxPos.x);
if (p->minPos.y > p->maxPos.y) swap(p->minPos.y, p->maxPos.y);
if (p->min_pos.x > p->max_pos.x) swap(p->min_pos.x, p->max_pos.x);
if (p->min_pos.y > p->max_pos.y) swap(p->min_pos.y, p->max_pos.y);
// scale all points
FOR_EACH(pnt, p->points) {
pnt->pos = transform(pnt->pos);
// also scale handles
pnt->deltaBefore = pnt->deltaBefore.mul(scale);
pnt->deltaAfter = pnt->deltaAfter .mul(scale);
pnt->delta_before = pnt->delta_before.mul(scale);
pnt->delta_after = pnt->delta_after .mul(scale);
}
}
}
......@@ -230,11 +230,11 @@ CombiningModeAction::CombiningModeAction(const set<SymbolPartP>& parts, SymbolPa
}
}
String CombiningModeAction::getName(bool toUndo) const {
String CombiningModeAction::getName(bool to_undo) const {
return _("Change combine mode");
}
void CombiningModeAction::perform(bool toUndo) {
void CombiningModeAction::perform(bool to_undo) {
FOR_EACH(pm, parts) {
swap(pm.first->combine, pm.second);
}
......@@ -246,11 +246,11 @@ SymbolPartNameAction::SymbolPartNameAction(const SymbolPartP& part, const String
: part(part), partName(name)
{}
String SymbolPartNameAction::getName(bool toUndo) const {
String SymbolPartNameAction::getName(bool to_undo) const {
return _("Change shape name");
}
void SymbolPartNameAction::perform(bool toUndo) {
void SymbolPartNameAction::perform(bool to_undo) {
swap(part->name, partName);
}
......@@ -260,12 +260,12 @@ AddSymbolPartAction::AddSymbolPartAction(Symbol& symbol, const SymbolPartP& part
: symbol(symbol), part(part)
{}
String AddSymbolPartAction::getName(bool toUndo) const {
String AddSymbolPartAction::getName(bool to_undo) const {
return _("Add ") + part->name;
}
void AddSymbolPartAction::perform(bool toUndo) {
if (toUndo) {
void AddSymbolPartAction::perform(bool to_undo) {
if (to_undo) {
assert(!symbol.parts.empty());
symbol.parts.erase (symbol.parts.begin());
} else {
......@@ -287,12 +287,12 @@ RemoveSymbolPartsAction::RemoveSymbolPartsAction(Symbol& symbol, const set<Symbo
}
}
String RemoveSymbolPartsAction::getName(bool toUndo) const {
String RemoveSymbolPartsAction::getName(bool to_undo) const {
return removals.size() == 1 ? _("Remove shape") : _("Remove shapes");
}
void RemoveSymbolPartsAction::perform(bool toUndo) {
if (toUndo) {
void RemoveSymbolPartsAction::perform(bool to_undo) {
if (to_undo) {
// reinsert the parts
// ascending order, this is the reverse of removal
FOR_EACH(r, removals) {
......@@ -325,12 +325,12 @@ DuplicateSymbolPartsAction::DuplicateSymbolPartsAction(Symbol& symbol, const set
}
}
String DuplicateSymbolPartsAction::getName(bool toUndo) const {
String DuplicateSymbolPartsAction::getName(bool to_undo) const {
return duplications.size() == 1 ? _("Duplicate shape") : _("Duplicate shapes");
}
void DuplicateSymbolPartsAction::perform(bool toUndo) {
if (toUndo) {
void DuplicateSymbolPartsAction::perform(bool to_undo) {
if (to_undo) {
// remove the clones
// walk in reverse order, otherwise we will shift the vector
FOR_EACH_REVERSE(d, duplications) {
......@@ -359,11 +359,11 @@ ReorderSymbolPartsAction::ReorderSymbolPartsAction(Symbol& symbol, size_t partId
: symbol(symbol), partId1(partId1), partId2(partId2)
{}
String ReorderSymbolPartsAction::getName(bool toUndo) const {
String ReorderSymbolPartsAction::getName(bool to_undo) const {
return _("Reorder");
}
void ReorderSymbolPartsAction::perform(bool toUndo) {
void ReorderSymbolPartsAction::perform(bool to_undo) {
assert(partId1 < symbol.parts.size());
assert(partId2 < symbol.parts.size());
swap(symbol.parts[partId1], symbol.parts[partId2]);
......
......@@ -33,8 +33,8 @@ class SymbolPartMoveAction : public SymbolPartAction {
public:
SymbolPartMoveAction(const set<SymbolPartP>& parts);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Update this action to move some more
void move(const Vector2D& delta);
......@@ -70,8 +70,8 @@ class SymbolPartRotateAction : public SymbolPartMatrixAction {
public:
SymbolPartRotateAction(const set<SymbolPartP>& parts, const Vector2D& center);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Update this action to rotate to a different angle
void rotateTo(double newAngle);
......@@ -93,8 +93,8 @@ class SymbolPartShearAction : public SymbolPartMatrixAction {
public:
SymbolPartShearAction(const set<SymbolPartP>& parts, const Vector2D& center);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Change shear by a given amount
void move(const Vector2D& deltaShear);
......@@ -114,8 +114,8 @@ class SymbolPartScaleAction : public SymbolPartAction {
public:
SymbolPartScaleAction(const set<SymbolPartP>& parts, int scaleX, int scaleY);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Change min and max coordinates
void move(const Vector2D& deltaMin, const Vector2D& deltaMax);
......@@ -145,8 +145,8 @@ class CombiningModeAction : public SymbolPartListAction {
public:
CombiningModeAction(const set<SymbolPartP>& parts, SymbolPartCombine mode);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
vector<pair<SymbolPartP,SymbolPartCombine> > parts; ///< Affected parts with new combining modes
......@@ -159,8 +159,8 @@ class SymbolPartNameAction : public SymbolPartListAction {
public:
SymbolPartNameAction(const SymbolPartP& part, const String& name);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
SymbolPartP part; ///< Affected part
......@@ -174,8 +174,8 @@ class AddSymbolPartAction : public SymbolPartListAction {
public:
AddSymbolPartAction(Symbol& symbol, const SymbolPartP& part);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
Symbol& symbol; ///< Symbol to add the part to
......@@ -189,8 +189,8 @@ class RemoveSymbolPartsAction : public SymbolPartListAction {
public:
RemoveSymbolPartsAction(Symbol& symbol, const set<SymbolPartP>& parts);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
Symbol& symbol;
......@@ -205,8 +205,8 @@ class DuplicateSymbolPartsAction : public SymbolPartListAction {
public:
DuplicateSymbolPartsAction(Symbol& symbol, const set<SymbolPartP>& parts);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Fill a set with all the new parts
void getParts(set<SymbolPartP>& parts);
......@@ -225,8 +225,8 @@ class ReorderSymbolPartsAction : public SymbolPartListAction {
public:
ReorderSymbolPartsAction(Symbol& symbol, size_t partId1, size_t partId2);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
Symbol& symbol; ///< Symbol to swap the parts in
......
This diff is collapsed.
......@@ -31,8 +31,8 @@ class ControlPointMoveAction : public Action {
public:
ControlPointMoveAction(const set<ControlPointP>& points);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Update this action to move some more
void move(const Vector2D& delta);
......@@ -52,16 +52,16 @@ class HandleMoveAction : public Action {
public:
HandleMoveAction(const SelectedHandle& handle);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
/// Update this action to move some more
void move(const Vector2D& delta);
private:
SelectedHandle handle; ///< The handle to move
Vector2D oldHandle; ///< Old value of this handle
Vector2D oldOther; ///< Old value of other handle, needed for contraints
Vector2D old_handle; ///< Old value of this handle
Vector2D old_other; ///< Old value of other handle, needed for contraints
Vector2D delta; ///< Amount we moved
public:
bool constrain; ///< Constrain movement?
......@@ -90,8 +90,8 @@ class SegmentModeAction : public Action {
public:
SegmentModeAction(const ControlPointP& p1, const ControlPointP& p2, SegmentMode mode);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
protected:
ControlPointUpdate point1, point2;
......@@ -104,8 +104,8 @@ class LockModeAction : public Action {
public:
LockModeAction(const ControlPointP& p, LockMode mode);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
ControlPointUpdate point; ///< The affected point
......@@ -120,8 +120,8 @@ class CurveDragAction : public SegmentModeAction {
public:
CurveDragAction(const ControlPointP& point1, const ControlPointP& point2);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
// Move the curve by this much, it is grabbed at time t
void move(const Vector2D& delta, double t);
......@@ -133,17 +133,17 @@ class CurveDragAction : public SegmentModeAction {
class ControlPointAddAction : public Action {
public:
/// Insert a new point in part, after position insertAfter_, at the time t on the segment
ControlPointAddAction(const SymbolPartP& part, UInt insertAfter, double t);
ControlPointAddAction(const SymbolPartP& part, UInt insert_after, double t);
virtual String getName(bool toUndo) const;
virtual void perform(bool toUndo);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
inline ControlPointP getNewPoint() const { return newPoint; }
inline ControlPointP getNewPoint() const { return new_point; }
private:
SymbolPartP part; ///< SymbolPart we are in
ControlPointP newPoint; ///< The point to insert
UInt insertAfter; ///< Insert after index .. in the array
ControlPointP new_point; ///< The point to insert
UInt insert_after; ///< Insert after index .. in the array
ControlPointUpdate point1, point2; ///< Update the points around the new point
};
......
......@@ -22,11 +22,11 @@ Card::Card() {
if (!game_for_new_cards()) {
throw InternalError(_("game_for_new_cards not set"));
}
data.init(game_for_new_cards()->cardFields);
data.init(game_for_new_cards()->card_fields);
}
Card::Card(const Game& game) {
data.init(game.cardFields);
data.init(game.card_fields);
}
String Card::identification() const {
......
......@@ -12,16 +12,16 @@
// ----------------------------------------------------------------------------- : Field
Field::Field()
: index (0) // sensible default?
, editable (true)
, saveValue (true)
, showStatistics (true)
, identifying (false)
, cardListColumn (-1)
, cardListWidth (100)
, cardListAllow (true)
// , cardListAlign (ALIGN_LEFT)
, tabIndex (0)
: index (0) // sensible default?
, editable (true)
, save_value (true)
, show_statistics (true)
, identifying (false)
, card_list_column (-1)
, card_list_width (100)
, card_list_allow (true)
// , card_list_align (ALIGN_LEFT)
, tab_index (0)
{}
Field::~Field() {}
......@@ -29,8 +29,17 @@ Field::~Field() {}
IMPLEMENT_REFLECTION(Field) {
if (!tag.reading()) {
String type = typeName();
REFLECT_N("type", type);
REFLECT(type);
}
REFLECT(editable);
REFLECT(save_value);
REFLECT(show_statistics);
REFLECT(identifying);
REFLECT(card_list_column);
REFLECT(card_list_width);
REFLECT(card_list_allow);
// REFLECT(card_list_align);
REFLECT(tab_index);
}
template <>
......@@ -49,6 +58,8 @@ shared_ptr<Field> read_new<Field>(Reader& reader) {
// ----------------------------------------------------------------------------- : Style
Style::~Style() {}
IMPLEMENT_REFLECTION(Style) {
}
......@@ -58,6 +69,8 @@ void initObject(const FieldP& field, StyleP& style) {
// ----------------------------------------------------------------------------- : Value
Value::~Value() {}
IMPLEMENT_REFLECTION(Value) {
}
......
......@@ -24,19 +24,19 @@ class Field {
Field();
virtual ~Field();
UInt index; ///< Used by IndexMap
String name; ///< Name of the field, for refering to it from scripts and files
String description; ///< Description, used in status bar
bool editable; ///< Can values of this field be edited?
bool saveValue; ///< Should values of this field be written to files? Can be false for script generated fields.
bool showStatistics; ///< Should this field appear as a group by choice in the statistics panel?
bool identifying; ///< Does this field give Card::identification()?
int cardListColumn; ///< What column to use in the card list? -1 = don't list
UInt cardListWidth; ///< Width of the card list column (pixels).
bool cardListAllow; ///< Is this field allowed to appear in the card list.
String cardListName; ///< Alternate name to use in card list.
// Alignment cardListAlign; ///< Alignment of the card list colummn.
int tabIndex; ///< Tab index in editor
UInt index; ///< Used by IndexMap
String name; ///< Name of the field, for refering to it from scripts and files
String description; ///< Description, used in status bar
bool editable; ///< Can values of this field be edited?
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel?
bool identifying; ///< Does this field give Card::identification()?
int card_list_column; ///< What column to use in the card list? -1 = don't list
UInt card_list_width; ///< Width of the card list column (pixels).
bool card_list_allow; ///< Is this field allowed to appear in the card list.
String card_list_name; ///< Alternate name to use in card list.
// Alignment card_list_align; ///< Alignment of the card list colummn.
int tab_index; ///< Tab index in editor
// Vector<DependendScript> dependendScripts; // scripts that depend on values of this field
/// Creates a new Value corresponding to this Field
......
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <data/field/text.hpp>
// ----------------------------------------------------------------------------- : TextField
TextField::TextField()
: multi_line(false), move_cursor_with_sort(false)
, default_name(_("Default"))
{}
StyleP TextField::newStyle(const FieldP& thisP) const {
assert(thisP.get() == this);
return new_shared<TextStyle>();
}
ValueP TextField::newValue(const FieldP& thisP) const {
assert(thisP.get() == this);
return new_shared<TextValue>();
}
FieldP TextField::clone() const {
return new_shared1<TextField>(*this);
}
String TextField::typeName() const {
return _("text");
}
IMPLEMENT_REFLECTION(TextField) {
REFLECT_BASE(Field);
REFLECT(multi_line);
// REFLECT(script);
// REFLECT_N("default", default_script);
REFLECT(move_cursor_with_sort);
REFLECT(default_name);
}
// ----------------------------------------------------------------------------- : TextStyle
StyleP TextStyle::clone() const {
return new_shared1<TextStyle>(*this);
}
IMPLEMENT_REFLECTION(TextStyle) {
REFLECT_BASE(Style);
}
// ----------------------------------------------------------------------------- : TextValue
ValueP TextValue::clone() const {
return new_shared1<TextValue>(*this);
}
IMPLEMENT_REFLECTION(TextValue) {
REFLECT_BASE(Value);
}
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_FIELD_TEXT
#define HEADER_DATA_FIELD_TEXT
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/field.hpp>
// ----------------------------------------------------------------------------- : TextField
/// A field that stores tagged text
class TextField : public Field {
public:
TextField();
// Script script;
// Script default_script;
bool multi_line; ///< Are newlines allowed in the text?
bool move_cursor_with_sort; ///< When the text is reordered by a script should the cursor position be updated?
String default_name; ///< Name of "default" value
virtual ValueP newValue(const FieldP& thisP) const;
virtual StyleP newStyle(const FieldP& thisP) const;
virtual FieldP clone() const;
virtual String typeName() const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : TextStyle
/// The Style for a TextField
class TextStyle : public Style {
public:
// FontInfo font; ///< Font to use for the text
// SymbolFontInfo symbol_font; ///< Symbol font for symbols in the text
bool always_symbol; ///< Should everything be drawn as symbols?
bool allow_formatting; ///< Is formating (bold/italic/..) allowed?
// Alignment alignment; ///< Alignment inside the box
int angle; ///< Angle of the text inside the box
int padding_left, padding_left_min; ///< Padding
int padding_right, padding_right_min; ///< Padding
int padding_top, padding_top_min; ///< Padding
int padding_bottom, padding_bottom_min; ///< Padding
double line_height_soft; ///< Line height for soft linebreaks
double line_height_hard; ///< Line height for hard linebreaks
double line_height_line; ///< Line height for <line> tags
String mask_filename; ///< Filename of the mask
// ContourMaskP mask; ///< Mask to fit the text to (may be null)
virtual StyleP clone() const;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : TextValue
/// The Value in a TextField
class TextValue : public Value {
public:
virtual ValueP clone() const;
String value;
private:
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -25,18 +25,18 @@ String Game::typeName() const { return _("game"); }
IMPLEMENT_REFLECTION(Game) {
// ioMseVersion(io, fileName, fileVersion);
REFLECT_N("full name", fullName);
REFLECT_N("icon", iconFilename);
// REFLECT_N("init script", initScript);
REFLECT_N("set field", setFields);
REFLECT_N("card field", cardFields);
// REFLECT_N("keyword parameter type", keywordParams);
// REFLECT_N("keyword separator type", keywordSeparators);
REFLECT(full_name);
REFLECT_N("icon", icon_filename);
// REFLECT(init_script);
REFLECT(set_fields);
REFLECT(card_fields);
// REFLECT_N("keyword parameter type", keyword_params);
// REFLECT_N("keyword separator type", keyword_separators);
// REFLECT_N("keyword", keywords);
// REFLECT_N("word list", wordLists);
// REFLECT_N("word list", word_lists);
}
void Game::validate() {
// a default for the full name
if (fullName.empty()) fullName = name();
if (full_name.empty()) full_name = name();
}
\ No newline at end of file
......@@ -19,10 +19,10 @@ DECLARE_POINTER_TYPE(Game);
class Game : public Packaged {
public:
String fullName;
String iconFilename;
vector<FieldP> setFields;
vector<FieldP> cardFields;
String full_name;
String icon_filename;
vector<FieldP> set_fields;
vector<FieldP> card_fields;
/// Loads the game with a particular name, for example "magic"
static GameP byName(const String& name);
......
......@@ -30,11 +30,11 @@ IMPLEMENT_REFLECTION(ColumnSettings) {
}
IMPLEMENT_REFLECTION(GameSettings) {
REFLECT_N("default style", defaultStyle);
REFLECT_N("default export", defaultExport);
REFLECT(default_style);
REFLECT(default_export);
// REFLECT_N("cardlist columns", columns);
REFLECT_N("sort cards by", sortCardsBy);
REFLECT_N("sort cards ascending", sortCardsAscending);
REFLECT(sort_cards_by);
REFLECT(sort_cards_ascending);
}
IMPLEMENT_REFLECTION(StyleSettings) {
......@@ -46,12 +46,12 @@ IMPLEMENT_REFLECTION(StyleSettings) {
Settings settings;
Settings::Settings()
: setWindowMaximized (false)
, setWindowWidth (790)
, setWindowHeight (300)
, cardNotesHeight (40)
, updatesUrl (_("http://magicseteditor.sourceforge.net/updates"))
, checkUpdates (CHECK_IF_CONNECTED)
: set_window_maximized (false)
, set_window_width (790)
, set_window_height (300)
, card_notes_height (40)
, updates_url (_("http://magicseteditor.sourceforge.net/updates"))
, check_updates (CHECK_IF_CONNECTED)
{}
void Settings::addRecentFile(const String& filename) {
......@@ -60,18 +60,18 @@ void Settings::addRecentFile(const String& filename) {
fn.Normalize();
String filenameAbs = fn.GetFullPath();
// remove duplicates
recentSets.erase(
remove(recentSets.begin(), recentSets.end(), filenameAbs),
recentSets.end()
recent_sets.erase(
remove(recent_sets.begin(), recent_sets.end(), filenameAbs),
recent_sets.end()
);
// add to front of list
recentSets.insert(recentSets.begin(), filenameAbs);
recent_sets.insert(recent_sets.begin(), filenameAbs);
// enforce size limit
if (recentSets.size() > maxRecentSets) recentSets.resize(maxRecentSets);
if (recent_sets.size() > max_recent_sets) recent_sets.resize(max_recent_sets);
}
GameSettings& Settings::gameSettingsFor(const Game& game) {
GameSettingsP& gs = settings.gameSettings[game.name()];
GameSettingsP& gs = settings.game_settings[game.name()];
if (!gs) gs.reset(new GameSettings);
return *gs;
}
......@@ -84,29 +84,29 @@ StyleSettings& Settings::styleSettingsFor(const CardStyle& style) {
}
*/
String userSettingsDir() {
String user_settings_dir() {
return _(""); // TODO
}
String Settings::settingsFile() {
// return userSettingsDir() + _("mse.config");
return userSettingsDir() + _("mse8.config"); // use different file during development of C++ port
// return user_settings_dir() + _("mse.config");
return user_settings_dir() + _("mse8.config"); // use different file during development of C++ port
}
IMPLEMENT_REFLECTION(Settings) {
// ioMseVersion(io, "settings", fileVersion);
REFLECT_N("recent set", recentSets);
REFLECT_N("window maximized", setWindowMaximized);
REFLECT_N("window width", setWindowWidth);
REFLECT_N("window height", setWindowHeight);
REFLECT_N("card notes height", cardNotesHeight);
REFLECT_N("default game", defaultGame);
REFLECT_N("apprentice location", apprenticeLocation);
REFLECT_N("updates url", updatesUrl);
REFLECT_N("check updates", checkUpdates);
// ioAll(io, "game settings", gameSettings);
// ioMseVersion(io, "settings", file_version);
REFLECT_N("recent_set", recent_sets);
REFLECT(set_window_maximized);
REFLECT(set_window_width);
REFLECT(set_window_height);
REFLECT(card_notes_height);
REFLECT(default_game);
REFLECT(apprentice_location);
REFLECT(updates_url);
REFLECT(check_updates);
// ioAll(io, game_settings);
// ioStyleSettings(io);
// REFLECT_N("default style settings", defaultStyleSettings);
// REFLECT(default_style_settings);
}
void Settings::read() {
......
......@@ -40,11 +40,11 @@ class ColumnSettings {
/// Settings for a Game
class GameSettings {
public:
String defaultStyle;
String defaultExport;
String default_style;
String default_export;
map<String, ColumnSettings> columns;
String sortCardsBy;
bool sortCardsAscending;
String sort_cards_by;
bool sort_cards_ascending;
DECLARE_REFLECTION();
};
......@@ -53,11 +53,11 @@ class GameSettings {
class StyleSettings {
public:
// Rendering/display settings
/* SimpleDefaultable<double> cardZoom = 1.0;
SimpleDefaultable<int> cardAngle = 0;
SimpleDefaultable<bool> cardAntiAlias = true;
SimpleDefaultable<bool> cardBorders = true;
SimpleDefaultable<bool> cardNormalExport = true;
/* SimpleDefaultable<double> card_zoom = 1.0;
SimpleDefaultable<int> card_angle = 0;
SimpleDefaultable<bool> card_anti_alias = true;
SimpleDefaultable<bool> card_borders = true;
SimpleDefaultable<bool> card_normal_export = true;
*/
DECLARE_REFLECTION();
......@@ -77,20 +77,20 @@ class Settings {
Settings();
// --------------------------------------------------- : Recently opened sets
vector<String> recentSets;
static const UInt maxRecentSets = 4; // store this many recent sets
vector<String> recent_sets;
static const UInt max_recent_sets = 4; // store this many recent sets
/// Add a file to the list of recent files
void addRecentFile(const String& filename);
// --------------------------------------------------- : Set window size
bool setWindowMaximized;
UInt setWindowWidth;
UInt setWindowHeight;
UInt cardNotesHeight;
bool set_window_maximized;
UInt set_window_width;
UInt set_window_height;
UInt card_notes_height;
// --------------------------------------------------- : Default pacakge selections
String defaultGame;
String default_game;
// --------------------------------------------------- : Game/style specific
......@@ -100,18 +100,18 @@ class Settings {
StyleSettings& styleSettingsFor(const CardStyle& style);
private:
map<String,GameSettingsP> gameSettings;
map<String,StyleSettingsP> styleSettings;
StyleSettings defaultStyleSettings;
map<String,GameSettingsP> game_settings;
map<String,StyleSettingsP> style_settings;
StyleSettings default_style_settings;
public:
// --------------------------------------------------- : Special game stuff
String apprenticeLocation;
String mwsLocation;
String apprentice_location;
String mws_location;
// --------------------------------------------------- : Update checking
String updatesUrl;
CheckUpdates checkUpdates;
String updates_url;
CheckUpdates check_updates;
// --------------------------------------------------- : The io
......
......@@ -27,30 +27,30 @@ IMPLEMENT_REFLECTION_ENUM(SegmentMode) {
IMPLEMENT_REFLECTION(ControlPoint) {
REFLECT_N("position", pos);
REFLECT_N("lock", lock);
REFLECT_N("line after", segmentAfter);
if (tag.reading() || segmentBefore == SEGMENT_CURVE) {
REFLECT_N("handle before", deltaBefore);
REFLECT_N("line_after", segment_after);
if (tag.reading() || segment_before == SEGMENT_CURVE) {
REFLECT_N("handle_before", delta_before);
}
if (tag.reading() || segmentAfter == SEGMENT_CURVE) {
REFLECT_N("handle after", deltaAfter);
if (tag.reading() || segment_after == SEGMENT_CURVE) {
REFLECT_N("handle_after", delta_after);
}
}
ControlPoint::ControlPoint()
: segmentBefore(SEGMENT_LINE), segmentAfter(SEGMENT_LINE)
: segment_before(SEGMENT_LINE), segment_after(SEGMENT_LINE)
, lock(LOCK_FREE)
{}
ControlPoint::ControlPoint(double x, double y)
: segmentBefore(SEGMENT_LINE), segmentAfter(SEGMENT_LINE)
: segment_before(SEGMENT_LINE), segment_after(SEGMENT_LINE)
, lock(LOCK_FREE)
, pos(x,y)
{}
ControlPoint::ControlPoint(double x, double y, double xb, double yb, double xa, double ya, LockMode lock)
: segmentBefore(SEGMENT_CURVE), segmentAfter(SEGMENT_CURVE)
: segment_before(SEGMENT_CURVE), segment_after(SEGMENT_CURVE)
, lock(lock)
, pos(x,y)
, deltaBefore(xb,yb)
, deltaAfter(xa,ya)
, delta_before(xb,yb)
, delta_after(xa,ya)
{}
void ControlPoint::onUpdateHandle(WhichHandle wh) {
......@@ -64,31 +64,31 @@ void ControlPoint::onUpdateHandle(WhichHandle wh) {
void ControlPoint::onUpdateLock() {
// The lock has changed, avarage the handle values
if (lock == LOCK_DIR) {
// deltaBefore = x * deltaAfter
Vector2D dir = (deltaBefore - deltaAfter).normalized();
deltaBefore = dir * deltaBefore.length();
deltaAfter = dir * -deltaAfter.length();
// delta_before = x * delta_after
Vector2D dir = (delta_before - delta_after).normalized();
delta_before = dir * delta_before.length();
delta_after = dir * -delta_after.length();
} else if (lock == LOCK_SIZE) {
// deltaBefore = -deltaAfter
deltaBefore = (deltaBefore - deltaAfter) * 0.5;
deltaAfter = -deltaBefore;
// delta_before = -delta_after
delta_before = (delta_before - delta_after) * 0.5;
delta_after = -delta_before;
}
}
Vector2D& ControlPoint::getHandle(WhichHandle wh) {
if (wh == HANDLE_BEFORE) {
return deltaBefore;
return delta_before;
} else {
assert(wh == HANDLE_AFTER);
return deltaAfter;
return delta_after;
}
}
Vector2D& ControlPoint::getOther(WhichHandle wh) {
if (wh == HANDLE_BEFORE) {
return deltaAfter;
return delta_after;
} else {
assert(wh == HANDLE_AFTER);
return deltaBefore;
return delta_before;
}
}
......@@ -112,13 +112,13 @@ IMPLEMENT_REFLECTION(SymbolPart) {
// enforce constraints
enforceConstraints();
calculateBounds();
if (maxPos.x > 100 && maxPos.y > 100) {
if (max_pos.x > 100 && max_pos.y > 100) {
// this is a <= 0.1.2 symbol, points range [0...500] instead of [0...1]
// adjust it
FOR_EACH(p, points) {
p->pos /= 500.0;
p->deltaBefore /= 500.0;
p->deltaAfter /= 500.0;
p->pos /= 500.0;
p->delta_before /= 500.0;
p->delta_after /= 500.0;
}
if (name.empty()) name = _("Shape");
calculateBounds();
......@@ -127,7 +127,7 @@ IMPLEMENT_REFLECTION(SymbolPart) {
}
SymbolPart::SymbolPart()
: combine(PART_OVERLAP), rotationCenter(.5, .5)
: combine(PART_OVERLAP), rotation_center(.5, .5)
{}
SymbolPartP SymbolPart::clone() const {
......@@ -143,16 +143,16 @@ void SymbolPart::enforceConstraints() {
for (int i = 0 ; i < (int)points.size() ; ++i) {
ControlPointP p1 = getPoint(i);
ControlPointP p2 = getPoint(i + 1);
p2->segmentBefore = p1->segmentAfter;
p2->segment_before = p1->segment_after;
p1->onUpdateLock();
}
}
void SymbolPart::calculateBounds() {
minPos = Vector2D::infinity();
maxPos = -Vector2D::infinity();
min_pos = Vector2D::infinity();
max_pos = -Vector2D::infinity();
for (int i = 0 ; i < (int)points.size() ; ++i) {
segmentBounds(*getPoint(i), *getPoint(i + 1), minPos, maxPos);
segment_bounds(*getPoint(i), *getPoint(i + 1), min_pos, max_pos);
}
}
......
......@@ -21,12 +21,12 @@ DECLARE_POINTER_TYPE(Symbol);
// ----------------------------------------------------------------------------- : ControlPoint
/// Mode of locking for control points in a bezier curve
/** Specificly: the relation between deltaBefore and deltaAfter
/** Specificly: the relation between delta_before and delta_after
*/
enum LockMode
{ LOCK_FREE ///< no locking
, LOCK_DIR ///< deltaBefore = x * deltaAfter
, LOCK_SIZE ///< deltaBefore = -deltaAfter
, LOCK_DIR ///< delta_before = x * delta_after
, LOCK_SIZE ///< delta_before = -delta_after
};
/// Is the segment between two ControlPoints a line or a curve?
......@@ -47,19 +47,19 @@ enum WhichHandle
class ControlPoint {
public:
Vector2D pos; ///< position of the control point itself
Vector2D deltaBefore; ///< delta to bezier control point, for curve before point
Vector2D deltaAfter; ///< delta to bezier control point, for curve after point
SegmentMode segmentBefore, segmentAfter;
Vector2D delta_before; ///< delta to bezier control point, for curve before point
Vector2D delta_after; ///< delta to bezier control point, for curve after point
SegmentMode segment_before, segment_after;
LockMode lock;
/// Default constructor
ControlPoint();
/// Constructor for straight lines, takes only the position
ControlPoint(double x, double y);
/// Constructor for curves lines, takes postions, deltaBefore, deltaAfter and lock mode
/// Constructor for curves lines, takes postions, delta_before, delta_after and lock mode
ControlPoint(double x, double y, double xb, double yb, double xa, double ya, LockMode lock = LOCK_FREE);
/// Must be called after deltaBefore/deltaAfter has changed, enforces lock constraints
/// Must be called after delta_before/delta_after has changed, enforces lock constraints
void onUpdateHandle(WhichHandle wh);
/// Must be called after lock has changed, enforces lock constraints
void onUpdateLock();
......@@ -124,10 +124,10 @@ class SymbolPart {
/// How is this part combined with parts below it?
SymbolPartCombine combine;
// Center of rotation, relative to the part, when the part is scaled to [0..1]
Vector2D rotationCenter;
Vector2D rotation_center;
/// Position and size of the part
/// this is the smallest axis aligned bounding box that fits around the part
Vector2D minPos, maxPos;
Vector2D min_pos, max_pos;
SymbolPart();
......
This diff is collapsed.
......@@ -67,7 +67,7 @@ void deCasteljau(const Vector2D& a1, Vector2D& a21, Vector2D& a34, const Vector2
/** Adds the resulting corner points of those lines to out, the last point is not added.
* All points are converted to display coordinates using rot.tr
*/
void segmentSubdivide(const ControlPoint& p0, const ControlPoint& p1, const Rotation& rot, vector<wxPoint>& out);
void segment_subdivide(const ControlPoint& p0, const ControlPoint& p1, const Rotation& rot, vector<wxPoint>& out);
// ----------------------------------------------------------------------------- : Bounds
......@@ -76,30 +76,30 @@ void segmentSubdivide(const ControlPoint& p0, const ControlPoint& p1, const Rota
* min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger.
*/
void segmentBounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
void segment_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
/// Find a bounding box that fits a curve between p1 and p2, stores the results in min and max.
/** min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger
*/
void bezierBounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
void bezier_bounds(const ControlPoint& p1, const ControlPoint& p2, Vector2D& min, Vector2D& max);
/// Find a bounding box that fits around p1 and p2, stores the result in min and max
/** min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger
*/
void lineBounds(const Vector2D& p1, const Vector2D& p2, Vector2D& min, Vector2D& max);
void line_bounds(const Vector2D& p1, const Vector2D& p2, Vector2D& min, Vector2D& max);
/// Find a bounding 'box' that fits around a single point
/** min is only changed if the minimum is smaller then the current value in min,
* max only if the maximum is larger
*/
void pointBounds(const Vector2D& p, Vector2D& min, Vector2D& max);
void point_bounds(const Vector2D& p, Vector2D& min, Vector2D& max);
// ----------------------------------------------------------------------------- : Point tests
/// Is a point inside the given symbol part?
bool pointInPart(const Vector2D& p, const SymbolPart& part);
bool point_in_part(const Vector2D& p, const SymbolPart& part);
// ----------------------------------------------------------------------------- : Finding points
......@@ -107,24 +107,24 @@ bool pointInPart(const Vector2D& p, const SymbolPart& part);
/// the line between p1 and p2 can also be a bezier curve
/** Returns the time on the segment in tOut, and the point on the segment in pOut
*/
bool posOnSegment(const Vector2D& pos, double range, const ControlPoint& p1, const ControlPoint& p2, Vector2D& pOut, double& tOut);
bool pos_on_segment(const Vector2D& pos, double range, const ControlPoint& p1, const ControlPoint& p2, Vector2D& pOut, double& tOut);
/// Finds the position of p0 on the line between p1 and p2, returns true if the point is on (or near)
/// the bezier curve between p1 and p2
bool posOnBezier (const Vector2D& pos, double range, const ControlPoint& p1, const ControlPoint& p2, Vector2D& pOut, double& tOut);
bool pos_on_bezier (const Vector2D& pos, double range, const ControlPoint& p1, const ControlPoint& p2, Vector2D& pOut, double& tOut);
/// Finds the position of p0 on the line p1-p2, returns true if the point is withing range of the line
/// if that is the case then (x,y) = p1 + (p2-p1) * out
bool posOnLine (const Vector2D& pos, double range, const Vector2D& p1, const Vector2D& p2, Vector2D& pOut, double& tOut);
bool pos_on_line (const Vector2D& pos, double range, const Vector2D& p1, const Vector2D& p2, Vector2D& pOut, double& tOut);
// ----------------------------------------------------------------------------- : Intersection
/// Counts the number of intersections between the ray/halfline from (-inf, pos.y) to pos
/// and the bezier curve between p1 and p2.
UInt intersectBezierRay(const ControlPoint& p1, const ControlPoint& p2, const Vector2D& pos);
UInt intersect_bezier_ray(const ControlPoint& p1, const ControlPoint& p2, const Vector2D& pos);
// Does the line between p1 and p2 intersect the ray (half line) from (-inf, pos.y) to pos?
bool intersectLineRay(const Vector2D& p1, const Vector2D& p2, const Vector2D& pos);
bool intersect_line_ray(const Vector2D& p1, const Vector2D& p2, const Vector2D& pos);
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -88,7 +88,7 @@ COMBINE_FUN(COMBINE_SHADOW, (b * a * a) / (255 * 255) )
/// Combine image b onto image a using some combining mode.
/// The results are stored in the image A.
template <ImageCombine combine>
void combineImageDo(Image& a, Image b) {
void combine_image_do(Image& a, Image b) {
UInt size = a.GetWidth() * a.GetHeight() * 3;
Byte *dataA = a.GetData(), *dataB = b.GetData();
// for each pixel: apply function
......@@ -97,7 +97,7 @@ void combineImageDo(Image& a, Image b) {
}
}
void combineImage(Image& a, const Image& b, ImageCombine combine) {
void combine_image(Image& a, const Image& b, ImageCombine combine) {
// Images must have same size
assert(a.GetWidth() == b.GetWidth());
assert(a.GetHeight() == b.GetHeight());
......@@ -108,7 +108,7 @@ void combineImage(Image& a, const Image& b, ImageCombine combine) {
}
// Combine image data, by dispatching to combineImageDo
switch(combine) {
#define DISPATCH(comb) case comb: combineImageDo<comb>(a,b); return
#define DISPATCH(comb) case comb: combine_image_do<comb>(a,b); return
DISPATCH(COMBINE_NORMAL);
DISPATCH(COMBINE_ADD);
DISPATCH(COMBINE_SUBTRACT);
......@@ -135,5 +135,6 @@ void combineImage(Image& a, const Image& b, ImageCombine combine) {
}
}
void drawCombineImage(DC& dc, UInt x, UInt y, const Image& img, ImageCombine combine) {
void draw_combine_image(DC& dc, UInt x, UInt y, const Image& img, ImageCombine combine) {
// todo
}
\ No newline at end of file
......@@ -41,7 +41,7 @@ void resample_and_clip(const Image& imgIn, Image& imgOut, wxRect rect);
/// Rotates an image counter clockwise
/// angle must be a multiple of 90, i.e. {0,90,180,270}
Image rotateImageBy(const Image& image, int angle);
Image rotate_image(const Image& image, int angle);
// ----------------------------------------------------------------------------- : Blending
......@@ -59,7 +59,7 @@ void vblend(Image& img1, const Image& img2);
* mask is used as a mask, white pixels are taken from img1, black pixels from img2
* color channels are blended separatly
*/
void maskBlend(Image& img1, const Image& img2, const Image& mask);
void mask_blend(Image& img1, const Image& img2, const Image& mask);
// ----------------------------------------------------------------------------- : Combining
......@@ -94,10 +94,10 @@ enum ImageCombine
/// The results are stored in the image A.
/// This image gets the alpha channel from B, it should then be
/// drawn onto the area where A originated.
void combineImage(Image& a, const Image& b, ImageCombine combine);
void combine_image(Image& a, const Image& b, ImageCombine combine);
/// Draw an image to a DC using a combining function
void drawCombineImage(DC& dc, UInt x, UInt y, const Image& img, ImageCombine combine);
void draw_combine_image(DC& dc, UInt x, UInt y, const Image& img, ImageCombine combine);
// ----------------------------------------------------------------------------- : Utility
......
......@@ -11,7 +11,7 @@
// ----------------------------------------------------------------------------- : Solving
UInt solveLinear(double a, double b, double* root) {
UInt solve_linear(double a, double b, double* root) {
if (a == 0) {
if (b == 0) {
root[0] = 0;
......@@ -25,9 +25,9 @@ UInt solveLinear(double a, double b, double* root) {
}
}
UInt solveQuadratic(double a, double b, double c, double* roots) {
UInt solve_quadratic(double a, double b, double c, double* roots) {
if (a == 0) {
return solveLinear(b, c, roots);
return solve_linear(b, c, roots);
} else {
double d = b*b - 4*a*c;
if (d < 0) return 0;
......@@ -37,11 +37,11 @@ UInt solveQuadratic(double a, double b, double c, double* roots) {
}
}
UInt solveCubic(double a, double b, double c, double d, double* roots) {
UInt solve_cubic(double a, double b, double c, double d, double* roots) {
if (a == 0) {
return solveQuadratic(b, c, d, roots);
return solve_quadratic(b, c, d, roots);
} else {
return solveCubic(b/a, c/a, d/a, roots);
return solve_cubic(b/a, c/a, d/a, roots);
}
}
......@@ -49,7 +49,7 @@ UInt solveCubic(double a, double b, double c, double d, double* roots) {
template <typename T>
inline T curt(T x) { return pow(x, 1.0 / 3); }
UInt solveCubic(double a, double b, double c, double* roots) {
UInt solve_cubic(double a, double b, double c, double* roots) {
double p = b - a*a / 3;
double q = c + (2 * a*a*a - 9 * a * b) / 27;
if (p == 0 && q == 0) {
......
......@@ -21,23 +21,23 @@
/// Solve a linear equation a x + b = 0
/** Returns the number of real roots, and the roots themselfs in the output parameter.
*/
UInt solveLinear(double a, double b, double* root);
UInt solve_linear(double a, double b, double* root);
/// Solve a quadratic equation a x^2 + b x + c == 0
/** Returns the number of real roots, and the roots themselfs in the output parameter.
*/
UInt solveQuadratic(double a, double b, double c, double* roots);
UInt solve_quadratic(double a, double b, double c, double* roots);
// Solve a cubic equation a x^3 + b x^2 + c x + d == 0
/** Returns the number of real roots, and the roots themselfs in the output parameter.
*/
UInt solveCubic(double a, double b, double c, double d, double* roots);
UInt solve_cubic(double a, double b, double c, double d, double* roots);
// Solve a cubic equation x^3 + a x^2 + b x + c == 0
/** Returns the number of real roots, and the roots themselfs in the output parameter.
* Based on http://en.wikipedia.org/wiki/Cubic_equation
*/
UInt solveCubic(double a, double b, double c, double* roots);
UInt solve_cubic(double a, double b, double c, double* roots);
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -14,7 +14,7 @@
// Rotates an image
// 'Rotater' is a function object that knows how to 'rotate' a pixel coordinate
template <class Rotater>
Image rotateImageImpl(Image img) {
Image rotate_image_impl(Image img) {
UInt width = img.GetWidth(), height = img.GetHeight();
// initialize the return image
Image ret;
......@@ -83,13 +83,13 @@ struct Rotate270 {
// ----------------------------------------------------------------------------- : Interface
Image rotateImageBy(const Image& image, int angle) {
Image rotate_image(const Image& image, int angle) {
if (angle == 90) {
return rotateImageImpl<Rotate90>(image);
return rotate_image_impl<Rotate90>(image);
} else if (angle == 180){
return rotateImageImpl<Rotate180>(image);
return rotate_image_impl<Rotate180>(image);
} else if (angle == 270){
return rotateImageImpl<Rotate270>(image);
return rotate_image_impl<Rotate270>(image);
} else{
return image;
}
......
......@@ -26,8 +26,8 @@ DECLARE_TYPEOF_COLLECTION(SetWindowPanel*);
SetWindow::SetWindow(Window* parent, const SetP& set)
: wxFrame(parent, wxID_ANY, _("Magic Set Editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
, currentPanel(nullptr)
, findDialog(nullptr)
, current_panel(nullptr)
, find_dialog(nullptr)
{
SetIcon(wxIcon(_("ICON_APP")));
......@@ -43,7 +43,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
menuExport->Append(ID_FILE_EXPORT_IMAGE, _("Card &Image..."), _("Export the selected card to an image file"));
menuExport->Append(ID_FILE_EXPORT_IMAGES, _("All Card I&mages..."), _("Export images for all cards"));
menuExport->Append(ID_FILE_EXPORT_APPR, _("&Apprentice..."), _("Export the set so it can be played with in Apprentice"));
menuExport->Append(ID_FILE_EXPORT_MWS, _("Magic &Workstation..."), _("Export the set so it can be played with in Magic Workstation"));
menuExport->Append(ID_FILE_EXPORT_MWS, _("Magic &Workstation..."), _("Export the set so it can be played with in Magic Workstation"));
menuFile->Append(ID_FILE_EXPORT, _("&Export"), _("Export the set..."), menuExport);
menuFile->AppendSeparator();
menuFile->Append(ID_FILE_INSPECT, _("Inspect Internal Data..."), _("Shows a the data in the set using a tree structure"));
......@@ -126,8 +126,8 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
// loose ends
tabBar->Realize();
SetSize(settings.setWindowWidth, settings.setWindowHeight);
if (settings.setWindowMaximized) {
SetSize(settings.set_window_width, settings.set_window_height);
if (settings.set_window_maximized) {
Maximize();
}
// SetWindows.push_back(&this); // register this window
......@@ -144,15 +144,15 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
SetWindow::~SetWindow() {
// store window size in settings
wxSize s = GetSize();
settings.setWindowMaximized = IsMaximized();
settings.set_window_maximized = IsMaximized();
if (!IsMaximized()) {
settings.setWindowWidth = s.GetWidth();
settings.setWindowHeight = s.GetHeight();
settings.set_window_width = s.GetWidth();
settings.set_window_height = s.GetHeight();
}
// destroy ui of selected panel
currentPanel->destroyUI(GetToolBar(), GetMenuBar());
current_panel->destroyUI(GetToolBar(), GetMenuBar());
// cleanup (see find stuff)
delete findDialog;
delete find_dialog;
// remove from list of main windows
// SetWindows.erase(remove(SetWindows.begin(), SetWindows.end(), &this));
// stop updating
......@@ -177,11 +177,11 @@ void SetWindow::addPanel(wxMenu* windowMenu, wxToolBar* tabBar, SetWindowPanel*
void SetWindow::selectPanel(int id) {
SetWindowPanel* toSelect = panels.at(id - ID_WINDOW_MIN);
if (currentPanel != toSelect) {
if (current_panel != toSelect) {
// destroy & create menus
if (currentPanel) currentPanel->destroyUI(GetToolBar(), GetMenuBar());
currentPanel = toSelect;
currentPanel->initUI(GetToolBar(), GetMenuBar());
if (current_panel) current_panel->destroyUI(GetToolBar(), GetMenuBar());
current_panel = toSelect;
current_panel->initUI(GetToolBar(), GetMenuBar());
}
// show/hide panels and select tabs
wxSizer* sizer = GetSizer();
......@@ -189,9 +189,9 @@ void SetWindow::selectPanel(int id) {
wxMenuBar* menuBar = GetMenuBar();
int wid = ID_WINDOW_MIN;
FOR_EACH(p, panels) {
sizer->Show (p, p == currentPanel);
tabBar->ToggleTool(wid, p == currentPanel);
menuBar->Check (wid, p == currentPanel);
sizer->Show (p, p == current_panel);
tabBar->ToggleTool(wid, p == current_panel);
menuBar->Check (wid, p == current_panel);
++wid;
}
// fix sizer stuff
......@@ -322,7 +322,7 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch (ev.GetId()) {
// file menu
case ID_FILE_SAVE_AS: ev.Enable(!set->actions.atSavePoint() || set->needSaveAs()); break;
case ID_FILE_EXPORT_IMAGE: ev.Enable(!!currentPanel->selectedCard()); break;
case ID_FILE_EXPORT_IMAGE: ev.Enable(!!current_panel->selectedCard()); break;
case ID_FILE_EXPORT_APPR: ev.Enable(set->game->isMagic()); break;
case ID_FILE_EXPORT_MWS: ev.Enable(set->game->isMagic()); break;
/*case ID_FILE_INSPECT: {
......@@ -346,15 +346,15 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
break;
}
// copy & paste & find
case ID_EDIT_CUT : ev.Enable(currentPanel->canCut()); break;
case ID_EDIT_COPY : ev.Enable(currentPanel->canCopy()); break;
case ID_EDIT_PASTE : ev.Enable(currentPanel->canPaste()); break;
case ID_EDIT_FIND : ev.Enable(currentPanel->canFind()); break;
case ID_EDIT_FIND_NEXT : ev.Enable(currentPanel->canFind()); break;
case ID_EDIT_REPLACE : ev.Enable(currentPanel->canReplace()); break;
case ID_EDIT_CUT : ev.Enable(current_panel->canCut()); break;
case ID_EDIT_COPY : ev.Enable(current_panel->canCopy()); break;
case ID_EDIT_PASTE : ev.Enable(current_panel->canPaste()); break;
case ID_EDIT_FIND : ev.Enable(current_panel->canFind()); break;
case ID_EDIT_FIND_NEXT : ev.Enable(current_panel->canFind()); break;
case ID_EDIT_REPLACE : ev.Enable(current_panel->canReplace()); break;
default:
// items created by the panel, and cut/copy/paste and find/replace
currentPanel->onUpdateUI(ev);
current_panel->onUpdateUI(ev);
}
}
......@@ -401,7 +401,7 @@ void SetWindow::onFileInspect(wxCommandEvent&) {
}*/
void SetWindow::onFileExportImage(wxCommandEvent&) {
CardP card = currentPanel->selectedCard();
CardP card = current_panel->selectedCard();
if (!card) return; // no card selected
String name = wxFileSelector(_("Save image"), _(""), card->identification(), _(""),
_("JPEG images (*.jpg)|*.jpg|Windows bitmaps (*.bmp)|*.bmp|PNG images (*.png)|*.png|GIF images (*.gif)|*.gif|TIFF images (*.tif)|*.tif"),
......@@ -465,38 +465,38 @@ void SetWindow::onEditRedo(wxCommandEvent&) {
}
void SetWindow::onEditCut (wxCommandEvent&) {
currentPanel->doCut();
current_panel->doCut();
}
void SetWindow::onEditCopy (wxCommandEvent&) {
currentPanel->doCopy();
current_panel->doCopy();
}
void SetWindow::onEditPaste(wxCommandEvent&) {
currentPanel->doPaste();
current_panel->doPaste();
}
void SetWindow::onEditFind(wxCommandEvent&) {
delete findDialog;
findDialog = new wxFindReplaceDialog(this, &findData, _("Find"));
findDialog->Show();
delete find_dialog;
find_dialog = new wxFindReplaceDialog(this, &find_data, _("Find"));
find_dialog->Show();
}
void SetWindow::onEditFindNext(wxCommandEvent&) {
currentPanel->doFind(findData);
current_panel->doFind(find_data);
}
void SetWindow::onEditReplace(wxCommandEvent&) {
delete findDialog;
findDialog = new wxFindReplaceDialog(this, &findData, _("Replace"), wxFR_REPLACEDIALOG);
findDialog->Show();
delete find_dialog;
find_dialog = new wxFindReplaceDialog(this, &find_data, _("Replace"), wxFR_REPLACEDIALOG);
find_dialog->Show();
}
// find events
void SetWindow::onFind (wxFindDialogEvent&) {
currentPanel->doFind(findData);
current_panel->doFind(find_data);
}
void SetWindow::onFindNext (wxFindDialogEvent&) {
currentPanel->doFind(findData);
current_panel->doFind(find_data);
}
void SetWindow::onReplace (wxFindDialogEvent&) {
currentPanel->doReplace(findData);
current_panel->doReplace(find_data);
}
void SetWindow::onReplaceAll(wxFindDialogEvent&) {
// todo
......@@ -541,7 +541,7 @@ void SetWindow::onHelpAbout(wxCommandEvent&) {
// ----------------------------------------------------------------------------- : Window events - menu - for child panel
void SetWindow::onChildMenu(wxCommandEvent& ev) {
currentPanel->onCommand(ev.GetId());
current_panel->onCommand(ev.GetId());
}
// ----------------------------------------------------------------------------- : Event table
......
......@@ -41,14 +41,14 @@ class SetWindow : public wxFrame, public SetView {
// gui items
vector<SetWindowPanel*> panels; ///< All panels on this window
SetWindowPanel* currentPanel;
SetWindowPanel* current_panel;
/// Number of items in the recent sets list
size_t numberOfRecentSets;
size_t number_of_recentSets;
// data for find/replace
wxDialog* findDialog;
wxFindReplaceData findData;
wxDialog* find_dialog;
wxFindReplaceData find_data;
// --------------------------------------------------- : Panel managment
......
......@@ -35,7 +35,7 @@ void SymbolControl::switchEditor(const SymbolEditorBaseP& e) {
}
void SymbolControl::onChangeSymbol() {
selectedParts.clear();
selected_parts.clear();
switchEditor(new_shared2<SymbolSelectEditor>(this, false));
Refresh(false);
}
......@@ -49,14 +49,14 @@ void SymbolControl::onModeChange(wxCommandEvent& ev) {
switchEditor(new_shared2<SymbolSelectEditor>(this, true));
break;
case ID_MODE_POINTS:
if (selectedParts.size() == 1) {
singleSelection = *selectedParts.begin();
switchEditor(new_shared2<SymbolPointEditor>(this, singleSelection));
if (selected_parts.size() == 1) {
single_selection = *selected_parts.begin();
switchEditor(new_shared2<SymbolPointEditor>(this, single_selection));
}
break;
case ID_MODE_SHAPES:
if (!selectedParts.empty()) {
selectedParts.clear();
if (!selected_parts.empty()) {
selected_parts.clear();
signalSelectionChange();
}
switchEditor(new_shared1<SymbolBasicShapeEditor>(this));
......@@ -78,26 +78,26 @@ void SymbolControl::onUpdateSelection() {
switch(editor->modeToolId()) {
case ID_MODE_POINTS:
// can only select a single part!
if (selectedParts.size() > 1) {
SymbolPartP part = *selectedParts.begin();
selectedParts.clear();
selectedParts.insert(part);
if (selected_parts.size() > 1) {
SymbolPartP part = *selected_parts.begin();
selected_parts.clear();
selected_parts.insert(part);
signalSelectionChange();
} else if (selectedParts.empty()) {
selectedParts.insert(singleSelection);
} else if (selected_parts.empty()) {
selected_parts.insert(single_selection);
signalSelectionChange();
}
if (singleSelection != *selectedParts.begin()) {
if (single_selection != *selected_parts.begin()) {
// begin editing another part
singleSelection = *selectedParts.begin();
editor = new_shared2<SymbolPointEditor>(this, singleSelection);
single_selection = *selected_parts.begin();
editor = new_shared2<SymbolPointEditor>(this, single_selection);
Refresh(false);
}
break;
case ID_MODE_SHAPES:
if (!selectedParts.empty()) {
if (!selected_parts.empty()) {
// there can't be a selection
selectedParts.clear();
selected_parts.clear();
signalSelectionChange();
}
break;
......@@ -108,15 +108,15 @@ void SymbolControl::onUpdateSelection() {
}
void SymbolControl::selectPart(const SymbolPartP& part) {
selectedParts.clear();
selectedParts.insert(part);
selected_parts.clear();
selected_parts.insert(part);
switchEditor(new_shared2<SymbolSelectEditor>(this, false));
signalSelectionChange();
}
void SymbolControl::activatePart(const SymbolPartP& part) {
selectedParts.clear();
selectedParts.insert(part);
selected_parts.clear();
selected_parts.insert(part);
switchEditor(new_shared2<SymbolPointEditor>(this, part));
}
......@@ -154,34 +154,34 @@ void SymbolControl::onPaint(wxPaintEvent& e) {
void SymbolControl::onLeftDown(wxMouseEvent& ev) {
Vector2D pos = rotation.trInv(RealPoint(ev.GetX(), ev.GetY()));
if (editor) editor->onLeftDown(pos, ev);
lastPos = pos;
last_pos = pos;
ev.Skip(); // for focus
}
void SymbolControl::onLeftUp(wxMouseEvent& ev) {
Vector2D pos = rotation.trInv(RealPoint(ev.GetX(), ev.GetY()));
if (editor) editor->onLeftUp(pos, ev);
lastPos = pos;
last_pos = pos;
}
void SymbolControl::onLeftDClick(wxMouseEvent& ev) {
Vector2D pos = rotation.trInv(RealPoint(ev.GetX(), ev.GetY()));
if (editor) editor->onLeftDClick(pos, ev);
lastPos = pos;
last_pos = pos;
}
void SymbolControl::onRightDown(wxMouseEvent& ev) {
Vector2D pos = rotation.trInv(RealPoint(ev.GetX(), ev.GetY()));
if (editor) editor->onRightDown(pos, ev);
lastPos = pos;
last_pos = pos;
}
void SymbolControl::onMotion(wxMouseEvent& ev) {
Vector2D pos = rotation.trInv(RealPoint(ev.GetX(), ev.GetY()));
// Dragging something?
if (ev.LeftIsDown()) {
if (editor) editor->onMouseDrag(lastPos, pos, ev);
if (editor) editor->onMouseDrag(last_pos, pos, ev);
} else {
if (editor) editor->onMouseMove(lastPos, pos, ev);
if (editor) editor->onMouseMove(last_pos, pos, ev);
}
lastPos = pos;
last_pos = pos;
}
// Key events, just forward
......@@ -207,7 +207,7 @@ void SymbolControl::onUpdateUI(wxUpdateUIEvent& ev) {
ev.Check(editor->modeToolId() == ev.GetId());
if (ev.GetId() == ID_MODE_POINTS) {
// can only edit points when a single part is selected <TODO?>
ev.Enable(selectedParts.size() == 1);
ev.Enable(selected_parts.size() == 1);
}
break;
case ID_MODE_PAINT:
......
......@@ -71,8 +71,8 @@ class SymbolControl : public wxControl, public SymbolViewer {
public:
/// What parts are selected
set<SymbolPartP> selectedParts;
SymbolPartP singleSelection;
set<SymbolPartP> selected_parts;
SymbolPartP single_selection;
/// Parent window
SymbolWindow* parent;
......@@ -82,7 +82,7 @@ class SymbolControl : public wxControl, public SymbolViewer {
SymbolEditorBaseP editor;
/// Last mouse position
Vector2D lastPos;
Vector2D last_pos;
// --------------------------------------------------- : Events
......
......@@ -20,12 +20,12 @@ SymbolPartList::SymbolPartList(Window* parent, int id, SymbolP symbol)
// Create image list
wxImageList* images = new wxImageList(16,16);
// NOTE: this is based on the order of the SymbolPartCombine enum!
images->Add(loadResourceImage(_("COMBINE_OR")));
images->Add(loadResourceImage(_("COMBINE_SUB")));
images->Add(loadResourceImage(_("COMBINE_AND")));
images->Add(loadResourceImage(_("COMBINE_XOR")));
images->Add(loadResourceImage(_("COMBINE_OVER")));
images->Add(loadResourceImage(_("COMBINE_BORDER")));
images->Add(load_resource_image(_("COMBINE_OR")));
images->Add(load_resource_image(_("COMBINE_SUB")));
images->Add(load_resource_image(_("COMBINE_AND")));
images->Add(load_resource_image(_("COMBINE_XOR")));
images->Add(load_resource_image(_("COMBINE_OVER")));
images->Add(load_resource_image(_("COMBINE_BORDER")));
AssignImageList(images, wxIMAGE_LIST_SMALL);
// create columns
InsertColumn(0, _("Name"));
......@@ -74,7 +74,7 @@ void SymbolPartList::selectItem(long item) {
}
}
void SymbolPartList::getSelectedParts(set<SymbolPartP>& sel) {
void SymbolPartList::getselected_parts(set<SymbolPartP>& sel) {
sel.clear();
long count = GetItemCount();
for (long i = 0 ; i < count ; ++ i) {
......
......@@ -31,7 +31,7 @@ class SymbolPartList : public wxListCtrl, public SymbolView {
inline SymbolPartP getSelection() const { return getPart(selected); }
/// Get a set of selected parts
void getSelectedParts(set<SymbolPartP>& sel);
void getselected_parts(set<SymbolPartP>& sel);
/// Select the specified parts, and nothing else
void selectParts(const set<SymbolPartP>& sel);
......
This diff is collapsed.
......@@ -99,23 +99,23 @@ class SymbolPointEditor : public SymbolEditorBase {
};
Selection selection;
// points
set<ControlPointP> selectedPoints;
set<ControlPointP> selected_points;
// handle
SelectedHandle selectedHandle;
SelectedHandle selected_handle;
// line
ControlPointP selectedLine1, selectedLine2; // selected the line between these points
double selectedLineT; // time on the line of the selection
ControlPointP selected_line1, selected_line2; // selected the line between these points
double selected_line_t; // time on the line of the selection
// Mouse feedback
Selection hovering;
// handle
SelectedHandle hoverHandle; // the handle currently under the cursor
SelectedHandle hover_handle; // the handle currently under the cursor
// new point
Vector2D newPoint;
Vector2D new_point;
// line
ControlPointP hoverLine1, hoverLine2; // hovering on the line between these points
double hoverLineT;
int hoverLine1Idx; // index of hoverLine1 in the list of points
ControlPointP hover_line_1, hover_line_2; // hovering on the line between these points
double hover_line_t;
int hover_line_1_idx; // index of hover_line_1 in the list of points
// Gui stock
wxBitmap background;
......
This diff is collapsed.
......@@ -105,7 +105,7 @@ class SymbolSelectEditor : public SymbolEditorBase {
/// Find the first part at the given position
SymbolPartP findPart(const Vector2D& pos);
/// Update minV and maxV to be the bounding box of the selectedParts
/// Update minV and maxV to be the bounding box of the selected_parts
/// Updates center to be the rotation center of the parts
void updateBoundingBox();
......
......@@ -103,7 +103,7 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolPart& part, HighlightStyle
vector<wxPoint> points;
size_t size = part.points.size();
for(size_t i = 0 ; i < size ; ++i) {
segmentSubdivide(*part.getPoint((int)i), *part.getPoint((int)i+1), rotation, points);
segment_subdivide(*part.getPoint((int)i), *part.getPoint((int)i+1), rotation, points);
}
// draw
if (style == HIGHLIGHT_BORDER) {
......@@ -165,7 +165,7 @@ void SymbolViewer::drawSymbolPart(const SymbolPart& part, DC* border, DC* interi
vector<wxPoint> points;
size_t size = part.points.size();
for(size_t i = 0 ; i < size ; ++i) {
segmentSubdivide(*part.getPoint((int)i), *part.getPoint((int)i+1), rotation, points);
segment_subdivide(*part.getPoint((int)i), *part.getPoint((int)i+1), rotation, points);
}
// draw border
if (border) {
......
......@@ -218,7 +218,7 @@ void SymbolWindow::onUpdateUI(wxUpdateUIEvent& ev) {
void SymbolWindow::onSelectFromList(wxListEvent& ev) {
if (inSelectionEvent) return ;
inSelectionEvent = true;
parts->getSelectedParts(control->selectedParts);
parts->getselected_parts(control->selected_parts);
control->onUpdateSelection();
inSelectionEvent = false;
}
......@@ -229,7 +229,7 @@ void SymbolWindow::onActivateFromList(wxListEvent& ev) {
void SymbolWindow::onSelectFromControl() {
if (inSelectionEvent) return ;
inSelectionEvent = true;
parts->selectParts(control->selectedParts);
parts->selectParts(control->selected_parts);
inSelectionEvent = false;
}
......
......@@ -22,7 +22,7 @@ void clearDC(DC& dc, const wxBrush& brush) {
// ----------------------------------------------------------------------------- : Image related
Image loadResourceImage(String name) {
Image load_resource_image(String name) {
#ifdef __WXMSW__
// Load resource
// based on wxLoadUserResource
......
......@@ -23,7 +23,7 @@ void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH);
// ----------------------------------------------------------------------------- : Resource related
/// Load an image from a resource
Image loadResourceImage(String name);
Image load_resource_image(String name);
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -161,7 +161,7 @@
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;__WINDOWS__;__WXMSW__;DEBUG=1;__WXDEBUG__;__WIN95__;__WIN32__;WINVER=0x0400;STRICT;UNICODE;_UNICODE;wxUSE_UNICODE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="2"
......
......@@ -63,8 +63,8 @@ class TokenIterator {
private:
String input;
size_t pos;
vector<Token> buffer; // buffer of unread tokens, front() = current
stack<bool> openBraces; // braces we entered, true if the brace was from a smart string escape
vector<Token> buffer; // buffer of unread tokens, front() = current
stack<bool> open_braces; // braces we entered, true if the brace was from a smart string escape
/// Read the next token, and add it to the buffer
void addToken();
/// Read the next token which is a string (after the opening ")
......@@ -125,7 +125,7 @@ void TokenIterator::addToken() {
// name
size_t start = pos - 1;
while (pos < input.size() && isAlnum_(input.GetChar(pos))) ++pos;
Token t = {TOK_NAME, cannocialNameForm(input.substr(start, pos-start)) }; // convert name to cannocial form
Token t = {TOK_NAME, cannocial_name_form(input.substr(start, pos-start)) }; // convert name to cannocial form
buffer.push_back(t);
} else if (isDigit(c)) {
// number
......@@ -151,21 +151,21 @@ void TokenIterator::addToken() {
} else if (c==_('"')) {
// string
addStringToken();
} else if (c == _('}') && !openBraces.empty() && openBraces.top()) {
} else if (c == _('}') && !open_braces.empty() && open_braces.top()) {
// closing smart string, resume to string parsing
// "a{e}b" --> "a" "{ e }" "b"
openBraces.pop();
open_braces.pop();
Token t2 = {TOK_RPAREN, _("}\"")};
buffer.push_back(t2);
addStringToken();
} else if (isLparen(c)) {
// paranthesis/brace
openBraces.push(false);
open_braces.push(false);
Token t = { TOK_LPAREN, String(1,c) };
buffer.push_back(t);
} else if (isRparen(c)) {
// paranthesis/brace
if (!openBraces.empty()) openBraces.pop();
if (!open_braces.empty()) open_braces.pop();
Token t = { TOK_RPAREN, String(1,c) };
buffer.push_back(t);
} else if(c==_('#')) {
......@@ -197,7 +197,7 @@ void TokenIterator::addStringToken() {
// smart string
// "a{e}b" --> "a" "{ e }" "b"
buffer.push_back(t);
openBraces.push(true);
open_braces.push(true);
Token t2 = {TOK_LPAREN, _("\"{")};
buffer.push_back(t2);
return;
......
......@@ -16,77 +16,77 @@ DECLARE_TYPEOF_COLLECTION(Action*);
DECLARE_TYPEOF_COLLECTION(ActionListener*);
ActionStack::ActionStack()
: savePoint(nullptr)
: save_point(nullptr)
{}
ActionStack::~ActionStack() {
// we own the actions, delete them
FOR_EACH(a, undoActions) delete a;
FOR_EACH(a, redoActions) delete a;
FOR_EACH(a, undo_actions) delete a;
FOR_EACH(a, redo_actions) delete a;
}
void ActionStack::add(Action* action, bool allowMerge) {
void ActionStack::add(Action* action, bool allow_merge) {
if (!action) return; // no action
action->perform(false); // TODO: delete action if perform throws
redoActions.clear();
redo_actions.clear();
tellListeners(*action);
// try to merge?
if (allowMerge && !undoActions.empty() && undoActions.back()->merge(action)) {
if (allow_merge && !undo_actions.empty() && undo_actions.back()->merge(action)) {
// merged with top undo action
delete action;
} else {
undoActions.push_back(action);
undo_actions.push_back(action);
}
}
void ActionStack::undo() {
assert(canUndo());
Action* action = undoActions.back();
Action* action = undo_actions.back();
action->perform(true);
// move to redo stack
undoActions.pop_back();
redoActions.push_back(action);
undo_actions.pop_back();
redo_actions.push_back(action);
}
void ActionStack::redo() {
assert(canRedo());
Action* action = redoActions.back();
Action* action = redo_actions.back();
action->perform(false);
// move to undo stack
redoActions.pop_back();
undoActions.push_back(action);
redo_actions.pop_back();
undo_actions.push_back(action);
}
bool ActionStack::canUndo() const {
return !undoActions.empty();
return !undo_actions.empty();
}
bool ActionStack::canRedo() const {
return !redoActions.empty();
return !redo_actions.empty();
}
String ActionStack::undoName() const {
if (canUndo()) {
return _("Undo ") + capitalize(undoActions.back()->getName(true));
return _("Undo ") + capitalize(undo_actions.back()->getName(true));
} else {
return _("Undo");
}
}
String ActionStack::redoName() const {
if (canRedo()) {
return _("Redo ") + capitalize(redoActions.back()->getName(false));
return _("Redo ") + capitalize(redo_actions.back()->getName(false));
} else {
return _("Redo");
}
}
bool ActionStack::atSavePoint() const {
return (undoActions.empty() && savePoint == nullptr)
|| (undoActions.back() == savePoint);
return (undo_actions.empty() && save_point == nullptr)
|| (undo_actions.back() == save_point);
}
void ActionStack::setSavePoint() {
if (undoActions.empty()) {
savePoint = nullptr;
if (undo_actions.empty()) {
save_point = nullptr;
} else {
savePoint = undoActions.back();
save_point = undo_actions.back();
}
}
......
......@@ -23,17 +23,17 @@ class Action {
virtual ~Action() {};
/// Name of the action, for use in strings like "Undo <name>"
virtual String getName(bool toUndo) const = 0;
virtual String getName(bool to_undo) const = 0;
/// Perform the action
/** @param toUndo if true, undo the action instead of doing it
/** @param to_undo if true, undo the action instead of doing it
*
* Must be implemented in derived class.
*
* Perform will only ever be called alternatingly with toUndo = true/false,
* the first time with toUndo = false
* Perform will only ever be called alternatingly with to_undo = true/false,
* the first time with to_undo = false
*/
virtual void perform(bool toUndo) = 0;
virtual void perform(bool to_undo) = 0;
/// Try to merge another action to the end of this action.
/** Either: return false and do nothing
......@@ -103,12 +103,12 @@ class ActionStack {
private:
/// Actions to be undone
/// Owns the action objects!
vector<Action*> undoActions;
vector<Action*> undo_actions;
/// Actions to be redone
/// Owns the action objects!
vector<Action*> redoActions;
vector<Action*> redo_actions;
/// Point at which the file was saved, corresponds to the top of the undo stack at that point
Action* savePoint;
Action* save_point;
/// Objects that are listening to actions
vector<ActionListener*> listeners;
};
......
......@@ -13,19 +13,19 @@
// ----------------------------------------------------------------------------- : Reader
Reader::Reader(const InputStreamP& input, String filename)
: input(input), filename(filename), lineNumber(0)
, indent(0), expectedIndent(0), justOpened(false)
: input(input), filename(filename), line_number(0)
, indent(0), expected_indent(0), just_opened(false)
, stream(*input)
{
moveNext();
}
bool Reader::enterBlock(const Char* name) {
if (justOpened) moveNext(); // on the key of the parent block, first move inside it
if (indent != expectedIndent) return false; // not enough indentation
if (just_opened) moveNext(); // on the key of the parent block, first move inside it
if (indent != expected_indent) return false; // not enough indentation
if (name == key) {
justOpened = true;
expectedIndent += 1; // the indent inside the block must be at least this much
just_opened = true;
expected_indent += 1; // the indent inside the block must be at least this much
return true;
} else {
return false;
......@@ -33,21 +33,21 @@ bool Reader::enterBlock(const Char* name) {
}
void Reader::exitBlock() {
assert(expectedIndent > 0);
expectedIndent -= 1;
multiLineStr.clear();
if (justOpened) moveNext(); // leave this key
assert(expected_indent > 0);
expected_indent -= 1;
multi_line_str.clear();
if (just_opened) moveNext(); // leave this key
// Dump the remainder of the block
// TODO: issue warnings?
while (indent > expectedIndent) {
while (indent > expected_indent) {
moveNext();
}
}
void Reader::moveNext() {
justOpened = false;
just_opened = false;
key.clear();
multiLineStr.clear();
multi_line_str.clear();
indent = -1; // if no line is read it never has the expected indentation
// repeat until we have a good line
while (key.empty() && !input->Eof()) {
......@@ -55,7 +55,7 @@ void Reader::moveNext() {
}
// did we reach the end of the file?
if (key.empty() && input->Eof()) {
lineNumber += 1;
line_number += 1;
indent = -1;
}
}
......@@ -70,10 +70,10 @@ void Reader::readLine() {
}
// read key / value
size_t pos = line.find_first_of(_(':'), indent);
key = trim(line.substr(indent, pos - indent));
value = pos == String::npos ? _("") : trimLeft(line.substr(pos+1));
key = cannocial_name_form(trim(line.substr(indent, pos - indent)));
value = pos == String::npos ? _("") : trim_left(line.substr(pos+1));
// we read a line
lineNumber += 1;
line_number += 1;
// was it a comment?
if (!key.empty() && key.GetChar(0) == _('#')) {
key.clear();
......@@ -83,25 +83,25 @@ void Reader::readLine() {
// ----------------------------------------------------------------------------- : Handling basic types
template <> void Reader::handle(String& s) {
if (!multiLineStr.empty()) {
s = multiLineStr;
if (!multi_line_str.empty()) {
s = multi_line_str;
} else if (value.empty()) {
// a multiline string
bool first = true;
// read all lines that are indented enough
readLine();
while (indent >= expectedIndent) {
while (indent >= expected_indent) {
if (!first) value += '\n';
first = false;
multiLineStr += line.substr(expectedIndent); // strip expected indent
multi_line_str += line.substr(expected_indent); // strip expected indent
readLine();
}
// moveNext(), but without emptying multiLineStr
justOpened = false;
just_opened = false;
while (key.empty() && !input->Eof()) {
readLine();
}
s = multiLineStr;
s = multi_line_str;
} else {
s = value;
}
......
......@@ -64,18 +64,18 @@ class Reader {
/// The key and value of the last line we read
String key, value;
/// A string spanning multiple lines
String multiLineStr;
String multi_line_str;
/// Indentation of the last line we read
int indent;
/// Indentation of the block we are in
int expectedIndent;
int expected_indent;
/// Did we just open a block (i.e. not read any more lines of it)?
bool justOpened;
bool just_opened;
/// Filename for error messages
String filename;
/// Line number for error messages
UInt lineNumber;
UInt line_number;
/// Input stream we are reading from
InputStreamP input;
/// Text stream wrapping the input stream
......
......@@ -16,7 +16,7 @@ Writer::Writer(const OutputStreamP& output)
: output(output)
, stream(*output)
, indentation(0)
, justOpened(false)
, just_opened(false)
{
stream.WriteString(BYTE_ORDER_MARK);
}
......@@ -24,25 +24,27 @@ Writer::Writer(const OutputStreamP& output)
void Writer::enterBlock(const Char* name) {
// indenting into a sub-block?
if (justOpened) {
if (just_opened) {
writeKey();
stream.WriteString(_(":\n"));
}
// don't write the key yet
indentation += 1;
openedKey = name;
justOpened = true;
opened_key = name;
just_opened = true;
}
void Writer::exitBlock() {
assert(indentation > 0);
indentation -= 1;
justOpened = false;
just_opened = false;
}
void Writer::writeKey() {
writeIndentation();
writeUTF8(stream, openedKey);
// Use ' ' instead of '_' because it is more human readable
FOR_EACH(c, opened_key) if (c == _('_')) c = _(' ');
writeUTF8(stream, opened_key);
}
void Writer::writeIndentation() {
for(int i = 1 ; i < indentation ; ++i) {
......@@ -53,7 +55,7 @@ void Writer::writeIndentation() {
// ----------------------------------------------------------------------------- : Handling basic types
void Writer::handle(const String& value) {
if (!justOpened) {
if (!just_opened) {
throw InternalError(_("Can only write a value in a key that was just opened"));
}
// write indentation and key
......@@ -86,7 +88,7 @@ void Writer::handle(const String& value) {
writeUTF8(stream, value);
}
stream.PutChar(_('\n'));
justOpened = false;
just_opened = false;
}
template <> void Writer::handle(const int& value) {
......
......@@ -53,9 +53,9 @@ class Writer {
/// Indentation of the current block
int indentation;
/// Did we just open a block (i.e. not written any lines of it)?
bool justOpened;
bool just_opened;
/// Last key opened
String openedKey;
String opened_key;
/// Output stream we are writing to
OutputStreamP output;
......@@ -69,7 +69,7 @@ class Writer {
/// Leave the block we are in
void exitBlock();
/// Write the openedKey and the required indentation
/// Write the opened_key and the required indentation
void writeKey();
/// Output some taps to represent the indentation level
void writeIndentation();
......
......@@ -52,7 +52,7 @@ String trim(const String& s){
}
}
String trimLeft(const String& s) {
String trim_left(const String& s) {
size_t start = s.find_first_not_of(_(' '));
if (start == String::npos) {
return String();
......@@ -63,7 +63,7 @@ String trimLeft(const String& s) {
// ----------------------------------------------------------------------------- : Words
String lastWord(const String& s) {
String last_word(const String& s) {
size_t endLastWord = s.find_last_not_of(_(' '));
size_t startLastWord = s.find_last_of( _(' '), endLastWord);
if (endLastWord == String::npos) {
......@@ -75,7 +75,7 @@ String lastWord(const String& s) {
}
}
String stripLastWord(const String& s) {
String strip_last_word(const String& s) {
size_t endLastWord = s.find_last_not_of(_(' '));
size_t startLastWord = s.find_last_of(_(' '), endLastWord);
if (endLastWord == String::npos || startLastWord == String::npos) {
......@@ -116,3 +116,20 @@ String capitalize(const String& s) {
}
return result;
}
String cannocial_name_form(const String& str) {
String ret;
ret.reserve(str.size());
bool leading = true;
FOR_EACH_CONST(c, str) {
if ((c == _('_') || c == _(' ')) && !leading) {
ret += _('_');
} else if (isAlnum(c)) {
ret += toLower(c);
leading = false;
} else {
// ignore non alpha numeric
}
}
return ret;
}
......@@ -52,9 +52,9 @@ typedef IF_UNICODE(wchar_t, char) Char;
String decodeUTF8BOM(const String& s);
/// UTF8 Byte order mark for writing at the start of files
/** In non-unicode builds it is UTF8 encoded \xFEFF
* In unicode builds it is a normal \xFEFF
*/
/** In non-unicode builds it is UTF8 encoded \xFEFF.
* In unicode builds it is a normal \xFEFF.
*/
const Char BYTE_ORDER_MARK[] = IF_UNICODE(L"\xFEFF", "\xEF\xBB\xBF");
/// Writes a string to an output stream, encoded as UTF8
......@@ -79,30 +79,32 @@ inline Char toLower(Char c) { return IF_UNICODE( towlower(c) , tolower(c) ); }
String trim(const String&);
/// Remove whitespace from the start of a string
String trimLeft(const String&);
String trim_left(const String&);
// ----------------------------------------------------------------------------- : Words
/// Returns the last word in a string
String lastWord(const String&);
String last_word(const String&);
/// Remove the last word from a string, leaves whitespace before that word
String stripLastWord(const String&);
String strip_last_word(const String&);
// ----------------------------------------------------------------------------- : Caseing
/// Make each word in a string start with an upper case character.
/// for use in menus
/** for use in menus */
String capitalize(const String&);
/// Make the first word in a string start with an upper case character.
/// for use in dialogs
String capitalizeSentence(const String&);
/** for use in dialogs */
String capitalize_sentence(const String&);
/// Convert a field name to cannocial form: lower case and ' ' instead of '_'
/// non alphanumeric characters are ignored
/// "camalCase" is converted to words "camel case"
String cannocialNameForm(const String&);
/// Convert a field name to cannocial form
/** - lower case and '_' instead of ' '.
* - non alphanumeric characters are droped
* - "camalCase" is converted to words "camel case" (TODO)
*/
String cannocial_name_form(const String&);
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_VERSION
#define HEADER_UTIL_VERSION
/** @file util/version.hpp
*
* @brief Utility functions related to version numbers.
* This header also stores the MSE version number.
*/
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- : Version datatype
/// A version number
struct Version {
public:
Version() : version(0) {}
Version(UInt version) : version(version) {}
bool operator < (Version v) { return version < v.versionSuffix; }
/// Convert a version number to a string
String toString();
/// Convert a string to a version number
static Version fromString(UInt version);
private:
UInt version; ///< Version number encoded as aabbcc, where a=major, b=minor, c=revision
};
// ----------------------------------------------------------------------------- : Versions
/// The verwsion number of MSE
const Version app_version = 000300; // 0.3.0
const Char* version_suffix = _(" (beta)");
/// File version, usually the same as program version,
/** When no files are changed the file version is not incremented
* Changes:
* 0.2.0 : start of version numbering practice
* 0.2.2 : _("include file")
* 0.2.6 : fix in settings loading
* 0.2.7 : new tag system, different style of close tags
* 0.3.0 : port of code to C++
*/
const Version file_version = 000300; // 0.3.0
// ----------------------------------------------------------------------------- : EOF
#endif
......@@ -214,7 +214,7 @@ COLLABORATION_GRAPH = NO
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = YES
INCLUDE_GRAPH = YES
INCLUDE_GRAPH = NO
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
......
/** @page coding_conventions Coding conventions
MSE uses the following coding style:
@code
/// Doxygen documentation
class ClassName {
public:
void someMemberFunction();
private:
int some_member; ///< postfix doxygen documentation
};
void a_global_function();
enum MyEnumeration
{ MY_SOMETHING
, MY_SOMETHING_ELSE
};
@endcode
The rules are:
- Classes use CaptializationForEachWord
- Member functions use camelCase
- Data members and globals use lower_case_with_underscores
- Constants (enumeration values) and macros are UPPER_CASE_WITH_UNDERSCORES
The exceptions to this are:
- wxWidgets functions, which LookLikeThis
- wxWidget classes, which look like wxSomeClass
- C++ standard library and boost, lower_case for everything
- Person names, in particular deCasteljau
- Class names in function names, in particular clearDC
*/
/** \mainpage
/** @mainpage
This is the documentation of the Magic Set Editor (MSE) source code, automatically generated using doxygen.
<h2>Structure</h2>
The MSE source code is subdivided into several directories, with the following meaning:
- util: Utility functions and classes, stuff that would work equally well in another project
- gfx: Graphics related functions, again mostly independent of MSE.
This directory contains algorithms for image blending, scaling, and bezier curve functions.
- data: Data structures, like sets, cards, symbols, etc.
These data structures are documented in the <a href="http://magicseteditor.sourceforge.net/extending">'Extending MSE'</a> section of the official documentation.
- data/action: Actions that can be applied to those data structures.
- gui: Graphical User Interface
- resource: Resource files used (icons, cursors, etc.)
Before starting with the source code, you should take a look at the following:
- \subpage structure "Structure of the MSE source code"
- \subpage dependencies "Libraries and dependencies"
- \subpage coding_conventions "Coding conventions"
- \subpage tricks "Tricks used by MSE"
@page structure Structure of the MSE source code
<h2>Libraries/dependencies</h2>
The MSE source code is subdivided into several directories, with the following meaning:
- <tt>util</tt>: Utility functions and classes, stuff that would work equally well in another project
- <tt>util/io</tt>: Classes related to input and output
- <tt>gfx</tt>: Graphics related functions, again mostly independent of MSE.
This directory contains algorithms for image blending, scaling, and bezier curve functions.
- <tt>data</tt>: Data structures, like sets, cards, symbols, etc.
These data structures are documented in the <a href="http://magicseteditor.sourceforge.net/extending">'Extending MSE'</a> section of the official documentation.
- <tt>data/action</tt>: Actions that can be applied to those data structures.
- <tt>data/field</tt>: Data types for fields, values and styles. One source file per type.
- <tt>data/format</tt>: File formats and import/export stuff.
- <tt>script</tt>: The scripting system.
- <tt>gui</tt>: Graphical User Interface
- <tt>set</tt>: SetWindow related
- <tt>symbol</tt>: SymbolWindow related
- <tt>resource</tt>: Resource files used (icons, cursors, etc.)
See <a href="dirs.html">the directory list</a> for details.
@page dependencies Libraries and dependencies
MSE depends on the following libraries:
- <a href="http://wxwidgets.org">wxWidgets</a> for the GUI.
......@@ -25,99 +39,4 @@ Additional tools (not needed for building MSE) also depend on:
- <a href="http://doxygen.org">doxygen</a> for generating the documentation.
- Perl for small utility scripts
<h2>Coding style</h2>
MSE uses the following coding style:
@code
class ClassName {
public:
void someFunction();
private:
int someMember;
};
@endcode
The exception to this rule are wxWidgets functions, which LookLikeThis; and classes, which look like wxSomeClass.
As well as standard library functions.
<h2>Macro and template tricks</h2>
The source code uses several macro/preprocessor and template tricks to make the code more readable.
<h3>Smart pointers</h3>
MSE makes extensive use of boost::shared_ptr. To make the code more readable there are typedefs for these pointer types, using a suffix P.
These are defined using a macro:
@code
DECLARE_POINTER_TYPE(MyClass);
MyClassP someObject; // the same as boost::shared_ptr<MyClass> someObject
@endcode
To create new shared_ptrs the function new_shared# can be used (where # is the number of arguments):
@code
MyClassP someObject;
someObject = new_shared2<MyClass>(arg1, arg2);
@endcode
Implemented in: util/smart_ptr.hpp
<h3>Iterating</h3>
To iterate over containers the FOR_EACH macro is used:
@code
vector<CardP> cards;
FOR_EACH(card, cards) {
doSomething(card);
}
@endcode
Is equivalent to:
@code
vector<CardP> cards;
for(vector<CardP>::iterator it = cards.begin() ; it != cards.end() ; ++it) {
CardP& card = *it;
doSomething(card);
}
@endcode
The iterators are completely hidden!
There are several veriations to this macro, for using const iterators (FOR_EACH_CONST), iterating in reverse (FOR_EACH_REVERSE),
for iterating over two collections in parallel (FOR_EACH_2), and for getting access to the iterator (FOR_EACH_IT).
Each of these macros require that the collection type has been declared using:
@code
DECLARE_COLLECTION_TYPE(CardP);
@endcode
This allows the calling of TYPEOF(cards) to evaluate to vector<CardP>.
Implemented in: util/for_each.hpp
<h3>Reflection</h3>
The io (input/output) system is based on reflection.
For a class to support reflection the following must be declared:
@code
class SomeClass {
int member1, member2;
DECLARE_REFLECTION();
};
@endcode
Then in a source file the members of the class have to be specified:
@code
IMPLEMENT_REFLECTION(SomeClass) {
REFLECT(member1);
REFLECT_N("another_name", member2);
}
@endcode
Simlairly for enumerations (a declaration is not necessary):
@code
IMPLEMENT_REFLECTION_ENUM(MyEnum) {
VALUE(value_of_enum_1); // the default value
VALUE(value_of_enum_2);
}
@endcode
Implemented in: util/reflect.hpp
*/
\ No newline at end of file
/** @page tricks Macro and template tricks
The source code uses several macro/preprocessor and template tricks to make the code more readable.
<h2>Smart pointers</h2>
MSE makes extensive use of boost::shared_ptr. To make the code more readable there are typedefs for these pointer types, using a suffix P.
These are defined using a macro:
@code
DECLARE_POINTER_TYPE(MyClass);
MyClassP someObject; // the same as boost::shared_ptr<MyClass> someObject
@endcode
To create new shared_ptrs the function new_shared# can be used (where # is the number of arguments):
@code
MyClassP someObject;
someObject = new_shared2<MyClass>(arg1, arg2);
@endcode
Implemented in: util/smart_ptr.hpp
<h2>Iterating</h2>
To iterate over containers the FOR_EACH macro is used:
@code
vector<CardP> cards;
FOR_EACH(card, cards) {
doSomething(card);
}
@endcode
Is equivalent to:
@code
vector<CardP> cards;
for(vector<CardP>::iterator it = cards.begin() ; it != cards.end() ; ++it) {
CardP& card = *it;
doSomething(card);
}
@endcode
The iterators are completely hidden!
There are several veriations to this macro, for using const iterators (FOR_EACH_CONST), iterating in reverse (FOR_EACH_REVERSE),
for iterating over two collections in parallel (FOR_EACH_2), and for getting access to the iterator (FOR_EACH_IT).
Each of these macros require that the collection type has been declared using:
@code
DECLARE_COLLECTION_TYPE(CardP);
@endcode
This allows the calling of TYPEOF(cards) to evaluate to vector<CardP>.
Implemented in: util/for_each.hpp
<h2>Reflection</h2>
The io (input/output) system is based on reflection.
For a class to support reflection the following must be declared:
@code
class SomeClass {
int member1, member2;
DECLARE_REFLECTION();
};
@endcode
Then in a source file the members of the class have to be specified:
@code
IMPLEMENT_REFLECTION(SomeClass) {
REFLECT(member1);
REFLECT_N("another_name", member2);
}
@endcode
Simlairly for enumerations (a declaration is not necessary):
@code
IMPLEMENT_REFLECTION_ENUM(MyEnum) {
VALUE_N("value1", MY_VALUE1); // the first is the default value
VALUE_N("value2", MY_VALUE2);
}
@endcode
Reflection is used by the following classes:
- Reader
- Writer
- GetMember
Implemented in: util/reflect.hpp
*/
\ No newline at end of file
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