Commit be4009b6 authored by twanvl's avatar twanvl

added SymbolValueEditor + minor fixes

parent 263c2ca9
......@@ -150,7 +150,7 @@ class ControlPointAddAction : public Action {
// ----------------------------------------------------------------------------- : Remove control point
/// 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);
......
......@@ -203,7 +203,7 @@ void GraphControl::setData(const GraphDataPre& data) {
void GraphControl::setData(const GraphDataP& data) {
if (graph) {
graph->setData(data);
current_item.clear(); // TODO : preserver selection
current_item.clear(); // TODO : preserve selection
Refresh(false);
}
}
......
......@@ -201,7 +201,7 @@ void SymbolControl::onSize(wxSizeEvent& ev) {
Refresh(false);
}
void SymbolControl::onUpdateUI(wxUpdateUIEvent& ev) {
if (!editor) return;
if (!editor) return;
switch (ev.GetId()) {
case ID_MODE_SELECT: case ID_MODE_ROTATE: case ID_MODE_POINTS: case ID_MODE_SHAPES: //case ID_MODE_PAINT:
ev.Check(editor->modeToolId() == ev.GetId());
......
......@@ -10,8 +10,12 @@
#include <gui/symbol/control.hpp>
#include <gui/symbol/part_list.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/io/reader.hpp>
#include <util/error.hpp>
#include <wx/filename.h>
#include <wx/wfstream.h>
......@@ -29,7 +33,7 @@ SymbolPartP defaultSymbolPart(double d) {
}
// A default symbol, a square
SymbolP defaultSymbol() {
SymbolP default_symbol() {
SymbolP symbol = new_shared<Symbol>();
symbol->parts.push_back(defaultSymbolPart(0));
return symbol;
......@@ -38,12 +42,29 @@ SymbolP defaultSymbol() {
// ----------------------------------------------------------------------------- : Constructor
SymbolWindow::SymbolWindow(Window* parent) {
init(parent, defaultSymbol());
init(parent, default_symbol());
}
SymbolWindow::SymbolWindow(Window* parent, String filename) {
// TODO
init(parent, defaultSymbol());
SymbolWindow::SymbolWindow(Window* parent, const String& filename) {
// TODO : open file
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) {
......@@ -122,12 +143,17 @@ void SymbolWindow::init(Window* parent, SymbolP symbol) {
s->Add(v, 0, wxEXPAND);
s->Add(control, 1, wxEXPAND);
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
void SymbolWindow::onFileNew(wxCommandEvent& ev) {
SymbolP symbol = defaultSymbol();
SymbolP symbol = default_symbol();
parts->setSymbol(symbol);
control->setSymbol(symbol);
}
......@@ -151,12 +177,25 @@ void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
}
void SymbolWindow::onFileSave(wxCommandEvent& ev) {
// TODO
onFileSaveAs(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) {
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) {
......@@ -191,7 +230,7 @@ void SymbolWindow::onUpdateUI(wxUpdateUIEvent& ev) {
switch(ev.GetId()) {
// file menu
case ID_FILE_STORE: {
// ev.Enable(value);
ev.Enable(value);
break;
// undo/redo
} case ID_EDIT_UNDO: {
......
......@@ -9,13 +9,14 @@
// ----------------------------------------------------------------------------- : Includes
#include "../../util/prec.hpp"
#include <util/prec.hpp>
#include <data/symbol.hpp>
#include <wx/listctrl.h>
//#include "control.hpp"
class SymbolControl;
class SymbolPartList;
DECLARE_POINTER_TYPE(SymbolValue);
DECLARE_POINTER_TYPE(Set);
// ----------------------------------------------------------------------------- : SymbolWindow
......@@ -25,9 +26,9 @@ class SymbolWindow : public Frame {
/// Construct a SymbolWindow
SymbolWindow(Window* parent);
/// Construct a SymbolWindow showing a symbol from a file
SymbolWindow(Window* parent, String filename);
// /// Construct a SymbolWindow showing a symbol from a set
// SymbolWindow(Window* parent);
SymbolWindow(Window* parent, const String& filename);
// /// Construct a SymbolWindow showing a symbol value in a set
SymbolWindow(Window* parent, const SymbolValueP& value, const SetP& set);
private:
// --------------------------------------------------- : Children
......@@ -39,8 +40,8 @@ class SymbolWindow : public Frame {
SymbolPartList* parts; ///< A list of parts in the symbol
// when editing a symbol field
// SymbolValueP value
// SetP set
SymbolValueP value;
SetP set;
// --------------------------------------------------- : Event handling
DECLARE_EVENT_TABLE();
......
......@@ -112,5 +112,5 @@ void ChoiceValueEditor::determineSize() {
}
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() {
}
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() {
Color c = wxGetColourFromUser(0, value().value());
......
......@@ -7,7 +7,18 @@
// ----------------------------------------------------------------------------- : Includes
#include <gui/value/symbol.hpp>
#include <gui/symbol/window.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : SymbolValueEditor
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 @@
class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
public:
DECLARE_VALUE_EDITOR(Symbol);
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&);
virtual void determineSize();
};
// ----------------------------------------------------------------------------- : EOF
......
......@@ -20,6 +20,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
public:
DECLARE_VALUE_EDITOR(Text);
// virtual void determineSize();
};
// ----------------------------------------------------------------------------- : EOF
......
......@@ -95,9 +95,8 @@ void DataViewer::setStyles(IndexMap<FieldP,StyleP>& styles) {
(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 //%%%
if (!viewers.back()) viewers.pop_back();
ValueViewerP viewer = makeViewer(s);
if (viewer) viewers.push_back(viewer);
}
}
// sort viewers by z-index of style
......
......@@ -28,7 +28,7 @@ void filter_symbol(Image& symbol, const SymbolFilter& filter) {
AColor result = filter.color((double)x / width, (double)y / height, point);
// Store color
data[0] = result.Red();
data[2] = result.Green();
data[1] = result.Green();
data[2] = result.Blue();
alpha[0] = result.alpha;
// next
......
......@@ -18,7 +18,8 @@ Image render_symbol(const SymbolP& symbol, double border_radius, int size) {
Bitmap bmp(size, size);
wxMemoryDC dc;
dc.SelectObject(bmp);
clearDC_black(dc);
clearDC(dc, Color(0,128,0));
viewer.rotation.setZoom(size);
viewer.draw(dc);
dc.SelectObject(wxNullBitmap);
return bmp.ConvertToImage();
......@@ -28,7 +29,7 @@ Image render_symbol(const SymbolP& symbol, double border_radius, int size) {
SymbolViewer::SymbolViewer(const SymbolP& symbol, double border_radius)
: border_radius(border_radius)
, rotation(0, RealRect(0,0,500,500))
, rotation(0, RealRect(0,0,500,500), 500)
{
setSymbol(symbol);
}
......
......@@ -79,12 +79,15 @@ class ValueViewer {
// ----------------------------------------------------------------------------- : Utility
#define DECLARE_VALUE_VIEWER(Type) \
protected: \
inline Type##Style& style() const { return static_cast< Type##Style&>(*styleP); } \
inline const Type##Value& value() const { return static_cast<const Type##Value&>(*valueP); } \
inline const Type##Field& field() const { return style().field(); } \
public: \
#define DECLARE_VALUE_VIEWER(Type) \
protected: \
inline Type##Style& style() const { return static_cast< Type##Style&>(*ValueViewer::styleP); } \
inline const Type##Value& value() const { return static_cast<const Type##Value&>(*ValueViewer::valueP); } \
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: \
Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style)
......
......@@ -217,18 +217,21 @@ void ScriptManager::alsoUpdate(deque<ToUpdate>& to_update, const vector<Dependen
}
break;
} case DEP_CARDS_FIELD: {
// TODO
break;
} case DEP_STYLE: {
// TODO
break;
} case DEP_CARD_COPY_DEP: {
// TODO
break;
} case DEP_SET_COPY_DEP: {
// TODO
break;
} default:
assert(false);
}
/*
if (d.type == DependendScript.setField) {
/* if (d.type == DependendScript.setField) {
// from set data
ValueP value = set->data.at(ds.index);
toUpdate.push_back(ToUpdate(&*value));
......
......@@ -43,6 +43,7 @@ void ActionStack::add(Action* action, bool allow_merge) {
void ActionStack::undo() {
assert(canUndo());
if (!canUndo()) return;
Action* action = undo_actions.back();
action->perform(true);
tellListeners(*action, true);
......@@ -52,6 +53,7 @@ void ActionStack::undo() {
}
void ActionStack::redo() {
assert(canRedo());
if (!canRedo()) return;
Action* action = redo_actions.back();
action->perform(false);
tellListeners(*action, false);
......
......@@ -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
String name;
UInt infix = 0;
......
......@@ -98,7 +98,7 @@ class Package {
/// Creates a new, unique, filename with the specified prefix and suffix
/// for example newFileName("image/",".jpg") -> "image/1.jpg"
/// 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.
/// Must be called for files not opened using openOut/nameOut
......
......@@ -66,7 +66,11 @@ typedef unsigned int UInt;
#define nullptr 0
/// 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
#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