Commit 7b570b21 authored by twanvl's avatar twanvl

rotation and style changing works

parent 11181f53
......@@ -80,6 +80,14 @@ void ReorderCardsAction::perform(bool to_undo) {
// ----------------------------------------------------------------------------- : Change stylesheet
String DisplayChangeAction::getName(bool to_undo) const {
assert(false);
return _("");
}
void DisplayChangeAction::perform(bool to_undo) {
assert(false);
}
String ChangeCardStyleAction::getName(bool to_undo) const {
return _("Change style");
......@@ -88,6 +96,7 @@ void ChangeCardStyleAction::perform(bool to_undo) {
swap(card->stylesheet, stylesheet);
}
String ChangeSetStyleAction::getName(bool to_undo) const {
return _("Change style (all cards)");
}
......
......@@ -76,8 +76,15 @@ class ReorderCardsAction : public CardListAction {
// ----------------------------------------------------------------------------- : Change stylesheet
/// An action that affects the rendering/display/look of a set or cards in the set
class DisplayChangeAction : public Action {
public:
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
};
/// Changing the style of a a card
class ChangeCardStyleAction : public Action {
class ChangeCardStyleAction : public DisplayChangeAction {
public:
ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet)
: card(card), stylesheet(stylesheet) {}
......@@ -91,7 +98,7 @@ class ChangeCardStyleAction : public Action {
};
/// Changing the style of a set to that of a card
class ChangeSetStyleAction : public Action {
class ChangeSetStyleAction : public DisplayChangeAction {
public:
ChangeSetStyleAction(Set& set, const CardP& card)
: set(set), card(card) {}
......
......@@ -32,7 +32,7 @@ Bitmap export_bitmap(const SetP& set, const CardP& card) {
// viewer.rotation.angle = 0;
// viewer.rotation.zoom = 1.0;
}
RealSize size = viewer.getRotation().getExternalRect().size();
RealSize size = viewer.getRotation().getExternalSize();
// create bitmap & dc
Bitmap bitmap(size.width, size.height);
if (!bitmap.Ok()) throw InternalError(_("Unable to create bitmap"));
......
......@@ -20,10 +20,7 @@ CardViewer::CardViewer(Window* parent, int id, long style)
wxSize CardViewer::DoGetBestSize() const {
wxSize ws = GetSize(), cs = GetClientSize();
if (set) {
StyleSheetP stylesheet = set->stylesheetFor(card);
if (stylesheet) {
return wxSize(stylesheet->card_width, stylesheet->card_height) + ws - cs;
}
return (wxSize)getRotation().getExternalSize() + ws - cs;
}
return cs;
}
......
......@@ -91,7 +91,7 @@ SetInfoEditor::SetInfoEditor(Window* parent, int id, long style)
{}
void SetInfoEditor::onChangeSet() {
setStyles(set->stylesheet->set_info_style);
setStyles(set->stylesheet, set->stylesheet->set_info_style);
setData(set->data);
}
......@@ -103,7 +103,7 @@ StylingEditor::StylingEditor(Window* parent, int id, long style)
void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) {
this->stylesheet = stylesheet;
setStyles(stylesheet->styling_style);
setStyles(set->stylesheet, stylesheet->styling_style);
setData(set->stylingDataFor(*stylesheet));
}
......
......@@ -56,7 +56,7 @@ void TextCtrl::setValue(String* value) {
// assign to this control
IndexMap<FieldP,StyleP> styles; styles.add(field, style);
IndexMap<FieldP,ValueP> values; values.add(field, value);
setStyles(styles);
setStyles(set->stylesheet, styles);
setData(values);
// determine required height
viewers.front()->getEditor()->determineSize();
......
......@@ -175,7 +175,7 @@ void CardsPanel::onCommand(int id) {
: id == ID_CARD_ROTATE_180 ? 180
: 270
);
//onRenderSettingsChange();
set->actions.tellListeners(DisplayChangeAction(),true);
break;
}
case ID_SELECT_COLUMNS: {
......@@ -196,8 +196,13 @@ bool CardsPanel::wantsToHandle(const Action&, bool undone) const {
return false;
}
void CardsPanel::onAction(const Action& action, bool undo) {
// TODO
void CardsPanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, DisplayChangeAction) {
// The style changed, maybe also the size of editor
Layout();
//if (current_panel) current_panel->Layout();
//fixMinWindowSize();
}
}
void CardsPanel::onRenderSettingsChange() {
......@@ -224,4 +229,5 @@ void CardsPanel::selectCard(const CardP& card) {
card_list->setCard(card);
editor->setCard(card);
notes->setValue(card ? &card->notes : nullptr);
Layout();
}
......@@ -83,11 +83,13 @@ void StylePanel::onStyleSelect(wxCommandEvent&) {
stylesheet = StyleSheetP();
}
set->actions.add(new ChangeCardStyleAction(card, stylesheet));
Layout();
}
}
void StylePanel::onUseForAll(wxCommandEvent&) {
set->actions.add(new ChangeSetStyleAction(*set, card));
Layout();
}
BEGIN_EVENT_TABLE(StylePanel, wxPanel)
......
......@@ -27,6 +27,7 @@
#include <data/card.hpp>
#include <data/settings.hpp>
#include <data/format/formats.hpp>
#include <data/action/set.hpp>
DECLARE_TYPEOF_COLLECTION(SetWindowPanel*);
DECLARE_TYPEOF_COLLECTION(SetWindow*);
......@@ -231,11 +232,11 @@ void SetWindow::onChangeSet() {
}
void SetWindow::onAction(const Action& action, bool undone) {
// TYPE_CASE_(action, SetStyleChange) {
// // The style changed, maybe also the size of the viewer
// Layout();
// fixMinWindowSize();
// }
TYPE_CASE_(action, DisplayChangeAction) {
// The style changed, maybe also the size of card viewers
if (current_panel) current_panel->Layout();
fixMinWindowSize();
}
}
......@@ -517,13 +518,10 @@ void SetWindow::onReplaceAll(wxFindDialogEvent&) {
void SetWindow::onEditPreferences(wxCommandEvent&) {
PreferencesWindow wnd(this);
wnd.ShowModal();
// if (wnd.ShowModal() == wxID_OK) {
// // render settings may have changed, notify all windows
// FOR_EACH(m, setWindows) {
// m->onRenderSettingsChange();
// }
// }
if (wnd.ShowModal() == wxID_OK) {
// render settings may have changed, notify all windows
set->actions.tellListeners(DisplayChangeAction(),true);
}
}
......
......@@ -14,6 +14,8 @@
#include <data/field.hpp>
#include <data/settings.hpp>
#include <data/action/value.hpp>
#include <data/action/set.hpp>
#include <gui/util.hpp> // clearDC
DECLARE_TYPEOF_COLLECTION(ValueViewerP);
typedef IndexMap<FieldP,StyleP> IndexMap_FieldP_StyleP;
......@@ -25,17 +27,14 @@ DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP);
// ----------------------------------------------------------------------------- : Drawing
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, set->stylesheet->card_background);
RotatedDC rdc(dc, ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), ss.card_anti_alias() && !nativeLook(), true);
draw(rdc, stylesheet->card_background);
}
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(background);
dc.DrawRectangle(dc.getInternalRect());
clearDC(dc.getDC(), background);
// update style scripts
if (card) set->updateFor(card);
// draw values
......@@ -59,9 +58,8 @@ ValueViewer* DataViewer::focusedViewer() const { return nullptr; }
Context& DataViewer::getContext() const { return set->getContext(); }
Rotation DataViewer::getRotation() const {
StyleSheetP stylesheet = set->stylesheetFor(card);
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom());
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), true);
}
// ----------------------------------------------------------------------------- : Setting data
......@@ -70,7 +68,8 @@ void DataViewer::setCard(const CardP& card) {
if (!card) return; // TODO: clear editor?
assert(set);
this->card = card;
setStyles(set->stylesheet->card_style);
stylesheet = set->stylesheetFor(card);
setStyles(stylesheet, stylesheet->card_style);
setData(card->data);
}
......@@ -82,11 +81,12 @@ struct CompareViewer {
}
};
void DataViewer::setStyles(IndexMap<FieldP,StyleP>& styles) {
void DataViewer::setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles) {
if (!viewers.empty() && styles.contains(viewers.front()->getStyle())) {
// already using these styles
return;
}
this->stylesheet = stylesheet;
// create viewers
viewers.clear();
FOR_EACH(s, styles) {
......@@ -117,6 +117,11 @@ ValueViewerP DataViewer::makeViewer(const StyleP& style) {
}
void DataViewer::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, DisplayChangeAction) {
// refresh
setCard(card);
return;
}
TYPE_CASE(action, ValueAction) {
FOR_EACH(v, viewers) {
if (v->getValue() == action.valueP) {
......
......@@ -22,9 +22,6 @@ class Context;
/// A viewer can generate an image of some values, usually a card.
class DataViewer : public SetView {
public:
/// Rotation and zoom to use when drawing
// Rotation rotation;
// --------------------------------------------------- : Drawing
/// Draw the current (card/data) to the given dc
......@@ -63,7 +60,7 @@ class DataViewer : public SetView {
// --------------------------------------------------- : The viewers
protected:
/// Set the styles for the data to be shown, recreating the viewers
void setStyles(IndexMap<FieldP,StyleP>& styles);
void setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles);
/// Set the data to be shown in the viewers, refresh them
void setData(IndexMap<FieldP,ValueP>& values);
......@@ -82,6 +79,8 @@ class DataViewer : public SetView {
vector<ValueViewerP> viewers; ///< The viewers for the different values in the data
CardP card; ///< The card that is currently displayed, if any
public:
StyleSheetP stylesheet; ///< Stylesheet being used
};
// ----------------------------------------------------------------------------- : EOF
......
......@@ -23,12 +23,12 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
ScriptableImage& img = it->second;
ScriptImageP i;
if (nativeLook()) {
i = img.update(viewer.getContext(), *getSet().stylesheet, 16, 16, ASPECT_BORDER, false);
i = img.update(viewer.getContext(), *viewer.stylesheet, 16, 16, ASPECT_BORDER, false);
} else if(style().render_style & RENDER_TEXT) {
// also drawing text
i = img.update(viewer.getContext(), *getSet().stylesheet, 0, 0);
i = img.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
} else {
i = img.update(viewer.getContext(), *getSet().stylesheet,
i = img.update(viewer.getContext(), *viewer.stylesheet,
dc.trS(style().width), dc.trS(style().height),
style().alignment == ALIGN_STRETCH ? ASPECT_STRETCH : ASPECT_FIT
);
......
......@@ -17,12 +17,15 @@ int constrain_angle(int angle) {
return (a / 90) * 90; // multiple of 90
}
Rotation::Rotation(int angle, const RealRect& rect, double zoom)
Rotation::Rotation(int angle, const RealRect& rect, double zoom, bool is_internal)
: angle(constrain_angle(angle))
, size(rect.size())
, origin(rect.position())
, zoom(zoom)
{
if (is_internal) {
size = trNoNeg(size);
}
// set origin
if (revX()) origin.x += size.width;
if (revY()) origin.y += size.height;
......@@ -108,12 +111,12 @@ Rotater::~Rotater() {
// ----------------------------------------------------------------------------- : RotatedDC
RotatedDC::RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality)
: Rotation(angle, rect, zoom)
RotatedDC::RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality, bool is_internal)
: Rotation(angle, rect, zoom, is_internal)
, dc(dc), high_quality(high_quality)
{}
RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, bool high_quality = false)
RotatedDC::RotatedDC(DC& dc, const Rotation& rotation, bool high_quality)
: Rotation(rotation)
, dc(dc), high_quality(high_quality&&false)
{}
......
......@@ -22,9 +22,11 @@
*/
class Rotation {
public:
/// Construct a rotation object with the given rectangle of external coordinates
/// and a given rotation angle and zoom factor
Rotation(int angle, const RealRect& rect, double zoom = 1.0);
/// Construct a rotation object
/** with the given rectangle of external coordinates and a given rotation angle and zoom factor.
* if is_internal then the rect gives the internal coordinates, its origin should be (0,0)
*/
Rotation(int angle, const RealRect& rect, double zoom = 1.0, bool is_internal = false);
/// Change the zoom factor
inline void setZoom(double z) { zoom = z; }
......@@ -34,6 +36,8 @@ class Rotation {
inline RealSize getInternalSize() const { return trInvNoNeg(size); }
/// The intarnal rectangle (origin at (0,0))
inline RealRect getInternalRect() const { return RealRect(RealPoint(0,0), getInternalSize()); }
/// The size of the external rectangle (as passed to the constructor) == trNoNeg(getInternalSize())
inline RealSize getExternalSize() const { return size; }
/// The external rectangle (as passed to the constructor) == trNoNeg(getInternalRect())
RealRect getExternalRect() const;
......@@ -120,7 +124,7 @@ class Rotater {
*/
class RotatedDC : public Rotation {
public:
RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality);
RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, bool high_quality, bool is_internal = false);
RotatedDC(DC& dc, const Rotation& rotation, bool high_quality);
// --------------------------------------------------- : Drawing
......
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