diff --git a/Clip2D/.vscode/launch.json b/Clip2D/.vscode/launch.json
new file mode 100644
index 0000000..850ce87
--- /dev/null
+++ b/Clip2D/.vscode/launch.json
@@ -0,0 +1,16 @@
+{
+ "configurations": [
+ {
+ "name": "Visual Studio: Start Debugging",
+ "type": "cppvsdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}\\x64\\Debug\\${workspaceFolderBasename}.exe",
+ "stopAtEntry": false,
+ "cwd": "${workspaceFolder}",
+ "console": "integratedTerminal",
+ "preLaunchTask": "Visual Studio: Build Solution",
+ "internalConsoleOptions": "neverOpen"
+ }
+ ],
+ "version": "0.2.0"
+}
\ No newline at end of file
diff --git a/Clip2D/.vscode/settings.json b/Clip2D/.vscode/settings.json
new file mode 100644
index 0000000..d47ab15
--- /dev/null
+++ b/Clip2D/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "git.openRepositoryInParentFolders": "never"
+}
\ No newline at end of file
diff --git a/Clip2D/.vscode/tasks.json b/Clip2D/.vscode/tasks.json
new file mode 100644
index 0000000..6e0a647
--- /dev/null
+++ b/Clip2D/.vscode/tasks.json
@@ -0,0 +1,23 @@
+{
+ "tasks": [
+ {
+ "type": "shell",
+ "label": "Visual Studio: Build Solution",
+ "command": "msbuild",
+ "args": [
+ "${workspaceFolder}\\${workspaceFolderBasename}.sln",
+ "/p:Configuration=Debug",
+ "/p:Platform=x64"
+ ],
+ "options": {
+ "cwd": "${workspaceFolder}"
+ },
+ "problemMatcher": [
+ "$msCompile"
+ ],
+ "group": "build",
+ "detail": "Task generated by Debugger."
+ }
+ ],
+ "version": "2.0.0"
+}
\ No newline at end of file
diff --git a/Clip2D/Clip2D.sln b/Clip2D/Clip2D.sln
new file mode 100644
index 0000000..429480d
--- /dev/null
+++ b/Clip2D/Clip2D.sln
@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.11.35327.3
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Clip2D", "Clip2D\Clip2D.vcxproj", "{EC5E118A-9177-477E-B3BA-626132771FD7}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Debug|x64.ActiveCfg = Debug|x64
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Debug|x64.Build.0 = Debug|x64
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Debug|x86.ActiveCfg = Debug|Win32
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Debug|x86.Build.0 = Debug|Win32
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Release|x64.ActiveCfg = Release|x64
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Release|x64.Build.0 = Release|x64
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Release|x86.ActiveCfg = Release|Win32
+ {EC5E118A-9177-477E-B3BA-626132771FD7}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {5DC2FE4C-9EDC-4A37-B388-F654C87D94E0}
+ EndGlobalSection
+EndGlobal
diff --git a/Clip2D/Clip2D/Clip2D.aps b/Clip2D/Clip2D/Clip2D.aps
new file mode 100644
index 0000000..61a3867
Binary files /dev/null and b/Clip2D/Clip2D/Clip2D.aps differ
diff --git a/Clip2D/Clip2D/Clip2D.cpp b/Clip2D/Clip2D/Clip2D.cpp
new file mode 100644
index 0000000..aa80715
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2D.cpp
@@ -0,0 +1,184 @@
+
+// Clip2D.cpp : Defines the class behaviors for the application.
+//
+
+#include "pch.h"
+#include "framework.h"
+#include "afxwinappex.h"
+#include "afxdialogex.h"
+#include "Clip2D.h"
+#include "MainFrm.h"
+
+#include "Clip2DDoc.h"
+#include "Clip2DView.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+
+// CClip2DApp
+
+BEGIN_MESSAGE_MAP(CClip2DApp, CWinApp)
+ ON_COMMAND(ID_APP_ABOUT, &CClip2DApp::OnAppAbout)
+ // Standard file based document commands
+ ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
+ ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
+ // Standard print setup command
+ ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinApp::OnFilePrintSetup)
+END_MESSAGE_MAP()
+
+
+// CClip2DApp construction
+
+CClip2DApp::CClip2DApp() noexcept
+{
+
+ // support Restart Manager
+ m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
+#ifdef _MANAGED
+ // If the application is built using Common Language Runtime support (/clr):
+ // 1) This additional setting is needed for Restart Manager support to work properly.
+ // 2) In your project, you must add a reference to System.Windows.Forms in order to build.
+ System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException);
+#endif
+
+ // TODO: replace application ID string below with unique ID string; recommended
+ // format for string is CompanyName.ProductName.SubProduct.VersionInformation
+ SetAppID(_T("Clip2D.AppID.NoVersion"));
+
+ // TODO: add construction code here,
+ // Place all significant initialization in InitInstance
+}
+
+// The one and only CClip2DApp object
+
+CClip2DApp theApp;
+
+
+// CClip2DApp initialization
+
+BOOL CClip2DApp::InitInstance()
+{
+ // InitCommonControlsEx() is required on Windows XP if an application
+ // manifest specifies use of ComCtl32.dll version 6 or later to enable
+ // visual styles. Otherwise, any window creation will fail.
+ INITCOMMONCONTROLSEX InitCtrls;
+ InitCtrls.dwSize = sizeof(InitCtrls);
+ // Set this to include all the common control classes you want to use
+ // in your application.
+ InitCtrls.dwICC = ICC_WIN95_CLASSES;
+ InitCommonControlsEx(&InitCtrls);
+
+ CWinApp::InitInstance();
+
+
+ // Initialize OLE libraries
+ if (!AfxOleInit())
+ {
+ AfxMessageBox(IDP_OLE_INIT_FAILED);
+ return FALSE;
+ }
+
+ AfxEnableControlContainer();
+
+ EnableTaskbarInteraction(FALSE);
+
+ // AfxInitRichEdit2() is required to use RichEdit control
+ // AfxInitRichEdit2();
+
+ // Standard initialization
+ // If you are not using these features and wish to reduce the size
+ // of your final executable, you should remove from the following
+ // the specific initialization routines you do not need
+ // Change the registry key under which our settings are stored
+ // TODO: You should modify this string to be something appropriate
+ // such as the name of your company or organization
+ SetRegistryKey(_T("Local AppWizard-Generated Applications"));
+ LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
+
+
+ // Register the application's document templates. Document templates
+ // serve as the connection between documents, frame windows and views
+ CSingleDocTemplate* pDocTemplate;
+ pDocTemplate = new CSingleDocTemplate(
+ IDR_MAINFRAME,
+ RUNTIME_CLASS(CClip2DDoc),
+ RUNTIME_CLASS(CMainFrame), // main SDI frame window
+ RUNTIME_CLASS(CClip2DView));
+ if (!pDocTemplate)
+ return FALSE;
+ AddDocTemplate(pDocTemplate);
+
+
+ // Parse command line for standard shell commands, DDE, file open
+ CCommandLineInfo cmdInfo;
+ ParseCommandLine(cmdInfo);
+
+
+
+ // Dispatch commands specified on the command line. Will return FALSE if
+ // app was launched with /RegServer, /Register, /Unregserver or /Unregister.
+ if (!ProcessShellCommand(cmdInfo))
+ return FALSE;
+
+ // The one and only window has been initialized, so show and update it
+ m_pMainWnd->ShowWindow(SW_SHOW);
+ m_pMainWnd->UpdateWindow();
+ return TRUE;
+}
+
+int CClip2DApp::ExitInstance()
+{
+ //TODO: handle additional resources you may have added
+ AfxOleTerm(FALSE);
+
+ return CWinApp::ExitInstance();
+}
+
+// CClip2DApp message handlers
+
+
+// CAboutDlg dialog used for App About
+
+class CAboutDlg : public CDialogEx
+{
+public:
+ CAboutDlg() noexcept;
+
+// Dialog Data
+#ifdef AFX_DESIGN_TIME
+ enum { IDD = IDD_ABOUTBOX };
+#endif
+
+protected:
+ virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
+
+// Implementation
+protected:
+ DECLARE_MESSAGE_MAP()
+};
+
+CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX)
+{
+}
+
+void CAboutDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+}
+
+BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
+END_MESSAGE_MAP()
+
+// App command to run the dialog
+void CClip2DApp::OnAppAbout()
+{
+ CAboutDlg aboutDlg;
+ aboutDlg.DoModal();
+}
+
+// CClip2DApp message handlers
+
+
+
diff --git a/Clip2D/Clip2D/Clip2D.h b/Clip2D/Clip2D/Clip2D.h
new file mode 100644
index 0000000..b833f19
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2D.h
@@ -0,0 +1,33 @@
+
+// Clip2D.h : main header file for the Clip2D application
+//
+#pragma once
+
+#ifndef __AFXWIN_H__
+ #error "include 'pch.h' before including this file for PCH"
+#endif
+
+#include "resource.h" // main symbols
+
+
+// CClip2DApp:
+// See Clip2D.cpp for the implementation of this class
+//
+
+class CClip2DApp : public CWinApp
+{
+public:
+ CClip2DApp() noexcept;
+
+
+// Overrides
+public:
+ virtual BOOL InitInstance();
+ virtual int ExitInstance();
+
+// Implementation
+ afx_msg void OnAppAbout();
+ DECLARE_MESSAGE_MAP()
+};
+
+extern CClip2DApp theApp;
diff --git a/Clip2D/Clip2D/Clip2D.rc b/Clip2D/Clip2D/Clip2D.rc
new file mode 100644
index 0000000..3982028
Binary files /dev/null and b/Clip2D/Clip2D/Clip2D.rc differ
diff --git a/Clip2D/Clip2D/Clip2D.vcxproj b/Clip2D/Clip2D/Clip2D.vcxproj
new file mode 100644
index 0000000..c54106c
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2D.vcxproj
@@ -0,0 +1,223 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 17.0
+ {EC5E118A-9177-477E-B3BA-626132771FD7}
+ MFCProj
+ Clip2D
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+ Dynamic
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+ Dynamic
+
+
+ Application
+ true
+ v143
+ Unicode
+ Dynamic
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+ Dynamic
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+ Use
+ Level3
+ true
+ _WINDOWS;_DEBUG;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Windows
+
+
+ false
+ true
+ _DEBUG;%(PreprocessorDefinitions)
+
+
+ 0x0409
+ _DEBUG;%(PreprocessorDefinitions)
+ $(IntDir);%(AdditionalIncludeDirectories)
+
+
+
+
+ Use
+ Level3
+ true
+ WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Windows
+
+
+ false
+ true
+ _DEBUG;%(PreprocessorDefinitions)
+
+
+ 0x0409
+ _DEBUG;%(PreprocessorDefinitions)
+ $(IntDir);%(AdditionalIncludeDirectories)
+
+
+
+
+ Use
+ Level3
+ true
+ true
+ true
+ WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Windows
+ true
+ true
+
+
+ false
+ true
+ NDEBUG;%(PreprocessorDefinitions)
+
+
+ 0x0409
+ NDEBUG;%(PreprocessorDefinitions)
+ $(IntDir);%(AdditionalIncludeDirectories)
+
+
+
+
+ Use
+ Level3
+ true
+ true
+ true
+ _WINDOWS;NDEBUG;%(PreprocessorDefinitions)
+ pch.h
+
+
+ Windows
+ true
+ true
+
+
+ false
+ true
+ NDEBUG;%(PreprocessorDefinitions)
+
+
+ 0x0409
+ NDEBUG;%(PreprocessorDefinitions)
+ $(IntDir);%(AdditionalIncludeDirectories)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Create
+ Create
+ Create
+ Create
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Clip2D/Clip2D/Clip2D.vcxproj.filters b/Clip2D/Clip2D/Clip2D.vcxproj.filters
new file mode 100644
index 0000000..f350e92
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2D.vcxproj.filters
@@ -0,0 +1,87 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Resource Files
+
+
+
+
+ Resource Files
+
+
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+ Resource Files
+
+
+
\ No newline at end of file
diff --git a/Clip2D/Clip2D/Clip2D.vcxproj.user b/Clip2D/Clip2D/Clip2D.vcxproj.user
new file mode 100644
index 0000000..21b6804
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2D.vcxproj.user
@@ -0,0 +1,6 @@
+
+
+
+ Clip2D.rc
+
+
\ No newline at end of file
diff --git a/Clip2D/Clip2D/Clip2DDoc.cpp b/Clip2D/Clip2D/Clip2DDoc.cpp
new file mode 100644
index 0000000..52f8a56
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2DDoc.cpp
@@ -0,0 +1,138 @@
+
+// Clip2DDoc.cpp : implementation of the CClip2DDoc class
+//
+
+#include "pch.h"
+#include "framework.h"
+// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
+// and search filter handlers and allows sharing of document code with that project.
+#ifndef SHARED_HANDLERS
+#include "Clip2D.h"
+#endif
+
+#include "Clip2DDoc.h"
+
+#include
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+// CClip2DDoc
+
+IMPLEMENT_DYNCREATE(CClip2DDoc, CDocument)
+
+BEGIN_MESSAGE_MAP(CClip2DDoc, CDocument)
+END_MESSAGE_MAP()
+
+
+// CClip2DDoc construction/destruction
+
+CClip2DDoc::CClip2DDoc() noexcept
+{
+ // TODO: add one-time construction code here
+
+}
+
+CClip2DDoc::~CClip2DDoc()
+{
+}
+
+BOOL CClip2DDoc::OnNewDocument()
+{
+ if (!CDocument::OnNewDocument())
+ return FALSE;
+
+ // TODO: add reinitialization code here
+ // (SDI documents will reuse this document)
+
+ return TRUE;
+}
+
+
+
+
+// CClip2DDoc serialization
+
+void CClip2DDoc::Serialize(CArchive& ar)
+{
+ if (ar.IsStoring())
+ {
+ // TODO: add storing code here
+ }
+ else
+ {
+ // TODO: add loading code here
+ }
+}
+
+#ifdef SHARED_HANDLERS
+
+// Support for thumbnails
+void CClip2DDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
+{
+ // Modify this code to draw the document's data
+ dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
+
+ CString strText = _T("TODO: implement thumbnail drawing here");
+ LOGFONT lf;
+
+ CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
+ pDefaultGUIFont->GetLogFont(&lf);
+ lf.lfHeight = 36;
+
+ CFont fontDraw;
+ fontDraw.CreateFontIndirect(&lf);
+
+ CFont* pOldFont = dc.SelectObject(&fontDraw);
+ dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
+ dc.SelectObject(pOldFont);
+}
+
+// Support for Search Handlers
+void CClip2DDoc::InitializeSearchContent()
+{
+ CString strSearchContent;
+ // Set search contents from document's data.
+ // The content parts should be separated by ";"
+
+ // For example: strSearchContent = _T("point;rectangle;circle;ole object;");
+ SetSearchContent(strSearchContent);
+}
+
+void CClip2DDoc::SetSearchContent(const CString& value)
+{
+ if (value.IsEmpty())
+ {
+ RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
+ }
+ else
+ {
+ CMFCFilterChunkValueImpl *pChunk = nullptr;
+ ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
+ if (pChunk != nullptr)
+ {
+ pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
+ SetChunkValue(pChunk);
+ }
+ }
+}
+
+#endif // SHARED_HANDLERS
+
+// CClip2DDoc diagnostics
+
+#ifdef _DEBUG
+void CClip2DDoc::AssertValid() const
+{
+ CDocument::AssertValid();
+}
+
+void CClip2DDoc::Dump(CDumpContext& dc) const
+{
+ CDocument::Dump(dc);
+}
+#endif //_DEBUG
+
+
+// CClip2DDoc commands
diff --git a/Clip2D/Clip2D/Clip2DDoc.h b/Clip2D/Clip2D/Clip2DDoc.h
new file mode 100644
index 0000000..fb56bf0
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2DDoc.h
@@ -0,0 +1,48 @@
+
+// Clip2DDoc.h : interface of the CClip2DDoc class
+//
+
+
+#pragma once
+
+
+class CClip2DDoc : public CDocument
+{
+protected: // create from serialization only
+ CClip2DDoc() noexcept;
+ DECLARE_DYNCREATE(CClip2DDoc)
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+public:
+ virtual BOOL OnNewDocument();
+ virtual void Serialize(CArchive& ar);
+#ifdef SHARED_HANDLERS
+ virtual void InitializeSearchContent();
+ virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
+#endif // SHARED_HANDLERS
+
+// Implementation
+public:
+ virtual ~CClip2DDoc();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext& dc) const;
+#endif
+
+protected:
+
+// Generated message map functions
+protected:
+ DECLARE_MESSAGE_MAP()
+
+#ifdef SHARED_HANDLERS
+ // Helper function that sets search content for a Search Handler
+ void SetSearchContent(const CString& value);
+#endif // SHARED_HANDLERS
+};
diff --git a/Clip2D/Clip2D/Clip2DView.cpp b/Clip2D/Clip2D/Clip2DView.cpp
new file mode 100644
index 0000000..73e442b
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2DView.cpp
@@ -0,0 +1,283 @@
+
+// Clip2DView.cpp : implementation of the CClip2DView class
+//
+
+#include "pch.h"
+#include "framework.h"
+// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
+// and search filter handlers and allows sharing of document code with that project.
+#ifndef SHARED_HANDLERS
+#include "Clip2D.h"
+#endif
+
+#include "Clip2DDoc.h"
+#include "Clip2DView.h"
+
+#define Round(x) ((int)(x + 0.5))
+#define PI 3.1415926
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+// CClip2DView
+
+IMPLEMENT_DYNCREATE(CClip2DView, CView)
+
+BEGIN_MESSAGE_MAP(CClip2DView, CView)
+ON_WM_MOUSEMOVE()
+ON_WM_ERASEBKGND()
+ON_WM_LBUTTONDOWN()
+ON_WM_RBUTTONDOWN()
+// Standard printing commands
+ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
+ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
+ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
+END_MESSAGE_MAP()
+
+// CClip2DView construction/destruction
+
+CClip2DView::CClip2DView() noexcept {
+ // TODO: add construction code here
+ nRHWidth = 100;
+ nRHHeight = 100;
+ nScale = 2;
+}
+
+CClip2DView::~CClip2DView() {
+}
+
+BOOL CClip2DView::PreCreateWindow(CREATESTRUCT &cs) {
+ // TODO: Modify the Window class or styles here by modifying
+ // the CREATESTRUCT cs
+
+ return CView::PreCreateWindow(cs);
+}
+
+// CClip2DView drawing
+
+void CClip2DView::OnDraw(CDC * /*pDC*/) {
+ CClip2DDoc *pDoc = GetDocument();
+ ASSERT_VALID(pDoc);
+ if (!pDoc)
+ return;
+
+ // TODO: add draw code for native data here
+ DoubleBuffer();
+}
+
+// CClip2DView printing
+
+BOOL CClip2DView::OnPreparePrinting(CPrintInfo *pInfo) {
+ // default preparation
+ return DoPreparePrinting(pInfo);
+}
+
+void CClip2DView::OnBeginPrinting(CDC * /*pDC*/, CPrintInfo * /*pInfo*/) {
+ // TODO: add extra initialization before printing
+}
+
+void CClip2DView::OnEndPrinting(CDC * /*pDC*/, CPrintInfo * /*pInfo*/) {
+ // TODO: add cleanup after printing
+}
+
+// CClip2DView diagnostics
+
+#ifdef _DEBUG
+void CClip2DView::AssertValid() const {
+ CView::AssertValid();
+}
+
+void CClip2DView::Dump(CDumpContext &dc) const {
+ CView::Dump(dc);
+}
+
+CClip2DDoc *CClip2DView::GetDocument() const // non-debug version is inline
+{
+ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClip2DDoc)));
+ return (CClip2DDoc *)m_pDocument;
+}
+#endif //_DEBUG
+
+void CClip2DView::DoubleBuffer() {
+ CRect rect;
+ GetClientRect(&rect);
+ CDC *pDC = GetDC();
+ pDC->SetMapMode(MM_ANISOTROPIC);
+ pDC->SetWindowExt(rect.Width(), rect.Height());
+ pDC->SetViewportExt(rect.Width(), -rect.Height());
+ pDC->SetViewportOrg(rect.Width() / 2, rect.Height() / 2);
+ CDC MemDC;
+ CBitmap NewBitmap, *pOldBitmap;
+ MemDC.CreateCompatibleDC(pDC);
+ NewBitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
+ pOldBitmap = MemDC.SelectObject(&NewBitmap);
+ MemDC.FillSolidRect(&rect, pDC->GetBkColor());
+ MemDC.SetMapMode(MM_ANISOTROPIC);
+ MemDC.SetWindowExt(rect.Width(), rect.Height());
+ MemDC.SetViewportExt(rect.Width(), -rect.Height());
+ MemDC.SetViewportOrg(rect.Width() / 2, rect.Height() / 2);
+
+ Diamond(&MemDC, FALSE);
+ DrawRect(&MemDC, nScale);
+ Diamond(&MemDC, TRUE);
+
+ pDC->BitBlt(-rect.Width() / 2, -rect.Height() / 2, rect.Width(), rect.Height(), &MemDC, -rect.Width() / 2, -rect.Height() / 2, SRCCOPY);
+ MemDC.SelectObject(pOldBitmap);
+ NewBitmap.DeleteObject();
+ ReleaseDC(pDC);
+}
+
+void CClip2DView::DrawRect(CDC *pDC, int nScale) {
+ pDC->Rectangle(Round(nRCenter.x - nRHWidth), Round(nRCenter.y + nRHHeight),
+ Round(nRCenter.x + nRHWidth), Round(nRCenter.y - nRHHeight));
+}
+
+void CClip2DView::OnMouseMove(UINT nFlags, CPoint point) {
+ // TODO: Add your message handler code here and/or call default
+ nRCenter = Convert(point);
+ Invalidate(FALSE);
+ CView::OnMouseMove(nFlags, point);
+}
+
+BOOL CClip2DView::LBLineClip() {
+ double tmax, tmin, dx, dy;
+ dx = P[1].x - P[0].x;
+ dy = P[1].y - P[0].y;
+ tmax = 0.0, tmin = 1.0;
+ double wxl = nRCenter.x - nRHWidth / nScale;
+ double wxr = nRCenter.x + nRHWidth / nScale;
+ double wyb = nRCenter.y - nRHHeight / nScale;
+ double wyt = nRCenter.y + nRHHeight / nScale;
+ if (ClipTest(-dx, P[0].x - wxl, tmax, tmin)) {
+ if (ClipTest(dx, wxr - P[0].x, tmax, tmin)) {
+ if (ClipTest(-dy, P[0].y - wyb, tmax, tmin)) {
+ if (ClipTest(dy, wyt - P[0].y, tmax, tmin)) {
+ if (tmin < 1.0) {
+ P[1].x = P[0].x + tmin * dx;
+ P[1].y = P[0].y + tmin * dy;
+ }
+ if (tmax > 0.0) {
+ P[0].x = P[0].x + tmax * dx;
+ P[0].y = P[0].y + tmax * dy;
+ }
+ return TRUE;
+ }
+ }
+ }
+ }
+ return FALSE;
+}
+
+BOOL CClip2DView::ClipTest(double u, double v, double &tmax, double &tmin) {
+ double t;
+ BOOL ReturnValue = TRUE;
+ if (u < 0.0) {
+ t = v / u;
+ if (t > tmin)
+ ReturnValue = FALSE;
+ else if (t > tmax)
+ tmax = t;
+ }
+ else {
+ if (u > 0.0) {
+ t = v / u;
+ if (t < tmax)
+ ReturnValue = FALSE;
+ else if (t < tmin)
+ tmin = t;
+ }
+ else {
+ if (v < 0.0)
+ ReturnValue = FALSE;
+ }
+ }
+ return (ReturnValue);
+}
+
+CP2 CClip2DView::Convert(CPoint point) {
+ CRect rect;
+ GetClientRect(&rect);
+ CP2 ptemp;
+ ptemp.x = point.x - rect.Width() / 2;
+ ptemp.y = rect.Height() / 2 - point.y;
+ return ptemp;
+}
+
+BOOL CClip2DView::OnEraseBkgnd(CDC *pDC) {
+ // TODO: Add your message handler code here and/or call default
+ return TRUE;
+}
+
+void CClip2DView::Diamond(CDC *pDC, BOOL bclip) {
+ CPen NewPen, *pOldPen;
+ if (bclip)
+ NewPen.CreatePen(PS_SOLID, nScale, RGB(0, 0, 0));
+ else
+ NewPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
+ pOldPen = pDC->SelectObject(&NewPen);
+ int numHexagons = 30;
+ double baseRadius = 10;
+ double rotationAngle = -PI / 196;
+
+ for (int h = 0; h < numHexagons; h++) {
+ double r = baseRadius * (h + 1);
+ int n = 6;
+ V = new CP2[n];
+ double thta = 2 * PI / n;
+
+ for (int i = 0; i < n; i++) {
+ double angle = i * thta + h * rotationAngle;
+ V[i].x = r * cos(angle);
+ V[i].y = r * sin(angle);
+ }
+
+ for (int i = 0; i < n; i++) {
+ int j = (i + 1) % n;
+ if (!bclip) {
+ pDC->MoveTo(Round(V[i].x), Round(V[i].y));
+ pDC->LineTo(Round(V[j].x), Round(V[j].y));
+ }
+ else {
+ P[0] = V[i];
+ P[1] = V[j];
+ if (LBLineClip()) {
+ pDC->MoveTo(ZoomX(Round(P[0].x)), ZoomY(Round(P[0].y)));
+ pDC->LineTo(ZoomX(Round(P[1].x)), ZoomY(Round(P[1].y)));
+ }
+ }
+ }
+
+ delete[] V;
+ }
+ pDC->SelectObject(pOldPen);
+ NewPen.DeleteObject();
+}
+
+int CClip2DView::ZoomX(int x) {
+ return Round((x - nRCenter.x) * nScale + nRCenter.x);
+}
+
+int CClip2DView::ZoomY(int y) {
+ return Round((y - nRCenter.y) * nScale + nRCenter.y);
+}
+
+void CClip2DView::OnLButtonDown(UINT nFlags, CPoint point) {
+ // TODO: Add your message handler code here and/or call default
+ if (nScale <= 5)
+ nScale = nScale + 1;
+ else
+ MessageBox(_T("The magnification is too large"));
+ Invalidate(FALSE);
+ CView::OnLButtonDown(nFlags, point);
+}
+
+void CClip2DView::OnRButtonDown(UINT nFlags, CPoint point) {
+ // TODO: Add your message handler code here and/or call default
+ if (nScale >= 2)
+ nScale = nScale - 1;
+ else
+ MessageBox(_T("The magnification is too small"));
+ Invalidate(FALSE);
+ CView::OnRButtonDown(nFlags, point);
+}
diff --git a/Clip2D/Clip2D/Clip2DView.h b/Clip2D/Clip2D/Clip2DView.h
new file mode 100644
index 0000000..fbca3fb
--- /dev/null
+++ b/Clip2D/Clip2D/Clip2DView.h
@@ -0,0 +1,64 @@
+
+// Clip2DView.h : interface of the CClip2DView class
+//
+
+#pragma once
+
+#include "P2.h"
+
+class CClip2DView : public CView {
+protected: // create from serialization only
+ CClip2DView() noexcept;
+ DECLARE_DYNCREATE(CClip2DView)
+
+ // Attributes
+public:
+ CClip2DDoc *GetDocument() const;
+
+ // Operations
+public:
+ void DoubleBuffer();
+ void DrawRect(CDC *pDC, int nscale);
+ CP2 Convert(CPoint point);
+ void Diamond(CDC *pDC, BOOL bClip);
+ int ZoomX(int x);
+ int ZoomY(int y);
+ BOOL LBLineClip();
+ BOOL ClipTest(double, double, double &, double &);
+
+ // Overrides
+public:
+ virtual void OnDraw(CDC *pDC); // overridden to draw this view
+ virtual BOOL PreCreateWindow(CREATESTRUCT &cs);
+
+protected:
+ virtual BOOL OnPreparePrinting(CPrintInfo *pInfo);
+ virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
+ virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
+
+ // Implementation
+public:
+ virtual ~CClip2DView();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext &dc) const;
+#endif
+
+protected:
+ CP2 P[2];
+ CP2 *V;
+ UINT nScale;
+ CP2 nRCenter;
+ double nRHHeight, nRHWidth;
+
+protected:
+ afx_msg void OnMouseMove(UINT nFlags, CPoint point);
+ afx_msg BOOL OnEraseBkgnd(CDC *pDC);
+ afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
+ afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
+ DECLARE_MESSAGE_MAP()
+};
+
+#ifndef _DEBUG // debug version in Clip2DView.cpp
+inline CClip2DDoc *CClip2DView::GetDocument() const { return reinterpret_cast(m_pDocument); }
+#endif
diff --git a/Clip2D/Clip2D/MainFrm.cpp b/Clip2D/Clip2D/MainFrm.cpp
new file mode 100644
index 0000000..798e6f9
--- /dev/null
+++ b/Clip2D/Clip2D/MainFrm.cpp
@@ -0,0 +1,96 @@
+
+// MainFrm.cpp : implementation of the CMainFrame class
+//
+
+#include "pch.h"
+#include "framework.h"
+#include "Clip2D.h"
+
+#include "MainFrm.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#endif
+
+// CMainFrame
+
+IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
+
+BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
+ ON_WM_CREATE()
+END_MESSAGE_MAP()
+
+static UINT indicators[] =
+{
+ ID_SEPARATOR, // status line indicator
+ ID_INDICATOR_CAPS,
+ ID_INDICATOR_NUM,
+ ID_INDICATOR_SCRL,
+};
+
+// CMainFrame construction/destruction
+
+CMainFrame::CMainFrame() noexcept
+{
+ // TODO: add member initialization code here
+}
+
+CMainFrame::~CMainFrame()
+{
+}
+
+int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
+{
+ if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
+ return -1;
+
+ if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
+ !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
+ {
+ TRACE0("Failed to create toolbar\n");
+ return -1; // fail to create
+ }
+
+ if (!m_wndStatusBar.Create(this))
+ {
+ TRACE0("Failed to create status bar\n");
+ return -1; // fail to create
+ }
+ m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
+
+ // TODO: Delete these three lines if you don't want the toolbar to be dockable
+ m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
+ EnableDocking(CBRS_ALIGN_ANY);
+ DockControlBar(&m_wndToolBar);
+
+
+ return 0;
+}
+
+BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
+{
+ if( !CFrameWnd::PreCreateWindow(cs) )
+ return FALSE;
+ // TODO: Modify the Window class or styles here by modifying
+ // the CREATESTRUCT cs
+
+ return TRUE;
+}
+
+// CMainFrame diagnostics
+
+#ifdef _DEBUG
+void CMainFrame::AssertValid() const
+{
+ CFrameWnd::AssertValid();
+}
+
+void CMainFrame::Dump(CDumpContext& dc) const
+{
+ CFrameWnd::Dump(dc);
+}
+#endif //_DEBUG
+
+
+// CMainFrame message handlers
+
diff --git a/Clip2D/Clip2D/MainFrm.h b/Clip2D/Clip2D/MainFrm.h
new file mode 100644
index 0000000..976d34b
--- /dev/null
+++ b/Clip2D/Clip2D/MainFrm.h
@@ -0,0 +1,43 @@
+
+// MainFrm.h : interface of the CMainFrame class
+//
+
+#pragma once
+
+class CMainFrame : public CFrameWnd
+{
+
+protected: // create from serialization only
+ CMainFrame() noexcept;
+ DECLARE_DYNCREATE(CMainFrame)
+
+// Attributes
+public:
+
+// Operations
+public:
+
+// Overrides
+public:
+ virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
+
+// Implementation
+public:
+ virtual ~CMainFrame();
+#ifdef _DEBUG
+ virtual void AssertValid() const;
+ virtual void Dump(CDumpContext& dc) const;
+#endif
+
+protected: // control bar embedded members
+ CToolBar m_wndToolBar;
+ CStatusBar m_wndStatusBar;
+
+// Generated message map functions
+protected:
+ afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
+ DECLARE_MESSAGE_MAP()
+
+};
+
+
diff --git a/Clip2D/Clip2D/P2.cpp b/Clip2D/Clip2D/P2.cpp
new file mode 100644
index 0000000..44d1fc6
--- /dev/null
+++ b/Clip2D/Clip2D/P2.cpp
@@ -0,0 +1,8 @@
+#include "pch.h"
+#include "P2.h"
+
+CP2::CP2() {
+}
+
+CP2::~CP2() {
+}
diff --git a/Clip2D/Clip2D/P2.h b/Clip2D/Clip2D/P2.h
new file mode 100644
index 0000000..cf8f059
--- /dev/null
+++ b/Clip2D/Clip2D/P2.h
@@ -0,0 +1,8 @@
+#pragma once
+class CP2 {
+public:
+ CP2();
+ virtual ~CP2();
+ double x, y;
+ UINT rc;
+};
diff --git a/Clip2D/Clip2D/Resource.h b/Clip2D/Clip2D/Resource.h
new file mode 100644
index 0000000..fcbeab7
--- /dev/null
+++ b/Clip2D/Clip2D/Resource.h
@@ -0,0 +1,19 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by Clip2D.rc
+//
+#define IDD_ABOUTBOX 100
+#define IDP_OLE_INIT_FAILED 100
+#define IDR_MAINFRAME 128
+#define IDR_Clip2DTYPE 130
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 310
+#define _APS_NEXT_CONTROL_VALUE 1000
+#define _APS_NEXT_SYMED_VALUE 310
+#define _APS_NEXT_COMMAND_VALUE 32771
+#endif
+#endif
diff --git a/Clip2D/Clip2D/framework.h b/Clip2D/Clip2D/framework.h
new file mode 100644
index 0000000..36afc12
--- /dev/null
+++ b/Clip2D/Clip2D/framework.h
@@ -0,0 +1,49 @@
+#pragma once
+
+#ifndef VC_EXTRALEAN
+#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
+#endif
+
+#include "targetver.h"
+
+#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
+
+// turns off MFC's hiding of some common and often safely ignored warning messages
+#define _AFX_ALL_WARNINGS
+
+#include // MFC core and standard components
+#include // MFC extensions
+
+
+#include // MFC Automation classes
+
+
+
+#ifndef _AFX_NO_OLE_SUPPORT
+#include // MFC support for Internet Explorer 4 Common Controls
+#endif
+#ifndef _AFX_NO_AFXCMN_SUPPORT
+#include // MFC support for Windows Common Controls
+#endif // _AFX_NO_AFXCMN_SUPPORT
+
+#include // MFC support for ribbons and control bars
+
+
+
+
+
+
+
+
+
+#ifdef _UNICODE
+#if defined _M_IX86
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#elif defined _M_X64
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#else
+#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
+#endif
+#endif
+
+
diff --git a/Clip2D/Clip2D/pch.cpp b/Clip2D/Clip2D/pch.cpp
new file mode 100644
index 0000000..64b7eef
--- /dev/null
+++ b/Clip2D/Clip2D/pch.cpp
@@ -0,0 +1,5 @@
+// pch.cpp: source file corresponding to the pre-compiled header
+
+#include "pch.h"
+
+// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
diff --git a/Clip2D/Clip2D/pch.h b/Clip2D/Clip2D/pch.h
new file mode 100644
index 0000000..885d5d6
--- /dev/null
+++ b/Clip2D/Clip2D/pch.h
@@ -0,0 +1,13 @@
+// pch.h: This is a precompiled header file.
+// Files listed below are compiled only once, improving build performance for future builds.
+// This also affects IntelliSense performance, including code completion and many code browsing features.
+// However, files listed here are ALL re-compiled if any one of them is updated between builds.
+// Do not add files here that you will be updating frequently as this negates the performance advantage.
+
+#ifndef PCH_H
+#define PCH_H
+
+// add headers that you want to pre-compile here
+#include "framework.h"
+
+#endif //PCH_H
diff --git a/Clip2D/Clip2D/res/Clip2D.ico b/Clip2D/Clip2D/res/Clip2D.ico
new file mode 100644
index 0000000..1c753ea
Binary files /dev/null and b/Clip2D/Clip2D/res/Clip2D.ico differ
diff --git a/Clip2D/Clip2D/res/Clip2D.rc2 b/Clip2D/Clip2D/res/Clip2D.rc2
new file mode 100644
index 0000000..85b7896
Binary files /dev/null and b/Clip2D/Clip2D/res/Clip2D.rc2 differ
diff --git a/Clip2D/Clip2D/res/Clip2DDoc.ico b/Clip2D/Clip2D/res/Clip2DDoc.ico
new file mode 100644
index 0000000..96365d4
Binary files /dev/null and b/Clip2D/Clip2D/res/Clip2DDoc.ico differ
diff --git a/Clip2D/Clip2D/res/Toolbar.bmp b/Clip2D/Clip2D/res/Toolbar.bmp
new file mode 100644
index 0000000..d501723
Binary files /dev/null and b/Clip2D/Clip2D/res/Toolbar.bmp differ
diff --git a/Clip2D/Clip2D/targetver.h b/Clip2D/Clip2D/targetver.h
new file mode 100644
index 0000000..87c0086
--- /dev/null
+++ b/Clip2D/Clip2D/targetver.h
@@ -0,0 +1,8 @@
+#pragma once
+
+// Including SDKDDKVer.h defines the highest available Windows platform.
+
+// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
+// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
+
+#include