Implemented CardList

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@23 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-10-18 17:48:14 +00:00
parent 7504e0540f
commit 29d072e949
29 changed files with 762 additions and 63 deletions
+22
View File
@@ -11,6 +11,28 @@
// ----------------------------------------------------------------------------- : Alignment
double align_delta_x(Alignment align, double box_width, double obj_width) {
if (align & ALIGN_CENTER) return (box_width - obj_width) / 2;
else if (align & ALIGN_RIGHT) return box_width - obj_width;
else return 0;
}
double align_delta_y(Alignment align, double box_height, double obj_height) {
if (align & ALIGN_MIDDLE) return (box_height - obj_height) / 2;
else if (align & ALIGN_BOTTOM) return box_height - obj_height;
else return 0;
}
RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRect& outer) {
return RealPoint(
outer.position.x + align_delta_x(align, outer.size.width, to_align.width),
outer.position.y + align_delta_y(align, outer.size.height, to_align.height)
);
}
// ----------------------------------------------------------------------------- : Reflection stuff
/// Convert a String to an Alignment
Alignment fromString(const String& str) {
int al = 0;
+3 -2
View File
@@ -32,7 +32,8 @@ enum Alignment
, ALIGN_JUSTIFY_OVERFLOW = 0x1000
, ALIGN_STRETCH = 0x2000
// common combinations
, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT
, ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT
, ALIGN_MIDDLE_CENTER = ALIGN_MIDDLE | ALIGN_CENTER
};
@@ -40,7 +41,7 @@ enum Alignment
double align_delta_x(Alignment align, double box_width, double obj_width);
/// How much should an object with obj_height be moved to be aligned in a box with box_height?
double align_delta_t(Alignment align, double box_height, double obj_height);
double align_delta_y(Alignment align, double box_height, double obj_height);
/// Align a rectangle inside another rectangle
/** returns the topleft coordinates of the inner rectangle after alignment
+7
View File
@@ -185,6 +185,13 @@
FOR_EACH_2_T(TYPEOF_IT(Collection1), TYPEOF_REF(Collection1), Elem1, Collection1, \
TYPEOF_IT(Collection2), TYPEOF_REF(Collection2), Elem2, Collection2)
/// Iterate over two constants collections in parallel, their type must be declared with DECLARE_TYPEOF.
/** Usage: FOR_EACH_2_CONST(e1,collect1, e2,collect2) { body-of-loop }
*/
#define FOR_EACH_2_CONST(Elem1,Collection1, Elem2,Collection2) \
FOR_EACH_2_T(TYPEOF_CIT(Collection1), TYPEOF_CREF(Collection1), Elem1, Collection1, \
TYPEOF_CIT(Collection2), TYPEOF_CREF(Collection2), Elem2, Collection2)
// ----------------------------------------------------------------------------- : EOF
#endif
+6
View File
@@ -50,9 +50,15 @@ String Package::name() const {
else if ( ext == String::npos) return filename.substr(slash+1);
else return filename.substr(slash+1, ext-slash-1);
}
String Package::fullName() const {
return name();
}
const String& Package::absoluteFilename() const {
return filename;
}
InputStreamP Package::openIconFile() {
return InputStreamP();
}
void Package::open(const String& n) {
+5
View File
@@ -51,9 +51,14 @@ class Package {
bool needSaveAs() const;
/// Determines the short name of this package: the filename without path or extension
String name() const;
/// Return the full name of this package, by default equal to name()
virtual String fullName() const;
/// Return the absolute filename of this file
const String& absoluteFilename() const;
/// Get an input stream for the package icon, if there is any
virtual InputStreamP openIconFile();
/// Open a package, should only be called when the package is constructed using the default constructor!
/// @pre open not called before [TODO]
void open(const String& package);
+29 -1
View File
@@ -8,11 +8,12 @@
#include <util/io/package_manager.hpp>
#include <util/error.hpp>
#include <data/game.hpp>
// ----------------------------------------------------------------------------- : PackageManager
String program_dir() {
return _("."); //TODO
return wxGetCwd(); //TODO
}
PackageManager packages;
@@ -36,6 +37,33 @@ PackageManager::PackageManager() {
data_directory += _("/data");
}
PackagedP PackageManager::openAny(const String& name) {
wxFileName fn(data_directory + _("/") + name);
fn.Normalize();
String filename = fn.GetFullPath();
// Is this package already loaded?
PackagedP& p = loaded_packages[filename];
if (p) {
return p;
} else {
// load with the right type, based on extension
if (fn.GetExt() == _("mse-game")) p = new_shared<Game>();
// else if (fn.GetExt() == _("mse-style")) p = new_shared<CardStyle>();
// else if (fn.GetExt() == _("mse-locale")) p = new_shared<Locale>();
// else if (fn.GetExt() == _("mse-include")) p = new_shared<IncludePackage>();
// else if (fn.GetExt() == _("mse-symbol-font")) p = new_shared<SymbolFont>();
else {
throw PackageError(_("Unrecognized package type: ") + fn.GetExt());
}
p->open(filename);
return p;
}
}
String PackageManager::findFirst(const String& pattern) {
return wxFindFirstFile(data_directory + _("/") + pattern, 0);
}
void PackageManager::destroy() {
loaded_packages.clear();
}
+8 -3
View File
@@ -44,9 +44,14 @@ class PackageManager {
}
}
/// Open a package with the specified name
/// the type of package is determined by its extension!
PackagedP openAnyPackage(const String& filename);
/// Open a package with the specified name, the type of package is determined by its extension!
PackagedP openAny(const String& name);
/// Find a package whos name matches a pattern
/** Find more using wxFindNextFile().
* If no package is found returns an empty string.
*/
String findFirst(const String& pattern);
/// Empty the list of packages.
/** This function MUST be called before the program terminates, otherwise
+39
View File
@@ -61,6 +61,45 @@ String trim_left(const String& s) {
}
}
bool smart_less(const String& as, const String& bs) {
bool in_num = false; // are we inside a number?
bool lt = false; // is as less than bs?
bool eq = true; // so far is everything equal?
FOR_EACH_2_CONST(a, as, b, bs) {
bool na = isDigit(a), nb = isDigit(b);
Char la = toLower(a), lb = toLower(b);
if (na && nb) {
// compare numbers
in_num = true;
if (eq && a != b) {
eq = false;
lt = a < b;
}
} else if (in_num && na) {
// comparing numbers, one is longer, therefore it is greater
return false;
} else if (in_num && nb) {
return true;
} else if (in_num && !eq) {
// two numbers of the same length, but not equal
return lt;
} else {
// compare characters
if (la < lb) return true;
if (la > lb) return false;
}
in_num = na && nb;
}
// When we are at the end; shorter strings come first
// This is true for normal string collation
// and also when both end in a number and another digit follows
if (as.size() != bs.size()) {
return as.size() < bs.size();
} else {
return lt;
}
}
// ----------------------------------------------------------------------------- : Words
String last_word(const String& s) {
+7
View File
@@ -81,6 +81,13 @@ String trim(const String&);
/// Remove whitespace from the start of a string
String trim_left(const String&);
/// Compare two strings, is the first less than the first?
/** Uses a smart comparison algorithm that understands numbers.
* The comparison is case insensitive.
* Doesn't handle leading zeros.
*/
bool smart_less(const String&, const String&);
// ----------------------------------------------------------------------------- : Words
/// Returns the last word in a string
+3
View File
@@ -130,6 +130,9 @@ enum ChildMenuID {
, ID_SHAPE_STAR
, ID_SHAPE_MAX
, ID_SIDES
// CardList
, ID_SELECT_COLUMNS = 3001
};