Make sure the following tools are installed:
- Visual Studio 2017+
Microsoft.VisualStudio.Workload.NativeDesktopworkload is needed for Desktop C++ development
- CMake
- Command
cmakeshould be in%PATH% - Verify if
cmake --versionshows version
- Command
If in doubt, run python3 verify_or_install_tools.py (requires Python 3.7+).
git clone https://github.com/sundaramramaswamy/inker
cd inker
cmake -B build
cmake --build buildThis should build ink.exe under //build/Debug.
Open Visual Studio with
start build\Inker.slnIn the Solution Explorer, right-click ink project and click Set as Startup Project.
Add new sources (.h/.cpp) to src/ and list them in //CMakeLists.txt along with other sources.
Build in Visual Studio. It should pick up the changes you made in the CMake script.
The idea is to implement an inking application using MVA Pattern (an extension of MVC). Refer and use the interfaces in eventing.h and view.h; implement a Controller class which extends/inherits from WindowEventHandler -- an interface containing methods like OnMousePressed, OnKeyReleased, OnPaint, etc.
Build an ink document (model) using the OnMousePressed, OnMouseDragged and OnMouseReleased functions. One way to structure your document
Document
Collection of Stroke
Stroke
Collection of Points
Point
A pair of floats (Vector2)
When the user clicks, drags and releases the mouse, you'd get a bunch of points which form one stroke. A document is a collection of such strokes.
During the OnPaint(View*) you'd refer to your document (model) and for every stroke do a bunch of View::DrawLine calls. This would render the document on to the view.
The default state of the project comes with a TestController class (//src/test_controller.h) that simply logs the events it receives and paints Hello, world. You've to implement your own InkController for the above work. Make sure in main.cpp you set your InkController as the window's event handler. Other than main.cpp, eventing.h and view.h you can pretty much ignore all the other files in the project.
When the user clicks a stroke with Ctrl held down, you can hit-test all the strokes in the document and check if the click was atop a stroke. If yes, you'd remove that stroke from your document. In the next OnPaint call this change would automatically be picked up and you don't have to do anything extra to see the stroke go away.
You can make the document fancy by having strokes of different colours. It’s up to you define how to switch the pen colour. One way would be to assign colours to keyboard keys 1 (Black), 2 (Red), 3 (Blue), etc. and switch the colour when the user presses a corresponding key. You’d store every stroke with a colour in your model. During render, you’d draw the stroke with DrawLines passing the stroke’s colour as Color (which is a collection of four unsigned chars).
- Spirit of C++
- C++ Language and Standard Library Reference
- Keep this open when you’re writing C++ code
- C++ Function Parameter Choices -- Cheatsheet
- Useful to know what parameter type to take in functions
- C++ ISO FAQ
- Very useful when you’ve doubts