| 1 | /* |
| 2 | Copyright (C) 1999-2006 Id Software, Inc. and contributors. |
| 3 | For a list of contributors, see the accompanying CONTRIBUTORS file. |
| 4 | |
| 5 | This file is part of GtkRadiant. |
| 6 | |
| 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. |
| 11 | |
| 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. |
| 16 | |
| 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 |
| 20 | */ |
| 21 | |
| 22 | // |
| 23 | // Surface Dialog |
| 24 | // |
| 25 | // Leonardo Zide ([email protected]) |
| 26 | // |
| 27 | |
| 28 | #include "surfacedialog.h" |
| 29 | |
| 30 | #include <gtk/gtk.h> |
| 31 | |
| 32 | #include "debugging/debugging.h" |
| 33 | #include "warnings.h" |
| 34 | |
| 35 | #include "iscenegraph.h" |
| 36 | #include "itexdef.h" |
| 37 | #include "iundo.h" |
| 38 | #include "iselection.h" |
| 39 | |
| 40 | #include <gdk/gdkkeysyms.h> |
| 41 | |
| 42 | #include "signal/isignal.h" |
| 43 | #include "generic/object.h" |
| 44 | #include "math/vector.h" |
| 45 | #include "texturelib.h" |
| 46 | #include "shaderlib.h" |
| 47 | #include "stringio.h" |
| 48 | |
| 49 | #include "gtkutil/idledraw.h" |
| 50 | #include "gtkutil/dialog.h" |
| 51 | #include "gtkutil/entry.h" |
| 52 | #include "gtkutil/nonmodal.h" |
| 53 | #include "gtkutil/pointer.h" |
| 54 | #include "gtkutil/glwidget.h" //Shamus: For Textool |
| 55 | #include "gtkutil/button.h" |
| 56 | #include "map.h" |
| 57 | #include "select.h" |
| 58 | #include "patchmanip.h" |
| 59 | #include "brushmanip.h" |
| 60 | #include "patchdialog.h" |
| 61 | #include "preferences.h" |
| 62 | #include "brush_primit.h" |
| 63 | #include "xywindow.h" |
| 64 | #include "mainframe.h" |
| 65 | #include "gtkdlgs.h" |
| 66 | #include "dialog.h" |
| 67 | #include "brush.h" //Shamus: for Textool |
| 68 | #include "patch.h" |
| 69 | #include "commands.h" |
| 70 | #include "stream/stringstream.h" |
| 71 | #include "grid.h" |
| 72 | #include "textureentry.h" |
| 73 | |
| 74 | //NOTE: Proper functioning of Textool currently requires that the "#if 1" lines in |
| 75 | // brush_primit.h be changed to "#if 0". add/removeScale screws this up ATM. :-) |
| 76 | // Plus, Radiant seems to work just fine without that stuff. ;-) |
| 77 | |
| 78 | #define TEXTOOL_ENABLED 0 |
| 79 | |
| 80 | #if TEXTOOL_ENABLED |
| 81 | |
| 82 | namespace TexTool |
| 83 | { |
| 84 | |
| 85 | //Shamus: Textool function prototypes |
| 86 | gboolean size_allocate( ui::Widget, GtkAllocation *, gpointer ); |
| 87 | gboolean expose( ui::Widget, GdkEventExpose *, gpointer ); |
| 88 | gboolean button_press( ui::Widget, GdkEventButton *, gpointer ); |
| 89 | gboolean button_release( ui::Widget, GdkEventButton *, gpointer ); |
| 90 | gboolean motion( ui::Widget, GdkEventMotion *, gpointer ); |
| 91 | void flipX( ui::ToggleButton, gpointer ); |
| 92 | void flipY( ui::ToggleButton, gpointer ); |
| 93 | |
| 94 | //End Textool function prototypes |
| 95 | |
| 96 | //Shamus: Textool globals |
| 97 | ui::Widget g_textoolWin; |
| 98 | //End Textool globals |
| 99 | |
| 100 | void queueDraw(){ |
| 101 | #if GTK_TARGET == 3 |
| 102 | gtk_gl_area_queue_render( GTK_GL_AREA((GtkWidget *) g_textoolWin) ); |
| 103 | #else |
| 104 | gtk_widget_queue_draw( g_textoolWin ); |
| 105 | #endif |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | #endif |
| 111 | |
| 112 | inline void spin_button_set_step( ui::SpinButton spin, gfloat step ){ |
| 113 | #if 1 |
| 114 | gtk_adjustment_set_step_increment(gtk_spin_button_get_adjustment( spin ), step); |
| 115 | #else |
| 116 | GValue gvalue = GValue_default(); |
| 117 | g_value_init( &gvalue, G_TYPE_DOUBLE ); |
| 118 | g_value_set_double( &gvalue, step ); |
| 119 | g_object_set( G_OBJECT( gtk_spin_button_get_adjustment( spin ) ), "step-increment", &gvalue, NULL ); |
| 120 | #endif |
| 121 | } |
| 122 | |
| 123 | class Increment |
| 124 | { |
| 125 | float& m_f; |
| 126 | public: |
| 127 | ui::SpinButton m_spin; |
| 128 | ui::Entry m_entry; |
| 129 | Increment( float& f ) : m_f( f ), m_spin( ui::null ), m_entry( ui::null ){ |
| 130 | } |
| 131 | void cancel(){ |
| 132 | entry_set_float( m_entry, m_f ); |
| 133 | } |
| 134 | typedef MemberCaller<Increment, void(), &Increment::cancel> CancelCaller; |
| 135 | void apply(){ |
| 136 | m_f = static_cast<float>( entry_get_float( m_entry ) ); |
| 137 | spin_button_set_step( m_spin, m_f ); |
| 138 | } |
| 139 | typedef MemberCaller<Increment, void(), &Increment::apply> ApplyCaller; |
| 140 | }; |
| 141 | |
| 142 | void SurfaceInspector_GridChange(); |
| 143 | |
| 144 | class SurfaceInspector : public Dialog |
| 145 | { |
| 146 | ui::Window BuildDialog(); |
| 147 | |
| 148 | NonModalEntry m_textureEntry; |
| 149 | NonModalSpinner m_hshiftSpinner; |
| 150 | NonModalEntry m_hshiftEntry; |
| 151 | NonModalSpinner m_vshiftSpinner; |
| 152 | NonModalEntry m_vshiftEntry; |
| 153 | NonModalSpinner m_hscaleSpinner; |
| 154 | NonModalEntry m_hscaleEntry; |
| 155 | NonModalSpinner m_vscaleSpinner; |
| 156 | NonModalEntry m_vscaleEntry; |
| 157 | NonModalSpinner m_rotateSpinner; |
| 158 | NonModalEntry m_rotateEntry; |
| 159 | |
| 160 | IdleDraw m_idleDraw; |
| 161 | |
| 162 | GtkCheckButton* m_surfaceFlags[32]; |
| 163 | GtkCheckButton* m_contentFlags[32]; |
| 164 | |
| 165 | NonModalEntry m_valueEntry; |
| 166 | ui::Entry m_valueEntryWidget{ui::null}; |
| 167 | public: |
| 168 | WindowPositionTracker m_positionTracker; |
| 169 | |
| 170 | // Dialog Data |
| 171 | float m_fitHorizontal; |
| 172 | float m_fitVertical; |
| 173 | |
| 174 | Increment m_hshiftIncrement; |
| 175 | Increment m_vshiftIncrement; |
| 176 | Increment m_hscaleIncrement; |
| 177 | Increment m_vscaleIncrement; |
| 178 | Increment m_rotateIncrement; |
| 179 | ui::Entry m_texture{ui::null}; |
| 180 | |
| 181 | SurfaceInspector() : |
| 182 | m_textureEntry( ApplyShaderCaller( *this ), UpdateCaller( *this ) ), |
| 183 | m_hshiftSpinner( ApplyTexdefCaller( *this ), UpdateCaller( *this ) ), |
| 184 | m_hshiftEntry( Increment::ApplyCaller( m_hshiftIncrement ), Increment::CancelCaller( m_hshiftIncrement ) ), |
| 185 | m_vshiftSpinner( ApplyTexdefCaller( *this ), UpdateCaller( *this ) ), |
| 186 | m_vshiftEntry( Increment::ApplyCaller( m_vshiftIncrement ), Increment::CancelCaller( m_vshiftIncrement ) ), |
| 187 | m_hscaleSpinner( ApplyTexdefCaller( *this ), UpdateCaller( *this ) ), |
| 188 | m_hscaleEntry( Increment::ApplyCaller( m_hscaleIncrement ), Increment::CancelCaller( m_hscaleIncrement ) ), |
| 189 | m_vscaleSpinner( ApplyTexdefCaller( *this ), UpdateCaller( *this ) ), |
| 190 | m_vscaleEntry( Increment::ApplyCaller( m_vscaleIncrement ), Increment::CancelCaller( m_vscaleIncrement ) ), |
| 191 | m_rotateSpinner( ApplyTexdefCaller( *this ), UpdateCaller( *this ) ), |
| 192 | m_rotateEntry( Increment::ApplyCaller( m_rotateIncrement ), Increment::CancelCaller( m_rotateIncrement ) ), |
| 193 | m_idleDraw( UpdateCaller( *this ) ), |
| 194 | m_valueEntry( ApplyFlagsCaller( *this ), UpdateCaller( *this ) ), |
| 195 | m_hshiftIncrement( g_si_globals.shift[0] ), |
| 196 | m_vshiftIncrement( g_si_globals.shift[1] ), |
| 197 | m_hscaleIncrement( g_si_globals.scale[0] ), |
| 198 | m_vscaleIncrement( g_si_globals.scale[1] ), |
| 199 | m_rotateIncrement( g_si_globals.rotate ){ |
| 200 | m_fitVertical = 1; |
| 201 | m_fitHorizontal = 1; |
| 202 | m_positionTracker.setPosition( c_default_window_pos ); |
| 203 | } |
| 204 | |
| 205 | void constructWindow( ui::Window main_window ){ |
| 206 | m_parent = main_window; |
| 207 | Create(); |
| 208 | AddGridChangeCallback( FreeCaller<void(), SurfaceInspector_GridChange>() ); |
| 209 | } |
| 210 | void destroyWindow(){ |
| 211 | Destroy(); |
| 212 | } |
| 213 | bool visible() { |
| 214 | return GetWidget().visible(); |
| 215 | } |
| 216 | void queueDraw(){ |
| 217 | if ( visible() ) { |
| 218 | m_idleDraw.queueDraw(); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | void Update(); |
| 223 | typedef MemberCaller<SurfaceInspector, void(), &SurfaceInspector::Update> UpdateCaller; |
| 224 | void ApplyShader(); |
| 225 | typedef MemberCaller<SurfaceInspector, void(), &SurfaceInspector::ApplyShader> ApplyShaderCaller; |
| 226 | void ApplyTexdef(); |
| 227 | typedef MemberCaller<SurfaceInspector, void(), &SurfaceInspector::ApplyTexdef> ApplyTexdefCaller; |
| 228 | void ApplyFlags(); |
| 229 | typedef MemberCaller<SurfaceInspector, void(), &SurfaceInspector::ApplyFlags> ApplyFlagsCaller; |
| 230 | }; |
| 231 | |
| 232 | namespace |
| 233 | { |
| 234 | SurfaceInspector* g_SurfaceInspector; |
| 235 | |
| 236 | inline SurfaceInspector& getSurfaceInspector(){ |
| 237 | ASSERT_NOTNULL( g_SurfaceInspector ); |
| 238 | return *g_SurfaceInspector; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | void SurfaceInspector_constructWindow( ui::Window main_window ){ |
| 243 | getSurfaceInspector().constructWindow( main_window ); |
| 244 | } |
| 245 | void SurfaceInspector_destroyWindow(){ |
| 246 | getSurfaceInspector().destroyWindow(); |
| 247 | } |
| 248 | |
| 249 | void SurfaceInspector_queueDraw(){ |
| 250 | getSurfaceInspector().queueDraw(); |
| 251 | } |
| 252 | |
| 253 | namespace |
| 254 | { |
| 255 | CopiedString g_selectedShader; |
| 256 | TextureProjection g_selectedTexdef; |
| 257 | ContentsFlagsValue g_selectedFlags; |
| 258 | size_t g_selectedShaderSize[2]; |
| 259 | } |
| 260 | |
| 261 | void SurfaceInspector_SetSelectedShader( const char* shader ){ |
| 262 | g_selectedShader = shader; |
| 263 | SurfaceInspector_queueDraw(); |
| 264 | } |
| 265 | |
| 266 | void SurfaceInspector_SetSelectedTexdef( const TextureProjection& projection ){ |
| 267 | g_selectedTexdef = projection; |
| 268 | SurfaceInspector_queueDraw(); |
| 269 | } |
| 270 | |
| 271 | void SurfaceInspector_SetSelectedFlags( const ContentsFlagsValue& flags ){ |
| 272 | g_selectedFlags = flags; |
| 273 | SurfaceInspector_queueDraw(); |
| 274 | } |
| 275 | |
| 276 | static bool s_texture_selection_dirty = false; |
| 277 | |
| 278 | void SurfaceInspector_updateSelection(){ |
| 279 | s_texture_selection_dirty = true; |
| 280 | SurfaceInspector_queueDraw(); |
| 281 | |
| 282 | #if TEXTOOL_ENABLED |
| 283 | if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) { |
| 284 | TexTool::queueDraw(); |
| 285 | //globalOutputStream() << "textool texture changed..\n"; |
| 286 | } |
| 287 | #endif |
| 288 | } |
| 289 | |
| 290 | void SurfaceInspector_SelectionChanged( const Selectable& selectable ){ |
| 291 | SurfaceInspector_updateSelection(); |
| 292 | } |
| 293 | |
| 294 | void SurfaceInspector_SetCurrent_FromSelected(){ |
| 295 | if ( s_texture_selection_dirty == true ) { |
| 296 | s_texture_selection_dirty = false; |
| 297 | if ( !g_SelectedFaceInstances.empty() ) { |
| 298 | TextureProjection projection; |
| 299 | //This *may* be the point before it fucks up... Let's see! |
| 300 | //Yep, there was a call to removeScale in there... |
| 301 | Scene_BrushGetTexdef_Component_Selected( GlobalSceneGraph(), projection ); |
| 302 | |
| 303 | SurfaceInspector_SetSelectedTexdef( projection ); |
| 304 | |
| 305 | Scene_BrushGetShaderSize_Component_Selected( GlobalSceneGraph(), g_selectedShaderSize[0], g_selectedShaderSize[1] ); |
| 306 | g_selectedTexdef.m_brushprimit_texdef.coords[0][2] = float_mod( g_selectedTexdef.m_brushprimit_texdef.coords[0][2], (float)g_selectedShaderSize[0] ); |
| 307 | g_selectedTexdef.m_brushprimit_texdef.coords[1][2] = float_mod( g_selectedTexdef.m_brushprimit_texdef.coords[1][2], (float)g_selectedShaderSize[1] ); |
| 308 | |
| 309 | CopiedString name; |
| 310 | Scene_BrushGetShader_Component_Selected( GlobalSceneGraph(), name ); |
| 311 | if ( string_not_empty( name.c_str() ) ) { |
| 312 | SurfaceInspector_SetSelectedShader( name.c_str() ); |
| 313 | } |
| 314 | |
| 315 | ContentsFlagsValue flags; |
| 316 | Scene_BrushGetFlags_Component_Selected( GlobalSceneGraph(), flags ); |
| 317 | SurfaceInspector_SetSelectedFlags( flags ); |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | TextureProjection projection; |
| 322 | Scene_BrushGetTexdef_Selected( GlobalSceneGraph(), projection ); |
| 323 | SurfaceInspector_SetSelectedTexdef( projection ); |
| 324 | |
| 325 | CopiedString name; |
| 326 | Scene_BrushGetShader_Selected( GlobalSceneGraph(), name ); |
| 327 | if ( string_empty( name.c_str() ) ) { |
| 328 | Scene_PatchGetShader_Selected( GlobalSceneGraph(), name ); |
| 329 | } |
| 330 | if ( string_not_empty( name.c_str() ) ) { |
| 331 | SurfaceInspector_SetSelectedShader( name.c_str() ); |
| 332 | } |
| 333 | |
| 334 | ContentsFlagsValue flags( 0, 0, 0, false ); |
| 335 | Scene_BrushGetFlags_Selected( GlobalSceneGraph(), flags ); |
| 336 | SurfaceInspector_SetSelectedFlags( flags ); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | const char* SurfaceInspector_GetSelectedShader(){ |
| 342 | SurfaceInspector_SetCurrent_FromSelected(); |
| 343 | return g_selectedShader.c_str(); |
| 344 | } |
| 345 | |
| 346 | const TextureProjection& SurfaceInspector_GetSelectedTexdef(){ |
| 347 | SurfaceInspector_SetCurrent_FromSelected(); |
| 348 | return g_selectedTexdef; |
| 349 | } |
| 350 | |
| 351 | const ContentsFlagsValue& SurfaceInspector_GetSelectedFlags(){ |
| 352 | SurfaceInspector_SetCurrent_FromSelected(); |
| 353 | return g_selectedFlags; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | |
| 358 | /* |
| 359 | =================================================== |
| 360 | |
| 361 | SURFACE INSPECTOR |
| 362 | |
| 363 | =================================================== |
| 364 | */ |
| 365 | |
| 366 | si_globals_t g_si_globals; |
| 367 | |
| 368 | |
| 369 | // make the shift increments match the grid settings |
| 370 | // the objective being that the shift+arrows shortcuts move the texture by the corresponding grid size |
| 371 | // this depends on a scale value if you have selected a particular texture on which you want it to work: |
| 372 | // we move the textures in pixels, not world units. (i.e. increment values are in pixel) |
| 373 | // depending on the texture scale it doesn't take the same amount of pixels to move of GetGridSize() |
| 374 | // increment * scale = gridsize |
| 375 | // hscale and vscale are optional parameters, if they are zero they will be set to the default scale |
| 376 | // NOTE: the default scale depends if you are using BP mode or regular. |
| 377 | // For regular it's 0.5f (128 pixels cover 64 world units), for BP it's simply 1.0f |
| 378 | // see fenris #2810 |
| 379 | void DoSnapTToGrid( float hscale, float vscale ){ |
| 380 | g_si_globals.shift[0] = static_cast<float>( float_to_integer( static_cast<float>( GetGridSize() ) / hscale ) ); |
| 381 | g_si_globals.shift[1] = static_cast<float>( float_to_integer( static_cast<float>( GetGridSize() ) / vscale ) ); |
| 382 | getSurfaceInspector().queueDraw(); |
| 383 | } |
| 384 | |
| 385 | void SurfaceInspector_GridChange(){ |
| 386 | if ( g_si_globals.m_bSnapTToGrid ) { |
| 387 | DoSnapTToGrid( Texdef_getDefaultTextureScale(), Texdef_getDefaultTextureScale() ); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | // make the shift increments match the grid settings |
| 392 | // the objective being that the shift+arrows shortcuts move the texture by the corresponding grid size |
| 393 | // this depends on the current texture scale used? |
| 394 | // we move the textures in pixels, not world units. (i.e. increment values are in pixel) |
| 395 | // depending on the texture scale it doesn't take the same amount of pixels to move of GetGridSize() |
| 396 | // increment * scale = gridsize |
| 397 | static void OnBtnMatchGrid( ui::Widget widget, gpointer data ){ |
| 398 | float hscale, vscale; |
| 399 | hscale = static_cast<float>( gtk_spin_button_get_value( getSurfaceInspector().m_hscaleIncrement.m_spin ) ); |
| 400 | vscale = static_cast<float>( gtk_spin_button_get_value( getSurfaceInspector().m_vscaleIncrement.m_spin ) ); |
| 401 | |
| 402 | if ( hscale == 0.0f || vscale == 0.0f ) { |
| 403 | globalOutputStream() << "ERROR: unexpected scale == 0.0f\n"; |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | DoSnapTToGrid( hscale, vscale ); |
| 408 | } |
| 409 | |
| 410 | // DoSurface will always try to show the surface inspector |
| 411 | // or update it because something new has been selected |
| 412 | // Shamus: It does get called when the SI is hidden, but not when you select something new. ;-) |
| 413 | void DoSurface( void ){ |
| 414 | if ( !getSurfaceInspector().GetWidget() ) { |
| 415 | getSurfaceInspector().Create(); |
| 416 | |
| 417 | } |
| 418 | getSurfaceInspector().Update(); |
| 419 | //getSurfaceInspector().importData(); //happens in .ShowDlg() anyway |
| 420 | getSurfaceInspector().ShowDlg(); |
| 421 | } |
| 422 | |
| 423 | void SurfaceInspector_toggleShown(){ |
| 424 | if ( getSurfaceInspector().visible() ) { |
| 425 | getSurfaceInspector().HideDlg(); |
| 426 | } |
| 427 | else |
| 428 | { |
| 429 | DoSurface(); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | void SurfaceInspector_FitTexture(){ |
| 434 | UndoableCommand undo( "textureAutoFit" ); |
| 435 | Select_FitTexture( getSurfaceInspector().m_fitHorizontal, getSurfaceInspector().m_fitVertical ); |
| 436 | } |
| 437 | |
| 438 | void SurfaceInspector_FitTextureW(){ |
| 439 | UndoableCommand undo( "textureAutoFitW" ); |
| 440 | Select_FitTexture( getSurfaceInspector().m_fitHorizontal, 0 ); |
| 441 | } |
| 442 | |
| 443 | void SurfaceInspector_FitTextureH(){ |
| 444 | UndoableCommand undo( "textureAutoFitH" ); |
| 445 | Select_FitTexture( 0, getSurfaceInspector().m_fitVertical ); |
| 446 | } |
| 447 | |
| 448 | static void OnBtnPatchdetails( ui::Widget widget, gpointer data ){ |
| 449 | Patch_CapTexture(); |
| 450 | } |
| 451 | |
| 452 | static void OnBtnPatchnatural( ui::Widget widget, gpointer data ){ |
| 453 | Patch_NaturalTexture(); |
| 454 | } |
| 455 | |
| 456 | static void OnBtnPatchreset( ui::Widget widget, gpointer data ){ |
| 457 | Patch_ResetTexture(); |
| 458 | } |
| 459 | |
| 460 | static void OnBtnPatchFit( ui::Widget widget, gpointer data ){ |
| 461 | Patch_FitTexture(); |
| 462 | } |
| 463 | |
| 464 | static void OnBtnAxial( ui::Widget widget, gpointer data ){ |
| 465 | //globalOutputStream() << "--> [OnBtnAxial]...\n"; |
| 466 | UndoableCommand undo( "textureDefault" ); |
| 467 | TextureProjection projection; |
| 468 | //globalOutputStream() << " TexDef_Construct_Default()...\n"; |
| 469 | TexDef_Construct_Default( projection ); |
| 470 | //globalOutputStream() << " Select_SetTexdef()...\n"; |
| 471 | |
| 472 | #if TEXTOOL_ENABLED |
| 473 | |
| 474 | //Shamus: |
| 475 | if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) { |
| 476 | // Scale up texture width/height if in BP mode... |
| 477 | //NOTE: This may not be correct any more! :-P |
| 478 | if ( !g_SelectedFaceInstances.empty() ) { |
| 479 | Face & face = g_SelectedFaceInstances.last().getFace(); |
| 480 | float x = face.getShader().m_state->getTexture().width; |
| 481 | float y = face.getShader().m_state->getTexture().height; |
| 482 | projection.m_brushprimit_texdef.coords[0][0] /= x; |
| 483 | projection.m_brushprimit_texdef.coords[0][1] /= y; |
| 484 | projection.m_brushprimit_texdef.coords[1][0] /= x; |
| 485 | projection.m_brushprimit_texdef.coords[1][1] /= y; |
| 486 | } |
| 487 | } |
| 488 | #endif |
| 489 | |
| 490 | Select_SetTexdef( projection ); |
| 491 | } |
| 492 | |
| 493 | static void OnBtnFaceFit( ui::Widget widget, gpointer data ){ |
| 494 | getSurfaceInspector().exportData(); |
| 495 | SurfaceInspector_FitTexture(); |
| 496 | } |
| 497 | |
| 498 | static void OnBtnFaceFitW( GtkWidget *widget, gpointer data ){ |
| 499 | getSurfaceInspector().exportData(); |
| 500 | SurfaceInspector_FitTextureW(); |
| 501 | } |
| 502 | |
| 503 | static void OnBtnFaceFitH( GtkWidget *widget, gpointer data ){ |
| 504 | getSurfaceInspector().exportData(); |
| 505 | SurfaceInspector_FitTextureH(); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | |
| 510 | typedef const char* FlagName; |
| 511 | |
| 512 | const FlagName surfaceflagNamesDefault[32] = { |
| 513 | "surf1", |
| 514 | "surf2", |
| 515 | "surf3", |
| 516 | "surf4", |
| 517 | "surf5", |
| 518 | "surf6", |
| 519 | "surf7", |
| 520 | "surf8", |
| 521 | "surf9", |
| 522 | "surf10", |
| 523 | "surf11", |
| 524 | "surf12", |
| 525 | "surf13", |
| 526 | "surf14", |
| 527 | "surf15", |
| 528 | "surf16", |
| 529 | "surf17", |
| 530 | "surf18", |
| 531 | "surf19", |
| 532 | "surf20", |
| 533 | "surf21", |
| 534 | "surf22", |
| 535 | "surf23", |
| 536 | "surf24", |
| 537 | "surf25", |
| 538 | "surf26", |
| 539 | "surf27", |
| 540 | "surf28", |
| 541 | "surf29", |
| 542 | "surf30", |
| 543 | "surf31", |
| 544 | "surf32" |
| 545 | }; |
| 546 | |
| 547 | const FlagName contentflagNamesDefault[32] = { |
| 548 | "cont1", |
| 549 | "cont2", |
| 550 | "cont3", |
| 551 | "cont4", |
| 552 | "cont5", |
| 553 | "cont6", |
| 554 | "cont7", |
| 555 | "cont8", |
| 556 | "cont9", |
| 557 | "cont10", |
| 558 | "cont11", |
| 559 | "cont12", |
| 560 | "cont13", |
| 561 | "cont14", |
| 562 | "cont15", |
| 563 | "cont16", |
| 564 | "cont17", |
| 565 | "cont18", |
| 566 | "cont19", |
| 567 | "cont20", |
| 568 | "cont21", |
| 569 | "cont22", |
| 570 | "cont23", |
| 571 | "cont24", |
| 572 | "cont25", |
| 573 | "cont26", |
| 574 | "cont27", |
| 575 | "cont28", |
| 576 | "cont29", |
| 577 | "cont30", |
| 578 | "cont31", |
| 579 | "cont32" |
| 580 | }; |
| 581 | |
| 582 | const char* getSurfaceFlagName( std::size_t bit ){ |
| 583 | const char* value = g_pGameDescription->getKeyValue( surfaceflagNamesDefault[bit] ); |
| 584 | if ( string_empty( value ) ) { |
| 585 | return surfaceflagNamesDefault[bit]; |
| 586 | } |
| 587 | return value; |
| 588 | } |
| 589 | |
| 590 | const char* getContentFlagName( std::size_t bit ){ |
| 591 | const char* value = g_pGameDescription->getKeyValue( contentflagNamesDefault[bit] ); |
| 592 | if ( string_empty( value ) ) { |
| 593 | return contentflagNamesDefault[bit]; |
| 594 | } |
| 595 | return value; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | // ============================================================================= |
| 600 | // SurfaceInspector class |
| 601 | |
| 602 | guint togglebutton_connect_toggled( ui::ToggleButton button, const Callback<void()>& callback ){ |
| 603 | return g_signal_connect_swapped( G_OBJECT( button ), "toggled", G_CALLBACK( callback.getThunk() ), callback.getEnvironment() ); |
| 604 | } |
| 605 | |
| 606 | ui::Window SurfaceInspector::BuildDialog(){ |
| 607 | ui::Window window = ui::Window(create_floating_window( "Surface Inspector", m_parent )); |
| 608 | |
| 609 | m_positionTracker.connect( window ); |
| 610 | |
| 611 | global_accel_connect_window( window ); |
| 612 | |
| 613 | window_connect_focus_in_clear_focus_widget( window ); |
| 614 | |
| 615 | |
| 616 | { |
| 617 | // replaced by only the vbox: |
| 618 | auto vbox = ui::VBox( FALSE, 5 ); |
| 619 | vbox.show(); |
| 620 | window.add(vbox); |
| 621 | gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 ); |
| 622 | |
| 623 | { |
| 624 | auto hbox2 = ui::HBox( FALSE, 5 ); |
| 625 | hbox2.show(); |
| 626 | vbox.pack_start( hbox2, FALSE, FALSE, 0 ); |
| 627 | |
| 628 | { |
| 629 | ui::Widget label = ui::Label( "Texture" ); |
| 630 | label.show(); |
| 631 | hbox2.pack_start( label, FALSE, TRUE, 0 ); |
| 632 | } |
| 633 | { |
| 634 | auto entry = ui::Entry(ui::New); |
| 635 | entry.show(); |
| 636 | hbox2.pack_start( entry, TRUE, TRUE, 0 ); |
| 637 | m_texture = entry; |
| 638 | m_textureEntry.connect( entry ); |
| 639 | GlobalTextureEntryCompletion::instance().connect( entry ); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | |
| 644 | { |
| 645 | auto table = ui::Table(6, 4, FALSE); |
| 646 | table.show(); |
| 647 | vbox.pack_start( table, FALSE, FALSE, 0 ); |
| 648 | gtk_table_set_row_spacings(table, 5); |
| 649 | gtk_table_set_col_spacings(table, 5); |
| 650 | { |
| 651 | ui::Widget label = ui::Label( "Horizontal shift" ); |
| 652 | label.show(); |
| 653 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 654 | table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0}); |
| 655 | } |
| 656 | { |
| 657 | auto spin = ui::SpinButton( ui::Adjustment( 0, -8192, 8192, 2, 8, 0 ), 0, 2 ); |
| 658 | m_hshiftIncrement.m_spin = spin; |
| 659 | m_hshiftSpinner.connect( spin ); |
| 660 | spin.show(); |
| 661 | table.attach(spin, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0}); |
| 662 | spin.dimensions(60, -1); |
| 663 | } |
| 664 | { |
| 665 | ui::Widget label = ui::Label( "Step" ); |
| 666 | label.show(); |
| 667 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 668 | table.attach(label, {2, 3, 0, 1}, {GTK_FILL, 0}); |
| 669 | } |
| 670 | { |
| 671 | auto entry = ui::Entry(ui::New); |
| 672 | entry.show(); |
| 673 | table.attach(entry, {3, 4, 0, 1}, {GTK_EXPAND | GTK_FILL, 0}); |
| 674 | entry.dimensions(50, -1); |
| 675 | m_hshiftIncrement.m_entry = entry; |
| 676 | m_hshiftEntry.connect( entry ); |
| 677 | } |
| 678 | { |
| 679 | ui::Widget label = ui::Label( "Vertical shift" ); |
| 680 | label.show(); |
| 681 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 682 | table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0}); |
| 683 | } |
| 684 | { |
| 685 | auto spin = ui::SpinButton( ui::Adjustment( 0, -8192, 8192, 2, 8, 0 ), 0, 2 ); |
| 686 | m_vshiftIncrement.m_spin = spin; |
| 687 | m_vshiftSpinner.connect( spin ); |
| 688 | spin.show(); |
| 689 | table.attach(spin, {1, 2, 1, 2}, {GTK_FILL, 0}); |
| 690 | spin.dimensions(60, -1); |
| 691 | } |
| 692 | { |
| 693 | ui::Widget label = ui::Label( "Step" ); |
| 694 | label.show(); |
| 695 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 696 | table.attach(label, {2, 3, 1, 2}, {GTK_FILL, 0}); |
| 697 | } |
| 698 | { |
| 699 | auto entry = ui::Entry(ui::New); |
| 700 | entry.show(); |
| 701 | table.attach(entry, {3, 4, 1, 2}, {GTK_FILL, 0}); |
| 702 | entry.dimensions(50, -1); |
| 703 | m_vshiftIncrement.m_entry = entry; |
| 704 | m_vshiftEntry.connect( entry ); |
| 705 | } |
| 706 | { |
| 707 | ui::Widget label = ui::Label( "Horizontal stretch" ); |
| 708 | label.show(); |
| 709 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 710 | table.attach(label, {0, 1, 2, 3}, {GTK_FILL, 0}); |
| 711 | } |
| 712 | { |
| 713 | auto spin = ui::SpinButton( ui::Adjustment( 0, -8192, 8192, 2, 8, 0 ), 0, 5 ); |
| 714 | m_hscaleIncrement.m_spin = spin; |
| 715 | m_hscaleSpinner.connect( spin ); |
| 716 | spin.show(); |
| 717 | table.attach(spin, {1, 2, 2, 3}, {GTK_FILL, 0}); |
| 718 | spin.dimensions(60, -1); |
| 719 | } |
| 720 | { |
| 721 | ui::Widget label = ui::Label( "Step" ); |
| 722 | label.show(); |
| 723 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 724 | table.attach(label, {2, 3, 2, 3}, {GTK_FILL, 0}); |
| 725 | } |
| 726 | { |
| 727 | auto entry = ui::Entry(ui::New); |
| 728 | entry.show(); |
| 729 | table.attach(entry, {3, 4, 2, 3}, {GTK_FILL, 0}); |
| 730 | entry.dimensions(50, -1); |
| 731 | m_hscaleIncrement.m_entry = entry; |
| 732 | m_hscaleEntry.connect( entry ); |
| 733 | } |
| 734 | { |
| 735 | ui::Widget label = ui::Label( "Vertical stretch" ); |
| 736 | label.show(); |
| 737 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 738 | table.attach(label, {0, 1, 3, 4}, {GTK_FILL, 0}); |
| 739 | } |
| 740 | { |
| 741 | auto spin = ui::SpinButton( ui::Adjustment( 0, -8192, 8192, 2, 8, 0 ), 0, 5 ); |
| 742 | m_vscaleIncrement.m_spin = spin; |
| 743 | m_vscaleSpinner.connect( spin ); |
| 744 | spin.show(); |
| 745 | table.attach(spin, {1, 2, 3, 4}, {GTK_FILL, 0}); |
| 746 | spin.dimensions(60, -1); |
| 747 | } |
| 748 | { |
| 749 | ui::Widget label = ui::Label( "Step" ); |
| 750 | label.show(); |
| 751 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 752 | table.attach(label, {2, 3, 3, 4}, {GTK_FILL, 0}); |
| 753 | } |
| 754 | { |
| 755 | auto entry = ui::Entry(ui::New); |
| 756 | entry.show(); |
| 757 | table.attach(entry, {3, 4, 3, 4}, {GTK_FILL, 0}); |
| 758 | entry.dimensions(50, -1); |
| 759 | m_vscaleIncrement.m_entry = entry; |
| 760 | m_vscaleEntry.connect( entry ); |
| 761 | } |
| 762 | { |
| 763 | ui::Widget label = ui::Label( "Rotate" ); |
| 764 | label.show(); |
| 765 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 766 | table.attach(label, {0, 1, 4, 5}, {GTK_FILL, 0}); |
| 767 | } |
| 768 | { |
| 769 | auto spin = ui::SpinButton( ui::Adjustment( 0, -8192, 8192, 2, 8, 0 ), 0, 2 ); |
| 770 | m_rotateIncrement.m_spin = spin; |
| 771 | m_rotateSpinner.connect( spin ); |
| 772 | spin.show(); |
| 773 | table.attach(spin, {1, 2, 4, 5}, {GTK_FILL, 0}); |
| 774 | spin.dimensions(60, -1); |
| 775 | gtk_spin_button_set_wrap( spin, TRUE ); |
| 776 | } |
| 777 | { |
| 778 | ui::Widget label = ui::Label( "Step" ); |
| 779 | label.show(); |
| 780 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 ); |
| 781 | table.attach(label, {2, 3, 4, 5}, {GTK_FILL, 0}); |
| 782 | } |
| 783 | { |
| 784 | auto entry = ui::Entry(ui::New); |
| 785 | entry.show(); |
| 786 | table.attach(entry, {3, 4, 4, 5}, {GTK_FILL, 0}); |
| 787 | entry.dimensions(50, -1); |
| 788 | m_rotateIncrement.m_entry = entry; |
| 789 | m_rotateEntry.connect( entry ); |
| 790 | } |
| 791 | { |
| 792 | // match grid button |
| 793 | ui::Widget button = ui::Button( "Match Grid" ); |
| 794 | button.show(); |
| 795 | table.attach(button, {2, 4, 5, 6}, {GTK_EXPAND | GTK_FILL, 0}); |
| 796 | button.connect( "clicked", G_CALLBACK( OnBtnMatchGrid ), 0 ); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | { |
| 801 | auto frame = ui::Frame( "Texturing" ); |
| 802 | frame.show(); |
| 803 | vbox.pack_start( frame, FALSE, FALSE, 0 ); |
| 804 | { |
| 805 | auto table = ui::Table(4, 4, FALSE); |
| 806 | table.show(); |
| 807 | frame.add(table); |
| 808 | gtk_table_set_row_spacings(table, 5); |
| 809 | gtk_table_set_col_spacings(table, 5); |
| 810 | gtk_container_set_border_width( GTK_CONTAINER( table ), 5 ); |
| 811 | { |
| 812 | ui::Widget label = ui::Label( "Brush" ); |
| 813 | label.show(); |
| 814 | table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0}); |
| 815 | } |
| 816 | { |
| 817 | ui::Widget label = ui::Label( "Patch" ); |
| 818 | label.show(); |
| 819 | table.attach(label, {0, 1, 2, 3}, {GTK_FILL, 0}); |
| 820 | } |
| 821 | { |
| 822 | ui::Widget label = ui::Label( "Width" ); |
| 823 | label.show(); |
| 824 | table.attach(label, {2, 3, 0, 1}, {GTK_FILL, 0}); |
| 825 | } |
| 826 | { |
| 827 | ui::Widget label = ui::Label( "Height" ); |
| 828 | label.show(); |
| 829 | table.attach(label, {3, 4, 0, 1}, {GTK_FILL, 0}); |
| 830 | } |
| 831 | { |
| 832 | ui::Widget button = ui::Button( "Axial" ); |
| 833 | button.show(); |
| 834 | table.attach(button, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); |
| 835 | button.connect( "clicked", |
| 836 | G_CALLBACK( OnBtnAxial ), 0 ); |
| 837 | button.dimensions(60, -1); |
| 838 | } |
| 839 | { |
| 840 | ui::Widget button = ui::Button( "Fit" ); |
| 841 | button.show(); |
| 842 | table.attach(button, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); |
| 843 | button.connect( "clicked", |
| 844 | G_CALLBACK( OnBtnFaceFit ), 0 ); |
| 845 | button.dimensions(60, -1); |
| 846 | } |
| 847 | { |
| 848 | ui::Widget button = ui::Button( "CAP" ); |
| 849 | button.show(); |
| 850 | table.attach(button, {0, 1, 3, 4}, {GTK_EXPAND | GTK_FILL, 0}); |
| 851 | button.connect( "clicked", |
| 852 | G_CALLBACK( OnBtnPatchdetails ), 0 ); |
| 853 | button.dimensions(60, -1); |
| 854 | } |
| 855 | { |
| 856 | ui::Widget button = ui::Button( "Set..." ); |
| 857 | button.show(); |
| 858 | table.attach(button, {1, 2, 3, 4}, {GTK_EXPAND | GTK_FILL, 0}); |
| 859 | button.connect( "clicked", |
| 860 | G_CALLBACK( OnBtnPatchreset ), 0 ); |
| 861 | button.dimensions(60, -1); |
| 862 | } |
| 863 | { |
| 864 | ui::Widget button = ui::Button( "Natural" ); |
| 865 | button.show(); |
| 866 | table.attach(button, {2, 3, 3, 4}, {GTK_EXPAND | GTK_FILL, 0}); |
| 867 | button.connect( "clicked", |
| 868 | G_CALLBACK( OnBtnPatchnatural ), 0 ); |
| 869 | button.dimensions(60, -1); |
| 870 | } |
| 871 | { |
| 872 | ui::Widget button = ui::Button( "Fit" ); |
| 873 | button.show(); |
| 874 | table.attach(button, {3, 4, 3, 4}, {GTK_EXPAND | GTK_FILL, 0}); |
| 875 | button.connect( "clicked", |
| 876 | G_CALLBACK( OnBtnPatchFit ), 0 ); |
| 877 | button.dimensions(60, -1); |
| 878 | } |
| 879 | { |
| 880 | auto spin = ui::SpinButton( ui::Adjustment( 1, 0, 1 << 16, 1, 10, 0 ), 0, 6 ); |
| 881 | spin.show(); |
| 882 | table.attach(spin, {2, 3, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); |
| 883 | spin.dimensions(60, -1); |
| 884 | AddDialogData( spin, m_fitHorizontal ); |
| 885 | } |
| 886 | { |
| 887 | auto spin = ui::SpinButton( ui::Adjustment( 1, 0, 1 << 16, 1, 10, 0 ), 0, 6 ); |
| 888 | spin.show(); |
| 889 | table.attach(spin, {3, 4, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); |
| 890 | spin.dimensions(60, -1); |
| 891 | AddDialogData( spin, m_fitVertical ); |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | if ( !string_empty( g_pGameDescription->getKeyValue( "si_flags" ) ) ) { |
| 896 | { |
| 897 | auto frame = ui::Frame( "Surface Flags" ); |
| 898 | frame.show(); |
| 899 | vbox.pack_start( frame, TRUE, TRUE, 0 ); |
| 900 | { |
| 901 | auto vbox3 = ui::VBox( FALSE, 4 ); |
| 902 | //gtk_container_set_border_width(GTK_CONTAINER(vbox3), 4); |
| 903 | vbox3.show(); |
| 904 | frame.add(vbox3); |
| 905 | { |
| 906 | auto table = ui::Table( 8, 4, FALSE ); |
| 907 | table.show(); |
| 908 | vbox3.pack_start( table, TRUE, TRUE, 0 ); |
| 909 | gtk_table_set_row_spacings( table, 0 ); |
| 910 | gtk_table_set_col_spacings( table, 0 ); |
| 911 | |
| 912 | GtkCheckButton** p = m_surfaceFlags; |
| 913 | |
| 914 | for (unsigned int c = 0; c != 4; ++c) |
| 915 | { |
| 916 | for (unsigned int r = 0; r != 8; ++r) |
| 917 | { |
| 918 | auto check = ui::CheckButton( getSurfaceFlagName( c * 8 + r ) ); |
| 919 | check.show(); |
| 920 | table.attach(check, {c, c + 1, r, r + 1}, {GTK_EXPAND | GTK_FILL, 0}); |
| 921 | *p++ = check; |
| 922 | guint handler_id = togglebutton_connect_toggled( check, ApplyFlagsCaller( *this ) ); |
| 923 | g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) ); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | } |
| 929 | { |
| 930 | auto frame = ui::Frame( "Content Flags" ); |
| 931 | frame.show(); |
| 932 | vbox.pack_start( frame, TRUE, TRUE, 0 ); |
| 933 | { |
| 934 | auto vbox3 = ui::VBox( FALSE, 4 ); |
| 935 | //gtk_container_set_border_width(GTK_CONTAINER(vbox3), 4); |
| 936 | vbox3.show(); |
| 937 | frame.add(vbox3); |
| 938 | { |
| 939 | |
| 940 | auto table = ui::Table( 8, 4, FALSE ); |
| 941 | table.show(); |
| 942 | vbox3.pack_start( table, TRUE, TRUE, 0 ); |
| 943 | gtk_table_set_row_spacings( table, 0 ); |
| 944 | gtk_table_set_col_spacings( table, 0 ); |
| 945 | |
| 946 | GtkCheckButton** p = m_contentFlags; |
| 947 | |
| 948 | for (unsigned int c = 0; c != 4; ++c) |
| 949 | { |
| 950 | for (unsigned int r = 0; r != 8; ++r) |
| 951 | { |
| 952 | auto check = ui::CheckButton( getContentFlagName( c * 8 + r ) ); |
| 953 | check.show(); |
| 954 | table.attach(check, {c, c + 1, r, r + 1}, {GTK_EXPAND | GTK_FILL, 0}); |
| 955 | *p++ = check; |
| 956 | guint handler_id = togglebutton_connect_toggled( check, ApplyFlagsCaller( *this ) ); |
| 957 | g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) ); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | // not allowed to modify detail flag using Surface Inspector |
| 962 | gtk_widget_set_sensitive( ui::CheckButton::from(m_contentFlags[BRUSH_DETAIL_FLAG]), FALSE ); |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | { |
| 967 | auto frame = ui::Frame( "Value" ); |
| 968 | frame.show(); |
| 969 | vbox.pack_start( frame, TRUE, TRUE, 0 ); |
| 970 | { |
| 971 | auto vbox3 = ui::VBox( FALSE, 4 ); |
| 972 | gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 4 ); |
| 973 | vbox3.show(); |
| 974 | frame.add(vbox3); |
| 975 | |
| 976 | { |
| 977 | auto entry = ui::Entry(ui::New); |
| 978 | entry.show(); |
| 979 | vbox3.pack_start( entry, TRUE, TRUE, 0 ); |
| 980 | m_valueEntryWidget = entry; |
| 981 | m_valueEntry.connect( entry ); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | #if TEXTOOL_ENABLED |
| 988 | if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) { |
| 989 | // Shamus: Textool goodies... |
| 990 | ui::Widget frame = ui::Frame( "Textool" ); |
| 991 | frame.show(); |
| 992 | vbox.pack_start( frame , FALSE, FALSE, 0 ); |
| 993 | { |
| 994 | //Prolly should make this a member or global var, so the SI can draw on it... |
| 995 | TexTool::g_textoolWin = glwidget_new( FALSE ); |
| 996 | // --> Dunno, but this stuff may be necessary... (Looks like it!) |
| 997 | g_object_ref( TexTool::g_textoolWin ); |
| 998 | gtk_widget_set_events( TexTool::g_textoolWin, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ); |
| 999 | gtk_widget_set_can_focus( TexTool::g_textoolWin, true ); |
| 1000 | // <-- end stuff... |
| 1001 | TexTool::g_textoolWin.show(); |
| 1002 | TexTool::g_textoolWin.dimensions( -1, 240 ); //Yeah! |
| 1003 | frame.add(TexTool::g_textoolWin); |
| 1004 | |
| 1005 | TexTool::g_textoolWin.connect( "size_allocate", G_CALLBACK( TexTool::size_allocate ), NULL ); |
| 1006 | TexTool::g_textoolWin.connect( "expose_event", G_CALLBACK( TexTool::expose ), NULL ); |
| 1007 | TexTool::g_textoolWin.connect( "button_press_event", G_CALLBACK( TexTool::button_press ), NULL ); |
| 1008 | TexTool::g_textoolWin.connect( "button_release_event", G_CALLBACK( TexTool::button_release ), NULL ); |
| 1009 | TexTool::g_textoolWin.connect( "motion_notify_event", G_CALLBACK( TexTool::motion ), NULL ); |
| 1010 | } |
| 1011 | { |
| 1012 | ui::Widget hbox = ui::HBox( FALSE, 5 ); |
| 1013 | hbox.show(); |
| 1014 | vbox.pack_start( hbox , FALSE, FALSE, 0 ); |
| 1015 | // Checkboxes go here... (Flip X/Y) |
| 1016 | ui::Widget flipX = ui::CheckButton( "Flip X axis" ); |
| 1017 | ui::Widget flipY = ui::CheckButton( "Flip Y axis" ); |
| 1018 | flipX.show(); |
| 1019 | flipY.show(); |
| 1020 | hbox.pack_start( flipX, FALSE, FALSE, 0 ); |
| 1021 | hbox.pack_start( flipY, FALSE, FALSE, 0 ); |
| 1022 | |
| 1023 | //Instead of this, we probably need to create a vbox to put into the frame, then the |
| 1024 | //window, then the hbox. !!! FIX !!! |
| 1025 | // frame.add(hbox); |
| 1026 | |
| 1027 | //Hmm. Do we really need g_object_set_data? Mebbe not... And we don't! :-) |
| 1028 | // g_object_set_data(G_OBJECT(flipX), "handler", gint_to_pointer(flipX.connect("toggled", G_CALLBACK(TexTool::flipX), 0))); |
| 1029 | // g_object_set_data(G_OBJECT(flipY), "handler", gint_to_pointer(flipY.connect("toggled", G_CALLBACK(TexTool::flipY), 0))); |
| 1030 | //Instead, just do: |
| 1031 | flipX.connect( "toggled", G_CALLBACK( TexTool::flipX ), NULL ); |
| 1032 | flipY.connect( "toggled", G_CALLBACK( TexTool::flipY ), NULL ); |
| 1033 | } |
| 1034 | } |
| 1035 | #endif |
| 1036 | } |
| 1037 | |
| 1038 | return window; |
| 1039 | } |
| 1040 | |
| 1041 | /* |
| 1042 | ============== |
| 1043 | Update |
| 1044 | |
| 1045 | Set the fields to the current texdef (i.e. map/texdef -> dialog widgets) |
| 1046 | if faces selected (instead of brushes) -> will read this face texdef, else current texdef |
| 1047 | if only patches selected, will read the patch texdef |
| 1048 | =============== |
| 1049 | */ |
| 1050 | |
| 1051 | void spin_button_set_value_no_signal( ui::SpinButton spin, gdouble value ){ |
| 1052 | guint handler_id = gpointer_to_int( g_object_get_data( G_OBJECT( spin ), "handler" ) ); |
| 1053 | g_signal_handler_block( G_OBJECT( gtk_spin_button_get_adjustment( spin ) ), handler_id ); |
| 1054 | gtk_spin_button_set_value( spin, value ); |
| 1055 | g_signal_handler_unblock( G_OBJECT( gtk_spin_button_get_adjustment( spin ) ), handler_id ); |
| 1056 | } |
| 1057 | |
| 1058 | void spin_button_set_step_increment( ui::SpinButton spin, gdouble value ){ |
| 1059 | auto adjust = gtk_spin_button_get_adjustment( spin ); |
| 1060 | gtk_adjustment_set_step_increment(adjust, value); |
| 1061 | } |
| 1062 | |
| 1063 | void SurfaceInspector::Update(){ |
| 1064 | const char * name = SurfaceInspector_GetSelectedShader(); |
| 1065 | |
| 1066 | if ( shader_is_texture( name ) ) { |
| 1067 | m_texture.text(shader_get_textureName(name)); |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 1071 | m_texture.text(""); |
| 1072 | } |
| 1073 | |
| 1074 | texdef_t shiftScaleRotate; |
| 1075 | //Shamus: This is where we get into trouble--the BP code tries to convert to a "faked" |
| 1076 | //shift, rotate & scale values from the brush face, which seems to screw up for some reason. |
| 1077 | //!!! FIX !!! |
| 1078 | /*globalOutputStream() << "--> SI::Update. About to do ShiftScaleRotate_fromFace()...\n"; |
| 1079 | SurfaceInspector_GetSelectedBPTexdef(); |
| 1080 | globalOutputStream() << "BP: (" << g_selectedBrushPrimitTexdef.coords[0][0] << ", " << g_selectedBrushPrimitTexdef.coords[0][1] << ")(" |
| 1081 | << g_selectedBrushPrimitTexdef.coords[1][0] << ", " << g_selectedBrushPrimitTexdef.coords[1][1] << ")(" |
| 1082 | << g_selectedBrushPrimitTexdef.coords[0][2] << ", " << g_selectedBrushPrimitTexdef.coords[1][2] << ") SurfaceInspector::Update\n";//*/ |
| 1083 | //Ok, it's screwed up *before* we get here... |
| 1084 | ShiftScaleRotate_fromFace( shiftScaleRotate, SurfaceInspector_GetSelectedTexdef() ); |
| 1085 | |
| 1086 | // normalize again to hide the ridiculously high scale values that get created when using texlock |
| 1087 | shiftScaleRotate.shift[0] = float_mod( shiftScaleRotate.shift[0], (float)g_selectedShaderSize[0] ); |
| 1088 | shiftScaleRotate.shift[1] = float_mod( shiftScaleRotate.shift[1], (float)g_selectedShaderSize[1] ); |
| 1089 | |
| 1090 | { |
| 1091 | spin_button_set_value_no_signal( m_hshiftIncrement.m_spin, shiftScaleRotate.shift[0] ); |
| 1092 | spin_button_set_step_increment( m_hshiftIncrement.m_spin, g_si_globals.shift[0] ); |
| 1093 | entry_set_float( m_hshiftIncrement.m_entry, g_si_globals.shift[0] ); |
| 1094 | } |
| 1095 | |
| 1096 | { |
| 1097 | spin_button_set_value_no_signal( m_vshiftIncrement.m_spin, shiftScaleRotate.shift[1] ); |
| 1098 | spin_button_set_step_increment( m_vshiftIncrement.m_spin, g_si_globals.shift[1] ); |
| 1099 | entry_set_float( m_vshiftIncrement.m_entry, g_si_globals.shift[1] ); |
| 1100 | } |
| 1101 | |
| 1102 | { |
| 1103 | spin_button_set_value_no_signal( m_hscaleIncrement.m_spin, shiftScaleRotate.scale[0] ); |
| 1104 | spin_button_set_step_increment( m_hscaleIncrement.m_spin, g_si_globals.scale[0] ); |
| 1105 | entry_set_float( m_hscaleIncrement.m_entry, g_si_globals.scale[0] ); |
| 1106 | } |
| 1107 | |
| 1108 | { |
| 1109 | spin_button_set_value_no_signal( m_vscaleIncrement.m_spin, shiftScaleRotate.scale[1] ); |
| 1110 | spin_button_set_step_increment( m_vscaleIncrement.m_spin, g_si_globals.scale[1] ); |
| 1111 | entry_set_float( m_vscaleIncrement.m_entry, g_si_globals.scale[1] ); |
| 1112 | } |
| 1113 | |
| 1114 | { |
| 1115 | spin_button_set_value_no_signal( m_rotateIncrement.m_spin, shiftScaleRotate.rotate ); |
| 1116 | spin_button_set_step_increment( m_rotateIncrement.m_spin, g_si_globals.rotate ); |
| 1117 | entry_set_float( m_rotateIncrement.m_entry, g_si_globals.rotate ); |
| 1118 | } |
| 1119 | |
| 1120 | if ( !string_empty( g_pGameDescription->getKeyValue( "si_flags" ) ) ) { |
| 1121 | ContentsFlagsValue flags( SurfaceInspector_GetSelectedFlags() ); |
| 1122 | |
| 1123 | entry_set_int( m_valueEntryWidget, flags.m_value ); |
| 1124 | |
| 1125 | for ( GtkCheckButton** p = m_surfaceFlags; p != m_surfaceFlags + 32; ++p ) |
| 1126 | { |
| 1127 | toggle_button_set_active_no_signal( ui::CheckButton::from( *p ), flags.m_surfaceFlags & ( 1 << ( p - m_surfaceFlags ) ) ); |
| 1128 | } |
| 1129 | |
| 1130 | for ( GtkCheckButton** p = m_contentFlags; p != m_contentFlags + 32; ++p ) |
| 1131 | { |
| 1132 | toggle_button_set_active_no_signal( ui::CheckButton::from( *p ), flags.m_contentFlags & ( 1 << ( p - m_contentFlags ) ) ); |
| 1133 | } |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /* |
| 1138 | ============== |
| 1139 | Apply |
| 1140 | |
| 1141 | Reads the fields to get the current texdef (i.e. widgets -> MAP) |
| 1142 | in brush primitive mode, grab the fake shift scale rot and compute a new texture matrix |
| 1143 | =============== |
| 1144 | */ |
| 1145 | void SurfaceInspector::ApplyShader(){ |
| 1146 | StringOutputStream name( 256 ); |
| 1147 | name << GlobalTexturePrefix_get() << gtk_entry_get_text( m_texture ); |
| 1148 | |
| 1149 | // TTimo: detect and refuse invalid texture names (at least the ones with spaces) |
| 1150 | if ( !texdef_name_valid( name.c_str() ) ) { |
| 1151 | globalErrorStream() << "invalid texture name '" << name.c_str() << "'\n"; |
| 1152 | SurfaceInspector_queueDraw(); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | UndoableCommand undo( "textureNameSetSelected" ); |
| 1157 | Select_SetShader( name.c_str() ); |
| 1158 | } |
| 1159 | |
| 1160 | void SurfaceInspector::ApplyTexdef(){ |
| 1161 | texdef_t shiftScaleRotate; |
| 1162 | |
| 1163 | shiftScaleRotate.shift[0] = static_cast<float>( gtk_spin_button_get_value( m_hshiftIncrement.m_spin ) ); |
| 1164 | shiftScaleRotate.shift[1] = static_cast<float>( gtk_spin_button_get_value( m_vshiftIncrement.m_spin ) ); |
| 1165 | shiftScaleRotate.scale[0] = static_cast<float>( gtk_spin_button_get_value( m_hscaleIncrement.m_spin ) ); |
| 1166 | shiftScaleRotate.scale[1] = static_cast<float>( gtk_spin_button_get_value( m_vscaleIncrement.m_spin ) ); |
| 1167 | shiftScaleRotate.rotate = static_cast<float>( gtk_spin_button_get_value( m_rotateIncrement.m_spin ) ); |
| 1168 | |
| 1169 | TextureProjection projection; |
| 1170 | //Shamus: This is the other place that screws up, it seems, since it doesn't seem to do the |
| 1171 | //conversion from the face (I think) and so bogus values end up in the thing... !!! FIX !!! |
| 1172 | //This is actually OK. :-P |
| 1173 | ShiftScaleRotate_toFace( shiftScaleRotate, projection ); |
| 1174 | |
| 1175 | UndoableCommand undo( "textureProjectionSetSelected" ); |
| 1176 | Select_SetTexdef( projection ); |
| 1177 | } |
| 1178 | |
| 1179 | void SurfaceInspector::ApplyFlags(){ |
| 1180 | unsigned int surfaceflags = 0; |
| 1181 | for ( GtkCheckButton** p = m_surfaceFlags; p != m_surfaceFlags + 32; ++p ) |
| 1182 | { |
| 1183 | if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( *p ) ) ) { |
| 1184 | surfaceflags |= ( 1 << ( p - m_surfaceFlags ) ); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | unsigned int contentflags = 0; |
| 1189 | for ( GtkCheckButton** p = m_contentFlags; p != m_contentFlags + 32; ++p ) |
| 1190 | { |
| 1191 | if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( *p ) ) ) { |
| 1192 | contentflags |= ( 1 << ( p - m_contentFlags ) ); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | int value = entry_get_int( m_valueEntryWidget ); |
| 1197 | |
| 1198 | UndoableCommand undo( "flagsSetSelected" ); |
| 1199 | Select_SetFlags( ContentsFlagsValue( surfaceflags, contentflags, value, true ) ); |
| 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | void Face_getTexture( Face& face, CopiedString& shader, TextureProjection& projection, ContentsFlagsValue& flags ){ |
| 1204 | shader = face.GetShader(); |
| 1205 | face.GetTexdef( projection ); |
| 1206 | flags = face.getShader().m_flags; |
| 1207 | } |
| 1208 | typedef Function<void(Face&, CopiedString&, TextureProjection&, ContentsFlagsValue&), Face_getTexture> FaceGetTexture; |
| 1209 | |
| 1210 | void Face_setTexture( Face& face, const char* shader, const TextureProjection& projection, const ContentsFlagsValue& flags ){ |
| 1211 | face.SetShader( shader ); |
| 1212 | face.SetTexdef( projection ); |
| 1213 | face.SetFlags( flags ); |
| 1214 | } |
| 1215 | typedef Function<void(Face&, const char*, const TextureProjection&, const ContentsFlagsValue&), Face_setTexture> FaceSetTexture; |
| 1216 | |
| 1217 | |
| 1218 | void Patch_getTexture( Patch& patch, CopiedString& shader, TextureProjection& projection, ContentsFlagsValue& flags ){ |
| 1219 | shader = patch.GetShader(); |
| 1220 | projection = TextureProjection( texdef_t(), brushprimit_texdef_t(), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) ); |
| 1221 | flags = ContentsFlagsValue( 0, 0, 0, false ); |
| 1222 | } |
| 1223 | typedef Function<void(Patch&, CopiedString&, TextureProjection&, ContentsFlagsValue&), Patch_getTexture> PatchGetTexture; |
| 1224 | |
| 1225 | void Patch_setTexture( Patch& patch, const char* shader, const TextureProjection& projection, const ContentsFlagsValue& flags ){ |
| 1226 | patch.SetShader( shader ); |
| 1227 | } |
| 1228 | typedef Function<void(Patch&, const char*, const TextureProjection&, const ContentsFlagsValue&), Patch_setTexture> PatchSetTexture; |
| 1229 | |
| 1230 | |
| 1231 | typedef Callback<void(CopiedString&, TextureProjection&, ContentsFlagsValue&)> GetTextureCallback; |
| 1232 | typedef Callback<void(const char*, const TextureProjection&, const ContentsFlagsValue&)> SetTextureCallback; |
| 1233 | |
| 1234 | struct Texturable |
| 1235 | { |
| 1236 | GetTextureCallback getTexture; |
| 1237 | SetTextureCallback setTexture; |
| 1238 | }; |
| 1239 | |
| 1240 | |
| 1241 | void Face_getClosest( Face& face, SelectionTest& test, SelectionIntersection& bestIntersection, Texturable& texturable ){ |
| 1242 | SelectionIntersection intersection; |
| 1243 | face.testSelect( test, intersection ); |
| 1244 | if ( intersection.valid() |
| 1245 | && SelectionIntersection_closer( intersection, bestIntersection ) ) { |
| 1246 | bestIntersection = intersection; |
| 1247 | texturable.setTexture = makeCallback( FaceSetTexture(), face ); |
| 1248 | texturable.getTexture = makeCallback( FaceGetTexture(), face ); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | class OccludeSelector : public Selector |
| 1254 | { |
| 1255 | SelectionIntersection& m_bestIntersection; |
| 1256 | bool& m_occluded; |
| 1257 | public: |
| 1258 | OccludeSelector( SelectionIntersection& bestIntersection, bool& occluded ) : m_bestIntersection( bestIntersection ), m_occluded( occluded ){ |
| 1259 | m_occluded = false; |
| 1260 | } |
| 1261 | void pushSelectable( Selectable& selectable ){ |
| 1262 | } |
| 1263 | void popSelectable(){ |
| 1264 | } |
| 1265 | void addIntersection( const SelectionIntersection& intersection ){ |
| 1266 | if ( SelectionIntersection_closer( intersection, m_bestIntersection ) ) { |
| 1267 | m_bestIntersection = intersection; |
| 1268 | m_occluded = true; |
| 1269 | } |
| 1270 | } |
| 1271 | }; |
| 1272 | |
| 1273 | class BrushGetClosestFaceVisibleWalker : public scene::Graph::Walker |
| 1274 | { |
| 1275 | SelectionTest& m_test; |
| 1276 | Texturable& m_texturable; |
| 1277 | mutable SelectionIntersection m_bestIntersection; |
| 1278 | public: |
| 1279 | BrushGetClosestFaceVisibleWalker( SelectionTest& test, Texturable& texturable ) : m_test( test ), m_texturable( texturable ){ |
| 1280 | } |
| 1281 | bool pre( const scene::Path& path, scene::Instance& instance ) const { |
| 1282 | if ( path.top().get().visible() ) { |
| 1283 | BrushInstance* brush = Instance_getBrush( instance ); |
| 1284 | if ( brush != 0 ) { |
| 1285 | m_test.BeginMesh( brush->localToWorld() ); |
| 1286 | |
| 1287 | for ( Brush::const_iterator i = brush->getBrush().begin(); i != brush->getBrush().end(); ++i ) |
| 1288 | { |
| 1289 | Face_getClosest( *( *i ), m_test, m_bestIntersection, m_texturable ); |
| 1290 | } |
| 1291 | } |
| 1292 | else |
| 1293 | { |
| 1294 | SelectionTestable* selectionTestable = Instance_getSelectionTestable( instance ); |
| 1295 | if ( selectionTestable ) { |
| 1296 | bool occluded; |
| 1297 | OccludeSelector selector( m_bestIntersection, occluded ); |
| 1298 | selectionTestable->testSelect( selector, m_test ); |
| 1299 | if ( occluded ) { |
| 1300 | Patch* patch = Node_getPatch( path.top() ); |
| 1301 | if ( patch != 0 ) { |
| 1302 | m_texturable.setTexture = makeCallback( PatchSetTexture(), *patch ); |
| 1303 | m_texturable.getTexture = makeCallback( PatchGetTexture(), *patch ); |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | m_texturable = Texturable(); |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | else{ |
| 1314 | return false; |
| 1315 | } |
| 1316 | return true; |
| 1317 | } |
| 1318 | }; |
| 1319 | |
| 1320 | Texturable Scene_getClosestTexturable( scene::Graph& graph, SelectionTest& test ){ |
| 1321 | Texturable texturable; |
| 1322 | graph.traverse( BrushGetClosestFaceVisibleWalker( test, texturable ) ); |
| 1323 | return texturable; |
| 1324 | } |
| 1325 | |
| 1326 | bool Scene_getClosestTexture( scene::Graph& graph, SelectionTest& test, CopiedString& shader, TextureProjection& projection, ContentsFlagsValue& flags ){ |
| 1327 | Texturable texturable = Scene_getClosestTexturable( graph, test ); |
| 1328 | if ( texturable.getTexture != GetTextureCallback() ) { |
| 1329 | texturable.getTexture( shader, projection, flags ); |
| 1330 | return true; |
| 1331 | } |
| 1332 | return false; |
| 1333 | } |
| 1334 | |
| 1335 | void Scene_setClosestTexture( scene::Graph& graph, SelectionTest& test, const char* shader, const TextureProjection& projection, const ContentsFlagsValue& flags ){ |
| 1336 | Texturable texturable = Scene_getClosestTexturable( graph, test ); |
| 1337 | if ( texturable.setTexture != SetTextureCallback() ) { |
| 1338 | texturable.setTexture( shader, projection, flags ); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | class FaceTexture |
| 1344 | { |
| 1345 | public: |
| 1346 | TextureProjection m_projection; |
| 1347 | ContentsFlagsValue m_flags; |
| 1348 | }; |
| 1349 | |
| 1350 | FaceTexture g_faceTextureClipboard; |
| 1351 | |
| 1352 | void FaceTextureClipboard_setDefault(){ |
| 1353 | g_faceTextureClipboard.m_flags = ContentsFlagsValue( 0, 0, 0, false ); |
| 1354 | TexDef_Construct_Default( g_faceTextureClipboard.m_projection ); |
| 1355 | } |
| 1356 | |
| 1357 | void TextureClipboard_textureSelected( const char* shader ){ |
| 1358 | FaceTextureClipboard_setDefault(); |
| 1359 | } |
| 1360 | |
| 1361 | class TextureBrowser; |
| 1362 | void TextureBrowser_SetSelectedShader( TextureBrowser& textureBrowser, const char* shader ); |
| 1363 | const char* TextureBrowser_GetSelectedShader( TextureBrowser& textureBrowser ); |
| 1364 | |
| 1365 | void Scene_copyClosestTexture( SelectionTest& test ){ |
| 1366 | CopiedString shader; |
| 1367 | if ( Scene_getClosestTexture( GlobalSceneGraph(), test, shader, g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags ) ) { |
| 1368 | TextureBrowser_SetSelectedShader( GlobalTextureBrowser(), shader.c_str() ); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | void Scene_applyClosestTexture( SelectionTest& test ){ |
| 1373 | UndoableCommand command( "facePaintTexture" ); |
| 1374 | |
| 1375 | Scene_setClosestTexture( GlobalSceneGraph(), test, TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), g_faceTextureClipboard.m_projection, g_faceTextureClipboard.m_flags ); |
| 1376 | |
| 1377 | SceneChangeNotify(); |
| 1378 | } |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | void SelectedFaces_copyTexture(){ |
| 1385 | if ( !g_SelectedFaceInstances.empty() ) { |
| 1386 | Face& face = g_SelectedFaceInstances.last().getFace(); |
| 1387 | face.GetTexdef( g_faceTextureClipboard.m_projection ); |
| 1388 | g_faceTextureClipboard.m_flags = face.getShader().m_flags; |
| 1389 | |
| 1390 | TextureBrowser_SetSelectedShader( GlobalTextureBrowser(), face.getShader().getShader() ); |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | void FaceInstance_pasteTexture( FaceInstance& faceInstance ){ |
| 1395 | faceInstance.getFace().SetTexdef( g_faceTextureClipboard.m_projection ); |
| 1396 | faceInstance.getFace().SetShader( TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) ); |
| 1397 | faceInstance.getFace().SetFlags( g_faceTextureClipboard.m_flags ); |
| 1398 | SceneChangeNotify(); |
| 1399 | } |
| 1400 | |
| 1401 | bool SelectedFaces_empty(){ |
| 1402 | return g_SelectedFaceInstances.empty(); |
| 1403 | } |
| 1404 | |
| 1405 | void SelectedFaces_pasteTexture(){ |
| 1406 | UndoableCommand command( "facePasteTexture" ); |
| 1407 | g_SelectedFaceInstances.foreach( FaceInstance_pasteTexture ); |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | void SurfaceInspector_constructPreferences( PreferencesPage& page ){ |
| 1413 | page.appendCheckBox( "", "Surface Inspector Increments Match Grid", g_si_globals.m_bSnapTToGrid ); |
| 1414 | } |
| 1415 | void SurfaceInspector_constructPage( PreferenceGroup& group ){ |
| 1416 | PreferencesPage page( group.createPage( "Surface Inspector", "Surface Inspector Preferences" ) ); |
| 1417 | SurfaceInspector_constructPreferences( page ); |
| 1418 | } |
| 1419 | void SurfaceInspector_registerPreferencesPage(){ |
| 1420 | PreferencesDialog_addSettingsPage( makeCallbackF(SurfaceInspector_constructPage) ); |
| 1421 | } |
| 1422 | |
| 1423 | void SurfaceInspector_registerCommands(){ |
| 1424 | GlobalCommands_insert( "FitTexture", makeCallbackF(SurfaceInspector_FitTexture), Accelerator( 'B', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 1425 | GlobalCommands_insert( "SurfaceInspector", makeCallbackF(SurfaceInspector_toggleShown), Accelerator( 'S' ) ); |
| 1426 | |
| 1427 | GlobalCommands_insert( "FaceCopyTexture", makeCallbackF(SelectedFaces_copyTexture) ); |
| 1428 | GlobalCommands_insert( "FacePasteTexture", makeCallbackF(SelectedFaces_pasteTexture) ); |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | #include "preferencesystem.h" |
| 1433 | |
| 1434 | |
| 1435 | void SurfaceInspector_Construct(){ |
| 1436 | g_SurfaceInspector = new SurfaceInspector; |
| 1437 | |
| 1438 | SurfaceInspector_registerCommands(); |
| 1439 | |
| 1440 | FaceTextureClipboard_setDefault(); |
| 1441 | |
| 1442 | GlobalPreferenceSystem().registerPreference( "SurfaceWnd", make_property<WindowPositionTracker_String>( getSurfaceInspector().m_positionTracker) ); |
| 1443 | GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Scale1", make_property_string( g_si_globals.scale[0] ) ); |
| 1444 | GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Scale2", make_property_string( g_si_globals.scale[1] ) ); |
| 1445 | GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Shift1", make_property_string( g_si_globals.shift[0] ) ); |
| 1446 | GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Shift2", make_property_string( g_si_globals.shift[1] ) ); |
| 1447 | GlobalPreferenceSystem().registerPreference( "SI_SurfaceTexdef_Rotate", make_property_string( g_si_globals.rotate ) ); |
| 1448 | GlobalPreferenceSystem().registerPreference( "SnapTToGrid", make_property_string( g_si_globals.m_bSnapTToGrid ) ); |
| 1449 | |
| 1450 | typedef FreeCaller<void(const Selectable&), SurfaceInspector_SelectionChanged> SurfaceInspectorSelectionChangedCaller; |
| 1451 | GlobalSelectionSystem().addSelectionChangeCallback( SurfaceInspectorSelectionChangedCaller() ); |
| 1452 | typedef FreeCaller<void(), SurfaceInspector_updateSelection> SurfaceInspectorUpdateSelectionCaller; |
| 1453 | Brush_addTextureChangedCallback( SurfaceInspectorUpdateSelectionCaller() ); |
| 1454 | Patch_addTextureChangedCallback( SurfaceInspectorUpdateSelectionCaller() ); |
| 1455 | |
| 1456 | SurfaceInspector_registerPreferencesPage(); |
| 1457 | } |
| 1458 | void SurfaceInspector_Destroy(){ |
| 1459 | delete g_SurfaceInspector; |
| 1460 | } |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | #if TEXTOOL_ENABLED |
| 1465 | |
| 1466 | namespace TexTool { // namespace hides these symbols from other object-files |
| 1467 | // |
| 1468 | //Shamus: Textool functions, including GTK+ callbacks |
| 1469 | // |
| 1470 | |
| 1471 | //NOTE: Black screen when TT first comes up is caused by an uninitialized Extent... !!! FIX !!! |
| 1472 | // But... You can see down below that it *is* initialized! WTF? |
| 1473 | struct Extent |
| 1474 | { |
| 1475 | float minX, minY, maxX, maxY; |
| 1476 | float width( void ) { return fabs( maxX - minX ); } |
| 1477 | float height( void ) { return fabs( maxY - minY ); } |
| 1478 | }; |
| 1479 | |
| 1480 | //This seems to control the texture scale... (Yep! ;-) |
| 1481 | Extent extents = { -2.0f, -2.0f, +2.0f, +2.0f }; |
| 1482 | brushprimit_texdef_t tm; // Texture transform matrix |
| 1483 | Vector2 pts[c_brush_maxFaces]; |
| 1484 | Vector2 center; |
| 1485 | int numPts; |
| 1486 | int textureNum; |
| 1487 | Vector2 textureSize; |
| 1488 | Vector2 windowSize; |
| 1489 | #define VP_PADDING 1.2 |
| 1490 | #define PI 3.14159265358979 |
| 1491 | bool lButtonDown = false; |
| 1492 | bool rButtonDown = false; |
| 1493 | //int dragPoint; |
| 1494 | //int anchorPoint; |
| 1495 | bool haveAnchor = false; |
| 1496 | brushprimit_texdef_t currentBP; |
| 1497 | brushprimit_texdef_t origBP; // Original brush primitive (before we muck it up) |
| 1498 | float controlRadius = 5.0f; |
| 1499 | float rotationAngle = 0.0f; |
| 1500 | float rotationAngle2 = 0.0f; |
| 1501 | float oldRotationAngle; |
| 1502 | Vector2 rotationPoint; |
| 1503 | bool translatingX = false; // Widget state variables |
| 1504 | bool translatingY = false; |
| 1505 | bool scalingX = false; |
| 1506 | bool scalingY = false; |
| 1507 | bool rotating = false; |
| 1508 | bool resizingX = false; // Not sure what this means... :-/ |
| 1509 | bool resizingY = false; |
| 1510 | float origAngle, origScaleX, origScaleY; |
| 1511 | Vector2 oldCenter; |
| 1512 | |
| 1513 | |
| 1514 | // Function prototypes (move up to top later...) |
| 1515 | |
| 1516 | void DrawCircularArc( Vector2 ctr, float startAngle, float endAngle, float radius ); |
| 1517 | |
| 1518 | |
| 1519 | void CopyPointsFromSelectedFace( void ){ |
| 1520 | // Make sure that there's a face and winding to get! |
| 1521 | |
| 1522 | if ( g_SelectedFaceInstances.empty() ) { |
| 1523 | numPts = 0; |
| 1524 | return; |
| 1525 | } |
| 1526 | |
| 1527 | Face & face = g_SelectedFaceInstances.last().getFace(); |
| 1528 | textureNum = face.getShader().m_state->getTexture().texture_number; |
| 1529 | textureSize.x() = face.getShader().m_state->getTexture().width; |
| 1530 | textureSize.y() = face.getShader().m_state->getTexture().height; |
| 1531 | //globalOutputStream() << "--> Texture #" << textureNum << ": " << textureSize.x() << " x " << textureSize.y() << "...\n"; |
| 1532 | |
| 1533 | currentBP = SurfaceInspector_GetSelectedTexdef().m_brushprimit_texdef; |
| 1534 | |
| 1535 | face.EmitTextureCoordinates(); |
| 1536 | Winding & w = face.getWinding(); |
| 1537 | int count = 0; |
| 1538 | |
| 1539 | for ( Winding::const_iterator i = w.begin(); i != w.end(); i++ ) |
| 1540 | { |
| 1541 | //globalOutputStream() << (*i).texcoord.x() << " " << (*i).texcoord.y() << ", "; |
| 1542 | pts[count].x() = ( *i ).texcoord.x(); |
| 1543 | pts[count].y() = ( *i ).texcoord.y(); |
| 1544 | count++; |
| 1545 | } |
| 1546 | |
| 1547 | numPts = count; |
| 1548 | |
| 1549 | //globalOutputStream() << " ..copied points\n"; |
| 1550 | } |
| 1551 | |
| 1552 | brushprimit_texdef_t bp; |
| 1553 | //This approach is probably wrongheaded and just not right anyway. So, !!! FIX !!! [DONE] |
| 1554 | void CommitChanges( void ){ |
| 1555 | texdef_t t; // Throwaway, since this is BP only |
| 1556 | |
| 1557 | bp.coords[0][0] = tm.coords[0][0] * origBP.coords[0][0] + tm.coords[0][1] * origBP.coords[1][0]; |
| 1558 | bp.coords[0][1] = tm.coords[0][0] * origBP.coords[0][1] + tm.coords[0][1] * origBP.coords[1][1]; |
| 1559 | bp.coords[0][2] = tm.coords[0][0] * origBP.coords[0][2] + tm.coords[0][1] * origBP.coords[1][2] + tm.coords[0][2]; |
| 1560 | //Ok, this works for translation... |
| 1561 | // bp.coords[0][2] = tm.coords[0][0] * origBP.coords[0][2] + tm.coords[0][1] * origBP.coords[1][2] + tm.coords[0][2] * textureSize.x(); |
| 1562 | bp.coords[1][0] = tm.coords[1][0] * origBP.coords[0][0] + tm.coords[1][1] * origBP.coords[1][0]; |
| 1563 | bp.coords[1][1] = tm.coords[1][0] * origBP.coords[0][1] + tm.coords[1][1] * origBP.coords[1][1]; |
| 1564 | bp.coords[1][2] = tm.coords[1][0] * origBP.coords[0][2] + tm.coords[1][1] * origBP.coords[1][2] + tm.coords[1][2]; |
| 1565 | // bp.coords[1][2] = tm.coords[1][0] * origBP.coords[0][2] + tm.coords[1][1] * origBP.coords[1][2] + tm.coords[1][2] * textureSize.y(); |
| 1566 | |
| 1567 | //This doesn't work: g_brush_texture_changed(); |
| 1568 | // Let's try this: |
| 1569 | //Note: We should only set an undo *after* the button has been released... !!! FIX !!! |
| 1570 | //Definitely *should* have an undo, though! |
| 1571 | // UndoableCommand undo("textureProjectionSetSelected"); |
| 1572 | Select_SetTexdef( TextureProjection( t, bp, Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) ) ); |
| 1573 | //This is working, but for some reason the translate is causing the rest of the SI |
| 1574 | //widgets to yield bad readings... !!! FIX !!! |
| 1575 | //I.e., click on textool window, translate face wireframe, then controls go crazy. Dunno why. |
| 1576 | //It's because there were some uncommented out add/removeScale functions in brush.h and a |
| 1577 | //removeScale in brushmanip.cpp... :-/ |
| 1578 | //Translate isn't working at all now... :-( |
| 1579 | //It's because we need to multiply in some scaling factor (prolly the texture width/height) |
| 1580 | //Yep. :-P |
| 1581 | } |
| 1582 | |
| 1583 | void UpdateControlPoints( void ){ |
| 1584 | CommitChanges(); |
| 1585 | |
| 1586 | // Init texture transform matrix |
| 1587 | |
| 1588 | tm.coords[0][0] = 1.0f; tm.coords[0][1] = 0.0f; tm.coords[0][2] = 0.0f; |
| 1589 | tm.coords[1][0] = 0.0f; tm.coords[1][1] = 1.0f; tm.coords[1][2] = 0.0f; |
| 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | /* |
| 1594 | For shifting we have: |
| 1595 | */ |
| 1596 | /* |
| 1597 | The code that should provide reasonable defaults, but doesn't for some reason: |
| 1598 | It's scaling the BP by 128 for some reason, between the time it's created and the |
| 1599 | time we get back to the SI widgets: |
| 1600 | |
| 1601 | static void OnBtnAxial(GtkWidget *widget, gpointer data) |
| 1602 | { |
| 1603 | UndoableCommand undo("textureDefault"); |
| 1604 | TextureProjection projection; |
| 1605 | TexDef_Construct_Default(projection); |
| 1606 | Select_SetTexdef(projection); |
| 1607 | } |
| 1608 | |
| 1609 | Select_SetTexdef() calls Scene_BrushSetTexdef_Component_Selected(GlobalSceneGraph(), projection) |
| 1610 | which is in brushmanip.h: This eventually calls |
| 1611 | Texdef_Assign(m_texdef, texdef, m_brushprimit_texdef, brushprimit_texdef) in class Face... |
| 1612 | which just copies from brushpr to m_brushpr... |
| 1613 | */ |
| 1614 | |
| 1615 | //Small problem with this thing: It's scaled to the texture which is all screwed up... !!! FIX !!! [DONE] |
| 1616 | //Prolly should separate out the grid drawing so that we can draw it behind the polygon. |
| 1617 | const float gridWidth = 1.3f; // Let's try an absolute height... WORKS!!! |
| 1618 | // NOTE that 2.0 is the height of the viewport. Dunno why... Should make collision |
| 1619 | // detection easier... |
| 1620 | const float gridRadius = gridWidth * 0.5f; |
| 1621 | |
| 1622 | typedef const float WidgetColor[3]; |
| 1623 | const WidgetColor widgetColor[10] = { |
| 1624 | { 1.0000f, 0.2000f, 0.0000f }, // Red |
| 1625 | { 0.9137f, 0.9765f, 0.4980f }, // Yellow |
| 1626 | { 0.0000f, 0.6000f, 0.3216f }, // Green |
| 1627 | { 0.6157f, 0.7726f, 0.8196f }, // Cyan |
| 1628 | { 0.4980f, 0.5000f, 0.4716f }, // Grey |
| 1629 | |
| 1630 | // Highlight colors |
| 1631 | { 1.0000f, 0.6000f, 0.4000f }, // Light Red |
| 1632 | { 1.0000f, 1.0000f, 0.8980f }, // Light Yellow |
| 1633 | { 0.4000f, 1.0000f, 0.7216f }, // Light Green |
| 1634 | { 1.0000f, 1.0000f, 1.0000f }, // Light Cyan |
| 1635 | { 0.8980f, 0.9000f, 0.8716f } // Light Grey |
| 1636 | }; |
| 1637 | |
| 1638 | #define COLOR_RED 0 |
| 1639 | #define COLOR_YELLOW 1 |
| 1640 | #define COLOR_GREEN 2 |
| 1641 | #define COLOR_CYAN 3 |
| 1642 | #define COLOR_GREY 4 |
| 1643 | #define COLOR_LT_RED 5 |
| 1644 | #define COLOR_LT_YELLOW 6 |
| 1645 | #define COLOR_LT_GREEN 7 |
| 1646 | #define COLOR_LT_CYAN 8 |
| 1647 | #define COLOR_LT_GREY 9 |
| 1648 | |
| 1649 | void DrawControlWidgets( void ){ |
| 1650 | //Note that the grid should go *behind* the face outline... !!! FIX !!! |
| 1651 | // Grid |
| 1652 | float xStart = center.x() - ( gridWidth / 2.0f ); |
| 1653 | float yStart = center.y() - ( gridWidth / 2.0f ); |
| 1654 | float xScale = ( extents.height() / extents.width() ) * ( textureSize.y() / textureSize.x() ); |
| 1655 | |
| 1656 | glPushMatrix(); |
| 1657 | //Small problem with this approach: Changing the center point in the TX code doesn't seem to |
| 1658 | //change anything here--prolly because we load a new identity matrix. A couple of ways to fix |
| 1659 | //this would be to get rid of that code, or change the center to a new point by taking into |
| 1660 | //account the transforms that we toss with the new identity matrix. Dunno which is better. |
| 1661 | glLoadIdentity(); |
| 1662 | glScalef( xScale, 1.0, 1.0 ); // Will that square it up? Yup. |
| 1663 | glRotatef( static_cast<float>( radians_to_degrees( atan2( -currentBP.coords[0][1], currentBP.coords[0][0] ) ) ), 0.0, 0.0, -1.0 ); |
| 1664 | glTranslatef( -center.x(), -center.y(), 0.0 ); |
| 1665 | |
| 1666 | // Circle |
| 1667 | glColor3fv( translatingX && translatingY ? widgetColor[COLOR_LT_YELLOW] : widgetColor[COLOR_YELLOW] ); |
| 1668 | glBegin( GL_LINE_LOOP ); |
| 1669 | DrawCircularArc( center, 0, 2.0f * PI, gridRadius * 0.16 ); |
| 1670 | |
| 1671 | glEnd(); |
| 1672 | |
| 1673 | // Axes |
| 1674 | glBegin( GL_LINES ); |
| 1675 | glColor3fv( translatingY && !translatingX ? widgetColor[COLOR_LT_GREEN] : widgetColor[COLOR_GREEN] ); |
| 1676 | glVertex2f( center.x(), center.y() + ( gridRadius * 0.16 ) ); |
| 1677 | glVertex2f( center.x(), center.y() + ( gridRadius * 1.00 ) ); |
| 1678 | glColor3fv( translatingX && !translatingY ? widgetColor[COLOR_LT_RED] : widgetColor[COLOR_RED] ); |
| 1679 | glVertex2f( center.x() + ( gridRadius * 0.16 ), center.y() ); |
| 1680 | glVertex2f( center.x() + ( gridRadius * 1.00 ), center.y() ); |
| 1681 | glEnd(); |
| 1682 | |
| 1683 | // Arrowheads |
| 1684 | glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); |
| 1685 | glBegin( GL_TRIANGLES ); |
| 1686 | glColor3fv( translatingY && !translatingX ? widgetColor[COLOR_LT_GREEN] : widgetColor[COLOR_GREEN] ); |
| 1687 | glVertex2f( center.x(), center.y() + ( gridRadius * 1.10 ) ); |
| 1688 | glVertex2f( center.x() + ( gridRadius * 0.06 ), center.y() + ( gridRadius * 0.94 ) ); |
| 1689 | glVertex2f( center.x() - ( gridRadius * 0.06 ), center.y() + ( gridRadius * 0.94 ) ); |
| 1690 | glColor3fv( translatingX && !translatingY ? widgetColor[COLOR_LT_RED] : widgetColor[COLOR_RED] ); |
| 1691 | glVertex2f( center.x() + ( gridRadius * 1.10 ), center.y() ); |
| 1692 | glVertex2f( center.x() + ( gridRadius * 0.94 ), center.y() + ( gridRadius * 0.06 ) ); |
| 1693 | glVertex2f( center.x() + ( gridRadius * 0.94 ), center.y() - ( gridRadius * 0.06 ) ); |
| 1694 | glEnd(); |
| 1695 | |
| 1696 | // Arc |
| 1697 | glBegin( GL_LINE_STRIP ); |
| 1698 | glColor3fv( rotating ? widgetColor[COLOR_LT_CYAN] : widgetColor[COLOR_CYAN] ); |
| 1699 | DrawCircularArc( center, 0.03f * PI, 0.47f * PI, gridRadius * 0.90 ); |
| 1700 | glEnd(); |
| 1701 | |
| 1702 | // Boxes |
| 1703 | glColor3fv( scalingY && !scalingX ? widgetColor[COLOR_LT_GREEN] : widgetColor[COLOR_GREEN] ); |
| 1704 | glBegin( GL_LINES ); |
| 1705 | glVertex2f( center.x() + ( gridRadius * 0.20 ), center.y() + ( gridRadius * 1.50 ) ); |
| 1706 | glVertex2f( center.x() - ( gridRadius * 0.20 ), center.y() + ( gridRadius * 1.50 ) ); |
| 1707 | glEnd(); |
| 1708 | glBegin( GL_LINE_LOOP ); |
| 1709 | glVertex2f( center.x() + ( gridRadius * 0.10 ), center.y() + ( gridRadius * 1.40 ) ); |
| 1710 | glVertex2f( center.x() - ( gridRadius * 0.10 ), center.y() + ( gridRadius * 1.40 ) ); |
| 1711 | glVertex2f( center.x() - ( gridRadius * 0.10 ), center.y() + ( gridRadius * 1.20 ) ); |
| 1712 | glVertex2f( center.x() + ( gridRadius * 0.10 ), center.y() + ( gridRadius * 1.20 ) ); |
| 1713 | glEnd(); |
| 1714 | |
| 1715 | glColor3fv( scalingX && !scalingY ? widgetColor[COLOR_LT_RED] : widgetColor[COLOR_RED] ); |
| 1716 | glBegin( GL_LINES ); |
| 1717 | glVertex2f( center.x() + ( gridRadius * 1.50 ), center.y() + ( gridRadius * 0.20 ) ); |
| 1718 | glVertex2f( center.x() + ( gridRadius * 1.50 ), center.y() - ( gridRadius * 0.20 ) ); |
| 1719 | glEnd(); |
| 1720 | glBegin( GL_LINE_LOOP ); |
| 1721 | glVertex2f( center.x() + ( gridRadius * 1.40 ), center.y() + ( gridRadius * 0.10 ) ); |
| 1722 | glVertex2f( center.x() + ( gridRadius * 1.40 ), center.y() - ( gridRadius * 0.10 ) ); |
| 1723 | glVertex2f( center.x() + ( gridRadius * 1.20 ), center.y() - ( gridRadius * 0.10 ) ); |
| 1724 | glVertex2f( center.x() + ( gridRadius * 1.20 ), center.y() + ( gridRadius * 0.10 ) ); |
| 1725 | glEnd(); |
| 1726 | |
| 1727 | glColor3fv( scalingX && scalingY ? widgetColor[COLOR_LT_CYAN] : widgetColor[COLOR_CYAN] ); |
| 1728 | glBegin( GL_LINE_STRIP ); |
| 1729 | glVertex2f( center.x() + ( gridRadius * 1.50 ), center.y() + ( gridRadius * 1.10 ) ); |
| 1730 | glVertex2f( center.x() + ( gridRadius * 1.50 ), center.y() + ( gridRadius * 1.50 ) ); |
| 1731 | glVertex2f( center.x() + ( gridRadius * 1.10 ), center.y() + ( gridRadius * 1.50 ) ); |
| 1732 | glEnd(); |
| 1733 | glBegin( GL_LINE_LOOP ); |
| 1734 | glVertex2f( center.x() + ( gridRadius * 1.40 ), center.y() + ( gridRadius * 1.40 ) ); |
| 1735 | glVertex2f( center.x() + ( gridRadius * 1.40 ), center.y() + ( gridRadius * 1.20 ) ); |
| 1736 | glVertex2f( center.x() + ( gridRadius * 1.20 ), center.y() + ( gridRadius * 1.20 ) ); |
| 1737 | glVertex2f( center.x() + ( gridRadius * 1.20 ), center.y() + ( gridRadius * 1.40 ) ); |
| 1738 | glEnd(); |
| 1739 | |
| 1740 | glPopMatrix(); |
| 1741 | } |
| 1742 | |
| 1743 | void DrawControlPoints( void ){ |
| 1744 | glColor3f( 1, 1, 1 ); |
| 1745 | glBegin( GL_LINE_LOOP ); |
| 1746 | |
| 1747 | for ( int i = 0; i < numPts; i++ ) |
| 1748 | glVertex2f( pts[i].x(), pts[i].y() ); |
| 1749 | |
| 1750 | glEnd(); |
| 1751 | } |
| 1752 | |
| 1753 | // Note: Setup and all that jazz must be done by the caller! |
| 1754 | |
| 1755 | void DrawCircularArc( Vector2 ctr, float startAngle, float endAngle, float radius ){ |
| 1756 | float stepSize = ( 2.0f * PI ) / 200.0f; |
| 1757 | |
| 1758 | for ( float angle = startAngle; angle <= endAngle; angle += stepSize ) |
| 1759 | glVertex2f( ctr.x() + radius * cos( angle ), ctr.y() + radius * sin( angle ) ); |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | void focus(){ |
| 1764 | if ( numPts == 0 ) { |
| 1765 | return; |
| 1766 | } |
| 1767 | |
| 1768 | // Find selected texture's extents... |
| 1769 | |
| 1770 | extents.minX = extents.maxX = pts[0].x(), |
| 1771 | extents.minY = extents.maxY = pts[0].y(); |
| 1772 | |
| 1773 | for ( int i = 1; i < numPts; i++ ) |
| 1774 | { |
| 1775 | if ( pts[i].x() < extents.minX ) { |
| 1776 | extents.minX = pts[i].x(); |
| 1777 | } |
| 1778 | if ( pts[i].x() > extents.maxX ) { |
| 1779 | extents.maxX = pts[i].x(); |
| 1780 | } |
| 1781 | if ( pts[i].y() < extents.minY ) { |
| 1782 | extents.minY = pts[i].y(); |
| 1783 | } |
| 1784 | if ( pts[i].y() > extents.maxY ) { |
| 1785 | extents.maxY = pts[i].y(); |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | // Do some viewport fitting stuff... |
| 1790 | |
| 1791 | //globalOutputStream() << "--> Center: " << center.x() << ", " << center.y() << "\n"; |
| 1792 | //globalOutputStream() << "--> Extents (stage 1): " << extents.minX << ", " |
| 1793 | // << extents.maxX << ", " << extents.minY << ", " << extents.maxY << "\n"; |
| 1794 | // TTimo: Apply a ratio to get the area we'll draw. |
| 1795 | center.x() = 0.5f * ( extents.minX + extents.maxX ), |
| 1796 | center.y() = 0.5f * ( extents.minY + extents.maxY ); |
| 1797 | extents.minX = center.x() + VP_PADDING * ( extents.minX - center.x() ), |
| 1798 | extents.minY = center.y() + VP_PADDING * ( extents.minY - center.y() ), |
| 1799 | extents.maxX = center.x() + VP_PADDING * ( extents.maxX - center.x() ), |
| 1800 | extents.maxY = center.y() + VP_PADDING * ( extents.maxY - center.y() ); |
| 1801 | //globalOutputStream() << "--> Extents (stage 2): " << extents.minX << ", " |
| 1802 | // << extents.maxX << ", " << extents.minY << ", " << extents.maxY << "\n"; |
| 1803 | |
| 1804 | // TTimo: We want a texture with the same X / Y ratio. |
| 1805 | // TTimo: Compute XY space / window size ratio. |
| 1806 | float SSize = extents.width(), TSize = extents.height(); |
| 1807 | float ratioX = textureSize.x() * extents.width() / windowSize.x(), |
| 1808 | ratioY = textureSize.y() * extents.height() / windowSize.y(); |
| 1809 | //globalOutputStream() << "--> Texture size: " << textureSize.x() << ", " << textureSize.y() << "\n"; |
| 1810 | //globalOutputStream() << "--> Window size: " << windowSize.x() << ", " << windowSize.y() << "\n"; |
| 1811 | |
| 1812 | if ( ratioX > ratioY ) { |
| 1813 | TSize = ( windowSize.y() * ratioX ) / textureSize.y(); |
| 1814 | // TSize = extents.width() * (windowSize.y() / windowSize.x()) * (textureSize.x() / textureSize.y()); |
| 1815 | } |
| 1816 | else |
| 1817 | { |
| 1818 | SSize = ( windowSize.x() * ratioY ) / textureSize.x(); |
| 1819 | // SSize = extents.height() * (windowSize.x() / windowSize.y()) * (textureSize.y() / textureSize.x()); |
| 1820 | } |
| 1821 | |
| 1822 | extents.minX = center.x() - 0.5f * SSize, extents.maxX = center.x() + 0.5f * SSize, |
| 1823 | extents.minY = center.y() - 0.5f * TSize, extents.maxY = center.y() + 0.5f * TSize; |
| 1824 | //globalOutputStream() << "--> Extents (stage 3): " << extents.minX << ", " |
| 1825 | // << extents.maxX << ", " << extents.minY << ", " << extents.maxY << "\n"; |
| 1826 | } |
| 1827 | |
| 1828 | gboolean size_allocate( ui::Widget win, GtkAllocation * a, gpointer ){ |
| 1829 | windowSize.x() = a->width; |
| 1830 | windowSize.y() = a->height; |
| 1831 | queueDraw(); |
| 1832 | return false; |
| 1833 | } |
| 1834 | |
| 1835 | gboolean expose( ui::Widget win, GdkEventExpose * e, gpointer ){ |
| 1836 | // globalOutputStream() << "--> Textool Window was exposed!\n"; |
| 1837 | // globalOutputStream() << " (window width/height: " << cc << "/" << e->area.height << ")\n"; |
| 1838 | |
| 1839 | // windowSize.x() = e->area.width, windowSize.y() = e->area.height; |
| 1840 | //This needs to go elsewhere... |
| 1841 | // InitTextool(); |
| 1842 | |
| 1843 | if ( glwidget_make_current( win ) == FALSE ) { |
| 1844 | globalOutputStream() << " FAILED to make current! Oh, the agony! :-(\n"; |
| 1845 | return true; |
| 1846 | } |
| 1847 | |
| 1848 | CopyPointsFromSelectedFace(); |
| 1849 | |
| 1850 | if ( !lButtonDown ) { |
| 1851 | focus(); |
| 1852 | } |
| 1853 | |
| 1854 | // Probably should init button/anchor states here as well... |
| 1855 | // rotationAngle = 0.0f; |
| 1856 | glClearColor( 0, 0, 0, 0 ); |
| 1857 | glViewport( 0, 0, e->area.width, e->area.height ); |
| 1858 | glMatrixMode( GL_PROJECTION ); |
| 1859 | glLoadIdentity(); |
| 1860 | |
| 1861 | //??? |
| 1862 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 1863 | glDisable( GL_DEPTH_TEST ); |
| 1864 | glDisable( GL_BLEND ); |
| 1865 | |
| 1866 | glOrtho( extents.minX, extents.maxX, extents.maxY, extents.minY, -1, 1 ); |
| 1867 | |
| 1868 | glColor3f( 1, 1, 1 ); |
| 1869 | // draw the texture background |
| 1870 | glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); |
| 1871 | glBindTexture( GL_TEXTURE_2D, textureNum ); |
| 1872 | |
| 1873 | glEnable( GL_TEXTURE_2D ); |
| 1874 | glBegin( GL_QUADS ); |
| 1875 | glTexCoord2f( extents.minX, extents.minY ); |
| 1876 | glVertex2f( extents.minX, extents.minY ); |
| 1877 | glTexCoord2f( extents.maxX, extents.minY ); |
| 1878 | glVertex2f( extents.maxX, extents.minY ); |
| 1879 | glTexCoord2f( extents.maxX, extents.maxY ); |
| 1880 | glVertex2f( extents.maxX, extents.maxY ); |
| 1881 | glTexCoord2f( extents.minX, extents.maxY ); |
| 1882 | glVertex2f( extents.minX, extents.maxY ); |
| 1883 | glEnd(); |
| 1884 | glDisable( GL_TEXTURE_2D ); |
| 1885 | |
| 1886 | // draw the texture-space grid |
| 1887 | glColor3fv( widgetColor[COLOR_GREY] ); |
| 1888 | glBegin( GL_LINES ); |
| 1889 | |
| 1890 | const int gridSubdivisions = 8; |
| 1891 | const float gridExtents = 4.0f; |
| 1892 | |
| 1893 | for ( int i = 0; i < gridSubdivisions + 1; ++i ) |
| 1894 | { |
| 1895 | float y = i * ( gridExtents / float(gridSubdivisions) ); |
| 1896 | float x = i * ( gridExtents / float(gridSubdivisions) ); |
| 1897 | glVertex2f( 0, y ); |
| 1898 | glVertex2f( gridExtents, y ); |
| 1899 | glVertex2f( x, 0 ); |
| 1900 | glVertex2f( x, gridExtents ); |
| 1901 | } |
| 1902 | |
| 1903 | glEnd(); |
| 1904 | |
| 1905 | DrawControlPoints(); |
| 1906 | DrawControlWidgets(); |
| 1907 | //??? |
| 1908 | // reset the current texture |
| 1909 | // glBindTexture(GL_TEXTURE_2D, 0); |
| 1910 | // glFinish(); |
| 1911 | glwidget_swap_buffers( win ); |
| 1912 | |
| 1913 | return false; |
| 1914 | } |
| 1915 | |
| 1916 | /*int FindSelectedPoint(int x, int y) |
| 1917 | { |
| 1918 | for(int i=0; i<numPts; i++) |
| 1919 | { |
| 1920 | int nx = (int)(windowSize.x() * (pts[i].x() - extents.minX) / extents.width()); |
| 1921 | int ny = (int)(windowSize.y() * (pts[i].y() - extents.minY) / extents.height()); |
| 1922 | |
| 1923 | if (abs(nx - x) <= 3 && abs(ny - y) <= 3) |
| 1924 | return i; |
| 1925 | } |
| 1926 | |
| 1927 | return -1; |
| 1928 | }//*/ |
| 1929 | |
| 1930 | Vector2 trans; |
| 1931 | Vector2 trans2; |
| 1932 | Vector2 dragPoint; // Defined in terms of window space (+x/-y) |
| 1933 | Vector2 oldTrans; |
| 1934 | gboolean button_press( ui::Widget win, GdkEventButton * e, gpointer ){ |
| 1935 | // globalOutputStream() << "--> Textool button press...\n"; |
| 1936 | |
| 1937 | if ( e->button == 1 ) { |
| 1938 | lButtonDown = true; |
| 1939 | GlobalUndoSystem().start(); |
| 1940 | |
| 1941 | origBP = currentBP; |
| 1942 | |
| 1943 | //globalOutputStream() << "--> Original BP: [" << origBP.coords[0][0] << "][" << origBP.coords[0][1] << "][" << origBP.coords[0][2] << "]\n"; |
| 1944 | //globalOutputStream() << " [" << origBP.coords[1][0] << "][" << origBP.coords[1][1] << "][" << origBP.coords[1][2] << "]\n"; |
| 1945 | //float angle = atan2(origBP.coords[0][1], origBP.coords[0][0]) * 180.0f / 3.141592653589f; |
| 1946 | origAngle = ( origBP.coords[0][1] > 0 ? PI : -PI ); // Could also be -PI... !!! FIX !!! [DONE] |
| 1947 | |
| 1948 | if ( origBP.coords[0][0] != 0.0f ) { |
| 1949 | origAngle = atan( origBP.coords[0][1] / origBP.coords[0][0] ); |
| 1950 | } |
| 1951 | |
| 1952 | origScaleX = origBP.coords[0][0] / cos( origAngle ); |
| 1953 | origScaleY = origBP.coords[1][1] / cos( origAngle ); |
| 1954 | rotationAngle = origAngle; |
| 1955 | oldCenter[0] = oldCenter[1] = 0; |
| 1956 | |
| 1957 | //globalOutputStream() << "--> BP stats: ang=" << origAngle * RAD_TO_DEG << ", scale=" << origScaleX << "/" << origScaleY << "\n"; |
| 1958 | //Should also set the Flip X/Y checkboxes here as well... !!! FIX !!! |
| 1959 | //Also: should reverse texture left/right up/down instead of flipping the points... |
| 1960 | |
| 1961 | //disnowok |
| 1962 | //float nx = windowSize.x() * (e->x - extents.minX) / (extents.maxX - extents.minX); |
| 1963 | //float ny = windowSize.y() * (e->y - extents.minY) / (extents.maxY - extents.minY); |
| 1964 | //disdoes... |
| 1965 | //But I want it to scroll the texture window, not the points... !!! FIX !!! |
| 1966 | //Actually, should scroll the texture window only when mouse is down on no widgets... |
| 1967 | float nx = e->x / windowSize.x() * extents.width() + extents.minX; |
| 1968 | float ny = e->y / windowSize.y() * extents.height() + extents.minY; |
| 1969 | trans.x() = -tm.coords[0][0] * nx - tm.coords[0][1] * ny; |
| 1970 | trans.y() = -tm.coords[1][0] * nx - tm.coords[1][1] * ny; |
| 1971 | |
| 1972 | dragPoint.x() = e->x, dragPoint.y() = e->y; |
| 1973 | trans2.x() = nx, trans2.y() = ny; |
| 1974 | oldRotationAngle = rotationAngle; |
| 1975 | // oldTrans.x() = tm.coords[0][2] - nx * textureSize.x(); |
| 1976 | // oldTrans.y() = tm.coords[1][2] - ny * textureSize.y(); |
| 1977 | oldTrans.x() = tm.coords[0][2]; |
| 1978 | oldTrans.y() = tm.coords[1][2]; |
| 1979 | oldCenter.x() = center.x(); |
| 1980 | oldCenter.y() = center.y(); |
| 1981 | |
| 1982 | queueDraw(); |
| 1983 | |
| 1984 | return true; |
| 1985 | } |
| 1986 | /* else if (e->button == 3) |
| 1987 | { |
| 1988 | rButtonDown = true; |
| 1989 | }//*/ |
| 1990 | |
| 1991 | //globalOutputStream() << "(" << (haveAnchor ? "anchor" : "released") << ")\n"; |
| 1992 | |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
| 1996 | gboolean button_release( ui::Widget win, GdkEventButton * e, gpointer ){ |
| 1997 | // globalOutputStream() << "--> Textool button release...\n"; |
| 1998 | |
| 1999 | if ( e->button == 1 ) { |
| 2000 | /* float ptx = e->x / windowSize.x() * extents.width() + extents.minX; |
| 2001 | float pty = e->y / windowSize.y() * extents.height() + extents.minY; |
| 2002 | |
| 2003 | //This prolly should go into the mouse move code... |
| 2004 | //Doesn't work correctly anyway... |
| 2005 | if (translatingX || translatingY) |
| 2006 | center.x() = ptx, center.y() = pty;//*/ |
| 2007 | |
| 2008 | lButtonDown = false; |
| 2009 | |
| 2010 | if ( translatingX || translatingY ) { |
| 2011 | GlobalUndoSystem().finish( "translateTexture" ); |
| 2012 | } |
| 2013 | else if ( rotating ) { |
| 2014 | GlobalUndoSystem().finish( "rotateTexture" ); |
| 2015 | } |
| 2016 | else if ( scalingX || scalingY ) { |
| 2017 | GlobalUndoSystem().finish( "scaleTexture" ); |
| 2018 | } |
| 2019 | else if ( resizingX || resizingY ) { |
| 2020 | GlobalUndoSystem().finish( "resizeTexture" ); |
| 2021 | } |
| 2022 | else |
| 2023 | { |
| 2024 | GlobalUndoSystem().finish( "textoolUnknown" ); |
| 2025 | } |
| 2026 | |
| 2027 | rotating = translatingX = translatingY = scalingX = scalingY |
| 2028 | = resizingX = resizingY = false; |
| 2029 | |
| 2030 | queueDraw(); |
| 2031 | } |
| 2032 | else if ( e->button == 3 ) { |
| 2033 | rButtonDown = false; |
| 2034 | } |
| 2035 | |
| 2036 | return true; |
| 2037 | } |
| 2038 | |
| 2039 | /* |
| 2040 | void C2DView::GridForWindow( float c[2], int x, int y) |
| 2041 | { |
| 2042 | SpaceForWindow( c, x, y ); |
| 2043 | if ( !m_bDoGrid ) |
| 2044 | return; |
| 2045 | c[0] /= m_GridStep[0]; |
| 2046 | c[1] /= m_GridStep[1]; |
| 2047 | c[0] = (float)floor( c[0] + 0.5f ); |
| 2048 | c[1] = (float)floor( c[1] + 0.5f ); |
| 2049 | c[0] *= m_GridStep[0]; |
| 2050 | c[1] *= m_GridStep[1]; |
| 2051 | } |
| 2052 | void C2DView::SpaceForWindow( float c[2], int x, int y) |
| 2053 | { |
| 2054 | c[0] = ((float)(x))/((float)(m_rect.right-m_rect.left))*(m_Maxs[0]-m_Mins[0])+m_Mins[0]; |
| 2055 | c[1] = ((float)(y))/((float)(m_rect.bottom-m_rect.top))*(m_Maxs[1]-m_Mins[1])+m_Mins[1]; |
| 2056 | } |
| 2057 | */ |
| 2058 | gboolean motion( ui::Widget win, GdkEventMotion * e, gpointer ){ |
| 2059 | // globalOutputStream() << "--> Textool motion...\n"; |
| 2060 | |
| 2061 | if ( lButtonDown ) { |
| 2062 | if ( translatingX || translatingY ) { |
| 2063 | float ptx = e->x / windowSize.x() * extents.width() + extents.minX; |
| 2064 | float pty = e->y / windowSize.y() * extents.height() + extents.minY; |
| 2065 | |
| 2066 | //Need to fix this to take the rotation angle into account, so that it moves along |
| 2067 | //the rotated X/Y axis... |
| 2068 | if ( translatingX ) { |
| 2069 | // tm.coords[0][2] = (trans.x() + ptx) * textureSize.x(); |
| 2070 | //This works, but only when the angle is zero. !!! FIX !!! [DONE] |
| 2071 | // tm.coords[0][2] = oldCenter.x() + (ptx * textureSize.x()); |
| 2072 | tm.coords[0][2] = oldTrans.x() + ( ptx - trans2.x() ) * textureSize.x(); |
| 2073 | // center.x() = oldCenter.x() + (ptx - trans2.x()); |
| 2074 | } |
| 2075 | |
| 2076 | if ( translatingY ) { |
| 2077 | // tm.coords[1][2] = (trans.y() + pty) * textureSize.y(); |
| 2078 | // tm.coords[1][2] = oldCenter.y() + (pty * textureSize.y()); |
| 2079 | tm.coords[1][2] = oldTrans.y() + ( pty - trans2.y() ) * textureSize.y(); |
| 2080 | // center.y() = oldCenter.y() + (pty - trans2.y()); |
| 2081 | } |
| 2082 | |
| 2083 | //Need to update center.x/y() so that the widget translates as well. Also, oldCenter |
| 2084 | //is badly named... Should be oldTrans or something like that... !!! FIX !!! |
| 2085 | //Changing center.x/y() here doesn't seem to change anything... :-/ |
| 2086 | UpdateControlPoints(); |
| 2087 | } |
| 2088 | else if ( rotating ) { |
| 2089 | // Shamus: New rotate code |
| 2090 | int cx = (int)( windowSize.x() * ( center.x() - extents.minX ) / extents.width() ); |
| 2091 | int cy = (int)( windowSize.y() * ( center.y() - extents.minY ) / extents.height() ); |
| 2092 | Vector3 v1( dragPoint.x() - cx, dragPoint.y() - cy, 0 ), v2( e->x - cx, e->y - cy, 0 ); |
| 2093 | |
| 2094 | vector3_normalise( v1 ); |
| 2095 | vector3_normalise( v2 ); |
| 2096 | float c = vector3_dot( v1, v2 ); |
| 2097 | Vector3 cross = vector3_cross( v1, v2 ); |
| 2098 | float s = vector3_length( cross ); |
| 2099 | |
| 2100 | if ( cross[2] > 0 ) { |
| 2101 | s = -s; |
| 2102 | } |
| 2103 | |
| 2104 | // Problem with this: arcsin/cos seems to only return -90 to 90 and 0 to 180... |
| 2105 | // Can't derive angle from that! |
| 2106 | |
| 2107 | //rotationAngle = asin(s);// * 180.0f / 3.141592653589f; |
| 2108 | rotationAngle = acos( c ); |
| 2109 | //rotationAngle2 = asin(s); |
| 2110 | if ( cross[2] < 0 ) { |
| 2111 | rotationAngle = -rotationAngle; |
| 2112 | } |
| 2113 | |
| 2114 | //NO! DOESN'T WORK! rotationAngle -= 45.0f * DEG_TO_RAD; |
| 2115 | //Let's try this: |
| 2116 | //No wok. |
| 2117 | /*c = cos(rotationAngle - oldRotationAngle); |
| 2118 | s = sin(rotationAngle - oldRotationAngle); |
| 2119 | rotationAngle += oldRotationAngle; |
| 2120 | //c += cos(oldRotationAngle); |
| 2121 | //s += sin(oldRotationAngle); |
| 2122 | //rotationAngle += oldRotationAngle; |
| 2123 | //c %= 2.0 * PI; |
| 2124 | //s %= 2.0 * PI; |
| 2125 | //rotationAngle %= 2.0 * PI;//*/ |
| 2126 | |
| 2127 | //This is wrong... Hmm... |
| 2128 | //It seems to shear the texture instead of rotating it... !!! FIX !!! |
| 2129 | // Now it rotates correctly. Seems TTimo was overcomplicating things here... ;-) |
| 2130 | |
| 2131 | // Seems like what needs to happen here is multiplying these rotations by tm... !!! FIX !!! |
| 2132 | |
| 2133 | // See brush_primit.cpp line 244 (Texdef_EmitTextureCoordinates()) for where texcoords come from... |
| 2134 | |
| 2135 | tm.coords[0][0] = c; |
| 2136 | tm.coords[0][1] = s; |
| 2137 | tm.coords[1][0] = -s; |
| 2138 | tm.coords[1][1] = c; |
| 2139 | //It doesn't work anymore... Dunno why... |
| 2140 | //tm.coords[0][2] = -trans.x(); // This works!!! Yeah!!! |
| 2141 | //tm.coords[1][2] = -trans.y(); |
| 2142 | //nope. |
| 2143 | //tm.coords[0][2] = rotationPoint.x(); // This works, but strangely... |
| 2144 | //tm.coords[1][2] = rotationPoint.y(); |
| 2145 | //tm.coords[0][2] = 0;// center.x() / 2.0f; |
| 2146 | //tm.coords[1][2] = 0;// center.y() / 2.0f; |
| 2147 | //No. |
| 2148 | //tm.coords[0][2] = -(center.x() * textureSize.x()); |
| 2149 | //tm.coords[1][2] = -(center.y() * textureSize.y()); |
| 2150 | //Eh? No, but seems to be getting closer... |
| 2151 | /*float ptx = e->x / windowSize.x() * extents.width() + extents.minX; |
| 2152 | float pty = e->y / windowSize.y() * extents.height() + extents.minY; |
| 2153 | tm.coords[0][2] = -c * center.x() - s * center.y() + ptx; |
| 2154 | tm.coords[1][2] = s * center.x() - c * center.x() + pty;//*/ |
| 2155 | //Kinda works, but center drifts around on non-square textures... |
| 2156 | /*tm.coords[0][2] = (-c * center.x() - s * center.y()) * textureSize.x(); |
| 2157 | tm.coords[1][2] = ( s * center.x() - c * center.y()) * textureSize.y();//*/ |
| 2158 | //Rotates correctly, but not around the actual center of the face's points... |
| 2159 | /*tm.coords[0][2] = -c * center.x() * textureSize.x() - s * center.y() * textureSize.y(); |
| 2160 | tm.coords[1][2] = s * center.x() * textureSize.x() - c * center.y() * textureSize.y();//*/ |
| 2161 | //Yes!!! |
| 2162 | tm.coords[0][2] = ( -c * center.x() * textureSize.x() - s * center.y() * textureSize.y() ) + center.x() * textureSize.x(); |
| 2163 | tm.coords[1][2] = ( s * center.x() * textureSize.x() - c * center.y() * textureSize.y() ) + center.y() * textureSize.y(); //*/ |
| 2164 | //This doesn't work... |
| 2165 | //And this is the wrong place for this anyway (I'm pretty sure). |
| 2166 | /*tm.coords[0][2] += oldCenter.x(); |
| 2167 | tm.coords[1][2] += oldCenter.y();//*/ |
| 2168 | UpdateControlPoints(); // will cause a redraw |
| 2169 | } |
| 2170 | |
| 2171 | return true; |
| 2172 | } |
| 2173 | else // Check for widget mouseovers |
| 2174 | { |
| 2175 | Vector2 tran; |
| 2176 | float nx = e->x / windowSize.x() * extents.width() + extents.minX; |
| 2177 | float ny = e->y / windowSize.y() * extents.height() + extents.minY; |
| 2178 | // Translate nx/y to the "center" point... |
| 2179 | nx -= center.x(); |
| 2180 | ny -= center.y(); |
| 2181 | ny = -ny; // Flip Y-axis so that increasing numbers move up |
| 2182 | |
| 2183 | tran.x() = tm.coords[0][0] * nx + tm.coords[0][1] * ny; |
| 2184 | tran.y() = tm.coords[1][0] * nx + tm.coords[1][1] * ny; |
| 2185 | //This doesn't seem to generate a valid distance from the center--for some reason it |
| 2186 | //calculates a fixed number every time |
| 2187 | //Look at nx/y above: they're getting fixed there! !!! FIX !!! [DONE] |
| 2188 | float dist = sqrt( ( nx * nx ) + ( ny * ny ) ); |
| 2189 | // Normalize to the 2.0 = height standard (for now) |
| 2190 | //globalOutputStream() << "--> Distance before: " << dist; |
| 2191 | dist = dist * 2.0f / extents.height(); |
| 2192 | //globalOutputStream() << ". After: " << dist; |
| 2193 | tran.x() = tran.x() * 2.0f / extents.height(); |
| 2194 | tran.y() = tran.y() * 2.0f / extents.height(); |
| 2195 | //globalOutputStream() << ". Trans: " << tran.x() << ", " << tran.y() << "\n"; |
| 2196 | |
| 2197 | //Let's try this instead... |
| 2198 | //Interesting! It seems that e->x/y are rotated |
| 2199 | //(no, they're not--the TM above is what's doing it...) |
| 2200 | nx = ( ( e->x / windowSize.y() ) * 2.0f ) - ( windowSize.x() / windowSize.y() ); |
| 2201 | ny = ( ( e->y / windowSize.y() ) * 2.0f ) - ( windowSize.y() / windowSize.y() ); |
| 2202 | ny = -ny; |
| 2203 | //Cool! It works! Now just need to do rotation... |
| 2204 | |
| 2205 | rotating = translatingX = translatingY = scalingX = scalingY |
| 2206 | = resizingX = resizingY = false; |
| 2207 | |
| 2208 | if ( dist < ( gridRadius * 0.16f ) ) { |
| 2209 | translatingX = translatingY = true; |
| 2210 | } |
| 2211 | else if ( dist > ( gridRadius * 0.16f ) && dist < ( gridRadius * 1.10f ) |
| 2212 | && fabs( ny ) < ( gridRadius * 0.05f ) && nx > 0 ) { |
| 2213 | translatingX = true; |
| 2214 | } |
| 2215 | else if ( dist > ( gridRadius * 0.16f ) && dist < ( gridRadius * 1.10f ) |
| 2216 | && fabs( nx ) < ( gridRadius * 0.05f ) && ny > 0 ) { |
| 2217 | translatingY = true; |
| 2218 | } |
| 2219 | // Should tighten up the angle on this, or put this test after the axis tests... |
| 2220 | else if ( tran.x() > 0 && tran.y() > 0 |
| 2221 | && ( dist > ( gridRadius * 0.82f ) && dist < ( gridRadius * 0.98f ) ) ) { |
| 2222 | rotating = true; |
| 2223 | } |
| 2224 | |
| 2225 | queueDraw(); |
| 2226 | |
| 2227 | return true; |
| 2228 | } |
| 2229 | |
| 2230 | return false; |
| 2231 | } |
| 2232 | |
| 2233 | //It seems the fake tex coords conversion is screwing this stuff up... !!! FIX !!! |
| 2234 | //This is still wrong... Prolly need to do something with the oldScaleX/Y stuff... |
| 2235 | void flipX( ui::ToggleButton, gpointer ){ |
| 2236 | // globalOutputStream() << "--> Flip X...\n"; |
| 2237 | //Shamus: |
| 2238 | // SurfaceInspector_GetSelectedBPTexdef(); // Refresh g_selectedBrushPrimitTexdef... |
| 2239 | // tm.coords[0][0] = -tm.coords[0][0]; |
| 2240 | // tm.coords[1][0] = -tm.coords[1][0]; |
| 2241 | // tm.coords[0][0] = -tm.coords[0][0]; // This should be correct now...Nope. |
| 2242 | // tm.coords[1][1] = -tm.coords[1][1]; |
| 2243 | tm.coords[0][0] = -tm.coords[0][0]; // This should be correct now... |
| 2244 | tm.coords[1][0] = -tm.coords[1][0]; |
| 2245 | // tm.coords[2][0] = -tm.coords[2][0];//wil wok? no. |
| 2246 | UpdateControlPoints(); |
| 2247 | } |
| 2248 | |
| 2249 | void flipY( ui::ToggleButton, gpointer ){ |
| 2250 | // globalOutputStream() << "--> Flip Y...\n"; |
| 2251 | // tm.coords[0][1] = -tm.coords[0][1]; |
| 2252 | // tm.coords[1][1] = -tm.coords[1][1]; |
| 2253 | // tm.coords[0][1] = -tm.coords[0][1]; // This should be correct now...Nope. |
| 2254 | // tm.coords[1][0] = -tm.coords[1][0]; |
| 2255 | tm.coords[0][1] = -tm.coords[0][1]; // This should be correct now... |
| 2256 | tm.coords[1][1] = -tm.coords[1][1]; |
| 2257 | // tm.coords[2][1] = -tm.coords[2][1];//wil wok? no. |
| 2258 | UpdateControlPoints(); |
| 2259 | } |
| 2260 | |
| 2261 | } // end namespace TexTool |
| 2262 | |
| 2263 | #endif |