From 2d23567675a21b275ae12f292b40bb8ec35c0282 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Sat, 22 Jul 2017 06:11:47 +0200 Subject: [PATCH] Fixed textures for the texture browser --- radiant/preferences.cpp | 50 +++++++++++++++++++++++++++++++++++++- radiant/preferences.h | 3 +++ radiant/texwindow.cpp | 53 +++++++++++++++++++++++++++++++++++------ 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index 30a6dbe2..4e2836ea 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -105,6 +105,9 @@ #define CHASEMOUSE_KEY "ChaseMouse" #define MOUSEWHEELZOOM_KEY "MousewheelZoom" #define ENTITYSHOW_KEY "EntityShow" +#define FIXEDTEXSIZE_KEY "UseFixedTextureSize" +#define FIXEDTEXSIZEWIDTH_KEY "FixedTextureSizeWidth" +#define FIXEDTEXSIZEHEIGHT_KEY "FixedTextureSizeHeight" #define TEXTURESCALE_KEY "TextureScale" #define TEXTURESCROLLBAR_KEY "TextureScrollbar" #define DISPLAYLISTS_KEY "UseDisplayLists" @@ -628,6 +631,9 @@ PrefsDlg::PrefsDlg (){ m_bSelectCurves = TRUE; m_bSelectModels = TRUE; m_nEntityShowState = ENTITY_SKINNED_BOXED; + m_bFixedTextureSize = TRUE; + m_nFixedTextureSizeWidth = 64; + m_nFixedTextureSizeHeight = 64; m_nTextureScale = 2; m_bSwitchClip = FALSE; m_bSelectWholeEntities = TRUE; @@ -1539,11 +1545,12 @@ void PrefsDlg::BuildDialog(){ // Main Preferences dialog GtkWidget *dialog, *mainvbox, *hbox, *sc_win, *preflabel; + GtkWidget *ftw_label, *fth_label; // Widgets on notebook pages GtkWidget *check, *label, *scale, *hbox2, *combo, *table, *spin, *entry, *pixmap, *radio, *button, *pageframe, *vbox; - + GtkSizeGroup *size_group; GList *combo_list = (GList*)NULL; GList *lst; GtkAdjustment *adj; @@ -2074,7 +2081,48 @@ void PrefsDlg::BuildDialog(){ gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), (const char *)lst->data ); } g_list_free( combo_list ); + + check = gtk_check_button_new_with_label( _( "Use Fixed Texture Size" ) ); + gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 ); + gtk_widget_show( check ); + AddDialogData( check, &m_bFixedTextureSize, DLG_CHECK_BOOL ); + hbox2 = gtk_hbox_new( FALSE, 5 ); + gtk_box_pack_start( GTK_BOX( vbox ), hbox2, FALSE, FALSE, 0 ); + gtk_widget_show( hbox2 ); + + ftw_label = label = gtk_label_new( _( "Fixed Texture Wdith" ) ); + gtk_box_pack_start( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 ); + gtk_misc_set_alignment( GTK_MISC( label ), 0.0, 0.0 ); + gtk_widget_show( label ); + + spin = gtk_spin_button_new( GTK_ADJUSTMENT( gtk_adjustment_new( 1, 1, 1024, 1, 10, 0 ) ), 1, 0 ); + gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE ); + g_object_set( spin, "xalign", 1.0, NULL ); + gtk_box_pack_start( GTK_BOX( hbox2 ), spin, FALSE, FALSE, 0 ); + gtk_widget_show( spin ); + AddDialogData( spin, &m_nFixedTextureSizeWidth, DLG_SPIN_INT ); + + hbox2 = gtk_hbox_new( FALSE, 5 ); + gtk_box_pack_start( GTK_BOX( vbox ), hbox2, FALSE, FALSE, 0 ); + gtk_widget_show( hbox2 ); + + fth_label = label = gtk_label_new( _( "Fixed Texture Height" ) ); + gtk_box_pack_start( GTK_BOX( hbox2 ), label, FALSE, FALSE, 0 ); + gtk_misc_set_alignment( GTK_MISC( label ), 0.0, 0.0 ); + gtk_widget_show( label ); + + spin = gtk_spin_button_new( GTK_ADJUSTMENT( gtk_adjustment_new( 1, 1, 1024, 1, 10, 0 ) ), 1, 0 ); + gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE ); + g_object_set( spin, "xalign", 1.0, NULL ); + gtk_box_pack_start( GTK_BOX( hbox2 ), spin, FALSE, FALSE, 0 ); + gtk_widget_show( spin ); + AddDialogData( spin, &m_nFixedTextureSizeHeight, DLG_SPIN_INT ); + + size_group = gtk_size_group_new( GTK_SIZE_GROUP_HORIZONTAL ); + gtk_size_group_add_widget( size_group, ftw_label ); + gtk_size_group_add_widget( size_group, fth_label ); + g_object_unref( size_group ); check = gtk_check_button_new_with_label( _( "Show Texture Directory List" ) ); gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 ); gtk_widget_show( check ); diff --git a/radiant/preferences.h b/radiant/preferences.h index e20fab54..fa2fefe7 100644 --- a/radiant/preferences.h +++ b/radiant/preferences.h @@ -650,6 +650,9 @@ int m_nCubicScale; bool m_bSelectCurves; bool m_bSelectModels; int m_nEntityShowState; +bool m_bFixedTextureSize; +int m_nFixedTextureSizeWidth; +int m_nFixedTextureSizeHeight; int m_nTextureScale; bool m_bNormalizeColors; bool m_bSwitchClip; diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 264e18ee..b80d1445 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -1129,6 +1129,44 @@ void Texture_ShowStartupShaders(){ ============================================================================ */ +void Texture_GetSize( qtexture_t *tex, int & nWidth, int & nHeight ){ + if( !tex ) + return; + + if( g_PrefsDlg.m_bFixedTextureSize && g_PrefsDlg.m_nFixedTextureSizeWidth > 0 && g_PrefsDlg.m_nFixedTextureSizeHeight > 0 ) + { + nWidth = g_PrefsDlg.m_nFixedTextureSizeWidth; + nHeight = g_PrefsDlg.m_nFixedTextureSizeHeight; + float ratioWidth = nHeight / nWidth; + float ratioHeight = nWidth / nHeight; + if( tex->width * ratioWidth > tex->height * ratioHeight ) + { + nHeight *= tex->height * 1.0f / tex->width * ratioWidth; + } else + if( tex->height * ratioHeight > tex->width * ratioWidth ) + { + nWidth *= tex->width * 1.0f / tex->height * ratioHeight; + } + } else { + nWidth = (int)( tex->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + nHeight = (int)( tex->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + } +} + +void Texture_GetPosSize( qtexture_t *tex, int & nWidth, int & nHeight ){ + if( !tex ) + return; + + if( g_PrefsDlg.m_bFixedTextureSize && g_PrefsDlg.m_nFixedTextureSizeWidth > 0 && g_PrefsDlg.m_nFixedTextureSizeHeight > 0 ) + { + nWidth = g_PrefsDlg.m_nFixedTextureSizeWidth; + nHeight = g_PrefsDlg.m_nFixedTextureSizeHeight; + } else { + nWidth = (int)( tex->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + nHeight = (int)( tex->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + } +} + void Texture_StartPos( void ){ //++timo TODO: check use of current_texture and current_row? current_x = 8; @@ -1195,8 +1233,9 @@ IShader* Texture_NextPos( int *x, int *y ){ continue; } - int nWidth = (int)( q->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); - int nHeight = (int)( q->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + int nWidth; + int nHeight; + Texture_GetPosSize( q, nWidth, nHeight ); if ( current_x + nWidth > g_qeglobals.d_texturewin.width - 8 && current_row ) { // go to the next row unless the texture is the first on the row current_x = 8; current_y -= current_row + FONT_HEIGHT + 4; @@ -1263,7 +1302,7 @@ void WINAPI Texture_SetTexture( texdef_t *texdef, brushprimit_texdef_t *brushpri g_dlgFind.updateTextures( texdef->GetName() ); if ( !g_dlgFind.isOpen() && bSetSelection ) { - Select_SetTexture( texdef,brushprimit_texdef,bFitScale ); + Select_SetTexture( texdef,brushprimit_texdef, bFitScale ); } //plugins: send a message telling that the selected texture may have changed @@ -1348,8 +1387,9 @@ void SelectTexture( int mx, int my, bool bShift, bool bFitScale ){ if ( !q ) { break; } - int nWidth = (int)( q->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); - int nHeight = (int)( q->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + int nWidth; + int nHeight; + Texture_GetPosSize( q, nWidth, nHeight ); if ( mx > x && mx - x < nWidth && my < y && y - my < nHeight + FONT_HEIGHT ) { if ( bShift ) { @@ -1519,8 +1559,7 @@ void Texture_Draw( int width, int height ){ break; } - nWidth = (int)( q->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); - nHeight = (int)( q->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); + Texture_GetSize( q, nWidth, nHeight ); if ( y != last_y ) { last_y = y;