mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2025-04-24 03:11:05 +00:00
New: Texture directory list widget
This commit is contained in:
parent
30aa7950ab
commit
6c759f1e0a
5 changed files with 247 additions and 3 deletions
|
@ -2373,7 +2373,11 @@ static void TextureListDialog_response( GtkWidget *widget, gint response_id, gpo
|
|||
if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
|
||||
GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
|
||||
if ( gtk_tree_path_get_depth( path ) == 1 ) {
|
||||
Texture_ShowDirectory( gtk_tree_path_get_indices( path )[0] + CMD_TEXTUREWAD );
|
||||
char* p;
|
||||
gtk_tree_model_get( model, &iter, 0, &p, -1 );
|
||||
|
||||
Texture_ShowDirectory_by_path( p );
|
||||
g_free( p );
|
||||
}
|
||||
gtk_tree_path_free( path );
|
||||
}
|
||||
|
@ -2428,7 +2432,7 @@ void DoTextureListDlg(){
|
|||
// Initialize dialog
|
||||
GtkTreeIter iter;
|
||||
GSList *textures = (GSList*)NULL;
|
||||
FillTextureMenu( &textures );
|
||||
FillTextureList( &textures );
|
||||
while ( textures != NULL )
|
||||
{
|
||||
gtk_list_store_append( store, &iter );
|
||||
|
|
|
@ -2360,6 +2360,98 @@ GtkWidget* create_framed_widget( GtkWidget* widget ){
|
|||
return frame;
|
||||
}
|
||||
|
||||
static void textdirlist_activate( GtkTreeView *tree_view )
|
||||
{
|
||||
GtkTreeSelection* selection;
|
||||
|
||||
GtkTreeModel* model;
|
||||
GtkTreeIter iter;
|
||||
|
||||
selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( tree_view ) );
|
||||
|
||||
if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
|
||||
GtkTreePath* path = gtk_tree_model_get_path( model, &iter );
|
||||
if ( gtk_tree_path_get_depth( path ) == 1 ) {
|
||||
char* p;
|
||||
gtk_tree_model_get( model, &iter, 0, &p, -1 );
|
||||
|
||||
Texture_ShowDirectory_by_path( p );
|
||||
g_free( p );
|
||||
}
|
||||
gtk_tree_path_free( path );
|
||||
}
|
||||
}
|
||||
|
||||
static void textdirlist_row_activated( GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data )
|
||||
{
|
||||
textdirlist_activate( tree_view );
|
||||
}
|
||||
static void textdirlist_cursor_changed( GtkTreeView *tree_view, gpointer user_data )
|
||||
{
|
||||
textdirlist_activate( tree_view );
|
||||
}
|
||||
|
||||
GtkWidget* create_texdirlist_widget( void )
|
||||
{
|
||||
GtkWidget *scr;
|
||||
GtkWidget* view;
|
||||
|
||||
scr = gtk_scrolled_window_new( (GtkAdjustment*)NULL, (GtkAdjustment*)NULL );
|
||||
|
||||
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
|
||||
gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
|
||||
gtk_widget_set_vexpand( scr, TRUE );
|
||||
gtk_widget_set_hexpand( scr, TRUE );
|
||||
|
||||
{
|
||||
GtkListStore* store = gtk_list_store_new( 1, G_TYPE_STRING );
|
||||
|
||||
view = gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) );
|
||||
gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
|
||||
|
||||
{
|
||||
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
|
||||
GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Textures", renderer, "text", 0, (char *) NULL );
|
||||
gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
|
||||
}
|
||||
|
||||
gtk_container_add( GTK_CONTAINER( scr ), view );
|
||||
|
||||
g_object_set_data( G_OBJECT( g_qeglobals_gui.d_main_window ), "dirlist_treeview" , view );
|
||||
|
||||
FillTextureDirListWidget();
|
||||
|
||||
g_object_unref( G_OBJECT( store ) );
|
||||
|
||||
gtk_tree_selection_set_mode( gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ), GTK_SELECTION_SINGLE );
|
||||
#if GTK_CHECK_VERSION( 3,12,0 )
|
||||
gtk_tree_view_set_activate_on_single_click( GTK_TREE_VIEW( view ), TRUE );
|
||||
#else
|
||||
g_signal_connect( view, "cursor-changed", G_CALLBACK( textdirlist_cursor_changed ), view );
|
||||
#endif
|
||||
g_signal_connect( view, "row-activated", G_CALLBACK( textdirlist_row_activated ), view );
|
||||
|
||||
gtk_widget_set_vexpand( view, TRUE );
|
||||
gtk_widget_set_hexpand( view, TRUE );
|
||||
gtk_widget_show( view );
|
||||
|
||||
}
|
||||
|
||||
gtk_widget_show( scr );
|
||||
|
||||
#if GTK_CHECK_VERSION( 3,12,0 )
|
||||
todo; //set the scrolledwindow to the default size that doesn't require scrollbars
|
||||
#else
|
||||
{
|
||||
gint view_width;
|
||||
//trying to set a nice initial size for the scrolledwindow
|
||||
gtk_widget_get_preferred_width( view, NULL, &view_width );
|
||||
gtk_widget_set_size_request( scr, view_width + 25, -1 );
|
||||
}
|
||||
#endif
|
||||
return scr;
|
||||
}
|
||||
|
||||
gboolean entry_focus_in( GtkWidget *widget, GdkEventFocus *event, gpointer user_data ){
|
||||
gtk_window_remove_accel_group( GTK_WINDOW( g_pParentWnd->m_pWidget ), global_accel );
|
||||
return FALSE;
|
||||
|
@ -2623,7 +2715,16 @@ void MainFrame::Create(){
|
|||
m_pTexWnd = new TexWnd();
|
||||
{
|
||||
GtkWidget* frame = create_framed_texwnd( m_pTexWnd );
|
||||
gtk_paned_add2( GTK_PANED( vsplit2 ), frame );
|
||||
|
||||
GtkWidget* texDirList = create_texdirlist_widget();
|
||||
|
||||
GtkWidget* texSplit = gtk_paned_new( GTK_ORIENTATION_HORIZONTAL );
|
||||
|
||||
gtk_paned_add2( GTK_PANED( vsplit2 ), texSplit );
|
||||
gtk_paned_add1( GTK_PANED( texSplit ), texDirList );
|
||||
gtk_paned_add2( GTK_PANED( texSplit ), frame );
|
||||
|
||||
gtk_widget_show( texSplit );
|
||||
}
|
||||
|
||||
// console
|
||||
|
@ -5829,6 +5930,7 @@ void MainFrame::OnTexturesShaderlistonly(){
|
|||
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( item ), g_PrefsDlg.m_bTexturesShaderlistOnly ? TRUE : FALSE );
|
||||
g_bIgnoreCommands--;
|
||||
FillTextureMenu();
|
||||
FillTextureDirListWidget();
|
||||
}
|
||||
|
||||
void MainFrame::OnTextureWad( unsigned int nID ){
|
||||
|
|
|
@ -261,6 +261,8 @@ void MRU_Activate( int index );
|
|||
|
||||
void FillTextureMenu( GSList** pArray = NULL );
|
||||
void FillBSPMenu( void );
|
||||
void FillTextureList( GSList** pArray );
|
||||
void FillTextureDirListWidget( void );
|
||||
|
||||
// profile functions - kind of utility lib
|
||||
// they are kind of dumb, they expect to get the path to the .ini file or to the prefs directory when called
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
void Texture_Init();
|
||||
void Texture_ShowDirectory( int menunum );
|
||||
void Texture_ShowDirectory();
|
||||
void Texture_ShowDirectory_by_path( const char* pPath );
|
||||
void Texture_ShowAll();
|
||||
void WINAPI Texture_ShowInuse();
|
||||
extern char texture_directory[];
|
||||
|
|
|
@ -555,6 +555,9 @@ void ClearGSList( GSList* lst ){
|
|||
}
|
||||
|
||||
void FillTextureMenu( GSList** pArray ){
|
||||
|
||||
return;
|
||||
/*
|
||||
GtkWidget *menu, *sep, *item; // point to the Textures GtkMenu and to the last separator
|
||||
GList *lst;
|
||||
GSList *texdirs = NULL;
|
||||
|
@ -700,8 +703,140 @@ void FillTextureMenu( GSList** pArray ){
|
|||
temp = temp->next;
|
||||
}
|
||||
ClearGSList( texdirs );
|
||||
*/
|
||||
}
|
||||
|
||||
void FillTextureList( GSList** pArray )
|
||||
{
|
||||
GSList *p;
|
||||
char dirRoot[NAME_MAX];
|
||||
int texture_num;
|
||||
GSList *texdirs = NULL;
|
||||
GSList *texdirs_tmp = NULL;
|
||||
|
||||
texture_num = 0;
|
||||
|
||||
// scan texture dirs and pak files only if not restricting to shaderlist
|
||||
if ( !g_PrefsDlg.m_bTexturesShaderlistOnly ) {
|
||||
texdirs_tmp = vfsGetDirList( "textures/" );
|
||||
for ( p = texdirs_tmp; p; p = g_slist_next( p ) )
|
||||
{
|
||||
// Hydra: erm, this didn't used to do anything except leak memory...
|
||||
// For Halflife support this is required to work however.
|
||||
// g_slist_append(texdirs, p->data);
|
||||
texdirs = g_slist_append( texdirs, g_strdup( (char *)p->data ) );
|
||||
}
|
||||
vfsClearFileDirList( &texdirs_tmp );
|
||||
}
|
||||
|
||||
// scan the shaders in shaderlist.txt
|
||||
BuildShaderList();
|
||||
PreloadShaders();
|
||||
DumpUnreferencedShaders();
|
||||
while ( l_shaderfiles != NULL )
|
||||
{
|
||||
char shaderfile[PATH_MAX];
|
||||
gboolean found = FALSE;
|
||||
|
||||
ExtractFileName( (char*)l_shaderfiles->data, shaderfile );
|
||||
StripExtension( shaderfile );
|
||||
strlwr( shaderfile );
|
||||
|
||||
for ( GSList *tmp = texdirs; tmp; tmp = g_slist_next( tmp ) )
|
||||
if ( !strcasecmp( (char*)tmp->data, shaderfile ) ) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !found ) {
|
||||
texdirs = g_slist_prepend( texdirs, g_strdup( shaderfile ) );
|
||||
}
|
||||
|
||||
g_free( l_shaderfiles->data );
|
||||
l_shaderfiles = g_slist_remove( l_shaderfiles, l_shaderfiles->data );
|
||||
}
|
||||
|
||||
// sort the list
|
||||
texdirs = g_slist_sort( texdirs, (GCompareFunc)strcmp );
|
||||
|
||||
GSList *temp = texdirs;
|
||||
while ( temp )
|
||||
{
|
||||
char* ptr = strchr( (char*)temp->data, '_' );
|
||||
|
||||
// do we shrink the menus?
|
||||
if ( ptr != NULL ) {
|
||||
// extract the root
|
||||
strcpy( dirRoot, (char*)temp->data );
|
||||
dirRoot[ptr - (char*)temp->data + 1] = 0;
|
||||
|
||||
// we shrink only if we have at least two things to shrink :-)
|
||||
if ( temp->next && ( strstr( (char*)temp->next->data, dirRoot ) == (char*)temp->next->data ) ) {
|
||||
do
|
||||
{
|
||||
if ( pArray ) {
|
||||
*pArray = g_slist_append( *pArray, g_strdup( (char*)temp->data ) );
|
||||
}
|
||||
if ( ++texture_num == MAX_TEXTUREDIRS ) {
|
||||
Sys_Printf( "WARNING: max texture directories count has been reached!\n" );
|
||||
ClearGSList( texdirs );
|
||||
return;
|
||||
}
|
||||
temp = temp->next;
|
||||
}
|
||||
while ( temp && ( strstr( (char*)temp->data, dirRoot ) == temp->data ) );
|
||||
|
||||
ptr = strchr( dirRoot, '_' );
|
||||
*ptr = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( pArray ) {
|
||||
*pArray = g_slist_append( *pArray, g_strdup( (char*)temp->data ) );
|
||||
}
|
||||
if ( ++texture_num == MAX_TEXTUREDIRS ) {
|
||||
Sys_Printf( "WARNING: max texture directories count has been reached!\n" );
|
||||
ClearGSList( texdirs );
|
||||
return;
|
||||
}
|
||||
|
||||
temp = temp->next;
|
||||
}
|
||||
ClearGSList( texdirs );
|
||||
}
|
||||
|
||||
void FillTextureDirListWidget( void )
|
||||
{
|
||||
GtkWidget* treeview;
|
||||
GtkTreeModel* model;
|
||||
GtkListStore* store;
|
||||
GtkTreeIter iter;
|
||||
GSList *textures = (GSList*)NULL;
|
||||
|
||||
treeview = GTK_WIDGET( g_object_get_data( G_OBJECT( g_qeglobals_gui.d_main_window ), "dirlist_treeview" ) );
|
||||
if( treeview == NULL )
|
||||
return;
|
||||
model = gtk_tree_view_get_model( GTK_TREE_VIEW( treeview ) );
|
||||
store = GTK_LIST_STORE( model );
|
||||
|
||||
gtk_list_store_clear( store );
|
||||
|
||||
FillTextureList( &textures );
|
||||
while ( textures != NULL )
|
||||
{
|
||||
gtk_list_store_append( store, &iter );
|
||||
gtk_list_store_set( store, &iter, 0, (gchar*)textures->data, -1 );
|
||||
|
||||
g_free( textures->data );
|
||||
textures = g_slist_remove( textures, textures->data );
|
||||
}
|
||||
}
|
||||
|
||||
void Texture_ShowDirectory_by_path( const char* pPath )
|
||||
{
|
||||
snprintf( texture_directory, sizeof( texture_directory ), "%s%s", pPath, "/" );
|
||||
Texture_ShowDirectory();
|
||||
}
|
||||
/*
|
||||
==============
|
||||
Texture_ShowDirectory
|
||||
|
|
Loading…
Reference in a new issue