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 );
148 typedef std::vector<scene::Instance*> InstanceVector;
153 PATCHCAP_INVERTED_BEVEL,
154 PATCHCAP_INVERTED_ENDCAP,
158 EMessageBoxReturn DoCapDlg( ECapDialog *type );
160 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
163 if ( DoCapDlg( &nType ) == eIDOK ) {
167 case PATCHCAP_INVERTED_BEVEL:
173 case PATCHCAP_INVERTED_ENDCAP:
176 case PATCHCAP_ENDCAP:
179 case PATCHCAP_CYLINDER:
180 eType = eCapCylinder;
183 ERROR_MESSAGE( "invalid patch cap type" );
187 InstanceVector instances;
188 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
189 instances.push_back(&patch);
191 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
193 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
198 Patch* Scene_GetUltimateSelectedVisiblePatch(){
199 if ( GlobalSelectionSystem().countSelected() != 0 ) {
200 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
201 if ( node.visible() ) {
202 return Node_getPatch( node );
209 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
210 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
211 patch.ProjectTexture(Patch::m_CycleCapIndex);
213 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
217 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
218 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
219 patch.FlipTexture(axis);
223 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
224 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
225 patch.NaturalTexture();
231 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
232 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
233 patch.InsertRemove(bInsert, bColumn, bFirst);
237 void Scene_PatchInvert_Selected( scene::Graph& graph ){
238 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
239 patch.InvertMatrix();
243 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
244 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
245 patch.Redisperse(major);
249 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
250 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
255 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
256 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
257 patch.TransposeMatrix();
261 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
262 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
263 patch.SetShader(name);
268 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
269 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
271 name = patch->GetShader();
275 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
276 Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
277 if (shader_equal(patch.getPatch().GetShader(), name)) {
278 patch.setSelected(true);
284 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
285 Scene_forEachVisiblePatch([&](Patch &patch) {
286 if (shader_equal(patch.GetShader(), find)) {
287 patch.SetShader(replace);
292 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
293 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
294 if (shader_equal(patch.GetShader(), find)) {
295 patch.SetShader(replace);
301 AABB PatchCreator_getBounds(){
302 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
304 float gridSize = GetGridSize();
306 if ( aabb.extents[0] == 0 ) {
307 aabb.extents[0] = gridSize;
309 if ( aabb.extents[1] == 0 ) {
310 aabb.extents[1] = gridSize;
312 if ( aabb.extents[2] == 0 ) {
313 aabb.extents[2] = gridSize;
316 if ( aabb_valid( aabb ) ) {
319 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
322 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
324 void Patch_XactCylinder(){
325 UndoableCommand undo( "patchCreateXactCylinder" );
327 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
330 void Patch_XactSphere(){
331 UndoableCommand undo( "patchCreateXactSphere" );
333 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
336 void Patch_XactCone(){
337 UndoableCommand undo( "patchCreateXactCone" );
339 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
342 void Patch_Cylinder(){
343 UndoableCommand undo( "patchCreateCylinder" );
345 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
348 void Patch_DenseCylinder(){
349 UndoableCommand undo( "patchCreateDenseCylinder" );
351 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
354 void Patch_VeryDenseCylinder(){
355 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
357 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
360 void Patch_SquareCylinder(){
361 UndoableCommand undo( "patchCreateSquareCylinder" );
363 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
367 UndoableCommand undo( "patchCreateCaps" );
369 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
373 UndoableCommand undo( "patchCreateBevel" );
375 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
379 UndoableCommand undo( "patchCreateSphere" );
381 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
384 void Patch_SquareBevel(){
387 void Patch_SquareEndcap(){
391 UndoableCommand undo( "patchCreateCone" );
393 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
397 UndoableCommand undo( "patchCreatePlane" );
399 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
402 void Patch_InsertInsertColumn(){
403 UndoableCommand undo( "patchInsertColumns" );
405 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
408 void Patch_InsertAddColumn(){
409 UndoableCommand undo( "patchAddColumns" );
411 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
414 void Patch_InsertInsertRow(){
415 UndoableCommand undo( "patchInsertRows" );
417 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
420 void Patch_InsertAddRow(){
421 UndoableCommand undo( "patchAddRows" );
423 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
426 void Patch_DeleteFirstColumn(){
427 UndoableCommand undo( "patchDeleteFirstColumns" );
429 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
432 void Patch_DeleteLastColumn(){
433 UndoableCommand undo( "patchDeleteLastColumns" );
435 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
438 void Patch_DeleteFirstRow(){
439 UndoableCommand undo( "patchDeleteFirstRows" );
441 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
444 void Patch_DeleteLastRow(){
445 UndoableCommand undo( "patchDeleteLastRows" );
447 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
451 UndoableCommand undo( "patchInvert" );
453 Scene_PatchInvert_Selected( GlobalSceneGraph() );
456 void Patch_RedisperseRows(){
457 UndoableCommand undo( "patchRedisperseRows" );
459 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
462 void Patch_RedisperseCols(){
463 UndoableCommand undo( "patchRedisperseColumns" );
465 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
468 void Patch_SmoothRows(){
469 UndoableCommand undo( "patchSmoothRows" );
471 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
474 void Patch_SmoothCols(){
475 UndoableCommand undo( "patchSmoothColumns" );
477 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
480 void Patch_Transpose(){
481 UndoableCommand undo( "patchTranspose" );
483 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
487 // FIXME: add support for patch cap creation
488 // Patch_CapCurrent();
489 UndoableCommand undo( "patchCreateCaps" );
491 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
494 void Patch_CycleProjection(){
495 UndoableCommand undo( "patchCycleUVProjectionAxis" );
497 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
501 void Patch_OverlayOn(){
505 void Patch_OverlayOff(){
508 void Patch_FlipTextureX(){
509 UndoableCommand undo( "patchFlipTextureU" );
511 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
514 void Patch_FlipTextureY(){
515 UndoableCommand undo( "patchFlipTextureV" );
517 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
520 void Patch_NaturalTexture(){
521 UndoableCommand undo( "patchNaturalTexture" );
523 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
526 void Patch_CapTexture(){
527 UndoableCommand command( "patchCapTexture" );
529 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
532 void Patch_ResetTexture(){
534 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
535 UndoableCommand command( "patchTileTexture" );
536 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
540 void Patch_FitTexture(){
541 UndoableCommand command( "patchFitTexture" );
543 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
549 class filter_patch_all : public PatchFilter
552 bool filter( const Patch& patch ) const {
557 class filter_patch_shader : public PatchFilter
559 const char* m_shader;
561 filter_patch_shader( const char* shader ) : m_shader( shader ){
563 bool filter( const Patch& patch ) const {
564 return shader_equal( patch.GetShader(), m_shader );
568 class filter_patch_flags : public PatchFilter
572 filter_patch_flags( int flags ) : m_flags( flags ){
574 bool filter( const Patch& patch ) const {
575 return ( patch.getShaderFlags() & m_flags ) != 0;
580 filter_patch_all g_filter_patch_all;
581 filter_patch_shader g_filter_patch_clip( "textures/common/clip" );
582 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
583 filter_patch_flags g_filter_patch_translucent( QER_TRANS );
585 void PatchFilters_construct(){
586 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
587 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
588 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
589 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
593 #include "preferences.h"
595 void Patch_constructPreferences( PreferencesPage& page ){
596 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
598 void Patch_constructPage( PreferenceGroup& group ){
599 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
600 Patch_constructPreferences( page );
602 void Patch_registerPreferencesPage(){
603 PreferencesDialog_addDisplayPage( makeCallbackF(Patch_constructPage) );
607 #include "preferencesystem.h"
609 void PatchPreferences_construct(){
610 GlobalPreferenceSystem().registerPreference( "Subdivisions", make_property_string( g_PatchSubdivideThreshold ) );
614 #include "generic/callback.h"
616 void Patch_registerCommands(){
617 GlobalCommands_insert( "InvertCurveTextureX", makeCallbackF(Patch_FlipTextureX), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
618 GlobalCommands_insert( "InvertCurveTextureY", makeCallbackF(Patch_FlipTextureY), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
619 GlobalCommands_insert( "NaturalizePatch", makeCallbackF(Patch_NaturalTexture), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
620 GlobalCommands_insert( "PatchCylinder", makeCallbackF(Patch_Cylinder) );
621 GlobalCommands_insert( "PatchDenseCylinder", makeCallbackF(Patch_DenseCylinder) );
622 GlobalCommands_insert( "PatchVeryDenseCylinder", makeCallbackF(Patch_VeryDenseCylinder) );
623 GlobalCommands_insert( "PatchSquareCylinder", makeCallbackF(Patch_SquareCylinder) );
624 GlobalCommands_insert( "PatchXactCylinder", makeCallbackF(Patch_XactCylinder) );
625 GlobalCommands_insert( "PatchXactSphere", makeCallbackF(Patch_XactSphere) );
626 GlobalCommands_insert( "PatchXactCone", makeCallbackF(Patch_XactCone) );
627 GlobalCommands_insert( "PatchEndCap", makeCallbackF(Patch_Endcap) );
628 GlobalCommands_insert( "PatchBevel", makeCallbackF(Patch_Bevel) );
629 GlobalCommands_insert( "PatchSquareBevel", makeCallbackF(Patch_SquareBevel) );
630 GlobalCommands_insert( "PatchSquareEndcap", makeCallbackF(Patch_SquareEndcap) );
631 GlobalCommands_insert( "PatchCone", makeCallbackF(Patch_Cone) );
632 GlobalCommands_insert( "PatchSphere", makeCallbackF(Patch_Sphere) );
633 GlobalCommands_insert( "SimplePatchMesh", makeCallbackF(Patch_Plane), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
634 GlobalCommands_insert( "PatchInsertInsertColumn", makeCallbackF(Patch_InsertInsertColumn), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
635 GlobalCommands_insert( "PatchInsertAddColumn", makeCallbackF(Patch_InsertAddColumn) );
636 GlobalCommands_insert( "PatchInsertInsertRow", makeCallbackF(Patch_InsertInsertRow), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
637 GlobalCommands_insert( "PatchInsertAddRow", makeCallbackF(Patch_InsertAddRow) );
638 GlobalCommands_insert( "PatchDeleteFirstColumn", makeCallbackF(Patch_DeleteFirstColumn) );
639 GlobalCommands_insert( "PatchDeleteLastColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
640 GlobalCommands_insert( "PatchDeleteFirstRow", makeCallbackF(Patch_DeleteFirstRow), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
641 GlobalCommands_insert( "PatchDeleteLastRow", makeCallbackF(Patch_DeleteLastRow) );
642 GlobalCommands_insert( "InvertCurve", makeCallbackF(Patch_Invert), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
643 GlobalCommands_insert( "RedisperseRows", makeCallbackF(Patch_RedisperseRows), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
644 GlobalCommands_insert( "RedisperseCols", makeCallbackF(Patch_RedisperseCols), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
645 GlobalCommands_insert( "SmoothRows", makeCallbackF(Patch_SmoothRows), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
646 GlobalCommands_insert( "SmoothCols", makeCallbackF(Patch_SmoothCols), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
647 GlobalCommands_insert( "MatrixTranspose", makeCallbackF(Patch_Transpose), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
648 GlobalCommands_insert( "CapCurrentCurve", makeCallbackF(Patch_Cap), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
649 GlobalCommands_insert( "CycleCapTexturePatch", makeCallbackF(Patch_CycleProjection), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
650 GlobalCommands_insert( "MakeOverlayPatch", makeCallbackF(Patch_OverlayOn), Accelerator( 'Y' ) );
651 GlobalCommands_insert( "ClearPatchOverlays", makeCallbackF(Patch_OverlayOff), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
654 void Patch_constructToolbar( ui::Toolbar toolbar ){
655 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "cap_curve.png", "CapCurrentCurve" );
658 void Patch_constructMenu( ui::Menu menu ){
659 create_menu_item_with_mnemonic( menu, "Cylinder", "PatchCylinder" );
661 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
662 if ( g_Layout_enableDetachableMenus.m_value ) {
663 menu_tearoff( menu_in_menu );
665 create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
666 create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
667 create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
668 create_menu_item_with_mnemonic( menu_in_menu, "Exact Cylinder...", "PatchXactCylinder" );
670 menu_separator( menu );
671 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
672 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
674 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
675 if ( g_Layout_enableDetachableMenus.m_value ) {
676 menu_tearoff( menu_in_menu );
678 create_menu_item_with_mnemonic( menu_in_menu, "Square Endcap", "PatchSquareBevel" );
679 create_menu_item_with_mnemonic( menu_in_menu, "Square Bevel", "PatchSquareEndcap" );
681 menu_separator( menu );
682 create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
683 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
684 menu_separator( menu );
685 create_menu_item_with_mnemonic( menu, "Sphere", "PatchSphere" );
686 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
687 menu_separator( menu );
688 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
689 menu_separator( menu );
691 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert" );
692 if ( g_Layout_enableDetachableMenus.m_value ) {
693 menu_tearoff( menu_in_menu );
695 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
696 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
697 menu_separator( menu_in_menu );
698 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
699 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
702 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
703 if ( g_Layout_enableDetachableMenus.m_value ) {
704 menu_tearoff( menu_in_menu );
706 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn" );
707 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn" );
708 menu_separator( menu_in_menu );
709 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow" );
710 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow" );
712 menu_separator( menu );
714 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
715 if ( g_Layout_enableDetachableMenus.m_value ) {
716 menu_tearoff( menu_in_menu );
718 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
719 auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
720 if ( g_Layout_enableDetachableMenus.m_value ) {
721 menu_tearoff( menu_3 );
723 create_menu_item_with_mnemonic( menu_3, "Rows", "RedisperseRows" );
724 create_menu_item_with_mnemonic( menu_3, "Columns", "RedisperseCols" );
725 auto menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
726 if ( g_Layout_enableDetachableMenus.m_value ) {
727 menu_tearoff( menu_4 );
729 create_menu_item_with_mnemonic( menu_4, "Rows", "SmoothRows" );
730 create_menu_item_with_mnemonic( menu_4, "Columns", "SmoothCols" );
731 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
733 menu_separator( menu );
734 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
735 create_menu_item_with_mnemonic( menu, "Cycle Cap Texture", "CycleCapTexturePatch" );
736 menu_separator( menu );
738 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
739 if ( g_Layout_enableDetachableMenus.m_value ) {
740 menu_tearoff( menu_in_menu );
742 create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
743 create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
748 #include "gtkutil/dialog.h"
749 #include "gtkutil/widget.h"
751 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
754 ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog );
756 auto accel = ui::AccelGroup(ui::New);
757 window.add_accel_group( accel );
758 auto width = ui::ComboBoxText(ui::New);
759 auto height = ui::ComboBoxText(ui::New);
761 auto hbox = create_dialog_hbox( 4, 4 );
764 auto table = create_dialog_table( 2, 2, 4, 4 );
765 hbox.pack_start( table, TRUE, TRUE, 0 );
767 auto label = ui::Label( "Width:" );
769 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
770 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
773 auto label = ui::Label( "Height:" );
775 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
776 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
781 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, #x )
796 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
799 table.attach(combo, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
803 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, #x )
818 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
821 table.attach(combo, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
826 auto vbox = create_dialog_vbox( 4 );
827 hbox.pack_start( vbox, TRUE, TRUE, 0 );
829 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
830 vbox.pack_start( button, FALSE, FALSE, 0 );
831 widget_make_default( button );
832 gtk_widget_grab_focus( button );
833 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
836 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
837 vbox.pack_start( button, FALSE, FALSE, 0 );
838 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
844 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
845 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
847 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
848 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
849 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
851 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
860 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
862 ModalDialogButton ok_button( dialog, eIDOK );
863 ModalDialogButton cancel_button( dialog, eIDCANCEL );
864 ui::Widget bevel{ui::null};
865 ui::Widget ibevel{ui::null};
866 ui::Widget endcap{ui::null};
867 ui::Widget iendcap{ui::null};
868 ui::Widget cylinder{ui::null};
870 ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog );
872 auto accel_group = ui::AccelGroup(ui::New);
873 window.add_accel_group( accel_group );
876 auto hbox = create_dialog_hbox( 4, 4 );
880 // Gef: Added a vbox to contain the toggle buttons
881 auto radio_vbox = create_dialog_vbox( 4 );
882 hbox.add(radio_vbox);
885 auto table = ui::Table( 5, 2, FALSE );
887 radio_vbox.pack_start( table, TRUE, TRUE, 0 );
888 gtk_table_set_row_spacings( table, 5 );
889 gtk_table_set_col_spacings( table, 5 );
892 auto image = new_local_image( "cap_bevel.png" );
894 table.attach(image, {0, 1, 0, 1}, {GTK_FILL, 0});
897 auto image = new_local_image( "cap_endcap.png" );
899 table.attach(image, {0, 1, 1, 2}, {GTK_FILL, 0});
902 auto image = new_local_image( "cap_ibevel.png" );
904 table.attach(image, {0, 1, 2, 3}, {GTK_FILL, 0});
907 auto image = new_local_image( "cap_iendcap.png" );
909 table.attach(image, {0, 1, 3, 4}, {GTK_FILL, 0});
912 auto image = new_local_image( "cap_cylinder.png" );
914 table.attach(image, {0, 1, 4, 5}, {GTK_FILL, 0});
919 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Bevel" ));
921 table.attach(button, {1, 2, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
922 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
927 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Endcap" ));
929 table.attach(button, {1, 2, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
930 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
935 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Bevel" ));
937 table.attach(button, {1, 2, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
938 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
943 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Endcap" ));
945 table.attach(button, {1, 2, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
946 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
951 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Cylinder" ));
953 table.attach(button, {1, 2, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
954 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
962 auto vbox = create_dialog_vbox( 4 );
963 hbox.pack_start( vbox, FALSE, FALSE, 0 );
965 auto button = create_modal_dialog_button( "OK", ok_button );
966 vbox.pack_start( button, FALSE, FALSE, 0 );
967 widget_make_default( button );
968 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
971 auto button = create_modal_dialog_button( "Cancel", cancel_button );
972 vbox.pack_start( button, FALSE, FALSE, 0 );
973 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
979 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
981 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
982 if ( ret == eIDOK ) {
983 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
984 *type = PATCHCAP_BEVEL;
986 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
987 *type = PATCHCAP_ENDCAP;
989 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
990 *type = PATCHCAP_INVERTED_BEVEL;
992 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
993 *type = PATCHCAP_INVERTED_ENDCAP;
995 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
996 *type = PATCHCAP_CYLINDER;