diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-10-12 11:13:09 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-11-27 11:33:10 +0100 |
commit | d464d505fbf6e53a38afdd3661d320fac8c760d6 (patch) | |
tree | 3bf7db8591172bf948198f19d36df5df886486bb /include/svx/sdr/contact | |
parent | 3e1e2b6687b0259ae28441cc0d314de0d908776b (diff) |
Refactor calc non-linear ViewToDevice transform
This change solves the non-linear World-To-View trans-
formation that calc uses due to it's screen rendering
as good as currently possible (AFAIK).
Calcv view is layouted on pixel base (due to better
homogen distances and full pixel lines between cells),
but this leads to having a non-linear transformation
between discrete units (pixels, view) and model coordinates
(World). In principle, each cell has it's own (so called)
ViewTransformation -> the position on screen depends on
the mappings of all cells top/left from it. This is
obvioulsly non-linear and can sometimes be seen by
producing 'offset' errors when many cells (small and thin)
are shown in low zoom stages.
No better solution for this comes to mind easily. The
extremes are - on the one hand AntiAliasing the whole
calc edit view and accept 'unsharp/AAed' lines - on the
other hand what we have now.
Maybe a future solution could find a mapping that gets
close to linear mapping for the full view. On the long
run this state is hard to keep correct. Even with this
extended solution the mapping of SdrObjects spawning
mutiple cells is assumed 'linear' in that area - which
is in reality currently not the case (!)
Note: This is only true for the screen visualization,
print and/or PDF export do not do that pixel-based
layouting.
Note2: This mechanism is general in DrawingLayer (look
for '.*GridOffset.*'. If it is deactivated by providing
no offsets, the result is the unchanged, linear mapping.
First step: Add interfaces to get a possible GridOffset
at ViewObjectContact. There it belongs, we have a view-
dependent offset per object and view. Add mechanisms to
create on-demand and reach back to the view (aka calc's
derivation of it).
Second step: Implement the on-demand creation, adapt to
use it in ViewObjectContact::getPrimitive2DSequence, add
stuff to reset on zoom change, disable temporarily old
mechanism -> paint already works. Need to adapt the
places from old mechanism where the GridOffset was used,
but no longer the geometry creations.
Third step: Isolated and disabled old mechanism (by
already removing SetGridOffset). Marked all places that
possibly need change with '//Z' tag. Main work now will
be to adapt in the SdrView implementations in svx to know
about having a SdrObject-dependent ViewTransformation
at all (currently not known, was hard-coded at some places
from the old code, ViewTransformation set as MapMode at
a target OutputDevice, not member at SdrView at all...).
Fourth step: Adapt the Handles and OverlayObjects to
use an evtl. existing GridOffset. The mechanism is that
the SdrHdl(s) can be seen as 'Model-Objects', these get
converted to OverlayObjects in the ::CreateB2dIAObject()
implementations, for all SdrMarkView and SdrPageView,
so this is the place where the ObjectContact is known
(the SdrPageWindow *is* a ObjectContact) and the view-
dependent GridOffset can be calculated per SdrObject.
I modified OverlayObject to be able to work with a
set Offset that embeds the created visualization using
this additionally.
Handles get now correctly set and have a working HitTest
(due to that already using the primitives). Some inter-
action stuff already working, some will need more
adaption. We simply have no concept for this stuff...
Refactored to not get dependencies to SdrObject in
ObjectContact.
Fifth Step: Make HitTest work by adding the View-And-
Object dependent GridOffset in the View when HitTest
is triggered. This is in SdrMarkView::CheckSingleSdrObjectHit
where pObj->GetCurrentBoundRect() is used that gets the
view-independent form. To make HitTest work, add a possible
GridOffset.
Since this will be necessary more often in SdrView hierarchy,
added a tooling method (getPossibleGridOffsetForSdrObject)
at that level after checking that at that level will be
reachable at all potential spots.
Inside that method the correct ObjectContact will be identified
and the object-specific offset requested there.
Sixth Step: Adaptions and started some cleanups. Still some
adaptions needed:
- After creation of new object, need to relocate from
used GridOffset setting to WorldCoordinates
- Interactions, e.g. start with dragging handles or full
object/points
Seventh Step: React on EndCreateObj. Here, the created
SdrObject is in model coordinates and needs to be adapted
to evtl. GridOffset. This is 'tricky' due to calculating
the possible offset based on new coordinates 'close'
to the target position, but may be in the wrong cell.
Nonetheless this is the best we can do here.
Last (hopefully) missing are now all interaction
viszualizations. They already work and are applied
correctly, but wrong visualized.
Have taken the time to unify adding OverlayObjects for
selection visualization to OverlayManager, see
handleNewOverlayObject. This does all needed when adding
OverlayObjects in one place where the GridOffset can
also be handled. It makles things more safe - not possible
to forget one of the three steps for others.
Eighth Step: Do the same unification for creating the
OverlayGeometry, also rename methods to make usage more
clear. We now have
SdrHdl::insertNewlyCreatedOverlayObjectForSdrHdl
SdrDragMethod::insertNewlyCreatedOverlayObjectForSdrDragMethod
which can do the needed GridOffset changes centralized.
Needed to get a ObjectContact for this at SdrDragMethod,
so adapted ::CreateOverlayGeometry implementations
accordingly. Missing is now the implementation in
insertNewlyCreatedOverlayObjectForSdrDragMethod to add
the GridOffset - if used. This has no SdrObject at this
time, so we will need a fallback to do the same using a
Range (Rectangle). The stuff doing this for SdrObject
already has a fallback and is based on using the Rectangle
from the SdrObject anyways, so this will be possible.
Ninth Step: Cleanup of old stuff (no more //Z), adapted
some usages of OverlayObject creations to use
getViewIndependentPrimitive2DContainer instead of the
view dependent parts so that offset applied to
drag-overlays is correct and not already added. Adapted
insertNewlyCreatedOverlayObjectForSdrDragMethod to use
calculateGridOffsetForB2DRange. Use now that instead of
SdrObject-based approach in calc - is more generic.
Getting closer, but still not complete - there is an
error with dragging the grepped handle somehow - the
offset for drag is somehow wrong.
Tenth Step: Corrected that offset error. Of course at
interaction start and progress (move) the coordinates
are in GrifOffset coordinates and need to be corrected
to Model coordinates. Done that at ::BegDragObj and
::MovDragObj, works well.
Of course there are exceptions for the crop-handles, so
needed to add setting the correct parameters at SdrHdl
when these got created, then all works as expected.
The strategy is to *not* change the model data itself
in any way, instead do all changes/adaptions in the
view-only code. This has minimal impact and is needed
due to having a 1:n relationship between model and
views anyways.
There are two directions: All visualizations are adapted
to take the GridOffset into account (SdrObjects, overlay,
handles, InteractionObjects, ...). In the other direction
input like MousePosition is in principle in calc EditView
in 'GridOffset'-coordinates and needs to be mapped back
before usage.
Change-Id: I2ecdd409def96a7248a26a65a22e59eb962880a0
Reviewed-on: https://gerrit.libreoffice.org/64057
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
Diffstat (limited to 'include/svx/sdr/contact')
-rw-r--r-- | include/svx/sdr/contact/objectcontact.hxx | 10 | ||||
-rw-r--r-- | include/svx/sdr/contact/objectcontactofpageview.hxx | 120 | ||||
-rw-r--r-- | include/svx/sdr/contact/viewobjectcontact.hxx | 7 |
3 files changed, 137 insertions, 0 deletions
diff --git a/include/svx/sdr/contact/objectcontact.hxx b/include/svx/sdr/contact/objectcontact.hxx index d305d61b007d..dd1606e380fd 100644 --- a/include/svx/sdr/contact/objectcontact.hxx +++ b/include/svx/sdr/contact/objectcontact.hxx @@ -163,6 +163,16 @@ public: // wanted (like in such cases) this method is used. It will reuse the current // ViewInformation2D, but clear the ViewPort (no ViewPort means all is visible) void resetViewPort(); + + // interface to support GridOffset for non-linear ViewToDevice transformation (calc) + virtual bool supportsGridOffsets() const; + virtual void calculateGridOffsetForViewOjectContact( + basegfx::B2DVector& rTarget, + const ViewObjectContact& rClient) const; + virtual void calculateGridOffsetForB2DRange( + basegfx::B2DVector& rTarget, + const basegfx::B2DRange& rB2DRange) const; + void resetAllGridOffsets(); }; }} diff --git a/include/svx/sdr/contact/objectcontactofpageview.hxx b/include/svx/sdr/contact/objectcontactofpageview.hxx new file mode 100644 index 000000000000..020b454cce87 --- /dev/null +++ b/include/svx/sdr/contact/objectcontactofpageview.hxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SVX_INC_SDR_CONTACT_OBJECTCONTACTOFPAGEVIEW_HXX +#define INCLUDED_SVX_INC_SDR_CONTACT_OBJECTCONTACTOFPAGEVIEW_HXX + +#include <svx/sdr/contact/objectcontact.hxx> +#include <vcl/idle.hxx> + +class SdrPageWindow; +class SdrPage; + +namespace sdr +{ + namespace contact + { + class SVX_DLLPUBLIC ObjectContactOfPageView : public ObjectContact, public Idle + { + // the owner of this ObjectContactOfPageView. Set from constructor and not + // to be changed in any way. + SdrPageWindow& mrPageWindow; + + // Process the whole displaying, the real version + void DoProcessDisplay(DisplayInfo& rDisplayInfo); + + public: + // access to SdrPageWindow + SdrPageWindow& GetPageWindow() const { return mrPageWindow; } + + // access to SdrPage of PageView + SdrPage* GetSdrPage() const; + + // basic constructor, used from SdrPageView. + explicit ObjectContactOfPageView(SdrPageWindow& rPageWindow, + const sal_Char *pDebugName); + virtual ~ObjectContactOfPageView() override; + + // LazyInvalidate request. This is used from the VOCs to mark that they + // got invalidated by an ActionChanged() call. An active view needs to remember + // this and take action on it. Default implementation directly calls back + // triggerLazyInvalidate() which promptly handles the request + virtual void setLazyInvalidate(ViewObjectContact& rVOC) override; + + // call this to support evtl. preparations for repaint + virtual void PrepareProcessDisplay() override; + + // From baseclass Timer, the timeout call triggered by the LazyInvalidate mechanism + virtual void Invoke() final override; + + // Process the whole displaying + virtual void ProcessDisplay(DisplayInfo& rDisplayInfo) override; + + // test if visualizing of entered groups is switched on at all + virtual bool DoVisualizeEnteredGroup() const override; + + // get active group's (the entered group) ViewContact + virtual const ViewContact* getActiveViewContact() const override; + + // Invalidate given rectangle at the window/output which is represented by + // this ObjectContact. + virtual void InvalidatePartOfView(const basegfx::B2DRange& rRange) const override; + + // Get info about the need to visualize GluePoints. The default + // is that it is not necessary. + virtual bool AreGluePointsVisible() const override; + + // check if text animation is allowed. + virtual bool IsTextAnimationAllowed() const override; + + // check if graphic animation is allowed. + virtual bool IsGraphicAnimationAllowed() const override; + + // print? Default is false + virtual bool isOutputToPrinter() const override; + + // recording MetaFile? Default is false + virtual bool isOutputToRecordingMetaFile() const override; + + // pdf export? Default is false + virtual bool isOutputToPDFFile() const override; + + // gray display mode + virtual bool isDrawModeGray() const override; + + // high contrast display mode + virtual bool isDrawModeHighContrast() const override; + + // override access to SdrPageView + virtual SdrPageView* TryToGetSdrPageView() const override; + + // access to OutputDevice. May return 0L like the default implementations do. Override as needed. + virtual OutputDevice* TryToGetOutputDevice() const override; + + /** sets all UNO controls which are associated with this ObjectContact to + design or alive mode. + */ + void SetUNOControlsDesignMode( bool _bDesignMode ) const; + }; + } // end of namespace contact +} // end of namespace sdr + +#endif // INCLUDED_SVX_INC_SDR_CONTACT_OBJECTCONTACTOFPAGEVIEW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/sdr/contact/viewobjectcontact.hxx b/include/svx/sdr/contact/viewobjectcontact.hxx index ce17890ee93d..a6d929c6c203 100644 --- a/include/svx/sdr/contact/viewobjectcontact.hxx +++ b/include/svx/sdr/contact/viewobjectcontact.hxx @@ -58,6 +58,9 @@ private: // the PrimitiveAnimation if Primitive2DContainer contains animations std::unique_ptr<sdr::animation::PrimitiveAnimation> mpPrimitiveAnimation; + // possible on-demand calculated GridOffset for non-linear ViewToDevice transformation (calc) + basegfx::B2DVector maGridOffset; + // This bool gets set when the object gets invalidated by ActionChanged() and // can be used from the OC to late-invalidates bool mbLazyInvalidate : 1; @@ -124,6 +127,10 @@ public: // just process the sub-hierarchy, used as tooling from getPrimitive2DSequenceHierarchy drawinglayer::primitive2d::Primitive2DContainer getPrimitive2DSequenceSubHierarchy(DisplayInfo& rDisplayInfo) const; + + // interface to support GridOffset for non-linear ViewToDevice transformation (calc) + const basegfx::B2DVector& getGridOffset() const; + void resetGridOffset(); }; }} |