0032433: Visualization, TKService - introduce Wasm_Window implementing Aspect_Window...
[occt.git] / src / Aspect / Aspect_Window.hxx
1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Aspect_Window_HeaderFile
17 #define _Aspect_Window_HeaderFile
18
19 #include <Aspect_Background.hxx>
20 #include <Aspect_GradientBackground.hxx>
21 #include <Aspect_FBConfig.hxx>
22 #include <Aspect_FillMethod.hxx>
23 #include <Quantity_Color.hxx>
24 #include <Aspect_GradientFillMethod.hxx>
25 #include <Aspect_TypeOfResize.hxx>
26 #include <Aspect_Drawable.hxx>
27 #include <Graphic3d_Vec2.hxx>
28 #include <Standard.hxx>
29 #include <Standard_Transient.hxx>
30 #include <Standard_Type.hxx>
31 #include <TCollection_AsciiString.hxx>
32
33 class Aspect_DisplayConnection;
34
35 DEFINE_STANDARD_HANDLE(Aspect_Window, Standard_Transient)
36
37 //! Defines a window.
38 class Aspect_Window : public Standard_Transient
39 {
40   DEFINE_STANDARD_RTTIEXT(Aspect_Window, Standard_Transient)
41 public:
42
43   //! Modifies the window background.
44   Standard_EXPORT void SetBackground (const Aspect_Background& ABack);
45
46   //! Modifies the window background.
47   Standard_EXPORT void SetBackground (const Quantity_Color& color);
48
49   //! Modifies the window gradient background.
50   Standard_EXPORT void SetBackground (const Aspect_GradientBackground& ABackground);
51
52   //! Modifies the window gradient background.
53   Standard_EXPORT void SetBackground (const Quantity_Color& theFirstColor, const Quantity_Color& theSecondColor, const Aspect_GradientFillMethod theFillMethod);
54
55   //! Opens the window <me>.
56   Standard_EXPORT virtual void Map() const = 0;
57
58   //! Closes the window <me>.
59   Standard_EXPORT virtual void Unmap() const = 0;
60
61   //! Apply the resizing to the window <me>.
62   Standard_EXPORT virtual Aspect_TypeOfResize DoResize() = 0;
63
64   //! Apply the mapping change to the window <me>.
65   //! and returns TRUE if the window is mapped at screen.
66   Standard_EXPORT virtual Standard_Boolean DoMapping() const = 0;
67
68   //! Returns the window background.
69   Standard_EXPORT Aspect_Background Background() const;
70
71   //! Returns the current image background fill mode.
72   Standard_EXPORT Aspect_FillMethod BackgroundFillMethod() const;
73
74   //! Returns the window gradient background.
75   Standard_EXPORT Aspect_GradientBackground GradientBackground() const;
76
77   //! Returns True if the window <me> is opened
78   //! and False if the window is closed.
79   Standard_EXPORT virtual Standard_Boolean IsMapped() const = 0;
80
81   //! Returns True if the window <me> is virtual
82   Standard_EXPORT Standard_Boolean IsVirtual() const;
83
84   //! Setup the virtual state
85   Standard_EXPORT void SetVirtual (const Standard_Boolean theVirtual);
86
87   //! Returns The Window RATIO equal to the physical
88   //! WIDTH/HEIGHT dimensions
89   Standard_EXPORT virtual Standard_Real Ratio() const = 0;
90
91   //! Returns The Window POSITION in PIXEL
92   Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, Standard_Integer& Y2) const = 0;
93
94   //! Returns The Window SIZE in PIXEL
95   Standard_EXPORT virtual void Size (Standard_Integer& Width, Standard_Integer& Height) const = 0;
96
97   //! Returns native Window handle (HWND on Windows, Window with Xlib, and so on)
98   Standard_EXPORT virtual Aspect_Drawable NativeHandle() const = 0;
99
100   //! Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on)
101   Standard_EXPORT virtual Aspect_Drawable NativeParentHandle() const = 0;
102
103   //! Returns native Window FB config (GLXFBConfig on Xlib)
104   Standard_EXPORT virtual Aspect_FBConfig NativeFBConfig() const = 0;
105
106   //! Returns connection to Display or NULL.
107   const Handle(Aspect_DisplayConnection)& DisplayConnection() const { return myDisplay; }
108
109   //! Sets window title.
110   virtual void SetTitle (const TCollection_AsciiString& theTitle) { (void )theTitle; }
111
112   //! Invalidate entire window content.
113   //!
114   //! Implementation is expected to allow calling this method from non-GUI thread,
115   //! e.g. by queuing exposure event into window message queue or in other thread-safe manner.
116   //!
117   //! Optional display argument should be passed when called from non-GUI thread
118   //! on platforms implementing thread-unsafe connections to display.
119   //! NULL can be passed instead otherwise.
120   virtual void InvalidateContent (const Handle(Aspect_DisplayConnection)& theDisp) { (void )theDisp; }
121
122 public:
123
124   //! Return device pixel ratio (logical to backing store scale factor).
125   virtual Standard_Real DevicePixelRatio() const { return 1.0; }
126
127   //! Convert point from logical units into backing store units.
128   virtual Graphic3d_Vec2d ConvertPointToBacking (const Graphic3d_Vec2d& thePnt) const
129   {
130     return thePnt * DevicePixelRatio();
131   }
132
133   //! Convert point from backing store units to logical units.
134   virtual Graphic3d_Vec2d ConvertPointFromBacking (const Graphic3d_Vec2d& thePnt) const
135   {
136     return thePnt / DevicePixelRatio();
137   }
138
139 public:
140
141   //! Dumps the content of me into the stream
142   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
143
144 protected:
145
146   //! Initializes the data of a Window.
147   Standard_EXPORT Aspect_Window();
148
149 protected:
150
151   Handle(Aspect_DisplayConnection) myDisplay; //!< Display connection
152   Aspect_Background MyBackground;
153   Aspect_GradientBackground MyGradientBackground;
154   Aspect_FillMethod MyBackgroundFillMethod;
155   Standard_Boolean MyIsVirtual;
156
157 };
158
159 #endif // _Aspect_Window_HeaderFile