]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/filterbar.cpp
Merge commit '6291935031c28286b34cbf4b483181e51c1d8ea6' into master-merge
[xonotic/netradiant.git] / radiant / filterbar.cpp
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
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
156 gboolean Detail_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
157         if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) {
158                 GlobalCommands_find( "MakeDetail" ).m_callback();
159                 ToggleActions = 0;
160                 return TRUE;
161         }
162         return FALSE;
163 }
164
165
166 gboolean Structural_button_press( ui::Widget widget, GdkEventButton *event, gpointer data ){
167         if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) {
168                 GlobalCommands_find( "MakeStructural" ).m_callback();
169                 ToggleActions = 0;
170                 return TRUE;
171         }
172         return FALSE;
173 }
174
175
176 ui::Toolbar create_filter_toolbar(){
177                         auto filter_toolbar = ui::Toolbar::from( gtk_toolbar_new() );
178                         gtk_orientable_set_orientation( GTK_ORIENTABLE(filter_toolbar), GTK_ORIENTATION_HORIZONTAL );
179                         gtk_toolbar_set_style( filter_toolbar, GTK_TOOLBAR_ICONS );
180                         filter_toolbar.show();
181
182
183                         auto space = [&]() {
184                                 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
185                                         btn.show();
186                                         filter_toolbar.add(btn);
187                         };
188
189                         g_signal_connect( G_OBJECT( filter_toolbar ), "enter_notify_event", G_CALLBACK( ToggleActions0 ), 0 );
190
191                         toolbar_append_toggle_button( filter_toolbar, "World (ALT + 1)", "f-world.png", "FilterWorldBrushes" );
192
193                         {
194                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Structural (CTRL + SHIFT + D)\nRightClick: MakeStructural", "f-structural.png", "FilterStructural" );
195                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Structural_button_press ), 0 );
196                         }
197
198                         {
199                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Details (CTRL + D)\nRightClick: MakeDetail", "f-details.png", "FilterDetails" );
200                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Detail_button_press ), 0 );
201                         }
202
203                         toolbar_append_toggle_button( filter_toolbar, "Patches (CTRL + P)", "patch_wireframe.png", "FilterPatches" );
204                         space();
205
206                         {
207                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Areaportals (ALT + 3)\nRightClick: toggle tex\n\tnoDraw\n\tnoDrawNonSolid", "f-areaportal.png", "FilterAreaportals" );
208                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Areaportals_button_press ), 0 );
209                         }
210
211
212                         toolbar_append_toggle_button( filter_toolbar, "Translucent (ALT + 4)", "f-translucent.png", "FilterTranslucent" );
213
214                         {
215                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Liquids (ALT + 5)\nRightClick: toggle tex\n\twaterCaulk\n\tlavaCaulk\n\tslimeCaulk", "f-liquids.png", "FilterLiquids" );
216                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Liquids_button_press ), 0 );
217                         }
218
219                         {
220                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Caulk (ALT + 6)\nRightClick: tex Caulk", "f-caulk.png", "FilterCaulk" );
221                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Caulk_button_press ), 0 );
222                         }
223
224                         {
225                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Clips (ALT + 7)\nRightClick: toggle tex\n\tplayerClip\n\tweapClip", "f-clip.png", "FilterClips" );
226                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Clip_button_press ), 0 );
227                         }
228
229                         {
230                                 auto button = toolbar_append_toggle_button( filter_toolbar, "HintsSkips (CTRL + H)\nRightClick: toggle tex\n\thint\n\thintLocal\n\thintSkip", "f-hint.png", "FilterHintsSkips" );
231                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Hint_button_press ), 0 );
232                         }
233
234                         //toolbar_append_toggle_button( filter_toolbar, "Paths (ALT + 8)", "texture_lock.png", "FilterPaths" );
235                         space();
236                         toolbar_append_toggle_button( filter_toolbar, "Entities (ALT + 2)", "f-entities.png", "FilterEntities" );
237                         toolbar_append_toggle_button( filter_toolbar, "Lights (ALT + 0)", "f-lights.png", "FilterLights" );
238                         toolbar_append_toggle_button( filter_toolbar, "Models (SHIFT + M)", "f-models.png", "FilterModels" );
239
240                         {
241                                 auto button = toolbar_append_toggle_button( filter_toolbar, "Triggers (CTRL + SHIFT + T)\nRightClick: tex Trigger", "f-triggers.png", "FilterTriggers" );
242                                 g_signal_connect( G_OBJECT( button ), "button_press_event", G_CALLBACK( Trigger_button_press ), 0 );
243                         }
244
245                         //toolbar_append_toggle_button( filter_toolbar, "Decals (SHIFT + D)", "f-decals.png", "FilterDecals" );
246                         space();
247                         toolbar_append_button( filter_toolbar, "InvertFilters", "f-invert.png", "InvertFilters" );
248                         toolbar_append_button( filter_toolbar, "ResetFilters", "f-reset.png", "ResetFilters" );
249                         return filter_toolbar;
250 }