2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
22 #include "patchmanip.h"
24 #include "debugging/debugging.h"
27 #include "iselection.h"
30 #include "math/vector.h"
31 #include "math/aabb.h"
32 #include "generic/callback.h"
34 #include "gtkutil/menu.h"
35 #include "gtkutil/image.h"
37 #include "mainframe.h"
41 #include "texwindow.h"
47 PatchCreator* g_patchCreator = 0;
49 void Scene_PatchConstructPrefab( scene::Graph& graph, const AABB aabb, const char* shader, EPatchPrefab eType, int axis, std::size_t width = 3, std::size_t height = 3 ){
51 GlobalSelectionSystem().setSelectedAll( false );
53 NodeSmartReference node( g_patchCreator->createPatch() );
54 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
56 Patch* patch = Node_getPatch( node );
57 patch->SetShader( shader );
59 patch->ConstructPrefab( aabb, eType, axis, width, height );
60 patch->controlPointsChanged();
63 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
64 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
65 patchpath.push( makeReference( node.get() ) );
66 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
70 void PatchAutoCapTexture( Patch& patch ) {
72 AABB box = patch.localAABB();
73 float x = box.extents.x();
74 float y = box.extents.y();
75 float z = box.extents.z();
77 int cap_direction = -1;
80 else if ( y < x && y < z )
82 else if ( z < x && z < x )
85 if ( cap_direction >= 0 )
86 patch.ProjectTexture(cap_direction);
88 patch.NaturalTexture();
91 void Patch_AutoCapTexture(){
92 UndoableCommand command( "patchAutoCapTexture" );
93 Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture );
97 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
98 if ( ( type == eCapEndCap || type == eCapIEndCap )
99 && patch.getWidth() != 5 ) {
100 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
103 if ( ( type == eCapBevel || type == eCapIBevel )
104 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
105 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
108 if ( type == eCapCylinder
109 && patch.getWidth() != 9 ) {
110 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
115 NodeSmartReference cap( g_patchCreator->createPatch() );
116 Node_getTraversable( instance.path().parent() )->insert( cap );
118 Patch* cap_patch = Node_getPatch( cap );
119 patch.MakeCap( cap_patch, type, ROW, true );
120 cap_patch->SetShader( shader );
121 PatchAutoCapTexture(*cap_patch);
123 scene::Path path( instance.path() );
125 path.push( makeReference( cap.get() ) );
126 selectPath( path, true );
130 NodeSmartReference cap( g_patchCreator->createPatch() );
131 Node_getTraversable( instance.path().parent() )->insert( cap );
133 Patch* cap_patch = Node_getPatch( cap );
134 patch.MakeCap( cap_patch, type, ROW, false );
135 cap_patch->SetShader( shader );
136 PatchAutoCapTexture(*cap_patch);
138 scene::Path path( instance.path() );
140 path.push( makeReference( cap.get() ) );
141 selectPath( path, true );
145 typedef std::vector<scene::Instance*> InstanceVector;
147 class PatchStoreInstance
149 InstanceVector& m_instances;
151 PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
153 void operator()( PatchInstance& patch ) const {
154 m_instances.push_back( &patch );
161 PATCHCAP_INVERTED_BEVEL,
162 PATCHCAP_INVERTED_ENDCAP,
166 EMessageBoxReturn DoCapDlg( ECapDialog *type );
168 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
171 if ( DoCapDlg( &nType ) == eIDOK ) {
175 case PATCHCAP_INVERTED_BEVEL:
181 case PATCHCAP_INVERTED_ENDCAP:
184 case PATCHCAP_ENDCAP:
187 case PATCHCAP_CYLINDER:
188 eType = eCapCylinder;
191 ERROR_MESSAGE( "invalid patch cap type" );
195 InstanceVector instances;
196 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
197 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
199 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
204 Patch* Scene_GetUltimateSelectedVisiblePatch(){
205 if ( GlobalSelectionSystem().countSelected() != 0 ) {
206 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
207 if ( node.visible() ) {
208 return Node_getPatch( node );
215 class PatchCapTexture
218 void operator()( Patch& patch ) const {
219 patch.ProjectTexture( Patch::m_CycleCapIndex );
223 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
224 Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
225 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
229 class PatchFlipTexture
233 PatchFlipTexture( int axis ) : m_axis( axis ){
235 void operator()( Patch& patch ) const {
236 patch.FlipTexture( m_axis );
240 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
241 Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
244 class PatchNaturalTexture
247 void operator()( Patch& patch ) const {
248 patch.NaturalTexture();
252 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
253 Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
258 class PatchInsertRemove
260 bool m_insert, m_column, m_first;
262 PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
264 void operator()( Patch& patch ) const {
265 patch.InsertRemove( m_insert, m_column, m_first );
269 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
270 Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
273 class PatchInvertMatrix
276 void operator()( Patch& patch ) const {
277 patch.InvertMatrix();
281 void Scene_PatchInvert_Selected( scene::Graph& graph ){
282 Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
285 class PatchRedisperse
287 EMatrixMajor m_major;
289 PatchRedisperse( EMatrixMajor major ) : m_major( major ){
291 void operator()( Patch& patch ) const {
292 patch.Redisperse( m_major );
296 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
297 Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
302 EMatrixMajor m_major;
304 PatchSmooth( EMatrixMajor major ) : m_major( major ){
306 void operator()( Patch& patch ) const {
307 patch.Smooth( m_major );
311 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
312 Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
315 class PatchTransposeMatrix
318 void operator()( Patch& patch ) const {
319 patch.TransposeMatrix();
323 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
324 Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
331 PatchSetShader( const char* name )
334 void operator()( Patch& patch ) const {
335 patch.SetShader( m_name );
339 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
340 Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
344 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
345 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
347 name = patch->GetShader();
351 class PatchSelectByShader
355 inline PatchSelectByShader( const char* name )
358 void operator()( PatchInstance& patch ) const {
359 if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
360 patch.setSelected( true );
365 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
366 Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
370 class PatchFindReplaceShader
373 const char* m_replace;
375 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
377 void operator()( Patch& patch ) const {
378 if ( shader_equal( patch.GetShader(), m_find ) ) {
379 patch.SetShader( m_replace );
384 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
385 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
388 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
389 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
393 AABB PatchCreator_getBounds(){
394 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
396 float gridSize = GetGridSize();
398 if ( aabb.extents[0] == 0 ) {
399 aabb.extents[0] = gridSize;
401 if ( aabb.extents[1] == 0 ) {
402 aabb.extents[1] = gridSize;
404 if ( aabb.extents[2] == 0 ) {
405 aabb.extents[2] = gridSize;
408 if ( aabb_valid( aabb ) ) {
411 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
414 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
416 void Patch_XactCylinder(){
417 UndoableCommand undo( "patchCreateXactCylinder" );
419 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
422 void Patch_XactSphere(){
423 UndoableCommand undo( "patchCreateXactSphere" );
425 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
428 void Patch_XactCone(){
429 UndoableCommand undo( "patchCreateXactCone" );
431 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
434 void Patch_Cylinder(){
435 UndoableCommand undo( "patchCreateCylinder" );
437 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
440 void Patch_DenseCylinder(){
441 UndoableCommand undo( "patchCreateDenseCylinder" );
443 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
446 void Patch_VeryDenseCylinder(){
447 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
449 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
452 void Patch_SquareCylinder(){
453 UndoableCommand undo( "patchCreateSquareCylinder" );
455 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
459 UndoableCommand undo( "patchCreateCaps" );
461 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
465 UndoableCommand undo( "patchCreateBevel" );
467 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
471 UndoableCommand undo( "patchCreateSphere" );
473 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
476 void Patch_SquareBevel(){
479 void Patch_SquareEndcap(){
483 UndoableCommand undo( "patchCreateCone" );
485 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
489 UndoableCommand undo( "patchCreatePlane" );
491 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
494 void Patch_InsertInsertColumn(){
495 UndoableCommand undo( "patchInsertColumns" );
497 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
500 void Patch_InsertAddColumn(){
501 UndoableCommand undo( "patchAddColumns" );
503 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
506 void Patch_InsertInsertRow(){
507 UndoableCommand undo( "patchInsertRows" );
509 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
512 void Patch_InsertAddRow(){
513 UndoableCommand undo( "patchAddRows" );
515 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
518 void Patch_DeleteFirstColumn(){
519 UndoableCommand undo( "patchDeleteFirstColumns" );
521 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
524 void Patch_DeleteLastColumn(){
525 UndoableCommand undo( "patchDeleteLastColumns" );
527 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
530 void Patch_DeleteFirstRow(){
531 UndoableCommand undo( "patchDeleteFirstRows" );
533 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
536 void Patch_DeleteLastRow(){
537 UndoableCommand undo( "patchDeleteLastRows" );
539 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
543 UndoableCommand undo( "patchInvert" );
545 Scene_PatchInvert_Selected( GlobalSceneGraph() );
548 void Patch_RedisperseRows(){
549 UndoableCommand undo( "patchRedisperseRows" );
551 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
554 void Patch_RedisperseCols(){
555 UndoableCommand undo( "patchRedisperseColumns" );
557 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
560 void Patch_SmoothRows(){
561 UndoableCommand undo( "patchSmoothRows" );
563 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
566 void Patch_SmoothCols(){
567 UndoableCommand undo( "patchSmoothColumns" );
569 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
572 void Patch_Transpose(){
573 UndoableCommand undo( "patchTranspose" );
575 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
579 // FIXME: add support for patch cap creation
580 // Patch_CapCurrent();
581 UndoableCommand undo( "patchCreateCaps" );
583 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
586 void Patch_CycleProjection(){
587 UndoableCommand undo( "patchCycleUVProjectionAxis" );
589 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
593 void Patch_OverlayOn(){
597 void Patch_OverlayOff(){
600 void Patch_FlipTextureX(){
601 UndoableCommand undo( "patchFlipTextureU" );
603 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
606 void Patch_FlipTextureY(){
607 UndoableCommand undo( "patchFlipTextureV" );
609 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
612 void Patch_NaturalTexture(){
613 UndoableCommand undo( "patchNaturalTexture" );
615 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
618 void Patch_CapTexture(){
619 UndoableCommand command( "patchCapTexture" );
621 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
624 void Patch_ResetTexture(){
626 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
627 UndoableCommand command( "patchTileTexture" );
628 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
632 void Patch_FitTexture(){
633 UndoableCommand command( "patchFitTexture" );
635 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
641 class filter_patch_all : public PatchFilter
644 bool filter( const Patch& patch ) const {
649 class filter_patch_shader : public PatchFilter
651 const char* m_shader;
653 filter_patch_shader( const char* shader ) : m_shader( shader ){
655 bool filter( const Patch& patch ) const {
656 return shader_equal( patch.GetShader(), m_shader );
660 class filter_patch_flags : public PatchFilter
664 filter_patch_flags( int flags ) : m_flags( flags ){
666 bool filter( const Patch& patch ) const {
667 return ( patch.getShaderFlags() & m_flags ) != 0;
672 filter_patch_all g_filter_patch_all;
673 filter_patch_shader g_filter_patch_clip( "textures/common/clip" );
674 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
675 filter_patch_flags g_filter_patch_translucent( QER_TRANS );
677 void PatchFilters_construct(){
678 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
679 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
680 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
681 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
685 #include "preferences.h"
687 void Patch_constructPreferences( PreferencesPage& page ){
688 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
690 void Patch_constructPage( PreferenceGroup& group ){
691 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
692 Patch_constructPreferences( page );
694 void Patch_registerPreferencesPage(){
695 PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
699 #include "preferencesystem.h"
701 void PatchPreferences_construct(){
702 GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) );
706 #include "generic/callback.h"
708 void Patch_registerCommands(){
709 GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
710 GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
711 GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
712 GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
713 GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
714 GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
715 GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
716 GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
717 GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
718 GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
719 GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
720 GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
721 GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
722 GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
723 GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
724 GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
725 GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
726 GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller<Patch_InsertInsertColumn>(), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
727 GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller<Patch_InsertAddColumn>() );
728 GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller<Patch_InsertInsertRow>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
729 GlobalCommands_insert( "PatchInsertAddRow", FreeCaller<Patch_InsertAddRow>() );
730 GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
731 GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
732 GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
733 GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>() );
734 GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
735 GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
736 GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
737 GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
738 GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
739 GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
740 GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
741 GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
742 GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
743 GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
746 void Patch_constructToolbar( GtkToolbar* toolbar ){
747 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.bmp", "CapCurrentCurve" );
750 void Patch_constructMenu( GtkMenu* menu ){
751 create_menu_item_with_mnemonic( menu, "Cylinder", "PatchCylinder" );
753 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
754 if ( g_Layout_enableDetachableMenus.m_value ) {
755 menu_tearoff( menu_in_menu );
757 create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
758 create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
759 create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
760 create_menu_item_with_mnemonic( menu_in_menu, "Exact Cylinder...", "PatchXactCylinder" );
762 menu_separator( menu );
763 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
764 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
766 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
767 if ( g_Layout_enableDetachableMenus.m_value ) {
768 menu_tearoff( menu_in_menu );
770 create_menu_item_with_mnemonic( menu_in_menu, "Square Endcap", "PatchSquareBevel" );
771 create_menu_item_with_mnemonic( menu_in_menu, "Square Bevel", "PatchSquareEndcap" );
773 menu_separator( menu );
774 create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
775 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
776 menu_separator( menu );
777 create_menu_item_with_mnemonic( menu, "Sphere", "PatchSphere" );
778 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
779 menu_separator( menu );
780 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
781 menu_separator( menu );
783 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert" );
784 if ( g_Layout_enableDetachableMenus.m_value ) {
785 menu_tearoff( menu_in_menu );
787 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
788 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
789 menu_separator( menu_in_menu );
790 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
791 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
794 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
795 if ( g_Layout_enableDetachableMenus.m_value ) {
796 menu_tearoff( menu_in_menu );
798 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn" );
799 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn" );
800 menu_separator( menu_in_menu );
801 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow" );
802 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow" );
804 menu_separator( menu );
806 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
807 if ( g_Layout_enableDetachableMenus.m_value ) {
808 menu_tearoff( menu_in_menu );
810 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
811 GtkMenu* menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
812 if ( g_Layout_enableDetachableMenus.m_value ) {
813 menu_tearoff( menu_3 );
815 create_menu_item_with_mnemonic( menu_3, "Rows", "RedisperseRows" );
816 create_menu_item_with_mnemonic( menu_3, "Columns", "RedisperseCols" );
817 GtkMenu* menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
818 if ( g_Layout_enableDetachableMenus.m_value ) {
819 menu_tearoff( menu_4 );
821 create_menu_item_with_mnemonic( menu_4, "Rows", "SmoothRows" );
822 create_menu_item_with_mnemonic( menu_4, "Columns", "SmoothCols" );
823 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
825 menu_separator( menu );
826 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
827 create_menu_item_with_mnemonic( menu, "Cycle Cap Texture", "CycleCapTexturePatch" );
828 menu_separator( menu );
830 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
831 if ( g_Layout_enableDetachableMenus.m_value ) {
832 menu_tearoff( menu_in_menu );
834 create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
835 create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
840 #include <gtk/gtkbox.h>
841 #include <gtk/gtktable.h>
842 #include <gtk/gtktogglebutton.h>
843 #include <gtk/gtkradiobutton.h>
844 #include <gtk/gtkcombobox.h>
845 #include <gtk/gtklabel.h>
846 #include "gtkutil/dialog.h"
847 #include "gtkutil/widget.h"
849 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
854 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
856 GtkAccelGroup* accel = gtk_accel_group_new();
857 gtk_window_add_accel_group( window, accel );
860 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
861 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
863 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
864 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
866 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
867 gtk_widget_show( GTK_WIDGET( label ) );
868 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
869 (GtkAttachOptions) ( GTK_FILL ),
870 (GtkAttachOptions) ( 0 ), 0, 0 );
871 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
874 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
875 gtk_widget_show( GTK_WIDGET( label ) );
876 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
877 (GtkAttachOptions) ( GTK_FILL ),
878 (GtkAttachOptions) ( 0 ), 0, 0 );
879 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
883 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
884 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
899 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
901 gtk_widget_show( GTK_WIDGET( combo ) );
902 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
903 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
904 (GtkAttachOptions) ( 0 ), 0, 0 );
909 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
910 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
925 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
927 gtk_widget_show( GTK_WIDGET( combo ) );
928 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
929 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
930 (GtkAttachOptions) ( 0 ), 0, 0 );
937 GtkVBox* vbox = create_dialog_vbox( 4 );
938 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
940 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
941 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
942 widget_make_default( GTK_WIDGET( button ) );
943 gtk_widget_grab_focus( GTK_WIDGET( button ) );
944 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
947 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
948 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
949 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
955 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
956 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
958 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
959 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
960 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
962 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
965 gtk_widget_destroy( GTK_WIDGET( window ) );
971 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
973 ModalDialogButton ok_button( dialog, eIDOK );
974 ModalDialogButton cancel_button( dialog, eIDCANCEL );
981 GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
983 GtkAccelGroup *accel_group = gtk_accel_group_new();
984 gtk_window_add_accel_group( window, accel_group );
987 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
988 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
991 // Gef: Added a vbox to contain the toggle buttons
992 GtkVBox* radio_vbox = create_dialog_vbox( 4 );
993 gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
996 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
997 gtk_widget_show( GTK_WIDGET( table ) );
998 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
999 gtk_table_set_row_spacings( table, 5 );
1000 gtk_table_set_col_spacings( table, 5 );
1003 GtkImage* image = new_local_image( "cap_bevel.bmp" );
1004 gtk_widget_show( GTK_WIDGET( image ) );
1005 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1006 (GtkAttachOptions) ( GTK_FILL ),
1007 (GtkAttachOptions) ( 0 ), 0, 0 );
1010 GtkImage* image = new_local_image( "cap_endcap.bmp" );
1011 gtk_widget_show( GTK_WIDGET( image ) );
1012 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1013 (GtkAttachOptions) ( GTK_FILL ),
1014 (GtkAttachOptions) ( 0 ), 0, 0 );
1017 GtkImage* image = new_local_image( "cap_ibevel.bmp" );
1018 gtk_widget_show( GTK_WIDGET( image ) );
1019 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1020 (GtkAttachOptions) ( GTK_FILL ),
1021 (GtkAttachOptions) ( 0 ), 0, 0 );
1024 GtkImage* image = new_local_image( "cap_iendcap.bmp" );
1025 gtk_widget_show( GTK_WIDGET( image ) );
1026 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1027 (GtkAttachOptions) ( GTK_FILL ),
1028 (GtkAttachOptions) ( 0 ), 0, 0 );
1031 GtkImage* image = new_local_image( "cap_cylinder.bmp" );
1032 gtk_widget_show( GTK_WIDGET( image ) );
1033 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1034 (GtkAttachOptions) ( GTK_FILL ),
1035 (GtkAttachOptions) ( 0 ), 0, 0 );
1040 GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1041 gtk_widget_show( button );
1042 gtk_table_attach( table, button, 1, 2, 0, 1,
1043 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1044 (GtkAttachOptions) ( 0 ), 0, 0 );
1045 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1050 GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1051 gtk_widget_show( button );
1052 gtk_table_attach( table, button, 1, 2, 1, 2,
1053 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1054 (GtkAttachOptions) ( 0 ), 0, 0 );
1055 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1060 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1061 gtk_widget_show( button );
1062 gtk_table_attach( table, button, 1, 2, 2, 3,
1063 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1064 (GtkAttachOptions) ( 0 ), 0, 0 );
1065 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1070 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1071 gtk_widget_show( button );
1072 gtk_table_attach( table, button, 1, 2, 3, 4,
1073 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1074 (GtkAttachOptions) ( 0 ), 0, 0 );
1075 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1080 GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1081 gtk_widget_show( button );
1082 gtk_table_attach( table, button, 1, 2, 4, 5,
1083 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1084 (GtkAttachOptions) ( 0 ), 0, 0 );
1085 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1093 GtkVBox* vbox = create_dialog_vbox( 4 );
1094 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1096 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1097 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1098 widget_make_default( GTK_WIDGET( button ) );
1099 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1102 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1103 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1104 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1109 // Initialize dialog
1110 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1112 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1113 if ( ret == eIDOK ) {
1114 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1115 *type = PATCHCAP_BEVEL;
1117 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1118 *type = PATCHCAP_ENDCAP;
1120 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1121 *type = PATCHCAP_INVERTED_BEVEL;
1123 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1124 *type = PATCHCAP_INVERTED_ENDCAP;
1126 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1127 *type = PATCHCAP_CYLINDER;
1131 gtk_widget_destroy( GTK_WIDGET( window ) );