#include "gtkutil/widget.h"
#include "gtkutil/glwidget.h"
#include "gtkutil/filechooser.h"
+#include "gtkutil/cursor.h"
#include "gtkmisc.h"
#include "select.h"
#include "csg.h"
// draw label
glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
- glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
+ //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label ); //fails with GCC
+ //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, reinterpret_cast<const GLubyte*>( label ) ); //worx
+ GlobalOpenGL().drawString( label );
}
float fDiff( float f1, float f2 ){
bool show_blocks;
int blockSize;
- bool m_bCamXYUpdate;
+// bool m_bCamXYUpdate;
bool m_bChaseMouse;
bool m_bSizePaint;
show_blocks( false ),
- m_bCamXYUpdate( true ),
+// m_bCamXYUpdate( true ),
m_bChaseMouse( true ),
m_bSizePaint( true ),
void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
float old_scale = Scale();
ZoomIn();
- if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
+ if ( g_xywindow_globals.m_bZoomInToPointer ) {
float scale_diff = 1.0 / old_scale - 1.0 / Scale();
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
}
}
+void XYWnd::Redraw() {
+ if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
+ if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
+ GlobalOpenGL_debugAssertNoErrors();
+ XY_Draw();
+ GlobalOpenGL_debugAssertNoErrors();
+
+ m_XORRectangle.set( rectangle_t() );
+ }
+ glwidget_swap_buffers( m_gl_widget );
+ }
+}
+
VIEWTYPE GlobalXYWnd_getCurrentViewType(){
ASSERT_NOTNULL( g_pParentWnd );
ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
if ( event->type == GDK_BUTTON_PRESS ) {
+ gtk_widget_grab_focus( xywnd->GetWidget() );
+
if( !xywnd->Active() ){
g_pParentWnd->SetActiveXY( xywnd );
}
}
gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
+ gtk_widget_grab_focus( xywnd->GetWidget() );
+ ui::Window window = xywnd->m_parent ? xywnd->m_parent : MainFrame_getWindow();
+ if( !gtk_window_is_active( window ) )
+ gtk_window_present( window );
+
if( !xywnd->Active() ){
g_pParentWnd->SetActiveXY( xywnd );
}
}
gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
- if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
- if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
- GlobalOpenGL_debugAssertNoErrors();
- xywnd->XY_Draw();
- GlobalOpenGL_debugAssertNoErrors();
-
- xywnd->m_XORRectangle.set( rectangle_t() );
- }
- glwidget_swap_buffers( xywnd->GetWidget() );
- }
+ xywnd->Redraw();
return FALSE;
}
-
void XYWnd_CameraMoved( XYWnd& xywnd ){
- if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
+// if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
//XYWnd_Update( xywnd );
xywnd.UpdateCameraIcon();
- }
+// }
}
XYWnd::XYWnd() :
m_window_observer( NewWindowObserver() ),
m_XORRectangle( m_gl_widget ),
m_chasemouse_handler( 0 ){
+
m_bActive = false;
m_buttonstate = 0;
Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
- updateProjection();
- updateModelview();
+ // This reconstruct=false argument is used to avoid a circular dependency
+ // between modelview and projection initialization and a valgrind complaint
+ updateProjection( false );
+ updateModelview( false );
+ m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
}
}
+//#include "gtkutil/image.h"
+
+/* is called on every mouse move fraction; ain't good! */
void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
Vector3 mousePosition;
XY_ToPoint( x, y, mousePosition );
+#if 0 // NetRadiantCustom
+ if ( ClipMode() ) {
+ if( GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ){
+ GdkCursor *cursor;
+ cursor = gdk_cursor_new( GDK_CROSSHAIR );
+ //cursor = gdk_cursor_new( GDK_FLEUR );
+ gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
+ gdk_cursor_unref( cursor );
+ }
+ else{
+ GdkCursor *cursor;
+ cursor = gdk_cursor_new( GDK_HAND2 );
+// GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
+// cursor = gdk_cursor_new_from_pixbuf( gdk_display_get_default(), pixbuf, 0, 0 );
+// g_object_unref( pixbuf );
+ gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
+ gdk_cursor_unref( cursor );
+
+ }
+ }
+#else
if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
- GdkCursor *cursor;
- cursor = gdk_cursor_new( GDK_CROSSHAIR );
- gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
- gdk_cursor_unref( cursor );
+ set_cursor ( m_gl_widget, GDK_CROSSHAIR );
}
+#endif
else
{
- gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), 0 );
+ default_cursor( m_gl_widget );
}
}
}
unsigned int MoveCamera_buttons(){
- return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
+// return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
+ return RAD_CONTROL | RAD_MBUTTON;
}
void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
}
unsigned int OrientCamera_buttons(){
- if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
- return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
- }
+// if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
+// return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
+// }
return RAD_MBUTTON;
}
void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
+ //globalOutputStream() << Camera_getAngles( camwnd ) << " b4\n";
Vector3 point = g_vector3_identity;
xywnd->XY_ToPoint( x, y, point );
- xywnd->XY_SnapToGrid( point );
+ //xywnd->XY_SnapToGrid( point );
vector3_subtract( point, Camera_getOrigin( camwnd ) );
int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
if ( point[n1] || point[n2] ) {
Vector3 angles( Camera_getAngles( camwnd ) );
angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
+ if( angles[CAMERA_YAW] < 0 )
+ angles[CAMERA_YAW] = angles[CAMERA_YAW] + 360;
+ if ( nAngle == CAMERA_PITCH ){
+ if( fabs( angles[CAMERA_PITCH] ) > 90 ){
+ angles[CAMERA_PITCH] = ( angles[CAMERA_PITCH] > 0 ) ? ( -angles[CAMERA_PITCH] + 180 ) : ( -angles[CAMERA_PITCH] - 180 );
+ if( xywnd->GetViewType() == YZ ){
+ if( angles[CAMERA_YAW] < 180 ){
+ angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
+ }
+ }
+ else if( angles[CAMERA_YAW] < 90 || angles[CAMERA_YAW] > 270 ){
+ angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
+ }
+ }
+ else{
+ if( xywnd->GetViewType() == YZ ){
+ if( angles[CAMERA_YAW] > 180 ){
+ angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
+ }
+ }
+ else if( angles[CAMERA_YAW] > 90 && angles[CAMERA_YAW] < 270 ){
+ angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
+ }
+ }
+ }
Camera_setAngles( camwnd, angles );
}
+ //globalOutputStream() << Camera_getAngles( camwnd ) << "\n";
}
unsigned int SetCustomPivotOrigin_buttons(){
m_nNewBrushPressy = y;
m_bNewBrushDrag = true;
- GlobalUndoSystem().start();
}
void XYWnd::NewBrushDrag_End( int x, int y ){
}
if ( m_NewBrushDrag == 0 ) {
+ GlobalUndoSystem().start();
NodeSmartReference node( GlobalBrushCreator().createBrush() );
Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
}
else {
- GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), "There's already a worldspawn in your map!"
- "",
+ GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(),
+ "There's already a worldspawn in your map!",
"Info",
eMB_OK,
eMB_ICONDEFAULT );
};
void XYWnd::OnContextMenu(){
- if ( g_xywindow_globals.m_bRightClick == false ) {
- return;
- }
+// if ( g_xywindow_globals.m_bRightClick == false ) {
+// return;
+// }
if ( !m_mnuDrop ) { // first time, load it up
auto menu = m_mnuDrop = ui::Menu(ui::New);
Move_End();
}
m_move_started = true;
- g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
+ /* NetRadiantCustom did this instead:
+ g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this ); */
+ g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this );
m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
}
void XYWnd::Move_End(){
m_move_started = false;
- g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
+ /* NetRadiant did this instead:
+ g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false ); */
+ g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget, false );
g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
}
}
int g_dragZoom = 0;
+int g_zoom2x = 0;
+int g_zoom2y = 0;
void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
if ( y != 0 ) {
}
else
{
+ if ( g_xywindow_globals.m_bZoomInToPointer ) {
+ reinterpret_cast<XYWnd*>( data )->ZoomInWithMouse( g_zoom2x, g_zoom2y );
+ }
+ else{
reinterpret_cast<XYWnd*>( data )->ZoomIn();
+ }
g_dragZoom += 8;
}
}
return FALSE;
}
-void XYWnd::Zoom_Begin(){
+void XYWnd::Zoom_Begin( int x, int y ){
if ( m_zoom_started ) {
Zoom_End();
}
m_zoom_started = true;
g_dragZoom = 0;
- g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
+ g_zoom2x = x;
+ g_zoom2y = y;
+ /* NetRadiantCustom did this instead:
+ g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this ); */
+ g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
}
EntityCreate_MouseDown( x, y );
}
else if ( buttons == Zoom_buttons() ) {
- Zoom_Begin();
+ Zoom_Begin( x, y );
}
else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
Clipper_OnLButtonDown( x, y );
}
// control mbutton = move camera
- else if ( getButtonState() == MoveCamera_buttons() ) {
+ else if ( buttons == MoveCamera_buttons() ) {
XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
}
// mbutton = angle camera
- else if ( getButtonState() == OrientCamera_buttons() ) {
+ else if ( buttons == OrientCamera_buttons() ) {
XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
}
void WXY_BackgroundSelect( void ){
bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
+
+ ui::Window main_window = MainFrame_getWindow();
+
if ( !brushesSelected ) {
- ui::alert( ui::root, "You have to select some brushes to get the bounding box for.\n",
+ ui::alert( main_window, "You have to select some brushes to get the bounding box for.\n",
"No selection", ui::alert_type::OK, ui::alert_icon::Error );
return;
}
- const char *filename = MainFrame_getWindow().file_dialog( TRUE, "Background Image", NULL, NULL );
+ const char *filename = main_window.file_dialog( TRUE, "Background Image", NULL, NULL );
+
g_pParentWnd->ActiveXY()->XY_DisableBackground();
+
if ( filename ) {
g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
}
+
+ // Draw the background image immediately (do not wait for user input).
+ g_pParentWnd->ActiveXY()->Redraw();
}
/*
void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
Cam.fov = 48 / m_fScale;
Cam.box = 16 / m_fScale;
+// globalOutputStream() << "pitch " << angles[CAMERA_PITCH] << " yaw " << angles[CAMERA_YAW] << "\n";
if ( m_viewType == XY ) {
Cam.x = origin[0];
else if ( m_viewType == YZ ) {
Cam.x = origin[1];
Cam.y = origin[2];
- Cam.a = degrees_to_radians( angles[CAMERA_PITCH] );
+ Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] > 180 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
}
else
{
Cam.x = origin[0];
Cam.y = origin[2];
- Cam.a = degrees_to_radians( angles[CAMERA_PITCH] );
+ Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] < 270 && angles[CAMERA_YAW] > 90 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
}
//glColor3f( 0.0, 0.0, 1.0 );
XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
glDisable( GL_BLEND );
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
}
glDrawBuffer( GL_BACK );
Shader* m_state_selected;
};
-void XYWnd::updateProjection(){
+void XYWnd::updateProjection( bool reconstruct ){
m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
m_projection[15] = 1.0f;
+ if (reconstruct) {
m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
}
+}
// note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
-void XYWnd::updateModelview(){
+void XYWnd::updateModelview( bool reconstruct ){
int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
int nDim2 = ( m_viewType == XY ) ? 1 : 2;
m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
m_modelview[15] = 1;
+ if (reconstruct) {
m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
+ }
}
/*
glEnable( GL_BLEND );
glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glDisable( GL_BLEND );
Feedback_draw2D( m_viewType );
EntityClassMenu g_EntityClassMenu;
-
// Names
void ShowNamesToggle(){
GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
+// TargetNames
+void ShowTargetNamesToggle(){
+ GlobalEntityCreator().setShowTargetNames( !GlobalEntityCreator().getShowTargetNames() );
+ XY_UpdateAllWindows();
+}
+
+typedef FreeCaller<void(), ShowTargetNamesToggle> ShowTargetNamesToggleCaller;
+
+void ShowTargetNamesExport( const Callback<void(bool)> & importer ){
+ importer( GlobalEntityCreator().getShowTargetNames() );
+}
+
+typedef FreeCaller<void(const Callback<void(bool)> &), ShowTargetNamesExport> ShowTargetNamesExportCaller;
+
// Angles
void ShowAnglesToggle(){
GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
ToggleItem g_show_names( g_show_names_callback );
+ShowTargetNamesExportCaller g_show_targetnames_caller;
+Callback<void(const Callback<void(bool)> &)> g_show_targetnames_callback( g_show_targetnames_caller );
+ToggleItem g_show_targetnames( g_show_targetnames_callback );
+
ShowAnglesExportCaller g_show_angles_caller;
Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
ToggleItem g_show_angles( g_show_angles_callback );
GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
+ GlobalToggles_insert( "ShowTargetNames", ShowTargetNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_targetnames ) );
GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
//page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
- page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
+// page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
+ page.appendCheckBox( "", "Zoom In to Mouse pointer", g_xywindow_globals.m_bZoomInToPointer );
}
void Orthographic_constructPage( PreferenceGroup& group ){
PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
- GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
- GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", make_property_string( g_xywindow_globals.m_bImprovedWheelZoom ) );
+// GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
+ GlobalPreferenceSystem().registerPreference( "2DZoomInToPointer", make_property_string( g_xywindow_globals.m_bZoomInToPointer ) );
GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
- GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
+// GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );