| 1 | #include "filterbar.h" |
| 2 | |
| 3 | #include "gtk/gtk.h" |
| 4 | |
| 5 | #include "gtkmisc.h" |
| 6 | #include "gtkutil/widget.h" |
| 7 | #include "stream/stringstream.h" |
| 8 | #include "select.h" |
| 9 | #include "iundo.h" |
| 10 | #include "preferences.h" |
| 11 | |
| 12 | #include "commands.h" |
| 13 | #include "gtkutil/accelerator.h" |
| 14 | #include "generic/callback.h" |
| 15 | |
| 16 | #include "entity.h" |
| 17 | int ToggleActions = 0; |
| 18 | int ButtonNum = 0; |
| 19 | |
| 20 | |
| 21 | gboolean ToggleActions0( ui::Widget widget, GdkEvent *event, gpointer user_data ){ |
| 22 | ToggleActions = 0; |
| 23 | return FALSE; |
| 24 | //globalOutputStream() << "ToggleActions\n"; |
| 25 | } |
| 26 | |
| 27 | |
| 28 | void SetCommonShader( const char* key, const char* shader ){ |
| 29 | const char* gotShader = g_pGameDescription->getKeyValue( key ); |
| 30 | UndoableCommand undo( "textureNameSetSelected" ); |
| 31 | if ( gotShader && *gotShader ){ |
| 32 | Select_SetShader( gotShader ); |
| 33 | } |
| 34 | else{ |
| 35 | Select_SetShader( shader ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | |
| 40 | gboolean Areaportals_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 41 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 42 | if ( ButtonNum == 1 ){ |
| 43 | ToggleActions %= 2; |
| 44 | } |
| 45 | else{ |
| 46 | ToggleActions = 0; |
| 47 | ButtonNum = 1; |
| 48 | } |
| 49 | if( ToggleActions == 0 ){ |
| 50 | SetCommonShader( "shader_nodraw", "textures/common/nodraw" ); |
| 51 | } |
| 52 | else if( ToggleActions == 1 ){ |
| 53 | SetCommonShader( "shader_nodrawnonsolid", "textures/common/nodrawnonsolid" ); |
| 54 | } |
| 55 | //SetCommonShader( "shader_caulk", "textures/common/caulk" ); |
| 56 | //globalOutputStream() << "Found '" << "fullname" << "'\n"; |
| 57 | ToggleActions++; |
| 58 | return TRUE; |
| 59 | } |
| 60 | return FALSE; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | gboolean Caulk_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 65 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 66 | SetCommonShader( "shader_caulk", "textures/common/caulk" ); |
| 67 | ToggleActions = 0; |
| 68 | return TRUE; |
| 69 | } |
| 70 | return FALSE; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | gboolean Clip_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 75 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 76 | if ( ButtonNum == 3 ){ |
| 77 | ToggleActions %= 2; |
| 78 | } |
| 79 | else{ |
| 80 | ToggleActions = 0; |
| 81 | ButtonNum = 3; |
| 82 | } |
| 83 | if( ToggleActions == 0 ){ |
| 84 | SetCommonShader( "shader_clip", "textures/common/clip" ); |
| 85 | } |
| 86 | else if( ToggleActions == 1 ){ |
| 87 | SetCommonShader( "shader_weapclip", "textures/common/weapclip" ); |
| 88 | } |
| 89 | ToggleActions++; |
| 90 | return TRUE; |
| 91 | } |
| 92 | return FALSE; |
| 93 | } |
| 94 | |
| 95 | |
| 96 | gboolean Liquids_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 97 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 98 | if ( ButtonNum == 4 ){ |
| 99 | ToggleActions %= 3; |
| 100 | } |
| 101 | else{ |
| 102 | ToggleActions = 0; |
| 103 | ButtonNum = 4; |
| 104 | } |
| 105 | if( ToggleActions == 0 ){ |
| 106 | SetCommonShader( "shader_watercaulk", "textures/common/watercaulk" ); |
| 107 | } |
| 108 | else if( ToggleActions == 1 ){ |
| 109 | SetCommonShader( "shader_lavacaulk", "textures/common/lavacaulk" ); |
| 110 | } |
| 111 | else if( ToggleActions == 2 ){ |
| 112 | SetCommonShader( "shader_slimecaulk", "textures/common/slimecaulk" ); |
| 113 | } |
| 114 | ToggleActions++; |
| 115 | return TRUE; |
| 116 | } |
| 117 | return FALSE; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | gboolean Hint_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 122 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 123 | if ( ButtonNum == 5 ){ |
| 124 | ToggleActions %= 3; |
| 125 | } |
| 126 | else{ |
| 127 | ToggleActions = 0; |
| 128 | ButtonNum = 5; |
| 129 | } |
| 130 | if( ToggleActions == 0 ){ |
| 131 | SetCommonShader( "shader_hint", "textures/common/hint" ); |
| 132 | } |
| 133 | else if( ToggleActions == 1 ){ |
| 134 | SetCommonShader( "shader_hintlocal", "textures/common/hintlocal" ); |
| 135 | } |
| 136 | else if( ToggleActions == 2 ){ |
| 137 | SetCommonShader( "shader_hintskip", "textures/common/hintskip" ); |
| 138 | } |
| 139 | ToggleActions++; |
| 140 | return TRUE; |
| 141 | } |
| 142 | return FALSE; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | gboolean Trigger_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 147 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 148 | SetCommonShader( "shader_trigger", "textures/common/trigger" ); |
| 149 | ToggleActions = 0; |
| 150 | return TRUE; |
| 151 | } |
| 152 | return FALSE; |
| 153 | } |
| 154 | |
| 155 | gboolean Func_Groups_button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){ |
| 156 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 157 | UndoableCommand undo( "create func_group" ); |
| 158 | Entity_createFromSelection( "func_group", g_vector3_identity ); |
| 159 | ToggleActions = 0; |
| 160 | return TRUE; |
| 161 | } |
| 162 | return FALSE; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | gboolean Detail_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 167 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 168 | GlobalCommands_find( "MakeDetail" ).m_callback(); |
| 169 | ToggleActions = 0; |
| 170 | return TRUE; |
| 171 | } |
| 172 | return FALSE; |
| 173 | } |
| 174 | |
| 175 | |
| 176 | gboolean Structural_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 177 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 178 | GlobalCommands_find( "MakeStructural" ).m_callback(); |
| 179 | ToggleActions = 0; |
| 180 | return TRUE; |
| 181 | } |
| 182 | return FALSE; |
| 183 | } |
| 184 | |
| 185 | gboolean Region_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){ |
| 186 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 187 | GlobalCommands_find( "RegionOff" ).m_callback(); |
| 188 | ToggleActions = 0; |
| 189 | return TRUE; |
| 190 | } |
| 191 | return FALSE; |
| 192 | } |
| 193 | |
| 194 | gboolean Hide_button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){ |
| 195 | if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { |
| 196 | GlobalCommands_find( "ShowHidden" ).m_callback(); |
| 197 | ToggleActions = 0; |
| 198 | return TRUE; |
| 199 | } |
| 200 | return FALSE; |
| 201 | } |
| 202 | |
| 203 | ui::Toolbar create_filter_toolbar(){ |
| 204 | auto toolbar = ui::Toolbar::from( gtk_toolbar_new() ); |
| 205 | gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL ); |
| 206 | gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); |
| 207 | // gtk_toolbar_set_show_arrow( toolbar, TRUE ); |
| 208 | toolbar.show(); |
| 209 | |
| 210 | |
| 211 | auto space = [&]() { |
| 212 | auto btn = ui::ToolItem::from(gtk_separator_tool_item_new()); |
| 213 | btn.show(); |
| 214 | toolbar.add(btn); |
| 215 | }; |
| 216 | |
| 217 | g_signal_connect( G_OBJECT( toolbar ), "enter_notify_event", G_CALLBACK( ToggleActions0 ), 0 ); |
| 218 | |
| 219 | toolbar_append_toggle_button( toolbar, "World (ALT + 1)", "f-world.png", "FilterWorldBrushes" ); |
| 220 | |
| 221 | { |
| 222 | auto button = toolbar_append_toggle_button( toolbar, "Structural (CTRL + SHIFT + D)\nRightClick: MakeStructural", "f-structural.png", "FilterStructural" ); |
| 223 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Structural_button_press ), 0 ); |
| 224 | } |
| 225 | |
| 226 | { |
| 227 | auto button = toolbar_append_toggle_button( toolbar, "Details (CTRL + D)\nRightClick: MakeDetail", "f-details.png", "FilterDetails" ); |
| 228 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Detail_button_press ), 0 ); |
| 229 | } |
| 230 | |
| 231 | { |
| 232 | auto button = toolbar_append_toggle_button( toolbar, "Func_Groups\nRightClick: create func_group", "f-funcgroups.png", "FilterFuncGroups" ); |
| 233 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Func_Groups_button_press ), 0 ); |
| 234 | |
| 235 | toolbar_append_toggle_button( toolbar, "Patches (CTRL + P)", "patch_wireframe.png", "FilterPatches" ); |
| 236 | } |
| 237 | |
| 238 | space(); |
| 239 | |
| 240 | { |
| 241 | if ( g_pGameDescription->mGameType == "doom3" ) { |
| 242 | auto button = toolbar_append_toggle_button( toolbar, "Areaportals (ALT + 3)\nRightClick: toggle tex\n\tnoDraw\n\tnoDrawNonSolid", "f-areaportal.png", "FilterVisportals" ); |
| 243 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Areaportals_button_press ), 0 ); |
| 244 | } |
| 245 | else{ |
| 246 | auto button = toolbar_append_toggle_button( toolbar, "Areaportals (ALT + 3)\nRightClick: toggle tex\n\tnoDraw\n\tnoDrawNonSolid", "f-areaportal.png", "FilterAreaportals" ); |
| 247 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Areaportals_button_press ), 0 ); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | toolbar_append_toggle_button( toolbar, "Translucent (ALT + 4)", "f-translucent.png", "FilterTranslucent" ); |
| 252 | |
| 253 | { |
| 254 | auto button = toolbar_append_toggle_button( toolbar, "Liquids (ALT + 5)\nRightClick: toggle tex\n\twaterCaulk\n\tlavaCaulk\n\tslimeCaulk", "f-liquids.png", "FilterLiquids" ); |
| 255 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Liquids_button_press ), 0 ); |
| 256 | } |
| 257 | |
| 258 | { |
| 259 | auto button = toolbar_append_toggle_button( toolbar, "Caulk (ALT + 6)\nRightClick: tex Caulk", "f-caulk.png", "FilterCaulk" ); |
| 260 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Caulk_button_press ), 0 ); |
| 261 | } |
| 262 | |
| 263 | { |
| 264 | auto button = toolbar_append_toggle_button( toolbar, "Clips (ALT + 7)\nRightClick: toggle tex\n\tplayerClip\n\tweapClip", "f-clip.png", "FilterClips" ); |
| 265 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Clip_button_press ), 0 ); |
| 266 | } |
| 267 | |
| 268 | { |
| 269 | auto button = toolbar_append_toggle_button( toolbar, "HintsSkips (CTRL + H)\nRightClick: toggle tex\n\thint\n\thintLocal\n\thintSkip", "f-hint.png", "FilterHintsSkips" ); |
| 270 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Hint_button_press ), 0 ); |
| 271 | } |
| 272 | |
| 273 | //toolbar_append_toggle_button( toolbar, "Paths (ALT + 8)", "texture_lock.png", "FilterPaths" ); |
| 274 | |
| 275 | space(); |
| 276 | |
| 277 | toolbar_append_toggle_button( toolbar, "Entities (ALT + 2)", "f-entities.png", "FilterEntities" ); |
| 278 | toolbar_append_toggle_button( toolbar, "Lights (ALT + 0)", "f-lights.png", "FilterLights" ); |
| 279 | toolbar_append_toggle_button( toolbar, "Models (SHIFT + M)", "f-models.png", "FilterModels" ); |
| 280 | |
| 281 | { |
| 282 | auto button = toolbar_append_toggle_button( toolbar, "Triggers (CTRL + SHIFT + T)\nRightClick: tex Trigger", "f-triggers.png", "FilterTriggers" ); |
| 283 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Trigger_button_press ), 0 ); |
| 284 | } |
| 285 | |
| 286 | //toolbar_append_toggle_button( toolbar, "Decals (SHIFT + D)", "f-decals.png", "FilterDecals" ); |
| 287 | |
| 288 | space(); |
| 289 | |
| 290 | toolbar_append_button( toolbar, "InvertFilters", "f-invert.png", "InvertFilters" ); |
| 291 | |
| 292 | toolbar_append_button( toolbar, "ResetFilters", "f-reset.png", "ResetFilters" ); |
| 293 | |
| 294 | space(); |
| 295 | |
| 296 | { |
| 297 | auto button = toolbar_append_toggle_button( toolbar, "Region Set Selection (CTRL + SHIFT + R)\nRightClick: Region Off", "f-region.png", "RegionSetSelection" ); |
| 298 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Region_button_press ), 0 ); |
| 299 | } |
| 300 | |
| 301 | { |
| 302 | auto button = toolbar_append_toggle_button( toolbar, "Hide Selected (H)\nRightClick: Show Hidden (SHIFT + H)", "f-hide.png", "HideSelected" ); |
| 303 | g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Hide_button_press ), 0 ); |
| 304 | } |
| 305 | |
| 306 | return toolbar; |
| 307 | } |