#include "debugging/debugging.h"
#include "warnings.h"
+#include "defaults.h"
#include "ifilesystem.h"
#include "iundo.h"
#include "igl.h"
#include "shaders.h"
#include "commands.h"
-#define NOTEX_BASENAME "notex"
-#define SHADERNOTEX_BASENAME "shadernotex"
-
bool TextureBrowser_showWads(){
return !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) );
}
void TextureGroups_addWad( TextureGroups& groups, const char* archive ){
if ( extension_equal( path_get_extension( archive ), "wad" ) ) {
-#if 1
groups.insert( archive );
-#else
- CopiedString archiveBaseName( path_get_filename_start( archive ), path_get_filename_base_end( archive ) );
- groups.insert( archiveBaseName );
-#endif
}
}
+
typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addWad> TextureGroupsAddWadCaller;
namespace
CopiedString g_notex;
CopiedString g_shadernotex;
+
bool isMissing(const char* name);
+
bool isNotex(const char* name);
bool isMissing(const char* name){
}
bool isNotex(const char* name){
- if ( string_equal_suffix( name, "/" NOTEX_BASENAME ) ) {
+ if ( string_equal_suffix( name, "/" DEFAULT_NOTEX_BASENAME ) ) {
return true;
}
- if ( string_equal_suffix( name, "/" SHADERNOTEX_BASENAME ) ) {
+ if ( string_equal_suffix( name, "/" DEFAULT_SHADERNOTEX_BASENAME ) ) {
return true;
}
return false;
}
}
}
+
typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addShader> TextureGroupsAddShaderCaller;
void TextureGroups_addDirectory( TextureGroups& groups, const char* directory ){
{
gdouble m_value;
guint m_handler;
+
typedef void ( *ValueChangedFunction )( void* data, gdouble value );
+
ValueChangedFunction m_function;
void* m_data;
reinterpret_cast<DeferredAdjustment*>( data )->m_value = 0;
return FALSE;
}
+
public:
DeferredAdjustment( ValueChangedFunction function, void* data ) : m_value( 0 ), m_handler( 0 ), m_function( function ), m_data( data ){
}
+
void flush(){
if ( m_handler != 0 ) {
g_source_remove( m_handler );
deferred_value_changed( this );
}
}
+
void value_changed( gdouble value ){
m_value = value;
if ( m_handler == 0 ) {
m_handler = g_idle_add( deferred_value_changed, this );
}
}
+
static void adjustment_value_changed(ui::Adjustment adjustment, DeferredAdjustment* self ){
self->value_changed( gtk_adjustment_get_value(adjustment) );
}
};
-
class TextureBrowser;
typedef ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw> TextureBrowserQueueDrawCaller;
};
void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
void TextureBrowser_fixedSize( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport;
void TextureBrowser_filterMissing( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport;
void TextureBrowser_filterFallback( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport;
void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer );
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport;
class TextureBrowser
ui::Window m_parent{ui::null};
ui::GLArea m_gl_widget{ui::null};
ui::Widget m_texture_scroll{ui::null};
-ui::TreeView m_treeViewTree{ui::null};
+ui::TreeView m_treeViewTree{ui::New};
ui::TreeView m_treeViewTags{ui::null};
ui::Frame m_tag_frame{ui::null};
ui::ListStore m_assigned_store{ui::null};
bool m_tags;
// The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
int m_uniformTextureSize;
+
// Return the display width of a texture in the texture browser
int getTextureWidth( qtexture_t* tex ){
int width;
}
return width;
}
+
// Return the display height of a texture in the texture browser
int getTextureHeight( qtexture_t* tex ){
int height;
}
}
else {
- if ( !shader_equal_prefix( shader_get_textureName( shader->getName() ), g_TextureBrowser_currentDirectory.c_str() ) ) {
+ if ( TextureBrowser_showWads() )
+ {
+ if ( g_TextureBrowser_currentDirectory != ""
+ && !string_equal( shader->getWadName(), g_TextureBrowser_currentDirectory.c_str() ) )
+ {
+ return false;
+ }
+ }
+ else if ( !shader_equal_prefix( shader_get_textureName( shader->getName() ), g_TextureBrowser_currentDirectory.c_str() ) ) {
return false;
}
}
m_realiseCallbacks();
TextureBrowser_constructTreeStore();
}
+
void unrealise(){
}
+
void insert( const SignalHandler& handler ){
m_realiseCallbacks.connectLast( handler );
}
endswith( strTemp.c_str(), ".diffuse" ) ||
endswith( strTemp.c_str(), ".blend" ) ||
endswith( strTemp.c_str(), ".alpha" ) ||
- endswith( strTemp.c_str(), "_norm" ) ||
+ endswith( strTemp.c_str(), "_alpha" ) ||
+ /* Quetoo */
+ endswith( strTemp.c_str(), "_h" ) ||
+ endswith( strTemp.c_str(), "_local" ) ||
+ endswith( strTemp.c_str(), "_nm" ) ||
+ endswith( strTemp.c_str(), "_s" ) ||
+ /* DarkPlaces */
endswith( strTemp.c_str(), "_bump" ) ||
endswith( strTemp.c_str(), "_glow" ) ||
endswith( strTemp.c_str(), "_gloss" ) ||
+ endswith( strTemp.c_str(), "_luma" ) ||
+ endswith( strTemp.c_str(), "_norm" ) ||
endswith( strTemp.c_str(), "_pants" ) ||
endswith( strTemp.c_str(), "_shirt" ) ||
endswith( strTemp.c_str(), "_reflect" ) ||
- endswith( strTemp.c_str(), "_alpha" ) ||
+ /* Unvanquished */
+ endswith( strTemp.c_str(), "_d" ) ||
+ endswith( strTemp.c_str(), "_n" ) ||
+ endswith( strTemp.c_str(), "_p" ) ||
+ endswith( strTemp.c_str(), "_g" ) ||
+ endswith( strTemp.c_str(), "_a" ) ||
0;
}
void visit( const char* name ){
IShader* shader = QERApp_Shader_ForName( CopiedString( StringRange( name, path_get_filename_base_end( name ) ) ).c_str() );
shader->DecRef();
+ shader->setWadName( g_TextureBrowser_currentDirectory.c_str() );
}
};
}
-
class TextureCategoryLoadShader
{
const char* m_directory;
: m_directory( directory ), m_count( count ){
m_count = 0;
}
+
void operator()( const char* name ) const {
if ( shader_equal_prefix( name, "textures/" )
&& shader_equal_prefix( name + string_length( "textures/" ), m_directory ) ) {
IShader* shader = QERApp_Shader_ForName( name.c_str() );
shader->DecRef();
}
+
typedef ConstPointerCaller<char, void(const char*), TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
class LoadTexturesByTypeVisitor : public ImageModules::Visitor
LoadTexturesByTypeVisitor( const char* dirstring )
: m_dirstring( dirstring ){
}
+
void visit( const char* minor, const _QERPlugImageTable& table ) const {
GlobalFileSystem().forEachFile( m_dirstring, minor, TextureDirectoryLoadTextureCaller( m_dirstring ) );
}
void TextureBrowser_ShowDirectory( TextureBrowser& textureBrowser, const char* directory ){
if ( TextureBrowser_showWads() ) {
+ g_TextureBrowser_currentDirectory = directory;
+ TextureBrowser_heightChanged( textureBrowser );
+
Archive* archive = GlobalFileSystem().getArchive( directory );
- ASSERT_NOTNULL( archive );
- LoadShaderVisitor visitor;
- archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
+ if ( archive != nullptr )
+ {
+ LoadShaderVisitor visitor;
+ archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
+ }
+ else if ( extension_equal_i( path_get_extension( directory ), "wad" ) )
+ {
+ globalErrorStream() << "Failed to load " << directory << "\n";
+ }
}
else
{
void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer ){
importer( TextureBrowser_hideUnused() );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer ){
importer( GlobalTextureBrowser().m_showShaders );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer ){
importer( g_TextureBrowser_shaderlistOnly );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
void TextureBrowser_fixedSize( const Callback<void(bool)> & importer ){
importer( g_TextureBrowser_fixedSize );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
void TextureBrowser_filterMissing( const Callback<void(bool)> & importer ){
importer( g_TextureBrowser_filterMissing );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport;
void TextureBrowser_filterFallback( const Callback<void(bool)> & importer ){
importer( g_TextureBrowser_filterFallback );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport;
void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer ){
importer( g_TextureBrowser_enableAlpha );
}
+
typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport;
void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){
glBegin( GL_QUADS );
int font_height = TextureBrowser_fontHeight( textureBrowser );
for ( int i = 0; i < nHeight; i += 8 )
+ {
for ( int j = 0; j < nWidth; j += 8 )
{
unsigned char color = (i + j) / 8 % 2 ? 0x66 : 0x99;
glVertex2i(x + left, y - nHeight - font_height + bottom);
glVertex2i(x + right, y - nHeight - font_height + bottom);
}
+ }
glEnd();
glEnable( GL_TEXTURE_2D );
}
}
}
+const char* TextureGroups_transformDirName( const char* dirName, StringOutputStream *archiveName )
+{
+ if ( TextureBrowser_showWads() ) {
+ archiveName->clear();
+ *archiveName << StringRange( path_get_filename_start( dirName ), path_get_filename_base_end( dirName ) ) \
+ << "." << path_get_extension( dirName );
+ return archiveName->c_str();
+ }
+ return dirName;
+}
+
void TextureGroups_constructTreeModel( TextureGroups groups, ui::TreeStore store ){
// put the information from the old textures menu into a treeview
GtkTreeIter iter, child;
TextureGroups::const_iterator i = groups.begin();
while ( i != groups.end() )
{
- const char* dirName = ( *i ).c_str();
+ StringOutputStream archiveName;
+ StringOutputStream nextArchiveName;
+ const char* dirName = TextureGroups_transformDirName( ( *i ).c_str(), &archiveName );
+
const char* firstUnderscore = strchr( dirName, '_' );
StringRange dirRoot( dirName, ( firstUnderscore == 0 ) ? dirName : firstUnderscore + 1 );
TextureGroups::const_iterator next = i;
++next;
+
if ( firstUnderscore != 0
&& next != groups.end()
- && string_equal_start( ( *next ).c_str(), dirRoot ) ) {
+ && string_equal_start( TextureGroups_transformDirName( ( *next ).c_str(), &nextArchiveName ), dirRoot ) ) {
gtk_tree_store_append( store, &iter, NULL );
gtk_tree_store_set( store, &iter, 0, CopiedString( StringRange( dirName, firstUnderscore ) ).c_str(), -1 );
// keep going...
- while ( i != groups.end() && string_equal_start( ( *i ).c_str(), dirRoot ) )
+ while ( i != groups.end() && string_equal_start( TextureGroups_transformDirName( ( *i ).c_str(), &nextArchiveName ), dirRoot ) )
{
gtk_tree_store_append( store, &child, &iter );
- gtk_tree_store_set( store, &child, 0, ( *i ).c_str(), -1 );
+ gtk_tree_store_set( store, &child, 0, TextureGroups_transformDirName( ( *i ).c_str(), &nextArchiveName ), -1 );
++i;
}
}
}
void TextureBrowser_createTreeViewTree(){
- g_TextureBrowser.m_treeViewTree = ui::TreeView(ui::New);
gtk_tree_view_set_enable_search(g_TextureBrowser.m_treeViewTree, FALSE );
gtk_tree_view_set_headers_visible(g_TextureBrowser.m_treeViewTree, FALSE );
}
void TextureBrowser_addTag();
+
void TextureBrowser_renameTag();
+
void TextureBrowser_deleteTag();
void TextureBrowser_createContextMenu( ui::Widget treeview, GdkEventButton *event ){
create_menu_item_with_mnemonic( menu, "Show All", "ShowAllTextures" );
// we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
- if ( g_pGameDescription->mGameType == "doom3" || !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
+ if ( g_pGameDescription->mGameType == "doom3" || TextureBrowser_showWads() ) {
g_TextureBrowser.m_showShaders = true;
}
else
}
void TextureBrowser_SetNotex(){
- StringOutputStream name( 256 );
- name << GlobalRadiant().getAppPath() << "bitmaps/" NOTEX_BASENAME ".png";
- g_notex = name.c_str();
+ IShader* notex = QERApp_Shader_ForName( DEFAULT_NOTEX_NAME );
+ IShader* shadernotex = QERApp_Shader_ForName( DEFAULT_SHADERNOTEX_NAME );
+
+ g_notex = notex->getTexture()->name;
+ g_shadernotex = shadernotex->getTexture()->name;
- name = StringOutputStream(256);
- name << GlobalRadiant().getAppPath() << "bitmaps/" SHADERNOTEX_BASENAME " .png";
- g_shadernotex = name.c_str();
+ notex->DecRef();
+ shadernotex->DecRef();
}
ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
}
else
{
- g_TextureBrowser.m_parent.alert( "Select a single tag for renaming." );
+ ui::alert( g_TextureBrowser.m_parent, "Select a single tag for renaming." );
}
}
gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
if ( g_slist_length( selected ) == 1 ) { // we only delete a single tag
- auto result = g_TextureBrowser.m_parent.alert( "Are you sure you want to delete the selected tag?", "Delete Tag", ui::alert_type::YESNO, ui::alert_icon::Question );
+ auto result = ui::alert( g_TextureBrowser.m_parent, "Are you sure you want to delete the selected tag?", "Delete Tag", ui::alert_type::YESNO, ui::alert_icon::Question );
if ( result == ui::alert_response::YES ) {
GtkTreeIter iterSelected;
}
}
else {
- g_TextureBrowser.m_parent.alert( "Select a single tag for deletion." );
+ ui::alert( g_TextureBrowser.m_parent, "Select a single tag for deletion." );
}
}
}
void TextureBrowser_showUntagged(){
- auto result = g_TextureBrowser.m_parent.alert( "WARNING! This function might need a lot of memory and time. Are you sure you want to use it?", "Show Untagged", ui::alert_type::YESNO, ui::alert_icon::Warning );
+ auto result = ui::alert( g_TextureBrowser.m_parent, "WARNING! This function might need a lot of memory and time. Are you sure you want to use it?", "Show Untagged", ui::alert_type::YESNO, ui::alert_icon::Warning );
if ( result == ui::alert_response::YES ) {
g_TextureBrowser.m_found_shaders.clear();
PreferencesPage page( group.createPage( "Texture Browser", "Texture Browser Preferences" ) );
TextureBrowser_constructPreferences( page );
}
+
void TextureBrowser_registerPreferencesPage(){
PreferencesDialog_addSettingsPage( makeCallbackF(TextureBrowser_constructPage) );
}
TextureBrowser_textureSelected = TextureClipboard_textureSelected;
}
+
void TextureBrowser_Destroy(){
GlobalShaderSystem().detach( g_ShadersObserver );
Textures_setModeChangedNotify( Callback<void()>() );
}
+
+#if WORKAROUND_WINDOWS_GTK2_GLWIDGET
+ui::GLArea TextureBrowser_getGLWidget(){
+ return GlobalTextureBrowser().m_gl_widget;
+}
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET