bool m_tags;
// The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
int m_uniformTextureSize;
+ int m_uniformTextureMinSize;
// Return the display width of a texture in the texture browser
- int getTextureWidth( qtexture_t* tex ){
- int width;
+ /*void getTextureWH( qtexture_t* tex, int *width, int *height ){
if ( !g_TextureBrowser_fixedSize ) {
// Don't use uniform size
- width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
+ *width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
+ *height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
+
}
- else if
- ( tex->width >= tex->height ) {
+ else if ( tex->width >= tex->height ) {
// Texture is square, or wider than it is tall
- width = m_uniformTextureSize;
+ if ( tex->width >= m_uniformTextureSize ){
+ *width = m_uniformTextureSize;
+ *height = (int)( m_uniformTextureSize * ( (float)tex->height / tex->width ) );
+ }
+ else if ( tex->width <= m_uniformTextureMinSize ){
+ *width = m_uniformTextureMinSize;
+ *height = (int)( m_uniformTextureMinSize * ( (float)tex->height / tex->width ) );
- }
- else {
+ }
+ else {
- // Otherwise, preserve the texture's aspect ratio
- width = (int)( m_uniformTextureSize * ( (float)tex->width / tex->height ) );
+ *width = tex->width;
+ *height = tex->height;
- }
++ }
+ }
+ else {
+ // Texture taller than it is wide
+ if ( tex->height >= m_uniformTextureSize ){
+ *height = m_uniformTextureSize;
+ *width = (int)( m_uniformTextureSize * ( (float)tex->width / tex->height ) );
+ }
+ else if ( tex->height <= m_uniformTextureMinSize ){
+ *height = m_uniformTextureMinSize;
+ *width = (int)( m_uniformTextureMinSize * ( (float)tex->width / tex->height ) );
+ }
+ else {
+ *width = tex->width;
+ *height = tex->height;
+ }
}
- return width;
}
- // Return the display height of a texture in the texture browser
- int getTextureHeight( qtexture_t* tex ){
- int height;
- if ( !g_TextureBrowser_fixedSize ) {
+ */
+ void getTextureWH( qtexture_t* tex, int *width, int *height ){
// Don't use uniform size
- height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
- }
- else if ( tex->height >= tex->width ) {
- // Texture is square, or taller than it is wide
- height = m_uniformTextureSize;
+ *width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
+ *height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
+
+ if ( g_TextureBrowser_fixedSize ){
+ int W = *width;
+ int H = *height;
+ if ( W >= H ) {
+ // Texture is square, or wider than it is tall
+ if ( W >= m_uniformTextureSize ){
+ *width = m_uniformTextureSize;
+ *height = m_uniformTextureSize * H / W;
- }
++ }
+ else if ( W <= m_uniformTextureMinSize ){
+ *width = m_uniformTextureMinSize;
+ *height = m_uniformTextureMinSize * H / W;
+ }
- }
- else {
+ }
+ else {
- // Otherwise, preserve the texture's aspect ratio
- height = (int)( m_uniformTextureSize * ( (float)tex->height / tex->width ) );
+ // Texture taller than it is wide
+ if ( H >= m_uniformTextureSize ){
+ *height = m_uniformTextureSize;
+ *width = m_uniformTextureSize * W / H;
- }
++ }
+ else if ( H <= m_uniformTextureMinSize ){
+ *height = m_uniformTextureMinSize;
+ *width = m_uniformTextureMinSize * W / H;
+ }
+ }
}
- return height;
}
TextureBrowser() :
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 );
+ if ( archive != nullptr )
+ {
- LoadShaderVisitor visitor;
- archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
+ LoadShaderVisitor visitor;
+ archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
+
+ // Doom3-like dds/ prefix (used by DarkPlaces).
+ archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "dds/textures/" );
+ }
+ else if ( extension_equal_i( path_get_extension( directory ), "wad" ) )
+ {
+ globalErrorStream() << "Failed to load " << directory << "\n";
+ }
}
else
{
void TextureBrowser_destroyWindow(){
GlobalShaderSystem().setActiveShadersChangedNotify( Callback<void()>() );
- g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_sizeHandler );
- g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_exposeHandler );
+ TextureBrowser_destroyGLWidget();
+}
+
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+/* workaround for gtkglext on gtk 2 issue: OpenGL texture viewport being drawn over the other pages */
+/* this is very ugly: force the resizing of the viewport to a single bottom line by forcing the
+ * resizing of the gl widget by expanding some empty boxes, so the widget area size is reduced
+ * while covered by another page, so the texture viewport is still rendered over the other page
+ * but does not annoy the user that much because it's just a line on the bottom that may even
+ * be printed over existing bottom frame or very close to it. */
+void TextureBrowser_showGLWidget(){
+ TextureBrowser &textureBrowser = GlobalTextureBrowser();
+ if ( isWindowConstructed && isGLWidgetConstructed )
+ {
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_vfiller, FALSE, FALSE, 0, ui::Packing::START );
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hframe, TRUE, TRUE, 0, ui::Packing::START );
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hfiller, FALSE, FALSE, 0, ui::Packing::START );
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_gl_widget, TRUE, TRUE, 0, ui::Packing::START );
+
+ textureBrowser.m_gl_widget.show();
- }
++}
+}
+
+void TextureBrowser_hideGLWidget(){
+ TextureBrowser &textureBrowser = GlobalTextureBrowser();
+ if ( isWindowConstructed && isGLWidgetConstructed )
+ {
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_vfiller, TRUE, TRUE, 0, ui::Packing::START);
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hframe, FALSE, FALSE, 0, ui::Packing::END );
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hfiller, TRUE, TRUE, 0, ui::Packing::START);
+ textureBrowser.m_vframe.set_child_packing( textureBrowser.m_gl_widget, FALSE, FALSE, 0, ui::Packing::END );
+
+ // The hack needs the GL widget to not be hidden to work,
+ // so resizing it triggers the redraw of it with the new size.
+ // GlobalTextureBrowser().m_gl_widget.hide();
- g_TextureBrowser.m_gl_widget.unref();
+ // Trigger the redraw.
+ TextureBrowser_redraw( &GlobalTextureBrowser() );
+ ui::process();
+ }
}
+#endif // WORKAROUND_MACOS_GTK2_GLWIDGET
const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){
return textureBrowser.color_textureback;
}
};
- returnz(g_TextureBrowser.m_uniformTextureMinSize);
+ struct UniformTextureMinSize {
+ static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
++ returnz(GlobalTextureBrowser().m_uniformTextureMinSize);
+ }
+
+ static void Import(TextureBrowser &self, int value) {
+ if (value > 16)
+ TextureBrowser_setUniformSize(self, value);
+ }
+ };
+
void TextureBrowser_constructPreferences( PreferencesPage& page ){
page.appendCheckBox(
"", "Texture scrollbar",
make_property<TextureScale>(GlobalTextureBrowser())
);
}
- page.appendSpinner(
- "Texture Thumbnail Size",
- GlobalTextureBrowser().m_uniformTextureSize,
- GlobalTextureBrowser().m_uniformTextureSize,
- 16, 8192
- );
+ page.appendSpinner( "Thumbnails Max Size", GlobalTextureBrowser().m_uniformTextureSize, GlobalTextureBrowser().m_uniformTextureSize, 16, 8192 );
+ page.appendSpinner( "Thumbnails Min Size", GlobalTextureBrowser().m_uniformTextureMinSize, GlobalTextureBrowser().m_uniformTextureMinSize, 16, 8192 );
page.appendEntry( "Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement );
{
- const char* startup_shaders[] = { "None", TextureBrowser_getComonShadersName() };
+ const char* startup_shaders[] = { "None", TextureBrowser_getCommonShadersName() };
page.appendCombo( "Load Shaders at Startup", reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ), STRING_ARRAY_RANGE( startup_shaders ) );
}
}
GlobalCommands_insert( "CopyTag", makeCallbackF(TextureBrowser_copyTag) );
GlobalCommands_insert( "PasteTag", makeCallbackF(TextureBrowser_pasteTag) );
GlobalCommands_insert( "RefreshShaders", makeCallbackF(VFS_Refresh) );
- GlobalToggles_insert( "ShowInUse", makeCallbackF(TextureBrowser_ToggleHideUnused), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hideunused_item ), Accelerator( 'U' ) );
+ GlobalToggles_insert( "ShowInUse", makeCallbackF(TextureBrowser_ToggleHideUnused), ToggleItem::AddCallbackCaller( textureBrowser.m_hideunused_item ), Accelerator( 'U' ) );
GlobalCommands_insert( "ShowAllTextures", makeCallbackF(TextureBrowser_showAll), Accelerator( 'A', (GdkModifierType)GDK_CONTROL_MASK ) );
GlobalCommands_insert( "ToggleTextures", makeCallbackF(TextureBrowser_toggleShow), Accelerator( 'T' ) );
- GlobalToggles_insert( "ToggleShowShaders", makeCallbackF(TextureBrowser_ToggleShowShaders), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaders_item ) );
- GlobalToggles_insert( "ToggleShowShaderlistOnly", makeCallbackF(TextureBrowser_ToggleShowShaderListOnly), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaderlistonly_item ) );
- GlobalToggles_insert( "FixedSize", makeCallbackF(TextureBrowser_FixedSize), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_fixedsize_item ) );
- GlobalToggles_insert( "FilterMissing", makeCallbackF(TextureBrowser_FilterMissing), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_filternotex_item ) );
- GlobalToggles_insert( "FilterFallback", makeCallbackF(TextureBrowser_FilterFallback), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hidenotex_item ) );
- GlobalToggles_insert( "EnableAlpha", makeCallbackF(TextureBrowser_EnableAlpha), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_enablealpha_item ) );
-
- GlobalPreferenceSystem().registerPreference( "TextureScale", make_property_string<TextureScale>(g_TextureBrowser) );
- GlobalPreferenceSystem().registerPreference( "UniformTextureSize", make_property_string<UniformTextureSize>(g_TextureBrowser) );
- GlobalPreferenceSystem().registerPreference( "UniformTextureMinSize", make_property_string<UniformTextureMinSize>(g_TextureBrowser) );
- GlobalPreferenceSystem().registerPreference( "TextureScrollbar", make_property_string<TextureBrowser_ShowScrollbar>(GlobalTextureBrowser()));
- GlobalPreferenceSystem().registerPreference( "ShowShaders", make_property_string( GlobalTextureBrowser().m_showShaders ) );
+ GlobalToggles_insert( "ToggleShowShaders", makeCallbackF(TextureBrowser_ToggleShowShaders), ToggleItem::AddCallbackCaller( textureBrowser.m_showshaders_item ) );
+ GlobalToggles_insert( "ToggleShowShaderlistOnly", makeCallbackF(TextureBrowser_ToggleShowShaderListOnly), ToggleItem::AddCallbackCaller( textureBrowser.m_showshaderlistonly_item ) );
+ GlobalToggles_insert( "FixedSize", makeCallbackF(TextureBrowser_FixedSize), ToggleItem::AddCallbackCaller( textureBrowser.m_fixedsize_item ) );
+ GlobalToggles_insert( "FilterMissing", makeCallbackF(TextureBrowser_FilterMissing), ToggleItem::AddCallbackCaller( textureBrowser.m_filternotex_item ) );
+ GlobalToggles_insert( "FilterFallback", makeCallbackF(TextureBrowser_FilterFallback), ToggleItem::AddCallbackCaller( textureBrowser.m_hidenotex_item ) );
+ GlobalToggles_insert( "EnableAlpha", makeCallbackF(TextureBrowser_EnableAlpha), ToggleItem::AddCallbackCaller( textureBrowser.m_enablealpha_item ) );
+
+ GlobalPreferenceSystem().registerPreference( "TextureScale", make_property_string<TextureScale>(textureBrowser) );
+ GlobalPreferenceSystem().registerPreference( "UniformTextureSize", make_property_string<UniformTextureSize>(textureBrowser) );
++ GlobalPreferenceSystem().registerPreference( "UniformTextureMinSize", make_property_string<UniformTextureMinSize>(textureBrowser) );
+ GlobalPreferenceSystem().registerPreference( "TextureScrollbar", make_property_string<TextureBrowser_ShowScrollbar>(textureBrowser));
+ GlobalPreferenceSystem().registerPreference( "ShowShaders", make_property_string( textureBrowser.m_showShaders ) );
GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", make_property_string( g_TextureBrowser_shaderlistOnly ) );
GlobalPreferenceSystem().registerPreference( "FixedSize", make_property_string( g_TextureBrowser_fixedSize ) );
GlobalPreferenceSystem().registerPreference( "FilterMissing", make_property_string( g_TextureBrowser_filterMissing ) );