]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/xywindow.cpp
radiant: fix windows build
[xonotic/netradiant.git] / radiant / xywindow.cpp
index 6b3d893b7f44dfcfe73264ac538c9c0db9cc7cd6..c06994c4fa90df0765d4ef1fae205952bd124c4a 100644 (file)
@@ -139,7 +139,9 @@ void ClipPoint::Draw( const char *label, float scale ){
 
        // 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 ){
@@ -545,7 +547,7 @@ void XYWnd::ZoomOut(){
 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;
@@ -569,6 +571,20 @@ void XYWnd::Redraw() {
        }
 }
 
+void XYWnd::FocusOnBounds( AABB& bounds ){
+       SetOrigin( bounds.origin );
+       int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
+       int nDim2 = ( m_viewType == XY ) ? 1 : 2;
+       if( bounds.extents[ nDim1 ] < 128.f )
+               bounds.extents[ nDim1 ] = 128.f;
+       if( bounds.extents[ nDim2 ] < 128.f )
+               bounds.extents[ nDim2 ] = 128.f;
+       float scale1 = Width() / ( 3.f * bounds.extents[ nDim1 ] );
+       float scale2 = Height() / ( 3.f * bounds.extents[ nDim2 ] );
+       SetScale( MIN( scale1, scale2 ) );
+
+}
+
 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
        ASSERT_NOTNULL( g_pParentWnd );
        ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
@@ -763,6 +779,8 @@ void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
 
 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 );
                }
@@ -802,6 +820,11 @@ void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
 }
 
 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 );
        }
@@ -995,12 +1018,37 @@ void XYWnd::Clipper_OnMouseMoved( int x, int y ){
        }
 }
 
+//#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 ) {
                set_cursor ( m_gl_widget, GDK_CROSSHAIR );
        }
+#endif
        else
        {
                default_cursor( m_gl_widget );
@@ -1299,6 +1347,8 @@ unsigned int Zoom_buttons(){
 }
 
 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 ) {
@@ -1311,7 +1361,12 @@ void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
                        }
                        else
                        {
-                               reinterpret_cast<XYWnd*>( data )->ZoomIn();
+                               if ( g_xywindow_globals.m_bZoomInToPointer ) {
+                                       reinterpret_cast<XYWnd*>( data )->ZoomInWithMouse( g_zoom2x, g_zoom2y );
+                               }
+                               else{
+                                       reinterpret_cast<XYWnd*>( data )->ZoomIn();
+                               }
                                g_dragZoom += 8;
                        }
                }
@@ -1323,12 +1378,14 @@ gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xy
        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_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 );
@@ -1377,7 +1434,7 @@ void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
                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 );
@@ -2697,7 +2754,7 @@ void XYWnd::OnEntityCreate( const char* item ){
 
 
 
-void GetFocusPosition( Vector3& position ){
+void GetCenterPosition( Vector3& position ){
        if ( GlobalSelectionSystem().countSelected() != 0 ) {
                Select_GetMid( position );
        }
@@ -2707,15 +2764,15 @@ void GetFocusPosition( Vector3& position ){
        }
 }
 
-void XYWnd_Focus( XYWnd* xywnd ){
+void XYWnd_Centralize( XYWnd* xywnd ){
        Vector3 position;
-       GetFocusPosition( position );
+       GetCenterPosition( position );
        xywnd->PositionView( position );
 }
 
-void XY_Split_Focus(){
+void XY_Split_Centralize(){
        Vector3 position;
-       GetFocusPosition( position );
+       GetCenterPosition( position );
        if ( g_pParentWnd->GetXYWnd() ) {
                g_pParentWnd->GetXYWnd()->PositionView( position );
        }
@@ -2727,10 +2784,52 @@ void XY_Split_Focus(){
        }
 }
 
+void XY_Centralize(){
+       if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
+               // centralize all
+               XY_Split_Centralize();
+               return;
+       }
+
+       XYWnd* xywnd = g_pParentWnd->GetXYWnd();
+       XYWnd_Centralize( xywnd );
+}
+
+
+
+void GetSelectionBbox( AABB& bounds ){
+       if ( GlobalSelectionSystem().countSelected() != 0 ) {
+               Scene_BoundsSelected( GlobalSceneGraph(), bounds );
+       }
+       else
+       {
+               bounds = AABB( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Vector3( 128.f, 128.f, 128.f ) );
+       }
+}
+
+void XYWnd_Focus( XYWnd* xywnd ){
+       AABB bounds;
+       GetSelectionBbox( bounds );
+       xywnd->FocusOnBounds( bounds );
+}
+
+void XY_Split_Focus(){
+       AABB bounds;
+       GetSelectionBbox( bounds );
+       if ( g_pParentWnd->GetXYWnd() ) {
+               g_pParentWnd->GetXYWnd()->FocusOnBounds( bounds );
+       }
+       if ( g_pParentWnd->GetXZWnd() ) {
+               g_pParentWnd->GetXZWnd()->FocusOnBounds( bounds );
+       }
+       if ( g_pParentWnd->GetYZWnd() ) {
+               g_pParentWnd->GetYZWnd()->FocusOnBounds( bounds );
+       }
+}
+
 void XY_Focus(){
        if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
-               // cannot do this in a split window
-               // do something else that the user may want here
+               // focus all
                XY_Split_Focus();
                return;
        }
@@ -2739,16 +2838,18 @@ void XY_Focus(){
        XYWnd_Focus( xywnd );
 }
 
+
+
 void XY_TopFrontSide( VIEWTYPE viewtype ){
        if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
                // cannot do this in a split window
                // do something else that the user may want here
-               XY_Split_Focus();
+               XY_Split_Centralize();
                return;
        }
        XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
        xywnd->SetViewType( viewtype );
-       XYWnd_Focus( xywnd );
+       XYWnd_Centralize( xywnd );
 }
 
 void XY_Top(){
@@ -2773,14 +2874,14 @@ void XY_NextView( XYWnd* xywnd ){
        else{
                xywnd->SetViewType( XY );
        }
-       XYWnd_Focus( xywnd );
+       XYWnd_Centralize( xywnd );
 }
 
 void XY_Next(){
        if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
                // cannot do this in a split window
                // do something else that the user may want here
-               XY_Split_Focus();
+               XY_Split_Centralize();
                return;
        }
        XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
@@ -2869,7 +2970,6 @@ void unrealise(){
 EntityClassMenu g_EntityClassMenu;
 
 
-
 // Names
 void ShowNamesToggle(){
        GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
@@ -2884,6 +2984,20 @@ void ShowNamesExport( const Callback<void(bool)> & importer ){
 
 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() );
@@ -3013,6 +3127,10 @@ ShowNamesExportCaller g_show_names_caller;
 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 );
@@ -3057,6 +3175,7 @@ void XYShow_registerCommands(){
 
        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 ) );
@@ -3076,6 +3195,7 @@ void Orthographic_constructPreferences( PreferencesPage& page ){
        //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( "", "Zoom In to Mouse pointer", g_xywindow_globals.m_bZoomInToPointer );
 }
 void Orthographic_constructPage( PreferenceGroup& group ){
        PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
@@ -3127,12 +3247,13 @@ void XYWindow_Construct(){
        GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
        GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
        GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
-       GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Centralize), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "XYFocusOnSelected", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_grave ) );
 
        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( "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 ) );
@@ -3157,8 +3278,6 @@ void XYWindow_Construct(){
        GlobalPreferenceSystem().registerPreference( "SI_Colors11", make_property_string( g_xywindow_globals.color_selbrushes ) );
 
 
-
-
        GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
        GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );