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"
25 #include <gdk/gdkkeysyms.h>
27 #include "debugging/debugging.h"
30 #include "iselection.h"
33 #include "math/vector.h"
34 #include "math/aabb.h"
35 #include "generic/callback.h"
37 #include "gtkutil/menu.h"
38 #include "gtkutil/image.h"
40 #include "mainframe.h"
44 #include "texwindow.h"
50 PatchCreator* g_patchCreator = 0;
52 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, bool redisperse = false ){
54 GlobalSelectionSystem().setSelectedAll( false );
56 NodeSmartReference node( g_patchCreator->createPatch() );
57 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
59 Patch* patch = Node_getPatch( node );
60 patch->SetShader( shader );
62 patch->ConstructPrefab( aabb, eType, axis, width, height );
64 patch->Redisperse( COL );
65 patch->Redisperse( ROW );
67 patch->controlPointsChanged();
70 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
71 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
72 patchpath.push( makeReference( node.get() ) );
73 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
77 void PatchAutoCapTexture( Patch& patch ) {
79 AABB box = patch.localAABB();
80 float x = box.extents.x();
81 float y = box.extents.y();
82 float z = box.extents.z();
84 int cap_direction = -1;
87 else if ( y < x && y < z )
89 else if ( z < x && z < x )
92 if ( cap_direction >= 0 )
93 patch.ProjectTexture(cap_direction);
95 patch.NaturalTexture();
98 void Patch_AutoCapTexture(){
99 UndoableCommand command( "patchAutoCapTexture" );
100 Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture );
104 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
105 if ( ( type == eCapEndCap || type == eCapIEndCap )
106 && patch.getWidth() != 5 ) {
107 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
110 if ( ( type == eCapBevel || type == eCapIBevel )
111 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
112 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
115 if ( type == eCapCylinder
116 && patch.getWidth() != 9 ) {
117 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
122 NodeSmartReference cap( g_patchCreator->createPatch() );
123 Node_getTraversable( instance.path().parent() )->insert( cap );
125 Patch* cap_patch = Node_getPatch( cap );
126 patch.MakeCap( cap_patch, type, ROW, true );
127 cap_patch->SetShader( shader );
128 PatchAutoCapTexture(*cap_patch);
130 scene::Path path( instance.path() );
132 path.push( makeReference( cap.get() ) );
133 selectPath( path, true );
137 NodeSmartReference cap( g_patchCreator->createPatch() );
138 Node_getTraversable( instance.path().parent() )->insert( cap );
140 Patch* cap_patch = Node_getPatch( cap );
141 patch.MakeCap( cap_patch, type, ROW, false );
142 cap_patch->SetShader( shader );
143 PatchAutoCapTexture(*cap_patch);
145 scene::Path path( instance.path() );
147 path.push( makeReference( cap.get() ) );
148 selectPath( path, true );
153 typedef std::vector<scene::Instance*> InstanceVector;
158 PATCHCAP_INVERTED_BEVEL,
159 PATCHCAP_INVERTED_ENDCAP,
163 EMessageBoxReturn DoCapDlg( ECapDialog *type );
165 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
168 if ( DoCapDlg( &nType ) == eIDOK ) {
172 case PATCHCAP_INVERTED_BEVEL:
178 case PATCHCAP_INVERTED_ENDCAP:
181 case PATCHCAP_ENDCAP:
184 case PATCHCAP_CYLINDER:
185 eType = eCapCylinder;
188 ERROR_MESSAGE( "invalid patch cap type" );
192 InstanceVector instances;
193 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
194 instances.push_back(&patch);
196 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
198 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
203 void Patch_deform( Patch& patch, scene::Instance& instance, const int deform, const int axis ){
206 for ( PatchControlIter i = patch.begin(); i != patch.end(); ++i ){
207 PatchControl& control = *i;
208 int randomNumber = int( deform * ( float( std::rand() ) / float( RAND_MAX ) ) );
209 control.m_vertex[ axis ] += randomNumber;
212 patch.controlPointsChanged();
215 void Scene_PatchDeform( scene::Graph& graph, const int deform, const int axis )
217 InstanceVector instances;
218 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
219 instances.push_back(&patch);
221 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
223 Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform, axis );
228 void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){
230 // Create a new patch node
231 NodeSmartReference node( g_patchCreator->createPatch() );
232 // Insert the node into worldspawn
233 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
235 // Retrieve the contained patch from the node
236 Patch* targetPatch = Node_getPatch( node );
238 // Create the opposite patch with the given thickness = distance
241 targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 );
243 // Now select the newly created patches
245 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
246 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
247 patchpath.push( makeReference( node.get() ) );
248 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
251 if( seams && thickness != 0.0f){
260 // Now create the four walls
261 for ( ; i < iend; i++ ){
262 // Allocate new patch
263 NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() );
264 // Insert each node into worldspawn
265 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
267 // Retrieve the contained patch from the node
268 Patch* wallPatch = Node_getPatch( node );
270 // Create the wall patch by passing i as wallIndex
271 wallPatch->createThickenedWall( patch, *targetPatch, i );
273 if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) ||
274 ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ||
275 ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){
276 //globalOutputStream() << "Thicken: Discarding degenerate patch.\n";
277 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node );
280 // Now select the newly created patches
282 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
283 patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) );
284 patchpath.push( makeReference( node.get() ) );
285 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
290 // Invert the target patch so that it faces the opposite direction
291 targetPatch->InvertMatrix();
294 void Scene_PatchThicken( scene::Graph& graph, const int thickness, bool seams, const int axis )
296 InstanceVector instances;
297 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
298 instances.push_back(&patch);
300 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
302 Patch_thicken( *Node_getPatch( ( *i )->path().top() ), *( *i ), thickness, seams, axis );
307 Patch* Scene_GetUltimateSelectedVisiblePatch(){
308 if ( GlobalSelectionSystem().countSelected() != 0 ) {
309 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
310 if ( node.visible() ) {
311 return Node_getPatch( node );
318 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
319 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
320 patch.ProjectTexture(Patch::m_CycleCapIndex);
322 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
326 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
327 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
328 patch.FlipTexture(axis);
332 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
333 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
334 patch.NaturalTexture();
340 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
341 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
342 patch.InsertRemove(bInsert, bColumn, bFirst);
346 void Scene_PatchInvert_Selected( scene::Graph& graph ){
347 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
348 patch.InvertMatrix();
352 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
353 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
354 patch.Redisperse(major);
358 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
359 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
364 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
365 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
366 patch.TransposeMatrix();
370 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
371 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
372 patch.SetShader(name);
377 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
378 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
380 name = patch->GetShader();
384 class PatchSelectByShader
388 inline PatchSelectByShader( const char* name )
391 void operator()( PatchInstance& patch ) const {
392 if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
393 patch.setSelected( true );
398 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
399 Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
400 if (shader_equal(patch.getPatch().GetShader(), name)) {
401 patch.setSelected(true);
407 class PatchFindReplaceShader
410 const char* m_replace;
412 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
414 void operator()( Patch& patch ) const {
415 if ( shader_equal( patch.GetShader(), m_find ) ) {
416 patch.SetShader( m_replace );
422 bool DoingSearch( const char *repl ){
423 return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
426 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
427 if( DoingSearch( replace ) ){
428 Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) );
431 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
435 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
436 if( DoingSearch( replace ) ){
437 //do nothing, because alternative is replacing to notex
438 //perhaps deselect ones with not matching shaders here?
441 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
446 AABB PatchCreator_getBounds(){
447 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
449 float gridSize = GetGridSize();
451 if ( aabb.extents[0] == 0 ) {
452 aabb.extents[0] = gridSize;
454 if ( aabb.extents[1] == 0 ) {
455 aabb.extents[1] = gridSize;
457 if ( aabb.extents[2] == 0 ) {
458 aabb.extents[2] = gridSize;
461 if ( aabb_valid( aabb ) ) {
464 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
467 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
469 void Patch_XactCylinder(){
470 UndoableCommand undo( "patchCreateXactCylinder" );
472 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
475 void Patch_XactSphere(){
476 UndoableCommand undo( "patchCreateXactSphere" );
478 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
481 void Patch_XactCone(){
482 UndoableCommand undo( "patchCreateXactCone" );
484 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
487 void Patch_Cylinder(){
488 UndoableCommand undo( "patchCreateCylinder" );
490 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
493 void Patch_DenseCylinder(){
494 UndoableCommand undo( "patchCreateDenseCylinder" );
496 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
499 void Patch_VeryDenseCylinder(){
500 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
502 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
505 void Patch_SquareCylinder(){
506 UndoableCommand undo( "patchCreateSquareCylinder" );
508 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
512 UndoableCommand undo( "patchCreateCaps" );
514 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
518 UndoableCommand undo( "patchCreateBevel" );
520 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
524 UndoableCommand undo( "patchCreateSphere" );
526 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
529 void Patch_SquareBevel(){
532 void Patch_SquareEndcap(){
536 UndoableCommand undo( "patchCreateCone" );
538 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
542 UndoableCommand undo( "patchCreatePlane" );
544 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
547 void Patch_InsertFirstColumn(){
548 UndoableCommand undo( "patchInsertFirstColumns" );
550 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
553 void Patch_InsertLastColumn(){
554 UndoableCommand undo( "patchInsertLastColumns" );
556 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
559 void Patch_InsertFirstRow(){
560 UndoableCommand undo( "patchInsertFirstRows" );
562 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
565 void Patch_InsertLastRow(){
566 UndoableCommand undo( "patchInsertLastRows" );
568 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
571 void Patch_DeleteFirstColumn(){
572 UndoableCommand undo( "patchDeleteFirstColumns" );
574 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
577 void Patch_DeleteLastColumn(){
578 UndoableCommand undo( "patchDeleteLastColumns" );
580 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
583 void Patch_DeleteFirstRow(){
584 UndoableCommand undo( "patchDeleteFirstRows" );
586 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
589 void Patch_DeleteLastRow(){
590 UndoableCommand undo( "patchDeleteLastRows" );
592 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
596 UndoableCommand undo( "patchInvert" );
598 Scene_PatchInvert_Selected( GlobalSceneGraph() );
601 void Patch_RedisperseRows(){
602 UndoableCommand undo( "patchRedisperseRows" );
604 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
607 void Patch_RedisperseCols(){
608 UndoableCommand undo( "patchRedisperseColumns" );
610 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
613 void Patch_SmoothRows(){
614 UndoableCommand undo( "patchSmoothRows" );
616 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
619 void Patch_SmoothCols(){
620 UndoableCommand undo( "patchSmoothColumns" );
622 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
625 void Patch_Transpose(){
626 UndoableCommand undo( "patchTranspose" );
628 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
632 // FIXME: add support for patch cap creation
633 // Patch_CapCurrent();
634 UndoableCommand undo( "patchCreateCaps" );
636 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
639 void Patch_CycleProjection(){
640 UndoableCommand undo( "patchCycleUVProjectionAxis" );
642 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
646 void Patch_OverlayOn(){
650 void Patch_OverlayOff(){
653 void Patch_FlipTextureX(){
654 UndoableCommand undo( "patchFlipTextureU" );
656 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
659 void Patch_FlipTextureY(){
660 UndoableCommand undo( "patchFlipTextureV" );
662 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
665 void Patch_NaturalTexture(){
666 UndoableCommand undo( "patchNaturalTexture" );
668 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
671 void Patch_CapTexture(){
672 UndoableCommand command( "patchCapTexture" );
674 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
677 void Patch_ResetTexture(){
679 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
680 UndoableCommand command( "patchTileTexture" );
681 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
685 void Patch_FitTexture(){
686 UndoableCommand command( "patchFitTexture" );
688 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
691 void DoPatchDeformDlg();
694 UndoableCommand undo( "patchDeform" );
699 void DoPatchThickenDlg();
701 void Patch_Thicken(){
702 UndoableCommand undo( "patchThicken" );
711 class filter_patch_all : public PatchFilter
714 bool filter( const Patch& patch ) const {
719 class filter_patch_shader : public PatchFilter
721 const char* m_shader;
723 filter_patch_shader( const char* shader ) : m_shader( shader ){
725 bool filter( const Patch& patch ) const {
726 return shader_equal( patch.GetShader(), m_shader );
730 class filter_patch_flags : public PatchFilter
734 filter_patch_flags( int flags ) : m_flags( flags ){
736 bool filter( const Patch& patch ) const {
737 return ( patch.getShaderFlags() & m_flags ) != 0;
742 filter_patch_all g_filter_patch_all;
743 filter_patch_flags g_filter_patch_clip( QER_CLIP );
744 filter_patch_shader g_filter_patch_commonclip( "textures/common/clip" );
745 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
746 filter_patch_flags g_filter_patch_translucent( QER_TRANS | QER_ALPHATEST );
748 void PatchFilters_construct(){
749 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
750 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
751 add_patch_filter( g_filter_patch_commonclip, EXCLUDE_CLIP );
752 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
753 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
757 #include "preferences.h"
759 void Patch_constructPreferences( PreferencesPage& page ){
760 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
762 void Patch_constructPage( PreferenceGroup& group ){
763 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
764 Patch_constructPreferences( page );
766 void Patch_registerPreferencesPage(){
767 PreferencesDialog_addDisplayPage( makeCallbackF(Patch_constructPage) );
771 #include "preferencesystem.h"
773 void PatchPreferences_construct(){
774 GlobalPreferenceSystem().registerPreference( "Subdivisions", make_property_string( g_PatchSubdivideThreshold ) );
778 #include "generic/callback.h"
780 void Patch_registerCommands(){
781 GlobalCommands_insert( "InvertCurveTextureX", makeCallbackF(Patch_FlipTextureX), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
782 GlobalCommands_insert( "InvertCurveTextureY", makeCallbackF(Patch_FlipTextureY), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
783 GlobalCommands_insert( "NaturalizePatch", makeCallbackF(Patch_NaturalTexture), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
784 GlobalCommands_insert( "PatchCylinder", makeCallbackF(Patch_Cylinder) );
785 // GlobalCommands_insert( "PatchDenseCylinder", makeCallbackF(Patch_DenseCylinder) );
786 // GlobalCommands_insert( "PatchVeryDenseCylinder", makeCallbackF(Patch_VeryDenseCylinder) );
787 GlobalCommands_insert( "PatchSquareCylinder", makeCallbackF(Patch_SquareCylinder) );
788 GlobalCommands_insert( "PatchXactCylinder", makeCallbackF(Patch_XactCylinder) );
789 GlobalCommands_insert( "PatchXactSphere", makeCallbackF(Patch_XactSphere) );
790 GlobalCommands_insert( "PatchXactCone", makeCallbackF(Patch_XactCone) );
791 GlobalCommands_insert( "PatchEndCap", makeCallbackF(Patch_Endcap) );
792 GlobalCommands_insert( "PatchBevel", makeCallbackF(Patch_Bevel) );
793 // GlobalCommands_insert( "PatchSquareBevel", makeCallbackF(Patch_SquareBevel) );
794 // GlobalCommands_insert( "PatchSquareEndcap", makeCallbackF(Patch_SquareEndcap) );
795 GlobalCommands_insert( "PatchCone", makeCallbackF(Patch_Cone) );
796 GlobalCommands_insert( "PatchSphere", makeCallbackF(Patch_Sphere) );
797 GlobalCommands_insert( "SimplePatchMesh", makeCallbackF(Patch_Plane), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
798 GlobalCommands_insert( "PatchInsertFirstColumn", makeCallbackF(Patch_InsertFirstColumn), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
799 GlobalCommands_insert( "PatchInsertLastColumn", makeCallbackF(Patch_InsertLastColumn) );
800 GlobalCommands_insert( "PatchInsertFirstRow", makeCallbackF(Patch_InsertFirstRow), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
801 GlobalCommands_insert( "PatchInsertLastRow", makeCallbackF(Patch_InsertLastRow) );
802 GlobalCommands_insert( "PatchDeleteFirstColumn", makeCallbackF(Patch_DeleteFirstColumn) );
803 GlobalCommands_insert( "PatchDeleteLastColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
804 GlobalCommands_insert( "PatchDeleteFirstRow", makeCallbackF(Patch_DeleteFirstRow) );
805 GlobalCommands_insert( "PatchDeleteLastRow", makeCallbackF(Patch_DeleteLastRow) );
806 GlobalCommands_insert( "InvertCurve", makeCallbackF(Patch_Invert), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
807 // GlobalCommands_insert( "RedisperseRows", makeCallbackF(Patch_RedisperseRows), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
808 GlobalCommands_insert( "RedisperseRows", makeCallbackF(Patch_RedisperseRows) );
809 // GlobalCommands_insert( "RedisperseCols", makeCallbackF(Patch_RedisperseCols), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
810 GlobalCommands_insert( "RedisperseCols", makeCallbackF(Patch_RedisperseCols) );
811 GlobalCommands_insert( "SmoothRows", makeCallbackF(Patch_SmoothRows), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
812 GlobalCommands_insert( "SmoothCols", makeCallbackF(Patch_SmoothCols), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
813 GlobalCommands_insert( "MatrixTranspose", makeCallbackF(Patch_Transpose), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
814 GlobalCommands_insert( "CapCurrentCurve", makeCallbackF(Patch_Cap), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
815 GlobalCommands_insert( "CycleCapTexturePatch", makeCallbackF(Patch_CycleProjection), Accelerator( 'N', (GdkModifierType)GDK_SHIFT_MASK ) );
816 // GlobalCommands_insert( "MakeOverlayPatch", makeCallbackF(Patch_OverlayOn), Accelerator( 'Y' ) );
817 // GlobalCommands_insert( "ClearPatchOverlays", makeCallbackF(Patch_OverlayOff), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
818 GlobalCommands_insert( "PatchDeform", makeCallbackF(Patch_Deform) );
819 GlobalCommands_insert( "PatchThicken", makeCallbackF(Patch_Thicken), Accelerator( 'T', (GdkModifierType)GDK_CONTROL_MASK ) );
822 void Patch_constructToolbar( ui::Toolbar toolbar ){
823 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "cap_curve.png", "CapCurrentCurve" );
826 void Patch_constructMenu( ui::Menu menu ){
827 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
828 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
829 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
830 create_menu_item_with_mnemonic( menu, "Cylinder (9x3)", "PatchCylinder" );
831 create_menu_item_with_mnemonic( menu, "Square Cylinder (9x3)", "PatchSquareCylinder" );
832 create_menu_item_with_mnemonic( menu, "Exact Cylinder...", "PatchXactCylinder" );
833 create_menu_item_with_mnemonic( menu, "Cone (9x3)", "PatchCone" );
834 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
835 create_menu_item_with_mnemonic( menu, "Sphere (9x5)", "PatchSphere" );
836 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
838 // ui::Menu menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
839 // if ( g_Layout_enableDetachableMenus.m_value ) {
840 // menu_tearoff( menu_in_menu );
842 // create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
843 // create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
844 // create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
848 // create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
849 // create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
851 menu_separator( menu );
852 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
853 menu_separator( menu );
855 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert/Delete" );
856 if ( g_Layout_enableDetachableMenus.m_value ) {
857 menu_tearoff( menu_in_menu );
859 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Columns", "PatchInsertFirstColumn" );
860 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Columns", "PatchInsertLastColumn" );
861 menu_separator( menu_in_menu );
862 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Rows", "PatchInsertFirstRow" );
863 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Rows", "PatchInsertLastRow" );
864 menu_separator( menu_in_menu );
865 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Columns", "PatchDeleteFirstColumn" );
866 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Columns", "PatchDeleteLastColumn" );
867 menu_separator( menu_in_menu );
868 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Rows", "PatchDeleteFirstRow" );
869 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Rows", "PatchDeleteLastRow" );
871 menu_separator( menu );
873 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
874 if ( g_Layout_enableDetachableMenus.m_value ) {
875 menu_tearoff( menu_in_menu );
877 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
878 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
880 menu_separator( menu_in_menu );
881 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
882 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
884 menu_separator( menu_in_menu );
885 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
886 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
888 menu_separator( menu );
890 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
891 if ( g_Layout_enableDetachableMenus.m_value ) {
892 menu_tearoff( menu_in_menu );
894 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
895 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
896 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
897 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
900 // menu_separator( menu );
902 // auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
903 // if ( g_Layout_enableDetachableMenus.m_value ) {
904 // menu_tearoff( menu_in_menu );
906 // create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
907 // create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
909 menu_separator( menu );
910 create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
911 create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
915 #include "gtkutil/dialog.h"
916 #include "gtkutil/widget.h"
918 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
920 GtkWidget* redisperseCheckBox;
922 ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog );
924 auto accel = ui::AccelGroup(ui::New);
925 window.add_accel_group( accel );
926 auto width = ui::ComboBoxText(ui::New);
927 auto height = ui::ComboBoxText(ui::New);
929 auto hbox = create_dialog_hbox( 4, 4 );
932 auto table = create_dialog_table( 3, 2, 4, 4 );
933 hbox.pack_start( table, TRUE, TRUE, 0 );
935 auto label = ui::Label( "Width:" );
937 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
938 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
941 auto label = ui::Label( "Height:" );
943 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
944 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
949 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, #x )
964 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
967 table.attach(combo, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
971 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, #x )
986 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
989 table.attach(combo, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
992 if( prefab != ePlane ){
993 GtkWidget* _redisperseCheckBox = gtk_check_button_new_with_label( "Square" );
994 gtk_widget_set_tooltip_text( _redisperseCheckBox, "Redisperse columns & rows" );
995 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _redisperseCheckBox ), FALSE );
996 gtk_widget_show( _redisperseCheckBox );
997 gtk_table_attach( table, _redisperseCheckBox, 0, 2, 2, 3,
998 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
999 (GtkAttachOptions) ( 0 ), 0, 0 );
1000 redisperseCheckBox = _redisperseCheckBox;
1006 auto vbox = create_dialog_vbox( 4 );
1007 hbox.pack_start( vbox, TRUE, TRUE, 0 );
1009 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1010 vbox.pack_start( button, FALSE, FALSE, 0 );
1011 widget_make_default( button );
1012 gtk_widget_grab_focus( button );
1013 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1016 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1017 vbox.pack_start( button, FALSE, FALSE, 0 );
1018 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1023 // Initialize dialog
1024 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
1025 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
1027 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1028 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
1029 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
1030 bool redisperse = false;
1031 if( prefab != ePlane ){
1032 redisperse = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( redisperseCheckBox ) ) ? true : false;
1034 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h, redisperse );
1041 void DoPatchDeformDlg(){
1048 ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1050 GtkAccelGroup* accel = gtk_accel_group_new();
1051 gtk_window_add_accel_group( window, accel );
1054 auto hbox = create_dialog_hbox( 4, 4 );
1055 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1057 auto table = create_dialog_table( 2, 2, 4, 4 );
1058 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1060 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1061 gtk_widget_show( GTK_WIDGET( label ) );
1062 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1063 (GtkAttachOptions) ( GTK_FILL ),
1064 (GtkAttachOptions) ( 0 ), 0, 0 );
1065 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1068 // GtkWidget* entry = gtk_entry_new();
1069 // gtk_entry_set_text( GTK_ENTRY( entry ), "64" );
1070 // gtk_widget_show( entry );
1071 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1072 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1073 // (GtkAttachOptions) ( 0 ), 0, 0 );
1078 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 64, -9999, 9999, 1, 10, 0 ) );
1079 //GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
1080 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1081 gtk_widget_show( spin );
1082 gtk_table_attach( table, spin, 1, 2, 0, 1,
1083 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1084 (GtkAttachOptions) ( 0 ), 0, 0 );
1085 gtk_widget_set_size_request( spin, 64, -1 );
1086 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1091 // Create the radio button group for choosing the axis
1092 GtkWidget* _rndZ = gtk_radio_button_new_with_label_from_widget( NULL, "Z" );
1093 GtkWidget* _rndY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "Y" );
1094 GtkWidget* _rndX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "X" );
1095 gtk_widget_show( _rndZ );
1096 gtk_widget_show( _rndY );
1097 gtk_widget_show( _rndX );
1100 GtkHBox* _hbox = create_dialog_hbox( 4, 4 );
1101 gtk_table_attach( table, GTK_WIDGET( _hbox ), 0, 2, 1, 2,
1102 (GtkAttachOptions) ( GTK_FILL ),
1103 (GtkAttachOptions) ( 0 ), 0, 0 );
1104 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndX ), TRUE, TRUE, 0 );
1105 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndY ), TRUE, TRUE, 0 );
1106 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndZ ), TRUE, TRUE, 0 );
1113 auto vbox = create_dialog_vbox( 4 );
1114 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1116 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1117 vbox.pack_start( button, FALSE, FALSE, 0 );
1118 widget_make_default( button );
1119 gtk_widget_grab_focus( button );
1120 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1123 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1124 vbox.pack_start( button, FALSE, FALSE, 0 );
1125 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1130 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1131 //int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1132 gtk_spin_button_update ( GTK_SPIN_BUTTON( deformW ) );
1133 int deform = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( deformW ) ) );
1135 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndX ) ) ){
1138 else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndY ) ) ){
1141 Scene_PatchDeform( GlobalSceneGraph(), deform, axis );
1143 gtk_widget_destroy( GTK_WIDGET( window ) );
1148 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1150 ModalDialogButton ok_button( dialog, eIDOK );
1151 ModalDialogButton cancel_button( dialog, eIDCANCEL );
1152 ui::Widget bevel{ui::null};
1153 ui::Widget ibevel{ui::null};
1154 ui::Widget endcap{ui::null};
1155 ui::Widget iendcap{ui::null};
1156 ui::Widget cylinder{ui::null};
1158 ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog );
1160 auto accel_group = ui::AccelGroup(ui::New);
1161 window.add_accel_group( accel_group );
1164 auto hbox = create_dialog_hbox( 4, 4 );
1168 // Gef: Added a vbox to contain the toggle buttons
1169 auto radio_vbox = create_dialog_vbox( 4 );
1170 hbox.add(radio_vbox);
1173 auto table = ui::Table( 5, 2, FALSE );
1175 radio_vbox.pack_start( table, TRUE, TRUE, 0 );
1176 gtk_table_set_row_spacings( table, 5 );
1177 gtk_table_set_col_spacings( table, 5 );
1180 auto image = new_local_image( "cap_bevel.png" );
1182 table.attach(image, {0, 1, 0, 1}, {GTK_FILL, 0});
1185 auto image = new_local_image( "cap_endcap.png" );
1187 table.attach(image, {0, 1, 1, 2}, {GTK_FILL, 0});
1190 auto image = new_local_image( "cap_ibevel.png" );
1192 table.attach(image, {0, 1, 2, 3}, {GTK_FILL, 0});
1195 auto image = new_local_image( "cap_iendcap.png" );
1197 table.attach(image, {0, 1, 3, 4}, {GTK_FILL, 0});
1200 auto image = new_local_image( "cap_cylinder.png" );
1202 table.attach(image, {0, 1, 4, 5}, {GTK_FILL, 0});
1207 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Bevel" ));
1209 table.attach(button, {1, 2, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
1210 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1215 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Endcap" ));
1217 table.attach(button, {1, 2, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
1218 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1223 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Bevel" ));
1225 table.attach(button, {1, 2, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
1226 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1231 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Endcap" ));
1233 table.attach(button, {1, 2, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
1234 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1239 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Cylinder" ));
1241 table.attach(button, {1, 2, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
1242 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1250 auto vbox = create_dialog_vbox( 4 );
1251 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1253 auto button = create_modal_dialog_button( "OK", ok_button );
1254 vbox.pack_start( button, FALSE, FALSE, 0 );
1255 widget_make_default( button );
1256 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1259 auto button = create_modal_dialog_button( "Cancel", cancel_button );
1260 vbox.pack_start( button, FALSE, FALSE, 0 );
1261 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1266 // Initialize dialog
1267 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1269 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1270 if ( ret == eIDOK ) {
1271 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1272 *type = PATCHCAP_BEVEL;
1274 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1275 *type = PATCHCAP_ENDCAP;
1277 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1278 *type = PATCHCAP_INVERTED_BEVEL;
1280 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1281 *type = PATCHCAP_INVERTED_ENDCAP;
1283 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1284 *type = PATCHCAP_CYLINDER;
1294 void DoPatchThickenDlg(){
1296 GtkWidget* thicknessW;
1302 ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1304 GtkAccelGroup* accel = gtk_accel_group_new();
1305 gtk_window_add_accel_group( window, accel );
1308 auto hbox = create_dialog_hbox( 4, 4 );
1309 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1311 auto table = create_dialog_table( 2, 4, 4, 4 );
1312 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1314 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1315 gtk_widget_show( GTK_WIDGET( label ) );
1316 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1317 (GtkAttachOptions) ( GTK_FILL ),
1318 (GtkAttachOptions) ( 0 ), 0, 0 );
1319 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1322 // GtkWidget* entry = gtk_entry_new();
1323 // gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1324 // gtk_widget_set_size_request( entry, 40, -1 );
1325 // gtk_widget_show( entry );
1326 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1327 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1328 // (GtkAttachOptions) ( 0 ), 0, 0 );
1330 // thicknessW = entry;
1333 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 16, -9999, 9999, 1, 10, 0 ) );
1334 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1335 gtk_widget_show( spin );
1336 gtk_table_attach( table, spin, 1, 2, 0, 1,
1337 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1338 (GtkAttachOptions) ( 0 ), 0, 0 );
1339 gtk_widget_set_size_request( spin, 48, -1 );
1340 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1345 // Create the "create seams" label
1346 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1347 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1348 gtk_widget_show( _seamsCheckBox );
1349 gtk_table_attach( table, _seamsCheckBox, 2, 4, 0, 1,
1350 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1351 (GtkAttachOptions) ( 0 ), 0, 0 );
1352 seamsW = _seamsCheckBox;
1356 // Create the radio button group for choosing the extrude axis
1357 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1358 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1359 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1360 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1361 gtk_widget_show( _radNormals );
1362 gtk_widget_show( _radX );
1363 gtk_widget_show( _radY );
1364 gtk_widget_show( _radZ );
1367 // Pack the buttons into the table
1368 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1369 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1370 (GtkAttachOptions) ( 0 ), 0, 0 );
1371 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1372 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1373 (GtkAttachOptions) ( 0 ), 0, 0 );
1374 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1375 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1376 (GtkAttachOptions) ( 0 ), 0, 0 );
1377 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1378 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1379 (GtkAttachOptions) ( 0 ), 0, 0 );
1386 auto vbox = create_dialog_vbox( 4 );
1387 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1389 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1390 vbox.pack_start( button, FALSE, FALSE, 0 );
1391 widget_make_default( button );
1392 gtk_widget_grab_focus( button );
1393 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1396 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1397 vbox.pack_start( button, FALSE, FALSE, 0 );
1398 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1403 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1404 int axis = 3; // Extrude along normals
1406 //float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1407 gtk_spin_button_update ( GTK_SPIN_BUTTON( thicknessW ) );
1408 float thickness = static_cast<float>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( thicknessW ) ) );
1409 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1411 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1414 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1417 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1421 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1424 gtk_widget_destroy( GTK_WIDGET( window ) );