Welcome to SWTI Docs 1.4
Simple Windows Text Interface is made out of 4 static objects.
-
Cursor which is used for printing colorful text on screen
-
Keyboard which is used for detecting user keyboard input
-
Mouse which is used for detecting user mouse input
-
Window which is used for resizing window
These four objects have in total about 40 methods to interact with console.
Installation
The installation of SWTI library is easy.
Download repository and copy the folder SWTI/swti to your project folder.
It contains header and source code for the library.
In your application, include a header "#include swti/swti.hpp"
.
-
Visual Studio - you will also need to add header and source files to your project. Right click on the right folder header files and add existing file and choose SWTI/swti.hpp. Do the same for source files and add SWTI/swti.cpp.
-
Code Blocks - click on the left pane folders and add existing header and source files to your project.
-
GNU Console - You can use following command
g++ main.cpp swti/swti.cpp -o main.exe
to compile your project. Change main.cpp and main.exe to whatever you prefer. If you get some errors, make sure you are including the header and you can use these flags-static-libstdc++ -static-libgcc
.
Hello world
You can use this simple example to ensure that SWTI library is installed correctly. Following code writes colorful Hello world on a specified position. It uses the Cursor object and methods setColor and setPosition.
#include <iostream>
#include "swti/swti.hpp"
int main()
{
Cursor.setColor(YELLOW);
Cursor.setPosition(5, 2);
std::cout << "Hello world!" << std::endl;
}
Troubleshooting
If something doesn't work, try to create a new project without any additional libraries other than SWTI. If you succeed, the problem is collision with function names in the library. In C++ functions or objects with same names cannot be used and namespace should be used. To solve this issue, you can create one for swti, in which you include a header and the source file.
#include <iostream>
namespace swti
{
#include "swti/swti.hpp"
#include "swti/swti.cpp" // source is needed
}
int main()
{
swti::Color color = swti::LIGHTGREEN;
swti::Cursor.setColor(color);
std::cout << "SWTI Works!\n";
}
You need to use swti::
prefix for every function and object. If something still doesn't work, please add issue.