CrossWindow
A basic cross platform system abstraction library for managing windows and performing OS tasks.
Features
-
๐ Simple Window, File Dialog, and Message Dialog Creation -
โจ๏ธ ๐ฑ๏ธ ๐ ๐ฎ Basic Input (Keyboard, Mouse, Touch, and Gamepad) -
๐ป Platform specific features (Mac Transparency, Mobile Accelerometer, etc.) -
๐ Unit Tests + Test Coverage (Appveyor for Windows, CircleCI for Android / MacOS / iOS, Travis for Linux/Noop) -
๐ Modern and well maintained C++ 11, with a promise to evolve as the standard evolves. (C++ Modules, Package Managers, etc.)
Supported Platforms
-
๐ผ๏ธ Windows (Win32) -
๐ Mac (Cocoa) -
๐ฑ iOS (AppKit) -
๐ง Linux (XCB) -
๐ค Android -
๐ WebAssembly -
โ Noop (Headless)
Installation
First add the repo as a submodule in your dependencies folder such as external/:
cd external
git submodule add https://github.com/alaingalvan/crosswindow.gitThen in your CMakeLists.txt file, include the following:
# โฌ Add your dependency:
add_subdirectories(external/CrossWindow)
# โ When creating your executable use CrossWindow's abstraction function:
xwin_add_executable(
# Target
${PROJECT_NAME}
# Source Files (make sure to surround in quotations so CMake treats it as a list)
"${SOURCE_FILES}"
)
# ๐ Link CrossWindow to your project:
target_link_libraries(
${PROJECT_NAME}
CrossWindow
)Fill out the rest of your CMakeLists.txt file with any other source files and dependencies you may have, then in your project root:
# ๐ผ๏ธ To build your Visual Studio solution on Windows x64
mkdir visualstudio
cd visualstudio
cmake .. -A x64
# ๐ To build your XCode project On Mac OS for Mac OS / iOS
mkdir xcode
cd xcode
cmake .. -G Xcode
# ๐ง To build your .make file on Linux
mkdir make
cd make
cmake ..
# ๐จ Build on any platform:
cmake --build .For WebAssembly you'll need to have Emscripten installed. Assuming you have the SDK installed, do the following to build a WebAssembly project:
# ๐ For WebAssembly Projects
mkdir webassembly
cd webassembly
cmake .. -DXWIN_OS=WASM -DCMAKE_TOOLCHAIN_FILE="$EMSDK/emscripten/1.38.1/cmake/Modules/Platform/Emscripten.cmake" -DCMAKE_BUILD_TYPE=Release
# Run emconfigure with the normal configure command as an argument.
$EMSDK/emscripten/emconfigure ./configure
# Run emmake with the normal make to generate linked LLVM bitcode.
$EMSDK/emscripten/emmake make
# Compile the linked bitcode generated by make (project.bc) to JavaScript.
# 'project.bc' should be replaced with the make output for your project (e.g. 'yourproject.so')
$EMSDK/emscripten/emcc project.bc -o project.jsFor more information visit the Emscripten Docs on CMake.
For Android Studio you'll need to make a project, then edit your build.gradle file.
// ๐ค To build your Android Studio project
android {
...
externalNativeBuild {
cmake {
...
// Use the following syntax when passing arguments to variables:
// arguments "-DVAR_NAME=ARGUMENT".
arguments "-DXWIN_OS=ANDROID",
// The following line passes 'rtti' and 'exceptions' to 'ANDROID_CPP_FEATURES'.
"-DANDROID_CPP_FEATURES=rtti exceptions"
}
}
buildTypes {...}
// Use this block to link Gradle to your CMake build script.
externalNativeBuild {
cmake {...}
}
}for more information visit Android Studio's docs on CMake.
Usage
Then create a main delegate function void xmain(int argc, const char** argv) in a .cpp file in your project (for example "XMain.cpp") where you'll put your application logic:
#include "CrossWindow/CrossWindow.h"
void xmain(int argc, const char** argv)
{
// ๐ผ๏ธ Create Window Description
xwin::WindowDesc windowDesc;
windowDesc.name = "Test";
windowDesc.title = "My Title";
windowDesc.visible = true;
windowDesc.width = 1280;
windowDesc.height = 720;
bool closed = false;
// ๐ Initialize
xwin::Window window;
xwin::EventQueue eventQueue;
if (!window.create(windowDesc, eventQueue))
{ return; }
// ๐ Engine loop
bool isRunning = true;
while (isRunning)
{
// โป๏ธ Update the event queue
eventQueue.update();
// ๐ Iterate through that queue:
while (!eventQueue.empty())
{
const xwin::Event& event = eventQueue.front();
if (event.type == xwin::EventType::Mouse)
{
const xwin::MouseData mouse = event.data.mouse;
}
if (event.type == xwin::EventType::Close)
{
window.close();
isRunning = false;
}
eventQueue.pop();
}
}
}This xmain function will be called from a platform specific main function that will be included in your main project by CMake. If you ever need to access something from the platform specific main function for whatever reason, you'll find it in xwin::getXWinState().
For more examples visit the Documentation or try out the demos.
Development
Be sure to have CMake Installed.
| CMake Options | Description |
|---|---|
XWIN_TESTS |
Whether or not unit tests are enabled. Defaults to OFF, Can be ON or OFF. |
XWIN_PROTOCOL |
The protocol to use for window generation, defaults to AUTO, can be can be NOOP, WIN32, COCOA, APPKIT, XCB , ANDROID, or WASM. |
XWIN_OS |
Optional - What Operating System to build for, functions as a quicker way of setting target platforms. Defaults to AUTO, can be NOOP, WINDOWS, MACOS, LINUX, ANDROID, IOS, WASM. If your platform supports multiple protocols, the final protocol will be automatically set to CrossWindow defaults ( WIN32 on Windows, XCB on Linux ). If XWIN_PROTOCOL is set this option is ignored. |
We would recommend making a folder where solution files will be built to to avoid making your file system look too messy, such as visualstudio/ or xcode/ depending on the platform you're building for:
# ๐ฏ Clone the repo
git clone https://github.com/alaingalvan/crosswindow.git --recurse-submodules
cd crosswindow
# ๐ผ๏ธ To build your Visual Studio solution on Windows x64
mkdir visualstudio
cd visualstudio
cmake .. -DXWIN_TESTS=ON -A x64
# ๐ To build your XCode project On Mac OS for Mac OS / iOS
mkdir xcode
cd xcode
cmake .. -DXWIN_TESTS=ON -G Xcode
# ๐ง To build your makefile on Linux
mkdir make
cd make
cmake .. -DXWIN_TESTS=ONWhenever you add new files to the project, run cmake .. from your solution/project folder, and if you edit the CMakeLists.txt file be sure to delete the generated files and run Cmake again.
Project Goals
-
๐ XLib / Wayland / XLib support for Linux -
โ Windows 10 Apps / Window 10 Arm / Xbox One support with Universal Windows Platform (WMP). -
๐ญ Linux flavor OS targets (XWIN_OScan beUBUNTU,DEBIAN,FEDORA, etc.) -
๐ ฟ๏ธ Playstation 4 support -
๐ Nintendo Switch support -
๐ฆ Create-CrossWindow-App CLI Tool similar to Create-React-App to auto-generate all platform specific projects and set up your seed with 0 configuration.create-xwin-app MyGame.
License
CrossWindow is licensed as either MIT or Apache-2.0, whichever you would prefer.
