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 ){
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 );
63 patch->controlPointsChanged();
66 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
67 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
68 patchpath.push( makeReference( node.get() ) );
69 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
73 void PatchAutoCapTexture( Patch& patch ) {
75 AABB box = patch.localAABB();
76 float x = box.extents.x();
77 float y = box.extents.y();
78 float z = box.extents.z();
80 int cap_direction = -1;
83 else if ( y < x && y < z )
85 else if ( z < x && z < x )
88 if ( cap_direction >= 0 )
89 patch.ProjectTexture(cap_direction);
91 patch.NaturalTexture();
94 void Patch_AutoCapTexture(){
95 UndoableCommand command( "patchAutoCapTexture" );
96 Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture );
100 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
101 if ( ( type == eCapEndCap || type == eCapIEndCap )
102 && patch.getWidth() != 5 ) {
103 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
106 if ( ( type == eCapBevel || type == eCapIBevel )
107 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
108 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
111 if ( type == eCapCylinder
112 && patch.getWidth() != 9 ) {
113 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
118 NodeSmartReference cap( g_patchCreator->createPatch() );
119 Node_getTraversable( instance.path().parent() )->insert( cap );
121 Patch* cap_patch = Node_getPatch( cap );
122 patch.MakeCap( cap_patch, type, ROW, true );
123 cap_patch->SetShader( shader );
124 PatchAutoCapTexture(*cap_patch);
126 scene::Path path( instance.path() );
128 path.push( makeReference( cap.get() ) );
129 selectPath( path, true );
133 NodeSmartReference cap( g_patchCreator->createPatch() );
134 Node_getTraversable( instance.path().parent() )->insert( cap );
136 Patch* cap_patch = Node_getPatch( cap );
137 patch.MakeCap( cap_patch, type, ROW, false );
138 cap_patch->SetShader( shader );
139 PatchAutoCapTexture(*cap_patch);
141 scene::Path path( instance.path() );
143 path.push( makeReference( cap.get() ) );
144 selectPath( path, true );
149 typedef std::vector<scene::Instance*> InstanceVector;
154 PATCHCAP_INVERTED_BEVEL,
155 PATCHCAP_INVERTED_ENDCAP,
159 EMessageBoxReturn DoCapDlg( ECapDialog *type );
161 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
164 if ( DoCapDlg( &nType ) == eIDOK ) {
168 case PATCHCAP_INVERTED_BEVEL:
174 case PATCHCAP_INVERTED_ENDCAP:
177 case PATCHCAP_ENDCAP:
180 case PATCHCAP_CYLINDER:
181 eType = eCapCylinder;
184 ERROR_MESSAGE( "invalid patch cap type" );
188 InstanceVector instances;
189 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
190 instances.push_back(&patch);
192 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
194 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
199 void Patch_deform( Patch& patch, scene::Instance& instance, const int deform ){
202 for (PatchControlIter i = patch.begin(); i != patch.end(); ++i)
204 PatchControl& control = *i;
205 int randomNumber = int( deform * (float(std::rand()) / float(RAND_MAX)));
206 control.m_vertex[2] += randomNumber;
209 patch.controlPointsChanged();
212 void Scene_PatchDeform( scene::Graph& graph, const int deform )
214 InstanceVector instances;
215 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
216 instances.push_back(&patch);
218 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
220 Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform );
225 Patch* Scene_GetUltimateSelectedVisiblePatch(){
226 if ( GlobalSelectionSystem().countSelected() != 0 ) {
227 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
228 if ( node.visible() ) {
229 return Node_getPatch( node );
236 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
237 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
238 patch.ProjectTexture(Patch::m_CycleCapIndex);
240 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
244 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
245 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
246 patch.FlipTexture(axis);
250 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
251 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
252 patch.NaturalTexture();
258 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
259 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
260 patch.InsertRemove(bInsert, bColumn, bFirst);
264 void Scene_PatchInvert_Selected( scene::Graph& graph ){
265 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
266 patch.InvertMatrix();
270 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
271 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
272 patch.Redisperse(major);
276 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
277 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
282 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
283 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
284 patch.TransposeMatrix();
288 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
289 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
290 patch.SetShader(name);
295 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
296 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
298 name = patch->GetShader();
302 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
303 Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
304 if (shader_equal(patch.getPatch().GetShader(), name)) {
305 patch.setSelected(true);
311 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
312 Scene_forEachVisiblePatch([&](Patch &patch) {
313 if (shader_equal(patch.GetShader(), find)) {
314 patch.SetShader(replace);
319 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
320 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
321 if (shader_equal(patch.GetShader(), find)) {
322 patch.SetShader(replace);
328 AABB PatchCreator_getBounds(){
329 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
331 float gridSize = GetGridSize();
333 if ( aabb.extents[0] == 0 ) {
334 aabb.extents[0] = gridSize;
336 if ( aabb.extents[1] == 0 ) {
337 aabb.extents[1] = gridSize;
339 if ( aabb.extents[2] == 0 ) {
340 aabb.extents[2] = gridSize;
343 if ( aabb_valid( aabb ) ) {
346 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
349 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
351 void Patch_XactCylinder(){
352 UndoableCommand undo( "patchCreateXactCylinder" );
354 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
357 void Patch_XactSphere(){
358 UndoableCommand undo( "patchCreateXactSphere" );
360 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
363 void Patch_XactCone(){
364 UndoableCommand undo( "patchCreateXactCone" );
366 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
369 void Patch_Cylinder(){
370 UndoableCommand undo( "patchCreateCylinder" );
372 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
375 void Patch_DenseCylinder(){
376 UndoableCommand undo( "patchCreateDenseCylinder" );
378 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
381 void Patch_VeryDenseCylinder(){
382 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
384 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
387 void Patch_SquareCylinder(){
388 UndoableCommand undo( "patchCreateSquareCylinder" );
390 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
394 UndoableCommand undo( "patchCreateCaps" );
396 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
400 UndoableCommand undo( "patchCreateBevel" );
402 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
406 UndoableCommand undo( "patchCreateSphere" );
408 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
411 void Patch_SquareBevel(){
414 void Patch_SquareEndcap(){
418 UndoableCommand undo( "patchCreateCone" );
420 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
424 UndoableCommand undo( "patchCreatePlane" );
426 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
429 void Patch_InsertInsertColumn(){
430 UndoableCommand undo( "patchInsertColumns" );
432 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
435 void Patch_InsertAddColumn(){
436 UndoableCommand undo( "patchAddColumns" );
438 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
441 void Patch_InsertInsertRow(){
442 UndoableCommand undo( "patchInsertRows" );
444 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
447 void Patch_InsertAddRow(){
448 UndoableCommand undo( "patchAddRows" );
450 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
453 void Patch_DeleteFirstColumn(){
454 UndoableCommand undo( "patchDeleteFirstColumns" );
456 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
459 void Patch_DeleteLastColumn(){
460 UndoableCommand undo( "patchDeleteLastColumns" );
462 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
465 void Patch_DeleteFirstRow(){
466 UndoableCommand undo( "patchDeleteFirstRows" );
468 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
471 void Patch_DeleteLastRow(){
472 UndoableCommand undo( "patchDeleteLastRows" );
474 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
478 UndoableCommand undo( "patchInvert" );
480 Scene_PatchInvert_Selected( GlobalSceneGraph() );
483 void Patch_RedisperseRows(){
484 UndoableCommand undo( "patchRedisperseRows" );
486 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
489 void Patch_RedisperseCols(){
490 UndoableCommand undo( "patchRedisperseColumns" );
492 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
495 void Patch_SmoothRows(){
496 UndoableCommand undo( "patchSmoothRows" );
498 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
501 void Patch_SmoothCols(){
502 UndoableCommand undo( "patchSmoothColumns" );
504 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
507 void Patch_Transpose(){
508 UndoableCommand undo( "patchTranspose" );
510 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
514 // FIXME: add support for patch cap creation
515 // Patch_CapCurrent();
516 UndoableCommand undo( "patchCreateCaps" );
518 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
521 void Patch_CycleProjection(){
522 UndoableCommand undo( "patchCycleUVProjectionAxis" );
524 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
528 void Patch_OverlayOn(){
532 void Patch_OverlayOff(){
535 void Patch_FlipTextureX(){
536 UndoableCommand undo( "patchFlipTextureU" );
538 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
541 void Patch_FlipTextureY(){
542 UndoableCommand undo( "patchFlipTextureV" );
544 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
547 void Patch_NaturalTexture(){
548 UndoableCommand undo( "patchNaturalTexture" );
550 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
553 void Patch_CapTexture(){
554 UndoableCommand command( "patchCapTexture" );
556 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
559 void Patch_ResetTexture(){
561 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
562 UndoableCommand command( "patchTileTexture" );
563 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
567 void Patch_FitTexture(){
568 UndoableCommand command( "patchFitTexture" );
570 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
573 void DoPatchDeformDlg();
576 UndoableCommand undo( "patchDeform" );
584 class filter_patch_all : public PatchFilter
587 bool filter( const Patch& patch ) const {
592 class filter_patch_shader : public PatchFilter
594 const char* m_shader;
596 filter_patch_shader( const char* shader ) : m_shader( shader ){
598 bool filter( const Patch& patch ) const {
599 return shader_equal( patch.GetShader(), m_shader );
603 class filter_patch_flags : public PatchFilter
607 filter_patch_flags( int flags ) : m_flags( flags ){
609 bool filter( const Patch& patch ) const {
610 return ( patch.getShaderFlags() & m_flags ) != 0;
615 filter_patch_all g_filter_patch_all;
616 filter_patch_shader g_filter_patch_clip( "textures/common/clip" );
617 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
618 filter_patch_flags g_filter_patch_translucent( QER_TRANS );
620 void PatchFilters_construct(){
621 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
622 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
623 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
624 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
628 #include "preferences.h"
630 void Patch_constructPreferences( PreferencesPage& page ){
631 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
633 void Patch_constructPage( PreferenceGroup& group ){
634 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
635 Patch_constructPreferences( page );
637 void Patch_registerPreferencesPage(){
638 PreferencesDialog_addDisplayPage( makeCallbackF(Patch_constructPage) );
642 #include "preferencesystem.h"
644 void PatchPreferences_construct(){
645 GlobalPreferenceSystem().registerPreference( "Subdivisions", make_property_string( g_PatchSubdivideThreshold ) );
649 #include "generic/callback.h"
651 void Patch_registerCommands(){
652 GlobalCommands_insert( "InvertCurveTextureX", makeCallbackF(Patch_FlipTextureX), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
653 GlobalCommands_insert( "InvertCurveTextureY", makeCallbackF(Patch_FlipTextureY), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
654 GlobalCommands_insert( "IncPatchColumn", makeCallbackF(Patch_InsertInsertColumn), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
655 GlobalCommands_insert( "IncPatchRow", makeCallbackF(Patch_InsertInsertRow), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
656 GlobalCommands_insert( "DecPatchColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
657 GlobalCommands_insert( "DecPatchRow", makeCallbackF(Patch_DeleteLastRow), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
658 GlobalCommands_insert( "NaturalizePatch", makeCallbackF(Patch_NaturalTexture), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
659 GlobalCommands_insert( "PatchCylinder", makeCallbackF(Patch_Cylinder) );
660 GlobalCommands_insert( "PatchDenseCylinder", makeCallbackF(Patch_DenseCylinder) );
661 GlobalCommands_insert( "PatchVeryDenseCylinder", makeCallbackF(Patch_VeryDenseCylinder) );
662 GlobalCommands_insert( "PatchSquareCylinder", makeCallbackF(Patch_SquareCylinder) );
663 GlobalCommands_insert( "PatchXactCylinder", makeCallbackF(Patch_XactCylinder) );
664 GlobalCommands_insert( "PatchXactSphere", makeCallbackF(Patch_XactSphere) );
665 GlobalCommands_insert( "PatchXactCone", makeCallbackF(Patch_XactCone) );
666 GlobalCommands_insert( "PatchEndCap", makeCallbackF(Patch_Endcap) );
667 GlobalCommands_insert( "PatchBevel", makeCallbackF(Patch_Bevel) );
668 GlobalCommands_insert( "PatchSquareBevel", makeCallbackF(Patch_SquareBevel) );
669 GlobalCommands_insert( "PatchSquareEndcap", makeCallbackF(Patch_SquareEndcap) );
670 GlobalCommands_insert( "PatchCone", makeCallbackF(Patch_Cone) );
671 GlobalCommands_insert( "PatchSphere", makeCallbackF(Patch_Sphere) );
672 GlobalCommands_insert( "SimplePatchMesh", makeCallbackF(Patch_Plane), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
673 GlobalCommands_insert( "PatchInsertInsertColumn", makeCallbackF(Patch_InsertInsertColumn), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
674 GlobalCommands_insert( "PatchInsertAddColumn", makeCallbackF(Patch_InsertAddColumn) );
675 GlobalCommands_insert( "PatchInsertInsertRow", makeCallbackF(Patch_InsertInsertRow), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
676 GlobalCommands_insert( "PatchInsertAddRow", makeCallbackF(Patch_InsertAddRow) );
677 GlobalCommands_insert( "PatchDeleteFirstColumn", makeCallbackF(Patch_DeleteFirstColumn) );
678 GlobalCommands_insert( "PatchDeleteLastColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
679 GlobalCommands_insert( "PatchDeleteFirstRow", makeCallbackF(Patch_DeleteFirstRow), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
680 GlobalCommands_insert( "PatchDeleteLastRow", makeCallbackF(Patch_DeleteLastRow) );
681 GlobalCommands_insert( "InvertCurve", makeCallbackF(Patch_Invert), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
682 GlobalCommands_insert( "RedisperseRows", makeCallbackF(Patch_RedisperseRows), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
683 GlobalCommands_insert( "RedisperseCols", makeCallbackF(Patch_RedisperseCols), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
684 GlobalCommands_insert( "SmoothRows", makeCallbackF(Patch_SmoothRows), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
685 GlobalCommands_insert( "SmoothCols", makeCallbackF(Patch_SmoothCols), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
686 GlobalCommands_insert( "MatrixTranspose", makeCallbackF(Patch_Transpose), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
687 GlobalCommands_insert( "CapCurrentCurve", makeCallbackF(Patch_Cap), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
688 GlobalCommands_insert( "CycleCapTexturePatch", makeCallbackF(Patch_CycleProjection), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
689 GlobalCommands_insert( "MakeOverlayPatch", makeCallbackF(Patch_OverlayOn), Accelerator( 'Y' ) );
690 GlobalCommands_insert( "ClearPatchOverlays", makeCallbackF(Patch_OverlayOff), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
691 GlobalCommands_insert( "PatchDeform", makeCallbackF(Patch_Deform) );
694 void Patch_constructToolbar( ui::Toolbar toolbar ){
695 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "cap_curve.png", "CapCurrentCurve" );
698 void Patch_constructMenu( ui::Menu menu ){
699 create_menu_item_with_mnemonic( menu, "Cylinder", "PatchCylinder" );
701 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
702 if ( g_Layout_enableDetachableMenus.m_value ) {
703 menu_tearoff( menu_in_menu );
705 create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
706 create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
707 create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
708 create_menu_item_with_mnemonic( menu_in_menu, "Exact Cylinder...", "PatchXactCylinder" );
710 menu_separator( menu );
711 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
712 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
714 // auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
715 // if ( g_Layout_enableDetachableMenus.m_value ) {
716 // menu_tearoff( menu_in_menu );
718 create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
719 create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
721 menu_separator( menu );
722 create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
723 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
724 menu_separator( menu );
725 create_menu_item_with_mnemonic( menu, "Sphere", "PatchSphere" );
726 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
727 menu_separator( menu );
728 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
729 menu_separator( menu );
731 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert" );
732 if ( g_Layout_enableDetachableMenus.m_value ) {
733 menu_tearoff( menu_in_menu );
735 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
736 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
737 menu_separator( menu_in_menu );
738 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
739 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
742 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
743 if ( g_Layout_enableDetachableMenus.m_value ) {
744 menu_tearoff( menu_in_menu );
746 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn" );
747 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn" );
748 menu_separator( menu_in_menu );
749 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow" );
750 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow" );
752 menu_separator( menu );
754 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
755 if ( g_Layout_enableDetachableMenus.m_value ) {
756 menu_tearoff( menu_in_menu );
758 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
759 // auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
760 // if ( g_Layout_enableDetachableMenus.m_value ) {
761 // menu_tearoff( menu_3 );
763 menu_separator( menu_in_menu );
764 create_menu_item_with_mnemonic( menu, "Rows", "RedisperseRows" );
765 create_menu_item_with_mnemonic( menu, "Columns", "RedisperseCols" );
766 // auto menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
767 // if ( g_Layout_enableDetachableMenus.m_value ) {
768 // menu_tearoff( menu_4 );
770 create_menu_item_with_mnemonic( menu, "Rows", "SmoothRows" );
771 create_menu_item_with_mnemonic( menu, "Columns", "SmoothCols" );
772 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
775 menu_separator( menu );
776 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
777 create_menu_item_with_mnemonic( menu, "Cycle Cap Texture", "CycleCapTexturePatch" );
778 menu_separator( menu );
780 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
781 if ( g_Layout_enableDetachableMenus.m_value ) {
782 menu_tearoff( menu_in_menu );
784 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
785 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
786 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
787 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
790 menu_separator( menu );
792 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
793 if ( g_Layout_enableDetachableMenus.m_value ) {
794 menu_tearoff( menu_in_menu );
796 create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
797 create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
799 menu_separator( menu );
800 create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
804 #include "gtkutil/dialog.h"
805 #include "gtkutil/widget.h"
807 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
810 ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog );
812 auto accel = ui::AccelGroup(ui::New);
813 window.add_accel_group( accel );
814 auto width = ui::ComboBoxText(ui::New);
815 auto height = ui::ComboBoxText(ui::New);
817 auto hbox = create_dialog_hbox( 4, 4 );
820 auto table = create_dialog_table( 2, 2, 4, 4 );
821 hbox.pack_start( table, TRUE, TRUE, 0 );
823 auto label = ui::Label( "Width:" );
825 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
826 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
829 auto label = ui::Label( "Height:" );
831 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
832 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
837 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, #x )
852 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
855 table.attach(combo, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
859 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, #x )
874 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
877 table.attach(combo, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
882 auto vbox = create_dialog_vbox( 4 );
883 hbox.pack_start( vbox, TRUE, TRUE, 0 );
885 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
886 vbox.pack_start( button, FALSE, FALSE, 0 );
887 widget_make_default( button );
888 gtk_widget_grab_focus( button );
889 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
892 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
893 vbox.pack_start( button, FALSE, FALSE, 0 );
894 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
900 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
901 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
903 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
904 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
905 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
907 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
914 void DoPatchDeformDlg(){
918 ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
920 GtkAccelGroup* accel = gtk_accel_group_new();
921 gtk_window_add_accel_group( window, accel );
924 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
925 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
927 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
928 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
930 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
931 gtk_widget_show( GTK_WIDGET( label ) );
932 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
933 (GtkAttachOptions) ( GTK_FILL ),
934 (GtkAttachOptions) ( 0 ), 0, 0 );
935 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
938 GtkWidget* entry = gtk_entry_new();
939 gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
940 gtk_widget_show( entry );
941 gtk_table_attach( table, entry, 1, 2, 0, 1,
942 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
943 (GtkAttachOptions) ( 0 ), 0, 0 );
949 auto vbox = create_dialog_vbox( 4 );
950 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
952 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
953 vbox.pack_start( button, FALSE, FALSE, 0 );
954 widget_make_default( button );
955 gtk_widget_grab_focus( button );
956 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
959 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
960 vbox.pack_start( button, FALSE, FALSE, 0 );
961 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
966 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
967 int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
968 Scene_PatchDeform( GlobalSceneGraph(), deform );
971 gtk_widget_destroy( GTK_WIDGET( window ) );
976 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
978 ModalDialogButton ok_button( dialog, eIDOK );
979 ModalDialogButton cancel_button( dialog, eIDCANCEL );
980 ui::Widget bevel{ui::null};
981 ui::Widget ibevel{ui::null};
982 ui::Widget endcap{ui::null};
983 ui::Widget iendcap{ui::null};
984 ui::Widget cylinder{ui::null};
986 ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog );
988 auto accel_group = ui::AccelGroup(ui::New);
989 window.add_accel_group( accel_group );
992 auto hbox = create_dialog_hbox( 4, 4 );
996 // Gef: Added a vbox to contain the toggle buttons
997 auto radio_vbox = create_dialog_vbox( 4 );
998 hbox.add(radio_vbox);
1001 auto table = ui::Table( 5, 2, FALSE );
1003 radio_vbox.pack_start( table, TRUE, TRUE, 0 );
1004 gtk_table_set_row_spacings( table, 5 );
1005 gtk_table_set_col_spacings( table, 5 );
1008 auto image = new_local_image( "cap_bevel.png" );
1010 table.attach(image, {0, 1, 0, 1}, {GTK_FILL, 0});
1013 auto image = new_local_image( "cap_endcap.png" );
1015 table.attach(image, {0, 1, 1, 2}, {GTK_FILL, 0});
1018 auto image = new_local_image( "cap_ibevel.png" );
1020 table.attach(image, {0, 1, 2, 3}, {GTK_FILL, 0});
1023 auto image = new_local_image( "cap_iendcap.png" );
1025 table.attach(image, {0, 1, 3, 4}, {GTK_FILL, 0});
1028 auto image = new_local_image( "cap_cylinder.png" );
1030 table.attach(image, {0, 1, 4, 5}, {GTK_FILL, 0});
1035 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Bevel" ));
1037 table.attach(button, {1, 2, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
1038 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1043 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Endcap" ));
1045 table.attach(button, {1, 2, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
1046 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1051 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Bevel" ));
1053 table.attach(button, {1, 2, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
1054 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1059 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Endcap" ));
1061 table.attach(button, {1, 2, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
1062 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1067 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Cylinder" ));
1069 table.attach(button, {1, 2, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
1070 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1078 auto vbox = create_dialog_vbox( 4 );
1079 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1081 auto button = create_modal_dialog_button( "OK", ok_button );
1082 vbox.pack_start( button, FALSE, FALSE, 0 );
1083 widget_make_default( button );
1084 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1087 auto button = create_modal_dialog_button( "Cancel", cancel_button );
1088 vbox.pack_start( button, FALSE, FALSE, 0 );
1089 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1094 // Initialize dialog
1095 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1097 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1098 if ( ret == eIDOK ) {
1099 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1100 *type = PATCHCAP_BEVEL;
1102 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1103 *type = PATCHCAP_ENDCAP;
1105 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1106 *type = PATCHCAP_INVERTED_BEVEL;
1108 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1109 *type = PATCHCAP_INVERTED_ENDCAP;
1111 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1112 *type = PATCHCAP_CYLINDER;