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