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; }
/*! \brief register_rt_range() creates the slider from the passed data, and attaches it the the gui. This is called during gui tab loading to embed sliders into regular tabs. \param widget is the widget defined in Gui datamap file. Used to load all the necessary attributes to stick the control in the right place. */ G_MODULE_EXPORT void register_rt_range(GtkWidget * widget) { gconstpointer *object = NULL; Rtv_Map *rtv_map = NULL; GHashTable *rt_sliders = NULL; GHashTable *aw_sliders = NULL; GHashTable *ww_sliders = NULL; GHashTable *enr_sliders = NULL; gchar * source = NULL; const gchar *name = NULL; TabIdent ident; Rt_Slider *slider = NULL; rtv_map = (Rtv_Map *)DATA_GET(global_data,"rtv_map"); source = (gchar *)OBJ_GET(widget,"source"); ident = (TabIdent)(GINT)OBJ_GET(widget,"tab_ident"); name = glade_get_widget_name(widget); g_return_if_fail(rtv_map); g_return_if_fail(source); object = (gconstpointer *)g_hash_table_lookup(rtv_map->rtv_hash,source); rt_sliders = (GHashTable *)DATA_GET(global_data,"rt_sliders"); aw_sliders = (GHashTable *)DATA_GET(global_data,"aw_sliders"); ww_sliders = (GHashTable *)DATA_GET(global_data,"ww_sliders"); enr_sliders = (GHashTable *)DATA_GET(global_data,"enr_sliders"); if (!rt_sliders) { rt_sliders = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,dealloc_slider); DATA_SET_FULL(global_data,"rt_sliders",rt_sliders,g_hash_table_destroy); } if (!aw_sliders) { aw_sliders = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,dealloc_slider); DATA_SET_FULL(global_data,"aw_sliders",aw_sliders,g_hash_table_destroy); } if (!ww_sliders) { ww_sliders = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,dealloc_slider); DATA_SET_FULL(global_data,"ww_sliders",ww_sliders,g_hash_table_destroy); } if (!enr_sliders) { enr_sliders = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,dealloc_slider); DATA_SET_FULL(global_data,"enr_sliders",enr_sliders,g_hash_table_destroy); } if (!(object)) { MTXDBG(CRITICAL,_("ERROR! There is no datasource named \"%s\", Check config of widget %s\n"),source,(name == NULL ? "undefined":name)); return; } slider = (Rt_Slider *)g_malloc0(sizeof(Rt_Slider)); slider->ctrl_name = g_strdup((name == NULL ? "undefined":name)); slider->tbl = -1; slider->table_num = -1; slider->row = -1; slider->history = (GArray *) DATA_GET(object,"history"); slider->friendly_name = (gchar *) DATA_GET(object,"dlog_gui_name"); slider->temp_dep = (GBOOLEAN)DATA_GET(object,"temp_dep"); if ((gchar *)DATA_GET(object,"real_lower")) slider->lower = (GINT)strtol((gchar *)DATA_GET(object,"real_lower"),NULL,10); else printf(_("No \"real_lower\" value defined for control name %s, datasource %s\n"),slider->ctrl_name,source); if ((gchar *)DATA_GET(object,"real_upper")) slider->upper = (GINT)strtol((gchar *)DATA_GET(object,"real_upper"),NULL,10); else printf(_("No \"real_upper\" value defined for control name %s, datasource %s\n"),slider->ctrl_name,source); slider->object = object; slider->textval = NULL; if (GTK_IS_SCALE(widget)) { slider->type = MTX_RANGE; slider->pbar = widget; } /* generic container (Table/box HOLDING a mtx pbar */ else if (GTK_IS_CONTAINER(widget)) { GtkProgressBarOrientation orient; /* We don't like GTK+'s progress bar, so rip it out and * stick in my custom version instead. Get the orientation * first... */ orient = (GtkProgressBarOrientation)(GINT)OBJ_GET(widget,"orientation"); slider->pbar = mtx_progress_bar_new(); mtx_progress_bar_set_hold_time(MTX_PROGRESS_BAR(slider->pbar),(GINT)DATA_GET(global_data,"pbar_hold_time")); gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(slider->pbar),orient); gtk_container_add(GTK_CONTAINER(widget),slider->pbar); slider->type = MTX_PROGRESS; } switch (ident) { case RUNTIME_TAB: printf("inserted slider into runtime tab!\n"); g_hash_table_insert(rt_sliders,g_strdup(slider->ctrl_name),(gpointer)slider); break; case ENRICHMENTS_TAB: g_hash_table_insert(enr_sliders,g_strdup(slider->ctrl_name),(gpointer)slider); break; case WARMUP_WIZ_TAB: g_hash_table_insert(ww_sliders,g_strdup(slider->ctrl_name),(gpointer)slider); break; case ACCEL_WIZ_TAB: g_hash_table_insert(aw_sliders,g_strdup(slider->ctrl_name),(gpointer)slider); break; default: break; } }
/*! \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; }
/*! \brief add_slider() creates the slider from the passed data, and attaches it the the gui. \param ctrl_name is the name of the slider as defined in the config file \param tbl is the table number to bind this slider to \param table_num is the table_num from the firmware that this slider is bound to. (used for the sliders on the 3D view) \param row is the row of the table (tbl) that this slider goes on \param source is the data source for this slider \param ident is the enumeration of the page this slider goes on \returns a Struct Rt_Slider * */ G_MODULE_EXPORT Rt_Slider * add_slider(gchar *ctrl_name, gint tbl, gint table_num, gint row, gchar *source, TabIdent ident) { Rt_Slider *slider = NULL; GtkWidget *label = NULL; GtkWidget *pbar = NULL; GtkWidget *table = NULL; GtkWidget *hbox = NULL; gchar * name = NULL; Rtv_Map *rtv_map = NULL; gconstpointer *object = NULL; rtv_map = (Rtv_Map *)DATA_GET(global_data,"rtv_map"); object = (gconstpointer *)g_hash_table_lookup(rtv_map->rtv_hash,source); if (!(object)) { MTXDBG(CRITICAL,_("Request to create slider for non-existant datasource \"%s\"\n"),source); return NULL; } if (ident == RUNTIME_TAB) name = g_strdup_printf("runtime_rt_table%i",tbl); else if (ident == WARMUP_WIZ_TAB) name = g_strdup_printf("ww_rt_table%i",tbl); else if (ident == VE3D_VIEWER_TAB) name = g_strdup_printf("ve3d_rt_table%i_%i",tbl,table_num); else { MTXDBG(CRITICAL,_("Page ident passed is not handled, ERROR, widget add aborted\n")); return NULL; } table = lookup_widget(name); if (!table) { MTXDBG(CRITICAL,_("Table \"%s\" was not found, RuntimeSlider map or runtime datamap has a typo\n"),name); g_free(name); return NULL; } g_free(name); slider = (Rt_Slider *)g_malloc0(sizeof(Rt_Slider)); slider->ctrl_name = g_strdup(ctrl_name); slider->tbl = tbl; slider->table_num = table_num; slider->row = row; slider->last = 0.0; slider->type = MTX_PROGRESS; slider->friendly_name = (gchar *) DATA_GET(object,"dlog_gui_name"); slider->temp_dep = (GBOOLEAN)DATA_GET(object,"temp_dep"); if ((gchar *)DATA_GET(object,"real_lower")) slider->lower = (GINT)strtol((gchar *)DATA_GET(object,"real_lower"),NULL,10); else MTXDBG(CRITICAL,_("No \"real_lower\" value defined for control name %s, datasource %s\n"),ctrl_name,source); if ((gchar *)DATA_GET(object,"real_upper")) slider->upper = (GINT)strtol((gchar *)DATA_GET(object,"real_upper"),NULL,10); else MTXDBG(CRITICAL,_("No \"real_upper\" value defined for control name %s, datasource %s\n"),ctrl_name,source); slider->history = (GArray *) DATA_GET(object,"history"); slider->object = object; hbox = gtk_hbox_new(FALSE,5); label = gtk_label_new(NULL); slider->label = label; gtk_label_set_markup(GTK_LABEL(label),slider->friendly_name); gtk_misc_set_alignment(GTK_MISC(label),0.0,0.5); gtk_box_pack_start(GTK_BOX(hbox),label,TRUE,TRUE,0); label = gtk_entry_new(); gtk_entry_set_has_frame(GTK_ENTRY(label),FALSE); gtk_entry_set_width_chars(GTK_ENTRY(label),6); gtk_entry_set_alignment(GTK_ENTRY(label),1); gtk_entry_set_editable(GTK_ENTRY(label),FALSE); /* PRELIGHT seems to not give the box as NORMAL does, not sure why */ gtk_widget_modify_base(GTK_WIDGET(label),GTK_STATE_NORMAL,>k_widget_get_style(slider->label)->bg[GTK_STATE_PRELIGHT]); slider->textval = label; gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0); if ((ident == RUNTIME_TAB) || (ident == VE3D_VIEWER_TAB)) { if (((tbl+1) % 2) == 0) gtk_size_group_add_widget(size_group_right,hbox); else gtk_size_group_add_widget(size_group_left,hbox); } gtk_table_attach (GTK_TABLE (table),hbox, 0,2,slider->row,(slider->row)+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); pbar = mtx_progress_bar_new(); /* 1.1 Seconds peak hold time */ mtx_progress_bar_set_hold_time(MTX_PROGRESS_BAR(pbar),1100); gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pbar), GTK_PROGRESS_LEFT_TO_RIGHT); gtk_table_attach (GTK_TABLE (table),pbar, 2,3,slider->row,(slider->row)+1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND|GTK_SHRINK), (GtkAttachOptions) (GTK_FILL|GTK_EXPAND|GTK_SHRINK), 0, 0); slider->pbar = pbar; slider->parent = table; gtk_widget_show_all(slider->parent); return slider; }