]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/iui.h
set eol-style
[xonotic/netradiant.git] / include / iui.h
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //-----------------------------------------------------------------------------
23 //
24 // DESCRIPTION:
25 // interface for all-purpose messaging and UI
26 // window class for MFC, Gtk or Q3 UI
27 // each version of Radiant implements the API, using the native code that it needs
28
29 #ifndef __IUI_H_
30 #define __IUI_H_
31
32 // this one can be hooked in the GL window procs for customizing GUI through plugins
33 // the class is implemented by the plugin module, and given to Radiant who calls into it
34 class IWindowListener
35 {
36 public:
37   // Increment the number of references to this object
38   virtual void IncRef () = 0;
39   // Decrement the reference count
40   virtual void DecRef () = 0;
41   // since Radiant is MFC we don't use a WNDPROC, we wrap the MFC handlers
42   // the handler is called first, if returns false Radiant continues processing
43   //++timo maybe add more later ? OnKeyUp and OnKeyDown for instance
44   //++timo TODO: add handlers everywhere
45   // Gef: Changed 2nd & 3rd params to gdouble's for sub-integer grid sizes
46   virtual bool OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) = 0;
47   virtual bool OnMButtonDown(guint32 nFlags, gdouble x, gdouble y) = 0;
48   virtual bool OnRButtonDown(guint32 nFlags, gdouble x, gdouble y) = 0;
49   virtual bool OnLButtonUp(guint32 nFlags, gdouble x, gdouble y) = 0;
50   virtual bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) = 0;
51   virtual bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) = 0;
52   virtual bool OnMouseMove(guint32 nFlags, gdouble x, gdouble y) = 0;
53   virtual bool OnKeyPressed(char *s) = 0;
54
55   // paint message, the caller makes the GL context current, calls Paint, then swaps GL buffers
56   // return value might be false if something failed and closure is requested .. then the buffer swap will be cancelled
57   virtual bool Paint() = 0;
58   // window is closing (nothing you can do, just telling)
59   virtual void Close() = 0;
60 };
61
62 // IWindowListener with additional properties
63 // NOTE: for now it is both a window and the GL widget
64 //   in the case of Gtk, there are two widgets, the window widget (a container) and the GL widget
65 class IWindow
66 {
67 public:
68   // Increment the number of references to this object
69   virtual void IncRef () = 0;
70   // Decrement the reference count
71   virtual void DecRef () = 0;
72   // misc data ------------------------------------------------
73   // get pixel size
74   virtual int getHeight() = 0;
75   virtual int getWidth() = 0;
76   // initialisation stuff -------------------------------------
77   // set pixel size and other parameters before showing it
78   virtual void setSizeParm(int width, int height) = 0;
79   // set the IWindowListener (implemented by the plugin using this window)
80   virtual void setListener(IWindowListener *) = 0;
81   // set the window name
82   virtual void setName(char *) = 0;
83   // will actually create the GL and the window based on the parameters
84   virtual bool Show() = 0;
85   // commands -------------------------------------------------
86   // call this to ask for a Redraw
87   virtual void Redraw() = 0;
88 };
89
90 // various Radiant messages --------
91 // this one holds the total number of supported messages (this is used to allocate structs)
92 #define RADIANT_MSGCOUNT 5
93 // they start with a 0, can be indexed in an array
94 // something was selected / deselected
95 #define RADIANT_SELECTION 0
96 // a brush face was selected / deselected
97 #define RADIANT_SFACE     1
98 // current texture / shader changed
99 #define RADIANT_TEXTURE   2
100 // Radiant is going to enter "sleep mode" (all GL contexts will be destroyed)
101 #define RADIANT_SLEEP     3
102 // Radiant has left "sleep mode" (GL contexts are recreated)
103 #define RADIANT_WAKEUP    4
104
105
106 // this one can be used to listen for Radiant-specific events, not related to a window
107 class IListener
108 {
109 public:
110   // Increment the number of references to this object
111   virtual void IncRef () = 0;
112   // Decrement the reference count
113   virtual void DecRef () = 0;
114   // message is one of the RADIANT_* consts
115   virtual void DispatchRadiantMsg( int Msg ) = 0;
116 };
117
118 // this one is provided by Radiant, it's a wrapper for some usefull functions
119 class IXYWndWrapper
120 {
121 public:
122   virtual void SnapToGrid( int x1, int y1, vec3_t pt ) = 0;
123   virtual VIEWTYPE GetViewType( void ) = 0;
124 };
125
126 #define UI_MAJOR "ui"
127
128 // create an IWindow with GL context
129 typedef IWindow* (WINAPI* PFN_QERAPP_CREATEGLWINDOW) ();
130
131 // will hook the given IWindowListener to the XY window and increment the ref count
132 //++timo TODO: add hooking in the CAM view and Z view
133 typedef void (WINAPI* PFN_QERAPP_HOOKWINDOW)    (IWindowListener *);
134 // will unhook the given IWindowListener
135 typedef void (WINAPI* PFN_QERAPP_UNHOOKWINDOW)  (IWindowListener *);
136 // to retrieve the IXYWndWrapper
137 typedef IXYWndWrapper* (WINAPI* PFN_QERAPP_GETXYWNDWRAPPER)     ();
138
139 // will hook a given listener into Radiant listening for the given message and increment ref count
140 // call several times to listen for several messages
141 typedef void (WINAPI* PFN_QERAPP_HOOKLISTENER)  (IListener *, int Msg);
142 // will unhook the listener and return the number of messages the given listener was removed from
143 typedef int  (WINAPI* PFN_QERAPP_UNHOOKLISTENER)(IListener *);
144
145 // TODO: create GL widget, destroy it
146
147 struct _QERUITable
148 {
149   int m_nSize;
150   PFN_QERAPP_CREATEGLWINDOW m_pfnCreateGLWindow;
151   PFN_QERAPP_HOOKWINDOW         m_pfnHookWindow;
152   PFN_QERAPP_UNHOOKWINDOW       m_pfnUnHookWindow;
153   PFN_QERAPP_GETXYWNDWRAPPER    m_pfnGetXYWndWrapper;
154   PFN_QERAPP_HOOKLISTENER       m_pfnHookListener;
155   PFN_QERAPP_UNHOOKLISTENER     m_pfnUnHookListener;
156 };
157
158 #endif