Beispiel #1
0
gboolean update_pbar(gpointer data)
{
	static gfloat lower = 0.0;
	static gfloat upper = 1.0;
	gfloat cur_val = 0.0;
	gfloat interval = 0.0;
	static gboolean rising = TRUE;

	GtkWidget * pbar = (GtkWidget *)data;
	interval = (upper-lower)/100.0;
	cur_val = mtx_progress_bar_get_fraction(MTX_PROGRESS_BAR (pbar));
	if (cur_val >= upper)
		rising = FALSE;
	if (cur_val <= lower)
		rising = TRUE;

	if (rising)
	{
		cur_val+=interval;
		if (cur_val > upper)
			cur_val = upper;
	}
	else
	{
		cur_val-=interval;
		if (cur_val < lower)
			cur_val = lower;
	}
	mtx_progress_bar_set_fraction (MTX_PROGRESS_BAR (pbar),cur_val);
	return FALSE;

}
Beispiel #2
0
/*!
  \brief rt_update_values() is called for each runtime slider to update
  it's position and label (label is periodic and not every time due to pango
  speed problems)
  \param key is unused
  \param value is the pointer to Rt_Slider
  \param data is unused
  */
G_MODULE_EXPORT void rt_update_values(gpointer key, gpointer value, gpointer data)
{
	static GRand *rand = NULL;
	static GMutex *rtv_mutex = NULL;
	Rt_Slider *slider = (Rt_Slider *)value;
	gint count = slider->count;
	gint last_upd = slider->last_upd;
	gfloat upper = 0.0;
	gfloat lower = 0.0;
	gint precision = 0;
	gfloat current = 0.0;
	gfloat previous = 0.0;
	GArray *history = NULL;
	gchar * tmpbuf = NULL;

	if (DATA_GET(global_data,"leaving"))
		return;

	if (!rtv_mutex)
		rtv_mutex = (GMutex *)DATA_GET(global_data,"rtv_mutex");
	if (!rand)
		rand = g_rand_new();
	history = (GArray *)DATA_GET(slider->object,"history");
	if (!history)
		return;
	if ((GINT)history->len-1 <= 0)
		return;
	precision = (GINT)DATA_GET(slider->object,"precision");
	g_mutex_lock(rtv_mutex);
	/*printf("runtime_gui history length is %i, current index %i\n",history->len,history->len-1);*/
	current = g_array_index(history, gfloat, history->len-1);
	previous = slider->last;
	slider->last = current;
	g_mutex_unlock(rtv_mutex);

	if (slider->temp_dep)
	{
		upper = temp_to_host((gfloat)slider->upper);
		lower = temp_to_host((gfloat)slider->lower);
	}
	else
	{
		upper = (gfloat)slider->upper;
		lower = (gfloat)slider->lower;
	}

	
	gdk_threads_enter();
	if ((current != previous) || 
			(DATA_GET(global_data,"rt_forced_update")))
	{
		gfloat percentage = (current-lower)/(upper-lower);
		gfloat tmpf = percentage <= 1.0 ? percentage : 1.0;
		tmpf = tmpf >= 0.0 ? tmpf : 0.0;
		switch (slider->type)
		{
			case MTX_PROGRESS:
				mtx_progress_bar_set_fraction(MTX_PROGRESS_BAR
						(slider->pbar),
						tmpf);
				break;
			case MTX_RANGE:
				gtk_range_set_value(GTK_RANGE(slider->pbar),current);
				break;
			default:
				break;
		}


		/* If changed by more than 5% or has been at least 5 
		 * times withot an update or rt_forced_update is set
		 * */
		if ((slider->textval) && ((abs(count-last_upd) > 2) || 
					(DATA_GET(global_data,"rt_forced_update"))))
		{
			tmpbuf = g_strdup_printf("%1$.*2$f",current,precision);

			//gtk_label_set_text(GTK_LABEL(slider->textval),tmpbuf);
			gtk_entry_set_text(GTK_ENTRY(slider->textval),tmpbuf);
			g_free(tmpbuf);
			last_upd = count;
		}
		slider->last_percentage = percentage;
	}
	else if (slider->textval && ((abs(count-last_upd)%g_rand_int_range(rand,25,50)) == 0))
	{
		tmpbuf = g_strdup_printf("%1$.*2$f",current,precision);

		//gtk_label_set_text(GTK_LABEL(slider->textval),tmpbuf);
		gtk_entry_set_text(GTK_ENTRY(slider->textval),tmpbuf);
		g_free(tmpbuf);
		last_upd = count;
	}

	gdk_threads_leave();
	if (last_upd > 5000)
		last_upd = 0;
	count++;
	if (count > 5000)
		count = 0;
	slider->count = count;
	slider->last_upd = last_upd;
	return;
}