文档|演示|其他库
Cross Window是一个跨平台系统抽象库,用于管理Windows和执行OS任务。它旨在易于集成,直观,并支持应用程序可能需要的所有内容。
?简单的窗口,文件对话框和消息对话框创建。
⌨️?qu? ?基本输入(键盘,鼠标,触摸和游戏手柄)。
?平台特定功能(MAC透明度,移动加速度计等)。
?单元测试 +测试覆盖范围( Windows的AppVeyor, Android / MacOS / iOS的CircleCi,[Travis] [Travis-url] for Linux / noop )。
?橱窗 - Win32
? Mac Cocoa
iOS- UIKit
? Linux XCB或XLib
? Android(正在进行中)
WebAssembly Emscripten
noop(无头)
首先将存储库添加为依赖项文件夹中的子模块,例如external/ :
# ⤵️ Add your dependency as a git submodule:
git submodule add https://github.com/alaingalvan/crosswindow.git external/crosswindow然后在您的CMakeLists.txt文件中,包括以下内容:
# ⤵️ Add to your CMake Project:
add_subdirectory (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
)用您可能拥有的任何其他源文件和依赖项填写其余的CMakeLists.txt文件,然后在您的项目root中:
# ?️ To build your Visual Studio solution on Windows x64
cmake -B build -A x64
# ? To build your XCode project On Mac OS for Mac OS
cmake -B build -G Xcode
# To build your XCode project on Mac OS for iOS / iPad OS / tvOS / watchOS
cmake -B build -G Xcode -DCMAKE_SYSTEM_NAME=iOS
# ? To build your .make file on Linux
cmake -B build
# ? Build on any platform:
cmake -B build --build对于WebAssembly,您需要安装Emscripten。假设您已安装了SDK,请执行以下操作以构建WebAssembly项目:
# 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.js有关更多信息,请访问有关CMAKE的Emscripten文档。
对于Android Studio,您需要进行一个项目,然后编辑build.gradle文件。
// ? 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 { .. . }
}
}有关更多信息,请访问Android Studio关于CMAKE的文档。
然后在项目中的.cpp文件(例如“ XMain.cpp ”)中创建一个主委托函数void xmain(int argc, const char** argv)其中您将放置您的应用程序逻辑:
# 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::MouseInput)
{
const xwin::MouseInputData mouse = event. data . mouseInput ;
}
if (event. type == xwin::EventType::Close)
{
window. close ();
isRunning = false ;
}
eventQueue. pop ();
}
}
}该xmain函数将从平台特定的主函数中调用,该功能将通过CMAKE包含在您的主要项目中。如果出于任何原因,您需要从平台特定的主要功能访问某些内容,则可以在xwin::getXWinState()中找到它。
确保安装了CMAKE。
| CMAKE选项 | 描述 |
|---|---|
XWIN_TESTS | 是否启用了单元测试。默认为OFF ,可以ON或OFF 。 |
XWIN_API | 用于窗口生成的OS API,默认为AUTO API可以是NOOP , WIN32 ,可可, COCOA , UIKIT , XCB , ANDROID或WASM 。 |
XWIN_OS | 可选- 要构建的操作系统可作为设置目标平台的更快的方法。默认为AUTO ,可以是NOOP , WINDOWS , MACOS , LINUX , ANDROID , IOS , WASM 。如果您的平台支持多个API,则最终API将自动设置为CrossWindow默认值(Windows上的WIN32 ,Linux上的XCB )。如果设置了XWIN_API ,则忽略此选项。 |
首先安装git,然后在任何文件夹中打开任何终端,然后键入:
# ? Clone the repo
git clone https://github.com/alaingalvan/crosswindow.git --recurse-submodules
# ? go inside the folder
cd crosswindow
# ? If you forget to `recurse-submodules` you can always run:
git submodule update --init
从那里我们需要设置构建文件。确保安装以下内容:
cmake
IDE,例如Visual Studio,Xcode或编译器,例如GCC。
然后从repo文件夹中输入以下内容:
# ?️ To build your Visual Studio solution on Windows x64
cmake -B build -A x64 -DXWIN_TESTS=ON
# ? To build your XCode project on Mac OS
cmake -B build -G Xcode -DXWIN_TESTS=ON
# ? To build your .make file on Linux
cmake -B build -DXWIN_TESTS=ON
# ? Build on any platform:
cmake -B build --build每当您将新文件添加到项目中时,请从解决方案/项目文件夹/build/运行cmake .. ,如果您编辑CMakeLists.txt文件,请务必确保删除生成的文件并再次运行cmake。
CrossWindow被许可为MIT或Apache-2.0 ,无论您喜欢哪个。