00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(INCLUDED_XYWINDOW_H)
00023 #define INCLUDED_XYWINDOW_H
00024
00025 #include "math/matrix.h"
00026 #include "signal/signal.h"
00027
00028 #include "gtkutil/cursor.h"
00029 #include "gtkutil/window.h"
00030 #include "gtkutil/xorrectangle.h"
00031 #include "../camera/view.h"
00032 #include "../map/map.h"
00033 #include "texturelib.h"
00034 #include <gtk/gtkmenuitem.h>
00035
00036
00037 const int XYWND_MINSIZE_X = 200;
00038 const int XYWND_MINSIZE_Y = 200;
00039
00040 #include "iradiant.h"
00041
00042 class Shader;
00043 class SelectionSystemWindowObserver;
00044 namespace scene
00045 {
00046 class Node;
00047 }
00048 typedef struct _GtkWindow GtkWindow;
00049 typedef struct _GtkMenu GtkMenu;
00050
00051 void FlipClip ();
00052 void SplitClip ();
00053 void Clip ();
00054 void OnClipMode (bool enabled);
00055 bool ClipMode ();
00056
00057 inline const char* ViewType_getTitle (EViewType viewtype)
00058 {
00059 if (viewtype == XY) {
00060 return "XY Top";
00061 }
00062 if (viewtype == XZ) {
00063 return "XZ Front";
00064 }
00065 if (viewtype == YZ) {
00066 return "YZ Side";
00067 }
00068 return "";
00069 }
00070
00071 class XYWnd
00072 {
00073 GtkWidget* m_gl_widget;
00074 guint m_sizeHandler;
00075 guint m_exposeHandler;
00076
00077 DeferredDraw m_deferredDraw;
00078 DeferredMotion m_deferred_motion;
00079 public:
00080 GtkWindow* m_parent;
00081 XYWnd ();
00082 ~XYWnd ();
00083
00084 void queueDraw ()
00085 {
00086 m_deferredDraw.draw();
00087 }
00088 GtkWidget* getWidget ()
00089 {
00090 return m_gl_widget;
00091 }
00092
00093 public:
00094 SelectionSystemWindowObserver* m_window_observer;
00095 XORRectangle m_XORRectangle;
00096
00097 static void captureStates ();
00098 static void releaseStates ();
00099
00100 void positionView (const Vector3& position);
00101 const Vector3& getOrigin ();
00102 void setOrigin (const Vector3& origin);
00103 void scroll (int x, int y);
00104
00105 void draw ();
00106 void drawCameraIcon (const Vector3& origin, const Vector3& angles);
00107 void drawBlockGrid ();
00108 void drawAxis ();
00109 void drawGrid ();
00110 void drawBackground ();
00111 void loadBackgroundImage (const std::string& name);
00112 void disableBackground ();
00113
00114 void XY_MouseUp (int x, int y, unsigned int buttons);
00115 void XY_MouseDown (int x, int y, unsigned int buttons);
00116 void XY_MouseMoved (int x, int y, unsigned int buttons);
00117
00118 void NewBrushDrag_Begin (int x, int y);
00119 void NewBrushDrag (int x, int y);
00120 void NewBrushDrag_End (int x, int y);
00121
00122 void XY_ToPoint (int x, int y, Vector3& point);
00123 void snapToGrid (Vector3& point);
00124
00125 void beginMove ();
00126 void endMove ();
00127 bool m_move_started;
00128 guint m_move_focusOut;
00129
00130 void beginZoom ();
00131 void endZoom ();
00132 bool m_zoom_started;
00133 guint m_zoom_focusOut;
00134
00135 void SetActive (bool b)
00136 {
00137 m_bActive = b;
00138 }
00139
00140 bool Active ()
00141 {
00142 return m_bActive;
00143 }
00144
00145 void Clipper_OnLButtonDown (int x, int y);
00146 void Clipper_OnLButtonUp (int x, int y);
00147 void Clipper_OnMouseMoved (int x, int y);
00148 void Clipper_Crosshair_OnMouseMoved (int x, int y);
00149 void DropClipPoint (int pointx, int pointy);
00150
00151 void setViewType (EViewType n);
00152 bool m_bActive;
00153
00154 int m_chasemouse_current_x, m_chasemouse_current_y;
00155 int m_chasemouse_delta_x, m_chasemouse_delta_y;
00156
00157 guint m_chasemouse_handler;
00158 void chaseMouse ();
00159 bool chaseMouseMotion (int pointx, int pointy);
00160
00161 void updateModelview ();
00162 void updateProjection ();
00163 Matrix4 m_projection;
00164 Matrix4 m_modelview;
00165
00166 int m_nWidth;
00167 int m_nHeight;
00168
00169
00170 qtexture_t *m_tex;
00171 bool m_backgroundActivated;
00172 float m_alpha;
00173 float m_xmin, m_ymin, m_xmax, m_ymax;
00174 private:
00175 float m_fScale;
00176 Vector3 m_vOrigin;
00177
00178 View m_view;
00179 static Shader* m_state_selected;
00180
00181 int m_ptCursorX, m_ptCursorY;
00182
00183 unsigned int m_buttonstate;
00184
00185 int m_nNewBrushPressx;
00186 int m_nNewBrushPressy;
00187 scene::Node* m_NewBrushDrag;
00188 bool m_bNewBrushDrag;
00189
00190 Vector3 m_mousePosition;
00191
00192 EViewType m_viewType;
00193
00194 void OriginalButtonUp (guint32 nFlags, int point, int pointy);
00195 void OriginalButtonDown (guint32 nFlags, int point, int pointy);
00196
00197 GtkMenuItem* m_mnitem_separator;
00198 GtkMenuItem* m_mnitem_connect;
00199 GtkMenuItem* m_mnitem_fitface;
00200 void OnContextMenu ();
00201 void PaintSizeInfo (int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds);
00202
00203 int m_entityCreate_x, m_entityCreate_y;
00204 bool m_entityCreate;
00205
00206 public:
00207 void ButtonState_onMouseDown (unsigned int buttons)
00208 {
00209 m_buttonstate |= buttons;
00210 }
00211 void ButtonState_onMouseUp (unsigned int buttons)
00212 {
00213 m_buttonstate &= ~buttons;
00214 }
00215 unsigned int getButtonState () const
00216 {
00217 return m_buttonstate;
00218 }
00219 void EntityCreate_MouseDown (int x, int y);
00220 void EntityCreate_MouseMove (int x, int y);
00221 void EntityCreate_MouseUp (int x, int y);
00222
00223 void onEntityCreate (const std::string& item);
00224 EViewType GetViewType ()
00225 {
00226 return m_viewType;
00227 }
00228 void SetScale (float f);
00229 float Scale ()
00230 {
00231 return m_fScale;
00232 }
00233 int Width ()
00234 {
00235 return m_nWidth;
00236 }
00237 int Height ()
00238 {
00239 return m_nHeight;
00240 }
00241
00242 Signal0 onDestroyed;
00243 Signal3<const WindowVector&, ButtonIdentifier, ModifierFlags> onMouseDown;
00244 void mouseDown (const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers);
00245 typedef Member3<XYWnd, const WindowVector&, ButtonIdentifier, ModifierFlags, void, &XYWnd::mouseDown>
00246 MouseDownCaller;
00247 };
00248
00249 inline void XYWnd_Update (XYWnd& xywnd)
00250 {
00251 xywnd.queueDraw();
00252 }
00253
00254 struct xywindow_globals_t
00255 {
00256 Vector3 color_gridback;
00257 Vector3 color_gridminor;
00258 Vector3 color_gridmajor;
00259 Vector3 color_gridblock;
00260 Vector3 color_gridtext;
00261 Vector3 color_brushes;
00262 Vector3 color_selbrushes;
00263 Vector3 color_clipper;
00264 Vector3 color_viewname;
00265 Vector3 color_gridminor_alt;
00266 Vector3 color_gridmajor_alt;
00267 Vector3 AxisColorX;
00268 Vector3 AxisColorY;
00269 Vector3 AxisColorZ;
00270
00271 bool m_bRightClick;
00272 bool m_bNoStipple;
00273
00274 xywindow_globals_t () :
00275 color_gridback(0.77f, 0.77f, 0.77f), color_gridminor(0.83f, 0.83f, 0.83f), color_gridmajor(0.89f, 0.89f,
00276 0.89f), color_gridblock(1.0f, 1.0f, 1.0f), color_gridtext(0.0f, 0.0f, 0.0f), color_brushes(0.0f,
00277 0.0f, 0.0f), color_selbrushes(1.0f, 0.0f, 0.0f), color_clipper(0.0f, 0.0f, 1.0f), color_viewname(
00278 0.5f, 0.0f, 0.75f), color_gridminor_alt(0.f, 0.f, 0.f), color_gridmajor_alt(0.f, 0.f, 0.f),
00279
00280 AxisColorX(1.f, 0.f, 0.f), AxisColorY(0.f, 1.f, 0.f), AxisColorZ(0.f, 0.f, 1.f), m_bRightClick(true),
00281 m_bNoStipple(false)
00282 {
00283 }
00284
00285 };
00286
00287 extern xywindow_globals_t g_xywindow_globals;
00288
00289 EViewType GlobalXYWnd_getCurrentViewType ();
00290
00291 typedef struct _GtkWindow GtkWindow;
00292 void XY_Top_Shown_Construct (GtkWindow* parent);
00293 void YZ_Side_Shown_Construct (GtkWindow* parent);
00294 void XZ_Front_Shown_Construct (GtkWindow* parent);
00295
00296 void XYWindow_Construct ();
00297 void XYWindow_Destroy ();
00298 void WXY_Print ();
00299 void WXY_BackgroundSelect ();
00300 void XYShow_registerCommands ();
00301 void XYWnd_registerShortcuts ();
00302
00303 #endif