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

📄 showlyricdlg.c

📁 ShowLyric是一款用于Audacious的歌词显示插件
💻 C
📖 第 1 页 / 共 2 页
字号:
	// 保持当前行在最中间	LyricItem *pCurrentItem = (LyricItem *) current->data;	int iNewY = pVbox->allocation.y - pCurrentItem->pLabel->allocation.y			+ pLyricWnd->allocation.height / 2;	if (current->next)	{		LyricItem *pNextItem = (LyricItem *) current->next->data;		double f = ((double)iTime - pCurrentItem->iTime) / (pNextItem->iTime				- pCurrentItem->iTime);		int iAdd = (GTK_WIDGET(pNextItem->pLabel)->allocation.y - GTK_WIDGET(pCurrentItem->pLabel)->allocation.y) * f;		iNewY -= iAdd;	}	if (IsSmaller(&iNewY) || iNewY == 0)	{		gtk_layout_move(GTK_LAYOUT(pLayout), pVbox, 18, iNewY);		//LyricDebug("iNewY=%d", iNewY);	}	gtk_window_get_position(GTK_WINDOW(pLyricWnd), &theApp.m_configs.pos.iX,			&theApp.m_configs.pos.iY);	return TRUE;}inline gint number_between(gint from, gint to, gdouble rate){	return from + rate * (to - from);}void color_between(GdkColor * from, GdkColor * to, gdouble rate,		GdkColor * result){	if (!from || !to || !result)		return;	result->pixel = number_between(from->pixel, to->pixel, rate);	result->red = number_between(from->red, to->red, rate);	result->green = number_between(from->green, to->green, rate);	result->blue = number_between(from->blue, to->blue, rate);}inline gboolean IsSmaller(int *piNew){	static int iOldY;	static int iBuffer; // 如果跳跃太大,多余的跳跃将缓存到该变量中,在后面的移动中慢慢释放出来,以防止跳跃太大	static int iRate; // 释放缓存的速度	if (*piNew == 50000)	{		iOldY = *piNew;		iBuffer = 0;		iRate = 0;		return TRUE;	}	// 如果是后退则直接后退	if (*piNew > iOldY + 50)	{		iOldY = *piNew;		iBuffer = 0;		iRate = 0;		return TRUE;	}	// 如果是前进, 则做延缓处理	if (*piNew < iOldY || (*piNew == iOldY && iBuffer > 0))	{		int iTmp = iOldY - *piNew, iFlag = iRate + 1;		if (iTmp > iFlag && iTmp < 20)		{			iBuffer += iOldY - *piNew - iFlag;			if (iBuffer <= 0)				iRate = 0;			else if (iBuffer <= 10)				iRate = 1;			else if (iBuffer <= 20)				iRate = 2;			else if (iBuffer <= 30)				iRate = 3;			else if (iBuffer <= 40)				iRate = 4;			else if (iBuffer <= 50)				iRate = 5;			else if (iBuffer <= 60)				iRate = 6;			else if (iBuffer > 60)				iRate = 10;			*piNew = iOldY - iFlag;		}		else		{			if (iBuffer > 0)			{				int iAdd = iRate < iBuffer ? iRate : iBuffer;				*piNew += iAdd;				iBuffer -= iAdd;				if (iBuffer <= 0)					iRate = 0;				else if (iBuffer <= 10)					iRate = 1;				else if (iBuffer <= 20)					iRate = 2;				else if (iBuffer <= 30)					iRate = 3;				else if (iBuffer <= 40)					iRate = 4;				else if (iBuffer <= 50)					iRate = 5;				else if (iBuffer <= 60)					iRate = 6;				else if (iBuffer > 60)					iRate = 10;				if (iOldY - *piNew < 0)				{					iBuffer = iOldY - *piNew;					*piNew = iOldY;				}			}		}		// LyricDebug("iY=%d, iBuffer=%d, iRate=%d", iOldY - *piNew, iBuffer, iRate);		iOldY = *piNew;		return TRUE;	}	return FALSE;}void ShowLyric(){	GtkWidget *pLyricWnd = glade_xml_get_widget(theApp.m_xml, "ShowLyric");	GtkWidget* pVbox = glade_xml_get_widget(theApp.m_xml, "vboxLyrics");	gint iMaxWidth = 0;	// 显示歌词	PangoFontDescription *font_desc =		pango_font_description_from_string(theApp.m_configs.szLyricFontName);	GList* list = g_list_first(this.m_ListCurrLyric);	while (list)	{		LyricItem* lpItem = list->data;		if (lpItem)		{			lpItem->pLabel = (GtkWidget*)gtk_label_new(lpItem->lpszValue);			gtk_label_set_single_line_mode(GTK_LABEL(lpItem->pLabel), TRUE);			gtk_widget_modify_fg(GTK_WIDGET(lpItem->pLabel), GTK_STATE_NORMAL,					&theApp.m_configs.colors.normal);			gtk_widget_modify_font(GTK_WIDGET(lpItem->pLabel), font_desc);			//			gtk_widget_modify_bg(GTK_WIDGET(lpItem->pLabel), GTK_STATE_NORMAL,			//					&theApp.m_configs.colors.background);			gtk_widget_show(GTK_WIDGET(lpItem->pLabel));			gtk_box_pack_start(GTK_BOX(pVbox), GTK_WIDGET(lpItem->pLabel),					FALSE, FALSE, 0);			gint iWidth  = 0;			PangoLayout *layout = NULL;			layout = gtk_widget_create_pango_layout(GTK_WIDGET(lpItem->pLabel),					lpItem->lpszValue);			if(layout){			    pango_layout_get_pixel_size(layout, &iWidth, NULL);			    g_object_unref(layout);			}			if (iWidth > iMaxWidth)				iMaxWidth = iWidth;		}		list = g_list_next(list);	}	gint iWndHeight = 0, iTemp = 0;	gtk_window_get_size(GTK_WINDOW(pLyricWnd), &iTemp, &iWndHeight);	gtk_window_resize(GTK_WINDOW(pLyricWnd), iMaxWidth + 40, iWndHeight);	gtk_widget_show(GTK_WIDGET(pVbox));	gtk_window_move(GTK_WINDOW(pLyricWnd), theApp.m_configs.pos.iX,			theApp.m_configs.pos.iY);	gtk_widget_show(pLyricWnd);	SmartShowWnd(TRUE);	this.m_TimerId = gtk_timeout_add(100, ScrollLyric, &this.m_ListCurrLyric);}// 刷新并生效配置void RefreshLyricSetting(){	GtkWidget *pLyricWnd = glade_xml_get_widget(theApp.m_xml, "ShowLyric");	gtk_window_set_opacity(GTK_WINDOW(pLyricWnd), 1 - theApp.m_configs.iOpacity			/ 100.0);	gtk_window_set_decorated(GTK_WINDOW(pLyricWnd), theApp.m_configs.bShowBroad);	GList* list = g_list_first(this.m_ListCurrLyric);	gint iMaxWidth = 0;	PangoFontDescription *font_desc =		pango_font_description_from_string(theApp.m_configs.szLyricFontName);	while (list)	{		LyricItem* lpItem = list->data;		if (lpItem && lpItem->pLabel)		{			gtk_widget_modify_fg(GTK_WIDGET(lpItem->pLabel), GTK_STATE_NORMAL,					&theApp.m_configs.colors.normal);			gtk_widget_modify_font(GTK_WIDGET(lpItem->pLabel), font_desc);			gint iWidth  = 0;			PangoLayout *layout = NULL;			layout = gtk_widget_create_pango_layout(GTK_WIDGET(lpItem->pLabel),					lpItem->lpszValue);			if(layout){			    pango_layout_get_pixel_size(layout, &iWidth, NULL);			    g_object_unref(layout);			}			if (iWidth > iMaxWidth)				iMaxWidth = iWidth;		}		list = g_list_next(list);	}	gint iWndHeight = 0, iTemp = 0;	gtk_window_get_size(GTK_WINDOW(pLyricWnd), &iTemp, &iWndHeight);	gtk_window_resize(GTK_WINDOW(pLyricWnd), iMaxWidth + 40, iWndHeight);	gtk_widget_modify_fg(GTK_WIDGET(pLyricWnd), GTK_STATE_NORMAL,			&theApp.m_configs.colors.background);}void on_MenuAbout_activate(GtkWidget* wideget, gpointer user_data){	theApp.About(GTK_WINDOW(user_data));}void on_MenuEditLyric_activate(GtkWidget* wideget, gpointer user_data){	this.m_EditLyricDlg.EditLyric();}void on_MenuReDownLoad_activate(GtkWidget* wideget, gpointer user_data){	SongInfo info;	if (theApp.m_player.GetSongInfo(&info))	{		gchar szLrcFile[MAX_PATH] =		{ 0 };		sprintf(szLrcFile, "%s/%s/%s.lyric", theApp.m_configs.szLyricPath,				info.szArtist, info.szTitle);		strcpy(info.szLyricFileName, szLrcFile);		theApp.SearchLyric(info, FALSE);	}}void ChangeLyricTime(int iAdd){	GList *list= this.m_ListCurrLyric;	if (!list)return;	this.m_bLyricChanging = TRUE;	while (list)	{		LyricItem *item = (LyricItem *) list->data;		item->iTime += iAdd;		list = g_list_next(list);	}	this.m_bLyricChanging = FALSE;	this.m_bLyricChanged = TRUE;}void on_MenuUpTime_activate(GtkWidget* wideget, gpointer user_data){	ChangeLyricTime(500);}void on_MenuDownTime_activate(GtkWidget* wideget, gpointer user_data){	ChangeLyricTime(-500);}void on_MenuShowBroad_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data){	GtkWidget *pLyricWnd = glade_xml_get_widget(theApp.m_xml, "ShowLyric");	gtk_window_set_decorated(GTK_WINDOW(pLyricWnd), checkmenuitem->active);	theApp.m_configs.bShowBroad = checkmenuitem->active;	theApp.UpdataSetting();}void on_MenuMouseScroll_toggled(GtkCheckMenuItem *checkmenuitem, gpointer user_data){	this.m_bScrollMouseChange = !this.m_bScrollMouseChange; }void on_MenuConfig_activate(GtkWidget* wideget, gpointer user_data){	gtk_widget_show(glade_xml_get_widget(theApp.m_xml, "ConfigDlg"));}gboolean on_ShowLyric_scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer user_data){	if (event->type != GDK_SCROLL || !this.m_bScrollMouseChange)return FALSE;		switch (event->direction)	{	case GDK_SCROLL_UP:	case GDK_SCROLL_LEFT:		ChangeLyricTime(1000);		break;	case GDK_SCROLL_DOWN:	case GDK_SCROLL_RIGHT:		ChangeLyricTime(-1000);		break;	}	return FALSE;}gboolean on_ShowLyric_motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer user_data){	return FALSE;}gboolean on_ShowLyric_button_press_event(GtkWidget *widget, GdkEventButton *event,		gpointer user_data){	if (event->button == 3)	{		GtkWidget *pLyricWnd = glade_xml_get_widget(theApp.m_xml, "ShowLyric");		GtkWidget *window = glade_xml_get_widget(theApp.m_xml, "LyricMenu");		GtkCheckMenuItem *pMenuMouseScroll = (GtkCheckMenuItem*)glade_xml_get_widget(theApp.m_xml, "MenuMouseScroll");;		GtkCheckMenuItem *pMenuShowBroad = (GtkCheckMenuItem*)glade_xml_get_widget(theApp.m_xml, "MenuShowBroad");;		pMenuMouseScroll->active = this.m_bScrollMouseChange;		pMenuShowBroad->active = gtk_window_get_decorated(GTK_WINDOW(pLyricWnd));		gtk_menu_popup(GTK_MENU(window), NULL, NULL, NULL, NULL, event->button,				0);		return TRUE;	}	return FALSE;}void on_ShowLyric_window_state_event(gpointer data){	if (!data)		return;	GtkWidget *window=GTK_WIDGET(data);	int istate = gdk_window_get_state(GDK_WINDOW(window->window));	gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);	gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);	switch (istate)	{	case GDK_WINDOW_STATE_ICONIFIED:		gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), FALSE);		gtk_window_set_skip_pager_hint(GTK_WINDOW(window), FALSE);		//LyricDebug("GDK_WINDOW_STATE_ICONIFIED:the window is minimized.\n");		break;	case GDK_WINDOW_STATE_WITHDRAWN:		//LyricDebug("GDK_WINDOW_STATE_WITHDRAWN:the window is not shown.\n");		break;	case GDK_WINDOW_STATE_MAXIMIZED:		//LyricDebug("GDK_WINDOW_STATE_MAXIMIZED:the window is maximized.\n");		break;	case GDK_WINDOW_STATE_STICKY:		//LyricDebug("GDK_WINDOW_STATE_STICKY:the window is sticky.\n");		break;	case GDK_WINDOW_STATE_FULLSCREEN:		//LyricDebug("GDK_WINDOW_STATE_FULLSCREEN:the window is maximized without decorations.\n");		break;	case GDK_WINDOW_STATE_ABOVE:		//LyricDebug("GDK_WINDOW_STATE_ABOVE:the window is kept above other windows. \n");		break;	case GDK_WINDOW_STATE_BELOW:		//LyricDebug("GDK_WINDOW_STATE_BELOW:the window is kept below other windows. \n");		break;		/*		 default:		 //LyricDebug("unknow state(%d)\n", istate);		 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), FALSE);		 gtk_window_set_skip_pager_hint (GTK_WINDOW (window), FALSE);		 break;		 */	}}gboolean on_ShowLyric_delete_event(GtkWidget *widget, GdkEvent *event,		gpointer user_data){	// 将关闭事件改成最小化	gtk_window_iconify(GTK_WINDOW(user_data));	// 如果返回FALSE,GTK将发出"destroy"信号;	// 如果返回TRUE, 则不让该窗口关闭	return TRUE;}

⌨️ 快捷键说明

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