⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pan-view.c

📁 Gqview,Linux下基于GTK+库写成的轻量级而能丰富的图像浏览程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
		work = work->next;		}	return NULL;}static PanItem *pan_item_find_by_coord(PanWindow *pw, ItemType type, gint x, gint y, const gchar *key){	PanItem *pi;	pi = pan_item_find_by_coord_l(pw->list, type, x, y, key);	if (pi) return pi;	return pan_item_find_by_coord_l(pw->list_static, type, x, y, key);}/* *----------------------------------------------------------------------------- * layout generation *----------------------------------------------------------------------------- */static gint islink_loop(const gchar *s){	gchar *sl;	struct stat st;	gint ret = FALSE;	sl = path_from_utf8(s);	if (lstat(sl, &st) == 0 && S_ISLNK(st.st_mode))		{		gchar *buf;		gint l;		buf = g_malloc(st.st_size + 1);		l = readlink(sl, buf, st.st_size);		if (l == st.st_size)			{			buf[l] = '\0';			parse_out_relatives(buf);			l = strlen(buf);			parse_out_relatives(sl);			if (buf[0] == '/')				{				if (strncmp(sl, buf, l) == 0 &&				    (sl[l] == '\0' || sl[l] == '/' || l == 1)) ret = TRUE;				}			else				{				gchar *link_path;				link_path = concat_dir_and_file(sl, buf);				parse_out_relatives(link_path);				if (strncmp(sl, link_path, l) == 0 &&				    (sl[l] == '\0' || sl[l] == '/' || l == 1)) ret = TRUE;				g_free(link_path);				}			}		g_free(buf);		}	g_free(sl);	return ret;}static gint is_ignored(const gchar *s, gint ignore_symlinks){	struct stat st;	const gchar *n;	if (!lstat_utf8(s, &st)) return TRUE;#if 0	/* normal filesystems have directories with some size or block allocation,	 * special filesystems (like linux /proc) set both to zero.	 * enable this check if you enable listing the root "/" folder	 */	if (st.st_size == 0 && st.st_blocks == 0) return TRUE;#endif	if (S_ISLNK(st.st_mode) && (ignore_symlinks || islink_loop(s))) return TRUE;	n = filename_from_path(s);	if (n && strcmp(n, GQVIEW_RC_DIR) == 0) return TRUE;	return FALSE;}static GList *pan_window_layout_list(const gchar *path, SortType sort, gint ascend,				     gint ignore_symlinks){	GList *flist = NULL;	GList *dlist = NULL;	GList *result;	GList *folders;	filelist_read(path, &flist, &dlist);	if (sort != SORT_NONE)		{		flist = filelist_sort(flist, sort, ascend);		dlist = filelist_sort(dlist, sort, ascend);		}	result = flist;	folders = dlist;	while (folders)		{		FileData *fd;		fd = folders->data;		folders = g_list_remove(folders, fd);		if (!is_ignored(fd->path, ignore_symlinks) &&		    filelist_read(fd->path, &flist, &dlist))			{			if (sort != SORT_NONE)				{				flist = filelist_sort(flist, sort, ascend);				dlist = filelist_sort(dlist, sort, ascend);				}			result = g_list_concat(result, flist);			folders = g_list_concat(dlist, folders);			}		file_data_free(fd);		}	return result;}static void pan_window_layout_compute_grid(PanWindow *pw, const gchar *path, gint *width, gint *height){	GList *list;	GList *work;	gint x, y;	gint grid_size;	gint next_y;	list = pan_window_layout_list(path, SORT_NAME, TRUE, pw->ignore_symlinks);	grid_size = (gint)sqrt((double)g_list_length(list));	if (pw->size > LAYOUT_SIZE_THUMB_LARGE)		{		grid_size = grid_size * (512 + PAN_THUMB_GAP) * pw->image_size / 100;		}	else		{		grid_size = grid_size * (PAN_THUMB_SIZE + PAN_THUMB_GAP);		}	next_y = 0;	*width = PAN_FOLDER_BOX_BORDER * 2;	*height = PAN_FOLDER_BOX_BORDER * 2;	x = PAN_THUMB_GAP;	y = PAN_THUMB_GAP;	work = list;	while (work)		{		FileData *fd;		PanItem *pi;		fd = work->data;		work = work->next;		if (pw->size > LAYOUT_SIZE_THUMB_LARGE)			{			pi = pan_item_new_image(pw, fd, x, y, 10, 10);			x += pi->width + PAN_THUMB_GAP;			if (y + pi->height + PAN_THUMB_GAP > next_y) next_y = y + pi->height + PAN_THUMB_GAP;			if (x > grid_size)				{				x = PAN_THUMB_GAP;				y = next_y;				}			}		else			{			pi = pan_item_new_thumb(pw, fd, x, y);			x += PAN_THUMB_SIZE + PAN_THUMB_GAP;			if (x > grid_size)				{				x = PAN_THUMB_GAP;				y += PAN_THUMB_SIZE + PAN_THUMB_GAP;				}			}		pan_item_size_coordinates(pi, PAN_THUMB_GAP, width, height);		}	g_list_free(list);}static void pan_window_Layout_compute_folders_flower_size(PanWindow *pw, gint *width, gint *height){	GList *work;	gint x1, y1, x2, y2;	x1 = 0;	y1 = 0;	x2 = 0;	y2 = 0;	work = pw->list;	while (work)		{		PanItem *pi;		pi = work->data;		work = work->next;		if (x1 > pi->x) x1 = pi->x;		if (y1 > pi->y) y1 = pi->y;		if (x2 < pi->x + pi->width) x2 = pi->x + pi->width;		if (y2 < pi->y + pi->height) y2 = pi->y + pi->height;		}	x1 -= PAN_FOLDER_BOX_BORDER;	y1 -= PAN_FOLDER_BOX_BORDER;	x2 += PAN_FOLDER_BOX_BORDER;	y2 += PAN_FOLDER_BOX_BORDER;	work = pw->list;	while (work)		{		PanItem *pi;		pi = work->data;		work = work->next;		pi->x -= x1;		pi->y -= y1;		if (pi->type == ITEM_TRIANGLE && pi->data)			{			gint *coord;			coord = pi->data;			coord[0] -= x1;			coord[1] -= y1;			coord[2] -= x1;			coord[3] -= y1;			coord[4] -= x1;			coord[5] -= y1;			}		}	if (width) *width = x2 - x1;	if (height) *height = y2 - y1;}typedef struct _FlowerGroup FlowerGroup;struct _FlowerGroup {	GList *items;	GList *children;	gint x;	gint y;	gint width;	gint height;	gdouble angle;	gint circumference;	gint diameter;};static void pan_window_layout_compute_folder_flower_move(FlowerGroup *group, gint x, gint y){	GList *work;	work = group->items;	while (work)		{		PanItem *pi;		pi = work->data;		work = work->next;		pi->x += x;		pi->y += y;		}	group->x += x;	group->y += y;}#define PI 3.14159static void pan_window_layout_compute_folder_flower_position(FlowerGroup *group, FlowerGroup *parent,							     gint *result_x, gint *result_y){	gint x, y;	gint radius;	gdouble a;	radius = parent->circumference / (2*PI);	radius = MAX(radius, parent->diameter / 2 + group->diameter / 2);	a = 2*PI * group->diameter / parent->circumference;	x = (gint)((double)radius * cos(parent->angle + a / 2));	y = (gint)((double)radius * sin(parent->angle + a / 2));	parent->angle += a;	x += parent->x;	y += parent->y;	x += parent->width / 2;	y += parent->height / 2;	x -= group->width / 2;	y -= group->height / 2;	*result_x = x;	*result_y = y;}static void pan_window_layout_compute_folder_flower_build(PanWindow *pw, FlowerGroup *group, FlowerGroup *parent){	GList *work;	gint x, y;	if (!group) return;	if (parent && parent->children)		{		pan_window_layout_compute_folder_flower_position(group, parent, &x, &y);		}	else		{		x = 0;		y = 0;		}	pan_window_layout_compute_folder_flower_move(group, x, y);	if (parent)		{		PanItem *pi;		gint px, py, gx, gy;		gint x1, y1, x2, y2;		px = parent->x + parent->width / 2;		py = parent->y + parent->height / 2;		gx = group->x + group->width / 2;		gy = group->y + group->height / 2;		x1 = MIN(px, gx);		y1 = MIN(py, gy);		x2 = MAX(px, gx + 5);		y2 = MAX(py, gy + 5);		pi = pan_item_new_tri(pw, NULL, x1, y1, x2 - x1, y2 - y1,				      px, py, gx, gy, gx + 5, gy + 5,				      255, 40, 40, 128);		pan_item_tri_border(pi, BORDER_1 | BORDER_3,				    255, 0, 0, 128);		}	pw->list = g_list_concat(group->items, pw->list);	group->items = NULL;	group->circumference = 0;	work = group->children;	while (work)		{		FlowerGroup *child;		child = work->data;		work = work->next;		group->circumference += child->diameter;		}	work = g_list_last(group->children);	while (work)		{		FlowerGroup *child;		child = work->data;		work = work->prev;		pan_window_layout_compute_folder_flower_build(pw, child, group);		}	g_list_free(group->children);	g_free(group);}static FlowerGroup *pan_window_layout_compute_folders_flower_path(PanWindow *pw, const gchar *path,								  gint x, gint y){	FlowerGroup *group;	GList *f;	GList *d;	GList *work;	PanItem *pi_box;	gint x_start;	gint y_height;	gint grid_size;	gint grid_count;	if (!filelist_read(path, &f, &d)) return NULL;	if (!f && !d) return NULL;	f = filelist_sort(f, SORT_NAME, TRUE);	d = filelist_sort(d, SORT_NAME, TRUE);	pi_box = pan_item_new_text(pw, x, y, path, TEXT_ATTR_NONE,				   PAN_TEXT_COLOR, 255);	y += pi_box->height;	pi_box = pan_item_new_box(pw, file_data_new_simple(path),				  x, y,				  PAN_FOLDER_BOX_BORDER * 2, PAN_FOLDER_BOX_BORDER * 2,				  PAN_FOLDER_BOX_OUTLINE_THICKNESS,				  PAN_FOLDER_BOX_COLOR, PAN_FOLDER_BOX_ALPHA,				  PAN_FOLDER_BOX_OUTLINE_COLOR, PAN_FOLDER_BOX_OUTLINE_ALPHA);	x += PAN_FOLDER_BOX_BORDER;	y += PAN_FOLDER_BOX_BORDER;	grid_size = (gint)(sqrt(g_list_length(f)) + 0.9);	grid_count = 0;	x_start = x;	y_height = y;	work = f;	while (work)		{		FileData *fd;		PanItem *pi;		fd = work->data;		work = work->next;		if (pw->size > LAYOUT_SIZE_THUMB_LARGE)			{			pi = pan_item_new_image(pw, fd, x, y, 10, 10);			x += pi->width + PAN_THUMB_GAP;			if (pi->height > y_height) y_height = pi->height;			}		else			{			pi = pan_item_new_thumb(pw, fd, x, y);			x += PAN_THUMB_SIZE + PAN_THUMB_GAP;			y_height = PAN_THUMB_SIZE;			}		grid_count++;		if (grid_count >= grid_size)			{			grid_count = 0;			x = x_start;			y += y_height + PAN_THUMB_GAP;			y_height = 0;			}		pan_item_size_by_item(pi_box, pi, PAN_FOLDER_BOX_BORDER);		}	group = g_new0(FlowerGroup, 1);	group->items = pw->list;	pw->list = NULL;	group->width = pi_box->width;	group->height = pi_box->y + pi_box->height;	group->diameter = (int)sqrt(group->width * group->width + group->height * group->height);	group->children = NULL;	work = d;	while (work)		{		FileData *fd;		FlowerGroup *child;		fd = work->data;		work = work->next;		if (!is_ignored(fd->path, pw->ignore_symlinks))			{			child = pan_window_layout_compute_folders_flower_path(pw, fd->path, 0, 0);			if (child) group->children = g_list_prepend(group->children, child);			}		}	if (!f && !group->children)		{		work = group->items;		while (work)			{			PanItem *pi;			pi = work->data;			work = work->next;			pan_item_free(pi);			}		g_list_free(group->items);		g_free(group);		group = NULL;		}	g_list_free(f);	filelist_free(d);	return group;}static void pan_window_layout_compute_folders_flower(PanWindow *pw, const gchar *path,						     gint *width, gint *height,						     gint *scroll_x, gint *scroll_y){	FlowerGroup *group;	GList *list;	group = pan_window_layout_compute_folders_flower_path(pw, path, 0, 0);	pan_window_layout_compute_folder_flower_build(pw, group, NULL);	pan_window_Layout_compute_folders_flower_size(pw, width, height);	list = pan_item_find_by_path(pw, ITEM_BOX, path, FALSE, FALSE);	if (list)		{		PanItem *pi = list->data;		*scroll_x = pi->x + pi->width / 2;		*scroll_y = pi->y + pi->height / 2;		}	g_list_free(list);}static void pan_window_layout_compute_folders_linear_path(PanWindow *pw, const gchar *path,							  gint *x, gint *y, gint *level,							  PanItem *parent,							  gint *width, gint *height){	GList *f;	GList *d;	GList *work;	PanItem *pi_box;	gint y_height = 0;	if (!filelist_read(path, &f, &d)) return;	if (!f && !d) return;	f = filelist_sort(f, SORT_NAME, TRUE);	d = filelist_sort(d, SORT_NAME, TRUE);	*x = PAN_FOLDER_BOX_BORDER + ((*level) * MAX(PAN_FOLDER_BOX_BORDER, PAN_THUMB_GAP));	pi_box = pan_item_new_text(pw, *x, *y, path, TEXT_ATTR_NONE,				   PAN_TEXT_COLOR, 255);	*y += pi_box->height;	pi_box = pan_item_new_box(pw, file_data_new_simple(path),				  *x, *y,				  PAN_FOLDER_BOX_BORDER, PAN_FOLDER_BOX_BORDER,				  PAN_FOLDER_BOX_OUTLINE_THICKNESS,				  PAN_FOLDER_BOX_COLOR, PAN_FOLDER_BOX_ALPHA,				  PAN_FOLDER_BOX_OUTLINE_COLOR, PAN_FOLDER_BOX_OUTLINE_ALPHA);	*x += PAN_FOLDER_BOX_BORDER;	*y += PAN_FOLDER_BOX_BORDER;	work = f;	while (work)		{		FileData *fd;		PanItem *pi;		fd = work->data;		work = work->next;		if (pw->size > LAYOUT_SIZE_THUMB_LARGE)			{			pi = pan_item_new_image(pw, fd, *x, *y, 10, 10);			*x += pi->width + PAN_THUMB_GAP;			if (pi->height > y_height) y_height = pi->height;			}		else			{			pi = pan_item_new_thumb(pw, fd, *x, *y);			*x += PAN_THUMB_SIZE + PAN_THUMB_GAP;			y_height = PAN_THUMB_SIZE;			}		pan_item_size_by_item(pi_box, pi, PAN_FOLDER_BOX_BORDER);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -