From 3cbf2577c1c8e874bceac22dec45be226ca87265 Mon Sep 17 00:00:00 2001 From: twanvl Date: Mon, 20 Nov 2006 17:26:34 +0000 Subject: [PATCH] added native look editor and the set info panel git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@82 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/field/boolean.cpp | 8 ++ src/data/field/boolean.hpp | 2 +- src/gui/control/card_editor.cpp | 7 -- src/gui/control/card_editor.hpp | 9 ++ src/gui/control/card_list.cpp | 2 +- src/gui/control/card_list.hpp | 2 +- src/gui/control/filtered_card_list.cpp | 2 +- src/gui/control/filtered_card_list.hpp | 2 +- src/gui/control/native_look_editor.cpp | 110 +++++++++++++++++++++++++ src/gui/control/native_look_editor.hpp | 76 +++++++++++++++++ src/gui/set/cards_panel.hpp | 2 +- src/gui/set/set_info_panel.cpp | 67 +++++++++++++++ src/gui/set/set_info_panel.hpp | 24 ++++++ src/gui/set/window.cpp | 17 ++-- src/gui/util.cpp | 60 +++++++++++++- src/gui/util.hpp | 8 +- src/gui/value/editor.hpp | 9 ++ src/mse.vcproj | 6 ++ src/render/card/viewer.cpp | 16 ++-- src/render/card/viewer.hpp | 6 +- src/render/text/element.cpp | 4 +- src/render/text/element.hpp | 12 +-- src/render/text/font.cpp | 2 +- src/render/text/line.cpp | 2 +- src/render/text/symbol.cpp | 2 +- src/render/text/viewer.cpp | 4 +- src/script/image.cpp | 23 ++++++ src/script/image.hpp | 3 + src/script/script_manager.cpp | 2 + src/script/scriptable.cpp | 5 ++ src/script/scriptable.hpp | 4 + src/util/string.cpp | 8 ++ 32 files changed, 458 insertions(+), 48 deletions(-) create mode 100644 src/gui/control/native_look_editor.cpp create mode 100644 src/gui/control/native_look_editor.hpp diff --git a/src/data/field/boolean.cpp b/src/data/field/boolean.cpp index a3a1efab..87654279 100644 --- a/src/data/field/boolean.cpp +++ b/src/data/field/boolean.cpp @@ -31,6 +31,14 @@ IMPLEMENT_REFLECTION(BooleanField) { // ----------------------------------------------------------------------------- : BooleanStyle +BooleanStyle::BooleanStyle(const ChoiceFieldP& field) + : ChoiceStyle(field) +{ + render_style = RENDER_BOTH; + choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")")); + choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")")); +} + IMPLEMENT_REFLECTION(BooleanStyle) { REFLECT_BASE(ChoiceStyle); } diff --git a/src/data/field/boolean.hpp b/src/data/field/boolean.hpp index 5f8bc0f8..ca58f8f0 100644 --- a/src/data/field/boolean.hpp +++ b/src/data/field/boolean.hpp @@ -35,7 +35,7 @@ class BooleanField : public ChoiceField { /// The Style for a BooleanField class BooleanStyle : public ChoiceStyle { public: - inline BooleanStyle(const ChoiceFieldP& field) : ChoiceStyle(field) {} + BooleanStyle(const ChoiceFieldP& field); DECLARE_HAS_FIELD(Boolean); // not DECLARE_STYLE_TYPE, because we use a normal ChoiceValueViewer/Editor // no extra data diff --git a/src/gui/control/card_editor.cpp b/src/gui/control/card_editor.cpp index 254928d4..10cf03de 100644 --- a/src/gui/control/card_editor.cpp +++ b/src/gui/control/card_editor.cpp @@ -18,13 +18,6 @@ DECLARE_TYPEOF_COLLECTION(ValueViewer*); // ----------------------------------------------------------------------------- : DataEditor -#define FOR_EACH_EDITOR \ - FOR_EACH(v, viewers) \ - if (ValueEditor* e = v->getEditor()) -#define FOR_EACH_EDITOR_REVERSE \ - FOR_EACH_REVERSE(v, viewers) \ - if (ValueEditor* e = v->getEditor()) - DataEditor::DataEditor(Window* parent, int id, long style) : CardViewer(parent, id, style) , current_viewer(nullptr) diff --git a/src/gui/control/card_editor.hpp b/src/gui/control/card_editor.hpp index 4b9b2375..d2d57658 100644 --- a/src/gui/control/card_editor.hpp +++ b/src/gui/control/card_editor.hpp @@ -110,5 +110,14 @@ class DataEditor : public CardViewer { /// By default a DataEditor edits cards typedef DataEditor CardEditor; +// ----------------------------------------------------------------------------- : Utility + +#define FOR_EACH_EDITOR \ + FOR_EACH(v, viewers) \ + if (ValueEditor* e = v->getEditor()) +#define FOR_EACH_EDITOR_REVERSE \ + FOR_EACH_REVERSE(v, viewers) \ + if (ValueEditor* e = v->getEditor()) + // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 22f08783..15b7eda8 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -29,7 +29,7 @@ DEFINE_EVENT_TYPE(EVENT_CARD_SELECT); // ----------------------------------------------------------------------------- : CardListBase -CardListBase::CardListBase(Window* parent, int id, int additional_style) +CardListBase::CardListBase(Window* parent, int id, long additional_style) : wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | wxLC_SINGLE_SEL) { // create image list diff --git a/src/gui/control/card_list.hpp b/src/gui/control/card_list.hpp index 7f770b35..f287a6c6 100644 --- a/src/gui/control/card_list.hpp +++ b/src/gui/control/card_list.hpp @@ -47,7 +47,7 @@ struct CardSelectEvent : public wxCommandEvent { */ class CardListBase : public wxListView, public SetView { public: - CardListBase(Window* parent, int id, int additional_style = 0); + CardListBase(Window* parent, int id, long additional_style = 0); ~CardListBase(); // --------------------------------------------------- : Selection diff --git a/src/gui/control/filtered_card_list.cpp b/src/gui/control/filtered_card_list.cpp index cc83bdd9..477271e7 100644 --- a/src/gui/control/filtered_card_list.cpp +++ b/src/gui/control/filtered_card_list.cpp @@ -12,7 +12,7 @@ DECLARE_TYPEOF_COLLECTION(CardP); // ----------------------------------------------------------------------------- : FilteredCardList -FilteredCardList::FilteredCardList(Window* parent, int id, int style) +FilteredCardList::FilteredCardList(Window* parent, int id, long style) : CardListBase(parent, id, style) {} diff --git a/src/gui/control/filtered_card_list.hpp b/src/gui/control/filtered_card_list.hpp index 56f961cf..8322a815 100644 --- a/src/gui/control/filtered_card_list.hpp +++ b/src/gui/control/filtered_card_list.hpp @@ -29,7 +29,7 @@ class CardListFilter { /// A card list that lists a subset of the cards in the set class FilteredCardList : public CardListBase { public: - FilteredCardList(Window* parent, int id, int style = 0); + FilteredCardList(Window* parent, int id, long style = 0); /// Change the filter to use void setFilter(const CardListFilterP& filter_); diff --git a/src/gui/control/native_look_editor.cpp b/src/gui/control/native_look_editor.cpp new file mode 100644 index 00000000..52f83b50 --- /dev/null +++ b/src/gui/control/native_look_editor.cpp @@ -0,0 +1,110 @@ +//+----------------------------------------------------------------------------+ +//| 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 +#include +#include +#include + +DECLARE_TYPEOF_COLLECTION(ValueViewerP); +typedef IndexMap IndexMap_FieldP_StyleP; +DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP); + +// ----------------------------------------------------------------------------- : NativeLookEditor + +NativeLookEditor::NativeLookEditor(Window* parent, int id, long style) + : DataEditor(parent, id, style) +{} + +void NativeLookEditor::draw(DC& dc) { + RotatedDC rdc(dc, 0, RealRect(RealPoint(0,0),GetClientSize()), 1, 0); + DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); +} +void NativeLookEditor::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 label + dc.SetFont(*wxNORMAL_FONT); + dc.DrawText(capitalize_sentence(s.fieldP->name), RealPoint(margin_left, s.top + 1)); + // draw 3D border + draw_control_border(this, dc.getDC(), wxRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2)); + // draw viewer + v.draw(dc); + ValueEditor* e = v.getEditor(); + if (e) e->drawSelection(dc); +} + +void NativeLookEditor::resizeViewers() { + // size stuff + UInt y = margin; + int w; + GetClientSize(&w, 0); + const int default_height = 17; + // Set editor sizes + FOR_EACH(v, viewers) { + StyleP s = v->getStyle(); + s->left = margin + label_width; + s->top = y; + s->width = w - s->left - margin; + s->height = default_height; + ValueEditor* e = v->getEditor(); + if (e) e->determineSize(); + y += s->height + vspace; + } +} + +void NativeLookEditor::onInit() { + // Give fieldEditors a chance to show/hide controls (scrollbar) when selecting other editors + FOR_EACH_EDITOR { + e->onShow(true); + } + resizeViewers(); +} + +wxSize NativeLookEditor::DoGetBestSize() const { + return wxSize(200, 200); +} +void NativeLookEditor::onSize(wxSizeEvent& ev) { +// CardViewre::onSize(ev); + resizeViewers(); +} + +BEGIN_EVENT_TABLE(NativeLookEditor, DataEditor) + EVT_SIZE (NativeLookEditor::onSize) +END_EVENT_TABLE() + + +// ----------------------------------------------------------------------------- : SetInfoEditor + +SetInfoEditor::SetInfoEditor(Window* parent, int id, long style) + : NativeLookEditor(parent, id, style) +{} + +void SetInfoEditor::onChangeSet() { + setStyles(set->stylesheet->set_info_style); + setData(set->data); +} + +// ----------------------------------------------------------------------------- : StylingEditor + +StylingEditor::StylingEditor(Window* parent, int id, long style) + : NativeLookEditor(parent, id, style) +{} + +void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) { + this->stylesheet = stylesheet; + setStyles(stylesheet->styling_style); + setData(set->stylingDataFor(*stylesheet)); +} + +void StylingEditor::onChangeSet() { + showStylesheet(set->stylesheet); +} diff --git a/src/gui/control/native_look_editor.hpp b/src/gui/control/native_look_editor.hpp new file mode 100644 index 00000000..87ab7c2e --- /dev/null +++ b/src/gui/control/native_look_editor.hpp @@ -0,0 +1,76 @@ +//+----------------------------------------------------------------------------+ +//| 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_NATIVE_LOOK_EDITOR +#define HEADER_GUI_CONTROL_NATIVE_LOOK_EDITOR + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +// ----------------------------------------------------------------------------- : NativeLookEditor + +/// A data editor with a platform native look +class NativeLookEditor : public DataEditor { + public: + NativeLookEditor(Window* parent, int id, long style = 0); + + /// Uses a native look + virtual bool nativeLook() const { return true; } + virtual bool drawBorders() const { return false; } + + virtual void draw(DC& dc); + virtual void drawViewer(RotatedDC& dc, ValueViewer& v); + + protected: + // Best size doesn't really matter, as long as it is not too small + virtual wxSize DoGetBestSize() const; + virtual void onInit(); + + private: + static const UInt margin = 6; + static const UInt margin_left = 4; + static const UInt label_width = 150; + static const UInt vspace = 10; + + DECLARE_EVENT_TABLE(); + + void onSize(wxSizeEvent&); + /// Resize the viewers so they match with this control + void resizeViewers(); +}; + + +// ----------------------------------------------------------------------------- : SetInfoEditor + +/// Editor for set.data +class SetInfoEditor : public NativeLookEditor { + public: + SetInfoEditor(Window* parent, int id, long style = 0); + protected: + virtual void onChangeSet(); +}; + +// ----------------------------------------------------------------------------- : StylingEditor + +/// Editor for styling data +class StylingEditor : public NativeLookEditor { + public: + StylingEditor(Window* parent, int id, long style = 0); + + /// Show the styling for given stylesheet in the editor + void showStylesheet(const StyleSheetP& stylesheet); + + protected: + virtual void onChangeSet(); + + private: + StyleSheetP stylesheet; ///< The stylesheet for which we are showing the styling data +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/gui/set/cards_panel.hpp b/src/gui/set/cards_panel.hpp index 369130c6..2f2eff50 100644 --- a/src/gui/set/cards_panel.hpp +++ b/src/gui/set/cards_panel.hpp @@ -25,7 +25,7 @@ class CardsPanel : public SetWindowPanel { ~CardsPanel(); void onChangeSet(); - + // --------------------------------------------------- : UI virtual void initUI (wxToolBar* tb, wxMenuBar* mb); diff --git a/src/gui/set/set_info_panel.cpp b/src/gui/set/set_info_panel.cpp index 56f6c104..18162a40 100644 --- a/src/gui/set/set_info_panel.cpp +++ b/src/gui/set/set_info_panel.cpp @@ -7,10 +7,77 @@ // ----------------------------------------------------------------------------- : Includes #include +#include +#include +#include // ----------------------------------------------------------------------------- : SetInfoPanel SetInfoPanel::SetInfoPanel(Window* parent, int id) : SetWindowPanel(parent, id) { + // init controls + editor = new SetInfoEditor(this, wxID_ANY); + // init sizer + wxSizer* s = new wxBoxSizer(wxVERTICAL); + s->Add(editor, 1, wxEXPAND, 2); + s->SetSizeHints(this); + SetSizer(s); } + +void SetInfoPanel::onChangeSet() { + editor->setSet(set); +} + +// ----------------------------------------------------------------------------- : UI + +void SetInfoPanel::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->Realize(); + // Menus + IconMenu* menuFormat = new IconMenu(); + menuFormat->Append(ID_FORMAT_BOLD, _("TOOL_BOLD"), _("Bold\tCtrl+B"), _("Makes the selected text bold"), wxITEM_CHECK); + menuFormat->Append(ID_FORMAT_ITALIC, _("TOOL_ITALIC"), _("Italic\tCtrl+I"), _("Makes the selected text italic"), wxITEM_CHECK); + menuFormat->Append(ID_FORMAT_SYMBOL, _("TOOL_SYMBOL"), _("Symbols\tCtrl+M"), _("Draws the selected text with symbols"), wxITEM_CHECK); + menuFormat->Append(ID_FORMAT_REMINDER, _("TOOL_REMINDER"), _("Reminder Text\tCtrl+R"), _("Show reminder text for the selected keyword"), wxITEM_CHECK); + mb->Insert(2, menuFormat, _("&Format")); +} + +void SetInfoPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) { + // Toolbar + tb->DeleteTool(ID_FORMAT_BOLD); + tb->DeleteTool(ID_FORMAT_ITALIC); + tb->DeleteTool(ID_FORMAT_SYMBOL); + // Menus + delete mb->Remove(2); +} + +void SetInfoPanel::onUpdateUI(wxUpdateUIEvent& e) { + switch (e.GetId()) { + case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: { + e.Enable(editor->canFormat(e.GetId())); + e.Check (editor->hasFormat(e.GetId())); + break; + } + } +} + +void SetInfoPanel::onCommand(int id) { + switch (id) { + case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: { + editor->doFormat(id); + } + } +} + +// ----------------------------------------------------------------------------- : Clipboard + +bool SetInfoPanel::canCut() const { return editor->canCut(); } +bool SetInfoPanel::canCopy() const { return editor->canCopy(); } +bool SetInfoPanel::canPaste() const { return editor->canPaste(); } +void SetInfoPanel::doCut() { editor->doCut(); } +void SetInfoPanel::doCopy() { editor->doCopy(); } +void SetInfoPanel::doPaste() { editor->doPaste(); } diff --git a/src/gui/set/set_info_panel.hpp b/src/gui/set/set_info_panel.hpp index 0ec989f1..5f29624b 100644 --- a/src/gui/set/set_info_panel.hpp +++ b/src/gui/set/set_info_panel.hpp @@ -12,11 +12,35 @@ #include #include +class SetInfoEditor; + // ----------------------------------------------------------------------------- : SetInfoPanel class SetInfoPanel : public SetWindowPanel { public: SetInfoPanel(Window* parent, int id); + + // --------------------------------------------------- : UI + + virtual void initUI (wxToolBar* tb, wxMenuBar* mb); + virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb); + virtual void onUpdateUI(wxUpdateUIEvent& e); + virtual void onCommand(int id); + + // --------------------------------------------------- : Clipboard + + virtual bool canCut() const; + virtual bool canCopy() const; + virtual bool canPaste() const; + virtual void doCut(); + virtual void doCopy(); + virtual void doPaste(); + + protected: + virtual void onChangeSet(); + + private: + SetInfoEditor* editor; }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 20a10d77..96f2f0e4 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -116,16 +116,13 @@ SetWindow::SetWindow(Window* parent, const SetP& set) // NOTE: place the CardsPanel last in the panels list, // this way the card list is the last to be told of a set change // this way everyone else already uses the new set when it sends a CardSelectEvent - addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 2, _("F5"), _("Cards"), _("Cards"), _("Edit the cards in the set")); -// addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6")); - addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Change the style of cards")); + addPanel(menuWindow, tabBar, new CardsPanel (this, wxID_ANY), 3, _("F5"), _("Cards"), _("Cards"), _("Edit the cards in the set")); + addPanel(menuWindow, tabBar, new SetInfoPanel (this, wxID_ANY), 0, _("F6"), _("Set info"), _("&Set Information"), _("Edit information about the set, its creator, etc.")); + addPanel(menuWindow, tabBar, new StylePanel (this, wxID_ANY), 1, _("F7"), _("Style"), _("Style"), _("Change the style of cards")); // addPanel(menuWindow, tabBar, new KeywordsPanel(this, wxID_ANY), 2, _("F8")); -// addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 3, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set")); - //addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10")) -// selectPanel(idWindowMin + 4); // select cards panel - - addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 0, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set")); - selectPanel(ID_WINDOW_MIN+2); // test + addPanel(menuWindow, tabBar, new StatsPanel (this, wxID_ANY), 2, _("F9"), _("Stats"), _("Statistics"), _("Show statistics about the cards in the set")); +// addPanel(*s, *menuWindow, *tabBar, new DraftPanel (&this, wxID_ANY), 4, _("F10")) + selectPanel(ID_WINDOW_MIN + 3); // select cards panel // loose ends tabBar->Realize(); @@ -227,8 +224,6 @@ void SetWindow::onChangeSet() { // make sure there is always at least one card // some things need this if (set->cards.empty()) set->cards.push_back(new_shared1(*set->game)); - // does the set need a scriptUpdater? If so, we can do it -// if (!set->scriptUpdater) scriptUpdater.set = set; // all panels view the same set FOR_EACH(p, panels) { p->setSet(set); diff --git a/src/gui/util.cpp b/src/gui/util.cpp index 6b7224c4..6a5206d2 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -11,6 +11,12 @@ #include #include +#if defined(wxMSW) && wxUSE_UXTHEME + #include + #include + #include +#endif + // ----------------------------------------------------------------------------- : DC related /// Fill a DC with a single color @@ -43,7 +49,7 @@ void draw_checker(RotatedDC& dc, const RealRect& rect) { // ----------------------------------------------------------------------------- : Image related -Image load_resource_image(String name) { +Image load_resource_image(const String& name) { #ifdef __WXMSW__ // Load resource // based on wxLoadUserResource @@ -61,4 +67,54 @@ Image load_resource_image(String name) { wxMemoryInputStream stream(data, len); return wxImage(stream); #endif -} \ No newline at end of file +} + +// ----------------------------------------------------------------------------- : Platform look + +// Draw a basic 3D border +void draw3DBorder(DC& dc, int x1, int y1, int x2, int y2) { + dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)); + dc.DrawLine(x1, y1, x2, y1); + dc.DrawLine(x1, y1, x1, y2); + dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)); + dc.DrawLine(x1-1, y1-1, x2+1, y1-1); + dc.DrawLine(x1-1, y1-1, x1-1, y2+1); + dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT)); + dc.DrawLine(x1, y2, x2, y2); + dc.DrawLine(x2, y1, x2, y2+1); + dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)); + dc.DrawLine(x1-1, y2+1, x2+1, y2+1); + dc.DrawLine(x2+1, y1-1, x2+1, y2+2); +} + +void draw_control_border(Window* win, DC& dc, const wxRect& rect) { + #if defined(wxMSW) && wxUSE_UXTHEME + RECT r; + wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get(); + if (themeEngine && themeEngine->IsAppThemed()) { + wxUxThemeHandle hTheme(win, L_("EDIT")); + r.left = rect.x -1; + r.top = rect.y -1; + r.right = rect.x + rect.width + 1; + r.bottom = rect.y + rect.height + 1; + if (hTheme) { + wxUxThemeEngine::Get()->DrawThemeBackground( + hTheme, + dc.GetHDC(), + EP_EDITTEXT, + ETS_NORMAL, + &r, + NULL + ); + return; + } + } + r.left = rect.x - 2; + r.top = rect.y - 2; + r.right = rect.x + rect.width + 2; + r.bottom = rect.y + rect.height + 2; + DrawEdge((HDC)dc.GetHDC(), &r, EDGE_SUNKEN, BF_RECT); + #else + draw3DBorder(dc, rect.x - 1, rect.y - 1, rect.x + rect.width, rect.y + rect.height); + #endif +} diff --git a/src/gui/util.hpp b/src/gui/util.hpp index 5baf07a4..58ebdcc7 100644 --- a/src/gui/util.hpp +++ b/src/gui/util.hpp @@ -29,7 +29,13 @@ void draw_checker(RotatedDC& dc, const RealRect&); // ----------------------------------------------------------------------------- : Resource related /// Load an image from a resource -Image load_resource_image(String name); +Image load_resource_image(const String& name); + +// ----------------------------------------------------------------------------- : Platform look + +/// Draws a border for a control *around* a rect +/** Based on wxRendererXP::DrawComboBoxDropButton */ +void draw_control_border(Window* win, DC& dc, const wxRect& rect); // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/gui/value/editor.hpp b/src/gui/value/editor.hpp index 7017f638..aff2604d 100644 --- a/src/gui/value/editor.hpp +++ b/src/gui/value/editor.hpp @@ -95,6 +95,15 @@ class ValueEditor { /// The cursor type to use when the mouse is over this control virtual wxCursor cursor() const { return wxCursor(); } + /// determines prefered size in the native look, update the style + virtual void determineSize() {} + /// The editor is shown or hidden + virtual void onShow(bool) {} + + /// Draw selection indicators + /** note: the drawing of the value is done by the viewer, only a selection indicator is drawn here + */ + virtual void drawSelection(RotatedDC& dc) {} }; // ----------------------------------------------------------------------------- : Utility diff --git a/src/mse.vcproj b/src/mse.vcproj index 4a68a79e..75b9740f 100644 --- a/src/mse.vcproj +++ b/src/mse.vcproj @@ -404,6 +404,12 @@ + + + + diff --git a/src/render/card/viewer.cpp b/src/render/card/viewer.cpp index c0ea623c..4c748672 100644 --- a/src/render/card/viewer.cpp +++ b/src/render/card/viewer.cpp @@ -27,23 +27,26 @@ void DataViewer::draw(DC& dc) { StyleSheetP stylesheet = set->stylesheetFor(card); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); RotatedDC rdc(dc, ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), ss.card_anti_alias() && !nativeLook()); - draw(rdc); + draw(rdc, set->stylesheet->card_background); } -void DataViewer::draw(RotatedDC& dc) { +void DataViewer::draw(RotatedDC& dc, const Color& background) { if (!set) return; // no set specified, don't draw anything // fill with background color dc.SetPen(*wxTRANSPARENT_PEN); - dc.SetBrush(set->stylesheet->card_background); + dc.SetBrush(background); dc.DrawRectangle(dc.getInternalRect()); // update style scripts if (card) set->updateFor(card); // draw values FOR_EACH(v, viewers) { // draw low z index fields first if (v->getStyle()->visible) {// visible - v->draw(dc); + drawViewer(dc, *v); } } } +void DataViewer::drawViewer(RotatedDC& dc, ValueViewer& v) { + v.draw(dc); +} // ----------------------------------------------------------------------------- : Utility for ValueViewers @@ -80,8 +83,9 @@ void DataViewer::setStyles(IndexMap& styles) { viewers.clear(); FOR_EACH(s, styles) { if ((s->visible || s->visible.isScripted()) && - (s->width || s->width .isScripted()) && - (s->height || s->height .isScripted())) { + nativeLook() || ( + (s->width || s->width .isScripted()) && + (s->height || s->height .isScripted()))) { // no need to make a viewer for things that are always invisible viewers.push_back(makeViewer(s)); // REMOVEME //TODO //%%% diff --git a/src/render/card/viewer.hpp b/src/render/card/viewer.hpp index cca68ea0..532f4aea 100644 --- a/src/render/card/viewer.hpp +++ b/src/render/card/viewer.hpp @@ -28,9 +28,11 @@ class DataViewer : public SetView { // --------------------------------------------------- : Drawing /// Draw the current (card/data) to the given dc - void draw(DC& dc); + virtual void draw(DC& dc); /// Draw the current (card/data) to the given dc - virtual void draw(RotatedDC& dc); + virtual void draw(RotatedDC& dc, const Color& background); + /// Draw a single viewer + virtual void drawViewer(RotatedDC& dc, ValueViewer& v); // --------------------------------------------------- : Utility for ValueViewers diff --git a/src/render/text/element.cpp b/src/render/text/element.cpp index 03c70dd6..eb00393a 100644 --- a/src/render/text/element.cpp +++ b/src/render/text/element.cpp @@ -14,13 +14,13 @@ DECLARE_TYPEOF_COLLECTION(TextElementP); // ----------------------------------------------------------------------------- : TextElements -void TextElements::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const { +void TextElements::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { FOR_EACH_CONST(e, elements) { size_t start_ = max(start, e->start); size_t end_ = min(end, e->end); if (start_ < end_) { e->draw(dc, scale, - RealRect(rect.position.x + xs[start_-start], rect.position.y, + RealRect(rect.position.x + xs[start_-start] - xs[0], rect.position.y, xs[end_-start] - xs[start_-start], rect.size.height), xs + start_ - start, what, start_, end_); } diff --git a/src/render/text/element.hpp b/src/render/text/element.hpp index 3168fccb..0fbd1aa1 100644 --- a/src/render/text/element.hpp +++ b/src/render/text/element.hpp @@ -59,7 +59,7 @@ class TextElement { /// Draw a subsection section of the text in the given rectangle /** xs give the x coordinates for each character * this->start <= start < end <= this->end <= text.size() */ - virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const = 0; + virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const = 0; /// Get information on all characters in the range [start...end) and store them in out virtual void getCharInfo(RotatedDC& dc, double scale, vector& out) const = 0; /// Return the minimum scale factor allowed (starts at 1) @@ -96,7 +96,7 @@ class TextElement { class TextElements : public vector { public: /// Draw all the elements (as need to show the range start..end) - void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const; + void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const; // Get information on all characters in the range [start...end) and store them in out void getCharInfo(RotatedDC& dc, double scale, size_t start, size_t end, vector& out) const; /// Return the minimum scale factor allowed by all elements @@ -131,7 +131,7 @@ class FontTextElement : public SimpleTextElement { , font(font) {} - virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const; + virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const; virtual void getCharInfo(RotatedDC& dc, double scale, vector& out) const; virtual double minScale() const; private: @@ -147,7 +147,7 @@ class SymbolTextElement : public SimpleTextElement { , font(font), ctx(*ctx) {} - virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const; + virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const; virtual void getCharInfo(RotatedDC& dc, double scale, vector& out) const; virtual double minScale() const; private: @@ -172,7 +172,7 @@ class HorizontalLineTextElement : public TextElement { public: HorizontalLineTextElement(const String& text, size_t start ,size_t end) : TextElement(text, start, end) {} - virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const; + virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const; virtual void getCharInfo(RotatedDC& dc, double scale, vector& out) const; virtual double minScale() const; }; @@ -185,7 +185,7 @@ class CompoundTextElement : public TextElement { public: CompoundTextElement(const String& text, size_t start ,size_t end) : TextElement(text, start, end) {} - virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const; + virtual void draw (RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const; virtual RealSize charSize(RotatedDC& dc, double scale, size_t index) const; private: diff --git a/src/render/text/font.cpp b/src/render/text/font.cpp index b81db9ef..7e3be07b 100644 --- a/src/render/text/font.cpp +++ b/src/render/text/font.cpp @@ -11,7 +11,7 @@ // ----------------------------------------------------------------------------- : FontTextElement -void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const { +void FontTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { dc.SetFont(font->font, font->size * scale); if (end != start && text.substr(end-1, 1) == _("\n")) end -= 1; // don't draw the newline character at the end diff --git a/src/render/text/line.cpp b/src/render/text/line.cpp index 8bbe903b..afaf8db4 100644 --- a/src/render/text/line.cpp +++ b/src/render/text/line.cpp @@ -10,7 +10,7 @@ // ----------------------------------------------------------------------------- : HorizontalLineTextElement -void HorizontalLineTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const { +void HorizontalLineTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { // handled by TextViewer } diff --git a/src/render/text/symbol.cpp b/src/render/text/symbol.cpp index 9aa338d8..0cf34652 100644 --- a/src/render/text/symbol.cpp +++ b/src/render/text/symbol.cpp @@ -11,7 +11,7 @@ // ----------------------------------------------------------------------------- : SymbolTextElement -void SymbolTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, double* xs, DrawWhat what, size_t start, size_t end) const { +void SymbolTextElement::draw(RotatedDC& dc, double scale, const RealRect& rect, const double* xs, DrawWhat what, size_t start, size_t end) const { if (font.font) { font.font->draw(dc, ctx, rect, font.size * scale, font.alignment, text.substr(start, end-start)); } diff --git a/src/render/text/viewer.cpp b/src/render/text/viewer.cpp index 5f9f2bad..ba223dd2 100644 --- a/src/render/text/viewer.cpp +++ b/src/render/text/viewer.cpp @@ -257,11 +257,11 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const String& text, const Text } double TextViewer::lineLeft(RotatedDC& dc, const TextStyle& style, double y) { - return 0; + return 0 + style.padding_left; // return style.mask.rowLeft(y, dc.getInternalSize()) + style.padding_left; } double TextViewer::lineRight(RotatedDC& dc, const TextStyle& style, double y) { - return style.width; + return style.width - style.padding_right; // return style.mask.rowRight(y, dc.getInternalSize()) - style.padding_right; } ContourMask::ContourMask() {} // MOVEME //@@ diff --git a/src/script/image.cpp b/src/script/image.cpp index c44ddccf..3046e52d 100644 --- a/src/script/image.cpp +++ b/src/script/image.cpp @@ -10,6 +10,7 @@ #include