mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Localisation, using Locale class
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@113 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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 <gui/control/text_ctrl.hpp>
|
||||
#include <gui/value/editor.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/field/text.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(ValueViewerP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextCtrl
|
||||
|
||||
TextCtrl::TextCtrl(Window* parent, int id, long style)
|
||||
: DataEditor(parent, id, style)
|
||||
, value(nullptr)
|
||||
{}
|
||||
|
||||
Rotation TextCtrl::getRotation() const {
|
||||
return Rotation(0, RealRect(RealPoint(0,0),GetClientSize()));
|
||||
}
|
||||
|
||||
void TextCtrl::draw(DC& dc) {
|
||||
RotatedDC rdc(dc, getRotation(), false);
|
||||
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
|
||||
}
|
||||
void TextCtrl::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
// draw background
|
||||
Style& s = *v.getStyle();
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
dc.DrawRectangle(s.getRect().grow(1));
|
||||
// draw viewer
|
||||
v.draw(dc);
|
||||
}
|
||||
|
||||
|
||||
void TextCtrl::setValue(String* value) {
|
||||
this->value = value;
|
||||
if (viewers.empty() && value) {
|
||||
// create a field, style and value
|
||||
TextFieldP field(new TextField);
|
||||
TextStyleP style(new TextStyle(field));
|
||||
TextValueP value(new TextValue(field));
|
||||
// set stuff
|
||||
field->index = 0;
|
||||
style->width = 100;
|
||||
style->height = 20;
|
||||
style->left = style->top = 1;
|
||||
value->value.assign(*this->value);
|
||||
// assign to this control
|
||||
IndexMap<FieldP,StyleP> styles; styles.add(field, style);
|
||||
IndexMap<FieldP,ValueP> values; values.add(field, value);
|
||||
setStyles(styles);
|
||||
setData(values);
|
||||
// determine required height
|
||||
viewers.front()->getEditor()->determineSize();
|
||||
SetMinSize(wxSize(style->width + 6, style->height + 6));
|
||||
}
|
||||
valueChanged();
|
||||
}
|
||||
void TextCtrl::valueChanged() {
|
||||
if (!viewers.empty()) {
|
||||
TextValue& tv = static_cast<TextValue&>(*viewers.front()->getValue());
|
||||
tv.value.assign(value ? *value : wxEmptyString);
|
||||
viewers.front()->onValueChange();
|
||||
}
|
||||
onChange();
|
||||
}
|
||||
void TextCtrl::onAction(const Action& action, bool undone) {
|
||||
DataEditor::onAction(action, undone);
|
||||
TYPE_CASE(action, TextValueAction) {
|
||||
TextValue& tv = static_cast<TextValue&>(*viewers.front()->getValue());
|
||||
if (&tv == action.valueP.get()) {
|
||||
// the value has changed
|
||||
if (value) *value = tv.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
void TextCtrl::onChangeSet() {
|
||||
DataEditor::onChangeSet();
|
||||
setValue(nullptr);
|
||||
}
|
||||
|
||||
void TextCtrl::onInit() {
|
||||
// Give viewers a chance to show/hide controls (scrollbar) when selecting other editors
|
||||
FOR_EACH_EDITOR {
|
||||
e->onShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TextCtrl::onSize(wxSizeEvent&) {
|
||||
if (!viewers.empty()) {
|
||||
wxSize cs = GetClientSize();
|
||||
Style& style = *viewers.front()->getStyle();
|
||||
style.width = cs.GetWidth() - 2;
|
||||
style.height = cs.GetHeight() - 2;
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(TextCtrl, DataEditor)
|
||||
EVT_SIZE (TextCtrl::onSize)
|
||||
END_EVENT_TABLE()
|
||||
@@ -0,0 +1,60 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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_GUI_CONTROL_TEXT_CTRL
|
||||
#define HEADER_GUI_CONTROL_TEXT_CTRL
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/card_editor.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextCtrl
|
||||
|
||||
/// A control for editing a String
|
||||
/** Implemented using a DataEditor. A fake Field and Value are created for the item.
|
||||
*
|
||||
* TODO:
|
||||
* Possible problem: If multiple TextCtrls are editing the same value they will both
|
||||
* create a Value, actions modifying one of them will not match with actions modifying the other
|
||||
* Possible solution: 1. Global map of Values
|
||||
* 2. Ignore the problem, it will not happen in practice
|
||||
*/
|
||||
class TextCtrl : public DataEditor {
|
||||
public:
|
||||
TextCtrl(Window* parent, int id, long style = 0);
|
||||
|
||||
/// Set the value that is being edited
|
||||
void setValue(String* value);
|
||||
/// Notification that the value has changed outside this control
|
||||
void valueChanged();
|
||||
|
||||
/// Uses a native look
|
||||
virtual bool nativeLook() const { return true; }
|
||||
virtual bool drawBorders() const { return false; }
|
||||
virtual Rotation getRotation() const;
|
||||
|
||||
virtual void draw(DC& dc);
|
||||
virtual void drawViewer(RotatedDC& dc, ValueViewer& v);
|
||||
|
||||
/// When an action is received, change the underlying value
|
||||
virtual void onAction(const Action&, bool undone);
|
||||
virtual void onChangeSet();
|
||||
|
||||
protected:
|
||||
virtual void onInit();
|
||||
|
||||
private:
|
||||
String* value; ///< Value to edit
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
void onSize(wxSizeEvent&);
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -35,7 +35,7 @@ CardsPanel::CardsPanel(Window* parent, int id)
|
||||
notes = new TextCtrl(notesP, ID_NOTES);
|
||||
// init sizer for notes panel
|
||||
wxSizer* sn = new wxBoxSizer(wxVERTICAL);
|
||||
sn->Add(new wxStaticText(notesP, wxID_ANY, _("Card notes:")), 0, wxEXPAND, 2);
|
||||
sn->Add(new wxStaticText(notesP, wxID_ANY, _LABEL_("card notes")), 0, wxEXPAND, 2);
|
||||
sn->Add(notes, 1, wxEXPAND | wxTOP, 2);
|
||||
notesP->SetSizer(sn);
|
||||
// init splitter
|
||||
@@ -68,15 +68,15 @@ void CardsPanel::onChangeSet() {
|
||||
|
||||
void CardsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
// Toolbar
|
||||
tb->AddTool(ID_FORMAT_BOLD, _(""), Bitmap(_("TOOL_BOLD")), wxNullBitmap, wxITEM_CHECK, _("Bold"));
|
||||
tb->AddTool(ID_FORMAT_ITALIC, _(""), Bitmap(_("TOOL_ITALIC")), wxNullBitmap, wxITEM_CHECK, _("Italic"));
|
||||
tb->AddTool(ID_FORMAT_SYMBOL, _(""), Bitmap(_("TOOL_SYMBOL")), wxNullBitmap, wxITEM_CHECK, _("Symbols"));
|
||||
tb->AddTool(ID_FORMAT_REMINDER, _(""), Bitmap(_("TOOL_REMINDER")), wxNullBitmap, wxITEM_CHECK, _("Reminder Text"));
|
||||
tb->AddTool(ID_FORMAT_BOLD, _(""), Bitmap(_("TOOL_BOLD")), wxNullBitmap, wxITEM_CHECK, _TOOL_("bold"));
|
||||
tb->AddTool(ID_FORMAT_ITALIC, _(""), Bitmap(_("TOOL_ITALIC")), wxNullBitmap, wxITEM_CHECK, _TOOL_("italic"));
|
||||
tb->AddTool(ID_FORMAT_SYMBOL, _(""), Bitmap(_("TOOL_SYMBOL")), wxNullBitmap, wxITEM_CHECK, _TOOL_("symbols"));
|
||||
tb->AddTool(ID_FORMAT_REMINDER, _(""), Bitmap(_("TOOL_REMINDER")), wxNullBitmap, wxITEM_CHECK, _TOOL_("reminder text"));
|
||||
tb->AddSeparator();
|
||||
tb->AddTool(ID_CARD_ADD, _(""), Bitmap(_("TOOL_CARD_ADD")), wxNullBitmap, wxITEM_NORMAL,_("Add card"));
|
||||
tb->AddTool(ID_CARD_REMOVE, _(""), Bitmap(_("TOOL_CARD_DEl")), wxNullBitmap, wxITEM_NORMAL,_("Remove selected card"));
|
||||
tb->AddTool(ID_CARD_ADD, _(""), Bitmap(_("TOOL_CARD_ADD")), wxNullBitmap, wxITEM_NORMAL,_TOOL_("add card"));
|
||||
tb->AddTool(ID_CARD_REMOVE, _(""), Bitmap(_("TOOL_CARD_DEl")), wxNullBitmap, wxITEM_NORMAL,_TOOL_("remove card"));
|
||||
tb->AddSeparator();
|
||||
tb->AddTool(ID_CARD_ROTATE, _(""), Bitmap(_("TOOL_CARD_ROTATE")),wxNullBitmap,wxITEM_NORMAL,_("Rotate card"));
|
||||
tb->AddTool(ID_CARD_ROTATE, _(""), Bitmap(_("TOOL_CARD_ROTATE")),wxNullBitmap,wxITEM_NORMAL,_TOOL_("rotate card"));
|
||||
tb->Realize();
|
||||
// Menus
|
||||
IconMenu* menuCard = new IconMenu();
|
||||
|
||||
@@ -64,7 +64,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
||||
// recent files go here
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append(ID_FILE_EXIT, _("E&xit\tAlt+F4"), _("Quits Magic Set Editor; prompts to save the set"));
|
||||
menuBar->Append(menuFile, _("&File"));
|
||||
menuBar->Append(menuFile, _MENU_("file"));
|
||||
|
||||
IconMenu* menuEdit = new IconMenu();
|
||||
menuEdit->Append(ID_EDIT_UNDO, _("TOOL_UNDO"), _("&Undo\tCtrl+Z"), _("Undoes the last action"));
|
||||
|
||||
+3
-3
@@ -76,13 +76,13 @@ Image load_resource_image(const String& name) {
|
||||
// based on wxLoadUserResource
|
||||
// The image can be in an IMAGE resource, in any file format
|
||||
HRSRC hResource = ::FindResource(wxGetInstance(), name, _("IMAGE"));
|
||||
if ( hResource == 0 ) throw InternalError(_("Resource not found: ") + name);
|
||||
if ( hResource == 0 ) throw InternalError(String::Format(_("Resource not found: %s"), name));
|
||||
|
||||
HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
|
||||
if ( hData == 0 ) throw InternalError(_("Resource not an image: ") + name);
|
||||
if ( hData == 0 ) throw InternalError(String::Format(_("Resource not an image: %s"), name));
|
||||
|
||||
char* data = (char *)::LockResource(hData);
|
||||
if ( !data ) throw InternalError(_("Resource cannot be locked: ") + name);
|
||||
if ( !data ) throw InternalError(String::Format(_("Resource cannot be locked: %s"), name));
|
||||
|
||||
int len = ::SizeofResource(wxGetInstance(), hResource);
|
||||
wxMemoryInputStream stream(data, len);
|
||||
|
||||
Reference in New Issue
Block a user