Fixed TextCtrl to work for keyword properties;

Added wrapping of <> around parameters to TextElement;
Added colors for keyword parameters;
Added menu & toolbar for keyword panel;
Fixed bug in package, save/save-as was the wrong way around;
Added third quality setting to RotatedDC: using SetUserScale, this gets you more precise positioning.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@250 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-04-12 17:35:00 +00:00
parent 1fc7e57b91
commit 42ab8c84c0
36 changed files with 468 additions and 116 deletions
+11
View File
@@ -13,6 +13,7 @@
#include <gui/control/card_viewer.hpp>
class ValueEditor;
class FindInfo;
// ----------------------------------------------------------------------------- : DataEditor
@@ -58,6 +59,16 @@ class DataEditor : public CardViewer {
/// A menu item from getMenu was selected
void onCommand(int id);
// --------------------------------------------------- : Search/replace
/// Do a search or replace action for the given FindInfo
/** If from_start == false: searches only from the current selection onward (or backward)
* If from_start == true: searches everything
*
* Returns true when more searching is needed.
*/
bool search(FindInfo& find, bool from_start);
// --------------------------------------------------- : ValueViewers
protected:
+1 -1
View File
@@ -246,7 +246,7 @@ void GraphControl::setData(const GraphDataP& data) {
void GraphControl::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this);
wxSize cs = GetClientSize();
RotatedDC rdc(dc, 0, RealRect(RealPoint(0,0),cs), 1, false);
RotatedDC rdc(dc, 0, RealRect(RealPoint(0,0),cs), 1, QUALITY_LOW);
rdc.SetPen(*wxTRANSPARENT_PEN);
rdc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
rdc.DrawRectangle(rdc.getInternalRect());
+1 -1
View File
@@ -26,7 +26,7 @@ Rotation NativeLookEditor::getRotation() const {
}
void NativeLookEditor::draw(DC& dc) {
RotatedDC rdc(dc, getRotation(), false);
RotatedDC rdc(dc, getRotation(), QUALITY_LOW);
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
}
void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
+59 -40
View File
@@ -16,9 +16,10 @@ DECLARE_TYPEOF_COLLECTION(ValueViewerP);
// ----------------------------------------------------------------------------- : TextCtrl
TextCtrl::TextCtrl(Window* parent, int id, long style)
TextCtrl::TextCtrl(Window* parent, int id, bool multi_line, long style)
: DataEditor(parent, id, style)
, value(nullptr)
, multi_line(multi_line)
{}
Rotation TextCtrl::getRotation() const {
@@ -26,44 +27,37 @@ Rotation TextCtrl::getRotation() const {
}
void TextCtrl::draw(DC& dc) {
RotatedDC rdc(dc, getRotation(), false);
RotatedDC rdc(dc, getRotation(), QUALITY_LOW);
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
}
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 FakeTextValue(field, this->value));
// set stuff
field->index = 0;
field->multi_line = true;
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(set->stylesheet, styles);
setData(values);
// determine size
wxSize cs = GetClientSize();
style->width = cs.GetWidth() - 2;
style->height = cs.GetHeight() - 2;
viewers.front()->getEditor()->determineSize(true);
// We don't wan to change the window size
//SetMinSize(RealSize(style->width + 6, style->height + 6));
} else if (value) {
TextStyle& TextCtrl::getStyle() {
assert(!viewers.empty());
return static_cast<TextStyle&>(*viewers.front()->getStyle());
}
TextField& TextCtrl::getField() {
assert(!viewers.empty());
return static_cast<TextField&>(*viewers.front()->getField());
}
void TextCtrl::updateSize() {
wxSize cs = GetClientSize();
Style& style = getStyle();
style.width = cs.GetWidth() - 2;
style.height = cs.GetHeight() - 2;
viewers.front()->getEditor()->determineSize(true);
}
void TextCtrl::setValue(String* value, bool untagged) {
if (value != this->value) {
this->value = value;
// create a new value, for a different underlying actual value
ValueViewer& viewer = *viewers.front();
TextValueP new_value(new FakeTextValue(static_pointer_cast<TextField>(viewer.getField()), this->value));
ValueViewer& viewer = *viewers.front();
TextValueP new_value(new FakeTextValue(static_pointer_cast<TextField>(viewer.getField()), this->value, untagged));
viewer.setValue(new_value);
updateSize();
valueChanged();
}
valueChanged();
}
void TextCtrl::valueChanged() {
if (!viewers.empty()) {
@@ -87,7 +81,29 @@ void TextCtrl::onAction(const Action& action, bool undone) {
}
void TextCtrl::onChangeSet() {
DataEditor::onChangeSet();
setValue(nullptr);
// initialize
if (viewers.empty()) {
// create a field, style and value
TextFieldP field(new TextField);
TextStyleP style(new TextStyle(field));
TextValueP value(new FakeTextValue(field, nullptr, false));
// set stuff
field->index = 0;
field->multi_line = multi_line;
style->width = 100;
style->height = 20;
style->left = style->top = 1;
style->font.color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
// assign to this control
IndexMap<FieldP,StyleP> styles; styles.add(field, style);
IndexMap<FieldP,ValueP> values; values.add(field, value);
setStyles(set->stylesheet, styles);
setData(values);
updateSize();
onChange();
} else {
setValue(nullptr);
}
}
void TextCtrl::onInit() {
@@ -99,16 +115,19 @@ void TextCtrl::onInit() {
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;
viewers.front()->getEditor()->determineSize(true);
updateSize();
onChange();
}
onChange();
}
wxSize TextCtrl::DoGetBestSize() const {
return wxSize(1,1);
if (multi_line || viewers.empty()) {
// flexible size
return wxSize(1,1);
} else {
wxSize ws = GetSize(), cs = GetClientSize();
Style& style = *viewers.front()->getStyle();
return wxSize(style.width, style.height) + ws - cs;
}
}
BEGIN_EVENT_TABLE(TextCtrl, DataEditor)
+14 -3
View File
@@ -12,6 +12,9 @@
#include <util/prec.hpp>
#include <gui/control/card_editor.hpp>
class TextField;
class TextStyle;
// ----------------------------------------------------------------------------- : TextCtrl
/// A control for editing a String
@@ -25,13 +28,20 @@
*/
class TextCtrl : public DataEditor {
public:
TextCtrl(Window* parent, int id, long style = 0);
TextCtrl(Window* parent, int id, bool multi_line, long style = 0);
/// Set the value that is being edited
void setValue(String* value);
void setValue(String* value, bool untagged = false);
/// Notification that the value has changed outside this control
void valueChanged();
/// Get access to the field used by the control
TextField& getField();
/// Get access to the style used by the control
TextStyle& getStyle();
/// Update the size, for example after changing the style
void updateSize();
/// Uses a native look
virtual bool nativeLook() const { return true; }
virtual bool drawBorders() const { return false; }
@@ -48,7 +58,8 @@ class TextCtrl : public DataEditor {
virtual wxSize DoGetBestSize() const;
private:
String* value; ///< Value to edit
String* value; ///< Value to edit
bool multi_line; ///< Multi line text control?
DECLARE_EVENT_TABLE();
+1 -1
View File
@@ -367,7 +367,7 @@ void ImageSlicePreview::draw(DC& dc) {
wxMemoryDC mdc; mdc.SelectObject(bitmap);
// draw checker pattern behind image
RealRect rect = GetClientSize();
RotatedDC rdc(mdc, 0, rect, 1, false);
RotatedDC rdc(mdc, 0, rect, 1, QUALITY_LOW);
draw_checker(rdc, rect);
rdc.DrawImage(image, RealPoint(0,0));
mdc.SelectObject(wxNullBitmap);
+1 -1
View File
@@ -31,7 +31,7 @@ CardsPanel::CardsPanel(Window* parent, int id)
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
card_list = new ImageCardList(splitter, ID_CARD_LIST);
notesP = new Panel(splitter, wxID_ANY);
notes = new TextCtrl(notesP, ID_NOTES);
notes = new TextCtrl(notesP, ID_NOTES, true);
collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour);
collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
// init sizer for notes panel
+1 -1
View File
@@ -27,7 +27,7 @@ class CardsPanel : public SetWindowPanel {
CardsPanel(Window* parent, int id);
~CardsPanel();
void onChangeSet();
virtual void onChangeSet();
// --------------------------------------------------- : UI
+107 -7
View File
@@ -9,7 +9,11 @@
#include <gui/set/keywords_panel.hpp>
#include <gui/control/keyword_list.hpp>
#include <gui/control/text_ctrl.hpp>
#include <gui/icon_menu.hpp>
#include <gui/util.hpp>
#include <data/keyword.hpp>
#include <data/field/text.hpp>
#include <util/window_id.hpp>
#include <wx/listctrl.h>
#include <wx/splitter.h>
@@ -19,16 +23,17 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
: SetWindowPanel(parent, id)
{
// init controls
Panel* panel;
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
list = new KeywordList(splitter, wxID_ANY);
panel = new Panel(splitter, wxID_ANY);
keyword = new TextCtrl(panel, wxID_ANY);
match = new TextCtrl(panel, wxID_ANY);
reminder = new TextCtrl(panel, wxID_ANY);
rules = new TextCtrl(panel, wxID_ANY);
keyword = new TextCtrl(panel, wxID_ANY, false);
match = new TextCtrl(panel, wxID_ANY, false);
reminder = new TextCtrl(panel, wxID_ANY, false);
rules = new TextCtrl(panel, wxID_ANY, true);
// init sizer for panel
wxSizer* sp = new wxBoxSizer(wxVERTICAL);
sp->Add(new wxStaticText(panel, wxID_ANY, _("This is a standard $game keyword, you can not edit it. ")
_("If you make a copy of the keyword your copy will take precedent.")), 0, wxALL, 6);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Keyword:")), 0, wxALL, 6);
sp->Add(keyword, 0, wxEXPAND | wxALL & ~wxTOP, 6);
wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, panel, _("Match"));
@@ -38,13 +43,14 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
sp->Add(s2, 0, wxEXPAND | wxALL, 6);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Reminder:")), 0, wxALL, 6);
sp->Add(reminder, 0, wxEXPAND | wxALL & ~wxTOP, 6);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Example:")), 0, wxALL, 6);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Rules:")), 0, wxALL, 6);
sp->Add(rules, 0, wxEXPAND | wxALL & ~wxTOP, 6);
sp->Add(rules, 1, wxEXPAND | wxALL & ~wxTOP, 6);
panel->SetSizer(sp);
// init splitter
splitter->SetMinimumPaneSize(100);
splitter->SetSashGravity(0.5);
splitter->SplitVertically(list, panel, -200);
splitter->SplitVertically(list, panel);
// init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(splitter, 1, wxEXPAND);
@@ -55,8 +61,102 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
/* wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
s2->Add(list_active, 1, wxEXPAND);
s2->Add(list_inactive, 1, wxEXPAND);*/
// init menus
menuKeyword = new IconMenu();
menuKeyword->Append(ID_KEYWORD_PREV, _MENU_("previous keyword"), _HELP_("previous keyword"));
menuKeyword->Append(ID_KEYWORD_NEXT, _MENU_("next keyword"), _HELP_("next keyword"));
menuKeyword->AppendSeparator();
menuKeyword->Append(ID_KEYWORD_ADD, _("keyword_add"), _MENU_("add keyword"), _HELP_("add keyword"));
// NOTE: space after "Del" prevents wx from making del an accellerator
// otherwise we delete a card when delete is pressed inside the editor
menuKeyword->Append(ID_KEYWORD_REMOVE, _("keyword_del"), _MENU_("remove keyword")+_(" "),_HELP_("remove keyword"));
}
KeywordsPanel::~KeywordsPanel() {
delete menuKeyword;
}
// ----------------------------------------------------------------------------- : UI
void KeywordsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
// Toolbar
tb->AddTool(ID_KEYWORD_ADD, _(""), load_resource_tool_image(_("keyword_add")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("add keyword"), _HELP_("add keyword"));
tb->AddTool(ID_KEYWORD_REMOVE, _(""), load_resource_tool_image(_("keyword_del")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("remove keyword"),_HELP_("remove keyword"));
tb->Realize();
// Menus
mb->Insert(2, menuKeyword, _MENU_("keywords"));
}
void KeywordsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
// Toolbar
tb->DeleteTool(ID_KEYWORD_ADD);
tb->DeleteTool(ID_KEYWORD_REMOVE);
// Menus
mb->Remove(2);
}
void KeywordsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
switch (ev.GetId()) {
case ID_KEYWORD_PREV: ev.Enable(list->canSelectPrevious()); break;
case ID_KEYWORD_NEXT: ev.Enable(list->canSelectNext()); break;
case ID_KEYWORD_REMOVE: ev.Enable(list->getKeyword() && !list->getKeyword()->fixed); break;
}
}
void KeywordsPanel::onCommand(int id) {
switch (id) {
case ID_KEYWORD_PREV:
list->selectPrevious();
break;
case ID_KEYWORD_NEXT:
list->selectNext();
break;
case ID_KEYWORD_ADD:
// set->actions.add(new AddKeywordAction(*set));
break;
case ID_KEYWORD_REMOVE:
// set->actions.add(new RemoveKeywordAction(*set, list->getKeyword()));
break;
}
}
// ----------------------------------------------------------------------------- : Events
void KeywordsPanel::onChangeSet() {
list->setSet(set);
// init text controls
keyword ->setSet(set);
keyword ->getStyle().font.size = 16;
keyword ->getStyle().font.font.SetPointSize(16);
keyword ->getStyle().padding_bottom = 1;
keyword ->updateSize();
match ->setSet(set);
match ->getStyle().font.size = 12;
match ->getStyle().font.font.SetPointSize(12);
match ->getStyle().padding_bottom = 1;
match ->updateSize();
reminder->setSet(set);
reminder->getStyle().padding_bottom = 2;
reminder->updateSize();
rules ->setSet(set);
// re-layout
panel->Layout();
}
void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
if (ev.keyword) {
panel->Enable(!ev.keyword->fixed);
keyword->setValue(&ev.keyword->keyword, true);
match ->setValue(&ev.keyword->match);
rules ->setValue(&ev.keyword->rules);
} else {
panel->Enable(false);
}
}
BEGIN_EVENT_TABLE(KeywordsPanel, wxPanel)
EVT_KEYWORD_SELECT(wxID_ANY, KeywordsPanel::onKeywordSelect)
END_EVENT_TABLE()
+17
View File
@@ -15,6 +15,8 @@
class wxSplitterWindow;
class KeywordList;
class TextCtrl;
class IconMenu;
struct KeywordSelectEvent;
// ----------------------------------------------------------------------------- : KeywordsPanel
@@ -22,17 +24,32 @@ class TextCtrl;
class KeywordsPanel : public SetWindowPanel {
public:
KeywordsPanel(Window* parent, int id);
~KeywordsPanel();
virtual void onChangeSet();
// --------------------------------------------------- : UI
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
virtual void onUpdateUI(wxUpdateUIEvent&);
virtual void onCommand(int id);
private:
DECLARE_EVENT_TABLE();
// --------------------------------------------------- : Controls
wxSplitterWindow* splitter;
wxPanel* panel;
KeywordList* list;
TextCtrl* keyword;
TextCtrl* match;
TextCtrl* reminder;
TextCtrl* rules;
IconMenu* menuKeyword;
// --------------------------------------------------- : Events
void onKeywordSelect(KeywordSelectEvent& ev);
};
// ----------------------------------------------------------------------------- : EOF
+11
View File
@@ -94,6 +94,17 @@ class ValueEditor {
virtual size_t selectionStart() const { return 0; }
virtual size_t selectionEnd() const { return 0; }
// --------------------------------------------------- : Search / replace
/// Do a search or replace action for the given FindInfo
/** If from_start == false: searches only from the current selection onward (or backward),
* excluding the sellection itself.
* If from_start == true: searches everything
*
* Returns true when more searching is needed.
*/
bool search(FindInfo& find, bool from_start);
// --------------------------------------------------- : Other
/// The cursor type to use when the mouse is over this control
+2 -2
View File
@@ -529,7 +529,7 @@ void TextValueEditor::moveSelection(IndexType t, size_t new_end, bool also_move_
{
// Move selection
shared_ptr<DC> dc = editor().overdrawDC();
RotatedDC rdc(*dc, viewer.getRotation(), false);
RotatedDC rdc(*dc, viewer.getRotation(), QUALITY_LOW);
if (nativeLook()) {
// clip the dc to the region of this control
rdc.SetClippingRegion(style().getRect());
@@ -659,7 +659,7 @@ void TextValueEditor::determineSize(bool force_fit) {
Bitmap bmp(1,1);
dc.SelectObject(bmp);
dc.SetFont(style().font.font);
style().height = dc.GetCharHeight() + 2;
style().height = dc.GetCharHeight() + 2 + style().padding_top + style().padding_bottom;
}
}
+18
View File
@@ -15,6 +15,24 @@
#include <render/value/text.hpp>
class TextValueEditorScrollBar;
class wxFindReplaceData;
DECLARE_POINTER_TYPE(Card);
// ----------------------------------------------------------------------------- : Search/replace
/// Information for search/replace
class FindInfo {
public:
FindInfo(wxFindReplaceData& what) : what(what) {}
virtual ~FindInfo() {}
/// Handle that a match was found.
/** Should return whether more searching is needed.
*/
virtual bool handle(const CardP& card, const TextValueP& value, size_t start, size_t end) = 0;
wxFindReplaceData& what; ///< What to search for, the direction to search in
};
// ----------------------------------------------------------------------------- : TextValueEditor