Implemented selection using rectangles in symbol editor

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@535 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-07-09 21:19:59 +00:00
parent b409188013
commit c7d31ddb4a
8 changed files with 479 additions and 11 deletions
+81
View File
@@ -0,0 +1,81 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2007 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_GUI_SYMBOL_SELECTION
#define HEADER_GUI_SYMBOL_SELECTION
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
class Vector2D;
DECLARE_POINTER_TYPE(Symbol);
DECLARE_POINTER_TYPE(SymbolPart);
DECLARE_POINTER_TYPE(SymbolShape);
class SymbolGroup;
// ----------------------------------------------------------------------------- : Selection
enum SelectMode
{ SELECT_OVERRIDE // give a completely new selection
, SELECT_IF_OUTSIDE // define a new selection if the affected part is not already selected
, SELECT_TOGGLE // toggle selection of affected part
};
/// The selected parts of a symbol, enforcing constraints
class SymbolPartsSelection {
public:
inline SymbolPartsSelection() : root(nullptr) {}
void setSymbol(const SymbolP& symbol);
/// Clear selection
void clear();
/// Select a part or toggle its selection
/** Return true if the selection changed */
bool select(const SymbolPartP& part, SelectMode mode = SELECT_OVERRIDE);
/// Toggle the selection of the parts in a rectangle (a,b) or (a,c) but not in both
/** Return true if the selection changed */
bool selectRect(const Vector2D& a, const Vector2D& b, const Vector2D& c);
/// Find a part by position (not just in the selection!)
/** Returns SymbolPartP() if nothing is found.
* Does not select inside groups unless the part in question is already selected.
*/
SymbolPartP find(const Vector2D& position) const;
/// Get the selection
inline const set<SymbolPartP>& get() const { return selection; }
/// Is the selection empty?
inline bool empty() const { return selection.empty(); }
/// Number of items selected
inline size_t size() const { return selection.size(); }
/// Is a part selected?
inline bool selected(const SymbolPartP& part) const {
return selection.find(part) != selection.end();
}
/// Get any SymbolShape if there is one selected
SymbolShapeP getAShape() const;
private:
Symbol* root;
set<SymbolPartP> selection;
/// Find a part, in some root
SymbolPartP find(const SymbolPartP& part, const Vector2D& pos) const;
/// Select rect for some parent
bool selectRect(const SymbolGroup& parent, const Vector2D& a, const Vector2D& b, const Vector2D& c);
/// Make sure not both a parent and its child/decendant are selected
void clearChildren (SymbolPart* part);
/// Is a part another's ancestor?
static bool isAncestor(SymbolPart* ancestor, SymbolPart* part);
};
// ----------------------------------------------------------------------------- : EOF
#endif