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

📄 gtkprogressbar.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 2 页
字号:
{  GtkProgressBar *pbar;  GtkWidget *widget;  gint size;  pbar = GTK_PROGRESS_BAR (progress);  widget = GTK_WIDGET (progress);  /* calculate start pos */  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)    {      size = MAX (2, widget->allocation.width / pbar->activity_blocks);      if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)	{	  pbar->activity_pos = widget->style->klass->xthickness;	  pbar->activity_dir = 0;	}      else	{	  pbar->activity_pos = widget->allocation.width - 	    widget->style->klass->xthickness - (widget->allocation.height - 		widget->style->klass->ythickness * 2);	  pbar->activity_dir = 1;	}    }  else    {      size = MAX (2, widget->allocation.height / pbar->activity_blocks);      if (pbar->orientation == GTK_PROGRESS_TOP_TO_BOTTOM)	{	  pbar->activity_pos = widget->style->klass->ythickness;	  pbar->activity_dir = 0;	}      else	{	  pbar->activity_pos = widget->allocation.height -	    widget->style->klass->ythickness - (widget->allocation.width - 		widget->style->klass->xthickness * 2);	  pbar->activity_dir = 1;	}    }}static voidgtk_progress_bar_paint (GtkProgress *progress){  GtkProgressBar *pbar;  GtkWidget *widget;  gint amount;  gint block_delta = 0;  gint space = 0;  gint i;  gint x;  gint y;  gfloat percentage;  gint size;  g_return_if_fail (progress != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));  pbar = GTK_PROGRESS_BAR (progress);  widget = GTK_WIDGET (progress);  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)    space = widget->allocation.width -      2 * widget->style->klass->xthickness;  else    space = widget->allocation.height -      2 * widget->style->klass->ythickness;  percentage = gtk_progress_get_current_percentage (progress);  if (progress->offscreen_pixmap)    {      gtk_paint_box (widget->style,		     progress->offscreen_pixmap,		     GTK_STATE_NORMAL, GTK_SHADOW_IN, 		     NULL, widget, "trough",		     0, 0,		     widget->allocation.width,		     widget->allocation.height);            if (progress->activity_mode)	{	  if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||	      pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)	    {	      size = MAX (2, widget->allocation.width / pbar->activity_blocks);	      	      gtk_paint_box (widget->style,			     progress->offscreen_pixmap,			     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,			     NULL, widget, "bar",			     pbar->activity_pos,			     widget->style->klass->ythickness,			     size,			     widget->allocation.height - widget->style->klass->ythickness * 2);	      return;	    }	  else	    {	      size = MAX (2, widget->allocation.height / pbar->activity_blocks);	      	      gtk_paint_box (widget->style,			     progress->offscreen_pixmap,			     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,			     NULL, widget, "bar",			     widget->style->klass->xthickness,			     pbar->activity_pos,			     widget->allocation.width - widget->style->klass->xthickness * 2,			     size);	      return;	    }	}            amount = percentage * space;            if (amount > 0)	{	  switch (pbar->orientation)	    {	      	    case GTK_PROGRESS_LEFT_TO_RIGHT:	      	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)		{		  gtk_paint_box (widget->style,				 progress->offscreen_pixmap,				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				 NULL, widget, "bar",				 widget->style->klass->xthickness,				 widget->style->klass->ythickness,				 amount,				 widget->allocation.height - widget->style->klass->ythickness * 2);		}	      else		{		  x = widget->style->klass->xthickness;		  		  for (i = 0; i <= pbar->in_block; i++)		    {		      block_delta = (((i + 1) * space) / pbar->blocks)			- ((i * space) / pbar->blocks);		      		      gtk_paint_box (widget->style,				     progress->offscreen_pixmap,				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				     NULL, widget, "bar",				     x,				     widget->style->klass->ythickness,				     block_delta,				     widget->allocation.height - widget->style->klass->ythickness * 2);		      		      x +=  block_delta;		    }		}	      break;	      	    case GTK_PROGRESS_RIGHT_TO_LEFT:	      	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)		{		  gtk_paint_box (widget->style,				 progress->offscreen_pixmap,				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				 NULL, widget, "bar",				 widget->allocation.width - 				 widget->style->klass->xthickness - amount,				 widget->style->klass->ythickness,				 amount,				 widget->allocation.height -				 widget->style->klass->ythickness * 2);		}	      else		{		  x = widget->allocation.width - 		    widget->style->klass->xthickness;		  		  for (i = 0; i <= pbar->in_block; i++)		    {		      block_delta = (((i + 1) * space) / pbar->blocks) -			((i * space) / pbar->blocks);		      		      x -=  block_delta;		      		      gtk_paint_box (widget->style,				     progress->offscreen_pixmap,				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				     NULL, widget, "bar",				     x,				     widget->style->klass->ythickness,				     block_delta,				     widget->allocation.height -				     widget->style->klass->ythickness * 2);		    }		}	      break;	    case GTK_PROGRESS_BOTTOM_TO_TOP:	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)		{		  gtk_paint_box (widget->style,				 progress->offscreen_pixmap,				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				 NULL, widget, "bar",				 widget->style->klass->xthickness,				 widget->allocation.height - 				 widget->style->klass->ythickness - amount,				 widget->allocation.width -				 widget->style->klass->xthickness * 2,				 amount);		}	      else		{		  y = widget->allocation.height - 		    widget->style->klass->ythickness;		  		  for (i = 0; i <= pbar->in_block; i++)		    {		      block_delta = (((i + 1) * space) / pbar->blocks) -			((i * space) / pbar->blocks);		      		      y -= block_delta;		      		      gtk_paint_box (widget->style,				     progress->offscreen_pixmap,				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				     NULL, widget, "bar",				     widget->style->klass->xthickness,				     y,				     widget->allocation.width - 				     widget->style->klass->xthickness * 2,				     block_delta);		    }		}	      break;	      	    case GTK_PROGRESS_TOP_TO_BOTTOM:	      	      if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)		{		  gtk_paint_box (widget->style,				 progress->offscreen_pixmap,				 GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				 NULL, widget, "bar",				 widget->style->klass->xthickness,				 widget->style->klass->ythickness,				 widget->allocation.width -				 widget->style->klass->xthickness * 2,				 amount);		}	      else		{		  y = widget->style->klass->ythickness;		  		  for (i = 0; i <= pbar->in_block; i++)		    {		      		      block_delta = (((i + 1) * space) / pbar->blocks)			- ((i * space) / pbar->blocks);		      		      gtk_paint_box (widget->style,				     progress->offscreen_pixmap,				     GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,				     NULL, widget, "bar",				     widget->style->klass->xthickness,				     y,				     widget->allocation.width -				     widget->style->klass->xthickness * 2,				     block_delta);		      		      y += block_delta;		    }		}	      break;	      	    default:	      break;	    }	}            if (progress->show_text && pbar->bar_style != GTK_PROGRESS_DISCRETE)	{	  gint x;	  gint y;	  gchar *buf;	  GdkRectangle rect;	  buf = gtk_progress_get_current_text (progress);	  x = widget->style->klass->xthickness + 1 + 	    (widget->allocation.width - 2 * widget->style->klass->xthickness -	     3 - gdk_text_width (widget->style->font, buf, strlen (buf)))	    * progress->x_align; 	  y = widget->style->font->ascent + 1 +	    (widget->allocation.height - 2 * widget->style->klass->ythickness -	     3 - gdk_text_height (widget->style->font, buf, strlen (buf)))	    * progress->y_align;	  rect.x = widget->style->klass->xthickness + 1;	  rect.y = widget->style->klass->ythickness + 1;	  rect.width = widget->allocation.width -	    2 * widget->style->klass->xthickness - 3;	  rect.height = widget->allocation.height -	    2 * widget->style->klass->ythickness - 3;	  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],				     &rect);	  gdk_draw_text (progress->offscreen_pixmap, widget->style->font,			 widget->style->fg_gc[widget->state],			 x, y, buf, strlen (buf));	  gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],				     NULL);	  g_free (buf); 	}    }}/*******************************************************************/voidgtk_progress_bar_update (GtkProgressBar *pbar,			 gfloat          percentage){  g_return_if_fail (pbar != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));  /***********************************************************************   *          Use of gtk_progress_bar_update() is deprecated !	         *    * Use gtk_progress_set_value or gtk_progress_set_percentage instead.  *   ***********************************************************************/  gtk_progress_set_percentage (GTK_PROGRESS (pbar), percentage);}voidgtk_progress_bar_set_orientation (GtkProgressBar           *pbar,				  GtkProgressBarOrientation orientation){  g_return_if_fail (pbar != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));  if (pbar->orientation != orientation)    {      pbar->orientation = orientation;      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))	gtk_widget_queue_resize (GTK_WIDGET (pbar));    }}voidgtk_progress_bar_set_bar_style (GtkProgressBar     *pbar,				GtkProgressBarStyle bar_style){  g_return_if_fail (pbar != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));  if (pbar->bar_style != bar_style)    {      pbar->bar_style = bar_style;      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))	gtk_widget_queue_resize (GTK_WIDGET (pbar));    }}voidgtk_progress_bar_set_discrete_blocks (GtkProgressBar *pbar,				      guint           blocks){  g_return_if_fail (pbar != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));  g_return_if_fail (blocks > 1);  if (pbar->blocks != blocks)    {      pbar->blocks = blocks;      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (pbar)))	gtk_widget_queue_resize (GTK_WIDGET (pbar));    }}voidgtk_progress_bar_set_activity_step (GtkProgressBar *pbar,                                    guint           step){  g_return_if_fail (pbar != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));  if (pbar->activity_step != step)    pbar->activity_step = step;}voidgtk_progress_bar_set_activity_blocks (GtkProgressBar *pbar,				      guint           blocks){  g_return_if_fail (pbar != NULL);  g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));  g_return_if_fail (blocks > 1);  if (pbar->activity_blocks != blocks)    pbar->activity_blocks = blocks;}

⌨️ 快捷键说明

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