- Added 'package list' field type

- Some refactoring of the other field types

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@790 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-12-26 23:37:45 +00:00
parent 7b340db04f
commit d493394519
32 changed files with 573 additions and 94 deletions
+1 -24
View File
@@ -6,29 +6,6 @@
// ----------------------------------------------------------------------------- : Includes
#include <gui/value/editor.hpp>
#include <gui/value/text.hpp>
#include <gui/value/choice.hpp>
#include <gui/value/multiple_choice.hpp>
#include <gui/value/image.hpp>
#include <gui/value/symbol.hpp>
#include <gui/value/color.hpp>
#include <gui/value/information.hpp>
//#include <gui/value/editor.hpp>
// ----------------------------------------------------------------------------- : ValueEditor
// ----------------------------------------------------------------------------- : Type dispatch
#define IMPLEMENT_MAKE_EDITOR(Type) \
ValueViewerP Type##Style::makeEditor(DataEditor& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueEditor(parent, static_pointer_cast<Type##Style>(thisP))); \
}
IMPLEMENT_MAKE_EDITOR(Text);
IMPLEMENT_MAKE_EDITOR(Choice);
IMPLEMENT_MAKE_EDITOR(MultipleChoice);
IMPLEMENT_MAKE_EDITOR(Color);
IMPLEMENT_MAKE_EDITOR(Image);
IMPLEMENT_MAKE_EDITOR(Symbol);
IMPLEMENT_MAKE_EDITOR(Info);
+4
View File
@@ -147,6 +147,10 @@ class ValueEditor {
void Type##ValueEditor::redraw() { \
editor().redraw(*this); \
} \
ValueViewerP Type##Style::makeEditor(DataEditor& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueEditor(parent, static_pointer_cast<Type##Style>(thisP))); \
} \
Type##ValueEditor::Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
: Type##ValueViewer(parent, style)
+119
View File
@@ -0,0 +1,119 @@
//+----------------------------------------------------------------------------+
//| 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) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <gui/value/package_choice.hpp>
#include <gui/drop_down_list.hpp>
#include <gui/util.hpp>
#include <data/action/value.hpp>
DECLARE_TYPEOF_COLLECTION(PackageChoiceValueViewer::Item);
// ----------------------------------------------------------------------------- : DropDownPackageChoiceList
/// A drop down list of color choices
class DropDownPackageChoiceList : public DropDownList {
public:
DropDownPackageChoiceList(Window* parent, PackageChoiceValueEditor* editor);
protected:
virtual size_t itemCount() const;
virtual String itemText(size_t item) const;
virtual bool lineBelow(size_t item) const;
virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const;
virtual void select(size_t selection);
virtual size_t selection() const;
private:
PackageChoiceValueEditor& editor;
};
DropDownPackageChoiceList::DropDownPackageChoiceList(Window* parent, PackageChoiceValueEditor* editor)
: DropDownList(parent, false, editor)
, editor(*editor)
{
icon_size.width = 16;
icon_size.height = 16;
item_size.height = max(16., item_size.height);
}
size_t DropDownPackageChoiceList::itemCount() const {
return editor.items.size() + (editor.field().required ? 0 : 1);
}
String DropDownPackageChoiceList::itemText(size_t item) const {
if (item == 0 && !editor.field().required) return _("");
else {
size_t i = item - !editor.field().required;
return editor.items[i].name;
}
}
bool DropDownPackageChoiceList::lineBelow(size_t item) const {
return item == 0 && !editor.field().required;
}
void DropDownPackageChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const {
if (item == 0 && !editor.field().required) return;
size_t i = item - !editor.field().required;
const Bitmap& bmp = editor.items[i].image;
if (bmp.Ok()) dc.DrawBitmap(bmp, x, y);
}
void DropDownPackageChoiceList::select(size_t item) {
String new_value;
if (item != 0 || editor.field().required) {
size_t i = item - !editor.field().required;
new_value = editor.items[i].package_name;
}
editor.change(new_value);
}
size_t DropDownPackageChoiceList::selection() const {
size_t n = 0;
FOR_EACH(i, editor.items) {
if (editor.value().package_name == i.package_name) {
return n + !editor.field().required;
}
++n;
}
return editor.field().required ? NO_SELECTION : 0;
}
// ----------------------------------------------------------------------------- : PackageChoiceValueEditor
IMPLEMENT_VALUE_EDITOR(PackageChoice) {}
bool PackageChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
if (!drop_down) initDropDown();
return drop_down->onMouseInParent(ev, false);
}
bool PackageChoiceValueEditor::onChar(wxKeyEvent& ev) {
if (!drop_down) initDropDown();
return drop_down->onCharInParent(ev);
}
void PackageChoiceValueEditor::onLoseFocus() {
if (drop_down) drop_down->hide(false);
}
void PackageChoiceValueEditor::draw(RotatedDC& dc) {
PackageChoiceValueViewer::draw(dc);
if (nativeLook()) {
draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectStraight(style().getInternalRect().grow(1)), drop_down && drop_down->IsShown());
}
}
void PackageChoiceValueEditor::determineSize(bool) {
style().height = max(style().height(), 16.);
}
void PackageChoiceValueEditor::change(const String& c) {
perform(value_action(card(), valueP(), c));
}
void PackageChoiceValueEditor::initDropDown() {
if (drop_down) return;
drop_down = new_shared2<DropDownPackageChoiceList>(&editor(), this);
}
+42
View File
@@ -0,0 +1,42 @@
//+----------------------------------------------------------------------------+
//| 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_VALUE_PACKAGE_CHOICE
#define HEADER_GUI_VALUE_PACKAGE_CHOICE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <gui/value/editor.hpp>
#include <render/value/package_choice.hpp>
DECLARE_SHARED_POINTER_TYPE(DropDownList);
// ----------------------------------------------------------------------------- : PackageChoiceValueEditor
/// An editor 'control' for editing PackageChoiceValues
class PackageChoiceValueEditor : public PackageChoiceValueViewer, public ValueEditor {
public:
DECLARE_VALUE_EDITOR(PackageChoice);
virtual void draw(RotatedDC& dc);
virtual void determineSize(bool force_fit);
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent& ev);
virtual bool onChar(wxKeyEvent& ev);
virtual void onLoseFocus();
private:
DropDownListP drop_down;
friend class DropDownPackageChoiceList;
/// Change the choice
void change(const String& c);
/// Initialize the drop down list
void initDropDown();
};
// ----------------------------------------------------------------------------- : EOF
#endif