#include "multimon.h"
#include "console.h"
#include "commands.h"
-
-
#include "gtkutil/window.h"
+#if defined(WORKAROUND_WINDOWS_GTK2_GLWIDGET) || defined(WORKAROUND_MACOS_GTK2_GLWIDGET)
+#include "texwindow.h"
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET || WORKAROUND_MACOS_GTK2_GLWIDGET
+
class GroupDlg
{
public:
std::vector<Callback<void(const Callback<void(const char *)> &)>> g_pages;
}
+static void workaround_macos_show_hide(){
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+ if ( g_current_page == 2 )
+ {
+ TextureBrowser_showGLWidget();
+ }
+ else
+ {
+ TextureBrowser_hideGLWidget();
+ }
+#endif // WORKAROUND_MACOS_GTK2_GLWIDGET
+}
+
void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){
if ( pageIndex < g_pages.size() ) {
g_pages[pageIndex]( PointerCaller<GtkWindow, void(const char*), gtk_window_set_title>( window ) );
}
+
+ workaround_macos_show_hide();
}
static gboolean switch_page( GtkNotebook *notebook, gpointer page, guint page_num, gpointer data ){
- GroupDialog_updatePageTitle( ui::Window::from(data), page_num );
g_current_page = page_num;
-
+ GroupDialog_updatePageTitle( ui::Window::from(data), page_num );
return FALSE;
}
}
}
-
ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback<void(const Callback<void(const char *)> &)>& title ){
ui::Widget w = ui::Label( tabLabel );
w.show();
return page;
}
-
bool GroupDialog_isShown(){
return g_GroupDlg.m_window.visible();
}
g_GroupDlg.m_window = ui::Window{ui::null};
}
-
ui::Window GroupDialog_getWindow(){
return ui::Window(g_GroupDlg.m_window);
}
}
ui::Widget GroupDialog_getPage(){
- return ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ));
+ return ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ) );
}
void GroupDialog_setPage( ui::Widget page ){
g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
+
+ workaround_macos_show_hide();
}
#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
void GroupDialog_showPage( ui::Widget page ){
+
if ( GroupDialog_getPage() == page ) {
GroupDialog_ToggleShow();
g_GroupDlg.m_window.show();
GroupDialog_setPage( page );
}
+
+ workaround_macos_show_hide();
}
void GroupDialog_cycle(){
}
}
-
#include "preferencesystem.h"
void GroupDialog_Construct(){
CopiedString shader;
ui::Window m_parent{ui::null};
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+ui::VBox m_vframe{ui::null};
+ui::VBox m_vfiller{ui::null};
+ui::HBox m_hframe{ui::null};
+ui::HBox m_hfiller{ui::null};
+#else // !WORKAROUND_MACOS_GTK2_GLWIDGET
+ui::VBox m_frame{ui::null};
+#endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
ui::GLArea m_gl_widget{ui::null};
ui::Widget m_texture_scroll{ui::null};
ui::TreeView m_treeViewTree{ui::New};
textureBrowser.color_textureback[1],
textureBrowser.color_textureback[2],
0 );
+
glViewport( 0, 0, textureBrowser.width, textureBrowser.height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
return FALSE;
}
-
TextureBrowser g_TextureBrowser;
TextureBrowser& GlobalTextureBrowser(){
IShader* shadernotex = QERApp_Shader_ForName( DEFAULT_SHADERNOTEX_NAME );
g_notex = notex->getTexture()->name;
+
g_shadernotex = shadernotex->getTexture()->name;
notex->DecRef();
shadernotex->DecRef();
}
+static bool isGLWidgetConstructed = false;
+static bool isWindowConstructed = false;
+
+void TextureBrowser_constructGLWidget(){
+ g_TextureBrowser.m_gl_widget = glwidget_new( FALSE );
+ g_object_ref( g_TextureBrowser.m_gl_widget._handle );
+
+ gtk_widget_set_events( g_TextureBrowser.m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK );
+ gtk_widget_set_can_focus( g_TextureBrowser.m_gl_widget, true );
+
+ g_TextureBrowser.m_sizeHandler = g_TextureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &g_TextureBrowser );
+ g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
+
+ g_TextureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &g_TextureBrowser );
+ g_TextureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &g_TextureBrowser );
+ g_TextureBrowser.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( TextureBrowser_motion ), &g_TextureBrowser );
+ g_TextureBrowser.m_gl_widget.connect( "scroll_event", G_CALLBACK( TextureBrowser_scroll ), &g_TextureBrowser );
+
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+ g_TextureBrowser.m_hframe.pack_start( g_TextureBrowser.m_gl_widget, TRUE, TRUE, 0 );
+#else // !WORKAROUND_MACOS_GTK2_GLWIDGET
+ g_TextureBrowser.m_frame.pack_start( g_TextureBrowser.m_gl_widget, TRUE, TRUE, 0 );
+#endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
+
+ g_TextureBrowser.m_gl_widget.show();
+
+ isGLWidgetConstructed = true;
+}
+
ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
// The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
// position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
g_TextureBrowser.m_texture_scroll.visible(g_TextureBrowser.m_showTextureScrollbar);
}
{ // gl_widget
- g_TextureBrowser.m_gl_widget = glwidget_new( FALSE );
- g_object_ref( g_TextureBrowser.m_gl_widget._handle );
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+ g_TextureBrowser.m_vframe = ui::VBox( FALSE, 0 );
+ table.attach(g_TextureBrowser.m_vframe, {1, 2, 1, 2});
+
+ g_TextureBrowser.m_vfiller = ui::VBox( FALSE, 0 );
+ g_TextureBrowser.m_vframe.pack_start( g_TextureBrowser.m_vfiller, FALSE, FALSE, 0 );
- gtk_widget_set_events( g_TextureBrowser.m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK );
- gtk_widget_set_can_focus( g_TextureBrowser.m_gl_widget, true );
+ g_TextureBrowser.m_hframe = ui::HBox( FALSE, 0 );
+ g_TextureBrowser.m_vframe.pack_start( g_TextureBrowser.m_hframe, TRUE, TRUE, 0 );
- table.attach(g_TextureBrowser.m_gl_widget, {1, 2, 1, 2});
- g_TextureBrowser.m_gl_widget.show();
+ g_TextureBrowser.m_hfiller = ui::HBox( FALSE, 0 );
+ g_TextureBrowser.m_hframe.pack_start( g_TextureBrowser.m_hfiller, FALSE, FALSE, 0 );
- g_TextureBrowser.m_sizeHandler = g_TextureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &g_TextureBrowser );
- g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
+ g_TextureBrowser.m_vframe.show();
+ g_TextureBrowser.m_vfiller.show();
+ g_TextureBrowser.m_hframe.show(),
+ g_TextureBrowser.m_hfiller.show();
+#else // !WORKAROUND_MACOS_GTK2_GLWIDGET
+ g_TextureBrowser.m_frame = ui::VBox( FALSE, 0 );
+ table.attach(g_TextureBrowser.m_frame, {1, 2, 1, 2});
+ g_TextureBrowser.m_frame.show();
+#endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
- g_TextureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &g_TextureBrowser );
- g_TextureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &g_TextureBrowser );
- g_TextureBrowser.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( TextureBrowser_motion ), &g_TextureBrowser );
- g_TextureBrowser.m_gl_widget.connect( "scroll_event", G_CALLBACK( TextureBrowser_scroll ), &g_TextureBrowser );
+ TextureBrowser_constructGLWidget();
}
// tag stuff
// TODO do we need this?
//gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
+ isWindowConstructed = true;
+
return table;
}
+void TextureBrowser_destroyGLWidget(){
+ if ( isGLWidgetConstructed )
+ {
+ 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 );
+
+#ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
+ g_TextureBrowser.m_hframe.remove( g_TextureBrowser.m_gl_widget );
+#else // !WORKAROUND_MACOS_GTK2_GLWIDGET
+ g_TextureBrowser.m_frame.remove( g_TextureBrowser.m_gl_widget );
+#endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
+
+ g_TextureBrowser.m_gl_widget.unref();
+
+ isGLWidgetConstructed = false;
+ }
+}
+
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();
+}
- g_TextureBrowser.m_gl_widget.unref();
+#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(){
+ if ( isWindowConstructed && isGLWidgetConstructed )
+ {
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_vfiller, FALSE, FALSE, 0, ui::Packing::START );
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_hframe, TRUE, TRUE, 0, ui::Packing::START );
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_hfiller, FALSE, FALSE, 0, ui::Packing::START );
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_gl_widget, TRUE, TRUE, 0, ui::Packing::START );
+ GlobalTextureBrowser().m_gl_widget.show();
+ }
+}
+
+void TextureBrowser_hideGLWidget(){
+ if ( isWindowConstructed && isGLWidgetConstructed )
+ {
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_vfiller, TRUE, TRUE, 0, ui::Packing::START);
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_hframe, FALSE, FALSE, 0, ui::Packing::END );
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_hfiller, TRUE, TRUE, 0, ui::Packing::START);
+ GlobalTextureBrowser().m_vframe.set_child_packing( GlobalTextureBrowser().m_gl_widget, FALSE, FALSE, 0, ui::Packing::END );
+ GdkEventExpose event = {};
+ TextureBrowser_expose( GlobalTextureBrowser().m_gl_widget, &event, &GlobalTextureBrowser() );
+ }
}
+#endif // WORKAROUND_MACOS_GTK2_GLWIDGET
const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){
return textureBrowser.color_textureback;