Commit be4009b6 authored by twanvl's avatar twanvl

added SymbolValueEditor + minor fixes

parent 263c2ca9
...@@ -150,7 +150,7 @@ class ControlPointAddAction : public Action { ...@@ -150,7 +150,7 @@ class ControlPointAddAction : public Action {
// ----------------------------------------------------------------------------- : Remove control point // ----------------------------------------------------------------------------- : Remove control point
/// Action that removes any number of points from a symbol part /// Action that removes any number of points from a symbol part
/// TODO: If less then 3 points are left removes the entire part! /// TODO: If less then 3 points are left removes the entire part?
Action* controlPointRemoveAction(const SymbolPartP& part, const set<ControlPointP>& toDelete); Action* controlPointRemoveAction(const SymbolPartP& part, const set<ControlPointP>& toDelete);
......
...@@ -203,7 +203,7 @@ void GraphControl::setData(const GraphDataPre& data) { ...@@ -203,7 +203,7 @@ void GraphControl::setData(const GraphDataPre& data) {
void GraphControl::setData(const GraphDataP& data) { void GraphControl::setData(const GraphDataP& data) {
if (graph) { if (graph) {
graph->setData(data); graph->setData(data);
current_item.clear(); // TODO : preserver selection current_item.clear(); // TODO : preserve selection
Refresh(false); Refresh(false);
} }
} }
......
...@@ -10,8 +10,12 @@ ...@@ -10,8 +10,12 @@
#include <gui/symbol/control.hpp> #include <gui/symbol/control.hpp>
#include <gui/symbol/part_list.hpp> #include <gui/symbol/part_list.hpp>
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <data/set.hpp>
#include <data/field/symbol.hpp>
#include <data/action/value.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <util/io/reader.hpp> #include <util/io/reader.hpp>
#include <util/error.hpp>
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/wfstream.h> #include <wx/wfstream.h>
...@@ -29,7 +33,7 @@ SymbolPartP defaultSymbolPart(double d) { ...@@ -29,7 +33,7 @@ SymbolPartP defaultSymbolPart(double d) {
} }
// A default symbol, a square // A default symbol, a square
SymbolP defaultSymbol() { SymbolP default_symbol() {
SymbolP symbol = new_shared<Symbol>(); SymbolP symbol = new_shared<Symbol>();
symbol->parts.push_back(defaultSymbolPart(0)); symbol->parts.push_back(defaultSymbolPart(0));
return symbol; return symbol;
...@@ -38,12 +42,29 @@ SymbolP defaultSymbol() { ...@@ -38,12 +42,29 @@ SymbolP defaultSymbol() {
// ----------------------------------------------------------------------------- : Constructor // ----------------------------------------------------------------------------- : Constructor
SymbolWindow::SymbolWindow(Window* parent) { SymbolWindow::SymbolWindow(Window* parent) {
init(parent, defaultSymbol()); init(parent, default_symbol());
} }
SymbolWindow::SymbolWindow(Window* parent, String filename) { SymbolWindow::SymbolWindow(Window* parent, const String& filename) {
// TODO // TODO : open file
init(parent, defaultSymbol()); init(parent, default_symbol());
}
SymbolWindow::SymbolWindow(Window* parent, const SymbolValueP& value, const SetP& set)
: value(value), set(set)
{
// attempt to load symbol
SymbolP symbol;
if (!value->filename.empty()) {
try {
// load symbol
symbol = set->readFile<SymbolP>(value->filename);
} catch (const Error& e) {
handle_error(e);
}
}
if (!symbol) symbol = default_symbol();
init(parent, symbol);
} }
void SymbolWindow::init(Window* parent, SymbolP symbol) { void SymbolWindow::init(Window* parent, SymbolP symbol) {
...@@ -122,12 +143,17 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) { ...@@ -122,12 +143,17 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) {
s->Add(v, 0, wxEXPAND); s->Add(v, 0, wxEXPAND);
s->Add(control, 1, wxEXPAND); s->Add(control, 1, wxEXPAND);
SetSizer(s); SetSizer(s);
// we want update ui events
wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED);
SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
em->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
} }
// ----------------------------------------------------------------------------- : Event handling // ----------------------------------------------------------------------------- : Event handling
void SymbolWindow::onFileNew(wxCommandEvent& ev) { void SymbolWindow::onFileNew(wxCommandEvent& ev) {
SymbolP symbol = defaultSymbol(); SymbolP symbol = default_symbol();
parts->setSymbol(symbol); parts->setSymbol(symbol);
control->setSymbol(symbol); control->setSymbol(symbol);
} }
...@@ -151,12 +177,25 @@ void SymbolWindow::onFileOpen(wxCommandEvent& ev) { ...@@ -151,12 +177,25 @@ void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
} }
void SymbolWindow::onFileSave(wxCommandEvent& ev) { void SymbolWindow::onFileSave(wxCommandEvent& ev) {
// TODO
onFileSaveAs(ev);
} }
void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) { void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
String name = wxFileSelector(_("Save symbol"),_(""),_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxSAVE, this);
if (!name.empty()) {
Writer writer(new_shared1<wxFileOutputStream>(name));
writer.handle(control->getSymbol());
}
} }
void SymbolWindow::onFileStore(wxCommandEvent& ev) { void SymbolWindow::onFileStore(wxCommandEvent& ev) {
if (value) {
FileName new_filename = set->newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
Writer writer(set->openOut(new_filename));
writer.handle(control->getSymbol());
set->actions.add(value_action(value, new_filename));
}
} }
void SymbolWindow::onFileExit(wxCommandEvent& ev) { void SymbolWindow::onFileExit(wxCommandEvent& ev) {
...@@ -191,7 +230,7 @@ void SymbolWindow::onUpdateUI(wxUpdateUIEvent& ev) { ...@@ -191,7 +230,7 @@ void SymbolWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch(ev.GetId()) { switch(ev.GetId()) {
// file menu // file menu
case ID_FILE_STORE: { case ID_FILE_STORE: {
// ev.Enable(value); ev.Enable(value);
break; break;
// undo/redo // undo/redo
} case ID_EDIT_UNDO: { } case ID_EDIT_UNDO: {
......
...@@ -9,13 +9,14 @@ ...@@ -9,13 +9,14 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include "../../util/prec.hpp" #include <util/prec.hpp>
#include <data/symbol.hpp> #include <data/symbol.hpp>
#include <wx/listctrl.h> #include <wx/listctrl.h>
//#include "control.hpp"
class SymbolControl; class SymbolControl;
class SymbolPartList; class SymbolPartList;
DECLARE_POINTER_TYPE(SymbolValue);
DECLARE_POINTER_TYPE(Set);
// ----------------------------------------------------------------------------- : SymbolWindow // ----------------------------------------------------------------------------- : SymbolWindow
...@@ -25,9 +26,9 @@ class SymbolWindow : public Frame { ...@@ -25,9 +26,9 @@ class SymbolWindow : public Frame {
/// Construct a SymbolWindow /// Construct a SymbolWindow
SymbolWindow(Window* parent); SymbolWindow(Window* parent);
/// Construct a SymbolWindow showing a symbol from a file /// Construct a SymbolWindow showing a symbol from a file
SymbolWindow(Window* parent, String filename); SymbolWindow(Window* parent, const String& filename);
// /// Construct a SymbolWindow showing a symbol from a set // /// Construct a SymbolWindow showing a symbol value in a set
// SymbolWindow(Window* parent); SymbolWindow(Window* parent, const SymbolValueP& value, const SetP& set);
private: private:
// --------------------------------------------------- : Children // --------------------------------------------------- : Children
...@@ -39,8 +40,8 @@ class SymbolWindow : public Frame { ...@@ -39,8 +40,8 @@ class SymbolWindow : public Frame {
SymbolPartList* parts; ///< A list of parts in the symbol SymbolPartList* parts; ///< A list of parts in the symbol
// when editing a symbol field // when editing a symbol field
// SymbolValueP value SymbolValueP value;
// SetP set SetP set;
// --------------------------------------------------- : Event handling // --------------------------------------------------- : Event handling
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
......
...@@ -112,5 +112,5 @@ void ChoiceValueEditor::determineSize() { ...@@ -112,5 +112,5 @@ void ChoiceValueEditor::determineSize() {
} }
void ChoiceValueEditor::change(const Defaultable<String>& c) { void ChoiceValueEditor::change(const Defaultable<String>& c) {
getSet().actions.add(value_action(static_pointer_cast<ChoiceValue>(valueP), c)); getSet().actions.add(value_action(valueP(), c));
} }
...@@ -148,7 +148,7 @@ void ColorValueEditor::determineSize() { ...@@ -148,7 +148,7 @@ void ColorValueEditor::determineSize() {
} }
void ColorValueEditor::change(const Defaultable<Color>& c) { void ColorValueEditor::change(const Defaultable<Color>& c) {
getSet().actions.add(value_action(static_pointer_cast<ColorValue>(valueP), c)); getSet().actions.add(value_action(valueP(), c));
} }
void ColorValueEditor::changeCustom() { void ColorValueEditor::changeCustom() {
Color c = wxGetColourFromUser(0, value().value()); Color c = wxGetColourFromUser(0, value().value());
......
...@@ -7,7 +7,18 @@ ...@@ -7,7 +7,18 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <gui/value/symbol.hpp> #include <gui/value/symbol.hpp>
#include <gui/symbol/window.hpp>
// ----------------------------------------------------------------------------- : // ----------------------------------------------------------------------------- : SymbolValueEditor
IMPLEMENT_VALUE_EDITOR(Symbol) {} IMPLEMENT_VALUE_EDITOR(Symbol) {}
void SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
// TODO : use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
wnd->Show();
}
void SymbolValueEditor::determineSize() {
style().height = 50;
}
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
class SymbolValueEditor : public SymbolValueViewer, public ValueEditor { class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
public: public:
DECLARE_VALUE_EDITOR(Symbol); DECLARE_VALUE_EDITOR(Symbol);
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&);
virtual void determineSize();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -20,6 +20,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor { ...@@ -20,6 +20,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
public: public:
DECLARE_VALUE_EDITOR(Text); DECLARE_VALUE_EDITOR(Text);
// virtual void determineSize();
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -95,9 +95,8 @@ void DataViewer::setStyles(IndexMap<FieldP,StyleP>& styles) { ...@@ -95,9 +95,8 @@ void DataViewer::setStyles(IndexMap<FieldP,StyleP>& styles) {
(s->width || s->width .isScripted()) && (s->width || s->width .isScripted()) &&
(s->height || s->height .isScripted()))) { (s->height || s->height .isScripted()))) {
// no need to make a viewer for things that are always invisible // no need to make a viewer for things that are always invisible
viewers.push_back(makeViewer(s)); ValueViewerP viewer = makeViewer(s);
// REMOVEME //TODO //%%% if (viewer) viewers.push_back(viewer);
if (!viewers.back()) viewers.pop_back();
} }
} }
// sort viewers by z-index of style // sort viewers by z-index of style
......
...@@ -28,7 +28,7 @@ void filter_symbol(Image& symbol, const SymbolFilter& filter) { ...@@ -28,7 +28,7 @@ void filter_symbol(Image& symbol, const SymbolFilter& filter) {
AColor result = filter.color((double)x / width, (double)y / height, point); AColor result = filter.color((double)x / width, (double)y / height, point);
// Store color // Store color
data[0] = result.Red(); data[0] = result.Red();
data[2] = result.Green(); data[1] = result.Green();
data[2] = result.Blue(); data[2] = result.Blue();
alpha[0] = result.alpha; alpha[0] = result.alpha;
// next // next
......
...@@ -18,7 +18,8 @@ Image render_symbol(const SymbolP& symbol, double border_radius, int size) { ...@@ -18,7 +18,8 @@ Image render_symbol(const SymbolP& symbol, double border_radius, int size) {
Bitmap bmp(size, size); Bitmap bmp(size, size);
wxMemoryDC dc; wxMemoryDC dc;
dc.SelectObject(bmp); dc.SelectObject(bmp);
clearDC_black(dc); clearDC(dc, Color(0,128,0));
viewer.rotation.setZoom(size);
viewer.draw(dc); viewer.draw(dc);
dc.SelectObject(wxNullBitmap); dc.SelectObject(wxNullBitmap);
return bmp.ConvertToImage(); return bmp.ConvertToImage();
...@@ -28,7 +29,7 @@ Image render_symbol(const SymbolP& symbol, double border_radius, int size) { ...@@ -28,7 +29,7 @@ Image render_symbol(const SymbolP& symbol, double border_radius, int size) {
SymbolViewer::SymbolViewer(const SymbolP& symbol, double border_radius) SymbolViewer::SymbolViewer(const SymbolP& symbol, double border_radius)
: border_radius(border_radius) : border_radius(border_radius)
, rotation(0, RealRect(0,0,500,500)) , rotation(0, RealRect(0,0,500,500), 500)
{ {
setSymbol(symbol); setSymbol(symbol);
} }
......
...@@ -81,9 +81,12 @@ class ValueViewer { ...@@ -81,9 +81,12 @@ class ValueViewer {
#define DECLARE_VALUE_VIEWER(Type) \ #define DECLARE_VALUE_VIEWER(Type) \
protected: \ protected: \
inline Type##Style& style() const { return static_cast< Type##Style&>(*styleP); } \ inline Type##Style& style() const { return static_cast< Type##Style&>(*ValueViewer::styleP); } \
inline const Type##Value& value() const { return static_cast<const Type##Value&>(*valueP); } \ inline const Type##Value& value() const { return static_cast<const Type##Value&>(*ValueViewer::valueP); } \
inline const Type##Field& field() const { return style().field(); } \ inline const Type##Field& field() const { return style().field(); } \
inline Type##StyleP styleP() const { return static_pointer_cast<Type##Style>(ValueViewer::styleP); } \
inline Type##ValueP valueP() const { return static_pointer_cast<Type##Value>(ValueViewer::valueP); } \
inline Type##FieldP fieldP() const { return static_pointer_cast<Type##Field>(style().fieldP); } \
public: \ public: \
Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style) Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style)
......
...@@ -217,18 +217,21 @@ void ScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependen ...@@ -217,18 +217,21 @@ void ScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependen
} }
break; break;
} case DEP_CARDS_FIELD: { } case DEP_CARDS_FIELD: {
// TODO
break; break;
} case DEP_STYLE: { } case DEP_STYLE: {
// TODO
break; break;
} case DEP_CARD_COPY_DEP: { } case DEP_CARD_COPY_DEP: {
// TODO
break; break;
} case DEP_SET_COPY_DEP: { } case DEP_SET_COPY_DEP: {
// TODO
break; break;
} default: } default:
assert(false); assert(false);
} }
/* /* if (d.type == DependendScript.setField) {
if (d.type == DependendScript.setField) {
// from set data // from set data
ValueP value = set->data.at(ds.index); ValueP value = set->data.at(ds.index);
toUpdate.push_back(ToUpdate(&*value)); toUpdate.push_back(ToUpdate(&*value));
......
...@@ -43,6 +43,7 @@ void ActionStack::add(Action* action, bool allow_merge) { ...@@ -43,6 +43,7 @@ void ActionStack::add(Action* action, bool allow_merge) {
void ActionStack::undo() { void ActionStack::undo() {
assert(canUndo()); assert(canUndo());
if (!canUndo()) return;
Action* action = undo_actions.back(); Action* action = undo_actions.back();
action->perform(true); action->perform(true);
tellListeners(*action, true); tellListeners(*action, true);
...@@ -52,6 +53,7 @@ void ActionStack::undo() { ...@@ -52,6 +53,7 @@ void ActionStack::undo() {
} }
void ActionStack::redo() { void ActionStack::redo() {
assert(canRedo()); assert(canRedo());
if (!canRedo()) return;
Action* action = redo_actions.back(); Action* action = redo_actions.back();
action->perform(false); action->perform(false);
tellListeners(*action, false); tellListeners(*action, false);
......
...@@ -203,7 +203,7 @@ String Package::nameOut(const String& file) { ...@@ -203,7 +203,7 @@ String Package::nameOut(const String& file) {
} }
} }
String Package::newFileName(const String& prefix, const String& suffix) { FileName Package::newFileName(const String& prefix, const String& suffix) {
assert(wxThread::IsMain()); // Writing should only be done from the main thread assert(wxThread::IsMain()); // Writing should only be done from the main thread
String name; String name;
UInt infix = 0; UInt infix = 0;
......
...@@ -98,7 +98,7 @@ class Package { ...@@ -98,7 +98,7 @@ class Package {
/// Creates a new, unique, filename with the specified prefix and suffix /// Creates a new, unique, filename with the specified prefix and suffix
/// for example newFileName("image/",".jpg") -> "image/1.jpg" /// for example newFileName("image/",".jpg") -> "image/1.jpg"
/// Returns the name of a temporary file that can be written to. /// Returns the name of a temporary file that can be written to.
String newFileName(const String& prefix, const String& suffix); FileName newFileName(const String& prefix, const String& suffix);
/// Signal that a file is still used by this package. /// Signal that a file is still used by this package.
/// Must be called for files not opened using openOut/nameOut /// Must be called for files not opened using openOut/nameOut
......
...@@ -66,7 +66,11 @@ typedef unsigned int UInt; ...@@ -66,7 +66,11 @@ typedef unsigned int UInt;
#define nullptr 0 #define nullptr 0
/// A string standing for a filename, has different behaviour when reading/writing /// A string standing for a filename, has different behaviour when reading/writing
class FileName : public String {}; class FileName : public String {
public:
FileName() {}
FileName(const String& s) : String(s) {}
};
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment