• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_H_
6 #define FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include <flutter_glfw.h>
12 
13 #include "plugin_registrar.h"
14 
15 namespace flutter {
16 
17 // A data type for window position and size.
18 struct WindowFrame {
19   int left;
20   int top;
21   int width;
22   int height;
23 };
24 
25 // A window displaying Flutter content.
26 class FlutterWindow {
27  public:
FlutterWindow(FlutterDesktopWindowRef window)28   explicit FlutterWindow(FlutterDesktopWindowRef window) : window_(window) {}
29 
30   ~FlutterWindow() = default;
31 
32   // Prevent copying.
33   FlutterWindow(FlutterWindow const&) = delete;
34   FlutterWindow& operator=(FlutterWindow const&) = delete;
35 
36   // Enables or disables hover tracking.
37   //
38   // If hover is enabled, mouse movement will send hover events to the Flutter
39   // engine, rather than only tracking the mouse while the button is pressed.
40   // Defaults to off.
SetHoverEnabled(bool enabled)41   void SetHoverEnabled(bool enabled) {
42     FlutterDesktopWindowSetHoverEnabled(window_, enabled);
43   }
44 
45   // Sets the displayed title of the window.
SetTitle(const std::string & title)46   void SetTitle(const std::string& title) {
47     FlutterDesktopWindowSetTitle(window_, title.c_str());
48   }
49 
50   // Sets the displayed icon for the window.
51   //
52   // The pixel format is 32-bit RGBA. The provided image data only needs to be
53   // valid for the duration of the call to this method. Pass a nullptr to revert
54   // to the default icon.
SetIcon(uint8_t * pixel_data,int width,int height)55   void SetIcon(uint8_t* pixel_data, int width, int height) {
56     FlutterDesktopWindowSetIcon(window_, pixel_data, width, height);
57   }
58 
59   // Returns the frame of the window, including any decoration (e.g., title
60   // bar), in screen coordinates.
GetFrame()61   WindowFrame GetFrame() {
62     WindowFrame frame = {};
63     FlutterDesktopWindowGetFrame(window_, &frame.left, &frame.top, &frame.width,
64                                  &frame.height);
65     return frame;
66   }
67 
68   // Set the frame of the window, including any decoration (e.g., title
69   // bar), in screen coordinates.
SetFrame(const WindowFrame & frame)70   void SetFrame(const WindowFrame& frame) {
71     FlutterDesktopWindowSetFrame(window_, frame.left, frame.top, frame.width,
72                                  frame.height);
73   }
74 
75   // Returns the number of pixels per screen coordinate for the window.
76   //
77   // Flutter uses pixel coordinates, so this is the ratio of positions and sizes
78   // seen by Flutter as compared to the screen.
GetScaleFactor()79   double GetScaleFactor() {
80     return FlutterDesktopWindowGetScaleFactor(window_);
81   }
82 
83  private:
84   // Handle for interacting with the C API's window.
85   //
86   // Note: window_ is conceptually owned by the controller, not this object.
87   FlutterDesktopWindowRef window_;
88 };
89 
90 }  // namespace flutter
91 
92 #endif  // FLUTTER_SHELL_PLATFORM_GLFW_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_H_
93