├── cmath.cpp ├── variant.cpp ├── Windows ├── vector.cpp ├── point.cpp ├── Ink │ ├── stylustip.cpp │ ├── drawingflags.cpp │ ├── applicationgesture.cpp │ ├── gesturerecognitionresult.cpp │ ├── stylustip.h │ ├── Ink.pri │ ├── extendedproperty.cpp │ ├── gesturerecognitionresult.h │ └── drawingflags.h ├── Input │ ├── inputdevice.cpp │ ├── mousebuttonstate.cpp │ ├── querycursoreventargs.cpp │ ├── StylusPlugIns │ │ ├── StylusPlugIns.pri │ │ ├── rawstylusactions.cpp │ │ └── rawstylusactions.h │ ├── mousebuttonstate.h │ ├── inputeventargs.cpp │ ├── styluspointproperty.cpp │ ├── pencontexts.h │ ├── inputdevice.h │ ├── Input.pri │ ├── inputeventargs.h │ ├── querycursoreventargs.h │ ├── styluspointpropertyinfo.cpp │ ├── styluspointproperty.h │ ├── mousedevice.h │ ├── styluspointpropertyinfo.h │ ├── styluseventargs.cpp │ ├── styluspointproperties.h │ ├── pencontexts.cpp │ └── stylusdevice.h ├── Media │ ├── hittestresult.cpp │ ├── drawingcontext.cpp │ ├── pointhittestparameters.cpp │ ├── hittestparameters.cpp │ ├── streamgeometrycontext.cpp │ ├── hittestparameters.h │ ├── pointhittestresult.cpp │ ├── drawingvisual.h │ ├── matrix.cpp │ ├── pointhittestparameters.h │ ├── Media.pri │ ├── hittestresult.h │ ├── containervisual.h │ ├── pointhittestresult.h │ ├── streamgeometry.h │ ├── visual.h │ ├── containervisual.cpp │ ├── drawingvisual.cpp │ ├── visual.cpp │ ├── streamgeometry.cpp │ ├── drawing.h │ └── geometry.h ├── Controls │ ├── editingmode.cpp │ ├── inkcanvasselectionhitresult.cpp │ ├── Controls.pri │ ├── inkcanvasselectionhitresult.h │ ├── editingmode.h │ ├── decorator.h │ └── decorator.cpp ├── size.cpp ├── propertymetadata.cpp ├── propertymetadata.h ├── rect.cpp ├── dispatcher.h ├── dispatcher.cpp ├── Windows.pri ├── dependencyproperty.cpp ├── dependencyobject.cpp ├── dependencyobject.h └── dependencyproperty.h ├── Collections ├── Generic │ ├── array.cpp │ ├── list.cpp │ ├── Generic.pri │ └── array.h ├── ObjectModel │ ├── collection.cpp │ ├── ObjectModel.pri │ └── collection.h ├── Specialized │ ├── notifycollectionchangedeventargs.cpp │ └── Specialized.pri └── Collections.pri ├── Internal ├── doubleutil.cpp ├── Ink │ ├── serializationflags.cpp │ ├── contoursegment.cpp │ ├── elementsclipboarddata.cpp │ ├── inkcanvasclipboardformat.cpp │ ├── GestureRecognition │ │ └── GestureRecognition.pri │ ├── quad.cpp │ ├── InkSerializedFormat │ │ ├── transformdescriptor.h │ │ ├── strokedescriptor.h │ │ ├── strokedescriptor.cpp │ │ ├── transformdescriptor.cpp │ │ ├── InkSerializedFormat.pri │ │ ├── algomodule.cpp │ │ ├── algomodule.h │ │ ├── metricblock.h │ │ ├── serializationhelper.h │ │ └── guidlist.h │ ├── serializationflags.h │ ├── inkcanvasclipboardformat.h │ ├── strokefindices.cpp │ ├── strokenodedata.cpp │ ├── strokenodedata.h │ ├── textclipboarddata.h │ ├── contoursegment.h │ ├── textclipboarddata.cpp │ ├── quad.h │ ├── elementsclipboarddata.h │ ├── Ink.pri │ ├── isfclipboarddata.h │ ├── erasingstroke.h │ └── lassohelper.h ├── finallyhelper.cpp ├── Controls │ ├── Controls.pri │ └── inkcanvasfeedbackadorner.h ├── Internal.pri ├── finallyhelper.h ├── debug.h ├── debug.cpp └── matrixutil.h ├── mshwgst.dll ├── mshwgst.exp ├── mshwgst.lib ├── Activities ├── Activities.pri └── Presentation │ ├── clipboarddata.cpp │ ├── Presentation.pri │ └── clipboarddata.h ├── InkCanvasJni.version ├── guid.cpp ├── inkcanvas.qrc ├── eventargs.cpp ├── Landing ├── Landing.pri ├── Android │ ├── Android.pri │ ├── inkcanvasandroid.h │ ├── java │ │ └── com │ │ │ └── tal │ │ │ └── inkcanvas │ │ │ └── Stroke.java │ └── androidstreamgeometrycontext.h ├── Ios │ ├── Ios.pri │ ├── strokewrapper.h │ ├── inkcanvasios.h │ ├── uibezierpathwrapper.h │ ├── inkcanvasios.m │ ├── iosstreamgeometrycontext.h │ └── uibezierpathwrapper.m ├── Macos │ ├── Macos.pri │ ├── strokewrapper.h │ ├── inkcanvasmacos.h │ ├── nsbezierpathwrapper.h │ ├── inkcanvasmacos.m │ ├── macosstreamgeometrycontext.h │ └── nsbezierpathwrapper.m └── Qt │ ├── Qt.pri │ ├── inkcanvasqt.h │ ├── qtstreamgeometrycontext.h │ └── qtpainterdrawingcontext.h ├── .gitlab-ci.yml ├── single.cpp ├── double.cpp ├── README.md ├── mshwgst.def ├── propgetset.awk ├── eraser.svg ├── sharedptr.h ├── erasercursor.svg ├── conanfile.py ├── cmath.h ├── eventargs.h ├── single.h ├── InkCanvas_global.h ├── double.h └── InkCanvas.pro /cmath.cpp: -------------------------------------------------------------------------------- 1 | #include "cmath.h" 2 | -------------------------------------------------------------------------------- /variant.cpp: -------------------------------------------------------------------------------- 1 | #include "variant.h" 2 | -------------------------------------------------------------------------------- /Windows/vector.cpp: -------------------------------------------------------------------------------- 1 | #include "vector.h" 2 | -------------------------------------------------------------------------------- /Windows/point.cpp: -------------------------------------------------------------------------------- 1 | #include "point.h" 2 | 3 | -------------------------------------------------------------------------------- /Collections/Generic/array.cpp: -------------------------------------------------------------------------------- 1 | #include "array.h" 2 | -------------------------------------------------------------------------------- /Collections/Generic/list.cpp: -------------------------------------------------------------------------------- 1 | #include "list.h" 2 | -------------------------------------------------------------------------------- /Internal/doubleutil.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/doubleutil.h" 2 | -------------------------------------------------------------------------------- /Collections/ObjectModel/collection.cpp: -------------------------------------------------------------------------------- 1 | #include "collection.h" 2 | -------------------------------------------------------------------------------- /Windows/Ink/stylustip.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Ink/stylustip.h" 2 | -------------------------------------------------------------------------------- /Internal/Ink/serializationflags.cpp: -------------------------------------------------------------------------------- 1 | #include "serializationflags.h" 2 | -------------------------------------------------------------------------------- /Internal/finallyhelper.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/finallyhelper.h" 2 | 3 | -------------------------------------------------------------------------------- /Windows/Ink/drawingflags.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Ink/drawingflags.h" 2 | -------------------------------------------------------------------------------- /Windows/Input/inputdevice.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/inputdevice.h" 2 | -------------------------------------------------------------------------------- /Windows/Media/hittestresult.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/hittestresult.h" 2 | -------------------------------------------------------------------------------- /mshwgst.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmguo/QtInkCanvas/HEAD/mshwgst.dll -------------------------------------------------------------------------------- /mshwgst.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmguo/QtInkCanvas/HEAD/mshwgst.exp -------------------------------------------------------------------------------- /mshwgst.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cmguo/QtInkCanvas/HEAD/mshwgst.lib -------------------------------------------------------------------------------- /Internal/Ink/contoursegment.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/contoursegment.h" 2 | 3 | -------------------------------------------------------------------------------- /Windows/Controls/editingmode.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Controls/editingmode.h" 2 | 3 | -------------------------------------------------------------------------------- /Windows/Input/mousebuttonstate.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/mousebuttonstate.h" 2 | -------------------------------------------------------------------------------- /Windows/Media/drawingcontext.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/drawingcontext.h" 2 | 3 | -------------------------------------------------------------------------------- /Activities/Activities.pri: -------------------------------------------------------------------------------- 1 | include(Presentation/Presentation.pri) 2 | 3 | SOURCES += 4 | -------------------------------------------------------------------------------- /Windows/Ink/applicationgesture.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Ink/applicationgesture.h" 2 | 3 | -------------------------------------------------------------------------------- /Activities/Presentation/clipboarddata.cpp: -------------------------------------------------------------------------------- 1 | #include "Activities/Presentation/clipboarddata.h" 2 | -------------------------------------------------------------------------------- /Internal/Ink/elementsclipboarddata.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/elementsclipboarddata.h" 2 | 3 | -------------------------------------------------------------------------------- /Internal/Ink/inkcanvasclipboardformat.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/inkcanvasclipboardformat.h" 2 | -------------------------------------------------------------------------------- /Windows/Ink/gesturerecognitionresult.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Ink/gesturerecognitionresult.h" 2 | -------------------------------------------------------------------------------- /Windows/Input/querycursoreventargs.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/querycursoreventargs.h" 2 | 3 | -------------------------------------------------------------------------------- /Windows/Media/pointhittestparameters.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/pointhittestparameters.h" 2 | 3 | -------------------------------------------------------------------------------- /InkCanvasJni.version: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | JNI_OnLoad; 4 | 5 | local: 6 | *; 7 | }; 8 | -------------------------------------------------------------------------------- /Collections/Specialized/notifycollectionchangedeventargs.cpp: -------------------------------------------------------------------------------- 1 | #include "notifycollectionchangedeventargs.h" 2 | -------------------------------------------------------------------------------- /Windows/Controls/inkcanvasselectionhitresult.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Controls/inkcanvasselectionhitresult.h" 2 | 3 | -------------------------------------------------------------------------------- /guid.cpp: -------------------------------------------------------------------------------- 1 | #include "guid.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | Guid Guid::Empty; 6 | 7 | INKCANVAS_END_NAMESPACE 8 | -------------------------------------------------------------------------------- /Collections/ObjectModel/ObjectModel.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/collection.cpp 3 | 4 | HEADERS += \ 5 | $$PWD/collection.h 6 | -------------------------------------------------------------------------------- /Activities/Presentation/Presentation.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/clipboarddata.h 3 | 4 | SOURCES += \ 5 | $$PWD/clipboarddata.cpp 6 | -------------------------------------------------------------------------------- /Collections/Collections.pri: -------------------------------------------------------------------------------- 1 | include(Generic/Generic.pri) 2 | include(ObjectModel/ObjectModel.pri) 3 | include(Specialized/Specialized.pri) 4 | -------------------------------------------------------------------------------- /Internal/Ink/GestureRecognition/GestureRecognition.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/nativerecognizer.h 3 | 4 | SOURCES += \ 5 | $$PWD/nativerecognizer.cpp 6 | -------------------------------------------------------------------------------- /Windows/size.cpp: -------------------------------------------------------------------------------- 1 | #include "size.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | Size const Size::s_empty = CreateEmptySize(); 6 | 7 | INKCANVAS_END_NAMESPACE 8 | -------------------------------------------------------------------------------- /Collections/Generic/Generic.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/array.h \ 3 | $$PWD/list.h 4 | 5 | SOURCES += \ 6 | $$PWD/array.cpp \ 7 | $$PWD/list.cpp 8 | -------------------------------------------------------------------------------- /inkcanvas.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | eraser.svg 4 | erasercursor.svg 5 | 6 | 7 | -------------------------------------------------------------------------------- /Collections/Specialized/Specialized.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/notifycollectionchangedeventargs.h 3 | 4 | SOURCES += \ 5 | $$PWD/notifycollectionchangedeventargs.cpp 6 | -------------------------------------------------------------------------------- /Internal/Ink/quad.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/quad.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | Quad Quad::s_empty(Point(0, 0), Point(0, 0), Point(0, 0), Point(0, 0)); 6 | 7 | INKCANVAS_END_NAMESPACE 8 | -------------------------------------------------------------------------------- /eventargs.cpp: -------------------------------------------------------------------------------- 1 | #include "eventargs.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | EventArgs EventArgs::Empty; 6 | 7 | EventArgs::EventArgs() 8 | { 9 | 10 | } 11 | 12 | INKCANVAS_END_NAMESPACE 13 | -------------------------------------------------------------------------------- /Windows/propertymetadata.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/propertymetadata.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | PropertyMetadata::PropertyMetadata() 6 | { 7 | 8 | } 9 | 10 | INKCANVAS_END_NAMESPACE 11 | -------------------------------------------------------------------------------- /Landing/Landing.pri: -------------------------------------------------------------------------------- 1 | inkcanvas_qt : { include(Qt/Qt.pri) } 2 | inkcanvas_android : { include(Android/Android.pri) } 3 | inkcanvas_ios : { include(Ios/Ios.pri) } 4 | inkcanvas_macos : { include(Macos/Macos.pri) } 5 | -------------------------------------------------------------------------------- /Windows/Media/hittestparameters.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/hittestparameters.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | HitTestParameters::HitTestParameters() 6 | { 7 | 8 | } 9 | 10 | INKCANVAS_END_NAMESPACE 11 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - deploy 3 | 4 | deploy-job: 5 | stage: deploy 6 | tags: 7 | - "qt-conan" 8 | script: 9 | - echo "deploy-to-conan" 10 | - git rev-parse HEAD 11 | - py conanfile.py 12 | -------------------------------------------------------------------------------- /Landing/Android/Android.pri: -------------------------------------------------------------------------------- 1 | SOURCES += \ 2 | $$PWD/androidstreamgeometrycontext.cpp \ 3 | $$PWD/inkcanvasandroid.cpp 4 | 5 | HEADERS += \ 6 | $$PWD/androidstreamgeometrycontext.h \ 7 | $$PWD/inkcanvasandroid.h 8 | -------------------------------------------------------------------------------- /Windows/Media/streamgeometrycontext.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/streamgeometrycontext.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | StreamGeometryContext::StreamGeometryContext() 6 | { 7 | 8 | } 9 | 10 | INKCANVAS_END_NAMESPACE 11 | -------------------------------------------------------------------------------- /single.cpp: -------------------------------------------------------------------------------- 1 | #include "single.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | const float Single::NegativeInfinity = (float)-1.0 / (float)(0.0); 6 | const float Single::PositiveInfinity = (float)1.0 / (float)(0.0); 7 | const float Single::NaN = (float)0.0 / (float)0.0; 8 | 9 | INKCANVAS_END_NAMESPACE 10 | -------------------------------------------------------------------------------- /Internal/Controls/Controls.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/inkcanvasfeedbackadorner.h \ 3 | $$PWD/inkcanvasinnercanvas.h \ 4 | $$PWD/inkcanvasselectionadorner.h 5 | 6 | SOURCES += \ 7 | $$PWD/inkcanvasfeedbackadorner.cpp \ 8 | $$PWD/inkcanvasinnercanvas.cpp \ 9 | $$PWD/inkcanvasselectionadorner.cpp 10 | -------------------------------------------------------------------------------- /double.cpp: -------------------------------------------------------------------------------- 1 | #include "double.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | //const double Double::NegativeInfinity = -1.0 / 0.0; 6 | const double Double::PositiveInfinity = 1.0 / 0.0; 7 | const double Double::NegativeInfinity = -PositiveInfinity; 8 | const double Double::NaN = 0.0 / 0.0; 9 | 10 | INKCANVAS_END_NAMESPACE 11 | -------------------------------------------------------------------------------- /Windows/propertymetadata.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPERTYMETADATA_H 2 | #define PROPERTYMETADATA_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | // namespace System.Windows 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class PropertyMetadata 10 | { 11 | public: 12 | PropertyMetadata(); 13 | }; 14 | 15 | INKCANVAS_END_NAMESPACE 16 | 17 | #endif // PROPERTYMETADATA_H 18 | -------------------------------------------------------------------------------- /Internal/Internal.pri: -------------------------------------------------------------------------------- 1 | include(Ink/Ink.pri) 2 | !inkcanvas_core: include(Controls/Controls.pri) 3 | 4 | HEADERS += \ 5 | $$PWD/debug.h \ 6 | $$PWD/doubleutil.h \ 7 | $$PWD/finallyhelper.h \ 8 | $$PWD/matrixutil.h 9 | 10 | SOURCES += \ 11 | $$PWD/debug.cpp \ 12 | $$PWD/doubleutil.cpp \ 13 | $$PWD/finallyhelper.cpp \ 14 | $$PWD/matrixutil.cpp 15 | -------------------------------------------------------------------------------- /Landing/Ios/Ios.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/inkcanvasios.h \ 3 | $$PWD/iosstreamgeometrycontext.h \ 4 | $$PWD/strokewrapper.h \ 5 | $$PWD/uibezierpathwrapper.h 6 | 7 | SOURCES += \ 8 | $$PWD/iosstreamgeometrycontext.cpp \ 9 | $$PWD/strokewrapper.cpp 10 | 11 | OBJECTIVE_SOURCES += \ 12 | $$PWD/uibezierpathwrapper.m \ 13 | $$PWD/inkcanvasios.m 14 | -------------------------------------------------------------------------------- /Landing/Macos/Macos.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/inkcanvasmacos.h \ 3 | $$PWD/macosstreamgeometrycontext.h \ 4 | $$PWD/strokewrapper.h \ 5 | $$PWD/nsbezierpathwrapper.h 6 | 7 | SOURCES += \ 8 | $$PWD/macosstreamgeometrycontext.cpp \ 9 | $$PWD/strokewrapper.cpp 10 | 11 | OBJECTIVE_SOURCES += \ 12 | $$PWD/nsbezierpathwrapper.m \ 13 | $$PWD/inkcanvasmacos.m 14 | -------------------------------------------------------------------------------- /Landing/Qt/Qt.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/inkcanvasqt.h \ 3 | $$PWD/qtstreamgeometrycontext.h 4 | 5 | SOURCES += \ 6 | $$PWD/inkcanvasqt.cpp \ 7 | $$PWD/qtstreamgeometrycontext.cpp 8 | 9 | !inkcanvas_core { 10 | 11 | HEADERS += \ 12 | $$PWD/qtpainterdrawingcontext.h 13 | 14 | SOURCES += \ 15 | $$PWD/qtpainterdrawingcontext.cpp 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Windows/Media/hittestparameters.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_HITTESTPARAMETERS_H 2 | #define WINDOWS_MEDIA_HITTESTPARAMETERS_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | // namespace System.Windows.Media 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class HitTestParameters 10 | { 11 | public: 12 | HitTestParameters(); 13 | }; 14 | 15 | INKCANVAS_END_NAMESPACE 16 | 17 | #endif // WINDOWS_MEDIA_HITTESTPARAMETERS_H 18 | -------------------------------------------------------------------------------- /Windows/rect.cpp: -------------------------------------------------------------------------------- 1 | #include "rect.h" 2 | #include "Internal/debug.h" 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | Rect Rect::s_empty = CreateEmptyRect(); 7 | 8 | bool Rect::IsEmpty() const 9 | { 10 | // The funny width and height tests are to handle NaNs 11 | Debug::Assert((!(_width < 0) && !(_height < 0)) || (*this == Empty())); 12 | 13 | return _width < 0; 14 | } 15 | 16 | INKCANVAS_END_NAMESPACE 17 | -------------------------------------------------------------------------------- /Windows/Input/StylusPlugIns/StylusPlugIns.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/dynamicrenderer.h \ 3 | $$PWD/rawstylusactions.h \ 4 | $$PWD/rawstylusinput.h \ 5 | $$PWD/stylusplugin.h \ 6 | $$PWD/stylusplugincollection.h 7 | 8 | SOURCES += \ 9 | $$PWD/dynamicrenderer.cpp \ 10 | $$PWD/rawstylusactions.cpp \ 11 | $$PWD/rawstylusinput.cpp \ 12 | $$PWD/stylusplugin.cpp \ 13 | $$PWD/stylusplugincollection.cpp 14 | -------------------------------------------------------------------------------- /Windows/Controls/Controls.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/decorator.h \ 3 | $$PWD/editingmode.h \ 4 | $$PWD/inkcanvas.h \ 5 | $$PWD/inkcanvasselectionhitresult.h \ 6 | $$PWD/inkevents.h \ 7 | $$PWD/inkpresenter.h 8 | 9 | SOURCES += \ 10 | $$PWD/decorator.cpp \ 11 | $$PWD/editingmode.cpp \ 12 | $$PWD/inkcanvas.cpp \ 13 | $$PWD/inkcanvasselectionhitresult.cpp \ 14 | $$PWD/inkevents.cpp \ 15 | $$PWD/inkpresenter.cpp 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QtInkCanvas 2 | A porting of WPF InkCanvas to Qt enviriment. 3 | 4 | # 支持下列功能特性: 5 | + 笔迹书写(平滑、压力感应) 6 | + 选择(点选、套索) 7 | + 擦除(笔迹擦除、像素擦除) 8 | + 复制粘贴 9 | + 辅组视觉(选择框、套索,光标) 10 | + 手势识别 11 | 12 | # 方案 13 | + C# 转 C++ 14 | + QEvent - > EventArgs 15 | + QWidget/QGraphicsItem -> Visual/UIElement 16 | + QPainterPath -> Geometry 17 | + Geometry+QBrush+QPen -> Drawing 18 | + Signal/Slot -> EventHandler 19 | + 简单实现 DependencyObject DependencyProperty 和 RouteEvent 20 | -------------------------------------------------------------------------------- /Internal/finallyhelper.h: -------------------------------------------------------------------------------- 1 | #ifndef FINALLYHELPER_H 2 | #define FINALLYHELPER_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class FinallyHelper 11 | { 12 | public: 13 | FinallyHelper(std::function finalize) : finalize_(finalize) {} 14 | 15 | ~FinallyHelper() { 16 | finalize_(); 17 | } 18 | 19 | private: 20 | std::function finalize_; 21 | }; 22 | 23 | INKCANVAS_END_NAMESPACE 24 | 25 | #endif // FINALLYHELPER_H 26 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/transformdescriptor.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMDESCRIPTOR_H 2 | #define TRANSFORMDESCRIPTOR_H 3 | 4 | #include "Internal/Ink/InkSerializedFormat/isftagandguidcache.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | class TransformDescriptor 9 | { 10 | public: 11 | double Transform[6]; 12 | uint Size = 0; 13 | KnownTagCache::KnownTagIndex Tag; 14 | 15 | public: 16 | bool Compare(TransformDescriptor const & that); 17 | }; 18 | 19 | INKCANVAS_END_NAMESPACE 20 | 21 | #endif // TRANSFORMDESCRIPTOR_H 22 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/strokedescriptor.h: -------------------------------------------------------------------------------- 1 | #ifndef STROKEDESCRIPTOR_H 2 | #define STROKEDESCRIPTOR_H 3 | 4 | #include "Internal/Ink/InkSerializedFormat/isftagandguidcache.h" 5 | #include "Collections/Generic/list.h" 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class StrokeDescriptor 10 | { 11 | public: 12 | List Template; 13 | uint Size; 14 | 15 | public: 16 | StrokeDescriptor(); 17 | 18 | bool IsEqual(StrokeDescriptor const & strd); 19 | }; 20 | 21 | INKCANVAS_END_NAMESPACE 22 | 23 | #endif // STROKEDESCRIPTOR_H 24 | -------------------------------------------------------------------------------- /mshwgst.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | AddStroke 3 | AdviseInkChange 4 | CloneContext 5 | CreateContext 6 | CreateRecognizer 7 | DestroyContext 8 | DestroyRecognizer 9 | EndInkInput 10 | GetBestResultString 11 | GetContextPropertyList 12 | GetContextPropertyValue 13 | GetEnabledUnicodeRanges 14 | GetGuide 15 | GetLatticePtr 16 | GetPreferredPacketDescription 17 | GetRecoAttributes 18 | GetResultPropertyList 19 | GetUnicodeRanges 20 | IsStringSupported 21 | Process 22 | ResetContext 23 | SetCACMode 24 | SetContextPropertyValue 25 | SetEnabledUnicodeRanges 26 | SetFactoid 27 | SetFlags 28 | SetGuide 29 | SetTextContext -------------------------------------------------------------------------------- /Windows/Input/mousebuttonstate.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_MOUSEBUTTONSTATE_H 2 | #define WINDOWS_INPUT_MOUSEBUTTONSTATE_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | enum class MouseButtonState 9 | { 10 | /// 11 | /// The button is released. 12 | /// 13 | Released, 14 | 15 | /// 16 | /// The button is pressed. 17 | /// 18 | Pressed, 19 | 20 | // Update the IsValid helper in RawMouseState.cs if this enum changes. 21 | }; 22 | 23 | INKCANVAS_END_NAMESPACE 24 | 25 | #endif // WINDOWS_INPUT_MOUSEBUTTONSTATE_H 26 | -------------------------------------------------------------------------------- /Windows/dispatcher.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPATCHER_H 2 | #define DISPATCHER_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | class QThread; 9 | class QAbstractEventDispatcher; 10 | 11 | INKCANVAS_BEGIN_NAMESPACE 12 | 13 | class Dispatcher 14 | { 15 | public: 16 | void VerifyAccess(); 17 | 18 | bool CheckAccess(); 19 | 20 | void BeginInvoke(std::function func, void* data); 21 | 22 | static Dispatcher* from(QThread* thread); 23 | 24 | private: 25 | Dispatcher(QThread* thread); 26 | QAbstractEventDispatcher* eventDispatche_; 27 | }; 28 | 29 | INKCANVAS_END_NAMESPACE 30 | 31 | #endif // DISPATCHER_H 32 | -------------------------------------------------------------------------------- /Landing/Ios/strokewrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef STROKEWRAPPER_H 2 | #define STROKEWRAPPER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | long StrokeWrapper_new(int n, double x[], double y[], float pressures[], 9 | double width, int fitToCorve, int ellipseShape, int addPressure); 10 | long StrokeWrapper_clone(long stroke); 11 | void StrokeWrapper_transform(long stroke, double matrix[6]); 12 | bool StrokeWrapper_hitTest(long stroke, double x, double y); 13 | void * StrokeWrapper_getGeometry(long stroke, double bounds[4]); 14 | void StrokeWrapper_delete(long stroke); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif // STROKEWRAPPER_H 21 | -------------------------------------------------------------------------------- /Landing/Macos/strokewrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef STROKEWRAPPER_H 2 | #define STROKEWRAPPER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | long StrokeWrapper_new(int n, double x[], double y[], float pressures[], 9 | double width, int fitToCorve, int ellipseShape, int addPressure); 10 | long StrokeWrapper_clone(long stroke); 11 | void StrokeWrapper_transform(long stroke, double matrix[6]); 12 | bool StrokeWrapper_hitTest(long stroke, double x, double y); 13 | void * StrokeWrapper_getGeometry(long stroke, double bounds[4]); 14 | void StrokeWrapper_delete(long stroke); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | 21 | #endif // STROKEWRAPPER_H 22 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/strokedescriptor.cpp: -------------------------------------------------------------------------------- 1 | #include "strokedescriptor.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | StrokeDescriptor::StrokeDescriptor() 6 | { 7 | 8 | } 9 | 10 | bool StrokeDescriptor::IsEqual(StrokeDescriptor const & strd) 11 | { 12 | // If the no of templates in them are different return false 13 | if( Template.Count() != strd.Template.Count() ) 14 | return false; 15 | 16 | // Compare each tag in the template. If any one of them is different, return false; 17 | for( int i = 0; i < Template.Count(); i++ ) 18 | if( Template[i] != strd.Template[i] ) 19 | return false; 20 | return true; 21 | } 22 | 23 | INKCANVAS_END_NAMESPACE 24 | -------------------------------------------------------------------------------- /Windows/Media/pointhittestresult.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/pointhittestresult.h" 2 | 3 | #include "Windows/uielement.h" 4 | 5 | INKCANVAS_BEGIN_NAMESPACE 6 | 7 | PointHitTestResult::PointHitTestResult() 8 | : HitTestResult(nullptr) 9 | { 10 | 11 | } 12 | 13 | PointHitTestResult::PointHitTestResult(UIElement * visualHit, Point const & pointHit) 14 | : HitTestResult(visualHit) 15 | { 16 | _pointHit = pointHit; 17 | } 18 | 19 | 20 | /// 21 | /// Re-expose QWidget property strongly typed to 2D QWidget. 22 | /// 23 | UIElement* PointHitTestResult::VisualHit() 24 | { 25 | return (UIElement*) HitTestResult::VisualHit(); 26 | } 27 | 28 | INKCANVAS_END_NAMESPACE 29 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/transformdescriptor.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/InkSerializedFormat/transformdescriptor.h" 2 | #include "Internal/doubleutil.h" 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | bool TransformDescriptor::Compare(TransformDescriptor const & that) 7 | { 8 | if( that.Tag == Tag ) 9 | { 10 | if( that.Size == Size ) 11 | { 12 | for(unsigned int i = 0; i < Size; i++ ) 13 | { 14 | if( !DoubleUtil::AreClose(that.Transform[i], Transform[i] )) 15 | return false; 16 | } 17 | return true; 18 | } 19 | else 20 | return false; 21 | } 22 | return false; 23 | } 24 | 25 | INKCANVAS_END_NAMESPACE 26 | -------------------------------------------------------------------------------- /Landing/Ios/inkcanvasios.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVASIOS_H 2 | #define INKCANVASIOS_H 3 | 4 | #import "Foundation/Foundation.h" 5 | #import "UIKit/UIBezierPath.h" 6 | 7 | @interface ICStroke : NSObject { 8 | long _stroke; 9 | } 10 | 11 | - (instancetype) initWithPoints:(int) n points:(CGPoint[]) points pressures:(float[]) pressures 12 | width:(double) width fitToCorve:(bool) fitToCorve 13 | ellipseShape:(bool) ellipseShape addPressure:(bool) addPressure; 14 | - (ICStroke*) clone; 15 | - (void) transformWithMatrix:(CGAffineTransform) matrix; 16 | - (bool) hitTestWithPoint:(CGPoint) point; 17 | - (UIBezierPath*) getGeometryAndBounds:(CGRect*) bounds; 18 | - (void) dealloc; 19 | @end 20 | 21 | #endif // INKCANVASIOS_H 22 | -------------------------------------------------------------------------------- /Windows/Input/inputeventargs.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/inputeventargs.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | /// 6 | /// Initializes a new instance of the InputEventArgs class. 7 | /// 8 | /// 9 | /// The input device to associate with this event. 10 | /// 11 | /// 12 | /// The time when the input occured. 13 | /// 14 | InputEventArgs::InputEventArgs(InputDevice* inputDevice, int timestamp) 15 | { 16 | /* inputDevice parameter being null is valid*/ 17 | /* timestamp parameter is valuetype, need not be checked */ 18 | _inputDevice = inputDevice; 19 | _timestamp = timestamp; 20 | } 21 | 22 | int InputEventArgs::_timestamp = 0; 23 | 24 | INKCANVAS_END_NAMESPACE 25 | -------------------------------------------------------------------------------- /propgetset.awk: -------------------------------------------------------------------------------- 1 | NR==1 { 2 | gsub("\\r", "") 3 | gsub("\\n", "") 4 | type=$1 5 | name=$2 6 | print $0 "()" 7 | } 8 | 9 | /^ {8}get \{/ { 10 | gsub("get \\{ ?", "") 11 | gsub(" ?\\}", "") 12 | print $0 13 | } 14 | 15 | /^ {8}get/ { 16 | } 17 | 18 | /^ {8}set \{/ { 19 | print " }" 20 | print " void Set" name "(" type " value)" 21 | print " {" 22 | gsub("set \\{ ?", "") 23 | gsub(" ?\\}", "") 24 | print $0 25 | } 26 | 27 | /^ {8}set/ { 28 | print " }" 29 | print " void Set" name "(" type " value)" 30 | print " {" 31 | } 32 | 33 | /^ {4}\{/ { 34 | print $0 35 | } 36 | 37 | /^ {4}\}/ { 38 | print $0 39 | } 40 | 41 | /^ {12}/ { 42 | print substr($0, 4) 43 | } 44 | 45 | END { 46 | print "\n" 47 | } 48 | -------------------------------------------------------------------------------- /Internal/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_H 2 | #define DEBUG_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | // namespace System.Diagnostics 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class Debug 10 | { 11 | public: 12 | static inline void Assert(bool condition) 13 | { 14 | (void) condition; 15 | #ifdef QT_DEBUG 16 | _Assert(condition, ""); 17 | #endif 18 | } 19 | 20 | static inline void Assert(bool condition, char const * message) 21 | { 22 | (void) condition; 23 | (void) message; 24 | #ifdef QT_DEBUG 25 | _Assert(condition, message); 26 | #endif 27 | } 28 | 29 | static void Log(char const * message, ...); 30 | 31 | private: 32 | static void _Assert(bool condition, char const * message); 33 | }; 34 | 35 | INKCANVAS_END_NAMESPACE 36 | 37 | #endif // DEBUG_H 38 | -------------------------------------------------------------------------------- /Windows/Input/StylusPlugIns/rawstylusactions.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/StylusPlugIns/rawstylusactions.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | const RawStylusActions RawStylusActionsHelper::MaxActions = 6 | RawStylusActions::None | 7 | RawStylusActions::Activate | 8 | RawStylusActions::Deactivate | 9 | RawStylusActions::Down | 10 | RawStylusActions::Up | 11 | RawStylusActions::Move | 12 | RawStylusActions::InAirMove | 13 | RawStylusActions::InRange | 14 | RawStylusActions::OutOfRange | 15 | RawStylusActions::SystemGesture; 16 | 17 | bool RawStylusActionsHelper::IsValid(RawStylusActions action) 18 | { 19 | if (action < RawStylusActions::None || action > MaxActions) 20 | { 21 | return false; 22 | } 23 | return true; 24 | } 25 | 26 | INKCANVAS_END_NAMESPACE 27 | -------------------------------------------------------------------------------- /Landing/Macos/inkcanvasmacos.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVASIOS_H 2 | #define INKCANVASIOS_H 3 | 4 | #import "Foundation/Foundation.h" 5 | #import "AppKit/NSBezierPath.h" 6 | 7 | @interface InkCanvasMacos : NSObject {} 8 | - (long) newStrokeWithPoints:(int) n points:(CGPoint[]) points pressures:(float[]) pressures 9 | width:(double) width fitToCorve:(bool) fitToCorve 10 | ellipseShape:(bool) ellipseShape addPressure:(bool) addPressure; 11 | - (long) cloneStroke:(long) stroke; 12 | - (void) transformStroke:(long) stroke withMatrix:(CGAffineTransform) matrix; 13 | - (bool) hitTestStroke:(long) stroke withPoint:(CGPoint) point; 14 | - (NSBezierPath*) getStrokeGeometry:(long) stroke andBounds:(CGRect) bounds; 15 | - (void) deleteStroke:(long) stroke; 16 | @end 17 | 18 | #endif // INKCANVASIOS_H 19 | -------------------------------------------------------------------------------- /eraser.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 01 通用/图标/48px/eraser 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Landing/Android/inkcanvasandroid.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVASANDROID_H 2 | #define INKCANVASANDROID_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | 11 | jlong createStroke(JNIEnv * env, jobject object, jobjectArray points, jfloatArray pressures, 12 | jfloat width, jboolean fitToCorve, jboolean ellipseShape, jboolean addPressure); 13 | 14 | jlong cloneStroke(JNIEnv * env, jobject object, jlong stroke); 15 | 16 | void transformStroke(JNIEnv * env, jobject object, jlong stroke, jobject matrix); 17 | 18 | jboolean hitTestStroke(JNIEnv * env, jobject object, jlong stroke, jobject point); 19 | 20 | jobject getStrokeGeometry(JNIEnv * env, jobject object, jlong stroke, jobject bounds); 21 | 22 | void freeStroke(JNIEnv * env, jobject object, jlong stroke); 23 | 24 | INKCANVAS_END_NAMESPACE 25 | 26 | #endif // INKCANVASANDROID_H 27 | -------------------------------------------------------------------------------- /sharedptr.h: -------------------------------------------------------------------------------- 1 | #ifndef SHAREDPTR_H 2 | #define SHAREDPTR_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #ifdef INKCANVAS_QT 7 | #include 8 | #include 9 | #include 10 | INKCANVAS_BEGIN_NAMESPACE 11 | #ifdef Q_COMPILER_TEMPLATE_ALIAS 12 | template using SharedPointer = QSharedPointer; 13 | template using EnableSharedFromThis = QEnableSharedFromThis; 14 | #else 15 | #define SharedPointer QSharedPointer 16 | #define EnableSharedFromThis QEnableSharedFromThis 17 | #endif 18 | #define shared_from_this sharedFromThis 19 | INKCANVAS_END_NAMESPACE 20 | #else 21 | #include 22 | INKCANVAS_BEGIN_NAMESPACE 23 | template using SharedPointer = std::shared_ptr; 24 | template using EnableSharedFromThis = std::enable_shared_from_this; 25 | INKCANVAS_END_NAMESPACE 26 | #endif 27 | 28 | #endif // SHAREDPTR_H 29 | -------------------------------------------------------------------------------- /Windows/Media/drawingvisual.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_DRAWINGVISUAL_H 2 | #define WINDOWS_MEDIA_DRAWINGVISUAL_H 3 | 4 | #include "containervisual.h" 5 | 6 | // namespace System.Windows.Media 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class DrawingContext; 10 | class DrawingGroup; 11 | 12 | class DrawingVisual : public ContainerVisual 13 | { 14 | Q_OBJECT 15 | public: 16 | DrawingVisual(); 17 | 18 | virtual ~DrawingVisual() override; 19 | 20 | DrawingContext * RenderOpen(); 21 | 22 | void RenderClose(); 23 | 24 | DrawingGroup * GetDrawing(); 25 | 26 | public: 27 | virtual QRectF boundingRect() const override; 28 | 29 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; 30 | 31 | private: 32 | DrawingGroup * drawing_ = nullptr; 33 | }; 34 | 35 | INKCANVAS_END_NAMESPACE 36 | 37 | #endif // WINDOWS_MEDIA_DRAWINGVISUAL_H 38 | -------------------------------------------------------------------------------- /erasercursor.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 橡皮最小 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Internal/Ink/serializationflags.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATIONFLAGS_H 2 | #define SERIALIZATIONFLAGS_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | /// 9 | /// Specifies how to persist the ink. 10 | /// 11 | enum class PersistenceFormat 12 | { 13 | 14 | /// 15 | /// Native ink serialization format. 16 | /// 17 | InkSerializedFormat = 0, 18 | 19 | /// 20 | /// GIF serialization format. 21 | /// 22 | Gif = 1, 23 | }; 24 | 25 | /// 26 | /// Specifies how to compress the ink. 27 | /// 28 | enum class CompressionMode 29 | { 30 | /// 31 | /// Compressed 32 | /// 33 | Compressed = 0, 34 | 35 | 36 | /// 37 | /// NoCompression 38 | /// 39 | NoCompression = 2 40 | }; 41 | 42 | INKCANVAS_END_NAMESPACE 43 | 44 | #endif // SERIALIZATIONFLAGS_H 45 | -------------------------------------------------------------------------------- /Windows/Input/styluspointproperty.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/styluspointproperty.h" 2 | 3 | #include 4 | 5 | INKCANVAS_BEGIN_NAMESPACE 6 | 7 | StylusPointProperty const StylusPointProperty::Empty; 8 | 9 | void StylusPointProperty::Initialize(Guid const & identifier, bool isButton) 10 | { 11 | // 12 | // validate isButton for known guids 13 | // 14 | if (StylusPointPropertyIds::IsKnownButton(identifier)) 15 | { 16 | if (!isButton) 17 | { 18 | //error, this is a known button 19 | throw std::runtime_error("isButton"); 20 | } 21 | } 22 | else 23 | { 24 | if (StylusPointPropertyIds::IsKnownId(identifier) && isButton) 25 | { 26 | //error, this is a known guid that is NOT a button 27 | throw std::runtime_error("isButton"); 28 | } 29 | } 30 | 31 | //_id = identifier; 32 | //_isButton = isButton; 33 | } 34 | 35 | INKCANVAS_END_NAMESPACE 36 | -------------------------------------------------------------------------------- /Windows/Ink/stylustip.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INK_STYLUSTIP_H 2 | #define WINDOWS_INK_STYLUSTIP_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #ifdef INKCANVAS_QT 7 | #include 8 | #endif 9 | 10 | INKCANVAS_BEGIN_NAMESPACE 11 | 12 | enum class StylusTip 13 | { 14 | /// 15 | /// Rectangle 16 | /// 17 | Rectangle = 0, 18 | 19 | /// 20 | /// Ellipse 21 | /// 22 | Ellipse 23 | }; 24 | 25 | // namespace System.Windows.Ink 26 | 27 | class StylusTipHelper 28 | { 29 | public: 30 | static bool IsDefined(StylusTip stylusTip) 31 | { 32 | if (stylusTip < StylusTip::Rectangle || stylusTip > StylusTip::Ellipse) 33 | { 34 | return false; 35 | } 36 | return true; 37 | } 38 | }; 39 | 40 | INKCANVAS_END_NAMESPACE 41 | 42 | #ifdef INKCANVAS_QT 43 | Q_DECLARE_METATYPE(INKCANVAS_PREPEND_NAMESPACE(StylusTip)) 44 | #endif 45 | 46 | #endif // WINDOWS_INK_STYLUSTIP_H 47 | -------------------------------------------------------------------------------- /Landing/Ios/uibezierpathwrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef UIBEZIERPATHWRAPPER_H 2 | #define UIBEZIERPATHWRAPPER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void * UIBezierPathWrapper_new(); 9 | void UIBezierPathWrapper_moveToPoint(void * path, double x, double y); 10 | void UIBezierPathWrapper_addLineToPoint(void * path, double x, double y); 11 | void UIBezierPathWrapper_addQuadCurveToPoint(void * path, double x, double y, double cx, double cy); 12 | void UIBezierPathWrapper_addCurveToPoint(void * path, double x, double y, double cx1, double cy1, double cx2, double cy2); 13 | void UIBezierPathWrapper_addArcWithCenter(void * path, double x, double y, double radius, double startAngle, double endAngle, int clockwise); 14 | void UIBezierPathWrapper_currentPoint(void * path, double * x, double * y); 15 | void UIBezierPathWrapper_closePath(void * path); 16 | void UIBezierPathWrapper_delete(void * path); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // UIBEZIERPATHWRAPPER_H 23 | -------------------------------------------------------------------------------- /Landing/Macos/nsbezierpathwrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef NSBezierPathWRAPPER_H 2 | #define NSBezierPathWRAPPER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void * NSBezierPathWrapper_new(); 9 | void NSBezierPathWrapper_moveToPoint(void * path, double x, double y); 10 | void NSBezierPathWrapper_addLineToPoint(void * path, double x, double y); 11 | void NSBezierPathWrapper_addQuadCurveToPoint(void * path, double x, double y, double cx, double cy); 12 | void NSBezierPathWrapper_addCurveToPoint(void * path, double x, double y, double cx1, double cy1, double cx2, double cy2); 13 | void NSBezierPathWrapper_addArcWithCenter(void * path, double x, double y, double radius, double startAngle, double endAngle, int clockwise); 14 | void NSBezierPathWrapper_currentPoint(void * path, double * x, double * y); 15 | void NSBezierPathWrapper_closePath(void * path); 16 | void NSBezierPathWrapper_delete(void * path); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // NSBezierPathWRAPPER_H 23 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/InkSerializedFormat.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/algomodule.h \ 3 | $$PWD/compress.h \ 4 | $$PWD/drawingattributeserializer.h \ 5 | $$PWD/extendedpropertyserializer.h \ 6 | $$PWD/guidlist.h \ 7 | $$PWD/isftagandguidcache.h \ 8 | $$PWD/metricblock.h \ 9 | $$PWD/metricentry.h \ 10 | $$PWD/serializationhelper.h \ 11 | $$PWD/strokecollectionserializer.h \ 12 | $$PWD/strokedescriptor.h \ 13 | $$PWD/strokeserializer.h \ 14 | $$PWD/transformdescriptor.h 15 | 16 | SOURCES += \ 17 | $$PWD/algomodule.cpp \ 18 | $$PWD/compress.cpp \ 19 | $$PWD/drawingattributeserializer.cpp \ 20 | $$PWD/extendedpropertyserializer.cpp \ 21 | $$PWD/guidlist.cpp \ 22 | $$PWD/isftagandguidcache.cpp \ 23 | $$PWD/metricblock.cpp \ 24 | $$PWD/metricentry.cpp \ 25 | $$PWD/serializationhelper.cpp \ 26 | $$PWD/strokecollectionserializer.cpp \ 27 | $$PWD/strokedescriptor.cpp \ 28 | $$PWD/strokeserializer.cpp \ 29 | $$PWD/transformdescriptor.cpp 30 | -------------------------------------------------------------------------------- /Internal/Ink/inkcanvasclipboardformat.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVASCLIPBOARDFORMAT_H 2 | #define INKCANVASCLIPBOARDFORMAT_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | // namespace System.Windows.Controls 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | enum class InkCanvasClipboardFormat 12 | { 13 | /// 14 | /// Ink Serialized Format 15 | /// 16 | InkSerializedFormat = 0, 17 | /// 18 | /// Text Format 19 | /// 20 | Text, 21 | /// 22 | /// Xaml Format 23 | /// 24 | Xaml, 25 | }; 26 | 27 | // namespace MS.Internal.Ink 28 | 29 | // The bits which internally represents the formats supported by InkCanvas 30 | enum class InkCanvasClipboardDataFormat 31 | { 32 | None = 0x00, // None 33 | XAML = 0x01, // XAML 34 | ISF = 0x02, // ISF 35 | }; 36 | 37 | Q_DECLARE_FLAGS(InkCanvasClipboardDataFormats, InkCanvasClipboardDataFormat) 38 | 39 | INKCANVAS_END_NAMESPACE 40 | 41 | #endif // INKCANVASCLIPBOARDFORMAT_H 42 | -------------------------------------------------------------------------------- /Internal/Ink/strokefindices.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/strokefindices.h" 2 | 3 | #ifdef INKCANVAS_QT 4 | #include 5 | #endif 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | StrokeFIndices StrokeFIndices::s_empty(AfterLast, BeforeFirst); 10 | StrokeFIndices StrokeFIndices::s_full(BeforeFirst, AfterLast); 11 | 12 | StrokeFIndices::StrokeFIndices(double beginFIndex, double endFIndex) 13 | { 14 | _beginFIndex = beginFIndex; 15 | _endFIndex = endFIndex; 16 | } 17 | 18 | #ifdef INKCANVAS_QT 19 | QString StrokeFIndices::ToString() const 20 | { 21 | return QString("{") + GetStringRepresentation(_beginFIndex) + "," + GetStringRepresentation(_endFIndex) + "}"; 22 | } 23 | #endif 24 | 25 | char const * StrokeFIndices::GetStringRepresentation(double fIndex) 26 | { 27 | if (DoubleUtil::AreClose(fIndex, BeforeFirst)) 28 | { 29 | return "BeforeFirst"; 30 | } 31 | if (DoubleUtil::AreClose(fIndex, AfterLast)) 32 | { 33 | return "AfterLast"; 34 | } 35 | return ""; 36 | //return QString("%1").arg(fIndex); 37 | } 38 | 39 | INKCANVAS_END_NAMESPACE 40 | -------------------------------------------------------------------------------- /Windows/Media/matrix.cpp: -------------------------------------------------------------------------------- 1 | #include "matrix.h" 2 | #include "Internal/debug.h" 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | Matrix Matrix::s_identity = CreateIdentity(); 7 | 8 | void Matrix::Debug_CheckType() 9 | { 10 | switch(_type) 11 | { 12 | case MatrixTypes::TRANSFORM_IS_IDENTITY: 13 | return; 14 | case MatrixTypes::TRANSFORM_IS_UNKNOWN: 15 | return; 16 | case MatrixTypes::TRANSFORM_IS_SCALING: 17 | Debug::Assert(_m21 == 0); 18 | Debug::Assert(_m12 == 0); 19 | Debug::Assert(_offsetX == 0); 20 | Debug::Assert(_offsetY == 0); 21 | return; 22 | case MatrixTypes::TRANSFORM_IS_TRANSLATION: 23 | Debug::Assert(_m21 == 0); 24 | Debug::Assert(_m12 == 0); 25 | Debug::Assert(_m11 == 1); 26 | Debug::Assert(_m22 == 1); 27 | return; 28 | case MatrixTypes::TRANSFORM_IS_SCALING_TRANSLATION: 29 | Debug::Assert(_m21 == 0); 30 | Debug::Assert(_m12 == 0); 31 | return; 32 | default: 33 | Debug::Assert(false); 34 | return; 35 | } 36 | } 37 | 38 | INKCANVAS_END_NAMESPACE 39 | -------------------------------------------------------------------------------- /conanfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from QtToolsFish import conans_tools 4 | from QtToolsFish.Conans import QtConanFile 5 | 6 | package_name = "InkCanvas" 7 | package_version = "master" 8 | 9 | package_user_channel = "cmguo/stable" 10 | 11 | 12 | class ConanConfig(QtConanFile): 13 | name = package_name 14 | version = package_version 15 | 16 | git_url = "git@gitlab.xiaoheiban.cn:windows/talcloud_khaos_inkcanvas" 17 | git_branch = "develop/master" 18 | 19 | short_paths = True 20 | 21 | exports_sources = "*" 22 | 23 | def source(self): 24 | conans_tools.move_dir_files_to_folder(self.get_library_name()) 25 | super(ConanConfig, self).source() 26 | 27 | def package_include(self): 28 | super(ConanConfig, self).package_include() 29 | 30 | 31 | if __name__ == '__main__': 32 | conans_tools.remove_cache(package_version=f"{package_name}/{package_version}", user_channel=package_user_channel) 33 | conans_tools.create(user_channel=package_user_channel) 34 | conans_tools.upload(package_version=f"{package_name}/{package_version}", user_channel=package_user_channel) 35 | -------------------------------------------------------------------------------- /Windows/dispatcher.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/dispatcher.h" 2 | #include "Internal/debug.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | static QMutex dlock; 11 | static QMap dispatchers; 12 | 13 | Dispatcher* Dispatcher::from(QThread *thread) 14 | { 15 | QMutexLocker l(&dlock); 16 | Dispatcher * d = dispatchers.value(thread, nullptr); 17 | if (d == nullptr) { 18 | d = new Dispatcher(thread); 19 | dispatchers.insert(thread, d); 20 | } 21 | return d; 22 | } 23 | 24 | Dispatcher::Dispatcher(QThread *thread) 25 | { 26 | eventDispatche_ = thread->eventDispatcher(); 27 | } 28 | 29 | void Dispatcher::VerifyAccess() 30 | { 31 | Debug::Assert(eventDispatche_ && QThread::currentThread()->eventDispatcher() == eventDispatche_); 32 | } 33 | 34 | bool Dispatcher::CheckAccess() 35 | { 36 | return eventDispatche_ && QThread::currentThread()->eventDispatcher() == eventDispatche_; 37 | } 38 | 39 | void Dispatcher::BeginInvoke(std::function, void *) 40 | { 41 | 42 | } 43 | 44 | INKCANVAS_END_NAMESPACE 45 | -------------------------------------------------------------------------------- /Windows/Windows.pri: -------------------------------------------------------------------------------- 1 | include(Media/Media.pri) 2 | include(Ink/Ink.pri) 3 | !inkcanvas_core: include(Controls/Controls.pri) 4 | include(Input/Input.pri) 5 | 6 | HEADERS += \ 7 | $$PWD/point.h \ 8 | $$PWD/rect.h \ 9 | $$PWD/size.h \ 10 | $$PWD/vector.h 11 | 12 | SOURCES += \ 13 | $$PWD/point.cpp \ 14 | $$PWD/rect.cpp \ 15 | $$PWD/size.cpp \ 16 | $$PWD/vector.cpp 17 | 18 | !inkcanvas_core: { 19 | 20 | HEADERS += \ 21 | $$PWD/dependencyobject.h \ 22 | $$PWD/dependencyproperty.h \ 23 | $$PWD/dependencypropertychangedeventargs.h \ 24 | $$PWD/dispatcher.h \ 25 | $$PWD/effectivevalueentry.h \ 26 | $$PWD/propertymetadata.h \ 27 | $$PWD/routedeventargs.h \ 28 | $$PWD/uielement.h \ 29 | 30 | SOURCES += \ 31 | $$PWD/dependencyobject.cpp \ 32 | $$PWD/dependencyproperty.cpp \ 33 | $$PWD/dependencypropertychangedeventargs.cpp \ 34 | $$PWD/dispatcher.cpp \ 35 | $$PWD/effectivevalueentry.cpp \ 36 | $$PWD/propertymetadata.cpp \ 37 | $$PWD/routedeventargs.cpp \ 38 | $$PWD/uielement.cpp \ 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Windows/Media/pointhittestparameters.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_POINTHITTESTPARAMETERS_H 2 | #define WINDOWS_MEDIA_POINTHITTESTPARAMETERS_H 3 | 4 | #include "Windows/Media/hittestparameters.h" 5 | #include "Windows/point.h" 6 | 7 | // namespace System.Windows.Media 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | /// 11 | /// This is the class for specifying parameters hit testing with a point. 12 | /// 13 | class PointHitTestParameters : public HitTestParameters 14 | { 15 | public: 16 | /// 17 | /// The constructor takes the point to hit test with. 18 | /// 19 | PointHitTestParameters(Point const & point) : HitTestParameters() 20 | { 21 | _hitPoint = point; 22 | } 23 | 24 | /// 25 | /// The point to hit test against. 26 | /// 27 | Point & HitPoint() 28 | { 29 | return _hitPoint; 30 | } 31 | 32 | void SetHitPoint(Point const & hitPoint) 33 | { 34 | _hitPoint = hitPoint; 35 | } 36 | 37 | private: 38 | Point _hitPoint; 39 | }; 40 | 41 | INKCANVAS_END_NAMESPACE 42 | 43 | #endif // WINDOWS_MEDIA_POINTHITTESTPARAMETERS_H 44 | -------------------------------------------------------------------------------- /Windows/Media/Media.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/geometry.h \ 3 | $$PWD/matrix.h \ 4 | $$PWD/streamgeometry.h \ 5 | $$PWD/streamgeometrycontext.h \ 6 | 7 | SOURCES += \ 8 | $$PWD/geometry.cpp \ 9 | $$PWD/matrix.cpp \ 10 | $$PWD/streamgeometry.cpp \ 11 | $$PWD/streamgeometrycontext.cpp \ 12 | 13 | !inkcanvas_core: { 14 | 15 | HEADERS += \ 16 | $$PWD/containervisual.h \ 17 | $$PWD/drawing.h \ 18 | $$PWD/drawingcontext.h \ 19 | $$PWD/drawingdrawingcontext.h \ 20 | $$PWD/drawingvisual.h \ 21 | $$PWD/hittestparameters.h \ 22 | $$PWD/hittestresult.h \ 23 | $$PWD/pointhittestparameters.h \ 24 | $$PWD/pointhittestresult.h \ 25 | $$PWD/visual.h 26 | 27 | SOURCES += \ 28 | $$PWD/containervisual.cpp \ 29 | $$PWD/drawing.cpp \ 30 | $$PWD/drawingcontext.cpp \ 31 | $$PWD/drawingdrawingcontext.cpp \ 32 | $$PWD/drawingvisual.cpp \ 33 | $$PWD/hittestparameters.cpp \ 34 | $$PWD/hittestresult.cpp \ 35 | $$PWD/pointhittestparameters.cpp \ 36 | $$PWD/pointhittestresult.cpp \ 37 | $$PWD/visual.cpp 38 | } 39 | -------------------------------------------------------------------------------- /Windows/Media/hittestresult.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_HITTESTRESULT_H 2 | #define WINDOWS_MEDIA_HITTESTRESULT_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | // namespace System.Windows.Media 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class DependencyObject; 10 | 11 | /// 12 | /// This base returns the visual that was hit during a hit test pass. 13 | /// 14 | class HitTestResult 15 | { 16 | private: 17 | DependencyObject* _visualHit; 18 | 19 | friend bool operator==(HitTestResult const & l, HitTestResult const & r) 20 | { 21 | return l._visualHit == r._visualHit; 22 | } 23 | 24 | friend bool operator!=(HitTestResult const & l, HitTestResult const & r) 25 | { 26 | return !(l == r); 27 | } 28 | 29 | public: 30 | HitTestResult(DependencyObject* visualHit) 31 | { 32 | _visualHit = visualHit; 33 | } 34 | 35 | /// 36 | /// Returns the visual that was hit. May be a Visual or Visual3D. 37 | /// 38 | DependencyObject* VisualHit() 39 | { 40 | return _visualHit; 41 | } 42 | }; 43 | 44 | INKCANVAS_END_NAMESPACE 45 | 46 | #endif // WINDOWS_MEDIA_HITTESTRESULT_H 47 | -------------------------------------------------------------------------------- /Windows/Media/containervisual.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_CONTAINERVISUAL_H 2 | #define WINDOWS_MEDIA_CONTAINERVISUAL_H 3 | 4 | #include "visual.h" 5 | #include "Collections/ObjectModel/collection.h" 6 | 7 | #include 8 | 9 | // namespace System.Windows.Media 10 | INKCANVAS_BEGIN_NAMESPACE 11 | 12 | class Geometry; 13 | 14 | class ContainerVisual; 15 | 16 | class VisualCollection : public Collection 17 | { 18 | public: 19 | VisualCollection(ContainerVisual * parent); 20 | void Add(Visual* visual); 21 | void Insert(int index, Visual* visual); 22 | void Remove(Visual* visual); 23 | 24 | private: 25 | ContainerVisual* parent_; 26 | }; 27 | 28 | class ContainerVisual : public QObject, public Visual 29 | { 30 | Q_OBJECT 31 | public: 32 | static constexpr int ITEM_DATA = 6000; 33 | 34 | static ContainerVisual* fromItem(QGraphicsItem* item); 35 | 36 | public: 37 | ContainerVisual(); 38 | 39 | VisualCollection& Children(); 40 | 41 | Geometry* Clip(); 42 | 43 | void SetClip(Geometry*); 44 | 45 | private: 46 | VisualCollection children_; 47 | }; 48 | 49 | INKCANVAS_END_NAMESPACE 50 | 51 | #endif // WINDOWS_MEDIA_CONTAINERVISUAL_H 52 | -------------------------------------------------------------------------------- /Windows/Media/pointhittestresult.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_POINTHITTESTRESULT_H 2 | #define WINDOWS_MEDIA_POINTHITTESTRESULT_H 3 | 4 | #include "Windows/Media/hittestresult.h" 5 | #include "Windows/point.h" 6 | 7 | // namespace System.Windows.Media 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class UIElement; 11 | 12 | /// 13 | /// This class returns the point and QWidget hit during a hit test pass. 14 | /// 15 | class PointHitTestResult : public HitTestResult 16 | { 17 | private: 18 | Point _pointHit; 19 | 20 | /// 21 | /// This constructor takes a QWidget and point respresenting a hit. 22 | /// 23 | public: 24 | PointHitTestResult(); 25 | 26 | PointHitTestResult(UIElement * visualHit, Point const & pointHit); 27 | 28 | /// 29 | /// The point in local space of the hit QWidget. 30 | /// 31 | Point PointHit() 32 | { 33 | return _pointHit; 34 | } 35 | 36 | /// 37 | /// Re-expose QWidget property strongly typed to 2D QWidget. 38 | /// 39 | UIElement* VisualHit(); 40 | }; 41 | 42 | INKCANVAS_END_NAMESPACE 43 | 44 | #endif // WINDOWS_MEDIA_POINTHITTESTRESULT_H 45 | -------------------------------------------------------------------------------- /Windows/Input/pencontexts.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_PENCONTEXTS_H 2 | #define WINDOWS_INPUT_PENCONTEXTS_H 3 | 4 | #include "Windows/Input/StylusPlugIns/rawstylusactions.h" 5 | #include "Windows/Input/StylusPlugIns/rawstylusinput.h" 6 | #include "Windows/Media/matrix.h" 7 | 8 | #include 9 | #include 10 | 11 | INKCANVAS_BEGIN_NAMESPACE 12 | 13 | class StylusPlugInCollection; 14 | class RawStylusInputCustomData; 15 | class UIElement; 16 | 17 | class PenContexts : public QObject 18 | { 19 | Q_OBJECT 20 | public: 21 | PenContexts(UIElement * element); 22 | 23 | QMutex& SyncRoot(); 24 | 25 | void AddStylusPlugInCollection(StylusPlugInCollection* pic); 26 | 27 | void RemoveStylusPlugInCollection(StylusPlugInCollection* pic); 28 | 29 | void FireCustomData(); 30 | 31 | public: 32 | bool eventFilter(QObject *watched, QEvent *event) override; 33 | 34 | private: 35 | QMutex mutex_; 36 | UIElement * element_; 37 | List stylusPlugIns_; 38 | Matrix transform_; 39 | RawStylusActions action_; 40 | List customDatas_; 41 | }; 42 | 43 | INKCANVAS_END_NAMESPACE 44 | 45 | #endif // WINDOWS_INPUT_PENCONTEXTS_H 46 | -------------------------------------------------------------------------------- /Internal/Ink/strokenodedata.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/strokenodedata.h" 2 | #include "Internal/debug.h" 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | StrokeNodeData StrokeNodeData::s_empty; 7 | 8 | /// 9 | /// Constructor for nodes of a pressure insensitive stroke 10 | /// 11 | /// position of the node 12 | StrokeNodeData::StrokeNodeData(Point const & position) 13 | { 14 | _position = position; 15 | _pressure = 1; 16 | } 17 | 18 | /// 19 | /// Constructor for nodes with pressure data 20 | /// 21 | /// position of the node 22 | /// pressure scaling factor at the node 23 | StrokeNodeData::StrokeNodeData(Point const & position, float pressure) 24 | { 25 | Debug::Assert(DoubleUtil::GreaterThan(pressure, 0)); 26 | 27 | _position = position; 28 | _pressure = pressure; 29 | } 30 | 31 | /// Tells whether the structre was properly initialized 32 | bool StrokeNodeData::IsEmpty() const 33 | { 34 | Debug::Assert(DoubleUtil::AreClose(0, s_empty._pressure)); 35 | return DoubleUtil::AreClose(_pressure, s_empty._pressure); 36 | } 37 | 38 | INKCANVAS_END_NAMESPACE 39 | -------------------------------------------------------------------------------- /Windows/Ink/Ink.pri: -------------------------------------------------------------------------------- 1 | HEADERS += \ 2 | $$PWD/drawingattributes.h \ 3 | $$PWD/drawingflags.h \ 4 | $$PWD/extendedproperty.h \ 5 | $$PWD/extendedpropertycollection.h \ 6 | $$PWD/incrementalhittester.h \ 7 | $$PWD/knownids.h \ 8 | $$PWD/stroke.h \ 9 | $$PWD/strokecollection.h \ 10 | $$PWD/strokeintersection.h \ 11 | $$PWD/stylusshape.h \ 12 | $$PWD/stylustip.h 13 | 14 | SOURCES += \ 15 | $$PWD/drawingattributes.cpp \ 16 | $$PWD/drawingflags.cpp \ 17 | $$PWD/extendedproperty.cpp \ 18 | $$PWD/extendedpropertycollection.cpp \ 19 | $$PWD/incrementalhittester.cpp \ 20 | $$PWD/knownids.cpp \ 21 | $$PWD/stroke.cpp \ 22 | $$PWD/strokecollection.cpp \ 23 | $$PWD/strokeintersection.cpp \ 24 | $$PWD/stylusshape.cpp \ 25 | $$PWD/stylustip.cpp 26 | 27 | !inkcanvas_core: { 28 | 29 | HEADERS += \ 30 | $$PWD/applicationgesture.h \ 31 | $$PWD/events.h \ 32 | $$PWD/gesturerecognitionresult.h \ 33 | 34 | SOURCES += \ 35 | $$PWD/applicationgesture.cpp \ 36 | $$PWD/gesturerecognitionresult.cpp \ 37 | 38 | win32 { 39 | HEADERS += \ 40 | $$PWD/gesturerecognizer.h \ 41 | 42 | SOURCES += \ 43 | $$PWD/gesturerecognizer.cpp \ 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Windows/Media/streamgeometry.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_STREAMGEOMETRY_H 2 | #define WINDOWS_MEDIA_STREAMGEOMETRY_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Windows/Media/geometry.h" 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | /// 10 | /// FillRule - 11 | /// 12 | enum FillRule 13 | { 14 | /// 15 | /// EvenOdd - 16 | /// 17 | EvenOdd = 0, 18 | 19 | /// 20 | /// Nonzero - 21 | /// 22 | Nonzero = 1, 23 | }; 24 | 25 | 26 | class StreamGeometryContext; 27 | 28 | // namespace System.Windows.Media 29 | 30 | class StreamGeometry : public Geometry 31 | { 32 | public: 33 | StreamGeometry(); 34 | 35 | virtual ~StreamGeometry() override; 36 | 37 | void SetFillRule(FillRule value); 38 | 39 | StreamGeometryContext &Open(); 40 | 41 | void Close(void * path); 42 | 43 | void * path() { return path_; } 44 | 45 | virtual Rect Bounds() override; 46 | 47 | #ifdef INKCANVAS_QT_DRAW 48 | virtual void Draw(QPainter& painter) override; 49 | #endif 50 | 51 | private: 52 | StreamGeometryContext * context_ = nullptr; 53 | void * path_ = nullptr; 54 | }; 55 | 56 | INKCANVAS_END_NAMESPACE 57 | 58 | #endif // WINDOWS_MEDIA_STREAMGEOMETRY_H 59 | -------------------------------------------------------------------------------- /cmath.h: -------------------------------------------------------------------------------- 1 | #ifndef CMATH_H 2 | #define CMATH_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class Math 12 | { 13 | public: 14 | static constexpr double PI = 3.14159265358979323846; 15 | 16 | static double Sqrt(double v) 17 | { 18 | return sqrt(v); 19 | } 20 | 21 | static double Abs(double v) 22 | { 23 | return abs(v); 24 | } 25 | 26 | static double Max(double v1, double v2) 27 | { 28 | return (std::max)(v1, v2); 29 | } 30 | 31 | static double Min(double v1, double v2) 32 | { 33 | return (std::min)(v1, v2); 34 | } 35 | 36 | static double Round(double v) 37 | { 38 | return std::round(v); 39 | } 40 | 41 | static double Sin(double v) 42 | { 43 | return sin(v); 44 | } 45 | 46 | static double Cos(double v) 47 | { 48 | return cos(v); 49 | } 50 | 51 | static double Tan(double v) 52 | { 53 | return tan(v); 54 | } 55 | 56 | static double Atan(double v) 57 | { 58 | return atan(v); 59 | } 60 | 61 | static double Atan2(double y, double x) 62 | { 63 | return atan2(y, x); 64 | } 65 | }; 66 | 67 | INKCANVAS_END_NAMESPACE 68 | 69 | #endif // CMATH_H 70 | -------------------------------------------------------------------------------- /Windows/Media/visual.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_VISUAL_H 2 | #define WINDOWS_MEDIA_VISUAL_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include "Windows/dependencyobject.h" 7 | #include "pointhittestparameters.h" 8 | #include "Windows/Media/matrix.h" 9 | 10 | #include 11 | 12 | // namespace System.Windows.Media 13 | INKCANVAS_BEGIN_NAMESPACE 14 | 15 | class HitTestResult; 16 | 17 | class INKCANVAS_EXPORT Visual : public QGraphicsItem, public DependencyObject 18 | { 19 | public: 20 | Visual(); 21 | 22 | virtual ~Visual() override; 23 | 24 | public: 25 | void SetOpacity(double opacity); 26 | 27 | GeneralTransform TransformToAncestor(Visual* visual); 28 | 29 | GeneralTransform TransformToDescendant(Visual* visual); 30 | 31 | void AddVisualChild(Visual *); 32 | 33 | void RemoveVisualChild(Visual *); 34 | 35 | Visual* VisualParent(); 36 | 37 | protected: 38 | virtual void OnVisualChildrenChanged(DependencyObject* visualAdded, DependencyObject* visualRemoved); 39 | 40 | virtual HitTestResult HitTestCore(PointHitTestParameters hitTestParams); 41 | 42 | public: 43 | virtual QRectF boundingRect() const override; 44 | 45 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; 46 | }; 47 | 48 | INKCANVAS_END_NAMESPACE 49 | 50 | #endif // WINDOWS_MEDIA_VISUAL_H 51 | -------------------------------------------------------------------------------- /Windows/dependencyproperty.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/dependencyproperty.h" 2 | #include "Windows/dependencypropertychangedeventargs.h" 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | QVariant const DependencyProperty::UnsetValue; 7 | 8 | DependencyProperty::DependencyProperty(QVariant dflt) 9 | : default_(dflt) 10 | { 11 | } 12 | 13 | DependencyProperty::DependencyProperty(QVariant dflt, DependencyProperty::PropertyChangedCallback changed) 14 | : default_(dflt) 15 | , changed_(changed) 16 | { 17 | 18 | } 19 | 20 | DependencyProperty::DependencyProperty(QVariant dflt, DependencyProperty::PropertyChangedCallback changed, DependencyProperty::ValidateValueCallback validate) 21 | : default_(dflt) 22 | , changed_(changed) 23 | , validate_(validate) 24 | { 25 | 26 | } 27 | 28 | int DependencyProperty::GlobalIndex() const 29 | { 30 | return 0; 31 | } 32 | 33 | QVariant DependencyProperty::DefaultValue() const 34 | { 35 | if (default_.userType() == qMetaTypeId()) 36 | return default_.value()->DefaultValue(); 37 | else 38 | return default_; 39 | } 40 | 41 | void DependencyProperty::Changed(DependencyObject& d, QVariant old, QVariant new_) const 42 | { 43 | if (changed_) { 44 | DependencyPropertyChangedEventArgs args(this, old, new_); 45 | changed_(d, args); 46 | } 47 | } 48 | 49 | INKCANVAS_END_NAMESPACE 50 | -------------------------------------------------------------------------------- /Windows/Ink/extendedproperty.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Ink/extendedproperty.h" 2 | #include "Windows/Ink/knownids.h" 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | ExtendedProperty ExtendedProperty::Empty; 7 | 8 | /// 9 | /// Create a new drawing attribute with the specified key and value 10 | /// 11 | /// Identifier of attribute 12 | /// Attribute value - not that the Type for value is tied to the id 13 | /// Value type must be compatible with attribute Id 14 | ExtendedProperty::ExtendedProperty(Guid const & id, Variant const & value) 15 | { 16 | if (id== Guid::Empty) 17 | { 18 | throw std::runtime_error("(SR.Get(SRID.InvalidGuid)"); 19 | } 20 | _id = id; 21 | _value = value; 22 | } 23 | 24 | ExtendedProperty::ExtendedProperty() 25 | { 26 | } 27 | 28 | #ifdef INKCANVAS_QT_VARIANT 29 | 30 | QString ExtendedProperty::ToString() 31 | { 32 | QString val; 33 | //if (Value == null) 34 | //{ 35 | // val = ""; 36 | //} 37 | //else if (Value is string) 38 | //{ 39 | // val = "\"" + Value.ToString() + "\""; 40 | //} 41 | //else 42 | //{ 43 | // val = Value.ToString(); 44 | //} 45 | return KnownIds::ConvertToString(Id()) + "," + Value().toString(); 46 | } 47 | 48 | #endif 49 | 50 | INKCANVAS_END_NAMESPACE 51 | -------------------------------------------------------------------------------- /Windows/Controls/inkcanvasselectionhitresult.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_CONTROLS_INKCANVASSELECTIONHITRESULT_H 2 | #define WINDOWS_CONTROLS_INKCANVASSELECTIONHITRESULT_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | // namespace System.Windows.Controls 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | /// 10 | /// InkCanvas Selection Hit Result 11 | /// 12 | enum class InkCanvasSelectionHitResult 13 | { 14 | /// 15 | /// None 16 | /// 17 | None = 0, 18 | /// 19 | /// TopLeft 20 | /// 21 | TopLeft = 1, 22 | /// 23 | /// Top 24 | /// 25 | Top = 2, 26 | /// 27 | /// TopRight 28 | /// 29 | TopRight = 3, 30 | /// 31 | /// Right 32 | /// 33 | Right = 4, 34 | /// 35 | /// BottomRight 36 | /// 37 | BottomRight = 5, 38 | /// 39 | /// Bottom 40 | /// 41 | Bottom = 6, 42 | /// 43 | /// BottomLeft 44 | /// 45 | BottomLeft = 7, 46 | /// 47 | /// Left 48 | /// 49 | Left = 8, 50 | /// 51 | /// Selection 52 | /// 53 | Selection = 9, 54 | }; 55 | 56 | INKCANVAS_END_NAMESPACE 57 | 58 | #endif // WINDOWS_CONTROLS_INKCANVASSELECTIONHITRESULT_H 59 | -------------------------------------------------------------------------------- /Windows/Input/inputdevice.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_INPUTDEVICE_H 2 | #define WINDOWS_INPUT_INPUTDEVICE_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Collections/Generic/array.h" 6 | #include "sharedptr.h" 7 | 8 | #include 9 | 10 | class QInputEvent; 11 | 12 | // namespace System.Windows.Input 13 | INKCANVAS_BEGIN_NAMESPACE 14 | 15 | class UIElement; 16 | class Visual; 17 | class PresentationSource; 18 | class RoutedEvent; 19 | class StylusPointDescription; 20 | 21 | /// 22 | /// Provides the base class for all input devices. 23 | /// 24 | class InputDevice : public QObject 25 | { 26 | Q_OBJECT 27 | protected: 28 | /// 29 | /// Constructs an instance of the InputDevice class. 30 | /// 31 | InputDevice() 32 | { 33 | // Only we can create these. 34 | // 35 | } 36 | 37 | public: 38 | /// 39 | /// Returns the element that input from this device is sent to. 40 | /// 41 | virtual UIElement* Target() = 0; 42 | 43 | /// 44 | /// Returns the PresentationSource that is reporting input for this device. 45 | /// 46 | virtual PresentationSource* ActiveSource() = 0; 47 | 48 | virtual int Id() = 0; 49 | 50 | virtual SharedPointer PointDescription() = 0; 51 | 52 | virtual Array PacketData(QEvent& event) = 0; 53 | }; 54 | 55 | INKCANVAS_END_NAMESPACE 56 | 57 | #endif // WINDOWS_INPUT_INPUTDEVICE_H 58 | -------------------------------------------------------------------------------- /Landing/Qt/inkcanvasqt.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVASQT_H 2 | #define INKCANVASQT_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | class QPainterPath; 11 | 12 | INKCANVAS_BEGIN_NAMESPACE 13 | 14 | class Stroke; 15 | 16 | class INKCANVAS_EXPORT InkCanvasQt 17 | { 18 | public: 19 | static QSharedPointer createStroke(QList const & points, QList const & pressures, 20 | qreal width, bool fitToCorve = true, bool ellipseShape = true, bool addPressure = true); 21 | 22 | static QSharedPointer createStroke(QPainterPath const & path, QColor color, qreal width); 23 | 24 | // may release old from out 25 | static void cloneStroke(QSharedPointer & out, QSharedPointer const & stroke); 26 | 27 | // may release old from out 28 | static void shareStroke(QSharedPointer & out, QSharedPointer const & stroke); 29 | 30 | static void transformStroke(QSharedPointer const & stroke, QMatrix const & matrix); 31 | 32 | static bool hitTestStroke(QSharedPointer const & stroke, QPointF const & point); 33 | 34 | static QPainterPath const & getStrokeGeometry(QSharedPointer const & stroke, QRectF & bounds); 35 | 36 | static void freeStroke(QSharedPointer & stroke); 37 | 38 | // called when unload library 39 | static void unload(); 40 | 41 | }; 42 | 43 | INKCANVAS_END_NAMESPACE 44 | 45 | #endif // INKCANVASQT_H 46 | -------------------------------------------------------------------------------- /Windows/Input/Input.pri: -------------------------------------------------------------------------------- 1 | !inkcanvas_core: include(StylusPlugIns/StylusPlugIns.pri) 2 | 3 | HEADERS += \ 4 | $$PWD/styluspoint.h \ 5 | $$PWD/styluspointcollection.h \ 6 | $$PWD/styluspointdescription.h \ 7 | $$PWD/styluspointproperties.h \ 8 | $$PWD/styluspointproperty.h \ 9 | $$PWD/styluspointpropertyids.h \ 10 | $$PWD/styluspointpropertyinfo.h \ 11 | $$PWD/styluspointpropertyinfodefaults.h 12 | 13 | SOURCES += \ 14 | $$PWD/styluspoint.cpp \ 15 | $$PWD/styluspointcollection.cpp \ 16 | $$PWD/styluspointdescription.cpp \ 17 | $$PWD/styluspointproperties.cpp \ 18 | $$PWD/styluspointproperty.cpp \ 19 | $$PWD/styluspointpropertyids.cpp \ 20 | $$PWD/styluspointpropertyinfo.cpp \ 21 | $$PWD/styluspointpropertyinfodefaults.cpp 22 | 23 | !inkcanvas_core: { 24 | 25 | HEADERS += \ 26 | $$PWD/inputdevice.h \ 27 | $$PWD/inputeventargs.h \ 28 | $$PWD/mousebuttoneventargs.h \ 29 | $$PWD/mousebuttonstate.h \ 30 | $$PWD/mousedevice.h \ 31 | $$PWD/mouseeventargs.h \ 32 | $$PWD/pencontexts.h \ 33 | $$PWD/querycursoreventargs.h \ 34 | $$PWD/stylusdevice.h \ 35 | $$PWD/styluseventargs.h \ 36 | 37 | SOURCES += \ 38 | $$PWD/inputdevice.cpp \ 39 | $$PWD/inputeventargs.cpp \ 40 | $$PWD/mousebuttoneventargs.cpp \ 41 | $$PWD/mousebuttonstate.cpp \ 42 | $$PWD/mousedevice.cpp \ 43 | $$PWD/mouseeventargs.cpp \ 44 | $$PWD/pencontexts.cpp \ 45 | $$PWD/querycursoreventargs.cpp \ 46 | $$PWD/stylusdevice.cpp \ 47 | $$PWD/styluseventargs.cpp \ 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Windows/Controls/editingmode.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_CONTROLS_EDITINGMODE_H 2 | #define WINDOWS_CONTROLS_EDITINGMODE_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | // namespace System.Windows.Controls 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | enum class InkCanvasEditingMode 12 | { 13 | /// 14 | /// None 15 | /// 16 | None = 0, 17 | /// 18 | /// Ink 19 | /// 20 | Ink, 21 | /// 22 | /// GestureOnly 23 | /// 24 | GestureOnly, 25 | /// 26 | /// InkAndGesture 27 | /// 28 | InkAndGesture, 29 | /// 30 | /// Select 31 | /// 32 | Select, 33 | /// 34 | /// EraseByPoint 35 | /// 36 | EraseByPoint, 37 | /// 38 | /// EraseByStroke 39 | /// 40 | EraseByStroke, 41 | }; 42 | 43 | // NOTICE-2004/10/13-WAYNEZEN, 44 | // Whenever the InkCanvasEditingMode is modified, please update this EditingModeHelper.IsDefined. 45 | class EditingModeHelper 46 | { 47 | public: 48 | // Helper like Enum.IsDefined, for InkCanvasEditingMode:: 49 | static bool IsDefined(InkCanvasEditingMode InkCanvasEditingMode) 50 | { 51 | return (InkCanvasEditingMode >= InkCanvasEditingMode::None && InkCanvasEditingMode <= InkCanvasEditingMode::EraseByStroke); 52 | } 53 | }; 54 | 55 | INKCANVAS_END_NAMESPACE 56 | 57 | Q_DECLARE_METATYPE(INKCANVAS_PREPEND_NAMESPACE(InkCanvasEditingMode)) 58 | 59 | #endif // WINDOWS_CONTROLS_EDITINGMODE_H 60 | -------------------------------------------------------------------------------- /eventargs.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTARGS_H 2 | #define EVENTARGS_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class EventArgs; 11 | 12 | class EventHandler 13 | { 14 | public: 15 | EventHandler() : data_(nullptr), handle_(nullptr) {} 16 | 17 | EventHandler(std::nullptr_t) : data_(nullptr), handle_(nullptr) {} 18 | 19 | void operator()(EventArgs & e) const 20 | { 21 | handle_(data_, e); 22 | } 23 | 24 | friend bool operator==(EventHandler const & l, EventHandler const & r) 25 | { 26 | return l.data_ == r.data_ && l.handle_ == r.handle_; 27 | } 28 | 29 | friend bool operator!=(EventHandler const & l, EventHandler const & r) 30 | { 31 | return !(l == r); 32 | } 33 | 34 | protected: 35 | EventHandler(void * data, void (*handle)(void*, EventArgs & e)) : data_(data), handle_(handle) {} 36 | 37 | private: 38 | void * data_ = nullptr; 39 | void (*handle_)(void*, EventArgs & e) = nullptr; 40 | }; 41 | 42 | template 43 | class EventHandlerT : public EventHandler 44 | { 45 | public: 46 | EventHandlerT(T * obj) : EventHandler(obj, handle) {} 47 | private: 48 | static void handle(void* obj, EventArgs & e) 49 | { 50 | (reinterpret_cast(obj)->*H)(static_cast(e)); 51 | } 52 | }; 53 | 54 | // namespace System 55 | 56 | class EventArgs 57 | { 58 | public: 59 | static EventArgs Empty; 60 | 61 | EventArgs(); 62 | }; 63 | 64 | INKCANVAS_END_NAMESPACE 65 | 66 | #endif // EVENTARGS_H 67 | -------------------------------------------------------------------------------- /Windows/Media/containervisual.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/containervisual.h" 2 | 3 | INKCANVAS_BEGIN_NAMESPACE 4 | 5 | ContainerVisual *ContainerVisual::fromItem(QGraphicsItem *item) 6 | { 7 | if (item == nullptr) 8 | return nullptr; 9 | QVariant elem = item->data(ITEM_DATA); 10 | if (elem.userType() == qMetaTypeId()) { 11 | ContainerVisual * ue = elem.value(); 12 | if (ue == item) 13 | return ue; 14 | } 15 | return nullptr; 16 | } 17 | 18 | ContainerVisual::ContainerVisual() 19 | : children_(this) 20 | { 21 | setData(ITEM_DATA, QVariant::fromValue(this)); 22 | } 23 | 24 | VisualCollection& ContainerVisual::Children() 25 | { 26 | return children_; 27 | } 28 | 29 | Geometry* ContainerVisual::Clip() 30 | { 31 | return nullptr; 32 | } 33 | 34 | void ContainerVisual::SetClip(Geometry *) 35 | { 36 | } 37 | 38 | VisualCollection::VisualCollection(ContainerVisual *parent) 39 | : parent_(parent) 40 | { 41 | } 42 | 43 | void VisualCollection::Add(Visual *visual) 44 | { 45 | parent_->AddVisualChild(visual); 46 | Collection::Add(visual); 47 | } 48 | 49 | void VisualCollection::Insert(int index, Visual *visual) 50 | { 51 | parent_->AddVisualChild(visual); 52 | if (index < Count()) 53 | visual->stackBefore(at(index)); 54 | InsertItem(index, visual); 55 | } 56 | 57 | void VisualCollection::Remove(Visual *visual) 58 | { 59 | if (Contains(visual)) { 60 | Collection::Remove(visual); 61 | parent_->RemoveVisualChild(visual); 62 | } 63 | } 64 | 65 | INKCANVAS_END_NAMESPACE 66 | -------------------------------------------------------------------------------- /Windows/dependencyobject.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/dependencyobject.h" 2 | #include "Windows/dependencyproperty.h" 3 | #include "Windows/dispatcher.h" 4 | #include "Windows/Media/visual.h" 5 | 6 | #include 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | DependencyObject::DependencyObject() 12 | { 13 | } 14 | 15 | DependencyObject::~DependencyObject() 16 | { 17 | } 18 | 19 | void DependencyObject::SetValue(DependencyProperty const * prop, QVariant value) 20 | { 21 | QVariant old = props_.value(prop); 22 | if (value == old) 23 | return; 24 | props_[prop] = value; 25 | prop->Changed(*this, old, value); 26 | } 27 | 28 | 29 | QVariant DependencyObject::GetValue(DependencyProperty const * prop) 30 | { 31 | QVariant v = props_.value(prop); 32 | if (v.isValid()) 33 | return v; 34 | v = prop->DefaultValue(); 35 | if (v.isValid()) { 36 | props_.insert(prop, v); 37 | //prop->Changed(*this, QVariant(), v); 38 | } 39 | return v; 40 | } 41 | 42 | void DependencyObject::InvalidateSubProperty(DependencyProperty const *) 43 | { 44 | 45 | } 46 | 47 | Dispatcher* DependencyObject::GetDispatcher() const 48 | { 49 | return Dispatcher::from(QThread::currentThread()); 50 | } 51 | 52 | void DependencyObject::VerifyAccess() const 53 | { 54 | GetDispatcher()->VerifyAccess(); 55 | } 56 | 57 | bool DependencyObject::CheckAccess() const 58 | { 59 | return GetDispatcher()->CheckAccess(); 60 | } 61 | 62 | void DependencyObject::OnPropertyChanged(DependencyPropertyChangedEventArgs &) 63 | { 64 | } 65 | 66 | INKCANVAS_END_NAMESPACE 67 | -------------------------------------------------------------------------------- /Internal/debug.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/debug.h" 2 | 3 | #include 4 | 5 | #ifdef INKCANVAS_ANDROID 6 | #include 7 | #elif defined INKCANVAS_IOS || defined INKCANVAS_MACOS 8 | #include 9 | extern "C" void NS_Log(char const * t, char const * m, va_list args); 10 | #elif defined INKCANVAS_QT 11 | #include 12 | #include 13 | #include 14 | #endif 15 | 16 | #define _STRING(x) #x 17 | #define STRING(x) _STRING(x) 18 | 19 | INKCANVAS_BEGIN_NAMESPACE 20 | 21 | void Debug::Log(const char *message, ...) 22 | { 23 | #ifdef INKCANVAS_ANDROID 24 | va_list args; 25 | va_start(args, message); 26 | __android_log_vprint(ANDROID_LOG_WARN, STRING(INKCANVAS_NAMESPACE), message, args); 27 | va_end(args); 28 | #elif defined INKCANVAS_IOS || defined INKCANVAS_MACOS 29 | va_list args; 30 | va_start(args, message); 31 | NS_Log(STRING(INKCANVAS_NAMESPACE), message, args); 32 | va_end(args); 33 | #elif defined INKCANVAS_QT 34 | va_list args; 35 | va_start(args, message); 36 | char buf[1024]; 37 | #if defined WIN32 38 | vsprintf_s(buf, message, args); 39 | #else 40 | vsprintf(buf, message, args); 41 | #endif 42 | va_end(args); 43 | qDebug() << buf; 44 | #else 45 | (void) message; 46 | #endif 47 | } 48 | 49 | void Debug::_Assert(bool condition, char const * message) 50 | { 51 | if (condition) 52 | return; 53 | #ifdef INKCANVAS_ANDROID 54 | __android_log_assert(message, "InkCanvasAndroid", nullptr); 55 | #else 56 | assert(condition); 57 | (void) message; 58 | #endif 59 | } 60 | 61 | INKCANVAS_END_NAMESPACE 62 | -------------------------------------------------------------------------------- /Windows/Controls/decorator.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_CONTROLS_DECORATOR_H 2 | #define WINDOWS_CONTROLS_DECORATOR_H 3 | 4 | #include "Windows/uielement.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | class Decorator : public FrameworkElement 9 | { 10 | Q_OBJECT 11 | public: 12 | Decorator(); 13 | 14 | virtual UIElement* Child(); 15 | 16 | virtual void SetChild(UIElement * value); 17 | 18 | private: 19 | UIElement* child_ = nullptr; 20 | }; 21 | 22 | class DrawingContext; 23 | 24 | class Adorner : public FrameworkElement 25 | { 26 | Q_OBJECT 27 | public: 28 | Adorner(UIElement* adornedElement); 29 | 30 | UIElement* AdornedElement(); 31 | 32 | virtual GeneralTransform GetDesiredTransform(GeneralTransform const& transform); 33 | 34 | virtual void OnRender(DrawingContext& drawingContext) = 0; 35 | 36 | protected: 37 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; 38 | 39 | private: 40 | UIElement* adornedElement_; 41 | }; 42 | 43 | class AdornerLayer : public FrameworkElement 44 | { 45 | Q_OBJECT 46 | public: 47 | void Add(Adorner* adorner); 48 | 49 | void Remove(Adorner* adorner); 50 | 51 | static AdornerLayer *GetAdornerLayer(Visual* visual); 52 | }; 53 | 54 | class AdornerDecorator : public Decorator 55 | { 56 | Q_OBJECT 57 | public: 58 | AdornerDecorator(); 59 | 60 | virtual void SetChild(UIElement * value); 61 | 62 | AdornerLayer* GetAdornerLayer(); 63 | 64 | private: 65 | AdornerLayer* adornerLayer_; 66 | }; 67 | 68 | INKCANVAS_END_NAMESPACE 69 | 70 | #endif // WINDOWS_CONTROLS_DECORATOR_H 71 | -------------------------------------------------------------------------------- /Landing/Macos/inkcanvasmacos.m: -------------------------------------------------------------------------------- 1 | #include "inkcanvasmacos.h" 2 | #include "strokewrapper.h" 3 | 4 | void NS_Log(char const * t, char const * m, va_list args) 5 | { 6 | NSLogv([NSString stringWithFormat:@"%s %s", t, m], args); 7 | } 8 | 9 | @implementation InkCanvasMacos 10 | 11 | - (long) newStrokeWithPoints:(int) n points:(CGPoint[]) points pressures:(float[]) pressures 12 | width:(double) width fitToCorve:(bool) fitToCorve 13 | ellipseShape:(bool) ellipseShape addPressure:(bool) addPressure { 14 | double x[n]; 15 | double y[n]; 16 | for (int i = 0; i < n; ++n) { 17 | x[i] = points[i].x; 18 | y[i] = points[i].y; 19 | } 20 | return StrokeWrapper_new(n, x, y, pressures, width, 21 | fitToCorve, ellipseShape, addPressure); 22 | } 23 | 24 | - (long) cloneStroke:(long) stroke { 25 | return StrokeWrapper_clone(stroke); 26 | } 27 | 28 | - (void) transformStroke:(long) stroke withMatrix:(CGAffineTransform) matrix { 29 | double matrix2[6] = {matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty}; 30 | StrokeWrapper_transform(stroke, matrix2); 31 | } 32 | 33 | - (bool) hitTestStroke:(long) stroke withPoint:(CGPoint) point { 34 | return StrokeWrapper_hitTest(stroke, point.x, point.y); 35 | } 36 | 37 | - (NSBezierPath*) getStrokeGeometry:(long) stroke andBounds:(CGRect) bounds { 38 | double b[4]; 39 | void * path = StrokeWrapper_getGeometry(stroke, b); 40 | bounds = CGRectMake(b[0], b[1], b[2], b[3]); 41 | return (NSBezierPath*) path; 42 | } 43 | 44 | - (void) deleteStroke:(long) stroke { 45 | StrokeWrapper_delete(stroke); 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Internal/Ink/strokenodedata.h: -------------------------------------------------------------------------------- 1 | #ifndef STROKENODEDATA_H 2 | #define STROKENODEDATA_H 3 | 4 | #include "Internal/doubleutil.h" 5 | #include "Windows/point.h" 6 | 7 | // namespace MS.Internal.Ink 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | /// 11 | /// This structure represents a node on a stroke spine. 12 | /// 13 | class StrokeNodeData 14 | { 15 | private: 16 | static StrokeNodeData s_empty; 17 | 18 | public: 19 | /// Returns static object representing an unitialized node 20 | static StrokeNodeData Empty() { return s_empty; } 21 | 22 | StrokeNodeData() 23 | { 24 | } 25 | 26 | /// 27 | /// Constructor for nodes of a pressure insensitive stroke 28 | /// 29 | /// position of the node 30 | StrokeNodeData(Point const & position); 31 | 32 | /// 33 | /// Constructor for nodes with pressure data 34 | /// 35 | /// position of the node 36 | /// pressure scaling factor at the node 37 | StrokeNodeData(Point const & position, float pressure); 38 | 39 | /// Tells whether the structre was properly initialized 40 | bool IsEmpty() const; 41 | 42 | /// Position of the node 43 | Point const & Position() const 44 | { 45 | return _position; 46 | } 47 | 48 | /// Pressure scaling factor at the node 49 | float PressureFactor() const { return _pressure; } 50 | 51 | private: 52 | Point _position; 53 | float _pressure = 0.0; 54 | }; 55 | 56 | INKCANVAS_END_NAMESPACE 57 | 58 | #endif // STROKENODEDATA_H 59 | -------------------------------------------------------------------------------- /Landing/Ios/inkcanvasios.m: -------------------------------------------------------------------------------- 1 | #include "inkcanvasios.h" 2 | #include "strokewrapper.h" 3 | 4 | void NS_Log(char const * t, char const * m, va_list args) 5 | { 6 | NSLogv([NSString stringWithFormat:@"%s %s", t, m], args); 7 | } 8 | 9 | @implementation ICStroke 10 | 11 | - (instancetype) initWithPoints:(int) n points:(CGPoint[]) points pressures:(float[]) pressures 12 | width:(double) width fitToCorve:(bool) fitToCorve 13 | ellipseShape:(bool) ellipseShape addPressure:(bool) addPressure { 14 | double x[n]; 15 | double y[n]; 16 | for (int i = 0; i < n; ++i) { 17 | x[i] = points[i].x; 18 | y[i] = points[i].y; 19 | } 20 | _stroke = StrokeWrapper_new(n, x, y, pressures, width, 21 | fitToCorve, ellipseShape, addPressure); 22 | return self; 23 | } 24 | 25 | - (ICStroke*) clone { 26 | ICStroke* sc = [ICStroke alloc]; 27 | sc->_stroke = StrokeWrapper_clone(_stroke); 28 | return sc; 29 | } 30 | 31 | - (void) transformWithMatrix:(CGAffineTransform) matrix { 32 | double matrix2[6] = {matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty}; 33 | StrokeWrapper_transform(_stroke, matrix2); 34 | } 35 | 36 | - (bool) hitTestWithPoint:(CGPoint) point { 37 | return StrokeWrapper_hitTest(_stroke, point.x, point.y); 38 | } 39 | 40 | - (UIBezierPath*) getGeometryAndBounds:(CGRect*) bounds { 41 | double b[4]; 42 | void * path = StrokeWrapper_getGeometry(_stroke, b); 43 | if (bounds) 44 | *bounds = CGRectMake(b[0], b[1], b[2], b[3]); 45 | return (UIBezierPath*) path; 46 | } 47 | 48 | - (void) dealloc { 49 | StrokeWrapper_delete(_stroke); 50 | [super dealloc]; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Windows/dependencyobject.h: -------------------------------------------------------------------------------- 1 | #ifndef DEPENDENCYOBJECT_H 2 | #define DEPENDENCYOBJECT_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class Dispatcher; 12 | class DependencyProperty; 13 | class DependencyPropertyChangedEventArgs; 14 | 15 | enum RequestFlags 16 | { 17 | FullyResolved = 0x00, 18 | AnimationBaseValue = 0x01, 19 | CoercionBaseValue = 0x02, 20 | DeferredReferences = 0x04, 21 | SkipDefault = 0x08, 22 | RawEntry = 0x10, 23 | }; 24 | 25 | // namespace System.Windows 26 | 27 | class DependencyObject 28 | { 29 | public: 30 | DependencyObject(); 31 | 32 | virtual ~DependencyObject(); 33 | 34 | public: 35 | void SetValue(DependencyProperty const * prop, QVariant value); 36 | 37 | template 38 | void SetValue(DependencyProperty const * prop, T value) 39 | { 40 | SetValue(prop, QVariant::fromValue(value)); 41 | } 42 | 43 | QVariant GetValue(DependencyProperty const * prop); 44 | 45 | template 46 | T GetValue(DependencyProperty const * prop) 47 | { 48 | QVariant value = GetValue(prop); 49 | if (value.isNull()) 50 | return T(); 51 | return value.value(); 52 | } 53 | 54 | void InvalidateSubProperty(DependencyProperty const * prop); 55 | 56 | Dispatcher* GetDispatcher() const; 57 | 58 | void VerifyAccess() const; 59 | 60 | bool CheckAccess() const; 61 | 62 | protected: 63 | virtual void OnPropertyChanged(DependencyPropertyChangedEventArgs& e); 64 | 65 | private: 66 | QMap props_; 67 | }; 68 | 69 | INKCANVAS_END_NAMESPACE 70 | 71 | #endif // DEPENDENCYOBJECT_H 72 | -------------------------------------------------------------------------------- /Landing/Ios/iosstreamgeometrycontext.h: -------------------------------------------------------------------------------- 1 | #ifndef IOSSTREAMGEOMETRYCONTEXT_H 2 | #define IOSSTREAMGEOMETRYCONTEXT_H 3 | 4 | #include 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | class StreamGeometry; 9 | 10 | class IosStreamGeometryContext : public StreamGeometryContext 11 | { 12 | public: 13 | IosStreamGeometryContext(StreamGeometry * geometry); 14 | virtual ~IosStreamGeometryContext() override; 15 | 16 | // StreamGeometryContext interface 17 | public: 18 | virtual void BeginFigure(const Point &startPoint, bool isFilled, bool isClosed) override; 19 | virtual void LineTo(const Point &point, bool isStroked, bool isSmoothJoin) override; 20 | virtual void QuadraticBezierTo(const Point &point1, const Point &point2, bool isStroked, bool isSmoothJoin) override; 21 | virtual void BezierTo(const Point &point1, const Point &point2, const Point &point3, bool isStroked, bool isSmoothJoin) override; 22 | virtual void PolyLineTo(const List &points, bool isStroked, bool isSmoothJoin) override; 23 | virtual void PolyQuadraticBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 24 | virtual void PolyBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 25 | virtual void ArcTo(const Point &point, const Size &size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked, bool isSmoothJoin) override; 26 | virtual void Close() override; 27 | virtual void SetClosedState(bool closed) override; 28 | virtual void DisposeCore() override; 29 | 30 | private: 31 | StreamGeometry * geometry_ = nullptr; 32 | void * path_ = nullptr; 33 | }; 34 | 35 | INKCANVAS_END_NAMESPACE 36 | 37 | #endif // IOSSTREAMGEOMETRYCONTEXT_H 38 | -------------------------------------------------------------------------------- /Landing/Macos/macosstreamgeometrycontext.h: -------------------------------------------------------------------------------- 1 | #ifndef IOSSTREAMGEOMETRYCONTEXT_H 2 | #define IOSSTREAMGEOMETRYCONTEXT_H 3 | 4 | #include 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | class StreamGeometry; 9 | 10 | class MacosStreamGeometryContext : public StreamGeometryContext 11 | { 12 | public: 13 | MacosStreamGeometryContext(StreamGeometry * geometry); 14 | virtual ~MacosStreamGeometryContext() override; 15 | 16 | // StreamGeometryContext interface 17 | public: 18 | virtual void BeginFigure(const Point &startPoint, bool isFilled, bool isClosed) override; 19 | virtual void LineTo(const Point &point, bool isStroked, bool isSmoothJoin) override; 20 | virtual void QuadraticBezierTo(const Point &point1, const Point &point2, bool isStroked, bool isSmoothJoin) override; 21 | virtual void BezierTo(const Point &point1, const Point &point2, const Point &point3, bool isStroked, bool isSmoothJoin) override; 22 | virtual void PolyLineTo(const List &points, bool isStroked, bool isSmoothJoin) override; 23 | virtual void PolyQuadraticBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 24 | virtual void PolyBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 25 | virtual void ArcTo(const Point &point, const Size &size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked, bool isSmoothJoin) override; 26 | virtual void Close() override; 27 | virtual void SetClosedState(bool closed) override; 28 | virtual void DisposeCore() override; 29 | 30 | private: 31 | StreamGeometry * geometry_ = nullptr; 32 | void * path_ = nullptr; 33 | }; 34 | 35 | INKCANVAS_END_NAMESPACE 36 | 37 | #endif // IOSSTREAMGEOMETRYCONTEXT_H 38 | -------------------------------------------------------------------------------- /Landing/Qt/qtstreamgeometrycontext.h: -------------------------------------------------------------------------------- 1 | #ifndef QTSTREAMGEOMETRYCONTEXT_H 2 | #define QTSTREAMGEOMETRYCONTEXT_H 3 | 4 | #include "Windows/Media/streamgeometrycontext.h" 5 | 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class StreamGeometry; 11 | 12 | class QtStreamGeometryContext : public StreamGeometryContext 13 | { 14 | public: 15 | QtStreamGeometryContext(StreamGeometry* geometry); 16 | 17 | 18 | // StreamGeometryContext interface 19 | public: 20 | virtual void BeginFigure(const Point &startPoint, bool isFilled, bool isClosed) override; 21 | virtual void LineTo(const Point &point, bool isStroked, bool isSmoothJoin) override; 22 | virtual void QuadraticBezierTo(const Point &point1, const Point &point2, bool isStroked, bool isSmoothJoin) override; 23 | virtual void BezierTo(const Point &point1, const Point &point2, const Point &point3, bool isStroked, bool isSmoothJoin) override; 24 | virtual void PolyLineTo(const List &points, bool isStroked, bool isSmoothJoin) override; 25 | virtual void PolyQuadraticBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 26 | virtual void PolyBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 27 | virtual void ArcTo(const Point &point, const Size &size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked, bool isSmoothJoin) override; 28 | virtual void DisposeCore() override; 29 | virtual void SetClosedState(bool closed) override; 30 | 31 | private: 32 | StreamGeometry* geometry_; 33 | QPainterPath path_; 34 | bool isStarted_ = false; 35 | bool isClosed_ = false; 36 | bool isFilled_ = false; 37 | }; 38 | 39 | INKCANVAS_END_NAMESPACE 40 | 41 | #endif // QTSTREAMGEOMETRYCONTEXT_H 42 | -------------------------------------------------------------------------------- /Windows/Media/drawingvisual.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/drawingvisual.h" 2 | #include "Windows/Media/drawing.h" 3 | 4 | #include 5 | #include 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | DrawingVisual::DrawingVisual() 10 | { 11 | setFlag(ItemHasNoContents, false); 12 | } 13 | 14 | DrawingVisual::~DrawingVisual() 15 | { 16 | if (drawing_) 17 | delete drawing_; 18 | } 19 | 20 | class VisualDrawingContext : public DrawingGroupDrawingContext 21 | { 22 | public: 23 | VisualDrawingContext(DrawingVisual* visual) 24 | : DrawingGroupDrawingContext(visual->GetDrawing()) 25 | , visual_(visual) 26 | { 27 | } 28 | 29 | virtual void CloseCore(List rootDrawingGroupChildren) override 30 | { 31 | DrawingGroupDrawingContext::CloseCore(rootDrawingGroupChildren); 32 | visual_->RenderClose(); 33 | } 34 | 35 | private: 36 | DrawingVisual* visual_; 37 | }; 38 | 39 | DrawingContext * DrawingVisual::RenderOpen() 40 | { 41 | prepareGeometryChange(); 42 | if (drawing_) 43 | delete drawing_; 44 | drawing_ = new DrawingGroup; 45 | return new VisualDrawingContext(this); 46 | } 47 | 48 | void DrawingVisual::RenderClose() 49 | { 50 | prepareGeometryChange(); 51 | } 52 | 53 | DrawingGroup * DrawingVisual::GetDrawing() 54 | { 55 | return drawing_; 56 | } 57 | 58 | QRectF DrawingVisual::boundingRect() const 59 | { 60 | return drawing_ ? QRectF(drawing_->Bounds()) : QRectF(); 61 | } 62 | 63 | void DrawingVisual::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 64 | { 65 | //qDebug() << "DrawingVisual::paint" << this->boundingRect() << painter->clipRegion(); 66 | if (drawing_) { 67 | drawing_->Draw(*painter); 68 | } 69 | } 70 | 71 | INKCANVAS_END_NAMESPACE 72 | -------------------------------------------------------------------------------- /Landing/Android/java/com/tal/inkcanvas/Stroke.java: -------------------------------------------------------------------------------- 1 | package com.tal.inkcanvas; 2 | 3 | import android.graphics.Matrix; 4 | import android.graphics.Path; 5 | import android.graphics.PointF; 6 | import android.graphics.RectF; 7 | 8 | public class Stroke 9 | { 10 | private long handle_ = 0; 11 | 12 | static { 13 | System.loadLibrary("InkCanvasAndroid"); 14 | } 15 | 16 | /* 17 | if pressures != null, addPressure is ignored 18 | */ 19 | public Stroke(final PointF[] points, final float[] pressures, final float width, final boolean fitToCorve, final boolean ellipseShape, 20 | final boolean addPressure) { 21 | handle_ = create(points, pressures, width, fitToCorve, ellipseShape, addPressure); 22 | } 23 | 24 | public Stroke(final Stroke o) { 25 | handle_ = clone(o.handle_); 26 | } 27 | 28 | public void transform(final Matrix matrix) { 29 | transform(handle_, matrix); 30 | } 31 | 32 | public boolean hitTest(final PointF point) { 33 | return hitTest(handle_, point); 34 | } 35 | 36 | public Path getGeometry(final RectF bounds) { 37 | return getGeometry(handle_, bounds); 38 | } 39 | 40 | @Override 41 | public void finalize() { 42 | free(handle_); 43 | handle_ = 0; 44 | } 45 | 46 | private native long create(PointF[] points, float[] pressures, float width, 47 | boolean fitToCorve, boolean ellipseShape, boolean addPressure); 48 | 49 | private native long clone(long handle); 50 | 51 | private native void transform(long handle, Matrix matrix); 52 | 53 | private native boolean hitTest(long handle, PointF point); 54 | 55 | private native Path getGeometry(long handle, RectF bounds); 56 | 57 | private native void free(long handle); 58 | } 59 | -------------------------------------------------------------------------------- /Windows/Media/visual.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/visual.h" 2 | #include "Windows/Media/drawingvisual.h" 3 | #include "Windows/Media/hittestresult.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | INKCANVAS_BEGIN_NAMESPACE 11 | 12 | //static int count = 0; 13 | 14 | Visual::Visual() 15 | : QGraphicsItem(nullptr) 16 | { 17 | //qDebug() << "Visual ++ " << ++count; 18 | setFlag(ItemHasNoContents); 19 | } 20 | 21 | Visual::~Visual() 22 | { 23 | //qDebug() << "Visual -- " << --count; 24 | } 25 | 26 | void Visual::SetOpacity(double opacity) 27 | { 28 | setOpacity(opacity); 29 | } 30 | 31 | GeneralTransform Visual::TransformToAncestor(Visual* visual) 32 | { 33 | return itemTransform(visual).toAffine(); 34 | } 35 | 36 | GeneralTransform Visual::TransformToDescendant(Visual* visual) 37 | { 38 | return itemTransform(visual).toAffine(); 39 | } 40 | 41 | 42 | void Visual::AddVisualChild(Visual * visual) 43 | { 44 | visual->setParentItem(this); 45 | } 46 | 47 | void Visual::RemoveVisualChild(Visual * visual) 48 | { 49 | if (visual->parentItem() == this) { 50 | if (scene()) 51 | scene()->removeItem(visual); 52 | else 53 | visual->setParentItem(nullptr); 54 | } 55 | } 56 | 57 | Visual *Visual::VisualParent() 58 | { 59 | return static_cast(parentItem()); 60 | } 61 | 62 | void Visual::OnVisualChildrenChanged(DependencyObject*, DependencyObject*) 63 | { 64 | 65 | } 66 | 67 | HitTestResult Visual::HitTestCore(PointHitTestParameters) 68 | { 69 | return HitTestResult(nullptr); 70 | } 71 | 72 | QRectF Visual::boundingRect() const 73 | { 74 | return QRectF(); 75 | } 76 | 77 | void Visual::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) 78 | { 79 | } 80 | 81 | INKCANVAS_END_NAMESPACE 82 | -------------------------------------------------------------------------------- /Landing/Android/androidstreamgeometrycontext.h: -------------------------------------------------------------------------------- 1 | #ifndef ANDROIDSTREAMGEOMETRYCONTEXT_H 2 | #define ANDROIDSTREAMGEOMETRYCONTEXT_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class StreamGeometry; 11 | 12 | class AndroidStreamGeometryContext : public StreamGeometryContext 13 | { 14 | public: 15 | static bool init(JavaVM * vm, JNIEnv * env_); 16 | 17 | AndroidStreamGeometryContext(StreamGeometry * geometry); 18 | 19 | private: 20 | StreamGeometry * geometry_ = nullptr; 21 | JNIEnv * env_ = nullptr; 22 | void* path_ = nullptr; 23 | Point lastPoint_; 24 | 25 | // StreamGeometryContext interface 26 | public: 27 | virtual void BeginFigure(const Point &startPoint, bool isFilled, bool isClosed) override; 28 | virtual void LineTo(const Point &point, bool isStroked, bool isSmoothJoin) override; 29 | virtual void QuadraticBezierTo(const Point &point1, const Point &point2, bool isStroked, bool isSmoothJoin) override; 30 | virtual void BezierTo(const Point &point1, const Point &point2, const Point &point3, bool isStroked, bool isSmoothJoin) override; 31 | virtual void PolyLineTo(const List &points, bool isStroked, bool isSmoothJoin) override; 32 | virtual void PolyQuadraticBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 33 | virtual void PolyBezierTo(const List &points, bool isStroked, bool isSmoothJoin) override; 34 | virtual void ArcTo(const Point &point, const Size &size, double rotationAngle, bool isLargeArc, SweepDirection sweepDirection, bool isStroked, bool isSmoothJoin) override; 35 | virtual void SetClosedState(bool closed) override; 36 | virtual void Close() override; 37 | virtual void DisposeCore() override; 38 | }; 39 | 40 | INKCANVAS_END_NAMESPACE 41 | 42 | #endif // ANDROIDSTREAMGEOMETRYCONTEXT_H 43 | -------------------------------------------------------------------------------- /Internal/matrixutil.h: -------------------------------------------------------------------------------- 1 | #ifndef MATRIXUTIL_H 2 | #define MATRIXUTIL_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | enum class MatrixTypes 9 | { 10 | TRANSFORM_IS_IDENTITY = 0, 11 | TRANSFORM_IS_TRANSLATION = 1, 12 | TRANSFORM_IS_SCALING = 2, 13 | TRANSFORM_IS_SCALING_TRANSLATION = 3, 14 | TRANSFORM_IS_UNKNOWN = 4 15 | }; 16 | 17 | inline MatrixTypes operator |(MatrixTypes l, MatrixTypes r) 18 | { 19 | return static_cast(static_cast(l) | static_cast(r)); 20 | } 21 | 22 | inline int operator &(MatrixTypes l, MatrixTypes r) 23 | { 24 | return static_cast(l) & static_cast(r); 25 | } 26 | 27 | class Matrix; 28 | class Rect; 29 | 30 | class MatrixUtil 31 | { 32 | public: 33 | /// 34 | /// TransformRect - Internal helper for perf 35 | /// 36 | /// The Rect to transform. 37 | /// The Matrix with which to transform the Rect. 38 | static void TransformRect(Rect & rect, Matrix const & matrix); 39 | 40 | /// 41 | /// Multiplies two transformations, where the behavior is matrix1 *= matrix2. 42 | /// This code exists so that we can efficient combine matrices without copying 43 | /// the data around, since each matrix is 52 bytes. 44 | /// To reduce duplication and to ensure consistent behavior, this is the 45 | /// method which is used to implement Matrix * Matrix as well. 46 | /// 47 | static void MultiplyMatrix(Matrix & matrix1, Matrix const & matrix2); 48 | 49 | /// 50 | /// Applies an offset to the specified matrix in place. 51 | /// 52 | static void PrependOffset( 53 | Matrix & matrix, 54 | double offsetX, 55 | double offsetY); 56 | }; 57 | 58 | INKCANVAS_END_NAMESPACE 59 | 60 | #endif // MATRIXUTIL_H 61 | -------------------------------------------------------------------------------- /Landing/Macos/nsbezierpathwrapper.m: -------------------------------------------------------------------------------- 1 | #include "nsbezierpathwrapper.h" 2 | 3 | #import "AppKit/NSBezierPath.h" 4 | 5 | void * NSBezierPathWrapper_new() 6 | { 7 | NSBezierPath *aPath = [NSBezierPath new]; 8 | return aPath; 9 | } 10 | 11 | void NSBezierPathWrapper_moveToPoint(void * path, double x, double y) 12 | { 13 | NSBezierPath *aPath = (id) path; 14 | [aPath moveToPoint:CGPointMake(x, y)]; 15 | } 16 | 17 | void NSBezierPathWrapper_addLineToPoint(void * path, double x, double y) 18 | { 19 | NSBezierPath *aPath = (id) path; 20 | [aPath lineToPoint:CGPointMake(x, y)]; 21 | } 22 | 23 | void NSBezierPathWrapper_addQuadCurveToPoint(void * path, double x, double y, double cx, double cy) 24 | { 25 | NSBezierPath *aPath = (id) path; 26 | [aPath quadCurveToPoint:CGPointMake(x, y) controlPoint:CGPointMake(cx, cy)]; 27 | } 28 | 29 | void NSBezierPathWrapper_addCurveToPoint(void * path, double x, double y, double cx1, double cy1, double cx2, double cy2) 30 | { 31 | NSBezierPath *aPath = (id) path; 32 | [aPath curveToPoint:CGPointMake(x, y) controlPoint1:CGPointMake(cx1, cy1) controlPoint2:CGPointMake(cx2, cy2)]; 33 | } 34 | 35 | void NSBezierPathWrapper_addArcWithCenter(void * path, double x, double y, double radius, double startAngle, double endAngle, int clockwise) 36 | { 37 | NSBezierPath *aPath = (id) path; 38 | [aPath appendBezierPathWithArcWithCenter:CGPointMake(x, y) radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise]; 39 | } 40 | 41 | void NSBezierPathWrapper_currentPoint(void * path, double * x, double * y) 42 | { 43 | NSBezierPath *aPath = (id) path; 44 | CGPoint p = [aPath currentPoint]; 45 | *x = p.x; *y = p.y; 46 | } 47 | 48 | void NSBezierPathWrapper_closePath(void * path) 49 | { 50 | NSBezierPath *aPath = (id) path; 51 | [aPath closePath]; 52 | } 53 | 54 | void NSBezierPathWrapper_delete(void * path) 55 | { 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Landing/Ios/uibezierpathwrapper.m: -------------------------------------------------------------------------------- 1 | #include "uibezierpathwrapper.h" 2 | 3 | #include 4 | 5 | void * UIBezierPathWrapper_new() 6 | { 7 | UIBezierPath *aPath = [UIBezierPath new]; 8 | return aPath; 9 | } 10 | 11 | void UIBezierPathWrapper_moveToPoint(void * path, double x, double y) 12 | { 13 | UIBezierPath *aPath = (id) path; 14 | [aPath moveToPoint:CGPointMake(x, y)]; 15 | } 16 | 17 | void UIBezierPathWrapper_addLineToPoint(void * path, double x, double y) 18 | { 19 | UIBezierPath *aPath = (id) path; 20 | [aPath addLineToPoint:CGPointMake(x, y)]; 21 | } 22 | 23 | void UIBezierPathWrapper_addQuadCurveToPoint(void * path, double x, double y, double cx, double cy) 24 | { 25 | UIBezierPath *aPath = (id) path; 26 | [aPath addQuadCurveToPoint:CGPointMake(x, y) controlPoint:CGPointMake(cx, cy)]; 27 | } 28 | 29 | void UIBezierPathWrapper_addCurveToPoint(void * path, double x, double y, double cx1, double cy1, double cx2, double cy2) 30 | { 31 | UIBezierPath *aPath = (id) path; 32 | [aPath addCurveToPoint:CGPointMake(x, y) controlPoint1:CGPointMake(cx1, cy1) controlPoint2:CGPointMake(cx2, cy2)]; 33 | } 34 | 35 | void UIBezierPathWrapper_addArcWithCenter(void * path, double x, double y, double radius, double startAngle, double endAngle, int clockwise) 36 | { 37 | UIBezierPath *aPath = (id) path; 38 | [aPath addArcWithCenter:CGPointMake(x, y) radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise]; 39 | } 40 | 41 | void UIBezierPathWrapper_currentPoint(void * path, double * x, double * y) 42 | { 43 | UIBezierPath *aPath = (id) path; 44 | CGPoint p = [aPath currentPoint]; 45 | *x = p.x; *y = p.y; 46 | } 47 | 48 | void UIBezierPathWrapper_closePath(void * path) 49 | { 50 | UIBezierPath *aPath = (id) path; 51 | [aPath closePath]; 52 | } 53 | 54 | void UIBezierPathWrapper_delete(void * path) 55 | { 56 | (void) path; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /single.h: -------------------------------------------------------------------------------- 1 | #ifndef SINGLE_H 2 | #define SINGLE_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class Single 12 | { 13 | public: 14 | // 15 | // constants 16 | // 17 | static constexpr float MinValue = -3.40282346638528859e+38f; 18 | static constexpr float Epsilon = 1.4e-45f; 19 | static constexpr float MaxValue = 3.40282346638528859e+38f; 20 | static const float PositiveInfinity; 21 | static const float NegativeInfinity; 22 | static const float NaN; 23 | 24 | static bool IsInfinity(float f) { 25 | return (*reinterpret_cast(&f) & 0x7FFFFFFF) == 0x7F800000; 26 | } 27 | 28 | static bool IsPositiveInfinity(float f) { 29 | return *reinterpret_cast(&f) == 0x7F800000; 30 | } 31 | 32 | static bool IsNegativeInfinity(float f) { 33 | return *reinterpret_cast(&f) == 0xFF800000; 34 | } 35 | 36 | static bool IsNaN(float f) { 37 | return (*reinterpret_cast(&f) & 0x7FFFFFFF) > 0x7F800000; 38 | } 39 | 40 | // Compares this object to another object, returning an integer that 41 | // indicates the relationship. 42 | // Returns a value less than zero if this object 43 | // null is considered to be less than any instance. 44 | // If object is not of type Single, this method throws an ArgumentException. 45 | // 46 | int Compare(float l, float r) { 47 | if (l < r) return -1; 48 | if (l > r) return 1; 49 | if (l == r) return 0; 50 | 51 | // At least one of the values is NaN. 52 | if (IsNaN(l)) 53 | return (IsNaN(r) ? 0 : -1); 54 | else // f is NaN. 55 | return 1; 56 | } 57 | 58 | static bool Equals(float l, float r) { 59 | if (l == r) { 60 | return true; 61 | } 62 | return IsNaN(l) && IsNaN(r); 63 | } 64 | 65 | }; 66 | 67 | INKCANVAS_END_NAMESPACE 68 | 69 | #endif // SINGLE_H 70 | -------------------------------------------------------------------------------- /Internal/Ink/textclipboarddata.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTCLIPBOARDDATA_H 2 | #define TEXTCLIPBOARDDATA_H 3 | 4 | #include "elementsclipboarddata.h" 5 | 6 | #include 7 | 8 | // namespace MS.Internal.Ink 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class TextClipboardData : public ElementsClipboardData 12 | { 13 | //------------------------------------------------------------------------------- 14 | // 15 | // Constructors 16 | // 17 | //------------------------------------------------------------------------------- 18 | 19 | //#region Constructors 20 | public: 21 | // The default constructor 22 | TextClipboardData(); 23 | 24 | // The constructor with a string as argument 25 | TextClipboardData(QString text); 26 | 27 | //#endregion Constructors 28 | 29 | protected: 30 | // Checks if the data can be pasted. 31 | virtual bool CanPaste(DataObject const * dataObject); 32 | 33 | //------------------------------------------------------------------------------- 34 | // 35 | // Protected Methods 36 | // 37 | //------------------------------------------------------------------------------- 38 | 39 | //#region Protected Methods 40 | 41 | // Checks if the data can be copied. 42 | virtual bool CanCopy(); 43 | 44 | // Copy the text to the IDataObject 45 | virtual void DoCopy(DataObject * dataObject); 46 | 47 | // Retrieves the text from the IDataObject instance. 48 | // Then create a textbox with the text data. 49 | virtual void DoPaste(DataObject const * dataObject); 50 | 51 | //#endregion Protected Methods 52 | 53 | //------------------------------------------------------------------------------- 54 | // 55 | // Private Fields 56 | // 57 | //------------------------------------------------------------------------------- 58 | 59 | //#region Private Fields 60 | 61 | private: 62 | QString _text; 63 | 64 | ////#endregion Private Fields 65 | }; 66 | 67 | INKCANVAS_END_NAMESPACE 68 | 69 | #endif // TEXTCLIPBOARDDATA_H 70 | -------------------------------------------------------------------------------- /Windows/dependencyproperty.h: -------------------------------------------------------------------------------- 1 | #ifndef DEPENDENCYPROPERTY_H 2 | #define DEPENDENCYPROPERTY_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | // namespace System.Windows 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class DependencyObject; 12 | class DependencyPropertyChangedEventArgs; 13 | 14 | class DefaultValueFactory 15 | { 16 | public: 17 | virtual ~DefaultValueFactory() {} 18 | virtual QVariant DefaultValue() = 0; 19 | }; 20 | 21 | class DependencyProperty 22 | { 23 | public: 24 | typedef std::function PropertyChangedCallback; 25 | 26 | typedef std::function ValidateValueCallback; 27 | 28 | DependencyProperty(DefaultValueFactory* dflt) 29 | : DependencyProperty(QVariant::fromValue(dflt)) 30 | { 31 | } 32 | 33 | DependencyProperty(DefaultValueFactory* dflt, PropertyChangedCallback changed) 34 | : DependencyProperty(QVariant::fromValue(dflt), changed) 35 | { 36 | } 37 | 38 | DependencyProperty(DefaultValueFactory* dflt, PropertyChangedCallback changed, ValidateValueCallback validate) 39 | : DependencyProperty(QVariant::fromValue(dflt), changed, validate) 40 | { 41 | } 42 | 43 | DependencyProperty(QVariant dflt); 44 | 45 | DependencyProperty(QVariant dflt, PropertyChangedCallback changed); 46 | 47 | DependencyProperty(QVariant dflt, PropertyChangedCallback changed, ValidateValueCallback validate); 48 | 49 | static QVariant const UnsetValue; 50 | 51 | int GlobalIndex() const; 52 | 53 | QVariant DefaultValue() const; 54 | 55 | void Changed(DependencyObject& d, QVariant old, QVariant new_) const; 56 | 57 | private: 58 | QVariant default_; 59 | std::function changed_; 60 | std::function validate_; 61 | }; 62 | 63 | INKCANVAS_END_NAMESPACE 64 | 65 | Q_DECLARE_METATYPE(INKCANVAS_PREPEND_NAMESPACE(DefaultValueFactory)*) 66 | 67 | #endif // DEPENDENCYPROPERTY_H 68 | -------------------------------------------------------------------------------- /InkCanvas_global.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVAS_GLOBAL_H 2 | #define INKCANVAS_GLOBAL_H 3 | 4 | #ifdef INKCANVAS_QT 5 | # define INKCANVAS_NAMESPACE InkCanvasQt 6 | #elif defined INKCANVAS_ANDROID 7 | # define INKCANVAS_NAMESPACE InkCanvasAndroid 8 | #elif defined INKCANVAS_IOS 9 | # define INKCANVAS_NAMESPACE InkCanvasIos 10 | #elif defined INKCANVAS_MACOS 11 | # define INKCANVAS_NAMESPACE InkCanvasMacos 12 | #elif defined INKCANVAS_CORE 13 | # define INKCANVAS_NAMESPACE InkCanvasCore 14 | #else 15 | # define INKCANVAS_QT 1 16 | # define INKCANVAS_QT_VARIANT 1 17 | # define INKCANVAS_NAMESPACE QtInkCanvas 18 | #endif 19 | 20 | #ifdef INKCANVAS_CORE 21 | # define STROKE_COLLECTION_EDIT_MASK 0 22 | # define STROKE_COLLECTION_MULTIPLE_LAYER 0 23 | #else 24 | # define STROKE_COLLECTION_EDIT_MASK 1 25 | # define STROKE_COLLECTION_MULTIPLE_LAYER 1 26 | #endif 27 | 28 | #if !defined INKCANVAS_CORE && defined INKCANVAS_QT 29 | # define INKCANVAS_QT_SIGNALS 30 | # define INKCANVAS_QT_DRAW 31 | #endif 32 | 33 | #ifdef INKCANVAS_QT 34 | # include 35 | #else 36 | # define Q_DECL_EXPORT 37 | # define Q_DECL_IMPORT 38 | #endif 39 | 40 | #if defined(INKCANVAS_LIBRARY) 41 | # define INKCANVAS_EXPORT Q_DECL_EXPORT 42 | #else 43 | # define INKCANVAS_EXPORT Q_DECL_IMPORT 44 | #endif 45 | 46 | #ifdef INKCANVAS_NAMESPACE 47 | # define INKCANVAS_BEGIN_NAMESPACE namespace INKCANVAS_NAMESPACE { 48 | # define INKCANVAS_END_NAMESPACE } 49 | # define INKCANVAS_USE_NAMESPACE using namespace ::INKCANVAS_NAMESPACE; 50 | # define INKCANVAS_PREPEND_NAMESPACE(name) ::INKCANVAS_NAMESPACE::name 51 | # define INKCANVAS_FORWARD_DECLARE_CLASS(name) \ 52 | INKCANVAS_BEGIN_NAMESPACE class name; INKCANVAS_END_NAMESPACE \ 53 | using INKCANVAS_PREPEND_NAMESPACE(name); 54 | #else 55 | # define INKCANVAS_BEGIN_NAMESPACE 56 | # define INKCANVAS_END_NAMESPACE 57 | # define INKCANVAS_USE_NAMESPACE 58 | # define INKCANVAS_PREPEND_NAMESPACE(name) ::name 59 | # define INKCANVAS_FORWARD_DECLARE_CLASS(name) class name 60 | #endif 61 | 62 | #endif // INKCANVAS_GLOBAL_H 63 | -------------------------------------------------------------------------------- /Windows/Media/streamgeometry.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Media/streamgeometry.h" 2 | 3 | #ifdef INKCANVAS_QT 4 | #include "Landing/Qt/qtstreamgeometrycontext.h" 5 | #include 6 | #endif 7 | 8 | #ifdef INKCANVAS_ANDROID 9 | #include "Landing/Android/androidstreamgeometrycontext.h" 10 | #endif 11 | 12 | #ifdef INKCANVAS_IOS 13 | #include "Landing/Ios/iosstreamgeometrycontext.h" 14 | #endif 15 | 16 | #ifdef INKCANVAS_MACOS 17 | #include "Landing/Macos/macosstreamgeometrycontext.h" 18 | #endif 19 | 20 | INKCANVAS_BEGIN_NAMESPACE 21 | 22 | StreamGeometry::StreamGeometry() 23 | : context_(nullptr) 24 | { 25 | } 26 | 27 | StreamGeometry::~StreamGeometry() 28 | { 29 | if (context_) 30 | delete context_; 31 | } 32 | 33 | void StreamGeometry::SetFillRule(FillRule value) 34 | { 35 | if (path_ == nullptr) 36 | return; 37 | #ifdef INKCANVAS_QT 38 | reinterpret_cast(path_)->setFillRule(value == FillRule::EvenOdd ? Qt::OddEvenFill : Qt::WindingFill); 39 | #else 40 | (void) value; 41 | #endif 42 | } 43 | 44 | StreamGeometryContext &StreamGeometry::Open() 45 | { 46 | if (context_) 47 | return *context_; 48 | #ifdef INKCANVAS_QT 49 | context_ = new QtStreamGeometryContext(this); 50 | #endif 51 | #ifdef INKCANVAS_ANDROID 52 | context_ = new AndroidStreamGeometryContext(this); 53 | #endif 54 | #ifdef INKCANVAS_IOS 55 | context_ = new IosStreamGeometryContext(this); 56 | #endif 57 | #ifdef INKCANVAS_MACOS 58 | context_ = new MacosStreamGeometryContext(this); 59 | #endif 60 | return *context_; 61 | } 62 | 63 | void StreamGeometry::Close(void * path) 64 | { 65 | path_ = path; 66 | } 67 | 68 | Rect StreamGeometry::Bounds() 69 | { 70 | #ifdef INKCANVAS_QT 71 | return reinterpret_cast(path_)->boundingRect(); 72 | #else 73 | return Rect(); 74 | #endif 75 | } 76 | 77 | #ifdef INKCANVAS_QT_DRAW 78 | void StreamGeometry::Draw(QPainter &painter) 79 | { 80 | painter.drawPath(*reinterpret_cast(path_)); 81 | } 82 | #endif 83 | 84 | INKCANVAS_END_NAMESPACE 85 | -------------------------------------------------------------------------------- /Internal/Ink/contoursegment.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTOURSEGMENT_H 2 | #define CONTOURSEGMENT_H 3 | 4 | #include "Internal/doubleutil.h" 5 | #include "Windows/point.h" 6 | 7 | // namespace MS.Internal.Ink 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class ContourSegment 11 | { 12 | public: 13 | /// 14 | /// Constructor for linear segments 15 | /// 16 | /// segment's begin point 17 | /// segment's end point 18 | ContourSegment(Point const &begin, Point const &end) 19 | { 20 | _begin = begin; 21 | _vector = DoubleUtil::AreClose(begin, end) ? Vector(0, 0) : (end - begin); 22 | _radius = Point(0, 0); 23 | } 24 | 25 | /// 26 | /// Constructor for arcs 27 | /// 28 | /// arc's begin point 29 | /// arc's end point 30 | /// arc's center 31 | ContourSegment(Point const &begin, Point const &end, Point const ¢er) 32 | { 33 | _begin = begin; 34 | _vector = end - begin; 35 | _radius = center - begin; 36 | } 37 | 38 | /// Tells whether the segment is arc or straight 39 | bool IsArc() const { return (_radius.X() != 0) || (_radius.Y() != 0); } 40 | 41 | /// Returns the begin Point &of the segment 42 | Point const & Begin() const { return _begin; } 43 | 44 | /// Returns the end Point &of the segment 45 | Point End() const { return _begin + _vector; } 46 | 47 | /// Returns the Point from Begin to End 48 | Vector const & GetVector() const { return _vector; } 49 | 50 | /// Returns the Point from Begin to the center of the circle 51 | /// (zero Point for linear segments 52 | Vector Radius() const { return _radius; } 53 | 54 | private: 55 | Point _begin; 56 | Vector _vector; 57 | Vector _radius; 58 | }; 59 | 60 | INKCANVAS_END_NAMESPACE 61 | 62 | #endif // CONTOURSEGMENT_H 63 | -------------------------------------------------------------------------------- /Internal/Ink/textclipboarddata.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/textclipboarddata.h" 2 | 3 | #include 4 | 5 | INKCANVAS_BEGIN_NAMESPACE 6 | 7 | TextClipboardData::TextClipboardData() 8 | : TextClipboardData(nullptr) 9 | { 10 | 11 | } 12 | 13 | TextClipboardData::TextClipboardData(QString text) 14 | : _text(text) 15 | { 16 | 17 | } 18 | 19 | // Checks if the data can be pasted. 20 | bool TextClipboardData::CanPaste(DataObject const * dataObject) 21 | { 22 | return ( dataObject->hasFormat("UnicodeText") 23 | || dataObject->hasFormat("Text")); 24 | } 25 | 26 | //------------------------------------------------------------------------------- 27 | // 28 | // Protected Methods 29 | // 30 | //------------------------------------------------------------------------------- 31 | 32 | //#region Protected Methods 33 | 34 | // Checks if the data can be copied. 35 | bool TextClipboardData::CanCopy() 36 | { 37 | return !_text.isEmpty(); 38 | } 39 | 40 | // Copy the text to the IDataObject 41 | void TextClipboardData::DoCopy(DataObject * dataObject) 42 | { 43 | // Put the text to the clipboard 44 | dataObject->setData("UnicodeText", _text.toUtf8()); 45 | } 46 | 47 | // Retrieves the text from the IDataObject instance. 48 | // Then create a textbox with the text data. 49 | void TextClipboardData::DoPaste(DataObject const * dataObject) 50 | { 51 | ElementList() = List(); 52 | 53 | // Get the string from the data object. 54 | QString text = dataObject->data("UnicodeText"); 55 | 56 | if ( text.isEmpty() ) 57 | { 58 | // OemText can be retrieved as CF_TEXT. 59 | text = dataObject->data("Text"); 60 | } 61 | 62 | if ( !text.isEmpty() ) 63 | { 64 | // Now, create a text box and set the text to it. 65 | //TextBox textBox = new TextBox(); 66 | 67 | //textBox.Text = text; 68 | //textBox.TextWrapping = TextWrapping.Wrap; 69 | 70 | // Add the textbox to the array list. 71 | //ElementList().Add(textBox); 72 | } 73 | 74 | } 75 | 76 | INKCANVAS_END_NAMESPACE 77 | -------------------------------------------------------------------------------- /Windows/Input/inputeventargs.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_INPUTEVENTARGS_H 2 | #define WINDOWS_INPUT_INPUTEVENTARGS_H 3 | 4 | #include "Windows/routedeventargs.h" 5 | 6 | // namespace System.Windows.Input 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class InputDevice; 10 | 11 | /// 12 | /// The InputEventArgs class represents a type of RoutedEventArgs that 13 | /// are relevant to all input events. 14 | /// 15 | class InputEventArgs : public RoutedEventArgs 16 | { 17 | public: 18 | /// 19 | /// Initializes a new instance of the InputEventArgs class. 20 | /// 21 | /// 22 | /// The input device to associate with this event. 23 | /// 24 | /// 25 | /// The time when the input occured. 26 | /// 27 | InputEventArgs(InputDevice* inputDevice, int timestamp); 28 | 29 | /// 30 | /// Read-only access to the input device that initiated this 31 | /// event. 32 | /// 33 | InputDevice* Device() 34 | { 35 | return _inputDevice; 36 | } 37 | void SetDevice(InputDevice* value) 38 | { 39 | _inputDevice = value; 40 | } 41 | 42 | /// 43 | /// Read-only access to the input timestamp. 44 | /// 45 | int Timestamp() 46 | { 47 | return _timestamp; 48 | } 49 | 50 | 51 | /// 52 | /// The mechanism used to call the type-specific handler on the 53 | /// target. 54 | /// 55 | /// 56 | /// The generic handler to call in a type-specific way. 57 | /// 58 | /// 59 | /// The target to call the handler on. 60 | /// 61 | //virtual void InvokeEventHandler(Delegate genericHandler, QObject* genericTarget); 62 | 63 | private: 64 | InputDevice* _inputDevice; 65 | static int _timestamp; 66 | }; 67 | 68 | INKCANVAS_END_NAMESPACE 69 | 70 | #endif // WINDOWS_INPUT_INPUTEVENTARGS_H 71 | -------------------------------------------------------------------------------- /Internal/Controls/inkcanvasfeedbackadorner.h: -------------------------------------------------------------------------------- 1 | #ifndef INKCANVASFEEDBACKADORNER_H 2 | #define INKCANVASFEEDBACKADORNER_H 3 | 4 | #include "Windows/Controls/decorator.h" 5 | 6 | #include 7 | 8 | // namespace MS.Internal.Controls 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class InkCanvas; 12 | class DrawingContext; 13 | 14 | /// 15 | /// InkCanvasFeedbackAdorner 16 | /// 17 | class InkCanvasFeedbackAdorner : public Adorner 18 | { 19 | Q_OBJECT 20 | // No default constructor 21 | private: 22 | InkCanvasFeedbackAdorner(); 23 | 24 | public: 25 | /// 26 | /// InkCanvasFeedbackAdorner Constructor 27 | /// 28 | /// The adorned InkCanvas 29 | InkCanvasFeedbackAdorner(InkCanvas& inkCanvas); 30 | 31 | /// 32 | /// The overridden GetDesiredTransform method 33 | /// 34 | virtual GeneralTransform GetDesiredTransform(GeneralTransform const & transform) override; 35 | 36 | private: 37 | /// 38 | /// The OnBoundsUpdated method 39 | /// 40 | /// 41 | void OnBoundsUpdated(Rect const &rect); 42 | 43 | protected: 44 | /// 45 | /// The overridden MeasureOverride method 46 | /// 47 | /// 48 | virtual Size MeasureOverride(Size constraint) override; 49 | 50 | /// 51 | /// The overridden OnRender method 52 | /// 53 | /// 54 | virtual void OnRender(DrawingContext& drawingContext) override; 55 | 56 | public: 57 | /// 58 | /// The method is called by InkCanvasSelection.UpdateFeedbackRect 59 | /// 60 | /// 61 | void UpdateBounds(Rect const &rect); 62 | 63 | private: 64 | InkCanvas& _inkCanvas; 65 | Size _frameSize; 66 | Rect _previousRect = Rect::Empty(); 67 | double _offsetX = 0; 68 | double _offsetY = 0; 69 | 70 | QPen _adornerBorderPen; 71 | 72 | static constexpr int CornerResizeHandleSize = 8; 73 | static constexpr double BorderMargin = 8; 74 | 75 | }; 76 | 77 | INKCANVAS_END_NAMESPACE 78 | 79 | #endif // INKCANVASFEEDBACKADORNER_H 80 | -------------------------------------------------------------------------------- /Windows/Input/querycursoreventargs.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_QUERYCURSOREVENTARGS_H 2 | #define WINDOWS_INPUT_QUERYCURSOREVENTARGS_H 3 | 4 | #include "Windows/Input/mouseeventargs.h" 5 | 6 | #include 7 | 8 | // namespace System.Windows.Input 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | /// 12 | /// Provides data for the QueryCursor event. 13 | /// 14 | class QueryCursorEventArgs : public MouseEventArgs 15 | { 16 | public: 17 | /// 18 | /// Initializes a new instance of the QueryCursorEventArgs class. 19 | /// 20 | /// 21 | /// The logical Mouse device associated with this event. 22 | /// 23 | /// 24 | /// The time when the input occured. 25 | /// 26 | QueryCursorEventArgs(MouseDevice* mouse, int timestamp) 27 | : MouseEventArgs(mouse, timestamp) 28 | { 29 | } 30 | 31 | /// 32 | /// Initializes a new instance of the QueryCursorEventArgs class. 33 | /// 34 | /// 35 | /// The logical Mouse device associated with this event. 36 | /// 37 | /// 38 | /// The time when the input occured. 39 | /// 40 | /// 41 | /// The stylus pointer that was involved with this event. 42 | /// 43 | QueryCursorEventArgs(MouseDevice* mouse, int timestamp, StylusDevice* stylusDevice) 44 | : MouseEventArgs(mouse, timestamp, stylusDevice) 45 | { 46 | } 47 | 48 | /// 49 | /// The cursor to set. 50 | /// 51 | QCursor Cursor() 52 | { 53 | return _cursor; 54 | } 55 | void SetCursor(QCursor value) 56 | { 57 | _cursor = value; 58 | } 59 | 60 | protected: 61 | /// 62 | /// The mechanism used to call the type-specific handler on the 63 | /// target. 64 | /// 65 | /// 66 | /// The generic handler to call in a type-specific way. 67 | /// 68 | /// 69 | /// The target to call the handler on. 70 | /// 71 | //virtual void InvokeEventHandler(Delegate genericHandler, object genericTarget) 72 | 73 | private: 74 | QCursor _cursor; 75 | }; 76 | 77 | INKCANVAS_END_NAMESPACE 78 | 79 | #endif // WINDOWS_INPUT_QUERYCURSOREVENTARGS_H 80 | -------------------------------------------------------------------------------- /Windows/Input/styluspointpropertyinfo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Windows/Input/styluspointpropertyinfo.h" 3 | #include "Windows/Input/styluspointpropertyinfodefaults.h" 4 | #include "Windows/Input/styluspointproperty.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | StylusPointPropertyInfo::StylusPointPropertyInfo(StylusPointProperty const & stylusPointProperty) 9 | : prop_(&stylusPointProperty) //base checks for null 10 | { 11 | StylusPointPropertyInfo info = 12 | StylusPointPropertyInfoDefaults::GetStylusPointPropertyInfoDefault(stylusPointProperty); 13 | _min = info._min; 14 | _max = info._max; 15 | _resolution = info._resolution; 16 | _unit = info._unit; 17 | 18 | } 19 | 20 | StylusPointPropertyInfo::StylusPointPropertyInfo(StylusPointProperty const & stylusPointProperty, int minimum, int maximum, 21 | StylusPointPropertyUnit unit, float resolution) 22 | : prop_(&stylusPointProperty) //base checks for null 23 | { 24 | // validate unit 25 | //if (!StylusPointPropertyUnitHelper::IsDefined(unit)) 26 | //{ 27 | // throw std::runtime_error("unit"); 28 | //} 29 | 30 | // validate min/max 31 | if (maximum < minimum) 32 | { 33 | throw std::runtime_error("maximum"); 34 | } 35 | 36 | // validate resolution 37 | if (resolution < 0.0f) 38 | { 39 | throw std::runtime_error("resolution"); 40 | } 41 | 42 | _min = minimum; 43 | _max = maximum; 44 | _resolution = resolution; 45 | _unit = unit; 46 | } 47 | 48 | bool StylusPointPropertyInfo::AreCompatible(StylusPointPropertyInfo const & stylusPointPropertyInfo1, StylusPointPropertyInfo const & stylusPointPropertyInfo2) 49 | { 50 | //Debug.Assert(( stylusPointPropertyInfo1.Id != StylusPointPropertyIds.X && 51 | // stylusPointPropertyInfo1.Id != StylusPointPropertyIds.Y && 52 | // stylusPointPropertyInfo2.Id != StylusPointPropertyIds.X && 53 | // stylusPointPropertyInfo2.Id != StylusPointPropertyIds.Y), 54 | // "Why are you checking X, Y for compatibility? They're always compatible"); 55 | // 56 | // we only take ID and IsButton into account, we don't take metrics into account 57 | // 58 | return (stylusPointPropertyInfo1.Id() == stylusPointPropertyInfo2.Id() && 59 | stylusPointPropertyInfo1.IsButton() == stylusPointPropertyInfo2.IsButton()); 60 | } 61 | 62 | INKCANVAS_END_NAMESPACE 63 | -------------------------------------------------------------------------------- /Internal/Ink/quad.h: -------------------------------------------------------------------------------- 1 | #ifndef QUAD_H 2 | #define QUAD_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Windows/rect.h" 6 | #include "Collections/Generic/list.h" 7 | 8 | // namespace MS.Internal.Ink 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class Quad 12 | { 13 | private: 14 | static Quad s_empty; 15 | 16 | public: 17 | /// Returns the static object representing an empty (unitialized) quad 18 | static Quad const & Empty() { return s_empty; } 19 | 20 | /// Constructor 21 | Quad(Point a, Point b, Point c, Point d) 22 | { 23 | _A = a; _B = b; _C = c; _D = d; 24 | } 25 | 26 | /// The A vertex of the quad 27 | public: 28 | Point const& A() const { return _A; } 29 | void SetA(Point const& value) { _A = value; } 30 | 31 | /// The B vertex of the quad 32 | Point const& B() const { return _B; } 33 | void SetB(Point const& value) { _B = value; } 34 | 35 | /// The C vertex of the quad 36 | Point const& C() const { return _C; } 37 | void SetC(Point const& value) { _C = value; } 38 | 39 | /// The D vertex of the quad 40 | Point const& D() const { return _D; } 41 | void SetD(Point const& value) { _D = value; } 42 | 43 | // Returns quad's vertex by index where A is of the index 0, B - is 1, etc 44 | Point const & operator[](int index) const 45 | { 46 | switch (index) 47 | { 48 | case 0: return _A; 49 | case 1: return _B; 50 | case 2: return _C; 51 | case 3: return _D; 52 | default: 53 | throw new std::runtime_error("index"); 54 | } 55 | } 56 | 57 | /// Tells whether the quad is invalid (empty) 58 | bool IsEmpty() const 59 | { 60 | return (_A == _B) && (_C == _D); 61 | } 62 | 63 | void GetPoints(List & pointBuffer) const 64 | { 65 | pointBuffer.Add(_A); 66 | pointBuffer.Add(_B); 67 | pointBuffer.Add(_C); 68 | pointBuffer.Add(_D); 69 | } 70 | 71 | /// Returns the bounds of the quad 72 | Rect Bounds() const 73 | { 74 | return IsEmpty() ? Rect::Empty() : Rect::Union(Rect(_A, _B), Rect(_C, _D)); 75 | } 76 | 77 | private: 78 | Point _A; 79 | Point _B; 80 | Point _C; 81 | Point _D; 82 | }; 83 | 84 | INKCANVAS_END_NAMESPACE 85 | 86 | #endif // QUAD_H 87 | -------------------------------------------------------------------------------- /Windows/Ink/gesturerecognitionresult.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INK_GESTURERECOGNITIONRESULT_H 2 | #define WINDOWS_INK_GESTURERECOGNITIONRESULT_H 3 | 4 | #include "applicationgesture.h" 5 | 6 | INKCANVAS_BEGIN_NAMESPACE 7 | 8 | /// 9 | /// RecognitionConfidence 10 | /// 11 | enum class RecognitionConfidence 12 | { 13 | /// 14 | /// Strong 15 | /// 16 | Strong = 0, 17 | /// 18 | /// Intermediate 19 | /// 20 | Intermediate = 1, 21 | /// 22 | /// Poor 23 | /// 24 | Poor = 2, 25 | }; 26 | 27 | // namespace System.Windows.Ink 28 | 29 | /// 30 | /// GestureRecognitionResult 31 | /// 32 | class GestureRecognitionResult 33 | { 34 | //------------------------------------------------------------------------------- 35 | // 36 | // Constructors 37 | // 38 | //------------------------------------------------------------------------------- 39 | public: 40 | //#region Constructors 41 | 42 | GestureRecognitionResult(RecognitionConfidence confidence, ApplicationGesture gesture) 43 | { 44 | _confidence = confidence; 45 | _gesture = gesture; 46 | } 47 | 48 | //#endregion Constructors 49 | 50 | //------------------------------------------------------------------------------- 51 | // 52 | // Public Properties 53 | // 54 | //------------------------------------------------------------------------------- 55 | 56 | //#region Public Properties 57 | 58 | /// 59 | /// RecognitionConfidence Proeprty 60 | /// 61 | RecognitionConfidence GetRecognitionConfidence() 62 | { 63 | return _confidence; 64 | } 65 | 66 | /// 67 | /// ApplicationGesture Property 68 | /// 69 | ApplicationGesture GetApplicationGesture() 70 | { 71 | return _gesture; 72 | } 73 | 74 | //#endregion Public Properties 75 | 76 | //------------------------------------------------------------------------------- 77 | // 78 | // Private Fields 79 | // 80 | //------------------------------------------------------------------------------- 81 | 82 | //#region Private Fields 83 | 84 | private: 85 | RecognitionConfidence _confidence; 86 | ApplicationGesture _gesture; 87 | 88 | //#endregion Private Fields 89 | }; 90 | 91 | INKCANVAS_END_NAMESPACE 92 | 93 | #endif // WINDOWS_INK_GESTURERECOGNITIONRESULT_H 94 | -------------------------------------------------------------------------------- /Windows/Input/styluspointproperty.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_STYLUSPOINTPROPERTY_H 2 | #define WINDOWS_INPUT_STYLUSPOINTPROPERTY_H 3 | 4 | #include "Windows/Input/styluspointpropertyids.h" 5 | 6 | #ifdef INKCANVAS_QT 7 | #include 8 | #endif 9 | 10 | // namespace System.Windows.Input 11 | INKCANVAS_BEGIN_NAMESPACE 12 | 13 | class StylusPointProperty 14 | { 15 | public: 16 | /// 17 | /// Instance data 18 | /// 19 | private: 20 | Guid const & _id; 21 | bool _isButton; 22 | 23 | /// 24 | /// StylusPointProperty 25 | /// 26 | /// identifier 27 | /// isButton 28 | public: 29 | static StylusPointProperty const Empty; 30 | 31 | StylusPointProperty() : _id(Guid::Empty), _isButton(false) {} 32 | 33 | StylusPointProperty(Guid const & identifier, bool isButton) 34 | : _id(identifier) 35 | , _isButton(isButton) 36 | { 37 | Initialize(identifier, isButton); 38 | } 39 | 40 | /// 41 | /// StylusPointProperty 42 | /// 43 | /// 44 | /// Protected - used by the StylusPointPropertyInfo ctor 45 | StylusPointProperty(StylusPointProperty const & stylusPointProperty) 46 | : _id(stylusPointProperty._id) 47 | , _isButton(stylusPointProperty._isButton) 48 | { 49 | //Initialize(stylusPointProperty._id, stylusPointProperty._isButton); 50 | } 51 | 52 | /// 53 | /// Common ctor helper 54 | /// 55 | /// identifier 56 | /// isButton 57 | private: 58 | void Initialize(Guid const & identifier, bool isButton); 59 | 60 | public: 61 | /// 62 | /// Id 63 | /// 64 | Guid const & Id() const 65 | { 66 | return _id; 67 | } 68 | 69 | /// 70 | /// IsButton 71 | /// 72 | bool IsButton() const 73 | { 74 | return _isButton; 75 | } 76 | 77 | #ifdef INKCANVAS_QT 78 | /// 79 | /// Returns a human readable string representation 80 | /// 81 | QString ToString() const 82 | { 83 | return QString("{Id=") + 84 | StylusPointPropertyIds::GetStringRepresentation(_id) + 85 | ", IsButton=" + 86 | _isButton + 87 | "}"; 88 | } 89 | #endif 90 | 91 | }; 92 | 93 | INKCANVAS_END_NAMESPACE 94 | 95 | #endif // WINDOWS_INPUT_STYLUSPOINTPROPERTY_H 96 | -------------------------------------------------------------------------------- /Internal/Ink/elementsclipboarddata.h: -------------------------------------------------------------------------------- 1 | #ifndef ELEMENTSCLIPBOARDDATA_H 2 | #define ELEMENTSCLIPBOARDDATA_H 3 | 4 | #include "Activities/Presentation/clipboarddata.h" 5 | #include "Collections/Generic/list.h" 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class UIElement; 10 | 11 | // namespace MS.Internal.Ink 12 | 13 | class ElementsClipboardData : public ClipboardData 14 | { 15 | //------------------------------------------------------------------------------- 16 | // 17 | // Constructors 18 | // 19 | //------------------------------------------------------------------------------- 20 | 21 | //#region Constructors 22 | public: 23 | // The default constructor 24 | ElementsClipboardData() { } 25 | 26 | // The constructor which takes a FrameworkElement array. 27 | ElementsClipboardData(List elements) 28 | { 29 | //if ( elements != null ) 30 | //{ 31 | ElementList() = (elements); 32 | //} 33 | } 34 | 35 | //#endregion Constructors 36 | 37 | //------------------------------------------------------------------------------- 38 | // 39 | // Properties 40 | // 41 | //------------------------------------------------------------------------------- 42 | 43 | //#region Properties 44 | 45 | // Gets the element array. 46 | List& Elements() 47 | { 48 | //if ( ElementList() != null ) 49 | { 50 | return _elementList; 51 | } 52 | //else 53 | //{ 54 | // return new List(); 55 | //} 56 | } 57 | 58 | //#endregion Properties 59 | 60 | //------------------------------------------------------------------------------- 61 | // 62 | // Protected Properties 63 | // 64 | //------------------------------------------------------------------------------- 65 | 66 | //#region Protected Properties 67 | 68 | // Sets/Gets the array list 69 | protected: 70 | List& ElementList() 71 | { 72 | return _elementList; 73 | } 74 | 75 | //#endregion Protected Properties 76 | 77 | //------------------------------------------------------------------------------- 78 | // 79 | // Private Fields 80 | // 81 | //------------------------------------------------------------------------------- 82 | 83 | //#region Private Fields 84 | 85 | private: 86 | List _elementList; 87 | 88 | //#endregion Private Fields 89 | 90 | }; 91 | 92 | INKCANVAS_END_NAMESPACE 93 | 94 | #endif // ELEMENTSCLIPBOARDDATA_H 95 | -------------------------------------------------------------------------------- /Collections/ObjectModel/collection.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLECTIONS_OBJECTMODEL_COLLECTION_H 2 | #define COLLECTIONS_OBJECTMODEL_COLLECTION_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Collections/Generic/list.h" 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | template 10 | class Collection 11 | { 12 | public: 13 | typedef typename List::const_iterator const_iterator; 14 | 15 | T const & operator[](int index) const 16 | { 17 | return items[index]; 18 | } 19 | 20 | int Count() const 21 | { 22 | return items.Count(); 23 | } 24 | 25 | void Add(T const & item) { 26 | int index = items.Count(); 27 | InsertItem(index, item); 28 | } 29 | 30 | void Clear() { 31 | ClearItems(); 32 | } 33 | 34 | bool Contains(T const & item) { 35 | return items.Contains(item); 36 | } 37 | 38 | int IndexOf(T const & item) { 39 | return items.IndexOf(item); 40 | } 41 | 42 | void Insert(int index, T const & item) { 43 | InsertItem(index, item); 44 | } 45 | 46 | bool Remove(T const & item) { 47 | int index = items.IndexOf(item); 48 | if (index < 0) return false; 49 | RemoveItem(index); 50 | return true; 51 | } 52 | 53 | void RemoveAt(int index) { 54 | RemoveItem(index); 55 | } 56 | 57 | virtual void ClearItems() { 58 | items.Clear(); 59 | } 60 | 61 | virtual void InsertItem(int index, T const & item) { 62 | items.Insert(index, item); 63 | } 64 | 65 | virtual void RemoveItem(int index) { 66 | items.RemoveAt(index); 67 | } 68 | 69 | virtual void SetItem(int index, T const & item) { 70 | items[index] = item; 71 | } 72 | 73 | void SetCapacity(int n) { items.reserve(n); } 74 | 75 | const_iterator begin() const 76 | { 77 | return items.begin(); 78 | } 79 | 80 | const_iterator end() const 81 | { 82 | return items.end(); 83 | } 84 | 85 | int IndexOf(T const & t) const 86 | { 87 | return items.IndexOf(t); 88 | } 89 | 90 | bool Contains(T const & t) const 91 | { 92 | return items.Contains(t); 93 | } 94 | 95 | protected: 96 | List & Items() { return items; } 97 | 98 | T & at(int index) 99 | { 100 | return items[index]; 101 | } 102 | 103 | private: 104 | List items; 105 | }; 106 | 107 | INKCANVAS_END_NAMESPACE 108 | 109 | #endif // COLLECTIONS_OBJECTMODEL_COLLECTION_H 110 | -------------------------------------------------------------------------------- /Windows/Input/StylusPlugIns/rawstylusactions.h: -------------------------------------------------------------------------------- 1 | #ifndef RAWSTYLUSACTIONS_H 2 | #define RAWSTYLUSACTIONS_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | /// 11 | /// The raw actions being reported from the stylus. 12 | /// 13 | /// 14 | /// Note that multiple actions can be reported at once. 15 | /// 16 | //[Flags] 17 | enum class RawStylusActions 18 | { 19 | /// 20 | /// NoAction 21 | /// 22 | None = 0x000, 23 | 24 | /// 25 | /// The stylus became active in the application. The application 26 | /// may need to refresh its stylus state. 27 | /// 28 | Activate = 0x001, 29 | 30 | /// 31 | /// The stylus became inactive in the application. The application 32 | /// may need to clear its stylus state. 33 | /// 34 | Deactivate = 0x002, 35 | 36 | /// 37 | /// The stylus just came in contact with the digitizer 38 | /// 39 | Down = 0x004, 40 | 41 | /// 42 | /// The stylus just lost contact with the digitizer 43 | /// 44 | Up = 0x008, 45 | 46 | /// 47 | /// The stylus is sending more data while in contact with the digitizer. 48 | /// 49 | Move = 0x010, 50 | 51 | /// 52 | /// The stylus is sending more data while hovering in-air over the digitizer. 53 | /// 54 | InAirMove = 0x020, 55 | 56 | /// 57 | /// The stylus is now in range of the digitizer. 58 | /// 59 | InRange = 0x040, 60 | 61 | /// 62 | /// The stylus is now out of range of the digitizer. 63 | /// 64 | OutOfRange = 0x080, 65 | 66 | /// 67 | /// The stylus is now out of range of the digitizer. 68 | /// 69 | SystemGesture = 0x100, 70 | }; 71 | 72 | inline RawStylusActions operator | (RawStylusActions lhs, RawStylusActions rhs) 73 | { 74 | using T = std::underlying_type_t ; 75 | return static_cast(static_cast(lhs) | static_cast(rhs)); 76 | } 77 | 78 | /// 79 | /// Internal helper for validating RawStylusActions 80 | /// 81 | class RawStylusActionsHelper 82 | { 83 | private: 84 | static const RawStylusActions MaxActions; 85 | 86 | static bool IsValid(RawStylusActions action); 87 | }; 88 | 89 | INKCANVAS_END_NAMESPACE 90 | 91 | #endif // RAWSTYLUSACTIONS_H 92 | -------------------------------------------------------------------------------- /Internal/Ink/Ink.pri: -------------------------------------------------------------------------------- 1 | !inkcanvas_core: include(InkSerializedFormat/InkSerializedFormat.pri) 2 | !inkcanvas_core: win32: include(GestureRecognition/GestureRecognition.pri) 3 | 4 | HEADERS += \ 5 | $$PWD/bezier.h \ 6 | $$PWD/contoursegment.h \ 7 | $$PWD/cuspdata.h \ 8 | $$PWD/ellipticalnodeoperations.h \ 9 | $$PWD/erasingstroke.h \ 10 | $$PWD/quad.h \ 11 | $$PWD/lasso.h \ 12 | $$PWD/strokefindices.h \ 13 | $$PWD/strokenode.h \ 14 | $$PWD/strokenodedata.h \ 15 | $$PWD/strokenodeiterator.h \ 16 | $$PWD/strokenodeoperations.h \ 17 | $$PWD/strokerenderer.h \ 18 | 19 | SOURCES += \ 20 | $$PWD/bezier.cpp \ 21 | $$PWD/contoursegment.cpp \ 22 | $$PWD/cuspdata.cpp \ 23 | $$PWD/ellipticalnodeoperations.cpp \ 24 | $$PWD/erasingstroke.cpp \ 25 | $$PWD/quad.cpp \ 26 | $$PWD/lasso.cpp \ 27 | $$PWD/strokefindices.cpp \ 28 | $$PWD/strokenode.cpp \ 29 | $$PWD/strokenodedata.cpp \ 30 | $$PWD/strokenodeiterator.cpp \ 31 | $$PWD/strokenodeoperations.cpp \ 32 | $$PWD/strokerenderer.cpp \ 33 | 34 | inkcanvas_core: { 35 | 36 | HEADERS += \ 37 | $$PWD/InkSerializedFormat/isftagandguidcache.h \ 38 | 39 | SOURCES += \ 40 | $$PWD/InkSerializedFormat/isftagandguidcache.cpp \ 41 | 42 | } 43 | 44 | !inkcanvas_core: { 45 | 46 | HEADERS += \ 47 | $$PWD/clipboardprocessor.h \ 48 | $$PWD/editingbehavior.h \ 49 | $$PWD/editingcoordinator.h \ 50 | $$PWD/elementsclipboarddata.h \ 51 | $$PWD/eraserbehavior.h \ 52 | $$PWD/renderer.h \ 53 | $$PWD/inkcanvasclipboardformat.h \ 54 | $$PWD/inkcanvasselection.h \ 55 | $$PWD/inkcollectionbehavior.h \ 56 | $$PWD/isfclipboarddata.h \ 57 | $$PWD/lassohelper.h \ 58 | $$PWD/lassoselectionbehavior.h \ 59 | $$PWD/pencursormanager.h \ 60 | $$PWD/selectioneditingbehavior.h \ 61 | $$PWD/selectioneditor.h \ 62 | $$PWD/serializationflags.h \ 63 | $$PWD/styluseditingbehavior.h \ 64 | $$PWD/textclipboarddata.h 65 | 66 | SOURCES += \ 67 | $$PWD/clipboardprocessor.cpp \ 68 | $$PWD/editingbehavior.cpp \ 69 | $$PWD/editingcoordinator.cpp \ 70 | $$PWD/elementsclipboarddata.cpp \ 71 | $$PWD/eraserbehavior.cpp \ 72 | $$PWD/renderer.cpp \ 73 | $$PWD/inkcanvasclipboardformat.cpp \ 74 | $$PWD/inkcanvasselection.cpp \ 75 | $$PWD/inkcollectionbehavior.cpp \ 76 | $$PWD/isfclipboarddata.cpp \ 77 | $$PWD/lassohelper.cpp \ 78 | $$PWD/lassoselectionbehavior.cpp \ 79 | $$PWD/pencursormanager.cpp \ 80 | $$PWD/selectioneditingbehavior.cpp \ 81 | $$PWD/selectioneditor.cpp \ 82 | $$PWD/serializationflags.cpp \ 83 | $$PWD/styluseditingbehavior.cpp \ 84 | $$PWD/textclipboarddata.cpp 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Internal/Ink/isfclipboarddata.h: -------------------------------------------------------------------------------- 1 | #ifndef ISFCLIPBOARDDATA_H 2 | #define ISFCLIPBOARDDATA_H 3 | 4 | #include "Activities/Presentation/clipboarddata.h" 5 | #include "sharedptr.h" 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class StrokeCollection; 10 | 11 | // namespace MS.Internal.Ink 12 | 13 | class ISFClipboardData : public ClipboardData 14 | { 15 | //------------------------------------------------------------------------------- 16 | // 17 | // Constructors 18 | // 19 | //------------------------------------------------------------------------------- 20 | 21 | //#region Constructors 22 | public: 23 | // The default constructor 24 | ISFClipboardData(); 25 | 26 | // The constructor which takes StrokeCollection argument 27 | ISFClipboardData(SharedPointer strokes); 28 | 29 | // Checks if the data can be pasted. 30 | virtual bool CanPaste(DataObject const * dataObject) override; 31 | 32 | //#endregion Constructors 33 | 34 | //------------------------------------------------------------------------------- 35 | // 36 | // Methods 37 | // 38 | //------------------------------------------------------------------------------- 39 | 40 | //#region Methods 41 | protected: 42 | // Checks if there is stroke data in this instance 43 | virtual bool CanCopy() override; 44 | 45 | // Copies the strokes to the IDataObject 46 | /// 47 | /// Critical: This code asserts to set data on a data object 48 | /// 49 | //[SecurityCritical] 50 | virtual void DoCopy(DataObject* dataObject) override; 51 | 52 | // Retrieves the stroks from the IDataObject 53 | virtual void DoPaste(DataObject const * dataObject) override; 54 | 55 | //#endregion Methods 56 | 57 | //------------------------------------------------------------------------------- 58 | // 59 | // Properties 60 | // 61 | //------------------------------------------------------------------------------- 62 | 63 | //#region Properties 64 | 65 | public: 66 | // Gets the strokes 67 | SharedPointer Strokes() 68 | { 69 | return _strokes; 70 | } 71 | 72 | //#endregion Properties 73 | 74 | //------------------------------------------------------------------------------- 75 | // 76 | // Private Fields 77 | // 78 | //------------------------------------------------------------------------------- 79 | 80 | //#region Private Fields 81 | private: 82 | SharedPointer _strokes; 83 | 84 | //#endregion Private Fields 85 | 86 | }; 87 | 88 | INKCANVAS_END_NAMESPACE 89 | 90 | #endif // ISFCLIPBOARDDATA_H 91 | -------------------------------------------------------------------------------- /Windows/Controls/decorator.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Controls/decorator.h" 2 | 3 | #ifdef INKCANVAS_QT 4 | #include "Landing/Qt/qtpainterdrawingcontext.h" 5 | #endif 6 | 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | Decorator::Decorator() 12 | { 13 | 14 | } 15 | 16 | UIElement *Decorator::Child() 17 | { 18 | return child_; 19 | } 20 | 21 | void Decorator::SetChild(UIElement *value) 22 | { 23 | if (child_ == value) 24 | return; 25 | if (child_) 26 | RemoveVisualChild(child_); 27 | child_ = value; 28 | if (child_) 29 | AddVisualChild(child_); 30 | } 31 | 32 | Adorner::Adorner(UIElement* adornedElement) 33 | : adornedElement_(adornedElement) 34 | { 35 | setFlag(ItemHasNoContents, false); 36 | } 37 | 38 | UIElement* Adorner::AdornedElement() 39 | { 40 | return adornedElement_; 41 | } 42 | 43 | GeneralTransform Adorner::GetDesiredTransform(const GeneralTransform &transform) 44 | { 45 | return transform; 46 | } 47 | 48 | void Adorner::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 49 | { 50 | (void) option; 51 | (void) widget; 52 | QTransform transform(painter->transform()); 53 | painter->setTransform(QTransform(GetDesiredTransform(transform.toAffine()))); 54 | QtPainterDrawingContext context(*painter); 55 | OnRender(context); 56 | painter->setTransform(transform); 57 | } 58 | 59 | void AdornerLayer::Add(Adorner *adorner) 60 | { 61 | AddVisualChild(adorner); 62 | } 63 | 64 | void AdornerLayer::Remove(Adorner *adorner) 65 | { 66 | RemoveVisualChild(adorner); 67 | } 68 | 69 | AdornerLayer *AdornerLayer::GetAdornerLayer(Visual *visual) 70 | { 71 | Visual * parent = visual->VisualParent(); 72 | while (parent) { 73 | UIElement * ue = fromItem(parent); 74 | AdornerLayer* l = qobject_cast(ue); 75 | if (l) 76 | return l; 77 | AdornerDecorator* d = qobject_cast(ue); 78 | if (d) 79 | return d->GetAdornerLayer(); 80 | parent = parent->VisualParent(); 81 | } 82 | return nullptr; 83 | } 84 | 85 | AdornerDecorator::AdornerDecorator() 86 | { 87 | adornerLayer_ = new AdornerLayer; 88 | } 89 | 90 | void AdornerDecorator::SetChild(UIElement *value) 91 | { 92 | Decorator::SetChild(value); 93 | if (value) 94 | AddVisualChild(adornerLayer_); 95 | else 96 | RemoveVisualChild(adornerLayer_); 97 | } 98 | 99 | AdornerLayer *AdornerDecorator::GetAdornerLayer() 100 | { 101 | return adornerLayer_; 102 | } 103 | 104 | INKCANVAS_END_NAMESPACE 105 | -------------------------------------------------------------------------------- /Windows/Input/mousedevice.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_MOUSEDEVICE_H 2 | #define WINDOWS_INPUT_MOUSEDEVICE_H 3 | 4 | #include "Windows/Input/inputdevice.h" 5 | #include "Windows/Input/mousebuttonstate.h" 6 | #include "Windows/routedeventargs.h" 7 | #include "Windows/point.h" 8 | 9 | class QGraphicsSceneMouseEvent; 10 | 11 | INKCANVAS_BEGIN_NAMESPACE 12 | 13 | class UIElement; 14 | class MouseDevice; 15 | 16 | class MouseEvent : public RoutedEvent 17 | { 18 | public: 19 | MouseEvent(int type); 20 | virtual void handle(QEvent &event, QList handlers) override; 21 | }; 22 | 23 | class INKCANVAS_EXPORT Mouse 24 | { 25 | public: 26 | static MouseDevice* PrimaryDevice; 27 | 28 | static MouseEvent MouseDownEvent; 29 | 30 | static MouseEvent MouseMoveEvent; 31 | 32 | static MouseEvent MouseUpEvent; 33 | 34 | static MouseEvent MouseEnterEvent; 35 | 36 | static MouseEvent MouseHoverEvent; 37 | 38 | static MouseEvent MouseLeaveEvent; 39 | 40 | static MouseEvent QueryCursorEvent; 41 | 42 | static void UpdateCursor(UIElement* element); 43 | 44 | static void SetLastInput(QGraphicsSceneMouseEvent& input); 45 | 46 | static int GetTimestamp(); 47 | }; 48 | 49 | class MouseDevice : public InputDevice 50 | { 51 | Q_OBJECT 52 | public: 53 | MouseDevice(); 54 | 55 | void SetLastPosition(QPointF const & pos); 56 | 57 | /// 58 | /// Calculates the position of the mouse relative to 59 | /// a particular element. 60 | /// 61 | Point GetPosition(Visual* relativeTo); 62 | 63 | /// 64 | /// The state of the left button. 65 | /// 66 | MouseButtonState LeftButton(); 67 | 68 | /// 69 | /// The state of the right button. 70 | /// 71 | MouseButtonState RightButton(); 72 | 73 | /// 74 | /// The state of the middle button. 75 | /// 76 | MouseButtonState MiddleButton(); 77 | 78 | MouseButtonState XButton1(); 79 | 80 | MouseButtonState XButton2(); 81 | 82 | UIElement* Captured(); 83 | 84 | virtual UIElement* Target() override; 85 | 86 | virtual PresentationSource* ActiveSource() override; 87 | 88 | virtual int Id() override; 89 | 90 | virtual SharedPointer PointDescription() override; 91 | 92 | virtual Array PacketData(QEvent& event) override; 93 | 94 | private: 95 | SharedPointer description_; 96 | QPointF lastPosition_; 97 | }; 98 | 99 | INKCANVAS_END_NAMESPACE 100 | 101 | #endif // WINDOWS_INPUT_MOUSEDEVICE_H 102 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/algomodule.cpp: -------------------------------------------------------------------------------- 1 | #include "Internal/Ink/InkSerializedFormat/algomodule.h" 2 | #include 3 | 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | AlgoModule::AlgoModule() 7 | { 8 | 9 | } 10 | 11 | /// 12 | /// Compresses int[] packet data, returns it as a byte[] 13 | /// 14 | /// assumed to be point data (x,x,x,x,x,x,x) 15 | /// magic byte specifying the compression to use 16 | /// 17 | QByteArray AlgoModule::CompressPacketData(Array input, quint8 compression) 18 | { 19 | QByteArray output(input.Length() * 4 + 1, 0); 20 | compression = (quint8)(input.Length() * 4); 21 | output[0] = compression; 22 | memcpy(output.data() + 1, &input[0], input.Length() * 4); 23 | return output; 24 | } 25 | 26 | /// 27 | /// DecompressPacketData - given a compressed byte[], uncompress it to the outputBuffer 28 | /// 29 | /// compressed byte from the ISF stream 30 | /// prealloc'd buffer to write to 31 | /// 32 | uint AlgoModule::DecompressPacketData(QByteArray input, QVector& outputBuffer) 33 | { 34 | if (input.size() < 2) 35 | { 36 | throw std::runtime_error(("Input buffer passed was shorter than expected")); 37 | } 38 | 39 | quint8 compression = (quint8)(outputBuffer.size() * 4); 40 | 41 | if (compression != (quint8)input[0]) 42 | { 43 | throw std::runtime_error(("Input buffer passed was shorter than expected")); 44 | } 45 | 46 | memcpy(outputBuffer.data(), input.data() + 1, outputBuffer.size() * 4); 47 | return outputBuffer.size() * 4 + 1; 48 | } 49 | 50 | /// 51 | /// Compresses property data which is already in the form of a byte[] 52 | /// into a compressed byte[] 53 | /// 54 | /// byte[] data ready to be compressed 55 | /// the compression to use 56 | /// 57 | QByteArray AlgoModule::CompressPropertyData(QByteArray input, quint8) 58 | { 59 | QByteArray output(input.size() + 1, 0); 60 | memcpy(output.data() + 1, input.data(), input.length()); 61 | return output; 62 | } 63 | 64 | /// 65 | /// Decompresses property data (from a compressed byte[] to an uncompressed byte[]) 66 | /// 67 | /// The byte[] to decompress 68 | /// 69 | QByteArray AlgoModule::DecompressPropertyData(QByteArray input) 70 | { 71 | QByteArray output(input.size() - 1, 0); 72 | memcpy(output.data(), input.data() + 1, input.size() - 1); 73 | return output; 74 | } 75 | 76 | INKCANVAS_END_NAMESPACE 77 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/algomodule.h: -------------------------------------------------------------------------------- 1 | #ifndef ALGOMODULE_H 2 | #define ALGOMODULE_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include 6 | #include 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class AlgoModule 12 | { 13 | public: 14 | /// 15 | /// Ctor 16 | /// 17 | AlgoModule(); 18 | 19 | /// 20 | /// Compresses int[] packet data, returns it as a byte[] 21 | /// 22 | /// assumed to be point data (x,x,x,x,x,x,x) 23 | /// magic byte specifying the compression to use 24 | /// 25 | QByteArray CompressPacketData(Array input, quint8 compression); 26 | 27 | /// 28 | /// DecompressPacketData - given a compressed byte[], uncompress it to the outputBuffer 29 | /// 30 | /// compressed byte from the ISF stream 31 | /// prealloc'd buffer to write to 32 | /// 33 | uint DecompressPacketData(QByteArray input, QVector& outputBuffer); 34 | 35 | /// 36 | /// Compresses property data which is already in the form of a byte[] 37 | /// into a compressed byte[] 38 | /// 39 | /// byte[] data ready to be compressed 40 | /// the compression to use 41 | /// 42 | QByteArray CompressPropertyData(QByteArray input, quint8 compression); 43 | 44 | /// 45 | /// Decompresses property data (from a compressed byte[] to an uncompressed byte[]) 46 | /// 47 | /// The byte[] to decompress 48 | /// 49 | QByteArray DecompressPropertyData(QByteArray input); 50 | 51 | private: 52 | /// 53 | /// Privates, lazy initialized, do not reference directly 54 | /// 55 | // HuffModule _huffModule; 56 | // MultiByteCodec _multiByteCodec; 57 | // DeltaDelta _deltaDelta; 58 | // GorillaCodec _gorillaCodec; 59 | // LZCodec _lzCodec; 60 | 61 | public: 62 | /// 63 | /// Static members defined in Penimc code 64 | /// 65 | static constexpr quint8 NoCompression = 0x00; 66 | static constexpr quint8 DefaultCompression = 0xC0; 67 | static constexpr quint8 IndexedHuffman = 0x80; 68 | static constexpr quint8 LempelZiv = 0x80; 69 | static constexpr quint8 DefaultBAACount = 8; 70 | static constexpr quint8 MaxBAACount = 10; 71 | 72 | 73 | static constexpr double DefaultFirstSquareRoot[] = { 1, 1, 1, 4, 9, 16, 36, 49}; 74 | }; 75 | 76 | INKCANVAS_END_NAMESPACE 77 | 78 | #endif // ALGOMODULE_H 79 | -------------------------------------------------------------------------------- /Windows/Ink/drawingflags.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INK_DRAWINGFLAGS_H 2 | #define WINDOWS_INK_DRAWINGFLAGS_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | // namespace System.Windows.Ink 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | enum class DrawingFlag 10 | { 11 | /// The stroke should be drawn as a polyline 12 | Polyline = 0x00000000, 13 | /// The stroke should be fit to a curve, such as a bezier. 14 | FitToCurve = 0x00000001, 15 | /// The stroke should be rendered by subtracting its rendering values 16 | /// from those on the screen 17 | SubtractiveTransparency = 0x00000002, 18 | /// Ignore any stylus pressure information when rendering 19 | IgnorePressure = 0x00000004, 20 | /// The stroke should be rendered with anti-aliased edges 21 | AntiAliased = 0x00000010, 22 | /// Ignore any stylus rotation information when rendering 23 | IgnoreRotation = 0x00000020, 24 | /// Ignore any stylus angle information when rendering 25 | IgnoreAngle = 0x00000040, 26 | }; 27 | 28 | #ifdef INKCANVAS_QT 29 | 30 | INKCANVAS_END_NAMESPACE 31 | 32 | #include 33 | #include 34 | 35 | INKCANVAS_BEGIN_NAMESPACE 36 | 37 | inline DrawingFlag operator ~(DrawingFlag f) 38 | { 39 | return static_cast(~static_cast(f)); 40 | } 41 | 42 | Q_DECLARE_FLAGS(DrawingFlags, DrawingFlag) 43 | 44 | Q_DECLARE_OPERATORS_FOR_FLAGS(DrawingFlags) 45 | 46 | INKCANVAS_END_NAMESPACE 47 | 48 | Q_DECLARE_METATYPE(INKCANVAS_PREPEND_NAMESPACE(DrawingFlags)) 49 | 50 | #else 51 | 52 | typedef DrawingFlag DrawingFlags; 53 | 54 | inline DrawingFlag operator ~(DrawingFlag f) 55 | { 56 | return static_cast(~static_cast(f)); 57 | } 58 | 59 | inline DrawingFlag operator |(DrawingFlag l, DrawingFlag r) 60 | { 61 | return static_cast(static_cast(l) | static_cast(r)); 62 | } 63 | 64 | inline DrawingFlag operator &(DrawingFlag l, DrawingFlag r) 65 | { 66 | return static_cast(static_cast(l) & static_cast(r)); 67 | } 68 | 69 | inline DrawingFlag operator ^(DrawingFlag l, DrawingFlag r) 70 | { 71 | return static_cast(static_cast(l) ^ static_cast(r)); 72 | } 73 | 74 | inline bool operator==(DrawingFlag l, int r) 75 | { 76 | return static_cast(l) == r; 77 | } 78 | 79 | inline bool operator!=(DrawingFlag l, int r) 80 | { 81 | return static_cast(l) != r; 82 | } 83 | 84 | inline bool operator==(int l, DrawingFlag r) 85 | { 86 | return static_cast(l) == r; 87 | } 88 | 89 | inline bool operator!=(int l, DrawingFlag r) 90 | { 91 | return static_cast(l) != r; 92 | } 93 | 94 | INKCANVAS_END_NAMESPACE 95 | 96 | #endif 97 | 98 | #endif // WINDOWS_INK_DRAWINGFLAGS_H 99 | -------------------------------------------------------------------------------- /Activities/Presentation/clipboarddata.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIPBOARDDATA_H 2 | #define CLIPBOARDDATA_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | class QMimeData; 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | typedef QMimeData DataObject; 11 | 12 | // namespace System.Activities.Presentation 13 | 14 | class ClipboardData 15 | { 16 | //------------------------------------------------------------------------------- 17 | // 18 | // Constructors 19 | // 20 | //------------------------------------------------------------------------------- 21 | 22 | public: 23 | virtual ~ClipboardData() {}; 24 | //------------------------------------------------------------------------------- 25 | // 26 | // Methods 27 | // 28 | //------------------------------------------------------------------------------- 29 | 30 | //#region Methods 31 | public: 32 | /// 33 | /// Copy the data to the IDataObject 34 | /// 35 | /// The IDataObject instance 36 | /// Returns true if the data is copied. Otherwise, returns false 37 | /// 38 | /// Critical: This code copies ink content to the clipboard and accepts a dataobject which is 39 | /// created under an elevation 40 | /// 41 | //[SecurityCritical] 42 | bool CopyToDataObject(DataObject* dataObject) 43 | { 44 | // Check if the data can be copied 45 | if ( CanCopy() ) 46 | { 47 | // Do copy. 48 | DoCopy(dataObject); 49 | return true; 50 | } 51 | 52 | return false; 53 | } 54 | 55 | /// 56 | /// Paste the data from the IDataObject 57 | /// 58 | /// The IDataObject instance 59 | void PasteFromDataObject(DataObject const * dataObject) 60 | { 61 | // Check if we can paste. 62 | if ( CanPaste(dataObject) ) 63 | { 64 | // Do Paste. 65 | DoPaste(dataObject); 66 | } 67 | } 68 | 69 | virtual bool CanPaste(DataObject const * dataObject) = 0; 70 | 71 | //#endregion Methods 72 | 73 | //------------------------------------------------------------------------------- 74 | // 75 | // Protected Methods 76 | // 77 | //------------------------------------------------------------------------------- 78 | 79 | //#region Protected Methods 80 | 81 | // Those are the abstract methods which need to be implemented in the derived classes. 82 | protected: 83 | virtual bool CanCopy() = 0; 84 | virtual void DoCopy(DataObject* dataObject) = 0; 85 | virtual void DoPaste(DataObject const * dataObject) = 0; 86 | 87 | //#endregion Protected Methods 88 | 89 | }; 90 | 91 | INKCANVAS_END_NAMESPACE 92 | 93 | #endif // CLIPBOARDDATA_H 94 | -------------------------------------------------------------------------------- /double.h: -------------------------------------------------------------------------------- 1 | #ifndef DOUBLE_H 2 | #define DOUBLE_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include 7 | #include 8 | 9 | INKCANVAS_BEGIN_NAMESPACE 10 | 11 | class Double 12 | { 13 | public: 14 | static constexpr double MinValue = -1.7976931348623157E+308; 15 | static constexpr double MaxValue = 1.7976931348623157E+308; 16 | 17 | // Note Epsilon should be a double whose hex representation is 0x1 18 | // on little endian machines. 19 | static constexpr double Epsilon = 4.9406564584124654E-324; 20 | // static constexpr double NegativeInfinity = (double)-1.0 / (double)(0.0); 21 | // static constexpr double PositiveInfinity = (double)1.0 / (double)(0.0); 22 | // static constexpr double NaN = (double)0.0 / (double)0.0; 23 | static const double NegativeInfinity; 24 | static const double PositiveInfinity; 25 | static const double NaN; 26 | 27 | static bool IsInfinity(double d) 28 | { 29 | return (*reinterpret_cast(&d) & 0x7FFFFFFFFFFFFFFF) == 0x7FF0000000000000; 30 | } 31 | 32 | static bool IsPositiveInfinity(double d) 33 | { 34 | //Jit will generate inlineable code with this 35 | if (d == PositiveInfinity) 36 | { 37 | return true; 38 | } 39 | else 40 | { 41 | return false; 42 | } 43 | } 44 | 45 | static bool IsNegativeInfinity(double d) 46 | { 47 | //Jit will generate inlineable code with this 48 | if (d == NegativeInfinity) 49 | { 50 | return true; 51 | } 52 | else 53 | { 54 | return false; 55 | } 56 | } 57 | 58 | static bool IsNegative(double d) 59 | { 60 | return (*reinterpret_cast(&d) & 0x8000000000000000) == 0x8000000000000000; 61 | } 62 | 63 | static bool IsNaN(double d) 64 | { 65 | return (*reinterpret_cast(&d) & 0x7FFFFFFFFFFFFFFFL) > 0x7FF0000000000000L; 66 | } 67 | 68 | static int Compare(double l, double r) 69 | { 70 | if (l < r) return -1; 71 | if (l > r) return 1; 72 | if (l == r) return 0; 73 | 74 | // At least one of the values is NaN. 75 | if (IsNaN(l)) 76 | return (IsNaN(r) ? 0 : -1); 77 | else 78 | return 1; 79 | } 80 | 81 | static bool Equals(double l, double r) 82 | { 83 | // This code below is written this way for performance reasons i.e the != and == check is intentional. 84 | if (l == r) { 85 | return true; 86 | } 87 | return IsNaN(l) && IsNaN(r); 88 | } 89 | 90 | static double Mod (double l, int r) 91 | { 92 | return l - floor(l / r) * r; 93 | } 94 | 95 | }; 96 | 97 | INKCANVAS_END_NAMESPACE 98 | 99 | #endif // DOUBLE_H 100 | -------------------------------------------------------------------------------- /Windows/Media/drawing.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_DRAWING_H 2 | #define WINDOWS_MEDIA_DRAWING_H 3 | 4 | #include "Windows/Media/drawingdrawingcontext.h" 5 | #include "Windows/rect.h" 6 | 7 | class QPainter; 8 | class QSvgRenderer; 9 | 10 | // namespace System.Windows.Media 11 | INKCANVAS_BEGIN_NAMESPACE 12 | 13 | class DrawingContext; 14 | class Drawing 15 | { 16 | public: 17 | Drawing(); 18 | 19 | virtual ~Drawing(); 20 | 21 | virtual Rect Bounds() = 0; 22 | 23 | virtual void Draw(QPainter& painer) = 0; 24 | 25 | }; 26 | 27 | class DrawingGroup : public Drawing 28 | { 29 | public: 30 | DrawingGroup(); 31 | 32 | virtual ~DrawingGroup() override; 33 | 34 | DrawingContext* Open(); 35 | 36 | List& Children(); 37 | 38 | virtual Rect Bounds() override; 39 | 40 | virtual void Draw(QPainter& painer) override; 41 | 42 | private: 43 | friend class DrawingGroupDrawingContext; 44 | 45 | void Close(List rootDrawingGroupChildren); 46 | 47 | private: 48 | List children_; 49 | }; 50 | 51 | #include 52 | #include 53 | 54 | class Geometry; 55 | 56 | class GeometryDrawing : public Drawing 57 | { 58 | public: 59 | GeometryDrawing(); 60 | 61 | virtual ~GeometryDrawing() override; 62 | 63 | void SetBrush(QBrush); 64 | 65 | void SetPen(QPen); 66 | 67 | void SetGeometry(Geometry *); 68 | 69 | virtual Rect Bounds() override; 70 | 71 | virtual void Draw(QPainter& painer) override; 72 | 73 | private: 74 | QBrush brush_; 75 | QPen pen_; 76 | Geometry * geometry_ = nullptr; 77 | }; 78 | 79 | class ImageDrawing : public Drawing 80 | { 81 | public: 82 | ImageDrawing(); 83 | 84 | virtual ~ImageDrawing() override; 85 | 86 | void SetImageSource(QImage); 87 | 88 | void SetRect(Rect); 89 | 90 | virtual Rect Bounds() override; 91 | 92 | virtual void Draw(QPainter& painer) override; 93 | 94 | private: 95 | QImage image_; 96 | Rect rect_ = Rect::Empty(); 97 | }; 98 | 99 | class SvgImageDrawing : public Drawing 100 | { 101 | public: 102 | SvgImageDrawing(); 103 | 104 | virtual ~SvgImageDrawing() override; 105 | 106 | void SetImageSource(QSvgRenderer * renderer); 107 | 108 | void SetRect(Rect); 109 | 110 | virtual Rect Bounds() override; 111 | 112 | virtual void Draw(QPainter& painer) override; 113 | 114 | private: 115 | QSvgRenderer * renderer_; 116 | Rect rect_ = Rect::Empty(); 117 | }; 118 | 119 | class DrawingGroupDrawingContext : public DrawingDrawingContext 120 | { 121 | public: 122 | DrawingGroupDrawingContext(DrawingGroup* drawingGroup); 123 | protected: 124 | void CloseCore(List rootDrawingGroupChildren); 125 | 126 | private: 127 | DrawingGroup* drawingGroup_ = nullptr; 128 | }; 129 | 130 | INKCANVAS_END_NAMESPACE 131 | 132 | #endif // WINDOWS_MEDIA_DRAWING_H 133 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/metricblock.h: -------------------------------------------------------------------------------- 1 | #ifndef METRICBLOCK_H 2 | #define METRICBLOCK_H 3 | 4 | #include "Internal/Ink/InkSerializedFormat/metricentry.h" 5 | 6 | class QIODevice; 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class MetricEntry; 11 | 12 | /// 13 | /// CMetricBlock owns CMetricEntry which is created based on the Packet Description of the stroke. It also 14 | /// stores the pointer of the next Block. This is not used in the context of a stroke but is used in the 15 | /// context of WispInk. Wispink forms a linked list based on the CMetricBlocks of all the strokes. 16 | /// 17 | 18 | class MetricBlock 19 | { 20 | MetricEntry* _Entry = nullptr; 21 | uint _Count = 0; 22 | uint _size = 0; 23 | 24 | public: 25 | /// 26 | /// Constructor 27 | /// 28 | MetricBlock(); 29 | 30 | /// 31 | /// Gets the MetricEntry list associated with this instance 32 | /// 33 | /// 34 | MetricEntry* GetMetricEntryList() 35 | { 36 | return _Entry; 37 | } 38 | 39 | /// 40 | /// Gets the count of MetricEntry for this instance 41 | /// 42 | uint MetricEntryCount() 43 | { 44 | return _Count; 45 | } 46 | 47 | // Returns the size required to serialize this instance 48 | uint Size(); 49 | 50 | /// 51 | /// Adds a new metric entry in the existing list of metric entries 52 | /// 53 | /// 54 | /// 55 | void AddMetricEntry(MetricEntry* newEntry); 56 | 57 | /// 58 | /// Adds a new metric entry in the existing list of metric entries 59 | /// 60 | /// 61 | /// 62 | /// 63 | MetricEntryType AddMetricEntry(StylusPointPropertyInfo const & property, KnownTagCache::KnownTagIndex tag); 64 | 65 | /// 66 | /// This function Packs the data in the buffer provided. The 67 | /// function is being called during the save loop and caller 68 | /// must call GetSize for the block before calling this function. 69 | /// The buffer must be preallocated and buffer size must be at 70 | /// least the size of the block. 71 | /// On return cbBuffer contains the size of the data written. 72 | /// Called only by BuildMetricTable funtion 73 | /// 74 | /// 75 | /// 76 | uint Pack(QIODevice& strm); 77 | // 78 | // 79 | 80 | /// 81 | /// This function compares pMetricColl with the current one. If pMetricColl has more entries apart from the one 82 | /// in the current list with which some of its entries are identical, setType is set as SUPERSET. 83 | /// 84 | /// 85 | /// 86 | /// 87 | bool CompareMetricBlock( MetricBlock& metricColl, SetType& setType); 88 | }; 89 | 90 | INKCANVAS_END_NAMESPACE 91 | 92 | #endif // METRICBLOCK_H 93 | -------------------------------------------------------------------------------- /Internal/Ink/erasingstroke.h: -------------------------------------------------------------------------------- 1 | #ifndef ERASINGSTROKE_H 2 | #define ERASINGSTROKE_H 3 | 4 | #include "Internal/Ink/strokenodeiterator.h" 5 | #include "Internal/Ink/strokenode.h" 6 | #include "Collections/Generic/list.h" 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class StylusShape; 11 | 12 | // namespace MS.Internal.Ink 13 | 14 | /// 15 | /// This class represents a contour of an erasing stroke, and provides 16 | /// internal API for static and incremental stroke_contour vs stroke_contour 17 | /// hit-testing. 18 | /// 19 | class ErasingStroke 20 | { 21 | public: 22 | 23 | 24 | /// 25 | /// Constructor for incremental erasing 26 | /// 27 | /// The shape of the eraser's tip 28 | ErasingStroke(StylusShape& erasingShape); 29 | 30 | /// 31 | /// Constructor for static (atomic) erasing 32 | /// 33 | /// The shape of the eraser's tip 34 | /// the spine of the erasing stroke 35 | ErasingStroke(StylusShape &erasingShape, List const & path); 36 | 37 | /// 38 | /// Generates stroke nodes along a given path. 39 | /// Drops any previously genererated nodes. 40 | /// 41 | /// 42 | void MoveTo(List const & path); 43 | 44 | /// 45 | /// Returns the bounds of the eraser's last move. 46 | /// 47 | /// 48 | Rect Bounds() { return _bounds; } 49 | 50 | /// 51 | /// Hit-testing for stroke erase scenario. 52 | /// 53 | /// the stroke nodes to iterate 54 | /// true if the strokes intersect, false otherwise 55 | bool HitTest(StrokeNodeIterator const & iterator); 56 | 57 | /// 58 | /// Hit-testing for point erase. 59 | /// 60 | /// 61 | /// 62 | /// 63 | bool EraseTest(StrokeNodeIterator const & iterator, List& intersections); 64 | 65 | 66 | private: 67 | Array FilterPoints(Array const & path); 68 | 69 | private: 70 | StrokeNodeIterator _nodeIterator; 71 | List _erasingStrokeNodes; 72 | Rect _bounds = Rect::Empty(); 73 | 74 | #if POINTS_FILTER_TRACE 75 | int _totalPointsAdded = 0; 76 | int _totalPointsScreened = 0; 77 | int _collinearPointsScreened = 0; 78 | #endif 79 | 80 | // The collinear tolerance used in points filtering algorithm. The valie 81 | // should be further tuned considering trade-off of performance and accuracy. 82 | // In general, the larger the value, more points are filtered but less accurate. 83 | // For a value of 0.5, typically 70% - 80% percent of the points are filtered out. 84 | private: 85 | static constexpr double CollinearTolerance = 0.1; 86 | 87 | }; 88 | 89 | INKCANVAS_END_NAMESPACE 90 | 91 | #endif // ERASINGSTROKE_H 92 | -------------------------------------------------------------------------------- /Windows/Input/styluspointpropertyinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_STYLUSPOINTPROPERTYINFO_H 2 | #define WINDOWS_INPUT_STYLUSPOINTPROPERTYINFO_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Windows/Input/styluspointproperty.h" 6 | 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | enum StylusPointPropertyUnit { 10 | 11 | None = 0, 12 | 13 | Inches = 1, 14 | 15 | Centimeters = 2, 16 | 17 | Degrees = 3, 18 | 19 | Radians = 4, 20 | 21 | Seconds = 5, 22 | 23 | Pounds = 6, 24 | 25 | Grams = 7 26 | }; 27 | 28 | // namespace System.Windows.Input 29 | 30 | class StylusPointPropertyInfo 31 | { 32 | private: 33 | /// 34 | /// Instance data 35 | /// 36 | StylusPointProperty const * prop_; 37 | int _min; 38 | int _max; 39 | float _resolution; 40 | StylusPointPropertyUnit _unit; 41 | 42 | /// 43 | /// For a given StylusPointProperty, instantiates a StylusPointPropertyInfo with default values 44 | /// 45 | /// 46 | public: 47 | StylusPointPropertyInfo() : prop_(&StylusPointProperty::Empty) {} 48 | 49 | StylusPointPropertyInfo(StylusPointProperty const & stylusPointProperty); 50 | 51 | /// 52 | /// StylusPointProperty 53 | /// 54 | /// 55 | /// minimum 56 | /// maximum 57 | /// unit 58 | /// resolution 59 | StylusPointPropertyInfo(StylusPointProperty const & stylusPointProperty, int minimum, int maximum, 60 | StylusPointPropertyUnit unit, float resolution); 61 | 62 | operator StylusPointProperty const & () const 63 | { 64 | return *prop_; 65 | } 66 | 67 | Guid const & Id() const 68 | { 69 | return prop_->Id(); 70 | } 71 | 72 | bool IsButton() const 73 | { 74 | return prop_->IsButton(); 75 | } 76 | 77 | /// 78 | /// Minimum 79 | /// 80 | int Minimum() const 81 | { 82 | return _min; 83 | } 84 | 85 | /// 86 | /// Maximum 87 | /// 88 | int Maximum() const 89 | { 90 | return _max; 91 | } 92 | 93 | /// 94 | /// Resolution 95 | /// 96 | float Resolution() const 97 | { 98 | return _resolution; 99 | } 100 | 101 | /// 102 | /// Unit 103 | /// 104 | StylusPointPropertyUnit Unit() const 105 | { 106 | return _unit; 107 | } 108 | 109 | /// 110 | /// helper method for comparing compat for two StylusPointPropertyInfos 111 | /// 112 | static bool AreCompatible(StylusPointPropertyInfo const & stylusPointPropertyInfo1, StylusPointPropertyInfo const & stylusPointPropertyInfo2); 113 | }; 114 | 115 | INKCANVAS_END_NAMESPACE 116 | 117 | #endif // WINDOWS_INPUT_STYLUSPOINTPROPERTYINFO_H 118 | -------------------------------------------------------------------------------- /Windows/Input/styluseventargs.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/styluseventargs.h" 2 | #include "Windows/Input/stylusdevice.h" 3 | #include 4 | INKCANVAS_BEGIN_NAMESPACE 5 | 6 | StylusEventArgs::StylusEventArgs(QTouchEvent& event) 7 | : InputEventArgs(Stylus::GetDevice(event.device()), static_cast(event.timestamp())) 8 | , event_(&event) 9 | { 10 | } 11 | 12 | ///////////////////////////////////////////////////////////////////// 13 | /// 14 | /// Initializes a new instance of the StylusEventArgs class. 15 | /// 16 | /// 17 | /// The logical Stylus device associated with this event. 18 | /// 19 | /// 20 | /// The time when the input occured. 21 | /// 22 | StylusEventArgs::StylusEventArgs(StylusDevice* stylus, int timestamp) 23 | : InputEventArgs(stylus, timestamp) 24 | , event_(nullptr) 25 | { 26 | if( stylus == nullptr ) 27 | { 28 | throw std::runtime_error("stylus"); 29 | } 30 | } 31 | 32 | ///////////////////////////////////////////////////////////////////// 33 | /// 34 | /// Read-only access to the stylus device associated with this 35 | /// event. 36 | /// 37 | StylusDevice* StylusEventArgs::GetStylusDevice() 38 | { 39 | return (StylusDevice*)Device(); 40 | } 41 | 42 | ///////////////////////////////////////////////////////////////////// 43 | /// 44 | /// Calculates the position of the stylus relative to a particular element. 45 | /// 46 | Point StylusEventArgs::GetPosition(Visual* relativeTo) 47 | { 48 | return GetStylusDevice()->GetPosition(relativeTo); 49 | } 50 | 51 | ///////////////////////////////////////////////////////////////////// 52 | /// 53 | /// Indicates the stylus is not touching the surface. 54 | /// 55 | bool StylusEventArgs::InAir() 56 | { 57 | return GetStylusDevice()->InAir(); 58 | } 59 | 60 | 61 | ///////////////////////////////////////////////////////////////////// 62 | /// 63 | /// Indicates stylusDevice is in the inverted state. 64 | /// 65 | bool StylusEventArgs::Inverted() 66 | { 67 | return GetStylusDevice()->Inverted(); 68 | } 69 | 70 | ///////////////////////////////////////////////////////////////////// 71 | /// 72 | /// Returns a StylusPointCollection for processing the data from input. 73 | /// This method creates a new StylusPointCollection and copies the data. 74 | /// 75 | SharedPointer StylusEventArgs::GetStylusPoints(Visual* relativeTo) 76 | { 77 | return GetStylusDevice()->GetStylusPoints(relativeTo); 78 | } 79 | 80 | ///////////////////////////////////////////////////////////////////// 81 | /// 82 | /// Returns a StylusPointCollection for processing the data from input. 83 | /// This method creates a new StylusPointCollection and copies the data. 84 | /// 85 | SharedPointer StylusEventArgs::GetStylusPoints(Visual* relativeTo, SharedPointer subsetToReformatTo) 86 | { 87 | return GetStylusDevice()->GetStylusPoints(relativeTo, subsetToReformatTo); 88 | } 89 | 90 | INKCANVAS_END_NAMESPACE 91 | -------------------------------------------------------------------------------- /Windows/Media/geometry.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_MEDIA_GEOMETRY_H 2 | #define WINDOWS_MEDIA_GEOMETRY_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include "Windows/point.h" 7 | #include "Windows/rect.h" 8 | #include "Collections/Generic/list.h" 9 | 10 | #ifdef INKCANVAS_QT_DRAW 11 | class QPainter; 12 | #endif 13 | 14 | #ifdef INKCANVAS_QT 15 | #include 16 | #endif 17 | 18 | // namespace System.Windows.Media 19 | INKCANVAS_BEGIN_NAMESPACE 20 | 21 | enum SweepDirection 22 | { 23 | /// 24 | /// Counterclockwise - 25 | /// 26 | Counterclockwise = 0, 27 | 28 | /// 29 | /// Clockwise - 30 | /// 31 | Clockwise = 1, 32 | }; 33 | 34 | 35 | class Geometry 36 | { 37 | public: 38 | Geometry(); 39 | 40 | virtual ~Geometry(); 41 | 42 | virtual Rect Bounds() = 0; 43 | 44 | #ifdef INKCANVAS_QT_DRAW 45 | virtual void Draw(QPainter& painter) = 0; 46 | #endif 47 | 48 | bool tryTakeOwn(void * owner); 49 | 50 | bool releaseOwn(void * owner); 51 | 52 | private: 53 | void * owner_ = nullptr; 54 | }; 55 | 56 | #ifdef INKCANVAS_QT 57 | 58 | class PathGeometry : public Geometry 59 | { 60 | public: 61 | PathGeometry(); 62 | 63 | Geometry * GetOutlinedPathGeometry(); 64 | 65 | void Add(QPainterPath& path); 66 | 67 | PathGeometry* Combine(Geometry * geometry); 68 | 69 | virtual Rect Bounds() override; 70 | 71 | #ifdef INKCANVAS_QT_DRAW 72 | virtual void Draw(QPainter& painter) override; 73 | #endif 74 | 75 | private: 76 | QPainterPath path_; 77 | }; 78 | 79 | #endif 80 | 81 | class GeometryGroup : public Geometry 82 | { 83 | public: 84 | virtual ~GeometryGroup() override; 85 | 86 | List& Children(); 87 | 88 | virtual Rect Bounds() override; 89 | 90 | #ifdef INKCANVAS_QT_DRAW 91 | virtual void Draw(QPainter& painter) override; 92 | #endif 93 | 94 | private: 95 | List children_; 96 | }; 97 | 98 | class LineGeometry : public Geometry 99 | { 100 | public: 101 | LineGeometry(Point const & point0, Point const & point1); 102 | 103 | virtual Rect Bounds() override; 104 | 105 | #ifdef INKCANVAS_QT_DRAW 106 | virtual void Draw(QPainter& painter) override; 107 | #endif 108 | 109 | private: 110 | Point start_; 111 | Point end_; 112 | }; 113 | 114 | class RectangleGeometry : public Geometry 115 | { 116 | public: 117 | RectangleGeometry(Rect const & rectangle); 118 | RectangleGeometry(Rect const & rectangle, double radiusX, double radiusY); 119 | 120 | virtual Rect Bounds() override; 121 | 122 | #ifdef INKCANVAS_QT_DRAW 123 | virtual void Draw(QPainter& painter) override; 124 | #endif 125 | 126 | private: 127 | Rect rectangle_; 128 | Size radius_; 129 | }; 130 | 131 | class EllipseGeometry : public Geometry 132 | { 133 | public: 134 | EllipseGeometry(Point const & center, double radiusX, double radiusY); 135 | 136 | virtual Rect Bounds() override; 137 | 138 | #ifdef INKCANVAS_QT_DRAW 139 | virtual void Draw(QPainter& painter) override; 140 | #endif 141 | 142 | private: 143 | Rect rectangle_; 144 | }; 145 | 146 | INKCANVAS_END_NAMESPACE 147 | 148 | #endif // WINDOWS_MEDIA_GEOMETRY_H 149 | -------------------------------------------------------------------------------- /Collections/Generic/array.h: -------------------------------------------------------------------------------- 1 | #ifndef COLLECTIONS_GENERIC_ARRAY_H 2 | #define COLLECTIONS_GENERIC_ARRAY_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #ifdef INKCANVAS_QT 7 | 8 | #include 9 | 10 | INKCANVAS_BEGIN_NAMESPACE 11 | 12 | template 13 | class Array : private QVector 14 | { 15 | public: 16 | Array() {} 17 | Array(int n) { resize(n); } 18 | Array(QVector const & array) : QVector(array) {} 19 | Array(QVector && array) : QVector(std::move(array)) {} 20 | Array(Array const & array) : QVector(array) {} 21 | Array(Array && array) : QVector(std::move(array)) {} 22 | Array(std::initializer_list list) : QVector(list) {} 23 | 24 | Array & operator=(Array const & array) { QVector::operator=(array); return *this; } 25 | Array & operator=(Array && array) { QVector::operator=(std::move(array)); return *this; } 26 | 27 | int Length() const { return QVector::size(); } 28 | //void Add(T const & t) { push_back(t); } 29 | //void Insert(int index, T const & t) { insert(begin() + index, t); } 30 | //void Clear() { clear(); } 31 | 32 | T & operator[](int index) { return QVector::operator[](static_cast(index)); } 33 | T const & operator[](int index) const { return QVector::operator[](static_cast(index)); } 34 | 35 | using QVector::begin; 36 | using QVector::end; 37 | 38 | public: 39 | using QVector::empty; 40 | 41 | void resize(int n) { QVector::resize(static_cast(n)); } 42 | 43 | QVector const & toQVector() const { return *this; } 44 | QVector && toQVector() { return std::move(*this); } 45 | }; 46 | 47 | INKCANVAS_END_NAMESPACE 48 | 49 | #else 50 | 51 | #include 52 | 53 | INKCANVAS_BEGIN_NAMESPACE 54 | 55 | template 56 | class Array : private std::vector 57 | { 58 | public: 59 | typedef typename std::vector::value_type value_type; 60 | Array() {} 61 | Array(int n) { resize(n); } 62 | Array(std::vector const & array) : std::vector(array) {} 63 | Array(std::vector && array) : std::vector(std::move(array)) {} 64 | Array(Array const & array) : std::vector(array) {} 65 | Array(Array && array) : std::vector(std::move(array)) {} 66 | Array(std::initializer_list list) : std::vector(list) {} 67 | 68 | Array & operator=(Array const & array) { std::vector::operator=(array); return *this; } 69 | Array & operator=(Array && array) { std::vector::operator=(std::move(array)); return *this; } 70 | 71 | int Length() const { return static_cast(std::vector::size()); } 72 | void Add(T const & t) { push_back(t); } 73 | void Insert(int index, T const & t) { insert(begin() + index, t); } 74 | void Clear() { std::vector::clear(); } 75 | 76 | T & operator[](int index) { return std::vector::operator[](static_cast(index)); } 77 | T const & operator[](int index) const { return std::vector::operator[](static_cast(index)); } 78 | 79 | using std::vector::begin; 80 | using std::vector::end; 81 | 82 | public: 83 | using std::vector::empty; 84 | 85 | void resize(int n) { std::vector::resize(static_cast(n)); } 86 | }; 87 | 88 | INKCANVAS_END_NAMESPACE 89 | 90 | #endif 91 | 92 | #endif // COLLECTIONS_GENERIC_ARRAY_H 93 | -------------------------------------------------------------------------------- /InkCanvas.pro: -------------------------------------------------------------------------------- 1 | QT += gui widgets svg 2 | 3 | TEMPLATE = lib 4 | DEFINES += INKCANVAS_LIBRARY 5 | 6 | CONFIG += c++17 inkcanvas_qt 7 | 8 | include($$(applyCommonConfig)) 9 | 10 | include(../config.pri) 11 | 12 | # The following define makes your compiler emit warnings if you use 13 | # any Qt feature that has been marked deprecated (the exact warnings 14 | # depend on your compiler). Please consult the documentation of the 15 | # deprecated API in order to know how to port your code away from it. 16 | DEFINES += QT_DEPRECATED_WARNINGS 17 | 18 | # You can also make your code fail to compile if it uses deprecated APIs. 19 | # In order to do so, uncomment the following line. 20 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 21 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 22 | 23 | DEFINES += DEBUG_RENDERING_FEEDBACK=0 24 | DEFINES += DEBUG_LASSO_FEEDBACK=0 25 | DEFINES += DEBUG_OUTPUT=0 26 | DEFINES += OLD_ISF=0 27 | 28 | SOURCES += \ 29 | cmath.cpp \ 30 | double.cpp \ 31 | eventargs.cpp \ 32 | guid.cpp \ 33 | single.cpp \ 34 | variant.cpp 35 | 36 | HEADERS += \ 37 | InkCanvas_global.h \ 38 | cmath.h \ 39 | double.h \ 40 | single.h \ 41 | eventargs.h \ 42 | guid.h \ 43 | variant.h 44 | 45 | RESOURCES += \ 46 | inkcanvas.qrc 47 | 48 | include(Windows/Windows.pri) 49 | include(Internal/Internal.pri) 50 | include(Activities/Activities.pri) 51 | include(Collections/Collections.pri) 52 | include(Landing/Landing.pri) 53 | 54 | includes.files = $$PWD/*.h 55 | includes.windows.files = $$PWD/Windows/*.h 56 | includes.windows.control.files = $$PWD/Windows/Controls/*.h 57 | includes.windows.ink.files = $$PWD/Windows/Ink/*.h 58 | includes.windows.media.files = $$PWD/Windows/Media/*.h 59 | includes.windows.input.files = $$PWD/Windows/Input/*.h 60 | includes.internal.files = $$PWD/Internal/*.h 61 | includes.internal.control.files = $$PWD/Internal/Controls/*.h 62 | includes.internal.ink.files = $$PWD/Internal/Ink/*.h 63 | 64 | includes.path = $$[QT_INSTALL_HEADERS]/InkCanvas 65 | includes.windows.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Windows 66 | includes.windows.control.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Windows/Controls 67 | includes.windows.ink.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Windows/Ink 68 | includes.windows.media.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Windows/Media 69 | includes.windows.input.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Windows/Input 70 | includes.internal.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Internal 71 | includes.internal.control.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Internal/Controls 72 | includes.internal.ink.path = $$[QT_INSTALL_HEADERS]/InkCanvas/Internal/Ink 73 | target.path = $$[QT_INSTALL_LIBS] 74 | 75 | INSTALLS += includes \ 76 | includes.windows \ 77 | includes.windows.control \ 78 | includes.windows.ink \ 79 | includes.windows.input \ 80 | includes.windows.media \ 81 | includes.internal \ 82 | includes.internal.control \ 83 | includes.internal.ink \ 84 | 85 | # Default rules for deployment. 86 | unix { 87 | target.path = /usr/lib 88 | } 89 | !isEmpty(target.path): INSTALLS += target 90 | 91 | win32 { 92 | #INCLUDEPATH += "C:\Program Files (x86)\Microsoft Tablet PC Platform SDK\Include" 93 | LIBS += -ladvapi32 94 | #LIBS += -L$$PWD -lmshwgst 95 | } 96 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/serializationhelper.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATIONHELPER_H 2 | #define SERIALIZATIONHELPER_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | class QIODevice; 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | /// 11 | /// Summary description for HelperMethods. 12 | /// 13 | class SerializationHelper 14 | { 15 | public: 16 | /// 17 | /// returns the no of byte it requires to mutlibyte encode a quint32 value 18 | /// 19 | /// 20 | /// 21 | static quint32 VarSize(quint32 Value); 22 | 23 | 24 | /// 25 | /// MultiByte Encodes an quint32 Value into the stream 26 | /// 27 | /// 28 | /// 29 | /// 30 | static quint32 Encode(QIODevice& strm, quint32 Value); 31 | 32 | 33 | /// 34 | /// Multibyte encodes a unsinged long value in the stream 35 | /// 36 | /// 37 | /// 38 | /// 39 | static quint32 EncodeLarge(QIODevice& strm, quint64 ulValue); 40 | 41 | 42 | /// 43 | /// Multibyte encodes a signed integer value into a stream. Use 1's complement to 44 | /// store signed values. This means both 00 and 01 are actually 0, but we don't 45 | /// need to encode all negative numbers as 64 bit values. 46 | /// 47 | /// 48 | /// 49 | /// 50 | // Use 1's complement to store signed values. This means both 00 and 01 are 51 | // actually 0, but we don't need to encode all negative numbers as 64 bit values. 52 | static quint32 SignEncode(QIODevice& strm, int Value); 53 | 54 | /// 55 | /// Decodes a multi byte encoded unsigned integer from the stream 56 | /// 57 | /// 58 | /// 59 | /// 60 | static quint32 Decode(QIODevice& strm, quint32& dw); 61 | 62 | 63 | /// 64 | /// Decodes a multibyte encoded unsigned long from the stream 65 | /// 66 | /// 67 | /// 68 | /// 69 | static quint32 DecodeLarge(QIODevice& strm, quint64& ull); 70 | 71 | 72 | /// 73 | /// Decodes a multibyte encoded signed integer from the stream 74 | /// 75 | /// 76 | /// 77 | /// 78 | static quint32 SignDecode(QIODevice& strm, int& i); 79 | 80 | /// 81 | /// Converts the CLR type information into a COM-compatible type enumeration 82 | /// 83 | /// The CLR type information of the object to convert 84 | /// Throw an exception if unknown type is used 85 | /// The COM-compatible type enumeration 86 | /// Only supports the types of data that are supported in ISF ExtendedProperties 87 | //static VarEnum ConvertToVarEnum(Type type, bool throwOnError); 88 | }; 89 | 90 | INKCANVAS_END_NAMESPACE 91 | 92 | #endif // SERIALIZATIONHELPER_H 93 | -------------------------------------------------------------------------------- /Windows/Input/styluspointproperties.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_STYLUSPOINTPROPERTIES_H 2 | #define WINDOWS_INPUT_STYLUSPOINTPROPERTIES_H 3 | 4 | #include "Windows/Input/styluspointproperty.h" 5 | 6 | // namespace System.Windows.Input 7 | INKCANVAS_BEGIN_NAMESPACE 8 | 9 | class StylusPointProperties 10 | { 11 | public: 12 | /// 13 | /// X 14 | /// 15 | static StylusPointProperty const X; 16 | 17 | /// 18 | /// Y 19 | /// 20 | static StylusPointProperty const Y; 21 | 22 | /// 23 | /// Z 24 | /// 25 | static StylusPointProperty const Z; 26 | 27 | /// 28 | /// Width 29 | /// 30 | static StylusPointProperty const Width; 31 | 32 | /// 33 | /// Height 34 | /// 35 | static StylusPointProperty const Height; 36 | 37 | /// 38 | /// SystemContact 39 | /// 40 | static StylusPointProperty const SystemTouch; 41 | 42 | /// 43 | /// PacketStatus 44 | /// 45 | static StylusPointProperty const PacketStatus; 46 | 47 | /// 48 | /// SerialNumber 49 | /// 50 | static StylusPointProperty const SerialNumber; 51 | 52 | /// 53 | /// NormalPressure 54 | /// 55 | static StylusPointProperty const NormalPressure; 56 | 57 | /// 58 | /// TangentPressure 59 | /// 60 | static StylusPointProperty const TangentPressure; 61 | 62 | /// 63 | /// ButtonPressure 64 | /// 65 | static StylusPointProperty const ButtonPressure; 66 | 67 | /// 68 | /// XTiltOrientation 69 | /// 70 | static StylusPointProperty const XTiltOrientation; 71 | 72 | /// 73 | /// YTiltOrientation 74 | /// 75 | static StylusPointProperty const YTiltOrientation; 76 | 77 | /// 78 | /// AzimuthOrientation 79 | /// 80 | static StylusPointProperty const AzimuthOrientation; 81 | 82 | /// 83 | /// AltitudeOrientation 84 | /// 85 | static StylusPointProperty const AltitudeOrientation; 86 | 87 | /// 88 | /// TwistOrientation 89 | /// 90 | static StylusPointProperty const TwistOrientation; 91 | 92 | /// 93 | /// PitchRotation 94 | /// 95 | static StylusPointProperty const PitchRotation; 96 | 97 | /// 98 | /// RollRotation 99 | /// 100 | static StylusPointProperty const RollRotation; 101 | 102 | /// 103 | /// YawRotation 104 | /// 105 | static StylusPointProperty const YawRotation; 106 | 107 | /// 108 | /// TipButton 109 | /// 110 | static StylusPointProperty const TipButton; 111 | 112 | /// 113 | /// BarrelButton 114 | /// 115 | static StylusPointProperty const BarrelButton; 116 | 117 | /// 118 | /// SecondaryTipButton 119 | /// 120 | static StylusPointProperty const SecondaryTipButton; 121 | }; 122 | 123 | INKCANVAS_END_NAMESPACE 124 | 125 | #endif // WINDOWS_INPUT_STYLUSPOINTPROPERTIES_H 126 | -------------------------------------------------------------------------------- /Landing/Qt/qtpainterdrawingcontext.h: -------------------------------------------------------------------------------- 1 | #ifndef QTPAINTERDRAWINGCONTEXT_H 2 | #define QTPAINTERDRAWINGCONTEXT_H 3 | 4 | #include "Windows/Media/drawingcontext.h" 5 | 6 | class QPainter; 7 | 8 | INKCANVAS_BEGIN_NAMESPACE 9 | 10 | class QtPainterDrawingContext : public DrawingContext 11 | { 12 | public: 13 | QtPainterDrawingContext(QPainter& painter); 14 | 15 | public: 16 | virtual void DrawLine( 17 | QPen pen, 18 | Point const & point0, 19 | Point const & point1) override; 20 | 21 | virtual void DrawLine( 22 | QPen pen, 23 | Point const & point0, 24 | AnimationClock * point0Animations, 25 | Point const & point1, 26 | AnimationClock * point1Animations) override; 27 | 28 | virtual void DrawRectangle( 29 | QBrush brush, 30 | QPen pen, 31 | Rect const & rectangle) override; 32 | 33 | virtual void DrawRectangle( 34 | QBrush brush, 35 | QPen pen, 36 | Rect const & rectangle, 37 | AnimationClock * rectangleAnimations) override; 38 | 39 | virtual void DrawRoundedRectangle( 40 | QBrush brush, 41 | QPen pen, 42 | Rect const & rectangle, 43 | double radiusX, 44 | double radiusY) override; 45 | 46 | virtual void DrawRoundedRectangle( 47 | QBrush brush, 48 | QPen pen, 49 | Rect const & rectangle, 50 | AnimationClock * rectangleAnimations, 51 | double radiusX, 52 | AnimationClock * radiusXAnimations, 53 | double radiusY, 54 | AnimationClock * radiusYAnimations) override; 55 | 56 | virtual void DrawEllipse( 57 | QBrush brush, 58 | QPen pen, 59 | Point const & center, 60 | double radiusX, 61 | double radiusY) override; 62 | 63 | virtual void DrawEllipse( 64 | QBrush brush, 65 | QPen pen, 66 | Point const & center, 67 | AnimationClock * centerAnimations, 68 | double radiusX, 69 | AnimationClock * radiusXAnimations, 70 | double radiusY, 71 | AnimationClock * radiusYAnimations) override; 72 | 73 | virtual void DrawGeometry( 74 | QBrush brush, 75 | QPen pen, 76 | Geometry * geometry) override; 77 | 78 | virtual void DrawImage( 79 | QImage imageSource, 80 | Rect const & rectangle) override; 81 | 82 | virtual void DrawImage( 83 | QImage imageSource, 84 | Rect const & rectangle, 85 | AnimationClock * rectangleAnimations) override; 86 | 87 | virtual void DrawDrawing( 88 | Drawing * drawing) override; 89 | 90 | virtual void PushClip( 91 | Geometry * clipGeometry) override; 92 | 93 | virtual void PushOpacityMask(QBrush brush) override; 94 | 95 | virtual void PushOpacity( 96 | double opacity 97 | ) override; 98 | 99 | virtual void PushOpacity( 100 | double opacity, 101 | AnimationClock * opacityAnimations) override; 102 | 103 | virtual void PushTransform( 104 | Matrix const & transform) override; 105 | 106 | virtual void Pop() override; 107 | 108 | virtual void Close() override; 109 | 110 | private: 111 | QPainter& painter_; 112 | }; 113 | 114 | INKCANVAS_END_NAMESPACE 115 | 116 | #endif // QTPAINTERDRAWINGCONTEXT_H 117 | -------------------------------------------------------------------------------- /Internal/Ink/lassohelper.h: -------------------------------------------------------------------------------- 1 | #ifndef LASSOHELPER_H 2 | #define LASSOHELPER_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Windows/rect.h" 6 | #include "Collections/Generic/list.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | INKCANVAS_BEGIN_NAMESPACE 13 | 14 | class DrawingVisual; 15 | class Visual; 16 | 17 | // namespace MS.Internal.Ink 18 | 19 | /// 20 | /// An internal helper class to draw lasso as a sequence of dots 21 | /// closed with a rubber line. LassoSelectionBehavior creates an object of 22 | /// this class to render a single lasso, so, for simplicity, 23 | /// LassoHelper objects are indended for one-time use only. 24 | /// 25 | class LassoHelper 26 | { 27 | //#region Fields 28 | 29 | // Visuals, geometry builders and drawing stuff 30 | DrawingVisual* _containerVisual = nullptr; 31 | QBrush _brush; 32 | QPen _pen; 33 | //Pen _linePen = null; 34 | 35 | // 36 | bool _isActivated = false; 37 | Point _firstLassoPoint; 38 | Point _lastLassoPoint; 39 | int _count = 0; 40 | 41 | // Entire lasso. Collected to hit test InkCanvas' subelements after stylus up. 42 | List _lasso; 43 | Rect _boundingBox; 44 | 45 | // NTRAID#T2-00000-2003/07/14-vsmirnov - some of these are probably not in sync 46 | // with the spec (which is not available at this moment), and also might 47 | // need to be different for the high contrast mode. 48 | public: 49 | static constexpr double MinDistanceSquared = 49.0; 50 | static constexpr double DotRadius = 2.5; 51 | static constexpr double DotCircumferenceThickness = 0.5; 52 | static constexpr double ConnectLineThickness = 0.75; 53 | static constexpr double ConnectLineOpacity = 0.75; 54 | static const QColor DotColor; //FromArgb(1, 0.89f, 0.3607f, 0.1843f); 55 | static const QColor DotCircumferenceColor; 56 | 57 | //#endregion 58 | 59 | //#region API 60 | /// 61 | /// Read-only access to the container visual for dynamic drawing a lasso 62 | /// 63 | public: 64 | ~LassoHelper(); 65 | 66 | Visual* GetVisual(); 67 | 68 | /// TBS 69 | Array AddPoints(List const & points); 70 | 71 | //#region ArePointsInLasso 72 | /// Copy-pasted Platform's Lasso.Contains(...) 73 | bool ArePointsInLasso(Array const & points, int percentIntersect); 74 | 75 | private: 76 | ///// 77 | ///// Draws a single lasso dot with the center at the given point. 78 | ///// 79 | void AddLassoPoint(Point const & lassoPoint); 80 | 81 | //#endregion 82 | 83 | /// TBS 84 | bool Contains(Point const & point); 85 | //#endregion 86 | 87 | //#region Implementation helpers 88 | /// Creates the container visual when needed. 89 | void EnsureVisual(); 90 | 91 | /// 92 | /// Creates and initializes objects required for drawing 93 | /// 94 | void EnsureReady(); 95 | 96 | //#endregion 97 | }; 98 | 99 | INKCANVAS_END_NAMESPACE 100 | 101 | #endif // LASSOHELPER_H 102 | -------------------------------------------------------------------------------- /Internal/Ink/InkSerializedFormat/guidlist.h: -------------------------------------------------------------------------------- 1 | #ifndef GUIDLIST_H 2 | #define GUIDLIST_H 3 | 4 | #include "InkCanvas_global.h" 5 | #include "Internal/Ink/InkSerializedFormat/isftagandguidcache.h" 6 | #include "Collections/Generic/list.h" 7 | #include "guid.h" 8 | 9 | #define OLD_ISF 0 10 | 11 | class QIODevice; 12 | 13 | INKCANVAS_BEGIN_NAMESPACE 14 | 15 | /// 16 | /// Summary description for GuidTagList. 17 | /// 18 | class GuidList 19 | { 20 | private: 21 | List _CustomGuids; 22 | 23 | 24 | public: 25 | static Guid Empty; 26 | 27 | GuidList(); 28 | 29 | /// 30 | /// Adds a guid to the list of Custom Guids if it is not a known guid and is already not 31 | /// in the list of Custom Guids 32 | /// 33 | /// 34 | /// 35 | bool Add(Guid const & guid); 36 | 37 | 38 | /// 39 | /// Finds the tag for a Guid based on the list of Known Guids 40 | /// 41 | /// 42 | /// 43 | static KnownTagCache::KnownTagIndex FindKnownTag(Guid const & guid); 44 | 45 | 46 | /// 47 | /// Finds the tag for a guid based on the list of Custom Guids 48 | /// 49 | /// 50 | /// 51 | KnownTagCache::KnownTagIndex FindCustomTag(Guid const & guid); 52 | 53 | 54 | /// 55 | /// Finds a tag corresponding to a guids 56 | /// 57 | /// 58 | /// 59 | /// 60 | KnownTagCache::KnownTagIndex FindTag(Guid const & guid, bool bFindInKnownListFirst); 61 | 62 | 63 | /// 64 | /// Finds a known guid based on a Tag 65 | /// 66 | /// 67 | /// 68 | static Guid const & FindKnownGuid(KnownTagCache::KnownTagIndex tag); 69 | 70 | 71 | /// 72 | /// Finds a Custom Guid based on a Tag 73 | /// 74 | /// 75 | /// 76 | Guid const & FindCustomGuid(KnownTagCache::KnownTagIndex tag); 77 | 78 | 79 | /// 80 | /// Finds a guid based on Tag 81 | /// 82 | /// 83 | /// 84 | Guid const & FindGuid(KnownTagCache::KnownTagIndex tag); 85 | 86 | 87 | /// 88 | /// Returns the expected size of data if it is a known guid 89 | /// 90 | /// 91 | /// 92 | static quint32 GetDataSizeIfKnownGuid(Guid const & guid); 93 | 94 | /// 95 | /// Serializes the GuidList in the memory stream and returns the size 96 | /// 97 | /// If null, calculates the size only 98 | /// 99 | quint32 Save(QIODevice& stream); 100 | 101 | 102 | /// 103 | /// Deserializes the GuidList from the memory stream 104 | /// 105 | /// 106 | /// 107 | /// 108 | quint32 Load(QIODevice& strm, quint32 size); 109 | }; 110 | 111 | INKCANVAS_END_NAMESPACE 112 | 113 | #endif // GUIDLIST_H 114 | -------------------------------------------------------------------------------- /Windows/Input/pencontexts.cpp: -------------------------------------------------------------------------------- 1 | #include "Windows/Input/pencontexts.h" 2 | #include "Windows/Input/mousedevice.h" 3 | #include "Windows/Input/StylusPlugIns/rawstylusinput.h" 4 | #include "Windows/Input/StylusPlugIns/stylusplugin.h" 5 | #include "Windows/Input/StylusPlugIns/stylusplugincollection.h" 6 | #include "Windows/Input/stylusdevice.h" 7 | #include "Windows/Input/mousedevice.h" 8 | #include "Windows/uielement.h" 9 | #include "Windows/Controls/inkcanvas.h" 10 | 11 | #include 12 | #include 13 | 14 | INKCANVAS_BEGIN_NAMESPACE 15 | 16 | PenContexts::PenContexts(UIElement * element) 17 | : mutex_(QMutex::Recursive) 18 | , element_(element) 19 | { 20 | if (Mouse::PrimaryDevice == nullptr) 21 | Mouse::PrimaryDevice = new MouseDevice; 22 | element->installEventFilter(this); 23 | } 24 | 25 | QMutex& PenContexts::SyncRoot() 26 | { 27 | return mutex_; 28 | } 29 | 30 | void PenContexts::AddStylusPlugInCollection(StylusPlugInCollection* pic) 31 | { 32 | stylusPlugIns_.Add(pic); 33 | } 34 | 35 | void PenContexts::RemoveStylusPlugInCollection(StylusPlugInCollection* pic) 36 | { 37 | stylusPlugIns_.Remove(pic); 38 | } 39 | 40 | void PenContexts::FireCustomData() 41 | { 42 | for (RawStylusInputCustomData & cd : customDatas_) { 43 | cd.Owner->FireCustomData(cd.Data, action_, true); 44 | } 45 | customDatas_.Clear(); 46 | } 47 | 48 | bool PenContexts::eventFilter(QObject *watched, QEvent *event) 49 | { 50 | switch (event->type()) { 51 | case QEvent::TouchBegin: 52 | if (qobject_cast(element_)->ActiveEditingMode() == InkCanvasEditingMode::Ink) { 53 | QSizeF gs = qobject_cast(element_)->property("StylusGroupSize").toSizeF(); 54 | gs = element_->sceneTransform().inverted().mapRect(QRectF({0, 0}, gs)).size(); 55 | Stylus::SetGroupSize(gs); 56 | } else { 57 | Stylus::SetGroupSize(QSizeF()); 58 | } 59 | Q_FALLTHROUGH(); 60 | case QEvent::TouchUpdate: 61 | case QEvent::TouchEnd: 62 | Stylus::SetLastInput(static_cast(*event)); 63 | customDatas_.Clear(); 64 | for (StylusPlugInCollection* pic : stylusPlugIns_) { 65 | RawStylusInput stylusInput(static_cast(*event), transform_, pic); 66 | pic->FireRawStylusInput(stylusInput); 67 | action_ = stylusInput.Actions(); 68 | customDatas_.AddRange(stylusInput.CustomDataList()); 69 | } 70 | break; 71 | case QEvent::GraphicsSceneMousePress: 72 | case QEvent::GraphicsSceneMouseMove: 73 | case QEvent::GraphicsSceneMouseRelease: 74 | Mouse::SetLastInput(static_cast(*event)); 75 | if (!element_->acceptTouchEvents() || 76 | static_cast(*event).source() == Qt::MouseEventNotSynthesized) { 77 | customDatas_.Clear(); 78 | for (StylusPlugInCollection* pic : stylusPlugIns_) { 79 | RawStylusInput stylusInput(static_cast(*event), transform_, pic); 80 | pic->FireRawStylusInput(stylusInput); 81 | action_ = stylusInput.Actions(); 82 | customDatas_.AddRange(stylusInput.CustomDataList()); 83 | } 84 | } 85 | break; 86 | default: 87 | break; 88 | } 89 | return QObject::eventFilter(watched, event); 90 | } 91 | 92 | INKCANVAS_END_NAMESPACE 93 | -------------------------------------------------------------------------------- /Windows/Input/stylusdevice.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWS_INPUT_STYLUSDEVICE_H 2 | #define WINDOWS_INPUT_STYLUSDEVICE_H 3 | 4 | #include "InkCanvas_global.h" 5 | 6 | #include "Windows/Input/inputdevice.h" 7 | #include "Windows/routedeventargs.h" 8 | #include "Windows/point.h" 9 | #include "sharedptr.h" 10 | 11 | #include 12 | #include 13 | 14 | class QTouchDevice; 15 | class QTouchEvent; 16 | class QInputEvent; 17 | 18 | INKCANVAS_BEGIN_NAMESPACE 19 | 20 | class StylusPointCollection; 21 | class StylusPointDescription; 22 | 23 | class StylusDevice; 24 | class Visual; 25 | 26 | class StylusEvent : public RoutedEvent 27 | { 28 | public: 29 | StylusEvent(int type, int type2); 30 | virtual void handle(QEvent &event, QList handlers) override; 31 | virtual void handle2(QEvent &event, QList handlers) override; 32 | }; 33 | 34 | class StylusPointPropertyInfo; 35 | 36 | class INKCANVAS_EXPORT Stylus 37 | { 38 | public: 39 | static StylusDevice* CurrentStylusDevice(); 40 | 41 | static StylusDevice* GetDevice(QTouchDevice* device); 42 | 43 | static StylusDevice* GetDevice(int id); 44 | 45 | static void SetGroupSize(QSizeF const & size); 46 | 47 | static QSizeF GetGroupSize(); 48 | 49 | static void SetLastInput(QTouchEvent& input); 50 | 51 | static SharedPointer DefaultPointDescription(); 52 | 53 | static StylusEvent StylusDownEvent; 54 | 55 | static StylusEvent StylusMoveEvent; 56 | 57 | static StylusEvent StylusUpEvent; 58 | 59 | static StylusPointPropertyInfo StylusPointIdPropertyInfo; 60 | 61 | static StylusDevice* CurrentDevice; 62 | 63 | private: 64 | static QMap devices_; 65 | static QSizeF groupSize_; 66 | }; 67 | 68 | class StylusGroup { 69 | public: 70 | int groupId = 0; 71 | QRectF bound; 72 | QVector allPointIds; 73 | QVector pointIds; 74 | QVector newPointIds; 75 | }; 76 | 77 | class INKCANVAS_EXPORT StylusDevice : public InputDevice 78 | { 79 | Q_OBJECT 80 | public: 81 | StylusDevice(QTouchDevice * device, int id); 82 | 83 | void SetLastPoints(QList const & points, bool reset); 84 | 85 | virtual int Id() override; 86 | 87 | bool InAir(); 88 | 89 | bool Inverted(); 90 | 91 | Point GetPosition(Visual* relativeTo); 92 | 93 | SharedPointer GetStylusPoints(Visual * visual); 94 | 95 | SharedPointer GetStylusPoints(Visual * visual, SharedPointer description); 96 | 97 | UIElement* Captured(); 98 | 99 | virtual UIElement* Target() override; 100 | 101 | virtual PresentationSource* ActiveSource() override; 102 | 103 | virtual SharedPointer PointDescription() override; 104 | 105 | virtual Array PacketData(QEvent& event) override; 106 | 107 | QMap const & StylusGroups() { return lastGroups_; } 108 | 109 | QTouchDevice * device() const { return device_; } 110 | 111 | private: 112 | int id_; 113 | QTouchDevice * device_; 114 | SharedPointer description_; 115 | QList lastPoints_; 116 | QMap lastGroups_; 117 | QMap groupMap_; 118 | }; 119 | 120 | INKCANVAS_END_NAMESPACE 121 | 122 | #endif // WINDOWS_INPUT_STYLUSDEVICE_H 123 | --------------------------------------------------------------------------------