文檔|演示|其他庫
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 ,無論您喜歡哪個。