📄 gsegycolormanager.c
字号:
/* * GTKSEISVIEWUI - Library of interface elements for GSEGYView * * Copyright (C) 2006 Vladimir Bashkardin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more av. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Author: Vladimir Bashkardin <vovizmus@users.sourceforge.net> */#include "gsegyfileaux.h"#include "gsegycolormanager.h"G_DEFINE_TYPE (GSEGYColorManager, g_segy_color_manager, G_TYPE_OBJECT)#define G_SEGY_COLOR_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), G_SEGY_TYPE_COLOR_MANAGER, GSEGYColorManagerPrivate))typedef struct _GSEGYColorManagerPrivate GSEGYColorManagerPrivate;struct _GSEGYColorManagerPrivate { GtkWidget *window; GtkWidget *vbox; GtkWidget *vbox1; GtkWidget *warning_frame; GtkWidget *warning_label; GtkWidget *frame; GtkWidget *button_box; GtkWidget *close_button; GtkWidget *scrolled_window; GtkWidget *tree_view; GtkListStore *palette_list_store; GtkCellRenderer *palette_name_renderer; GtkCellRenderer *palette_colors_renderer; gint list_selection; gboolean block_selection; GPtrArray *palettes; GtkSeisViewGl *seis_view;};static void g_segy_color_manager_init (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); private->window = NULL; private->vbox = NULL; private->warning_frame = NULL; private->warning_label = NULL; private->vbox1 = NULL; private->frame = NULL; private->button_box = NULL; private->close_button = NULL; private->scrolled_window = NULL; private->tree_view = NULL; private->palette_list_store = NULL; private->palette_name_renderer = NULL; private->palette_colors_renderer = NULL; private->list_selection = 0; private->block_selection = FALSE; private->palettes = NULL; private->seis_view = NULL;#ifdef DEBUG g_print ("<GSEGYColorManager is inited>\n");#endif}static void g_segy_color_manager_finalize (GObject *object) { GSEGYColorManager *self = G_SEGY_COLOR_MANAGER (object); GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); if (private->window) { gtk_widget_destroy (private->window); g_object_unref (G_OBJECT (private->palette_list_store)); } if (private->seis_view) g_object_unref (G_OBJECT (private->seis_view));#ifdef DEBUG g_print ("<GSEGYColorManager is finalized>\n");#endif if (G_OBJECT_CLASS (g_segy_color_manager_parent_class)->finalize) G_OBJECT_CLASS (g_segy_color_manager_parent_class)->finalize (object);}static void g_segy_color_manager_class_init (GSEGYColorManagerClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = g_segy_color_manager_finalize; g_type_class_add_private (klass, sizeof (GSEGYColorManagerPrivate));#ifdef DEBUG g_print ("<GSEGYColorManager class is inited>\n");#endif}static void g_segy_color_manager_get_selection (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); GtkTreeSelection* tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (private->tree_view)); GList *tree_path_list = gtk_tree_selection_get_selected_rows (tree_selection, NULL); GtkTreePath *tree_path = (GtkTreePath*)g_list_nth_data (tree_path_list, 0); gint* tree_indices = gtk_tree_path_get_indices (tree_path); private->list_selection = tree_indices[0]; g_list_free (tree_path_list);}static void g_segy_color_manager_set_selection (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); if (private->block_selection) return; GtkTreeSelection* tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (private->tree_view)); GtkTreePath *new_tree_path = gtk_tree_path_new_from_indices (private->list_selection, -1); gtk_tree_selection_select_path (tree_selection, new_tree_path); gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (private->tree_view), new_tree_path, NULL, FALSE, 0, 0); gtk_tree_path_free (new_tree_path);}static void g_segy_color_manager_set_palette (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); if (private->window) g_segy_color_manager_set_selection (self); if (private->seis_view) { gtk_seis_view_gl_set_palette (private->seis_view, (GSeisPalette*)g_ptr_array_index (private->palettes, private->list_selection)); gtk_seis_view_gl_redraw (private->seis_view); }}static void g_segy_color_manager_list_selection_handler (GtkTreeView *treeview, gpointer data) { GSEGYColorManager *self = G_SEGY_COLOR_MANAGER (data); GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); private->block_selection = TRUE; g_segy_color_manager_get_selection (self); g_segy_color_manager_set_palette (self); private->block_selection = FALSE;}static void g_segy_color_manager_close_button_handler (GtkWidget *widget, gpointer data) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (G_SEGY_COLOR_MANAGER (data)); gtk_widget_hide (private->window);}static gboolean g_segy_color_manager_window_close_handler (GtkWidget *widget, GdkEvent *event, gpointer data) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (G_SEGY_COLOR_MANAGER (data)); gtk_widget_hide (private->window); return TRUE;}void g_segy_color_manager_next_palette (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); if (private->list_selection == private->palettes->len - 1) return; private->list_selection = private->list_selection + 1; g_segy_color_manager_set_palette (self);}void g_segy_color_manager_previous_palette (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); if (0 == private->list_selection) return; private->list_selection = private->list_selection - 1; g_segy_color_manager_set_palette (self);}GtkWidget* g_segy_color_manager_get_main_widget (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); if (NULL == private->window) { private->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (private->window), 7); gtk_window_set_modal (GTK_WINDOW (private->window), FALSE); gtk_window_set_resizable (GTK_WINDOW (private->window), FALSE); gtk_window_set_title (GTK_WINDOW (private->window), _("Color manager")); gtk_signal_connect (GTK_OBJECT (private->window), "delete_event", GTK_SIGNAL_FUNC (g_segy_color_manager_window_close_handler), (gpointer)G_OBJECT (self)); private->vbox = gtk_vbox_new (FALSE, 3); gtk_container_add (GTK_CONTAINER (private->window), private->vbox); if (FALSE == gtk_seis_view_gl_can_change_palette_fast (private->seis_view)) { private->warning_frame = gtk_frame_new (_("WARNING!")); gtk_box_pack_start (GTK_BOX (private->vbox), private->warning_frame, FALSE, FALSE, 3); private->warning_label = gtk_label_new (_("The graphics card on this machine " "does not support palette rendering.\n" "The data has to be reloaded after " "pallete selection from the list below.\n")); g_object_set (G_OBJECT (private->warning_label), "xpad", 10, "ypad", 10, "justify" , GTK_JUSTIFY_CENTER, NULL); gtk_container_add (GTK_CONTAINER (private->warning_frame), private->warning_label); } private->frame = gtk_frame_new (_("Palette")); gtk_box_pack_start (GTK_BOX (private->vbox), private->frame, FALSE, FALSE, 0); private->vbox1 = gtk_vbox_new (FALSE, 3); gtk_container_set_border_width (GTK_CONTAINER (private->vbox1), 3); gtk_container_add (GTK_CONTAINER (private->frame), private->vbox1); private->scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (private->scrolled_window), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (private->scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request (GTK_WIDGET (private->scrolled_window), -1, 400); gtk_box_pack_start (GTK_BOX (private->vbox1), private->scrolled_window, FALSE, FALSE, 4); private->tree_view = gtk_tree_view_new (); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (private->tree_view), TRUE); gtk_tree_view_set_reorderable (GTK_TREE_VIEW (private->tree_view), FALSE); gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (private->tree_view)), GTK_SELECTION_SINGLE); private->palette_name_renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (private->tree_view), 0, _("Name"), private->palette_name_renderer, "text", 0, NULL); private->palette_colors_renderer = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (private->tree_view), 1, _("Colors"), private->palette_colors_renderer, "pixbuf", 1, NULL); private->palette_list_store = gtk_list_store_new (2, G_TYPE_STRING, GDK_TYPE_PIXBUF); GtkTreeIter iter; guint i; const gchar *palette_name; GdkPixbuf *palette_colors; GSeisPalette *palette; for (i = 0; i < private->palettes->len; i++) { palette = (GSeisPalette*)g_ptr_array_index (private->palettes, i); palette_name = g_seis_palette_get_name (palette); palette_colors = g_seis_palette_get_color_scale (palette); gtk_list_store_append (private->palette_list_store, &iter); gtk_list_store_set (private->palette_list_store, &iter, 0, palette_name, 1, palette_colors, -1); } gtk_tree_view_set_model (GTK_TREE_VIEW (private->tree_view), GTK_TREE_MODEL (private->palette_list_store)); gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (private->tree_view), FALSE); gtk_container_add (GTK_CONTAINER (private->scrolled_window), private->tree_view); gtk_signal_connect (GTK_OBJECT (private->tree_view), "cursor-changed", GTK_SIGNAL_FUNC (g_segy_color_manager_list_selection_handler), (gpointer)G_OBJECT (self)); gtk_box_pack_start (GTK_BOX (private->vbox), gtk_hseparator_new (), TRUE, TRUE, 5); private->button_box = gtk_hbutton_box_new (); gtk_button_box_set_layout (GTK_BUTTON_BOX (private->button_box), GTK_BUTTONBOX_SPREAD); gtk_box_pack_start (GTK_BOX (private->vbox), private->button_box, FALSE, FALSE, 5); private->close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); gtk_container_add (GTK_CONTAINER (private->button_box), private->close_button); gtk_signal_connect (GTK_OBJECT (private->close_button), "clicked", GTK_SIGNAL_FUNC (g_segy_color_manager_close_button_handler), (gpointer)G_OBJECT (self)); g_segy_color_manager_set_selection (self); gtk_widget_show_all (private->vbox); gsegy_view_set_window_icon (GTK_WINDOW (private->window)); } return private->window;}gboolean g_segy_color_manager_has_main_widget (GSEGYColorManager *self) { GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (self); return (private->window != NULL);}GSEGYColorManager* g_segy_color_manager_new (GPtrArray *palettes, GtkSeisViewGl *seis_view) { GSEGYColorManager *new_color_manager = G_SEGY_COLOR_MANAGER (g_object_new (G_SEGY_TYPE_COLOR_MANAGER, NULL)); GSEGYColorManagerPrivate *private = G_SEGY_COLOR_MANAGER_GET_PRIVATE (new_color_manager); private->palettes = palettes; private->seis_view = seis_view; g_object_ref (G_OBJECT (private->seis_view)); gtk_seis_view_gl_set_palette (private->seis_view, (GSeisPalette*)g_ptr_array_index (private->palettes, 0)); return new_color_manager;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -