Merge pull request #530 from Pan7/fixedTex

Fixed textures for the texture browser
This commit is contained in:
Timothee "TTimo" Besset 2017-08-05 15:12:16 -05:00 committed by GitHub
commit 222adc1c87
3 changed files with 98 additions and 8 deletions

View File

@ -105,6 +105,9 @@
#define CHASEMOUSE_KEY "ChaseMouse" #define CHASEMOUSE_KEY "ChaseMouse"
#define MOUSEWHEELZOOM_KEY "MousewheelZoom" #define MOUSEWHEELZOOM_KEY "MousewheelZoom"
#define ENTITYSHOW_KEY "EntityShow" #define ENTITYSHOW_KEY "EntityShow"
#define FIXEDTEXSIZE_KEY "UseFixedTextureSize"
#define FIXEDTEXSIZEWIDTH_KEY "FixedTextureSizeWidth"
#define FIXEDTEXSIZEHEIGHT_KEY "FixedTextureSizeHeight"
#define TEXTURESCALE_KEY "TextureScale" #define TEXTURESCALE_KEY "TextureScale"
#define TEXTURESCROLLBAR_KEY "TextureScrollbar" #define TEXTURESCROLLBAR_KEY "TextureScrollbar"
#define DISPLAYLISTS_KEY "UseDisplayLists" #define DISPLAYLISTS_KEY "UseDisplayLists"
@ -628,6 +631,9 @@ PrefsDlg::PrefsDlg (){
m_bSelectCurves = TRUE; m_bSelectCurves = TRUE;
m_bSelectModels = TRUE; m_bSelectModels = TRUE;
m_nEntityShowState = ENTITY_SKINNED_BOXED; m_nEntityShowState = ENTITY_SKINNED_BOXED;
m_bFixedTextureSize = TRUE;
m_nFixedTextureSizeWidth = 64;
m_nFixedTextureSizeHeight = 64;
m_nTextureScale = 2; m_nTextureScale = 2;
m_bSwitchClip = FALSE; m_bSwitchClip = FALSE;
m_bSelectWholeEntities = TRUE; m_bSelectWholeEntities = TRUE;
@ -1539,11 +1545,12 @@ void PrefsDlg::BuildDialog(){
// Main Preferences dialog // Main Preferences dialog
GtkWidget *dialog, *mainvbox, *hbox, *sc_win, *preflabel; GtkWidget *dialog, *mainvbox, *hbox, *sc_win, *preflabel;
GtkWidget *ftw_label, *fth_label;
// Widgets on notebook pages // Widgets on notebook pages
GtkWidget *check, *label, *scale, *hbox2, *combo, GtkWidget *check, *label, *scale, *hbox2, *combo,
*table, *spin, *entry, *pixmap, *table, *spin, *entry, *pixmap,
*radio, *button, *pageframe, *vbox; *radio, *button, *pageframe, *vbox;
GtkSizeGroup *size_group;
GList *combo_list = (GList*)NULL; GList *combo_list = (GList*)NULL;
GList *lst; GList *lst;
GtkAdjustment *adj; GtkAdjustment *adj;
@ -2074,7 +2081,48 @@ void PrefsDlg::BuildDialog(){
gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), (const char *)lst->data ); gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT( combo ), (const char *)lst->data );
} }
g_list_free( combo_list ); 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" ) ); check = gtk_check_button_new_with_label( _( "Show Texture Directory List" ) );
gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 ); gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 );
gtk_widget_show( check ); gtk_widget_show( check );

View File

@ -650,6 +650,9 @@ int m_nCubicScale;
bool m_bSelectCurves; bool m_bSelectCurves;
bool m_bSelectModels; bool m_bSelectModels;
int m_nEntityShowState; int m_nEntityShowState;
bool m_bFixedTextureSize;
int m_nFixedTextureSizeWidth;
int m_nFixedTextureSizeHeight;
int m_nTextureScale; int m_nTextureScale;
bool m_bNormalizeColors; bool m_bNormalizeColors;
bool m_bSwitchClip; bool m_bSwitchClip;

View File

@ -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 ){ void Texture_StartPos( void ){
//++timo TODO: check use of current_texture and current_row? //++timo TODO: check use of current_texture and current_row?
current_x = 8; current_x = 8;
@ -1195,8 +1233,9 @@ IShader* Texture_NextPos( int *x, int *y ){
continue; continue;
} }
int nWidth = (int)( q->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); int nWidth;
int nHeight = (int)( q->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); 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 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_x = 8;
current_y -= current_row + FONT_HEIGHT + 4; 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() ); g_dlgFind.updateTextures( texdef->GetName() );
if ( !g_dlgFind.isOpen() && bSetSelection ) { 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 //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 ) { if ( !q ) {
break; break;
} }
int nWidth = (int)( q->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); int nWidth;
int nHeight = (int)( q->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); int nHeight;
Texture_GetPosSize( q, nWidth, nHeight );
if ( mx > x && mx - x < nWidth if ( mx > x && mx - x < nWidth
&& my < y && y - my < nHeight + FONT_HEIGHT ) { && my < y && y - my < nHeight + FONT_HEIGHT ) {
if ( bShift ) { if ( bShift ) {
@ -1519,8 +1559,7 @@ void Texture_Draw( int width, int height ){
break; break;
} }
nWidth = (int)( q->width * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) ); Texture_GetSize( q, nWidth, nHeight );
nHeight = (int)( q->height * ( (float)g_PrefsDlg.m_nTextureScale / 100 ) );
if ( y != last_y ) { if ( y != last_y ) {
last_y = y; last_y = y;