From 86023af46cb7b0057fd3c9dae743660b2968e255 Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 1 Aug 2017 14:06:41 +0300 Subject: [PATCH] Radiant: misc... * local gtk2 themes support; cfgs are .gtkrc-2.0.radiant, .gtkrc-2.0.win; +~100 themes included; MS-Windows theme is one, inheriting current appearence on Windows * GTK2 theme & font selector (Misc->Colors->Gtk theme...) (need restart after pair of naughty engines tho) * openGL implementaion of rubberband selector (w/o rerendering whole scene) (fixes visual issues with Aero) --- Makefile | 1 + libs/gtkutil/xorrectangle.h | 90 +++-- radiant/gtktheme.cpp | 754 ++++++++++++++++++++++++++++++++++++ radiant/gtktheme.h | 14 + radiant/main.cpp | 17 + radiant/mainframe.cpp | 4 + radiant/texwindow.cpp | 6 +- radiant/xywindow.cpp | 11 +- 8 files changed, 859 insertions(+), 38 deletions(-) create mode 100644 radiant/gtktheme.cpp create mode 100644 radiant/gtktheme.h diff --git a/Makefile b/Makefile index b7521e0a..457f459a 100644 --- a/Makefile +++ b/Makefile @@ -654,6 +654,7 @@ $(INSTALLDIR)/radiant.$(EXE): \ radiant/groupdialog.o \ radiant/gtkdlgs.o \ radiant/gtkmisc.o \ + radiant/gtktheme.o \ radiant/help.o \ radiant/image.o \ radiant/mainframe.o \ diff --git a/libs/gtkutil/xorrectangle.h b/libs/gtkutil/xorrectangle.h index 6c4d64fc..73f1387f 100644 --- a/libs/gtkutil/xorrectangle.h +++ b/libs/gtkutil/xorrectangle.h @@ -25,6 +25,15 @@ #include #include "math/vector.h" + +#include "gtkutil/glwidget.h" +#include "igl.h" + +#include + +//#include "stream/stringstream.h" + + class rectangle_t { public: @@ -60,51 +69,62 @@ inline rectangle_t rectangle_from_area( const float min[2], const float max[2], class XORRectangle { - rectangle_t m_rectangle; - GtkWidget* m_widget; -GdkGC* m_gc; - -bool initialised() const { - return m_gc != 0; -} -void lazy_init(){ - if ( !initialised() ) { - m_gc = gdk_gc_new( m_widget->window ); - - GdkColor color = { 0, 0xffff, 0xffff, 0xffff, }; - GdkColormap* colormap = gdk_window_get_colormap( m_widget->window ); - gdk_colormap_alloc_color( colormap, &color, FALSE, TRUE ); - gdk_gc_copy( m_gc, m_widget->style->white_gc ); - gdk_gc_set_foreground( m_gc, &color ); - gdk_gc_set_background( m_gc, &color ); - - gdk_gc_set_function( m_gc, GDK_INVERT ); - } -} -void draw() const { - const int x = float_to_integer( m_rectangle.x ); - const int y = float_to_integer( m_rectangle.y ); - const int w = float_to_integer( m_rectangle.w ); - const int h = float_to_integer( m_rectangle.h ); - gdk_draw_rectangle( m_widget->window, m_gc, FALSE, x, -( h ) - ( y - m_widget->allocation.height ), w, h ); -} public: -XORRectangle( GtkWidget* widget ) : m_widget( widget ), m_gc( 0 ){ +XORRectangle( GtkWidget* widget ) : m_widget( widget ){ } ~XORRectangle(){ - if ( initialised() ) { - gdk_gc_unref( m_gc ); - } } void set( rectangle_t rectangle ){ if ( GTK_WIDGET_REALIZED( m_widget ) ) { - lazy_init(); - draw(); + if( m_rectangle.w != rectangle.w || m_rectangle.h != rectangle.h ){ + //if( !(m_rectangle.w == 0 && m_rectangle.h == 0 && rectangle.w == 0 && rectangle.h == 0) ){ + //globalOutputStream() << "m_x" << m_rectangle.x << " m_y" << m_rectangle.y << " m_w" << m_rectangle.w << " m_h" << m_rectangle.h << "\n"; + //globalOutputStream() << "__x" << rectangle.x << " __y" << rectangle.y << " __w" << rectangle.w << " __h" << rectangle.h << "\n"; + if ( glwidget_make_current( m_widget ) != FALSE ) { + GlobalOpenGL_debugAssertNoErrors(); + + gint width, height; + gdk_gl_drawable_get_size( gtk_widget_get_gl_drawable( m_widget ), &width, &height ); + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0, width, 0, height, -100, 100 ); + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + glDisable( GL_DEPTH_TEST ); + + glDrawBuffer( GL_FRONT ); + + glEnable( GL_BLEND ); + glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO ); + + glLineWidth( 2 ); + glColor3f( 1, 1, 1 ); + glDisable( GL_TEXTURE_2D ); + glBegin( GL_LINE_LOOP ); + glVertex2f( m_rectangle.x, m_rectangle.y + m_rectangle.h ); + glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y + m_rectangle.h ); + glVertex2f( m_rectangle.x + m_rectangle.w, m_rectangle.y ); + glVertex2f( m_rectangle.x, m_rectangle.y ); + glEnd(); + + glBegin( GL_LINE_LOOP ); + glVertex2f( rectangle.x, rectangle.y + rectangle.h ); + glVertex2f( rectangle.x + rectangle.w, rectangle.y + rectangle.h ); + glVertex2f( rectangle.x + rectangle.w, rectangle.y ); + glVertex2f( rectangle.x, rectangle.y ); + glEnd(); + + glDrawBuffer( GL_BACK ); + GlobalOpenGL_debugAssertNoErrors(); + //glwidget_swap_buffers( m_widget ); + glwidget_make_current( m_widget ); + } + } m_rectangle = rectangle; - draw(); } } }; diff --git a/radiant/gtktheme.cpp b/radiant/gtktheme.cpp new file mode 100644 index 00000000..0f3604a8 --- /dev/null +++ b/radiant/gtktheme.cpp @@ -0,0 +1,754 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Wed Jan 1 19:06:46 GMT+4 2003 + copyright : (C) 2003 - 2005 by Alex Shaduri + email : ashaduri '@' gmail.com + ***************************************************************************/ + + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include +#else +#include +#endif + +#include + + +#include +#include +#include +#include + + +#include "gtktheme.h" +#include "mainframe.h" +//#include "gtkutil/window.h" + +// ------------------------------------------------------ + + +std::string& get_orig_theme(); +std::string& get_orig_font(); + +std::string get_current_theme(); +std::string get_current_font(); + +std::string get_selected_theme(); +std::string get_selected_font(); + +void set_theme(const std::string& theme_name, const std::string& font); +void apply_theme(const std::string& theme_name, const std::string& font); + + + +GtkWidget* g_main_rc_window = NULL; + + +static std::string s_rc_file; + + + +// ------------------------------------------------------ + + + +GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name){ + GtkWidget *parent, *found_widget; + + for (;;) + { + if (GTK_IS_MENU (widget)) + parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); + else + parent = widget->parent; + if (!parent) + parent = (GtkWidget*)g_object_get_data (G_OBJECT (widget), "GladeParentKey"); + if (parent == NULL) + break; + widget = parent; + } + + found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget), + widget_name); + if (!found_widget) + g_warning ("Widget not found: %s", widget_name); + return found_widget; +} + + + + + + +void on_main_cancel_button_clicked( GtkButton *button, gpointer user_data ){ + set_theme( get_orig_theme(), get_orig_font() ); + gtk_widget_destroy( g_main_rc_window ); + g_main_rc_window = NULL; +} + + +void on_main_reset_button_clicked( GtkButton *button, gpointer user_data ){ + set_theme( get_orig_theme(), get_orig_font() ); +} + + +gboolean on_main_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data ){ + set_theme( get_orig_theme(), get_orig_font() ); + gtk_widget_destroy( g_main_rc_window ); + g_main_rc_window = NULL; + return TRUE; +} + + +void on_main_use_default_font_radio_toggled ( GtkToggleButton *togglebutton, gpointer user_data ){ + bool default_font = gtk_toggle_button_get_active( togglebutton ); + + gtk_widget_set_sensitive( lookup_widget( g_main_rc_window, "main_font_selector_button" ), !default_font ); + + apply_theme( get_selected_theme(), get_selected_font() ); +} + + +void on_main_font_selector_button_font_set( GtkFontButton *fontbutton, gpointer user_data ){ + apply_theme( get_selected_theme(), get_selected_font() ); +} + +void on_main_ok_button_clicked( GtkButton *button, gpointer user_data ){ + gtk_widget_destroy( g_main_rc_window ); + g_main_rc_window = NULL; +} + + + +#define GLADE_HOOKUP_OBJECT(component,widget,name) \ + g_object_set_data_full (G_OBJECT (component), name, \ + gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) + +#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ + g_object_set_data (G_OBJECT (component), name, widget) + +GtkWidget* +create_rc_window (void) +{ + GtkWidget *main_window; + GtkWidget *main_hbox; + GtkWidget *vbox1; + GtkWidget *hbox1; + GtkWidget *frame2; + GtkWidget *alignment3; + GtkWidget *scrolledwindow3; + GtkWidget *main_themelist; + GtkWidget *label1234; + GtkWidget *frame3; + GtkWidget *alignment4; + GtkWidget *vbox7; + GtkWidget *hbox8; + GtkWidget *vbox9; + GtkWidget *main_use_default_font_radio; + GSList *main_use_default_font_radio_group = NULL; + GtkWidget *main_use_custom_font_radio; + GtkWidget *alignment5; + GtkWidget *vbox10; + GtkWidget *hbox9; + GtkWidget *vbox11; + GtkWidget *main_font_selector_button; + GtkWidget *label669; + GtkWidget *vbox13; + GtkWidget *hbuttonbox1; + GtkWidget *hbox7; + GtkWidget *vbox6; + GtkWidget *hbox5; + GtkWidget *main_ok_button; + GtkWidget *main_cancel_button; + GtkWidget *main_reset_button; + GtkWidget *alignment2; + GtkWidget *hbox6; + GtkWidget *image1; + GtkWidget *label667; + GtkAccelGroup *accel_group; + GtkTooltips *tooltips; + + tooltips = gtk_tooltips_new (); + + accel_group = gtk_accel_group_new (); + + main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_set_name (main_window, "main_window"); + gtk_window_set_title (GTK_WINDOW (main_window), "Gtk2 Theme Selector"); + gtk_window_set_transient_for( GTK_WINDOW (main_window), MainFrame_getWindow() ); + gtk_window_set_destroy_with_parent( GTK_WINDOW (main_window), TRUE ); + + //gtk_window_set_keep_above ( GTK_WINDOW( main_window ), TRUE ); + + main_hbox = gtk_hbox_new (FALSE, 0); + gtk_widget_set_name (main_hbox, "main_hbox"); + gtk_widget_show (main_hbox); + gtk_container_add (GTK_CONTAINER (main_window), main_hbox); + gtk_widget_set_size_request (main_hbox, 310, 320); + gtk_window_resize(GTK_WINDOW(main_window), 310, 640); + + vbox1 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox1, "vbox1"); + gtk_widget_show (vbox1); + gtk_box_pack_start (GTK_BOX (main_hbox), vbox1, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (vbox1), 3); + + hbox1 = gtk_hbox_new (FALSE, 0); + gtk_widget_set_name (hbox1, "hbox1"); + gtk_widget_show (hbox1); + gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0); + + frame2 = gtk_frame_new (NULL); + gtk_widget_set_name (frame2, "frame2"); + gtk_widget_show (frame2); + gtk_box_pack_start (GTK_BOX (hbox1), frame2, TRUE, TRUE, 0); + gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_NONE); + + alignment3 = gtk_alignment_new (0.5, 0.5, 1, 1); + gtk_widget_set_name (alignment3, "alignment3"); + gtk_widget_show (alignment3); + gtk_container_add (GTK_CONTAINER (frame2), alignment3); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment3), 0, 0, 12, 0); + + scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL); + gtk_widget_set_name (scrolledwindow3, "scrolledwindow3"); + gtk_widget_show (scrolledwindow3); + gtk_container_add (GTK_CONTAINER (alignment3), scrolledwindow3); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_SHADOW_IN); + + main_themelist = gtk_tree_view_new (); + gtk_widget_set_name (main_themelist, "main_themelist"); + gtk_widget_show (main_themelist); + gtk_container_add (GTK_CONTAINER (scrolledwindow3), main_themelist); + GTK_WIDGET_SET_FLAGS (main_themelist, GTK_CAN_DEFAULT); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (main_themelist), FALSE); + + label1234 = gtk_label_new ("Theme"); + gtk_widget_set_name (label1234, "label1234"); + gtk_widget_show (label1234); + gtk_frame_set_label_widget (GTK_FRAME (frame2), label1234); + gtk_label_set_use_markup (GTK_LABEL (label1234), TRUE); + + frame3 = gtk_frame_new (NULL); + gtk_widget_set_name (frame3, "frame3"); + gtk_widget_show (frame3); + gtk_box_pack_start (GTK_BOX (vbox1), frame3, FALSE, FALSE, 9); + gtk_frame_set_shadow_type (GTK_FRAME (frame3), GTK_SHADOW_NONE); + + alignment4 = gtk_alignment_new (0.5, 0.5, 1, 1); + gtk_widget_set_name (alignment4, "alignment4"); + gtk_widget_show (alignment4); + gtk_container_add (GTK_CONTAINER (frame3), alignment4); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment4), 0, 0, 12, 0); + + vbox7 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox7, "vbox7"); + gtk_widget_show (vbox7); + gtk_container_add (GTK_CONTAINER (alignment4), vbox7); + + hbox8 = gtk_hbox_new (FALSE, 0); + gtk_widget_set_name (hbox8, "hbox8"); + gtk_widget_show (hbox8); + gtk_box_pack_start (GTK_BOX (vbox7), hbox8, FALSE, FALSE, 0); + + vbox9 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox9, "vbox9"); + gtk_widget_show (vbox9); + gtk_box_pack_start (GTK_BOX (hbox8), vbox9, TRUE, TRUE, 0); + + main_use_default_font_radio = gtk_radio_button_new_with_mnemonic (NULL, "Use theme default font"); + gtk_widget_set_name (main_use_default_font_radio, "main_use_default_font_radio"); + gtk_widget_show (main_use_default_font_radio); + gtk_box_pack_start (GTK_BOX (vbox9), main_use_default_font_radio, FALSE, FALSE, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (main_use_default_font_radio), main_use_default_font_radio_group); + main_use_default_font_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (main_use_default_font_radio)); + + main_use_custom_font_radio = gtk_radio_button_new_with_mnemonic (NULL, "Use custom font:"); + gtk_widget_set_name (main_use_custom_font_radio, "main_use_custom_font_radio"); + gtk_widget_show (main_use_custom_font_radio); + gtk_box_pack_start (GTK_BOX (vbox9), main_use_custom_font_radio, FALSE, FALSE, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (main_use_custom_font_radio), main_use_default_font_radio_group); + main_use_default_font_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (main_use_custom_font_radio)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (main_use_custom_font_radio), TRUE); + //gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (main_use_custom_font_radio), FALSE); + + alignment5 = gtk_alignment_new (0.5, 0.5, 1, 1); + gtk_widget_set_name (alignment5, "alignment5"); + gtk_widget_show (alignment5); + gtk_box_pack_start (GTK_BOX (vbox9), alignment5, TRUE, TRUE, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment5), 0, 0, 12, 0); + + vbox10 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox10, "vbox10"); + gtk_widget_show (vbox10); + gtk_container_add (GTK_CONTAINER (alignment5), vbox10); + + hbox9 = gtk_hbox_new (FALSE, 0); + gtk_widget_set_name (hbox9, "hbox9"); + gtk_widget_show (hbox9); + gtk_box_pack_start (GTK_BOX (vbox10), hbox9, FALSE, FALSE, 0); + + vbox11 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox11, "vbox11"); + gtk_widget_show (vbox11); + gtk_box_pack_start (GTK_BOX (hbox9), vbox11, TRUE, TRUE, 0); + + main_font_selector_button = gtk_font_button_new (); + gtk_widget_set_name (main_font_selector_button, "main_font_selector_button"); + gtk_widget_show (main_font_selector_button); + gtk_box_pack_start (GTK_BOX (vbox11), main_font_selector_button, FALSE, FALSE, 0); + + label669 = gtk_label_new ("Font"); + gtk_widget_set_name (label669, "label669"); + gtk_widget_show (label669); + gtk_frame_set_label_widget (GTK_FRAME (frame3), label669); + gtk_label_set_use_markup (GTK_LABEL (label669), TRUE); + + vbox13 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox13, "vbox13"); + gtk_widget_show (vbox13); + gtk_box_pack_start (GTK_BOX (vbox1), vbox13, FALSE, FALSE, 0); + + hbuttonbox1 = gtk_hbutton_box_new (); + gtk_widget_set_name (hbuttonbox1, "hbuttonbox1"); + gtk_widget_show (hbuttonbox1); + gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, FALSE, 0); + + hbox7 = gtk_hbox_new (FALSE, 0); + gtk_widget_set_name (hbox7, "hbox7"); + gtk_widget_show (hbox7); + gtk_box_pack_start (GTK_BOX (vbox1), hbox7, FALSE, TRUE, 6); + + vbox6 = gtk_vbox_new (FALSE, 0); + gtk_widget_set_name (vbox6, "vbox6"); + gtk_widget_show (vbox6); + gtk_box_pack_start (GTK_BOX (vbox1), vbox6, FALSE, FALSE, 0); + + hbox5 = gtk_hbox_new (TRUE, 0); + gtk_widget_set_name (hbox5, "hbox5"); + gtk_widget_show (hbox5); + gtk_box_pack_start (GTK_BOX (vbox6), hbox5, FALSE, FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (hbox5), 4); + + main_ok_button = gtk_button_new_from_stock ("gtk-ok"); + gtk_widget_set_name (main_ok_button, "main_ok_button"); + gtk_widget_show (main_ok_button); + gtk_box_pack_end (GTK_BOX (hbox5), main_ok_button, TRUE, TRUE, 4); + GTK_WIDGET_SET_FLAGS (main_ok_button, GTK_CAN_DEFAULT); + + main_cancel_button = gtk_button_new_from_stock ("gtk-cancel"); + gtk_widget_set_name (main_cancel_button, "main_cancel_button"); + gtk_widget_show (main_cancel_button); + gtk_box_pack_end (GTK_BOX (hbox5), main_cancel_button, TRUE, TRUE, 4); + GTK_WIDGET_SET_FLAGS (main_cancel_button, GTK_CAN_DEFAULT); + + main_reset_button = gtk_button_new (); + gtk_widget_set_name (main_reset_button, "main_reset_button"); + gtk_widget_show (main_reset_button); + gtk_box_pack_end (GTK_BOX (hbox5), main_reset_button, TRUE, TRUE, 4); + + alignment2 = gtk_alignment_new (0.5, 0.5, 0, 0); + gtk_widget_set_name (alignment2, "alignment2"); + gtk_widget_show (alignment2); + gtk_container_add (GTK_CONTAINER (main_reset_button), alignment2); + + hbox6 = gtk_hbox_new (FALSE, 2); + gtk_widget_set_name (hbox6, "hbox6"); + gtk_widget_show (hbox6); + gtk_container_add (GTK_CONTAINER (alignment2), hbox6); + + image1 = gtk_image_new_from_stock ("gtk-revert-to-saved", GTK_ICON_SIZE_BUTTON); + gtk_widget_set_name (image1, "image1"); + gtk_widget_show (image1); + gtk_box_pack_start (GTK_BOX (hbox6), image1, FALSE, FALSE, 0); + + label667 = gtk_label_new_with_mnemonic ("_Reset"); + gtk_widget_set_name (label667, "label667"); + gtk_widget_show (label667); + gtk_box_pack_start (GTK_BOX (hbox6), label667, FALSE, FALSE, 0); + + + g_signal_connect ((gpointer) main_window, "delete_event", + G_CALLBACK (on_main_window_delete_event), + NULL); + g_signal_connect ((gpointer) main_use_default_font_radio, "toggled", + G_CALLBACK (on_main_use_default_font_radio_toggled), + NULL); + g_signal_connect ((gpointer) main_font_selector_button, "font_set", + G_CALLBACK (on_main_font_selector_button_font_set), + NULL); + g_signal_connect ((gpointer) main_cancel_button, "clicked", + G_CALLBACK (on_main_cancel_button_clicked), + NULL); + g_signal_connect ((gpointer) main_reset_button, "clicked", + G_CALLBACK (on_main_reset_button_clicked), + NULL); + g_signal_connect ((gpointer) main_ok_button, "clicked", + G_CALLBACK (on_main_ok_button_clicked), + NULL); + + /* Store pointers to all widgets, for use by lookup_widget(). */ + GLADE_HOOKUP_OBJECT_NO_REF (main_window, main_window, "main_window"); + GLADE_HOOKUP_OBJECT (main_window, main_hbox, "main_hbox"); + GLADE_HOOKUP_OBJECT (main_window, vbox1, "vbox1"); + GLADE_HOOKUP_OBJECT (main_window, hbox1, "hbox1"); + GLADE_HOOKUP_OBJECT (main_window, frame2, "frame2"); + GLADE_HOOKUP_OBJECT (main_window, alignment3, "alignment3"); + GLADE_HOOKUP_OBJECT (main_window, scrolledwindow3, "scrolledwindow3"); + GLADE_HOOKUP_OBJECT (main_window, main_themelist, "main_themelist"); + GLADE_HOOKUP_OBJECT (main_window, label1234, "label1234"); + GLADE_HOOKUP_OBJECT (main_window, frame3, "frame3"); + GLADE_HOOKUP_OBJECT (main_window, alignment4, "alignment4"); + GLADE_HOOKUP_OBJECT (main_window, vbox7, "vbox7"); + GLADE_HOOKUP_OBJECT (main_window, hbox8, "hbox8"); + GLADE_HOOKUP_OBJECT (main_window, vbox9, "vbox9"); + GLADE_HOOKUP_OBJECT (main_window, main_use_default_font_radio, "main_use_default_font_radio"); + GLADE_HOOKUP_OBJECT (main_window, main_use_custom_font_radio, "main_use_custom_font_radio"); + GLADE_HOOKUP_OBJECT (main_window, alignment5, "alignment5"); + GLADE_HOOKUP_OBJECT (main_window, vbox10, "vbox10"); + GLADE_HOOKUP_OBJECT (main_window, hbox9, "hbox9"); + GLADE_HOOKUP_OBJECT (main_window, vbox11, "vbox11"); + GLADE_HOOKUP_OBJECT (main_window, main_font_selector_button, "main_font_selector_button"); + GLADE_HOOKUP_OBJECT (main_window, label669, "label669"); + GLADE_HOOKUP_OBJECT (main_window, vbox13, "vbox13"); + GLADE_HOOKUP_OBJECT (main_window, hbuttonbox1, "hbuttonbox1"); + GLADE_HOOKUP_OBJECT (main_window, hbox7, "hbox7"); + GLADE_HOOKUP_OBJECT (main_window, vbox6, "vbox6"); + GLADE_HOOKUP_OBJECT (main_window, hbox5, "hbox5"); + GLADE_HOOKUP_OBJECT (main_window, main_ok_button, "main_ok_button"); + GLADE_HOOKUP_OBJECT (main_window, main_cancel_button, "main_cancel_button"); + GLADE_HOOKUP_OBJECT (main_window, main_reset_button, "main_reset_button"); + GLADE_HOOKUP_OBJECT (main_window, alignment2, "alignment2"); + GLADE_HOOKUP_OBJECT (main_window, hbox6, "hbox6"); + GLADE_HOOKUP_OBJECT (main_window, image1, "image1"); + GLADE_HOOKUP_OBJECT (main_window, label667, "label667"); + + GLADE_HOOKUP_OBJECT_NO_REF (main_window, tooltips, "tooltips"); + + gtk_widget_grab_default (main_themelist); + gtk_window_add_accel_group (GTK_WINDOW (main_window), accel_group); + + return main_window; +} + + + + +static std::string gchar_to_string(gchar* gstr) +{ + std::string str = (gstr ? gstr : ""); + g_free(gstr); + return str; +} + + + +// ------------------------------------------------------ + + +static std::string s_orig_theme; +static std::string s_orig_font; + +std::string& get_orig_theme() +{ + return s_orig_theme; +} + + +std::string& get_orig_font() +{ + return s_orig_font; +} + + +// ------------------------------------------------------ + + +std::string get_current_theme() +{ + + GtkSettings* settings = gtk_settings_get_default(); + gchar* theme; + g_object_get(settings, "gtk-theme-name", &theme, NULL); + + /* dummy check */ + if( !g_ascii_isalnum( theme[0] ) ){ + g_free( theme ); + return ""; + } + return gchar_to_string(theme); +} + + + + +std::string get_current_font() +{ + return gchar_to_string( pango_font_description_to_string( gtk_rc_get_style( g_main_rc_window )->font_desc ) ); +} + + + +// ------------------------------------------------------ + + + +std::string get_selected_theme() +{ + GtkTreeView* treeview = GTK_TREE_VIEW(lookup_widget(g_main_rc_window, "main_themelist")); + GtkTreeModel* model = gtk_tree_view_get_model(treeview); + GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview); + + GtkTreeIter iter; + gtk_tree_selection_get_selected(selection, 0, &iter); + + gchar* theme_name; + gtk_tree_model_get(model, &iter, 0, &theme_name, -1); +// std::cout << theme_name << "\n"; + return gchar_to_string(theme_name); +} + + + +std::string get_selected_font() +{ +// GtkWidget* fontentry = lookup_widget(g_main_rc_window, "main_fontentry"); +// return gtk_entry_get_text(GTK_ENTRY(fontentry)); + + bool default_font = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(g_main_rc_window, "main_use_default_font_radio"))); + + if (default_font) + return ""; + + GtkWidget* fontbutton = lookup_widget(g_main_rc_window, "main_font_selector_button"); + return gtk_font_button_get_font_name(GTK_FONT_BUTTON(fontbutton)); +} + + +// ------------------------------------------------------ + + + +static void themelist_selection_changed_cb(GtkTreeSelection* selection, gpointer data) +{ + if (gtk_tree_selection_get_selected (selection, 0, 0)) + apply_theme(get_selected_theme(), get_current_font()); +} + + + +// ------------------------------------------------------ + + + +static void populate_with_themes(GtkWidget* w) +{ + + std::string search_path = gchar_to_string(gtk_rc_get_theme_dir()); + + if (search_path.size() && search_path[search_path.size() -1] != G_DIR_SEPARATOR) + search_path += G_DIR_SEPARATOR_S; + + GDir* gdir = g_dir_open(search_path.c_str(), 0, NULL); + if (gdir == NULL) + return; + + + char* name; + GList* glist = 0; + + while ( (name = const_cast(g_dir_read_name(gdir))) != NULL ) { + std::string filename = name; + +// if (g_ascii_strup(fname.c_str(), -1) == "Default") +// continue; + + std::string fullname = search_path + filename; + std::string rc = fullname; rc += G_DIR_SEPARATOR_S; rc += "gtk-2.0"; rc += G_DIR_SEPARATOR_S; rc += "gtkrc"; + + bool is_dir = 0; + if (g_file_test(fullname.c_str(), G_FILE_TEST_IS_DIR)) + is_dir = 1; + + if (is_dir && g_file_test(rc.c_str(), G_FILE_TEST_IS_REGULAR)) { + glist = g_list_insert_sorted(glist, g_strdup(filename.c_str()), (GCompareFunc)strcmp); + } + } + + g_dir_close(gdir); + + + + + // ---------------- tree + + + GtkTreeView* treeview = GTK_TREE_VIEW(w); + GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING); + gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store)); + + GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes ( + "Theme", gtk_cell_renderer_text_new(), + "text", 0, + NULL); + gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); + + + GtkTreeIter iter; + + int i =0, curr=0; + while (char* theme = (char*)g_list_nth_data(glist, i)) { + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, 0, theme, -1); + + if (strcmp(theme, get_current_theme().c_str()) == 0) { + curr = i; + } + + ++i; + } + + + GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + + // set the default theme + + // THIS IS IMPORTANT!!! + gtk_widget_grab_focus(w); + + std::stringstream str; + str << curr; + GtkTreePath* selpath = gtk_tree_path_new_from_string (str.str().c_str()); + if (selpath) { + gtk_tree_selection_select_path(selection, selpath); + gtk_tree_view_scroll_to_cell(treeview, selpath, NULL, true, 0.5, 0.0); + gtk_tree_path_free(selpath); + } + + g_signal_connect (G_OBJECT (selection), "changed", + G_CALLBACK (themelist_selection_changed_cb), NULL); + + g_object_unref (G_OBJECT (store)); + + + // ---------------- font + + + GtkWidget* fontbutton = lookup_widget(g_main_rc_window, "main_font_selector_button"); + gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), get_current_font().c_str()); + + +} + + + + +// ------------------------------------------------------ + + + + +void gtkThemeDlg(){ + if( g_main_rc_window ) return; + + s_rc_file = std::string( AppPath_get() ) + G_DIR_SEPARATOR_S + ".gtkrc-2.0.radiant"; + + g_main_rc_window = create_rc_window(); + + populate_with_themes( lookup_widget( g_main_rc_window, "main_themelist" ) ); + + get_orig_theme() = get_current_theme(); + get_orig_font() = get_current_font(); + + gtk_widget_show ( g_main_rc_window ); +} + + + +// ------------------------------- + + + +void set_theme(const std::string& theme_name, const std::string& font) +{ + if( theme_name.empty() ) return; + + // tree + GtkTreeView* treeview = GTK_TREE_VIEW(lookup_widget(g_main_rc_window, "main_themelist")); + GtkTreeModel* model = gtk_tree_view_get_model(treeview); + GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview); + + GtkTreeIter iter; + gtk_tree_model_get_iter_first(model, &iter); + + while(gtk_tree_model_iter_next(model, &iter)) { + + gchar* text; + gtk_tree_model_get (model, &iter, 0, &text, -1); + std::string theme = gchar_to_string(text); + + if (theme_name == theme) { + gtk_tree_selection_select_iter(selection, &iter); + break; + } + + } + + + // font + if (font != "") { + GtkWidget* fontbutton = lookup_widget(g_main_rc_window, "main_font_selector_button"); + //gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), get_current_font().c_str()); + gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), font.c_str()); + } + + + apply_theme(get_selected_theme(), get_selected_font()); + +} + + + + +void apply_theme(const std::string& theme_name, const std::string& font) +{ + + std::stringstream strstr; + strstr << "gtk-theme-name = \"" << theme_name << "\"\n"; + + if (font != "") + strstr << "style \"user-font\"\n{\nfont_name=\"" << font << "\"\n}\nwidget_class \"*\" style \"user-font\""; + + //strstr << "\ngtk-menu-popup-delay = 10"; + +// std::cout << strstr.str() << "\n\n\n"; + std::fstream f; + f.open(s_rc_file.c_str(), std::ios::out); + f << strstr.str(); + f.close(); + + + GtkSettings* settings = gtk_settings_get_default(); + + gtk_rc_reparse_all_for_settings (settings, true); +// gtk_rc_parse_string(strstr.str().c_str()); +// gtk_rc_parse("/root/.gtk-tmp"); +// gtk_rc_reset_styles(settings); + + //unlink(s_rc_file.c_str()); + + while (gtk_events_pending()) + gtk_main_iteration(); + + +} diff --git a/radiant/gtktheme.h b/radiant/gtktheme.h new file mode 100644 index 00000000..79425947 --- /dev/null +++ b/radiant/gtktheme.h @@ -0,0 +1,14 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Wed Jan 1 2003 + copyright : (C) 2003 - 2005 by Alex Shaduri + email : ashaduri '@' gmail.com + ***************************************************************************/ + +#ifndef _GTKTHEME_H_ +#define _GTKTHEME_H_ + +void gtkThemeDlg(); + +#endif diff --git a/radiant/main.cpp b/radiant/main.cpp index 3e797f2d..f7f6cf6b 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -543,6 +543,21 @@ void user_shortcuts_save(){ SaveCommandMap( path.c_str() ); } +void add_local_rc_files(){ + { + StringOutputStream path( 512 ); + path << AppPath_get() << ".gtkrc-2.0.radiant"; + gtk_rc_add_default_file( path.c_str() ); + } +#ifdef WIN32 + { + StringOutputStream path( 512 ); + path << AppPath_get() << ".gtkrc-2.0.win"; + gtk_rc_add_default_file( path.c_str() ); + } +#endif +} + int main( int argc, char* argv[] ){ crt_init(); @@ -594,6 +609,8 @@ int main( int argc, char* argv[] ){ paths_init(); + add_local_rc_files(); + if ( !check_version() ) { return EXIT_FAILURE; } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 147d1a65..60f3a5eb 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -118,6 +118,7 @@ #include "referencecache.h" #include "filterbar.h" +#include "gtktheme.h" struct layout_globals_t @@ -904,6 +905,8 @@ GtkMenuItem* create_colours_menu(){ create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" ); create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" ); + create_menu_item_with_mnemonic( menu_in_menu, "GTK Theme...", "gtkThemeDlg" ); + menu_separator( menu_in_menu ); create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" ); @@ -3306,6 +3309,7 @@ void MainFrame_Construct(){ GlobalToggles_insert( "MouseScale", FreeCaller(), ToggleItem::AddCallbackCaller( g_scalemode_button ) ); GlobalToggles_insert( "MouseDrag", FreeCaller(), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) ); + GlobalCommands_insert( "gtkThemeDlg", FreeCaller() ); GlobalCommands_insert( "ColorSchemeOriginal", FreeCaller() ); GlobalCommands_insert( "ColorSchemeQER", FreeCaller() ); GlobalCommands_insert( "ColorSchemeBlackAndGreen", FreeCaller() ); diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index cf1b6589..0dbb6a0b 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -2086,6 +2086,7 @@ GtkWidget* TextureBrowser_constructWindow( GtkWindow* toplevel ){ GtkWidget* menu_view = gtk_menu_new(); //GtkWidget* view_item = (GtkWidget*) TextureBrowser_constructViewMenu( GTK_MENU( menu_view ) ); + gtk_menu_set_title( GTK_MENU( menu_view ), "View" ); //gtk_menu_item_set_submenu( GTK_MENU_ITEM( view_item ), menu_view ); //gtk_menu_bar_append( GTK_MENU_BAR( menu_bar ), view_item ); @@ -2099,13 +2100,14 @@ GtkWidget* TextureBrowser_constructWindow( GtkWindow* toplevel ){ button_set_icon( button, "texbro_view.png" ); gtk_widget_show( GTK_WIDGET( button ) ); gtk_button_set_relief( button, GTK_RELIEF_NONE ); - gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); + gtk_widget_set_size_request( GTK_WIDGET( button ), 24, 24 ); GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( GTK_WIDGET( button ), GTK_CAN_DEFAULT ); gtk_toolbar_append_element( toolbar, GTK_TOOLBAR_CHILD_WIDGET, GTK_WIDGET( button ), "", "View", "", 0, 0, 0 ); g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( Popup_View_Menu ), menu_view ); - + //to show detached menu over floating tex bro + gtk_menu_attach_to_widget( GTK_MENU( menu_view ), GTK_WIDGET( button ), NULL ); button = toolbar_append_button( toolbar, "Find / Replace...", "texbro_gtk-find-and-replace.png", "FindReplaceTextures" ); gtk_widget_set_size_request( GTK_WIDGET( button ), 22, 22 ); diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index b33243f7..393a957a 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -720,7 +720,16 @@ Shader* XYWnd::m_state_selected = 0; void xy_update_xor_rectangle( XYWnd& self, rect_t area ){ if ( GTK_WIDGET_VISIBLE( self.GetWidget() ) ) { - self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.Width(), self.Height() ) ); + rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() ); + int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0; + int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2; + rect.x /= self.Scale(); + rect.y /= self.Scale(); + rect.w /= self.Scale(); + rect.h /= self.Scale(); + rect.x += self.GetOrigin()[nDim1]; + rect.y += self.GetOrigin()[nDim2]; + self.m_XORRectangle.set( rect ); } } -- 2.39.2