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 );
71 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
72 if ( ( type == eCapEndCap || type == eCapIEndCap )
73 && patch.getWidth() != 5 ) {
74 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
77 if ( ( type == eCapBevel || type == eCapIBevel )
78 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
79 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
82 if ( type == eCapCylinder
83 && patch.getWidth() != 9 ) {
84 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
89 NodeSmartReference cap( g_patchCreator->createPatch() );
90 Node_getTraversable( instance.path().parent() )->insert( cap );
92 patch.MakeCap( Node_getPatch( cap ), type, ROW, true );
93 Node_getPatch( cap )->SetShader( shader );
95 scene::Path path( instance.path() );
97 path.push( makeReference( cap.get() ) );
98 selectPath( path, true );
102 NodeSmartReference cap( g_patchCreator->createPatch() );
103 Node_getTraversable( instance.path().parent() )->insert( cap );
105 patch.MakeCap( Node_getPatch( cap ), type, ROW, false );
106 Node_getPatch( cap )->SetShader( shader );
108 scene::Path path( instance.path() );
110 path.push( makeReference( cap.get() ) );
111 selectPath( path, true );
115 typedef std::vector<scene::Instance*> InstanceVector;
117 class PatchStoreInstance
119 InstanceVector& m_instances;
121 PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
123 void operator()( PatchInstance& patch ) const {
124 m_instances.push_back( &patch );
131 PATCHCAP_INVERTED_BEVEL,
132 PATCHCAP_INVERTED_ENDCAP,
136 EMessageBoxReturn DoCapDlg( ECapDialog *type );
138 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
141 if ( DoCapDlg( &nType ) == eIDOK ) {
145 case PATCHCAP_INVERTED_BEVEL:
151 case PATCHCAP_INVERTED_ENDCAP:
154 case PATCHCAP_ENDCAP:
157 case PATCHCAP_CYLINDER:
158 eType = eCapCylinder;
161 ERROR_MESSAGE( "invalid patch cap type" );
165 InstanceVector instances;
166 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
167 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
169 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
174 Patch* Scene_GetUltimateSelectedVisiblePatch(){
175 if ( GlobalSelectionSystem().countSelected() != 0 ) {
176 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
177 if ( node.visible() ) {
178 return Node_getPatch( node );
185 class PatchCapTexture
188 void operator()( Patch& patch ) const {
189 patch.ProjectTexture( Patch::m_CycleCapIndex );
193 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
194 Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
195 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
199 class PatchFlipTexture
203 PatchFlipTexture( int axis ) : m_axis( axis ){
205 void operator()( Patch& patch ) const {
206 patch.FlipTexture( m_axis );
210 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
211 Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
214 class PatchNaturalTexture
217 void operator()( Patch& patch ) const {
218 patch.NaturalTexture();
222 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
223 Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
228 class PatchInsertRemove
230 bool m_insert, m_column, m_first;
232 PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
234 void operator()( Patch& patch ) const {
235 patch.InsertRemove( m_insert, m_column, m_first );
239 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
240 Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
243 class PatchInvertMatrix
246 void operator()( Patch& patch ) const {
247 patch.InvertMatrix();
251 void Scene_PatchInvert_Selected( scene::Graph& graph ){
252 Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
255 class PatchRedisperse
257 EMatrixMajor m_major;
259 PatchRedisperse( EMatrixMajor major ) : m_major( major ){
261 void operator()( Patch& patch ) const {
262 patch.Redisperse( m_major );
266 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
267 Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
272 EMatrixMajor m_major;
274 PatchSmooth( EMatrixMajor major ) : m_major( major ){
276 void operator()( Patch& patch ) const {
277 patch.Smooth( m_major );
281 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
282 Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
285 class PatchTransposeMatrix
288 void operator()( Patch& patch ) const {
289 patch.TransposeMatrix();
293 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
294 Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
301 PatchSetShader( const char* name )
304 void operator()( Patch& patch ) const {
305 patch.SetShader( m_name );
309 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
310 Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
314 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
315 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
317 name = patch->GetShader();
321 class PatchSelectByShader
325 inline PatchSelectByShader( const char* name )
328 void operator()( PatchInstance& patch ) const {
329 if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
330 patch.setSelected( true );
335 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
336 Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
340 class PatchFindReplaceShader
343 const char* m_replace;
345 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
347 void operator()( Patch& patch ) const {
348 if ( shader_equal( patch.GetShader(), m_find ) ) {
349 patch.SetShader( m_replace );
354 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
355 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
358 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
359 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
363 AABB PatchCreator_getBounds(){
364 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
366 float gridSize = GetGridSize();
368 if ( aabb.extents[0] == 0 ) {
369 aabb.extents[0] = gridSize;
371 if ( aabb.extents[1] == 0 ) {
372 aabb.extents[1] = gridSize;
374 if ( aabb.extents[2] == 0 ) {
375 aabb.extents[2] = gridSize;
378 if ( aabb_valid( aabb ) ) {
381 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
384 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
386 void Patch_XactCylinder(){
387 UndoableCommand undo( "patchCreateXactCylinder" );
389 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
392 void Patch_XactSphere(){
393 UndoableCommand undo( "patchCreateXactSphere" );
395 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
398 void Patch_XactCone(){
399 UndoableCommand undo( "patchCreateXactCone" );
401 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
404 void Patch_Cylinder(){
405 UndoableCommand undo( "patchCreateCylinder" );
407 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
410 void Patch_DenseCylinder(){
411 UndoableCommand undo( "patchCreateDenseCylinder" );
413 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
416 void Patch_VeryDenseCylinder(){
417 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
419 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
422 void Patch_SquareCylinder(){
423 UndoableCommand undo( "patchCreateSquareCylinder" );
425 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
429 UndoableCommand undo( "patchCreateCaps" );
431 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
435 UndoableCommand undo( "patchCreateBevel" );
437 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
441 UndoableCommand undo( "patchCreateSphere" );
443 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
446 void Patch_SquareBevel(){
449 void Patch_SquareEndcap(){
453 UndoableCommand undo( "patchCreateCone" );
455 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
459 UndoableCommand undo( "patchCreatePlane" );
461 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
464 void Patch_InsertInsertColumn(){
465 UndoableCommand undo( "patchInsertColumns" );
467 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
470 void Patch_InsertAddColumn(){
471 UndoableCommand undo( "patchAddColumns" );
473 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
476 void Patch_InsertInsertRow(){
477 UndoableCommand undo( "patchInsertRows" );
479 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
482 void Patch_InsertAddRow(){
483 UndoableCommand undo( "patchAddRows" );
485 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
488 void Patch_DeleteFirstColumn(){
489 UndoableCommand undo( "patchDeleteFirstColumns" );
491 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
494 void Patch_DeleteLastColumn(){
495 UndoableCommand undo( "patchDeleteLastColumns" );
497 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
500 void Patch_DeleteFirstRow(){
501 UndoableCommand undo( "patchDeleteFirstRows" );
503 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
506 void Patch_DeleteLastRow(){
507 UndoableCommand undo( "patchDeleteLastRows" );
509 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
513 UndoableCommand undo( "patchInvert" );
515 Scene_PatchInvert_Selected( GlobalSceneGraph() );
518 void Patch_RedisperseRows(){
519 UndoableCommand undo( "patchRedisperseRows" );
521 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
524 void Patch_RedisperseCols(){
525 UndoableCommand undo( "patchRedisperseColumns" );
527 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
530 void Patch_SmoothRows(){
531 UndoableCommand undo( "patchSmoothRows" );
533 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
536 void Patch_SmoothCols(){
537 UndoableCommand undo( "patchSmoothColumns" );
539 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
542 void Patch_Transpose(){
543 UndoableCommand undo( "patchTranspose" );
545 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
549 // FIXME: add support for patch cap creation
550 // Patch_CapCurrent();
551 UndoableCommand undo( "patchCreateCaps" );
553 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
556 void Patch_CycleProjection(){
557 UndoableCommand undo( "patchCycleUVProjectionAxis" );
559 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
563 void Patch_OverlayOn(){
567 void Patch_OverlayOff(){
570 void Patch_FlipTextureX(){
571 UndoableCommand undo( "patchFlipTextureU" );
573 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
576 void Patch_FlipTextureY(){
577 UndoableCommand undo( "patchFlipTextureV" );
579 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
582 void Patch_NaturalTexture(){
583 UndoableCommand undo( "patchNaturalTexture" );
585 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
594 class filter_patch_all : public PatchFilter
597 bool filter( const Patch& patch ) const {
602 class filter_patch_shader : public PatchFilter
604 const char* m_shader;
606 filter_patch_shader( const char* shader ) : m_shader( shader ){
608 bool filter( const Patch& patch ) const {
609 return shader_equal( patch.GetShader(), m_shader );
613 class filter_patch_flags : public PatchFilter
617 filter_patch_flags( int flags ) : m_flags( flags ){
619 bool filter( const Patch& patch ) const {
620 return ( patch.getShaderFlags() & m_flags ) != 0;
625 filter_patch_all g_filter_patch_all;
626 filter_patch_shader g_filter_patch_clip( "textures/common/clip" );
627 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
628 filter_patch_flags g_filter_patch_translucent( QER_TRANS );
630 void PatchFilters_construct(){
631 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
632 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
633 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
634 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
638 #include "preferences.h"
640 void Patch_constructPreferences( PreferencesPage& page ){
641 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
643 void Patch_constructPage( PreferenceGroup& group ){
644 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
645 Patch_constructPreferences( page );
647 void Patch_registerPreferencesPage(){
648 PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
652 #include "preferencesystem.h"
654 void PatchPreferences_construct(){
655 GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) );
659 #include "generic/callback.h"
661 void Patch_registerCommands(){
662 GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
663 GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
664 GlobalCommands_insert( "IncPatchColumn", FreeCaller<Patch_InsertInsertColumn>(), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
665 GlobalCommands_insert( "IncPatchRow", FreeCaller<Patch_InsertInsertRow>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
666 GlobalCommands_insert( "DecPatchColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
667 GlobalCommands_insert( "DecPatchRow", FreeCaller<Patch_DeleteLastRow>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
668 GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
669 GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
670 GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
671 GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
672 GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
673 GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
674 GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
675 GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
676 GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
677 GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
678 GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
679 GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
680 GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
681 GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
682 GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
683 GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller<Patch_InsertInsertColumn>() );
684 GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller<Patch_InsertAddColumn>() );
685 GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller<Patch_InsertInsertRow>() );
686 GlobalCommands_insert( "PatchInsertAddRow", FreeCaller<Patch_InsertAddRow>() );
687 GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
688 GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>() );
689 GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>() );
690 GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>() );
691 GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
692 GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
693 GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
694 GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
695 GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
696 GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
697 GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
698 GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
699 GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
700 GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
703 void Patch_constructToolbar( GtkToolbar* toolbar ){
704 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "cap_curve.png", "CapCurrentCurve" );
707 void Patch_constructMenu( GtkMenu* menu ){
708 create_menu_item_with_mnemonic( menu, "Cylinder", "PatchCylinder" );
710 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
711 if ( g_Layout_enableDetachableMenus.m_value ) {
712 menu_tearoff( menu_in_menu );
714 create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
715 create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
716 create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
717 create_menu_item_with_mnemonic( menu_in_menu, "Exact Cylinder...", "PatchXactCylinder" );
719 menu_separator( menu );
720 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
721 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
723 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
724 if ( g_Layout_enableDetachableMenus.m_value ) {
725 menu_tearoff( menu_in_menu );
727 create_menu_item_with_mnemonic( menu_in_menu, "Square Endcap", "PatchSquareBevel" );
728 create_menu_item_with_mnemonic( menu_in_menu, "Square Bevel", "PatchSquareEndcap" );
730 menu_separator( menu );
731 create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
732 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
733 menu_separator( menu );
734 create_menu_item_with_mnemonic( menu, "Sphere", "PatchSphere" );
735 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
736 menu_separator( menu );
737 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
738 menu_separator( menu );
740 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert" );
741 if ( g_Layout_enableDetachableMenus.m_value ) {
742 menu_tearoff( menu_in_menu );
744 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
745 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
746 menu_separator( menu_in_menu );
747 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
748 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
751 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
752 if ( g_Layout_enableDetachableMenus.m_value ) {
753 menu_tearoff( menu_in_menu );
755 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn" );
756 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn" );
757 menu_separator( menu_in_menu );
758 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow" );
759 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow" );
761 menu_separator( menu );
763 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
764 if ( g_Layout_enableDetachableMenus.m_value ) {
765 menu_tearoff( menu_in_menu );
767 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
768 GtkMenu* menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
769 if ( g_Layout_enableDetachableMenus.m_value ) {
770 menu_tearoff( menu_3 );
772 create_menu_item_with_mnemonic( menu_3, "Rows", "RedisperseRows" );
773 create_menu_item_with_mnemonic( menu_3, "Columns", "RedisperseCols" );
774 GtkMenu* menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
775 if ( g_Layout_enableDetachableMenus.m_value ) {
776 menu_tearoff( menu_4 );
778 create_menu_item_with_mnemonic( menu_4, "Rows", "SmoothRows" );
779 create_menu_item_with_mnemonic( menu_4, "Columns", "SmoothCols" );
780 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
782 menu_separator( menu );
783 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
784 create_menu_item_with_mnemonic( menu, "Cycle Cap Texture", "CycleCapTexturePatch" );
785 menu_separator( menu );
787 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
788 if ( g_Layout_enableDetachableMenus.m_value ) {
789 menu_tearoff( menu_in_menu );
791 create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
792 create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
797 #include <gtk/gtkbox.h>
798 #include <gtk/gtktable.h>
799 #include <gtk/gtktogglebutton.h>
800 #include <gtk/gtkradiobutton.h>
801 #include <gtk/gtkcombobox.h>
802 #include <gtk/gtklabel.h>
803 #include "gtkutil/dialog.h"
804 #include "gtkutil/widget.h"
806 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
811 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
813 GtkAccelGroup* accel = gtk_accel_group_new();
814 gtk_window_add_accel_group( window, accel );
817 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
818 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
820 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
821 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
823 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
824 gtk_widget_show( GTK_WIDGET( label ) );
825 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
826 (GtkAttachOptions) ( GTK_FILL ),
827 (GtkAttachOptions) ( 0 ), 0, 0 );
828 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
831 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
832 gtk_widget_show( GTK_WIDGET( label ) );
833 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
834 (GtkAttachOptions) ( GTK_FILL ),
835 (GtkAttachOptions) ( 0 ), 0, 0 );
836 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
840 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
841 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
856 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
858 gtk_widget_show( GTK_WIDGET( combo ) );
859 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
860 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
861 (GtkAttachOptions) ( 0 ), 0, 0 );
866 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
867 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
882 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
884 gtk_widget_show( GTK_WIDGET( combo ) );
885 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
886 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
887 (GtkAttachOptions) ( 0 ), 0, 0 );
894 GtkVBox* vbox = create_dialog_vbox( 4 );
895 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
897 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
898 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
899 widget_make_default( GTK_WIDGET( button ) );
900 gtk_widget_grab_focus( GTK_WIDGET( button ) );
901 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
904 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
905 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
906 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
912 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
913 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
915 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
916 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
917 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
919 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
922 gtk_widget_destroy( GTK_WIDGET( window ) );
928 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
930 ModalDialogButton ok_button( dialog, eIDOK );
931 ModalDialogButton cancel_button( dialog, eIDCANCEL );
938 GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
940 GtkAccelGroup *accel_group = gtk_accel_group_new();
941 gtk_window_add_accel_group( window, accel_group );
944 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
945 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
948 // Gef: Added a vbox to contain the toggle buttons
949 GtkVBox* radio_vbox = create_dialog_vbox( 4 );
950 gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
953 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
954 gtk_widget_show( GTK_WIDGET( table ) );
955 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
956 gtk_table_set_row_spacings( table, 5 );
957 gtk_table_set_col_spacings( table, 5 );
960 GtkImage* image = new_local_image( "cap_bevel.png" );
961 gtk_widget_show( GTK_WIDGET( image ) );
962 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
963 (GtkAttachOptions) ( GTK_FILL ),
964 (GtkAttachOptions) ( 0 ), 0, 0 );
967 GtkImage* image = new_local_image( "cap_endcap.png" );
968 gtk_widget_show( GTK_WIDGET( image ) );
969 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
970 (GtkAttachOptions) ( GTK_FILL ),
971 (GtkAttachOptions) ( 0 ), 0, 0 );
974 GtkImage* image = new_local_image( "cap_ibevel.png" );
975 gtk_widget_show( GTK_WIDGET( image ) );
976 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
977 (GtkAttachOptions) ( GTK_FILL ),
978 (GtkAttachOptions) ( 0 ), 0, 0 );
981 GtkImage* image = new_local_image( "cap_iendcap.png" );
982 gtk_widget_show( GTK_WIDGET( image ) );
983 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
984 (GtkAttachOptions) ( GTK_FILL ),
985 (GtkAttachOptions) ( 0 ), 0, 0 );
988 GtkImage* image = new_local_image( "cap_cylinder.png" );
989 gtk_widget_show( GTK_WIDGET( image ) );
990 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
991 (GtkAttachOptions) ( GTK_FILL ),
992 (GtkAttachOptions) ( 0 ), 0, 0 );
997 GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
998 gtk_widget_show( button );
999 gtk_table_attach( table, button, 1, 2, 0, 1,
1000 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1001 (GtkAttachOptions) ( 0 ), 0, 0 );
1002 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1007 GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1008 gtk_widget_show( button );
1009 gtk_table_attach( table, button, 1, 2, 1, 2,
1010 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1011 (GtkAttachOptions) ( 0 ), 0, 0 );
1012 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1017 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1018 gtk_widget_show( button );
1019 gtk_table_attach( table, button, 1, 2, 2, 3,
1020 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1021 (GtkAttachOptions) ( 0 ), 0, 0 );
1022 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1027 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1028 gtk_widget_show( button );
1029 gtk_table_attach( table, button, 1, 2, 3, 4,
1030 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1031 (GtkAttachOptions) ( 0 ), 0, 0 );
1032 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1037 GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1038 gtk_widget_show( button );
1039 gtk_table_attach( table, button, 1, 2, 4, 5,
1040 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1041 (GtkAttachOptions) ( 0 ), 0, 0 );
1042 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1050 GtkVBox* vbox = create_dialog_vbox( 4 );
1051 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1053 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1054 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1055 widget_make_default( GTK_WIDGET( button ) );
1056 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1059 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1060 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1061 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1066 // Initialize dialog
1067 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1069 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1070 if ( ret == eIDOK ) {
1071 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1072 *type = PATCHCAP_BEVEL;
1074 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1075 *type = PATCHCAP_ENDCAP;
1077 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1078 *type = PATCHCAP_INVERTED_BEVEL;
1080 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1081 *type = PATCHCAP_INVERTED_ENDCAP;
1083 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1084 *type = PATCHCAP_CYLINDER;
1088 gtk_widget_destroy( GTK_WIDGET( window ) );