File indexing completed on 2025-01-18 10:03:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef Draw_Window_HeaderFile
0018 #define Draw_Window_HeaderFile
0019
0020 #if defined(_WIN32)
0021 #include <windows.h>
0022 #endif
0023
0024 #include <Aspect_Drawable.hxx>
0025 #include <NCollection_Vec2.hxx>
0026 #include <TCollection_AsciiString.hxx>
0027
0028 #include <memory>
0029
0030 const Standard_Integer MAXCOLOR = 15;
0031
0032
0033 struct Draw_XSegment
0034 {
0035 NCollection_Vec2<short> Points[2];
0036
0037 NCollection_Vec2<short>& operator[](int theIndex) { return Points[theIndex]; }
0038 const NCollection_Vec2<short>& operator[](int theIndex) const { return Points[theIndex]; }
0039
0040 void Init (Standard_Integer theXStart, Standard_Integer theYStart, Standard_Integer theXEnd, Standard_Integer theYEnd)
0041 {
0042 Points[0].SetValues ((short )theXStart, (short )theYStart);
0043 Points[1].SetValues ((short )theXEnd, (short )theYEnd);
0044 }
0045 };
0046
0047 #if defined(_WIN32)
0048
0049 #define DRAWCLASS L"DRAWWINDOW"
0050 #define DRAWTITLE L"Draw View"
0051
0052 enum console_semaphore_value
0053 {
0054 STOP_CONSOLE,
0055 WAIT_CONSOLE_COMMAND,
0056 HAS_CONSOLE_COMMAND
0057 };
0058
0059
0060 extern console_semaphore_value volatile console_semaphore;
0061
0062
0063 #define DRAW_COMMAND_SIZE 1000
0064 extern wchar_t console_command[DRAW_COMMAND_SIZE + 1];
0065
0066
0067 Standard_EXPORT Standard_Boolean Init_Appli(HINSTANCE,HINSTANCE,int,HWND&);
0068 Standard_EXPORT void Run_Appli(HWND);
0069 Standard_EXPORT void Destroy_Appli(HINSTANCE);
0070
0071 #else
0072
0073
0074
0075 void Run_Appli (Standard_Boolean (*inteprete) (const char*));
0076
0077
0078 Standard_Boolean Init_Appli();
0079
0080
0081 void Destroy_Appli();
0082
0083 #if defined(HAVE_XLIB)
0084
0085 typedef unsigned long Window;
0086 typedef unsigned long Pixmap;
0087 typedef unsigned long Drawable;
0088
0089 #elif defined(__APPLE__)
0090 #ifdef __OBJC__
0091 @class NSView;
0092 @class NSWindow;
0093 @class NSImage;
0094 @class Draw_CocoaView;
0095 #else
0096 struct NSView;
0097 struct NSWindow;
0098 struct NSImage;
0099 struct Draw_CocoaView;
0100 #endif
0101 #endif
0102
0103 #endif
0104
0105
0106 class Draw_Window
0107 {
0108 public:
0109
0110
0111 typedef void (*FCallbackBeforeTerminate)();
0112
0113
0114
0115 Standard_EXPORT static void AddCallbackBeforeTerminate (FCallbackBeforeTerminate theCB);
0116
0117
0118 Standard_EXPORT static void RemoveCallbackBeforeTerminate (FCallbackBeforeTerminate theCB);
0119
0120
0121 Standard_EXPORT static Standard_Boolean DefineColor (const Standard_Integer theIndex,
0122 const char* theColorName);
0123
0124
0125 Standard_EXPORT static void Flush();
0126
0127 public:
0128
0129
0130 Standard_EXPORT virtual ~Draw_Window();
0131
0132
0133 Standard_EXPORT void GetPosition (Standard_Integer& thePosX,
0134 Standard_Integer& thePosY);
0135
0136
0137 Standard_EXPORT void SetPosition (Standard_Integer theNewXpos,
0138 Standard_Integer theNewYpos);
0139
0140
0141 Standard_EXPORT Standard_Integer HeightWin() const;
0142
0143
0144 Standard_EXPORT Standard_Integer WidthWin() const;
0145
0146
0147 Standard_EXPORT void SetDimension (Standard_Integer theNewDx,
0148 Standard_Integer theNewDy);
0149
0150
0151 Standard_EXPORT TCollection_AsciiString GetTitle() const;
0152
0153
0154 Standard_EXPORT void SetTitle (const TCollection_AsciiString& theTitle);
0155
0156
0157 Standard_EXPORT bool IsMapped() const;
0158
0159
0160 Standard_EXPORT void DisplayWindow();
0161
0162
0163 Standard_EXPORT void Hide();
0164
0165
0166 Standard_EXPORT void Destroy();
0167
0168
0169 Standard_EXPORT void Clear();
0170
0171
0172 Standard_Boolean GetUseBuffer() const { return myUseBuffer; }
0173
0174
0175 Standard_EXPORT void SetUseBuffer (Standard_Boolean theToUse);
0176
0177
0178
0179 Standard_EXPORT void SetColor (Standard_Integer theColor);
0180
0181
0182 Standard_EXPORT void SetMode (Standard_Integer theMode);
0183
0184
0185 Standard_EXPORT void DrawString (Standard_Integer theX, Standard_Integer theY,
0186 const char* theText);
0187
0188
0189 Standard_EXPORT void DrawSegments (const Draw_XSegment* theSegments,
0190 Standard_Integer theNumberOfElements);
0191
0192
0193 Standard_EXPORT void Redraw();
0194
0195
0196 Standard_EXPORT Standard_Boolean Save (const char* theFileName) const;
0197
0198
0199 virtual void WExpose() = 0;
0200
0201
0202 Standard_EXPORT void InitBuffer();
0203
0204 protected:
0205
0206
0207
0208
0209
0210
0211
0212 Standard_EXPORT Draw_Window (const char* theTitle,
0213 const NCollection_Vec2<int>& theXY,
0214 const NCollection_Vec2<int>& theSize,
0215 Aspect_Drawable theParent,
0216 Aspect_Drawable theWin);
0217
0218
0219 Standard_EXPORT void init (const NCollection_Vec2<int>& theXY,
0220 const NCollection_Vec2<int>& theSize);
0221
0222 public:
0223
0224 #if defined(_WIN32)
0225 Standard_Boolean IsEqualWindows (HANDLE theWindow) { return myWindow == theWindow; }
0226
0227 Standard_EXPORT static void SelectWait (HANDLE& theWindow, int& theX, int& theY, int& theButton);
0228 Standard_EXPORT static void SelectNoWait (HANDLE& theWindow, int& theX, int& theY, int& theButton);
0229
0230 Standard_EXPORT static LRESULT APIENTRY DrawProc (HWND, UINT, WPARAM, LPARAM);
0231 static HWND hWndClientMDI;
0232 #elif defined(HAVE_XLIB)
0233 Standard_Boolean IsEqualWindows (Window theWindow) { return myWindow == theWindow; }
0234
0235
0236 struct Draw_XEvent
0237 {
0238 Standard_Integer type;
0239 Window window;
0240 Standard_Integer button;
0241 Standard_Integer x;
0242 Standard_Integer y;
0243 };
0244
0245
0246 static void GetNextEvent (Draw_XEvent& theEvent);
0247
0248 void Wait (Standard_Boolean theToWait = Standard_True);
0249 #elif defined(__APPLE__)
0250 Standard_Boolean IsEqualWindows (const long theWindowNumber);
0251
0252 static void GetNextEvent (Standard_Boolean theWait,
0253 long& theWindowNumber,
0254 Standard_Integer& theX,
0255 Standard_Integer& theY,
0256 Standard_Integer& theButton);
0257 #endif
0258
0259 private:
0260
0261 #if defined(_WIN32)
0262 Standard_EXPORT static HWND createDrawWindow (HWND , int );
0263 Standard_EXPORT HDC getMemDC (HDC theWinDC);
0264 Standard_EXPORT void releaseMemDC(HDC theMemDC);
0265 #elif defined(HAVE_XLIB)
0266 Drawable GetDrawable() const { return myUseBuffer ? myImageBuffer : myWindow; }
0267 struct Base_Window;
0268 #endif
0269
0270 private:
0271
0272 #if defined(_WIN32)
0273 HWND myWindow;
0274 HBITMAP myMemHbm;
0275 HBITMAP myOldHbm;
0276 Standard_Integer myCurrPen;
0277 Standard_Integer myCurrMode;
0278 #elif defined(HAVE_XLIB)
0279 Window myWindow;
0280 Window myMother;
0281 Pixmap myImageBuffer;
0282 std::unique_ptr<Base_Window> myBase;
0283 #elif defined(__APPLE__)
0284 NSWindow* myWindow;
0285 Draw_CocoaView* myView;
0286 NSImage* myImageBuffer;
0287 #else
0288 Aspect_Drawable myWindow;
0289 #endif
0290 Standard_Integer myCurrentColor;
0291 Standard_Boolean myUseBuffer;
0292
0293 };
0294
0295 #endif