├── example ├── steam_appid.txt ├── test │ └── widget_test.dart ├── steam_api64.dll ├── windows │ ├── runner │ │ ├── resources │ │ │ └── app_icon.ico │ │ ├── resource.h │ │ ├── CMakeLists.txt │ │ ├── utils.h │ │ ├── runner.exe.manifest │ │ ├── flutter_window.h │ │ ├── main.cpp │ │ ├── utils.cpp │ │ ├── flutter_window.cpp │ │ ├── Runner.rc │ │ ├── win32_window.h │ │ └── win32_window.cpp │ ├── flutter │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugins.cmake │ │ └── CMakeLists.txt │ ├── .gitignore │ └── CMakeLists.txt ├── README.md ├── .metadata ├── lib │ ├── main.dart │ └── game.dart ├── .gitignore ├── pubspec.yaml ├── analysis_options.yaml └── pubspec.lock ├── test └── flame_steamworks_test.dart ├── lib ├── flame_steamworks.dart └── src │ ├── has_steam_client.dart │ └── has_steam_server.dart ├── analysis_options.yaml ├── .metadata ├── .gitignore ├── .vscode ├── tasks.json └── launch.json ├── CHANGELOG.md ├── LICENSE ├── pubspec.yaml └── README.md /example/steam_appid.txt: -------------------------------------------------------------------------------- 1 | 480 -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | -------------------------------------------------------------------------------- /test/flame_steamworks_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | -------------------------------------------------------------------------------- /example/steam_api64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeb-dev/flame_steamworks/HEAD/example/steam_api64.dll -------------------------------------------------------------------------------- /lib/flame_steamworks.dart: -------------------------------------------------------------------------------- 1 | export "src/has_steam_client.dart"; 2 | export "src/has_steam_server.dart"; 3 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aeb-dev/flame_steamworks/HEAD/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:aeb_lint/analysis_options.yaml 2 | 3 | linter: 4 | rules: 5 | always_specify_types: false 6 | avoid_positional_boolean_parameters: false 7 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | Simple windows application that listens steam for `UnreadChatMessagesChanged` event. Run `flutter run` command to see the example. After the application starts, ask a friend to send you a message. 2 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: c860cba910319332564e1e9d470a17074c1f2dfd 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: c860cba910319332564e1e9d470a17074c1f2dfd 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | add_executable(${BINARY_NAME} WIN32 5 | "flutter_window.cpp" 6 | "main.cpp" 7 | "utils.cpp" 8 | "win32_window.cpp" 9 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 10 | "Runner.rc" 11 | "runner.exe.manifest" 12 | ) 13 | apply_standard_settings(${BINARY_NAME}) 14 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 15 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 16 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 17 | add_dependencies(${BINARY_NAME} flutter_assemble) 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 25 | /pubspec.lock 26 | **/doc/api/ 27 | .dart_tool/ 28 | .packages 29 | build/ 30 | 31 | vmservice_info.txt 32 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import "dart:developer" as developer; 2 | import "dart:io"; 3 | 4 | import "package:flame/game.dart"; 5 | import "package:flutter/material.dart"; 6 | 7 | import "game.dart"; 8 | 9 | Future main() async { 10 | // Attempt to get the VM service URI and dump it to a file. 11 | try { 12 | final info = await developer.Service.getInfo(); 13 | final uri = info.serverUri; // may be null if service not yet available 14 | if (uri != null) { 15 | await File("vmservice_info.txt").writeAsString("{ \"uri\": \"$uri\" }"); 16 | } 17 | } catch (e) { 18 | // ignore or log somewhere safe 19 | } 20 | 21 | runApp(GameWidget(game: GameInstance())); 22 | } 23 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "start through steam", 6 | "command": "steam", 7 | "type": "shell", 8 | "dependsOn": "flutter build windows", 9 | "args": [ 10 | "-start", 11 | "steam://rungameid/16736235453614653440" 12 | ] 13 | }, 14 | { 15 | "label": "flutter build windows", 16 | "command": "flutter", 17 | "type": "shell", 18 | "args": [ 19 | "build", 20 | "windows", 21 | "--debug" 22 | ], 23 | "options": { 24 | "cwd": "${workspaceFolder}/example" 25 | } 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.3 2 | 3 | - Update flame 4 | - Update steamworks 5 | 6 | ## 0.4.2 7 | 8 | - Update `steamworks` to 0.4.4. 9 | 10 | ## 0.4.1 11 | 12 | - Update `steamworks` to 0.4.2. 13 | 14 | ## 0.4.0 15 | 16 | - Update `steamworks` to 0.4.0. 17 | - Update `flame` to 1.8.2. 18 | - Update dart to 3. 19 | - Update flutter to 3.10.0. 20 | 21 | ## 0.3.0 22 | 23 | - Update `steamworks` package and respective changes. 24 | - Update `flame` package and respective changes. 25 | 26 | ## 0.2.1 27 | 28 | - Update `steamworks` package and respective changes. 29 | 30 | ## 0.2.0 31 | 32 | - Changed the names of `SteamGame`, `SteamGameServer` mixins to `HasSteamClient`, `HasSteamServer`, respectively, in order to comply with flame naming conventions 33 | - Update readme and example 34 | 35 | ## 0.1.1 36 | 37 | - Update readme 38 | 39 | ## 0.1.0 40 | 41 | - Initial release 42 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "flame_steamworks", 9 | "request": "launch", 10 | "type": "dart" 11 | }, 12 | { 13 | "name": "flame_steamworks (profile mode)", 14 | "request": "launch", 15 | "type": "dart", 16 | "flutterMode": "profile" 17 | }, 18 | { 19 | "name": "flame_steamworks (release mode)", 20 | "request": "launch", 21 | "type": "dart", 22 | "flutterMode": "release" 23 | }, 24 | { 25 | "name": "flame_steamworks (steam)", 26 | "request": "attach", 27 | "type": "dart", 28 | "preLaunchTask": "start through steam", 29 | "cwd": "${workspaceFolder}/example", 30 | "vmServiceInfoFile": "vmservice_info.txt", 31 | }, 32 | ] 33 | } -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, Ahmet Enes Bayraktar 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /lib/src/has_steam_client.dart: -------------------------------------------------------------------------------- 1 | import "dart:ffi"; 2 | 3 | import "package:flame/game.dart"; 4 | import "package:steamworks/steamworks.dart"; 5 | 6 | /// A mixin to enable steam api for game client 7 | mixin HasSteamClient on FlameGame { 8 | /// Instance of the [SteamClient] to access the steam api 9 | /// Do not call this until [init] is called 10 | SteamClient get steamClient => SteamClient.instance; 11 | 12 | @override 13 | void update(double dt) { 14 | super.update(dt); 15 | 16 | steamClient.runFrame(); 17 | } 18 | 19 | /// Initializes [SteamClient]. Call this 20 | /// function before calling any function 21 | void init() { 22 | SteamClient.init(); 23 | } 24 | 25 | /// Registers a [Callback] 26 | Callback registerCallback( 27 | void Function(Pointer data) cb, 28 | ) => 29 | steamClient.registerCallback( 30 | cb: cb, 31 | ); 32 | 33 | /// Registers a [CallResult] 34 | CallResult registerCallResult( 35 | SteamApiCall asyncCallId, 36 | void Function(Pointer data, bool hasFailed) cb, 37 | ) => 38 | steamClient.registerCallResult( 39 | asyncCallId: asyncCallId, 40 | cb: cb, 41 | ); 42 | 43 | /// Unregisters a [Callback] 44 | void unregisterCallback( 45 | Callback callback, 46 | ) => 47 | steamClient.unregisterCallback( 48 | callback: callback, 49 | ); 50 | 51 | /// Unregisters a [CallResult] 52 | void unregisterCallResult( 53 | CallResult callResult, 54 | ) => 55 | steamClient.unregisterCallResult( 56 | callResult: callResult, 57 | ); 58 | } 59 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | if (target_length == 0) { 52 | return std::string(); 53 | } 54 | std::string utf8_string; 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /example/lib/game.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: public_member_api_docs, avoid_print 2 | 3 | import "package:flame/components.dart"; 4 | import "package:flame/game.dart"; 5 | import "package:flame/input.dart"; 6 | import "package:flame_steamworks/flame_steamworks.dart"; 7 | import "package:flutter/material.dart"; 8 | import "package:flutter/services.dart"; 9 | import "package:steamworks/steamworks.dart"; 10 | 11 | class GameInstance extends FlameGame with KeyboardEvents, HasSteamClient { 12 | TextPaint textPaint = TextPaint( 13 | style: const TextStyle( 14 | fontSize: 18.0, 15 | fontFamily: "Awesome Font", 16 | color: Colors.red, 17 | ), 18 | ); 19 | 20 | int count = 0; 21 | 22 | GameInstance() { 23 | add(FpsTextComponent()); 24 | init(); 25 | registerCallback((data) => ++count); 26 | } 27 | 28 | @override 29 | void render(Canvas canvas) { 30 | super.render(canvas); 31 | 32 | textPaint.render( 33 | canvas, 34 | "# of chat events received: $count", 35 | Vector2(5, 40), 36 | ); 37 | } 38 | 39 | @override 40 | KeyEventResult onKeyEvent( 41 | KeyEvent event, 42 | Set keysPressed, 43 | ) { 44 | bool isKeyDown = event is KeyDownEvent; 45 | 46 | bool isSpace = keysPressed.contains(LogicalKeyboardKey.space); 47 | 48 | if (isSpace && isKeyDown) { 49 | CSteamId steamId = steamClient.steamUser.getSteamId(); 50 | SteamApiCall callId = 51 | steamClient.steamUserStats.requestUserStats(steamId); 52 | 53 | registerCallResult( 54 | callId, 55 | (ptrUserStatus, hasFailed) { 56 | print("User stats received"); 57 | print("GameId: ${ptrUserStatus.gameId}"); 58 | print("SteamIdUser: ${ptrUserStatus.steamIdUser}"); 59 | }, 60 | ); 61 | 62 | return KeyEventResult.handled; 63 | } 64 | return KeyEventResult.ignored; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/has_steam_server.dart: -------------------------------------------------------------------------------- 1 | import "dart:ffi"; 2 | 3 | import "package:flame/game.dart"; 4 | import "package:steamworks/steamworks.dart"; 5 | 6 | /// A mixin to enable steam api for game server 7 | mixin HasSteamServer on FlameGame { 8 | /// Instance of the [SteamServer] to access the steam api. 9 | /// Do not call this until [init] is called 10 | SteamServer get steamServer => SteamServer.instance; 11 | 12 | @override 13 | void update(double dt) { 14 | super.update(dt); 15 | 16 | steamServer.runFrame(); 17 | } 18 | 19 | /// Initializes [SteamServer]. Call this 20 | /// function before calling any function 21 | void init( 22 | String ip, { 23 | int steamPort = 0, 24 | int gamePort = 27015, 25 | int queryPort = 27016, 26 | EServerMode serverMode = EServerMode.authenticationAndSecure, 27 | String versionString = "1.0.0.0", 28 | }) { 29 | SteamServer.init( 30 | ip: ip, 31 | steamPort: steamPort, 32 | gamePort: gamePort, 33 | queryPort: queryPort, 34 | serverMode: serverMode, 35 | versionString: versionString, 36 | ); 37 | } 38 | 39 | /// Registers a [Callback] 40 | Callback registerCallback( 41 | void Function(Pointer data) cb, 42 | ) => 43 | steamServer.registerCallback( 44 | cb: cb, 45 | ); 46 | 47 | /// Registers a [CallResult] 48 | CallResult registerCallResult( 49 | SteamApiCall asyncCallId, 50 | void Function(Pointer data, bool hasFailed) cb, 51 | ) => 52 | steamServer.registerCallResult( 53 | asyncCallId: asyncCallId, 54 | cb: cb, 55 | ); 56 | 57 | /// Unregisters a [Callback] 58 | void unregisterCallback( 59 | Callback callback, 60 | ) => 61 | steamServer.unregisterCallback( 62 | callback: callback, 63 | ); 64 | 65 | /// Unregisters a [CallResult] 66 | void unregisterCallResult( 67 | CallResult callResult, 68 | ) => 69 | steamServer.unregisterCallResult( 70 | callResult: callResult, 71 | ); 72 | } 73 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flame_steamworks 2 | description: A package that makes it possible to make a game in steam with flutter! 3 | version: 0.4.3 4 | homepage: https://github.com/aeb-dev/flame_steamworks 5 | repository: https://github.com/aeb-dev/flame_steamworks 6 | issues: https://github.com/aeb-dev/flame_steamworks/issues 7 | 8 | environment: 9 | sdk: ">=3.0.0 <4.0.0" 10 | flutter: ">=3.10.0" 11 | 12 | dependencies: 13 | flame: ^1.16.0 14 | flutter: 15 | sdk: flutter 16 | steamworks: ^0.4.6 17 | 18 | dev_dependencies: 19 | aeb_lint: ^1.1.0 20 | flutter_test: 21 | sdk: flutter 22 | 23 | platforms: 24 | linux: 25 | macos: 26 | windows: 27 | 28 | # For information on the generic Dart part of this file, see the 29 | # following page: https://dart.dev/tools/pub/pubspec 30 | 31 | # The following section is specific to Flutter. 32 | flutter: 33 | 34 | # To add assets to your package, add an assets section, like this: 35 | # assets: 36 | # - images/a_dot_burr.jpeg 37 | # - images/a_dot_ham.jpeg 38 | # 39 | # For details regarding assets in packages, see 40 | # https://flutter.dev/assets-and-images/#from-packages 41 | # 42 | # An image asset can refer to one or more resolution-specific "variants", see 43 | # https://flutter.dev/assets-and-images/#resolution-aware. 44 | 45 | # To add custom fonts to your package, add a fonts section here, 46 | # in this "flutter" section. Each entry in this list should have a 47 | # "family" key with the font family name, and a "fonts" key with a 48 | # list giving the asset and other descriptors for the font. For 49 | # example: 50 | # fonts: 51 | # - family: Schyler 52 | # fonts: 53 | # - asset: fonts/Schyler-Regular.ttf 54 | # - asset: fonts/Schyler-Italic.ttf 55 | # style: italic 56 | # - family: Trajan Pro 57 | # fonts: 58 | # - asset: fonts/TrajanPro.ttf 59 | # - asset: fonts/TrajanPro_Bold.ttf 60 | # weight: 700 61 | # 62 | # For details regarding fonts in packages, see 63 | # https://flutter.dev/custom-fonts/#from-packages 64 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates and shows a win32 window with |title| and position and size using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(example LANGUAGES CXX) 3 | 4 | set(BINARY_NAME "example") 5 | 6 | cmake_policy(SET CMP0063 NEW) 7 | 8 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 9 | 10 | # Configure build options. 11 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 12 | if(IS_MULTICONFIG) 13 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 14 | CACHE STRING "" FORCE) 15 | else() 16 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 17 | set(CMAKE_BUILD_TYPE "Debug" CACHE 18 | STRING "Flutter build mode" FORCE) 19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 20 | "Debug" "Profile" "Release") 21 | endif() 22 | endif() 23 | 24 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 25 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 26 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 27 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 28 | 29 | # Use Unicode for all projects. 30 | add_definitions(-DUNICODE -D_UNICODE) 31 | 32 | # Compilation settings that should be applied to most targets. 33 | function(APPLY_STANDARD_SETTINGS TARGET) 34 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 35 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 36 | target_compile_options(${TARGET} PRIVATE /EHsc) 37 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 38 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 39 | endfunction() 40 | 41 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 42 | 43 | # Flutter library and tool build rules. 44 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 45 | 46 | # Application build 47 | add_subdirectory("runner") 48 | 49 | # Generated plugin build rules, which manage building the plugins and adding 50 | # them to the application. 51 | include(flutter/generated_plugins.cmake) 52 | 53 | 54 | # === Installation === 55 | # Support files are copied into place next to the executable, so that it can 56 | # run in place. This is done instead of making a separate bundle (as on Linux) 57 | # so that building and running from within Visual Studio will work. 58 | set(BUILD_BUNDLE_DIR "$") 59 | # Make the "install" step default, as it's required to run. 60 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 61 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 62 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 63 | endif() 64 | 65 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 66 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 67 | 68 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 69 | COMPONENT Runtime) 70 | 71 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 72 | COMPONENT Runtime) 73 | 74 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 75 | COMPONENT Runtime) 76 | 77 | if(PLUGIN_BUNDLED_LIBRARIES) 78 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 79 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 80 | COMPONENT Runtime) 81 | endif() 82 | 83 | # Fully re-copy the assets directory on each build to avoid having stale files 84 | # from a previous install. 85 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 86 | install(CODE " 87 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 88 | " COMPONENT Runtime) 89 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 90 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 91 | 92 | # Install the AOT library on non-Debug builds only. 93 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 94 | CONFIGURATIONS Profile;Release 95 | COMPONENT Runtime) 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | ⚠️Until [this issue](https://github.com/dart-lang/sdk/issues/42816) is fixed, this package only support windows. There is a workaround though, you can generate platform specific api using https://github.com/aeb-dev/steamworks_gen 6 | 7 | # flame_steamworks 8 | A package that makes it possible to make a game in steam with flutter! It combines [steamworks](https://github.com/aeb-dev/steamworks) and [flame](https://github.com/flame-engine/flame). 9 | 10 |   11 | 12 | # Features 13 | The goal of this library is to provide complete coverage possible over steam api. We can split functionality provided with the steam api into three categories: 14 | 15 | - Initilization, common apis 16 | - Asynchronous callbacks 17 | - Asynchronous call results 18 | 19 | You can get detailed information about these from the [steam docs](https://partner.steamgames.com/doc/sdk/api) 20 | 21 |   22 | 23 | # Requirements 24 | 25 | You need to steam_api.dll and steam_api.lib to be able to use this package. You can either download from [here](https://partner.steamgames.com/?goto=%2Fdownloads%2Fsteamworks_sdk.zip) by signing in or you can use the files under the example. If you chose to download from steam, the files are under `redistributable_bin`. 26 | 27 |   28 | 29 | # How to use 30 | 31 | ## Flame Game Instance 32 | 33 | First we need a game right! Lets make it. 34 | 35 | ```dart 36 | class GameInstance extends FlameGame with KeyboardEvents, HasSteamClient { 37 | GameInstance() { 38 | init(); // it is important to call this to initialize steam api 39 | } 40 | } 41 | ``` 42 | 43 |   44 | 45 | ## Registering for a callback 46 | 47 | `HasSteamClient` mixin provides a simple api to register a callback. You can register a callback in any place in the code 48 | ```dart 49 | class GameInstance extends FlameGame with KeyboardEvents, HasSteamClient { 50 | GameInstance() { 51 | init(); 52 | registerCallback((data) => /*do what you want*/); 53 | } 54 | } 55 | ``` 56 | 57 | There are many callbacks in steam api, you check all of them on steam docs. 58 | 59 |   60 | 61 | ## Registering for a call result 62 | `HasSteamClient` mixin provides a simple api to register a call result. Call results are a little different from callbacks. Before you subscribe to call result, you need to make a request and subscribe to result of that request. 63 | ```dart 64 | class GameInstance extends FlameGame with KeyboardEvents, HasSteamClient { 65 | // We wait for space key to be pressed and if it is then we make a request for UserStatsReceived an subscribe to its result 66 | @override 67 | KeyEventResult onKeyEvent( 68 | RawKeyEvent event, 69 | Set keysPressed, 70 | ) { 71 | bool isKeyDown = event is RawKeyDownEvent; 72 | 73 | bool isSpace = keysPressed.contains(LogicalKeyboardKey.space); 74 | 75 | if (isSpace && isKeyDown) { 76 | CSteamId steamId = steamClient.steamUser.getSteamId(); 77 | SteamApiCall callId = 78 | steamClient.steamUserStats.requestUserStats(steamId); 79 | 80 | registerCallResult( 81 | callId, 82 | (ptrUserStatus, hasFailed) { 83 | print("User stats received"); 84 | print("GameId: ${ptrUserStatus.gameId}"); 85 | print("SteamIdUser: ${ptrUserStatus.steamIdUser}"); 86 | }, 87 | ); 88 | 89 | return KeyEventResult.handled; 90 | } 91 | return KeyEventResult.ignored; 92 | } 93 | } 94 | ``` 95 | 96 | There are many call results in steam api, you check all of them on steam docs. 97 | 98 |   99 | 100 | # Published games 101 | Here are a list of games that have been published on Steam that utilise this package: 102 | - Omnichess - https://store.steampowered.com/app/2009510 103 | 104 |   105 | 106 | # What is next? 107 | Well, steam is the limit! 108 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: A new Flutter project. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 6 | publish_to: "none" # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 1.0.0+1 19 | 20 | environment: 21 | sdk: ">=2.17.5 <3.0.0" 22 | flutter: ">=3.0.3" 23 | 24 | # Dependencies specify other packages that your package needs in order to work. 25 | # To automatically upgrade your package dependencies to the latest versions 26 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 27 | # dependencies can be manually updated by changing the version numbers below to 28 | # the latest version available on pub.dev. To see which dependencies have newer 29 | # versions available, run `flutter pub outdated`. 30 | dependencies: 31 | flutter: 32 | sdk: flutter 33 | flame: ^1.16.0 34 | flame_steamworks: 35 | path: ../ 36 | 37 | # The following adds the Cupertino Icons font to your application. 38 | # Use with the CupertinoIcons class for iOS style icons. 39 | cupertino_icons: ^1.0.2 40 | 41 | dev_dependencies: 42 | flutter_test: 43 | sdk: flutter 44 | 45 | # The "flutter_lints" package below contains a set of recommended lints to 46 | # encourage good coding practices. The lint set provided by the package is 47 | # activated in the `analysis_options.yaml` file located at the root of your 48 | # package. See that file for information about deactivating specific lint 49 | # rules and activating additional ones. 50 | flutter_lints: ^1.0.0 51 | 52 | # For information on the generic Dart part of this file, see the 53 | # following page: https://dart.dev/tools/pub/pubspec 54 | 55 | # The following section is specific to Flutter. 56 | flutter: 57 | # The following line ensures that the Material Icons font is 58 | # included with your application, so that you can use the icons in 59 | # the material Icons class. 60 | uses-material-design: true 61 | 62 | # To add assets to your application, add an assets section, like this: 63 | # assets: 64 | # - images/a_dot_burr.jpeg 65 | # - images/a_dot_ham.jpeg 66 | 67 | # An image asset can refer to one or more resolution-specific "variants", see 68 | # https://flutter.dev/assets-and-images/#resolution-aware. 69 | 70 | # For details regarding adding assets from package dependencies, see 71 | # https://flutter.dev/assets-and-images/#from-packages 72 | 73 | # To add custom fonts to your application, add a fonts section here, 74 | # in this "flutter" section. Each entry in this list should have a 75 | # "family" key with the font family name, and a "fonts" key with a 76 | # list giving the asset and other descriptors for the font. For 77 | # example: 78 | # fonts: 79 | # - family: Schyler 80 | # fonts: 81 | # - asset: fonts/Schyler-Regular.ttf 82 | # - asset: fonts/Schyler-Italic.ttf 83 | # style: italic 84 | # - family: Trajan Pro 85 | # fonts: 86 | # - asset: fonts/TrajanPro.ttf 87 | # - asset: fonts/TrajanPro_Bold.ttf 88 | # weight: 700 89 | # 90 | # For details regarding fonts from package dependencies, 91 | # see https://flutter.dev/custom-fonts/#from-packages 92 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 4 | 5 | # Configuration provided via flutter tool. 6 | include(${EPHEMERAL_DIR}/generated_config.cmake) 7 | 8 | # TODO: Move the rest of this into files in ephemeral. See 9 | # https://github.com/flutter/flutter/issues/57146. 10 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 11 | 12 | # Set fallback configurations for older versions of the flutter tool. 13 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 14 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 15 | endif() 16 | 17 | # === Flutter Library === 18 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 19 | 20 | # Published to parent scope for install step. 21 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 22 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 23 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 24 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 25 | 26 | list(APPEND FLUTTER_LIBRARY_HEADERS 27 | "flutter_export.h" 28 | "flutter_windows.h" 29 | "flutter_messenger.h" 30 | "flutter_plugin_registrar.h" 31 | "flutter_texture_registrar.h" 32 | ) 33 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 34 | add_library(flutter INTERFACE) 35 | target_include_directories(flutter INTERFACE 36 | "${EPHEMERAL_DIR}" 37 | ) 38 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 39 | add_dependencies(flutter flutter_assemble) 40 | 41 | # === Wrapper === 42 | list(APPEND CPP_WRAPPER_SOURCES_CORE 43 | "core_implementations.cc" 44 | "standard_codec.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 48 | "plugin_registrar.cc" 49 | ) 50 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 51 | list(APPEND CPP_WRAPPER_SOURCES_APP 52 | "flutter_engine.cc" 53 | "flutter_view_controller.cc" 54 | ) 55 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 56 | 57 | # Wrapper sources needed for a plugin. 58 | add_library(flutter_wrapper_plugin STATIC 59 | ${CPP_WRAPPER_SOURCES_CORE} 60 | ${CPP_WRAPPER_SOURCES_PLUGIN} 61 | ) 62 | apply_standard_settings(flutter_wrapper_plugin) 63 | set_target_properties(flutter_wrapper_plugin PROPERTIES 64 | POSITION_INDEPENDENT_CODE ON) 65 | set_target_properties(flutter_wrapper_plugin PROPERTIES 66 | CXX_VISIBILITY_PRESET hidden) 67 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 68 | target_include_directories(flutter_wrapper_plugin PUBLIC 69 | "${WRAPPER_ROOT}/include" 70 | ) 71 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 72 | 73 | # Wrapper sources needed for the runner. 74 | add_library(flutter_wrapper_app STATIC 75 | ${CPP_WRAPPER_SOURCES_CORE} 76 | ${CPP_WRAPPER_SOURCES_APP} 77 | ) 78 | apply_standard_settings(flutter_wrapper_app) 79 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 80 | target_include_directories(flutter_wrapper_app PUBLIC 81 | "${WRAPPER_ROOT}/include" 82 | ) 83 | add_dependencies(flutter_wrapper_app flutter_assemble) 84 | 85 | # === Flutter tool backend === 86 | # _phony_ is a non-existent file to force this command to run every time, 87 | # since currently there's no way to get a full input/output list from the 88 | # flutter tool. 89 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 90 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 91 | add_custom_command( 92 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 93 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 94 | ${CPP_WRAPPER_SOURCES_APP} 95 | ${PHONY_OUTPUT} 96 | COMMAND ${CMAKE_COMMAND} -E env 97 | ${FLUTTER_TOOL_ENVIRONMENT} 98 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 99 | ${FLUTTER_TARGET_PLATFORM} $ 100 | VERBATIM 101 | ) 102 | add_custom_target(flutter_assemble DEPENDS 103 | "${FLUTTER_LIBRARY}" 104 | ${FLUTTER_LIBRARY_HEADERS} 105 | ${CPP_WRAPPER_SOURCES_CORE} 106 | ${CPP_WRAPPER_SOURCES_PLUGIN} 107 | ${CPP_WRAPPER_SOURCES_APP} 108 | ) 109 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | linter: 2 | rules: 3 | # error 4 | avoid_empty_else: true 5 | avoid_print: true 6 | avoid_returning_null_for_future: true 7 | avoid_types_as_parameter_names: true 8 | avoid_web_libraries_in_flutter: true 9 | control_flow_in_finally: true 10 | empty_statements: true 11 | hash_and_equals: true 12 | iterable_contains_unrelated_type: true 13 | list_remove_unrelated_type: true 14 | no_duplicate_case_values: true 15 | no_logic_in_create_state: true 16 | prefer_relative_imports: true 17 | prefer_void_to_null: true 18 | throw_in_finally: true 19 | unnecessary_statements: true 20 | unrelated_type_equality_checks: true 21 | use_key_in_widget_constructors: true 22 | valid_regexps: true 23 | 24 | # style 25 | always_declare_return_types: true 26 | always_put_control_body_on_new_line: true 27 | always_require_non_null_named_parameters: true 28 | annotate_overrides: true 29 | avoid_bool_literals_in_conditional_expressions: true 30 | avoid_catches_without_on_clauses: true 31 | avoid_catching_errors: true 32 | avoid_final_parameters: true 33 | avoid_function_literals_in_foreach_calls: true 34 | avoid_init_to_null: true 35 | avoid_multiple_declarations_per_line: true 36 | avoid_null_checks_in_equality_operators: true 37 | avoid_private_typedef_functions: true 38 | avoid_return_types_on_setters: true 39 | avoid_returning_null_for_void: true 40 | avoid_returning_this: true 41 | avoid_shadowing_type_parameters: true 42 | avoid_single_cascade_in_expression_statements: true 43 | avoid_types_on_closure_parameters: true 44 | avoid_unnecessary_containers: true 45 | avoid_unused_constructor_parameters: true 46 | await_only_futures: true 47 | camel_case_extensions: true 48 | constant_identifier_names: true 49 | curly_braces_in_flow_control_structures: true 50 | directives_ordering: true 51 | empty_catches: true 52 | empty_constructor_bodies: true 53 | eol_at_end_of_file: true 54 | exhaustive_cases: true 55 | file_names: true 56 | implementation_imports: true 57 | library_names: true 58 | library_prefixes: true 59 | library_private_types_in_public_api: true 60 | non_constant_identifier_names: true 61 | null_closures: true 62 | overridden_fields: true 63 | package_api_docs: true 64 | package_prefixed_library_names: true 65 | prefer_collection_literals: true 66 | prefer_conditional_assignment: true 67 | prefer_const_constructors: true 68 | prefer_const_constructors_in_immutables: true 69 | prefer_const_declarations: true 70 | prefer_const_literals_to_create_immutables: true 71 | prefer_constructors_over_static_methods: true 72 | prefer_contains: true 73 | prefer_double_quotes: true 74 | prefer_equal_for_default_values: true 75 | prefer_expression_function_bodies: true 76 | prefer_final_fields: true 77 | prefer_for_elements_to_map_fromIterable: true 78 | prefer_function_declarations_over_variables: true 79 | prefer_generic_function_type_aliases: true 80 | prefer_if_elements_to_conditional_expressions: true 81 | prefer_if_null_operators: true 82 | prefer_initializing_formals: true 83 | prefer_inlined_adds: true 84 | prefer_interpolation_to_compose_strings: true 85 | prefer_is_empty: true 86 | prefer_is_not_empty: true 87 | prefer_is_not_operator: true 88 | prefer_iterable_whereType: true 89 | prefer_mixin: true 90 | prefer_null_aware_method_calls: true 91 | prefer_null_aware_operators: true 92 | prefer_spread_collections: true 93 | prefer_typing_uninitialized_variables: true 94 | provide_deprecation_message: true 95 | public_member_api_docs: true 96 | recursive_getters: true 97 | require_trailing_commas: true 98 | sized_box_for_whitespace: true 99 | slash_for_doc_comments: true 100 | sort_child_properties_last: true 101 | sort_unnamed_constructors_first: true 102 | type_annotate_public_apis: true 103 | type_init_formals: true 104 | unawaited_futures: true 105 | unnecessary_await_in_return: true 106 | unnecessary_brace_in_string_interps: true 107 | unnecessary_const: true 108 | unnecessary_final: true 109 | unnecessary_getters_setters: true 110 | unnecessary_late: true 111 | unnecessary_new: true 112 | unnecessary_null_aware_assignments: true 113 | unnecessary_null_checks: true 114 | unnecessary_null_in_if_null_operators: true 115 | unnecessary_overrides: true 116 | unnecessary_parenthesis: true 117 | unnecessary_string_escapes: true 118 | unnecessary_string_interpolations: true 119 | use_full_hex_values_for_flutter_colors: true 120 | use_function_type_syntax_for_parameters: true 121 | use_if_null_to_convert_nulls_to_bools: true 122 | use_is_even_rather_than_modulo: true 123 | use_named_constants: true 124 | use_rethrow_when_possible: true 125 | void_checks: true 126 | 127 | # pub 128 | package_names: true 129 | secure_pubspec_urls: true 130 | 131 | analyzer: 132 | language: 133 | strict-casts: true 134 | strict-inference: true 135 | strict-raw-types: true 136 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | namespace { 8 | 9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 10 | 11 | // The number of Win32Window objects that currently exist. 12 | static int g_active_window_count = 0; 13 | 14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 15 | 16 | // Scale helper to convert logical scaler values to physical using passed in 17 | // scale factor 18 | int Scale(int source, double scale_factor) { 19 | return static_cast(source * scale_factor); 20 | } 21 | 22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 23 | // This API is only needed for PerMonitor V1 awareness mode. 24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 25 | HMODULE user32_module = LoadLibraryA("User32.dll"); 26 | if (!user32_module) { 27 | return; 28 | } 29 | auto enable_non_client_dpi_scaling = 30 | reinterpret_cast( 31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 32 | if (enable_non_client_dpi_scaling != nullptr) { 33 | enable_non_client_dpi_scaling(hwnd); 34 | FreeLibrary(user32_module); 35 | } 36 | } 37 | 38 | } // namespace 39 | 40 | // Manages the Win32Window's window class registration. 41 | class WindowClassRegistrar { 42 | public: 43 | ~WindowClassRegistrar() = default; 44 | 45 | // Returns the singleton registar instance. 46 | static WindowClassRegistrar* GetInstance() { 47 | if (!instance_) { 48 | instance_ = new WindowClassRegistrar(); 49 | } 50 | return instance_; 51 | } 52 | 53 | // Returns the name of the window class, registering the class if it hasn't 54 | // previously been registered. 55 | const wchar_t* GetWindowClass(); 56 | 57 | // Unregisters the window class. Should only be called if there are no 58 | // instances of the window. 59 | void UnregisterWindowClass(); 60 | 61 | private: 62 | WindowClassRegistrar() = default; 63 | 64 | static WindowClassRegistrar* instance_; 65 | 66 | bool class_registered_ = false; 67 | }; 68 | 69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 70 | 71 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 72 | if (!class_registered_) { 73 | WNDCLASS window_class{}; 74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 75 | window_class.lpszClassName = kWindowClassName; 76 | window_class.style = CS_HREDRAW | CS_VREDRAW; 77 | window_class.cbClsExtra = 0; 78 | window_class.cbWndExtra = 0; 79 | window_class.hInstance = GetModuleHandle(nullptr); 80 | window_class.hIcon = 81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 82 | window_class.hbrBackground = 0; 83 | window_class.lpszMenuName = nullptr; 84 | window_class.lpfnWndProc = Win32Window::WndProc; 85 | RegisterClass(&window_class); 86 | class_registered_ = true; 87 | } 88 | return kWindowClassName; 89 | } 90 | 91 | void WindowClassRegistrar::UnregisterWindowClass() { 92 | UnregisterClass(kWindowClassName, nullptr); 93 | class_registered_ = false; 94 | } 95 | 96 | Win32Window::Win32Window() { 97 | ++g_active_window_count; 98 | } 99 | 100 | Win32Window::~Win32Window() { 101 | --g_active_window_count; 102 | Destroy(); 103 | } 104 | 105 | bool Win32Window::CreateAndShow(const std::wstring& title, 106 | const Point& origin, 107 | const Size& size) { 108 | Destroy(); 109 | 110 | const wchar_t* window_class = 111 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 112 | 113 | const POINT target_point = {static_cast(origin.x), 114 | static_cast(origin.y)}; 115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 117 | double scale_factor = dpi / 96.0; 118 | 119 | HWND window = CreateWindow( 120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 123 | nullptr, nullptr, GetModuleHandle(nullptr), this); 124 | 125 | if (!window) { 126 | return false; 127 | } 128 | 129 | return OnCreate(); 130 | } 131 | 132 | // static 133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 134 | UINT const message, 135 | WPARAM const wparam, 136 | LPARAM const lparam) noexcept { 137 | if (message == WM_NCCREATE) { 138 | auto window_struct = reinterpret_cast(lparam); 139 | SetWindowLongPtr(window, GWLP_USERDATA, 140 | reinterpret_cast(window_struct->lpCreateParams)); 141 | 142 | auto that = static_cast(window_struct->lpCreateParams); 143 | EnableFullDpiSupportIfAvailable(window); 144 | that->window_handle_ = window; 145 | } else if (Win32Window* that = GetThisFromHandle(window)) { 146 | return that->MessageHandler(window, message, wparam, lparam); 147 | } 148 | 149 | return DefWindowProc(window, message, wparam, lparam); 150 | } 151 | 152 | LRESULT 153 | Win32Window::MessageHandler(HWND hwnd, 154 | UINT const message, 155 | WPARAM const wparam, 156 | LPARAM const lparam) noexcept { 157 | switch (message) { 158 | case WM_DESTROY: 159 | window_handle_ = nullptr; 160 | Destroy(); 161 | if (quit_on_close_) { 162 | PostQuitMessage(0); 163 | } 164 | return 0; 165 | 166 | case WM_DPICHANGED: { 167 | auto newRectSize = reinterpret_cast(lparam); 168 | LONG newWidth = newRectSize->right - newRectSize->left; 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; 170 | 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 173 | 174 | return 0; 175 | } 176 | case WM_SIZE: { 177 | RECT rect = GetClientArea(); 178 | if (child_content_ != nullptr) { 179 | // Size and position the child window. 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 181 | rect.bottom - rect.top, TRUE); 182 | } 183 | return 0; 184 | } 185 | 186 | case WM_ACTIVATE: 187 | if (child_content_ != nullptr) { 188 | SetFocus(child_content_); 189 | } 190 | return 0; 191 | } 192 | 193 | return DefWindowProc(window_handle_, message, wparam, lparam); 194 | } 195 | 196 | void Win32Window::Destroy() { 197 | OnDestroy(); 198 | 199 | if (window_handle_) { 200 | DestroyWindow(window_handle_); 201 | window_handle_ = nullptr; 202 | } 203 | if (g_active_window_count == 0) { 204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 205 | } 206 | } 207 | 208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 209 | return reinterpret_cast( 210 | GetWindowLongPtr(window, GWLP_USERDATA)); 211 | } 212 | 213 | void Win32Window::SetChildContent(HWND content) { 214 | child_content_ = content; 215 | SetParent(content, window_handle_); 216 | RECT frame = GetClientArea(); 217 | 218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 219 | frame.bottom - frame.top, true); 220 | 221 | SetFocus(child_content_); 222 | } 223 | 224 | RECT Win32Window::GetClientArea() { 225 | RECT frame; 226 | GetClientRect(window_handle_, &frame); 227 | return frame; 228 | } 229 | 230 | HWND Win32Window::GetHandle() { 231 | return window_handle_; 232 | } 233 | 234 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 235 | quit_on_close_ = quit_on_close; 236 | } 237 | 238 | bool Win32Window::OnCreate() { 239 | // No-op; provided for subclasses. 240 | return true; 241 | } 242 | 243 | void Win32Window::OnDestroy() { 244 | // No-op; provided for subclasses. 245 | } 246 | -------------------------------------------------------------------------------- /example/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" 9 | url: "https://pub.dev" 10 | source: hosted 11 | version: "2.11.0" 12 | boolean_selector: 13 | dependency: transitive 14 | description: 15 | name: boolean_selector 16 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" 17 | url: "https://pub.dev" 18 | source: hosted 19 | version: "2.1.1" 20 | characters: 21 | dependency: transitive 22 | description: 23 | name: characters 24 | sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" 25 | url: "https://pub.dev" 26 | source: hosted 27 | version: "1.3.0" 28 | clock: 29 | dependency: transitive 30 | description: 31 | name: clock 32 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf 33 | url: "https://pub.dev" 34 | source: hosted 35 | version: "1.1.1" 36 | collection: 37 | dependency: transitive 38 | description: 39 | name: collection 40 | sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a 41 | url: "https://pub.dev" 42 | source: hosted 43 | version: "1.18.0" 44 | cupertino_icons: 45 | dependency: "direct main" 46 | description: 47 | name: cupertino_icons 48 | sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d 49 | url: "https://pub.dev" 50 | source: hosted 51 | version: "1.0.6" 52 | fake_async: 53 | dependency: transitive 54 | description: 55 | name: fake_async 56 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" 57 | url: "https://pub.dev" 58 | source: hosted 59 | version: "1.3.1" 60 | ffi: 61 | dependency: transitive 62 | description: 63 | name: ffi 64 | sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" 65 | url: "https://pub.dev" 66 | source: hosted 67 | version: "2.1.2" 68 | flame: 69 | dependency: "direct main" 70 | description: 71 | name: flame 72 | sha256: bb42a35fa5dabdea535daebe5b020e21a2fce8192b67b7e55cd30fed86d29f69 73 | url: "https://pub.dev" 74 | source: hosted 75 | version: "1.16.0" 76 | flame_steamworks: 77 | dependency: "direct main" 78 | description: 79 | path: ".." 80 | relative: true 81 | source: path 82 | version: "0.4.2" 83 | flutter: 84 | dependency: "direct main" 85 | description: flutter 86 | source: sdk 87 | version: "0.0.0" 88 | flutter_lints: 89 | dependency: "direct dev" 90 | description: 91 | name: flutter_lints 92 | sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493 93 | url: "https://pub.dev" 94 | source: hosted 95 | version: "1.0.4" 96 | flutter_test: 97 | dependency: "direct dev" 98 | description: flutter 99 | source: sdk 100 | version: "0.0.0" 101 | leak_tracker: 102 | dependency: transitive 103 | description: 104 | name: leak_tracker 105 | sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" 106 | url: "https://pub.dev" 107 | source: hosted 108 | version: "10.0.0" 109 | leak_tracker_flutter_testing: 110 | dependency: transitive 111 | description: 112 | name: leak_tracker_flutter_testing 113 | sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 114 | url: "https://pub.dev" 115 | source: hosted 116 | version: "2.0.1" 117 | leak_tracker_testing: 118 | dependency: transitive 119 | description: 120 | name: leak_tracker_testing 121 | sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 122 | url: "https://pub.dev" 123 | source: hosted 124 | version: "2.0.1" 125 | lints: 126 | dependency: transitive 127 | description: 128 | name: lints 129 | sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c 130 | url: "https://pub.dev" 131 | source: hosted 132 | version: "1.0.1" 133 | logging: 134 | dependency: transitive 135 | description: 136 | name: logging 137 | sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" 138 | url: "https://pub.dev" 139 | source: hosted 140 | version: "1.2.0" 141 | matcher: 142 | dependency: transitive 143 | description: 144 | name: matcher 145 | sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb 146 | url: "https://pub.dev" 147 | source: hosted 148 | version: "0.12.16+1" 149 | material_color_utilities: 150 | dependency: transitive 151 | description: 152 | name: material_color_utilities 153 | sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" 154 | url: "https://pub.dev" 155 | source: hosted 156 | version: "0.8.0" 157 | meta: 158 | dependency: transitive 159 | description: 160 | name: meta 161 | sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 162 | url: "https://pub.dev" 163 | source: hosted 164 | version: "1.11.0" 165 | ordered_set: 166 | dependency: transitive 167 | description: 168 | name: ordered_set 169 | sha256: "3858c7d84619edfab87c3e367584648020903187edb70b52697646f4b2a93022" 170 | url: "https://pub.dev" 171 | source: hosted 172 | version: "5.0.2" 173 | path: 174 | dependency: transitive 175 | description: 176 | name: path 177 | sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" 178 | url: "https://pub.dev" 179 | source: hosted 180 | version: "1.9.0" 181 | sky_engine: 182 | dependency: transitive 183 | description: flutter 184 | source: sdk 185 | version: "0.0.99" 186 | source_span: 187 | dependency: transitive 188 | description: 189 | name: source_span 190 | sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" 191 | url: "https://pub.dev" 192 | source: hosted 193 | version: "1.10.0" 194 | stack_trace: 195 | dependency: transitive 196 | description: 197 | name: stack_trace 198 | sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" 199 | url: "https://pub.dev" 200 | source: hosted 201 | version: "1.11.1" 202 | steamworks: 203 | dependency: transitive 204 | description: 205 | name: steamworks 206 | sha256: e98b3a58e947e7d6761a07cb97600ffa42bd0ddf8ecb1ac199b78a0a3c5e3760 207 | url: "https://pub.dev" 208 | source: hosted 209 | version: "0.4.6" 210 | stream_channel: 211 | dependency: transitive 212 | description: 213 | name: stream_channel 214 | sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 215 | url: "https://pub.dev" 216 | source: hosted 217 | version: "2.1.2" 218 | string_scanner: 219 | dependency: transitive 220 | description: 221 | name: string_scanner 222 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" 223 | url: "https://pub.dev" 224 | source: hosted 225 | version: "1.2.0" 226 | term_glyph: 227 | dependency: transitive 228 | description: 229 | name: term_glyph 230 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 231 | url: "https://pub.dev" 232 | source: hosted 233 | version: "1.2.1" 234 | test_api: 235 | dependency: transitive 236 | description: 237 | name: test_api 238 | sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" 239 | url: "https://pub.dev" 240 | source: hosted 241 | version: "0.6.1" 242 | vector_math: 243 | dependency: transitive 244 | description: 245 | name: vector_math 246 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" 247 | url: "https://pub.dev" 248 | source: hosted 249 | version: "2.1.4" 250 | vm_service: 251 | dependency: transitive 252 | description: 253 | name: vm_service 254 | sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 255 | url: "https://pub.dev" 256 | source: hosted 257 | version: "13.0.0" 258 | sdks: 259 | dart: ">=3.3.0-279.1.beta <4.0.0" 260 | flutter: ">=3.19.0" 261 | --------------------------------------------------------------------------------